@ultimabase/stripe 0.0.0-first.0 → 0.0.0-stage
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 +2 -6
- package/package.json +3 -48
- package/dist/accounts.d.ts +0 -9
- package/dist/accounts.d.ts.map +0 -1
- package/dist/accounts.js +0 -20
- package/dist/apply.d.ts +0 -26
- package/dist/apply.d.ts.map +0 -1
- package/dist/apply.js +0 -73
- package/dist/audit.d.ts +0 -3
- package/dist/audit.d.ts.map +0 -1
- package/dist/audit.js +0 -123
- package/dist/billing-gateway.d.ts +0 -158
- package/dist/billing-gateway.d.ts.map +0 -1
- package/dist/billing-gateway.js +0 -23
- package/dist/billing.d.ts +0 -130
- package/dist/billing.d.ts.map +0 -1
- package/dist/billing.js +0 -128
- package/dist/calls.d.ts +0 -61
- package/dist/calls.d.ts.map +0 -1
- package/dist/calls.js +0 -172
- package/dist/catalog.d.ts +0 -54
- package/dist/catalog.d.ts.map +0 -1
- package/dist/catalog.js +0 -182
- package/dist/credit.d.ts +0 -16
- package/dist/credit.d.ts.map +0 -1
- package/dist/credit.js +0 -18
- package/dist/credits.d.ts +0 -38
- package/dist/credits.d.ts.map +0 -1
- package/dist/credits.js +0 -138
- package/dist/customer.d.ts +0 -25
- package/dist/customer.d.ts.map +0 -1
- package/dist/customer.js +0 -88
- package/dist/describe.d.ts +0 -4
- package/dist/describe.d.ts.map +0 -1
- package/dist/describe.js +0 -56
- package/dist/duplicates.d.ts +0 -12
- package/dist/duplicates.d.ts.map +0 -1
- package/dist/duplicates.js +0 -24
- package/dist/fake-billing.d.ts +0 -72
- package/dist/fake-billing.d.ts.map +0 -1
- package/dist/fake-billing.js +0 -290
- package/dist/gateway.d.ts +0 -108
- package/dist/gateway.d.ts.map +0 -1
- package/dist/gateway.js +0 -196
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/job-input.d.ts +0 -6
- package/dist/job-input.d.ts.map +0 -1
- package/dist/job-input.js +0 -20
- package/dist/jobs.d.ts +0 -16
- package/dist/jobs.d.ts.map +0 -1
- package/dist/jobs.js +0 -189
- package/dist/keys.d.ts +0 -10
- package/dist/keys.d.ts.map +0 -1
- package/dist/keys.js +0 -30
- package/dist/kinds.d.ts +0 -11
- package/dist/kinds.d.ts.map +0 -1
- package/dist/kinds.js +0 -4
- package/dist/models.d.ts +0 -71
- package/dist/models.d.ts.map +0 -1
- package/dist/models.js +0 -41
- package/dist/plugin.d.ts +0 -41
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -229
- package/dist/portal.d.ts +0 -23
- package/dist/portal.d.ts.map +0 -1
- package/dist/portal.js +0 -66
- package/dist/product.d.ts +0 -57
- package/dist/product.d.ts.map +0 -1
- package/dist/product.js +0 -113
- package/dist/running.d.ts +0 -61
- package/dist/running.d.ts.map +0 -1
- package/dist/running.js +0 -35
- package/dist/sdk-billing.d.ts +0 -8
- package/dist/sdk-billing.d.ts.map +0 -1
- package/dist/sdk-billing.js +0 -200
- package/dist/sdk-common.d.ts +0 -13
- package/dist/sdk-common.d.ts.map +0 -1
- package/dist/sdk-common.js +0 -41
- package/dist/sdk-customer.d.ts +0 -9
- package/dist/sdk-customer.d.ts.map +0 -1
- package/dist/sdk-customer.js +0 -149
- package/dist/sdk-invoices.d.ts +0 -10
- package/dist/sdk-invoices.d.ts.map +0 -1
- package/dist/sdk-invoices.js +0 -53
- package/dist/sdk-recovery.d.ts +0 -5
- package/dist/sdk-recovery.d.ts.map +0 -1
- package/dist/sdk-recovery.js +0 -81
- package/dist/sync.d.ts +0 -8
- package/dist/sync.d.ts.map +0 -1
- package/dist/sync.js +0 -196
- package/dist/testing.d.ts +0 -24
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -100
- package/dist/webhook.d.ts +0 -4
- package/dist/webhook.d.ts.map +0 -1
- package/dist/webhook.js +0 -73
- package/src/accounts.ts +0 -30
- package/src/apply.ts +0 -99
- package/src/audit.ts +0 -171
- package/src/billing-gateway.ts +0 -188
- package/src/billing.ts +0 -361
- package/src/calls.ts +0 -280
- package/src/catalog.ts +0 -327
- package/src/credit.ts +0 -36
- package/src/credits.ts +0 -206
- package/src/customer.ts +0 -113
- package/src/describe.ts +0 -76
- package/src/duplicates.ts +0 -45
- package/src/fake-billing.ts +0 -388
- package/src/gateway.ts +0 -333
- package/src/index.ts +0 -35
- package/src/job-input.ts +0 -24
- package/src/jobs.ts +0 -230
- package/src/keys.ts +0 -40
- package/src/kinds.ts +0 -15
- package/src/models.ts +0 -107
- package/src/plugin.ts +0 -307
- package/src/portal.ts +0 -95
- package/src/product.ts +0 -203
- package/src/running.ts +0 -104
- package/src/sdk-billing.ts +0 -220
- package/src/sdk-common.ts +0 -57
- package/src/sdk-customer.ts +0 -203
- package/src/sdk-invoices.ts +0 -81
- package/src/sdk-recovery.ts +0 -93
- package/src/sync.ts +0 -246
- package/src/testing.ts +0 -135
- package/src/webhook.ts +0 -100
package/dist/billing.d.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import type { Field, FieldShapes, IndexShape, ModelFields, ModelIndexes, ModelOf, ModelUse, One, PluginTypes, ScalarOptions } from 'ultimabase';
|
|
2
|
-
import type { Stripe } from './plugin.ts';
|
|
3
|
-
import type { Every } from './product.ts';
|
|
4
|
-
type Uses = readonly ModelUse<string, PluginTypes>[];
|
|
5
|
-
/** A billing model's `use`: the plugin first, then the developer's. */
|
|
6
|
-
export type WithStripe<U extends Uses> = readonly [
|
|
7
|
-
ModelUse<'stripe', Stripe>,
|
|
8
|
-
...U
|
|
9
|
-
];
|
|
10
|
-
type Text = Field<string, ScalarOptions<string>>;
|
|
11
|
-
type Int = Field<number, {
|
|
12
|
-
readonly integer: true;
|
|
13
|
-
}>;
|
|
14
|
-
type Moment = Field<Date, ScalarOptions<Date>>;
|
|
15
|
-
type Optional<V> = Field<V | null, {
|
|
16
|
-
readonly optional: true;
|
|
17
|
-
}>;
|
|
18
|
-
type StripeId = Field<string, {
|
|
19
|
-
readonly unique: true;
|
|
20
|
-
}>;
|
|
21
|
-
type PayerOf<P> = One<P, {
|
|
22
|
-
readonly onDelete: 'cascade';
|
|
23
|
-
}>;
|
|
24
|
-
type OneOf<V extends string> = Field<V, ScalarOptions<string>>;
|
|
25
|
-
/** Stripe's statuses of a subscription. */
|
|
26
|
-
export type SubscriptionStatus = 'incomplete' | 'incomplete_expired' | 'trialing' | 'active' | 'past_due' | 'canceled' | 'unpaid' | 'paused';
|
|
27
|
-
/** The fields `defineSubscription` adds; `P` is the payer's thunk. */
|
|
28
|
-
export type SubscriptionFields<P> = {
|
|
29
|
-
readonly payer: PayerOf<P>;
|
|
30
|
-
readonly stripeId: StripeId;
|
|
31
|
-
/** The product's key and the price's name (D-372). */
|
|
32
|
-
readonly product: Text;
|
|
33
|
-
readonly price: Text;
|
|
34
|
-
readonly status: OneOf<SubscriptionStatus>;
|
|
35
|
-
readonly quantity: Int;
|
|
36
|
-
/**
|
|
37
|
-
* What one period costs, times the quantity, before discounts and taxes,
|
|
38
|
-
* in the currency's smallest unit: the price the payer subscribed at.
|
|
39
|
-
*/
|
|
40
|
-
readonly amount: Int;
|
|
41
|
-
/** The price's interval: every `everyCount` `every`. */
|
|
42
|
-
readonly every: OneOf<Every>;
|
|
43
|
-
readonly everyCount: Int;
|
|
44
|
-
readonly currentPeriodEnd: Moment;
|
|
45
|
-
readonly cancelAt: Optional<Date>;
|
|
46
|
-
readonly canceledAt: Optional<Date>;
|
|
47
|
-
readonly trialEnd: Optional<Date>;
|
|
48
|
-
readonly startedAt: Moment;
|
|
49
|
-
/** A change that waits for the period's end (D-373 point 8). */
|
|
50
|
-
readonly scheduledProduct: Optional<string>;
|
|
51
|
-
readonly scheduledPrice: Optional<string>;
|
|
52
|
-
readonly scheduledAt: Optional<Date>;
|
|
53
|
-
};
|
|
54
|
-
/** The fields `definePurchase` adds. */
|
|
55
|
-
export type PurchaseFields<P> = {
|
|
56
|
-
readonly payer: PayerOf<P>;
|
|
57
|
-
readonly stripeId: StripeId;
|
|
58
|
-
readonly product: Text;
|
|
59
|
-
readonly quantity: Int;
|
|
60
|
-
/** In the currency's smallest unit. */
|
|
61
|
-
readonly amount: Int;
|
|
62
|
-
readonly refunded: Int;
|
|
63
|
-
readonly status: OneOf<'paid' | 'refunded'>;
|
|
64
|
-
readonly paidAt: Moment;
|
|
65
|
-
/** Stripe's receipt page. */
|
|
66
|
-
readonly receiptUrl: Optional<string>;
|
|
67
|
-
};
|
|
68
|
-
/** The fields `defineBalance` adds. */
|
|
69
|
-
export type BalanceFields<P> = {
|
|
70
|
-
readonly owner: PayerOf<P>;
|
|
71
|
-
/** The credit's key (D-372). */
|
|
72
|
-
readonly credit: Text;
|
|
73
|
-
/** Never below zero. */
|
|
74
|
-
readonly amount: Int;
|
|
75
|
-
};
|
|
76
|
-
/** The fields `defineCreditHistory` adds: one move of credits (D-377). */
|
|
77
|
-
export type CreditHistoryFields<P> = {
|
|
78
|
-
readonly owner: PayerOf<P>;
|
|
79
|
-
readonly credit: Text;
|
|
80
|
-
/** Positive when given, negative when spent or taken back. */
|
|
81
|
-
readonly change: Int;
|
|
82
|
-
/** `purchase`, `subscription`, `refund`, or the application's own. */
|
|
83
|
-
readonly reason: Text;
|
|
84
|
-
/** The Stripe payment or invoice that moved it. */
|
|
85
|
-
readonly payment: Optional<string>;
|
|
86
|
-
};
|
|
87
|
-
type Definition<N, F, U extends Uses, X, A> = {
|
|
88
|
-
readonly name: N;
|
|
89
|
-
/** The stored table's or collection's name (D-63). */
|
|
90
|
-
readonly dbName?: string;
|
|
91
|
-
readonly use?: U;
|
|
92
|
-
readonly indexes?: ModelIndexes<X, F & A, WithStripe<U>>;
|
|
93
|
-
};
|
|
94
|
-
type Own<F, U extends Uses> = {
|
|
95
|
-
readonly fields: ModelFields<F, WithStripe<U>>;
|
|
96
|
-
};
|
|
97
|
-
/** The application's subscriptions, with its own fields (D-373). */
|
|
98
|
-
export declare function defineSubscription<const N extends string, const P extends () => object, const F extends FieldShapes, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, F, U, X, SubscriptionFields<P>> & Own<F, U> & {
|
|
99
|
-
readonly payer: P;
|
|
100
|
-
}): ModelOf<N, F & SubscriptionFields<P>, WithStripe<U>, X>;
|
|
101
|
-
/** The application's subscriptions (D-373). */
|
|
102
|
-
export declare function defineSubscription<const N extends string, const P extends () => object, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, {}, U, X, SubscriptionFields<P>> & {
|
|
103
|
-
readonly payer: P;
|
|
104
|
-
}): ModelOf<N, SubscriptionFields<P>, WithStripe<U>, X>;
|
|
105
|
-
/** The application's one-time purchases, with its own fields (D-373). */
|
|
106
|
-
export declare function definePurchase<const N extends string, const P extends () => object, const F extends FieldShapes, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, F, U, X, PurchaseFields<P>> & Own<F, U> & {
|
|
107
|
-
readonly payer: P;
|
|
108
|
-
}): ModelOf<N, F & PurchaseFields<P>, WithStripe<U>, X>;
|
|
109
|
-
/** The application's one-time purchases (D-373). */
|
|
110
|
-
export declare function definePurchase<const N extends string, const P extends () => object, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, {}, U, X, PurchaseFields<P>> & {
|
|
111
|
-
readonly payer: P;
|
|
112
|
-
}): ModelOf<N, PurchaseFields<P>, WithStripe<U>, X>;
|
|
113
|
-
/** The application's credit balances, with its own fields (D-374). */
|
|
114
|
-
export declare function defineBalance<const N extends string, const P extends () => object, const F extends FieldShapes, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, F, U, X, BalanceFields<P>> & Own<F, U> & {
|
|
115
|
-
readonly owner: P;
|
|
116
|
-
}): ModelOf<N, F & BalanceFields<P>, WithStripe<U>, X>;
|
|
117
|
-
/** The application's credit balances (D-374). */
|
|
118
|
-
export declare function defineBalance<const N extends string, const P extends () => object, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, {}, U, X, BalanceFields<P>> & {
|
|
119
|
-
readonly owner: P;
|
|
120
|
-
}): ModelOf<N, BalanceFields<P>, WithStripe<U>, X>;
|
|
121
|
-
/** The application's history of credits, with its own fields (D-377). */
|
|
122
|
-
export declare function defineCreditHistory<const N extends string, const P extends () => object, const F extends FieldShapes, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, F, U, X, CreditHistoryFields<P>> & Own<F, U> & {
|
|
123
|
-
readonly owner: P;
|
|
124
|
-
}): ModelOf<N, F & CreditHistoryFields<P>, WithStripe<U>, X>;
|
|
125
|
-
/** The application's history of credits: each move, given or spent (D-377). */
|
|
126
|
-
export declare function defineCreditHistory<const N extends string, const P extends () => object, const U extends Uses = [], const X extends readonly IndexShape[] = []>(definition: Definition<N, {}, U, X, CreditHistoryFields<P>> & {
|
|
127
|
-
readonly owner: P;
|
|
128
|
-
}): ModelOf<N, CreditHistoryFields<P>, WithStripe<U>, X>;
|
|
129
|
-
export {};
|
|
130
|
-
//# sourceMappingURL=billing.d.ts.map
|
package/dist/billing.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,KAAK,EACL,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,GAAG,EACH,WAAW,EACX,aAAa,EACb,MAAM,YAAY,CAAA;AAKnB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEzC,KAAK,IAAI,GAAG,SAAS,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAA;AACpD,uEAAuE;AACvE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,IAAI,IAAI,SAAS;IACjD,QAAQ,CAAC,QAAQ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,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAChC,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC3D,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAClC,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,MAAM,MAAM,EAC5B,KAAK,CAAC,CAAC,SAAS,IAAI,GAAG,EAAE,EACzB,KAAK,CAAC,CAAC,SAAS,SAAS,UAAU,EAAE,GAAG,EAAE,EAE1C,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAAG;IAC7D,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CACjB,GACC,OAAO,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
package/dist/billing.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { defineModel, Refused } from 'ultimabase';
|
|
2
|
-
import { knownKeys } from 'ultimabase/internal';
|
|
3
|
-
import { billingModels } from './kinds.js';
|
|
4
|
-
import { stripeUse } from './plugin.js';
|
|
5
|
-
const statuses = [
|
|
6
|
-
'incomplete',
|
|
7
|
-
'incomplete_expired',
|
|
8
|
-
'trialing',
|
|
9
|
-
'active',
|
|
10
|
-
'past_due',
|
|
11
|
-
'canceled',
|
|
12
|
-
'unpaid',
|
|
13
|
-
'paused',
|
|
14
|
-
];
|
|
15
|
-
const intervals = ['day', 'week', 'month', 'year'];
|
|
16
|
-
const added = (f, kind, payer) => {
|
|
17
|
-
const ref = f.one(payer, { onDelete: 'cascade' });
|
|
18
|
-
const optional = { optional: true };
|
|
19
|
-
if (kind === 'subscription') {
|
|
20
|
-
return {
|
|
21
|
-
payer: ref,
|
|
22
|
-
stripeId: f.string({ unique: true }),
|
|
23
|
-
product: f.string(),
|
|
24
|
-
price: f.string(),
|
|
25
|
-
status: f.enumOf(statuses),
|
|
26
|
-
quantity: f.number({ integer: true }),
|
|
27
|
-
amount: f.number({ integer: true }),
|
|
28
|
-
every: f.enumOf(intervals),
|
|
29
|
-
everyCount: f.number({ integer: true }),
|
|
30
|
-
currentPeriodEnd: f.dateTime(),
|
|
31
|
-
cancelAt: f.dateTime(optional),
|
|
32
|
-
canceledAt: f.dateTime(optional),
|
|
33
|
-
trialEnd: f.dateTime(optional),
|
|
34
|
-
startedAt: f.dateTime(),
|
|
35
|
-
scheduledProduct: f.string(optional),
|
|
36
|
-
scheduledPrice: f.string(optional),
|
|
37
|
-
scheduledAt: f.dateTime(optional),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (kind === 'purchase') {
|
|
41
|
-
return {
|
|
42
|
-
payer: ref,
|
|
43
|
-
stripeId: f.string({ unique: true }),
|
|
44
|
-
product: f.string(),
|
|
45
|
-
quantity: f.number({ integer: true }),
|
|
46
|
-
amount: f.number({ integer: true }),
|
|
47
|
-
refunded: f.number({ integer: true }),
|
|
48
|
-
status: f.enumOf(['paid', 'refunded']),
|
|
49
|
-
paidAt: f.dateTime(),
|
|
50
|
-
receiptUrl: f.string(optional),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (kind === 'history') {
|
|
54
|
-
return {
|
|
55
|
-
owner: ref,
|
|
56
|
-
credit: f.string(),
|
|
57
|
-
change: f.number({ integer: true }),
|
|
58
|
-
reason: f.string(),
|
|
59
|
-
payment: f.string(optional),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
owner: ref,
|
|
64
|
-
credit: f.string(),
|
|
65
|
-
amount: f.number({ integer: true }),
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
/** The indexes the plugin's queries need. */
|
|
69
|
-
const indexesOf = (kind) => {
|
|
70
|
-
if (kind === 'balance')
|
|
71
|
-
return [{ fields: ['owner', 'credit'], unique: true }];
|
|
72
|
-
// A payment gives its credits once: its moves are looked up by it.
|
|
73
|
-
if (kind === 'history')
|
|
74
|
-
return [{ fields: ['payment'] }];
|
|
75
|
-
return [];
|
|
76
|
-
};
|
|
77
|
-
// The kernel checks the model the thunk returns.
|
|
78
|
-
const isThunk = (value) => typeof value === 'function';
|
|
79
|
-
const entries = {
|
|
80
|
-
subscription: ['defineSubscription', 'payer'],
|
|
81
|
-
purchase: ['definePurchase', 'payer'],
|
|
82
|
-
balance: ['defineBalance', 'owner'],
|
|
83
|
-
history: ['defineCreditHistory', 'owner'],
|
|
84
|
-
};
|
|
85
|
-
/** Builds a billing model of `kind` from the developer's definition. */
|
|
86
|
-
function billingModel(kind, definition) {
|
|
87
|
-
const [entry, key] = entries[kind];
|
|
88
|
-
const { name, fields } = definition;
|
|
89
|
-
const keys = ['name', 'dbName', key, 'use', 'fields', 'indexes'];
|
|
90
|
-
knownKeys(name, definition, keys, 'access, hooks and plugin options');
|
|
91
|
-
const payer = Reflect.get(definition, key);
|
|
92
|
-
if (!isThunk(payer)) {
|
|
93
|
-
throw new Refused(`${entry}(${name}): ${key} is () => its model.`);
|
|
94
|
-
}
|
|
95
|
-
const target = payer;
|
|
96
|
-
const model = defineModel({
|
|
97
|
-
name,
|
|
98
|
-
...(definition.dbName === undefined ? {} : { dbName: definition.dbName }),
|
|
99
|
-
use: [stripeUse(), ...(definition.use ?? [])],
|
|
100
|
-
fields: (f) => {
|
|
101
|
-
const own = fields === undefined ? {} : Reflect.apply(fields, undefined, [f]);
|
|
102
|
-
if (typeof own !== 'object' || own === null) {
|
|
103
|
-
throw new Refused(`${entry}(${name}): fields returns an object.`);
|
|
104
|
-
}
|
|
105
|
-
const adds = added(f, kind, target);
|
|
106
|
-
const taken = Object.keys(adds).find((field) => Object.hasOwn(own, field));
|
|
107
|
-
if (taken !== undefined) {
|
|
108
|
-
throw new Refused(`${entry}(${name}): ${taken} is a field ${entry} adds.`);
|
|
109
|
-
}
|
|
110
|
-
return { ...own, ...adds };
|
|
111
|
-
},
|
|
112
|
-
indexes: [...indexesOf(kind), ...(definition.indexes ?? [])],
|
|
113
|
-
});
|
|
114
|
-
billingModels.set(model, { kind, payer: target });
|
|
115
|
-
return model;
|
|
116
|
-
}
|
|
117
|
-
export function defineSubscription(definition) {
|
|
118
|
-
return billingModel('subscription', definition);
|
|
119
|
-
}
|
|
120
|
-
export function definePurchase(definition) {
|
|
121
|
-
return billingModel('purchase', definition);
|
|
122
|
-
}
|
|
123
|
-
export function defineBalance(definition) {
|
|
124
|
-
return billingModel('balance', definition);
|
|
125
|
-
}
|
|
126
|
-
export function defineCreditHistory(definition) {
|
|
127
|
-
return billingModel('history', definition);
|
|
128
|
-
}
|
package/dist/calls.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Product, SubscriptionProduct } from './product.ts';
|
|
2
|
-
import { grant, spend } from './credits.ts';
|
|
3
|
-
type Payer = {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
};
|
|
6
|
-
/** A product's price names: `'monthly' | 'yearly'`. */
|
|
7
|
-
type PriceOf<P> = P extends SubscriptionProduct<string, infer N> ? N : never;
|
|
8
|
-
/** What `stripe.checkout` takes (D-373 point 7). */
|
|
9
|
-
export interface CheckoutArgs<P extends Product = Product> {
|
|
10
|
-
/** The payer's row, as `{ id }`. */
|
|
11
|
-
readonly payer: Payer;
|
|
12
|
-
readonly product: P;
|
|
13
|
-
/** One of a subscription product's prices; its only one by default. */
|
|
14
|
-
readonly price?: PriceOf<P>;
|
|
15
|
-
/** 1 by default. */
|
|
16
|
-
readonly quantity?: number;
|
|
17
|
-
readonly trialDays?: number;
|
|
18
|
-
/** Whether the payer must accept the portal's `termsUrl`. */
|
|
19
|
-
readonly terms?: boolean;
|
|
20
|
-
readonly promotionCodes?: boolean;
|
|
21
|
-
/** Where Stripe sends the payer back; `{CHECKOUT_SESSION_ID}` is replaced. */
|
|
22
|
-
readonly successUrl: string;
|
|
23
|
-
readonly cancelUrl: string;
|
|
24
|
-
readonly metadata?: Readonly<Record<string, string>>;
|
|
25
|
-
}
|
|
26
|
-
/** What `stripe.portal` takes (D-373 point 8). */
|
|
27
|
-
export interface PortalArgs<P extends SubscriptionProduct = SubscriptionProduct> {
|
|
28
|
-
readonly payer: Payer;
|
|
29
|
-
/** The portal option's `returnUrl` by default. */
|
|
30
|
-
readonly returnUrl?: string;
|
|
31
|
-
/** Opens the confirmation of a move to another product or price. */
|
|
32
|
-
readonly change?: {
|
|
33
|
-
readonly product: P;
|
|
34
|
-
readonly price: PriceOf<P>;
|
|
35
|
-
/** The subscription row's id, when the payer has several live ones. */
|
|
36
|
-
readonly subscription?: string;
|
|
37
|
-
};
|
|
38
|
-
/** Opens the confirmation of a cancellation. */
|
|
39
|
-
readonly cancel?: {
|
|
40
|
-
readonly subscription?: string;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/** Opens a Checkout for the payer and returns its URL. */
|
|
44
|
-
export declare function checkout<const P extends Product>(args: CheckoutArgs<P>): Promise<string>;
|
|
45
|
-
/** Opens the payer's customer portal, or one change's confirmation. */
|
|
46
|
-
export declare function portal<const P extends SubscriptionProduct>(args: PortalArgs<P>): Promise<string>;
|
|
47
|
-
/**
|
|
48
|
-
* Syncs the payer's Checkout `sessionId` when the client comes back, without
|
|
49
|
-
* waiting for the webhook; `NOT_FOUND` for another payer's.
|
|
50
|
-
*/
|
|
51
|
-
export declare function syncCheckout(sessionId: string, payer: Payer): Promise<void>;
|
|
52
|
-
/** The running plugin, from the application's functions (D-371 point 3). */
|
|
53
|
-
export declare const stripe: {
|
|
54
|
-
readonly checkout: typeof checkout;
|
|
55
|
-
readonly portal: typeof portal;
|
|
56
|
-
readonly syncCheckout: typeof syncCheckout;
|
|
57
|
-
readonly grant: typeof grant;
|
|
58
|
-
readonly spend: typeof spend;
|
|
59
|
-
};
|
|
60
|
-
export {};
|
|
61
|
-
//# sourceMappingURL=calls.d.ts.map
|
package/dist/calls.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAGhE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAG3C,KAAK,KAAK,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AACpC,uDAAuD;AACvD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE5E,oDAAoD;AACpD,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACxD,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,uEAAuE;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAC3B,oBAAoB;IACpB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAA;IACjC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,M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K,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,KAAK,CAAA;CACuB,CAAA"}
|
package/dist/calls.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// `stripe.checkout`, `stripe.portal` and `stripe.syncCheckout` (D-371 point
|
|
2
|
-
// 3, D-373 points 7 and 8): the server calls an application's functions make.
|
|
3
|
-
// Each runs under the payer's customer lock and expires the Checkouts the
|
|
4
|
-
// payer left open, so two tabs cannot both pay.
|
|
5
|
-
import { PublicError, Refused } from 'ultimabase';
|
|
6
|
-
import { liveStatuses, Missing } from './billing-gateway.js';
|
|
7
|
-
import { customerRow, ensureCustomer, locked, payerRow, renewed, } from './customer.js';
|
|
8
|
-
import { M, StripeCustomer } from './models.js';
|
|
9
|
-
import { runningOf, stripeOf } from './running.js';
|
|
10
|
-
import { grant, spend } from './credits.js';
|
|
11
|
-
import { syncCustomer } from './sync.js';
|
|
12
|
-
/** The catalog's product, or a bug: a product the plugin was not given. */
|
|
13
|
-
function catalogued(running, product) {
|
|
14
|
-
if (running.products.get(product.key) === product)
|
|
15
|
-
return product;
|
|
16
|
-
throw new Error(`${product.key} is not in stripePlugin's products.`);
|
|
17
|
-
}
|
|
18
|
-
/** The price's lookup key (D-372 point 3). */
|
|
19
|
-
function lookupKey(product, price) {
|
|
20
|
-
if (!('prices' in product))
|
|
21
|
-
return product.key;
|
|
22
|
-
const names = Object.keys(product.prices);
|
|
23
|
-
const [only] = names;
|
|
24
|
-
const name = price ?? (names.length === 1 ? only : undefined);
|
|
25
|
-
if (name === undefined || !names.includes(name)) {
|
|
26
|
-
throw new TypeError(`${product.key}'s price is one of ${names.join(', ')}.`);
|
|
27
|
-
}
|
|
28
|
-
return `${product.key}.${name}`;
|
|
29
|
-
}
|
|
30
|
-
/** The model naming the payers of a product: who the customer is for. */
|
|
31
|
-
function billingOf(running, product) {
|
|
32
|
-
const billing = 'prices' in product
|
|
33
|
-
? running.subscription
|
|
34
|
-
: (running.purchase ?? running.balance);
|
|
35
|
-
if (billing !== undefined)
|
|
36
|
-
return billing;
|
|
37
|
-
throw new Error(`${product.key} needs a model definePurchase returned, to record its payments.`);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Runs `run` with the payer's customer at Stripe, under its lock, after
|
|
41
|
-
* expiring its open Checkouts; a customer deleted at Stripe is created again.
|
|
42
|
-
*/
|
|
43
|
-
async function withCustomer(billing, payer, run) {
|
|
44
|
-
const { gateway } = stripeOf('stripe');
|
|
45
|
-
const read = await payerRow(billing.payer, payer.id);
|
|
46
|
-
const held = await customerRow(billing.payer.name, payer.id);
|
|
47
|
-
const done = await locked(held.id, async (row) => {
|
|
48
|
-
const attempt = async (current) => {
|
|
49
|
-
const { row: saved, stripeId } = await ensureCustomer(current, read);
|
|
50
|
-
try {
|
|
51
|
-
await gateway.expireCheckouts(stripeId);
|
|
52
|
-
return await run(gateway, stripeId, saved);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (!(error instanceof Missing) || current !== row)
|
|
56
|
-
throw error;
|
|
57
|
-
return attempt(await renewed(saved));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return { value: await attempt(row) };
|
|
61
|
-
});
|
|
62
|
-
if (done === undefined)
|
|
63
|
-
throw new Error('The payer’s customer was closed.');
|
|
64
|
-
return done.value;
|
|
65
|
-
}
|
|
66
|
-
const checkPositive = (name, value) => {
|
|
67
|
-
if (value !== undefined && (!Number.isSafeInteger(value) || value < 1)) {
|
|
68
|
-
throw new TypeError(`stripe.checkout: ${name} is a positive integer.`);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
/** Opens a Checkout for the payer and returns its URL. */
|
|
72
|
-
export async function checkout(args) {
|
|
73
|
-
const running = runningOf('stripe.checkout');
|
|
74
|
-
stripeOf('stripe.checkout');
|
|
75
|
-
const product = catalogued(running, args.product);
|
|
76
|
-
const key = lookupKey(product, args.price);
|
|
77
|
-
checkPositive('quantity', args.quantity);
|
|
78
|
-
checkPositive('trialDays', args.trialDays);
|
|
79
|
-
const subscribing = 'prices' in product;
|
|
80
|
-
return withCustomer(billingOf(running, product), args.payer, async (gateway, customerId) => {
|
|
81
|
-
if (subscribing && running.oneSubscription) {
|
|
82
|
-
const { subscriptions } = await gateway.readCustomer(customerId);
|
|
83
|
-
if (subscriptions.some(({ status }) => liveStatuses.includes(status))) {
|
|
84
|
-
throw new PublicError('ALREADY_SUBSCRIBED', 'The payer already has a subscription.');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return gateway.openCheckout({
|
|
88
|
-
customerId,
|
|
89
|
-
reference: args.payer.id,
|
|
90
|
-
mode: subscribing ? 'subscription' : 'payment',
|
|
91
|
-
product: product.key,
|
|
92
|
-
lookupKey: key,
|
|
93
|
-
quantity: args.quantity ?? 1,
|
|
94
|
-
trialDays: subscribing ? (args.trialDays ?? null) : null,
|
|
95
|
-
terms: args.terms ?? false,
|
|
96
|
-
promotionCodes: args.promotionCodes ?? false,
|
|
97
|
-
successUrl: args.successUrl,
|
|
98
|
-
cancelUrl: args.cancelUrl,
|
|
99
|
-
metadata: args.metadata ?? {},
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* The payer's subscription a deep link is about, or `NOT_SUBSCRIBED`; the
|
|
105
|
-
* code names one with `option` when the payer has several.
|
|
106
|
-
*/
|
|
107
|
-
async function subscriptionOf(model, payer, id, option) {
|
|
108
|
-
const where = {
|
|
109
|
-
payer: { is: { id: payer.id } },
|
|
110
|
-
status: { in: liveStatuses },
|
|
111
|
-
...(id === undefined ? {} : { id }),
|
|
112
|
-
};
|
|
113
|
-
const live = await model.queries.findMany({ where, take: 2 }, M);
|
|
114
|
-
const [one, other] = live;
|
|
115
|
-
if (one === undefined) {
|
|
116
|
-
throw new PublicError('NOT_SUBSCRIBED', 'The payer has no subscription.');
|
|
117
|
-
}
|
|
118
|
-
if (other !== undefined) {
|
|
119
|
-
throw new Refused(`stripe.portal: the payer has several live subscriptions; name the one with ${option}, a ${model.name} row’s id.`);
|
|
120
|
-
}
|
|
121
|
-
return one;
|
|
122
|
-
}
|
|
123
|
-
/** The portal's flow for the arguments. */
|
|
124
|
-
async function flowOf(running, model, args) {
|
|
125
|
-
const { change, cancel } = args;
|
|
126
|
-
if (change !== undefined && cancel !== undefined) {
|
|
127
|
-
throw new TypeError('stripe.portal takes change or cancel, not both.');
|
|
128
|
-
}
|
|
129
|
-
if (change !== undefined) {
|
|
130
|
-
const product = catalogued(running, change.product);
|
|
131
|
-
const lookup = lookupKey(product, change.price);
|
|
132
|
-
const row = await subscriptionOf(model, args.payer, change.subscription, 'change.subscription');
|
|
133
|
-
const subscriptionId = String(row['stripeId']);
|
|
134
|
-
return { kind: 'change', subscriptionId, lookupKey: lookup };
|
|
135
|
-
}
|
|
136
|
-
if (cancel !== undefined) {
|
|
137
|
-
const row = await subscriptionOf(model, args.payer, cancel.subscription, 'cancel.subscription');
|
|
138
|
-
return { kind: 'cancel', subscriptionId: String(row['stripeId']) };
|
|
139
|
-
}
|
|
140
|
-
return { kind: 'home' };
|
|
141
|
-
}
|
|
142
|
-
/** Opens the payer's customer portal, or one change's confirmation. */
|
|
143
|
-
export async function portal(args) {
|
|
144
|
-
const running = runningOf('stripe.portal');
|
|
145
|
-
const { gateway } = stripeOf('stripe.portal');
|
|
146
|
-
const model = running.subscription;
|
|
147
|
-
if (model === undefined) {
|
|
148
|
-
throw new Error('stripe.portal needs a model defineSubscription returned.');
|
|
149
|
-
}
|
|
150
|
-
const flow = await flowOf(running, model, args);
|
|
151
|
-
running.portal ??= (await gateway.readCatalog()).portal?.id ?? null;
|
|
152
|
-
const configuration = running.portal;
|
|
153
|
-
const returnUrl = args.returnUrl ?? running.catalog.portal.returnUrl;
|
|
154
|
-
return withCustomer(model, args.payer, async (_, customerId) => gateway.openPortal({ customerId, configuration, returnUrl, flow }));
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Syncs the payer's Checkout `sessionId` when the client comes back, without
|
|
158
|
-
* waiting for the webhook; `NOT_FOUND` for another payer's.
|
|
159
|
-
*/
|
|
160
|
-
export async function syncCheckout(sessionId, payer) {
|
|
161
|
-
const { gateway } = stripeOf('stripe.syncCheckout');
|
|
162
|
-
const customerId = await gateway.checkoutCustomer(sessionId);
|
|
163
|
-
const row = customerId === null
|
|
164
|
-
? null
|
|
165
|
-
: await StripeCustomer.findUnique({ where: { stripeId: customerId } }, M);
|
|
166
|
-
if (row === null || row.payer !== payer.id) {
|
|
167
|
-
throw new PublicError('NOT_FOUND', 'No Checkout of the payer matches.');
|
|
168
|
-
}
|
|
169
|
-
await syncCustomer(row.id);
|
|
170
|
-
}
|
|
171
|
-
/** The running plugin, from the application's functions (D-371 point 3). */
|
|
172
|
-
export const stripe = { checkout, portal, syncCheckout, grant, spend };
|
package/dist/catalog.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type CatalogState, type ProductWrite, type Recurring, type StripeGateway, type StripePrice, type StripeProduct } from './gateway.ts';
|
|
2
|
-
import { type PortalOptions } from './portal.ts';
|
|
3
|
-
import type { Every, Product } from './product.ts';
|
|
4
|
-
/** What an application sells, and how its payers manage it. */
|
|
5
|
-
export interface Catalog {
|
|
6
|
-
/** Every price's currency, in lowercase: `eur`. */
|
|
7
|
-
readonly currency: string;
|
|
8
|
-
/** Whether the amounts include the taxes. */
|
|
9
|
-
readonly taxBehavior: 'inclusive' | 'exclusive';
|
|
10
|
-
readonly products: readonly Product[];
|
|
11
|
-
readonly portal: PortalOptions;
|
|
12
|
-
}
|
|
13
|
-
/** A price as the catalog wants it. */
|
|
14
|
-
export interface WantedPrice {
|
|
15
|
-
/** Its product's key. */
|
|
16
|
-
readonly product: string;
|
|
17
|
-
readonly lookupKey: string;
|
|
18
|
-
readonly amount: number;
|
|
19
|
-
/** `null` for a one-time price. */
|
|
20
|
-
readonly recurring: Recurring<Every> | null;
|
|
21
|
-
readonly metadata: Readonly<Record<string, string>>;
|
|
22
|
-
}
|
|
23
|
-
/** One change to the catalog. */
|
|
24
|
-
export type CatalogStep = {
|
|
25
|
-
readonly kind: 'createProduct';
|
|
26
|
-
readonly product: ProductWrite;
|
|
27
|
-
} | {
|
|
28
|
-
readonly kind: 'updateProduct';
|
|
29
|
-
readonly product: ProductWrite;
|
|
30
|
-
readonly was: StripeProduct;
|
|
31
|
-
} | {
|
|
32
|
-
readonly kind: 'archiveProduct';
|
|
33
|
-
readonly was: StripeProduct;
|
|
34
|
-
} | {
|
|
35
|
-
readonly kind: 'createPrice';
|
|
36
|
-
readonly price: WantedPrice;
|
|
37
|
-
/** The price whose lookup key it takes over, archived after. */
|
|
38
|
-
readonly replaces: StripePrice | null;
|
|
39
|
-
} | {
|
|
40
|
-
readonly kind: 'updatePrice';
|
|
41
|
-
readonly price: WantedPrice;
|
|
42
|
-
readonly was: StripePrice;
|
|
43
|
-
} | {
|
|
44
|
-
readonly kind: 'archivePrice';
|
|
45
|
-
readonly was: StripePrice;
|
|
46
|
-
} | {
|
|
47
|
-
readonly kind: 'savePortal';
|
|
48
|
-
readonly id: string | null;
|
|
49
|
-
};
|
|
50
|
-
/** The changes that bring `state` to `catalog`, in order. */
|
|
51
|
-
export declare const planCatalog: (catalog: Catalog, state: CatalogState) => CatalogStep[];
|
|
52
|
-
/** Applies `steps`, planned from `state`, through `gateway`. */
|
|
53
|
-
export declare const applyCatalog: (catalog: Catalog, gateway: StripeGateway, state: CatalogState, steps: readonly CatalogStep[]) => Promise<void>;
|
|
54
|
-
//# sourceMappingURL=catalog.d.ts.map
|
package/dist/catalog.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAElB,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