Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App warmup caching #4133

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

App warmup caching #4133

wants to merge 6 commits into from

Conversation

shauns
Copy link
Contributor

@shauns shauns commented Jun 27, 2024

WHY are these changes introduced?

Improves command speed by caching some supporting data about the developer

WHAT is this pull request doing?

Caches:

  • that the partner has a partner account (permanent)
  • the account info of the partner (72h)

How to test your changes?

Run something like app info --verbose. Note 2 GraphQL queries to pull in that cached information. Run the command again, note the queries are gone.

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

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** 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.

Copy link
Contributor

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.66% (+0.03% 🔼)
7508/10333
🟡 Branches
69.22% (-0.02% 🔻)
3684/5322
🟡 Functions
71.7% (+0.07% 🔼)
1986/2770
🟡 Lines
73% (+0.03% 🔼)
7093/9716
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / partner-account-info.ts
76.92% (-23.08% 🔻)
33.33% (-66.67% 🔻)
100%
76.92% (-23.08% 🔻)

Test suite run success

1722 tests passing in 794 suites.

Report generated by 🧪jest coverage report action from e1df260

Copy link
Contributor

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/private/node/conf-store.d.ts
@@ -40,4 +40,6 @@ type CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['valu
  * @returns The value from the cache or the result of the function.
  */
 export declare function cacheRetrieveOrRepopulate(key: keyof Cache, fn: () => Promise<CacheValueForKey<typeof key>>, timeout?: number, config?: LocalStorage<ConfSchema>): Promise<CacheValueForKey<typeof key>>;
+export declare function getCachedPartnerAccountStatus(partnersToken: string): true | null;
+export declare function setCachedPartnerAccountStatus(partnersToken: string): void;
 export {};
\ No newline at end of file
packages/cli-kit/dist/private/node/session.d.ts
@@ -60,7 +60,9 @@ export interface OAuthSession {
     storefront?: string;
     businessPlatform?: string;
     appManagement?: string;
+    userId: string;
 }
+export declare function getLastSeenUserIdAfterAuth(): string | undefined;
 /**
  * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
  *
packages/cli-kit/dist/public/node/environment.d.ts
@@ -42,4 +42,5 @@ export declare function getBackendPort(): number | undefined;
 export declare function getIdentityTokenInformation(): {
     accessToken: string;
     refreshToken: string;
+    userId: string;
 } | undefined;
\ No newline at end of file
packages/cli-kit/dist/public/node/session.d.ts
@@ -17,9 +17,18 @@ interface EnsureAuthenticatedAdditionalOptions {
  * @param scopes - Optional array of extra scopes to authenticate with.
  * @param env - Optional environment variables to use.
  * @param options - Optional extra options to use.
- * @returns The access token for the Partners API.
+ * @returns The access token for the Partners API, and the user's ID.
  */
 export declare function ensureAuthenticatedPartners(scopes?: string[], env?: NodeJS.ProcessEnv, options?: EnsureAuthenticatedAdditionalOptions): Promise<string>;
+/**
+ * Ensures the user is authenticated, returns their user ID.
+ *
+ * If the CLI already ran  earlier -- under any context -- it won't repeat any work.
+ *
+ * @param env - Optional environment variables to use.
+ * @returns User ID, this should be the same for the same human beings.
+ */
+export declare function ensureAuthenticatedUserId(env?: NodeJS.ProcessEnv): Promise<string>;
 /**
  * Ensure that we have a valid session to access the App Management API.
  *
packages/cli-kit/dist/private/node/session/schema.d.ts
@@ -7,15 +7,18 @@ declare const IdentityTokenSchema: zod.ZodObject<{
     refreshToken: zod.ZodString;
     expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
     scopes: zod.ZodArray<zod.ZodString, "many">;
+    userId: zod.ZodString;
 }, "strip", zod.ZodTypeAny, {
     accessToken: string;
     scopes: string[];
     refreshToken: string;
     expiresAt: Date;
+    userId: string;
 }, {
     accessToken: string;
     scopes: string[];
     refreshToken: string;
+    userId: string;
     expiresAt?: unknown;
 }>;
 /**
@@ -53,15 +56,18 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         refreshToken: zod.ZodString;
         expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
         scopes: zod.ZodArray<zod.ZodString, "many">;
+        userId: zod.ZodString;
     }, "strip", zod.ZodTypeAny, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     }, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     }>;
     /**
@@ -111,6 +117,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     };
     applications: {} & {
         [k: string]: {
@@ -124,6 +131,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     };
     applications: {} & {
@@ -144,15 +152,18 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         refreshToken: zod.ZodString;
         expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
         scopes: zod.ZodArray<zod.ZodString, "many">;
+        userId: zod.ZodString;
     }, "strip", zod.ZodTypeAny, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     }, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     }>;
     /**
@@ -202,6 +213,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     };
     applications: {} & {
         [k: string]: {
@@ -215,6 +227,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     };
     applications: {} & {
@@ -235,15 +248,18 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         refreshToken: zod.ZodString;
         expiresAt: zod.ZodEffects<zod.ZodDate, Date, unknown>;
         scopes: zod.ZodArray<zod.ZodString, "many">;
+        userId: zod.ZodString;
     }, "strip", zod.ZodTypeAny, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     }, {
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     }>;
     /**
@@ -293,6 +309,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         scopes: string[];
         refreshToken: string;
         expiresAt: Date;
+        userId: string;
     };
     applications: {} & {
         [k: string]: {
@@ -306,6 +323,7 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
         accessToken: string;
         scopes: string[];
         refreshToken: string;
+        userId: string;
         expiresAt?: unknown;
     };
     applications: {} & {
@@ -319,4 +337,10 @@ export declare const SessionSchema: zod.ZodObject<{}, "strip", zod.ZodObject<{
 export type Session = zod.infer<typeof SessionSchema>;
 export type IdentityToken = zod.infer<typeof IdentityTokenSchema>;
 export type ApplicationToken = zod.infer<typeof ApplicationTokenSchema>;
+/**
+ * Confirms that a given identity token structure matches what the schema currently defines.
+ *
+ * A full re-auth is the expectation if this validation fails.
+ */
+export declare function validateCachedIdentityTokenStructure(identityToken: unknown): boolean;
 export {};
\ No newline at end of file

@HananAyad
Copy link

Do we now need to add user_id to the monorail instrumentation?

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.

None yet

2 participants