@mesub/node 0.1.0 → 0.1.3

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.
Files changed (50) hide show
  1. package/README.md +10 -5
  2. package/dist/{chunk-ELK7IBLO.js → chunk-35MOUS4W.js} +2 -2
  3. package/dist/{chunk-XDLLXY7Y.js → chunk-6HGYY2KN.js} +2 -2
  4. package/dist/{chunk-SGSYQJYT.cjs → chunk-BP5D5I66.cjs} +31 -22
  5. package/dist/chunk-BP5D5I66.cjs.map +1 -0
  6. package/dist/{chunk-KMPBFNJE.js → chunk-JCDJZDEJ.js} +16 -7
  7. package/dist/chunk-JCDJZDEJ.js.map +1 -0
  8. package/dist/{chunk-PCDZI7B4.cjs → chunk-RSN2QQUR.cjs} +7 -7
  9. package/dist/{chunk-PCDZI7B4.cjs.map → chunk-RSN2QQUR.cjs.map} +1 -1
  10. package/dist/{chunk-VMKI4VVA.cjs → chunk-WNHLTJ6F.cjs} +4 -4
  11. package/dist/{chunk-VMKI4VVA.cjs.map → chunk-WNHLTJ6F.cjs.map} +1 -1
  12. package/dist/{client-Dm1jamju.d.cts → client-BZB6KIGd.d.cts} +10 -3
  13. package/dist/{client-BQuRYSdB.d.ts → client-Q5QhXphp.d.ts} +10 -3
  14. package/dist/{errors-DqW3DMBS.d.ts → errors-BN4ZWUfM.d.ts} +1 -1
  15. package/dist/{errors-CtPucyOh.d.cts → errors-DcLfunS-.d.cts} +1 -1
  16. package/dist/express.cjs +21 -21
  17. package/dist/express.d.cts +7 -7
  18. package/dist/express.d.ts +7 -7
  19. package/dist/express.js +3 -3
  20. package/dist/{guard-DKb6iU1z.d.ts → guard-CaXiHMVF.d.ts} +1 -1
  21. package/dist/{guard-Dhy4fI6n.d.cts → guard-D4AB5HtN.d.cts} +1 -1
  22. package/dist/index.cjs +2 -2
  23. package/dist/index.d.cts +5 -5
  24. package/dist/index.d.ts +5 -5
  25. package/dist/index.js +1 -1
  26. package/dist/nest.cjs +13 -13
  27. package/dist/nest.d.cts +5 -5
  28. package/dist/nest.d.ts +5 -5
  29. package/dist/nest.js +2 -2
  30. package/dist/next.cjs +20 -20
  31. package/dist/next.d.cts +7 -7
  32. package/dist/next.d.ts +7 -7
  33. package/dist/next.js +3 -3
  34. package/dist/{routes-DWkRFOP0.d.cts → routes-DT8EFWSl.d.cts} +2 -2
  35. package/dist/{routes-CLtZnUzl.d.ts → routes-KoaD1Xsk.d.ts} +2 -2
  36. package/dist/situations.d.cts +1 -1
  37. package/dist/situations.d.ts +1 -1
  38. package/dist/{subscriptions-D1hE7MUc.d.ts → subscriptions-B6Lin6i_.d.cts} +7 -0
  39. package/dist/{subscriptions-D1hE7MUc.d.cts → subscriptions-B6Lin6i_.d.ts} +7 -0
  40. package/dist/testing.cjs +20 -18
  41. package/dist/testing.cjs.map +1 -1
  42. package/dist/testing.d.cts +2 -2
  43. package/dist/testing.d.ts +2 -2
  44. package/dist/testing.js +8 -6
  45. package/dist/testing.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-KMPBFNJE.js.map +0 -1
  48. package/dist/chunk-SGSYQJYT.cjs.map +0 -1
  49. /package/dist/{chunk-ELK7IBLO.js.map → chunk-35MOUS4W.js.map} +0 -0
  50. /package/dist/{chunk-XDLLXY7Y.js.map → chunk-6HGYY2KN.js.map} +0 -0
package/README.md CHANGED
@@ -11,9 +11,12 @@ have the wallet sign.
11
11
  **[Read the docs](https://docs.mesub.io)** for the walkthroughs. This page is
12
12
  the short version and the reference of the options.
13
13
 
14
- > **Status: early, 0.x, not on npm yet.** The API may still change between
15
- > minor versions. See the [board](https://github.com/orgs/Mesub-io/projects/4)
16
- > for what is next.
14
+ [![npm](https://img.shields.io/npm/v/@mesub/node)](https://www.npmjs.com/package/@mesub/node)
15
+
16
+ > **Status: early, 0.x.** The API may still change between minor versions:
17
+ > `npm update` takes patches (0.1.x), a new minor (0.2.0) takes
18
+ > `npm install @mesub/node@latest`. See the
19
+ > [board](https://github.com/orgs/Mesub-io/projects/4) for what is next.
17
20
 
18
21
  ## Install
19
22
 
@@ -21,7 +24,9 @@ the short version and the reference of the options.
21
24
  npm install @mesub/node
22
25
  ```
23
26
 
24
- Node 22 or later. No runtime dependency.
27
+ Node 22 or later. No runtime dependency. Every release is built by GitHub
28
+ Actions from a tagged commit and published with a provenance statement:
29
+ `npm audit signatures` verifies it.
25
30
 
26
31
  ## How it fits
27
32
 
@@ -679,7 +684,7 @@ Guards, webhooks, subscribing and managing against it:
679
684
  ```ts
680
685
  new Mesub({
681
686
  apiKey, // default: process.env.MESUB_API_KEY
682
- baseUrl, // default: https://api.mesub.io, may carry a path
687
+ baseUrl, // default: process.env.MESUB_BASE_URL, then https://api.mesub.io; may carry a path
683
688
  headers, // extra headers on every call, e.g. for a proxy
684
689
  timeout, // per attempt, ms, default 5000
685
690
  maxRetries, // default 2
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MesubError,
3
3
  customerOf
4
- } from "./chunk-KMPBFNJE.js";
4
+ } from "./chunk-JCDJZDEJ.js";
5
5
 
6
6
  // src/routes.ts
7
7
  var MAX_BODY_BYTES = 64 * 1024;
@@ -337,4 +337,4 @@ export {
337
337
  widgetCustomer,
338
338
  checkWidgetOptions
339
339
  };
340
- //# sourceMappingURL=chunk-ELK7IBLO.js.map
340
+ //# sourceMappingURL=chunk-35MOUS4W.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Mesub,
3
3
  customerOf
4
- } from "./chunk-KMPBFNJE.js";
4
+ } from "./chunk-JCDJZDEJ.js";
5
5
 
6
6
  // src/guard.ts
7
7
  var DENIAL_STATUS = {
@@ -117,4 +117,4 @@ export {
117
117
  accessOf,
118
118
  denialOf
119
119
  };
120
- //# sourceMappingURL=chunk-XDLLXY7Y.js.map
120
+ //# sourceMappingURL=chunk-6HGYY2KN.js.map
@@ -86,7 +86,7 @@ var AccessCache = class _AccessCache {
86
86
  };
87
87
 
88
88
  // src/version.ts
89
- var VERSION = "0.1.0";
89
+ var VERSION = "0.1.3";
90
90
  var API_VERSION = "2026-10-02";
91
91
  var API_VERSION_HEADER = "Mesub-Version";
92
92
 
@@ -109,23 +109,30 @@ function envKey() {
109
109
  return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access', _ => _.env, 'optionalAccess', _2 => _2["MESUB_API_KEY"]]);
110
110
  }
111
111
  function baseUrlOf(given, fallback) {
112
- if (given === void 0) return fallback;
113
- if (typeof given !== "string") throw new TypeError("baseUrl must be a string.");
112
+ if (given !== void 0) return checkedBaseUrl("baseUrl", given);
113
+ const fromEnv = envBaseUrl();
114
+ return fromEnv ? checkedBaseUrl("MESUB_BASE_URL", fromEnv) : fallback;
115
+ }
116
+ function envBaseUrl() {
117
+ return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access', _3 => _3.env, 'optionalAccess', _4 => _4["MESUB_BASE_URL"]]);
118
+ }
119
+ function checkedBaseUrl(name, given) {
120
+ if (typeof given !== "string") throw new TypeError(`${name} must be a string.`);
114
121
  let url;
115
122
  try {
116
123
  url = new URL(given);
117
124
  } catch (e4) {
118
- throw new TypeError(`baseUrl must be an absolute URL, not ${JSON.stringify(given)}.`);
125
+ throw new TypeError(`${name} must be an absolute URL, not ${JSON.stringify(given)}.`);
119
126
  }
120
127
  if (url.search !== "" || url.hash !== "" || given.includes("?") || given.includes("#")) {
121
128
  throw new TypeError(
122
- `baseUrl must have no query nor fragment, not ${JSON.stringify(given)}.`
129
+ `${name} must have no query nor fragment, not ${JSON.stringify(given)}.`
123
130
  );
124
131
  }
125
132
  const local = url.protocol === "http:" && LOOPBACK.has(url.hostname);
126
133
  if (url.protocol !== "https:" && !local) {
127
134
  throw new TypeError(
128
- `baseUrl must be https (http only to localhost or 127.0.0.1), not ${url.protocol}//${url.host}: every call carries the API key.`
135
+ `${name} must be https (http only to localhost or 127.0.0.1), not ${url.protocol}//${url.host}: every call carries the API key.`
129
136
  );
130
137
  }
131
138
  return given.replace(/\/+$/, "");
@@ -218,7 +225,7 @@ var CUSTOMER_KINDS = ["wallet", "external_id", "email"];
218
225
  function customerOf(customer) {
219
226
  if (typeof customer === "string") return { kind: "wallet", value: customer };
220
227
  const named = CUSTOMER_KINDS.filter(
221
- (kind2) => _optionalChain([customer, 'optionalAccess', _3 => _3[kind2]]) !== void 0
228
+ (kind2) => _optionalChain([customer, 'optionalAccess', _5 => _5[kind2]]) !== void 0
222
229
  );
223
230
  const kind = named[0];
224
231
  const value = kind && customer[kind];
@@ -343,6 +350,7 @@ var CLOSABLE = { ...BOOLEAN, absent: false };
343
350
  var CLOSABLE_FROM = { ...DATE_OR_NULL, absent: null };
344
351
  var TRANSACTION_EXPIRES_AT = { ...DATE_OR_NULL, absent: null };
345
352
  var AMOUNT_USD = { ...STRING_OR_NULL, absent: null };
353
+ var AMOUNT_RECEIVED = { ...STRING_OR_NULL, absent: null };
346
354
  var TOKEN = {
347
355
  ...OBJECT,
348
356
  absent: () => ({ symbol: null, name: null, logo_url: null, verified: false })
@@ -453,6 +461,7 @@ var SUBSCRIPTION_ATTEMPT = {
453
461
  reason: STRING_OR_NULL,
454
462
  amount: STRING,
455
463
  amount_usd: AMOUNT_USD,
464
+ amount_received: AMOUNT_RECEIVED,
456
465
  signature: STRING_OR_NULL,
457
466
  retry: BOOLEAN,
458
467
  retry_number: RETRY_COUNT,
@@ -880,7 +889,7 @@ function webhookSecretOf(given) {
880
889
  return secret || void 0;
881
890
  }
882
891
  function envSecret() {
883
- return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access', _4 => _4.env, 'optionalAccess', _5 => _5["MESUB_WEBHOOK_SECRET"]]);
892
+ return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access', _6 => _6.env, 'optionalAccess', _7 => _7["MESUB_WEBHOOK_SECRET"]]);
884
893
  }
885
894
  function headerIn(headers, name) {
886
895
  if (typeof headers.get === "function") {
@@ -982,7 +991,7 @@ var Transport = class {
982
991
  }
983
992
  }
984
993
  async #attempt(method, url, body, { deadline, signal, ...options }) {
985
- _optionalChain([signal, 'optionalAccess', _6 => _6.throwIfAborted, 'call', _7 => _7()]);
994
+ _optionalChain([signal, 'optionalAccess', _8 => _8.throwIfAborted, 'call', _9 => _9()]);
986
995
  const perAttempt = _nullishCoalesce(options.timeout, () => ( this.#config.timeout));
987
996
  const left = deadline === void 0 ? Infinity : deadline - Date.now();
988
997
  if (left <= 0) {
@@ -996,8 +1005,8 @@ var Transport = class {
996
1005
  const cutByDeadline = timeout < perAttempt;
997
1006
  const controller = new AbortController();
998
1007
  const timer = setTimeout(() => controller.abort(), timeout);
999
- const stop = () => controller.abort(_optionalChain([signal, 'optionalAccess', _8 => _8.reason]));
1000
- _optionalChain([signal, 'optionalAccess', _9 => _9.addEventListener, 'call', _10 => _10("abort", stop, { once: true })]);
1008
+ const stop = () => controller.abort(_optionalChain([signal, 'optionalAccess', _10 => _10.reason]));
1009
+ _optionalChain([signal, 'optionalAccess', _11 => _11.addEventListener, 'call', _12 => _12("abort", stop, { once: true })]);
1001
1010
  try {
1002
1011
  const response = await this.#config.fetch(url, {
1003
1012
  method,
@@ -1049,7 +1058,7 @@ var Transport = class {
1049
1058
  retryAfter: asked === null ? null : Math.min(asked, MAX_RETRY_AFTER)
1050
1059
  };
1051
1060
  } catch (cause) {
1052
- if (_optionalChain([signal, 'optionalAccess', _11 => _11.aborted])) throw signal.reason;
1061
+ if (_optionalChain([signal, 'optionalAccess', _13 => _13.aborted])) throw signal.reason;
1053
1062
  if (controller.signal.aborted && cutByDeadline) {
1054
1063
  const error2 = new MesubError(
1055
1064
  `Mesub did not answer within the ${Math.round(timeout)} ms left before the deadline.`,
@@ -1062,7 +1071,7 @@ var Transport = class {
1062
1071
  return { ok: false, error, retry: true, retryAfter: null };
1063
1072
  } finally {
1064
1073
  clearTimeout(timer);
1065
- _optionalChain([signal, 'optionalAccess', _12 => _12.removeEventListener, 'call', _13 => _13("abort", stop)]);
1074
+ _optionalChain([signal, 'optionalAccess', _14 => _14.removeEventListener, 'call', _15 => _15("abort", stop)]);
1066
1075
  }
1067
1076
  }
1068
1077
  };
@@ -1130,13 +1139,13 @@ function sleep(ms, signal) {
1130
1139
  return new Promise((resolve, reject) => {
1131
1140
  const stop = () => {
1132
1141
  clearTimeout(timer);
1133
- reject(_optionalChain([signal, 'optionalAccess', _14 => _14.reason]));
1142
+ reject(_optionalChain([signal, 'optionalAccess', _16 => _16.reason]));
1134
1143
  };
1135
1144
  const timer = setTimeout(() => {
1136
- _optionalChain([signal, 'optionalAccess', _15 => _15.removeEventListener, 'call', _16 => _16("abort", stop)]);
1145
+ _optionalChain([signal, 'optionalAccess', _17 => _17.removeEventListener, 'call', _18 => _18("abort", stop)]);
1137
1146
  resolve();
1138
1147
  }, ms);
1139
- _optionalChain([signal, 'optionalAccess', _17 => _17.addEventListener, 'call', _18 => _18("abort", stop, { once: true })]);
1148
+ _optionalChain([signal, 'optionalAccess', _19 => _19.addEventListener, 'call', _20 => _20("abort", stop, { once: true })]);
1140
1149
  });
1141
1150
  }
1142
1151
 
@@ -1325,7 +1334,7 @@ var Subscriptions = class {
1325
1334
  */
1326
1335
  async #settle(id, signal, { sends, cause, from, code, retryable, lead }) {
1327
1336
  const subscription = await this.#readBack(id, signal);
1328
- if (_optionalChain([subscription, 'optionalAccess', _19 => _19.status]) === "active" || _optionalChain([subscription, 'optionalAccess', _20 => _20.status]) === "cancelled") {
1337
+ if (_optionalChain([subscription, 'optionalAccess', _21 => _21.status]) === "active" || _optionalChain([subscription, 'optionalAccess', _22 => _22.status]) === "cancelled") {
1329
1338
  return { subscription };
1330
1339
  }
1331
1340
  const then = subscription === null ? "Reading the subscription back failed too" : `The subscription read back is ${subscription.status}`;
@@ -1362,7 +1371,7 @@ var Subscriptions = class {
1362
1371
  );
1363
1372
  return serverSubscriptionFrom(body);
1364
1373
  } catch (error) {
1365
- if (_optionalChain([signal, 'optionalAccess', _21 => _21.aborted])) throw error;
1374
+ if (_optionalChain([signal, 'optionalAccess', _23 => _23.aborted])) throw error;
1366
1375
  return null;
1367
1376
  }
1368
1377
  }
@@ -1775,7 +1784,7 @@ var Mesub = (_class3 = class {
1775
1784
  if (options.attempts === true) return this.ask(asked, slug, null, boundOf(options));
1776
1785
  const slot = await this.slotOf(asked);
1777
1786
  const cached = await this.cache.read(slot.who, slug, slot.scope);
1778
- if (_optionalChain([cached, 'optionalAccess', _22 => _22.fresh])) return cached.value;
1787
+ if (_optionalChain([cached, 'optionalAccess', _24 => _24.fresh])) return cached.value;
1779
1788
  return this.ask(asked, slug, slot);
1780
1789
  }
1781
1790
  /**
@@ -1791,7 +1800,7 @@ var Mesub = (_class3 = class {
1791
1800
  const slot = attempts ? null : await this.slotOf(asked);
1792
1801
  if (slot) {
1793
1802
  const cached = await this.lists.read(slot.who, null, slot.scope);
1794
- if (_optionalChain([cached, 'optionalAccess', _23 => _23.fresh])) return cached.value;
1803
+ if (_optionalChain([cached, 'optionalAccess', _25 => _25.fresh])) return cached.value;
1795
1804
  }
1796
1805
  const request = async () => accessListFrom(
1797
1806
  await this.transport.get("/v1/access", {
@@ -1952,7 +1961,7 @@ var Mesub = (_class3 = class {
1952
1961
  const slug = planOf(plan);
1953
1962
  const slot = await this.slotOf(asked);
1954
1963
  const cached = await this.cache.read(slot.who, slug, slot.scope, deadline);
1955
- if (_optionalChain([cached, 'optionalAccess', _24 => _24.fresh])) {
1964
+ if (_optionalChain([cached, 'optionalAccess', _26 => _26.fresh])) {
1956
1965
  return { access: cached.value.access, answer: cached.value, stale: false };
1957
1966
  }
1958
1967
  try {
@@ -2035,4 +2044,4 @@ function stillGrants(answer, now = Date.now()) {
2035
2044
 
2036
2045
 
2037
2046
  exports.DEFAULT_MAX_STALE_MS = DEFAULT_MAX_STALE_MS; exports.AccessCache = AccessCache; exports.VERSION = VERSION; exports.API_VERSION = API_VERSION; exports.API_VERSION_HEADER = API_VERSION_HEADER; exports.DEFAULT_MAX_ENTRIES = DEFAULT_MAX_ENTRIES; exports.MemoryStore = MemoryStore; exports.customerOf = customerOf; exports.MesubError = MesubError; exports.MesubSubmitError = MesubSubmitError; exports.verifyWebhook = verifyWebhook; exports.signedHeaders = signedHeaders; exports.Mesub = Mesub;
2038
- //# sourceMappingURL=chunk-SGSYQJYT.cjs.map
2047
+ //# sourceMappingURL=chunk-BP5D5I66.cjs.map