@zodiac-os/sdk 1.0.0 → 1.1.1
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 +9 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +76 -69
- package/dist/index.js.map +1 -1
- package/lib/index.cjs +228 -0
- package/package.json +20 -7
- package/dist/index.d.mts +0 -27
- package/dist/index.mjs +0 -111
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -7,3 +7,12 @@ Programmatically manage Safe + Zodiac account constellations with [Zodiac OS](ht
|
|
|
7
7
|
### Generate a Zodiac OS API key
|
|
8
8
|
|
|
9
9
|
Sign in to https://app.pilot.gnosisguild.org and create an API key at https://app.pilot.gnosisguild.org/admin/api-keys
|
|
10
|
+
|
|
11
|
+
## API Client options
|
|
12
|
+
|
|
13
|
+
| Option | Default | Description |
|
|
14
|
+
| ----------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `apiKey` | `ZODIAC_OS_API_KEY` | Api key you created to access your Zodiac OS workspace. Can either be specified directly in code or through the `ZODIAC_OS_API_KEY` environment variable |
|
|
16
|
+
| `workspace` | `ZODIAC_OS_WORKSPACE` | The Zodiac OS workspace you want to access with the client. Can also be specified via the `ZODIAC_OS_WORKSPACE` environment variable. |
|
|
17
|
+
| `baseUrl` | `https://app.pilor.gnosisguild.org/api/v1` | The URL the API client will be pointed at. This can also be specified via the `ZODIAC_OS_API_URL` environment variable. You probably do not need to specify this. |
|
|
18
|
+
| `fetch` | `global.fetch` | The `fetch` client that is used by the API client. You probably do not need to specify this. However, this can be useful for testing. |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApplyConstellationPayload, ApplyConstellationResult, ResolveConstellationPayload, ResolveConstellationResult } from '@zodiac-os/api-types';
|
|
2
2
|
|
|
3
3
|
type Options = {
|
|
4
|
-
workspace
|
|
5
|
-
apiKey
|
|
4
|
+
workspace?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
6
|
baseUrl?: string;
|
|
7
7
|
fetch?: typeof globalThis.fetch;
|
|
8
8
|
headers?: Record<string, string>;
|
|
@@ -12,8 +12,9 @@ declare class ApiClient {
|
|
|
12
12
|
private baseUrl;
|
|
13
13
|
private _fetch;
|
|
14
14
|
private headers;
|
|
15
|
-
constructor(
|
|
16
|
-
|
|
15
|
+
constructor({ baseUrl, workspace, fetch: customFetch, headers, apiKey, }?: Options);
|
|
16
|
+
protected postJson(endpoint: string, payload: unknown): Promise<any>;
|
|
17
|
+
protected get(endpoint: string): Promise<any>;
|
|
17
18
|
/**
|
|
18
19
|
* Applies an accounts specification to Zodiac OS.
|
|
19
20
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
|
|
22
|
-
// src/index.ts
|
|
23
|
-
var index_exports = {};
|
|
24
|
-
__export(index_exports, {
|
|
25
|
-
ApiClient: () => ApiClient
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/api.ts
|
|
30
|
-
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
var {
|
|
4
|
+
ZODIAC_OS_API_KEY,
|
|
5
|
+
ZODIAC_OS_WORKSPACE,
|
|
6
|
+
ZODIAC_OS_API_URL = "https://app.pilot.gnosisguild.org/api/v1"
|
|
7
|
+
} = process.env;
|
|
31
8
|
var ApiClient = class {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
apiKey;
|
|
10
|
+
baseUrl;
|
|
11
|
+
_fetch;
|
|
12
|
+
headers;
|
|
13
|
+
constructor({
|
|
14
|
+
baseUrl = ZODIAC_OS_API_URL,
|
|
15
|
+
workspace = ZODIAC_OS_WORKSPACE,
|
|
16
|
+
fetch: customFetch = fetch,
|
|
17
|
+
headers = {},
|
|
18
|
+
apiKey = ZODIAC_OS_API_KEY
|
|
19
|
+
} = {}) {
|
|
20
|
+
assert(
|
|
21
|
+
workspace,
|
|
22
|
+
'No workspace provided to the API client. Either pass it as the "workspace" option or set the ZODIAC_OS_WORKSPACE environment variable.'
|
|
23
|
+
);
|
|
24
|
+
this.baseUrl = baseUrl.replace(/\/$/, "") + "/workspace/" + workspace;
|
|
25
|
+
this._fetch = customFetch;
|
|
26
|
+
this.headers = headers;
|
|
27
|
+
assert(
|
|
28
|
+
apiKey,
|
|
29
|
+
'No API key provided to the API client. Either pass it as the "apiKey" option or set the ZODIAC_OS_API_KEY environment variable.'
|
|
30
|
+
);
|
|
31
|
+
this.apiKey = apiKey;
|
|
41
32
|
}
|
|
42
33
|
async postJson(endpoint, payload) {
|
|
43
34
|
const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {
|
|
@@ -47,36 +38,41 @@ var ApiClient = class {
|
|
|
47
38
|
"content-type": "application/json",
|
|
48
39
|
authorization: `Bearer ${this.apiKey}`
|
|
49
40
|
},
|
|
50
|
-
body:
|
|
41
|
+
body: jsonStringify(payload)
|
|
42
|
+
});
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
await handleApiError(res);
|
|
45
|
+
}
|
|
46
|
+
return res.json();
|
|
47
|
+
}
|
|
48
|
+
async get(endpoint) {
|
|
49
|
+
const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {
|
|
50
|
+
headers: { ...this.headers, authorization: `Bearer ${this.apiKey}` }
|
|
51
51
|
});
|
|
52
52
|
if (!res.ok) {
|
|
53
53
|
await handleApiError(res);
|
|
54
54
|
}
|
|
55
|
-
return
|
|
55
|
+
return res.json();
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Applies an accounts specification to Zodiac OS.
|
|
59
59
|
*/
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
specification: payload.specification,
|
|
63
|
-
source: payload.source
|
|
64
|
-
});
|
|
65
|
-
return await this.postJson("constellation/apply", payload);
|
|
60
|
+
applyConstellation(payload) {
|
|
61
|
+
return this.postJson("constellation/apply", payload);
|
|
66
62
|
}
|
|
67
63
|
/**
|
|
68
64
|
* Resolves an accounts specification to Zodiac OS.
|
|
69
65
|
*/
|
|
70
|
-
|
|
71
|
-
return
|
|
66
|
+
resolveConstellation(payload) {
|
|
67
|
+
return this.postJson("constellation/resolve", payload);
|
|
72
68
|
}
|
|
73
69
|
};
|
|
74
70
|
var ApiRequestError = class _ApiRequestError extends Error {
|
|
71
|
+
status;
|
|
72
|
+
statusText;
|
|
73
|
+
details;
|
|
75
74
|
constructor(message, opts) {
|
|
76
75
|
super(_ApiRequestError.composeMessage(message, opts.details));
|
|
77
|
-
__publicField(this, "status");
|
|
78
|
-
__publicField(this, "statusText");
|
|
79
|
-
__publicField(this, "details");
|
|
80
76
|
this.name = "ApiRequestError";
|
|
81
77
|
this.status = opts.status;
|
|
82
78
|
this.statusText = opts.statusText;
|
|
@@ -90,7 +86,7 @@ var ApiRequestError = class _ApiRequestError extends Error {
|
|
|
90
86
|
if (details == null) return message;
|
|
91
87
|
let detailsString;
|
|
92
88
|
try {
|
|
93
|
-
detailsString = typeof details === "string" ? details :
|
|
89
|
+
detailsString = typeof details === "string" ? details : jsonStringify(details, 2);
|
|
94
90
|
} catch (_err) {
|
|
95
91
|
detailsString = String(details);
|
|
96
92
|
}
|
|
@@ -102,35 +98,46 @@ Details: ${detailsString}`;
|
|
|
102
98
|
}
|
|
103
99
|
};
|
|
104
100
|
async function handleApiError(response) {
|
|
105
|
-
|
|
101
|
+
const contentType = response.headers.get("content-type");
|
|
102
|
+
if (contentType?.includes("application/json")) {
|
|
106
103
|
const errorData = await response.json();
|
|
107
|
-
|
|
108
|
-
status: response.status,
|
|
109
|
-
statusText: response.statusText,
|
|
110
|
-
details: errorData.error.details
|
|
111
|
-
});
|
|
112
|
-
} catch (jsonError) {
|
|
104
|
+
let error;
|
|
113
105
|
try {
|
|
114
|
-
|
|
115
|
-
throw new ApiRequestError(`Unexpected error: ${text}`, {
|
|
106
|
+
error = new ApiRequestError(errorData.error.message, {
|
|
116
107
|
status: response.status,
|
|
117
108
|
statusText: response.statusText,
|
|
118
|
-
|
|
109
|
+
details: errorData.error.details
|
|
119
110
|
});
|
|
120
|
-
} catch (
|
|
121
|
-
|
|
122
|
-
`
|
|
111
|
+
} catch (jsonShapeError) {
|
|
112
|
+
error = new ApiRequestError(
|
|
113
|
+
`Failed parsing error response: ${jsonShapeError}`,
|
|
123
114
|
{
|
|
124
115
|
status: response.status,
|
|
125
116
|
statusText: response.statusText,
|
|
126
|
-
|
|
117
|
+
details: errorData
|
|
127
118
|
}
|
|
128
119
|
);
|
|
129
120
|
}
|
|
121
|
+
throw error;
|
|
122
|
+
} else {
|
|
123
|
+
const text = await response.text();
|
|
124
|
+
throw new ApiRequestError(`Unexpected error: ${text}`, {
|
|
125
|
+
status: response.status,
|
|
126
|
+
statusText: response.statusText
|
|
127
|
+
});
|
|
130
128
|
}
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
var jsonStringify = (value, indent) => JSON.stringify(
|
|
131
|
+
value,
|
|
132
|
+
(_, value2) => {
|
|
133
|
+
if (typeof value2 === "bigint") {
|
|
134
|
+
return value2.toString();
|
|
135
|
+
}
|
|
136
|
+
return value2;
|
|
137
|
+
},
|
|
138
|
+
indent
|
|
139
|
+
);
|
|
140
|
+
export {
|
|
134
141
|
ApiClient
|
|
135
|
-
}
|
|
142
|
+
};
|
|
136
143
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/api.ts"],"sourcesContent":["import type {\n ApplyConstellationPayload,\n ApplyConstellationResult,\n ResolveConstellationPayload,\n ResolveConstellationResult,\n ApiError as ApiErrorResponse,\n} from '@zodiac-os/api-types'\nimport assert from 'assert'\n\nexport type Options = {\n workspace?: string\n apiKey?: string\n baseUrl?: string\n fetch?: typeof globalThis.fetch\n headers?: Record<string, string>\n}\n\nconst {\n ZODIAC_OS_API_KEY,\n ZODIAC_OS_WORKSPACE,\n ZODIAC_OS_API_URL = 'https://app.pilot.gnosisguild.org/api/v1',\n} = process.env\n\nexport class ApiClient {\n private apiKey: string\n private baseUrl: string\n private _fetch: typeof fetch\n private headers: Record<string, string>\n\n constructor({\n baseUrl = ZODIAC_OS_API_URL,\n workspace = ZODIAC_OS_WORKSPACE,\n fetch: customFetch = fetch,\n headers = {},\n apiKey = ZODIAC_OS_API_KEY,\n }: Options = {}) {\n assert(\n workspace,\n 'No workspace provided to the API client. Either pass it as the \"workspace\" option or set the ZODIAC_OS_WORKSPACE environment variable.'\n )\n\n this.baseUrl = baseUrl.replace(/\\/$/, '') + '/workspace/' + workspace\n\n this._fetch = customFetch\n this.headers = headers\n\n assert(\n apiKey,\n 'No API key provided to the API client. Either pass it as the \"apiKey\" option or set the ZODIAC_OS_API_KEY environment variable.'\n )\n\n this.apiKey = apiKey\n }\n\n protected async postJson(endpoint: string, payload: unknown) {\n const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {\n method: 'POST',\n headers: {\n ...this.headers,\n 'content-type': 'application/json',\n authorization: `Bearer ${this.apiKey}`,\n },\n body: jsonStringify(payload),\n })\n if (!res.ok) {\n await handleApiError(res)\n }\n\n return res.json()\n }\n\n protected async get(endpoint: string) {\n const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {\n headers: { ...this.headers, authorization: `Bearer ${this.apiKey}` },\n })\n\n if (!res.ok) {\n await handleApiError(res)\n }\n\n return res.json()\n }\n\n /**\n * Applies an accounts specification to Zodiac OS.\n */\n applyConstellation(\n payload: ApplyConstellationPayload\n ): Promise<ApplyConstellationResult> {\n return this.postJson('constellation/apply', payload)\n }\n\n /**\n * Resolves an accounts specification to Zodiac OS.\n */\n resolveConstellation(\n payload: ResolveConstellationPayload\n ): Promise<ResolveConstellationResult> {\n return this.postJson('constellation/resolve', payload)\n }\n}\n\nexport class ApiRequestError extends Error {\n public readonly status: number\n public readonly statusText: string\n public readonly details?: unknown\n\n constructor(\n message: string,\n opts: {\n status: number\n statusText: string\n details?: unknown\n cause?: unknown\n }\n ) {\n super(ApiRequestError.composeMessage(message, opts.details))\n this.name = 'ApiRequestError'\n this.status = opts.status\n this.statusText = opts.statusText\n this.details = opts.details\n if (opts.cause !== undefined) {\n ;(this as any).cause = opts.cause\n }\n }\n\n private static composeMessage(message: string, details?: unknown) {\n if (details == null) return message\n let detailsString: string\n try {\n detailsString =\n typeof details === 'string' ? details : jsonStringify(details, 2)\n } catch (_err) {\n detailsString = String(details)\n }\n return `${message}\\nDetails: ${detailsString}`\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n}\n\nasync function handleApiError(response: Response): Promise<never> {\n const contentType = response.headers.get('content-type')\n if (contentType?.includes('application/json')) {\n const errorData = (await response.json()) as ApiErrorResponse\n let error: ApiRequestError\n try {\n error = new ApiRequestError(errorData.error.message, {\n status: response.status,\n statusText: response.statusText,\n details: errorData.error.details,\n })\n } catch (jsonShapeError) {\n error = new ApiRequestError(\n `Failed parsing error response: ${jsonShapeError}`,\n {\n status: response.status,\n statusText: response.statusText,\n details: errorData,\n }\n )\n }\n throw error\n } else {\n // Not JSON, read as text directly\n const text = await response.text()\n throw new ApiRequestError(`Unexpected error: ${text}`, {\n status: response.status,\n statusText: response.statusText,\n })\n }\n}\n\n/** JSON.stringify with bigint support */\nconst jsonStringify = (value: unknown, indent?: number) =>\n JSON.stringify(\n value,\n (_, value) => {\n if (typeof value === 'bigint') {\n return value.toString()\n }\n\n return value\n },\n indent\n )\n"],"mappings":";AAOA,OAAO,YAAY;AAUnB,IAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA,oBAAoB;AACtB,IAAI,QAAQ;AAEL,IAAM,YAAN,MAAgB;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,OAAO,cAAc;AAAA,IACrB,UAAU,CAAC;AAAA,IACX,SAAS;AAAA,EACX,IAAa,CAAC,GAAG;AACf;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEA,SAAK,UAAU,QAAQ,QAAQ,OAAO,EAAE,IAAI,gBAAgB;AAE5D,SAAK,SAAS;AACd,SAAK,UAAU;AAEf;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAEA,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAgB,SAAS,UAAkB,SAAkB;AAC3D,UAAM,MAAM,MAAM,KAAK,OAAO,GAAG,KAAK,OAAO,IAAI,QAAQ,IAAI;AAAA,MA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,CAAC;AAAA,IACpE,SAAS,MAAM;AACb,sBAAgB,OAAO,OAAO;AAAA,IAChC;AACA,WAAO,GAAG,OAAO;AAAA,WAAc,aAAa;AAAA,EAC9C;AAAA,EAEA,WAAW;AACT,WAAO,GAAG,KAAK,IAAI,KAAK,KAAK,OAAO;AAAA,EACtC;AACF;AAEA,eAAe,eAAe,UAAoC;AAChE,QAAM,cAAc,SAAS,QAAQ,IAAI,cAAc;AACvD,MAAI,aAAa,SAAS,kBAAkB,GAAG;AAC7C,UAAM,YAAa,MAAM,SAAS,KAAK;AACvC,QAAI;AACJ,QAAI;AACF,cAAQ,IAAI,gBAAgB,UAAU,MAAM,SAAS;AAAA,QACnD,QAAQ,SAAS;AAAA,QACjB,YAAY,SAAS;AAAA,QACrB,SAAS,UAAU,MAAM;AAAA,MAC3B,CAAC;AAAA,IACH,SAAS,gBAAgB;AACvB,cAAQ,IAAI;AAAA,QACV,kCAAkC,cAAc;AAAA,QAChD;AAAA,UACE,QAAQ,SAAS;AAAA,UACjB,YAAY,SAAS;AAAA,UACrB,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AACA,UAAM;AAAA,EACR,OAAO;AAEL,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,UAAM,IAAI,gBAAgB,qBAAqB,IAAI,IAAI;AAAA,MACrD,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,IACvB,CAAC;AAAA,EACH;AACF;AAGA,IAAM,gBAAgB,CAAC,OAAgB,WACrC,KAAK;AAAA,EACH;AAAA,EACA,CAAC,GAAGA,WAAU;AACZ,QAAI,OAAOA,WAAU,UAAU;AAC7B,aAAOA,OAAM,SAAS;AAAA,IACxB;AAEA,WAAOA;AAAA,EACT;AAAA,EACA;AACF;","names":["value"]}
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// cli/run.ts
|
|
27
|
+
var import_arg = __toESM(require("arg"), 1);
|
|
28
|
+
|
|
29
|
+
// src/api.ts
|
|
30
|
+
var import_assert = __toESM(require("assert"), 1);
|
|
31
|
+
var {
|
|
32
|
+
ZODIAC_OS_API_KEY,
|
|
33
|
+
ZODIAC_OS_WORKSPACE,
|
|
34
|
+
ZODIAC_OS_API_URL = "https://app.pilot.gnosisguild.org/api/v1"
|
|
35
|
+
} = process.env;
|
|
36
|
+
var ApiClient = class {
|
|
37
|
+
apiKey;
|
|
38
|
+
baseUrl;
|
|
39
|
+
_fetch;
|
|
40
|
+
headers;
|
|
41
|
+
constructor({
|
|
42
|
+
baseUrl = ZODIAC_OS_API_URL,
|
|
43
|
+
workspace = ZODIAC_OS_WORKSPACE,
|
|
44
|
+
fetch: customFetch = fetch,
|
|
45
|
+
headers = {},
|
|
46
|
+
apiKey = ZODIAC_OS_API_KEY
|
|
47
|
+
} = {}) {
|
|
48
|
+
(0, import_assert.default)(
|
|
49
|
+
workspace,
|
|
50
|
+
'No workspace provided to the API client. Either pass it as the "workspace" option or set the ZODIAC_OS_WORKSPACE environment variable.'
|
|
51
|
+
);
|
|
52
|
+
this.baseUrl = baseUrl.replace(/\/$/, "") + "/workspace/" + workspace;
|
|
53
|
+
this._fetch = customFetch;
|
|
54
|
+
this.headers = headers;
|
|
55
|
+
(0, import_assert.default)(
|
|
56
|
+
apiKey,
|
|
57
|
+
'No API key provided to the API client. Either pass it as the "apiKey" option or set the ZODIAC_OS_API_KEY environment variable.'
|
|
58
|
+
);
|
|
59
|
+
this.apiKey = apiKey;
|
|
60
|
+
}
|
|
61
|
+
async postJson(endpoint, payload) {
|
|
62
|
+
const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
...this.headers,
|
|
66
|
+
"content-type": "application/json",
|
|
67
|
+
authorization: `Bearer ${this.apiKey}`
|
|
68
|
+
},
|
|
69
|
+
body: jsonStringify(payload)
|
|
70
|
+
});
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
await handleApiError(res);
|
|
73
|
+
}
|
|
74
|
+
return res.json();
|
|
75
|
+
}
|
|
76
|
+
async get(endpoint) {
|
|
77
|
+
const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {
|
|
78
|
+
headers: { ...this.headers, authorization: `Bearer ${this.apiKey}` }
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
await handleApiError(res);
|
|
82
|
+
}
|
|
83
|
+
return res.json();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Applies an accounts specification to Zodiac OS.
|
|
87
|
+
*/
|
|
88
|
+
applyConstellation(payload) {
|
|
89
|
+
return this.postJson("constellation/apply", payload);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolves an accounts specification to Zodiac OS.
|
|
93
|
+
*/
|
|
94
|
+
resolveConstellation(payload) {
|
|
95
|
+
return this.postJson("constellation/resolve", payload);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var ApiRequestError = class _ApiRequestError extends Error {
|
|
99
|
+
status;
|
|
100
|
+
statusText;
|
|
101
|
+
details;
|
|
102
|
+
constructor(message, opts) {
|
|
103
|
+
super(_ApiRequestError.composeMessage(message, opts.details));
|
|
104
|
+
this.name = "ApiRequestError";
|
|
105
|
+
this.status = opts.status;
|
|
106
|
+
this.statusText = opts.statusText;
|
|
107
|
+
this.details = opts.details;
|
|
108
|
+
if (opts.cause !== void 0) {
|
|
109
|
+
;
|
|
110
|
+
this.cause = opts.cause;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
static composeMessage(message, details) {
|
|
114
|
+
if (details == null) return message;
|
|
115
|
+
let detailsString;
|
|
116
|
+
try {
|
|
117
|
+
detailsString = typeof details === "string" ? details : jsonStringify(details, 2);
|
|
118
|
+
} catch (_err) {
|
|
119
|
+
detailsString = String(details);
|
|
120
|
+
}
|
|
121
|
+
return `${message}
|
|
122
|
+
Details: ${detailsString}`;
|
|
123
|
+
}
|
|
124
|
+
toString() {
|
|
125
|
+
return `${this.name}: ${this.message}`;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
async function handleApiError(response) {
|
|
129
|
+
const contentType = response.headers.get("content-type");
|
|
130
|
+
if (contentType?.includes("application/json")) {
|
|
131
|
+
const errorData = await response.json();
|
|
132
|
+
let error;
|
|
133
|
+
try {
|
|
134
|
+
error = new ApiRequestError(errorData.error.message, {
|
|
135
|
+
status: response.status,
|
|
136
|
+
statusText: response.statusText,
|
|
137
|
+
details: errorData.error.details
|
|
138
|
+
});
|
|
139
|
+
} catch (jsonShapeError) {
|
|
140
|
+
error = new ApiRequestError(
|
|
141
|
+
`Failed parsing error response: ${jsonShapeError}`,
|
|
142
|
+
{
|
|
143
|
+
status: response.status,
|
|
144
|
+
statusText: response.statusText,
|
|
145
|
+
details: errorData
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
} else {
|
|
151
|
+
const text = await response.text();
|
|
152
|
+
throw new ApiRequestError(`Unexpected error: ${text}`, {
|
|
153
|
+
status: response.status,
|
|
154
|
+
statusText: response.statusText
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var jsonStringify = (value, indent) => JSON.stringify(
|
|
159
|
+
value,
|
|
160
|
+
(_, value2) => {
|
|
161
|
+
if (typeof value2 === "bigint") {
|
|
162
|
+
return value2.toString();
|
|
163
|
+
}
|
|
164
|
+
return value2;
|
|
165
|
+
},
|
|
166
|
+
indent
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// cli/internalApi.ts
|
|
170
|
+
var InternalApiClient = class extends ApiClient {
|
|
171
|
+
listVaults() {
|
|
172
|
+
return this.get("vaults");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// cli/commands/typegen.ts
|
|
177
|
+
var t = __toESM(require("@babel/types"), 1);
|
|
178
|
+
var import_generator = require("@babel/generator");
|
|
179
|
+
var import_fs = require("fs");
|
|
180
|
+
var typegen = async () => {
|
|
181
|
+
const client = new InternalApiClient();
|
|
182
|
+
const vaults = await client.listVaults();
|
|
183
|
+
const vaultsEnum = (0, import_generator.generate)(
|
|
184
|
+
t.exportNamedDeclaration(
|
|
185
|
+
t.enumDeclaration(
|
|
186
|
+
t.identifier("Vault"),
|
|
187
|
+
t.enumStringBody(
|
|
188
|
+
vaults.map(
|
|
189
|
+
(vault) => t.enumStringMember(
|
|
190
|
+
t.identifier(vault.label.replaceAll(/ /g, "_")),
|
|
191
|
+
t.stringLiteral(vault.id)
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
const cwd = process.cwd();
|
|
199
|
+
(0, import_fs.mkdirSync)(`${cwd}/.zodiac-os/types`, { recursive: true });
|
|
200
|
+
(0, import_fs.writeFileSync)(`${cwd}/.zodiac-os/types/index.ts`, vaultsEnum.code);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// cli/run.ts
|
|
204
|
+
var run = async (argv = process.argv.slice(2)) => {
|
|
205
|
+
const args = (0, import_arg.default)({}, { argv });
|
|
206
|
+
const input = args._;
|
|
207
|
+
const [command] = input;
|
|
208
|
+
switch (command) {
|
|
209
|
+
case "typegen": {
|
|
210
|
+
await typegen();
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
default: {
|
|
214
|
+
throw new Error(`Unknown command "${command}"`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// cli/index.ts
|
|
220
|
+
run().then(
|
|
221
|
+
() => {
|
|
222
|
+
process.exit(0);
|
|
223
|
+
},
|
|
224
|
+
(error) => {
|
|
225
|
+
if (error) console.error(error);
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
);
|
package/package.json
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zodiac-os/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"author": "Gnosis Guild",
|
|
5
5
|
"license": "LGPL-3.0-only",
|
|
6
6
|
"homepage": "https://github.com/gnosisguild/zodiac-os-sdk",
|
|
7
7
|
"packageManager": "bun@1.1.12",
|
|
8
|
-
"
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/gnosisguild/zodiac-os-sdk"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
9
12
|
"module": "dist/index.mjs",
|
|
10
13
|
"types": "dist/index.d.ts",
|
|
11
14
|
"exports": {
|
|
12
15
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.mjs"
|
|
14
|
-
"require": "./dist/index.js"
|
|
16
|
+
"import": "./dist/index.mjs"
|
|
15
17
|
},
|
|
16
18
|
"files": [
|
|
17
19
|
"dist",
|
|
20
|
+
"lib",
|
|
18
21
|
"README.md",
|
|
19
22
|
"LICENSE"
|
|
20
23
|
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"zodiac-os": "./lib/index.js"
|
|
26
|
+
},
|
|
21
27
|
"scripts": {
|
|
22
|
-
"
|
|
28
|
+
"clean": "rimraf dist lib",
|
|
29
|
+
"prebuild": "bun clean",
|
|
30
|
+
"build": "tsup",
|
|
23
31
|
"prepublishOnly": "bun run build",
|
|
24
32
|
"check:format": "prettier --list-different .",
|
|
25
33
|
"check:types": "tsc -p tsconfig.json",
|
|
@@ -27,14 +35,19 @@
|
|
|
27
35
|
"test": "bun test"
|
|
28
36
|
},
|
|
29
37
|
"devDependencies": {
|
|
38
|
+
"@types/babel__generator": "^7.27.0",
|
|
30
39
|
"@types/bun": "^1.2.21",
|
|
31
40
|
"prettier": "^3.6.2",
|
|
41
|
+
"rimraf": "^6.1.0",
|
|
32
42
|
"tsup": "^8.5.0",
|
|
33
43
|
"typescript": "^5.9.2"
|
|
34
44
|
},
|
|
35
45
|
"dependencies": {
|
|
46
|
+
"@babel/generator": "^7.28.5",
|
|
47
|
+
"@babel/types": "^7.28.5",
|
|
36
48
|
"@epic-web/invariant": "1.0.0",
|
|
37
|
-
"@zodiac-os/api-types": "
|
|
38
|
-
"
|
|
49
|
+
"@zodiac-os/api-types": "1.4.0",
|
|
50
|
+
"arg": "^5.0.2",
|
|
51
|
+
"zodiac-roles-sdk": "^3.3.2"
|
|
39
52
|
}
|
|
40
53
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ApplyConstellationPayload, ApplyConstellationResult, ResolveConstellationPayload, ResolveConstellationResult } from '@zodiac-os/api-types';
|
|
2
|
-
|
|
3
|
-
type Options = {
|
|
4
|
-
workspace: string;
|
|
5
|
-
apiKey: string;
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
fetch?: typeof globalThis.fetch;
|
|
8
|
-
headers?: Record<string, string>;
|
|
9
|
-
};
|
|
10
|
-
declare class ApiClient {
|
|
11
|
-
private apiKey;
|
|
12
|
-
private baseUrl;
|
|
13
|
-
private _fetch;
|
|
14
|
-
private headers;
|
|
15
|
-
constructor(opts: Options);
|
|
16
|
-
private postJson;
|
|
17
|
-
/**
|
|
18
|
-
* Applies an accounts specification to Zodiac OS.
|
|
19
|
-
*/
|
|
20
|
-
applyConstellation(payload: ApplyConstellationPayload): Promise<ApplyConstellationResult>;
|
|
21
|
-
/**
|
|
22
|
-
* Resolves an accounts specification to Zodiac OS.
|
|
23
|
-
*/
|
|
24
|
-
resolveConstellation(payload: ResolveConstellationPayload): Promise<ResolveConstellationResult>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { ApiClient };
|
package/dist/index.mjs
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
// src/api.ts
|
|
6
|
-
var DEFAULT_BASE_URL = "https://app.pilot.gnosisguild.org/api/v1";
|
|
7
|
-
var ApiClient = class {
|
|
8
|
-
constructor(opts) {
|
|
9
|
-
__publicField(this, "apiKey");
|
|
10
|
-
__publicField(this, "baseUrl");
|
|
11
|
-
__publicField(this, "_fetch");
|
|
12
|
-
__publicField(this, "headers");
|
|
13
|
-
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "") + "/workspace/" + opts.workspace;
|
|
14
|
-
this._fetch = opts.fetch ?? fetch;
|
|
15
|
-
this.headers = opts.headers ?? {};
|
|
16
|
-
this.apiKey = opts.apiKey;
|
|
17
|
-
}
|
|
18
|
-
async postJson(endpoint, payload) {
|
|
19
|
-
const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {
|
|
20
|
-
method: "POST",
|
|
21
|
-
headers: {
|
|
22
|
-
...this.headers,
|
|
23
|
-
"content-type": "application/json",
|
|
24
|
-
authorization: `Bearer ${this.apiKey}`
|
|
25
|
-
},
|
|
26
|
-
body: JSON.stringify(payload)
|
|
27
|
-
});
|
|
28
|
-
if (!res.ok) {
|
|
29
|
-
await handleApiError(res);
|
|
30
|
-
}
|
|
31
|
-
return await res.json();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Applies an accounts specification to Zodiac OS.
|
|
35
|
-
*/
|
|
36
|
-
async applyConstellation(payload) {
|
|
37
|
-
this.resolveConstellation({
|
|
38
|
-
specification: payload.specification,
|
|
39
|
-
source: payload.source
|
|
40
|
-
});
|
|
41
|
-
return await this.postJson("constellation/apply", payload);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Resolves an accounts specification to Zodiac OS.
|
|
45
|
-
*/
|
|
46
|
-
async resolveConstellation(payload) {
|
|
47
|
-
return await this.postJson("constellation/resolve", payload);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var ApiRequestError = class _ApiRequestError extends Error {
|
|
51
|
-
constructor(message, opts) {
|
|
52
|
-
super(_ApiRequestError.composeMessage(message, opts.details));
|
|
53
|
-
__publicField(this, "status");
|
|
54
|
-
__publicField(this, "statusText");
|
|
55
|
-
__publicField(this, "details");
|
|
56
|
-
this.name = "ApiRequestError";
|
|
57
|
-
this.status = opts.status;
|
|
58
|
-
this.statusText = opts.statusText;
|
|
59
|
-
this.details = opts.details;
|
|
60
|
-
if (opts.cause !== void 0) {
|
|
61
|
-
;
|
|
62
|
-
this.cause = opts.cause;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
static composeMessage(message, details) {
|
|
66
|
-
if (details == null) return message;
|
|
67
|
-
let detailsString;
|
|
68
|
-
try {
|
|
69
|
-
detailsString = typeof details === "string" ? details : JSON.stringify(details, null, 2);
|
|
70
|
-
} catch (_err) {
|
|
71
|
-
detailsString = String(details);
|
|
72
|
-
}
|
|
73
|
-
return `${message}
|
|
74
|
-
Details: ${detailsString}`;
|
|
75
|
-
}
|
|
76
|
-
toString() {
|
|
77
|
-
return `${this.name}: ${this.message}`;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
async function handleApiError(response) {
|
|
81
|
-
try {
|
|
82
|
-
const errorData = await response.json();
|
|
83
|
-
throw new ApiRequestError(errorData.error.message, {
|
|
84
|
-
status: response.status,
|
|
85
|
-
statusText: response.statusText,
|
|
86
|
-
details: errorData.error.details
|
|
87
|
-
});
|
|
88
|
-
} catch (jsonError) {
|
|
89
|
-
try {
|
|
90
|
-
const text = await response.text();
|
|
91
|
-
throw new ApiRequestError(`Unexpected error: ${text}`, {
|
|
92
|
-
status: response.status,
|
|
93
|
-
statusText: response.statusText,
|
|
94
|
-
cause: jsonError
|
|
95
|
-
});
|
|
96
|
-
} catch (textError) {
|
|
97
|
-
throw new ApiRequestError(
|
|
98
|
-
`Unexpected error: ${response.status} ${response.statusText}`,
|
|
99
|
-
{
|
|
100
|
-
status: response.status,
|
|
101
|
-
statusText: response.statusText,
|
|
102
|
-
cause: textError
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
export {
|
|
109
|
-
ApiClient
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api.ts"],"sourcesContent":["import type {\n ApplyConstellationPayload,\n ApplyConstellationResult,\n ResolveConstellationPayload,\n ResolveConstellationResult,\n ApiError as ApiErrorResponse,\n} from '@zodiac-os/api-types'\n\nexport type Options = {\n workspace: string\n apiKey: string\n baseUrl?: string\n fetch?: typeof globalThis.fetch\n headers?: Record<string, string>\n}\n\nconst DEFAULT_BASE_URL = 'https://app.pilot.gnosisguild.org/api/v1'\n\nexport class ApiClient {\n private apiKey: string\n private baseUrl: string\n private _fetch: typeof fetch\n private headers: Record<string, string>\n\n constructor(opts: Options) {\n this.baseUrl =\n (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '') +\n '/workspace/' +\n opts.workspace\n\n this._fetch = opts.fetch ?? fetch\n this.headers = opts.headers ?? {}\n this.apiKey = opts.apiKey\n }\n\n private async postJson(endpoint: string, payload: unknown) {\n const res = await this._fetch(`${this.baseUrl}/${endpoint}`, {\n method: 'POST',\n headers: {\n ...this.headers,\n 'content-type': 'application/json',\n authorization: `Bearer ${this.apiKey}`,\n },\n body: JSON.stringify(payload),\n })\n if (!res.ok) {\n await handleApiError(res)\n }\n\n return await res.json()\n }\n\n /**\n * Applies an accounts specification to Zodiac OS.\n */\n async applyConstellation(\n payload: ApplyConstellationPayload\n ): Promise<ApplyConstellationResult> {\n this.resolveConstellation({\n specification: payload.specification,\n source: payload.source,\n })\n return await this.postJson('constellation/apply', payload)\n }\n\n /**\n * Resolves an accounts specification to Zodiac OS.\n */\n async resolveConstellation(\n payload: ResolveConstellationPayload\n ): Promise<ResolveConstellationResult> {\n return await this.postJson('constellation/resolve', payload)\n }\n}\n\nexport class ApiRequestError extends Error {\n public readonly status: number\n public readonly statusText: string\n public readonly details?: unknown\n\n constructor(\n message: string,\n opts: {\n status: number\n statusText: string\n details?: unknown\n cause?: unknown\n }\n ) {\n super(ApiRequestError.composeMessage(message, opts.details))\n this.name = 'ApiRequestError'\n this.status = opts.status\n this.statusText = opts.statusText\n this.details = opts.details\n if (opts.cause !== undefined) {\n ;(this as any).cause = opts.cause\n }\n }\n\n private static composeMessage(message: string, details?: unknown) {\n if (details == null) return message\n let detailsString: string\n try {\n detailsString =\n typeof details === 'string' ? details : JSON.stringify(details, null, 2)\n } catch (_err) {\n detailsString = String(details)\n }\n return `${message}\\nDetails: ${detailsString}`\n }\n\n toString() {\n return `${this.name}: ${this.message}`\n }\n}\n\nasync function handleApiError(response: Response): Promise<never> {\n try {\n const errorData = (await response.json()) as ApiErrorResponse\n throw new ApiRequestError(errorData.error.message, {\n status: response.status,\n statusText: response.statusText,\n details: errorData.error.details,\n })\n } catch (jsonError) {\n // If JSON parsing fails, try to read as string\n try {\n const text = await response.text()\n throw new ApiRequestError(`Unexpected error: ${text}`, {\n status: response.status,\n statusText: response.statusText,\n cause: jsonError,\n })\n } catch (textError) {\n // If both JSON and text parsing fail, throw a generic error\n throw new ApiRequestError(\n `Unexpected error: ${response.status} ${response.statusText}`,\n {\n status: response.status,\n statusText: response.statusText,\n cause: textError,\n }\n )\n }\n }\n}\n"],"mappings":";;;;;AAgBA,IAAM,mBAAmB;AAElB,IAAM,YAAN,MAAgB;AAAA,EAMrB,YAAY,MAAe;AAL3B,wBAAQ;AACR,wBAAQ;AACR,wBAAQ;AACR,wBAAQ;AAGN,SAAK,WACF,KAAK,WAAW,kBAAkB,QAAQ,OAAO,EAAE,IACpD,gBACA,KAAK;AAEP,SAAK,SAAS,KAAK,SAAS;AAC5B,SAAK,UAAU,KAAK,WAAW,CAAC;AAChC,SAAK,SAAS,KAAK;AAAA,EACrB;AAAA,EAEA,MAAc,SAAS,UAAkB,SAAkB;AACzD,UAAM,MAAM,MAAM,KAAK,OAAO,GAAG,KAAK,OAAO,IAAI,QAAQ,IAAI;AAAA,MAC3D,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,GAAG,KAAK;AAAA,QACR,gBAAgB;AAAA,QAChB,eAAe,UAAU,KAAK,MAAM;AAAA,MACtC;AAAA,MACA,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YA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