@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/resources/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/resources/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAqB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvH;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,MAAM;IACrB,2GAA2G;IAC3G,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,aAAa,C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AE;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;KACzC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAqBpC;;;;;OAKG;IACG,IAAI,CACR,QAAQ,EAAE,MAAM,EAChB,EAAE,SAAmB,EAAE,UAAkB,EAAE,MAAM,EAAE,GAAE;QACnD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,mBAAmB,KAAK,IAAI,CAAC;KACvC,GACL,OAAO,CAAC,mBAAmB,CAAC;IAoB/B;;;;;;OAMG;IACG,KAAK,CACT,QAAQ,EAAE,MAAM,EAChB,EAAE,SAA4B,EAAE,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5D,OAAO,CACN;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,mBAAmB,CAAA;KAAE,GACtF;QAAE,IAAI,EAAE,oBAAoB,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,mBAAmB,CAAA;KAAE,CAChG;YAiBa,IAAI;CAmCnB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
1
2
|
import { omitUndefined } from '../internal.js';
|
|
3
|
+
import { assertFundedForValue } from '../funding.js';
|
|
2
4
|
/** Terminal states. `wait()` stops on these rather than polling forever. */
|
|
3
5
|
const DONE = ['completed', 'delivered', 'proven'];
|
|
4
6
|
const FAILED = ['failed', 'error'];
|
|
@@ -25,6 +27,15 @@ export class ExecuteResource {
|
|
|
25
27
|
* signature is in — which on an M-of-N page is not the same as executed. Follow with `wait()`.
|
|
26
28
|
*/
|
|
27
29
|
async contractCall(p) {
|
|
30
|
+
// Before the intent exists, not after: an intent that can never execute should never be
|
|
31
|
+
// opened. A call forwarding no value is unaffected — the guard checks the amount first.
|
|
32
|
+
if (!p.skipFundingCheck) {
|
|
33
|
+
await assertFundedForValue(this.http, {
|
|
34
|
+
identityId: p.identityId,
|
|
35
|
+
chain: p.chain,
|
|
36
|
+
amount: p.contractCall.value,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
28
39
|
const intent = {
|
|
29
40
|
adiUrl: p.adiUrl,
|
|
30
41
|
legs: [{
|
|
@@ -42,16 +53,44 @@ export class ExecuteResource {
|
|
|
42
53
|
return this.open({
|
|
43
54
|
identity_id: p.identityId,
|
|
44
55
|
intent,
|
|
45
|
-
contract_addresses
|
|
56
|
+
// NOT the call target. `contract_addresses` names the CERTEN deployment (anchor, anchorV2,
|
|
57
|
+
// abstractAccount, entryPoint, factory) and must be an OBJECT — this sent `[target]`, which
|
|
58
|
+
// the endpoint rejects with `/contract_addresses must be object`, so every contractCall
|
|
59
|
+
// failed with a 400 naming a field the caller never set. The gateway applies the right
|
|
60
|
+
// defaults when it is omitted, so omitting it is correct; `contractAddresses` overrides it
|
|
61
|
+
// only for a non-standard deployment.
|
|
62
|
+
contract_addresses: p.contractAddresses,
|
|
46
63
|
signer_public_key: p.signerPublicKey ?? p.publicKey,
|
|
64
|
+
proof_class: p.proofClass,
|
|
47
65
|
signer_key_page: p.signerKeyPage,
|
|
48
66
|
}, p.sign, p.signerPublicKey ?? p.publicKey, p.idempotencyKey);
|
|
49
67
|
}
|
|
50
68
|
/** Authorize a native transfer, gated on proof. Same flow, simpler intent. */
|
|
51
69
|
async transfer(p) {
|
|
70
|
+
if (!p.skipFundingCheck) {
|
|
71
|
+
await assertFundedForValue(this.http, {
|
|
72
|
+
identityId: p.identityId,
|
|
73
|
+
// The abstract account that pays is the one on the chain the value lands on.
|
|
74
|
+
chain: p.toChain,
|
|
75
|
+
amount: p.amount,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
52
78
|
return this.open({
|
|
53
79
|
identity_id: p.identityId,
|
|
54
80
|
intent: {
|
|
81
|
+
// The upstream native-transfer path requires adiUrl, id, initiatedBy AND timestamp, none of
|
|
82
|
+
// which appear in the transfer shape the API documents. Omitting any one of them produces a
|
|
83
|
+
// bodyless 502 rather than a validation error: `adiUrl` is dereferenced with no null check,
|
|
84
|
+
// and `new Date(intent.timestamp).toISOString()` throws RangeError on undefined. Verified
|
|
85
|
+
// field by field against the live gateway — see certenIO/accumulate-api-bridge#1.
|
|
86
|
+
//
|
|
87
|
+
// The multi-leg branch upstream already defaults id/initiatedBy/timestamp itself; this path
|
|
88
|
+
// does not, so the SDK supplies them. Once the upstream defaults them too, these become
|
|
89
|
+
// harmless no-ops rather than load-bearing.
|
|
90
|
+
adiUrl: p.adiUrl,
|
|
91
|
+
id: randomUUID(),
|
|
92
|
+
initiatedBy: p.adiUrl,
|
|
93
|
+
timestamp: Date.now(),
|
|
55
94
|
fromChain: p.fromChain,
|
|
56
95
|
toChain: p.toChain,
|
|
57
96
|
fromAddress: p.fromAddress,
|
|
@@ -60,6 +99,7 @@ export class ExecuteResource {
|
|
|
60
99
|
tokenSymbol: p.tokenSymbol,
|
|
61
100
|
},
|
|
62
101
|
signer_public_key: p.signerPublicKey ?? p.publicKey,
|
|
102
|
+
proof_class: p.proofClass,
|
|
63
103
|
signer_key_page: p.signerKeyPage,
|
|
64
104
|
}, p.sign, p.signerPublicKey ?? p.publicKey, p.idempotencyKey);
|
|
65
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/resources/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1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O,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import type { ReadinessReport } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Is CERTEN able to serve right now?
|
|
5
|
+
*
|
|
6
|
+
* This answers the question that decides where someone should look when things do not work, and
|
|
7
|
+
* getting it wrong sends them somewhere useless. `GET /v1/chains` — which is what `doctor` used to
|
|
8
|
+
* lean on — proves only that the gateway is answering HTTP; it is a static registry read that keeps
|
|
9
|
+
* succeeding while the database, the api-bridge, the proof service or Accumulate are down. So the
|
|
10
|
+
* diagnosis said "gateway reachable: ok" and the user went looking at their own configuration for a
|
|
11
|
+
* fault that was never theirs.
|
|
12
|
+
*
|
|
13
|
+
* The case that matters most is `sponsor_below_floor`. When the onboarding sponsor account runs
|
|
14
|
+
* dry, identity creation still returns 202 and then never completes — the single worst failure mode
|
|
15
|
+
* in onboarding, because every visible signal says it worked. The probe reports it; nothing on the
|
|
16
|
+
* client side could see it.
|
|
17
|
+
*
|
|
18
|
+
* Public: no API key. That is deliberate on the gateway's side, and useful here — it means a
|
|
19
|
+
* caller whose credential is rejected can still find out whether the platform is the problem.
|
|
20
|
+
*/
|
|
21
|
+
export declare class HealthResource {
|
|
22
|
+
private http;
|
|
23
|
+
constructor(http: AxiosInstance);
|
|
24
|
+
/**
|
|
25
|
+
* Whether the gateway can serve, and what is wrong when it cannot.
|
|
26
|
+
*
|
|
27
|
+
* **Does not throw on 503.** A not-ready answer is the answer — it carries the reasons, and
|
|
28
|
+
* turning it into an exception would discard exactly the information worth having. Only a genuine
|
|
29
|
+
* transport failure throws, which is itself the distinct and useful signal that nothing is
|
|
30
|
+
* answering at all.
|
|
31
|
+
*/
|
|
32
|
+
ready(): Promise<ReadinessReport>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/resources/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEvC;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;CAUxC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is CERTEN able to serve right now?
|
|
3
|
+
*
|
|
4
|
+
* This answers the question that decides where someone should look when things do not work, and
|
|
5
|
+
* getting it wrong sends them somewhere useless. `GET /v1/chains` — which is what `doctor` used to
|
|
6
|
+
* lean on — proves only that the gateway is answering HTTP; it is a static registry read that keeps
|
|
7
|
+
* succeeding while the database, the api-bridge, the proof service or Accumulate are down. So the
|
|
8
|
+
* diagnosis said "gateway reachable: ok" and the user went looking at their own configuration for a
|
|
9
|
+
* fault that was never theirs.
|
|
10
|
+
*
|
|
11
|
+
* The case that matters most is `sponsor_below_floor`. When the onboarding sponsor account runs
|
|
12
|
+
* dry, identity creation still returns 202 and then never completes — the single worst failure mode
|
|
13
|
+
* in onboarding, because every visible signal says it worked. The probe reports it; nothing on the
|
|
14
|
+
* client side could see it.
|
|
15
|
+
*
|
|
16
|
+
* Public: no API key. That is deliberate on the gateway's side, and useful here — it means a
|
|
17
|
+
* caller whose credential is rejected can still find out whether the platform is the problem.
|
|
18
|
+
*/
|
|
19
|
+
export class HealthResource {
|
|
20
|
+
http;
|
|
21
|
+
constructor(http) {
|
|
22
|
+
this.http = http;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether the gateway can serve, and what is wrong when it cannot.
|
|
26
|
+
*
|
|
27
|
+
* **Does not throw on 503.** A not-ready answer is the answer — it carries the reasons, and
|
|
28
|
+
* turning it into an exception would discard exactly the information worth having. Only a genuine
|
|
29
|
+
* transport failure throws, which is itself the distinct and useful signal that nothing is
|
|
30
|
+
* answering at all.
|
|
31
|
+
*/
|
|
32
|
+
async ready() {
|
|
33
|
+
const { data, status } = await this.http.get('/v1/health/ready', {
|
|
34
|
+
// 503 is a documented outcome of this endpoint, not an error in it.
|
|
35
|
+
validateStatus: (s) => s === 200 || s === 503,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
...data,
|
|
39
|
+
ready: status === 200 && data?.status === 'ready',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/resources/health.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAE3C;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE;YAC/D,oEAAoE;YACpE,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;SAC9C,CAAC,CAAC;QACH,OAAO;YACL,GAAG,IAAI;YACP,KAAK,EAAE,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,OAAO;SAClD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import type { CreateIdentityParams, IdentityResponse, UpdateIdentityParams } from '../types.js';
|
|
2
|
+
import type { CreateIdentityParams, Identity, IdentityResponse, UpdateIdentityParams } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Accept what the gateway actually handed the caller.
|
|
5
|
+
*
|
|
6
|
+
* `mnemonic_retrieval.url` is a path, not an id and a token — so a method taking `(id, token)` only
|
|
7
|
+
* would make every caller split a string, and splitting it wrongly costs them the seed. Both forms
|
|
8
|
+
* are accepted, and an absolute URL works too in case the gateway ever returns one.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseMnemonicTarget(idOrUrl: string, token?: string): {
|
|
11
|
+
id: string;
|
|
12
|
+
token: string;
|
|
13
|
+
};
|
|
3
14
|
export declare class IdentityResource {
|
|
4
15
|
private http;
|
|
5
16
|
constructor(http: AxiosInstance);
|
|
@@ -20,7 +31,46 @@ export declare class IdentityResource {
|
|
|
20
31
|
* as a query string, where it was silently ignored — so the signature promised a capability the API does
|
|
21
32
|
* not have.
|
|
22
33
|
*/
|
|
23
|
-
get(id: string
|
|
34
|
+
get(id: string, opts?: {
|
|
35
|
+
/**
|
|
36
|
+
* Which enrichments to fetch. Defaults to ALL THREE, and each costs a live query —
|
|
37
|
+
* `governance` and `balances` hit the network, `balances` once PER LINKED CHAIN.
|
|
38
|
+
*
|
|
39
|
+
* Pass `[]` to skip them entirely. `status` and `can_sign` are computed before any
|
|
40
|
+
* enrichment runs and are always returned, so anything polling for readiness wants `[]`.
|
|
41
|
+
*/
|
|
42
|
+
include?: Array<'governance' | 'balances' | 'pending'>;
|
|
43
|
+
}): Promise<IdentityResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Create an identity and wait until it is genuinely usable.
|
|
46
|
+
*
|
|
47
|
+
* `create()` returns `202` and provisioning continues, so the response it gives back says nothing
|
|
48
|
+
* about whether the identity works. Every integration then writes the same poll loop, and the
|
|
49
|
+
* ones that do not write it hand around an identity that fails at the last step of every flow.
|
|
50
|
+
*
|
|
51
|
+
* "Usable" is `status` terminal AND `can_sign === true`, and those fail for different reasons:
|
|
52
|
+
*
|
|
53
|
+
* - `can_sign === false` — provisioning finished, but the on-chain key page is not held by your
|
|
54
|
+
* key. The identity exists, consumes org quota, and can never sign.
|
|
55
|
+
* - `can_sign === null` — the key page could not be READ. That is UNKNOWN, not a soft yes, and an
|
|
56
|
+
* Accumulate outage is exactly when the distinction matters most. This keeps polling, and says
|
|
57
|
+
* plainly that it could not determine the answer if the budget runs out.
|
|
58
|
+
*
|
|
59
|
+
* A timeout is neither success nor failure — provisioning may still complete — so it throws
|
|
60
|
+
* rather than returning something a caller could mistake for a ready identity.
|
|
61
|
+
*
|
|
62
|
+
* **Not the right call for `signing_mode: "provider"`.** The one-shot mnemonic URL expires in
|
|
63
|
+
* about ten minutes and this method is allowed to wait five, so waiting first burns most of the
|
|
64
|
+
* window on the one flow where losing the token loses the seed. Use `create()`, call
|
|
65
|
+
* `retrieveMnemonic()` immediately, then poll `get()`. If you do use this, the URL is carried
|
|
66
|
+
* through on `mnemonic_retrieval` rather than dropped — but it may already have expired.
|
|
67
|
+
*/
|
|
68
|
+
createAndWait(params: CreateIdentityParams, { timeoutMs, intervalMs, onPoll }?: {
|
|
69
|
+
timeoutMs?: number;
|
|
70
|
+
/** Overrides the cadence the gateway publishes. Leave unset to use it. */
|
|
71
|
+
intervalMs?: number;
|
|
72
|
+
onPoll?: (identity: Identity) => void;
|
|
73
|
+
}): Promise<Identity & Pick<IdentityResponse, 'mnemonic_retrieval'>>;
|
|
24
74
|
/** Link or unlink chains, set a webhook, or supply a `publicKey` to repair an identity created without one. */
|
|
25
75
|
update(id: string, params: UpdateIdentityParams): Promise<IdentityResponse>;
|
|
26
76
|
/** Retire an identity, freeing the slot it occupies against the org quota. Soft delete inside Certen only:
|
|
@@ -28,5 +78,36 @@ export declare class IdentityResource {
|
|
|
28
78
|
retire(id: string): Promise<{
|
|
29
79
|
success: boolean;
|
|
30
80
|
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Collect the mnemonic generated for a `signing_mode: "provider"` identity. **Once.**
|
|
83
|
+
*
|
|
84
|
+
* This had no client surface at all, which made it the most dangerous gap in the SDK. Creating a
|
|
85
|
+
* provider-mode identity never returns the mnemonic inline — it returns a `mnemonic_retrieval.url`
|
|
86
|
+
* — and the token behind that URL is consumed atomically on first read. So a caller who did not
|
|
87
|
+
* hand-roll the HTTP request lost the seed permanently, on the one flow where the key material
|
|
88
|
+
* exists and CERTEN is holding it for them.
|
|
89
|
+
*
|
|
90
|
+
* **Two clocks are running.** The token expires (10 minutes by default, published as
|
|
91
|
+
* `mnemonic_retrieval.expires_in`) and it dies on first read. Call this immediately after
|
|
92
|
+
* `create()` and persist the result before doing anything else — including before waiting for
|
|
93
|
+
* provisioning to finish, which takes longer than the token lives.
|
|
94
|
+
*
|
|
95
|
+
* Pass either the URL the create response gave you, or the id and token separately:
|
|
96
|
+
*
|
|
97
|
+
* ```ts
|
|
98
|
+
* const created = await certen.identity.create({ name: 'ops', signingMode: 'provider' });
|
|
99
|
+
* if (created.mnemonic_retrieval) {
|
|
100
|
+
* const { mnemonic } = await certen.identity.retrieveMnemonic(created.mnemonic_retrieval.url);
|
|
101
|
+
* await saveToVault(mnemonic); // there is no second chance
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* Requires `identity:write`. A second call fails with 404 — indistinguishable, by design, from a
|
|
106
|
+
* token that never existed.
|
|
107
|
+
*/
|
|
108
|
+
retrieveMnemonic(idOrUrl: string, token?: string): Promise<{
|
|
109
|
+
mnemonic: string;
|
|
110
|
+
warning?: string;
|
|
111
|
+
}>;
|
|
31
112
|
}
|
|
32
113
|
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/resources/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,aAAa,CAAC;
|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BAAgB,CAAC;IAUjF;kGAC8F;IACxF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAKvD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,gBAAgB,CACpB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAenD"}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { omitUndefined } from '../internal.js';
|
|
2
|
+
import { CertenError } from '../errors.js';
|
|
3
|
+
/** Statuses provisioning is still in flight in. Anything else is treated as terminal. */
|
|
4
|
+
const IN_FLIGHT = ['provisioning', 'pending', 'creating'];
|
|
5
|
+
const sleep = (ms) => new Promise((r) => { setTimeout(r, ms); });
|
|
6
|
+
/**
|
|
7
|
+
* Accept what the gateway actually handed the caller.
|
|
8
|
+
*
|
|
9
|
+
* `mnemonic_retrieval.url` is a path, not an id and a token — so a method taking `(id, token)` only
|
|
10
|
+
* would make every caller split a string, and splitting it wrongly costs them the seed. Both forms
|
|
11
|
+
* are accepted, and an absolute URL works too in case the gateway ever returns one.
|
|
12
|
+
*/
|
|
13
|
+
export function parseMnemonicTarget(idOrUrl, token) {
|
|
14
|
+
if (token)
|
|
15
|
+
return { id: idOrUrl, token };
|
|
16
|
+
const path = idOrUrl.includes('://') ? new URL(idOrUrl).pathname : idOrUrl;
|
|
17
|
+
const m = /\/v1\/identity\/([^/]+)\/mnemonic\/([^/?#]+)/.exec(path);
|
|
18
|
+
if (!m) {
|
|
19
|
+
throw new CertenError(`certen: "${idOrUrl}" is not a mnemonic retrieval URL. Pass the create response's `
|
|
20
|
+
+ 'mnemonic_retrieval.url, or the identity id and token as two arguments.', 0, 'INVALID_MNEMONIC_TARGET');
|
|
21
|
+
}
|
|
22
|
+
return { id: decodeURIComponent(m[1]), token: decodeURIComponent(m[2]) };
|
|
23
|
+
}
|
|
2
24
|
export class IdentityResource {
|
|
3
25
|
http;
|
|
4
26
|
constructor(http) {
|
|
@@ -35,10 +57,108 @@ export class IdentityResource {
|
|
|
35
57
|
* as a query string, where it was silently ignored — so the signature promised a capability the API does
|
|
36
58
|
* not have.
|
|
37
59
|
*/
|
|
38
|
-
async get(id) {
|
|
39
|
-
const { data } = await this.http.get(`/v1/identity/${id}
|
|
60
|
+
async get(id, opts = {}) {
|
|
61
|
+
const { data } = await this.http.get(`/v1/identity/${id}`, {
|
|
62
|
+
// Only sent when asked for: omitting the param keeps the gateway's default, while sending
|
|
63
|
+
// `include=` is the explicit "none" that a poll loop wants. The two are different requests
|
|
64
|
+
// and conflating them would silently strip enrichments from every ordinary read.
|
|
65
|
+
...(opts.include ? { params: { include: opts.include.join(',') } } : {}),
|
|
66
|
+
});
|
|
40
67
|
return data;
|
|
41
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Create an identity and wait until it is genuinely usable.
|
|
71
|
+
*
|
|
72
|
+
* `create()` returns `202` and provisioning continues, so the response it gives back says nothing
|
|
73
|
+
* about whether the identity works. Every integration then writes the same poll loop, and the
|
|
74
|
+
* ones that do not write it hand around an identity that fails at the last step of every flow.
|
|
75
|
+
*
|
|
76
|
+
* "Usable" is `status` terminal AND `can_sign === true`, and those fail for different reasons:
|
|
77
|
+
*
|
|
78
|
+
* - `can_sign === false` — provisioning finished, but the on-chain key page is not held by your
|
|
79
|
+
* key. The identity exists, consumes org quota, and can never sign.
|
|
80
|
+
* - `can_sign === null` — the key page could not be READ. That is UNKNOWN, not a soft yes, and an
|
|
81
|
+
* Accumulate outage is exactly when the distinction matters most. This keeps polling, and says
|
|
82
|
+
* plainly that it could not determine the answer if the budget runs out.
|
|
83
|
+
*
|
|
84
|
+
* A timeout is neither success nor failure — provisioning may still complete — so it throws
|
|
85
|
+
* rather than returning something a caller could mistake for a ready identity.
|
|
86
|
+
*
|
|
87
|
+
* **Not the right call for `signing_mode: "provider"`.** The one-shot mnemonic URL expires in
|
|
88
|
+
* about ten minutes and this method is allowed to wait five, so waiting first burns most of the
|
|
89
|
+
* window on the one flow where losing the token loses the seed. Use `create()`, call
|
|
90
|
+
* `retrieveMnemonic()` immediately, then poll `get()`. If you do use this, the URL is carried
|
|
91
|
+
* through on `mnemonic_retrieval` rather than dropped — but it may already have expired.
|
|
92
|
+
*/
|
|
93
|
+
async createAndWait(params, { timeoutMs = 300_000, intervalMs, onPoll } = {}) {
|
|
94
|
+
const created = await this.create(params);
|
|
95
|
+
const id = created.id;
|
|
96
|
+
if (!id) {
|
|
97
|
+
throw new CertenError('certen: the gateway accepted the identity but returned no id', 0, 'NO_IDENTITY_ID');
|
|
98
|
+
}
|
|
99
|
+
// The gateway now publishes how to wait, so this stops guessing. It used to poll every 3s
|
|
100
|
+
// starting IMMEDIATELY, against an operation that is a chain of anchored Accumulate
|
|
101
|
+
// transactions and cannot finish in under a minute — roughly twenty requests spent before
|
|
102
|
+
// anything could possibly have changed. An explicit `intervalMs` still wins, and a gateway that
|
|
103
|
+
// sends no `polling` block falls back to the old numbers rather than to nothing.
|
|
104
|
+
const polling = created.polling;
|
|
105
|
+
const pollInterval = intervalMs ?? (polling ? polling.interval_seconds * 1_000 : 3_000);
|
|
106
|
+
const firstPollDelay = intervalMs === undefined && polling
|
|
107
|
+
? polling.first_poll_after_seconds * 1_000
|
|
108
|
+
: 0;
|
|
109
|
+
const deadline = Date.now() + timeoutMs;
|
|
110
|
+
let last;
|
|
111
|
+
// Bounded by the deadline, so a large published delay can never overshoot the caller's budget.
|
|
112
|
+
if (firstPollDelay > 0)
|
|
113
|
+
await sleep(Math.min(firstPollDelay, Math.max(0, deadline - Date.now())));
|
|
114
|
+
while (Date.now() < deadline) {
|
|
115
|
+
// The response IS the identity (plus its joined sub-resources) since the gateway flattened
|
|
116
|
+
// these endpoints; it no longer arrives under an `identity` key.
|
|
117
|
+
// No enrichments while polling. This loop reads `status` and `can_sign`, both computed
|
|
118
|
+
// before any enrichment runs — so fetching governance, balances and pending on every
|
|
119
|
+
// iteration bought nothing. At the default 3s interval a 90s provisioning wait is ~30
|
|
120
|
+
// polls, each of which was making a governance network call, a balance network call PER
|
|
121
|
+
// LINKED CHAIN, and a pending lookup, then discarding all of it.
|
|
122
|
+
const identity = await this.get(id, { include: [] });
|
|
123
|
+
last = identity;
|
|
124
|
+
onPoll?.(identity);
|
|
125
|
+
if (!IN_FLIGHT.includes(identity.status)) {
|
|
126
|
+
if (identity.can_sign === true) {
|
|
127
|
+
// One enriched read at the end, so what comes back is exactly what it always was.
|
|
128
|
+
// Returning the lean poll result would silently drop `balances`, `governance` and
|
|
129
|
+
// `pending` for anyone reading them off this — a saving not worth a surprise.
|
|
130
|
+
const ready = await this.get(id).catch(() => identity);
|
|
131
|
+
// `mnemonic_retrieval` only ever appears on the create response, and this method used to
|
|
132
|
+
// throw that response away — so provider mode through `createAndWait` lost the seed with
|
|
133
|
+
// no way to notice. Carried through instead.
|
|
134
|
+
//
|
|
135
|
+
// It may already be too late: the token lives ~10 minutes and this call is allowed to
|
|
136
|
+
// wait five. A caller who needs the mnemonic should use `create()` and collect it first,
|
|
137
|
+
// then wait. This is a safety net, not the recommended path.
|
|
138
|
+
return created.mnemonic_retrieval
|
|
139
|
+
? { ...ready, mnemonic_retrieval: created.mnemonic_retrieval }
|
|
140
|
+
: ready;
|
|
141
|
+
}
|
|
142
|
+
if (identity.can_sign === false) {
|
|
143
|
+
throw new CertenError(`certen: identity ${id} finished provisioning as "${identity.status}" but cannot sign — `
|
|
144
|
+
+ 'its key page is not held by your key'
|
|
145
|
+
+ (identity.error_message ? `: ${identity.error_message}` : ''), 0, 'IDENTITY_CANNOT_SIGN');
|
|
146
|
+
}
|
|
147
|
+
if (identity.status === 'error') {
|
|
148
|
+
throw new CertenError(`certen: identity ${id} failed to provision`
|
|
149
|
+
+ (identity.error_message ? `: ${identity.error_message}` : ''), 0, 'IDENTITY_PROVISIONING_FAILED');
|
|
150
|
+
}
|
|
151
|
+
// Terminal status with can_sign null: the key page was unreadable. Keep asking — this is
|
|
152
|
+
// usually transient — and fall through to the unknown-answer error if it never resolves.
|
|
153
|
+
}
|
|
154
|
+
await sleep(pollInterval);
|
|
155
|
+
}
|
|
156
|
+
if (last && !IN_FLIGHT.includes(last.status) && last.can_sign == null) {
|
|
157
|
+
throw new CertenError(`certen: identity ${id} is "${last.status}" but whether it can sign could not be determined `
|
|
158
|
+
+ '— the on-chain key page was unreadable for the whole wait', 0, 'IDENTITY_CAN_SIGN_UNKNOWN');
|
|
159
|
+
}
|
|
160
|
+
throw new CertenError(`certen: identity ${id} is still "${last?.status ?? 'unknown'}" after ${timeoutMs}ms — it may yet finish`, 0, 'IDENTITY_WAIT_TIMEOUT');
|
|
161
|
+
}
|
|
42
162
|
/** Link or unlink chains, set a webhook, or supply a `publicKey` to repair an identity created without one. */
|
|
43
163
|
async update(id, params) {
|
|
44
164
|
const { data } = await this.http.patch(`/v1/identity/${id}`, omitUndefined({
|
|
@@ -55,5 +175,37 @@ export class IdentityResource {
|
|
|
55
175
|
const { data } = await this.http.delete(`/v1/identity/${id}`);
|
|
56
176
|
return data;
|
|
57
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Collect the mnemonic generated for a `signing_mode: "provider"` identity. **Once.**
|
|
180
|
+
*
|
|
181
|
+
* This had no client surface at all, which made it the most dangerous gap in the SDK. Creating a
|
|
182
|
+
* provider-mode identity never returns the mnemonic inline — it returns a `mnemonic_retrieval.url`
|
|
183
|
+
* — and the token behind that URL is consumed atomically on first read. So a caller who did not
|
|
184
|
+
* hand-roll the HTTP request lost the seed permanently, on the one flow where the key material
|
|
185
|
+
* exists and CERTEN is holding it for them.
|
|
186
|
+
*
|
|
187
|
+
* **Two clocks are running.** The token expires (10 minutes by default, published as
|
|
188
|
+
* `mnemonic_retrieval.expires_in`) and it dies on first read. Call this immediately after
|
|
189
|
+
* `create()` and persist the result before doing anything else — including before waiting for
|
|
190
|
+
* provisioning to finish, which takes longer than the token lives.
|
|
191
|
+
*
|
|
192
|
+
* Pass either the URL the create response gave you, or the id and token separately:
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* const created = await certen.identity.create({ name: 'ops', signingMode: 'provider' });
|
|
196
|
+
* if (created.mnemonic_retrieval) {
|
|
197
|
+
* const { mnemonic } = await certen.identity.retrieveMnemonic(created.mnemonic_retrieval.url);
|
|
198
|
+
* await saveToVault(mnemonic); // there is no second chance
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* Requires `identity:write`. A second call fails with 404 — indistinguishable, by design, from a
|
|
203
|
+
* token that never existed.
|
|
204
|
+
*/
|
|
205
|
+
async retrieveMnemonic(idOrUrl, token) {
|
|
206
|
+
const { id, token: tok } = parseMnemonicTarget(idOrUrl, token);
|
|
207
|
+
const { data } = await this.http.get(`/v1/identity/${encodeURIComponent(id)}/mnemonic/${encodeURIComponent(tok)}`);
|
|
208
|
+
return data;
|
|
209
|
+
}
|
|
58
210
|
}
|
|
59
211
|
//# sourceMappingURL=identity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/resources/identity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO/C,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAE3C;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,CAAC,MAA4B;QACvC,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,IAAI,MAAM,CAAC,cAAc;YAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC,cAAc,CAAC;QAC9E,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC;Y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,OAAO,IAAI,CAAC;IACd,CAAC;IAED;kGAC8F;IAC9F,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,KAAK,CAAC,gBAAgB,CACpB,OAAe,EACf,KAAc;QAEd,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC/D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAClC,gBAAgB,kBAAkB,CAAC,EAAE,CAAC,aAAa,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAC7E,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CASF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import type { OAuthClient, OAuthClientCredentials } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The OAuth2 clients your organization owns.
|
|
5
|
+
*
|
|
6
|
+
* `fetchOAuthToken` and `revokeOAuthToken` let a service obtain and give back tokens — but the
|
|
7
|
+
* client those tokens come from could only be created by a human opening the portal. So an
|
|
8
|
+
* integration could authenticate itself and could not provision itself, and every automated
|
|
9
|
+
* deployment stopped to wait on someone clicking through a browser.
|
|
10
|
+
*
|
|
11
|
+
* These sat at `/v1/admin/oauth-clients` behind `admin:write`, which was the same misfiling
|
|
12
|
+
* webhooks had: the rows are org-scoped and the create route explicitly refuses to cross orgs
|
|
13
|
+
* without admin scope, so this was always a customer capability wearing an operator's path. Moved
|
|
14
|
+
* to `/v1/oauth-clients` with `oauth:read` and `oauth:write`.
|
|
15
|
+
*
|
|
16
|
+
* **A secret appears exactly twice in its life** — once from `create()`, once from
|
|
17
|
+
* `rotateSecret()` — and never again from any read. Store it before doing anything else.
|
|
18
|
+
*/
|
|
19
|
+
export declare class OAuthClientsResource {
|
|
20
|
+
private http;
|
|
21
|
+
constructor(http: AxiosInstance);
|
|
22
|
+
/** Clients this organization owns. Never includes secrets. Requires `oauth:read`. */
|
|
23
|
+
list(): Promise<{
|
|
24
|
+
clients: OAuthClient[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a client and receive its credentials once.
|
|
28
|
+
*
|
|
29
|
+
* `scopes` is what tokens issued to this client may do — grant it the narrowest set that works,
|
|
30
|
+
* because a token is only as constrained as the client that minted it. Omitting it creates a
|
|
31
|
+
* client whose tokens can do nothing, which is rarely what anyone wants.
|
|
32
|
+
*
|
|
33
|
+
* `orgId` is for operators placing a client in another organization and requires `admin:write`;
|
|
34
|
+
* leave it unset and the client lands in your own org.
|
|
35
|
+
*
|
|
36
|
+
* NOT retry-safe — a repeat creates a second client. Requires `oauth:write`.
|
|
37
|
+
*/
|
|
38
|
+
create(params: {
|
|
39
|
+
scopes: string[];
|
|
40
|
+
orgId?: string;
|
|
41
|
+
}): Promise<OAuthClientCredentials>;
|
|
42
|
+
/**
|
|
43
|
+
* Deactivate a client and revoke every token it ever issued.
|
|
44
|
+
*
|
|
45
|
+
* Immediate and cascading: anything currently authenticating as this client stops working on the
|
|
46
|
+
* next request, including tokens that had hours left. That is the correct behaviour for a leaked
|
|
47
|
+
* client secret and a severe one for a live integration — reach for `rotateSecret` with a grace
|
|
48
|
+
* window when the goal is to change the credential rather than to stop the client.
|
|
49
|
+
*
|
|
50
|
+
* Idempotent: deactivation is a state, so a retry is safe. Requires `oauth:write`.
|
|
51
|
+
*/
|
|
52
|
+
remove(id: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Issue a new client secret, optionally keeping the old one alive while you deploy.
|
|
55
|
+
*
|
|
56
|
+
* `graceSeconds` is the whole point of this method over delete-and-recreate: the previous secret
|
|
57
|
+
* keeps working for that long, so a fleet can pick up the new one at its own pace instead of
|
|
58
|
+
* failing all at once. Defaults to 300 seconds, and the gateway caps it at seven days. Pass `0`
|
|
59
|
+
* for an immediate cutover — correct when the old secret has leaked, and a small outage otherwise.
|
|
60
|
+
*
|
|
61
|
+
* NOT retry-safe. Each call invalidates the secret the previous one issued, so calling twice
|
|
62
|
+
* strands whatever was mid-deployment with the first new secret. Requires `oauth:write`.
|
|
63
|
+
*/
|
|
64
|
+
rotateSecret(id: string, params?: {
|
|
65
|
+
graceSeconds?: number;
|
|
66
|
+
}): Promise<OAuthClientCredentials & {
|
|
67
|
+
grace_seconds?: number;
|
|
68
|
+
previous_secret_expires_at?: string | null;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=oauth-clients.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-clients.d.ts","sourceRoot":"","sources":["../../src/resources/oauth-clients.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAEvE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,oBAAoB;IACnB,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEvC,qFAAqF;IAC/E,IAAI,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;IAKjD;;;;;;;;;;;OAWG;IACG,MAAM,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAQnC;;;;;;;;;OASG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC;;;;;;;;;;OAUG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAC7E,sBAAsB,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,0BAA0B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAChG;CAOF"}
|