@openrails/billing-ui 0.250.0 → 0.251.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/CHANGELOG.md +16 -0
- package/README.md +19 -1
- package/dist/client/generated/error-codes.d.ts +1 -1
- package/dist/client/generated/routes.d.ts +3 -3
- package/dist/client/generated/wire.d.ts +1 -0
- package/dist/client/types.d.ts +6 -0
- package/dist/{client-HWr09qpX.js → client-imFR1UCe.js} +82 -81
- package/dist/client-imFR1UCe.js.map +1 -0
- package/dist/client.js +2 -2
- package/dist/hooks-C9JkHcRt.js +553 -0
- package/dist/hooks-C9JkHcRt.js.map +1 -0
- package/dist/index.js +778 -745
- package/dist/index.js.map +1 -1
- package/dist/react/config.d.ts +12 -3
- package/dist/react/provider.d.ts +14 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/client-HWr09qpX.js.map +0 -1
- package/dist/hooks-D9MR20BY.js +0 -537
- package/dist/hooks-D9MR20BY.js.map +0 -1
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { A as e, O as t, c as n, l as r, o as i, u as a } from "./client-imFR1UCe.js";
|
|
2
|
+
import { en as o } from "./locales/en.js";
|
|
3
|
+
import { createContext as s, useCallback as c, useContext as l, useEffect as u, useMemo as d, useRef as f, useState as p, useSyncExternalStore as m } from "react";
|
|
4
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
5
|
+
//#region src/i18n/messages.ts
|
|
6
|
+
function g(e) {
|
|
7
|
+
return e;
|
|
8
|
+
}
|
|
9
|
+
var _ = o;
|
|
10
|
+
function v(e, t) {
|
|
11
|
+
let n = { ...e };
|
|
12
|
+
for (let [e, r] of Object.entries(t)) {
|
|
13
|
+
if (r == null) continue;
|
|
14
|
+
let t = n[e];
|
|
15
|
+
typeof r == "string" ? r !== "" && (n[e] = r) : n[e] = v(typeof t == "object" ? t : {}, r);
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
function y(e) {
|
|
20
|
+
let t = e ? Array.isArray(e) ? e : [e] : [], n = o;
|
|
21
|
+
for (let e of t) n = v(n, e);
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
function b(e, t) {
|
|
25
|
+
return t ? e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e) : e;
|
|
26
|
+
}
|
|
27
|
+
function x(e, t) {
|
|
28
|
+
let n = e;
|
|
29
|
+
for (let e of t.split(".")) {
|
|
30
|
+
if (!n || typeof n != "object") return;
|
|
31
|
+
n = n[e];
|
|
32
|
+
}
|
|
33
|
+
return typeof n == "string" ? n : void 0;
|
|
34
|
+
}
|
|
35
|
+
function S(e) {
|
|
36
|
+
if (typeof e == "string") return e;
|
|
37
|
+
if (e && typeof e == "object" && "code" in e) {
|
|
38
|
+
let t = e.code;
|
|
39
|
+
if (typeof t == "string") return t;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function C(e) {
|
|
43
|
+
return e instanceof TypeError && /fetch|network/i.test(e.message);
|
|
44
|
+
}
|
|
45
|
+
function w(e) {
|
|
46
|
+
try {
|
|
47
|
+
return new Intl.PluralRules(e);
|
|
48
|
+
} catch {
|
|
49
|
+
return new Intl.PluralRules("en");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function T(e, t) {
|
|
53
|
+
try {
|
|
54
|
+
return new Intl.NumberFormat(t).format(e);
|
|
55
|
+
} catch {
|
|
56
|
+
return String(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function E(e, t, n) {
|
|
60
|
+
let r = w(n), i = (n, r) => {
|
|
61
|
+
let i = t?.(n, r);
|
|
62
|
+
if (i && i !== n) return i;
|
|
63
|
+
let a = x(e, n);
|
|
64
|
+
return a === void 0 ? void 0 : b(a, r);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
messages: e,
|
|
68
|
+
locale: n,
|
|
69
|
+
t: (e, t) => i(e, t) ?? e,
|
|
70
|
+
plural(e, t, a) {
|
|
71
|
+
let o = {
|
|
72
|
+
...a,
|
|
73
|
+
count: T(t, n)
|
|
74
|
+
};
|
|
75
|
+
return i(`${e}.${t}`, o) ?? i(`${e}.${r.select(t)}`, o) ?? i(`${e}.other`, o) ?? e;
|
|
76
|
+
},
|
|
77
|
+
error(t, n) {
|
|
78
|
+
let r = S(t);
|
|
79
|
+
if (r && r !== "generic" && r !== "network") {
|
|
80
|
+
let e = t && typeof t == "object" && "metadata" in t ? t.metadata : void 0, a = i(`errors.${r}`, {
|
|
81
|
+
...e,
|
|
82
|
+
...n
|
|
83
|
+
});
|
|
84
|
+
if (a) return a;
|
|
85
|
+
}
|
|
86
|
+
let a = C(t) ? "errors.network" : "errors.generic";
|
|
87
|
+
return i(a, n) ?? e.errors.generic;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/i18n/context.ts
|
|
93
|
+
var D = s(E(_));
|
|
94
|
+
function O() {
|
|
95
|
+
return l(D);
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/appearance.ts
|
|
99
|
+
var k = {
|
|
100
|
+
background: "--background",
|
|
101
|
+
foreground: "--foreground",
|
|
102
|
+
card: "--card",
|
|
103
|
+
mutedForeground: "--muted-foreground",
|
|
104
|
+
faintForeground: "--orck-faint",
|
|
105
|
+
border: "--border",
|
|
106
|
+
input: "--input",
|
|
107
|
+
primary: "--primary",
|
|
108
|
+
primaryForeground: "--primary-foreground",
|
|
109
|
+
destructive: "--destructive",
|
|
110
|
+
ring: "--ring",
|
|
111
|
+
radius: "--radius",
|
|
112
|
+
fontFamily: "--orck-font"
|
|
113
|
+
};
|
|
114
|
+
function A(e, t = "orck") {
|
|
115
|
+
let n = e?.variables;
|
|
116
|
+
if (!n) return;
|
|
117
|
+
let r = {};
|
|
118
|
+
for (let [e, i] of Object.entries(n)) i && (r[k[e].replace("--orck-", `--${t}-`)] = i);
|
|
119
|
+
return r;
|
|
120
|
+
}
|
|
121
|
+
function j(e) {
|
|
122
|
+
return e?.theme ?? "auto";
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/scope-context.ts
|
|
126
|
+
var M = s({}), N = () => l(M);
|
|
127
|
+
function P(e) {
|
|
128
|
+
let t = N(), n = e ?? t.appearance;
|
|
129
|
+
return {
|
|
130
|
+
className: "orck",
|
|
131
|
+
"data-orck-theme": j(n),
|
|
132
|
+
style: A(n)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/react/context.ts
|
|
137
|
+
var F = s(null);
|
|
138
|
+
function I() {
|
|
139
|
+
let e = l(F);
|
|
140
|
+
if (!e) throw Error("billing-ui: wrap the tree in <BillingProvider>");
|
|
141
|
+
return e;
|
|
142
|
+
}
|
|
143
|
+
var L = () => I().client, R = () => I().refresh, z = () => l(F);
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/react/config.ts
|
|
146
|
+
function B(t, n) {
|
|
147
|
+
let r = n ?? {
|
|
148
|
+
config: null,
|
|
149
|
+
loading: !0,
|
|
150
|
+
error: null
|
|
151
|
+
}, i = n !== void 0, a = 0, o = /* @__PURE__ */ new Set(), s = (e) => {
|
|
152
|
+
r = e;
|
|
153
|
+
for (let e of o) e();
|
|
154
|
+
}, c = () => {
|
|
155
|
+
i = !0;
|
|
156
|
+
let n = ++a;
|
|
157
|
+
r.loading || s({
|
|
158
|
+
...r,
|
|
159
|
+
loading: !0
|
|
160
|
+
}), t().then((e) => {
|
|
161
|
+
n === a && s({
|
|
162
|
+
config: e,
|
|
163
|
+
loading: !1,
|
|
164
|
+
error: null
|
|
165
|
+
});
|
|
166
|
+
}, (t) => {
|
|
167
|
+
n === a && s({
|
|
168
|
+
config: r.config,
|
|
169
|
+
loading: !1,
|
|
170
|
+
error: e(t)
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
subscribe(e) {
|
|
176
|
+
return o.add(e), () => o.delete(e);
|
|
177
|
+
},
|
|
178
|
+
snapshot: () => r,
|
|
179
|
+
ensure() {
|
|
180
|
+
n || (!i || r.error && !r.config && !r.loading) && c();
|
|
181
|
+
},
|
|
182
|
+
refetch: c
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function V(e, n, r) {
|
|
186
|
+
let i = e.safeParse(r);
|
|
187
|
+
if (i.success) return {
|
|
188
|
+
config: i.data,
|
|
189
|
+
loading: !1,
|
|
190
|
+
error: null
|
|
191
|
+
};
|
|
192
|
+
let a = i.error.issues[0];
|
|
193
|
+
return {
|
|
194
|
+
config: null,
|
|
195
|
+
loading: !1,
|
|
196
|
+
error: t("invalid_config", `${n}: ${a?.path.join(".")} ${a?.message}`)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function H(e) {
|
|
200
|
+
let t = m(e.subscribe, e.snapshot, e.snapshot);
|
|
201
|
+
return u(() => e.ensure(), [e]), {
|
|
202
|
+
...t,
|
|
203
|
+
refetch: e.refetch
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function U() {
|
|
207
|
+
return H(I().config);
|
|
208
|
+
}
|
|
209
|
+
function W() {
|
|
210
|
+
return H(I().customerConfig);
|
|
211
|
+
}
|
|
212
|
+
function G() {
|
|
213
|
+
let { client: e } = I(), { config: t } = U();
|
|
214
|
+
return d(() => ({
|
|
215
|
+
...Object.fromEntries((t?.currencies ?? []).map((e) => [e.code.toUpperCase(), e.decimals])),
|
|
216
|
+
...e.currencies
|
|
217
|
+
}), [t, e]);
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/react/provider.tsx
|
|
221
|
+
function K({ client: e, config: t, customerConfig: n, onChange: r, appearance: i, messages: a, t: o, locale: s, navigate: c, children: l }) {
|
|
222
|
+
let u = d(() => E(y(a), o, s), [
|
|
223
|
+
a,
|
|
224
|
+
o,
|
|
225
|
+
s
|
|
226
|
+
]), f = d(() => ({
|
|
227
|
+
appearance: i,
|
|
228
|
+
locale: s,
|
|
229
|
+
navigate: c
|
|
230
|
+
}), [
|
|
231
|
+
i,
|
|
232
|
+
s,
|
|
233
|
+
c
|
|
234
|
+
]);
|
|
235
|
+
return /* @__PURE__ */ h(M.Provider, {
|
|
236
|
+
value: f,
|
|
237
|
+
children: /* @__PURE__ */ h(D.Provider, {
|
|
238
|
+
value: u,
|
|
239
|
+
children: e ? /* @__PURE__ */ h(q, {
|
|
240
|
+
client: e,
|
|
241
|
+
config: t,
|
|
242
|
+
customerConfig: n,
|
|
243
|
+
onChange: r,
|
|
244
|
+
children: l
|
|
245
|
+
}) : l
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function q({ client: e, config: t, customerConfig: n, onChange: i, children: o }) {
|
|
250
|
+
let [s, l] = p(0), m = f(i);
|
|
251
|
+
u(() => {
|
|
252
|
+
m.current = i;
|
|
253
|
+
});
|
|
254
|
+
let g = c((e) => {
|
|
255
|
+
l((e) => e + 1), m.current?.(e);
|
|
256
|
+
}, []), _ = c(() => l((e) => e + 1), []), v = d(() => B(() => e.getConfig(), t && V(a, "config", t)), [e, t]), y = d(() => B(() => e.getCustomerConfig(), n && V(r, "customerConfig", n)), [e, n]), b = d(() => ({
|
|
257
|
+
client: e,
|
|
258
|
+
version: s,
|
|
259
|
+
notify: g,
|
|
260
|
+
refresh: _,
|
|
261
|
+
config: v,
|
|
262
|
+
customerConfig: y
|
|
263
|
+
}), [
|
|
264
|
+
e,
|
|
265
|
+
s,
|
|
266
|
+
g,
|
|
267
|
+
_,
|
|
268
|
+
v,
|
|
269
|
+
y
|
|
270
|
+
]);
|
|
271
|
+
return /* @__PURE__ */ h(F.Provider, {
|
|
272
|
+
value: b,
|
|
273
|
+
children: o
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/react/remote.ts
|
|
278
|
+
function J(t, n) {
|
|
279
|
+
let [r, i] = p(0), a = `${t}|${r}`, [o, s] = p({
|
|
280
|
+
request: null,
|
|
281
|
+
data: null,
|
|
282
|
+
error: null
|
|
283
|
+
}), l = f(n);
|
|
284
|
+
u(() => {
|
|
285
|
+
l.current = n;
|
|
286
|
+
}), u(() => {
|
|
287
|
+
let t = new AbortController();
|
|
288
|
+
return l.current(t.signal).then((e) => s({
|
|
289
|
+
request: a,
|
|
290
|
+
data: e,
|
|
291
|
+
error: null
|
|
292
|
+
}), (n) => {
|
|
293
|
+
t.signal.aborted || s((t) => ({
|
|
294
|
+
request: a,
|
|
295
|
+
data: t.data,
|
|
296
|
+
error: e(n)
|
|
297
|
+
}));
|
|
298
|
+
}), () => t.abort();
|
|
299
|
+
}, [a]);
|
|
300
|
+
let d = c(() => i((e) => e + 1), []), m = c((e) => s((t) => t.data === null ? t : {
|
|
301
|
+
...t,
|
|
302
|
+
data: e(t.data)
|
|
303
|
+
}), []);
|
|
304
|
+
return {
|
|
305
|
+
data: o.data,
|
|
306
|
+
loading: o.request !== a,
|
|
307
|
+
error: o.request === a ? o.error : null,
|
|
308
|
+
refetch: d,
|
|
309
|
+
replace: m
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
//#endregion
|
|
313
|
+
//#region src/react/hooks.ts
|
|
314
|
+
function Y() {
|
|
315
|
+
let [e, t] = p({});
|
|
316
|
+
return [e, c((e, n) => {
|
|
317
|
+
t((t) => {
|
|
318
|
+
let r = { ...t };
|
|
319
|
+
return n ? r[e] = n : delete r[e], r;
|
|
320
|
+
});
|
|
321
|
+
}, [])];
|
|
322
|
+
}
|
|
323
|
+
var X = () => t("wallet_required", "A wallet must sign this action.");
|
|
324
|
+
function Z(t = {}) {
|
|
325
|
+
let { client: r, version: a, notify: o } = I(), s = t.status ?? "all", l = t.limit ?? 100, u = J(`${s}|${l}|${a}`, (e) => r.listSubscriptions({
|
|
326
|
+
status: s,
|
|
327
|
+
limit: l,
|
|
328
|
+
signal: e
|
|
329
|
+
})), [d, f] = Y(), { replace: p } = u, m = c((e) => p((t) => ({
|
|
330
|
+
...t,
|
|
331
|
+
data: t.data.map((t) => t.id === e.id ? e : t)
|
|
332
|
+
})), [p]), h = c(async (t, n, r, i) => {
|
|
333
|
+
f(t, n);
|
|
334
|
+
try {
|
|
335
|
+
let e = await r();
|
|
336
|
+
return m(e), i(e), null;
|
|
337
|
+
} catch (t) {
|
|
338
|
+
return e(t);
|
|
339
|
+
} finally {
|
|
340
|
+
f(t, null);
|
|
341
|
+
}
|
|
342
|
+
}, [f, m]), g = c((e, t, a) => h(e, "cancel", async () => {
|
|
343
|
+
let o = await r.cancelSubscription(e, { reason: t });
|
|
344
|
+
if (!o.next_action) return o;
|
|
345
|
+
if (!i(o.next_action) || !a) throw X();
|
|
346
|
+
f(e, "signing");
|
|
347
|
+
let s = await n(o.next_action, a);
|
|
348
|
+
return f(e, "confirming"), r.cancelSubscription(e, {
|
|
349
|
+
reason: t,
|
|
350
|
+
signature: s
|
|
351
|
+
});
|
|
352
|
+
}, () => o({
|
|
353
|
+
type: "subscription.canceled",
|
|
354
|
+
subscriptionId: e
|
|
355
|
+
})), [
|
|
356
|
+
h,
|
|
357
|
+
r,
|
|
358
|
+
f,
|
|
359
|
+
o
|
|
360
|
+
]), _ = c((e) => h(e, "resume", () => r.resumeSubscription(e), () => o({
|
|
361
|
+
type: "subscription.resumed",
|
|
362
|
+
subscriptionId: e
|
|
363
|
+
})), [
|
|
364
|
+
h,
|
|
365
|
+
r,
|
|
366
|
+
o
|
|
367
|
+
]), v = c((e, t) => h(e, "payment_method", () => r.setSubscriptionPaymentMethod(e, t), () => o({
|
|
368
|
+
type: "subscription.payment_method_changed",
|
|
369
|
+
subscriptionId: e,
|
|
370
|
+
paymentMethodId: t
|
|
371
|
+
})), [
|
|
372
|
+
h,
|
|
373
|
+
r,
|
|
374
|
+
o
|
|
375
|
+
]), y = c(async (t, a, s) => {
|
|
376
|
+
f(t, "change");
|
|
377
|
+
try {
|
|
378
|
+
let e = await r.changeSubscription(t, a);
|
|
379
|
+
if (e.status === "requires_action" && i(e.next_action) && s) {
|
|
380
|
+
f(t, "signing");
|
|
381
|
+
let i = await n(e.next_action, s);
|
|
382
|
+
f(t, "confirming"), e = await r.changeSubscription(t, {
|
|
383
|
+
...a,
|
|
384
|
+
signature: i
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return o({
|
|
388
|
+
type: "subscription.changed",
|
|
389
|
+
subscriptionId: t,
|
|
390
|
+
change: e
|
|
391
|
+
}), e;
|
|
392
|
+
} catch (t) {
|
|
393
|
+
return e(t);
|
|
394
|
+
} finally {
|
|
395
|
+
f(t, null);
|
|
396
|
+
}
|
|
397
|
+
}, [
|
|
398
|
+
r,
|
|
399
|
+
f,
|
|
400
|
+
o
|
|
401
|
+
]);
|
|
402
|
+
return {
|
|
403
|
+
subscriptions: u.data?.data ?? null,
|
|
404
|
+
nextCursor: u.data?.next_cursor ?? null,
|
|
405
|
+
loading: u.loading,
|
|
406
|
+
error: u.error,
|
|
407
|
+
refetch: u.refetch,
|
|
408
|
+
pending: d,
|
|
409
|
+
cancel: g,
|
|
410
|
+
resume: _,
|
|
411
|
+
setPaymentMethod: v,
|
|
412
|
+
changeSubscription: y
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
function Q() {
|
|
416
|
+
let { client: t, version: n, notify: r } = I(), i = J(`${n}`, (e) => t.listPaymentMethods({ signal: e })), [a, o] = Y(), [s, l] = p(!1), { replace: u } = i, d = c(async (n) => {
|
|
417
|
+
l(!0);
|
|
418
|
+
try {
|
|
419
|
+
let e = await t.addPaymentMethod(n);
|
|
420
|
+
return u((t) => ({
|
|
421
|
+
...t,
|
|
422
|
+
data: [...t.data, e]
|
|
423
|
+
})), r({
|
|
424
|
+
type: "payment_method.added",
|
|
425
|
+
paymentMethodId: e.id
|
|
426
|
+
}), null;
|
|
427
|
+
} catch (t) {
|
|
428
|
+
return e(t);
|
|
429
|
+
} finally {
|
|
430
|
+
l(!1);
|
|
431
|
+
}
|
|
432
|
+
}, [
|
|
433
|
+
t,
|
|
434
|
+
r,
|
|
435
|
+
u
|
|
436
|
+
]), f = c(async (n) => {
|
|
437
|
+
o(n, "remove");
|
|
438
|
+
try {
|
|
439
|
+
return await t.removePaymentMethod(n), u((e) => ({
|
|
440
|
+
...e,
|
|
441
|
+
data: e.data.filter((e) => e.id !== n)
|
|
442
|
+
})), r({
|
|
443
|
+
type: "payment_method.removed",
|
|
444
|
+
paymentMethodId: n
|
|
445
|
+
}), null;
|
|
446
|
+
} catch (t) {
|
|
447
|
+
return e(t);
|
|
448
|
+
} finally {
|
|
449
|
+
o(n, null);
|
|
450
|
+
}
|
|
451
|
+
}, [
|
|
452
|
+
t,
|
|
453
|
+
o,
|
|
454
|
+
r,
|
|
455
|
+
u
|
|
456
|
+
]), m = c(async (n, i) => {
|
|
457
|
+
o(n, "default");
|
|
458
|
+
try {
|
|
459
|
+
await t.setDefaultPaymentMethod({
|
|
460
|
+
currency: i,
|
|
461
|
+
paymentMethodId: n
|
|
462
|
+
});
|
|
463
|
+
let e = i.toUpperCase();
|
|
464
|
+
return u((t) => ({
|
|
465
|
+
...t,
|
|
466
|
+
data: t.data.map((t) => {
|
|
467
|
+
let r = (t.default_currencies ?? []).filter((t) => t !== e);
|
|
468
|
+
return {
|
|
469
|
+
...t,
|
|
470
|
+
default_currencies: t.id === n ? [...r, e] : r
|
|
471
|
+
};
|
|
472
|
+
})
|
|
473
|
+
})), r({
|
|
474
|
+
type: "payment_method.default_changed",
|
|
475
|
+
paymentMethodId: n
|
|
476
|
+
}), null;
|
|
477
|
+
} catch (t) {
|
|
478
|
+
return e(t);
|
|
479
|
+
} finally {
|
|
480
|
+
o(n, null);
|
|
481
|
+
}
|
|
482
|
+
}, [
|
|
483
|
+
t,
|
|
484
|
+
o,
|
|
485
|
+
r,
|
|
486
|
+
u
|
|
487
|
+
]);
|
|
488
|
+
return {
|
|
489
|
+
methods: i.data?.data ?? null,
|
|
490
|
+
loading: i.loading,
|
|
491
|
+
error: i.error,
|
|
492
|
+
refetch: i.refetch,
|
|
493
|
+
pending: a,
|
|
494
|
+
adding: s,
|
|
495
|
+
add: d,
|
|
496
|
+
remove: f,
|
|
497
|
+
setDefault: m
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
var $ = {};
|
|
501
|
+
function ee(e = {}) {
|
|
502
|
+
let { client: t, version: n } = I(), r = e.pageSize ?? 20, i = `${r}|${e.rail ?? ""}`, [a, o] = p({
|
|
503
|
+
filter: i,
|
|
504
|
+
cursors: [null]
|
|
505
|
+
}), s = d(() => a.filter === i ? a.cursors : [null], [a, i]), l = s.length - 1, u = s[l], f = J(`${i}|${u ?? ""}|${n}`, async (n) => {
|
|
506
|
+
let i = await t.listPayments({
|
|
507
|
+
limit: r,
|
|
508
|
+
cursor: u,
|
|
509
|
+
rail: e.rail,
|
|
510
|
+
signal: n
|
|
511
|
+
}), a = [...new Set(i.data.flatMap((e) => e.order_id ? [e.order_id] : []))], o = {};
|
|
512
|
+
if (a.length) {
|
|
513
|
+
let e = await t.listOrders({
|
|
514
|
+
ids: a,
|
|
515
|
+
signal: n
|
|
516
|
+
});
|
|
517
|
+
for (let t of e.data) o[t.id] = t;
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
...i,
|
|
521
|
+
orders: o
|
|
522
|
+
};
|
|
523
|
+
}), m = f.data, h = m?.next_cursor ?? null;
|
|
524
|
+
return {
|
|
525
|
+
payments: m?.data ?? null,
|
|
526
|
+
orders: m?.orders ?? $,
|
|
527
|
+
page: l,
|
|
528
|
+
hasMore: h !== null,
|
|
529
|
+
loading: f.loading,
|
|
530
|
+
error: f.error,
|
|
531
|
+
next: c(() => {
|
|
532
|
+
h !== null && o({
|
|
533
|
+
filter: i,
|
|
534
|
+
cursors: [...s, h]
|
|
535
|
+
});
|
|
536
|
+
}, [
|
|
537
|
+
i,
|
|
538
|
+
s,
|
|
539
|
+
h
|
|
540
|
+
]),
|
|
541
|
+
previous: c(() => {
|
|
542
|
+
s.length > 1 && o({
|
|
543
|
+
filter: i,
|
|
544
|
+
cursors: s.slice(0, -1)
|
|
545
|
+
});
|
|
546
|
+
}, [i, s]),
|
|
547
|
+
refetch: f.refetch
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
//#endregion
|
|
551
|
+
export { E as _, U as a, b, L as c, z as d, P as f, O as g, j as h, K as i, I as l, A as m, ee as n, G as o, N as p, Z as r, W as s, Q as t, R as u, _ as v, y as x, g as y };
|
|
552
|
+
|
|
553
|
+
//# sourceMappingURL=hooks-C9JkHcRt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-C9JkHcRt.js","names":[],"sources":["../src/i18n/messages.ts","../src/i18n/context.ts","../src/appearance.ts","../src/scope-context.ts","../src/react/context.ts","../src/react/config.ts","../src/react/provider.tsx","../src/react/remote.ts","../src/react/hooks.ts"],"sourcesContent":["import { en } from \"../locales/en.ts\"\n\n/**\n * A count-dependent message: CLDR plural categories for the locale, with\n * `other` required. An exact-count key (`\"1\"`) wins over the category, like\n * ICU's `=1`, for locales whose single form differs from `{count}` (毎日).\n */\nexport type PluralMessage = {\n [K in Intl.LDMLPluralRule | \"1\"]?: string\n} & { other: string }\n\ntype Widen<T> = {\n [K in keyof T]: T[K] extends string\n ? string\n : T[K] extends PluralMessage\n ? PluralMessage\n : Widen<T[K]>\n}\n\n/** The complete message tree; English is the reference shape. */\nexport type BillingUiMessages = Widen<typeof en>\n\ntype DeepPartial<T> = {\n [K in keyof T]?: T[K] extends string\n ? string\n : T[K] extends PluralMessage\n ? Partial<PluralMessage>\n : DeepPartial<T[K]>\n}\n\n/** A locale bundle or host override: any subset of the tree. */\nexport type BillingUiMessageBundle = DeepPartial<BillingUiMessages>\n\ntype Paths<T, P extends string = \"\"> = {\n [K in keyof T & string]: T[K] extends string\n ? `${P}${K}`\n : T[K] extends PluralMessage\n ? never\n : Paths<T[K], `${P}${K}.`>\n}[keyof T & string]\n\ntype PluralPaths<T, P extends string = \"\"> = {\n [K in keyof T & string]: T[K] extends string\n ? never\n : T[K] extends PluralMessage\n ? `${P}${K}`\n : PluralPaths<T[K], `${P}${K}.`>\n}[keyof T & string]\n\n/** Dotted key of any message, e.g. `subscriptions.title`. */\nexport type MessageKey = Paths<BillingUiMessages>\n\n/** Dotted key of a count-dependent message, e.g. `interval.every.day`. */\nexport type PluralKey = PluralPaths<BillingUiMessages>\n\nexport type MessageVars = Record<string, string | number>\n\n/**\n * Host translation hook. Receives the bare key (`subscriptions.title`,\n * `errors.not_found`); return nothing or the key itself to use ours.\n */\nexport type BillingUiTranslate = (\n key: string,\n vars?: MessageVars\n) => string | null | undefined\n\n/** Types a locale bundle or override against the message tree. */\nexport function defineMessages(\n bundle: BillingUiMessageBundle\n): BillingUiMessageBundle {\n return bundle\n}\n\nexport const defaultMessages: BillingUiMessages = en\n\ntype Tree = { [key: string]: string | Tree }\n\nfunction mergeInto(target: Tree, source: Tree): Tree {\n const out: Tree = { ...target }\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined || value === null) continue\n const current = out[key]\n if (typeof value === \"string\") {\n if (value !== \"\") out[key] = value\n } else if (typeof current === \"object\") {\n out[key] = mergeInto(current, value)\n } else {\n out[key] = mergeInto({}, value)\n }\n }\n return out\n}\n\n/** Layers bundles over English; later bundles win, missing keys fall back. */\nexport function resolveMessages(\n bundles?: BillingUiMessageBundle | readonly BillingUiMessageBundle[]\n): BillingUiMessages {\n const list = bundles ? (Array.isArray(bundles) ? bundles : [bundles]) : []\n let tree = en as unknown as Tree\n for (const bundle of list) tree = mergeInto(tree, bundle as Tree)\n return tree as unknown as BillingUiMessages\n}\n\nexport function interpolate(template: string, vars?: MessageVars): string {\n if (!vars) return template\n return template.replace(/\\{(\\w+)\\}/g, (match, name: string) =>\n name in vars ? String(vars[name]) : match\n )\n}\n\nfunction lookup(messages: BillingUiMessages, key: string): string | undefined {\n let node: unknown = messages\n for (const part of key.split(\".\")) {\n if (!node || typeof node !== \"object\") return undefined\n node = (node as Tree)[part]\n }\n return typeof node === \"string\" ? node : undefined\n}\n\nexport interface Translator {\n messages: BillingUiMessages\n /** BCP 47 tag used for plural rules and numbers; the runtime's when unset. */\n locale?: string\n t(key: MessageKey, vars?: MessageVars): string\n /**\n * Count-dependent message: tries `<key>.<count>`, then the locale's plural\n * category, then `<key>.other`. `{count}` is locale-formatted.\n */\n plural(key: PluralKey, count: number, vars?: MessageVars): string\n /** Message for a billing error, error code, or thrown value. */\n error(error: unknown, vars?: MessageVars): string\n}\n\nfunction errorCode(error: unknown): string | undefined {\n if (typeof error === \"string\") return error\n if (error && typeof error === \"object\" && \"code\" in error) {\n const code = (error as { code: unknown }).code\n if (typeof code === \"string\") return code\n }\n return undefined\n}\n\nfunction isNetworkError(error: unknown): boolean {\n return error instanceof TypeError && /fetch|network/i.test(error.message)\n}\n\nfunction pluralRules(locale?: string): Intl.PluralRules {\n try {\n return new Intl.PluralRules(locale)\n } catch {\n return new Intl.PluralRules(\"en\")\n }\n}\n\nfunction formatCount(count: number, locale?: string): string {\n try {\n return new Intl.NumberFormat(locale).format(count)\n } catch {\n return String(count)\n }\n}\n\nexport function createTranslator(\n messages: BillingUiMessages,\n hostT?: BillingUiTranslate,\n locale?: string\n): Translator {\n const rules = pluralRules(locale)\n const translate = (key: string, vars?: MessageVars): string | undefined => {\n const hosted = hostT?.(key, vars)\n if (hosted && hosted !== key) return hosted\n const own = lookup(messages, key)\n return own === undefined ? undefined : interpolate(own, vars)\n }\n return {\n messages,\n locale,\n t: (key, vars) => translate(key, vars) ?? key,\n plural(key, count, vars) {\n const all = { ...vars, count: formatCount(count, locale) }\n return (\n translate(`${key}.${count}`, all) ??\n translate(`${key}.${rules.select(count)}`, all) ??\n translate(`${key}.other`, all) ??\n key\n )\n },\n error(error, vars) {\n const code = errorCode(error)\n if (code && code !== \"generic\" && code !== \"network\") {\n const metadata =\n error && typeof error === \"object\" && \"metadata\" in error\n ? (error as { metadata?: MessageVars }).metadata\n : undefined\n const message = translate(`errors.${code}`, { ...metadata, ...vars })\n if (message) return message\n }\n const fallback = isNetworkError(error)\n ? \"errors.network\"\n : \"errors.generic\"\n return translate(fallback, vars) ?? messages.errors.generic\n },\n }\n}\n","import { createContext, useContext } from \"react\"\n\nimport {\n createTranslator,\n defaultMessages,\n type Translator,\n} from \"./messages.ts\"\n\nexport const MessagesContext = createContext<Translator>(\n createTranslator(defaultMessages)\n)\n\n/** English defaults when rendered outside a `BillingProvider`. */\nexport function useMessages(): Translator {\n return useContext(MessagesContext)\n}\n","// Integrator theming. The component scopes the standard shadcn token set\n// under its root, so `theme` flips the whole palette and `variables` override\n// individual tokens without the integrator touching our CSS.\nimport type { CSSProperties } from \"react\"\n\n// `inherit` uses the host page's shadcn tokens (`--background`, ...) and its\n// `.dark` class instead of the bundled zinc palette.\nexport type BillingTheme = \"light\" | \"dark\" | \"auto\" | \"inherit\"\n\n// The tokens integrators may override. Values are raw CSS color/length\n// strings; they land as custom properties on the purchase root.\nexport interface BillingVariables {\n background?: string\n foreground?: string\n card?: string\n mutedForeground?: string\n faintForeground?: string\n border?: string\n input?: string\n primary?: string\n primaryForeground?: string\n destructive?: string\n ring?: string\n radius?: string\n fontFamily?: string\n}\n\nexport interface BillingAppearance {\n theme?: BillingTheme\n variables?: BillingVariables\n}\n\nconst VARIABLE_TO_CSS: Record<keyof BillingVariables, string> = {\n background: \"--background\",\n foreground: \"--foreground\",\n card: \"--card\",\n mutedForeground: \"--muted-foreground\",\n faintForeground: \"--orck-faint\",\n border: \"--border\",\n input: \"--input\",\n primary: \"--primary\",\n primaryForeground: \"--primary-foreground\",\n destructive: \"--destructive\",\n ring: \"--ring\",\n radius: \"--radius\",\n fontFamily: \"--orck-font\",\n}\n\nexport function appearanceStyle(\n appearance: BillingAppearance | undefined,\n namespace: \"orck\" | \"orba\" = \"orck\"\n): CSSProperties | undefined {\n const variables = appearance?.variables\n if (!variables) return undefined\n const style: Record<string, string> = {}\n for (const [key, value] of Object.entries(variables)) {\n if (!value) continue\n style[\n VARIABLE_TO_CSS[key as keyof BillingVariables].replace(\n \"--orck-\",\n `--${namespace}-`\n )\n ] = value\n }\n return style as CSSProperties\n}\n\nexport function appearanceTheme(\n appearance: BillingAppearance | undefined\n): BillingTheme {\n return appearance?.theme ?? \"auto\"\n}\n","import { createContext, useContext, type CSSProperties } from \"react\"\n\nimport {\n appearanceStyle,\n appearanceTheme,\n type BillingAppearance,\n type BillingTheme,\n} from \"./appearance\"\n\nexport type Navigate = (to: string) => void\n\nexport interface UiSettings {\n appearance?: BillingAppearance\n locale?: string\n navigate?: Navigate\n}\n\nexport const UiContext = createContext<UiSettings>({})\n\nexport const useUiSettings = (): UiSettings => useContext(UiContext)\n\nexport interface ScopeProps {\n className: string\n \"data-orck-theme\": BillingTheme\n style?: CSSProperties\n}\n\n/** Props that make an element a styling root; portals carry them too. */\nexport function useScopeProps(appearance?: BillingAppearance): ScopeProps {\n const settings = useUiSettings()\n const resolved = appearance ?? settings.appearance\n return {\n className: \"orck\",\n \"data-orck-theme\": appearanceTheme(resolved),\n style: appearanceStyle(resolved),\n }\n}\n","import { createContext, useContext } from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport type { CustomerConfig, SubscriptionChange } from \"../client/types\"\nimport type { ConfigStore } from \"./config\"\n\nexport type BillingChange =\n | {\n type: \"subscription.canceled\" | \"subscription.resumed\"\n subscriptionId: string\n }\n | {\n type: \"subscription.payment_method_changed\"\n subscriptionId: string\n /** null: the subscription follows the default card. */\n paymentMethodId: string | null\n }\n | {\n type: \"subscription.changed\"\n subscriptionId: string\n /** `status` may still be `processing` or `requires_action`. */\n change: SubscriptionChange\n }\n | {\n type:\n | \"payment_method.added\"\n | \"payment_method.removed\"\n | \"payment_method.default_changed\"\n paymentMethodId: string\n }\n\nexport interface BillingContextValue {\n client: BillingClient\n /** Bumped after every mutation; hooks refetch on change. */\n version: number\n notify(change: BillingChange): void\n /** Refetch every hook after a host-side change such as a plan switch. */\n refresh(): void\n /** The shared `GET /config`; read it with `useConfig()`. */\n config: ConfigStore\n /** The shared `GET /me/config`; read it with `useCustomerConfig()`. */\n customerConfig: ConfigStore<CustomerConfig>\n}\n\nexport const BillingContext = createContext<BillingContextValue | null>(null)\n\nexport function useBillingContext(): BillingContextValue {\n const ctx = useContext(BillingContext)\n if (!ctx) throw new Error(\"billing-ui: wrap the tree in <BillingProvider>\")\n return ctx\n}\n\nexport const useBillingClient = (): BillingClient => useBillingContext().client\n\nexport const useBillingRefresh = (): (() => void) => useBillingContext().refresh\n\n/** The billing context when a BillingProvider is present, else null. */\nexport const useOptionalBillingContext = (): BillingContextValue | null =>\n useContext(BillingContext)\n","import { useEffect, useMemo, useSyncExternalStore } from \"react\"\nimport type { z } from \"zod\"\n\nimport { localError, toBillingError, type BillingError } from \"../client/errors\"\nimport type {\n CurrencyScales,\n CustomerConfig,\n PublicConfig,\n} from \"../client/types\"\nimport { useBillingContext } from \"./context\"\n\nexport interface ConfigState<T = PublicConfig> {\n config: T | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\ninterface Snapshot<T> {\n config: T | null\n loading: boolean\n error: BillingError | null\n}\n\n/** One shared copy of a configuration read per client, fetched on first use. */\nexport interface ConfigStore<T = PublicConfig> {\n subscribe(listener: () => void): () => void\n snapshot(): Snapshot<T>\n /** Fetches the document unless it is loaded or loading. */\n ensure(): void\n refetch(): void\n}\n\n/**\n * The store of `read`'s document. `supplied` is the host's copy: the store\n * starts with it and never reads to load; a refetch (a retry) still reads.\n */\nexport function createConfigStore<T>(\n read: () => Promise<T>,\n supplied?: Snapshot<T>\n): ConfigStore<T> {\n let snapshot: Snapshot<T> = supplied ?? {\n config: null,\n loading: true,\n error: null,\n }\n let started = supplied !== undefined\n let latest = 0\n const listeners = new Set<() => void>()\n const set = (next: Snapshot<T>) => {\n snapshot = next\n for (const listener of listeners) listener()\n }\n const load = () => {\n started = true\n const request = ++latest\n if (!snapshot.loading) set({ ...snapshot, loading: true })\n read().then(\n (config) => {\n if (request === latest) set({ config, loading: false, error: null })\n },\n (err: unknown) => {\n if (request === latest)\n set({\n config: snapshot.config,\n loading: false,\n error: toBillingError(err),\n })\n }\n )\n }\n return {\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n snapshot: () => snapshot,\n // A read that failed with nothing loaded is tried again by the next\n // component: the customer may have signed in since.\n ensure() {\n if (supplied) return\n if (!started || (snapshot.error && !snapshot.config && !snapshot.loading))\n load()\n },\n refetch: load,\n }\n}\n\n/** The host's copy of a document, read as `schema` reads the server's. */\nexport function suppliedConfig<T>(\n schema: z.ZodType<T>,\n name: string,\n value: unknown\n): Snapshot<T> {\n const parsed = schema.safeParse(value)\n if (parsed.success)\n return { config: parsed.data, loading: false, error: null }\n const issue = parsed.error.issues[0]\n return {\n config: null,\n loading: false,\n error: localError(\n \"invalid_config\",\n `${name}: ${issue?.path.join(\".\")} ${issue?.message}`\n ),\n }\n}\n\nfunction useStore<T>(store: ConfigStore<T>): ConfigState<T> {\n const snapshot = useSyncExternalStore(\n store.subscribe,\n store.snapshot,\n store.snapshot\n )\n useEffect(() => store.ensure(), [store])\n return { ...snapshot, refetch: store.refetch }\n}\n\n/**\n * The deployment's configuration (`GET /config`), fetched once per\n * `BillingProvider` unless its `config` supplied it, and shared by every\n * component that reads it.\n */\nexport function useConfig(): ConfigState {\n return useStore(useBillingContext().config)\n}\n\n/**\n * The customer's merchant (`GET /me/config`): its payment setup and how it\n * presents itself, fetched once per `BillingProvider` for the signed-in\n * customer unless its `customerConfig` supplied it, and shared by every\n * component that reads it.\n */\nexport function useCustomerConfig(): ConfigState<CustomerConfig> {\n return useStore(useBillingContext().customerConfig)\n}\n\n/**\n * Currency scales: the server's registry, under the client's pinned copy and\n * host overrides, which stand alone until the registry loads.\n */\nexport function useCurrencyScales(): CurrencyScales {\n const { client } = useBillingContext()\n const { config } = useConfig()\n return useMemo(() => {\n const served = Object.fromEntries(\n (config?.currencies ?? []).map((c) => [c.code.toUpperCase(), c.decimals])\n )\n return { ...served, ...client.currencies }\n }, [config, client])\n}\n","import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\"\n\nimport type { BillingAppearance } from \"../appearance\"\nimport type { BillingClient } from \"../client/client\"\nimport {\n customerConfigSchema,\n publicConfigSchema,\n type CustomerConfig,\n type PublicConfig,\n} from \"../client/types\"\nimport { MessagesContext } from \"../i18n/context\"\nimport {\n createTranslator,\n resolveMessages,\n type BillingUiMessageBundle,\n type BillingUiTranslate,\n} from \"../i18n/messages\"\nimport { UiContext, type Navigate } from \"../scope-context\"\nimport { createConfigStore, suppliedConfig } from \"./config\"\nimport { BillingContext, type BillingChange } from \"./context\"\n\nexport interface BillingProviderProps {\n /**\n * The customer's client: hooks and the account panels read it, and a\n * purchase saves a new card to the customer first. Leave it out where no\n * customer is signed in, such as the shared payment page.\n */\n client?: BillingClient\n /**\n * The deployment's configuration as `GET /config` answers it, from the\n * host's own page response (Go: `Engine.PublicConfig`, or a remote\n * `Client.GetPublicConfig`). Supplied, billing-ui does not request it.\n */\n config?: PublicConfig\n /**\n * The customer's merchant's configuration as `GET /me/config` answers it,\n * from the host's own page response (Go: `Engine.CustomerConfig`).\n * Supplied, billing-ui does not request it to load; a retry still reads it.\n */\n customerConfig?: CustomerConfig\n /** Fires after each successful mutation: the host's cache-invalidation hook. */\n onChange?: (change: BillingChange) => void\n appearance?: BillingAppearance\n /** Locale bundle(s) layered over English; later entries win. */\n messages?: BillingUiMessageBundle | readonly BillingUiMessageBundle[]\n /** Host translation hook, consulted before the bundles. */\n t?: BillingUiTranslate\n /** BCP 47 tag for dates, money and plurals; defaults to the browser's. */\n locale?: string\n /** Host router for in-app links (e.g. the plans page). */\n navigate?: Navigate\n children?: ReactNode\n}\n\n/**\n * The one billing-ui provider: the client, and the appearance and words of\n * the styled components. Renders no DOM; surfaces create their own styling\n * roots, and no stylesheet loads until a styled component is imported.\n */\nexport function BillingProvider({\n client,\n config,\n customerConfig,\n onChange,\n appearance,\n messages,\n t,\n locale,\n navigate,\n children,\n}: BillingProviderProps) {\n const translator = useMemo(\n () => createTranslator(resolveMessages(messages), t, locale),\n [messages, t, locale]\n )\n const ui = useMemo(\n () => ({ appearance, locale, navigate }),\n [appearance, locale, navigate]\n )\n return (\n <UiContext.Provider value={ui}>\n <MessagesContext.Provider value={translator}>\n {client ? (\n <ClientProvider\n client={client}\n config={config}\n customerConfig={customerConfig}\n onChange={onChange}\n >\n {children}\n </ClientProvider>\n ) : (\n children\n )}\n </MessagesContext.Provider>\n </UiContext.Provider>\n )\n}\n\nfunction ClientProvider({\n client,\n config: hostConfig,\n customerConfig: hostCustomerConfig,\n onChange,\n children,\n}: {\n client: BillingClient\n config?: PublicConfig\n customerConfig?: CustomerConfig\n onChange?: (change: BillingChange) => void\n children?: ReactNode\n}) {\n const [version, setVersion] = useState(0)\n const onChangeRef = useRef(onChange)\n useEffect(() => {\n onChangeRef.current = onChange\n })\n const notify = useCallback((change: BillingChange) => {\n setVersion((v) => v + 1)\n onChangeRef.current?.(change)\n }, [])\n const refresh = useCallback(() => setVersion((v) => v + 1), [])\n const config = useMemo(\n () =>\n createConfigStore(\n () => client.getConfig(),\n hostConfig && suppliedConfig(publicConfigSchema, \"config\", hostConfig)\n ),\n [client, hostConfig]\n )\n const customerConfig = useMemo(\n () =>\n createConfigStore(\n () => client.getCustomerConfig(),\n hostCustomerConfig &&\n suppliedConfig(\n customerConfigSchema,\n \"customerConfig\",\n hostCustomerConfig\n )\n ),\n [client, hostCustomerConfig]\n )\n const value = useMemo(\n () => ({ client, version, notify, refresh, config, customerConfig }),\n [client, version, notify, refresh, config, customerConfig]\n )\n return (\n <BillingContext.Provider value={value}>{children}</BillingContext.Provider>\n )\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\"\n\nimport { toBillingError, type BillingError } from \"../client/errors\"\n\nexport interface RemoteState<T> {\n data: T | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\n// Keyed fetch that keeps the previous data while a newer key loads, so a\n// refetch after a mutation never flashes an empty list.\nexport function useRemote<T>(\n key: string,\n load: (signal: AbortSignal) => Promise<T>\n): RemoteState<T> & { replace: (update: (data: T) => T) => void } {\n const [nonce, setNonce] = useState(0)\n const request = `${key}|${nonce}`\n const [state, setState] = useState<{\n request: string | null\n data: T | null\n error: BillingError | null\n }>({ request: null, data: null, error: null })\n const loadRef = useRef(load)\n useEffect(() => {\n loadRef.current = load\n })\n\n useEffect(() => {\n const ctl = new AbortController()\n loadRef.current(ctl.signal).then(\n (data) => setState({ request, data, error: null }),\n (err: unknown) => {\n if (!ctl.signal.aborted)\n setState((s) => ({\n request,\n data: s.data,\n error: toBillingError(err),\n }))\n }\n )\n return () => ctl.abort()\n }, [request])\n\n const refetch = useCallback(() => setNonce((n) => n + 1), [])\n const replace = useCallback(\n (update: (data: T) => T) =>\n setState((s) => (s.data === null ? s : { ...s, data: update(s.data) })),\n []\n )\n return {\n data: state.data,\n loading: state.request !== request,\n error: state.request === request ? state.error : null,\n refetch,\n replace,\n }\n}\n","import { useCallback, useMemo, useState } from \"react\"\n\nimport {\n isWalletAction,\n signWalletAction,\n type SendSolanaTransaction,\n type SubscriptionChangeInput,\n} from \"../client/client\"\nimport { localError, toBillingError, type BillingError } from \"../client/errors\"\nimport type {\n NewCard,\n Order,\n Payment,\n PaymentMethod,\n Subscription,\n SubscriptionChange,\n} from \"../client/types\"\nimport { useBillingContext } from \"./context\"\nimport { useRemote } from \"./remote\"\n\n// Actions never throw: they resolve to null on success or the error.\nexport type ActionResult = Promise<BillingError | null>\n\n/** `signing` and `confirming` are a wallet step's stages. */\nexport type SubscriptionAction =\n \"cancel\" | \"resume\" | \"payment_method\" | \"change\" | \"signing\" | \"confirming\"\n\nexport interface SubscriptionsOptions {\n /** Server filter; default `all`. */\n status?: string\n limit?: number\n}\n\nexport interface SubscriptionsState {\n subscriptions: Subscription[] | null\n /** The next page's cursor; null on the last page. */\n nextCursor: string | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n /** In-flight action per subscription id. */\n pending: Readonly<Record<string, SubscriptionAction>>\n /**\n * Cancels at period end. A Solana subscription is canceled by the wallet:\n * pass `sendTransaction`; without it the cancel resolves to a\n * `wallet_required` error.\n */\n cancel: (\n subscriptionId: string,\n reason: string,\n sendTransaction?: SendSolanaTransaction\n ) => ActionResult\n resume: (subscriptionId: string) => ActionResult\n /** `null` makes the subscription follow the default card. */\n setPaymentMethod: (\n subscriptionId: string,\n paymentMethodId: string | null\n ) => ActionResult\n /**\n * Resolves to the change, whose `status` may still be `processing` or\n * `requires_action`, or to the error. A Solana change is signed with\n * `sendTransaction` and resolves once the chain confirms it.\n */\n changeSubscription: (\n subscriptionId: string,\n input: SubscriptionChangeInput & { idempotencyKey: string },\n sendTransaction?: SendSolanaTransaction\n ) => Promise<SubscriptionChange | BillingError>\n}\n\nfunction usePending<A extends string>() {\n const [pending, setPending] = useState<Readonly<Record<string, A>>>({})\n const mark = useCallback((id: string, action: A | null) => {\n setPending((p) => {\n const next = { ...p }\n if (action) next[id] = action\n else delete next[id]\n return next\n })\n }, [])\n return [pending, mark] as const\n}\n\nconst walletRequired = () =>\n localError(\"wallet_required\", \"A wallet must sign this action.\")\n\nexport function useSubscriptions(\n options: SubscriptionsOptions = {}\n): SubscriptionsState {\n const { client, version, notify } = useBillingContext()\n const status = options.status ?? \"all\"\n const limit = options.limit ?? 100\n const remote = useRemote(`${status}|${limit}|${version}`, (signal) =>\n client.listSubscriptions({ status, limit, signal })\n )\n const [pending, mark] = usePending<SubscriptionAction>()\n const { replace } = remote\n\n const patchRow = useCallback(\n (next: Subscription) =>\n replace((page) => ({\n ...page,\n data: page.data.map((s) => (s.id === next.id ? next : s)),\n })),\n [replace]\n )\n\n const act = useCallback(\n async (\n id: string,\n action: SubscriptionAction,\n run: () => Promise<Subscription>,\n done: (subscription: Subscription) => void\n ): ActionResult => {\n mark(id, action)\n try {\n const next = await run()\n patchRow(next)\n done(next)\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [mark, patchRow]\n )\n\n // A declined wallet prompt resolves to a `wallet_rejected` error.\n const cancel = useCallback(\n (id: string, reason: string, sendTransaction?: SendSolanaTransaction) =>\n act(\n id,\n \"cancel\",\n async () => {\n const sub = await client.cancelSubscription(id, { reason })\n if (!sub.next_action) return sub\n if (!isWalletAction(sub.next_action) || !sendTransaction)\n throw walletRequired()\n mark(id, \"signing\")\n const signature = await signWalletAction(\n sub.next_action,\n sendTransaction\n )\n mark(id, \"confirming\")\n return client.cancelSubscription(id, { reason, signature })\n },\n () => notify({ type: \"subscription.canceled\", subscriptionId: id })\n ),\n [act, client, mark, notify]\n )\n\n const resume = useCallback(\n (id: string) =>\n act(\n id,\n \"resume\",\n () => client.resumeSubscription(id),\n () => notify({ type: \"subscription.resumed\", subscriptionId: id })\n ),\n [act, client, notify]\n )\n\n const setPaymentMethod = useCallback(\n (id: string, paymentMethodId: string | null) =>\n act(\n id,\n \"payment_method\",\n () => client.setSubscriptionPaymentMethod(id, paymentMethodId),\n () =>\n notify({\n type: \"subscription.payment_method_changed\",\n subscriptionId: id,\n paymentMethodId,\n })\n ),\n [act, client, notify]\n )\n\n // An upgrade may open a successor subscription: notify refetches the list.\n const changeSubscription = useCallback(\n async (\n id: string,\n input: SubscriptionChangeInput & { idempotencyKey: string },\n sendTransaction?: SendSolanaTransaction\n ) => {\n mark(id, \"change\")\n try {\n let change = await client.changeSubscription(id, input)\n if (\n change.status === \"requires_action\" &&\n isWalletAction(change.next_action) &&\n sendTransaction\n ) {\n mark(id, \"signing\")\n const signature = await signWalletAction(\n change.next_action!,\n sendTransaction\n )\n mark(id, \"confirming\")\n change = await client.changeSubscription(id, { ...input, signature })\n }\n notify({\n type: \"subscription.changed\",\n subscriptionId: id,\n change,\n })\n return change\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify]\n )\n\n return {\n subscriptions: remote.data?.data ?? null,\n nextCursor: remote.data?.next_cursor ?? null,\n loading: remote.loading,\n error: remote.error,\n refetch: remote.refetch,\n pending,\n cancel,\n resume,\n setPaymentMethod,\n changeSubscription,\n }\n}\n\nexport type PaymentMethodAction = \"remove\" | \"default\"\n\nexport interface PaymentMethodsState {\n methods: PaymentMethod[] | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n pending: Readonly<Record<string, PaymentMethodAction>>\n adding: boolean\n add: (card: NewCard) => ActionResult\n remove: (paymentMethodId: string) => ActionResult\n /** Makes the card the default for the currency. */\n setDefault: (paymentMethodId: string, currency: string) => ActionResult\n}\n\nexport function usePaymentMethods(): PaymentMethodsState {\n const { client, version, notify } = useBillingContext()\n const remote = useRemote(`${version}`, (signal) =>\n client.listPaymentMethods({ signal })\n )\n const [pending, mark] = usePending<PaymentMethodAction>()\n const [adding, setAdding] = useState(false)\n const { replace } = remote\n\n const add = useCallback(\n async (card: NewCard): ActionResult => {\n setAdding(true)\n try {\n const method = await client.addPaymentMethod(card)\n replace((page) => ({ ...page, data: [...page.data, method] }))\n notify({ type: \"payment_method.added\", paymentMethodId: method.id })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n setAdding(false)\n }\n },\n [client, notify, replace]\n )\n\n const remove = useCallback(\n async (id: string): ActionResult => {\n mark(id, \"remove\")\n try {\n await client.removePaymentMethod(id)\n replace((page) => ({\n ...page,\n data: page.data.filter((m) => m.id !== id),\n }))\n notify({ type: \"payment_method.removed\", paymentMethodId: id })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify, replace]\n )\n\n const setDefault = useCallback(\n async (id: string, currency: string): ActionResult => {\n mark(id, \"default\")\n try {\n await client.setDefaultPaymentMethod({\n currency,\n paymentMethodId: id,\n })\n const code = currency.toUpperCase()\n replace((page) => ({\n ...page,\n data: page.data.map((m) => {\n const others = (m.default_currencies ?? []).filter(\n (c) => c !== code\n )\n return {\n ...m,\n default_currencies: m.id === id ? [...others, code] : others,\n }\n }),\n }))\n notify({\n type: \"payment_method.default_changed\",\n paymentMethodId: id,\n })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify, replace]\n )\n\n return {\n methods: remote.data?.data ?? null,\n loading: remote.loading,\n error: remote.error,\n refetch: remote.refetch,\n pending,\n adding,\n add,\n remove,\n setDefault,\n }\n}\n\nexport interface PaymentsOptions {\n pageSize?: number\n /** Filter by rail. */\n rail?: string\n}\n\nexport interface PaymentsState {\n payments: Payment[] | null\n /** The bills these payments settle, by order id: what each one bought. */\n orders: Record<string, Order>\n /** Zero-based. */\n page: number\n hasMore: boolean\n loading: boolean\n error: BillingError | null\n next: () => void\n previous: () => void\n refetch: () => void\n}\n\nconst noOrders: Record<string, Order> = {}\n\nexport function usePayments(options: PaymentsOptions = {}): PaymentsState {\n const { client, version } = useBillingContext()\n const pageSize = options.pageSize ?? 20\n // cursors[i] reads page i of this filter; page 0 is the newest payments.\n const filter = `${pageSize}|${options.rail ?? \"\"}`\n const [state, setState] = useState({\n filter,\n cursors: [null] as (string | null)[],\n })\n const cursors = useMemo(\n () => (state.filter === filter ? state.cursors : [null]),\n [state, filter]\n )\n const page = cursors.length - 1\n const cursor = cursors[page]\n const remote = useRemote(\n `${filter}|${cursor ?? \"\"}|${version}`,\n async (signal) => {\n const page = await client.listPayments({\n limit: pageSize,\n cursor,\n rail: options.rail,\n signal,\n })\n // One read names every payment on the page by the order it settles.\n const ids = [\n ...new Set(page.data.flatMap((p) => (p.order_id ? [p.order_id] : []))),\n ]\n const orders: Record<string, Order> = {}\n if (ids.length) {\n const bills = await client.listOrders({ ids, signal })\n for (const o of bills.data) orders[o.id] = o\n }\n return { ...page, orders }\n }\n )\n const data = remote.data\n const nextCursor = data?.next_cursor ?? null\n return {\n payments: data?.data ?? null,\n orders: data?.orders ?? noOrders,\n page,\n hasMore: nextCursor !== null,\n loading: remote.loading,\n error: remote.error,\n next: useCallback(() => {\n if (nextCursor !== null)\n setState({ filter, cursors: [...cursors, nextCursor] })\n }, [filter, cursors, nextCursor]),\n previous: useCallback(() => {\n if (cursors.length > 1)\n setState({ filter, cursors: cursors.slice(0, -1) })\n }, [filter, cursors]),\n refetch: remote.refetch,\n }\n}\n"],"mappings":";;;;;AAmEA,SAAgB,EACd,GACwB;CACxB,OAAO;AACT;AAEA,IAAa,IAAqC;AAIlD,SAAS,EAAU,GAAc,GAAoB;CACnD,IAAM,IAAY,EAAE,GAAG,EAAO;CAC9B,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAM,GAAG;EACjD,IAAI,KAAiC,MAAM;EAC3C,IAAM,IAAU,EAAI;EACpB,AAAI,OAAO,KAAU,WACf,MAAU,OAAI,EAAI,KAAO,KACxB,AAGL,EAAI,KAFO,EADF,OAAO,KAAY,WACP,IAEA,CAAC,GAFQ,CAEA;CAElC;CACA,OAAO;AACT;AAGA,SAAgB,EACd,GACmB;CACnB,IAAM,IAAO,IAAW,MAAM,QAAQ,CAAO,IAAI,IAAU,CAAC,CAAO,IAAK,CAAC,GACrE,IAAO;CACX,KAAK,IAAM,KAAU,GAAM,IAAO,EAAU,GAAM,CAAc;CAChE,OAAO;AACT;AAEA,SAAgB,EAAY,GAAkB,GAA4B;CAExE,OADK,IACE,EAAS,QAAQ,eAAe,GAAO,MAC5C,KAAQ,IAAO,OAAO,EAAK,EAAK,IAAI,CACtC,IAHkB;AAIpB;AAEA,SAAS,EAAO,GAA6B,GAAiC;CAC5E,IAAI,IAAgB;CACpB,KAAK,IAAM,KAAQ,EAAI,MAAM,GAAG,GAAG;EACjC,IAAI,CAAC,KAAQ,OAAO,KAAS,UAAU;EACvC,IAAQ,EAAc;CACxB;CACA,OAAO,OAAO,KAAS,WAAW,IAAO,KAAA;AAC3C;AAgBA,SAAS,EAAU,GAAoC;CACrD,IAAI,OAAO,KAAU,UAAU,OAAO;CACtC,IAAI,KAAS,OAAO,KAAU,YAAY,UAAU,GAAO;EACzD,IAAM,IAAQ,EAA4B;EAC1C,IAAI,OAAO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