@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/dist/index.js CHANGED
@@ -1,5 +1,21 @@
1
1
  'use strict';
2
2
 
3
+ // src/api-key.ts
4
+ var PREFIXED_FORMAT = /^wcak_(live|sandbox)_[0-9a-f]{64}$/;
5
+ var LEGACY_FORMAT = /^wcak_[0-9a-f]{64}$/;
6
+ function parseApiKey(apiKey) {
7
+ const prefixed = PREFIXED_FORMAT.exec(apiKey);
8
+ if (prefixed) {
9
+ return { environment: prefixed[1], legacyFormat: false };
10
+ }
11
+ if (LEGACY_FORMAT.test(apiKey)) {
12
+ return { environment: "live", legacyFormat: true };
13
+ }
14
+ throw new Error(
15
+ "apiKey must be `wcak_live_` or `wcak_sandbox_` followed by 64 lowercase hex (or a pre-sandbox `wcak_` key)"
16
+ );
17
+ }
18
+
3
19
  // src/errors.ts
4
20
  var WitniumchainApiError = class extends Error {
5
21
  status;
@@ -247,6 +263,13 @@ var WitniumchainClient = class {
247
263
  if (!config.baseUrl) {
248
264
  throw new Error("WitniumchainClient: baseUrl is required");
249
265
  }
266
+ if (config.apiKey !== void 0) {
267
+ try {
268
+ parseApiKey(config.apiKey);
269
+ } catch (err) {
270
+ throw new Error(`WitniumchainClient: ${err.message}`);
271
+ }
272
+ }
250
273
  this.cfg = config;
251
274
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
252
275
  this.chainBaseUrl = config.chainBaseUrl?.replace(/\/$/, "");
@@ -492,19 +515,6 @@ var WitniumchainClient = class {
492
515
  return this.req("POST", "/v1/auth/reset-password", { auth: "Public", body });
493
516
  }
494
517
  // ────────────────────────────────────────────────────────────────────────
495
- // Billing (/v1/billing/*)
496
- // ────────────────────────────────────────────────────────────────────────
497
- createCheckoutSession(body) {
498
- return this.req("POST", "/v1/billing/checkout", {
499
- auth: "SessionOrBearer",
500
- body
501
- });
502
- }
503
- createPortalSession() {
504
- return this.req("GET", "/v1/billing/portal", { auth: "SessionOrBearer" });
505
- }
506
- // Webhook endpoint is intentionally NOT exposed: only Stripe should call it.
507
- // ────────────────────────────────────────────────────────────────────────
508
518
  // Orgs (/v1/orgs/me/*)
509
519
  // ────────────────────────────────────────────────────────────────────────
510
520
  /** The calling API key's own description: its contract and signing key (API key only). */
@@ -1551,22 +1561,6 @@ var Subscriptions = class {
1551
1561
  this.client = client;
1552
1562
  }
1553
1563
  client;
1554
- /**
1555
- * Start a Stripe Checkout session for the supplied price. Returns the
1556
- * hosted Checkout URL; redirect the user to it. Stripe's
1557
- * `checkout.session.completed` webhook grants credits on success.
1558
- */
1559
- subscribe(body) {
1560
- return this.client.createCheckoutSession(body);
1561
- }
1562
- /**
1563
- * Open the Stripe Billing Portal for the calling user's org. Returns the
1564
- * hosted portal URL — redirect the user there for subscription /
1565
- * payment-method management.
1566
- */
1567
- manage() {
1568
- return this.client.createPortalSession();
1569
- }
1570
1564
  /** Recent credit-ledger entries (most recent 200). */
1571
1565
  getLedger() {
1572
1566
  return this.client.getLedger();
@@ -2048,13 +2042,25 @@ function safeParse(text) {
2048
2042
  }
2049
2043
 
2050
2044
  // src/api-key-client.ts
2051
- var API_KEY_FORMAT = /^wcak_[0-9a-f]{64}$/;
2052
2045
  var WitniumchainApiKeyClient = class {
2053
2046
  inner;
2047
+ /**
2048
+ * `live` or `sandbox`, from the key's prefix. Accounts
2049
+ * decides from its own record of the key; this is for the caller's checks
2050
+ * and logs.
2051
+ */
2052
+ environment;
2053
+ /** True for a pre-sandbox `wcak_` + 64 hex key. Rotate it to a `wcak_live_` key before accounts' cutoff. */
2054
+ legacyKeyFormat;
2054
2055
  constructor(config) {
2055
- if (!API_KEY_FORMAT.test(config.apiKey)) {
2056
- throw new Error("WitniumchainApiKeyClient: apiKey must be `wcak_` and 64 lowercase hex");
2056
+ let parsed;
2057
+ try {
2058
+ parsed = parseApiKey(config.apiKey);
2059
+ } catch (err) {
2060
+ throw new Error(`WitniumchainApiKeyClient: ${err.message}`);
2057
2061
  }
2062
+ this.environment = parsed.environment;
2063
+ this.legacyKeyFormat = parsed.legacyFormat;
2058
2064
  this.inner = new WitniumchainClient({
2059
2065
  baseUrl: config.baseUrl,
2060
2066
  apiKey: config.apiKey,
@@ -2246,6 +2252,7 @@ exports.defaultVerifierStorage = defaultVerifierStorage;
2246
2252
  exports.generateOwnerKeyFile = generateOwnerKeyFile;
2247
2253
  exports.ownerKeyFile = ownerKeyFile;
2248
2254
  exports.ownerKeyFileName = ownerKeyFileName;
2255
+ exports.parseApiKey = parseApiKey;
2249
2256
  exports.parseOwnerKeyFile = parseOwnerKeyFile;
2250
2257
  exports.randomWitnessScope = randomWitnessScope;
2251
2258
  exports.serializeOwnerKeyFile = serializeOwnerKeyFile;