@schemavaults/auth-server-sdk 0.36.5 → 0.38.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 +89 -0
- package/dist/api-scopes/errors.d.ts +35 -0
- package/dist/api-scopes/errors.js +35 -0
- package/dist/api-scopes/errors.js.map +1 -0
- package/dist/api-scopes/index.d.ts +6 -0
- package/dist/api-scopes/index.js +6 -0
- package/dist/api-scopes/index.js.map +1 -0
- package/dist/api-scopes/sync-api-server-scopes.d.ts +49 -0
- package/dist/api-scopes/sync-api-server-scopes.js +125 -0
- package/dist/api-scopes/sync-api-server-scopes.js.map +1 -0
- package/dist/api-scopes/sync-scopes-command.d.ts +32 -0
- package/dist/api-scopes/sync-scopes-command.js +185 -0
- package/dist/api-scopes/sync-scopes-command.js.map +1 -0
- package/dist/cli-args.d.ts +10 -0
- package/dist/cli-args.js +30 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.cjs +17803 -28
- package/dist/cli.js +41 -25
- package/dist/cli.js.map +1 -1
- package/dist/decode-jwts-with-key-manager.d.ts +7 -0
- package/dist/decode-jwts-with-key-manager.js +4 -2
- package/dist/decode-jwts-with-key-manager.js.map +1 -1
- package/dist/env/load-env-file.d.ts +14 -0
- package/dist/env/load-env-file.js +75 -0
- package/dist/env/load-env-file.js.map +1 -0
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.d.ts +7 -5
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.js +11 -5
- package/dist/openapi-operations/create-schemavaults-auth-resolvers.js.map +1 -1
- package/dist/route_guards/IRouteGuard.d.ts +1 -0
- package/dist/route_guards/base-route-guard.d.ts +3 -1
- package/dist/route_guards/base-route-guard.js +6 -1
- package/dist/route_guards/base-route-guard.js.map +1 -1
- package/dist/route_guards/init_route_guard_check_options.d.ts +1 -0
- package/dist/route_guards/route-guard-factory.js +2 -0
- package/dist/route_guards/route-guard-factory.js.map +1 -1
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -30,6 +30,95 @@ the auth session routes (`session/{token,whoami,logout}/route.ts`, see below) an
|
|
|
30
30
|
- `--help`, `-h` — Show help.
|
|
31
31
|
- `--version`, `-v` — Show package name and version.
|
|
32
32
|
|
|
33
|
+
## Defining API scopes from code (`sync-scopes`)
|
|
34
|
+
|
|
35
|
+
A resource server can keep its API scopes (the OAuth 2.0 scope values clients ask
|
|
36
|
+
for, e.g. `notes:read`) in code instead of typing them into the auth server console.
|
|
37
|
+
It sends its whole scope list to the auth server
|
|
38
|
+
(`PUT /api/resource-server/apis/{api_server_id}/scopes`), authenticated with the
|
|
39
|
+
same JWKS access key it already holds. The auth server creates the missing scopes and
|
|
40
|
+
updates changed descriptions (and `allow_dynamic_clients`, where an entry gives it)
|
|
41
|
+
in one transaction. **It never deletes a scope**: deleting one drops users' consents
|
|
42
|
+
and the per-app allowances set for it, so scopes the list leaves out are reported as
|
|
43
|
+
`not_in_manifest` and stay a decision for a person in the console. Per-app scope
|
|
44
|
+
allowances, the API server's dynamic-client policy and the dynamic client
|
|
45
|
+
registration setting are not touched either.
|
|
46
|
+
|
|
47
|
+
Write the list as a JSON manifest. Its `$schema` names the JSON Schema every auth
|
|
48
|
+
server serves at `/json-schema/api-server-scopes.json`, so editors (VS Code,
|
|
49
|
+
JetBrains, ...) auto-complete and check it while you type:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"$schema": "https://auth.schemavaults.com/json-schema/api-server-scopes.json",
|
|
54
|
+
"scopes": [
|
|
55
|
+
{ "scope": "notes:read", "description": "Read your notes." },
|
|
56
|
+
{ "scope": "notes:write", "description": "Create, edit and delete your notes.", "allow_dynamic_clients": true }
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- `scope`: one RFC 6749 scope-token (printable ASCII without spaces, `"` or `\`), at
|
|
62
|
+
most 128 characters, never an OpenID Connect scope name (`openid`, `profile`, ...),
|
|
63
|
+
each value listed once. A scope cannot be renamed (define a new one and delete the
|
|
64
|
+
old one in the console).
|
|
65
|
+
- `description`: 1 to 256 characters, shown on the consent screen.
|
|
66
|
+
- `allow_dynamic_clients` (optional): whether dynamically registered clients may be
|
|
67
|
+
granted the scope. Omit it to keep the current value (so a choice made in the
|
|
68
|
+
console stands); a new scope defaults to `true`.
|
|
69
|
+
- At most 100 scopes per API server in total.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
bunx @schemavaults/auth-server-sdk sync-scopes --init # writes ./api-scopes.json
|
|
73
|
+
bunx @schemavaults/auth-server-sdk sync-scopes --manifest ./api-scopes.json --dry-run
|
|
74
|
+
bunx @schemavaults/auth-server-sdk sync-scopes --manifest ./api-scopes.json
|
|
75
|
+
bunx @schemavaults/auth-server-sdk sync-scopes --manifest ./api-scopes.json --check # CI: exit 2 on drift
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Flag | Effect |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `--manifest <path>` | The manifest. Checked locally with the auth server's own schema before anything is sent |
|
|
81
|
+
| `--init` | Writes a starter manifest (to `--manifest`, default `./api-scopes.json`) whose `$schema` is the configured auth server's; never overwrites |
|
|
82
|
+
| `--dry-run` | Prints what would change, writes nothing |
|
|
83
|
+
| `--check` | Dry run that exits 2 when anything would be created or updated |
|
|
84
|
+
| `--env-file <path>` | Loads `SCHEMAVAULTS_API_SERVER_ID`, `SCHEMAVAULTS_AUTH_SERVER_URL`, `SCHEMAVAULTS_AUTH_JWKS_ACCESS_PRIVATE_KEY` and `SCHEMAVAULTS_APP_ENVIRONMENT` from a file first; its values win over the environment's |
|
|
85
|
+
|
|
86
|
+
It prints one line per created (`+`), updated (`~`) and `not_in_manifest` (`!`, a
|
|
87
|
+
warning only) scope. Exit codes: 0 on success, 1 on any error (an invalid manifest,
|
|
88
|
+
missing settings, a refusal), 2 for drift under `--check`. It reads the same settings
|
|
89
|
+
as `createSchemaVaultsAuthResolvers()`.
|
|
90
|
+
|
|
91
|
+
The CLI runs on Node, so it reads JSON manifests only. TypeScript apps can call the
|
|
92
|
+
function from a script instead (`{ [scope]: description }` is accepted as a shorthand
|
|
93
|
+
that keeps every scope's current `allow_dynamic_clients`):
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { syncApiServerScopes, ApiScopeSyncFailedError } from "@schemavaults/auth-server-sdk/api-scopes";
|
|
97
|
+
|
|
98
|
+
const result = await syncApiServerScopes({
|
|
99
|
+
scopes: [
|
|
100
|
+
{ scope: "notes:read", description: "Read your notes." },
|
|
101
|
+
{ scope: "notes:write", description: "Create, edit and delete your notes." },
|
|
102
|
+
],
|
|
103
|
+
dry_run: false,
|
|
104
|
+
// Defaults: SCHEMAVAULTS_API_SERVER_ID, getSchemaVaultsAuthServerUrl(),
|
|
105
|
+
// loadJwksAccessPrivateKey() (SCHEMAVAULTS_AUTH_JWKS_ACCESS_PRIVATE_KEY).
|
|
106
|
+
});
|
|
107
|
+
// result: { api_server_id, dry_run, created, updated (with `previous`), unchanged, not_in_manifest }
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
A list that fails the schema throws `InvalidApiScopeManifestError` without calling the
|
|
111
|
+
auth server; any other answer than 200 throws `ApiScopeSyncFailedError` with its
|
|
112
|
+
`status` and `code` (e.g. `validation_error`, `invalid_assertion`, `too_many_scopes`
|
|
113
|
+
(409), `hardcoded_api_server`). `API_SERVER_SCOPES_JSON_SCHEMA_PATH` is exported for
|
|
114
|
+
tools that build the schema URL from the configured auth server.
|
|
115
|
+
|
|
116
|
+
**Sync before you deploy, once per environment.** No client can be granted a scope
|
|
117
|
+
until it exists, so run the sync before shipping code whose `requiredScopes` name a
|
|
118
|
+
new scope. Each auth server deployment (staging, production) is synced separately with
|
|
119
|
+
the API server's key for that deployment, e.g. `--env-file .env.staging` then
|
|
120
|
+
`--env-file .env.production`. An auth server older than scope sync answers 404.
|
|
121
|
+
|
|
33
122
|
## Auth session routes (refresh token in a first-party HTTP-only cookie)
|
|
34
123
|
|
|
35
124
|
`@schemavaults/auth-server-sdk/auth-session-route` serves the browser SDK's
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** One reason a scope manifest was refused. */
|
|
2
|
+
export interface ApiScopeManifestIssue {
|
|
3
|
+
/** Where in the manifest, e.g. `scopes.1.description`. */
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly message: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The scope manifest failed the shared request schema on this machine; the
|
|
9
|
+
* auth server was not called.
|
|
10
|
+
*/
|
|
11
|
+
export declare class InvalidApiScopeManifestError extends TypeError {
|
|
12
|
+
readonly issues: readonly ApiScopeManifestIssue[];
|
|
13
|
+
constructor(issues: readonly ApiScopeManifestIssue[]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The auth server refused the sync (any answer but 200), or answered with
|
|
17
|
+
* an unexpected body.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ApiScopeSyncFailedError extends Error {
|
|
20
|
+
/** HTTP status of the answer (200 for an unexpected success body). */
|
|
21
|
+
readonly status: number;
|
|
22
|
+
/**
|
|
23
|
+
* The response's machine readable `error` code (e.g. `validation_error`,
|
|
24
|
+
* `invalid_assertion`, `too_many_scopes`), or null when it carried none.
|
|
25
|
+
*/
|
|
26
|
+
readonly code: string | null;
|
|
27
|
+
/** The offending fields of a `validation_error` answer. */
|
|
28
|
+
readonly issues: readonly ApiScopeManifestIssue[];
|
|
29
|
+
constructor(message: string, { status, code, issues, cause, }: {
|
|
30
|
+
status: number;
|
|
31
|
+
code?: string | null;
|
|
32
|
+
issues?: readonly ApiScopeManifestIssue[];
|
|
33
|
+
cause?: unknown;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scope manifest failed the shared request schema on this machine; the
|
|
3
|
+
* auth server was not called.
|
|
4
|
+
*/
|
|
5
|
+
export class InvalidApiScopeManifestError extends TypeError {
|
|
6
|
+
issues;
|
|
7
|
+
constructor(issues) {
|
|
8
|
+
super(`Invalid API scope manifest:\n${issues.map((issue) => ` - ${issue.path || "(manifest)"}: ${issue.message}`).join("\n")}`);
|
|
9
|
+
this.name = "InvalidApiScopeManifestError";
|
|
10
|
+
this.issues = issues;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The auth server refused the sync (any answer but 200), or answered with
|
|
15
|
+
* an unexpected body.
|
|
16
|
+
*/
|
|
17
|
+
export class ApiScopeSyncFailedError extends Error {
|
|
18
|
+
/** HTTP status of the answer (200 for an unexpected success body). */
|
|
19
|
+
status;
|
|
20
|
+
/**
|
|
21
|
+
* The response's machine readable `error` code (e.g. `validation_error`,
|
|
22
|
+
* `invalid_assertion`, `too_many_scopes`), or null when it carried none.
|
|
23
|
+
*/
|
|
24
|
+
code;
|
|
25
|
+
/** The offending fields of a `validation_error` answer. */
|
|
26
|
+
issues;
|
|
27
|
+
constructor(message, { status, code = null, issues = [], cause, }) {
|
|
28
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
29
|
+
this.name = "ApiScopeSyncFailedError";
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.issues = issues;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api-scopes/errors.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,SAAS;IAChD,MAAM,CAAmC;IAElD,YAAY,MAAwC;QAClD,KAAK,CACH,gCAAgC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,CAAC,IAAI,IAAI,YAAY,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC1H,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,sEAAsE;IAC7D,MAAM,CAAS;IACxB;;;OAGG;IACM,IAAI,CAAgB;IAC7B,2DAA2D;IAClD,MAAM,CAAmC;IAElD,YACE,OAAe,EACf,EACE,MAAM,EACN,IAAI,GAAG,IAAI,EACX,MAAM,GAAG,EAAE,EACX,KAAK,GAMN;QAED,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { syncApiServerScopes, syncApiServerScopes as default, parseApiScopeManifestScopes, apiServerScopesSyncPath, } from "./sync-api-server-scopes";
|
|
2
|
+
export type { SyncApiServerScopesOptions } from "./sync-api-server-scopes";
|
|
3
|
+
export { ApiScopeSyncFailedError, InvalidApiScopeManifestError } from "./errors";
|
|
4
|
+
export type { ApiScopeManifestIssue } from "./errors";
|
|
5
|
+
export { API_SERVER_SCOPES_JSON_SCHEMA_PATH, hasApiScopeSyncDrift, } from "@schemavaults/auth-common";
|
|
6
|
+
export type { ApiScopeManifestEntry, ApiScopeManifestEntryInput, ApiServerScopeSyncResult, SyncApiServerScopesRequest, SyncApiServerScopesRequestInput, SyncedApiScope, UpdatedApiScope, } from "@schemavaults/auth-common";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { syncApiServerScopes, syncApiServerScopes as default, parseApiScopeManifestScopes, apiServerScopesSyncPath, } from "./sync-api-server-scopes";
|
|
2
|
+
export { ApiScopeSyncFailedError, InvalidApiScopeManifestError } from "./errors";
|
|
3
|
+
// The manifest JSON Schema every auth server serves (`$schema` of manifest
|
|
4
|
+
// files): `new URL(API_SERVER_SCOPES_JSON_SCHEMA_PATH, auth_server_url)`.
|
|
5
|
+
export { API_SERVER_SCOPES_JSON_SCHEMA_PATH, hasApiScopeSyncDrift, } from "@schemavaults/auth-common";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api-scopes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,IAAI,OAAO,EAC9B,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAGjF,2EAA2E;AAC3E,0EAA0E;AAC1E,OAAO,EACL,kCAAkC,EAClC,oBAAoB,GACrB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ApiServerId } from "@schemavaults/app-definitions";
|
|
2
|
+
import { type ApiScopeManifestEntryInput, type ApiServerScopeSyncResult, type SyncApiServerScopesRequest } from "@schemavaults/auth-common";
|
|
3
|
+
/** Path of the sync endpoint on the auth server. */
|
|
4
|
+
export declare function apiServerScopesSyncPath(api_server_id: ApiServerId): string;
|
|
5
|
+
export interface SyncApiServerScopesOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The API server's whole scope list, or the shorthand
|
|
8
|
+
* `{ [scope]: description }` (which keeps every scope's current
|
|
9
|
+
* `allow_dynamic_clients`).
|
|
10
|
+
*/
|
|
11
|
+
readonly scopes: readonly ApiScopeManifestEntryInput[] | Readonly<Record<string, string>>;
|
|
12
|
+
/** Report what the sync would do without writing anything. */
|
|
13
|
+
readonly dry_run?: boolean;
|
|
14
|
+
/** Default: `SCHEMAVAULTS_API_SERVER_ID`. */
|
|
15
|
+
readonly api_server_id?: ApiServerId;
|
|
16
|
+
/** Default: `getSchemaVaultsAuthServerUrl()` (`SCHEMAVAULTS_AUTH_SERVER_URL` or the app environment's default). */
|
|
17
|
+
readonly auth_server_url?: string;
|
|
18
|
+
/** Default: `loadJwksAccessPrivateKey()` (`SCHEMAVAULTS_AUTH_JWKS_ACCESS_PRIVATE_KEY`). */
|
|
19
|
+
readonly jwks_access_private_key?: CryptoKey;
|
|
20
|
+
/** Override for tests. */
|
|
21
|
+
readonly fetch?: typeof fetch;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validates a manifest's scopes with the schema the auth server checks
|
|
25
|
+
* them with (`syncApiServerScopesRequestSchema`), without calling it.
|
|
26
|
+
*
|
|
27
|
+
* @throws InvalidApiScopeManifestError listing every problem.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseApiScopeManifestScopes(scopes: SyncApiServerScopesOptions["scopes"]): SyncApiServerScopesRequest["scopes"];
|
|
30
|
+
/**
|
|
31
|
+
* Defines the resource server's API scopes on the auth server from code
|
|
32
|
+
* (`PUT /api/resource-server/apis/{api_server_id}/scopes`): the auth server
|
|
33
|
+
* creates the listed scopes that are missing and updates the ones whose
|
|
34
|
+
* description, or `allow_dynamic_clients` when an entry gives it, changed.
|
|
35
|
+
* It never deletes; the scopes it defines that the list leaves out come
|
|
36
|
+
* back as `not_in_manifest`.
|
|
37
|
+
*
|
|
38
|
+
* Authenticates as the API server with a fresh single-use JWKS access
|
|
39
|
+
* assertion. The list is checked locally first, with the same schema the
|
|
40
|
+
* auth server uses. Run it once per environment's auth server (each with
|
|
41
|
+
* that deployment's API server key), before deploying code that requires
|
|
42
|
+
* a new scope: no client can be granted a scope until it exists.
|
|
43
|
+
*
|
|
44
|
+
* @throws InvalidApiScopeManifestError when the list is invalid (nothing is sent).
|
|
45
|
+
* @throws ApiScopeSyncFailedError when the auth server refuses the sync
|
|
46
|
+
* (`status` and `code` say why) or answers with an unexpected body.
|
|
47
|
+
*/
|
|
48
|
+
export declare function syncApiServerScopes(options: SyncApiServerScopesOptions): Promise<ApiServerScopeSyncResult>;
|
|
49
|
+
export default syncApiServerScopes;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createJwksAccessProofToken } from "@schemavaults/jwt";
|
|
2
|
+
import { apiServerIdSchema, } from "@schemavaults/app-definitions";
|
|
3
|
+
import { apiScopeManifestEntries, syncApiServerScopesRequestSchema, syncApiServerScopesResponseSchema, } from "@schemavaults/auth-common";
|
|
4
|
+
import getSchemavaultsApiServerId from "../env/get-schemavaults-api-server-id";
|
|
5
|
+
import getSchemaVaultsAuthServerUrl from "../env/get-schemavaults-auth-server-url";
|
|
6
|
+
import loadJwksAccessPrivateKey from "../env/loadJwksAccessPrivateKey";
|
|
7
|
+
import { ApiScopeSyncFailedError, InvalidApiScopeManifestError, } from "./errors";
|
|
8
|
+
/** Path of the sync endpoint on the auth server. */
|
|
9
|
+
export function apiServerScopesSyncPath(api_server_id) {
|
|
10
|
+
return `/api/resource-server/apis/${encodeURIComponent(api_server_id)}/scopes`;
|
|
11
|
+
}
|
|
12
|
+
function zodIssues(error) {
|
|
13
|
+
return error.issues.map((issue) => ({
|
|
14
|
+
path: issue.path.map(String).join("."),
|
|
15
|
+
message: issue.message,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates a manifest's scopes with the schema the auth server checks
|
|
20
|
+
* them with (`syncApiServerScopesRequestSchema`), without calling it.
|
|
21
|
+
*
|
|
22
|
+
* @throws InvalidApiScopeManifestError listing every problem.
|
|
23
|
+
*/
|
|
24
|
+
export function parseApiScopeManifestScopes(scopes) {
|
|
25
|
+
const parsed = syncApiServerScopesRequestSchema.safeParse({
|
|
26
|
+
scopes: apiScopeManifestEntries(scopes),
|
|
27
|
+
});
|
|
28
|
+
if (!parsed.success) {
|
|
29
|
+
throw new InvalidApiScopeManifestError(zodIssues(parsed.error));
|
|
30
|
+
}
|
|
31
|
+
return parsed.data.scopes;
|
|
32
|
+
}
|
|
33
|
+
function readErrorBody(body) {
|
|
34
|
+
if (typeof body !== "object" || body === null) {
|
|
35
|
+
return { code: null, message: null, issues: [] };
|
|
36
|
+
}
|
|
37
|
+
const record = body;
|
|
38
|
+
const issues = Array.isArray(record.issues)
|
|
39
|
+
? record.issues.flatMap((issue) => {
|
|
40
|
+
if (typeof issue !== "object" || issue === null)
|
|
41
|
+
return [];
|
|
42
|
+
const { path, message } = issue;
|
|
43
|
+
return typeof message === "string"
|
|
44
|
+
? [{ path: typeof path === "string" ? path : "", message }]
|
|
45
|
+
: [];
|
|
46
|
+
})
|
|
47
|
+
: [];
|
|
48
|
+
const error = typeof record.error === "string" ? record.error : null;
|
|
49
|
+
const message = typeof record.message === "string" ? record.message : null;
|
|
50
|
+
// The older resource-server envelope puts its reason text in `error`.
|
|
51
|
+
return message === null
|
|
52
|
+
? { code: null, message: error, issues }
|
|
53
|
+
: { code: error, message, issues };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Defines the resource server's API scopes on the auth server from code
|
|
57
|
+
* (`PUT /api/resource-server/apis/{api_server_id}/scopes`): the auth server
|
|
58
|
+
* creates the listed scopes that are missing and updates the ones whose
|
|
59
|
+
* description, or `allow_dynamic_clients` when an entry gives it, changed.
|
|
60
|
+
* It never deletes; the scopes it defines that the list leaves out come
|
|
61
|
+
* back as `not_in_manifest`.
|
|
62
|
+
*
|
|
63
|
+
* Authenticates as the API server with a fresh single-use JWKS access
|
|
64
|
+
* assertion. The list is checked locally first, with the same schema the
|
|
65
|
+
* auth server uses. Run it once per environment's auth server (each with
|
|
66
|
+
* that deployment's API server key), before deploying code that requires
|
|
67
|
+
* a new scope: no client can be granted a scope until it exists.
|
|
68
|
+
*
|
|
69
|
+
* @throws InvalidApiScopeManifestError when the list is invalid (nothing is sent).
|
|
70
|
+
* @throws ApiScopeSyncFailedError when the auth server refuses the sync
|
|
71
|
+
* (`status` and `code` say why) or answers with an unexpected body.
|
|
72
|
+
*/
|
|
73
|
+
export async function syncApiServerScopes(options) {
|
|
74
|
+
const scopes = parseApiScopeManifestScopes(options.scopes);
|
|
75
|
+
const dry_run = options.dry_run ?? false;
|
|
76
|
+
const api_server_id = options.api_server_id ?? getSchemavaultsApiServerId();
|
|
77
|
+
if (!apiServerIdSchema.safeParse(api_server_id).success) {
|
|
78
|
+
throw new TypeError("Invalid API server ID!");
|
|
79
|
+
}
|
|
80
|
+
const auth_server_url = options.auth_server_url ?? getSchemaVaultsAuthServerUrl();
|
|
81
|
+
const private_key = options.jwks_access_private_key ?? (await loadJwksAccessPrivateKey());
|
|
82
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
83
|
+
const assertion = await createJwksAccessProofToken({
|
|
84
|
+
api_server_id,
|
|
85
|
+
auth_server_url,
|
|
86
|
+
private_key,
|
|
87
|
+
});
|
|
88
|
+
const url = new URL(apiServerScopesSyncPath(api_server_id), auth_server_url);
|
|
89
|
+
if (dry_run) {
|
|
90
|
+
url.searchParams.set("dry_run", "true");
|
|
91
|
+
}
|
|
92
|
+
const response = await fetchImpl(url.toString(), {
|
|
93
|
+
method: "PUT",
|
|
94
|
+
headers: new Headers({
|
|
95
|
+
Authorization: `Bearer ${assertion}`,
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
Accept: "application/json",
|
|
98
|
+
}),
|
|
99
|
+
body: JSON.stringify({ scopes }),
|
|
100
|
+
});
|
|
101
|
+
let body;
|
|
102
|
+
try {
|
|
103
|
+
body = await response.json();
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
body = undefined;
|
|
107
|
+
if (response.ok) {
|
|
108
|
+
throw new ApiScopeSyncFailedError("The auth server answered the scope sync with a body that is not JSON", { status: response.status, cause: e });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (response.status !== 200) {
|
|
112
|
+
const { code, message, issues } = readErrorBody(body);
|
|
113
|
+
const hint = response.status === 404 && code !== "api_server_not_found"
|
|
114
|
+
? " (the auth server may predate scope sync)"
|
|
115
|
+
: "";
|
|
116
|
+
throw new ApiScopeSyncFailedError(`The auth server refused the scope sync (status: ${response.status}${code ? `, error: ${code}` : ""})${hint}${message ? `: ${message}` : ""}`, { status: response.status, code, issues });
|
|
117
|
+
}
|
|
118
|
+
const parsed = syncApiServerScopesResponseSchema.safeParse(body);
|
|
119
|
+
if (!parsed.success || parsed.data.data.api_server_id !== api_server_id) {
|
|
120
|
+
throw new ApiScopeSyncFailedError("Received an unexpected response to the scope sync", { status: response.status, ...(parsed.success ? {} : { cause: parsed.error }) });
|
|
121
|
+
}
|
|
122
|
+
return parsed.data.data;
|
|
123
|
+
}
|
|
124
|
+
export default syncApiServerScopes;
|
|
125
|
+
//# sourceMappingURL=sync-api-server-scopes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-api-server-scopes.js","sourceRoot":"","sources":["../../src/api-scopes/sync-api-server-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,iCAAiC,GAIlC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,0BAA0B,MAAM,sCAAsC,CAAC;AAC9E,OAAO,4BAA4B,MAAM,wCAAwC,CAAC;AAClF,OAAO,wBAAwB,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,uBAAuB,EACvB,4BAA4B,GAE7B,MAAM,UAAU,CAAC;AAElB,oDAAoD;AACpD,MAAM,UAAU,uBAAuB,CAAC,aAA0B;IAChE,OAAO,6BAA6B,kBAAkB,CAAC,aAAa,CAAC,SAAS,CAAC;AACjF,CAAC;AAuBD,SAAS,SAAS,CAAC,KAAiB;IAClC,OAAO,KAAK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AC,MAAM,KAAK,GAAG,IAAI,IAAI,KAAK,sBAAsB;YACxD,CAAC,CAAC,2CAA2C;YAC7C,CAAC,CAAC,EAAE,CAAC;QACT,MAAM,IAAI,uBAAuB,CAC/B,mDAAmD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAC7I,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAC1C,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,iCAAiC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjE,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,KAAK,aAAa,EAAE,CAAC;QACxE,MAAM,IAAI,uBAAuB,CAC/B,mDAAmD,EACnD,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAChF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AAC1B,CAAC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Exit codes of `auth-server-sdk sync-scopes`. */
|
|
2
|
+
export declare const SYNC_SCOPES_EXIT_CODES: {
|
|
3
|
+
/** Synced (or, under `--dry-run` / `--check`, nothing to do). */
|
|
4
|
+
readonly ok: 0;
|
|
5
|
+
/** Any error: bad flags or manifest, missing settings, a refusal. */
|
|
6
|
+
readonly error: 1;
|
|
7
|
+
/** `--check` only: the auth server's scopes differ from the manifest. */
|
|
8
|
+
readonly drift: 2;
|
|
9
|
+
};
|
|
10
|
+
/** The settings `--env-file` loads (the ones `syncApiServerScopes()` reads). */
|
|
11
|
+
export declare const SYNC_SCOPES_ENV_KEYS: readonly ["SCHEMAVAULTS_API_SERVER_ID", "SCHEMAVAULTS_AUTH_SERVER_URL", "SCHEMAVAULTS_AUTH_JWKS_ACCESS_PRIVATE_KEY", "SCHEMAVAULTS_APP_ENVIRONMENT"];
|
|
12
|
+
/** Where `--init` writes when `--manifest` is not given. */
|
|
13
|
+
export declare const DEFAULT_SCOPE_MANIFEST_PATH: "api-scopes.json";
|
|
14
|
+
export declare const SYNC_SCOPES_HELP_TEXT: string;
|
|
15
|
+
export interface SyncScopesCommandIo {
|
|
16
|
+
readonly stdout: (line: string) => void;
|
|
17
|
+
readonly stderr: (line: string) => void;
|
|
18
|
+
/** Directory relative paths resolve against. Default `process.cwd()`. */
|
|
19
|
+
readonly cwd?: string;
|
|
20
|
+
/** Override for tests. */
|
|
21
|
+
readonly fetch?: typeof fetch;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `auth-server-sdk sync-scopes`: reads a JSON scope manifest, checks it with
|
|
25
|
+
* the shared schema and syncs it with {@link syncApiServerScopes}. Prints
|
|
26
|
+
* one line per created, updated and `not_in_manifest` scope (the last only
|
|
27
|
+
* warn).
|
|
28
|
+
*
|
|
29
|
+
* @param args the arguments after the command name.
|
|
30
|
+
* @returns the process exit code ({@link SYNC_SCOPES_EXIT_CODES}).
|
|
31
|
+
*/
|
|
32
|
+
export declare function runSyncScopesCommand(args: readonly string[], io: SyncScopesCommandIo): Promise<number>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { API_SERVER_SCOPES_JSON_SCHEMA_PATH, hasApiScopeSyncDrift, syncApiServerScopesRequestSchema, } from "@schemavaults/auth-common";
|
|
5
|
+
import { readStringFlag } from "../cli-args";
|
|
6
|
+
import getSchemaVaultsAuthServerUrl from "../env/get-schemavaults-auth-server-url";
|
|
7
|
+
import { JWKS_ACCESS_PRIVATE_KEY_ENV_VAR_NAME } from "../env/loadJwksAccessPrivateKey";
|
|
8
|
+
import { loadEnvFile } from "../env/load-env-file";
|
|
9
|
+
import { ApiScopeSyncFailedError, InvalidApiScopeManifestError, } from "./errors";
|
|
10
|
+
import { syncApiServerScopes } from "./sync-api-server-scopes";
|
|
11
|
+
/** Exit codes of `auth-server-sdk sync-scopes`. */
|
|
12
|
+
export const SYNC_SCOPES_EXIT_CODES = {
|
|
13
|
+
/** Synced (or, under `--dry-run` / `--check`, nothing to do). */
|
|
14
|
+
ok: 0,
|
|
15
|
+
/** Any error: bad flags or manifest, missing settings, a refusal. */
|
|
16
|
+
error: 1,
|
|
17
|
+
/** `--check` only: the auth server's scopes differ from the manifest. */
|
|
18
|
+
drift: 2,
|
|
19
|
+
};
|
|
20
|
+
/** The settings `--env-file` loads (the ones `syncApiServerScopes()` reads). */
|
|
21
|
+
export const SYNC_SCOPES_ENV_KEYS = [
|
|
22
|
+
"SCHEMAVAULTS_API_SERVER_ID",
|
|
23
|
+
"SCHEMAVAULTS_AUTH_SERVER_URL",
|
|
24
|
+
JWKS_ACCESS_PRIVATE_KEY_ENV_VAR_NAME,
|
|
25
|
+
// Picks the default auth server URL when SCHEMAVAULTS_AUTH_SERVER_URL is unset.
|
|
26
|
+
"SCHEMAVAULTS_APP_ENVIRONMENT",
|
|
27
|
+
];
|
|
28
|
+
/** Where `--init` writes when `--manifest` is not given. */
|
|
29
|
+
export const DEFAULT_SCOPE_MANIFEST_PATH = "api-scopes.json";
|
|
30
|
+
export const SYNC_SCOPES_HELP_TEXT = ` sync-scopes Define this API server's scopes on the auth server
|
|
31
|
+
from a JSON manifest (never deletes a scope)
|
|
32
|
+
|
|
33
|
+
sync-scopes options:
|
|
34
|
+
--manifest <path> Scope manifest, shaped like
|
|
35
|
+
{ "$schema": "...", "scopes": [...] }
|
|
36
|
+
--init Write a starter manifest (to --manifest, default
|
|
37
|
+
./${DEFAULT_SCOPE_MANIFEST_PATH}) naming the auth server's JSON Schema
|
|
38
|
+
--dry-run Print what would change, write nothing
|
|
39
|
+
--check Dry run that exits 2 when anything would be
|
|
40
|
+
created or updated (for CI)
|
|
41
|
+
--env-file <path> Load SCHEMAVAULTS_API_SERVER_ID,
|
|
42
|
+
SCHEMAVAULTS_AUTH_SERVER_URL,
|
|
43
|
+
${JWKS_ACCESS_PRIVATE_KEY_ENV_VAR_NAME}
|
|
44
|
+
(and SCHEMAVAULTS_APP_ENVIRONMENT) from a file
|
|
45
|
+
first; its values win over the environment's
|
|
46
|
+
`;
|
|
47
|
+
function quote(text) {
|
|
48
|
+
return JSON.stringify(text);
|
|
49
|
+
}
|
|
50
|
+
function printResult(result, auth_server_url, io) {
|
|
51
|
+
const prefix = result.dry_run ? "would " : "";
|
|
52
|
+
for (const scope of result.created) {
|
|
53
|
+
io.stdout(`+ ${prefix}create ${scope.scope} ${quote(scope.description)} (allow_dynamic_clients: ${scope.allow_dynamic_clients})`);
|
|
54
|
+
}
|
|
55
|
+
for (const scope of result.updated) {
|
|
56
|
+
const changes = [];
|
|
57
|
+
if (scope.previous.description !== undefined) {
|
|
58
|
+
changes.push(`description: ${quote(scope.previous.description)} -> ${quote(scope.description)}`);
|
|
59
|
+
}
|
|
60
|
+
if (scope.previous.allow_dynamic_clients !== undefined) {
|
|
61
|
+
changes.push(`allow_dynamic_clients: ${scope.previous.allow_dynamic_clients} -> ${scope.allow_dynamic_clients}`);
|
|
62
|
+
}
|
|
63
|
+
io.stdout(`~ ${prefix}update ${scope.scope} ${changes.join("; ")}`);
|
|
64
|
+
}
|
|
65
|
+
for (const scope of result.not_in_manifest) {
|
|
66
|
+
io.stderr(`! not in manifest ${scope.scope} ${quote(scope.description)} (kept; delete it in the console if it is no longer used)`);
|
|
67
|
+
}
|
|
68
|
+
io.stdout(`${result.dry_run ? "Dry run for" : "Synced"} API server ${result.api_server_id} on ${auth_server_url}: ` +
|
|
69
|
+
`${result.created.length} ${result.dry_run ? "to create" : "created"}, ` +
|
|
70
|
+
`${result.updated.length} ${result.dry_run ? "to update" : "updated"}, ` +
|
|
71
|
+
`${result.unchanged.length} unchanged, ${result.not_in_manifest.length} not in manifest`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The configured auth server URL. Outside an app (e.g. in CI) the app
|
|
75
|
+
* environment it depends on is often unset, so say which settings to add.
|
|
76
|
+
*/
|
|
77
|
+
function resolveAuthServerUrl() {
|
|
78
|
+
try {
|
|
79
|
+
return getSchemaVaultsAuthServerUrl();
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw new Error(`Could not determine the auth server URL (${e instanceof Error ? e.message : String(e)}). ` +
|
|
83
|
+
"Set SCHEMAVAULTS_APP_ENVIRONMENT to development, test, staging or production, and " +
|
|
84
|
+
"SCHEMAVAULTS_AUTH_SERVER_URL unless that environment's default auth server applies (e.g. in the --env-file).", { cause: e });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function starterManifest(auth_server_url) {
|
|
88
|
+
return `${JSON.stringify({
|
|
89
|
+
$schema: new URL(API_SERVER_SCOPES_JSON_SCHEMA_PATH, auth_server_url).toString(),
|
|
90
|
+
scopes: [{ scope: "example:read", description: "Read your example data." }],
|
|
91
|
+
}, null, 2)}\n`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* `auth-server-sdk sync-scopes`: reads a JSON scope manifest, checks it with
|
|
95
|
+
* the shared schema and syncs it with {@link syncApiServerScopes}. Prints
|
|
96
|
+
* one line per created, updated and `not_in_manifest` scope (the last only
|
|
97
|
+
* warn).
|
|
98
|
+
*
|
|
99
|
+
* @param args the arguments after the command name.
|
|
100
|
+
* @returns the process exit code ({@link SYNC_SCOPES_EXIT_CODES}).
|
|
101
|
+
*/
|
|
102
|
+
export async function runSyncScopesCommand(args, io) {
|
|
103
|
+
const cwd = io.cwd ?? process.cwd();
|
|
104
|
+
const manifestFlag = readStringFlag(args, "--manifest");
|
|
105
|
+
const envFileFlag = readStringFlag(args, "--env-file");
|
|
106
|
+
const init = args.includes("--init");
|
|
107
|
+
const check = args.includes("--check");
|
|
108
|
+
const dry_run = check || args.includes("--dry-run");
|
|
109
|
+
if (manifestFlag.present && !manifestFlag.value) {
|
|
110
|
+
io.stderr("Error: --manifest requires a path argument");
|
|
111
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
112
|
+
}
|
|
113
|
+
if (envFileFlag.present && !envFileFlag.value) {
|
|
114
|
+
io.stderr("Error: --env-file requires a path argument");
|
|
115
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
if (envFileFlag.value) {
|
|
119
|
+
await loadEnvFile(resolve(cwd, envFileFlag.value), SYNC_SCOPES_ENV_KEYS);
|
|
120
|
+
}
|
|
121
|
+
if (init) {
|
|
122
|
+
const target = resolve(cwd, manifestFlag.value ?? DEFAULT_SCOPE_MANIFEST_PATH);
|
|
123
|
+
if (existsSync(target)) {
|
|
124
|
+
io.stderr(`Error: ${target} already exists; not overwriting it`);
|
|
125
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
126
|
+
}
|
|
127
|
+
await writeFile(target, starterManifest(resolveAuthServerUrl()), {
|
|
128
|
+
encoding: "utf8",
|
|
129
|
+
flag: "wx",
|
|
130
|
+
});
|
|
131
|
+
io.stdout(`Wrote ${target}. Edit its scopes, then run: auth-server-sdk sync-scopes --manifest <path> --dry-run`);
|
|
132
|
+
return SYNC_SCOPES_EXIT_CODES.ok;
|
|
133
|
+
}
|
|
134
|
+
if (!manifestFlag.value) {
|
|
135
|
+
io.stderr("Error: sync-scopes requires --manifest <path> (or --init to write one)");
|
|
136
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
137
|
+
}
|
|
138
|
+
const manifestPath = resolve(cwd, manifestFlag.value);
|
|
139
|
+
let manifest;
|
|
140
|
+
try {
|
|
141
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
io.stderr(`Error: could not read ${manifestPath} as JSON: ${e instanceof Error ? e.message : String(e)}`);
|
|
145
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
146
|
+
}
|
|
147
|
+
const parsed = syncApiServerScopesRequestSchema.safeParse(manifest);
|
|
148
|
+
if (!parsed.success) {
|
|
149
|
+
io.stderr(`Error: invalid scope manifest ${manifestPath}:`);
|
|
150
|
+
for (const issue of parsed.error.issues) {
|
|
151
|
+
io.stderr(` - ${issue.path.map(String).join(".") || "(manifest)"}: ${issue.message}`);
|
|
152
|
+
}
|
|
153
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
154
|
+
}
|
|
155
|
+
const auth_server_url = resolveAuthServerUrl();
|
|
156
|
+
const result = await syncApiServerScopes({
|
|
157
|
+
scopes: parsed.data.scopes,
|
|
158
|
+
dry_run,
|
|
159
|
+
auth_server_url,
|
|
160
|
+
...(io.fetch ? { fetch: io.fetch } : {}),
|
|
161
|
+
});
|
|
162
|
+
printResult(result, auth_server_url, io);
|
|
163
|
+
if (check && hasApiScopeSyncDrift(result)) {
|
|
164
|
+
io.stderr("Scope drift: the auth server's scopes do not match the manifest. Run sync-scopes without --check to apply it.");
|
|
165
|
+
return SYNC_SCOPES_EXIT_CODES.drift;
|
|
166
|
+
}
|
|
167
|
+
return SYNC_SCOPES_EXIT_CODES.ok;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
if (e instanceof ApiScopeSyncFailedError) {
|
|
171
|
+
io.stderr(`Error: ${e.message}`);
|
|
172
|
+
for (const issue of e.issues) {
|
|
173
|
+
io.stderr(` - ${issue.path || "(request)"}: ${issue.message}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (e instanceof InvalidApiScopeManifestError) {
|
|
177
|
+
io.stderr(`Error: ${e.message}`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
io.stderr(`Error: ${e instanceof Error ? e.message : String(e)}`);
|
|
181
|
+
}
|
|
182
|
+
return SYNC_SCOPES_EXIT_CODES.error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=sync-scopes-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-scopes-command.js","sourceRoot":"","sources":["../../src/api-scopes/sync-scopes-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EACL,kCAAkC,EAClC,oBAAoB,EACpB,gCAAgC,GAEjC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,4BAA4B,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,oCAAoC,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACL,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,mDAAmD;AACnD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,iEAAiE;IACjE,EAAE,EAAE,CAAC;IACL,qEAAqE;IACrE,KAAK,EAAE,CAAC;IACR,yEAAyE;IACzE,KAAK,EAAE,CAAC;CACA,CAAC;AAEX,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,4BAA4B;IAC5B,8BAA8B;IAC9B,oCAAoC;IACpC,gFAAgF;IAChF,8BAA8B;CACtB,CAAC;AAEX,4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IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,YAAY,4BAA4B,EAAE,CAAC;YACrD,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,sBAAsB,CAAC,KAAK,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Reads `<flag> <value>`; `present` with no `value` when the value is missing. */
|
|
2
|
+
export declare function readStringFlag(args: readonly string[], flag: string): {
|
|
3
|
+
present: boolean;
|
|
4
|
+
value: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* The first positional argument (the command), skipping the values of the
|
|
8
|
+
* flags that take one.
|
|
9
|
+
*/
|
|
10
|
+
export declare function findCommand(args: readonly string[], flagsWithValues: readonly string[]): string | undefined;
|
package/dist/cli-args.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Reads `<flag> <value>`; `present` with no `value` when the value is missing. */
|
|
2
|
+
export function readStringFlag(args, flag) {
|
|
3
|
+
const index = args.indexOf(flag);
|
|
4
|
+
if (index === -1) {
|
|
5
|
+
return { present: false, value: undefined };
|
|
6
|
+
}
|
|
7
|
+
const value = args[index + 1];
|
|
8
|
+
return {
|
|
9
|
+
present: true,
|
|
10
|
+
value: value !== undefined && !value.startsWith("-") ? value : undefined,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The first positional argument (the command), skipping the values of the
|
|
15
|
+
* flags that take one.
|
|
16
|
+
*/
|
|
17
|
+
export function findCommand(args, flagsWithValues) {
|
|
18
|
+
for (let index = 0; index < args.length; index++) {
|
|
19
|
+
const arg = args[index];
|
|
20
|
+
if (flagsWithValues.includes(arg)) {
|
|
21
|
+
index++;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (!arg.startsWith("-")) {
|
|
25
|
+
return arg;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=cli-args.js.map
|