Skip to content

Conversation

gonzaloriestra
Copy link
Contributor

@gonzaloriestra gonzaloriestra commented Oct 1, 2025

WHY are these changes introduced?

We are caching the current session for each Developer Platform client (Partners and App Management) as an instance variable, but we are creating instances from multiple places.

That could lead in multiple login requests during the same command. I think it's not happening right now, but it could happen eventually after some refactor.

WHAT is this pull request doing?

  • Moves the cached sessions to a global variable, ensuring there is only one, even if there are multiple clients.
  • Renames PartnersSession to Session because it was shared by both clients, and moves it to cli-kit

How to test your changes?

Log in and run commands

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Oct 1, 2025

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

We found no new type declarations in this PR

Existing type declarations

packages/cli-kit/dist/public/node/session.d.ts
@@ -6,6 +6,41 @@ export interface AdminSession {
     token: string;
     storeFqdn: string;
 }
+/**
+ * Session Object for developer platform clients, includes token and account info.
+ */
+export interface Session {
+    token: string;
+    businessPlatformToken: string;
+    accountInfo: AccountInfo;
+    userId: string;
+}
+export type AccountInfo = UserAccountInfo | ServiceAccountInfo | UnknownAccountInfo;
+interface UserAccountInfo {
+    type: 'UserAccount';
+    email: string;
+}
+interface ServiceAccountInfo {
+    type: 'ServiceAccount';
+    orgName: string;
+}
+interface UnknownAccountInfo {
+    type: 'UnknownAccount';
+}
+/**
+ * Type guard to check if an AccountInfo is a UserAccountInfo.
+ *
+ * @param account - The account info to check.
+ * @returns True if the account is a UserAccountInfo, false otherwise.
+ */
+export declare function isUserAccount(account: AccountInfo): account is UserAccountInfo;
+/**
+ * Type guard to check if an AccountInfo is a ServiceAccountInfo.
+ *
+ * @param account - The account info to check.
+ * @returns True if the account is a ServiceAccountInfo, false otherwise.
+ */
+export declare function isServiceAccount(account: AccountInfo): account is ServiceAccountInfo;
 /**
  * Ensure that we have a valid session with no particular scopes.
  *
@@ -86,4 +121,5 @@ export declare function ensureAuthenticatedBusinessPlatform(scopes?: BusinessPla
  *
  * @returns A promise that resolves when the logout is complete.
  */
-export declare function logout(): Promise<void>;
\ No newline at end of file
+export declare function logout(): Promise<void>;
+export {};
\ No newline at end of file

Copy link
Contributor

github-actions bot commented Oct 1, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
78.75% (+0.01% 🔼)
13734/17439
🟡 Branches
72.5% (+0.05% 🔼)
6693/9232
🟡 Functions
78.84% (+0.06% 🔼)
3528/4475
🟡 Lines
79.09% (+0.01% 🔼)
12983/16416
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / global-session-store.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / app-management-client.ts
52.98% (-0.8% 🔻)
47.71% (+0.03% 🔼)
49.54%
51.59% (-0.83% 🔻)

Test suite run success

3331 tests passing in 1382 suites.

Report generated by 🧪jest coverage report action from a1aa2c9

@gonzaloriestra gonzaloriestra changed the title Store session globally to avoid multiple instances Use a global cache for the sessions to avoid multiple instances Oct 2, 2025
@gonzaloriestra gonzaloriestra marked this pull request as ready for review October 2, 2025 11:43
@gonzaloriestra gonzaloriestra requested a review from a team as a code owner October 2, 2025 11:43
Copy link
Contributor

github-actions bot commented Oct 2, 2025

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run pnpm changeset add to track your changes and include them in the next release CHANGELOG.

Caution

DO NOT create changesets for features which you do not wish to be included in the public changelog of the next CLI release.

export function isServiceAccount(account: AccountInfo): account is ServiceAccountInfo {
return account.type === 'ServiceAccount'
}
export {AccountInfo, isUserAccount, isServiceAccount}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to re-export them here no? Whoever is using these can directly import from cli-kit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants