@forgecart/cli 2.202610130131.0 → 2.202610130322.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/dist/src/admin-api/admin-api-refusal.error.d.ts +2 -2
- package/dist/src/admin-api/admin-api-refusal.error.js +2 -2
- package/dist/src/admin-api/admin-api.client.d.ts +8 -4
- package/dist/src/admin-api/admin-api.client.js +11 -9
- package/dist/src/admin-api/admin-api.client.js.map +1 -1
- package/dist/src/admin-api/admin-api.result.d.ts +4 -0
- package/dist/src/admin-api/admin-api.result.js +17 -0
- package/dist/src/admin-api/admin-api.result.js.map +1 -1
- package/dist/src/authorization/cli-authorization-flow.d.ts +21 -14
- package/dist/src/authorization/cli-authorization-flow.js +40 -31
- package/dist/src/authorization/cli-authorization-flow.js.map +1 -1
- package/dist/src/authorization/cli-credential-check.d.ts +6 -13
- package/dist/src/authorization/cli-credential-check.js +6 -23
- package/dist/src/authorization/cli-credential-check.js.map +1 -1
- package/dist/src/authorization/cli-credential-step.d.ts +74 -0
- package/dist/src/authorization/cli-credential-step.js +154 -0
- package/dist/src/authorization/cli-credential-step.js.map +1 -0
- package/dist/src/authorization/cli-unauthorized-refusal.d.ts +18 -8
- package/dist/src/authorization/cli-unauthorized-refusal.js +26 -11
- package/dist/src/authorization/cli-unauthorized-refusal.js.map +1 -1
- package/dist/src/authorization/type/cli-authorization.types.d.ts +36 -4
- package/dist/src/authorization/type/cli-authorization.types.js +16 -3
- package/dist/src/authorization/type/cli-authorization.types.js.map +1 -1
- package/dist/src/commands/init.d.ts +0 -10
- package/dist/src/commands/init.js +17 -42
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/sync.js +2 -2
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/deploy/deploy.runner.d.ts +15 -8
- package/dist/src/deploy/deploy.runner.js +19 -10
- package/dist/src/deploy/deploy.runner.js.map +1 -1
- package/dist/src/sync/sync-dotenv.file.d.ts +30 -22
- package/dist/src/sync/sync-dotenv.file.js +49 -54
- package/dist/src/sync/sync-dotenv.file.js.map +1 -1
- package/dist/src/sync/sync-env-channel.d.ts +47 -0
- package/dist/src/sync/sync-env-channel.js +106 -0
- package/dist/src/sync/sync-env-channel.js.map +1 -0
- package/dist/src/sync/sync-env.runner.d.ts +26 -10
- package/dist/src/sync/sync-env.runner.js +73 -40
- package/dist/src/sync/sync-env.runner.js.map +1 -1
- package/dist/src/sync/sync-record.file.d.ts +8 -6
- package/dist/src/sync/sync-record.file.js +18 -5
- package/dist/src/sync/sync-record.file.js.map +1 -1
- package/dist/src/sync/sync-round.d.ts +23 -13
- package/dist/src/sync/sync-round.js +73 -37
- package/dist/src/sync/sync-round.js.map +1 -1
- package/dist/src/sync/sync-watch.d.ts +2 -1
- package/dist/src/sync/sync-watch.js +2 -1
- package/dist/src/sync/sync-watch.js.map +1 -1
- package/dist/src/sync/sync.runner.d.ts +16 -6
- package/dist/src/sync/sync.runner.js +29 -19
- package/dist/src/sync/sync.runner.js.map +1 -1
- package/dist/src/sync/type/sync.types.d.ts +49 -16
- package/dist/src/sync/type/sync.types.js.map +1 -1
- package/dist/src/sync/workspace-sync.client.d.ts +14 -8
- package/dist/src/sync/workspace-sync.client.js +40 -17
- package/dist/src/sync/workspace-sync.client.js.map +1 -1
- package/dist/src/util/dotenv.util.d.ts +19 -5
- package/dist/src/util/dotenv.util.js +42 -5
- package/dist/src/util/dotenv.util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A typed refusal the admin API answered an operation with (#2781, #411): the
|
|
3
3
|
* `ErrorCode` its GraphQL error carries and the variables beside it — what a
|
|
4
|
-
* caller routes on. Credentials the API refuses are no such error: they
|
|
5
|
-
*
|
|
4
|
+
* caller routes on. Credentials the API refuses are no such error: they are a
|
|
5
|
+
* `CliCredentialsRefusal`, which the credential step answers by authorizing.
|
|
6
6
|
*/
|
|
7
7
|
export declare class AdminApiRefusal extends Error {
|
|
8
8
|
readonly endpoint: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A typed refusal the admin API answered an operation with (#2781, #411): the
|
|
3
3
|
* `ErrorCode` its GraphQL error carries and the variables beside it — what a
|
|
4
|
-
* caller routes on. Credentials the API refuses are no such error: they
|
|
5
|
-
*
|
|
4
|
+
* caller routes on. Credentials the API refuses are no such error: they are a
|
|
5
|
+
* `CliCredentialsRefusal`, which the credential step answers by authorizing.
|
|
6
6
|
*/
|
|
7
7
|
export class AdminApiRefusal extends Error {
|
|
8
8
|
endpoint;
|
|
@@ -7,8 +7,9 @@ import type { AdminApiRequest } from './type/admin-api.types.js';
|
|
|
7
7
|
* the one surface `forgecart sync` and `forgecart deploy` reach the shop
|
|
8
8
|
* through. Every request goes to FORGECART_ADMIN_API_URL as given; every
|
|
9
9
|
* exchange is bounded by `--timeout` and ends when the interrupt it is given
|
|
10
|
-
* fires. Credentials the API refuses
|
|
11
|
-
*
|
|
10
|
+
* fires. Credentials the API refuses are a {@link CliCredentialsRefusal}, which
|
|
11
|
+
* the credential step answers by authorizing. Any other refusal is an
|
|
12
|
+
* {@link AdminApiRefusal} carrying its code.
|
|
12
13
|
*/
|
|
13
14
|
export declare class AdminApiClient {
|
|
14
15
|
private readonly credentials;
|
|
@@ -37,8 +38,11 @@ export declare class AdminApiClient {
|
|
|
37
38
|
/** The root field, once the body carries no error. */
|
|
38
39
|
private rootField;
|
|
39
40
|
/**
|
|
40
|
-
* A GraphQL error ends the call
|
|
41
|
-
*
|
|
41
|
+
* A GraphQL error ends the call. Refused credentials end it as a
|
|
42
|
+
* {@link CliCredentialsRefusal}: UNAUTHORIZED, FORBIDDEN, or the
|
|
43
|
+
* INVALID_ADMIN_SECRET and CHANNEL_NOT_FOUND that the shop's middleware
|
|
44
|
+
* answers outside Apollo. Any other code ends it as the typed
|
|
45
|
+
* {@link AdminApiRefusal}.
|
|
42
46
|
*/
|
|
43
47
|
private assertNoErrors;
|
|
44
48
|
private extensionsOf;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CliCredentialsRefusal } from '../authorization/cli-unauthorized-refusal.js';
|
|
2
2
|
import { isJsonObject } from '../json.js';
|
|
3
3
|
import { AdminApiInterruption } from './admin-api-interruption.error.js';
|
|
4
4
|
import { AdminApiRefusal } from './admin-api-refusal.error.js';
|
|
5
5
|
import { AdminApiResult } from './admin-api.result.js';
|
|
6
|
-
/** The codes the admin API refuses an admin operation's credentials with. */
|
|
7
|
-
const CREDENTIAL_REFUSALS = new Set(['UNAUTHORIZED', 'FORBIDDEN']);
|
|
8
6
|
/** Milliseconds in a second — `--timeout` is given in seconds. */
|
|
9
7
|
const MS_PER_SECOND = 1000;
|
|
10
8
|
/**
|
|
@@ -13,8 +11,9 @@ const MS_PER_SECOND = 1000;
|
|
|
13
11
|
* the one surface `forgecart sync` and `forgecart deploy` reach the shop
|
|
14
12
|
* through. Every request goes to FORGECART_ADMIN_API_URL as given; every
|
|
15
13
|
* exchange is bounded by `--timeout` and ends when the interrupt it is given
|
|
16
|
-
* fires. Credentials the API refuses
|
|
17
|
-
*
|
|
14
|
+
* fires. Credentials the API refuses are a {@link CliCredentialsRefusal}, which
|
|
15
|
+
* the credential step answers by authorizing. Any other refusal is an
|
|
16
|
+
* {@link AdminApiRefusal} carrying its code.
|
|
18
17
|
*/
|
|
19
18
|
export class AdminApiClient {
|
|
20
19
|
credentials;
|
|
@@ -114,8 +113,11 @@ export class AdminApiClient {
|
|
|
114
113
|
return AdminApiResult.of(this.endpoint, field, isJsonObject(data) ? data[field] : undefined);
|
|
115
114
|
}
|
|
116
115
|
/**
|
|
117
|
-
* A GraphQL error ends the call
|
|
118
|
-
*
|
|
116
|
+
* A GraphQL error ends the call. Refused credentials end it as a
|
|
117
|
+
* {@link CliCredentialsRefusal}: UNAUTHORIZED, FORBIDDEN, or the
|
|
118
|
+
* INVALID_ADMIN_SECRET and CHANNEL_NOT_FOUND that the shop's middleware
|
|
119
|
+
* answers outside Apollo. Any other code ends it as the typed
|
|
120
|
+
* {@link AdminApiRefusal}.
|
|
119
121
|
*/
|
|
120
122
|
assertNoErrors(errors, field) {
|
|
121
123
|
if (!Array.isArray(errors) || errors.length === 0)
|
|
@@ -123,8 +125,8 @@ export class AdminApiClient {
|
|
|
123
125
|
const first = errors[0];
|
|
124
126
|
const extensions = this.extensionsOf(first);
|
|
125
127
|
const code = typeof extensions.code === 'string' ? extensions.code : undefined;
|
|
126
|
-
if (code !== undefined &&
|
|
127
|
-
throw new
|
|
128
|
+
if (code !== undefined && CliCredentialsRefusal.isRefusalCode(code)) {
|
|
129
|
+
throw new CliCredentialsRefusal(code);
|
|
128
130
|
}
|
|
129
131
|
throw new AdminApiRefusal(this.endpoint, field, code ?? this.messageOf(first), this.errorVariables(extensions.variables));
|
|
130
132
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-api.client.js","sourceRoot":"","sources":["../../../src/admin-api/admin-api.client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"admin-api.client.js","sourceRoot":"","sources":["../../../src/admin-api/admin-api.client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAErF,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,kEAAkE;AAClE,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IAMN;IACA;IANnB;;;OAGG;IACH,YACmB,WAA2B,EAC3B,cAAsB;QADtB,gBAAW,GAAX,WAAW,CAAgB;QAC3B,mBAAc,GAAd,cAAc,CAAQ;IACtC,CA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QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC1D,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,iBAAiB,CAAC,MAAc;QACtC,OAAO,oBAAoB,IAAI,CAAC,QAAQ,kBAAkB,MAAM,CAAC,MAAM,CAAC,8BAA8B,CAAC;IACzG,CAAC;IAED,mGAAmG;IAC3F,aAAa,CAAC,KAAc;QAClC,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/D,IAAI,KAAK,YAAY,KAAK;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC;QACjD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;CACF"}
|
|
@@ -18,6 +18,10 @@ export declare class AdminApiResult {
|
|
|
18
18
|
readText(key: string): string;
|
|
19
19
|
readNullableString(key: string): string | null;
|
|
20
20
|
readStringList(key: string): string[];
|
|
21
|
+
/** A string field that must carry one of the values `accepts` admits. */
|
|
22
|
+
readMember<T extends string>(key: string, accepts: (value: string) => value is T): T;
|
|
23
|
+
/** A list of objects, each read field by field as a result of the same operation. */
|
|
24
|
+
readObjectList(key: string): AdminApiResult[];
|
|
21
25
|
readCount(key: string): number;
|
|
22
26
|
readBoolean(key: string): boolean;
|
|
23
27
|
private unreadable;
|
|
@@ -55,6 +55,23 @@ export class AdminApiResult {
|
|
|
55
55
|
}
|
|
56
56
|
return items;
|
|
57
57
|
}
|
|
58
|
+
/** A string field that must carry one of the values `accepts` admits. */
|
|
59
|
+
readMember(key, accepts) {
|
|
60
|
+
const value = this.readString(key);
|
|
61
|
+
if (!accepts(value))
|
|
62
|
+
throw this.unreadable();
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
/** A list of objects, each read field by field as a result of the same operation. */
|
|
66
|
+
readObjectList(key) {
|
|
67
|
+
const value = this.record[key];
|
|
68
|
+
if (!Array.isArray(value))
|
|
69
|
+
throw this.unreadable();
|
|
70
|
+
const items = value;
|
|
71
|
+
if (!items.every(isJsonObject))
|
|
72
|
+
throw this.unreadable();
|
|
73
|
+
return items.map((item) => new AdminApiResult(this.endpoint, this.field, item));
|
|
74
|
+
}
|
|
58
75
|
readCount(key) {
|
|
59
76
|
const value = this.record[key];
|
|
60
77
|
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-api.result.js","sourceRoot":"","sources":["../../../src/admin-api/admin-api.result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAEN;IACA;IACA;IAHnB,YACmB,QAAgB,EAChB,KAAa,EACb,MAA+B;QAF/B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAyB;IAC/C,CAAC;IAEJ,8DAA8D;IAC9D,MAAM,CAAC,EAAE,CAAC,QAAgB,EAAE,KAAa,EAAE,KAAc;QACvD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;YAAE,MAAM,cAAc,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3E,OAAO,IAAI,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,iEAAiE;IACzD,MAAM,CAAC,UAAU,CAAC,QAAgB,EAAE,KAAa;QACvD,OAAO,IAAI,KAAK,CACd,oBAAoB,QAAQ,eAAe,KAAK,8BAA8B,CAC/E,CAAC;IACJ,CAAC;IAED,2CAA2C;IAC3C,UAAU,CAAC,GAAW;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,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AU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import type { CliAuthorizationClient } from './cli-authorization.client.js';
|
|
2
2
|
import { type CliCredentials } from './type/cli-authorization.types.js';
|
|
3
3
|
/**
|
|
4
|
-
* The browser authorization
|
|
5
|
-
*
|
|
4
|
+
* The browser authorization the credential step runs when a key is in no
|
|
5
|
+
* source or the admin API refuses the credentials (#2772, launch#62 N3;
|
|
6
|
+
* record `refs/design/cli-improvements`, screen `init`).
|
|
6
7
|
*
|
|
7
|
-
* It opens an authorization on the admin API
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* the
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* It opens an authorization on the admin API that names the project's store,
|
|
9
|
+
* then prints the dashboard URL and the user code. Both come BEFORE any
|
|
10
|
+
* browser is attempted, for the reader whose browser never opens. It then
|
|
11
|
+
* opens the browser when a person is at a terminal, and polls at the cadence
|
|
12
|
+
* the request named until the authorization settles or the wait ends: at the
|
|
13
|
+
* window's close, or at `timeoutSec` when that comes first. The wait is quiet
|
|
14
|
+
* (no countdown, no interval, no attempt count), so an approval on the third
|
|
15
|
+
* poll reads exactly as one on the first. The device code is the poll's secret
|
|
16
|
+
* and is never printed.
|
|
15
17
|
*/
|
|
16
18
|
export declare class CliAuthorizationFlow {
|
|
17
19
|
private readonly client;
|
|
18
|
-
|
|
20
|
+
private readonly timeoutSec;
|
|
21
|
+
/**
|
|
22
|
+
* @param client the admin API's authorization operations.
|
|
23
|
+
* @param timeoutSec the longest the wait may last. When absent, the authorization's window bounds it.
|
|
24
|
+
*/
|
|
25
|
+
constructor(client: CliAuthorizationClient, timeoutSec: number | undefined);
|
|
19
26
|
/**
|
|
20
27
|
* Authorize this machine and answer the four credentials the approval
|
|
21
28
|
* delivers. A denial, an expiry or an elapsed wait ends the run on exit 3.
|
|
22
29
|
*
|
|
23
|
-
* @param report the
|
|
24
|
-
* @param
|
|
30
|
+
* @param report why the run authorizes, printed first.
|
|
31
|
+
* @param channelToken the channel token the project's sources name: the store `/authorize` preselects.
|
|
25
32
|
*/
|
|
26
|
-
authorize(report: readonly string[],
|
|
33
|
+
authorize(report: readonly string[], channelToken: string | undefined): Promise<CliCredentials>;
|
|
27
34
|
/** Poll until the authorization settles or the deadline passes. */
|
|
28
35
|
private awaitApproval;
|
|
29
36
|
/** The credentials an APPROVED answer delivers; null while PENDING. DENIED and EXPIRED end the run. */
|
|
@@ -6,50 +6,59 @@ import { readPackageVersion } from '../version.js';
|
|
|
6
6
|
import { CliUnauthorizedReason, CliUnauthorizedRefusal } from './cli-unauthorized-refusal.js';
|
|
7
7
|
import { CliAuthorizationState, } from './type/cli-authorization.types.js';
|
|
8
8
|
/**
|
|
9
|
-
* The browser authorization
|
|
10
|
-
*
|
|
9
|
+
* The browser authorization the credential step runs when a key is in no
|
|
10
|
+
* source or the admin API refuses the credentials (#2772, launch#62 N3;
|
|
11
|
+
* record `refs/design/cli-improvements`, screen `init`).
|
|
11
12
|
*
|
|
12
|
-
* It opens an authorization on the admin API
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* the
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
13
|
+
* It opens an authorization on the admin API that names the project's store,
|
|
14
|
+
* then prints the dashboard URL and the user code. Both come BEFORE any
|
|
15
|
+
* browser is attempted, for the reader whose browser never opens. It then
|
|
16
|
+
* opens the browser when a person is at a terminal, and polls at the cadence
|
|
17
|
+
* the request named until the authorization settles or the wait ends: at the
|
|
18
|
+
* window's close, or at `timeoutSec` when that comes first. The wait is quiet
|
|
19
|
+
* (no countdown, no interval, no attempt count), so an approval on the third
|
|
20
|
+
* poll reads exactly as one on the first. The device code is the poll's secret
|
|
21
|
+
* and is never printed.
|
|
20
22
|
*/
|
|
21
23
|
export class CliAuthorizationFlow {
|
|
22
24
|
client;
|
|
23
|
-
|
|
25
|
+
timeoutSec;
|
|
26
|
+
/**
|
|
27
|
+
* @param client the admin API's authorization operations.
|
|
28
|
+
* @param timeoutSec the longest the wait may last. When absent, the authorization's window bounds it.
|
|
29
|
+
*/
|
|
30
|
+
constructor(client, timeoutSec) {
|
|
24
31
|
this.client = client;
|
|
32
|
+
this.timeoutSec = timeoutSec;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
35
|
* Authorize this machine and answer the four credentials the approval
|
|
28
36
|
* delivers. A denial, an expiry or an elapsed wait ends the run on exit 3.
|
|
29
37
|
*
|
|
30
|
-
* @param report the
|
|
31
|
-
* @param
|
|
38
|
+
* @param report why the run authorizes, printed first.
|
|
39
|
+
* @param channelToken the channel token the project's sources name: the store `/authorize` preselects.
|
|
32
40
|
*/
|
|
33
|
-
async authorize(report,
|
|
41
|
+
async authorize(report, channelToken) {
|
|
34
42
|
for (const line of report)
|
|
35
43
|
print(line);
|
|
36
44
|
const authorization = await this.client.request({
|
|
37
45
|
deviceName: hostname(),
|
|
38
46
|
cliVersion: readPackageVersion(),
|
|
47
|
+
channelToken,
|
|
39
48
|
});
|
|
40
49
|
const interactive = this.isTerminal();
|
|
41
|
-
for (const line of this.handOff(authorization,
|
|
50
|
+
for (const line of this.handOff(authorization, interactive))
|
|
42
51
|
print(line);
|
|
43
52
|
if (interactive)
|
|
44
53
|
this.openBrowser(authorization.verificationUrl);
|
|
45
|
-
const credentials = await this.awaitApproval(authorization
|
|
54
|
+
const credentials = await this.awaitApproval(authorization);
|
|
46
55
|
print('');
|
|
47
56
|
print(' ✓ Authorized');
|
|
48
57
|
return credentials;
|
|
49
58
|
}
|
|
50
59
|
/** Poll until the authorization settles or the deadline passes. */
|
|
51
|
-
async awaitApproval(authorization
|
|
52
|
-
const deadline = this.deadlineOf(authorization
|
|
60
|
+
async awaitApproval(authorization) {
|
|
61
|
+
const deadline = this.deadlineOf(authorization);
|
|
53
62
|
const intervalMs = authorization.pollIntervalSec * 1000;
|
|
54
63
|
for (;;) {
|
|
55
64
|
const remainingMs = deadline.at - Date.now();
|
|
@@ -77,26 +86,26 @@ export class CliAuthorizationFlow {
|
|
|
77
86
|
return status.credentials;
|
|
78
87
|
}
|
|
79
88
|
/** The window's close — or `--timeout` from now, when that comes first. */
|
|
80
|
-
deadlineOf(authorization
|
|
89
|
+
deadlineOf(authorization) {
|
|
81
90
|
const window = {
|
|
82
91
|
at: Date.parse(authorization.expiresAt),
|
|
83
92
|
reason: CliUnauthorizedReason.EXPIRED,
|
|
84
93
|
};
|
|
85
|
-
if (timeoutSec === undefined)
|
|
94
|
+
if (this.timeoutSec === undefined)
|
|
86
95
|
return window;
|
|
87
|
-
const timeoutAt = Date.now() + timeoutSec * 1000;
|
|
96
|
+
const timeoutAt = Date.now() + this.timeoutSec * 1000;
|
|
88
97
|
if (timeoutAt >= window.at)
|
|
89
98
|
return window;
|
|
90
99
|
return { at: timeoutAt, reason: CliUnauthorizedReason.TIMED_OUT };
|
|
91
100
|
}
|
|
92
101
|
/** What the run prints once the authorization is open, for a terminal or for a log. */
|
|
93
|
-
handOff(authorization,
|
|
102
|
+
handOff(authorization, interactive) {
|
|
94
103
|
if (interactive)
|
|
95
|
-
return this.interactiveHandOff(authorization
|
|
96
|
-
return this.headlessHandOff(authorization
|
|
104
|
+
return this.interactiveHandOff(authorization);
|
|
105
|
+
return this.headlessHandOff(authorization);
|
|
97
106
|
}
|
|
98
107
|
/** A person at a terminal: the browser opens, and the comparison is asked for where they stand. */
|
|
99
|
-
interactiveHandOff(authorization
|
|
108
|
+
interactiveHandOff(authorization) {
|
|
100
109
|
return [
|
|
101
110
|
'',
|
|
102
111
|
' This machine is not authorized for any store yet.',
|
|
@@ -109,14 +118,14 @@ export class CliAuthorizationFlow {
|
|
|
109
118
|
'',
|
|
110
119
|
` ${authorization.userCode}`,
|
|
111
120
|
'',
|
|
112
|
-
` ${this.waitingLine(
|
|
121
|
+
` ${this.waitingLine()} · press Ctrl-C to abort`,
|
|
113
122
|
'',
|
|
114
123
|
' Not you? The code is shown in the browser — approve only if it matches',
|
|
115
124
|
` ${authorization.userCode}. Ctrl-C aborts and nothing is written.`,
|
|
116
125
|
];
|
|
117
126
|
}
|
|
118
127
|
/** No terminal: no browser, the URL and the code for whoever reads the log, and the bounded wait. */
|
|
119
|
-
headlessHandOff(authorization
|
|
128
|
+
headlessHandOff(authorization) {
|
|
120
129
|
return [
|
|
121
130
|
'',
|
|
122
131
|
' No TTY — not opening a browser.',
|
|
@@ -131,14 +140,14 @@ export class CliAuthorizationFlow {
|
|
|
131
140
|
'',
|
|
132
141
|
' — or supply the four keys in the environment and re-run.',
|
|
133
142
|
'',
|
|
134
|
-
` ${this.waitingLine(
|
|
143
|
+
` ${this.waitingLine()}`,
|
|
135
144
|
];
|
|
136
145
|
}
|
|
137
146
|
/** The wait, quiet: `--timeout` is the one number it echoes, because the caller passed it. */
|
|
138
|
-
waitingLine(
|
|
139
|
-
if (timeoutSec === undefined)
|
|
147
|
+
waitingLine() {
|
|
148
|
+
if (this.timeoutSec === undefined)
|
|
140
149
|
return 'Waiting for approval…';
|
|
141
|
-
return `Waiting for approval… (--timeout ${String(timeoutSec)}s)`;
|
|
150
|
+
return `Waiting for approval… (--timeout ${String(this.timeoutSec)}s)`;
|
|
142
151
|
}
|
|
143
152
|
/**
|
|
144
153
|
* Best effort by design: over ssh, in a container or on a locked-down laptop
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-authorization-flow.js","sourceRoot":"","sources":["../../../src/authorization/cli-authorization-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,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AC;QAC3E,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;YAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;QAClF,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACK,UAAU;QAChB,MAAM,QAAQ,GAAqB,OAAO,CAAC,KAAK,CAAC;QACjD,MAAM,OAAO,GAAoB,OAAO,CAAC,MAAM,CAAC;QAChD,OAAO,QAAQ,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CliCredentialKey, type CliCredentials } from './type/cli-authorization.types.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* environment, then the target's `.env`, then its
|
|
5
|
-
* (`channelToken`, `apiUrl`)
|
|
6
|
-
* found,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3
|
+
* The credential step's check (#2772, launch#62 N3). It reads each of the four
|
|
4
|
+
* keys from the environment, then the target's `.env`, then its
|
|
5
|
+
* `.forgecart/config.json` (`channelToken`, `apiUrl`), and the first non-empty
|
|
6
|
+
* value wins. With all four found, the step asks nothing. With any absent, it
|
|
7
|
+
* authorizes in the browser, and that run prints the check's {@link report}
|
|
8
|
+
* first.
|
|
9
9
|
*/
|
|
10
10
|
export declare class CliCredentialCheck {
|
|
11
11
|
private readonly environment;
|
|
@@ -14,13 +14,6 @@ export declare class CliCredentialCheck {
|
|
|
14
14
|
private constructor();
|
|
15
15
|
/** Look for the four keys for the storefront at `targetDir`. */
|
|
16
16
|
static read(targetDir: string, env?: NodeJS.ProcessEnv): Promise<CliCredentialCheck>;
|
|
17
|
-
/**
|
|
18
|
-
* The four credentials for the storefront at `targetDir`, for a command that
|
|
19
|
-
* never authorizes (`forgecart sync`, `forgecart deploy`): with one in no
|
|
20
|
-
* source, the check's {@link report} is printed — key names, never values —
|
|
21
|
-
* and the run exits 3 before any request.
|
|
22
|
-
*/
|
|
23
|
-
static settle(targetDir: string): Promise<CliCredentials>;
|
|
24
17
|
/** The value the check found for `key`: the environment's, then `.env`'s, then `config.json`'s. */
|
|
25
18
|
value(key: CliCredentialKey): string | undefined;
|
|
26
19
|
/** All four credentials — undefined while any one is absent. */
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { isJsonObject } from '../json.js';
|
|
4
|
-
import { print } from '../output.js';
|
|
5
|
-
import { CliUnauthorizedReason, CliUnauthorizedRefusal } from './cli-unauthorized-refusal.js';
|
|
6
4
|
import { CliCredentialKey } from './type/cli-authorization.types.js';
|
|
7
5
|
/** The report's source column: `.forgecart/config.json`, and the gutter after it. */
|
|
8
6
|
const SOURCE_COLUMN_WIDTH = 26;
|
|
@@ -16,12 +14,12 @@ const CONFIG_FIELDS = [
|
|
|
16
14
|
[CliCredentialKey.SHOP_API_URL, 'apiUrl'],
|
|
17
15
|
];
|
|
18
16
|
/**
|
|
19
|
-
*
|
|
20
|
-
* environment, then the target's `.env`, then its
|
|
21
|
-
* (`channelToken`, `apiUrl`)
|
|
22
|
-
* found,
|
|
23
|
-
*
|
|
24
|
-
*
|
|
17
|
+
* The credential step's check (#2772, launch#62 N3). It reads each of the four
|
|
18
|
+
* keys from the environment, then the target's `.env`, then its
|
|
19
|
+
* `.forgecart/config.json` (`channelToken`, `apiUrl`), and the first non-empty
|
|
20
|
+
* value wins. With all four found, the step asks nothing. With any absent, it
|
|
21
|
+
* authorizes in the browser, and that run prints the check's {@link report}
|
|
22
|
+
* first.
|
|
25
23
|
*/
|
|
26
24
|
export class CliCredentialCheck {
|
|
27
25
|
environment;
|
|
@@ -42,21 +40,6 @@ export class CliCredentialCheck {
|
|
|
42
40
|
}
|
|
43
41
|
return new CliCredentialCheck(environment, await CliCredentialCheck.readDotenv(join(targetDir, '.env')), await CliCredentialCheck.readConfig(join(targetDir, '.forgecart', 'config.json')));
|
|
44
42
|
}
|
|
45
|
-
/**
|
|
46
|
-
* The four credentials for the storefront at `targetDir`, for a command that
|
|
47
|
-
* never authorizes (`forgecart sync`, `forgecart deploy`): with one in no
|
|
48
|
-
* source, the check's {@link report} is printed — key names, never values —
|
|
49
|
-
* and the run exits 3 before any request.
|
|
50
|
-
*/
|
|
51
|
-
static async settle(targetDir) {
|
|
52
|
-
const check = await CliCredentialCheck.read(targetDir);
|
|
53
|
-
const credentials = check.credentials();
|
|
54
|
-
if (credentials !== undefined)
|
|
55
|
-
return credentials;
|
|
56
|
-
for (const line of check.report())
|
|
57
|
-
print(line);
|
|
58
|
-
throw new CliUnauthorizedRefusal(CliUnauthorizedReason.MISSING);
|
|
59
|
-
}
|
|
60
43
|
/** The value the check found for `key`: the environment's, then `.env`'s, then `config.json`'s. */
|
|
61
44
|
value(key) {
|
|
62
45
|
return this.environment.get(key) ?? this.dotenv?.get(key) ?? this.config?.get(key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-credential-check.js","sourceRoot":"","sources":["../../../src/authorization/cli-credential-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cli-credential-check.js","sourceRoot":"","sources":["../../../src/authorization/cli-credential-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAuB,MAA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;CACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type CliCredentials, type CliCredentialStepInput, type CliSettledCredentials } from './type/cli-authorization.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default shop API base, INCLUDING the mounted path. The API serves the shop
|
|
4
|
+
* GraphQL endpoint at `/shop-api` (`app/forgecart/src/main.ts`), and the SDK
|
|
5
|
+
* takes this value verbatim as its endpoint. The SDK swaps the scheme for the
|
|
6
|
+
* websocket and appends nothing to the path, so a pathless origin scaffolds a
|
|
7
|
+
* storefront whose every read dials a socket nothing answers (#2102): the
|
|
8
|
+
* operation rides graphql-ws's whole retry ladder and the page hangs with
|
|
9
|
+
* nothing logged. `init`'s `--api-url` defaults to it, and the credential step
|
|
10
|
+
* authorizes against its admin API when no source names an API.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_SHOP_API_URL = "https://api.forgecart.com/shop-api";
|
|
13
|
+
/**
|
|
14
|
+
* The ONE credential step (launch#62 N3). Every command that needs the four
|
|
15
|
+
* `FORGECART_*` keys reads them through this step. It looks for each key in
|
|
16
|
+
* the environment, then the storefront's `.env`, then its
|
|
17
|
+
* `.forgecart/config.json`.
|
|
18
|
+
*
|
|
19
|
+
* When a key is in no source, or the admin API refuses the credentials as one
|
|
20
|
+
* of the {@link CliCredentialRefusalCode} codes, the step authorizes this
|
|
21
|
+
* machine at `/authorize` with the project's store preselected. The four keys
|
|
22
|
+
* the approval delivers land in the storefront's `.env` the moment the poll
|
|
23
|
+
* delivers them, so a run that is interrupted afterwards keeps them and its
|
|
24
|
+
* re-run opens no browser. The command then continues on the delivered keys.
|
|
25
|
+
* A denial, an expiry or an elapsed wait exits 3 with
|
|
26
|
+
* FORGECART_CLI_UNAUTHORIZED and writes nothing. The step authorizes at most
|
|
27
|
+
* once per run: if the admin API refuses the credentials an approval has just
|
|
28
|
+
* delivered, the run exits 3 and never 1.
|
|
29
|
+
*/
|
|
30
|
+
export declare class CliCredentialStep {
|
|
31
|
+
private readonly input;
|
|
32
|
+
constructor(input: CliCredentialStepInput);
|
|
33
|
+
/**
|
|
34
|
+
* The four credentials the sources carry. When a key is in no source, the
|
|
35
|
+
* step returns the four an authorization delivers. Use this for a command
|
|
36
|
+
* that sends nothing to the admin API before its own work ends, as `init`
|
|
37
|
+
* does.
|
|
38
|
+
*/
|
|
39
|
+
settle(): Promise<CliSettledCredentials>;
|
|
40
|
+
/**
|
|
41
|
+
* Run `command` on the settled credentials. If the admin API refuses the
|
|
42
|
+
* credentials the sources carried, the step authorizes this machine and runs
|
|
43
|
+
* `command` once more on the delivered keys. A refusal of keys an
|
|
44
|
+
* authorization delivered ends the run on exit 3.
|
|
45
|
+
*/
|
|
46
|
+
run<T>(command: (credentials: CliCredentials) => Promise<T>): Promise<T>;
|
|
47
|
+
private settleFrom;
|
|
48
|
+
/**
|
|
49
|
+
* The command's run on the credentials the sources carry. The admin API
|
|
50
|
+
* refusing those credentials is the one failure that does not end the run:
|
|
51
|
+
* the step answers it by authorizing. Every other error propagates as
|
|
52
|
+
* thrown.
|
|
53
|
+
*/
|
|
54
|
+
private runOnSourced;
|
|
55
|
+
/** Authorize this machine for the project's store, and keep what the approval delivers in `.env` at once. */
|
|
56
|
+
private authorize;
|
|
57
|
+
/** Why a run whose credentials were all found authorizes: the code the admin API refused them with. */
|
|
58
|
+
private refusalReport;
|
|
59
|
+
/**
|
|
60
|
+
* The admin API that answers the authorization. The step uses
|
|
61
|
+
* FORGECART_ADMIN_API_URL when a source names it. Otherwise it uses
|
|
62
|
+
* {@link ADMIN_API_PATH} on the origin of the caller's shop API, else the
|
|
63
|
+
* shop API the sources name, else the platform's.
|
|
64
|
+
*/
|
|
65
|
+
private adminApiUrlOf;
|
|
66
|
+
/**
|
|
67
|
+
* Merge the four delivered keys into the storefront's `.env`. Each key is
|
|
68
|
+
* refreshed in place, and every other line is kept verbatim. The step
|
|
69
|
+
* creates the storefront directory if it does not exist yet.
|
|
70
|
+
*/
|
|
71
|
+
private writeDotenv;
|
|
72
|
+
/** Read a file that may legitimately not exist yet. Any other failure propagates. */
|
|
73
|
+
private readIfPresent;
|
|
74
|
+
}
|