@witnium/witniumchain 0.27.0 → 0.28.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 +29 -3
- package/dist/index.d.mts +1912 -465
- package/dist/index.d.ts +1912 -465
- package/dist/index.js +83 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -178,6 +178,9 @@ var WitniumchainClient = class {
|
|
|
178
178
|
// jar) get the refresh token in the response body and the SDK stashes it
|
|
179
179
|
// here as a fallback. Either path drives `refreshAccessToken` identically.
|
|
180
180
|
refreshToken;
|
|
181
|
+
// The ID token from the last code exchange or refresh, kept for
|
|
182
|
+
// RP-initiated logout (`id_token_hint`). Memory only, like the tokens.
|
|
183
|
+
idToken;
|
|
181
184
|
// Sentinel: the most recent token response set an HttpOnly refresh cookie.
|
|
182
185
|
// The SDK can't directly observe an HttpOnly cookie, but the response body
|
|
183
186
|
// tells us indirectly — server strips `refresh_token` when it sets the
|
|
@@ -235,7 +238,7 @@ var WitniumchainClient = class {
|
|
|
235
238
|
apiKeys;
|
|
236
239
|
/** The signed-in member's dashboard signing key on a managed contract. `client.dashboardKey.*`. */
|
|
237
240
|
dashboardKey;
|
|
238
|
-
/** The home org's managed contract: pause, resume, activity. `client.orgContract.*`. */
|
|
241
|
+
/** The home org's managed contract: pause, resume, activity, keys you hold. `client.orgContract.*`. */
|
|
239
242
|
orgContract;
|
|
240
243
|
keyRequests;
|
|
241
244
|
constructor(config) {
|
|
@@ -301,36 +304,36 @@ var WitniumchainClient = class {
|
|
|
301
304
|
// Backing methods for the `orgUsers` namespace. All resolve the caller's
|
|
302
305
|
// org + org-admin role server-side from the session — no orgId in the path.
|
|
303
306
|
getDashboardKey() {
|
|
304
|
-
return this.req("GET", "/v1/account/dashboard-key", { auth: "
|
|
307
|
+
return this.req("GET", "/v1/account/dashboard-key", { auth: "SessionOrBearer" });
|
|
305
308
|
}
|
|
306
309
|
ensureDashboardKey() {
|
|
307
|
-
return this.req("POST", "/v1/account/dashboard-key", { auth: "
|
|
310
|
+
return this.req("POST", "/v1/account/dashboard-key", { auth: "SessionOrBearer" });
|
|
308
311
|
}
|
|
309
312
|
/** Revoke your own added dashboard key on chain; 409 for the organization's base key. */
|
|
310
313
|
revokeDashboardKey() {
|
|
311
|
-
return this.req("DELETE", "/v1/account/dashboard-key", { auth: "
|
|
314
|
+
return this.req("DELETE", "/v1/account/dashboard-key", { auth: "SessionOrBearer", expectNoContent: true });
|
|
312
315
|
}
|
|
313
316
|
pauseOrgContract() {
|
|
314
|
-
return this.req("POST", "/v1/orgs/me/contract/pause", { auth: "
|
|
317
|
+
return this.req("POST", "/v1/orgs/me/contract/pause", { auth: "SessionOrBearer" });
|
|
315
318
|
}
|
|
316
319
|
/**
|
|
317
320
|
* Add a key you hold to the org's managed contract (plan §17.7): org
|
|
318
|
-
* admins, after a step-up
|
|
319
|
-
* the returned op confirms.
|
|
321
|
+
* admins, after a step-up (a bearer token needs a fresh `auth_time`).
|
|
322
|
+
* Witnium signs the add; the key counts once the returned op confirms.
|
|
320
323
|
*/
|
|
321
324
|
addOrgContractKey(body) {
|
|
322
|
-
return this.req("POST", "/v1/orgs/me/contract/keys", { auth: "
|
|
325
|
+
return this.req("POST", "/v1/orgs/me/contract/keys", { auth: "SessionOrBearer", body });
|
|
323
326
|
}
|
|
324
327
|
/** Revoke a key added with {@link addOrgContractKey} (org admins). */
|
|
325
328
|
removeOrgContractKey(publicKey) {
|
|
326
|
-
return this.req("DELETE", `/v1/orgs/me/contract/keys/${encodeURIComponent(publicKey)}`, { auth: "
|
|
329
|
+
return this.req("DELETE", `/v1/orgs/me/contract/keys/${encodeURIComponent(publicKey)}`, { auth: "SessionOrBearer" });
|
|
327
330
|
}
|
|
328
331
|
/** Needs a step-up within 5 minutes (`client.security.stepUp`). */
|
|
329
332
|
resumeOrgContract() {
|
|
330
|
-
return this.req("POST", "/v1/orgs/me/contract/resume", { auth: "
|
|
333
|
+
return this.req("POST", "/v1/orgs/me/contract/resume", { auth: "SessionOrBearer" });
|
|
331
334
|
}
|
|
332
335
|
getContractActivity(limit) {
|
|
333
|
-
return this.req("GET", "/v1/orgs/me/owner-operations", { auth: "
|
|
336
|
+
return this.req("GET", "/v1/orgs/me/owner-operations", { auth: "SessionOrBearer", query: { limit } });
|
|
334
337
|
}
|
|
335
338
|
/** Create an API key (org admin, after a step-up). The secret is in this response only. */
|
|
336
339
|
createApiKey(body) {
|
|
@@ -350,7 +353,7 @@ var WitniumchainClient = class {
|
|
|
350
353
|
return this.req("PATCH", "/v1/orgs/me", { auth: "SessionCookie", body });
|
|
351
354
|
}
|
|
352
355
|
listMembers() {
|
|
353
|
-
return this.req("GET", "/v1/orgs/me/members", { auth: "
|
|
356
|
+
return this.req("GET", "/v1/orgs/me/members", { auth: "SessionOrBearer" });
|
|
354
357
|
}
|
|
355
358
|
inviteMember(body) {
|
|
356
359
|
return this.req("POST", "/v1/orgs/me/members/invite", {
|
|
@@ -427,17 +430,17 @@ var WitniumchainClient = class {
|
|
|
427
430
|
return this.req("POST", "/v1/account/signing-key-requests", { auth: "SessionOrBearer", body });
|
|
428
431
|
}
|
|
429
432
|
listSigningKeyRequests() {
|
|
430
|
-
return this.req("GET", "/v1/account/signing-key-requests", { auth: "
|
|
433
|
+
return this.req("GET", "/v1/account/signing-key-requests", { auth: "SessionOrBearer" });
|
|
431
434
|
}
|
|
432
435
|
approveSigningKeyRequest(id, body) {
|
|
433
436
|
return this.req("POST", `/v1/account/signing-key-requests/${encodeURIComponent(id)}/approve`, {
|
|
434
|
-
auth: "
|
|
437
|
+
auth: "SessionOrBearer",
|
|
435
438
|
body
|
|
436
439
|
});
|
|
437
440
|
}
|
|
438
441
|
declineSigningKeyRequest(id) {
|
|
439
442
|
return this.req("POST", `/v1/account/signing-key-requests/${encodeURIComponent(id)}/decline`, {
|
|
440
|
-
auth: "
|
|
443
|
+
auth: "SessionOrBearer",
|
|
441
444
|
expectNoContent: true
|
|
442
445
|
});
|
|
443
446
|
}
|
|
@@ -491,12 +494,12 @@ var WitniumchainClient = class {
|
|
|
491
494
|
// ────────────────────────────────────────────────────────────────────────
|
|
492
495
|
createCheckoutSession(body) {
|
|
493
496
|
return this.req("POST", "/v1/billing/checkout", {
|
|
494
|
-
auth: "
|
|
497
|
+
auth: "SessionOrBearer",
|
|
495
498
|
body
|
|
496
499
|
});
|
|
497
500
|
}
|
|
498
501
|
createPortalSession() {
|
|
499
|
-
return this.req("GET", "/v1/billing/portal", { auth: "
|
|
502
|
+
return this.req("GET", "/v1/billing/portal", { auth: "SessionOrBearer" });
|
|
500
503
|
}
|
|
501
504
|
// Webhook endpoint is intentionally NOT exposed: only Stripe should call it.
|
|
502
505
|
// ────────────────────────────────────────────────────────────────────────
|
|
@@ -570,13 +573,13 @@ var WitniumchainClient = class {
|
|
|
570
573
|
}
|
|
571
574
|
pauseContract(body) {
|
|
572
575
|
return this.req("POST", "/v1/contracts/pause", {
|
|
573
|
-
auth: "
|
|
576
|
+
auth: "SessionOrBearer",
|
|
574
577
|
body
|
|
575
578
|
});
|
|
576
579
|
}
|
|
577
580
|
unpauseContract(body) {
|
|
578
581
|
return this.req("POST", "/v1/contracts/unpause", {
|
|
579
|
-
auth: "
|
|
582
|
+
auth: "SessionOrBearer",
|
|
580
583
|
body
|
|
581
584
|
});
|
|
582
585
|
}
|
|
@@ -677,10 +680,10 @@ var WitniumchainClient = class {
|
|
|
677
680
|
// Users / account (/v1/account/*)
|
|
678
681
|
// ────────────────────────────────────────────────────────────────────────
|
|
679
682
|
getAccount() {
|
|
680
|
-
return this.req("GET", "/v1/account", { auth: "
|
|
683
|
+
return this.req("GET", "/v1/account", { auth: "SessionOrBearer" });
|
|
681
684
|
}
|
|
682
685
|
getLedger() {
|
|
683
|
-
return this.req("GET", "/v1/account/ledger", { auth: "
|
|
686
|
+
return this.req("GET", "/v1/account/ledger", { auth: "SessionOrBearer" });
|
|
684
687
|
}
|
|
685
688
|
/**
|
|
686
689
|
* DEV-ONLY: hard-delete the authenticated user + their org + contracts +
|
|
@@ -892,6 +895,15 @@ var WitniumchainClient = class {
|
|
|
892
895
|
url.searchParams.set("code_challenge", challenge);
|
|
893
896
|
url.searchParams.set("code_challenge_method", "S256");
|
|
894
897
|
if (args.prompt) url.searchParams.set("prompt", args.prompt);
|
|
898
|
+
if (args.maxAge !== void 0) {
|
|
899
|
+
if (!Number.isInteger(args.maxAge) || args.maxAge < 0) {
|
|
900
|
+
throw new WitniumchainApiError({
|
|
901
|
+
status: 0,
|
|
902
|
+
message: `WitniumchainClient: beginOAuthLogin \`maxAge\` must be a non-negative integer (got ${args.maxAge}).`
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
url.searchParams.set("max_age", String(args.maxAge));
|
|
906
|
+
}
|
|
895
907
|
const storage = this.verifierStorageOrDefault();
|
|
896
908
|
storage.set(state, verifier);
|
|
897
909
|
storage.set(redirectUriKey(state), args.redirectUri);
|
|
@@ -1057,6 +1069,7 @@ var WitniumchainClient = class {
|
|
|
1057
1069
|
this.accessToken = void 0;
|
|
1058
1070
|
this.accessTokenFromSession = false;
|
|
1059
1071
|
this.refreshToken = void 0;
|
|
1072
|
+
this.idToken = void 0;
|
|
1060
1073
|
this.hasRefreshCookie = false;
|
|
1061
1074
|
this.sessionExchangeInFlight = void 0;
|
|
1062
1075
|
this.refreshInFlight = void 0;
|
|
@@ -1115,6 +1128,47 @@ var WitniumchainClient = class {
|
|
|
1115
1128
|
signOut() {
|
|
1116
1129
|
this.invalidateCredentials();
|
|
1117
1130
|
}
|
|
1131
|
+
/**
|
|
1132
|
+
* End the session at the authorization server (OIDC RP-Initiated Logout).
|
|
1133
|
+
*
|
|
1134
|
+
* Builds the `end_session_endpoint` URL with `id_token_hint` (the ID token
|
|
1135
|
+
* from {@link completeOAuthLogin}), `client_id` and
|
|
1136
|
+
* `post_logout_redirect_uri`, then forgets every in-memory credential like
|
|
1137
|
+
* {@link signOut}. The caller does the redirect
|
|
1138
|
+
* (`window.location.assign(result.logoutUrl)`).
|
|
1139
|
+
*
|
|
1140
|
+
* Throws when no `oauthClientId` is configured, when this client holds no
|
|
1141
|
+
* ID token (the login was not completed here, or it did not ask for
|
|
1142
|
+
* `openid`), or when the discovery document has no `end_session_endpoint`.
|
|
1143
|
+
*/
|
|
1144
|
+
async beginOAuthLogout(args) {
|
|
1145
|
+
if (!this.oauthClientId) {
|
|
1146
|
+
throw new WitniumchainApiError({
|
|
1147
|
+
status: 0,
|
|
1148
|
+
message: "WitniumchainClient: beginOAuthLogout requires `oauthClientId` to be set on the constructor."
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
if (!this.idToken) {
|
|
1152
|
+
throw new WitniumchainApiError({
|
|
1153
|
+
status: 0,
|
|
1154
|
+
message: "WitniumchainClient: beginOAuthLogout needs the ID token from completeOAuthLogin (request the `openid` scope and complete the login with this client)."
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
const discovery = await this.fetchDiscovery();
|
|
1158
|
+
if (!discovery.end_session_endpoint) {
|
|
1159
|
+
throw new WitniumchainApiError({
|
|
1160
|
+
status: 0,
|
|
1161
|
+
message: "OIDC discovery doc has no `end_session_endpoint`: the authorization server does not offer RP-initiated logout."
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
const url = new URL(discovery.end_session_endpoint);
|
|
1165
|
+
url.searchParams.set("id_token_hint", this.idToken);
|
|
1166
|
+
url.searchParams.set("client_id", this.oauthClientId);
|
|
1167
|
+
url.searchParams.set("post_logout_redirect_uri", args.postLogoutRedirectUri);
|
|
1168
|
+
if (args.state !== void 0) url.searchParams.set("state", args.state);
|
|
1169
|
+
this.invalidateCredentials();
|
|
1170
|
+
return { logoutUrl: url.toString() };
|
|
1171
|
+
}
|
|
1118
1172
|
// ────────────────────────────────────────────────────────────────────────
|
|
1119
1173
|
// Internal: OAuth flow helpers
|
|
1120
1174
|
// ────────────────────────────────────────────────────────────────────────
|
|
@@ -1157,6 +1211,7 @@ var WitniumchainClient = class {
|
|
|
1157
1211
|
return {
|
|
1158
1212
|
authorization_endpoint: parsed.authorization_endpoint,
|
|
1159
1213
|
token_endpoint: parsed.token_endpoint,
|
|
1214
|
+
end_session_endpoint: parsed.end_session_endpoint,
|
|
1160
1215
|
issuer: parsed.issuer ?? this.baseUrl
|
|
1161
1216
|
};
|
|
1162
1217
|
})();
|
|
@@ -1208,6 +1263,7 @@ var WitniumchainClient = class {
|
|
|
1208
1263
|
});
|
|
1209
1264
|
}
|
|
1210
1265
|
this.accessToken = tokens.access_token;
|
|
1266
|
+
if (tokens.id_token) this.idToken = tokens.id_token;
|
|
1211
1267
|
this.accessTokenFromSession = false;
|
|
1212
1268
|
if (tokens.refresh_token) {
|
|
1213
1269
|
this.refreshToken = tokens.refresh_token;
|
|
@@ -1297,9 +1353,11 @@ var WitniumchainClient = class {
|
|
|
1297
1353
|
headers,
|
|
1298
1354
|
body: bodyString,
|
|
1299
1355
|
signal: controller.signal,
|
|
1300
|
-
//
|
|
1301
|
-
//
|
|
1302
|
-
|
|
1356
|
+
// A request that carries a bearer credential sends no cookies: an
|
|
1357
|
+
// OAuth client on another site must not depend on (or leak) a
|
|
1358
|
+
// third-party cookie. Everything else sends cookies cross-origin for
|
|
1359
|
+
// a browser using the cookie session.
|
|
1360
|
+
credentials: headers["authorization"] === void 0 ? "include" : "omit"
|
|
1303
1361
|
});
|
|
1304
1362
|
} catch (err) {
|
|
1305
1363
|
throw new WitniumchainApiError({
|
|
@@ -1422,7 +1480,7 @@ var WitniumchainClient = class {
|
|
|
1422
1480
|
return;
|
|
1423
1481
|
}
|
|
1424
1482
|
case "SessionOrBearer": {
|
|
1425
|
-
if (this.accessToken) headers["authorization"] = `Bearer ${this.accessToken}`;
|
|
1483
|
+
if (this.accessToken && !this.accessTokenFromSession) headers["authorization"] = `Bearer ${this.accessToken}`;
|
|
1426
1484
|
else if (this.cfg.sessionCookie) headers["cookie"] = `wac_session=${this.cfg.sessionCookie}`;
|
|
1427
1485
|
return;
|
|
1428
1486
|
}
|