@stack-spot/portal-network 0.1.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/.generate-api.failed.json +1 -0
- package/dist/api/account.d.ts +2368 -0
- package/dist/api/account.d.ts.map +1 -0
- package/dist/api/account.js +1521 -0
- package/dist/api/account.js.map +1 -0
- package/dist/api/ai.d.ts +1432 -0
- package/dist/api/ai.d.ts.map +1 -0
- package/dist/api/ai.js +1342 -0
- package/dist/api/ai.js.map +1 -0
- package/dist/api/apiRuntime.d.ts +922 -0
- package/dist/api/apiRuntime.d.ts.map +1 -0
- package/dist/api/apiRuntime.js +599 -0
- package/dist/api/apiRuntime.js.map +1 -0
- package/dist/api/cloudAccount.d.ts +473 -0
- package/dist/api/cloudAccount.d.ts.map +1 -0
- package/dist/api/cloudAccount.js +300 -0
- package/dist/api/cloudAccount.js.map +1 -0
- package/dist/api/cloudServices.d.ts +1233 -0
- package/dist/api/cloudServices.d.ts.map +1 -0
- package/dist/api/cloudServices.js +715 -0
- package/dist/api/cloudServices.js.map +1 -0
- package/dist/api/insights.d.ts +123 -0
- package/dist/api/insights.d.ts.map +1 -0
- package/dist/api/insights.js +112 -0
- package/dist/api/insights.js.map +1 -0
- package/dist/api/plugin.d.ts +368 -0
- package/dist/api/plugin.d.ts.map +1 -0
- package/dist/api/plugin.js +218 -0
- package/dist/api/plugin.js.map +1 -0
- package/dist/api/serviceCatalog.d.ts +737 -0
- package/dist/api/serviceCatalog.d.ts.map +1 -0
- package/dist/api/serviceCatalog.js +611 -0
- package/dist/api/serviceCatalog.js.map +1 -0
- package/dist/api/workflows.d.ts +366 -0
- package/dist/api/workflows.d.ts.map +1 -0
- package/dist/api/workflows.js +175 -0
- package/dist/api/workflows.js.map +1 -0
- package/dist/api/workspace.js +1476 -0
- package/dist/api/workspace.js.map +1 -0
- package/dist/api/workspaceManager.d.ts +1121 -0
- package/dist/api/workspaceManager.d.ts.map +1 -0
- package/dist/api/workspaceManager.js +357 -0
- package/dist/api/workspaceManager.js.map +1 -0
- package/dist/api/workspaceSearchEngine.d.ts +93 -0
- package/dist/api/workspaceSearchEngine.d.ts.map +1 -0
- package/dist/api/workspaceSearchEngine.js +55 -0
- package/dist/api/workspaceSearchEngine.js.map +1 -0
- package/dist/apis.json +129 -0
- package/dist/client/account.d.ts +46 -0
- package/dist/client/account.d.ts.map +1 -0
- package/dist/client/account.js +104 -0
- package/dist/client/account.js.map +1 -0
- package/dist/error/CanceledError.d.ts +5 -0
- package/dist/error/CanceledError.d.ts.map +1 -0
- package/dist/error/CanceledError.js +7 -0
- package/dist/error/CanceledError.js.map +1 -0
- package/dist/error/DefaultAPIError.d.ts +9 -0
- package/dist/error/DefaultAPIError.d.ts.map +1 -0
- package/dist/error/DefaultAPIError.js +58 -0
- package/dist/error/DefaultAPIError.js.map +1 -0
- package/dist/error/StackspotAPIError.d.ts +19 -0
- package/dist/error/StackspotAPIError.d.ts.map +1 -0
- package/dist/error/StackspotAPIError.js +39 -0
- package/dist/error/StackspotAPIError.js.map +1 -0
- package/dist/error/dictionary/account.d.ts +55 -0
- package/dist/error/dictionary/account.d.ts.map +1 -0
- package/dist/error/dictionary/account.js +55 -0
- package/dist/error/dictionary/account.js.map +1 -0
- package/dist/error/dictionary/action.d.ts +163 -0
- package/dist/error/dictionary/action.d.ts.map +1 -0
- package/dist/error/dictionary/action.js +163 -0
- package/dist/error/dictionary/action.js.map +1 -0
- package/dist/error/dictionary/base.d.ts +21 -0
- package/dist/error/dictionary/base.d.ts.map +1 -0
- package/dist/error/dictionary/base.js +21 -0
- package/dist/error/dictionary/base.js.map +1 -0
- package/dist/error/dictionary/cnt-fields.d.ts +13 -0
- package/dist/error/dictionary/cnt-fields.d.ts.map +1 -0
- package/dist/error/dictionary/cnt-fields.js +13 -0
- package/dist/error/dictionary/cnt-fields.js.map +1 -0
- package/dist/error/dictionary/cnt.d.ts +79 -0
- package/dist/error/dictionary/cnt.d.ts.map +1 -0
- package/dist/error/dictionary/cnt.js +79 -0
- package/dist/error/dictionary/cnt.js.map +1 -0
- package/dist/error/dictionary/rte.d.ts +23 -0
- package/dist/error/dictionary/rte.d.ts.map +1 -0
- package/dist/error/dictionary/rte.js +23 -0
- package/dist/error/dictionary/rte.js.map +1 -0
- package/dist/error/dictionary/rtm.d.ts +9 -0
- package/dist/error/dictionary/rtm.d.ts.map +1 -0
- package/dist/error/dictionary/rtm.js +9 -0
- package/dist/error/dictionary/rtm.js.map +1 -0
- package/dist/error/dictionary/workspace-fields.d.ts +9 -0
- package/dist/error/dictionary/workspace-fields.d.ts.map +1 -0
- package/dist/error/dictionary/workspace-fields.js +9 -0
- package/dist/error/dictionary/workspace-fields.js.map +1 -0
- package/dist/error/dictionary/workspace.d.ts +99 -0
- package/dist/error/dictionary/workspace.d.ts.map +1 -0
- package/dist/error/dictionary/workspace.js +99 -0
- package/dist/error/dictionary/workspace.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/network/AutoMutation.d.ts +10 -0
- package/dist/network/AutoMutation.d.ts.map +1 -0
- package/dist/network/AutoMutation.js +20 -0
- package/dist/network/AutoMutation.js.map +1 -0
- package/dist/network/AutoOperation.d.ts +19 -0
- package/dist/network/AutoOperation.d.ts.map +1 -0
- package/dist/network/AutoOperation.js +99 -0
- package/dist/network/AutoOperation.js.map +1 -0
- package/dist/network/AutoQuery.d.ts +19 -0
- package/dist/network/AutoQuery.d.ts.map +1 -0
- package/dist/network/AutoQuery.js +70 -0
- package/dist/network/AutoQuery.js.map +1 -0
- package/dist/network/ManualMutation.d.ts +11 -0
- package/dist/network/ManualMutation.d.ts.map +1 -0
- package/dist/network/ManualMutation.js +32 -0
- package/dist/network/ManualMutation.js.map +1 -0
- package/dist/network/ManualOperation.d.ts +13 -0
- package/dist/network/ManualOperation.d.ts.map +1 -0
- package/dist/network/ManualOperation.js +53 -0
- package/dist/network/ManualOperation.js.map +1 -0
- package/dist/network/ManualQuery.d.ts +20 -0
- package/dist/network/ManualQuery.d.ts.map +1 -0
- package/dist/network/ManualQuery.js +77 -0
- package/dist/network/ManualQuery.js.map +1 -0
- package/dist/network/NetworkClient.d.ts +20 -0
- package/dist/network/NetworkClient.d.ts.map +1 -0
- package/dist/network/NetworkClient.js +85 -0
- package/dist/network/NetworkClient.js.map +1 -0
- package/dist/network/ReactQueryNetworkClient.d.ts +16 -0
- package/dist/network/ReactQueryNetworkClient.d.ts.map +1 -0
- package/dist/network/ReactQueryNetworkClient.js +125 -0
- package/dist/network/ReactQueryNetworkClient.js.map +1 -0
- package/dist/network/react-query-client.d.ts +3 -0
- package/dist/network/react-query-client.d.ts.map +1 -0
- package/dist/network/react-query-client.js +3 -0
- package/dist/network/react-query-client.js.map +1 -0
- package/dist/network/types.d.ts +55 -0
- package/dist/network/types.d.ts.map +1 -0
- package/dist/network/types.js +2 -0
- package/dist/network/types.js.map +1 -0
- package/package.json +56 -0
- package/readme.md +1 -0
- package/scripts/generate-apis.ts +134 -0
- package/src/api/account.ts +4793 -0
- package/src/api/ai.ts +3121 -0
- package/src/api/apiRuntime.ts +2029 -0
- package/src/api/cloudAccount.ts +1133 -0
- package/src/api/cloudServices.ts +2872 -0
- package/src/api/insights.ts +264 -0
- package/src/api/plugin.ts +685 -0
- package/src/api/serviceCatalog.ts +2908 -0
- package/src/api/workflows.ts +709 -0
- package/src/api/workspace.ts +5178 -0
- package/src/api/workspaceManager.ts +1516 -0
- package/src/api/workspaceSearchEngine.ts +153 -0
- package/src/apis.json +129 -0
- package/src/client/account.ts +52 -0
- package/src/error/CanceledError.ts +7 -0
- package/src/error/DefaultAPIError.ts +51 -0
- package/src/error/StackspotAPIError.ts +31 -0
- package/src/error/dictionary/account.ts +56 -0
- package/src/error/dictionary/action.ts +206 -0
- package/src/error/dictionary/base.ts +22 -0
- package/src/error/dictionary/cnt-fields.ts +14 -0
- package/src/error/dictionary/cnt.ts +80 -0
- package/src/error/dictionary/rte.ts +24 -0
- package/src/error/dictionary/rtm.ts +10 -0
- package/src/error/dictionary/workspace-fields.ts +10 -0
- package/src/error/dictionary/workspace.ts +100 -0
- package/src/index.ts +5 -0
- package/src/network/AutoMutation.ts +25 -0
- package/src/network/AutoOperation.ts +88 -0
- package/src/network/AutoQuery.ts +80 -0
- package/src/network/ManualMutation.ts +41 -0
- package/src/network/ManualOperation.ts +55 -0
- package/src/network/ManualQuery.ts +93 -0
- package/src/network/NetworkClient.ts +93 -0
- package/src/network/ReactQueryNetworkClient.ts +154 -0
- package/src/network/react-query-client.ts +3 -0
- package/src/network/types.ts +82 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-query-client.js","sourceRoot":"","sources":["../../src/network/react-query-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { RequestOpts } from '@oazapfts/runtime';
|
|
2
|
+
import { Session } from '@stack-spot/auth';
|
|
3
|
+
import { MutateOptions, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
4
|
+
import { StackspotAPIError } from '../error/StackspotAPIError.js';
|
|
5
|
+
export interface SessionManager {
|
|
6
|
+
hasSession(): boolean;
|
|
7
|
+
endSession(): void;
|
|
8
|
+
getSession(): Session;
|
|
9
|
+
}
|
|
10
|
+
export interface RequestOptions {
|
|
11
|
+
params?: Record<string, string | undefined>;
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export interface RequestWithBody extends RequestOptions {
|
|
15
|
+
body?: string | object | FormData;
|
|
16
|
+
}
|
|
17
|
+
export type Env = 'dev' | 'stg' | 'prd';
|
|
18
|
+
export type HTTPMethod = 'post' | 'patch' | 'delete' | 'put' | 'get';
|
|
19
|
+
export interface OperationConfig<Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result> {
|
|
20
|
+
name: string;
|
|
21
|
+
request: (...args: Args) => Promise<Result>;
|
|
22
|
+
permission: (...args: Args extends [AbortSignal] ? [] : [Args[1]]) => Promise<boolean>;
|
|
23
|
+
}
|
|
24
|
+
export interface FullOperationConfig<Args extends [AbortSignal, Record<string, any>] | [AbortSignal], Result> extends OperationConfig<Args, Result> {
|
|
25
|
+
apiName: string;
|
|
26
|
+
}
|
|
27
|
+
export interface OperationObject<Variables> {
|
|
28
|
+
isAllowed: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<boolean>;
|
|
29
|
+
useAllowed: (...args: Variables extends void ? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>] : [variables?: Partial<Variables>, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]) => Readonly<[boolean | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<boolean, StackspotAPIError>]>;
|
|
30
|
+
getPermissionKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[];
|
|
31
|
+
cancel: (variables?: Partial<Variables>) => boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface QueryObject<Variables, Result> extends OperationObject<Variables> {
|
|
34
|
+
query: (...args: Variables extends void ? [] : [variables: Variables]) => Promise<Result>;
|
|
35
|
+
useQuery: (...args: Variables extends void ? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>] : [variables: Variables, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]) => Result | undefined;
|
|
36
|
+
useStatefulQuery: (...args: Variables extends void ? [options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>] : [variables: Variables, options?: Omit<UseQueryOptions, 'queryFn' | 'queryKey'>]) => Readonly<[Result | undefined, boolean, StackspotAPIError | null | undefined, UseQueryResult<Result, StackspotAPIError>]>;
|
|
37
|
+
invalidate: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => Promise<void>;
|
|
38
|
+
getKey: (...args: Variables extends void ? [] : [variables?: Partial<Variables>]) => any[];
|
|
39
|
+
}
|
|
40
|
+
export interface AutoQueryObjectParams<Variables, Result> {
|
|
41
|
+
apiName: string;
|
|
42
|
+
fn: ((variables: Variables, opts?: RequestOpts) => Promise<Result>) | ((opts?: RequestOpts) => Promise<Result>);
|
|
43
|
+
onFetchPermission: typeof fetch;
|
|
44
|
+
transformError?: (error: any) => StackspotAPIError;
|
|
45
|
+
}
|
|
46
|
+
export interface MutationObject<Variables, Result> extends OperationObject<Variables> {
|
|
47
|
+
mutate: (...args: Variables extends void ? [] : [variables: Variables]) => Promise<Result>;
|
|
48
|
+
useMutation: (options?: Omit<UseMutationOptions<Result, StackspotAPIError, Variables>, 'mutationFn'>) => Readonly<[
|
|
49
|
+
(...args: Variables extends void ? [options?: MutateOptions<Result, StackspotAPIError>] : [variables: Variables, options?: MutateOptions<Result, StackspotAPIError, Variables>]) => Promise<Result>,
|
|
50
|
+
boolean,
|
|
51
|
+
StackspotAPIError | undefined,
|
|
52
|
+
UseMutationResult<Result, StackspotAPIError, Variables>
|
|
53
|
+
]>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/network/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC7H,OAAO,EAAE,iBA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CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,iBAAiB,CAAC;CACpD;AAED,MAAM,WAAW,cAAc,CAAC,SAAS,EAAE,MAAM,CAAE,SAAQ,eAAe,CAAC,SAAS,CAAC;IACnF,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,SAAS,SAAS,IAAI,GAAG,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3F,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,YAAY,CAAC,KAClG,QAAQ,CAAC;QACP,CAAC,GAAG,IAAI,EAAE,SAAS,SAAS,IAAI,GAC5B,CAAC,OAAO,CAAC,EAAG,aAAa,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,GACrD,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAC,CAAC,KACpF,OAAO,CAAC,MAAM,CAAC;QACpB,OAAO;QAAE,iBAAiB,GAAG,SAAS;QACtC,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,EAAE,SAAS,CAAC;KACxD,CAAC,CAAC;CACN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/network/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stack-spot/portal-network",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./api/*": "./dist/api/*.js"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@stack-spot/auth": "^5.2.0",
|
|
13
|
+
"@stack-spot/opa": "^2.2.0",
|
|
14
|
+
"@stack-spot/portal-translate": "^1.0.0",
|
|
15
|
+
"@tanstack/react-query": "^5.1.9",
|
|
16
|
+
"react": "^18.2.0",
|
|
17
|
+
"react-dom": "^18.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@inquirer/checkbox": "^2.3.5",
|
|
21
|
+
"@inquirer/prompts": "^5.0.5",
|
|
22
|
+
"@types/cli-progress": "^3.11.5",
|
|
23
|
+
"@types/node": "^20.14.2",
|
|
24
|
+
"@types/react": "^18.2.37",
|
|
25
|
+
"@types/react-dom": "^18.2.15",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
27
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
28
|
+
"cli-progress": "^3.12.0",
|
|
29
|
+
"eslint": "^8.53.0",
|
|
30
|
+
"eslint-plugin-filenames": "^1.3.2",
|
|
31
|
+
"eslint-plugin-import": "^2.29.0",
|
|
32
|
+
"eslint-plugin-lodash": "^7.4.0",
|
|
33
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
34
|
+
"eslint-plugin-react": "^7.33.2",
|
|
35
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
36
|
+
"eslint-plugin-react-refresh": "^0.4.4",
|
|
37
|
+
"inquirer-interactive-list-prompt": "^1.0.4",
|
|
38
|
+
"oazapfts": "^6.1.0",
|
|
39
|
+
"react": "18.2.0",
|
|
40
|
+
"react-dom": "18.2.0",
|
|
41
|
+
"rimraf": "^5.0.7",
|
|
42
|
+
"tsc-esm-fix": "^2.20.26",
|
|
43
|
+
"tsc-silent": "^1.2.2",
|
|
44
|
+
"tsx": "^4.15.1",
|
|
45
|
+
"typescript": "^5.2.2"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@oazapfts/runtime": "^1.0.3",
|
|
49
|
+
"lodash": "^4.17.21"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "rimraf dist && tsc-silent -p tsconfig.build.json --suppress @/src/api/ && tsc-esm-fix --target='dist'",
|
|
53
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
54
|
+
"generate": "tsx ./scripts/generate-apis.ts"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Network
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { exec } from 'child_process'
|
|
4
|
+
import { readFile, unlink, writeFile } from 'fs/promises'
|
|
5
|
+
import checkbox from '@inquirer/checkbox'
|
|
6
|
+
import { Presets, SingleBar } from 'cli-progress'
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import list from 'inquirer-interactive-list-prompt'
|
|
9
|
+
import apis from '../src/apis.json'
|
|
10
|
+
|
|
11
|
+
const MAX_ATTEMPTS = 5
|
|
12
|
+
const DELAY_MS = 2000
|
|
13
|
+
const TARGET_DIR = 'src/api'
|
|
14
|
+
const LOG_FILE = '.generate-api.failed.json'
|
|
15
|
+
const envs = [
|
|
16
|
+
{ name: 'Production', value: 'prd', key: 'p' },
|
|
17
|
+
{ name: 'Staging', value: 'stg', key: 's' },
|
|
18
|
+
{ name: 'Development', value: 'dev', key: 'd' },
|
|
19
|
+
] as const
|
|
20
|
+
|
|
21
|
+
function delay() {
|
|
22
|
+
return new Promise<void>(resolve => {
|
|
23
|
+
setTimeout(resolve, DELAY_MS)
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function generateAPICode(name: string, docsUrl: any) {
|
|
28
|
+
return new Promise<string>((resolve, reject) => {
|
|
29
|
+
let output = ''
|
|
30
|
+
const child = exec(
|
|
31
|
+
`pnpm oazapfts ${docsUrl} ${TARGET_DIR}/${name}.ts --optimistic --argumentStyle object`,
|
|
32
|
+
(_, out, err) => output += out || err,
|
|
33
|
+
)
|
|
34
|
+
child.on('error', err => reject(err.message))
|
|
35
|
+
child.on('close', code => code === 0 ? resolve(output) : reject(output))
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function generateCodeForAPIs(apiNames: (keyof typeof apis)[], env: 'dev' | 'stg' | 'prd') {
|
|
40
|
+
let progress = 0
|
|
41
|
+
const progressBar = new SingleBar({ clearOnComplete: true, stopOnComplete: true }, Presets.shades_classic)
|
|
42
|
+
progressBar.start(apiNames.length, 0)
|
|
43
|
+
const succeeded: string[] = []
|
|
44
|
+
const failed: string[] = []
|
|
45
|
+
const errors: string[] = []
|
|
46
|
+
await Promise.all(apiNames.map(async (name) => {
|
|
47
|
+
let retries = MAX_ATTEMPTS
|
|
48
|
+
while (retries > 0) {
|
|
49
|
+
try {
|
|
50
|
+
const api = apis[name]
|
|
51
|
+
if ('docs' in api) {
|
|
52
|
+
const docsUrl = `${api.url[env]}${api.docs}`
|
|
53
|
+
await generateAPICode(name, docsUrl)
|
|
54
|
+
}
|
|
55
|
+
retries = 0
|
|
56
|
+
succeeded.push(name)
|
|
57
|
+
progressBar.update(++progress)
|
|
58
|
+
} catch (error: any) {
|
|
59
|
+
retries--
|
|
60
|
+
await delay()
|
|
61
|
+
if (retries === 0) {
|
|
62
|
+
errors.push(error.message || `${error}`)
|
|
63
|
+
failed.push(name)
|
|
64
|
+
progressBar.update(++progress)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}))
|
|
69
|
+
const succeededStr = succeeded.length ? ` Code generated successfully for ${succeeded.length} APIs.` : ''
|
|
70
|
+
const failedStr = failed.length ? ` Failed to generate code for ${failed.length} APIs. Check the logs below.` : ''
|
|
71
|
+
console.log(`\nFinished!${succeededStr}${failedStr}`)
|
|
72
|
+
if (succeeded.length) {
|
|
73
|
+
console.log('\n> Generated code for:')
|
|
74
|
+
succeeded.forEach(api => console.log(` - ${api}`))
|
|
75
|
+
await removeLastFailed()
|
|
76
|
+
}
|
|
77
|
+
if (failed.length) {
|
|
78
|
+
console.log('\n> Failed to generate code for:')
|
|
79
|
+
failed.forEach(api => console.log(` - ${api}`))
|
|
80
|
+
await saveFailed(failed)
|
|
81
|
+
}
|
|
82
|
+
if (errors.length) throw new Error(errors.join('\n\n'))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function getLastFailed(): Promise<(keyof typeof apis)[]> {
|
|
86
|
+
try {
|
|
87
|
+
const raw = await readFile(LOG_FILE, { encoding: 'utf-8' })
|
|
88
|
+
return JSON.parse(raw)
|
|
89
|
+
} catch {
|
|
90
|
+
return []
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function removeLastFailed() {
|
|
95
|
+
try {
|
|
96
|
+
await unlink(LOG_FILE)
|
|
97
|
+
// eslint-disable-next-line no-empty
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function saveFailed(failed: string[]) {
|
|
102
|
+
try {
|
|
103
|
+
await writeFile(LOG_FILE, JSON.stringify(failed), { encoding: 'utf-8' })
|
|
104
|
+
// eslint-disable-next-line no-empty
|
|
105
|
+
} catch {}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function start() {
|
|
109
|
+
try {
|
|
110
|
+
const cmdEnvArg = process.argv[2]
|
|
111
|
+
const allAPINames = Object.keys(apis) as (keyof typeof apis)[]
|
|
112
|
+
if ((envs.map(e => e.value) as string[]).includes(cmdEnvArg?.trim() ?? '')) {
|
|
113
|
+
await generateCodeForAPIs(allAPINames, cmdEnvArg as 'prd' | 'stg' | 'dev')
|
|
114
|
+
} else {
|
|
115
|
+
const lastFailed = await getLastFailed()
|
|
116
|
+
const selectedAPIs = await checkbox({
|
|
117
|
+
message: 'Select the APIs you wish to update',
|
|
118
|
+
choices: allAPINames.map(api => ({ name: api, value: api, checked: !lastFailed.length || lastFailed.includes(api) })),
|
|
119
|
+
})
|
|
120
|
+
const env: 'prd' | 'stg' | 'dev' = await list({
|
|
121
|
+
message: 'Select an environment',
|
|
122
|
+
choices: envs,
|
|
123
|
+
default: envs[0].value,
|
|
124
|
+
})
|
|
125
|
+
await generateCodeForAPIs(selectedAPIs, env)
|
|
126
|
+
}
|
|
127
|
+
process.exit(0)
|
|
128
|
+
} catch (error: any) {
|
|
129
|
+
console.error(error.message || `${error}`)
|
|
130
|
+
process.exit(1)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
start()
|