@mesub/node 0.1.2 → 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.
- package/README.md +1 -1
- package/dist/{chunk-J2CE4QWV.js → chunk-35MOUS4W.js} +2 -2
- package/dist/{chunk-4AAPR37Y.js → chunk-6HGYY2KN.js} +2 -2
- package/dist/{chunk-4JSJOX35.cjs → chunk-BP5D5I66.cjs} +29 -22
- package/dist/chunk-BP5D5I66.cjs.map +1 -0
- package/dist/{chunk-NOS4FWWQ.js → chunk-JCDJZDEJ.js} +14 -7
- package/dist/chunk-JCDJZDEJ.js.map +1 -0
- package/dist/{chunk-66VVEXMU.cjs → chunk-RSN2QQUR.cjs} +7 -7
- package/dist/{chunk-66VVEXMU.cjs.map → chunk-RSN2QQUR.cjs.map} +1 -1
- package/dist/{chunk-SJRQDWTI.cjs → chunk-WNHLTJ6F.cjs} +4 -4
- package/dist/{chunk-SJRQDWTI.cjs.map → chunk-WNHLTJ6F.cjs.map} +1 -1
- package/dist/{client-BEuDegEY.d.cts → client-BZB6KIGd.d.cts} +3 -2
- package/dist/{client-CXQLkSAJ.d.ts → client-Q5QhXphp.d.ts} +3 -2
- package/dist/express.cjs +21 -21
- package/dist/express.d.cts +3 -3
- package/dist/express.d.ts +3 -3
- package/dist/express.js +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/nest.cjs +13 -13
- package/dist/nest.d.cts +1 -1
- package/dist/nest.d.ts +1 -1
- package/dist/nest.js +2 -2
- package/dist/next.cjs +20 -20
- package/dist/next.d.cts +3 -3
- package/dist/next.d.ts +3 -3
- package/dist/next.js +3 -3
- package/dist/{routes-CMzB52P6.d.cts → routes-DT8EFWSl.d.cts} +1 -1
- package/dist/{routes-B7wN4sby.d.ts → routes-KoaD1Xsk.d.ts} +1 -1
- package/dist/testing.cjs +13 -13
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4JSJOX35.cjs.map +0 -1
- package/dist/chunk-NOS4FWWQ.js.map +0 -1
- /package/dist/{chunk-J2CE4QWV.js.map → chunk-35MOUS4W.js.map} +0 -0
- /package/dist/{chunk-4AAPR37Y.js.map → chunk-6HGYY2KN.js.map} +0 -0
package/README.md
CHANGED
|
@@ -684,7 +684,7 @@ Guards, webhooks, subscribing and managing against it:
|
|
|
684
684
|
```ts
|
|
685
685
|
new Mesub({
|
|
686
686
|
apiKey, // default: process.env.MESUB_API_KEY
|
|
687
|
-
baseUrl, // default: https://api.mesub.io
|
|
687
|
+
baseUrl, // default: process.env.MESUB_BASE_URL, then https://api.mesub.io; may carry a path
|
|
688
688
|
headers, // extra headers on every call, e.g. for a proxy
|
|
689
689
|
timeout, // per attempt, ms, default 5000
|
|
690
690
|
maxRetries, // default 2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MesubError,
|
|
3
3
|
customerOf
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
340
|
+
//# sourceMappingURL=chunk-35MOUS4W.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Mesub,
|
|
3
3
|
customerOf
|
|
4
|
-
} from "./chunk-
|
|
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-
|
|
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.
|
|
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
|
|
113
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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',
|
|
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];
|
|
@@ -882,7 +889,7 @@ function webhookSecretOf(given) {
|
|
|
882
889
|
return secret || void 0;
|
|
883
890
|
}
|
|
884
891
|
function envSecret() {
|
|
885
|
-
return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access',
|
|
892
|
+
return typeof process === "undefined" ? void 0 : _optionalChain([process, 'access', _6 => _6.env, 'optionalAccess', _7 => _7["MESUB_WEBHOOK_SECRET"]]);
|
|
886
893
|
}
|
|
887
894
|
function headerIn(headers, name) {
|
|
888
895
|
if (typeof headers.get === "function") {
|
|
@@ -984,7 +991,7 @@ var Transport = class {
|
|
|
984
991
|
}
|
|
985
992
|
}
|
|
986
993
|
async #attempt(method, url, body, { deadline, signal, ...options }) {
|
|
987
|
-
_optionalChain([signal, 'optionalAccess',
|
|
994
|
+
_optionalChain([signal, 'optionalAccess', _8 => _8.throwIfAborted, 'call', _9 => _9()]);
|
|
988
995
|
const perAttempt = _nullishCoalesce(options.timeout, () => ( this.#config.timeout));
|
|
989
996
|
const left = deadline === void 0 ? Infinity : deadline - Date.now();
|
|
990
997
|
if (left <= 0) {
|
|
@@ -998,8 +1005,8 @@ var Transport = class {
|
|
|
998
1005
|
const cutByDeadline = timeout < perAttempt;
|
|
999
1006
|
const controller = new AbortController();
|
|
1000
1007
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
1001
|
-
const stop = () => controller.abort(_optionalChain([signal, 'optionalAccess',
|
|
1002
|
-
_optionalChain([signal, 'optionalAccess',
|
|
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 })]);
|
|
1003
1010
|
try {
|
|
1004
1011
|
const response = await this.#config.fetch(url, {
|
|
1005
1012
|
method,
|
|
@@ -1051,7 +1058,7 @@ var Transport = class {
|
|
|
1051
1058
|
retryAfter: asked === null ? null : Math.min(asked, MAX_RETRY_AFTER)
|
|
1052
1059
|
};
|
|
1053
1060
|
} catch (cause) {
|
|
1054
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
1061
|
+
if (_optionalChain([signal, 'optionalAccess', _13 => _13.aborted])) throw signal.reason;
|
|
1055
1062
|
if (controller.signal.aborted && cutByDeadline) {
|
|
1056
1063
|
const error2 = new MesubError(
|
|
1057
1064
|
`Mesub did not answer within the ${Math.round(timeout)} ms left before the deadline.`,
|
|
@@ -1064,7 +1071,7 @@ var Transport = class {
|
|
|
1064
1071
|
return { ok: false, error, retry: true, retryAfter: null };
|
|
1065
1072
|
} finally {
|
|
1066
1073
|
clearTimeout(timer);
|
|
1067
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1074
|
+
_optionalChain([signal, 'optionalAccess', _14 => _14.removeEventListener, 'call', _15 => _15("abort", stop)]);
|
|
1068
1075
|
}
|
|
1069
1076
|
}
|
|
1070
1077
|
};
|
|
@@ -1132,13 +1139,13 @@ function sleep(ms, signal) {
|
|
|
1132
1139
|
return new Promise((resolve, reject) => {
|
|
1133
1140
|
const stop = () => {
|
|
1134
1141
|
clearTimeout(timer);
|
|
1135
|
-
reject(_optionalChain([signal, 'optionalAccess',
|
|
1142
|
+
reject(_optionalChain([signal, 'optionalAccess', _16 => _16.reason]));
|
|
1136
1143
|
};
|
|
1137
1144
|
const timer = setTimeout(() => {
|
|
1138
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1145
|
+
_optionalChain([signal, 'optionalAccess', _17 => _17.removeEventListener, 'call', _18 => _18("abort", stop)]);
|
|
1139
1146
|
resolve();
|
|
1140
1147
|
}, ms);
|
|
1141
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1148
|
+
_optionalChain([signal, 'optionalAccess', _19 => _19.addEventListener, 'call', _20 => _20("abort", stop, { once: true })]);
|
|
1142
1149
|
});
|
|
1143
1150
|
}
|
|
1144
1151
|
|
|
@@ -1327,7 +1334,7 @@ var Subscriptions = class {
|
|
|
1327
1334
|
*/
|
|
1328
1335
|
async #settle(id, signal, { sends, cause, from, code, retryable, lead }) {
|
|
1329
1336
|
const subscription = await this.#readBack(id, signal);
|
|
1330
|
-
if (_optionalChain([subscription, 'optionalAccess',
|
|
1337
|
+
if (_optionalChain([subscription, 'optionalAccess', _21 => _21.status]) === "active" || _optionalChain([subscription, 'optionalAccess', _22 => _22.status]) === "cancelled") {
|
|
1331
1338
|
return { subscription };
|
|
1332
1339
|
}
|
|
1333
1340
|
const then = subscription === null ? "Reading the subscription back failed too" : `The subscription read back is ${subscription.status}`;
|
|
@@ -1364,7 +1371,7 @@ var Subscriptions = class {
|
|
|
1364
1371
|
);
|
|
1365
1372
|
return serverSubscriptionFrom(body);
|
|
1366
1373
|
} catch (error) {
|
|
1367
|
-
if (_optionalChain([signal, 'optionalAccess',
|
|
1374
|
+
if (_optionalChain([signal, 'optionalAccess', _23 => _23.aborted])) throw error;
|
|
1368
1375
|
return null;
|
|
1369
1376
|
}
|
|
1370
1377
|
}
|
|
@@ -1777,7 +1784,7 @@ var Mesub = (_class3 = class {
|
|
|
1777
1784
|
if (options.attempts === true) return this.ask(asked, slug, null, boundOf(options));
|
|
1778
1785
|
const slot = await this.slotOf(asked);
|
|
1779
1786
|
const cached = await this.cache.read(slot.who, slug, slot.scope);
|
|
1780
|
-
if (_optionalChain([cached, 'optionalAccess',
|
|
1787
|
+
if (_optionalChain([cached, 'optionalAccess', _24 => _24.fresh])) return cached.value;
|
|
1781
1788
|
return this.ask(asked, slug, slot);
|
|
1782
1789
|
}
|
|
1783
1790
|
/**
|
|
@@ -1793,7 +1800,7 @@ var Mesub = (_class3 = class {
|
|
|
1793
1800
|
const slot = attempts ? null : await this.slotOf(asked);
|
|
1794
1801
|
if (slot) {
|
|
1795
1802
|
const cached = await this.lists.read(slot.who, null, slot.scope);
|
|
1796
|
-
if (_optionalChain([cached, 'optionalAccess',
|
|
1803
|
+
if (_optionalChain([cached, 'optionalAccess', _25 => _25.fresh])) return cached.value;
|
|
1797
1804
|
}
|
|
1798
1805
|
const request = async () => accessListFrom(
|
|
1799
1806
|
await this.transport.get("/v1/access", {
|
|
@@ -1954,7 +1961,7 @@ var Mesub = (_class3 = class {
|
|
|
1954
1961
|
const slug = planOf(plan);
|
|
1955
1962
|
const slot = await this.slotOf(asked);
|
|
1956
1963
|
const cached = await this.cache.read(slot.who, slug, slot.scope, deadline);
|
|
1957
|
-
if (_optionalChain([cached, 'optionalAccess',
|
|
1964
|
+
if (_optionalChain([cached, 'optionalAccess', _26 => _26.fresh])) {
|
|
1958
1965
|
return { access: cached.value.access, answer: cached.value, stale: false };
|
|
1959
1966
|
}
|
|
1960
1967
|
try {
|
|
@@ -2037,4 +2044,4 @@ function stillGrants(answer, now = Date.now()) {
|
|
|
2037
2044
|
|
|
2038
2045
|
|
|
2039
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;
|
|
2040
|
-
//# sourceMappingURL=chunk-
|
|
2047
|
+
//# sourceMappingURL=chunk-BP5D5I66.cjs.map
|