@certen.io/sdk 0.4.0 → 0.7.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 +874 -185
- package/README.md +133 -119
- package/dist/client.d.ts +99 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +269 -20
- package/dist/client.js.map +1 -1
- package/dist/doctor.d.ts +53 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +451 -0
- package/dist/doctor.js.map +1 -0
- package/dist/error-codes.d.ts +14 -0
- package/dist/error-codes.d.ts.map +1 -0
- package/dist/error-codes.js +55 -0
- package/dist/error-codes.js.map +1 -0
- package/dist/errors.d.ts +91 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +130 -1
- package/dist/errors.js.map +1 -1
- package/dist/funding.d.ts +43 -0
- package/dist/funding.d.ts.map +1 -0
- package/dist/funding.js +116 -0
- package/dist/funding.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth.d.ts +56 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +68 -0
- package/dist/oauth.js.map +1 -0
- package/dist/registration.d.ts +33 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +49 -0
- package/dist/registration.js.map +1 -0
- package/dist/resources/admin.d.ts +52 -1
- package/dist/resources/admin.d.ts.map +1 -1
- package/dist/resources/admin.js +55 -0
- package/dist/resources/admin.js.map +1 -1
- package/dist/resources/billing.d.ts +242 -0
- package/dist/resources/billing.d.ts.map +1 -0
- package/dist/resources/billing.js +376 -0
- package/dist/resources/billing.js.map +1 -0
- package/dist/resources/chains.d.ts +38 -0
- package/dist/resources/chains.d.ts.map +1 -0
- package/dist/resources/chains.js +46 -0
- package/dist/resources/chains.js.map +1 -0
- package/dist/resources/device.d.ts +43 -0
- package/dist/resources/device.d.ts.map +1 -0
- package/dist/resources/device.js +49 -0
- package/dist/resources/device.js.map +1 -0
- package/dist/resources/execute.d.ts +39 -1
- package/dist/resources/execute.d.ts.map +1 -1
- package/dist/resources/execute.js +41 -1
- package/dist/resources/execute.js.map +1 -1
- package/dist/resources/health.d.ts +34 -0
- package/dist/resources/health.d.ts.map +1 -0
- package/dist/resources/health.js +43 -0
- package/dist/resources/health.js.map +1 -0
- package/dist/resources/identity.d.ts +83 -2
- package/dist/resources/identity.d.ts.map +1 -1
- package/dist/resources/identity.js +154 -2
- package/dist/resources/identity.js.map +1 -1
- package/dist/resources/oauth-clients.d.ts +71 -0
- package/dist/resources/oauth-clients.d.ts.map +1 -0
- package/dist/resources/oauth-clients.js +75 -0
- package/dist/resources/oauth-clients.js.map +1 -0
- package/dist/resources/pending.d.ts +13 -1
- package/dist/resources/pending.d.ts.map +1 -1
- package/dist/resources/pending.js +15 -0
- package/dist/resources/pending.js.map +1 -1
- package/dist/resources/proof.d.ts +75 -0
- package/dist/resources/proof.d.ts.map +1 -0
- package/dist/resources/proof.js +103 -0
- package/dist/resources/proof.js.map +1 -0
- package/dist/resources/registration-tokens.d.ts +51 -0
- package/dist/resources/registration-tokens.d.ts.map +1 -0
- package/dist/resources/registration-tokens.js +54 -0
- package/dist/resources/registration-tokens.js.map +1 -0
- package/dist/resources/transaction.d.ts +20 -0
- package/dist/resources/transaction.d.ts.map +1 -1
- package/dist/resources/transaction.js +28 -0
- package/dist/resources/transaction.js.map +1 -1
- package/dist/resources/transparency.d.ts +68 -0
- package/dist/resources/transparency.d.ts.map +1 -0
- package/dist/resources/transparency.js +83 -0
- package/dist/resources/transparency.js.map +1 -0
- package/dist/resources/webhooks.d.ts +97 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +112 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/self-signup.d.ts +66 -0
- package/dist/self-signup.d.ts.map +1 -0
- package/dist/self-signup.js +76 -0
- package/dist/self-signup.js.map +1 -0
- package/dist/shared-proof.d.ts +34 -0
- package/dist/shared-proof.d.ts.map +1 -0
- package/dist/shared-proof.js +78 -0
- package/dist/shared-proof.js.map +1 -0
- package/dist/types.d.ts +901 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/verify-receipt.d.ts +32 -0
- package/dist/verify-receipt.d.ts.map +1 -0
- package/dist/verify-receipt.js +176 -0
- package/dist/verify-receipt.js.map +1 -0
- package/package.json +6 -5
package/dist/oauth.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DEFAULT_BASE_URL } from './client.js';
|
|
3
|
+
import { CertenError } from './errors.js';
|
|
4
|
+
async function post(path, body, options) {
|
|
5
|
+
const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
6
|
+
try {
|
|
7
|
+
const { data } = await axios.post(`${base}${path}`, body, {
|
|
8
|
+
timeout: options.timeoutMs ?? 30_000,
|
|
9
|
+
headers: { 'Content-Type': 'application/json' },
|
|
10
|
+
});
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
const e = err;
|
|
15
|
+
const status = e.response?.status ?? 0;
|
|
16
|
+
const payload = e.response?.data;
|
|
17
|
+
// OAuth errors use `error` / `error_description` (RFC 6749) rather than this API's usual
|
|
18
|
+
// `error` / `code`, so the message is assembled from whichever arrived.
|
|
19
|
+
const message = payload?.error_description ?? payload?.error ?? e.message;
|
|
20
|
+
throw new CertenError(`certen: ${message}`, status, payload?.code ?? payload?.error ?? (status ? 'OAUTH_ERROR' : 'NETWORK_ERROR'), { body: payload });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Exchange client credentials for an access token.
|
|
25
|
+
*
|
|
26
|
+
* Returns an access token good for an hour and a refresh token good for thirty days.
|
|
27
|
+
*/
|
|
28
|
+
export function fetchOAuthToken(params, options = {}) {
|
|
29
|
+
return post('/v1/oauth/token', {
|
|
30
|
+
grant_type: 'client_credentials',
|
|
31
|
+
client_id: params.clientId,
|
|
32
|
+
client_secret: params.clientSecret,
|
|
33
|
+
...(params.scope ? { scope: params.scope } : {}),
|
|
34
|
+
}, options);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Trade a refresh token for a fresh pair.
|
|
38
|
+
*
|
|
39
|
+
* **The old refresh token is spent the moment this succeeds.** Replaying one that has already been
|
|
40
|
+
* used revokes its entire descendant chain — that is deliberate theft detection, not a bug: if a
|
|
41
|
+
* stolen token is replayed, both the thief's and the victim's tokens die and the compromise
|
|
42
|
+
* surfaces. So store the new pair before doing anything else, and never retry this call blindly
|
|
43
|
+
* with the same token.
|
|
44
|
+
*/
|
|
45
|
+
export function refreshOAuthToken(refreshToken, options = {}) {
|
|
46
|
+
return post('/v1/oauth/token', {
|
|
47
|
+
grant_type: 'refresh_token',
|
|
48
|
+
refresh_token: refreshToken,
|
|
49
|
+
}, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Revoke a token (RFC 7009).
|
|
53
|
+
*
|
|
54
|
+
* Accepts an access token or a refresh token; revoking a REFRESH token kills its whole descendant
|
|
55
|
+
* chain, which is what you want when responding to a leak.
|
|
56
|
+
*
|
|
57
|
+
* Always resolves when the request is understood, even for a token that never existed — the
|
|
58
|
+
* endpoint deliberately does not reveal whether it did, because an endpoint that distinguished them
|
|
59
|
+
* would be an oracle for guessing tokens. So a successful call means "this token is not valid now",
|
|
60
|
+
* not "this token was valid and now is not".
|
|
61
|
+
*/
|
|
62
|
+
export async function revokeOAuthToken(token, options = {}) {
|
|
63
|
+
await post('/v1/oauth/revoke', {
|
|
64
|
+
token,
|
|
65
|
+
...(options.tokenTypeHint ? { token_type_hint: options.tokenTypeHint } : {}),
|
|
66
|
+
}, options);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","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H,MAAM,UAAU,eAAe,CAC7B,MAAkE,EAClE,UAAoB,EAAE;IAEtB,OAAO,IAAI,CAAc,iBAAiB,EAAE;QAC1C,UAAU,EAAE,oBAAoB;QAChC,SAAS,EAAE,MAAM,CAAC,QAAQ;QAC1B,aAAa,EAAE,MAAM,CAAC,YAAY;QAClC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjD,EAAE,OAAO,CAAC,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAAoB,EACpB,UAAoB,EAAE;IAEtB,OAAO,IAAI,CAAc,iBAAiB,EAAE;QAC1C,UAAU,EAAE,eAAe;QAC3B,aAAa,EAAE,YAAY;KAC5B,EAAE,OAAO,CAAC,CAAC;AACd,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAa,EACb,UAA2E,EAAE;IAE7E,MAAM,IAAI,CAAU,kBAAkB,EAAE;QACtC,KAAK;QACL,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7E,EAAE,OAAO,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RedeemedRegistration } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Redeem a registration token for a new organization and its first API key.
|
|
4
|
+
*
|
|
5
|
+
* **Standalone, and necessarily so.** Every other call in this SDK goes through `CertenClient`,
|
|
6
|
+
* which requires a credential — and the entire point of this one is that the caller does not have
|
|
7
|
+
* one yet. Routing it through a constructor that demands `apiKey` would ask for the exact thing it
|
|
8
|
+
* exists to produce. Same reasoning as `fetchSharedProof` and `fetchOAuthToken`.
|
|
9
|
+
*
|
|
10
|
+
* Before this existed, an organization could only be born inside a browser: the Firebase login
|
|
11
|
+
* exchange created one just-in-time when no membership was found. So a platform could not provision
|
|
12
|
+
* its customers, a CI job could not create a scratch org, and an agent could not take its first
|
|
13
|
+
* step — every automated path stopped and waited for a person.
|
|
14
|
+
*
|
|
15
|
+
* A human still decides that an org may exist, by minting the token. What changed is that the
|
|
16
|
+
* decision and the provisioning no longer have to happen at the same keyboard at the same moment.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const { org, api_key } = await redeemRegistrationToken('crt_…');
|
|
20
|
+
* const certen = new CertenClient({ apiKey: api_key });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* **The API key is returned once.** Store it before doing anything else; no endpoint will repeat
|
|
24
|
+
* it. The token is single-use, so a failed store cannot be fixed by redeeming again.
|
|
25
|
+
*/
|
|
26
|
+
export declare function redeemRegistrationToken(token: string, options?: {
|
|
27
|
+
/** Overrides the organization name the minter pinned. */
|
|
28
|
+
orgName?: string;
|
|
29
|
+
/** Defaults to the SDK's configured gateway. */
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
}): Promise<RedeemedRegistration>;
|
|
33
|
+
//# sourceMappingURL=registration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../src/registration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACf,GACL,OAAO,CAAC,oBAAoB,CAAC,CA4B/B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DEFAULT_BASE_URL } from './client.js';
|
|
3
|
+
import { CertenError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Redeem a registration token for a new organization and its first API key.
|
|
6
|
+
*
|
|
7
|
+
* **Standalone, and necessarily so.** Every other call in this SDK goes through `CertenClient`,
|
|
8
|
+
* which requires a credential — and the entire point of this one is that the caller does not have
|
|
9
|
+
* one yet. Routing it through a constructor that demands `apiKey` would ask for the exact thing it
|
|
10
|
+
* exists to produce. Same reasoning as `fetchSharedProof` and `fetchOAuthToken`.
|
|
11
|
+
*
|
|
12
|
+
* Before this existed, an organization could only be born inside a browser: the Firebase login
|
|
13
|
+
* exchange created one just-in-time when no membership was found. So a platform could not provision
|
|
14
|
+
* its customers, a CI job could not create a scratch org, and an agent could not take its first
|
|
15
|
+
* step — every automated path stopped and waited for a person.
|
|
16
|
+
*
|
|
17
|
+
* A human still decides that an org may exist, by minting the token. What changed is that the
|
|
18
|
+
* decision and the provisioning no longer have to happen at the same keyboard at the same moment.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { org, api_key } = await redeemRegistrationToken('crt_…');
|
|
22
|
+
* const certen = new CertenClient({ apiKey: api_key });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **The API key is returned once.** Store it before doing anything else; no endpoint will repeat
|
|
26
|
+
* it. The token is single-use, so a failed store cannot be fixed by redeeming again.
|
|
27
|
+
*/
|
|
28
|
+
export async function redeemRegistrationToken(token, options = {}) {
|
|
29
|
+
const base = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
30
|
+
try {
|
|
31
|
+
const { data } = await axios.post(`${base}/v1/registration-tokens/redeem`, { token, ...(options.orgName ? { org_name: options.orgName } : {}) }, { timeout: options.timeoutMs ?? 30_000, headers: { 'Content-Type': 'application/json' } });
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
const e = err;
|
|
36
|
+
const status = e.response?.status ?? 0;
|
|
37
|
+
const payload = e.response?.data;
|
|
38
|
+
// A 404 here does NOT mean "wrong URL". The gateway deliberately reports unknown, expired,
|
|
39
|
+
// revoked and already-redeemed tokens identically, so that an endpoint needing no credential
|
|
40
|
+
// cannot be used to probe which guesses were close. Say that plainly, or the caller will go
|
|
41
|
+
// looking for a typo in the base URL.
|
|
42
|
+
const message = status === 404
|
|
43
|
+
? 'certen: this registration token cannot be redeemed — it is unknown, expired, revoked, or '
|
|
44
|
+
+ 'already used. These are reported identically on purpose. Ask for a new token.'
|
|
45
|
+
: payload?.error ?? e.message;
|
|
46
|
+
throw new CertenError(status === 404 ? message : `certen: ${message}`, status, payload?.code ?? (status ? 'REGISTRATION_FAILED' : 'NETWORK_ERROR'), { body: payload });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../src/registration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAa,EACb,UAMI,EAAE;IAEN,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvE,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,IAAI,CAC/B,GAAG,IAAI,gCAAgC,EACvC,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EACpE,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,CAC1F,CAAC;QACF,OAAO,IAA4B,CAAC;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,GAAG,GAAoD,CAAC;QAC/D,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,CAAC;QACvC,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC;QACjC,2FAA2F;QAC3F,6FAA6F;QAC7F,4FAA4F;QAC5F,sCAAsC;QACtC,MAAM,OAAO,GAAG,MAAM,KAAK,GAAG;YAC5B,CAAC,CAAC,2FAA2F;kBACzF,+EAA+E;YACnF,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC;QAChC,MAAM,IAAI,WAAW,CACnB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,OAAO,EAAE,EAC/C,MAAM,EACN,OAAO,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,eAAe,CAAC,EACnE,EAAE,IAAI,EAAE,OAAO,EAAE,CAClB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import type { CreateOrgParams, OrgResponse, CreateApiKeyParams, ApiKeyResponse, ApiKeyListItem, AuditLogResponse, UsageSummaryResponse } from '../types.js';
|
|
2
|
+
import type { CreateOrgParams, OrgResponse, CreateApiKeyParams, ApiKeyResponse, ApiKeyListItem, AuditLogResponse, AuditLogEntry, UsageSummaryResponse, ScopeInfo, ErrorCodeInfo } from '../types.js';
|
|
3
3
|
export declare class AdminResource {
|
|
4
4
|
private http;
|
|
5
5
|
constructor(http: AxiosInstance);
|
|
6
|
+
/**
|
|
7
|
+
* Every permission a key can be granted, and what each one covers.
|
|
8
|
+
*
|
|
9
|
+
* Read this before minting a key. The vocabulary was published nowhere, so the choice was made by
|
|
10
|
+
* guessing — and guessing wrong is asymmetric: under-grant and you get 403s, which are visible;
|
|
11
|
+
* over-grant, and the obvious answer to uncertainty is `*`, which hands a key that only needed to
|
|
12
|
+
* read a balance the ability to retire identities and publish price books.
|
|
13
|
+
*
|
|
14
|
+
* Needs no API key: choosing permissions should not require already holding one.
|
|
15
|
+
*/
|
|
16
|
+
scopes(): Promise<{
|
|
17
|
+
scopes: ScopeInfo[];
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Every error code this API can return, and what to do about each.
|
|
21
|
+
*
|
|
22
|
+
* Reads the catalogue from the LIVE gateway, which is the point: the SDK ships a vendored copy in
|
|
23
|
+
* `spec/errors.json`, but that copy is only as current as the release, and a gateway ahead of the
|
|
24
|
+
* SDK raises codes the vendored file has never heard of. Asking the deployment you are actually
|
|
25
|
+
* talking to is the only way to see those.
|
|
26
|
+
*
|
|
27
|
+
* `retryable` answers "will repeating this exact request eventually work?" — not "whose fault is
|
|
28
|
+
* it". A 503 from an unavailable rate oracle is retryable; a 402 is not, because retrying without
|
|
29
|
+
* paying changes nothing.
|
|
30
|
+
*
|
|
31
|
+
* Needs no API key: error handling should be buildable before you hold a credential.
|
|
32
|
+
*/
|
|
33
|
+
errors(): Promise<{
|
|
34
|
+
errors: ErrorCodeInfo[];
|
|
35
|
+
}>;
|
|
6
36
|
createOrg(params: CreateOrgParams): Promise<OrgResponse>;
|
|
7
37
|
createApiKey(params: CreateApiKeyParams): Promise<ApiKeyResponse>;
|
|
8
38
|
listApiKeys(): Promise<{
|
|
@@ -26,6 +56,27 @@ export declare class AdminResource {
|
|
|
26
56
|
limit?: number;
|
|
27
57
|
offset?: number;
|
|
28
58
|
}): Promise<AuditLogResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Every audit-log entry matching the filters, a page at a time.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* for await (const { item, index, total } of certen.admin.auditLogAll({ from })) {
|
|
64
|
+
* process.stdout.write(`
|
|
65
|
+
${index + 1} of ${total}`);
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* Yields `{ item, index, total }` rather than bare entries — unlike the other `listAll`s, because
|
|
70
|
+
* this endpoint DOES return a total and an audit export is the case where a caller genuinely
|
|
71
|
+
* needs it: these run long enough to want a progress line, and long enough that a silent early
|
|
72
|
+
* stop matters. Reading the full log by hand meant tracking the offset against
|
|
73
|
+
* `pagination.total`, which is the arithmetic this exists to stop people writing.
|
|
74
|
+
*/
|
|
75
|
+
auditLogAll(params?: Omit<Parameters<AdminResource['getAuditLog']>[0], 'limit' | 'offset'>, pageSize?: number): AsyncIterableIterator<{
|
|
76
|
+
item: AuditLogEntry;
|
|
77
|
+
index: number;
|
|
78
|
+
total: number | undefined;
|
|
79
|
+
}>;
|
|
29
80
|
getUsage(params?: {
|
|
30
81
|
from?: string;
|
|
31
82
|
to?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/resources/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/resources/admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,SAAS,EACT,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,q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AE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAUrF,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;CASvF"}
|
package/dist/resources/admin.js
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
|
+
import { paginateWithTotal } from '../client.js';
|
|
1
2
|
export class AdminResource {
|
|
2
3
|
http;
|
|
3
4
|
constructor(http) {
|
|
4
5
|
this.http = http;
|
|
5
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Every permission a key can be granted, and what each one covers.
|
|
9
|
+
*
|
|
10
|
+
* Read this before minting a key. The vocabulary was published nowhere, so the choice was made by
|
|
11
|
+
* guessing — and guessing wrong is asymmetric: under-grant and you get 403s, which are visible;
|
|
12
|
+
* over-grant, and the obvious answer to uncertainty is `*`, which hands a key that only needed to
|
|
13
|
+
* read a balance the ability to retire identities and publish price books.
|
|
14
|
+
*
|
|
15
|
+
* Needs no API key: choosing permissions should not require already holding one.
|
|
16
|
+
*/
|
|
17
|
+
async scopes() {
|
|
18
|
+
const { data } = await this.http.get('/v1/scopes');
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Every error code this API can return, and what to do about each.
|
|
23
|
+
*
|
|
24
|
+
* Reads the catalogue from the LIVE gateway, which is the point: the SDK ships a vendored copy in
|
|
25
|
+
* `spec/errors.json`, but that copy is only as current as the release, and a gateway ahead of the
|
|
26
|
+
* SDK raises codes the vendored file has never heard of. Asking the deployment you are actually
|
|
27
|
+
* talking to is the only way to see those.
|
|
28
|
+
*
|
|
29
|
+
* `retryable` answers "will repeating this exact request eventually work?" — not "whose fault is
|
|
30
|
+
* it". A 503 from an unavailable rate oracle is retryable; a 402 is not, because retrying without
|
|
31
|
+
* paying changes nothing.
|
|
32
|
+
*
|
|
33
|
+
* Needs no API key: error handling should be buildable before you hold a credential.
|
|
34
|
+
*/
|
|
35
|
+
async errors() {
|
|
36
|
+
const { data } = await this.http.get('/v1/errors');
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
6
39
|
async createOrg(params) {
|
|
7
40
|
const { data } = await this.http.post('/v1/admin/org', {
|
|
8
41
|
name: params.name,
|
|
@@ -51,6 +84,28 @@ export class AdminResource {
|
|
|
51
84
|
});
|
|
52
85
|
return data;
|
|
53
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Every audit-log entry matching the filters, a page at a time.
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* for await (const { item, index, total } of certen.admin.auditLogAll({ from })) {
|
|
92
|
+
* process.stdout.write(`
|
|
93
|
+
${index + 1} of ${total}`);
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* Yields `{ item, index, total }` rather than bare entries — unlike the other `listAll`s, because
|
|
98
|
+
* this endpoint DOES return a total and an audit export is the case where a caller genuinely
|
|
99
|
+
* needs it: these run long enough to want a progress line, and long enough that a silent early
|
|
100
|
+
* stop matters. Reading the full log by hand meant tracking the offset against
|
|
101
|
+
* `pagination.total`, which is the arithmetic this exists to stop people writing.
|
|
102
|
+
*/
|
|
103
|
+
auditLogAll(params, pageSize = 100) {
|
|
104
|
+
return paginateWithTotal(async (limit, offset) => {
|
|
105
|
+
const page = await this.getAuditLog({ ...params, limit, offset });
|
|
106
|
+
return { items: page.entries ?? [], total: page.pagination?.total };
|
|
107
|
+
}, pageSize);
|
|
108
|
+
}
|
|
54
109
|
async getUsage(params) {
|
|
55
110
|
const { data } = await this.http.get('/v1/admin/usage', {
|
|
56
111
|
params: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/resources/admin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/resources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K,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;QACtE,CAAC,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAuC;QACpD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACtD,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,EAAE,IAAI;gBAClB,EAAE,EAAE,MAAM,EAAE,EAAE;aACf;SACF,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { type CertenClient } from '../client.js';
|
|
3
|
+
import type { BalanceResponse, QuoteResponse, ObligationsResponse, DepositTarget, DepositIntentStatus, PaymentRecord, PricingCatalog, PayerAddress, LedgerEntry, ReceiptSummary, Receipt, ReceiptProof, VerificationKeys, ReceiptVerification, Pagination } from '../types.js';
|
|
4
|
+
export declare class BillingResource {
|
|
5
|
+
private http;
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* `client` is the whole client, not just its HTTP handle, because verifying a receipt has to
|
|
9
|
+
* reach the transparency log as well as billing. It is captured, never dereferenced during
|
|
10
|
+
* construction — the client assigns its resources in sequence, so `transparency` does not exist
|
|
11
|
+
* yet at this point but always does by the time anything here runs.
|
|
12
|
+
*/
|
|
13
|
+
constructor(http: AxiosInstance, client: CertenClient);
|
|
14
|
+
/**
|
|
15
|
+
* Every priced operation and what it costs — one call, no guessing.
|
|
16
|
+
*
|
|
17
|
+
* `quote()` prices ONE sku on ONE chain and needs the sku name up front, which is the problem:
|
|
18
|
+
* the names are not guessable (`identity.provision`, not `identity.create`), and nothing listed
|
|
19
|
+
* them. Discovering the price of onboarding meant guessing a name, being refused, and guessing
|
|
20
|
+
* again.
|
|
21
|
+
*
|
|
22
|
+
* Use this to find the sku, then `quote()` to get a binding price for a specific piece of work.
|
|
23
|
+
* Requires `billing:read`.
|
|
24
|
+
*/
|
|
25
|
+
pricing(): Promise<PricingCatalog>;
|
|
26
|
+
/** Available, held, credit line, and spendable. Requires `billing:read`. */
|
|
27
|
+
balance(): Promise<BalanceResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Price a piece of work before committing to it.
|
|
30
|
+
*
|
|
31
|
+
* Free, and the answer binds: pass the returned `id` as `quote_id` on the
|
|
32
|
+
* transaction and that is the price, regardless of what gas does in between.
|
|
33
|
+
* A quote is single-use and expires, so ask when you are ready to act.
|
|
34
|
+
*
|
|
35
|
+
* Worth checking `computation.gas_estimate_basis` on a cost-plus chain. A
|
|
36
|
+
* `class_thin` basis means the proof class has its own cost history but too
|
|
37
|
+
* little of it for the median to be stable — the number is indicative, and
|
|
38
|
+
* can move materially as more of that class executes.
|
|
39
|
+
*/
|
|
40
|
+
quote(params: {
|
|
41
|
+
chain: string;
|
|
42
|
+
proofClass?: 'on_demand' | 'on_cadence';
|
|
43
|
+
legCount?: number;
|
|
44
|
+
sku?: string;
|
|
45
|
+
additionalChains?: string[];
|
|
46
|
+
}): Promise<QuoteResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Re-read a quote you already have.
|
|
49
|
+
*
|
|
50
|
+
* Quotes are single-use and expire, and there was no way to ask about one after it was issued —
|
|
51
|
+
* so a caller who priced some work, got interrupted, and came back had to either guess whether
|
|
52
|
+
* their quote was still good or throw it away and ask again. Guessing wrong means a 400 in the
|
|
53
|
+
* middle of a transaction; throwing it away means the price can move underneath them.
|
|
54
|
+
*
|
|
55
|
+
* `quote()` CREATES; this one READS. Requires `billing:read`.
|
|
56
|
+
*/
|
|
57
|
+
quoteById(id: string): Promise<QuoteResponse & {
|
|
58
|
+
seconds_remaining: number | null;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* Pending intents and what they will cost — including `remaining_usd`, the
|
|
62
|
+
* amount that may actually be committed to new work.
|
|
63
|
+
*/
|
|
64
|
+
obligations(): Promise<ObligationsResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Every balance change, newest first. Requires `billing:read`.
|
|
67
|
+
*
|
|
68
|
+
* The append-only, double-entry record behind the balance: what moved, when, and why. Corrections
|
|
69
|
+
* appear as new REVERSING entries rather than edits, so the history is what happened.
|
|
70
|
+
*
|
|
71
|
+
* Use `ledgerAll()` to walk the whole thing.
|
|
72
|
+
*/
|
|
73
|
+
ledger(params?: {
|
|
74
|
+
limit?: number;
|
|
75
|
+
offset?: number;
|
|
76
|
+
}): Promise<{
|
|
77
|
+
entries: LedgerEntry[];
|
|
78
|
+
pagination?: Pagination;
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Every ledger entry, paging automatically.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* for await (const entry of certen.billing.ledgerAll()) { ... }
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* The endpoint returns no total and no `has_more`, so termination is inferred from a short page —
|
|
88
|
+
* which is why this belongs here once rather than in every caller that gets the condition subtly
|
|
89
|
+
* wrong and silently reports a partial ledger as complete.
|
|
90
|
+
*/
|
|
91
|
+
ledgerAll(pageSize?: number): AsyncIterableIterator<LedgerEntry>;
|
|
92
|
+
/** Signed receipts for every payment, charge, refund and adjustment. Requires `billing:read`. */
|
|
93
|
+
receipts(params?: {
|
|
94
|
+
limit?: number;
|
|
95
|
+
offset?: number;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
receipts: ReceiptSummary[];
|
|
98
|
+
pagination?: Pagination;
|
|
99
|
+
}>;
|
|
100
|
+
/** Every receipt, paging automatically. */
|
|
101
|
+
receiptsAll(pageSize?: number): AsyncIterableIterator<ReceiptSummary>;
|
|
102
|
+
/**
|
|
103
|
+
* One receipt, with its signature, its computation inputs, and the gateway's own verification.
|
|
104
|
+
*
|
|
105
|
+
* `verification` is CERTEN checking CERTEN, which settles nothing by itself. What makes the
|
|
106
|
+
* receipt evidence is that every check in it is reproducible by you: verify `signature` against
|
|
107
|
+
* `verificationKeys()`, reproduce `digest` from `body`, and fetch `receiptProof()` to show the
|
|
108
|
+
* receipt is in a log that was anchored on Accumulate.
|
|
109
|
+
*/
|
|
110
|
+
receipt(id: string): Promise<Receipt>;
|
|
111
|
+
/**
|
|
112
|
+
* The transparency-log inclusion proof for a receipt.
|
|
113
|
+
*
|
|
114
|
+
* **Store it alongside the receipt.** It remains valid forever against the tree head it names,
|
|
115
|
+
* and that head is pinned on Accumulate — so the proof outlives any cooperation from CERTEN,
|
|
116
|
+
* which is the entire point of it existing.
|
|
117
|
+
*
|
|
118
|
+
* Defaults to the newest ANCHORED head; a proof against an unanchored head is only as good as our
|
|
119
|
+
* word. Only receipts with `logged: true` have one — expect a 404 otherwise.
|
|
120
|
+
*/
|
|
121
|
+
receiptProof(id: string, params?: {
|
|
122
|
+
treeSize?: number;
|
|
123
|
+
}): Promise<ReceiptProof>;
|
|
124
|
+
/**
|
|
125
|
+
* The public keys receipts and tree heads are signed with.
|
|
126
|
+
*
|
|
127
|
+
* Deliberately unauthenticated on the gateway, and it should stay that way in your integration
|
|
128
|
+
* too: a verification key you can only obtain by asking us nicely could not settle a dispute
|
|
129
|
+
* with us.
|
|
130
|
+
*/
|
|
131
|
+
verificationKeys(): Promise<VerificationKeys>;
|
|
132
|
+
/**
|
|
133
|
+
* Check a receipt yourself, against independently published data.
|
|
134
|
+
*
|
|
135
|
+
* Recomputes the digest from the body, verifies the ed25519 signature against the PUBLISHED key
|
|
136
|
+
* set, recomputes the salted leaf, folds the RFC 6962 audit path, and compares the result with a
|
|
137
|
+
* signed tree head fetched separately — not with the root that travelled inside the proof, which
|
|
138
|
+
* would be comparing the proof with itself.
|
|
139
|
+
*
|
|
140
|
+
* Never throws for a failed check: `verified` is false and the reason is in `checks`. A check that
|
|
141
|
+
* could not be run is `skipped`, and `complete` goes false — a verifier that cannot reach the log
|
|
142
|
+
* must say so rather than imply a pass.
|
|
143
|
+
*/
|
|
144
|
+
verifyReceipt(id: string): Promise<ReceiptVerification>;
|
|
145
|
+
/**
|
|
146
|
+
* Register a wallet you pay from, so every future deposit from it credits automatically.
|
|
147
|
+
*
|
|
148
|
+
* This is the difference between funding once and funding repeatedly. `openPayment` opens a
|
|
149
|
+
* single-use intent matched on the EXACT amount within a TTL — right for a first deposit, and a
|
|
150
|
+
* step before every send thereafter. A registered address needs none of that: money arriving from
|
|
151
|
+
* it is attributed to this organization on sight.
|
|
152
|
+
*
|
|
153
|
+
* **The gateway's own 402 recommends doing this, and until now no client could.** Its `how_to_pay`
|
|
154
|
+
* block names `POST /v1/billing/deposit-addresses` as the recommended fix, while this SDK omitted
|
|
155
|
+
* it on the stated grounds that it needed a portal session rather than a machine key. That was
|
|
156
|
+
* wrong: the endpoint takes an API key with `billing:write`, which is exactly what an autonomous
|
|
157
|
+
* caller settling its own 402 is holding.
|
|
158
|
+
*
|
|
159
|
+
* An address belongs to ONE organization per chain. A duplicate is rejected rather than merged,
|
|
160
|
+
* because ambiguous attribution means crediting the wrong customer — expect a 409.
|
|
161
|
+
*/
|
|
162
|
+
registerPayerAddress(params: {
|
|
163
|
+
chain: string;
|
|
164
|
+
address: string;
|
|
165
|
+
label?: string;
|
|
166
|
+
}): Promise<PayerAddress>;
|
|
167
|
+
/** Wallets registered for automatic attribution. Requires `billing:read`. */
|
|
168
|
+
payerAddresses(): Promise<{
|
|
169
|
+
addresses: PayerAddress[];
|
|
170
|
+
}>;
|
|
171
|
+
/**
|
|
172
|
+
* Where to send stablecoin, optionally opening a single-use payment matched on
|
|
173
|
+
* the exact amount.
|
|
174
|
+
*
|
|
175
|
+
* Omit `amountUsd` to read the deposit address without opening anything — an
|
|
176
|
+
* intent for an unspecified amount could never be matched. Requires
|
|
177
|
+
* `billing:fund` (or `billing:write`).
|
|
178
|
+
*/
|
|
179
|
+
openPayment(params: {
|
|
180
|
+
chain: string;
|
|
181
|
+
amountUsd?: string;
|
|
182
|
+
}): Promise<DepositTarget>;
|
|
183
|
+
/**
|
|
184
|
+
* Status of a payment you opened. Requires `billing:read`.
|
|
185
|
+
*
|
|
186
|
+
* Use this rather than watching the balance: a second deposit or a charge in the
|
|
187
|
+
* same window moves the balance too, so inferring from it reports the wrong
|
|
188
|
+
* payment as matched.
|
|
189
|
+
*/
|
|
190
|
+
/**
|
|
191
|
+
* Payments the gateway has seen, most recent first.
|
|
192
|
+
*
|
|
193
|
+
* Distinct from a deposit INTENT. A payment can be credited without ever matching an intent —
|
|
194
|
+
* see `waitForPayment` — so this is the record that says whether money actually arrived.
|
|
195
|
+
*/
|
|
196
|
+
payments(params?: {
|
|
197
|
+
limit?: number;
|
|
198
|
+
}): Promise<{
|
|
199
|
+
payments: PaymentRecord[];
|
|
200
|
+
pagination?: Pagination;
|
|
201
|
+
}>;
|
|
202
|
+
payment(reference: string): Promise<DepositIntentStatus>;
|
|
203
|
+
/**
|
|
204
|
+
* Resolve once the payment is credited, or when it expires.
|
|
205
|
+
*
|
|
206
|
+
* Returns the terminal status rather than throwing on expiry — an expired
|
|
207
|
+
* payment is an ordinary outcome the caller should report, not an error. Only a
|
|
208
|
+
* genuine transport or auth failure throws.
|
|
209
|
+
*
|
|
210
|
+
* **It watches the payment feed as well as the intent, and that is not belt-and-braces.**
|
|
211
|
+
*
|
|
212
|
+
* It began as a workaround for a gateway bug: the gateway closed a deposit intent only when the
|
|
213
|
+
* payment had been attributed BY that intent, and since attribution tries a registered payer
|
|
214
|
+
* address first — and the funding flow registers the sender — a paid intent was never closed.
|
|
215
|
+
* Observed live: 1 USDC credited in seconds with `attribution: registered_address` while the
|
|
216
|
+
* intent sat `open` with `matched_at: null`, until it expired an hour later. Watching only the
|
|
217
|
+
* intent reported "not credited" on money that had already arrived. The gateway now closes the
|
|
218
|
+
* intent on credit regardless of how the org was identified.
|
|
219
|
+
*
|
|
220
|
+
* The feed watch stays, for two reasons that outlive that bug. The SDK is versioned separately
|
|
221
|
+
* and is regularly pointed at an older gateway, where the old behaviour is still live. And the
|
|
222
|
+
* intent can only ever report money that matched it: a deposit for the wrong amount, or one sent
|
|
223
|
+
* before the intent was opened, still credits the balance and still answers the caller's actual
|
|
224
|
+
* question — did my money arrive.
|
|
225
|
+
*
|
|
226
|
+
* On that path the returned status is synthesised with `status: 'matched'` and the credited
|
|
227
|
+
* payment's id, because from the caller's point of view the money arrived.
|
|
228
|
+
*/
|
|
229
|
+
waitForPayment(reference: string, opts?: {
|
|
230
|
+
intervalMs?: number;
|
|
231
|
+
timeoutMs?: number;
|
|
232
|
+
onPoll?: (status: DepositIntentStatus) => void;
|
|
233
|
+
}): Promise<DepositIntentStatus>;
|
|
234
|
+
/**
|
|
235
|
+
* A credited payment of this amount that arrived after `since`, if there is one.
|
|
236
|
+
*
|
|
237
|
+
* Returns null on any failure: an unavailable payments feed must never turn a wait that would
|
|
238
|
+
* otherwise have succeeded into an error, and the intent poll above remains the primary signal.
|
|
239
|
+
*/
|
|
240
|
+
private creditedSince;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,EACX,cAAc,EACd,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACX,MAAM,aAAa,CAAC;AAqCrB,qBAAa,eAAe;IAOd,OAAO,CAAC,IAAI;IAAiB,OAAO,CAAC,MAAM;IANvD;;;;;OAKG;gBACiB,IAAI,EAAE,aAAa,EAAU,MAAM,EAAE,YAAY;IAErE;;;;;;;;;;OAUG;IACG,OA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