@shopify/cli-kit 3.84.2 → 3.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/private/node/analytics/bounded-collections.js.map +1 -0
- package/dist/{public/node/themes → private/node}/analytics/error-categorizer.d.ts +7 -1
- package/dist/private/node/analytics/error-categorizer.js +106 -0
- package/dist/private/node/analytics/error-categorizer.js.map +1 -0
- package/dist/{public/node/themes → private/node}/analytics/storage.js +8 -3
- package/dist/private/node/analytics/storage.js.map +1 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.d.ts +6 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.js +8 -0
- package/dist/private/node/api/graphql/business-platform-destinations/user-email.js.map +1 -0
- package/dist/private/node/api/headers.d.ts +3 -6
- package/dist/private/node/api/headers.js +8 -24
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/conf-store.d.ts +20 -3
- package/dist/private/node/conf-store.js +32 -7
- package/dist/private/node/conf-store.js.map +1 -1
- package/dist/private/node/constants.d.ts +0 -1
- package/dist/private/node/constants.js +0 -1
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/context/service.d.ts +8 -2
- package/dist/private/node/context/service.js +9 -5
- package/dist/private/node/context/service.js.map +1 -1
- package/dist/private/node/otel-metrics.js +2 -3
- package/dist/private/node/otel-metrics.js.map +1 -1
- package/dist/private/node/session/schema.d.ts +796 -41
- package/dist/private/node/session/schema.js +24 -25
- package/dist/private/node/session/schema.js.map +1 -1
- package/dist/private/node/session/store.d.ts +21 -11
- package/dist/private/node/session/store.js +52 -18
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session/validate.d.ts +2 -7
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.d.ts +8 -6
- package/dist/private/node/session.js +99 -71
- package/dist/private/node/session.js.map +1 -1
- package/dist/private/node/ui/components/LoadingBar.d.ts +8 -0
- package/dist/private/node/ui/components/LoadingBar.js +21 -0
- package/dist/private/node/ui/components/LoadingBar.js.map +1 -0
- package/dist/private/node/ui/components/LoadingBar.test.d.ts +1 -0
- package/dist/private/node/ui/components/LoadingBar.test.js +182 -0
- package/dist/private/node/ui/components/LoadingBar.test.js.map +1 -0
- package/dist/private/node/ui/components/SingleTask.d.ts +8 -0
- package/dist/private/node/ui/components/SingleTask.js +27 -0
- package/dist/private/node/ui/components/SingleTask.js.map +1 -0
- package/dist/private/node/ui/components/SingleTask.test.d.ts +1 -0
- package/dist/private/node/ui/components/SingleTask.test.js +145 -0
- package/dist/private/node/ui/components/SingleTask.test.js.map +1 -0
- package/dist/private/node/ui/components/Tasks.d.ts +2 -1
- package/dist/private/node/ui/components/Tasks.js +5 -25
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +19 -103
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.d.ts +4 -0
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.js +15 -0
- package/dist/private/node/ui/hooks/use-exit-on-ctrl-c.js.map +1 -0
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/analytics.d.ts +77 -0
- package/dist/public/node/analytics.js +88 -0
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.js +2 -3
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/app-dev.d.ts +2 -0
- package/dist/public/node/api/app-dev.js +1 -0
- package/dist/public/node/api/app-dev.js.map +1 -1
- package/dist/public/node/base-command.d.ts +22 -0
- package/dist/public/node/base-command.js +1 -1
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/context/fqdn.d.ts +0 -4
- package/dist/public/node/context/fqdn.js +1 -23
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/context/local.d.ts +2 -2
- package/dist/public/node/context/local.js +2 -6
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/error-handler.js +2 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/http.d.ts +1 -1
- package/dist/public/node/http.js +1 -1
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/metadata.d.ts +31 -4
- package/dist/public/node/metadata.js.map +1 -1
- package/dist/public/node/session-prompt.d.ts +10 -0
- package/dist/public/node/session-prompt.js +86 -0
- package/dist/public/node/session-prompt.js.map +1 -0
- package/dist/public/node/session.d.ts +11 -6
- package/dist/public/node/session.js +15 -4
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/themes/api.js +28 -8
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/ui.d.ts +17 -1
- package/dist/public/node/ui.js +26 -2
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vendor/dev_server/dev-server.js +1 -5
- package/dist/public/node/vendor/dev_server/dev-server.js.map +1 -1
- package/dist/public/node/vendor/dev_server/env.js +2 -2
- package/dist/public/node/vendor/dev_server/env.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/private/node/context/spin-cache.d.ts +0 -2
- package/dist/private/node/context/spin-cache.js +0 -8
- package/dist/private/node/context/spin-cache.js.map +0 -1
- package/dist/public/node/context/spin.d.ts +0 -69
- package/dist/public/node/context/spin.js +0 -152
- package/dist/public/node/context/spin.js.map +0 -1
- package/dist/public/node/themes/analytics/bounded-collections.js.map +0 -1
- package/dist/public/node/themes/analytics/error-categorizer.js +0 -49
- package/dist/public/node/themes/analytics/error-categorizer.js.map +0 -1
- package/dist/public/node/themes/analytics/storage.js.map +0 -1
- package/dist/public/node/themes/analytics.d.ts +0 -60
- package/dist/public/node/themes/analytics.js +0 -71
- package/dist/public/node/themes/analytics.js.map +0 -1
- package/dist/public/node/vendor/dev_server/dev-server-spin.d.ts +0 -5
- package/dist/public/node/vendor/dev_server/dev-server-spin.js +0 -28
- package/dist/public/node/vendor/dev_server/dev-server-spin.js.map +0 -1
- /package/dist/{public/node/themes → private/node}/analytics/bounded-collections.d.ts +0 -0
- /package/dist/{public/node/themes → private/node}/analytics/bounded-collections.js +0 -0
- /package/dist/{public/node/themes → private/node}/analytics/storage.d.ts +0 -0
|
@@ -13,6 +13,7 @@ const IdentityTokenSchema = zod.object({
|
|
|
13
13
|
expiresAt: DateSchema,
|
|
14
14
|
scopes: zod.array(zod.string()),
|
|
15
15
|
userId: zod.string(),
|
|
16
|
+
alias: zod.string().optional(),
|
|
16
17
|
});
|
|
17
18
|
/**
|
|
18
19
|
* The schema represents an application token.
|
|
@@ -21,6 +22,11 @@ const ApplicationTokenSchema = zod.object({
|
|
|
21
22
|
accessToken: zod.string(),
|
|
22
23
|
expiresAt: DateSchema,
|
|
23
24
|
scopes: zod.array(zod.string()),
|
|
25
|
+
storeFqdn: zod.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
const SessionSchema = zod.object({
|
|
28
|
+
identity: IdentityTokenSchema,
|
|
29
|
+
applications: zod.object({}).catchall(ApplicationTokenSchema),
|
|
24
30
|
});
|
|
25
31
|
/**
|
|
26
32
|
* This schema represents the format of the session
|
|
@@ -30,34 +36,27 @@ const ApplicationTokenSchema = zod.object({
|
|
|
30
36
|
* @example
|
|
31
37
|
* ```
|
|
32
38
|
* {
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
39
|
+
* "accounts.shopify.com": {
|
|
40
|
+
* "user-123": {
|
|
41
|
+
* "identity": { ... }, // IdentityTokenSchema
|
|
42
|
+
* "applications": {
|
|
43
|
+
* "mystore.myshopify.com-admin": { // ApplicationTokenSchema
|
|
44
|
+
* "accessToken": "...",
|
|
45
|
+
* "expiresAt": "...",
|
|
46
|
+
* "scopes": ["..."],
|
|
47
|
+
* },
|
|
48
|
+
* "partners": { ... },
|
|
49
|
+
* }
|
|
50
|
+
* },
|
|
51
|
+
* "8765-4321": { ... }
|
|
52
|
+
* },
|
|
53
|
+
* "identity.spin.com": {
|
|
54
|
+
* "user-345": { ... }
|
|
55
|
+
* }
|
|
45
56
|
* }
|
|
46
57
|
* ```
|
|
47
58
|
*/
|
|
48
|
-
export const
|
|
49
|
-
/**
|
|
50
|
-
* It contains the identity token. Before usint it, we exchange it
|
|
51
|
-
* to get a token that we can use with different applications. The exchanged
|
|
52
|
-
* tokens for the applications are stored under applications.
|
|
53
|
-
*/
|
|
54
|
-
identity: IdentityTokenSchema,
|
|
55
|
-
/**
|
|
56
|
-
* It contains exchanged tokens for the applications the CLI
|
|
57
|
-
* authenticates with. Tokens are scoped under the fqdn of the applications.
|
|
58
|
-
*/
|
|
59
|
-
applications: zod.object({}).catchall(ApplicationTokenSchema),
|
|
60
|
-
}));
|
|
59
|
+
export const SessionsSchema = zod.object({}).catchall(zod.object({}).catchall(SessionSchema));
|
|
61
60
|
/**
|
|
62
61
|
* Confirms that a given identity token structure matches what the schema currently defines.
|
|
63
62
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/private/node/session/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,gCAAgC,CAAA;AAElD,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,IAAI;QAAE,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IACxE,OAAO,IAAI,CAAA;AACb,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;AAEd;;GAEG;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC,MAAM,CAAC;IACrC,WAAW,EAAE,GAAG,CAA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,CAAA;AAEF,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,mBAAmB;IAC7B,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;CAC9D,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAA;AAO7F;;;;GAIG;AACH,MAAM,UAAU,oCAAoC,CAAC,aAAsB;IACzE,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;IAC3D,OAAO,MAAM,CAAC,OAAO,CAAA;AACvB,CAAC","sourcesContent":["import {zod} from '../../../public/node/schema.js'\n\nconst DateSchema = zod.preprocess((arg) => {\n if (typeof arg === 'string' || arg instanceof Date) return new Date(arg)\n return null\n}, zod.date())\n\n/**\n * The schema represents an Identity token.\n */\nconst IdentityTokenSchema = zod.object({\n accessToken: zod.string(),\n refreshToken: zod.string(),\n expiresAt: DateSchema,\n scopes: zod.array(zod.string()),\n userId: zod.string(),\n alias: zod.string().optional(),\n})\n\n/**\n * The schema represents an application token.\n */\nconst ApplicationTokenSchema = zod.object({\n accessToken: zod.string(),\n expiresAt: DateSchema,\n scopes: zod.array(zod.string()),\n storeFqdn: zod.string().optional(),\n})\n\nconst SessionSchema = zod.object({\n identity: IdentityTokenSchema,\n applications: zod.object({}).catchall(ApplicationTokenSchema),\n})\n\n/**\n * This schema represents the format of the session\n * that we cache in the system to avoid unnecessary\n * token exchanges.\n *\n * @example\n * ```\n * {\n * \"accounts.shopify.com\": {\n * \"user-123\": {\n * \"identity\": { ... }, // IdentityTokenSchema\n * \"applications\": {\n * \"mystore.myshopify.com-admin\": { // ApplicationTokenSchema\n * \"accessToken\": \"...\",\n * \"expiresAt\": \"...\",\n * \"scopes\": [\"...\"],\n * },\n * \"partners\": { ... },\n * }\n * },\n * \"8765-4321\": { ... }\n * },\n * \"identity.spin.com\": {\n * \"user-345\": { ... }\n * }\n * }\n * ```\n */\nexport const SessionsSchema = zod.object({}).catchall(zod.object({}).catchall(SessionSchema))\n\nexport type Sessions = zod.infer<typeof SessionsSchema>\nexport type Session = zod.infer<typeof SessionSchema>\nexport type IdentityToken = zod.infer<typeof IdentityTokenSchema>\nexport type ApplicationToken = zod.infer<typeof ApplicationTokenSchema>\n\n/**\n * Confirms that a given identity token structure matches what the schema currently defines.\n *\n * A full re-auth is the expectation if this validation fails.\n */\nexport function validateCachedIdentityTokenStructure(identityToken: unknown) {\n const parsed = IdentityTokenSchema.safeParse(identityToken)\n return parsed.success\n}\n"]}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Sessions } from './schema.js';
|
|
2
2
|
/**
|
|
3
|
-
* Serializes the session as a JSON and stores it
|
|
4
|
-
* If the secure store is not available, the session is stored in the local config.
|
|
3
|
+
* Serializes the session as a JSON and stores it in the system.
|
|
5
4
|
* @param session - the session to store.
|
|
6
5
|
*/
|
|
7
|
-
export declare function store(
|
|
6
|
+
export declare function store(sessions: Sessions): Promise<void>;
|
|
8
7
|
/**
|
|
9
|
-
* Fetches the
|
|
10
|
-
* If the
|
|
11
|
-
*
|
|
12
|
-
* In the future might add some logic for supporting migrating the schema
|
|
13
|
-
* of already-persisted sessions.
|
|
14
|
-
* @returns Returns a promise that resolves with the session if it exists and is valid.
|
|
8
|
+
* Fetches the sessions from the local storage and returns it.
|
|
9
|
+
* If the format of the object is invalid, the method will discard it.
|
|
10
|
+
* @returns Returns a promise that resolves with the sessions object if it exists and is valid.
|
|
15
11
|
*/
|
|
16
|
-
export declare function fetch(): Promise<
|
|
12
|
+
export declare function fetch(): Promise<Sessions | undefined>;
|
|
17
13
|
/**
|
|
18
14
|
* Removes a session from the system.
|
|
19
15
|
*/
|
|
20
16
|
export declare function remove(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets the session alias for a given user ID.
|
|
19
|
+
*
|
|
20
|
+
* @param userId - The user ID of the session to get the alias for.
|
|
21
|
+
* @returns The alias for the session if it exists, otherwise undefined.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSessionAlias(userId: string): Promise<string | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Finds a session by its alias.
|
|
26
|
+
*
|
|
27
|
+
* @param alias - The alias to search for
|
|
28
|
+
* @returns The user ID if found, otherwise undefined
|
|
29
|
+
*/
|
|
30
|
+
export declare function findSessionByAlias(alias: string): Promise<string | undefined>;
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SessionsSchema } from './schema.js';
|
|
2
|
+
import { getSessions, removeCurrentSessionId, removeSessions, setSessions } from '../conf-store.js';
|
|
3
|
+
import { identityFqdn } from '../../../public/node/context/fqdn.js';
|
|
3
4
|
/**
|
|
4
|
-
* Serializes the session as a JSON and stores it
|
|
5
|
-
* If the secure store is not available, the session is stored in the local config.
|
|
5
|
+
* Serializes the session as a JSON and stores it in the system.
|
|
6
6
|
* @param session - the session to store.
|
|
7
7
|
*/
|
|
8
|
-
export async function store(
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
export async function store(sessions) {
|
|
9
|
+
const jsonSessions = JSON.stringify(sessions);
|
|
10
|
+
setSessions(jsonSessions);
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* Fetches the
|
|
14
|
-
* If the
|
|
15
|
-
*
|
|
16
|
-
* In the future might add some logic for supporting migrating the schema
|
|
17
|
-
* of already-persisted sessions.
|
|
18
|
-
* @returns Returns a promise that resolves with the session if it exists and is valid.
|
|
13
|
+
* Fetches the sessions from the local storage and returns it.
|
|
14
|
+
* If the format of the object is invalid, the method will discard it.
|
|
15
|
+
* @returns Returns a promise that resolves with the sessions object if it exists and is valid.
|
|
19
16
|
*/
|
|
20
17
|
export async function fetch() {
|
|
21
|
-
const content =
|
|
18
|
+
const content = getSessions();
|
|
22
19
|
if (!content) {
|
|
23
20
|
return undefined;
|
|
24
21
|
}
|
|
25
22
|
const contentJson = JSON.parse(content);
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
23
|
+
const parsedSessions = await SessionsSchema.safeParseAsync(contentJson);
|
|
24
|
+
if (parsedSessions.success) {
|
|
25
|
+
return parsedSessions.data;
|
|
29
26
|
}
|
|
30
27
|
else {
|
|
31
28
|
await remove();
|
|
@@ -36,6 +33,43 @@ export async function fetch() {
|
|
|
36
33
|
* Removes a session from the system.
|
|
37
34
|
*/
|
|
38
35
|
export async function remove() {
|
|
39
|
-
|
|
36
|
+
removeSessions();
|
|
37
|
+
removeCurrentSessionId();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the session alias for a given user ID.
|
|
41
|
+
*
|
|
42
|
+
* @param userId - The user ID of the session to get the alias for.
|
|
43
|
+
* @returns The alias for the session if it exists, otherwise undefined.
|
|
44
|
+
*/
|
|
45
|
+
export async function getSessionAlias(userId) {
|
|
46
|
+
const sessions = await fetch();
|
|
47
|
+
if (!sessions)
|
|
48
|
+
return undefined;
|
|
49
|
+
const fqdn = await identityFqdn();
|
|
50
|
+
if (!sessions[fqdn] || !sessions[fqdn][userId])
|
|
51
|
+
return undefined;
|
|
52
|
+
return sessions[fqdn][userId].identity.alias;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Finds a session by its alias.
|
|
56
|
+
*
|
|
57
|
+
* @param alias - The alias to search for
|
|
58
|
+
* @returns The user ID if found, otherwise undefined
|
|
59
|
+
*/
|
|
60
|
+
export async function findSessionByAlias(alias) {
|
|
61
|
+
const sessions = await fetch();
|
|
62
|
+
if (!sessions)
|
|
63
|
+
return undefined;
|
|
64
|
+
const fqdn = await identityFqdn();
|
|
65
|
+
const fqdnSessions = sessions[fqdn];
|
|
66
|
+
if (!fqdnSessions)
|
|
67
|
+
return undefined;
|
|
68
|
+
for (const [userId, session] of Object.entries(fqdnSessions)) {
|
|
69
|
+
if (session.identity.alias === alias) {
|
|
70
|
+
return userId;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
40
74
|
}
|
|
41
75
|
//# sourceMappingURL=store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAC,WAAW,EAAE,sBAAsB,EAAE,cAAc,EAAE,WAAW,EAAC,MAAM,kBAAkB,CAAA;AACjG,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AAGjE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,QAAkB;IAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;IAC7C,WAAW,CAAC,YAAY,CAAC,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,MAAM,OAAO,GAAG,WAAW,EAAE,CAAA;IAE7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACvE,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;QAC3B,OAAO,cAAc,CAAC,IAAI,CAAA;IAC5B,CAAC;S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\nimport {getSessions, removeCurrentSessionId, removeSessions, setSessions} from '../conf-store.js'\nimport {identityFqdn} from '../../../public/node/context/fqdn.js'\nimport type {Sessions} from './schema.js'\n\n/**\n * Serializes the session as a JSON and stores it in the system.\n * @param session - the session to store.\n */\nexport async function store(sessions: Sessions) {\n const jsonSessions = JSON.stringify(sessions)\n setSessions(jsonSessions)\n}\n\n/**\n * Fetches the sessions from the local storage and returns it.\n * If the format of the object is invalid, the method will discard it.\n * @returns Returns a promise that resolves with the sessions object if it exists and is valid.\n */\nexport async function fetch(): Promise<Sessions | undefined> {\n const content = getSessions()\n\n if (!content) {\n return undefined\n }\n const contentJson = JSON.parse(content)\n const parsedSessions = await SessionsSchema.safeParseAsync(contentJson)\n if (parsedSessions.success) {\n return parsedSessions.data\n } else {\n await remove()\n return undefined\n }\n}\n\n/**\n * Removes a session from the system.\n */\nexport async function remove() {\n removeSessions()\n removeCurrentSessionId()\n}\n\n/**\n * Gets the session alias for a given user ID.\n *\n * @param userId - The user ID of the session to get the alias for.\n * @returns The alias for the session if it exists, otherwise undefined.\n */\nexport async function getSessionAlias(userId: string): Promise<string | undefined> {\n const sessions = await fetch()\n if (!sessions) return undefined\n\n const fqdn = await identityFqdn()\n if (!sessions[fqdn] || !sessions[fqdn][userId]) return undefined\n return sessions[fqdn][userId].identity.alias\n}\n\n/**\n * Finds a session by its alias.\n *\n * @param alias - The alias to search for\n * @returns The user ID if found, otherwise undefined\n */\nexport async function findSessionByAlias(alias: string): Promise<string | undefined> {\n const sessions = await fetch()\n if (!sessions) return undefined\n\n const fqdn = await identityFqdn()\n const fqdnSessions = sessions[fqdn]\n if (!fqdnSessions) return undefined\n\n for (const [userId, session] of Object.entries(fqdnSessions)) {\n if (session.identity.alias === alias) {\n return userId\n }\n }\n\n return undefined\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Session } from './schema.js';
|
|
2
2
|
import { OAuthApplications } from '../session.js';
|
|
3
3
|
type ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok';
|
|
4
4
|
/**
|
|
@@ -8,10 +8,5 @@ type ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok';
|
|
|
8
8
|
* @param session - current session with identity and application tokens
|
|
9
9
|
* @returns 'ok' if the session is valid, 'needs_full_auth' if we need to re-authenticate, 'needs_refresh' if we need to refresh the session
|
|
10
10
|
*/
|
|
11
|
-
export declare function validateSession(scopes: string[], applications: OAuthApplications, session:
|
|
12
|
-
identity: IdentityToken;
|
|
13
|
-
applications: {
|
|
14
|
-
[x: string]: ApplicationToken;
|
|
15
|
-
};
|
|
16
|
-
}): Promise<ValidationResult>;
|
|
11
|
+
export declare function validateSession(scopes: string[], applications: OAuthApplications, session: Session | undefined): Promise<ValidationResult>;
|
|
17
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/private/node/session/validate.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAA;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/private/node/session/validate.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAA;AAC3C,OAAO,EAA2C,oCAAoC,EAAC,MAAM,aAAa,CAAA;AAC1G,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAC,aAAa,EAAC,MAAM,uCAAuC,CAAA;AAEnE,OAAO,EAAC,WAAW,EAAC,MAAM,gCAAgC,CAAA;AAI1D;;GAEG;AACH,SAAS,cAAc,CAAC,eAAyB,EAAE,QAAuB;IACxE,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAA;IACrC,IAAI,aAAa,EAAE,KAAK,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,KAA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AY,CAAC,QAAQ,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;QACpC,MAAM,SAAS,GAAG,GAAG,YAAY,CAAC,QAAQ,CAAC,SAAS,IAAI,KAAK,EAAE,CAAA;QAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAE,CAAA;QAC9C,gBAAgB,GAAG,gBAAgB,IAAI,cAAc,CAAC,KAAK,CAAC,CAAA;IAC9D,CAAC;IAED,WAAW,CAAC,uCAAuC,gBAAgB,EAAE,CAAC,CAAA;IAEtE,IAAI,CAAC,oCAAoC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5D,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IAED,IAAI,gBAAgB;QAAE,OAAO,eAAe,CAAA;IAE5C,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,cAAc,CAAC,KAAuB;IAC7C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,OAAO,KAAK,CAAC,SAAS,GAAG,eAAe,EAAE,CAAA;AAC5C,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC,6BAA6B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;AAC1F,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport {applicationId} from './identity.js'\nimport {ApplicationToken, IdentityToken, Session, validateCachedIdentityTokenStructure} from './schema.js'\nimport {sessionConstants} from '../constants.js'\nimport {firstPartyDev} from '../../../public/node/context/local.js'\nimport {OAuthApplications} from '../session.js'\nimport {outputDebug} from '../../../public/node/output.js'\n\ntype ValidationResult = 'needs_refresh' | 'needs_full_auth' | 'ok'\n\n/**\n * Validate if an identity token is valid for the requested scopes\n */\nfunction validateScopes(requestedScopes: string[], identity: IdentityToken) {\n const currentScopes = identity.scopes\n if (firstPartyDev() !== currentScopes.includes('employee')) return false\n return requestedScopes.every((scope) => currentScopes.includes(scope))\n}\n\n/**\n * Validate if the current session is valid or we need to refresh/re-authenticate\n * @param scopes - requested scopes to validate\n * @param applications - requested applications\n * @param session - current session with identity and application tokens\n * @returns 'ok' if the session is valid, 'needs_full_auth' if we need to re-authenticate, 'needs_refresh' if we need to refresh the session\n */\nexport async function validateSession(\n scopes: string[],\n applications: OAuthApplications,\n session: Session | undefined,\n): Promise<ValidationResult> {\n if (!session) return 'needs_full_auth'\n const scopesAreValid = validateScopes(scopes, session.identity)\n if (!scopesAreValid) return 'needs_full_auth'\n let tokensAreExpired = isTokenExpired(session.identity)\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n const token = session.applications[appId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n if (applications.appManagementApi) {\n const appId = applicationId('app-management')\n const token = session.applications[appId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n const token = session.applications[appId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = session.applications[realAppId]!\n tokensAreExpired = tokensAreExpired || isTokenExpired(token)\n }\n\n outputDebug(`- Token validation -> It's expired: ${tokensAreExpired}`)\n\n if (!validateCachedIdentityTokenStructure(session.identity)) {\n return 'needs_full_auth'\n }\n\n if (tokensAreExpired) return 'needs_refresh'\n\n return 'ok'\n}\n\nfunction isTokenExpired(token: ApplicationToken): boolean {\n if (!token) return true\n return token.expiresAt < expireThreshold()\n}\n\nfunction expireThreshold(): Date {\n return new Date(Date.now() + sessionConstants.expirationTimeMarginInMinutes * 60 * 1000)\n}\n"]}
|
|
@@ -67,7 +67,7 @@ type AuthMethod = 'partners_token' | 'device_auth' | 'theme_access_token' | 'cus
|
|
|
67
67
|
*
|
|
68
68
|
* This function performs the following steps:
|
|
69
69
|
* 1. Checks for a cached user ID in memory (obtained in the current run).
|
|
70
|
-
* 2. Attempts to fetch it from the
|
|
70
|
+
* 2. Attempts to fetch it from the local storage (from a previous auth session).
|
|
71
71
|
* 3. Checks if a custom token was used (either as a theme password or partners token).
|
|
72
72
|
* 4. If a custom token is present in the environment, generates a UUID and uses it as userId.
|
|
73
73
|
* 5. If after all this we don't have a userId, then reports as 'unknown'.
|
|
@@ -90,16 +90,18 @@ export declare function setLastSeenUserIdAfterAuth(id: string): void;
|
|
|
90
90
|
*/
|
|
91
91
|
export declare function getLastSeenAuthMethod(): Promise<AuthMethod>;
|
|
92
92
|
export declare function setLastSeenAuthMethod(method: AuthMethod): void;
|
|
93
|
+
export interface EnsureAuthenticatedAdditionalOptions {
|
|
94
|
+
noPrompt?: boolean;
|
|
95
|
+
forceRefresh?: boolean;
|
|
96
|
+
forceNewSession?: boolean;
|
|
97
|
+
}
|
|
93
98
|
/**
|
|
94
99
|
* This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
|
|
95
100
|
*
|
|
96
101
|
* @param applications - An object containing the applications we need to be authenticated with.
|
|
97
102
|
* @param _env - Optional environment variables to use.
|
|
98
|
-
* @param
|
|
103
|
+
* @param options - Optional extra options to use.
|
|
99
104
|
* @returns An instance with the access tokens organized by application.
|
|
100
105
|
*/
|
|
101
|
-
export declare function ensureAuthenticated(applications: OAuthApplications, _env?: NodeJS.ProcessEnv, { forceRefresh, noPrompt }?:
|
|
102
|
-
forceRefresh?: boolean;
|
|
103
|
-
noPrompt?: boolean;
|
|
104
|
-
}): Promise<OAuthSession>;
|
|
106
|
+
export declare function ensureAuthenticated(applications: OAuthApplications, _env?: NodeJS.ProcessEnv, { forceRefresh, noPrompt, forceNewSession }?: EnsureAuthenticatedAdditionalOptions): Promise<OAuthSession>;
|
|
105
107
|
export {};
|