@witnium/witniumchain 0.29.0 → 0.30.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/README.md +28 -5
- package/dist/index.d.mts +2291 -1214
- package/dist/index.d.ts +2291 -1214
- package/dist/index.js +39 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
// src/api-key.ts
|
|
2
|
+
var PREFIXED_FORMAT = /^wcak_(live|sandbox)_[0-9a-f]{64}$/;
|
|
3
|
+
var LEGACY_FORMAT = /^wcak_[0-9a-f]{64}$/;
|
|
4
|
+
function parseApiKey(apiKey) {
|
|
5
|
+
const prefixed = PREFIXED_FORMAT.exec(apiKey);
|
|
6
|
+
if (prefixed) {
|
|
7
|
+
return { environment: prefixed[1], legacyFormat: false };
|
|
8
|
+
}
|
|
9
|
+
if (LEGACY_FORMAT.test(apiKey)) {
|
|
10
|
+
return { environment: "live", legacyFormat: true };
|
|
11
|
+
}
|
|
12
|
+
throw new Error(
|
|
13
|
+
"apiKey must be `wcak_live_` or `wcak_sandbox_` followed by 64 lowercase hex (or a pre-sandbox `wcak_` key)"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
// src/errors.ts
|
|
2
18
|
var WitniumchainApiError = class extends Error {
|
|
3
19
|
status;
|
|
@@ -245,6 +261,13 @@ var WitniumchainClient = class {
|
|
|
245
261
|
if (!config.baseUrl) {
|
|
246
262
|
throw new Error("WitniumchainClient: baseUrl is required");
|
|
247
263
|
}
|
|
264
|
+
if (config.apiKey !== void 0) {
|
|
265
|
+
try {
|
|
266
|
+
parseApiKey(config.apiKey);
|
|
267
|
+
} catch (err) {
|
|
268
|
+
throw new Error(`WitniumchainClient: ${err.message}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
248
271
|
this.cfg = config;
|
|
249
272
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
250
273
|
this.chainBaseUrl = config.chainBaseUrl?.replace(/\/$/, "");
|
|
@@ -490,19 +513,6 @@ var WitniumchainClient = class {
|
|
|
490
513
|
return this.req("POST", "/v1/auth/reset-password", { auth: "Public", body });
|
|
491
514
|
}
|
|
492
515
|
// ────────────────────────────────────────────────────────────────────────
|
|
493
|
-
// Billing (/v1/billing/*)
|
|
494
|
-
// ────────────────────────────────────────────────────────────────────────
|
|
495
|
-
createCheckoutSession(body) {
|
|
496
|
-
return this.req("POST", "/v1/billing/checkout", {
|
|
497
|
-
auth: "SessionOrBearer",
|
|
498
|
-
body
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
createPortalSession() {
|
|
502
|
-
return this.req("GET", "/v1/billing/portal", { auth: "SessionOrBearer" });
|
|
503
|
-
}
|
|
504
|
-
// Webhook endpoint is intentionally NOT exposed: only Stripe should call it.
|
|
505
|
-
// ────────────────────────────────────────────────────────────────────────
|
|
506
516
|
// Orgs (/v1/orgs/me/*)
|
|
507
517
|
// ────────────────────────────────────────────────────────────────────────
|
|
508
518
|
/** The calling API key's own description: its contract and signing key (API key only). */
|
|
@@ -1549,22 +1559,6 @@ var Subscriptions = class {
|
|
|
1549
1559
|
this.client = client;
|
|
1550
1560
|
}
|
|
1551
1561
|
client;
|
|
1552
|
-
/**
|
|
1553
|
-
* Start a Stripe Checkout session for the supplied price. Returns the
|
|
1554
|
-
* hosted Checkout URL; redirect the user to it. Stripe's
|
|
1555
|
-
* `checkout.session.completed` webhook grants credits on success.
|
|
1556
|
-
*/
|
|
1557
|
-
subscribe(body) {
|
|
1558
|
-
return this.client.createCheckoutSession(body);
|
|
1559
|
-
}
|
|
1560
|
-
/**
|
|
1561
|
-
* Open the Stripe Billing Portal for the calling user's org. Returns the
|
|
1562
|
-
* hosted portal URL — redirect the user there for subscription /
|
|
1563
|
-
* payment-method management.
|
|
1564
|
-
*/
|
|
1565
|
-
manage() {
|
|
1566
|
-
return this.client.createPortalSession();
|
|
1567
|
-
}
|
|
1568
1562
|
/** Recent credit-ledger entries (most recent 200). */
|
|
1569
1563
|
getLedger() {
|
|
1570
1564
|
return this.client.getLedger();
|
|
@@ -2046,13 +2040,25 @@ function safeParse(text) {
|
|
|
2046
2040
|
}
|
|
2047
2041
|
|
|
2048
2042
|
// src/api-key-client.ts
|
|
2049
|
-
var API_KEY_FORMAT = /^wcak_[0-9a-f]{64}$/;
|
|
2050
2043
|
var WitniumchainApiKeyClient = class {
|
|
2051
2044
|
inner;
|
|
2045
|
+
/**
|
|
2046
|
+
* `live` or `sandbox`, from the key's prefix. Accounts
|
|
2047
|
+
* decides from its own record of the key; this is for the caller's checks
|
|
2048
|
+
* and logs.
|
|
2049
|
+
*/
|
|
2050
|
+
environment;
|
|
2051
|
+
/** True for a pre-sandbox `wcak_` + 64 hex key. Rotate it to a `wcak_live_` key before accounts' cutoff. */
|
|
2052
|
+
legacyKeyFormat;
|
|
2052
2053
|
constructor(config) {
|
|
2053
|
-
|
|
2054
|
-
|
|
2054
|
+
let parsed;
|
|
2055
|
+
try {
|
|
2056
|
+
parsed = parseApiKey(config.apiKey);
|
|
2057
|
+
} catch (err) {
|
|
2058
|
+
throw new Error(`WitniumchainApiKeyClient: ${err.message}`);
|
|
2055
2059
|
}
|
|
2060
|
+
this.environment = parsed.environment;
|
|
2061
|
+
this.legacyKeyFormat = parsed.legacyFormat;
|
|
2056
2062
|
this.inner = new WitniumchainClient({
|
|
2057
2063
|
baseUrl: config.baseUrl,
|
|
2058
2064
|
apiKey: config.apiKey,
|
|
@@ -2215,6 +2221,6 @@ var ownerKeyFile = {
|
|
|
2215
2221
|
sign: signWithOwnerKeyFile
|
|
2216
2222
|
};
|
|
2217
2223
|
|
|
2218
|
-
export { AccountSecurity, DashboardKey, DelegatedKeys, Enrollment, OWNER_KEY_FILE_FORMAT, OWNER_OP, OauthNamespace, OauthSessions, OrgApiKeys, OrgContract, OrgMembers, Organization, Recovery, SigningKeys, Subscriptions, WitnessProposeError, WitnessScopeConflictError, WitniumchainApiError, WitniumchainApiKeyClient, WitniumchainChainAdminClient, WitniumchainClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage, generateOwnerKeyFile, ownerKeyFile, ownerKeyFileName, parseOwnerKeyFile, randomWitnessScope, serializeOwnerKeyFile, signWithOwnerKeyFile, witnessScopeFor };
|
|
2224
|
+
export { AccountSecurity, DashboardKey, DelegatedKeys, Enrollment, OWNER_KEY_FILE_FORMAT, OWNER_OP, OauthNamespace, OauthSessions, OrgApiKeys, OrgContract, OrgMembers, Organization, Recovery, SigningKeys, Subscriptions, WitnessProposeError, WitnessScopeConflictError, WitniumchainApiError, WitniumchainApiKeyClient, WitniumchainChainAdminClient, WitniumchainClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage, generateOwnerKeyFile, ownerKeyFile, ownerKeyFileName, parseApiKey, parseOwnerKeyFile, randomWitnessScope, serializeOwnerKeyFile, signWithOwnerKeyFile, witnessScopeFor };
|
|
2219
2225
|
//# sourceMappingURL=index.mjs.map
|
|
2220
2226
|
//# sourceMappingURL=index.mjs.map
|