@mesub/node 0.1.0 → 0.1.2
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 +9 -4
- package/dist/{chunk-XDLLXY7Y.js → chunk-4AAPR37Y.js} +2 -2
- package/dist/{chunk-SGSYQJYT.cjs → chunk-4JSJOX35.cjs} +4 -2
- package/dist/chunk-4JSJOX35.cjs.map +1 -0
- package/dist/{chunk-PCDZI7B4.cjs → chunk-66VVEXMU.cjs} +7 -7
- package/dist/{chunk-PCDZI7B4.cjs.map → chunk-66VVEXMU.cjs.map} +1 -1
- package/dist/{chunk-ELK7IBLO.js → chunk-J2CE4QWV.js} +2 -2
- package/dist/{chunk-KMPBFNJE.js → chunk-NOS4FWWQ.js} +4 -2
- package/dist/chunk-NOS4FWWQ.js.map +1 -0
- package/dist/{chunk-VMKI4VVA.cjs → chunk-SJRQDWTI.cjs} +4 -4
- package/dist/{chunk-VMKI4VVA.cjs.map → chunk-SJRQDWTI.cjs.map} +1 -1
- package/dist/{client-Dm1jamju.d.cts → client-BEuDegEY.d.cts} +7 -1
- package/dist/{client-BQuRYSdB.d.ts → client-CXQLkSAJ.d.ts} +7 -1
- package/dist/{errors-DqW3DMBS.d.ts → errors-BN4ZWUfM.d.ts} +1 -1
- package/dist/{errors-CtPucyOh.d.cts → errors-DcLfunS-.d.cts} +1 -1
- package/dist/express.cjs +21 -21
- package/dist/express.d.cts +7 -7
- package/dist/express.d.ts +7 -7
- package/dist/express.js +3 -3
- package/dist/{guard-DKb6iU1z.d.ts → guard-CaXiHMVF.d.ts} +1 -1
- package/dist/{guard-Dhy4fI6n.d.cts → guard-D4AB5HtN.d.cts} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/nest.cjs +13 -13
- package/dist/nest.d.cts +5 -5
- package/dist/nest.d.ts +5 -5
- package/dist/nest.js +2 -2
- package/dist/next.cjs +20 -20
- package/dist/next.d.cts +7 -7
- package/dist/next.d.ts +7 -7
- package/dist/next.js +3 -3
- package/dist/{routes-CLtZnUzl.d.ts → routes-B7wN4sby.d.ts} +2 -2
- package/dist/{routes-DWkRFOP0.d.cts → routes-CMzB52P6.d.cts} +2 -2
- package/dist/situations.d.cts +1 -1
- package/dist/situations.d.ts +1 -1
- package/dist/{subscriptions-D1hE7MUc.d.ts → subscriptions-B6Lin6i_.d.cts} +7 -0
- package/dist/{subscriptions-D1hE7MUc.d.cts → subscriptions-B6Lin6i_.d.ts} +7 -0
- package/dist/testing.cjs +20 -18
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +8 -6
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-KMPBFNJE.js.map +0 -1
- package/dist/chunk-SGSYQJYT.cjs.map +0 -1
- /package/dist/{chunk-XDLLXY7Y.js.map → chunk-4AAPR37Y.js.map} +0 -0
- /package/dist/{chunk-ELK7IBLO.js.map → chunk-J2CE4QWV.js.map} +0 -0
package/dist/next.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { M as Mesub } from './client-
|
|
2
|
-
import { M as MesubAccess, P as PlanOption, C as CustomerOption, D as Denial } from './guard-
|
|
3
|
-
export { A as Asked, a as DenialReason } from './guard-
|
|
4
|
-
import { W as WidgetRoutesOptions } from './routes-
|
|
5
|
-
export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-
|
|
6
|
-
export { M as MesubError } from './errors-
|
|
7
|
-
export { C as Customer } from './subscriptions-
|
|
1
|
+
import { M as Mesub } from './client-CXQLkSAJ.js';
|
|
2
|
+
import { M as MesubAccess, P as PlanOption, C as CustomerOption, D as Denial } from './guard-CaXiHMVF.js';
|
|
3
|
+
export { A as Asked, a as DenialReason } from './guard-CaXiHMVF.js';
|
|
4
|
+
import { W as WidgetRoutesOptions } from './routes-B7wN4sby.js';
|
|
5
|
+
export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-B7wN4sby.js';
|
|
6
|
+
export { M as MesubError } from './errors-BN4ZWUfM.js';
|
|
7
|
+
export { C as Customer } from './subscriptions-B6Lin6i_.js';
|
|
8
8
|
|
|
9
9
|
/** `@mesub/node/next`: `withMesub()`. Web `Request`/`Response` only, nothing imported from `next`. */
|
|
10
10
|
|
package/dist/next.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
checkWidgetOptions,
|
|
4
4
|
handleWidget,
|
|
5
5
|
widgetCustomer
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J2CE4QWV.js";
|
|
7
7
|
import {
|
|
8
8
|
accessOf,
|
|
9
9
|
askerOf,
|
|
@@ -15,10 +15,10 @@ import {
|
|
|
15
15
|
guard,
|
|
16
16
|
plansOf,
|
|
17
17
|
retryAfterOf
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-4AAPR37Y.js";
|
|
19
19
|
import {
|
|
20
20
|
MesubError
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-NOS4FWWQ.js";
|
|
22
22
|
|
|
23
23
|
// src/next.ts
|
|
24
24
|
function withMesub(handler, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Customer, j as ServerSubscription } from './subscriptions-
|
|
2
|
-
import { M as Mesub } from './client-
|
|
1
|
+
import { C as Customer, j as ServerSubscription } from './subscriptions-B6Lin6i_.js';
|
|
2
|
+
import { M as Mesub } from './client-CXQLkSAJ.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The routes `@mesub/react` calls on your own server, so the browser never
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as Customer, j as ServerSubscription } from './subscriptions-
|
|
2
|
-
import { M as Mesub } from './client-
|
|
1
|
+
import { C as Customer, j as ServerSubscription } from './subscriptions-B6Lin6i_.cjs';
|
|
2
|
+
import { M as Mesub } from './client-BEuDegEY.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The routes `@mesub/react` calls on your own server, so the browser never
|
package/dist/situations.d.cts
CHANGED
package/dist/situations.d.ts
CHANGED
|
@@ -484,6 +484,13 @@ interface SubscriptionAttempt {
|
|
|
484
484
|
* knows no price, and from a Mesub that predates it.
|
|
485
485
|
*/
|
|
486
486
|
amount_usd: string | null;
|
|
487
|
+
/**
|
|
488
|
+
* What the receiver's account got of a `paid` one, in the mint's smallest
|
|
489
|
+
* unit: `amount` less the fee a Token-2022 mint withholds on transfers.
|
|
490
|
+
* Null when not known (an attempt not paid, one recorded before Mesub
|
|
491
|
+
* kept it) and from a Mesub that predates it.
|
|
492
|
+
*/
|
|
493
|
+
amount_received: string | null;
|
|
487
494
|
/** The transaction that paid. Null on every outcome but `paid`, a refused one included. */
|
|
488
495
|
signature: string | null;
|
|
489
496
|
/** The subscription had already failed on this period. */
|
|
@@ -484,6 +484,13 @@ interface SubscriptionAttempt {
|
|
|
484
484
|
* knows no price, and from a Mesub that predates it.
|
|
485
485
|
*/
|
|
486
486
|
amount_usd: string | null;
|
|
487
|
+
/**
|
|
488
|
+
* What the receiver's account got of a `paid` one, in the mint's smallest
|
|
489
|
+
* unit: `amount` less the fee a Token-2022 mint withholds on transfers.
|
|
490
|
+
* Null when not known (an attempt not paid, one recorded before Mesub
|
|
491
|
+
* kept it) and from a Mesub that predates it.
|
|
492
|
+
*/
|
|
493
|
+
amount_received: string | null;
|
|
487
494
|
/** The transaction that paid. Null on every outcome but `paid`, a refused one included. */
|
|
488
495
|
signature: string | null;
|
|
489
496
|
/** The subscription had already failed on this period. */
|
package/dist/testing.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk4JSJOX35cjs = require('./chunk-4JSJOX35.cjs');
|
|
8
8
|
|
|
9
9
|
// src/testing.ts
|
|
10
10
|
var ACCESS_ATTEMPTS = 5;
|
|
@@ -166,7 +166,7 @@ var FakeMesub = (_class = class {
|
|
|
166
166
|
* unless asked, so a failure shows at once. Any other option is passed on.
|
|
167
167
|
*/
|
|
168
168
|
client(options = {}) {
|
|
169
|
-
return new (0,
|
|
169
|
+
return new (0, _chunk4JSJOX35cjs.Mesub)({
|
|
170
170
|
maxRetries: 0,
|
|
171
171
|
...options,
|
|
172
172
|
apiKey: this.apiKey,
|
|
@@ -262,7 +262,7 @@ var FakeMesub = (_class = class {
|
|
|
262
262
|
* asked about, and to null for an external id or an email.
|
|
263
263
|
*/
|
|
264
264
|
setAccess(customer, plan, fields) {
|
|
265
|
-
const asked =
|
|
265
|
+
const asked = _chunk4JSJOX35cjs.customerOf.call(void 0, customer);
|
|
266
266
|
const answer = { ...nothing(asked, plan), ...fields, plan };
|
|
267
267
|
this.#answers.set(keyOf(asked, plan), answer);
|
|
268
268
|
return this.#fresh(answer);
|
|
@@ -307,6 +307,8 @@ var FakeMesub = (_class = class {
|
|
|
307
307
|
amount: "9990000",
|
|
308
308
|
// The default amount's worth only: no price is guessed for another.
|
|
309
309
|
amount_usd: attempt.amount === void 0 ? "9.99" : null,
|
|
310
|
+
// A mint that withholds nothing: the receiver got it all.
|
|
311
|
+
amount_received: _nullishCoalesce(attempt.amount, () => ( "9990000")),
|
|
310
312
|
signature: "fake_signature",
|
|
311
313
|
retry: false,
|
|
312
314
|
retry_number: null,
|
|
@@ -347,8 +349,8 @@ var FakeMesub = (_class = class {
|
|
|
347
349
|
object: "event",
|
|
348
350
|
type,
|
|
349
351
|
created_at: _nullishCoalesce(fields.created_at, () => ( now.toISOString())),
|
|
350
|
-
network: "
|
|
351
|
-
api_version:
|
|
352
|
+
network: "mainnet-beta",
|
|
353
|
+
api_version: _chunk4JSJOX35cjs.API_VERSION,
|
|
352
354
|
...sequence !== null && { sequence },
|
|
353
355
|
data,
|
|
354
356
|
detail: _nullishCoalesce(fields.detail, () => ( detailOf(type, now, data))),
|
|
@@ -390,8 +392,8 @@ var FakeMesub = (_class = class {
|
|
|
390
392
|
object: "event",
|
|
391
393
|
type,
|
|
392
394
|
created_at: _nullishCoalesce(fields.created_at, () => ( now.toISOString())),
|
|
393
|
-
network: "
|
|
394
|
-
api_version:
|
|
395
|
+
network: "mainnet-beta",
|
|
396
|
+
api_version: _chunk4JSJOX35cjs.API_VERSION,
|
|
395
397
|
...sequence !== null && { sequence },
|
|
396
398
|
data,
|
|
397
399
|
detail: _nullishCoalesce(fields.detail, () => ( detailOf(type, now, data)))
|
|
@@ -496,8 +498,8 @@ var FakeMesub = (_class = class {
|
|
|
496
498
|
object: "event",
|
|
497
499
|
type: each,
|
|
498
500
|
created_at,
|
|
499
|
-
network: "
|
|
500
|
-
api_version:
|
|
501
|
+
network: "mainnet-beta",
|
|
502
|
+
api_version: _chunk4JSJOX35cjs.API_VERSION,
|
|
501
503
|
sequence: this.#nextSequence(subscription.id),
|
|
502
504
|
data: structuredClone(data),
|
|
503
505
|
detail: eachDetail
|
|
@@ -561,12 +563,12 @@ var FakeMesub = (_class = class {
|
|
|
561
563
|
if (key !== this.apiKey) {
|
|
562
564
|
return error(401, "invalid_api_key", "That API key is not valid.");
|
|
563
565
|
}
|
|
564
|
-
const version = headers.get(
|
|
565
|
-
if (version !== null && version !==
|
|
566
|
+
const version = headers.get(_chunk4JSJOX35cjs.API_VERSION_HEADER);
|
|
567
|
+
if (version !== null && version !== _chunk4JSJOX35cjs.API_VERSION) {
|
|
566
568
|
return error(
|
|
567
569
|
400,
|
|
568
570
|
"unsupported_version",
|
|
569
|
-
`${
|
|
571
|
+
`${_chunk4JSJOX35cjs.API_VERSION_HEADER} must be one of the versions this API serves: ${_chunk4JSJOX35cjs.API_VERSION}.`
|
|
570
572
|
);
|
|
571
573
|
}
|
|
572
574
|
if (this.#failure) {
|
|
@@ -1016,7 +1018,7 @@ var FakeMesub = (_class = class {
|
|
|
1016
1018
|
if (subscription.external_id) customers.push({ external_id: subscription.external_id });
|
|
1017
1019
|
if (subscription.email) customers.push({ email: subscription.email });
|
|
1018
1020
|
for (const customer of customers) {
|
|
1019
|
-
const before = this.#answers.get(keyOf(
|
|
1021
|
+
const before = this.#answers.get(keyOf(_chunk4JSJOX35cjs.customerOf.call(void 0, customer), plan));
|
|
1020
1022
|
this.setAccess(customer, plan, {
|
|
1021
1023
|
wallet: subscription.wallet,
|
|
1022
1024
|
access: subscription.access,
|
|
@@ -1286,7 +1288,7 @@ async function signWebhook(payload, options) {
|
|
|
1286
1288
|
const body = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
1287
1289
|
const id = _nullishCoalesce(options.id, () => ( `msg_signed_${signedIds += 1}`));
|
|
1288
1290
|
const timestamp = _nullishCoalesce(options.timestamp, () => ( Math.floor(Date.now() / 1e3)));
|
|
1289
|
-
return { body, headers: await
|
|
1291
|
+
return { body, headers: await _chunk4JSJOX35cjs.signedHeaders.call(void 0, options.secret, id, timestamp, body) };
|
|
1290
1292
|
}
|
|
1291
1293
|
function detailOf(type, now, data) {
|
|
1292
1294
|
const start = now.toISOString();
|
|
@@ -1389,7 +1391,7 @@ function invalidSubmit(body) {
|
|
|
1389
1391
|
}
|
|
1390
1392
|
function askedIn(query) {
|
|
1391
1393
|
try {
|
|
1392
|
-
return
|
|
1394
|
+
return _chunk4JSJOX35cjs.customerOf.call(void 0, {
|
|
1393
1395
|
wallet: query["wallet"],
|
|
1394
1396
|
external_id: query["external_id"],
|
|
1395
1397
|
email: query["email"]
|
|
@@ -1425,9 +1427,9 @@ function fakePlan(slug, { token, ...over } = {}) {
|
|
|
1425
1427
|
verified: vouched,
|
|
1426
1428
|
...token
|
|
1427
1429
|
},
|
|
1428
|
-
mint: "
|
|
1430
|
+
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
1429
1431
|
period_hours: 720,
|
|
1430
|
-
network: "
|
|
1432
|
+
network: "mainnet-beta",
|
|
1431
1433
|
status: "active",
|
|
1432
1434
|
available: true,
|
|
1433
1435
|
ends_at: null,
|
|
@@ -1474,7 +1476,7 @@ function error(status, code, message, { retryable, retryAfter } = {}) {
|
|
|
1474
1476
|
async function stamped(response, id) {
|
|
1475
1477
|
const headers = new Headers(response.headers);
|
|
1476
1478
|
headers.set(REQUEST_ID_HEADER, id);
|
|
1477
|
-
headers.set(
|
|
1479
|
+
headers.set(_chunk4JSJOX35cjs.API_VERSION_HEADER, _chunk4JSJOX35cjs.API_VERSION);
|
|
1478
1480
|
if (response.ok) return new Response(response.body, { status: response.status, headers });
|
|
1479
1481
|
const body = await response.json();
|
|
1480
1482
|
return Response.json({ ...body, request_id: id }, { status: response.status, headers });
|