@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.
Files changed (50) hide show
  1. package/README.md +9 -4
  2. package/dist/{chunk-XDLLXY7Y.js → chunk-4AAPR37Y.js} +2 -2
  3. package/dist/{chunk-SGSYQJYT.cjs → chunk-4JSJOX35.cjs} +4 -2
  4. package/dist/chunk-4JSJOX35.cjs.map +1 -0
  5. package/dist/{chunk-PCDZI7B4.cjs → chunk-66VVEXMU.cjs} +7 -7
  6. package/dist/{chunk-PCDZI7B4.cjs.map → chunk-66VVEXMU.cjs.map} +1 -1
  7. package/dist/{chunk-ELK7IBLO.js → chunk-J2CE4QWV.js} +2 -2
  8. package/dist/{chunk-KMPBFNJE.js → chunk-NOS4FWWQ.js} +4 -2
  9. package/dist/chunk-NOS4FWWQ.js.map +1 -0
  10. package/dist/{chunk-VMKI4VVA.cjs → chunk-SJRQDWTI.cjs} +4 -4
  11. package/dist/{chunk-VMKI4VVA.cjs.map → chunk-SJRQDWTI.cjs.map} +1 -1
  12. package/dist/{client-Dm1jamju.d.cts → client-BEuDegEY.d.cts} +7 -1
  13. package/dist/{client-BQuRYSdB.d.ts → client-CXQLkSAJ.d.ts} +7 -1
  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-CLtZnUzl.d.ts → routes-B7wN4sby.d.ts} +2 -2
  35. package/dist/{routes-DWkRFOP0.d.cts → routes-CMzB52P6.d.cts} +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-XDLLXY7Y.js.map → chunk-4AAPR37Y.js.map} +0 -0
  50. /package/dist/{chunk-ELK7IBLO.js.map → chunk-J2CE4QWV.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/node-sdk/node-sdk/dist/chunk-VMKI4VVA.cjs","../src/guard.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACiCO,IAAM,cAAA,EAA8C;AAAA,EACvD,eAAA,EAAiB,GAAA;AAAA,EACjB,SAAA,EAAW,GAAA;AAAA,EACX,WAAA,EAAa;AACjB,CAAA;AAMO,IAAM,0BAAA,EAA4B,EAAA;AAMlC,SAAS,YAAA,CAAa,OAAA,EAA4D;AACrF,EAAA,MAAM,MAAA,kBAAQ,OAAA,mBAAQ,QAAA,6BAAU,YAAA;AAE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MAAA,CAAO,OAAO,EAAA,EAAI,CAAC;AAAA,EACjF,CAAA;AACJ;AAEO,SAAS,QAAA,CAAS,OAAA,EAAgE;AACrF,EAAA,MAAM,EAAE,SAAS,EAAA,EAAI,OAAA;AAErB,EAAA,OAAO;AAAA,IACH,MAAA,EACI,QAAA,CAAS,KAAA,IAAS,SAAA,EAAW,QAAA,CAAS,MAAA,mCAAS,OAAA,qBAAQ,QAAA,qBAAS,MAAA,6BAAQ,QAAA,UAAU,MAAA;AAAA,IACtF,QAAA;AAAA,IACA,IAAA,EAAM,OAAA,CAAQ,IAAA;AAAA,IACd,MAAA,EAAQ,OAAA,CAAQ,QAAA,CAAS,MAAA;AAAA,IACzB,KAAA,EAAO,OAAA,CAAQ,QAAA,CAAS;AAAA,EAC5B,CAAA;AACJ;AAEO,SAAS,QAAA,CAAS,OAAA,EAA4D;AACjF,EAAA,OAAO;AAAA,IACH,MAAA,EAAQ,OAAA,CAAQ,MAAA;AAAA,IAChB,MAAA,EAAQ,aAAA,CAAc,OAAA,CAAQ,MAAM,CAAA;AAAA,IACpC,MAAA,mCAAQ,OAAA,qBAAQ,QAAA,+BAAU,QAAA,UAAU;AAAA,EACxC,CAAA;AACJ;ADxJA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yTAAC","file":"/home/runner/work/node-sdk/node-sdk/dist/chunk-VMKI4VVA.cjs","sourcesContent":[null,"import type { AccessAnswer, Customer } from './answer.js';\nimport { type Decision, Mesub } from './client.js';\nimport { type Asked, customerOf } from './customer.js';\n\n/** Why a request was turned away, and what it answers by default. */\nexport type DenialReason = 'unauthenticated' | 'no_access' | 'unavailable';\n\nexport type GuardOutcome =\n | { allowed: true; customer: Asked; plan: string; decision: Decision }\n | { allowed: false; reason: DenialReason; decision?: Decision };\n\n/** Who is asking and what Mesub answered, as a guarded route receives it. */\nexport interface MesubAccess {\n /**\n * The wallet that pays. Asked by external id or email, the one Mesub\n * answered with; null when the answer is the outage fallback's and holds none.\n */\n wallet: string | null;\n /** Who Mesub was asked about: a wallet, your own id for them, or their email. */\n customer: Asked;\n /** The plan that let the request through: the first of the list that did. */\n plan: string;\n /** Mesub's answer for that plan. */\n answer: AccessAnswer | null;\n /** The answer came from the outage fallback. */\n stale: boolean;\n}\n\n/** A refusal, as `onDenied` receives it. */\nexport interface Denial {\n reason: DenialReason;\n /** 401, 402 or 503: what would be answered without `onDenied`. */\n status: number;\n /** Mesub's answer, for the first plan asked when there are several. */\n answer: AccessAnswer | null;\n}\n\n/** What a guard answers by default for each refusal. */\nexport const DENIAL_STATUS: Record<DenialReason, number> = {\n unauthenticated: 401,\n no_access: 402,\n unavailable: 503,\n};\n\n/**\n * Seconds a client should wait before asking again when Mesub is unreachable\n * and did not say how long itself.\n */\nexport const UNAVAILABLE_RETRY_AFTER_S = 30;\n\n/**\n * The `Retry-After` of a guard's 503, in seconds: the one Mesub sent with its\n * 429 or 503 when it sent one, `UNAVAILABLE_RETRY_AFTER_S` otherwise (#132).\n */\nexport function retryAfterOf(outcome: Extract<GuardOutcome, { allowed: false }>): string {\n const asked = outcome.decision?.retryAfter;\n\n return String(asked === undefined ? UNAVAILABLE_RETRY_AFTER_S : Math.ceil(asked / 1000));\n}\n\nlet shared: Mesub | undefined;\n\n/** The client a middleware uses when given none: built once, from MESUB_API_KEY. */\nexport function defaultClient(): Mesub {\n shared ??= new Mesub();\n\n return shared;\n}\n\n/**\n * The plan a guard asks about: one, any one of several (the first that grants\n * lets the request through), or either of those worked out per request.\n */\nexport type PlanOption<Req> =\n string | readonly string[] | ((request: Req) => string | readonly string[]);\n\n/**\n * The plans a guard asks about for that request, in order, each once. A\n * plan that is not a non-empty string, or no plan at all, is a broken\n * integration: thrown, never read as a refusal.\n */\nexport function plansOf<Req>(plan: PlanOption<Req>, request: Req): string[] {\n return checkedPlans(typeof plan === 'function' ? plan(request) : plan);\n}\n\n/**\n * Checks a fixed plan when the guard is built, so a typo fails at start-up\n * rather than on the first request. One worked out per request is checked\n * then, by `plansOf`.\n */\nexport function checkPlan<Req>(plan: PlanOption<Req>): void {\n if (typeof plan !== 'function') checkedPlans(plan);\n}\n\n/**\n * Each plan a guard asks about is one call to `/v1/access`, made for every\n * request, against the key's 1000 calls a minute. Three is what a Dev\n * project can hold; a list longer than that is more likely built from the\n * request than written by hand.\n */\nconst MAX_PLANS = 3;\n\nfunction checkedPlans(value: unknown): string[] {\n const plans: unknown[] =\n typeof value === 'string' ? [value] : Array.isArray(value) ? value : [];\n\n if (plans.length === 0 || !plans.every((plan) => typeof plan === 'string' && plan !== '')) {\n throw new TypeError('A guard needs a plan, or a list of plans, as non-empty strings.');\n }\n\n const unique = [...new Set(plans as string[])];\n\n if (unique.length > MAX_PLANS) {\n throw new TypeError(\n `A guard asks about ${MAX_PLANS} plans at most: each one is a call to Mesub on every request.`,\n );\n }\n\n return unique;\n}\n\n/**\n * Who is asking, from your own auth: `(req) => ({ external_id: req.user.id })`,\n * a wallet, or an email. Null or undefined when nobody is signed in, a 401.\n * May be async.\n *\n * It must come from a session you verified, never from the request itself (a\n * query, a body, a header the caller writes): whoever names a subscriber\n * would get their access.\n */\nexport type CustomerOption<Req> = (\n request: Req,\n) => Customer | string | null | undefined | Promise<Customer | string | null | undefined>;\n\n/** Checked when the guard is built: without `customer` it could not tell who is asking. */\nexport function checkCustomer<Req>(options: { customer: CustomerOption<Req> }): void {\n if (typeof options?.customer !== 'function') {\n throw new TypeError(\n 'A guard needs `customer`: a function of the request returning who is signed in, ' +\n 'e.g. `(req) => ({ external_id: req.user.id })`.',\n );\n }\n}\n\n/**\n * Who is asking, as `customer` names them, or null for nobody.\n *\n * A `customer` that returns something Mesub cannot be asked about (two\n * identifiers, an empty one, not a string) is a broken integration: thrown.\n */\nexport async function askerOf<Req>(\n request: Req,\n customer: CustomerOption<Req>,\n): Promise<Asked | null> {\n const named = await customer(request);\n\n if (named === null || named === undefined) return null;\n\n const asked = customerOf(named);\n\n if (asked.value === '') {\n throw new TypeError(\n '`customer` returned an empty value: return null when nobody is signed in.',\n );\n }\n\n return asked;\n}\n\n/** The customer as `decide` takes it. */\nfunction asCustomer(asked: Asked): Customer | string {\n if (asked.kind === 'wallet') return asked.value;\n\n return asked.kind === 'email' ? { email: asked.value } : { external_id: asked.value };\n}\n\n/**\n * The one decision the middlewares make: who is asking, from `askerOf`, then\n * whether they have access to one of the plans.\n *\n * - nobody is asking (`customer` returned null): `unauthenticated`\n * - the fallback of `hasAccess` otherwise, per plan, through `decide`,\n * within the client's `guardTimeout`. The plans are asked at once, so\n * several fit the same budget, and read in order: the first that grants\n * lets the request through, without waiting for the ones after it.\n * `unavailable` when none grants and Mesub failed (outage, rate limit) or\n * the budget ran out on one with nothing cached: 402 only ever means\n * Mesub said no, for every plan\n *\n * An integration error (a bad API key, an unknown plan) is thrown, unless a\n * plan before it in the list already granted.\n *\n * `plansFor` runs only once somebody is identified: a plan worked out from\n * the request never runs, nor throws, for an anonymous one.\n */\nexport async function guard(\n client: Mesub,\n asked: Asked | null,\n plansFor: () => readonly string[],\n): Promise<GuardOutcome> {\n if (!asked) return { allowed: false, reason: 'unauthenticated' };\n\n const plans = plansFor();\n const customer = asCustomer(asked);\n const pending = plans.map((plan) => client.decide(customer, plan));\n\n // The ones not read, once a plan before them grants, must not reject unhandled.\n for (const decision of pending) decision.catch(() => undefined);\n\n let first: Decision | undefined;\n let unavailable: Decision | undefined;\n\n for (const [index, next] of pending.entries()) {\n const decision = await next;\n\n if (decision.access) {\n return { allowed: true, customer: asked, plan: plans[index]!, decision };\n }\n\n first ??= decision;\n // Mesub failed or did not answer within the budget, and nothing was\n // cached for that customer and plan: not a no, an outage.\n if (decision.unavailable) unavailable ??= decision;\n }\n\n if (unavailable) return { allowed: false, reason: 'unavailable', decision: unavailable };\n\n return { allowed: false, reason: 'no_access', ...(first ? { decision: first } : {}) };\n}\n\n/** The body a refusal answers with. `status` only when there is an answer to read it from. */\nexport function denialBody(outcome: Extract<GuardOutcome, { allowed: false }>) {\n return {\n access: false,\n reason: outcome.reason,\n ...(outcome.decision?.answer ? { status: outcome.decision.answer.status } : {}),\n };\n}\n\nexport function accessOf(outcome: Extract<GuardOutcome, { allowed: true }>): MesubAccess {\n const { customer } = outcome;\n\n return {\n wallet:\n customer.kind === 'wallet' ? customer.value : (outcome.decision.answer?.wallet ?? null),\n customer,\n plan: outcome.plan,\n answer: outcome.decision.answer,\n stale: outcome.decision.stale,\n };\n}\n\nexport function denialOf(outcome: Extract<GuardOutcome, { allowed: false }>): Denial {\n return {\n reason: outcome.reason,\n status: DENIAL_STATUS[outcome.reason],\n answer: outcome.decision?.answer ?? null,\n };\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/node-sdk/node-sdk/dist/chunk-SJRQDWTI.cjs","../src/guard.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACiCO,IAAM,cAAA,EAA8C;AAAA,EACvD,eAAA,EAAiB,GAAA;AAAA,EACjB,SAAA,EAAW,GAAA;AAAA,EACX,WAAA,EAAa;AACjB,CAAA;AAMO,IAAM,0BAAA,EAA4B,EAAA;AAMlC,SAAS,YAAA,CAAa,OAAA,EAA4D;AACrF,EAAA,MAAM,MAAA,kBAAQ,OAAA,mBAAQ,QAAA,6BAAU,YAAA;AAEhC,EAAA,OAAO,MAAA,CAAO,MAAA,IAAU,KAAA,EAAA,EAAY,0BAAA,EAA4B,IAAA,CAAK,IAAA,CAAK,MAAA,EAAQ,GAAI,CAAC,CAAA;AAC3F;AAEA,IAAI,MAAA;AAGG,SAAS,aAAA,CAAA,EAAuB;AACnC,EAAA,OAAA,IAAW,IAAI,4BAAA,CAAM,CAAA;AAErB,EAAA,OAAO,MAAA;AACX;AAcO,SAAS,OAAA,CAAa,IAAA,EAAuB,OAAA,EAAwB;AACxE,EAAA,OAAO,YAAA,CAAa,OAAO,KAAA,IAAS,WAAA,EAAa,IAAA,CAAK,OAAO,EAAA,EAAI,IAAI,CAAA;AACzE;AAOO,SAAS,SAAA,CAA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AO,OAAA,CAAQ,QAAA,CAAS;AAAA,EAC5B,CAAA;AACJ;AAEO,SAAS,QAAA,CAAS,OAAA,EAA4D;AACjF,EAAA,OAAO;AAAA,IACH,MAAA,EAAQ,OAAA,CAAQ,MAAA;AAAA,IAChB,MAAA,EAAQ,aAAA,CAAc,OAAA,CAAQ,MAAM,CAAA;AAAA,IACpC,MAAA,mCAAQ,OAAA,qBAAQ,QAAA,+BAAU,QAAA,UAAU;AAAA,EACxC,CAAA;AACJ;ADxJA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,yTAAC","file":"/home/runner/work/node-sdk/node-sdk/dist/chunk-SJRQDWTI.cjs","sourcesContent":[null,"import type { AccessAnswer, Customer } from './answer.js';\nimport { type Decision, Mesub } from './client.js';\nimport { type Asked, customerOf } from './customer.js';\n\n/** Why a request was turned away, and what it answers by default. */\nexport type DenialReason = 'unauthenticated' | 'no_access' | 'unavailable';\n\nexport type GuardOutcome =\n | { allowed: true; customer: Asked; plan: string; decision: Decision }\n | { allowed: false; reason: DenialReason; decision?: Decision };\n\n/** Who is asking and what Mesub answered, as a guarded route receives it. */\nexport interface MesubAccess {\n /**\n * The wallet that pays. Asked by external id or email, the one Mesub\n * answered with; null when the answer is the outage fallback's and holds none.\n */\n wallet: string | null;\n /** Who Mesub was asked about: a wallet, your own id for them, or their email. */\n customer: Asked;\n /** The plan that let the request through: the first of the list that did. */\n plan: string;\n /** Mesub's answer for that plan. */\n answer: AccessAnswer | null;\n /** The answer came from the outage fallback. */\n stale: boolean;\n}\n\n/** A refusal, as `onDenied` receives it. */\nexport interface Denial {\n reason: DenialReason;\n /** 401, 402 or 503: what would be answered without `onDenied`. */\n status: number;\n /** Mesub's answer, for the first plan asked when there are several. */\n answer: AccessAnswer | null;\n}\n\n/** What a guard answers by default for each refusal. */\nexport const DENIAL_STATUS: Record<DenialReason, number> = {\n unauthenticated: 401,\n no_access: 402,\n unavailable: 503,\n};\n\n/**\n * Seconds a client should wait before asking again when Mesub is unreachable\n * and did not say how long itself.\n */\nexport const UNAVAILABLE_RETRY_AFTER_S = 30;\n\n/**\n * The `Retry-After` of a guard's 503, in seconds: the one Mesub sent with its\n * 429 or 503 when it sent one, `UNAVAILABLE_RETRY_AFTER_S` otherwise (#132).\n */\nexport function retryAfterOf(outcome: Extract<GuardOutcome, { allowed: false }>): string {\n const asked = outcome.decision?.retryAfter;\n\n return String(asked === undefined ? UNAVAILABLE_RETRY_AFTER_S : Math.ceil(asked / 1000));\n}\n\nlet shared: Mesub | undefined;\n\n/** The client a middleware uses when given none: built once, from MESUB_API_KEY. */\nexport function defaultClient(): Mesub {\n shared ??= new Mesub();\n\n return shared;\n}\n\n/**\n * The plan a guard asks about: one, any one of several (the first that grants\n * lets the request through), or either of those worked out per request.\n */\nexport type PlanOption<Req> =\n string | readonly string[] | ((request: Req) => string | readonly string[]);\n\n/**\n * The plans a guard asks about for that request, in order, each once. A\n * plan that is not a non-empty string, or no plan at all, is a broken\n * integration: thrown, never read as a refusal.\n */\nexport function plansOf<Req>(plan: PlanOption<Req>, request: Req): string[] {\n return checkedPlans(typeof plan === 'function' ? plan(request) : plan);\n}\n\n/**\n * Checks a fixed plan when the guard is built, so a typo fails at start-up\n * rather than on the first request. One worked out per request is checked\n * then, by `plansOf`.\n */\nexport function checkPlan<Req>(plan: PlanOption<Req>): void {\n if (typeof plan !== 'function') checkedPlans(plan);\n}\n\n/**\n * Each plan a guard asks about is one call to `/v1/access`, made for every\n * request, against the key's 1000 calls a minute. Three is what a Dev\n * project can hold; a list longer than that is more likely built from the\n * request than written by hand.\n */\nconst MAX_PLANS = 3;\n\nfunction checkedPlans(value: unknown): string[] {\n const plans: unknown[] =\n typeof value === 'string' ? [value] : Array.isArray(value) ? value : [];\n\n if (plans.length === 0 || !plans.every((plan) => typeof plan === 'string' && plan !== '')) {\n throw new TypeError('A guard needs a plan, or a list of plans, as non-empty strings.');\n }\n\n const unique = [...new Set(plans as string[])];\n\n if (unique.length > MAX_PLANS) {\n throw new TypeError(\n `A guard asks about ${MAX_PLANS} plans at most: each one is a call to Mesub on every request.`,\n );\n }\n\n return unique;\n}\n\n/**\n * Who is asking, from your own auth: `(req) => ({ external_id: req.user.id })`,\n * a wallet, or an email. Null or undefined when nobody is signed in, a 401.\n * May be async.\n *\n * It must come from a session you verified, never from the request itself (a\n * query, a body, a header the caller writes): whoever names a subscriber\n * would get their access.\n */\nexport type CustomerOption<Req> = (\n request: Req,\n) => Customer | string | null | undefined | Promise<Customer | string | null | undefined>;\n\n/** Checked when the guard is built: without `customer` it could not tell who is asking. */\nexport function checkCustomer<Req>(options: { customer: CustomerOption<Req> }): void {\n if (typeof options?.customer !== 'function') {\n throw new TypeError(\n 'A guard needs `customer`: a function of the request returning who is signed in, ' +\n 'e.g. `(req) => ({ external_id: req.user.id })`.',\n );\n }\n}\n\n/**\n * Who is asking, as `customer` names them, or null for nobody.\n *\n * A `customer` that returns something Mesub cannot be asked about (two\n * identifiers, an empty one, not a string) is a broken integration: thrown.\n */\nexport async function askerOf<Req>(\n request: Req,\n customer: CustomerOption<Req>,\n): Promise<Asked | null> {\n const named = await customer(request);\n\n if (named === null || named === undefined) return null;\n\n const asked = customerOf(named);\n\n if (asked.value === '') {\n throw new TypeError(\n '`customer` returned an empty value: return null when nobody is signed in.',\n );\n }\n\n return asked;\n}\n\n/** The customer as `decide` takes it. */\nfunction asCustomer(asked: Asked): Customer | string {\n if (asked.kind === 'wallet') return asked.value;\n\n return asked.kind === 'email' ? { email: asked.value } : { external_id: asked.value };\n}\n\n/**\n * The one decision the middlewares make: who is asking, from `askerOf`, then\n * whether they have access to one of the plans.\n *\n * - nobody is asking (`customer` returned null): `unauthenticated`\n * - the fallback of `hasAccess` otherwise, per plan, through `decide`,\n * within the client's `guardTimeout`. The plans are asked at once, so\n * several fit the same budget, and read in order: the first that grants\n * lets the request through, without waiting for the ones after it.\n * `unavailable` when none grants and Mesub failed (outage, rate limit) or\n * the budget ran out on one with nothing cached: 402 only ever means\n * Mesub said no, for every plan\n *\n * An integration error (a bad API key, an unknown plan) is thrown, unless a\n * plan before it in the list already granted.\n *\n * `plansFor` runs only once somebody is identified: a plan worked out from\n * the request never runs, nor throws, for an anonymous one.\n */\nexport async function guard(\n client: Mesub,\n asked: Asked | null,\n plansFor: () => readonly string[],\n): Promise<GuardOutcome> {\n if (!asked) return { allowed: false, reason: 'unauthenticated' };\n\n const plans = plansFor();\n const customer = asCustomer(asked);\n const pending = plans.map((plan) => client.decide(customer, plan));\n\n // The ones not read, once a plan before them grants, must not reject unhandled.\n for (const decision of pending) decision.catch(() => undefined);\n\n let first: Decision | undefined;\n let unavailable: Decision | undefined;\n\n for (const [index, next] of pending.entries()) {\n const decision = await next;\n\n if (decision.access) {\n return { allowed: true, customer: asked, plan: plans[index]!, decision };\n }\n\n first ??= decision;\n // Mesub failed or did not answer within the budget, and nothing was\n // cached for that customer and plan: not a no, an outage.\n if (decision.unavailable) unavailable ??= decision;\n }\n\n if (unavailable) return { allowed: false, reason: 'unavailable', decision: unavailable };\n\n return { allowed: false, reason: 'no_access', ...(first ? { decision: first } : {}) };\n}\n\n/** The body a refusal answers with. `status` only when there is an answer to read it from. */\nexport function denialBody(outcome: Extract<GuardOutcome, { allowed: false }>) {\n return {\n access: false,\n reason: outcome.reason,\n ...(outcome.decision?.answer ? { status: outcome.decision.answer.status } : {}),\n };\n}\n\nexport function accessOf(outcome: Extract<GuardOutcome, { allowed: true }>): MesubAccess {\n const { customer } = outcome;\n\n return {\n wallet:\n customer.kind === 'wallet' ? customer.value : (outcome.decision.answer?.wallet ?? null),\n customer,\n plan: outcome.plan,\n answer: outcome.decision.answer,\n stale: outcome.decision.stale,\n };\n}\n\nexport function denialOf(outcome: Extract<GuardOutcome, { allowed: false }>): Denial {\n return {\n reason: outcome.reason,\n status: DENIAL_STATUS[outcome.reason],\n answer: outcome.decision?.answer ?? null,\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { j as ServerSubscription, B as BlockedReason, T as Transport, R as RequestOptions, w as Subscriptions, A as AccessAnswer, a as AccessList, C as Customer, b as AccessOptions } from './subscriptions-D1hE7MUc.cjs';
1
+ import { j as ServerSubscription, B as BlockedReason, T as Transport, R as RequestOptions, w as Subscriptions, A as AccessAnswer, a as AccessList, C as Customer, b as AccessOptions } from './subscriptions-B6Lin6i_.cjs';
2
2
 
3
3
  /** One cached answer, with the two moments that decide what it is still good for. */
4
4
  interface CacheEntry<T> {
@@ -198,6 +198,12 @@ interface FirstPayment {
198
198
  mint: string | null;
199
199
  /** The transaction that paid it. */
200
200
  signature: string | null;
201
+ /**
202
+ * What the receiver's account got of it: `amount` less the fee a
203
+ * Token-2022 mint withholds. Null when not known, absent from a Mesub that
204
+ * predates it.
205
+ */
206
+ amount_received?: string | null;
201
207
  }
202
208
  /**
203
209
  * `subscription.ended`: `changed_at` only on a cancellation that reached its
@@ -1,4 +1,4 @@
1
- import { j as ServerSubscription, B as BlockedReason, T as Transport, R as RequestOptions, w as Subscriptions, A as AccessAnswer, a as AccessList, C as Customer, b as AccessOptions } from './subscriptions-D1hE7MUc.js';
1
+ import { j as ServerSubscription, B as BlockedReason, T as Transport, R as RequestOptions, w as Subscriptions, A as AccessAnswer, a as AccessList, C as Customer, b as AccessOptions } from './subscriptions-B6Lin6i_.js';
2
2
 
3
3
  /** One cached answer, with the two moments that decide what it is still good for. */
4
4
  interface CacheEntry<T> {
@@ -198,6 +198,12 @@ interface FirstPayment {
198
198
  mint: string | null;
199
199
  /** The transaction that paid it. */
200
200
  signature: string | null;
201
+ /**
202
+ * What the receiver's account got of it: `amount` less the fee a
203
+ * Token-2022 mint withholds. Null when not known, absent from a Mesub that
204
+ * predates it.
205
+ */
206
+ amount_received?: string | null;
201
207
  }
202
208
  /**
203
209
  * `subscription.ended`: `changed_at` only on a cancellation that reached its
@@ -1,4 +1,4 @@
1
- import { j as ServerSubscription } from './subscriptions-D1hE7MUc.js';
1
+ import { j as ServerSubscription } from './subscriptions-B6Lin6i_.js';
2
2
 
3
3
  /**
4
4
  * Stable codes to branch on, one per kind of failure; `apiCode` tells the
@@ -1,4 +1,4 @@
1
- import { j as ServerSubscription } from './subscriptions-D1hE7MUc.cjs';
1
+ import { j as ServerSubscription } from './subscriptions-B6Lin6i_.cjs';
2
2
 
3
3
  /**
4
4
  * Stable codes to branch on, one per kind of failure; `apiCode` tells the
package/dist/express.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkPCDZI7B4cjs = require('./chunk-PCDZI7B4.cjs');
6
+ var _chunk66VVEXMUcjs = require('./chunk-66VVEXMU.cjs');
7
7
 
8
8
 
9
9
 
@@ -15,16 +15,16 @@ var _chunkPCDZI7B4cjs = require('./chunk-PCDZI7B4.cjs');
15
15
 
16
16
 
17
17
 
18
- var _chunkVMKI4VVAcjs = require('./chunk-VMKI4VVA.cjs');
18
+ var _chunkSJRQDWTIcjs = require('./chunk-SJRQDWTI.cjs');
19
19
 
20
20
 
21
- var _chunkSGSYQJYTcjs = require('./chunk-SGSYQJYT.cjs');
21
+ var _chunk4JSJOX35cjs = require('./chunk-4JSJOX35.cjs');
22
22
 
23
23
  // src/express.ts
24
24
  function forNext(error) {
25
- if (!(error instanceof _chunkSGSYQJYTcjs.MesubError) || error.status === null) return error;
25
+ if (!(error instanceof _chunk4JSJOX35cjs.MesubError) || error.status === null) return error;
26
26
  if (error.status < 400 || error.status >= 500) return error;
27
- return new (0, _chunkSGSYQJYTcjs.MesubError)(error.message, {
27
+ return new (0, _chunk4JSJOX35cjs.MesubError)(error.message, {
28
28
  status: 500,
29
29
  code: error.code,
30
30
  apiCode: error.apiCode,
@@ -36,30 +36,30 @@ function forNext(error) {
36
36
  });
37
37
  }
38
38
  function requirePlan(plan, options) {
39
- _chunkVMKI4VVAcjs.checkPlan.call(void 0, plan);
40
- _chunkVMKI4VVAcjs.checkCustomer.call(void 0, options);
39
+ _chunkSJRQDWTIcjs.checkPlan.call(void 0, plan);
40
+ _chunkSJRQDWTIcjs.checkCustomer.call(void 0, options);
41
41
  return async (req, res, next) => {
42
42
  try {
43
- const client = _nullishCoalesce(options.client, () => ( _chunkVMKI4VVAcjs.defaultClient.call(void 0, )));
44
- const outcome = await _chunkVMKI4VVAcjs.guard.call(void 0,
43
+ const client = _nullishCoalesce(options.client, () => ( _chunkSJRQDWTIcjs.defaultClient.call(void 0, )));
44
+ const outcome = await _chunkSJRQDWTIcjs.guard.call(void 0,
45
45
  client,
46
- await _chunkVMKI4VVAcjs.askerOf.call(void 0, req, options.customer),
47
- () => _chunkVMKI4VVAcjs.plansOf.call(void 0, plan, req)
46
+ await _chunkSJRQDWTIcjs.askerOf.call(void 0, req, options.customer),
47
+ () => _chunkSJRQDWTIcjs.plansOf.call(void 0, plan, req)
48
48
  );
49
49
  if (outcome.allowed) {
50
- const locals = _chunkVMKI4VVAcjs.accessOf.call(void 0, outcome);
50
+ const locals = _chunkSJRQDWTIcjs.accessOf.call(void 0, outcome);
51
51
  res.locals["mesub"] = locals;
52
52
  return next();
53
53
  }
54
- const denial = _chunkVMKI4VVAcjs.denialOf.call(void 0, outcome);
54
+ const denial = _chunkSJRQDWTIcjs.denialOf.call(void 0, outcome);
55
55
  if (options.onDenied) {
56
56
  await options.onDenied(denial, req, res, next);
57
57
  return;
58
58
  }
59
59
  if (outcome.reason === "unavailable") {
60
- res.setHeader("Retry-After", _chunkVMKI4VVAcjs.retryAfterOf.call(void 0, outcome));
60
+ res.setHeader("Retry-After", _chunkSJRQDWTIcjs.retryAfterOf.call(void 0, outcome));
61
61
  }
62
- res.status(denial.status).json(_chunkVMKI4VVAcjs.denialBody.call(void 0, outcome));
62
+ res.status(denial.status).json(_chunkSJRQDWTIcjs.denialBody.call(void 0, outcome));
63
63
  } catch (error) {
64
64
  next(forNext(error));
65
65
  }
@@ -74,14 +74,14 @@ async function jsonBody(req) {
74
74
  for await (const chunk of req) {
75
75
  const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
76
76
  size += bytes.length;
77
- if (size > _chunkPCDZI7B4cjs.MAX_BODY_BYTES) throw new RangeError("The body is too large.");
77
+ if (size > _chunk66VVEXMUcjs.MAX_BODY_BYTES) throw new RangeError("The body is too large.");
78
78
  chunks.push(bytes);
79
79
  }
80
80
  if (size === 0) return void 0;
81
81
  return JSON.parse(Buffer.concat(chunks).toString("utf8"));
82
82
  }
83
83
  function mesubRoutes(options) {
84
- _chunkPCDZI7B4cjs.checkWidgetOptions.call(void 0, options);
84
+ _chunk66VVEXMUcjs.checkWidgetOptions.call(void 0, options);
85
85
  return async (req, res, next) => {
86
86
  try {
87
87
  let body;
@@ -98,10 +98,10 @@ function mesubRoutes(options) {
98
98
  return;
99
99
  }
100
100
  const publicRead = req.method === "GET" && req.path.startsWith("/plans/");
101
- const asked = publicRead ? null : await _chunkPCDZI7B4cjs.widgetCustomer.call(void 0, req, options.customer);
101
+ const asked = publicRead ? null : await _chunk66VVEXMUcjs.widgetCustomer.call(void 0, req, options.customer);
102
102
  const email = asked && options.email ? await options.email(req) : void 0;
103
- const answer = await _chunkPCDZI7B4cjs.handleWidget.call(void 0,
104
- _nullishCoalesce(options.client, () => ( _chunkVMKI4VVAcjs.defaultClient.call(void 0, ))),
103
+ const answer = await _chunk66VVEXMUcjs.handleWidget.call(void 0,
104
+ _nullishCoalesce(options.client, () => ( _chunkSJRQDWTIcjs.defaultClient.call(void 0, ))),
105
105
  {
106
106
  method: req.method,
107
107
  path: req.path,
@@ -125,5 +125,5 @@ function mesubRoutes(options) {
125
125
 
126
126
 
127
127
 
128
- exports.MesubError = _chunkSGSYQJYTcjs.MesubError; exports.mesubRoutes = mesubRoutes; exports.requirePlan = requirePlan;
128
+ exports.MesubError = _chunk4JSJOX35cjs.MesubError; exports.mesubRoutes = mesubRoutes; exports.requirePlan = requirePlan;
129
129
  //# sourceMappingURL=express.cjs.map
@@ -1,11 +1,11 @@
1
1
  import { Request, Response, NextFunction, RequestHandler } from 'express';
2
- import { M as Mesub } from './client-Dm1jamju.cjs';
3
- import { M as MesubAccess, C as CustomerOption, D as Denial, P as PlanOption } from './guard-Dhy4fI6n.cjs';
4
- export { A as Asked, a as DenialReason } from './guard-Dhy4fI6n.cjs';
5
- import { W as WidgetRoutesOptions } from './routes-DWkRFOP0.cjs';
6
- export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-DWkRFOP0.cjs';
7
- export { M as MesubError } from './errors-CtPucyOh.cjs';
8
- export { C as Customer } from './subscriptions-D1hE7MUc.cjs';
2
+ import { M as Mesub } from './client-BEuDegEY.cjs';
3
+ import { M as MesubAccess, C as CustomerOption, D as Denial, P as PlanOption } from './guard-D4AB5HtN.cjs';
4
+ export { A as Asked, a as DenialReason } from './guard-D4AB5HtN.cjs';
5
+ import { W as WidgetRoutesOptions } from './routes-CMzB52P6.cjs';
6
+ export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-CMzB52P6.cjs';
7
+ export { M as MesubError } from './errors-DcLfunS-.cjs';
8
+ export { C as Customer } from './subscriptions-B6Lin6i_.cjs';
9
9
 
10
10
  /** `@mesub/node/express`: `requirePlan()`. */
11
11
 
package/dist/express.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Request, Response, NextFunction, RequestHandler } from 'express';
2
- import { M as Mesub } from './client-BQuRYSdB.js';
3
- import { M as MesubAccess, C as CustomerOption, D as Denial, P as PlanOption } from './guard-DKb6iU1z.js';
4
- export { A as Asked, a as DenialReason } from './guard-DKb6iU1z.js';
5
- import { W as WidgetRoutesOptions } from './routes-CLtZnUzl.js';
6
- export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-CLtZnUzl.js';
7
- export { M as MesubError } from './errors-DqW3DMBS.js';
8
- export { C as Customer } from './subscriptions-D1hE7MUc.js';
2
+ import { M as Mesub } from './client-CXQLkSAJ.js';
3
+ import { M as MesubAccess, C as CustomerOption, D as Denial, P as PlanOption } from './guard-CaXiHMVF.js';
4
+ export { A as Asked, a as DenialReason } from './guard-CaXiHMVF.js';
5
+ import { W as WidgetRoutesOptions } from './routes-B7wN4sby.js';
6
+ export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-B7wN4sby.js';
7
+ export { M as MesubError } from './errors-BN4ZWUfM.js';
8
+ export { C as Customer } from './subscriptions-B6Lin6i_.js';
9
9
 
10
10
  /** `@mesub/node/express`: `requirePlan()`. */
11
11
 
package/dist/express.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  checkWidgetOptions,
4
4
  handleWidget,
5
5
  widgetCustomer
6
- } from "./chunk-ELK7IBLO.js";
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-XDLLXY7Y.js";
18
+ } from "./chunk-4AAPR37Y.js";
19
19
  import {
20
20
  MesubError
21
- } from "./chunk-KMPBFNJE.js";
21
+ } from "./chunk-NOS4FWWQ.js";
22
22
 
23
23
  // src/express.ts
24
24
  function forNext(error) {
@@ -1,4 +1,4 @@
1
- import { C as Customer, A as AccessAnswer } from './subscriptions-D1hE7MUc.js';
1
+ import { C as Customer, A as AccessAnswer } from './subscriptions-B6Lin6i_.js';
2
2
 
3
3
  /** Who a call is about, normalised as Mesub reads it. */
4
4
  interface Asked {
@@ -1,4 +1,4 @@
1
- import { C as Customer, A as AccessAnswer } from './subscriptions-D1hE7MUc.cjs';
1
+ import { C as Customer, A as AccessAnswer } from './subscriptions-B6Lin6i_.cjs';
2
2
 
3
3
  /** Who a call is about, normalised as Mesub reads it. */
4
4
  interface Asked {
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
 
12
12
 
13
- var _chunkSGSYQJYTcjs = require('./chunk-SGSYQJYT.cjs');
13
+ var _chunk4JSJOX35cjs = require('./chunk-4JSJOX35.cjs');
14
14
 
15
15
 
16
16
 
@@ -35,5 +35,5 @@ var _chunk43Q4PNF7cjs = require('./chunk-43Q4PNF7.cjs');
35
35
 
36
36
 
37
37
 
38
- exports.ACCESS_LINE = _chunk43Q4PNF7cjs.ACCESS_LINE; exports.API_VERSION = _chunkSGSYQJYTcjs.API_VERSION; exports.API_VERSION_HEADER = _chunkSGSYQJYTcjs.API_VERSION_HEADER; exports.AccessCache = _chunkSGSYQJYTcjs.AccessCache; exports.CONFIRMATIONS = _chunk43Q4PNF7cjs.CONFIRMATIONS; exports.DEFAULT_MAX_ENTRIES = _chunkSGSYQJYTcjs.DEFAULT_MAX_ENTRIES; exports.DEFAULT_MAX_STALE_MS = _chunkSGSYQJYTcjs.DEFAULT_MAX_STALE_MS; exports.MemoryStore = _chunkSGSYQJYTcjs.MemoryStore; exports.Mesub = _chunkSGSYQJYTcjs.Mesub; exports.MesubError = _chunkSGSYQJYTcjs.MesubError; exports.MesubSubmitError = _chunkSGSYQJYTcjs.MesubSubmitError; exports.SITUATIONS = _chunk43Q4PNF7cjs.SITUATIONS; exports.VERSION = _chunkSGSYQJYTcjs.VERSION; exports.explain = _chunk43Q4PNF7cjs.explain; exports.situationOf = _chunk43Q4PNF7cjs.situationOf; exports.verifyWebhook = _chunkSGSYQJYTcjs.verifyWebhook;
38
+ exports.ACCESS_LINE = _chunk43Q4PNF7cjs.ACCESS_LINE; exports.API_VERSION = _chunk4JSJOX35cjs.API_VERSION; exports.API_VERSION_HEADER = _chunk4JSJOX35cjs.API_VERSION_HEADER; exports.AccessCache = _chunk4JSJOX35cjs.AccessCache; exports.CONFIRMATIONS = _chunk43Q4PNF7cjs.CONFIRMATIONS; exports.DEFAULT_MAX_ENTRIES = _chunk4JSJOX35cjs.DEFAULT_MAX_ENTRIES; exports.DEFAULT_MAX_STALE_MS = _chunk4JSJOX35cjs.DEFAULT_MAX_STALE_MS; exports.MemoryStore = _chunk4JSJOX35cjs.MemoryStore; exports.Mesub = _chunk4JSJOX35cjs.Mesub; exports.MesubError = _chunk4JSJOX35cjs.MesubError; exports.MesubSubmitError = _chunk4JSJOX35cjs.MesubSubmitError; exports.SITUATIONS = _chunk43Q4PNF7cjs.SITUATIONS; exports.VERSION = _chunk4JSJOX35cjs.VERSION; exports.explain = _chunk43Q4PNF7cjs.explain; exports.situationOf = _chunk43Q4PNF7cjs.situationOf; exports.verifyWebhook = _chunk4JSJOX35cjs.verifyWebhook;
39
39
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { C as CacheStore, a as CacheEntry } from './client-Dm1jamju.cjs';
2
- export { A as AccessCache, b as AccessCacheOptions, c as AccessChangedDetail, d as CachedAnswer, e as CreatedDetail, D as DEFAULT_MAX_STALE_MS, f as Decision, E as EndedDetail, g as EventList, h as EventListParams, i as EventNetwork, j as EventType, k as Events, F as FirstPayment, H as HeaderSource, M as Mesub, l as MesubEvent, m as MesubOptions, N as NoDetail, P as PaymentFailedDetail, n as Plan, o as PlanStatus, p as PlanToken, q as Plans, R as RenewalIssue, r as RenewalUpcomingDetail, s as RenewedDetail, t as Revalidating, S as StoppedDetail, u as SubscriptionAccessGrantedEvent, v as SubscriptionAccessRevokedEvent, w as SubscriptionCancelledEvent, x as SubscriptionCreatedEvent, y as SubscriptionEndedEvent, z as SubscriptionExpiredEvent, B as SubscriptionPausedEvent, G as SubscriptionPaymentFailedEvent, I as SubscriptionRenewalUpcomingEvent, J as SubscriptionRenewedEvent, K as SubscriptionResumedEvent, L as SubscriptionStoppedEvent, O as SubscriptionUnpausedEvent, T as TestEvent, V as VerifyWebhookOptions, W as WebhookBody, Q as WebhookEvent, U as WebhookEventType, X as Webhooks, Y as verifyWebhook } from './client-Dm1jamju.cjs';
3
- export { M as MesubError, a as MesubErrorCode, b as MesubErrorOptions, c as MesubSubmitError, d as MesubSubmitErrorOptions } from './errors-CtPucyOh.cjs';
4
- export { A as AccessAnswer, a as AccessList, b as AccessOptions, c as AttemptsParams, B as BlockedReason, d as ConfirmOptions, e as ConfirmParams, f as ConfirmReasonCode, g as ConfirmResult, C as Customer, E as EndReason, L as LateReason, h as ListParams, P as PaymentStatus, i as PullOutcome, R as RequestOptions, S as ServedAttempt, j as ServerSubscription, k as ServerSubscriptionList, l as ServerSubscriptionStatus, m as StopReason, n as SubmitOptions, o as SubmitParams, p as SubmitResult, q as SubscribeCosts, r as SubscribeParams, s as SubscribeTransaction, t as SubscriptionAttempt, u as SubscriptionAttemptList, v as SubscriptionStatus, w as Subscriptions, W as WalletTransaction } from './subscriptions-D1hE7MUc.cjs';
1
+ import { C as CacheStore, a as CacheEntry } from './client-BEuDegEY.cjs';
2
+ export { A as AccessCache, b as AccessCacheOptions, c as AccessChangedDetail, d as CachedAnswer, e as CreatedDetail, D as DEFAULT_MAX_STALE_MS, f as Decision, E as EndedDetail, g as EventList, h as EventListParams, i as EventNetwork, j as EventType, k as Events, F as FirstPayment, H as HeaderSource, M as Mesub, l as MesubEvent, m as MesubOptions, N as NoDetail, P as PaymentFailedDetail, n as Plan, o as PlanStatus, p as PlanToken, q as Plans, R as RenewalIssue, r as RenewalUpcomingDetail, s as RenewedDetail, t as Revalidating, S as StoppedDetail, u as SubscriptionAccessGrantedEvent, v as SubscriptionAccessRevokedEvent, w as SubscriptionCancelledEvent, x as SubscriptionCreatedEvent, y as SubscriptionEndedEvent, z as SubscriptionExpiredEvent, B as SubscriptionPausedEvent, G as SubscriptionPaymentFailedEvent, I as SubscriptionRenewalUpcomingEvent, J as SubscriptionRenewedEvent, K as SubscriptionResumedEvent, L as SubscriptionStoppedEvent, O as SubscriptionUnpausedEvent, T as TestEvent, V as VerifyWebhookOptions, W as WebhookBody, Q as WebhookEvent, U as WebhookEventType, X as Webhooks, Y as verifyWebhook } from './client-BEuDegEY.cjs';
3
+ export { M as MesubError, a as MesubErrorCode, b as MesubErrorOptions, c as MesubSubmitError, d as MesubSubmitErrorOptions } from './errors-DcLfunS-.cjs';
4
+ export { A as AccessAnswer, a as AccessList, b as AccessOptions, c as AttemptsParams, B as BlockedReason, d as ConfirmOptions, e as ConfirmParams, f as ConfirmReasonCode, g as ConfirmResult, C as Customer, E as EndReason, L as LateReason, h as ListParams, P as PaymentStatus, i as PullOutcome, R as RequestOptions, S as ServedAttempt, j as ServerSubscription, k as ServerSubscriptionList, l as ServerSubscriptionStatus, m as StopReason, n as SubmitOptions, o as SubmitParams, p as SubmitResult, q as SubscribeCosts, r as SubscribeParams, s as SubscribeTransaction, t as SubscriptionAttempt, u as SubscriptionAttemptList, v as SubscriptionStatus, w as Subscriptions, W as WalletTransaction } from './subscriptions-B6Lin6i_.cjs';
5
5
  export { ACCESS_LINE, CONFIRMATIONS, ConfirmationKey, ExplainOptions, Explainable, ExplainedAction, Explanation, SITUATIONS, Situation, SituationActionId, SituationActionTemplate, SituationActor, SituationKey, SituationText, explain, situationOf } from './situations.cjs';
6
6
 
7
7
  /** Kept in step with package.json by `test/version.spec.ts`. */
8
- declare const VERSION = "0.1.0";
8
+ declare const VERSION = "0.1.2";
9
9
  /**
10
10
  * The version of the Mesub API this release was written against, sent in
11
11
  * the `Mesub-Version` header of every call, so the API can change its
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { C as CacheStore, a as CacheEntry } from './client-BQuRYSdB.js';
2
- export { A as AccessCache, b as AccessCacheOptions, c as AccessChangedDetail, d as CachedAnswer, e as CreatedDetail, D as DEFAULT_MAX_STALE_MS, f as Decision, E as EndedDetail, g as EventList, h as EventListParams, i as EventNetwork, j as EventType, k as Events, F as FirstPayment, H as HeaderSource, M as Mesub, l as MesubEvent, m as MesubOptions, N as NoDetail, P as PaymentFailedDetail, n as Plan, o as PlanStatus, p as PlanToken, q as Plans, R as RenewalIssue, r as RenewalUpcomingDetail, s as RenewedDetail, t as Revalidating, S as StoppedDetail, u as SubscriptionAccessGrantedEvent, v as SubscriptionAccessRevokedEvent, w as SubscriptionCancelledEvent, x as SubscriptionCreatedEvent, y as SubscriptionEndedEvent, z as SubscriptionExpiredEvent, B as SubscriptionPausedEvent, G as SubscriptionPaymentFailedEvent, I as SubscriptionRenewalUpcomingEvent, J as SubscriptionRenewedEvent, K as SubscriptionResumedEvent, L as SubscriptionStoppedEvent, O as SubscriptionUnpausedEvent, T as TestEvent, V as VerifyWebhookOptions, W as WebhookBody, Q as WebhookEvent, U as WebhookEventType, X as Webhooks, Y as verifyWebhook } from './client-BQuRYSdB.js';
3
- export { M as MesubError, a as MesubErrorCode, b as MesubErrorOptions, c as MesubSubmitError, d as MesubSubmitErrorOptions } from './errors-DqW3DMBS.js';
4
- export { A as AccessAnswer, a as AccessList, b as AccessOptions, c as AttemptsParams, B as BlockedReason, d as ConfirmOptions, e as ConfirmParams, f as ConfirmReasonCode, g as ConfirmResult, C as Customer, E as EndReason, L as LateReason, h as ListParams, P as PaymentStatus, i as PullOutcome, R as RequestOptions, S as ServedAttempt, j as ServerSubscription, k as ServerSubscriptionList, l as ServerSubscriptionStatus, m as StopReason, n as SubmitOptions, o as SubmitParams, p as SubmitResult, q as SubscribeCosts, r as SubscribeParams, s as SubscribeTransaction, t as SubscriptionAttempt, u as SubscriptionAttemptList, v as SubscriptionStatus, w as Subscriptions, W as WalletTransaction } from './subscriptions-D1hE7MUc.js';
1
+ import { C as CacheStore, a as CacheEntry } from './client-CXQLkSAJ.js';
2
+ export { A as AccessCache, b as AccessCacheOptions, c as AccessChangedDetail, d as CachedAnswer, e as CreatedDetail, D as DEFAULT_MAX_STALE_MS, f as Decision, E as EndedDetail, g as EventList, h as EventListParams, i as EventNetwork, j as EventType, k as Events, F as FirstPayment, H as HeaderSource, M as Mesub, l as MesubEvent, m as MesubOptions, N as NoDetail, P as PaymentFailedDetail, n as Plan, o as PlanStatus, p as PlanToken, q as Plans, R as RenewalIssue, r as RenewalUpcomingDetail, s as RenewedDetail, t as Revalidating, S as StoppedDetail, u as SubscriptionAccessGrantedEvent, v as SubscriptionAccessRevokedEvent, w as SubscriptionCancelledEvent, x as SubscriptionCreatedEvent, y as SubscriptionEndedEvent, z as SubscriptionExpiredEvent, B as SubscriptionPausedEvent, G as SubscriptionPaymentFailedEvent, I as SubscriptionRenewalUpcomingEvent, J as SubscriptionRenewedEvent, K as SubscriptionResumedEvent, L as SubscriptionStoppedEvent, O as SubscriptionUnpausedEvent, T as TestEvent, V as VerifyWebhookOptions, W as WebhookBody, Q as WebhookEvent, U as WebhookEventType, X as Webhooks, Y as verifyWebhook } from './client-CXQLkSAJ.js';
3
+ export { M as MesubError, a as MesubErrorCode, b as MesubErrorOptions, c as MesubSubmitError, d as MesubSubmitErrorOptions } from './errors-BN4ZWUfM.js';
4
+ export { A as AccessAnswer, a as AccessList, b as AccessOptions, c as AttemptsParams, B as BlockedReason, d as ConfirmOptions, e as ConfirmParams, f as ConfirmReasonCode, g as ConfirmResult, C as Customer, E as EndReason, L as LateReason, h as ListParams, P as PaymentStatus, i as PullOutcome, R as RequestOptions, S as ServedAttempt, j as ServerSubscription, k as ServerSubscriptionList, l as ServerSubscriptionStatus, m as StopReason, n as SubmitOptions, o as SubmitParams, p as SubmitResult, q as SubscribeCosts, r as SubscribeParams, s as SubscribeTransaction, t as SubscriptionAttempt, u as SubscriptionAttemptList, v as SubscriptionStatus, w as Subscriptions, W as WalletTransaction } from './subscriptions-B6Lin6i_.js';
5
5
  export { ACCESS_LINE, CONFIRMATIONS, ConfirmationKey, ExplainOptions, Explainable, ExplainedAction, Explanation, SITUATIONS, Situation, SituationActionId, SituationActionTemplate, SituationActor, SituationKey, SituationText, explain, situationOf } from './situations.js';
6
6
 
7
7
  /** Kept in step with package.json by `test/version.spec.ts`. */
8
- declare const VERSION = "0.1.0";
8
+ declare const VERSION = "0.1.2";
9
9
  /**
10
10
  * The version of the Mesub API this release was written against, sent in
11
11
  * the `Mesub-Version` header of every call, so the API can change its
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  MesubSubmitError,
11
11
  VERSION,
12
12
  verifyWebhook
13
- } from "./chunk-KMPBFNJE.js";
13
+ } from "./chunk-NOS4FWWQ.js";
14
14
  import {
15
15
  ACCESS_LINE,
16
16
  CONFIRMATIONS,
package/dist/nest.cjs CHANGED
@@ -9,10 +9,10 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkVMKI4VVAcjs = require('./chunk-VMKI4VVA.cjs');
12
+ var _chunkSJRQDWTIcjs = require('./chunk-SJRQDWTI.cjs');
13
13
 
14
14
 
15
- var _chunkSGSYQJYTcjs = require('./chunk-SGSYQJYT.cjs');
15
+ var _chunk4JSJOX35cjs = require('./chunk-4JSJOX35.cjs');
16
16
 
17
17
  // src/nest.ts
18
18
 
@@ -25,28 +25,28 @@ function setHeader(response, name, value) {
25
25
  else if (typeof response.header === "function") response.header(name, value);
26
26
  }
27
27
  function RequirePlan(plan, options) {
28
- _chunkVMKI4VVAcjs.checkPlan.call(void 0, plan);
29
- _chunkVMKI4VVAcjs.checkCustomer.call(void 0, options);
28
+ _chunkSJRQDWTIcjs.checkPlan.call(void 0, plan);
29
+ _chunkSJRQDWTIcjs.checkCustomer.call(void 0, options);
30
30
  class MesubPlanGuard {
31
31
  async canActivate(context) {
32
32
  const http = context.switchToHttp();
33
33
  const request = http.getRequest();
34
- const client = _nullishCoalesce(options.client, () => ( _chunkVMKI4VVAcjs.defaultClient.call(void 0, )));
35
- const outcome = await _chunkVMKI4VVAcjs.guard.call(void 0,
34
+ const client = _nullishCoalesce(options.client, () => ( _chunkSJRQDWTIcjs.defaultClient.call(void 0, )));
35
+ const outcome = await _chunkSJRQDWTIcjs.guard.call(void 0,
36
36
  client,
37
- await _chunkVMKI4VVAcjs.askerOf.call(void 0, request, options.customer),
38
- () => _chunkVMKI4VVAcjs.plansOf.call(void 0, plan, request)
37
+ await _chunkSJRQDWTIcjs.askerOf.call(void 0, request, options.customer),
38
+ () => _chunkSJRQDWTIcjs.plansOf.call(void 0, plan, request)
39
39
  );
40
40
  if (outcome.allowed) {
41
- request.mesub = _chunkVMKI4VVAcjs.accessOf.call(void 0, outcome);
41
+ request.mesub = _chunkSJRQDWTIcjs.accessOf.call(void 0, outcome);
42
42
  return true;
43
43
  }
44
- const denial = _chunkVMKI4VVAcjs.denialOf.call(void 0, outcome);
44
+ const denial = _chunkSJRQDWTIcjs.denialOf.call(void 0, outcome);
45
45
  await _optionalChain([options, 'access', _ => _.onDenied, 'optionalCall', _2 => _2(denial, request)]);
46
46
  if (outcome.reason === "unavailable") {
47
- setHeader(http.getResponse(), "Retry-After", _chunkVMKI4VVAcjs.retryAfterOf.call(void 0, outcome));
47
+ setHeader(http.getResponse(), "Retry-After", _chunkSJRQDWTIcjs.retryAfterOf.call(void 0, outcome));
48
48
  }
49
- throw new (0, _common.HttpException)(_chunkVMKI4VVAcjs.denialBody.call(void 0, outcome), denial.status);
49
+ throw new (0, _common.HttpException)(_chunkSJRQDWTIcjs.denialBody.call(void 0, outcome), denial.status);
50
50
  }
51
51
  }
52
52
  return _common.mixin.call(void 0, MesubPlanGuard);
@@ -58,5 +58,5 @@ var MesubAccess = _common.createParamDecorator.call(void 0,
58
58
 
59
59
 
60
60
 
61
- exports.MesubAccess = MesubAccess; exports.MesubError = _chunkSGSYQJYTcjs.MesubError; exports.RequirePlan = RequirePlan;
61
+ exports.MesubAccess = MesubAccess; exports.MesubError = _chunk4JSJOX35cjs.MesubError; exports.RequirePlan = RequirePlan;
62
62
  //# sourceMappingURL=nest.cjs.map
package/dist/nest.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Type, CanActivate } from '@nestjs/common';
2
- import { H as HeaderSource, M as Mesub } from './client-Dm1jamju.cjs';
3
- import { M as MesubAccess$1, P as PlanOption, C as CustomerOption, D as Denial } from './guard-Dhy4fI6n.cjs';
4
- export { A as Asked, a as DenialReason } from './guard-Dhy4fI6n.cjs';
5
- export { M as MesubError } from './errors-CtPucyOh.cjs';
6
- export { C as Customer } from './subscriptions-D1hE7MUc.cjs';
2
+ import { H as HeaderSource, M as Mesub } from './client-BEuDegEY.cjs';
3
+ import { M as MesubAccess$1, P as PlanOption, C as CustomerOption, D as Denial } from './guard-D4AB5HtN.cjs';
4
+ export { A as Asked, a as DenialReason } from './guard-D4AB5HtN.cjs';
5
+ export { M as MesubError } from './errors-DcLfunS-.cjs';
6
+ export { C as Customer } from './subscriptions-B6Lin6i_.cjs';
7
7
 
8
8
  /** `@mesub/node/nest`: `RequirePlan()` and `@MesubAccess()`. */
9
9
 
package/dist/nest.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Type, CanActivate } from '@nestjs/common';
2
- import { H as HeaderSource, M as Mesub } from './client-BQuRYSdB.js';
3
- import { M as MesubAccess$1, P as PlanOption, C as CustomerOption, D as Denial } from './guard-DKb6iU1z.js';
4
- export { A as Asked, a as DenialReason } from './guard-DKb6iU1z.js';
5
- export { M as MesubError } from './errors-DqW3DMBS.js';
6
- export { C as Customer } from './subscriptions-D1hE7MUc.js';
2
+ import { H as HeaderSource, M as Mesub } from './client-CXQLkSAJ.js';
3
+ import { M as MesubAccess$1, P as PlanOption, C as CustomerOption, D as Denial } from './guard-CaXiHMVF.js';
4
+ export { A as Asked, a as DenialReason } from './guard-CaXiHMVF.js';
5
+ export { M as MesubError } from './errors-BN4ZWUfM.js';
6
+ export { C as Customer } from './subscriptions-B6Lin6i_.js';
7
7
 
8
8
  /** `@mesub/node/nest`: `RequirePlan()` and `@MesubAccess()`. */
9
9
 
package/dist/nest.js CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  guard,
10
10
  plansOf,
11
11
  retryAfterOf
12
- } from "./chunk-XDLLXY7Y.js";
12
+ } from "./chunk-4AAPR37Y.js";
13
13
  import {
14
14
  MesubError
15
- } from "./chunk-KMPBFNJE.js";
15
+ } from "./chunk-NOS4FWWQ.js";
16
16
 
