@tailor-platform/sdk 0.16.3 → 0.17.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/CHANGELOG.md +17 -0
- package/README.md +75 -8
- package/dist/cli/api.d.mts +5 -1
- package/dist/cli/api.mjs +1 -1
- package/dist/cli/index.mjs +51 -75
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{resume-kyHIaNvK.mjs → resume-B2ba5opn.mjs} +141 -103
- package/dist/{resume-kyHIaNvK.mjs.map → resume-B2ba5opn.mjs.map} +1 -1
- package/dist/utils/test/index.d.mts +8 -2
- package/dist/utils/test/index.mjs +8 -6
- package/dist/utils/test/index.mjs.map +1 -1
- package/docs/cli/application.md +136 -0
- package/docs/cli/auth.md +110 -0
- package/docs/cli/secret.md +125 -0
- package/docs/cli/user.md +183 -0
- package/docs/cli/workflow.md +144 -0
- package/docs/cli/workspace.md +122 -0
- package/docs/cli-reference.md +80 -801
- package/docs/configuration.md +36 -32
- package/docs/generator/builtin.md +194 -0
- package/docs/generator/custom.md +150 -0
- package/docs/generator/index.md +56 -0
- package/docs/quickstart.md +9 -4
- package/docs/services/auth.md +225 -0
- package/docs/services/executor.md +304 -0
- package/docs/services/idp.md +106 -0
- package/docs/services/resolver.md +213 -0
- package/docs/services/secret.md +116 -0
- package/docs/services/staticwebsite.md +132 -0
- package/docs/services/tailordb.md +305 -0
- package/docs/services/workflow.md +176 -0
- package/docs/testing.md +3 -1
- package/package.json +4 -3
- package/docs/core-concepts.md +0 -609
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @tailor-platform/sdk
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#158](https://github.com/tailor-platform/sdk/pull/158) [`cde0a0a`](https://github.com/tailor-platform/sdk/commit/cde0a0a3e1d517e8036f799ce2a0b8958f7e18c4) Thanks [@riku99](https://github.com/riku99)! - CLI changes:
|
|
8
|
+
- Replace `--format` with `--json` for all list/detail commands. `--format` is no longer supported.
|
|
9
|
+
- Change default table layout for list output and humanize `createdAt` / `updatedAt` in table format (JSON remains ISO strings).
|
|
10
|
+
- `workspace list`: hide `updatedAt` in table output and add `--limit=<number>` to cap the number of workspaces shown.
|
|
11
|
+
|
|
12
|
+
**Breaking:** Scripts or tooling that relied on `--format` or the previous table layout may need to be updated.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#197](https://github.com/tailor-platform/sdk/pull/197) [`6c141f0`](https://github.com/tailor-platform/sdk/commit/6c141f0cf23d360f531dec2a39330b3fa755f7e1) Thanks [@toiroakr](https://github.com/toiroakr)! - Fix `tailordb truncate` command argument parsing: `-n` alias now works correctly and multiple type names can be specified as space-separated arguments
|
|
17
|
+
|
|
18
|
+
- [#191](https://github.com/tailor-platform/sdk/pull/191) [`92f0e99`](https://github.com/tailor-platform/sdk/commit/92f0e99f0bbcdd4616b56157cd2b67a71757fb05) Thanks [@toiroakr](https://github.com/toiroakr)! - fix: createTailorDBHook for Date
|
|
19
|
+
|
|
3
20
|
## 0.16.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,13 +1,80 @@
|
|
|
1
1
|
# Tailor Platform SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@tailor-platform/sdk` is a TypeScript SDK for building applications on the [Tailor Platform](https://docs.tailor.tech/).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Tailor Platform is a headless business platform that provides backend services for building enterprise applications. The SDK enables you to:
|
|
8
8
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
9
|
+
- Define type-safe database schemas with TailorDB
|
|
10
|
+
- Create custom GraphQL resolvers with business logic
|
|
11
|
+
- Set up event-driven executors for automation
|
|
12
|
+
- Orchestrate complex workflows with multiple jobs
|
|
13
|
+
- Configure authentication and authorization
|
|
14
|
+
|
|
15
|
+
All configurations are written in TypeScript, providing full type safety.
|
|
16
|
+
|
|
17
|
+
### Important Notes
|
|
18
|
+
|
|
19
|
+
Some SDK concepts differ from the native Tailor Platform. Be aware of these differences when referring to the official Tailor Platform documentation.
|
|
20
|
+
|
|
21
|
+
#### Resolver
|
|
22
|
+
|
|
23
|
+
The SDK's Resolver corresponds to Tailor Platform's [Pipeline Resolver](https://docs.tailor.tech/guides/pipeline). The key difference is that Pipeline steps are replaced with a single `body` function. See [Resolver](./docs/services/resolver.md) for details.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @tailor-platform/sdk
|
|
29
|
+
# OR
|
|
30
|
+
yarn add @tailor-platform/sdk
|
|
31
|
+
# OR
|
|
32
|
+
pnpm add @tailor-platform/sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
Create a new project using the CLI:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm create @tailor-platform/sdk my-app --template hello-world
|
|
41
|
+
cd my-app
|
|
42
|
+
npm run deploy -- --workspace-id <your-workspace-id>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
See [Available Templates](https://github.com/tailor-platform/sdk/tree/main/packages/create-sdk#available-templates) for more options.
|
|
46
|
+
|
|
47
|
+
For more details, see the [Quickstart Guide](./docs/quickstart.md).
|
|
48
|
+
|
|
49
|
+
## Learn More
|
|
50
|
+
|
|
51
|
+
### Configuration
|
|
52
|
+
|
|
53
|
+
- [Configuration](./docs/configuration.md) - Application and service configuration
|
|
54
|
+
|
|
55
|
+
### Services
|
|
56
|
+
|
|
57
|
+
| Service | Description |
|
|
58
|
+
| -------------------------------------------------- | -------------------------------------------- |
|
|
59
|
+
| [TailorDB](./docs/services/tailordb.md) | Type-safe database schema definition |
|
|
60
|
+
| [Resolver](./docs/services/resolver.md) | Custom GraphQL resolvers with business logic |
|
|
61
|
+
| [Executor](./docs/services/executor.md) | Event-driven handlers for automation |
|
|
62
|
+
| [Workflow](./docs/services/workflow.md) | Job orchestration for complex operations |
|
|
63
|
+
| [Auth](./docs/services/auth.md) | Authentication and authorization |
|
|
64
|
+
| [IdP](./docs/services/idp.md) | Built-in identity provider |
|
|
65
|
+
| [Static Website](./docs/services/staticwebsite.md) | Static file hosting |
|
|
66
|
+
| [Secret Manager](./docs/services/secret.md) | Secure credential storage |
|
|
67
|
+
|
|
68
|
+
### Guides
|
|
69
|
+
|
|
70
|
+
- [Testing Guide](./docs/testing.md) - Unit and E2E testing patterns
|
|
71
|
+
- [CLI Reference](./docs/cli-reference.md) - Command-line interface documentation
|
|
72
|
+
|
|
73
|
+
### Templates
|
|
74
|
+
|
|
75
|
+
See [Create Tailor Platform SDK](https://github.com/tailor-platform/sdk/tree/main/packages/create-sdk) for available project templates.
|
|
76
|
+
|
|
77
|
+
## Requirements
|
|
78
|
+
|
|
79
|
+
- Node.js 22 or later
|
|
80
|
+
- A Tailor Platform account ([request access](https://www.tailor.tech/demo))
|
package/dist/cli/api.d.mts
CHANGED
|
@@ -124,6 +124,7 @@ interface CodeGenerator<T = any, R = any, E = any, Ts = any, Rs = any> extends O
|
|
|
124
124
|
input: GeneratorInput<Ts, Rs>;
|
|
125
125
|
executorInputs: E[];
|
|
126
126
|
baseDir: string;
|
|
127
|
+
configPath: string;
|
|
127
128
|
}): GeneratorResult | Promise<GeneratorResult>;
|
|
128
129
|
}
|
|
129
130
|
//#endregion
|
|
@@ -193,7 +194,10 @@ interface WorkspaceCreateOptions {
|
|
|
193
194
|
declare function workspaceCreate(options: WorkspaceCreateOptions): Promise<WorkspaceInfo>;
|
|
194
195
|
//#endregion
|
|
195
196
|
//#region src/cli/workspace/list.d.ts
|
|
196
|
-
|
|
197
|
+
interface WorkspaceListOptions {
|
|
198
|
+
limit?: number;
|
|
199
|
+
}
|
|
200
|
+
declare function workspaceList(options?: WorkspaceListOptions): Promise<WorkspaceInfo[]>;
|
|
197
201
|
//#endregion
|
|
198
202
|
//#region src/cli/workspace/delete.d.ts
|
|
199
203
|
interface WorkspaceDeleteOptions {
|
package/dist/cli/api.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apply, generate, generateUserTypes, loadAccessToken, loadConfig, loadWorkspaceId, machineUserList, machineUserToken, oauth2ClientGet, oauth2ClientList, remove, show, workflowExecutionGet, workflowExecutionsList, workflowGet, workflowList, workflowResume, workflowStart, workspaceCreate, workspaceDelete, workspaceList } from "../resume-
|
|
1
|
+
import { apply, generate, generateUserTypes, loadAccessToken, loadConfig, loadWorkspaceId, machineUserList, machineUserToken, oauth2ClientGet, oauth2ClientList, remove, show, workflowExecutionGet, workflowExecutionsList, workflowGet, workflowList, workflowResume, workflowStart, workspaceCreate, workspaceDelete, workspaceList } from "../resume-B2ba5opn.mjs";
|
|
2
2
|
import "../job-CL8myeqs.mjs";
|
|
3
3
|
import { register } from "node:module";
|
|
4
4
|
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, executionsCommand, fetchAll, fetchLatestToken, fetchUserInfo,
|
|
2
|
+
import { PATScope, applyCommand, commonArgs, createCommand, deleteCommand, executionsCommand, fetchAll, fetchLatestToken, fetchUserInfo, generateCommand, getCommand, getCommand$1, initOAuth2Client, initOperatorClient, jsonArgs, listCommand as listCommand$1, listCommand$1 as listCommand$6, listCommand$2 as listCommand$7, listCommand$3 as listCommand, loadAccessToken, loadConfig, loadWorkspaceId, printData, readPackageJson, readPlatformConfig, removeCommand, resumeCommand, showCommand, startCommand, tokenCommand, withCommonArgs, writePlatformConfig } from "../resume-B2ba5opn.mjs";
|
|
3
3
|
import "../job-CL8myeqs.mjs";
|
|
4
4
|
import { register } from "node:module";
|
|
5
5
|
import { defineCommand, runCommand, runMain } from "citty";
|
|
6
|
-
import { z } from "zod";
|
|
7
6
|
import * as crypto from "node:crypto";
|
|
8
7
|
import ml from "multiline-ts";
|
|
9
8
|
import { consola as consola$1 } from "consola";
|
|
@@ -218,7 +217,7 @@ const createCommand$3 = defineCommand({
|
|
|
218
217
|
},
|
|
219
218
|
args: {
|
|
220
219
|
...commonArgs,
|
|
221
|
-
...
|
|
220
|
+
...jsonArgs,
|
|
222
221
|
name: {
|
|
223
222
|
type: "positional",
|
|
224
223
|
description: "Profile name",
|
|
@@ -238,7 +237,6 @@ const createCommand$3 = defineCommand({
|
|
|
238
237
|
}
|
|
239
238
|
},
|
|
240
239
|
run: withCommonArgs(async (args) => {
|
|
241
|
-
const format = parseFormat(args.format);
|
|
242
240
|
const config = readPlatformConfig();
|
|
243
241
|
if (config.profiles[args.name]) throw new Error(`Profile "${args.name}" already exists.`);
|
|
244
242
|
const token = await fetchLatestToken(config, args.user);
|
|
@@ -252,13 +250,13 @@ const createCommand$3 = defineCommand({
|
|
|
252
250
|
workspace_id: args["workspace-id"]
|
|
253
251
|
};
|
|
254
252
|
writePlatformConfig(config);
|
|
255
|
-
if (
|
|
253
|
+
if (!args.json) consola$1.success(`Profile "${args.name}" created successfully.`);
|
|
256
254
|
const profileInfo = {
|
|
257
255
|
name: args.name,
|
|
258
256
|
user: args.user,
|
|
259
257
|
workspaceId: args["workspace-id"]
|
|
260
258
|
};
|
|
261
|
-
|
|
259
|
+
printData(profileInfo, args.json);
|
|
262
260
|
})
|
|
263
261
|
});
|
|
264
262
|
|
|
@@ -295,10 +293,9 @@ const listCommand$5 = defineCommand({
|
|
|
295
293
|
},
|
|
296
294
|
args: {
|
|
297
295
|
...commonArgs,
|
|
298
|
-
...
|
|
296
|
+
...jsonArgs
|
|
299
297
|
},
|
|
300
298
|
run: withCommonArgs(async (args) => {
|
|
301
|
-
const format = parseFormat(args.format);
|
|
302
299
|
const config = readPlatformConfig();
|
|
303
300
|
const profiles = Object.entries(config.profiles);
|
|
304
301
|
if (profiles.length === 0) {
|
|
@@ -313,7 +310,7 @@ const listCommand$5 = defineCommand({
|
|
|
313
310
|
user: profile.user,
|
|
314
311
|
workspaceId: profile.workspace_id
|
|
315
312
|
}));
|
|
316
|
-
|
|
313
|
+
printData(profileInfos, args.json);
|
|
317
314
|
})
|
|
318
315
|
});
|
|
319
316
|
|
|
@@ -326,7 +323,7 @@ const updateCommand$1 = defineCommand({
|
|
|
326
323
|
},
|
|
327
324
|
args: {
|
|
328
325
|
...commonArgs,
|
|
329
|
-
...
|
|
326
|
+
...jsonArgs,
|
|
330
327
|
name: {
|
|
331
328
|
type: "positional",
|
|
332
329
|
description: "Profile name",
|
|
@@ -344,7 +341,6 @@ const updateCommand$1 = defineCommand({
|
|
|
344
341
|
}
|
|
345
342
|
},
|
|
346
343
|
run: withCommonArgs(async (args) => {
|
|
347
|
-
const format = parseFormat(args.format);
|
|
348
344
|
const config = readPlatformConfig();
|
|
349
345
|
if (!config.profiles[args.name]) throw new Error(`Profile "${args.name}" not found.`);
|
|
350
346
|
if (!args.user && !args["workspace-id"]) throw new Error("Please provide at least one property to update.");
|
|
@@ -362,13 +358,13 @@ const updateCommand$1 = defineCommand({
|
|
|
362
358
|
profile.user = newUser;
|
|
363
359
|
profile.workspace_id = newWorkspaceId;
|
|
364
360
|
writePlatformConfig(config);
|
|
365
|
-
if (
|
|
361
|
+
if (!args.json) consola$1.success(`Profile "${args.name}" updated successfully`);
|
|
366
362
|
const profileInfo = {
|
|
367
363
|
name: args.name,
|
|
368
364
|
user: newUser,
|
|
369
365
|
workspaceId: newWorkspaceId
|
|
370
366
|
};
|
|
371
|
-
|
|
367
|
+
printData(profileInfo, args.json);
|
|
372
368
|
})
|
|
373
369
|
});
|
|
374
370
|
|
|
@@ -554,7 +550,7 @@ const listSecretCommand = defineCommand({
|
|
|
554
550
|
},
|
|
555
551
|
args: {
|
|
556
552
|
...commonArgs,
|
|
557
|
-
...
|
|
553
|
+
...jsonArgs,
|
|
558
554
|
"workspace-id": {
|
|
559
555
|
type: "string",
|
|
560
556
|
description: "Workspace ID",
|
|
@@ -572,14 +568,13 @@ const listSecretCommand = defineCommand({
|
|
|
572
568
|
}
|
|
573
569
|
},
|
|
574
570
|
run: withCommonArgs(async (args) => {
|
|
575
|
-
const format = parseFormat(args.format);
|
|
576
571
|
try {
|
|
577
572
|
const secrets = await secretList({
|
|
578
573
|
workspaceId: args["workspace-id"],
|
|
579
574
|
profile: args.profile,
|
|
580
575
|
vaultName: args["vault-name"]
|
|
581
576
|
});
|
|
582
|
-
|
|
577
|
+
printData(secrets, args.json);
|
|
583
578
|
} catch (error) {
|
|
584
579
|
if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Vault "${args["vault-name"]}" not found.`);
|
|
585
580
|
throw error;
|
|
@@ -789,7 +784,7 @@ const listCommand$4 = defineCommand({
|
|
|
789
784
|
},
|
|
790
785
|
args: {
|
|
791
786
|
...commonArgs,
|
|
792
|
-
...
|
|
787
|
+
...jsonArgs,
|
|
793
788
|
"workspace-id": {
|
|
794
789
|
type: "string",
|
|
795
790
|
description: "Workspace ID",
|
|
@@ -802,12 +797,11 @@ const listCommand$4 = defineCommand({
|
|
|
802
797
|
}
|
|
803
798
|
},
|
|
804
799
|
run: withCommonArgs(async (args) => {
|
|
805
|
-
const format = parseFormat(args.format);
|
|
806
800
|
const vaults = await vaultList({
|
|
807
801
|
workspaceId: args["workspace-id"],
|
|
808
802
|
profile: args.profile
|
|
809
803
|
});
|
|
810
|
-
|
|
804
|
+
printData(vaults, args.json);
|
|
811
805
|
})
|
|
812
806
|
});
|
|
813
807
|
|
|
@@ -896,12 +890,13 @@ async function truncate(options) {
|
|
|
896
890
|
const hasTypes = options?.types && options.types.length > 0;
|
|
897
891
|
const hasNamespace = !!options?.namespace;
|
|
898
892
|
const hasAll = !!options?.all;
|
|
899
|
-
|
|
900
|
-
|
|
893
|
+
const optionCount = [
|
|
894
|
+
hasAll,
|
|
901
895
|
hasNamespace,
|
|
902
|
-
|
|
903
|
-
].filter(Boolean).length
|
|
904
|
-
if (
|
|
896
|
+
hasTypes
|
|
897
|
+
].filter(Boolean).length;
|
|
898
|
+
if (optionCount === 0) throw new Error("Please specify one of: --all, --namespace <name>, or type names");
|
|
899
|
+
if (optionCount > 1) throw new Error("Options --all, --namespace, and type names are mutually exclusive. Please specify only one.");
|
|
905
900
|
const namespaces = await getAllNamespaces(options?.configPath);
|
|
906
901
|
if (hasAll) {
|
|
907
902
|
if (namespaces.length === 0) {
|
|
@@ -977,7 +972,7 @@ const truncateCommand = defineCommand({
|
|
|
977
972
|
...commonArgs,
|
|
978
973
|
types: {
|
|
979
974
|
type: "positional",
|
|
980
|
-
description: "Type names to truncate
|
|
975
|
+
description: "Type names to truncate",
|
|
981
976
|
required: false
|
|
982
977
|
},
|
|
983
978
|
all: {
|
|
@@ -988,7 +983,7 @@ const truncateCommand = defineCommand({
|
|
|
988
983
|
},
|
|
989
984
|
namespace: {
|
|
990
985
|
type: "string",
|
|
991
|
-
description: "
|
|
986
|
+
description: "Namespace to use (if type names are specified, truncates only those types in this namespace)",
|
|
992
987
|
alias: "n"
|
|
993
988
|
},
|
|
994
989
|
yes: {
|
|
@@ -1015,13 +1010,14 @@ const truncateCommand = defineCommand({
|
|
|
1015
1010
|
}
|
|
1016
1011
|
},
|
|
1017
1012
|
run: withCommonArgs(async (args) => {
|
|
1013
|
+
const types = args._.length > 0 ? args._.map((arg) => String(arg)).filter(Boolean) : void 0;
|
|
1018
1014
|
await truncate({
|
|
1019
1015
|
workspaceId: args["workspace-id"],
|
|
1020
1016
|
profile: args.profile,
|
|
1021
1017
|
configPath: args.config,
|
|
1022
1018
|
all: args.all,
|
|
1023
1019
|
namespace: args.namespace,
|
|
1024
|
-
types
|
|
1020
|
+
types,
|
|
1025
1021
|
yes: args.yes
|
|
1026
1022
|
});
|
|
1027
1023
|
})
|
|
@@ -1071,10 +1067,9 @@ const listCommand$2 = defineCommand({
|
|
|
1071
1067
|
},
|
|
1072
1068
|
args: {
|
|
1073
1069
|
...commonArgs,
|
|
1074
|
-
...
|
|
1070
|
+
...jsonArgs
|
|
1075
1071
|
},
|
|
1076
1072
|
run: withCommonArgs(async (args) => {
|
|
1077
|
-
const format = parseFormat(args.format);
|
|
1078
1073
|
const config = readPlatformConfig();
|
|
1079
1074
|
const users = Object.keys(config.users);
|
|
1080
1075
|
if (users.length === 0) {
|
|
@@ -1084,35 +1079,19 @@ const listCommand$2 = defineCommand({
|
|
|
1084
1079
|
`);
|
|
1085
1080
|
return;
|
|
1086
1081
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
if (user === config.current_user) console.log(chalk.green.bold(`${user} (current)`));
|
|
1091
|
-
else console.log(user);
|
|
1092
|
-
});
|
|
1093
|
-
break;
|
|
1094
|
-
case "json":
|
|
1095
|
-
console.log(JSON.stringify(users));
|
|
1096
|
-
break;
|
|
1097
|
-
default: throw new Error(`Format "${format}" is invalid.`);
|
|
1082
|
+
if (args.json) {
|
|
1083
|
+
console.log(JSON.stringify(users));
|
|
1084
|
+
return;
|
|
1098
1085
|
}
|
|
1086
|
+
users.forEach((user) => {
|
|
1087
|
+
if (user === config.current_user) console.log(chalk.green.bold(`${user} (current)`));
|
|
1088
|
+
else console.log(user);
|
|
1089
|
+
});
|
|
1099
1090
|
})
|
|
1100
1091
|
});
|
|
1101
1092
|
|
|
1102
1093
|
//#endregion
|
|
1103
1094
|
//#region src/cli/user/pat/transform.ts
|
|
1104
|
-
const patFormatSchema = z.enum(["text", "json"]);
|
|
1105
|
-
const patFormatArgs = { format: {
|
|
1106
|
-
type: "string",
|
|
1107
|
-
description: `Output format (${patFormatSchema.options.join(", ")})`,
|
|
1108
|
-
alias: "f",
|
|
1109
|
-
default: "text"
|
|
1110
|
-
} };
|
|
1111
|
-
function parsePATFormat(format) {
|
|
1112
|
-
const parsed = patFormatSchema.safeParse(format);
|
|
1113
|
-
if (!parsed.success) throw new Error(`Format "${format}" is invalid. Must be one of: ${patFormatSchema.options.join(", ")}`);
|
|
1114
|
-
return parsed.data;
|
|
1115
|
-
}
|
|
1116
1095
|
function patScopeToString(scope) {
|
|
1117
1096
|
switch (scope) {
|
|
1118
1097
|
case PATScope.PAT_SCOPE_READ: return "read";
|
|
@@ -1132,9 +1111,14 @@ function getScopesFromWriteFlag(write) {
|
|
|
1132
1111
|
function getScopeStringsFromWriteFlag(write) {
|
|
1133
1112
|
return write ? ["read", "write"] : ["read"];
|
|
1134
1113
|
}
|
|
1135
|
-
function printCreatedToken(name, token, write,
|
|
1114
|
+
function printCreatedToken(name, token, write, action, json) {
|
|
1136
1115
|
const scopes = getScopeStringsFromWriteFlag(write);
|
|
1137
|
-
if (
|
|
1116
|
+
if (json) console.log(JSON.stringify({
|
|
1117
|
+
name,
|
|
1118
|
+
scopes,
|
|
1119
|
+
token
|
|
1120
|
+
}));
|
|
1121
|
+
else console.log(ml`
|
|
1138
1122
|
Personal access token ${action} successfully.
|
|
1139
1123
|
|
|
1140
1124
|
name: ${name}
|
|
@@ -1143,11 +1127,6 @@ function printCreatedToken(name, token, write, format, action) {
|
|
|
1143
1127
|
|
|
1144
1128
|
Please save this token in a secure location. You won't be able to see it again.
|
|
1145
1129
|
`);
|
|
1146
|
-
else console.log(JSON.stringify({
|
|
1147
|
-
name,
|
|
1148
|
-
scopes,
|
|
1149
|
-
token
|
|
1150
|
-
}));
|
|
1151
1130
|
}
|
|
1152
1131
|
|
|
1153
1132
|
//#endregion
|
|
@@ -1159,7 +1138,7 @@ const createCommand$1 = defineCommand({
|
|
|
1159
1138
|
},
|
|
1160
1139
|
args: {
|
|
1161
1140
|
...commonArgs,
|
|
1162
|
-
...
|
|
1141
|
+
...jsonArgs,
|
|
1163
1142
|
name: {
|
|
1164
1143
|
type: "positional",
|
|
1165
1144
|
description: "Token name",
|
|
@@ -1173,7 +1152,6 @@ const createCommand$1 = defineCommand({
|
|
|
1173
1152
|
}
|
|
1174
1153
|
},
|
|
1175
1154
|
run: withCommonArgs(async (args) => {
|
|
1176
|
-
const format = parsePATFormat(args.format);
|
|
1177
1155
|
const config = readPlatformConfig();
|
|
1178
1156
|
if (!config.current_user) throw new Error(ml`
|
|
1179
1157
|
No user logged in.
|
|
@@ -1187,7 +1165,7 @@ const createCommand$1 = defineCommand({
|
|
|
1187
1165
|
scopes
|
|
1188
1166
|
});
|
|
1189
1167
|
if (!result.accessToken) throw new Error("Failed to create personal access token");
|
|
1190
|
-
printCreatedToken(args.name, result.accessToken, args.write,
|
|
1168
|
+
printCreatedToken(args.name, result.accessToken, args.write, "created", args.json);
|
|
1191
1169
|
})
|
|
1192
1170
|
});
|
|
1193
1171
|
|
|
@@ -1227,10 +1205,9 @@ const listCommand$3 = defineCommand({
|
|
|
1227
1205
|
},
|
|
1228
1206
|
args: {
|
|
1229
1207
|
...commonArgs,
|
|
1230
|
-
...
|
|
1208
|
+
...jsonArgs
|
|
1231
1209
|
},
|
|
1232
1210
|
run: withCommonArgs(async (args) => {
|
|
1233
|
-
const format = parsePATFormat(args.format);
|
|
1234
1211
|
const config = readPlatformConfig();
|
|
1235
1212
|
if (!config.current_user) throw new Error(ml`
|
|
1236
1213
|
No user logged in.
|
|
@@ -1249,17 +1226,17 @@ const listCommand$3 = defineCommand({
|
|
|
1249
1226
|
`);
|
|
1250
1227
|
return;
|
|
1251
1228
|
}
|
|
1252
|
-
if (
|
|
1253
|
-
const maxNameLength = Math.max(...pats.map((pat) => pat.name.length));
|
|
1254
|
-
pats.forEach((pat) => {
|
|
1255
|
-
const info = transformPersonalAccessToken(pat);
|
|
1256
|
-
const paddedName = info.name.padStart(maxNameLength);
|
|
1257
|
-
console.log(`${paddedName}: ${info.scopes.join("/")}`);
|
|
1258
|
-
});
|
|
1259
|
-
} else {
|
|
1229
|
+
if (args.json) {
|
|
1260
1230
|
const patInfos = pats.map(transformPersonalAccessToken);
|
|
1261
1231
|
console.log(JSON.stringify(patInfos));
|
|
1232
|
+
return;
|
|
1262
1233
|
}
|
|
1234
|
+
const maxNameLength = Math.max(...pats.map((pat) => pat.name.length));
|
|
1235
|
+
pats.forEach((pat) => {
|
|
1236
|
+
const info = transformPersonalAccessToken(pat);
|
|
1237
|
+
const paddedName = info.name.padStart(maxNameLength);
|
|
1238
|
+
console.log(`${paddedName}: ${info.scopes.join("/")}`);
|
|
1239
|
+
});
|
|
1263
1240
|
})
|
|
1264
1241
|
});
|
|
1265
1242
|
|
|
@@ -1272,7 +1249,7 @@ const updateCommand = defineCommand({
|
|
|
1272
1249
|
},
|
|
1273
1250
|
args: {
|
|
1274
1251
|
...commonArgs,
|
|
1275
|
-
...
|
|
1252
|
+
...jsonArgs,
|
|
1276
1253
|
name: {
|
|
1277
1254
|
type: "positional",
|
|
1278
1255
|
description: "Token name",
|
|
@@ -1286,7 +1263,6 @@ const updateCommand = defineCommand({
|
|
|
1286
1263
|
}
|
|
1287
1264
|
},
|
|
1288
1265
|
run: withCommonArgs(async (args) => {
|
|
1289
|
-
const format = parsePATFormat(args.format);
|
|
1290
1266
|
const config = readPlatformConfig();
|
|
1291
1267
|
if (!config.current_user) throw new Error(ml`
|
|
1292
1268
|
No user logged in.
|
|
@@ -1301,7 +1277,7 @@ const updateCommand = defineCommand({
|
|
|
1301
1277
|
scopes
|
|
1302
1278
|
});
|
|
1303
1279
|
if (!result.accessToken) throw new Error("Failed to create personal access token");
|
|
1304
|
-
printCreatedToken(args.name, result.accessToken, args.write,
|
|
1280
|
+
printCreatedToken(args.name, result.accessToken, args.write, "updated", args.json);
|
|
1305
1281
|
})
|
|
1306
1282
|
});
|
|
1307
1283
|
|