@crvouga/mockingbird-service-stripe 0.1.0
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 +254 -0
- package/dist/account.d.ts +8 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +13 -0
- package/dist/account.js.map +1 -0
- package/dist/charges.d.ts +4 -0
- package/dist/charges.d.ts.map +1 -0
- package/dist/charges.js +89 -0
- package/dist/charges.js.map +1 -0
- package/dist/checkout-sessions.d.ts +5 -0
- package/dist/checkout-sessions.d.ts.map +1 -0
- package/dist/checkout-sessions.js +303 -0
- package/dist/checkout-sessions.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +1 -0
- package/dist/coupons.d.ts +4 -0
- package/dist/coupons.d.ts.map +1 -0
- package/dist/coupons.js +158 -0
- package/dist/coupons.js.map +1 -0
- package/dist/customers.d.ts +4 -0
- package/dist/customers.d.ts.map +1 -0
- package/dist/customers.js +218 -0
- package/dist/customers.js.map +1 -0
- package/dist/disputes.d.ts +4 -0
- package/dist/disputes.d.ts.map +1 -0
- package/dist/disputes.js +36 -0
- package/dist/disputes.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +74 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +4 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +76 -0
- package/dist/events.js.map +1 -0
- package/dist/expand.d.ts +11 -0
- package/dist/expand.d.ts.map +1 -0
- package/dist/expand.js +45 -0
- package/dist/expand.js.map +1 -0
- package/dist/fields.d.ts +25 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +117 -0
- package/dist/fields.js.map +1 -0
- package/dist/generated/openapi.d.ts +7 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +5 -0
- package/dist/generated/openapi.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +134 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +460 -0
- package/dist/internal.js.map +1 -0
- package/dist/invoice-items.d.ts +4 -0
- package/dist/invoice-items.d.ts.map +1 -0
- package/dist/invoice-items.js +179 -0
- package/dist/invoice-items.js.map +1 -0
- package/dist/invoices.d.ts +4 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +312 -0
- package/dist/invoices.js.map +1 -0
- package/dist/list.d.ts +24 -0
- package/dist/list.d.ts.map +1 -0
- package/dist/list.js +68 -0
- package/dist/list.js.map +1 -0
- package/dist/params.d.ts +29 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/params.js +165 -0
- package/dist/params.js.map +1 -0
- package/dist/payment-intents.d.ts +4 -0
- package/dist/payment-intents.d.ts.map +1 -0
- package/dist/payment-intents.js +232 -0
- package/dist/payment-intents.js.map +1 -0
- package/dist/payment-methods.d.ts +4 -0
- package/dist/payment-methods.d.ts.map +1 -0
- package/dist/payment-methods.js +99 -0
- package/dist/payment-methods.js.map +1 -0
- package/dist/prices.d.ts +4 -0
- package/dist/prices.d.ts.map +1 -0
- package/dist/prices.js +176 -0
- package/dist/prices.js.map +1 -0
- package/dist/products.d.ts +6 -0
- package/dist/products.d.ts.map +1 -0
- package/dist/products.js +202 -0
- package/dist/products.js.map +1 -0
- package/dist/promotion-codes.d.ts +4 -0
- package/dist/promotion-codes.d.ts.map +1 -0
- package/dist/promotion-codes.js +193 -0
- package/dist/promotion-codes.js.map +1 -0
- package/dist/qa-corpus.d.ts +26 -0
- package/dist/qa-corpus.d.ts.map +1 -0
- package/dist/qa-corpus.js +42 -0
- package/dist/qa-corpus.js.map +1 -0
- package/dist/refunds.d.ts +4 -0
- package/dist/refunds.d.ts.map +1 -0
- package/dist/refunds.js +125 -0
- package/dist/refunds.js.map +1 -0
- package/dist/render.d.ts +60 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +426 -0
- package/dist/render.js.map +1 -0
- package/dist/reshape-qa.d.ts +8 -0
- package/dist/reshape-qa.d.ts.map +1 -0
- package/dist/reshape-qa.js +102 -0
- package/dist/reshape-qa.js.map +1 -0
- package/dist/search.d.ts +32 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +64 -0
- package/dist/search.js.map +1 -0
- package/dist/setup-intents.d.ts +4 -0
- package/dist/setup-intents.d.ts.map +1 -0
- package/dist/setup-intents.js +129 -0
- package/dist/setup-intents.js.map +1 -0
- package/dist/state.d.ts +485 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +143 -0
- package/dist/state.js.map +1 -0
- package/dist/subscription-schedules.d.ts +4 -0
- package/dist/subscription-schedules.d.ts.map +1 -0
- package/dist/subscription-schedules.js +122 -0
- package/dist/subscription-schedules.js.map +1 -0
- package/dist/subscriptions.d.ts +23 -0
- package/dist/subscriptions.d.ts.map +1 -0
- package/dist/subscriptions.js +260 -0
- package/dist/subscriptions.js.map +1 -0
- package/dist/test-tokens.d.ts +27 -0
- package/dist/test-tokens.d.ts.map +1 -0
- package/dist/test-tokens.js +61 -0
- package/dist/test-tokens.js.map +1 -0
- package/dist/url.d.ts +6 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +38 -0
- package/dist/url.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { jsonResponse, opaqueToken } from "@crvouga/mockingbird-service";
|
|
2
|
+
import { parameterMissing, resourceMissing } from "./errors.js";
|
|
3
|
+
import { applyExpand } from "./expand.js";
|
|
4
|
+
import { mergeMetadata, optionalString, strippedString, validateEmail } from "./fields.js";
|
|
5
|
+
import { applyBalanceTransaction, requestScope, requireLiveCustomer, } from "./internal.js";
|
|
6
|
+
import { matchesCreated, paginate } from "./list.js";
|
|
7
|
+
import { bodyParams, queryParams } from "./params.js";
|
|
8
|
+
import { renderCustomer, renderCustomerBalanceTransaction, renderDeletedCustomer, renderPaymentMethod, } from "./render.js";
|
|
9
|
+
import { searchRecords } from "./search.js";
|
|
10
|
+
import { seconds, } from "./state.js";
|
|
11
|
+
const ADDRESS_KEYS = ["city", "country", "line1", "line2", "postal_code", "state"];
|
|
12
|
+
/** Stripe's account currency in test mode; a customer picks it up once a balance is set. */
|
|
13
|
+
const ACCOUNT_CURRENCY = "usd";
|
|
14
|
+
const toAddress = (raw) => {
|
|
15
|
+
const input = raw;
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const key of ADDRESS_KEYS) {
|
|
18
|
+
const value = input[key];
|
|
19
|
+
out[key] = value === undefined ? null : value;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
};
|
|
23
|
+
const apply = (current, params) => {
|
|
24
|
+
const next = { ...current, invoice_settings: { ...current.invoice_settings } };
|
|
25
|
+
if (params.address !== undefined)
|
|
26
|
+
next.address = params.address === "" ? null : toAddress(params.address);
|
|
27
|
+
if (params.balance !== undefined) {
|
|
28
|
+
next.balance = params.balance;
|
|
29
|
+
if (next.balance !== 0)
|
|
30
|
+
next.currency = ACCOUNT_CURRENCY;
|
|
31
|
+
}
|
|
32
|
+
next.description = optionalString(params, "description", current.description);
|
|
33
|
+
const email = optionalString(params, "email", current.email);
|
|
34
|
+
next.email = email === null ? null : validateEmail(email);
|
|
35
|
+
next.name = strippedString(params, "name", current.name);
|
|
36
|
+
next.phone = strippedString(params, "phone", current.phone);
|
|
37
|
+
next.metadata = mergeMetadata(current.metadata, params.metadata);
|
|
38
|
+
if (params.preferred_locales !== undefined)
|
|
39
|
+
next.preferred_locales = params.preferred_locales;
|
|
40
|
+
if (params.shipping !== undefined) {
|
|
41
|
+
if (params.shipping === "")
|
|
42
|
+
next.shipping = null;
|
|
43
|
+
else {
|
|
44
|
+
const shipping = params.shipping;
|
|
45
|
+
next.shipping = {
|
|
46
|
+
address: toAddress(shipping.address),
|
|
47
|
+
name: shipping.name,
|
|
48
|
+
phone: shipping.phone === undefined ? null : shipping.phone,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (params.tax_exempt !== undefined) {
|
|
53
|
+
next.tax_exempt =
|
|
54
|
+
params.tax_exempt === "" ? "none" : params.tax_exempt;
|
|
55
|
+
}
|
|
56
|
+
if (params.invoice_settings !== undefined) {
|
|
57
|
+
const settings = params.invoice_settings;
|
|
58
|
+
if (settings.custom_fields !== undefined) {
|
|
59
|
+
next.invoice_settings.custom_fields =
|
|
60
|
+
settings.custom_fields === ""
|
|
61
|
+
? []
|
|
62
|
+
: settings.custom_fields;
|
|
63
|
+
}
|
|
64
|
+
if (settings.default_payment_method !== undefined)
|
|
65
|
+
next.invoice_settings.default_payment_method =
|
|
66
|
+
settings.default_payment_method === "" ? null : String(settings.default_payment_method);
|
|
67
|
+
if (settings.footer !== undefined)
|
|
68
|
+
next.invoice_settings.footer = settings.footer === "" ? null : settings.footer;
|
|
69
|
+
}
|
|
70
|
+
return next;
|
|
71
|
+
};
|
|
72
|
+
/** Expansion table covering both the bare and the list-envelope spelling of the path. */
|
|
73
|
+
const expanders = (scope) => {
|
|
74
|
+
const defaultPaymentMethod = (id) => {
|
|
75
|
+
const method = scope.account.paymentMethods.get(id);
|
|
76
|
+
return method ? renderPaymentMethod(method) : undefined;
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
"invoice_settings.default_payment_method": defaultPaymentMethod,
|
|
80
|
+
"data.invoice_settings.default_payment_method": defaultPaymentMethod,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
export const customerHandlers = (services) => {
|
|
84
|
+
const render = (scope, customer, params) => applyExpand(renderCustomer(customer), params.expand, expanders(scope));
|
|
85
|
+
return {
|
|
86
|
+
PostCustomers: async (context) => {
|
|
87
|
+
const scope = requestScope(services, context);
|
|
88
|
+
const params = bodyParams(context);
|
|
89
|
+
const id = scope.ids.next("cus_");
|
|
90
|
+
const base = {
|
|
91
|
+
id,
|
|
92
|
+
address: null,
|
|
93
|
+
balance: 0,
|
|
94
|
+
created: seconds(scope.now),
|
|
95
|
+
currency: null,
|
|
96
|
+
description: null,
|
|
97
|
+
email: null,
|
|
98
|
+
invoice_prefix: opaqueToken(`invoice-prefix:${id}`, 8).toUpperCase(),
|
|
99
|
+
invoice_settings: {
|
|
100
|
+
custom_fields: null,
|
|
101
|
+
default_payment_method: null,
|
|
102
|
+
footer: null,
|
|
103
|
+
rendering_options: null,
|
|
104
|
+
},
|
|
105
|
+
metadata: {},
|
|
106
|
+
name: null,
|
|
107
|
+
phone: null,
|
|
108
|
+
preferred_locales: [],
|
|
109
|
+
shipping: null,
|
|
110
|
+
tax_exempt: "none",
|
|
111
|
+
};
|
|
112
|
+
const customer = apply(base, params);
|
|
113
|
+
scope.account.customers.insert(id, { kind: "live", customer });
|
|
114
|
+
scope.emit("customer.created", renderCustomer(customer));
|
|
115
|
+
return jsonResponse(200, render(scope, customer, params));
|
|
116
|
+
},
|
|
117
|
+
GetCustomers: async (context) => {
|
|
118
|
+
const scope = requestScope(services, context);
|
|
119
|
+
const params = queryParams(context);
|
|
120
|
+
const email = params.email;
|
|
121
|
+
const page = await paginate(scope.account.customers, params, {
|
|
122
|
+
url: "/v1/customers",
|
|
123
|
+
kind: "customer",
|
|
124
|
+
exists: (entry) => entry.kind === "live",
|
|
125
|
+
where: (entry) => entry.kind === "live" &&
|
|
126
|
+
matchesCreated(entry.customer.created, params.created) &&
|
|
127
|
+
(email === undefined || email === "" || entry.customer.email === email),
|
|
128
|
+
render: (entry) => (entry.kind === "live" ? renderCustomer(entry.customer) : undefined),
|
|
129
|
+
});
|
|
130
|
+
return jsonResponse(200, applyExpand(page, params.expand, expanders(scope)));
|
|
131
|
+
},
|
|
132
|
+
GetCustomersSearch: async (context) => {
|
|
133
|
+
const scope = requestScope(services, context);
|
|
134
|
+
const params = queryParams(context);
|
|
135
|
+
const records = scope.account.customers
|
|
136
|
+
.list({ order: "newest" })
|
|
137
|
+
.map((entry) => entry.value)
|
|
138
|
+
.flatMap((entry) => (entry.kind === "live" ? [entry.customer] : []));
|
|
139
|
+
return jsonResponse(200, searchRecords(records, params, {
|
|
140
|
+
url: "/v1/customers/search",
|
|
141
|
+
render: renderCustomer,
|
|
142
|
+
}));
|
|
143
|
+
},
|
|
144
|
+
GetCustomersCustomer: async (context) => {
|
|
145
|
+
const scope = requestScope(services, context);
|
|
146
|
+
const params = queryParams(context);
|
|
147
|
+
const id = context.params.customer ?? "";
|
|
148
|
+
const entry = scope.account.customers.get(id);
|
|
149
|
+
if (!entry)
|
|
150
|
+
throw resourceMissing("customer", id, "id");
|
|
151
|
+
return jsonResponse(200, entry.kind === "deleted"
|
|
152
|
+
? renderDeletedCustomer(id)
|
|
153
|
+
: render(scope, entry.customer, params));
|
|
154
|
+
},
|
|
155
|
+
PostCustomersCustomer: async (context) => {
|
|
156
|
+
const scope = requestScope(services, context);
|
|
157
|
+
const params = bodyParams(context);
|
|
158
|
+
const id = context.params.customer ?? "";
|
|
159
|
+
const entry = scope.account.customers.get(id);
|
|
160
|
+
if (!entry || entry.kind === "deleted")
|
|
161
|
+
throw resourceMissing("customer", id, "id", entry?.kind === "deleted" ? 400 : 404);
|
|
162
|
+
const customer = apply(entry.customer, params);
|
|
163
|
+
scope.account.customers.update(id, { kind: "live", customer });
|
|
164
|
+
scope.emit("customer.updated", renderCustomer(customer));
|
|
165
|
+
return jsonResponse(200, render(scope, customer, params));
|
|
166
|
+
},
|
|
167
|
+
DeleteCustomersCustomer: async (context) => {
|
|
168
|
+
const scope = requestScope(services, context);
|
|
169
|
+
const id = context.params.customer ?? "";
|
|
170
|
+
const entry = scope.account.customers.get(id);
|
|
171
|
+
if (!entry || entry.kind === "deleted")
|
|
172
|
+
throw resourceMissing("customer", id, "id");
|
|
173
|
+
scope.account.customers.update(id, { kind: "deleted", id });
|
|
174
|
+
scope.emit("customer.deleted", renderDeletedCustomer(id));
|
|
175
|
+
return jsonResponse(200, renderDeletedCustomer(id));
|
|
176
|
+
},
|
|
177
|
+
GetCustomersCustomerBalanceTransactions: async (context) => {
|
|
178
|
+
const scope = requestScope(services, context);
|
|
179
|
+
const params = queryParams(context);
|
|
180
|
+
const id = context.params.customer ?? "";
|
|
181
|
+
requireLiveCustomer(scope, id, "customer");
|
|
182
|
+
const page = await paginate(scope.account.balanceTransactions, params, {
|
|
183
|
+
url: `/v1/customers/${id}/balance_transactions`,
|
|
184
|
+
kind: "customer_balance_transaction",
|
|
185
|
+
where: (record) => record.customer === id && matchesCreated(record.created, params.created),
|
|
186
|
+
render: renderCustomerBalanceTransaction,
|
|
187
|
+
});
|
|
188
|
+
return jsonResponse(200, page);
|
|
189
|
+
},
|
|
190
|
+
PostCustomersCustomerBalanceTransactions: async (context) => {
|
|
191
|
+
const scope = requestScope(services, context);
|
|
192
|
+
const params = bodyParams(context);
|
|
193
|
+
const id = context.params.customer ?? "";
|
|
194
|
+
const customer = requireLiveCustomer(scope, id, "customer");
|
|
195
|
+
const amount = typeof params.amount === "number" ? params.amount : undefined;
|
|
196
|
+
if (amount === undefined)
|
|
197
|
+
throw parameterMissing("amount");
|
|
198
|
+
const currency = typeof params.currency === "string" && params.currency !== ""
|
|
199
|
+
? params.currency
|
|
200
|
+
: (customer.currency ?? ACCOUNT_CURRENCY);
|
|
201
|
+
const description = typeof params.description === "string" ? params.description : null;
|
|
202
|
+
const metadata = params.metadata ?? {};
|
|
203
|
+
const { id: transactionId } = applyBalanceTransaction(scope, {
|
|
204
|
+
customer,
|
|
205
|
+
amount,
|
|
206
|
+
currency,
|
|
207
|
+
description,
|
|
208
|
+
metadata,
|
|
209
|
+
type: "adjustment",
|
|
210
|
+
});
|
|
211
|
+
const transaction = scope.account.balanceTransactions.get(transactionId);
|
|
212
|
+
if (!transaction)
|
|
213
|
+
throw resourceMissing("customer_balance_transaction", transactionId, "transaction");
|
|
214
|
+
return jsonResponse(200, renderCustomerBalanceTransaction(transaction));
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
//# sourceMappingURL=customers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.js","sourceRoot":"","sources":["../src/customers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAC/F,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAwB,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC1F,OAAO,EACL,uBAAuB,EAEvB,YAAY,EACZ,mBAAmB,GAEpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,UAAU,EAAe,WAAW,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EACL,cAAc,EACd,gCAAgC,EAChC,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAKL,OAAO,GACR,MAAM,YAAY,CAAA;AAEnB,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAU,CAAA;AAE3F,4FAA4F;AAC5F,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAE9B,MAAM,SAAS,GAAG,CAAC,GAAY,EAAW,EAAE;IAC1C,MAAM,KAAK,GAAG,GAAyC,CAAA;IACvD,MAAM,GAAG,GAAG,EAA0D,CAAA;IACtE,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,MAAM,KAAK,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ceRoot":"","sources":["../src/disputes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAElF,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AAW3D,eAAO,MAAM,eAAe,GAAI,UAAU,QAAQ,KAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAwBlF,CAAA"}
|
package/dist/disputes.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsonResponse } from "@crvouga/mockingbird-service";
|
|
2
|
+
import { resourceMissing } from "./errors.js";
|
|
3
|
+
import { requestScope } from "./internal.js";
|
|
4
|
+
import { matchesCreated, paginate } from "./list.js";
|
|
5
|
+
import { queryParams } from "./params.js";
|
|
6
|
+
import { renderDispute } from "./render.js";
|
|
7
|
+
const stringOf = (params, key) => {
|
|
8
|
+
const value = params[key];
|
|
9
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
10
|
+
};
|
|
11
|
+
export const disputeHandlers = (services) => ({
|
|
12
|
+
GetDisputes: async (context) => {
|
|
13
|
+
const scope = requestScope(services, context);
|
|
14
|
+
const params = queryParams(context);
|
|
15
|
+
const charge = stringOf(params, "charge");
|
|
16
|
+
const paymentIntent = stringOf(params, "payment_intent");
|
|
17
|
+
const page = await paginate(scope.account.disputes, params, {
|
|
18
|
+
url: "/v1/disputes",
|
|
19
|
+
kind: "dispute",
|
|
20
|
+
where: (record) => matchesCreated(record.created, params.created) &&
|
|
21
|
+
(charge === null || record.charge === charge) &&
|
|
22
|
+
(paymentIntent === null || record.payment_intent === paymentIntent),
|
|
23
|
+
render: renderDispute,
|
|
24
|
+
});
|
|
25
|
+
return jsonResponse(200, page);
|
|
26
|
+
},
|
|
27
|
+
GetDisputesDispute: async (context) => {
|
|
28
|
+
const scope = requestScope(services, context);
|
|
29
|
+
const id = context.params.dispute ?? "";
|
|
30
|
+
const dispute = scope.account.disputes.get(id);
|
|
31
|
+
if (!dispute)
|
|
32
|
+
throw resourceMissing("dispute", id, "dispute");
|
|
33
|
+
return jsonResponse(200, renderDispute(dispute));
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=disputes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disputes.js","sourceRoot":"","sources":["../src/disputes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAe,WAAW,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,GAAW,EAAiB,EAAE;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AACjE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAoC,EAAE,CAAC,CAAC;IACxF,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAC7B,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC7C,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;QACnC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QACzC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;QACxD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAgB,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE;YACzE,GAAG,EAAE,cAAc;YACnB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAChB,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;gBAC9C,CAAC,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC;gBAC7C,CAAC,aAAa,KAAK,IAAI,IAAI,MAAM,CAAC,cAAc,KAAK,aAAa,CAAC;YACrE,MAAM,EAAE,aAAa;SACtB,CAAC,CAAA;QACF,OAAO,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAChC,CAAC;IACD,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACpC,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAC7C,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAA;QACvC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC9C,IAAI,CAAC,OAAO;YAAE,MAAM,eAAe,CAAC,SAAS,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;QAC7D,OAAO,YAAY,CAAC,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IAClD,CAAC;CACF,CAAC,CAAA"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HttpError } from "@crvouga/mockingbird-service";
|
|
2
|
+
export type StripeErrorType = "invalid_request_error" | "card_error" | "api_error" | "authentication_error";
|
|
3
|
+
export type StripeErrorInit = {
|
|
4
|
+
status: number;
|
|
5
|
+
message: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
param?: string;
|
|
8
|
+
type?: StripeErrorType;
|
|
9
|
+
decline_code?: string;
|
|
10
|
+
};
|
|
11
|
+
/** Stripe serialises error bodies with keys in alphabetical order. */
|
|
12
|
+
export declare const stripeErrorBody: (init: StripeErrorInit, requestLogUrl: string) => {
|
|
13
|
+
error: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
export declare class StripeError extends HttpError {
|
|
16
|
+
readonly init: StripeErrorInit;
|
|
17
|
+
constructor(init: StripeErrorInit);
|
|
18
|
+
}
|
|
19
|
+
export declare const invalidRequest: (message: string, param?: string, code?: string) => StripeError;
|
|
20
|
+
/** Declines answer 402 with `type: "card_error"`, exactly like a real declined charge. */
|
|
21
|
+
export declare const cardError: (message: string, code: string, declineCode: string, param?: string) => StripeError;
|
|
22
|
+
export declare const resourceMissing: (kind: string, id: string, param: string, status?: number) => StripeError;
|
|
23
|
+
export declare const parameterUnknown: (param: string) => StripeError;
|
|
24
|
+
export declare const parameterMissing: (param: string) => StripeError;
|
|
25
|
+
export declare const parameterInvalidInteger: (param: string, raw: string) => StripeError;
|
|
26
|
+
export declare const parameterInvalidEmpty: (param: string) => StripeError;
|
|
27
|
+
/** Stripe lists alternatives as "a, b, or c" (or "a or b"). */
|
|
28
|
+
export declare const humanList: (items: string[]) => string;
|
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAExD,MAAM,MAAM,eAAe,GACvB,uBAAuB,GACvB,YAAY,GACZ,WAAW,GACX,sBAAsB,CAAA;AAE1B,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,eAAe,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAKD,sEAAsE;AACtE,eAAO,MAAM,eAAe,GAAI,MAAM,eAAe,EAAE,eAAe,MAAM;;CAY3E,CAAA;AAED,qBAAa,WAAY,SAAQ,SAAS;IAC5B,QAAQ,CAAC,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe;CAI3C;AAED,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,QAAQ,MAAM,EAAE,OAAO,MAAM,gBAMzE,CAAA;AAEJ,0FAA0F;AAC1F,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,EAAE,MAAM,MAAM,EAAE,aAAa,MAAM,EAAE,QAAQ,MAAM,gBAQxF,CAAA;AAEJ,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,IAAI,MAAM,EAAE,OAAO,MAAM,EAAE,eAAY,gBACc,CAAA;AAEnG,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,gBAM1C,CAAA;AAEJ,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,gBAM1C,CAAA;AAEJ,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,gBAM9D,CAAA;AAEJ,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,gBAM/C,CAAA;AAEJ,+DAA+D;AAC/D,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,WAKgC,CAAA"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { HttpError } from "@crvouga/mockingbird-service";
|
|
2
|
+
/** Codes that Stripe documents; these carry a `doc_url`. */
|
|
3
|
+
const docUrl = (code) => `https://stripe.com/docs/error-codes/${code.replace(/_/g, "-")}`;
|
|
4
|
+
/** Stripe serialises error bodies with keys in alphabetical order. */
|
|
5
|
+
export const stripeErrorBody = (init, requestLogUrl) => {
|
|
6
|
+
const error = {};
|
|
7
|
+
if (init.code !== undefined) {
|
|
8
|
+
error.code = init.code;
|
|
9
|
+
error.doc_url = docUrl(init.code);
|
|
10
|
+
}
|
|
11
|
+
if (init.decline_code !== undefined)
|
|
12
|
+
error.decline_code = init.decline_code;
|
|
13
|
+
error.message = init.message;
|
|
14
|
+
if (init.param !== undefined)
|
|
15
|
+
error.param = init.param;
|
|
16
|
+
error.request_log_url = requestLogUrl;
|
|
17
|
+
error.type = init.type ?? "invalid_request_error";
|
|
18
|
+
return { error };
|
|
19
|
+
};
|
|
20
|
+
export class StripeError extends HttpError {
|
|
21
|
+
init;
|
|
22
|
+
constructor(init) {
|
|
23
|
+
super(init.status, undefined);
|
|
24
|
+
this.init = init;
|
|
25
|
+
this.name = "StripeError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const invalidRequest = (message, param, code) => new StripeError({
|
|
29
|
+
status: 400,
|
|
30
|
+
message,
|
|
31
|
+
...(param === undefined ? {} : { param }),
|
|
32
|
+
...(code === undefined ? {} : { code }),
|
|
33
|
+
});
|
|
34
|
+
/** Declines answer 402 with `type: "card_error"`, exactly like a real declined charge. */
|
|
35
|
+
export const cardError = (message, code, declineCode, param) => new StripeError({
|
|
36
|
+
status: 402,
|
|
37
|
+
message,
|
|
38
|
+
code,
|
|
39
|
+
decline_code: declineCode,
|
|
40
|
+
type: "card_error",
|
|
41
|
+
...(param === undefined ? {} : { param }),
|
|
42
|
+
});
|
|
43
|
+
export const resourceMissing = (kind, id, param, status = 404) => new StripeError({ status, code: "resource_missing", message: `No such ${kind}: '${id}'`, param });
|
|
44
|
+
export const parameterUnknown = (param) => new StripeError({
|
|
45
|
+
status: 400,
|
|
46
|
+
code: "parameter_unknown",
|
|
47
|
+
message: `Received unknown parameter: ${param}`,
|
|
48
|
+
param,
|
|
49
|
+
});
|
|
50
|
+
export const parameterMissing = (param) => new StripeError({
|
|
51
|
+
status: 400,
|
|
52
|
+
code: "parameter_missing",
|
|
53
|
+
message: `Missing required param: ${param}.`,
|
|
54
|
+
param,
|
|
55
|
+
});
|
|
56
|
+
export const parameterInvalidInteger = (param, raw) => new StripeError({
|
|
57
|
+
status: 400,
|
|
58
|
+
code: "parameter_invalid_integer",
|
|
59
|
+
message: `Invalid integer: ${raw}`,
|
|
60
|
+
param,
|
|
61
|
+
});
|
|
62
|
+
export const parameterInvalidEmpty = (param) => new StripeError({
|
|
63
|
+
status: 400,
|
|
64
|
+
code: "parameter_invalid_empty",
|
|
65
|
+
message: `You passed an empty string for '${param}'. We assume empty values are an attempt to unset a parameter; however '${param}' cannot be unset. You should remove '${param}' from your request or supply a non-empty value.`,
|
|
66
|
+
param,
|
|
67
|
+
});
|
|
68
|
+
/** Stripe lists alternatives as "a, b, or c" (or "a or b"). */
|
|
69
|
+
export const humanList = (items) => items.length <= 1
|
|
70
|
+
? (items[0] ?? "")
|
|
71
|
+
: items.length === 2
|
|
72
|
+
? `${items[0]} or ${items[1]}`
|
|
73
|
+
: `${items.slice(0, -1).join(", ")}, or ${items[items.length - 1]}`;
|
|
74
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAiBxD,4DAA4D;AAC5D,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,uCAAuC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAA;AAEjG,sEAAsE;AACtE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAqB,EAAE,aAAqB,EAAE,EAAE;IAC9E,MAAM,KAAK,GAA2B,EAAE,CAAA;IACxC,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACtB,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IACD,IA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AC/D,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAe,EAAE,EAAE,CAC3C,KAAK,CAAC,MAAM,IAAI,CAAC;IACf,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClB,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;QAClB,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE;QAC9B,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAA"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAElF,OAAO,EAAgB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAA;AA2D3D,eAAO,MAAM,aAAa,GAAI,UAAU,QAAQ,KAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAkBhF,CAAA"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsonResponse } from "@crvouga/mockingbird-service";
|
|
2
|
+
import { invalidRequest, resourceMissing } from "./errors.js";
|
|
3
|
+
import { requestScope } from "./internal.js";
|
|
4
|
+
import { clampLimit, matchesCreated } from "./list.js";
|
|
5
|
+
import { queryParams } from "./params.js";
|
|
6
|
+
import { renderEvent } from "./render.js";
|
|
7
|
+
/**
|
|
8
|
+
* The event ledger is keyed by insertion sequence, not by `evt_` id, so cursors resolve against
|
|
9
|
+
* the record's public id rather than its storage key. `list` already returns newest first.
|
|
10
|
+
*/
|
|
11
|
+
const pageEvents = (records, params) => {
|
|
12
|
+
const startingAfter = params.starting_after;
|
|
13
|
+
const endingBefore = params.ending_before;
|
|
14
|
+
if (typeof startingAfter === "string" &&
|
|
15
|
+
startingAfter !== "" &&
|
|
16
|
+
typeof endingBefore === "string" &&
|
|
17
|
+
endingBefore !== "")
|
|
18
|
+
throw invalidRequest("Received both starting_after and ending_before parameters. Please pass in only one.");
|
|
19
|
+
const type = typeof params.type === "string" ? params.type : undefined;
|
|
20
|
+
const types = Array.isArray(params.types)
|
|
21
|
+
? params.types.filter((entry) => typeof entry === "string")
|
|
22
|
+
: [];
|
|
23
|
+
const where = (record) => matchesCreated(record.created, params.created) &&
|
|
24
|
+
(type === undefined || type === "" || record.type === type) &&
|
|
25
|
+
(types.length === 0 || types.includes(record.type));
|
|
26
|
+
const cursorIndex = (id, param) => {
|
|
27
|
+
const index = records.findIndex((record) => record.id === id);
|
|
28
|
+
if (index === -1)
|
|
29
|
+
throw resourceMissing("event", id, param, 400);
|
|
30
|
+
return index;
|
|
31
|
+
};
|
|
32
|
+
const limit = clampLimit(params.limit);
|
|
33
|
+
let data;
|
|
34
|
+
let hasMore;
|
|
35
|
+
if (typeof startingAfter === "string" && startingAfter !== "") {
|
|
36
|
+
const rest = records.slice(cursorIndex(startingAfter, "starting_after") + 1).filter(where);
|
|
37
|
+
data = rest.slice(0, limit);
|
|
38
|
+
hasMore = rest.length > limit;
|
|
39
|
+
}
|
|
40
|
+
else if (typeof endingBefore === "string" && endingBefore !== "") {
|
|
41
|
+
const before = records.slice(0, cursorIndex(endingBefore, "ending_before")).filter(where);
|
|
42
|
+
data = before.slice(Math.max(0, before.length - limit));
|
|
43
|
+
hasMore = before.length > limit;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const rows = records.filter(where);
|
|
47
|
+
data = rows.slice(0, limit);
|
|
48
|
+
hasMore = rows.length > limit;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
object: "list",
|
|
52
|
+
data: data.map(renderEvent),
|
|
53
|
+
has_more: hasMore,
|
|
54
|
+
url: "/v1/events",
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export const eventHandlers = (services) => ({
|
|
58
|
+
GetEvents: async (context) => {
|
|
59
|
+
const scope = requestScope(services, context);
|
|
60
|
+
const params = queryParams(context);
|
|
61
|
+
const records = scope.account.events.list({ order: "newest" }).map((entry) => entry.value);
|
|
62
|
+
return jsonResponse(200, pageEvents(records, params));
|
|
63
|
+
},
|
|
64
|
+
GetEventsId: async (context) => {
|
|
65
|
+
const scope = requestScope(services, context);
|
|
66
|
+
queryParams(context);
|
|
67
|
+
const id = context.params.id ?? "";
|
|
68
|
+
const record = scope.account.events
|
|
69
|
+
.list({ order: "newest" })
|
|
70
|
+
.find((entry) => entry.value.id === id)?.value;
|
|
71
|
+
if (!record)
|
|
72
|
+
throw resourceMissing("event", id, "id");
|
|
73
|
+
return jsonResponse(200, renderEvent(record));
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAiB,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,OAA6B,EAAE,MAA+B,EAAE,EAAE;IACpF,MAAM,aAAa,GAAG,MAAM,CAAC,cAAc,CAAA;IAC3C,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAA;IACzC,IACE,OAAO,aAA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ed by the expansion path as Stripe spells it. */
|
|
3
|
+
export type ExpandResolvers = Readonly<Record<string, Expander | undefined>>;
|
|
4
|
+
/**
|
|
5
|
+
* Replace id strings with full objects wherever `expand` names a path the caller resolves.
|
|
6
|
+
* Paths are matched literally (including a leading `data.` on list envelopes, where the walker
|
|
7
|
+
* descends into every element). Unknown paths leave the id in place, as the mock never expands
|
|
8
|
+
* anything it has not been taught.
|
|
9
|
+
*/
|
|
10
|
+
export declare const applyExpand: <T>(value: T, expand: unknown, resolvers: ExpandResolvers) => T;
|
|
11
|
+
//# sourceMappingURL=expand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../src/expand.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAA;AAE9C,yFAAyF;AACzF,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;AAsB5E;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,CAAC,EAAE,QAAQ,OAAO,EAAE,WAAW,eAAe,KAAG,CAatF,CAAA"}
|
package/dist/expand.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const expandInto = (node, parts, resolver) => {
|
|
2
|
+
if (parts.length === 0 || node === null || typeof node !== "object")
|
|
3
|
+
return;
|
|
4
|
+
if (Array.isArray(node)) {
|
|
5
|
+
for (const item of node)
|
|
6
|
+
expandInto(item, parts, resolver);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const record = node;
|
|
10
|
+
const [head, ...rest] = parts;
|
|
11
|
+
if (head === undefined)
|
|
12
|
+
return;
|
|
13
|
+
if (rest.length === 0) {
|
|
14
|
+
const current = record[head];
|
|
15
|
+
if (typeof current === "string" && current !== "") {
|
|
16
|
+
const resolved = resolver(current);
|
|
17
|
+
if (resolved !== undefined && resolved !== null)
|
|
18
|
+
record[head] = resolved;
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
expandInto(record[head], rest, resolver);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Replace id strings with full objects wherever `expand` names a path the caller resolves.
|
|
26
|
+
* Paths are matched literally (including a leading `data.` on list envelopes, where the walker
|
|
27
|
+
* descends into every element). Unknown paths leave the id in place, as the mock never expands
|
|
28
|
+
* anything it has not been taught.
|
|
29
|
+
*/
|
|
30
|
+
export const applyExpand = (value, expand, resolvers) => {
|
|
31
|
+
const requested = Array.isArray(expand)
|
|
32
|
+
? expand.filter((entry) => typeof entry === "string")
|
|
33
|
+
: typeof expand === "string" && expand !== ""
|
|
34
|
+
? [expand]
|
|
35
|
+
: [];
|
|
36
|
+
for (const entry of requested) {
|
|
37
|
+
const path = entry.replace(/\[\]$/, "");
|
|
38
|
+
const resolver = resolvers[path];
|
|
39
|
+
if (!resolver)
|
|
40
|
+
continue;
|
|
41
|
+
expandInto(value, path.split("."), resolver);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=expand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.js","sourceRoot":"","sources":["../src/expand.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,CAAC,IAAa,EAAE,KAAwB,EAAE,QAAkB,EAAQ,EAAE;IACvF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAM;IAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,IAAI;YAAE,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC1D,OAAM;IACR,CAAC;I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AAE,SAAQ;QACvB,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Params } from "./params.js";
|
|
2
|
+
/**
|
|
3
|
+
* Apply Stripe's metadata semantics: `""` clears everything, a key with `""` deletes it, other
|
|
4
|
+
* keys merge; then enforce the documented limits on the result.
|
|
5
|
+
*/
|
|
6
|
+
export declare const mergeMetadata: (current: Record<string, string>, incoming: unknown) => Record<string, string>;
|
|
7
|
+
/** Optional string: absent keeps `current`, `""` unsets to null. */
|
|
8
|
+
export declare const optionalString: (params: Params, key: string, current: string | null) => string | null;
|
|
9
|
+
/** Ruby's `String#strip`: leading and trailing ASCII whitespace and NULs. */
|
|
10
|
+
export declare const strip: (value: string) => string;
|
|
11
|
+
/** Optional string that Stripe strips: absent keeps `current`, blank unsets to null. */
|
|
12
|
+
export declare const strippedString: (params: Params, key: string, current: string | null) => string | null;
|
|
13
|
+
/** Required string: `""` is rejected because the field cannot be unset. */
|
|
14
|
+
export declare const requiredString: (params: Params, key: string, current: string) => string;
|
|
15
|
+
export declare const optionalBoolean: (params: Params, key: string, current: boolean | null) => boolean | null;
|
|
16
|
+
export declare const validateEmail: (value: string) => string;
|
|
17
|
+
export declare const validateStatementDescriptor: (value: string) => string;
|
|
18
|
+
/** Stripe echoes decimals back the way Ruby's BigDecimal#to_s prints them (`0.15e1`). */
|
|
19
|
+
export declare const rubyBigDecimal: (raw: string) => string;
|
|
20
|
+
/** Normalise a decimal string: strip trailing fraction zeros and the sign of zero. */
|
|
21
|
+
export declare const normalizeDecimal: (raw: string) => string;
|
|
22
|
+
export declare const parseUnitAmountDecimal: (raw: string, param: string) => string;
|
|
23
|
+
/** `unit_amount` is the integer view of the decimal, or null when it has a fraction. */
|
|
24
|
+
export declare const unitAmountOf: (decimal: string) => number | null;
|
|
25
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAQzC;;;GAGG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,UAAU,OAAO,KAChB,MAAM,CAAC,MAAM,EAAE,MAAM,CAsBvB,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,KAAK,MAAM,EACX,SAAS,MAAM,GAAG,IAAI,KACrB,MAAM,GAAG,IAKX,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,WAA4C,CAAA;AAE/E,wFAAwF;AACxF,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,KAAK,MAAM,EACX,SAAS,MAAM,GAAG,IAAI,KACrB,MAAM,GAAG,IAKX,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,EAAE,KAAK,MAAM,EAAE,SAAS,MAAM,KAAG,MAK7E,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,KAAK,MAAM,EACX,SAAS,OAAO,GAAG,IAAI,KACtB,OAAO,GAAG,IAGZ,CAAA;AAID,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAI1C,CAAA;AAID,eAAO,MAAM,2BAA2B,GAAI,OAAO,MAAM,WAcxD,CAAA;AAED,yFAAyF;AACzF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,WAUzC,CAAA;AAKD,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,WAQ3C,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,KAA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