17
17
  // src/nest.ts
18
18
  import {
package/dist/next.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkPCDZI7B4cjs = require('./chunk-PCDZI7B4.cjs');
6
+ var _chunk66VVEXMUcjs = require('./chunk-66VVEXMU.cjs');
7
7
 
8
8
 
9
9
 
@@ -15,27 +15,27 @@ var _chunkPCDZI7B4cjs = require('./chunk-PCDZI7B4.cjs');
15
15
 
16
16
 
17
17
 
18
- var _chunkVMKI4VVAcjs = require('./chunk-VMKI4VVA.cjs');
18
+ var _chunkSJRQDWTIcjs = require('./chunk-SJRQDWTI.cjs');
19
19
 
20
20
 
21
- var _chunkSGSYQJYTcjs = require('./chunk-SGSYQJYT.cjs');
21
+ var _chunk4JSJOX35cjs = require('./chunk-4JSJOX35.cjs');
22
22
 
23
23
  // src/next.ts
24
24
  function withMesub(handler, options) {
25
- _chunkVMKI4VVAcjs.checkPlan.call(void 0, options.plan);
26
- _chunkVMKI4VVAcjs.checkCustomer.call(void 0, options);
25
+ _chunkSJRQDWTIcjs.checkPlan.call(void 0, options.plan);
26
+ _chunkSJRQDWTIcjs.checkCustomer.call(void 0, options);
27
27
  return async (request, context) => {
28
- const client = _nullishCoalesce(options.client, () => ( _chunkVMKI4VVAcjs.defaultClient.call(void 0, )));
29
- const outcome = await _chunkVMKI4VVAcjs.guard.call(void 0,
28
+ const client = _nullishCoalesce(options.client, () => ( _chunkSJRQDWTIcjs.defaultClient.call(void 0, )));
29
+ const outcome = await _chunkSJRQDWTIcjs.guard.call(void 0,
30
30
  client,
31
- await _chunkVMKI4VVAcjs.askerOf.call(void 0, request, options.customer),
32
- () => _chunkVMKI4VVAcjs.plansOf.call(void 0, options.plan, request)
31
+ await _chunkSJRQDWTIcjs.askerOf.call(void 0, request, options.customer),
32
+ () => _chunkSJRQDWTIcjs.plansOf.call(void 0, options.plan, request)
33
33
  );
34
- if (outcome.allowed) return handler(request, _chunkVMKI4VVAcjs.accessOf.call(void 0, outcome), context);
35
- const denial = _chunkVMKI4VVAcjs.denialOf.call(void 0, outcome);
34
+ if (outcome.allowed) return handler(request, _chunkSJRQDWTIcjs.accessOf.call(void 0, outcome), context);
35
+ const denial = _chunkSJRQDWTIcjs.denialOf.call(void 0, outcome);
36
36
  if (options.onDenied) return await options.onDenied(denial, request);
37
- const headers = outcome.reason === "unavailable" ? { "Retry-After": _chunkVMKI4VVAcjs.retryAfterOf.call(void 0, outcome) } : {};
38
- return Response.json(_chunkVMKI4VVAcjs.denialBody.call(void 0, outcome), { status: denial.status, headers });
37
+ const headers = outcome.reason === "unavailable" ? { "Retry-After": _chunkSJRQDWTIcjs.retryAfterOf.call(void 0, outcome) } : {};
38
+ return Response.json(_chunkSJRQDWTIcjs.denialBody.call(void 0, outcome), { status: denial.status, headers });
39
39
  };
40
40
  }
41
41
  async function pathOf(context) {
@@ -44,7 +44,7 @@ async function pathOf(context) {
44
44
  return `/${(_nullishCoalesce(segments, () => ( []))).map((segment) => encodeURIComponent(String(segment))).join("/")}`;
45
45
  }
46
46
  async function textOf(request) {
47
- if (Number(request.headers.get("content-length")) > _chunkPCDZI7B4cjs.MAX_BODY_BYTES) return null;
47
+ if (Number(request.headers.get("content-length")) > _chunk66VVEXMUcjs.MAX_BODY_BYTES) return null;
48
48
  if (request.body === null) return "";
49
49
  const reader = request.body.getReader();
50
50
  const decoder = new TextDecoder();
@@ -54,7 +54,7 @@ async function textOf(request) {
54
54
  const { done, value } = await reader.read();
55
55
  if (done) return text + decoder.decode();
56
56
  size += value.byteLength;
57
- if (size > _chunkPCDZI7B4cjs.MAX_BODY_BYTES) {
57
+ if (size > _chunk66VVEXMUcjs.MAX_BODY_BYTES) {
58
58
  await reader.cancel();
59
59
  return null;
60
60
  }
@@ -62,7 +62,7 @@ async function textOf(request) {
62
62
  }
63
63
  }
64
64
  function mesubRouteHandlers(options) {
65
- _chunkPCDZI7B4cjs.checkWidgetOptions.call(void 0, options);
65
+ _chunk66VVEXMUcjs.checkWidgetOptions.call(void 0, options);
66
66
  const handle = async (request, context) => {
67
67
  const path = await pathOf(context);
68
68
  let body;
@@ -84,10 +84,10 @@ function mesubRouteHandlers(options) {
84
84
  }
85
85
  }
86
86
  const publicRead = request.method === "GET" && path.startsWith("/plans/");
87
- const asked = publicRead ? null : await _chunkPCDZI7B4cjs.widgetCustomer.call(void 0, request, options.customer);
87
+ const asked = publicRead ? null : await _chunk66VVEXMUcjs.widgetCustomer.call(void 0, request, options.customer);
88
88
  const email = asked && options.email ? await options.email(request) : void 0;
89
- const answer = await _chunkPCDZI7B4cjs.handleWidget.call(void 0,
90
- _nullishCoalesce(options.client, () => ( _chunkVMKI4VVAcjs.defaultClient.call(void 0, ))),
89
+ const answer = await _chunk66VVEXMUcjs.handleWidget.call(void 0,
90
+ _nullishCoalesce(options.client, () => ( _chunkSJRQDWTIcjs.defaultClient.call(void 0, ))),
91
91
  {
92
92
  method: request.method,
93
93
  path,
@@ -109,5 +109,5 @@ function mesubRouteHandlers(options) {
109
109
 
110
110
 
111
111
 
112
- exports.MesubError = _chunkSGSYQJYTcjs.MesubError; exports.mesubRouteHandlers = mesubRouteHandlers; exports.withMesub = withMesub;
112
+ exports.MesubError = _chunk4JSJOX35cjs.MesubError; exports.mesubRouteHandlers = mesubRouteHandlers; exports.withMesub = withMesub;
113
113
  //# sourceMappingURL=next.cjs.map
package/dist/next.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { M as Mesub } from './client-Dm1jamju.cjs';
2
- import { M as MesubAccess, P as PlanOption, C as CustomerOption, D as Denial } from './guard-Dhy4fI6n.cjs';
3
- export { A as Asked, a as DenialReason } from './guard-Dhy4fI6n.cjs';
4
- import { W as WidgetRoutesOptions } from './routes-DWkRFOP0.cjs';
5
- export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-DWkRFOP0.cjs';
6
- export { M as MesubError } from './errors-CtPucyOh.cjs';
7
- export { C as Customer } from './subscriptions-D1hE7MUc.cjs';
1
+ import { M as Mesub } from './client-BEuDegEY.cjs';
2
+ import { M as MesubAccess, P as PlanOption, C as CustomerOption, D as Denial } from './guard-D4AB5HtN.cjs';
3
+ export { A as Asked, a as DenialReason } from './guard-D4AB5HtN.cjs';
4
+ import { W as WidgetRoutesOptions } from './routes-CMzB52P6.cjs';
5
+ export { a as WidgetPayment, b as WidgetSubscriptionDetail, c as WidgetSubscriptionList } from './routes-CMzB52P6.cjs';
6
+ export { M as MesubError } from './errors-DcLfunS-.cjs';
7
+ export { C as Customer } from './subscriptions-B6Lin6i_.cjs';
8
8
 
9
9
  /** `@mesub/node/next`: `withMesub()`. Web `Request`/`Response` only, nothing imported from `next`. */
10
10