@vendure/cloud 0.3.2 → 0.4.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 +6 -1
- package/dist/cli/commands/deployment/build-logs.js +2 -9
- package/dist/cli/commands/deployment/build-logs.js.map +1 -1
- package/dist/cli/commands/deployment/deploy.d.ts.map +1 -1
- package/dist/cli/commands/deployment/deploy.js +34 -64
- package/dist/cli/commands/deployment/deploy.js.map +1 -1
- package/dist/cli/commands/deployment/index.d.ts.map +1 -1
- package/dist/cli/commands/deployment/index.js +52 -27
- package/dist/cli/commands/deployment/index.js.map +1 -1
- package/dist/cli/commands/deployment/log-export.d.ts +13 -0
- package/dist/cli/commands/deployment/log-export.d.ts.map +1 -0
- package/dist/cli/commands/deployment/log-export.js +133 -0
- package/dist/cli/commands/deployment/log-export.js.map +1 -0
- package/dist/cli/commands/deployment/log-query-output.d.ts +13 -0
- package/dist/cli/commands/deployment/log-query-output.d.ts.map +1 -0
- package/dist/cli/commands/deployment/log-query-output.js +106 -0
- package/dist/cli/commands/deployment/log-query-output.js.map +1 -0
- package/dist/cli/commands/deployment/logs.d.ts +1 -0
- package/dist/cli/commands/deployment/logs.d.ts.map +1 -1
- package/dist/cli/commands/deployment/logs.js +347 -69
- package/dist/cli/commands/deployment/logs.js.map +1 -1
- package/dist/cli/commands/deployment/options.d.ts +2 -6
- package/dist/cli/commands/deployment/options.d.ts.map +1 -1
- package/dist/cli/commands/deployment/options.js +21 -9
- package/dist/cli/commands/deployment/options.js.map +1 -1
- package/dist/cli/commands/deployment/plan.d.ts +1 -1
- package/dist/cli/commands/deployment/plan.d.ts.map +1 -1
- package/dist/cli/commands/deployment/plan.js +4 -6
- package/dist/cli/commands/deployment/plan.js.map +1 -1
- package/dist/cli/commands/deployment/recovery.d.ts +9 -0
- package/dist/cli/commands/deployment/recovery.d.ts.map +1 -0
- package/dist/cli/commands/deployment/recovery.js +86 -0
- package/dist/cli/commands/deployment/recovery.js.map +1 -0
- package/dist/cli/commands/deployment/rollback.d.ts.map +1 -1
- package/dist/cli/commands/deployment/rollback.js +8 -3
- package/dist/cli/commands/deployment/rollback.js.map +1 -1
- package/dist/cli/commands/deployment/show.d.ts.map +1 -1
- package/dist/cli/commands/deployment/show.js +16 -5
- package/dist/cli/commands/deployment/show.js.map +1 -1
- package/dist/cli/commands/deployment/source.d.ts +1 -12
- package/dist/cli/commands/deployment/source.d.ts.map +1 -1
- package/dist/cli/commands/deployment/source.js +5 -13
- package/dist/cli/commands/deployment/source.js.map +1 -1
- package/dist/cli/commands/deployment/status.d.ts.map +1 -1
- package/dist/cli/commands/deployment/status.js +22 -20
- package/dist/cli/commands/deployment/status.js.map +1 -1
- package/dist/cli/commands/deployment/teardown.d.ts.map +1 -1
- package/dist/cli/commands/deployment/teardown.js +12 -1
- package/dist/cli/commands/deployment/teardown.js.map +1 -1
- package/dist/cli/commands/identity-context/keys.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/keys.js +6 -5
- package/dist/cli/commands/identity-context/keys.js.map +1 -1
- package/dist/cli/commands/identity-context/login.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/login.js +2 -2
- package/dist/cli/commands/identity-context/login.js.map +1 -1
- package/dist/cli/commands/identity-context/logout.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/logout.js +3 -4
- package/dist/cli/commands/identity-context/logout.js.map +1 -1
- package/dist/cli/commands/identity-context/org-switch.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/org-switch.js +19 -7
- package/dist/cli/commands/identity-context/org-switch.js.map +1 -1
- package/dist/cli/commands/identity-context/use.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/use.js +2 -3
- package/dist/cli/commands/identity-context/use.js.map +1 -1
- package/dist/cli/commands/identity-context/whoami.d.ts.map +1 -1
- package/dist/cli/commands/identity-context/whoami.js +33 -12
- package/dist/cli/commands/identity-context/whoami.js.map +1 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +0 -1
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/project-config/config/desired-state.d.ts +1 -1
- package/dist/cli/commands/project-config/config/desired-state.d.ts.map +1 -1
- package/dist/cli/commands/project-config/config/desired-state.js +4 -3
- package/dist/cli/commands/project-config/config/desired-state.js.map +1 -1
- package/dist/cli/commands/project-config/config/email/domain.d.ts +5 -0
- package/dist/cli/commands/project-config/config/email/domain.d.ts.map +1 -0
- package/dist/cli/commands/project-config/config/email/domain.js +80 -0
- package/dist/cli/commands/project-config/config/email/domain.js.map +1 -0
- package/dist/cli/commands/project-config/config/email/events.d.ts +4 -0
- package/dist/cli/commands/project-config/config/email/events.d.ts.map +1 -0
- package/dist/cli/commands/project-config/config/email/events.js +55 -0
- package/dist/cli/commands/project-config/config/email/events.js.map +1 -0
- package/dist/cli/commands/project-config/config/email/index.d.ts +2 -0
- package/dist/cli/commands/project-config/config/email/index.d.ts.map +1 -0
- package/dist/cli/commands/project-config/config/email/index.js +108 -0
- package/dist/cli/commands/project-config/config/email/index.js.map +1 -0
- package/dist/cli/commands/project-config/config/email/test-sending.d.ts +4 -0
- package/dist/cli/commands/project-config/config/email/test-sending.d.ts.map +1 -0
- package/dist/cli/commands/project-config/config/email/test-sending.js +68 -0
- package/dist/cli/commands/project-config/config/email/test-sending.js.map +1 -0
- package/dist/cli/commands/project-config/config/index.d.ts.map +1 -1
- package/dist/cli/commands/project-config/config/index.js +12 -7
- package/dist/cli/commands/project-config/config/index.js.map +1 -1
- package/dist/cli/commands/project-config/config/runtime.d.ts +2 -1
- package/dist/cli/commands/project-config/config/runtime.d.ts.map +1 -1
- package/dist/cli/commands/project-config/config/runtime.js +43 -29
- package/dist/cli/commands/project-config/config/runtime.js.map +1 -1
- package/dist/cli/commands/project-config/env/index.d.ts.map +1 -1
- package/dist/cli/commands/project-config/env/index.js +8 -2
- package/dist/cli/commands/project-config/env/index.js.map +1 -1
- package/dist/cli/commands/project-config/environment/index.d.ts.map +1 -1
- package/dist/cli/commands/project-config/environment/index.js +15 -1
- package/dist/cli/commands/project-config/environment/index.js.map +1 -1
- package/dist/cli/commands/project-config/environment/regions.d.ts +6 -0
- package/dist/cli/commands/project-config/environment/regions.d.ts.map +1 -0
- package/dist/cli/commands/project-config/environment/regions.js +22 -0
- package/dist/cli/commands/project-config/environment/regions.js.map +1 -0
- package/dist/cli/commands/project-config/init/init.d.ts.map +1 -1
- package/dist/cli/commands/project-config/init/init.js +28 -5
- package/dist/cli/commands/project-config/init/init.js.map +1 -1
- package/dist/cli/commands/project-config/project/list.d.ts.map +1 -1
- package/dist/cli/commands/project-config/project/list.js +8 -1
- package/dist/cli/commands/project-config/project/list.js.map +1 -1
- package/dist/cli/commands/project-config/project/show.d.ts.map +1 -1
- package/dist/cli/commands/project-config/project/show.js +12 -0
- package/dist/cli/commands/project-config/project/show.js.map +1 -1
- package/dist/cli/commands/project-config/project/subscription-state.d.ts +5 -0
- package/dist/cli/commands/project-config/project/subscription-state.d.ts.map +1 -0
- package/dist/cli/commands/project-config/project/subscription-state.js +57 -0
- package/dist/cli/commands/project-config/project/subscription-state.js.map +1 -0
- package/dist/cli/commands/project-config/source/connect.d.ts.map +1 -1
- package/dist/cli/commands/project-config/source/connect.js +5 -5
- package/dist/cli/commands/project-config/source/connect.js.map +1 -1
- package/dist/cli/commands/project-config/source/map.d.ts.map +1 -1
- package/dist/cli/commands/project-config/source/map.js +4 -4
- package/dist/cli/commands/project-config/source/map.js.map +1 -1
- package/dist/cli/commands/project-config/source/status.d.ts.map +1 -1
- package/dist/cli/commands/project-config/source/status.js +71 -17
- package/dist/cli/commands/project-config/source/status.js.map +1 -1
- package/dist/cli/commands/runtime-data/backup.d.ts +1 -0
- package/dist/cli/commands/runtime-data/backup.d.ts.map +1 -1
- package/dist/cli/commands/runtime-data/backup.js +36 -0
- package/dist/cli/commands/runtime-data/backup.js.map +1 -1
- package/dist/cli/commands/runtime-data/index.d.ts +1 -0
- package/dist/cli/commands/runtime-data/index.d.ts.map +1 -1
- package/dist/cli/commands/runtime-data/index.js +26 -4
- package/dist/cli/commands/runtime-data/index.js.map +1 -1
- package/dist/cli/commands/runtime-data/restore.d.ts.map +1 -1
- package/dist/cli/commands/runtime-data/restore.js +33 -5
- package/dist/cli/commands/runtime-data/restore.js.map +1 -1
- package/dist/cli/index.d.ts +13 -3
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +12 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lib/auth.d.ts +21 -2
- package/dist/cli/lib/auth.d.ts.map +1 -1
- package/dist/cli/lib/auth.js +22 -2
- package/dist/cli/lib/auth.js.map +1 -1
- package/dist/cli/lib/commit.d.ts +4 -0
- package/dist/cli/lib/commit.d.ts.map +1 -0
- package/dist/cli/lib/commit.js +22 -0
- package/dist/cli/lib/commit.js.map +1 -0
- package/dist/cli/lib/console-credential.d.ts +55 -0
- package/dist/cli/lib/console-credential.d.ts.map +1 -0
- package/dist/cli/lib/console-credential.js +164 -0
- package/dist/cli/lib/console-credential.js.map +1 -0
- package/dist/cli/lib/console-origins.d.ts +30 -0
- package/dist/cli/lib/console-origins.d.ts.map +1 -0
- package/dist/cli/lib/console-origins.js +87 -0
- package/dist/cli/lib/console-origins.js.map +1 -0
- package/dist/cli/lib/console-pairing.d.ts +15 -0
- package/dist/cli/lib/console-pairing.d.ts.map +1 -0
- package/dist/cli/lib/console-pairing.js +70 -0
- package/dist/cli/lib/console-pairing.js.map +1 -0
- package/dist/cli/lib/console-session-lock.d.ts +39 -0
- package/dist/cli/lib/console-session-lock.d.ts.map +1 -0
- package/dist/cli/lib/console-session-lock.js +235 -0
- package/dist/cli/lib/console-session-lock.js.map +1 -0
- package/dist/cli/lib/console-session.d.ts +47 -0
- package/dist/cli/lib/console-session.d.ts.map +1 -0
- package/dist/cli/lib/console-session.js +235 -0
- package/dist/cli/lib/console-session.js.map +1 -0
- package/dist/cli/lib/contract/backup-schedule-reasons.d.ts +4 -0
- package/dist/cli/lib/contract/backup-schedule-reasons.d.ts.map +1 -0
- package/dist/cli/lib/contract/backup-schedule-reasons.js +17 -0
- package/dist/cli/lib/contract/backup-schedule-reasons.js.map +1 -0
- package/dist/cli/lib/contract/build-settings.d.ts +1 -1
- package/dist/cli/lib/contract/database.d.ts +19 -0
- package/dist/cli/lib/contract/database.d.ts.map +1 -1
- package/dist/cli/lib/contract/database.js.map +1 -1
- package/dist/cli/lib/contract/deployments.d.ts +13 -0
- package/dist/cli/lib/contract/deployments.d.ts.map +1 -1
- package/dist/cli/lib/contract/deployments.js +38 -0
- package/dist/cli/lib/contract/deployments.js.map +1 -1
- package/dist/cli/lib/contract/desired-state.d.ts +3 -5
- package/dist/cli/lib/contract/desired-state.d.ts.map +1 -1
- package/dist/cli/lib/contract/desired-state.js +42 -28
- package/dist/cli/lib/contract/desired-state.js.map +1 -1
- package/dist/cli/lib/contract/foreign-credentials.d.ts +6 -4
- package/dist/cli/lib/contract/foreign-credentials.d.ts.map +1 -1
- package/dist/cli/lib/contract/foreign-credentials.js +7 -5
- package/dist/cli/lib/contract/foreign-credentials.js.map +1 -1
- package/dist/cli/lib/contract/logs.d.ts +120 -0
- package/dist/cli/lib/contract/logs.d.ts.map +1 -1
- package/dist/cli/lib/contract/logs.js +106 -1
- package/dist/cli/lib/contract/logs.js.map +1 -1
- package/dist/cli/lib/contract/managed-email.d.ts +57 -0
- package/dist/cli/lib/contract/managed-email.d.ts.map +1 -0
- package/dist/cli/lib/contract/managed-email.js +21 -0
- package/dist/cli/lib/contract/managed-email.js.map +1 -0
- package/dist/cli/lib/contract/projects.d.ts +6 -0
- package/dist/cli/lib/contract/projects.d.ts.map +1 -1
- package/dist/cli/lib/contract/regions.d.ts +11 -0
- package/dist/cli/lib/contract/regions.d.ts.map +1 -0
- package/dist/cli/lib/contract/regions.js +7 -0
- package/dist/cli/lib/contract/regions.js.map +1 -0
- package/dist/cli/lib/contract/runtime-operations.d.ts +0 -1
- package/dist/cli/lib/contract/runtime-operations.d.ts.map +1 -1
- package/dist/cli/lib/contract/source-disconnect-reasons.d.ts +4 -0
- package/dist/cli/lib/contract/source-disconnect-reasons.d.ts.map +1 -0
- package/dist/cli/lib/contract/source-disconnect-reasons.js +31 -0
- package/dist/cli/lib/contract/source-disconnect-reasons.js.map +1 -0
- package/dist/cli/lib/contract/source-repository.d.ts +1 -1
- package/dist/cli/lib/contract/source-repository.d.ts.map +1 -1
- package/dist/cli/lib/contract/source-repository.js +1 -0
- package/dist/cli/lib/contract/source-repository.js.map +1 -1
- package/dist/cli/lib/errors.d.ts +30 -0
- package/dist/cli/lib/errors.d.ts.map +1 -1
- package/dist/cli/lib/errors.js +46 -0
- package/dist/cli/lib/errors.js.map +1 -1
- package/dist/cli/lib/platform-address.d.ts +3 -0
- package/dist/cli/lib/platform-address.d.ts.map +1 -0
- package/dist/cli/lib/platform-address.js +7 -0
- package/dist/cli/lib/platform-address.js.map +1 -0
- package/dist/cli/lib/resolve.d.ts +1 -0
- package/dist/cli/lib/resolve.d.ts.map +1 -1
- package/dist/cli/lib/resolve.js +26 -3
- package/dist/cli/lib/resolve.js.map +1 -1
- package/dist/cli/lib/terminal-output.d.ts +8 -0
- package/dist/cli/lib/terminal-output.d.ts.map +1 -0
- package/dist/cli/lib/terminal-output.js +52 -0
- package/dist/cli/lib/terminal-output.js.map +1 -0
- package/dist/dev/dashboard-vite-config.d.ts +1 -0
- package/dist/dev/dashboard-vite-config.d.ts.map +1 -1
- package/dist/dev/dashboard-vite-config.js +26 -3
- package/dist/dev/dashboard-vite-config.js.map +1 -1
- package/dist/dev/dev-command.d.ts.map +1 -1
- package/dist/dev/dev-command.js +21 -1
- package/dist/dev/dev-command.js.map +1 -1
- package/dist/dev/dev-migrate.js +2 -0
- package/dist/dev/dev-migrate.js.map +1 -1
- package/dist/dev/dev-server.js +3 -0
- package/dist/dev/dev-server.js.map +1 -1
- package/dist/dev/dev-worker.js +2 -1
- package/dist/dev/dev-worker.js.map +1 -1
- package/dist/local-core.d.ts +2 -0
- package/dist/local-core.d.ts.map +1 -0
- package/dist/local-core.js +15 -0
- package/dist/local-core.js.map +1 -0
- package/dist/local-durable-execution-plugin.d.ts +3 -0
- package/dist/local-durable-execution-plugin.d.ts.map +1 -0
- package/dist/local-durable-execution-plugin.js +33 -0
- package/dist/local-durable-execution-plugin.js.map +1 -0
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +7 -0
- package/dist/local-runtime.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAKlF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AASD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,GAAG,IAAI,CASnF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Reading commits off a branch mapping, for the two command families that show them.
|
|
2
|
+
// The first seven characters, which is how a commit is written everywhere a customer reads one.
|
|
3
|
+
export function shortSha(sha) {
|
|
4
|
+
return sha.slice(0, 7);
|
|
5
|
+
}
|
|
6
|
+
// The commit a mapping wants deployed that no successful trigger has deployed, or null when the
|
|
7
|
+
// mapping is up to date. Anything other than a success on that exact SHA leaves it pending, so a
|
|
8
|
+
// failed or queued trigger still counts.
|
|
9
|
+
//
|
|
10
|
+
// Falsiness rather than `=== null`, because the mapping is a `client.get<T>` cast rather than a
|
|
11
|
+
// parsed value: a control plane that omits the field entirely would otherwise return `undefined`
|
|
12
|
+
// from a function declaring `string | null`, and the caller's own null check would pass it on.
|
|
13
|
+
export function pendingCommitSha(mapping) {
|
|
14
|
+
if (!mapping.desiredCommitSha)
|
|
15
|
+
return null;
|
|
16
|
+
if (mapping.lastTriggerStatus === "SUCCESS" &&
|
|
17
|
+
mapping.lastTriggerCommitSha === mapping.desiredCommitSha) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return mapping.desiredCommitSha;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit.js","sourceRoot":"","sources":["../../../src/cli/lib/commit.ts"],"names":[],"mappings":"AAEA,qFAAqF;AAErF,gGAAgG;AAChG,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,gGAAgG;AAChG,iGAAiG;AACjG,yCAAyC;AACzC,EAAE;AACF,gGAAgG;AAChG,iGAAiG;AACjG,+FAA+F;AAC/F,MAAM,UAAU,gBAAgB,CAAC,OAAmC;IAClE,IAAI,CAAC,OAAO,CAAC,gBAAgB;QAAE,OAAO,IAAI,CAAC;IAC3C,IACE,OAAO,CAAC,iBAAiB,KAAK,SAAS;QACvC,OAAO,CAAC,oBAAoB,KAAK,OAAO,CAAC,gBAAgB,EACzD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,OAAO,CAAC,gBAAgB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface StoredConsoleCredential {
|
|
2
|
+
schemaVersion: 2;
|
|
3
|
+
/** The Console app that issued the session. A session from another Console reads as absent. */
|
|
4
|
+
origin: string;
|
|
5
|
+
/** The Console API that issued both tokens, and the only one a refresh may call. */
|
|
6
|
+
apiOrigin: string;
|
|
7
|
+
accessToken: string;
|
|
8
|
+
/** Absolute expiry of the access token, ISO-8601. */
|
|
9
|
+
expiresAt: string;
|
|
10
|
+
refreshToken?: string;
|
|
11
|
+
}
|
|
12
|
+
/** `~/.vendure`. Not `~/.vendure-cloud`: this credential belongs to Console, not to Cloud. */
|
|
13
|
+
export declare function consoleConfigDir(home?: string): string;
|
|
14
|
+
export declare function consoleCredentialPath(home?: string): string;
|
|
15
|
+
export interface ConsoleCredentialLocation {
|
|
16
|
+
home?: string;
|
|
17
|
+
appOrigin?: string;
|
|
18
|
+
apiOrigin?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The stored credential, or `undefined`.
|
|
22
|
+
*
|
|
23
|
+
* Every failure reads as "no credential": a missing file, an unreadable one, malformed JSON, a
|
|
24
|
+
* schema version this build does not know, a session issued by a different Console, an untrusted
|
|
25
|
+
* origin named by the caller, and a machine whose control plane names no trusted Console. The
|
|
26
|
+
* answer to all of them is the same, which is that this machine has no shared session to reuse, and
|
|
27
|
+
* the caller falls back to the Cloud login it had before. Nothing here throws, including for a
|
|
28
|
+
* caller that names an origin this build does not trust.
|
|
29
|
+
*
|
|
30
|
+
* Expiry is deliberately not checked here. An expired credential may still carry a usable refresh
|
|
31
|
+
* token, so that decision belongs to the caller.
|
|
32
|
+
*
|
|
33
|
+
* A caller that names neither origin gets the Console its control plane pairs with, so the reader
|
|
34
|
+
* exported at the CLI boundary resolves the same Console as the session path (CLO-641).
|
|
35
|
+
*/
|
|
36
|
+
export declare function readConsoleCredential(location?: ConsoleCredentialLocation): StoredConsoleCredential | undefined;
|
|
37
|
+
/** Whether the access token is past its expiry, counting the skew. */
|
|
38
|
+
export declare function isConsoleCredentialExpired(credential: StoredConsoleCredential, now: Date): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Replace the stored credential.
|
|
41
|
+
*
|
|
42
|
+
* Only the refresh path calls this, and only while holding the session lock. Written through a
|
|
43
|
+
* temporary file and a rename, so a reader never sees half a token: a plain write truncates in
|
|
44
|
+
* place, and a crash inside it leaves unparseable JSON where a rotated refresh token used to be.
|
|
45
|
+
*/
|
|
46
|
+
export declare function writeConsoleCredential(credential: StoredConsoleCredential, location?: Pick<ConsoleCredentialLocation, "home">): void;
|
|
47
|
+
/**
|
|
48
|
+
* Remove the stored credential.
|
|
49
|
+
*
|
|
50
|
+
* The one caller is a refresh that Console refused, under the lock, against a refresh token that
|
|
51
|
+
* is still the stored one. Nothing else may reach it: a credential removed on a guess sends a
|
|
52
|
+
* person to the browser to log in over a session that was fine.
|
|
53
|
+
*/
|
|
54
|
+
export declare function discardConsoleCredential(location?: Pick<ConsoleCredentialLocation, "home">): void;
|
|
55
|
+
//# sourceMappingURL=console-credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-credential.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/console-credential.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,CAAC,CAAC;IACjB,+FAA+F;IAC/F,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAQD,8FAA8F;AAC9F,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,MAAkB,GAAG,MAAM,CAEjE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,MAAkB,GAAG,MAAM,CAEtE;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,GAAE,yBAA8B,GACvC,uBAAuB,GAAG,SAAS,CAgCrC;AA+CD,sEAAsE;AACtE,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,uBAAuB,EACnC,GAAG,EAAE,IAAI,GACR,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,uBAAuB,EACnC,QAAQ,GAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAM,GACrD,IAAI,CAgBN;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,GAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAM,GACrD,IAAI,CAWN"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { consoleOrigins } from "./console-origins.js";
|
|
5
|
+
import { pairedConsoleOrigins } from "./console-pairing.js";
|
|
6
|
+
import { logger } from "./logger.js";
|
|
7
|
+
/**
|
|
8
|
+
* Treat a session as expired slightly early, so a token that passes this check and then expires
|
|
9
|
+
* while the request is in flight does not surface as a failure somewhere further down.
|
|
10
|
+
*/
|
|
11
|
+
const EXPIRY_SKEW_MS = 60_000;
|
|
12
|
+
/** `~/.vendure`. Not `~/.vendure-cloud`: this credential belongs to Console, not to Cloud. */
|
|
13
|
+
export function consoleConfigDir(home = homedir()) {
|
|
14
|
+
return join(home, ".vendure");
|
|
15
|
+
}
|
|
16
|
+
export function consoleCredentialPath(home = homedir()) {
|
|
17
|
+
return join(consoleConfigDir(home), "console-credentials.json");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The stored credential, or `undefined`.
|
|
21
|
+
*
|
|
22
|
+
* Every failure reads as "no credential": a missing file, an unreadable one, malformed JSON, a
|
|
23
|
+
* schema version this build does not know, a session issued by a different Console, an untrusted
|
|
24
|
+
* origin named by the caller, and a machine whose control plane names no trusted Console. The
|
|
25
|
+
* answer to all of them is the same, which is that this machine has no shared session to reuse, and
|
|
26
|
+
* the caller falls back to the Cloud login it had before. Nothing here throws, including for a
|
|
27
|
+
* caller that names an origin this build does not trust.
|
|
28
|
+
*
|
|
29
|
+
* Expiry is deliberately not checked here. An expired credential may still carry a usable refresh
|
|
30
|
+
* token, so that decision belongs to the caller.
|
|
31
|
+
*
|
|
32
|
+
* A caller that names neither origin gets the Console its control plane pairs with, so the reader
|
|
33
|
+
* exported at the CLI boundary resolves the same Console as the session path (CLO-641).
|
|
34
|
+
*/
|
|
35
|
+
export function readConsoleCredential(location = {}) {
|
|
36
|
+
const expected = expectedOrigins(location);
|
|
37
|
+
if (!expected) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const { appOrigin, apiOrigin } = expected;
|
|
41
|
+
let raw;
|
|
42
|
+
try {
|
|
43
|
+
raw = readFileSync(consoleCredentialPath(location.home), "utf-8");
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
let value;
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
if (!isStoredConsoleCredential(value)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
// Both halves have to match. A token minted against a local development Console must never be
|
|
59
|
+
// replayed against production, and the app origin alone does not say which API issued it.
|
|
60
|
+
if (!originsMatch(value.origin, appOrigin) || !originsMatch(value.apiOrigin, apiOrigin)) {
|
|
61
|
+
// Named because it is the one case with a usable session on disk behind it.
|
|
62
|
+
logger.debug({ storedApiOrigin: value.apiOrigin, expectedApiOrigin: apiOrigin }, "Ignoring a Console session another Console issued");
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return { ...value, origin: appOrigin, apiOrigin };
|
|
66
|
+
}
|
|
67
|
+
function expectedOrigins(location) {
|
|
68
|
+
if (location.appOrigin === undefined && location.apiOrigin === undefined) {
|
|
69
|
+
return pairedConsoleOrigins();
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return consoleOrigins(location);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
// Same answer as an untrusted `VENDURE_CLOUD_CONSOLE_API_URL`: no Console can be named, so
|
|
76
|
+
// there is no session to read. A raw throw from here would pass the `ConsoleSession*Error`
|
|
77
|
+
// taxonomy that every caller on the refresh path handles.
|
|
78
|
+
logger.debug({ error }, "Untrusted Console origins named by the caller; ignoring the session");
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Compared as origins rather than as strings, so a stored trailing slash or an explicit default
|
|
83
|
+
// port is the same credential. An unparseable stored value is not this file's to repair.
|
|
84
|
+
function originsMatch(stored, expected) {
|
|
85
|
+
try {
|
|
86
|
+
return new URL(stored).origin === expected;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function isStoredConsoleCredential(value) {
|
|
93
|
+
if (!value || typeof value !== "object") {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const candidate = value;
|
|
97
|
+
return (candidate.schemaVersion === 2 &&
|
|
98
|
+
typeof candidate.origin === "string" &&
|
|
99
|
+
!!candidate.origin &&
|
|
100
|
+
typeof candidate.apiOrigin === "string" &&
|
|
101
|
+
!!candidate.apiOrigin &&
|
|
102
|
+
typeof candidate.accessToken === "string" &&
|
|
103
|
+
!!candidate.accessToken &&
|
|
104
|
+
typeof candidate.expiresAt === "string" &&
|
|
105
|
+
!!candidate.expiresAt &&
|
|
106
|
+
(candidate.refreshToken === undefined ||
|
|
107
|
+
(typeof candidate.refreshToken === "string" && !!candidate.refreshToken)));
|
|
108
|
+
}
|
|
109
|
+
/** Whether the access token is past its expiry, counting the skew. */
|
|
110
|
+
export function isConsoleCredentialExpired(credential, now) {
|
|
111
|
+
const expiresAt = Date.parse(credential.expiresAt);
|
|
112
|
+
if (Number.isNaN(expiresAt)) {
|
|
113
|
+
// An expiry this build cannot read is not a session it can vouch for.
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return expiresAt - EXPIRY_SKEW_MS <= now.getTime();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Replace the stored credential.
|
|
120
|
+
*
|
|
121
|
+
* Only the refresh path calls this, and only while holding the session lock. Written through a
|
|
122
|
+
* temporary file and a rename, so a reader never sees half a token: a plain write truncates in
|
|
123
|
+
* place, and a crash inside it leaves unparseable JSON where a rotated refresh token used to be.
|
|
124
|
+
*/
|
|
125
|
+
export function writeConsoleCredential(credential, location = {}) {
|
|
126
|
+
const directory = consoleConfigDir(location.home);
|
|
127
|
+
const destination = consoleCredentialPath(location.home);
|
|
128
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
129
|
+
const temporary = `${destination}.${process.pid}.tmp`;
|
|
130
|
+
try {
|
|
131
|
+
writeFileSync(temporary, `${JSON.stringify(credential, null, 2)}\n`, { mode: 0o600 });
|
|
132
|
+
renameSync(temporary, destination);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
try {
|
|
136
|
+
unlinkSync(temporary);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// The write may have failed before the temporary file existed at all.
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Remove the stored credential.
|
|
146
|
+
*
|
|
147
|
+
* The one caller is a refresh that Console refused, under the lock, against a refresh token that
|
|
148
|
+
* is still the stored one. Nothing else may reach it: a credential removed on a guess sends a
|
|
149
|
+
* person to the browser to log in over a session that was fine.
|
|
150
|
+
*/
|
|
151
|
+
export function discardConsoleCredential(location = {}) {
|
|
152
|
+
const path = consoleCredentialPath(location.home);
|
|
153
|
+
if (!existsSync(path)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
unlinkSync(path);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Another participant removed it first, or it is not ours to remove. Either way the session is
|
|
161
|
+
// gone as far as this process is concerned.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=console-credential.js.map
|
|
@@ -0,0 +1 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D,EAAE;IAEtD,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACzD,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;IACtD,IAAI,CAAC;QACH,aAAa,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACtF,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC;YACH,UAAU,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,sEAAsE;QACxE,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,WAAoD,EAAE;IAEtD,MAAM,IAAI,GAAG,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IACD,IAAI,CAAC;QACH,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,+FAA+F;QAC/F,4CAA4C;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The Console web app. Cloud never opens it; the origin identifies which Console issued a token. */
|
|
2
|
+
export declare const DEFAULT_CONSOLE_APP_ORIGIN = "https://console.vendure.io";
|
|
3
|
+
/** The Console API. Cloud calls its token endpoint to refresh a shared session. */
|
|
4
|
+
export declare const DEFAULT_CONSOLE_API_ORIGIN = "https://api.vendure.io";
|
|
5
|
+
export declare const STAGING_CONSOLE_API_ORIGIN = "https://staging.api.vendure.io";
|
|
6
|
+
export interface ConsoleOrigins {
|
|
7
|
+
appOrigin: string;
|
|
8
|
+
apiOrigin: string;
|
|
9
|
+
}
|
|
10
|
+
/** The two pairs by name, so a caller or a fixture never restates one of the four literals. */
|
|
11
|
+
export declare const DEFAULT_CONSOLE_ORIGINS: ConsoleOrigins;
|
|
12
|
+
export declare const STAGING_CONSOLE_ORIGINS: ConsoleOrigins;
|
|
13
|
+
/** Exported so a caller deciding what a loopback URL pairs with uses this same list. */
|
|
14
|
+
export declare function isLoopback(hostname: string): boolean;
|
|
15
|
+
/** The Console web app origin. Loopback is allowed for local development and tests. */
|
|
16
|
+
export declare function consoleAppOrigin(value?: string): string;
|
|
17
|
+
/** The Console API origin a token request may call. */
|
|
18
|
+
export declare function consoleApiOrigin(value?: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Select a matching app and API pair.
|
|
21
|
+
*
|
|
22
|
+
* Naming one staging origin selects the other, so a developer cannot half-configure themselves
|
|
23
|
+
* onto production. An explicit mixed pair is refused rather than silently corrected, because
|
|
24
|
+
* neither half is more likely to be the mistake.
|
|
25
|
+
*/
|
|
26
|
+
export declare function consoleOrigins(options: {
|
|
27
|
+
appOrigin?: string;
|
|
28
|
+
apiOrigin?: string;
|
|
29
|
+
}): ConsoleOrigins;
|
|
30
|
+
//# sourceMappingURL=console-origins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-origins.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/console-origins.ts"],"names":[],"mappings":"AAeA,qGAAqG;AACrG,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,mFAAmF;AACnF,eAAO,MAAM,0BAA0B,2BAA2B,CAAC;AAGnE,eAAO,MAAM,0BAA0B,mCAAmC,CAAC;AAE3E,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,+FAA+F;AAC/F,eAAO,MAAM,uBAAuB,EAAE,cAGrC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,cAGrC,CAAC;AAKF,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AA0BD,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,MAAmC,GAAG,MAAM,CAEnF;AAED,uDAAuD;AACvD,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,MAAmC,GAAG,MAAM,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,cAAc,CAmBjB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// The Console origins this machine may talk to, and the pairing rule between them.
|
|
2
|
+
//
|
|
3
|
+
// A vendored fork of `test/fixtures/console-auth/upstream/origins.ts` from
|
|
4
|
+
// `vendurehq/vendure-platform@0d09dfd2`, adapted for this repository's quoting and formatting and
|
|
5
|
+
// carrying no Cloud-specific logic. Local to this copy, and to be kept when syncing upstream: the
|
|
6
|
+
// `export` on `STAGING_CONSOLE_API_ORIGIN`, `isLoopback` and the two origin-pair constants, which
|
|
7
|
+
// exist so `console-pairing.ts` and its fixtures name a Console without restating its literals. Both tools have to agree on these origins exactly: the pair is
|
|
8
|
+
// recorded in the credential file, and a disagreement reads as "no credential" on one side and a
|
|
9
|
+
// usable session on the other. `test/cli-console-origins.test.ts` pins the cases upstream's README
|
|
10
|
+
// names.
|
|
11
|
+
//
|
|
12
|
+
// The checks past the host list matter as much as the list. A URL carrying a path, a query, a
|
|
13
|
+
// fragment, or credentials is a URL built to be appended to, and each of those points a request
|
|
14
|
+
// somewhere else while the hostname still reads correctly.
|
|
15
|
+
/** The Console web app. Cloud never opens it; the origin identifies which Console issued a token. */
|
|
16
|
+
export const DEFAULT_CONSOLE_APP_ORIGIN = "https://console.vendure.io";
|
|
17
|
+
/** The Console API. Cloud calls its token endpoint to refresh a shared session. */
|
|
18
|
+
export const DEFAULT_CONSOLE_API_ORIGIN = "https://api.vendure.io";
|
|
19
|
+
const STAGING_CONSOLE_APP_ORIGIN = "https://staging.console.vendure.io";
|
|
20
|
+
export const STAGING_CONSOLE_API_ORIGIN = "https://staging.api.vendure.io";
|
|
21
|
+
/** The two pairs by name, so a caller or a fixture never restates one of the four literals. */
|
|
22
|
+
export const DEFAULT_CONSOLE_ORIGINS = {
|
|
23
|
+
appOrigin: DEFAULT_CONSOLE_APP_ORIGIN,
|
|
24
|
+
apiOrigin: DEFAULT_CONSOLE_API_ORIGIN,
|
|
25
|
+
};
|
|
26
|
+
export const STAGING_CONSOLE_ORIGINS = {
|
|
27
|
+
appOrigin: STAGING_CONSOLE_APP_ORIGIN,
|
|
28
|
+
apiOrigin: STAGING_CONSOLE_API_ORIGIN,
|
|
29
|
+
};
|
|
30
|
+
const TRUSTED_APP_HOSTS = ["console.vendure.io", "staging.console.vendure.io"];
|
|
31
|
+
const TRUSTED_API_HOSTS = ["api.vendure.io", "staging.api.vendure.io"];
|
|
32
|
+
/** Exported so a caller deciding what a loopback URL pairs with uses this same list. */
|
|
33
|
+
export function isLoopback(hostname) {
|
|
34
|
+
return ["localhost", "127.0.0.1", "::1"].includes(hostname) || hostname.endsWith(".localhost");
|
|
35
|
+
}
|
|
36
|
+
function trustedOrigin(value, trustedHosts, subject) {
|
|
37
|
+
let url;
|
|
38
|
+
try {
|
|
39
|
+
url = new URL(value);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new Error(`The ${subject} URL is invalid.`);
|
|
43
|
+
}
|
|
44
|
+
const trustedRemote = trustedHosts.includes(url.hostname);
|
|
45
|
+
const loopback = isLoopback(url.hostname);
|
|
46
|
+
if ((!trustedRemote && !loopback) ||
|
|
47
|
+
(trustedRemote && url.protocol !== "https:") ||
|
|
48
|
+
(loopback && !["http:", "https:"].includes(url.protocol)) ||
|
|
49
|
+
url.username ||
|
|
50
|
+
url.password ||
|
|
51
|
+
url.pathname !== "/" ||
|
|
52
|
+
url.search ||
|
|
53
|
+
url.hash) {
|
|
54
|
+
throw new Error(`The ${subject} URL is not trusted.`);
|
|
55
|
+
}
|
|
56
|
+
return url.origin;
|
|
57
|
+
}
|
|
58
|
+
/** The Console web app origin. Loopback is allowed for local development and tests. */
|
|
59
|
+
export function consoleAppOrigin(value = DEFAULT_CONSOLE_APP_ORIGIN) {
|
|
60
|
+
return trustedOrigin(value, TRUSTED_APP_HOSTS, "Vendure Console");
|
|
61
|
+
}
|
|
62
|
+
/** The Console API origin a token request may call. */
|
|
63
|
+
export function consoleApiOrigin(value = DEFAULT_CONSOLE_API_ORIGIN) {
|
|
64
|
+
return trustedOrigin(value, TRUSTED_API_HOSTS, "Vendure Console API");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Select a matching app and API pair.
|
|
68
|
+
*
|
|
69
|
+
* Naming one staging origin selects the other, so a developer cannot half-configure themselves
|
|
70
|
+
* onto production. An explicit mixed pair is refused rather than silently corrected, because
|
|
71
|
+
* neither half is more likely to be the mistake.
|
|
72
|
+
*/
|
|
73
|
+
export function consoleOrigins(options) {
|
|
74
|
+
const explicitApp = options.appOrigin === undefined ? undefined : consoleAppOrigin(options.appOrigin);
|
|
75
|
+
const apiOrigin = consoleApiOrigin(options.apiOrigin ??
|
|
76
|
+
(explicitApp === STAGING_CONSOLE_APP_ORIGIN ? STAGING_CONSOLE_API_ORIGIN : undefined));
|
|
77
|
+
const appOrigin = explicitApp ??
|
|
78
|
+
(apiOrigin === STAGING_CONSOLE_API_ORIGIN
|
|
79
|
+
? STAGING_CONSOLE_APP_ORIGIN
|
|
80
|
+
: DEFAULT_CONSOLE_APP_ORIGIN);
|
|
81
|
+
if ((appOrigin === DEFAULT_CONSOLE_APP_ORIGIN && apiOrigin === STAGING_CONSOLE_API_ORIGIN) ||
|
|
82
|
+
(appOrigin === STAGING_CONSOLE_APP_ORIGIN && apiOrigin === DEFAULT_CONSOLE_API_ORIGIN)) {
|
|
83
|
+
throw new Error("The Vendure Console app and API origins must belong to the same environment.");
|
|
84
|
+
}
|
|
85
|
+
return { appOrigin, apiOrigin };
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=console-origins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-origins.js","sourceRoot":"","sources":["../../../src/cli/lib/console-origins.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,EAAE;AACF,2EAA2E;AAC3E,kGAAkG;AAClG,kGAAkG;AAClG,kGAAkG;AAClG,+JAA+J;AAC/J,iGAAiG;AACjG,mGAAmG;AACnG,SAAS;AACT,EAAE;AACF,8FAA8F;AAC9F,gGAAgG;AAChG,2DAA2D;AAE3D,qGAAqG;AACrG,MAAM,CAAC,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE,mFAAmF;AACnF,MAAM,CAAC,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AACxE,MAAM,CAAC,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAO3E,+FAA+F;AAC/F,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACrD,SAAS,EAAE,0BAA0B;IACrC,SAAS,EAAE,0BAA0B;CACtC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAmB;IACrD,SAAS,EAAE,0BAA0B;IACrC,SAAS,EAAE,0BAA0B;CACtC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,oBAAoB,EAAE,4BAA4B,CAAC,CAAC;AAC/E,MAAM,iBAAiB,GAAG,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,CA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C,CAAC;AACpE,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,gBAAgB,CAAC,QAAgB,0BAA0B;IACzE,OAAO,aAAa,CAAC,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAG9B;IACC,MAAM,WAAW,GACf,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpF,MAAM,SAAS,GAAG,gBAAgB,CAChC,OAAO,CAAC,SAAS;QACf,CAAC,WAAW,KAAK,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,SAAS,CAAC,CACxF,CAAC;IACF,MAAM,SAAS,GACb,WAAW;QACX,CAAC,SAAS,KAAK,0BAA0B;YACvC,CAAC,CAAC,0BAA0B;YAC5B,CAAC,CAAC,0BAA0B,CAAC,CAAC;IAClC,IACE,CAAC,SAAS,KAAK,0BAA0B,IAAI,SAAS,KAAK,0BAA0B,CAAC;QACtF,CAAC,SAAS,KAAK,0BAA0B,IAAI,SAAS,KAAK,0BAA0B,CAAC,EACtF,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ConsoleOrigins } from "./console-origins.js";
|
|
2
|
+
/**
|
|
3
|
+
* The Console origin pair for the control plane this invocation talks to, or `undefined` when no
|
|
4
|
+
* trusted Console can be named for it.
|
|
5
|
+
*
|
|
6
|
+
* `VENDURE_CLOUD_CONSOLE_API_URL` wins when set. Otherwise the hosted development control plane and
|
|
7
|
+
* any loopback one take the staging Console, and everything else takes production.
|
|
8
|
+
*
|
|
9
|
+
* Loopback takes staging as a default rather than as a configured pairing. `CONSOLE_API_URL` is
|
|
10
|
+
* commented out in `apps/control-plane/.env.example`, so a control plane run from this repository
|
|
11
|
+
* names no Console until someone sets it; staging is the value that example shows, and that control
|
|
12
|
+
* plane cannot pair with production because it runs on the test identity provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function pairedConsoleOrigins(cloudApiUrl?: string): ConsoleOrigins | undefined;
|
|
15
|
+
//# sourceMappingURL=console-pairing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-pairing.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/console-pairing.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,sBAAsB,CAAC;AAkB9B;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,GAAE,MAAoB,GAChC,cAAc,GAAG,SAAS,CAiB5B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { getApiUrl } from "./config.js";
|
|
2
|
+
import { DEFAULT_CONSOLE_ORIGINS, STAGING_CONSOLE_ORIGINS, consoleApiOrigin, consoleOrigins, isLoopback, } from "./console-origins.js";
|
|
3
|
+
import { logger } from "./logger.js";
|
|
4
|
+
// Which Console issued the session a given Cloud control plane accepts.
|
|
5
|
+
//
|
|
6
|
+
// A control plane resolves a Console session against the single Console its own `CONSOLE_API_URL`
|
|
7
|
+
// names, so the credential this machine reads has to be the one that Console wrote. When no Console
|
|
8
|
+
// can be named, there is no shared session and the command uses the Cloud login it used before.
|
|
9
|
+
//
|
|
10
|
+
// A table here rather than a field on `/auth/cli-config`, which already publishes deployment facts
|
|
11
|
+
// to this CLI and could publish this one without drifting. The reason is the call path, not the
|
|
12
|
+
// design: `resolveConsoleSession` is synchronous and runs before every command does any work, so
|
|
13
|
+
// serving this would put a network round trip in front of all of them. Worth revisiting if the
|
|
14
|
+
// table ever drifts.
|
|
15
|
+
const DEVELOPMENT_CLOUD_API_ORIGIN = "https://api.cloud.vendure.dev";
|
|
16
|
+
const CONSOLE_API_URL_ENV_VAR = "VENDURE_CLOUD_CONSOLE_API_URL";
|
|
17
|
+
/**
|
|
18
|
+
* The Console origin pair for the control plane this invocation talks to, or `undefined` when no
|
|
19
|
+
* trusted Console can be named for it.
|
|
20
|
+
*
|
|
21
|
+
* `VENDURE_CLOUD_CONSOLE_API_URL` wins when set. Otherwise the hosted development control plane and
|
|
22
|
+
* any loopback one take the staging Console, and everything else takes production.
|
|
23
|
+
*
|
|
24
|
+
* Loopback takes staging as a default rather than as a configured pairing. `CONSOLE_API_URL` is
|
|
25
|
+
* commented out in `apps/control-plane/.env.example`, so a control plane run from this repository
|
|
26
|
+
* names no Console until someone sets it; staging is the value that example shows, and that control
|
|
27
|
+
* plane cannot pair with production because it runs on the test identity provider.
|
|
28
|
+
*/
|
|
29
|
+
export function pairedConsoleOrigins(cloudApiUrl = getApiUrl()) {
|
|
30
|
+
const configured = process.env[CONSOLE_API_URL_ENV_VAR];
|
|
31
|
+
if (configured) {
|
|
32
|
+
return overrideOrigins(configured);
|
|
33
|
+
}
|
|
34
|
+
let url;
|
|
35
|
+
try {
|
|
36
|
+
url = new URL(cloudApiUrl);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Quiet: the request that uses this URL reports it, with the URL in hand.
|
|
40
|
+
logger.debug({ cloudApiUrl }, "Unreadable control-plane URL; ignoring any shared Console session");
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return pairsWithStaging(url) ? STAGING_CONSOLE_ORIGINS : DEFAULT_CONSOLE_ORIGINS;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The Console named by the variable, or `undefined` with a warning.
|
|
47
|
+
*
|
|
48
|
+
* Warned rather than logged quietly: somebody set this deliberately, and the symptom of ignoring it
|
|
49
|
+
* is the browser login CLO-641 exists to remove.
|
|
50
|
+
*/
|
|
51
|
+
function overrideOrigins(configured) {
|
|
52
|
+
try {
|
|
53
|
+
const apiOrigin = consoleApiOrigin(configured);
|
|
54
|
+
if (isLoopback(new URL(apiOrigin).hostname)) {
|
|
55
|
+
// One variable names one origin, and `consoleOrigins` answers a loopback API origin with a
|
|
56
|
+
// remote app origin, which is a pair no credential can match. A locally run Console has to be
|
|
57
|
+
// named by both of its origins, and there is nowhere here to say the second.
|
|
58
|
+
throw new Error("a loopback Console cannot be named by its API origin alone");
|
|
59
|
+
}
|
|
60
|
+
return consoleOrigins({ apiOrigin });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
logger.warn({ error, VENDURE_CLOUD_CONSOLE_API_URL: configured }, "VENDURE_CLOUD_CONSOLE_API_URL does not name a usable Vendure Console API; ignoring the shared Console session");
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function pairsWithStaging(url) {
|
|
68
|
+
return url.origin === DEVELOPMENT_CLOUD_API_ORIGIN || isLoopback(url.hostname);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=console-pairing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-pairing.js","sourceRoot":"","sources":["../../../src/cli/lib/console-pairing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,wEAAwE;AACxE,EAAE;AACF,kGAAkG;AAClG,oGAAoG;AACpG,gGAAgG;AAChG,EAAE;AACF,mGAAmG;AACnG,gGAAgG;AAChG,iGAAiG;AACjG,+FAA+F;AAC/F,qBAAqB;AAErB,MAAM,4BAA4B,GAAG,+BAA+B,CAAC;AACrE,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBA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}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long a lock file may sit untouched before another participant may take it over.
|
|
3
|
+
*
|
|
4
|
+
* A holder touches its own lock while it works, so this measures a holder that has stopped rather
|
|
5
|
+
* than one that is slow.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONSOLE_SESSION_LOCK_STALE_MS = 30000;
|
|
8
|
+
/**
|
|
9
|
+
* How long to wait for a lock somebody else holds.
|
|
10
|
+
*
|
|
11
|
+
* Never shorter than the stale budget. A waiter that gave up sooner could give up while the holder
|
|
12
|
+
* is dead but not yet stale, and then "I gave up waiting" would stop meaning "the holder is gone".
|
|
13
|
+
*/
|
|
14
|
+
export declare const CONSOLE_SESSION_LOCK_WAIT_MS = 30000;
|
|
15
|
+
/** The lock file, beside the credential it guards. */
|
|
16
|
+
export declare function consoleSessionLockPath(home?: string): string;
|
|
17
|
+
export interface ConsoleSessionLockOptions {
|
|
18
|
+
/** Overrides `os.homedir()`. Tests point this at a temporary directory. */
|
|
19
|
+
home?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The budgets belong to the protocol rather than to a caller. They are open here so a test can
|
|
22
|
+
* drive the stale and give-up paths without waiting half a minute for each one. A `waitMs` below
|
|
23
|
+
* `staleMs` is raised, because the protocol does not allow the shorter of the two.
|
|
24
|
+
*/
|
|
25
|
+
staleMs?: number;
|
|
26
|
+
waitMs?: number;
|
|
27
|
+
pollMs?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Run `work` while holding the Console session lock.
|
|
31
|
+
*
|
|
32
|
+
* Every step that spends a refresh token or rewrites the credential file goes through here,
|
|
33
|
+
* including the ones in the other tool. Guarding only some of the call sites leaves the double
|
|
34
|
+
* spend reachable through the rest.
|
|
35
|
+
*
|
|
36
|
+
* The lock is not reentrant.
|
|
37
|
+
*/
|
|
38
|
+
export declare function withConsoleSessionLock<T>(options: ConsoleSessionLockOptions, work: () => Promise<T>): Promise<T>;
|
|
39
|
+
//# sourceMappingURL=console-session-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-session-lock.d.ts","sourceRoot":"","sources":["../../../src/cli/lib/console-session-lock.ts"],"names":[],"mappings":"AAkCA;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAInD,sDAAsD;AACtD,wBAAgB,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,MAAM,WAAW,yBAAyB;IACxC,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAYD;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,OAAO,EAAE,yBAAyB,EAClC,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CASZ"}
|