@openrails/billing-ui 0.241.0 → 0.243.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.
Files changed (265) hide show
  1. package/CHANGELOG.md +27 -11
  2. package/README.md +41 -8
  3. package/dist/admin/billing-admin.d.ts +3 -0
  4. package/dist/admin/components/app-sidebar.d.ts +1 -0
  5. package/dist/admin/components/confirm.d.ts +4 -0
  6. package/dist/admin/components/cursor-pager.d.ts +8 -0
  7. package/dist/admin/components/data-table.d.ts +14 -0
  8. package/dist/admin/components/fact-card.d.ts +5 -0
  9. package/dist/admin/components/form-field-errors.d.ts +3 -0
  10. package/dist/admin/components/linked-table-row.d.ts +5 -0
  11. package/dist/admin/components/logo.d.ts +3 -0
  12. package/dist/admin/components/no-access.d.ts +3 -0
  13. package/dist/admin/components/no-merchants.d.ts +1 -0
  14. package/dist/admin/components/notification-bell.d.ts +2 -0
  15. package/dist/admin/components/route-error.d.ts +3 -0
  16. package/dist/admin/components/site-header.d.ts +9 -0
  17. package/dist/admin/components/status-badge.d.ts +3 -0
  18. package/dist/admin/components/typed-confirm-dialog.d.ts +11 -0
  19. package/dist/admin/components/ui/alert-dialog.d.ts +18 -0
  20. package/dist/admin/components/ui/avatar.d.ts +11 -0
  21. package/dist/admin/components/ui/badge.d.ts +7 -0
  22. package/dist/admin/components/ui/breadcrumb.d.ts +10 -0
  23. package/dist/admin/components/ui/button.d.ts +8 -0
  24. package/dist/admin/components/ui/card.d.ts +11 -0
  25. package/dist/admin/components/ui/chart.d.ts +44 -0
  26. package/dist/admin/components/ui/dialog.d.ts +17 -0
  27. package/dist/admin/components/ui/dropdown-menu.d.ts +29 -0
  28. package/dist/admin/components/ui/input.d.ts +3 -0
  29. package/dist/admin/components/ui/label.d.ts +3 -0
  30. package/dist/admin/components/ui/select.d.ts +15 -0
  31. package/dist/admin/components/ui/separator.d.ts +3 -0
  32. package/dist/admin/components/ui/sheet.d.ts +14 -0
  33. package/dist/admin/components/ui/sidebar.d.ts +63 -0
  34. package/dist/admin/components/ui/skeleton.d.ts +2 -0
  35. package/dist/admin/components/ui/sonner.d.ts +3 -0
  36. package/dist/admin/components/ui/switch.d.ts +5 -0
  37. package/dist/admin/components/ui/table.d.ts +10 -0
  38. package/dist/admin/components/ui/tabs.d.ts +10 -0
  39. package/dist/admin/components/ui/textarea.d.ts +3 -0
  40. package/dist/admin/components/ui/tooltip.d.ts +6 -0
  41. package/dist/admin/context.d.ts +1193 -0
  42. package/dist/admin/hooks/use-mobile.d.ts +1 -0
  43. package/dist/admin/index.d.ts +5 -0
  44. package/dist/admin/layouts/app-layout.d.ts +4 -0
  45. package/dist/admin/lib/api/client.d.ts +64 -0
  46. package/dist/admin/lib/api/copilot.d.ts +6 -0
  47. package/dist/admin/lib/api/credit-endpoints.d.ts +8 -0
  48. package/dist/admin/lib/api/credit-types.d.ts +9 -0
  49. package/dist/admin/lib/api/endpoints.d.ts +133 -0
  50. package/dist/admin/lib/api/index.d.ts +89 -0
  51. package/dist/admin/lib/api/invoice-profile-endpoints.d.ts +6 -0
  52. package/dist/admin/lib/api/metrics.d.ts +68 -0
  53. package/dist/admin/lib/api/order-endpoints.d.ts +21 -0
  54. package/dist/admin/lib/api/types.d.ts +122 -0
  55. package/dist/admin/lib/auth.d.ts +6 -0
  56. package/dist/admin/lib/capabilities.d.ts +13 -0
  57. package/dist/admin/lib/chunk-error.d.ts +1 -0
  58. package/dist/admin/lib/confirm.d.ts +11 -0
  59. package/dist/admin/lib/credit-queries.d.ts +23 -0
  60. package/dist/admin/lib/csv.d.ts +3 -0
  61. package/dist/admin/lib/cursor-pages.d.ts +13 -0
  62. package/dist/admin/lib/dialog-width.d.ts +6 -0
  63. package/dist/admin/lib/dom.d.ts +1 -0
  64. package/dist/admin/lib/duration.d.ts +3 -0
  65. package/dist/admin/lib/format.d.ts +23 -0
  66. package/dist/admin/lib/mount.d.ts +6 -0
  67. package/dist/admin/lib/mutations.d.ts +125 -0
  68. package/dist/admin/lib/order-queries.d.ts +29 -0
  69. package/dist/admin/lib/queries.d.ts +369 -0
  70. package/dist/admin/lib/query-client.d.ts +3 -0
  71. package/dist/admin/lib/toast.d.ts +10 -0
  72. package/dist/admin/lib/utils.d.ts +2 -0
  73. package/dist/admin/messages.d.ts +670 -0
  74. package/dist/admin/navigation.d.ts +14 -0
  75. package/dist/admin/pages/catalog/application-dialog.d.ts +2 -0
  76. package/dist/admin/pages/catalog/copilot-panel.d.ts +4 -0
  77. package/dist/admin/pages/catalog/index.d.ts +4 -0
  78. package/dist/admin/pages/catalog/meter-form.d.ts +6 -0
  79. package/dist/admin/pages/catalog/metering-model.d.ts +67 -0
  80. package/dist/admin/pages/catalog/metering.d.ts +3 -0
  81. package/dist/admin/pages/catalog/price-detail.d.ts +2 -0
  82. package/dist/admin/pages/catalog/price-format.d.ts +3 -0
  83. package/dist/admin/pages/catalog/price-wizard-logic.d.ts +20 -0
  84. package/dist/admin/pages/catalog/price-wizard.d.ts +10 -0
  85. package/dist/admin/pages/catalog/psp-links.d.ts +10 -0
  86. package/dist/admin/pages/catalog/rate-card-editor.d.ts +10 -0
  87. package/dist/admin/pages/customers/credit-form.d.ts +14 -0
  88. package/dist/admin/pages/customers/credits.d.ts +5 -0
  89. package/dist/admin/pages/customers/default-card-badges.d.ts +3 -0
  90. package/dist/admin/pages/customers/detail.d.ts +5 -0
  91. package/dist/admin/pages/customers/grant-duration.d.ts +32 -0
  92. package/dist/admin/pages/customers/index.d.ts +2 -0
  93. package/dist/admin/pages/customers/invoice-profile-model.d.ts +18 -0
  94. package/dist/admin/pages/customers/invoice-profile.d.ts +9 -0
  95. package/dist/admin/pages/dashboard/index.d.ts +2 -0
  96. package/dist/admin/pages/dashboard/lib.d.ts +48 -0
  97. package/dist/admin/pages/dashboard/range-picker.d.ts +1 -0
  98. package/dist/admin/pages/dashboard/range.d.ts +34 -0
  99. package/dist/admin/pages/dashboard/reports-model.d.ts +29 -0
  100. package/dist/admin/pages/dashboard/reports.d.ts +2 -0
  101. package/dist/admin/pages/dashboard/use-range.d.ts +5 -0
  102. package/dist/admin/pages/dashboard/widget-editor.d.ts +8 -0
  103. package/dist/admin/pages/dashboard/widget-tile.d.ts +9 -0
  104. package/dist/admin/pages/dashboard/widget-viz.d.ts +12 -0
  105. package/dist/admin/pages/ops/index.d.ts +2 -0
  106. package/dist/admin/pages/orders/detail.d.ts +5 -0
  107. package/dist/admin/pages/orders/index.d.ts +1 -0
  108. package/dist/admin/pages/orders/model.d.ts +7 -0
  109. package/dist/admin/pages/payments/attempts.d.ts +7 -0
  110. package/dist/admin/pages/payments/detail.d.ts +2 -0
  111. package/dist/admin/pages/payments/health-model.d.ts +149 -0
  112. package/dist/admin/pages/payments/health.d.ts +2 -0
  113. package/dist/admin/pages/payments/index.d.ts +2 -0
  114. package/dist/admin/pages/settings/configuration-edit.d.ts +9 -0
  115. package/dist/admin/pages/settings/index.d.ts +9 -0
  116. package/dist/admin/pages/settings/notifications.d.ts +2 -0
  117. package/dist/admin/pages/settings/setting-fields.d.ts +20 -0
  118. package/dist/admin/pages/subscriptions/change-subscription-dialog.d.ts +16 -0
  119. package/dist/admin/pages/subscriptions/detail.d.ts +2 -0
  120. package/dist/admin/pages/subscriptions/dunning.d.ts +2 -0
  121. package/dist/admin/pages/subscriptions/index.d.ts +2 -0
  122. package/dist/admin/pages/subscriptions/subscription-change-options.d.ts +23 -0
  123. package/dist/admin/pages/subscriptions/views.d.ts +15 -0
  124. package/dist/admin/router.d.ts +32 -0
  125. package/dist/admin/routes.d.ts +5 -0
  126. package/dist/admin/summary.d.ts +27 -0
  127. package/dist/admin/theme.d.ts +2 -0
  128. package/dist/admin/types.d.ts +56 -0
  129. package/dist/admin/ui-context.d.ts +14 -0
  130. package/dist/admin-attempts-lAoW-Urd.js +419 -0
  131. package/dist/admin-attempts-lAoW-Urd.js.map +1 -0
  132. package/dist/admin-auth-DQGHtt0j.js +14 -0
  133. package/dist/admin-auth-DQGHtt0j.js.map +1 -0
  134. package/dist/admin-badge-DR5-1qd8.js +31 -0
  135. package/dist/admin-badge-DR5-1qd8.js.map +1 -0
  136. package/dist/admin-button-CTL3DgOt.js +46 -0
  137. package/dist/admin-button-CTL3DgOt.js.map +1 -0
  138. package/dist/admin-capabilities-BuigAgtm.js +59 -0
  139. package/dist/admin-capabilities-BuigAgtm.js.map +1 -0
  140. package/dist/admin-card-bzAks3-3.js +51 -0
  141. package/dist/admin-card-bzAks3-3.js.map +1 -0
  142. package/dist/admin-catalog-CC7I4n0_.js +1189 -0
  143. package/dist/admin-catalog-CC7I4n0_.js.map +1 -0
  144. package/dist/admin-confirm-katGq0Qo.js +12 -0
  145. package/dist/admin-confirm-katGq0Qo.js.map +1 -0
  146. package/dist/admin-csv-CPoNZj2D.js +16 -0
  147. package/dist/admin-csv-CPoNZj2D.js.map +1 -0
  148. package/dist/admin-customers-D8u5gq3M.js +160 -0
  149. package/dist/admin-customers-D8u5gq3M.js.map +1 -0
  150. package/dist/admin-dashboard-DqqFjOzq.js +420 -0
  151. package/dist/admin-dashboard-DqqFjOzq.js.map +1 -0
  152. package/dist/admin-data-table-qfXLOFmN.js +96 -0
  153. package/dist/admin-data-table-qfXLOFmN.js.map +1 -0
  154. package/dist/admin-detail-5aNNvrc0.js +324 -0
  155. package/dist/admin-detail-5aNNvrc0.js.map +1 -0
  156. package/dist/admin-detail-7p684Uyc.js +342 -0
  157. package/dist/admin-detail-7p684Uyc.js.map +1 -0
  158. package/dist/admin-detail-CGOyqs7s.js +1312 -0
  159. package/dist/admin-detail-CGOyqs7s.js.map +1 -0
  160. package/dist/admin-detail-DUAJQg8G.js +710 -0
  161. package/dist/admin-detail-DUAJQg8G.js.map +1 -0
  162. package/dist/admin-dialog-BjuKI5Hp.js +88 -0
  163. package/dist/admin-dialog-BjuKI5Hp.js.map +1 -0
  164. package/dist/admin-dialog-width-BPrgdYlj.js +6 -0
  165. package/dist/admin-dialog-width-BPrgdYlj.js.map +1 -0
  166. package/dist/admin-dom-uMmZzRvU.js +149 -0
  167. package/dist/admin-dom-uMmZzRvU.js.map +1 -0
  168. package/dist/admin-dropdown-menu-BW1D_h6s.js +69 -0
  169. package/dist/admin-dropdown-menu-BW1D_h6s.js.map +1 -0
  170. package/dist/admin-dunning-B2zgtrOo.js +10 -0
  171. package/dist/admin-dunning-B2zgtrOo.js.map +1 -0
  172. package/dist/admin-fact-card-DO_fHosg.js +20 -0
  173. package/dist/admin-fact-card-DO_fHosg.js.map +1 -0
  174. package/dist/admin-form-field-errors-hbUMIriS.js +14 -0
  175. package/dist/admin-form-field-errors-hbUMIriS.js.map +1 -0
  176. package/dist/admin-format-DoohJ7Fg.js +136 -0
  177. package/dist/admin-format-DoohJ7Fg.js.map +1 -0
  178. package/dist/admin-health-B4jN2LwR.js +983 -0
  179. package/dist/admin-health-B4jN2LwR.js.map +1 -0
  180. package/dist/admin-input-CcfQfJFN.js +17 -0
  181. package/dist/admin-input-CcfQfJFN.js.map +1 -0
  182. package/dist/admin-invoice-profile-model-Cgjy3zV8.js +53 -0
  183. package/dist/admin-invoice-profile-model-Cgjy3zV8.js.map +1 -0
  184. package/dist/admin-label-BiEN5cjb.js +15 -0
  185. package/dist/admin-label-BiEN5cjb.js.map +1 -0
  186. package/dist/admin-linked-table-row-BsaUruCN.js +26 -0
  187. package/dist/admin-linked-table-row-BsaUruCN.js.map +1 -0
  188. package/dist/admin-metering-BGAXbT23.js +1702 -0
  189. package/dist/admin-metering-BGAXbT23.js.map +1 -0
  190. package/dist/admin-ops-B3mcr76u.js +217 -0
  191. package/dist/admin-ops-B3mcr76u.js.map +1 -0
  192. package/dist/admin-orders-dxC99Idl.js +192 -0
  193. package/dist/admin-orders-dxC99Idl.js.map +1 -0
  194. package/dist/admin-payments-Bs7HSfP0.js +246 -0
  195. package/dist/admin-payments-Bs7HSfP0.js.map +1 -0
  196. package/dist/admin-price-detail-DRquxpA9.js +482 -0
  197. package/dist/admin-price-detail-DRquxpA9.js.map +1 -0
  198. package/dist/admin-price-format-DM1qORWI.js +44 -0
  199. package/dist/admin-price-format-DM1qORWI.js.map +1 -0
  200. package/dist/admin-price-wizard-CI7K-2Nz.js +357 -0
  201. package/dist/admin-price-wizard-CI7K-2Nz.js.map +1 -0
  202. package/dist/admin-range-picker-Dr2M1EZr.js +192 -0
  203. package/dist/admin-range-picker-Dr2M1EZr.js.map +1 -0
  204. package/dist/admin-reports-CywKLiSA.js +320 -0
  205. package/dist/admin-reports-CywKLiSA.js.map +1 -0
  206. package/dist/admin-select-DBgprVW6.js +81 -0
  207. package/dist/admin-select-DBgprVW6.js.map +1 -0
  208. package/dist/admin-settings-Bmoy95uO.js +1434 -0
  209. package/dist/admin-settings-Bmoy95uO.js.map +1 -0
  210. package/dist/admin-skeleton-DsM7crYi.js +14 -0
  211. package/dist/admin-skeleton-DsM7crYi.js.map +1 -0
  212. package/dist/admin-status-badge-BFPgo71d.js +38 -0
  213. package/dist/admin-status-badge-BFPgo71d.js.map +1 -0
  214. package/dist/admin-subscriptions-CLYc_HEV.js +301 -0
  215. package/dist/admin-subscriptions-CLYc_HEV.js.map +1 -0
  216. package/dist/admin-switch-BJUxLCsa.js +20 -0
  217. package/dist/admin-switch-BJUxLCsa.js.map +1 -0
  218. package/dist/admin-table-CH9TrXJf.js +61 -0
  219. package/dist/admin-table-CH9TrXJf.js.map +1 -0
  220. package/dist/admin-tabs-528FJMjt.js +46 -0
  221. package/dist/admin-tabs-528FJMjt.js.map +1 -0
  222. package/dist/admin-textarea-DEz38RaI.js +15 -0
  223. package/dist/admin-textarea-DEz38RaI.js.map +1 -0
  224. package/dist/admin-typed-confirm-dialog-DU7m9-O7.js +66 -0
  225. package/dist/admin-typed-confirm-dialog-DU7m9-O7.js.map +1 -0
  226. package/dist/admin-utils-BK4Vh1o_.js +1809 -0
  227. package/dist/admin-utils-BK4Vh1o_.js.map +1 -0
  228. package/dist/admin-widget-viz-Da48c-Zf.js +581 -0
  229. package/dist/admin-widget-viz-Da48c-Zf.js.map +1 -0
  230. package/dist/admin.css +3 -0
  231. package/dist/admin.js +2164 -0
  232. package/dist/admin.js.map +1 -0
  233. package/dist/appearance.d.ts +1 -1
  234. package/dist/client/generated/error-codes.d.ts +1 -1
  235. package/dist/client/generated/routes.d.ts +2156 -189
  236. package/dist/client/generated/wire.d.ts +1265 -50
  237. package/dist/client/types.d.ts +0 -1
  238. package/dist/{client-Cxz_miQj.js → client-PjivPHmE.js} +2 -3
  239. package/dist/client-PjivPHmE.js.map +1 -0
  240. package/dist/client.js +1 -1
  241. package/dist/{hooks-aKefXeMO.js → hooks-Ckd8F2JF.js} +8 -8
  242. package/dist/hooks-Ckd8F2JF.js.map +1 -0
  243. package/dist/index.d.ts +1 -1
  244. package/dist/index.js +12 -12
  245. package/dist/index.js.map +1 -1
  246. package/dist/lib/{offer-label.d.ts → price-label.d.ts} +1 -1
  247. package/dist/locales/de.js +1 -1
  248. package/dist/locales/de.js.map +1 -1
  249. package/dist/locales/en.d.ts +1 -1
  250. package/dist/locales/en.js +1 -1
  251. package/dist/locales/en.js.map +1 -1
  252. package/dist/locales/es.js +1 -1
  253. package/dist/locales/es.js.map +1 -1
  254. package/dist/locales/ja.js +1 -1
  255. package/dist/locales/ja.js.map +1 -1
  256. package/dist/locales/ko.js +1 -1
  257. package/dist/locales/ko.js.map +1 -1
  258. package/dist/locales/zh.js +1 -1
  259. package/dist/locales/zh.js.map +1 -1
  260. package/dist/{offers.d.ts → product-list.d.ts} +5 -5
  261. package/dist/react.js +1 -1
  262. package/dist/styles.css +1 -1
  263. package/package.json +28 -6
  264. package/dist/client-Cxz_miQj.js.map +0 -1
  265. package/dist/hooks-aKefXeMO.js.map +0 -1
@@ -0,0 +1,1809 @@
1
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i, useState as a, useSyncExternalStore as o } from "react";
2
+ import { keepPreviousData as s, mutationOptions as c, queryOptions as l } from "@tanstack/react-query";
3
+ import { toast as u } from "sonner";
4
+ import { jsx as d } from "react/jsx-runtime";
5
+ import { clsx as f } from "clsx";
6
+ import { twMerge as p } from "tailwind-merge";
7
+ //#region src/admin/ui-context.tsx
8
+ var m = e({ namespace: "" });
9
+ function h() {
10
+ let e = n(m);
11
+ function t(t) {
12
+ return t === void 0 ? void 0 : `${e.namespace}${t}`;
13
+ }
14
+ return {
15
+ text: (t) => e.messages?.[t] ?? t,
16
+ id: t
17
+ };
18
+ }
19
+ function g({ id: e }) {
20
+ return h().text(e);
21
+ }
22
+ //#endregion
23
+ //#region src/admin/lib/api/client.ts
24
+ var _ = class extends Error {
25
+ status;
26
+ type;
27
+ code;
28
+ param;
29
+ metadata;
30
+ constructor(e, t, n) {
31
+ super(t?.error?.message || n), this.status = e, this.type = t?.error?.type, this.code = t?.error?.code, this.param = t?.error?.param, this.metadata = t?.error?.metadata;
32
+ }
33
+ get isPermissionDenied() {
34
+ return this.status === 403;
35
+ }
36
+ get revisionMismatch() {
37
+ return this.status === 409 && this.code === "revision_mismatch";
38
+ }
39
+ get merchantConfigReadOnly() {
40
+ return this.status === 409 && this.code === "merchant_config_read_only";
41
+ }
42
+ };
43
+ async function v(e) {
44
+ let t = null;
45
+ try {
46
+ t = await e.json();
47
+ } catch {}
48
+ return new _(e.status, t, `request failed (${e.status})`);
49
+ }
50
+ function y(e, t, n) {
51
+ let r = e + t;
52
+ if (n) {
53
+ let e = new URLSearchParams();
54
+ for (let [t, r] of Object.entries(n)) r !== void 0 && r !== "" && e.set(t, String(r));
55
+ let t = e.toString();
56
+ t && (r += `?${t}`);
57
+ }
58
+ return r;
59
+ }
60
+ async function b(e, t) {
61
+ let n = [], r;
62
+ for (;;) {
63
+ t?.throwIfAborted();
64
+ let i = await e(r);
65
+ if (n.push(...i.data), !i.next_cursor) return n;
66
+ if (i.next_cursor === r) throw Error("List paging stopped before all records were loaded");
67
+ r = i.next_cursor;
68
+ }
69
+ }
70
+ function x(e) {
71
+ let t = e.baseUrl.replace(/\/$/, ""), n = () => e.isCurrent && !e.isCurrent() ? void 0 : e.merchant?.slug;
72
+ async function r(n, r) {
73
+ let i = { ...r.headers };
74
+ r.body !== void 0 && (i["Content-Type"] = "application/json");
75
+ let a = {
76
+ method: r.method ?? "GET",
77
+ headers: i,
78
+ signal: r.signal,
79
+ body: r.rawBody ?? (r.body === void 0 ? void 0 : JSON.stringify(r.body))
80
+ }, o = y(t, n, r.query), s;
81
+ if (e.exchange) {
82
+ if (!e.merchant?.id || !e.auth.resourceFetch) throw Error("Merchant token exchange needs a merchant id and resourceFetch transport");
83
+ try {
84
+ s = await e.auth.resourceFetch(o, {
85
+ ...a,
86
+ ...e.exchange,
87
+ group: e.merchant.id
88
+ });
89
+ } catch (e) {
90
+ throw e && typeof e == "object" && "error" in e && e.error === "invalid_target" ? new _(403, { error: {
91
+ code: "merchant_unresolved",
92
+ message: "You hold no role at this merchant."
93
+ } }, "Merchant refused") : e;
94
+ }
95
+ } else s = await e.auth.authFetch(o, a);
96
+ if (!s.ok) throw await v(s);
97
+ return {
98
+ status: s.status,
99
+ body: s.status === 204 ? void 0 : await s.json()
100
+ };
101
+ }
102
+ async function i(e, t = {}) {
103
+ return r(e, t);
104
+ }
105
+ return {
106
+ namespace: e.namespace,
107
+ api: async (e, t = {}) => (await i(e, t)).body,
108
+ apiResponse: i,
109
+ selectedMerchant: n,
110
+ queryRoot: (t) => {
111
+ let n = t !== void 0 && t !== e.merchant?.slug && t !== e.merchant?.id ? t : e.merchant?.id || e.merchant?.slug || "unselected";
112
+ return [
113
+ ...e.namespace ? ["billing-admin", e.namespace] : [],
114
+ "merchant",
115
+ n
116
+ ];
117
+ }
118
+ };
119
+ }
120
+ //#endregion
121
+ //#region src/admin/lib/api/endpoints.ts
122
+ var S = [
123
+ "kind",
124
+ "owner",
125
+ "category",
126
+ "reason",
127
+ "response_code",
128
+ "card_entry",
129
+ "source",
130
+ "observed_via",
131
+ "avs_result",
132
+ "cvv_result",
133
+ "psp_id",
134
+ "customer_id",
135
+ "payment_id",
136
+ "order_id",
137
+ "subscription_id",
138
+ "cycle_id",
139
+ "since",
140
+ "until"
141
+ ], C = [
142
+ "owner",
143
+ "first_outcome",
144
+ "miss_reason",
145
+ "outcome",
146
+ "psp_id",
147
+ "subscription_id",
148
+ "due_since",
149
+ "due_until"
150
+ ];
151
+ function w(e, t) {
152
+ let n = {};
153
+ for (let r of t) {
154
+ let t = e.get(r)?.trim();
155
+ t && (n[r] = t);
156
+ }
157
+ return n;
158
+ }
159
+ var T = ["nmi", "stripe"];
160
+ function E(e) {
161
+ let { api: t } = e, n = (e, n, r, i) => t("/admin/customers", {
162
+ query: {
163
+ search: e,
164
+ limit: n,
165
+ cursor: r
166
+ },
167
+ signal: i
168
+ }), r = (e, n) => t(`/admin/customers/${e}`, { signal: n }), i = (e, n, r) => t("/admin/entitlements", {
169
+ query: {
170
+ customer_id: e,
171
+ ...n
172
+ },
173
+ signal: r
174
+ }), a = (e, n, r) => t("/admin/product-access", {
175
+ query: {
176
+ customer_id: e,
177
+ ...n
178
+ },
179
+ signal: r
180
+ }), o = (e, n, r) => t(`/admin/customers/${e}/payment-methods`, {
181
+ query: { ...n },
182
+ signal: r
183
+ }), s = (e, n) => t("/admin/product-access", {
184
+ method: "POST",
185
+ body: { items: [{
186
+ customer_id: e,
187
+ product_id: n.productId,
188
+ ...n.hours ? { hours: n.hours } : {},
189
+ ...n.endsAt ? { ends_at: n.endsAt } : {},
190
+ ...n.reason ? { reason: n.reason } : {},
191
+ ...n.note ? { note: n.note } : {}
192
+ }] }
193
+ }), c = (e, n) => t(`/admin/product-access/${e}/revoke`, {
194
+ method: "POST",
195
+ body: { reason: n }
196
+ }), l = (e, n, r, i) => t("/admin/subscriptions", {
197
+ query: {
198
+ ...e,
199
+ limit: n,
200
+ ...r ? { cursor: r } : {}
201
+ },
202
+ signal: i
203
+ }), u = (e, n) => t(`/admin/subscriptions/${e}`, { signal: n }), d = (e, n, r) => t(`/admin/subscriptions/${e}/cancel`, {
204
+ method: "POST",
205
+ body: {
206
+ reason: n,
207
+ revoke_access: r
208
+ }
209
+ }), f = (e) => t(`/admin/subscriptions/${e}/resume`, { method: "POST" }), p = (e, n) => t(`/admin/subscriptions/${e}/payment-method`, {
210
+ method: "PUT",
211
+ body: { payment_method_id: n }
212
+ }), m = (e, n) => t(`/admin/subscriptions/${e}/change/preview`, {
213
+ method: "POST",
214
+ body: n
215
+ }), h = (e, n, r) => t(`/admin/subscriptions/${e}/change`, {
216
+ method: "POST",
217
+ headers: { "Idempotency-Key": r },
218
+ body: n
219
+ }), g = (e, n, r) => t("/admin/payments", {
220
+ query: {
221
+ ...e,
222
+ ...n
223
+ },
224
+ signal: r
225
+ }), _ = (e, n) => t(`/admin/payments/${e}`, { signal: n }), v = (e, n, r, i) => {
226
+ let a = {
227
+ amount: n,
228
+ reason: r || void 0,
229
+ revoke_access: i
230
+ };
231
+ return t(`/admin/payments/${e}/refunds`, {
232
+ method: "POST",
233
+ headers: { "Idempotency-Key": crypto.randomUUID() },
234
+ body: a
235
+ });
236
+ }, y = (e, n, r) => t("/admin/payment-attempts", {
237
+ query: {
238
+ ...e,
239
+ ...n
240
+ },
241
+ signal: r
242
+ }), b = (e, n) => t(`/admin/payment-attempts/${e}`, { signal: n }), x = (e, n, r) => t("/admin/renewals", {
243
+ query: {
244
+ ...e,
245
+ ...n
246
+ },
247
+ signal: r
248
+ }), S = (e, n) => t(`/admin/renewals/${e}`, { signal: n }), C = (e, n, r, i) => t("/catalog/products", {
249
+ query: {
250
+ limit: e,
251
+ cursor: n,
252
+ archived: r
253
+ },
254
+ signal: i
255
+ }), w = (e, n) => t(`/catalog/products/${e}`, { signal: n }), T = (e) => t("/catalog/products", {
256
+ method: "POST",
257
+ body: e
258
+ }), E = (e, n) => t(`/catalog/products/${e}`, {
259
+ method: "PATCH",
260
+ body: n
261
+ }), D = (e = 500, n, r) => t("/catalog/meters", {
262
+ query: {
263
+ limit: e,
264
+ cursor: n
265
+ },
266
+ signal: r
267
+ }), O = (e, n) => t(`/catalog/meters/${encodeURIComponent(e)}`, { signal: n }), k = (e, n) => t(`/catalog/meters/${encodeURIComponent(e)}`, {
268
+ method: "PUT",
269
+ body: n
270
+ }), A = (e, t) => k(e.key, {
271
+ event_type: e.event_type,
272
+ value_property: e.value_property,
273
+ aggregation: e.aggregation,
274
+ unit: e.unit,
275
+ group_by: e.group_by ?? {},
276
+ rate_card: t,
277
+ expected_revision: e.revision
278
+ }), j = (e, n, r, i) => t("/catalog/prices", {
279
+ query: {
280
+ limit: e,
281
+ cursor: n,
282
+ product_id: r
283
+ },
284
+ signal: i
285
+ }), M = (e) => t("/catalog/prices", {
286
+ method: "POST",
287
+ body: e
288
+ }), N = (e, n = !1, r) => t(`/catalog/prices/${encodeURIComponent(e)}`, {
289
+ query: n ? { verify: !0 } : void 0,
290
+ signal: r
291
+ }), P = async (e) => {
292
+ let n = (await t("/catalog/products", { query: { keys: e } })).data[0];
293
+ if (!n) throw Error(`No product ${e}`);
294
+ return n;
295
+ }, F = (e, n) => t(`/catalog/prices/${encodeURIComponent(e)}`, {
296
+ method: "PATCH",
297
+ body: n
298
+ }), I = (e, n) => t(`/catalog/prices/${encodeURIComponent(e)}/history`, {
299
+ query: { limit: 500 },
300
+ signal: n
301
+ }), L = (e, n) => t("/catalog/price-migrations/preview", {
302
+ method: "POST",
303
+ body: {
304
+ product_key: e,
305
+ price_key: n
306
+ }
307
+ }), R = (e, n, r, i) => t("/catalog/price-migrations", {
308
+ method: "POST",
309
+ body: {
310
+ product_key: e,
311
+ price_key: n,
312
+ to_price_id: r,
313
+ effective_at: i
314
+ }
315
+ }), z = (e, n, r = 20, i) => t("/catalog/price-migrations", {
316
+ query: {
317
+ product_key: e,
318
+ price_key: n,
319
+ limit: r
320
+ },
321
+ signal: i
322
+ }), B = (e) => t(`/catalog/price-migrations/${e}/cancel`, { method: "POST" }), V = (e, n = !1) => t("/catalog/apply", {
323
+ method: "POST",
324
+ rawBody: e,
325
+ headers: { "Content-Type": "application/yaml" },
326
+ ...n ? { query: { force: "true" } } : {}
327
+ }), H = () => t("/merchant/psps/refresh", { method: "POST" }), U = (e, n, r) => t("/merchant/findings", {
328
+ query: {
329
+ ...e,
330
+ limit: n
331
+ },
332
+ signal: r
333
+ }), W = (e) => t(`/merchant/findings/${e}`), G = (e, n, r) => t(`/merchant/findings/${e}/resolve`, {
334
+ method: "POST",
335
+ body: {
336
+ outcome: n,
337
+ notes: r
338
+ }
339
+ }), K = (e) => t("/merchant/configuration", { signal: e }), q = (e) => t("/merchant/configuration", {
340
+ method: "PATCH",
341
+ body: e
342
+ }), J = (e) => t("/merchant/psps?limit=500", { signal: e }), Y = async (e) => (await Q(e)).rails, X = (e) => t("/merchant/psps", {
343
+ method: "POST",
344
+ body: e
345
+ }), ee = (e, n) => t(`/merchant/psps/${encodeURIComponent(e)}`, {
346
+ method: "PATCH",
347
+ body: n
348
+ }), Z = (e, n) => t("/merchant/psps/routing-preview", {
349
+ method: "POST",
350
+ body: e,
351
+ signal: n
352
+ }), Q = (e) => t("/config", { signal: e });
353
+ return {
354
+ listCustomers: n,
355
+ getCustomer: r,
356
+ listCustomerEntitlements: i,
357
+ listCustomerProductAccess: a,
358
+ listCustomerPaymentMethods: o,
359
+ grantProductAccess: s,
360
+ revokeProductAccess: c,
361
+ listSubscriptions: l,
362
+ getSubscription: u,
363
+ cancelSubscription: d,
364
+ resumeSubscription: f,
365
+ changeSubscriptionPaymentMethod: p,
366
+ previewSubscriptionChange: m,
367
+ changeSubscription: h,
368
+ listPayments: g,
369
+ getPayment: _,
370
+ refundPayment: v,
371
+ listPaymentAttempts: y,
372
+ getPaymentAttempt: b,
373
+ listRenewals: x,
374
+ getRenewal: S,
375
+ listProducts: C,
376
+ getProduct: w,
377
+ createProduct: T,
378
+ updateProduct: E,
379
+ listUsageMeters: D,
380
+ getUsageMeter: O,
381
+ putUsageMeter: k,
382
+ putUsageMeterRateCard: A,
383
+ listPrices: j,
384
+ createPrice: M,
385
+ getPrice: N,
386
+ getProductByKey: P,
387
+ updatePrice: F,
388
+ getPriceHistory: I,
389
+ previewPriceMigration: L,
390
+ createPriceMigration: R,
391
+ listPriceMigrations: z,
392
+ cancelPriceMigration: B,
393
+ applyCatalog: V,
394
+ refreshPSPs: H,
395
+ listFindings: U,
396
+ getFinding: W,
397
+ resolveFinding: G,
398
+ getMerchantConfiguration: K,
399
+ updateMerchantConfiguration: q,
400
+ listPSPs: J,
401
+ listRails: Y,
402
+ createPSP: X,
403
+ updatePSP: ee,
404
+ previewPSPRouting: Z,
405
+ getConfig: Q,
406
+ getAdminAccess: (e) => t("/admin/access", { signal: e }),
407
+ updateCustomer: (e, n) => t(`/admin/customers/${e}`, {
408
+ method: "PATCH",
409
+ body: n
410
+ }),
411
+ listWebhooks: (e) => t("/merchant/alert-webhooks", { signal: e }),
412
+ createWebhook: (e) => t("/merchant/alert-webhooks", {
413
+ method: "POST",
414
+ body: e
415
+ }),
416
+ updateWebhook: (e, n) => t(`/merchant/alert-webhooks/${e}`, {
417
+ method: "PATCH",
418
+ body: n
419
+ }),
420
+ deleteWebhook: (e) => t(`/merchant/alert-webhooks/${e}`, { method: "DELETE" })
421
+ };
422
+ }
423
+ //#endregion
424
+ //#region src/admin/lib/api/metrics.ts
425
+ var D = [
426
+ "stat",
427
+ "line",
428
+ "area",
429
+ "bar",
430
+ "donut",
431
+ "table"
432
+ ];
433
+ function O(e) {
434
+ let { api: t } = e;
435
+ return {
436
+ metricsQuery: (e, n) => t("/metrics/query", {
437
+ method: "POST",
438
+ body: e,
439
+ signal: n
440
+ }),
441
+ getDashboard: (e) => t("/metrics/dashboard", { signal: e }),
442
+ putDashboard: (e) => t("/merchant/dashboard", {
443
+ method: "PUT",
444
+ body: { widgets: e }
445
+ })
446
+ };
447
+ }
448
+ //#endregion
449
+ //#region src/admin/lib/api/copilot.ts
450
+ function k(e) {
451
+ let { api: t } = e;
452
+ return { askCatalog: (e) => t("/console/catalog/ask", {
453
+ method: "POST",
454
+ body: { question: e }
455
+ }) };
456
+ }
457
+ //#endregion
458
+ //#region src/admin/lib/api/credit-endpoints.ts
459
+ var A = (e) => `/admin/customers/${encodeURIComponent(e)}`;
460
+ function j(e) {
461
+ let { api: t } = e;
462
+ return {
463
+ listCreditGrants: (e, n, r, i, a) => t("/admin/credit-grants", {
464
+ query: {
465
+ customer_id: e,
466
+ currency: n,
467
+ limit: r,
468
+ cursor: i
469
+ },
470
+ signal: a
471
+ }),
472
+ createCreditGrant: async (e, n) => (await t("/admin/credit-grants", {
473
+ method: "POST",
474
+ body: { items: [{
475
+ customer_id: e,
476
+ ...n
477
+ }] }
478
+ })).items[0],
479
+ revokeCreditGrant: (e, n) => t(`/admin/credit-grants/${encodeURIComponent(e)}/revoke`, {
480
+ method: "POST",
481
+ body: { reason: n }
482
+ }),
483
+ listBalanceTransactions: (e, n, r, i, a) => t(`${A(e)}/balance/transactions`, {
484
+ query: {
485
+ currency: n,
486
+ limit: r,
487
+ cursor: i
488
+ },
489
+ signal: a
490
+ })
491
+ };
492
+ }
493
+ //#endregion
494
+ //#region src/admin/lib/api/order-endpoints.ts
495
+ function M(e) {
496
+ let { api: t } = e, n = (e, n, r) => t("/admin/orders", {
497
+ query: {
498
+ ...e,
499
+ ...n
500
+ },
501
+ signal: r
502
+ }), r = (e, n) => t(`/admin/orders/${e}`, { signal: n }), i = (e, n, r) => t("/admin/payments", {
503
+ query: {
504
+ order_id: e,
505
+ ...n
506
+ },
507
+ signal: r
508
+ });
509
+ function a(e) {
510
+ if (e.action === "record_payment") {
511
+ let n = {
512
+ order_id: e.id,
513
+ amount: e.amount ?? "",
514
+ transaction_id: e.reference ?? ""
515
+ };
516
+ return t("/admin/payments", {
517
+ method: "POST",
518
+ body: n
519
+ });
520
+ }
521
+ let n = {
522
+ waive_balance: "waive-balance",
523
+ mark_uncollectible: "mark-uncollectible"
524
+ }[e.action];
525
+ return t(`/admin/orders/${e.id}/${n}`, { method: "POST" });
526
+ }
527
+ return {
528
+ listOrders: n,
529
+ getOrder: r,
530
+ listOrderPayments: i,
531
+ applyUsageAction: a
532
+ };
533
+ }
534
+ //#endregion
535
+ //#region src/admin/lib/api/invoice-profile-endpoints.ts
536
+ function N(e) {
537
+ let { getCustomer: t } = e, { updateCustomer: n } = e;
538
+ return {
539
+ getInvoiceProfile: async (e, n) => (await t(e, n)).settings.invoice_profile ?? null,
540
+ putInvoiceProfile: async (e, t) => {
541
+ let { settings: r } = await n(e, { invoice_profile: t });
542
+ return r.invoice_profile;
543
+ }
544
+ };
545
+ }
546
+ //#endregion
547
+ //#region src/admin/lib/api/index.ts
548
+ function P(e) {
549
+ let t = E(e);
550
+ return {
551
+ ...t,
552
+ ...O(e),
553
+ ...k(e),
554
+ ...j(e),
555
+ ...M(e),
556
+ ...N(t)
557
+ };
558
+ }
559
+ //#endregion
560
+ //#region src/admin/lib/toast.ts
561
+ function F(e) {
562
+ let t = (t) => (n, r) => t(n, {
563
+ ...r,
564
+ toasterId: e
565
+ });
566
+ return Object.assign(t(u), {
567
+ error: t(u.error),
568
+ success: t(u.success),
569
+ info: t(u.info),
570
+ warning: t(u.warning)
571
+ });
572
+ }
573
+ function I(e) {
574
+ function t(t, n) {
575
+ if (t instanceof _) {
576
+ if (t.code === "revision_mismatch") {
577
+ e.error(`${n}: changed since you opened it`, { description: "The latest version is loaded; review it and try again." });
578
+ return;
579
+ }
580
+ if (t.isPermissionDenied) {
581
+ e.error(`${n}: your role lacks permission`, { description: t.message });
582
+ return;
583
+ }
584
+ let r = t.code ? `${n} (${t.code})` : n;
585
+ e.error(r, { description: t.message });
586
+ return;
587
+ }
588
+ e.error(n, { description: t instanceof Error ? t.message : String(t) });
589
+ }
590
+ function n(t) {
591
+ e.error(`${t} changed since you opened it`, { description: "Reloaded. Review the current version and edit again." });
592
+ }
593
+ return {
594
+ toastApiError: t,
595
+ toastStaleEdit: n
596
+ };
597
+ }
598
+ //#endregion
599
+ //#region src/admin/lib/queries.ts
600
+ function L(e) {
601
+ let t = e.rows[0] ?? [];
602
+ return Object.fromEntries(e.columns.map((e, n) => [e.name, t[n] ?? null]));
603
+ }
604
+ async function R(e, t) {
605
+ return {
606
+ data: await b((n) => e(n, t), t),
607
+ next_cursor: null
608
+ };
609
+ }
610
+ var z = (e) => ({
611
+ merchant: () => e(),
612
+ customers: () => [...e(), "customers"],
613
+ customer: (t) => [
614
+ ...e(),
615
+ "customers",
616
+ t
617
+ ],
618
+ subscriptions: () => [...e(), "subscriptions"],
619
+ subscription: (t) => [
620
+ ...e(),
621
+ "subscriptions",
622
+ t
623
+ ],
624
+ payments: () => [...e(), "payments"],
625
+ payment: (t) => [
626
+ ...e(),
627
+ "payments",
628
+ t
629
+ ],
630
+ attempts: () => [...e(), "payment-attempts"],
631
+ cycles: () => [...e(), "renewals"],
632
+ catalog: () => [...e(), "catalog"],
633
+ catalogDrift: () => [
634
+ ...e(),
635
+ "catalog",
636
+ "drift"
637
+ ],
638
+ usageMeters: () => [
639
+ ...e(),
640
+ "catalog",
641
+ "meters"
642
+ ],
643
+ usageMeter: (t) => [
644
+ ...e(),
645
+ "catalog",
646
+ "meters",
647
+ t
648
+ ],
649
+ settings: () => [...e(), "settings"],
650
+ alerts: () => [...e(), "alerts"],
651
+ ops: () => [...e(), "ops"],
652
+ dashboard: () => [...e(), "dashboard"],
653
+ notifications: () => [...e(), "notifications"]
654
+ }), B = (e) => e ? { errorAction: e } : void 0;
655
+ function V(e, t) {
656
+ let { queryRoot: n } = e, { getCustomer: r, getMerchantConfiguration: i, getPayment: a, getPaymentAttempt: o, getPrice: c, getPriceHistory: u, getProduct: d, getRenewal: f, getSubscription: p, getUsageMeter: m, listCustomerEntitlements: h, listCustomerPaymentMethods: g, listCustomerProductAccess: _, listCustomers: v, listFindings: y, listPaymentAttempts: x, listPSPs: S, listRails: C, previewPSPRouting: w, listPayments: T, listPrices: E, listProducts: D, listRenewals: O, listPriceMigrations: k, listSubscriptions: A, listUsageMeters: j, getAdminAccess: M, getConfig: N, listWebhooks: P, getDashboard: F, metricsQuery: I } = t, V = n, H = z(V);
657
+ return {
658
+ queryKeys: H,
659
+ merchantQueryKeys: () => {
660
+ let e = V();
661
+ return z(() => e);
662
+ },
663
+ adminQueries: {
664
+ customers: (e, t, n) => l({
665
+ queryKey: [...H.customers(), {
666
+ search: e,
667
+ limit: t,
668
+ cursor: n
669
+ }],
670
+ queryFn: ({ signal: r }) => v(e, t, n, r),
671
+ placeholderData: s,
672
+ meta: { errorAction: "Load customers" }
673
+ }),
674
+ customer: (e) => l({
675
+ queryKey: H.customer(e),
676
+ queryFn: ({ signal: t }) => r(e, t),
677
+ enabled: !!e,
678
+ meta: { errorAction: "Load customer" }
679
+ }),
680
+ customerSubscriptions: (e, t, n) => l({
681
+ queryKey: [
682
+ ...H.customer(e),
683
+ "subscriptions",
684
+ {
685
+ limit: t,
686
+ cursor: n
687
+ }
688
+ ],
689
+ queryFn: ({ signal: r }) => A({ customer_id: e }, t, n || void 0, r),
690
+ enabled: !!e,
691
+ placeholderData: s,
692
+ meta: { errorAction: "Load subscriptions" }
693
+ }),
694
+ customerPayments: (e, t, n) => l({
695
+ queryKey: [
696
+ ...H.customer(e),
697
+ "payments",
698
+ {
699
+ limit: t,
700
+ cursor: n
701
+ }
702
+ ],
703
+ queryFn: ({ signal: r }) => T({ customer_id: e }, {
704
+ limit: t,
705
+ cursor: n || void 0
706
+ }, r),
707
+ enabled: !!e,
708
+ placeholderData: s,
709
+ meta: { errorAction: "Load payments" }
710
+ }),
711
+ customerPaymentMethodsPage: (e, t, n) => l({
712
+ queryKey: [
713
+ ...H.customer(e),
714
+ "payment-methods",
715
+ {
716
+ limit: t,
717
+ cursor: n
718
+ }
719
+ ],
720
+ queryFn: ({ signal: r }) => g(e, {
721
+ limit: t,
722
+ cursor: n || void 0
723
+ }, r),
724
+ enabled: !!e,
725
+ placeholderData: s,
726
+ meta: { errorAction: "Load payment methods" }
727
+ }),
728
+ customerEntitlements: (e, t, n) => l({
729
+ queryKey: [
730
+ ...H.customer(e),
731
+ "entitlements",
732
+ {
733
+ limit: t,
734
+ cursor: n
735
+ }
736
+ ],
737
+ queryFn: ({ signal: r }) => h(e, {
738
+ limit: t,
739
+ cursor: n || void 0
740
+ }, r),
741
+ enabled: !!e,
742
+ placeholderData: s,
743
+ meta: { errorAction: "Load entitlements" }
744
+ }),
745
+ customerProductAccess: (e, t, n) => l({
746
+ queryKey: [
747
+ ...H.customer(e),
748
+ "product-access",
749
+ {
750
+ limit: t,
751
+ cursor: n
752
+ }
753
+ ],
754
+ queryFn: ({ signal: r }) => _(e, {
755
+ limit: t,
756
+ cursor: n || void 0
757
+ }, r),
758
+ enabled: !!e,
759
+ placeholderData: s,
760
+ meta: { errorAction: "Load product access" }
761
+ }),
762
+ subscriptions: (e, t, n) => l({
763
+ queryKey: [...H.subscriptions(), {
764
+ filters: e,
765
+ limit: t,
766
+ cursor: n
767
+ }],
768
+ queryFn: ({ signal: r }) => A(e, t, n || void 0, r),
769
+ placeholderData: s,
770
+ meta: { errorAction: "Load subscriptions" }
771
+ }),
772
+ subscription: (e) => l({
773
+ queryKey: H.subscription(e),
774
+ queryFn: ({ signal: t }) => p(e, t),
775
+ enabled: !!e,
776
+ meta: { errorAction: "Load subscription" }
777
+ }),
778
+ customerPaymentMethods: (e) => l({
779
+ queryKey: [...H.customer(e ?? "unselected"), "payment-methods"],
780
+ queryFn: ({ signal: t }) => b((n) => g(e, {
781
+ limit: 100,
782
+ cursor: n
783
+ }, t), t),
784
+ enabled: !!e
785
+ }),
786
+ payments: (e, t, n) => l({
787
+ queryKey: [...H.payments(), {
788
+ filters: e,
789
+ limit: t,
790
+ cursor: n
791
+ }],
792
+ queryFn: ({ signal: r }) => T(e, {
793
+ limit: t,
794
+ cursor: n
795
+ }, r),
796
+ placeholderData: s,
797
+ meta: { errorAction: "Load payments" }
798
+ }),
799
+ payment: (e) => l({
800
+ queryKey: H.payment(e),
801
+ queryFn: ({ signal: t }) => a(e, t),
802
+ enabled: !!e,
803
+ meta: { errorAction: "Load payment" }
804
+ }),
805
+ attempts: (e, t, n) => l({
806
+ queryKey: [...H.attempts(), {
807
+ filters: e,
808
+ limit: t,
809
+ cursor: n
810
+ }],
811
+ queryFn: ({ signal: r }) => x(e, {
812
+ limit: t,
813
+ cursor: n
814
+ }, r),
815
+ placeholderData: s,
816
+ meta: { errorAction: "Load payment attempts" }
817
+ }),
818
+ attempt: (e) => l({
819
+ queryKey: [...H.attempts(), e],
820
+ queryFn: ({ signal: t }) => o(e, t),
821
+ enabled: !!e,
822
+ meta: { errorAction: "Load payment attempt" }
823
+ }),
824
+ cycles: (e, t, n) => l({
825
+ queryKey: [...H.cycles(), {
826
+ filters: e,
827
+ limit: t,
828
+ cursor: n
829
+ }],
830
+ queryFn: ({ signal: r }) => O(e, {
831
+ limit: t,
832
+ cursor: n
833
+ }, r),
834
+ placeholderData: s,
835
+ meta: { errorAction: "Load renewals" }
836
+ }),
837
+ cycle: (e) => l({
838
+ queryKey: [...H.cycles(), e],
839
+ queryFn: ({ signal: t }) => f(e, t),
840
+ enabled: !!e,
841
+ meta: { errorAction: "Load renewal" }
842
+ }),
843
+ products: (e = {}) => {
844
+ let { limit: t = 100, cursor: n, errorAction: r } = e;
845
+ return l({
846
+ queryKey: [
847
+ ...H.catalog(),
848
+ "products",
849
+ {
850
+ limit: t,
851
+ cursor: n
852
+ }
853
+ ],
854
+ queryFn: ({ signal: e }) => D(t, n, void 0, e),
855
+ placeholderData: s,
856
+ meta: B(r)
857
+ });
858
+ },
859
+ allProducts: (e = {}) => l({
860
+ queryKey: [
861
+ ...H.catalog(),
862
+ "products",
863
+ "all"
864
+ ],
865
+ queryFn: ({ signal: e }) => R((e, t) => D(500, e, void 0, t), e),
866
+ meta: B(e.errorAction)
867
+ }),
868
+ prices: (e = {}) => {
869
+ let { productId: t, limit: n = 100, cursor: r, errorAction: i } = e;
870
+ return l({
871
+ queryKey: [
872
+ ...H.catalog(),
873
+ "prices",
874
+ {
875
+ productId: t,
876
+ limit: n,
877
+ cursor: r
878
+ }
879
+ ],
880
+ queryFn: ({ signal: e }) => E(n, r, t, e),
881
+ placeholderData: s,
882
+ meta: B(i)
883
+ });
884
+ },
885
+ allPrices: (e = {}) => l({
886
+ queryKey: [
887
+ ...H.catalog(),
888
+ "prices",
889
+ "all",
890
+ { productId: e.productId }
891
+ ],
892
+ queryFn: ({ signal: t }) => R((t, n) => E(500, t, e.productId, n), t),
893
+ meta: B(e.errorAction)
894
+ }),
895
+ price: (e, t = {}) => {
896
+ let { verify: n = !1, errorAction: r } = t;
897
+ return l({
898
+ queryKey: [
899
+ ...H.catalog(),
900
+ "prices",
901
+ e,
902
+ { verify: n }
903
+ ],
904
+ queryFn: ({ signal: t }) => c(e, n, t),
905
+ enabled: !!e,
906
+ placeholderData: s,
907
+ meta: B(r)
908
+ });
909
+ },
910
+ product: (e) => l({
911
+ queryKey: [
912
+ ...H.catalog(),
913
+ "products",
914
+ e ?? "unselected"
915
+ ],
916
+ queryFn: ({ signal: t }) => d(e, t),
917
+ enabled: !!e
918
+ }),
919
+ priceHistory: (e) => l({
920
+ queryKey: [
921
+ ...H.catalog(),
922
+ "prices",
923
+ "history",
924
+ e ?? "unselected"
925
+ ],
926
+ queryFn: ({ signal: t }) => u(e, t),
927
+ enabled: !!e
928
+ }),
929
+ priceMigrations: (e, t, n = 5) => l({
930
+ queryKey: [
931
+ ...H.catalog(),
932
+ "price-migrations",
933
+ {
934
+ productKey: e,
935
+ priceKey: t,
936
+ limit: n
937
+ }
938
+ ],
939
+ queryFn: ({ signal: r }) => k(e, t, n, r),
940
+ enabled: !!(e && t)
941
+ }),
942
+ catalogDrift: (e = !0, t = 200, n) => l({
943
+ queryKey: [...H.catalogDrift(), {
944
+ limit: t,
945
+ cursor: n
946
+ }],
947
+ queryFn: ({ signal: e }) => y({ type: "catalog.*" }, t, e),
948
+ enabled: e,
949
+ meta: { errorAction: "Load drift" }
950
+ }),
951
+ checkoutRouting: (e) => l({
952
+ queryKey: [
953
+ ...H.catalog(),
954
+ "prices",
955
+ e,
956
+ "routing"
957
+ ],
958
+ queryFn: ({ signal: t }) => w({ price_id: e }, t),
959
+ enabled: !!e,
960
+ meta: { errorAction: "Check checkout readiness" }
961
+ }),
962
+ usageMeters: (e = 200, t) => l({
963
+ queryKey: [...H.usageMeters(), {
964
+ limit: e,
965
+ cursor: t
966
+ }],
967
+ queryFn: ({ signal: n }) => j(e, t, n),
968
+ placeholderData: s,
969
+ meta: { errorAction: "Load usage meters" }
970
+ }),
971
+ allUsageMeters: () => l({
972
+ queryKey: [...H.usageMeters(), "all"],
973
+ queryFn: ({ signal: e }) => R((e, t) => j(500, e, t), e),
974
+ meta: { errorAction: "Load usage meters" }
975
+ }),
976
+ usageMeter: (e) => l({
977
+ queryKey: H.usageMeter(e),
978
+ queryFn: ({ signal: t }) => m(e, t),
979
+ enabled: !!e,
980
+ meta: { errorAction: "Load usage meter" }
981
+ }),
982
+ findings: (e = !0) => l({
983
+ queryKey: [
984
+ ...H.ops(),
985
+ "findings",
986
+ { limit: 100 }
987
+ ],
988
+ queryFn: ({ signal: e }) => y({}, 100, e),
989
+ enabled: e,
990
+ meta: { errorAction: "Load findings" }
991
+ }),
992
+ findingSummary: () => l({
993
+ queryKey: [
994
+ ...H.ops(),
995
+ "findings",
996
+ "summary"
997
+ ],
998
+ queryFn: async ({ signal: e }) => {
999
+ let t = L(await I({
1000
+ measures: [
1001
+ "open_findings",
1002
+ "orphaned_members",
1003
+ "freeloaders",
1004
+ "duplicate_coverage"
1005
+ ],
1006
+ range: { last: "1d" }
1007
+ }, e));
1008
+ return {
1009
+ total_open: Number(t.open_findings ?? 0),
1010
+ orphaned_members: Number(t.orphaned_members ?? 0),
1011
+ freeloaders: Number(t.freeloaders ?? 0),
1012
+ duplicate_coverage: Number(t.duplicate_coverage ?? 0)
1013
+ };
1014
+ },
1015
+ meta: { errorAction: "Load the findings summary" }
1016
+ }),
1017
+ merchantConfiguration: (e) => l({
1018
+ queryKey: H.settings(),
1019
+ queryFn: ({ signal: e }) => i(e),
1020
+ meta: B(e)
1021
+ }),
1022
+ psps: () => l({
1023
+ queryKey: [...H.settings(), "psps"],
1024
+ queryFn: ({ signal: e }) => S(e),
1025
+ meta: { errorAction: "Load PSPs" }
1026
+ }),
1027
+ rails: () => l({
1028
+ queryKey: [...H.settings(), "rails"],
1029
+ queryFn: ({ signal: e }) => C(e),
1030
+ staleTime: Infinity,
1031
+ meta: { errorAction: "Load rails" }
1032
+ }),
1033
+ config: () => l({
1034
+ queryKey: ["config"],
1035
+ queryFn: ({ signal: e }) => N(e),
1036
+ staleTime: 3e5,
1037
+ meta: { errorAction: "Load configuration" }
1038
+ }),
1039
+ access: () => l({
1040
+ queryKey: [...H.merchant(), "access"],
1041
+ queryFn: ({ signal: e }) => M(e),
1042
+ staleTime: 3e5,
1043
+ meta: { errorAction: "Load your access" }
1044
+ }),
1045
+ webhooks: () => l({
1046
+ queryKey: [...H.alerts(), "webhooks"],
1047
+ queryFn: ({ signal: e }) => P(e),
1048
+ meta: { errorAction: "Load webhooks" }
1049
+ }),
1050
+ dashboard: () => l({
1051
+ queryKey: H.dashboard(),
1052
+ queryFn: ({ signal: e }) => F(e),
1053
+ meta: { errorAction: "Load dashboard" }
1054
+ }),
1055
+ widgetMetrics: (e) => l({
1056
+ queryKey: [
1057
+ ...H.dashboard(),
1058
+ "metrics",
1059
+ e ?? "unselected"
1060
+ ],
1061
+ queryFn: ({ signal: t }) => I(e, t),
1062
+ enabled: !!e
1063
+ }),
1064
+ notifications: (e) => l({
1065
+ queryKey: H.notifications(),
1066
+ queryFn: ({ signal: e }) => y({ status: "requires_review" }, 10, e),
1067
+ enabled: e
1068
+ }),
1069
+ unreadNotifications: () => l({
1070
+ queryKey: [...H.notifications(), "count"],
1071
+ queryFn: async ({ signal: e }) => Number(L(await I({
1072
+ measures: ["open_findings"],
1073
+ range: { last: "1d" },
1074
+ filters: { finding_status: ["requires_review"] }
1075
+ }, e)).open_findings ?? 0),
1076
+ refetchInterval: 3e4,
1077
+ retry: !1
1078
+ })
1079
+ }
1080
+ };
1081
+ }
1082
+ //#endregion
1083
+ //#region src/admin/lib/mutations.ts
1084
+ var H = 200, U = async (e) => {
1085
+ let t = [], n;
1086
+ for (;;) {
1087
+ let r = await e(H, n);
1088
+ if (t.push(...r.data), !r.next_cursor || r.data.length === 0) return t;
1089
+ n = r.next_cursor;
1090
+ }
1091
+ }, W = (e, t) => e.invalidateQueries({
1092
+ queryKey: t,
1093
+ exact: !0
1094
+ }), G = (e, t) => () => W(e, t), K = (e, t) => () => e.invalidateQueries({ queryKey: t }), q = (e, ...t) => (n) => {
1095
+ n instanceof _ && n.code === "revision_mismatch" && Promise.all(t.map((t) => e.invalidateQueries({ queryKey: t })));
1096
+ };
1097
+ function J(e, t, n) {
1098
+ let { selectedMerchant: r } = e, { askCatalog: i, cancelPriceMigration: a, cancelSubscription: o, changeSubscriptionPaymentMethod: s, changeSubscription: l, createPrice: u, createProduct: d, createWebhook: f, createPSP: p, deleteWebhook: m, getCustomer: h, getProductByKey: g, grantProductAccess: v, listCustomers: y, listPayments: x, listSubscriptions: S, putUsageMeterRateCard: C, updatePSP: w, putUsageMeter: T, previewPriceMigration: E, previewSubscriptionChange: D, applyCatalog: O, refreshPSPs: k, refundPayment: A, createPriceMigration: j, resolveFinding: M, resumeSubscription: N, revokeProductAccess: P, updateCustomer: F, updateMerchantConfiguration: I, updatePrice: L, updateProduct: R, updateWebhook: z, putDashboard: B } = t, { adminQueries: V, merchantQueryKeys: J } = n, Y = (e) => (t) => {
1099
+ t instanceof _ && t.merchantConfigReadOnly && e.invalidateQueries({ queryKey: V.config().queryKey });
1100
+ }, X = (e, t) => () => Promise.all([W(e, [...t.alerts(), "webhooks"]), W(e, t.settings())]);
1101
+ return { adminMutations: {
1102
+ saveDashboard: (e) => {
1103
+ let t = J().dashboard();
1104
+ return c({
1105
+ mutationKey: [...t, "save"],
1106
+ mutationFn: (e) => B(e),
1107
+ onSuccess: (n) => e.setQueryData(t, n)
1108
+ });
1109
+ },
1110
+ findCustomer: () => {
1111
+ let e = J().customers();
1112
+ return c({
1113
+ mutationKey: [...e, "find"],
1114
+ mutationFn: async (e) => (await y(e, 1, "")).data[0]
1115
+ });
1116
+ },
1117
+ exportCustomers: () => {
1118
+ let e = J().customers();
1119
+ return c({
1120
+ mutationKey: [...e, "export"],
1121
+ mutationFn: (e) => U((t, n) => y(e, t, n ?? ""))
1122
+ });
1123
+ },
1124
+ exportSubscriptions: () => {
1125
+ let e = J().subscriptions();
1126
+ return c({
1127
+ mutationKey: [...e, "export"],
1128
+ mutationFn: (e) => U((t, n) => S(e, t, n))
1129
+ });
1130
+ },
1131
+ exportPayments: () => {
1132
+ let e = J().payments();
1133
+ return c({
1134
+ mutationKey: [...e, "export"],
1135
+ mutationFn: (e) => b((t) => x(e, {
1136
+ limit: H,
1137
+ cursor: t
1138
+ }))
1139
+ });
1140
+ },
1141
+ resolveFinding: (e) => {
1142
+ let t = J().ops();
1143
+ return c({
1144
+ mutationKey: [
1145
+ ...t,
1146
+ "findings",
1147
+ "resolve"
1148
+ ],
1149
+ mutationFn: ({ id: e, outcome: t, notes: n }) => M(e, t, n),
1150
+ onSuccess: K(e, t)
1151
+ });
1152
+ },
1153
+ refundPayment: (e, t, n, r) => {
1154
+ let i = J(), a = i.payments(), o = n ? i.customer(n) : void 0, s = r ? i.subscription(r) : void 0;
1155
+ return c({
1156
+ mutationKey: [
1157
+ ...a,
1158
+ t,
1159
+ "refund"
1160
+ ],
1161
+ mutationFn: ({ amount: e, reason: n, revokeAccess: r }) => A(t, e, n, r),
1162
+ onSuccess: () => Promise.all([
1163
+ e.invalidateQueries({ queryKey: a }),
1164
+ ...o ? [e.invalidateQueries({ queryKey: o })] : [],
1165
+ ...s ? [e.invalidateQueries({ queryKey: s })] : []
1166
+ ])
1167
+ });
1168
+ },
1169
+ cancelSubscription: (e, t, n) => {
1170
+ let r = J(), i = r.subscriptions(), a = n ? r.customer(n) : void 0;
1171
+ return c({
1172
+ mutationKey: [
1173
+ ...i,
1174
+ t,
1175
+ "cancel"
1176
+ ],
1177
+ mutationFn: ({ reason: e, revokeAccess: n }) => o(t, e, n),
1178
+ onSuccess: () => Promise.all([e.invalidateQueries({ queryKey: i }), ...a ? [e.invalidateQueries({ queryKey: a })] : []])
1179
+ });
1180
+ },
1181
+ resumeSubscription: (e, t, n) => {
1182
+ let r = J(), i = r.subscriptions(), a = n ? r.customer(n) : void 0;
1183
+ return c({
1184
+ mutationKey: [
1185
+ ...i,
1186
+ t,
1187
+ "resume"
1188
+ ],
1189
+ mutationFn: () => N(t),
1190
+ onSuccess: () => Promise.all([e.invalidateQueries({ queryKey: i }), ...a ? [e.invalidateQueries({ queryKey: a })] : []])
1191
+ });
1192
+ },
1193
+ changeSubscriptionPaymentMethod: (e, t, n) => {
1194
+ let r = J(), i = r.subscriptions(), a = n ? r.customer(n) : void 0;
1195
+ return c({
1196
+ mutationKey: [
1197
+ ...i,
1198
+ t,
1199
+ "payment-method"
1200
+ ],
1201
+ mutationFn: (e) => s(t, e),
1202
+ onSuccess: () => Promise.all([e.invalidateQueries({ queryKey: i }), ...a ? [e.invalidateQueries({ queryKey: a })] : []])
1203
+ });
1204
+ },
1205
+ previewSubscriptionChange: (e) => {
1206
+ let t = J().subscriptions();
1207
+ return c({
1208
+ mutationKey: [
1209
+ ...t,
1210
+ e,
1211
+ "change",
1212
+ "preview"
1213
+ ],
1214
+ mutationFn: (t) => D(e, t)
1215
+ });
1216
+ },
1217
+ changeSubscription: (e, t, n) => {
1218
+ let r = J(), i = r.subscriptions(), a = n ? r.customer(n) : void 0, o = r.payments();
1219
+ return c({
1220
+ mutationKey: [
1221
+ ...i,
1222
+ t,
1223
+ "change"
1224
+ ],
1225
+ mutationFn: (e) => l(t, e.change, e.idempotencyKey),
1226
+ onSuccess: () => Promise.all([
1227
+ e.invalidateQueries({ queryKey: i }),
1228
+ e.invalidateQueries({ queryKey: o }),
1229
+ ...a ? [e.invalidateQueries({ queryKey: a })] : []
1230
+ ])
1231
+ });
1232
+ },
1233
+ grantCustomerProductAccess: (e, t) => {
1234
+ let n = J().customer(t);
1235
+ return c({
1236
+ mutationKey: [
1237
+ ...n,
1238
+ "product-access",
1239
+ "grant"
1240
+ ],
1241
+ mutationFn: (e) => v(t, e),
1242
+ onSuccess: K(e, n)
1243
+ });
1244
+ },
1245
+ revokeCustomerProductAccess: (e, t) => {
1246
+ let n = J().customer(t);
1247
+ return c({
1248
+ mutationKey: [
1249
+ ...n,
1250
+ "product-access",
1251
+ "revoke"
1252
+ ],
1253
+ mutationFn: ({ grantId: e, reason: t }) => P(e, t),
1254
+ onSuccess: K(e, n)
1255
+ });
1256
+ },
1257
+ askCatalogCopilot: () => {
1258
+ let e = J();
1259
+ return c({
1260
+ mutationKey: [
1261
+ ...e.catalog(),
1262
+ "copilot",
1263
+ "ask"
1264
+ ],
1265
+ mutationFn: (e) => i(e)
1266
+ });
1267
+ },
1268
+ loadCatalogPriceDraft: () => {
1269
+ let e = J();
1270
+ return c({
1271
+ mutationKey: [
1272
+ ...e.catalog(),
1273
+ "copilot",
1274
+ "load-price-draft"
1275
+ ],
1276
+ mutationFn: async ({ productKey: e, priceKey: t }) => {
1277
+ let n = await g(e), r = n.prices.find((e) => e.key === t);
1278
+ if (!r) throw Error(`No live price ${e}/${t}`);
1279
+ return {
1280
+ price: r,
1281
+ productName: n.display_name,
1282
+ productKey: n.key
1283
+ };
1284
+ }
1285
+ });
1286
+ },
1287
+ createCatalogDraftPrice: (e) => {
1288
+ let t = J();
1289
+ return c({
1290
+ mutationKey: [
1291
+ ...t.catalog(),
1292
+ "copilot",
1293
+ "create-price"
1294
+ ],
1295
+ mutationFn: (e) => u(e),
1296
+ onSuccess: K(e, t.catalog())
1297
+ });
1298
+ },
1299
+ applyCatalog: (e) => {
1300
+ let t = J();
1301
+ return c({
1302
+ mutationKey: [...t.catalog(), "apply"],
1303
+ mutationFn: ({ document: e, force: t }) => O(e, t),
1304
+ onSuccess: K(e, t.catalog())
1305
+ });
1306
+ },
1307
+ refreshPSPs: (e) => {
1308
+ let t = J();
1309
+ return c({
1310
+ mutationKey: [...t.catalogDrift(), "refresh"],
1311
+ mutationFn: () => k(),
1312
+ onSuccess: K(e, t.catalogDrift())
1313
+ });
1314
+ },
1315
+ createProduct: (e) => {
1316
+ let t = J();
1317
+ return c({
1318
+ mutationKey: [
1319
+ ...t.catalog(),
1320
+ "products",
1321
+ "create"
1322
+ ],
1323
+ mutationFn: (e) => d(e),
1324
+ onSuccess: K(e, t.catalog())
1325
+ });
1326
+ },
1327
+ updateProduct: (e) => {
1328
+ let t = J();
1329
+ return c({
1330
+ mutationKey: [
1331
+ ...t.catalog(),
1332
+ "products",
1333
+ "update"
1334
+ ],
1335
+ mutationFn: ({ id: e, product: t }) => R(e, t),
1336
+ onSuccess: K(e, t.catalog()),
1337
+ onError: q(e, t.catalog())
1338
+ });
1339
+ },
1340
+ setProductActive: (e) => {
1341
+ let t = J();
1342
+ return c({
1343
+ mutationKey: [
1344
+ ...t.catalog(),
1345
+ "products",
1346
+ "set-active"
1347
+ ],
1348
+ mutationFn: ({ id: e, active: t, revision: n }) => R(e, {
1349
+ archived: !t,
1350
+ expected_revision: n
1351
+ }),
1352
+ onSuccess: K(e, t.catalog()),
1353
+ onError: q(e, t.catalog())
1354
+ });
1355
+ },
1356
+ createPrice: (e) => {
1357
+ let t = J();
1358
+ return c({
1359
+ mutationKey: [
1360
+ ...t.catalog(),
1361
+ "prices",
1362
+ "create"
1363
+ ],
1364
+ mutationFn: (e) => u(e),
1365
+ onSuccess: K(e, t.catalog())
1366
+ });
1367
+ },
1368
+ setPriceActive: (e) => {
1369
+ let t = J();
1370
+ return c({
1371
+ mutationKey: [
1372
+ ...t.catalog(),
1373
+ "prices",
1374
+ "set-active"
1375
+ ],
1376
+ mutationFn: ({ id: e, active: t, revision: n }) => L(e, {
1377
+ archived: !t,
1378
+ expected_revision: n
1379
+ }),
1380
+ onSuccess: K(e, t.catalog()),
1381
+ onError: q(e, t.catalog())
1382
+ });
1383
+ },
1384
+ putUsageMeter: (e) => {
1385
+ let t = J(), n = t.usageMeters();
1386
+ return c({
1387
+ mutationKey: [...n, "put"],
1388
+ mutationFn: ({ key: e, meter: t }) => T(e, t),
1389
+ onSuccess: (r, { key: i }) => Promise.all([e.invalidateQueries({ queryKey: n }), e.invalidateQueries({ queryKey: t.usageMeter(i) })]),
1390
+ onError: q(e, n)
1391
+ });
1392
+ },
1393
+ putDefaultUsageRateCard: (e) => {
1394
+ let t = J(), n = t.usageMeters();
1395
+ return c({
1396
+ mutationKey: [
1397
+ ...n,
1398
+ "rate-card",
1399
+ "put"
1400
+ ],
1401
+ mutationFn: ({ meter: e, rateCard: t }) => C(e, t),
1402
+ onSuccess: (r, { meter: i }) => Promise.all([e.invalidateQueries({ queryKey: n }), e.invalidateQueries({ queryKey: t.usageMeter(i.key) })]),
1403
+ onError: q(e, n)
1404
+ });
1405
+ },
1406
+ deleteDefaultUsageRateCard: (e) => {
1407
+ let t = J(), n = t.usageMeters();
1408
+ return c({
1409
+ mutationKey: [
1410
+ ...n,
1411
+ "rate-card",
1412
+ "delete"
1413
+ ],
1414
+ mutationFn: (e) => C(e, null),
1415
+ onSuccess: (r, i) => Promise.all([e.invalidateQueries({ queryKey: n }), e.invalidateQueries({ queryKey: t.usageMeter(i.key) })])
1416
+ });
1417
+ },
1418
+ previewPriceChange: () => {
1419
+ let e = J();
1420
+ return c({
1421
+ mutationKey: [
1422
+ ...e.catalog(),
1423
+ "prices",
1424
+ "preview-change"
1425
+ ],
1426
+ mutationFn: ({ productKey: e, priceKey: t }) => E(e, t)
1427
+ });
1428
+ },
1429
+ changePrice: (e) => {
1430
+ let t = J();
1431
+ return c({
1432
+ mutationKey: [
1433
+ ...t.catalog(),
1434
+ "prices",
1435
+ "change"
1436
+ ],
1437
+ mutationFn: async ({ price: e, migration: t }) => {
1438
+ let n = await u(e);
1439
+ return t && await j(t.productKey, t.priceKey, n.id, t.effectiveAt), n;
1440
+ },
1441
+ onSettled: K(e, t.catalog())
1442
+ });
1443
+ },
1444
+ cancelPriceMigration: (e) => {
1445
+ let t = J();
1446
+ return c({
1447
+ mutationKey: [
1448
+ ...t.catalog(),
1449
+ "price-migrations",
1450
+ "cancel"
1451
+ ],
1452
+ mutationFn: (e) => a(e),
1453
+ onSuccess: K(e, t.catalog())
1454
+ });
1455
+ },
1456
+ updateMerchantConfiguration: (e) => {
1457
+ let t = J();
1458
+ return c({
1459
+ mutationKey: [...t.settings(), "update"],
1460
+ mutationFn: (e) => I(e),
1461
+ onSettled: G(e, t.settings()),
1462
+ onError: Y(e)
1463
+ });
1464
+ },
1465
+ createPSP: (e) => {
1466
+ let t = r(), n = J();
1467
+ return c({
1468
+ mutationKey: [
1469
+ ...n.settings(),
1470
+ "psps",
1471
+ "create"
1472
+ ],
1473
+ retry: !1,
1474
+ gcTime: 0,
1475
+ mutationFn: (e) => {
1476
+ if (r() !== t) throw Error("Merchant changed; reopen this form before saving");
1477
+ return p(e);
1478
+ },
1479
+ onSettled: G(e, [...n.settings(), "psps"]),
1480
+ onError: Y(e)
1481
+ });
1482
+ },
1483
+ updatePSP: (e) => {
1484
+ let t = r(), n = J();
1485
+ return c({
1486
+ mutationKey: [
1487
+ ...n.settings(),
1488
+ "psps",
1489
+ "update"
1490
+ ],
1491
+ retry: !1,
1492
+ gcTime: 0,
1493
+ mutationFn: ({ id: e, psp: n }) => {
1494
+ if (r() !== t) throw Error("Merchant changed; reopen this form before saving");
1495
+ return w(e, n);
1496
+ },
1497
+ onSettled: G(e, [...n.settings(), "psps"]),
1498
+ onError: Y(e)
1499
+ });
1500
+ },
1501
+ setCreditLimit: () => {
1502
+ let e = J();
1503
+ return c({
1504
+ mutationKey: [
1505
+ ...e.settings(),
1506
+ "customer-controls",
1507
+ "credit-limit"
1508
+ ],
1509
+ mutationFn: ({ customerId: e, currency: t, amount: n }) => F(e, { credit_limits: [{
1510
+ currency: t,
1511
+ amount: n
1512
+ }] })
1513
+ });
1514
+ },
1515
+ lookupCustomerControls: () => {
1516
+ let e = J();
1517
+ return c({
1518
+ mutationKey: [
1519
+ ...e.settings(),
1520
+ "customer-controls",
1521
+ "lookup"
1522
+ ],
1523
+ mutationFn: async ({ customerId: e, currency: t }) => {
1524
+ let { settings: n } = await h(e).catch((e) => {
1525
+ throw e instanceof _ && e.status === 404 ? Error("No customer has this ID") : e;
1526
+ }), r = t.toUpperCase();
1527
+ return {
1528
+ currency: r,
1529
+ creditLimit: n.credit_limits.find((e) => e.currency === r)?.amount ?? "0",
1530
+ trustLevel: n.trust_levels.find((e) => e.currency === r)?.trust_level ?? ""
1531
+ };
1532
+ }
1533
+ });
1534
+ },
1535
+ createWebhook: (e) => {
1536
+ let t = J();
1537
+ return c({
1538
+ mutationKey: [
1539
+ ...t.alerts(),
1540
+ "webhooks",
1541
+ "create"
1542
+ ],
1543
+ mutationFn: (e) => f(e),
1544
+ onSuccess: X(e, t),
1545
+ onError: Y(e)
1546
+ });
1547
+ },
1548
+ updateWebhook: (e) => {
1549
+ let t = J();
1550
+ return c({
1551
+ mutationKey: [
1552
+ ...t.alerts(),
1553
+ "webhooks",
1554
+ "update"
1555
+ ],
1556
+ mutationFn: ({ id: e, webhook: t }) => z(e, t),
1557
+ onSuccess: X(e, t),
1558
+ onError: Y(e)
1559
+ });
1560
+ },
1561
+ deleteWebhook: (e) => {
1562
+ let t = J();
1563
+ return c({
1564
+ mutationKey: [
1565
+ ...t.alerts(),
1566
+ "webhooks",
1567
+ "delete"
1568
+ ],
1569
+ mutationFn: (e) => m(e),
1570
+ onSuccess: X(e, t),
1571
+ onError: Y(e)
1572
+ });
1573
+ }
1574
+ } };
1575
+ }
1576
+ //#endregion
1577
+ //#region src/admin/lib/credit-queries.ts
1578
+ function Y(e, t) {
1579
+ let { selectedMerchant: n } = e, r = (t, n) => [
1580
+ ...e.queryRoot(t),
1581
+ "customers",
1582
+ n
1583
+ ], { createCreditGrant: i, listCreditGrants: a, listBalanceTransactions: o, revokeCreditGrant: s } = t;
1584
+ function u(e) {
1585
+ if (!e || n() !== e) throw Error("The selected merchant changed. Reload this customer's credits.");
1586
+ }
1587
+ return {
1588
+ assertMerchant: u,
1589
+ creditQueries: {
1590
+ grants: (e, t, n, i, o) => l({
1591
+ queryKey: [
1592
+ ...r(e, t),
1593
+ "credit-grants",
1594
+ n,
1595
+ i,
1596
+ o
1597
+ ],
1598
+ enabled: !!(e && t && n),
1599
+ queryFn: ({ signal: r }) => (u(e), a(t, n, i, o, r))
1600
+ }),
1601
+ transactions: (e, t, n, i, a) => l({
1602
+ queryKey: [
1603
+ ...r(e, t),
1604
+ "transactions",
1605
+ n,
1606
+ i,
1607
+ a
1608
+ ],
1609
+ enabled: !!(e && t && n),
1610
+ queryFn: ({ signal: r }) => (u(e), o(t, n, i, a, r))
1611
+ })
1612
+ },
1613
+ creditMutations: {
1614
+ grant: (e, t, n) => c({
1615
+ mutationFn: (e) => (u(t), i(n, e)),
1616
+ onSettled: () => e.invalidateQueries({ queryKey: r(t, n) })
1617
+ }),
1618
+ revoke: (e, t, n) => c({
1619
+ mutationFn: ({ grant: e, reason: n }) => (u(t), s(e, n)),
1620
+ onSettled: () => e.invalidateQueries({ queryKey: r(t, n) })
1621
+ })
1622
+ }
1623
+ };
1624
+ }
1625
+ //#endregion
1626
+ //#region src/admin/lib/order-queries.ts
1627
+ function X(e, t, n) {
1628
+ let { queryRoot: r } = e, { queryKeys: i } = n, a = t, o = t, u = {
1629
+ root: () => [...r(), "orders"],
1630
+ detail: (e) => [...u.root(), e],
1631
+ profile: (e) => [...i.customer(e), "invoice-profile"]
1632
+ }, d = {
1633
+ list: (e, t, n) => l({
1634
+ queryKey: [
1635
+ ...u.root(),
1636
+ "list",
1637
+ e,
1638
+ t,
1639
+ n
1640
+ ],
1641
+ queryFn: ({ signal: r }) => a.listOrders(e, {
1642
+ limit: t,
1643
+ cursor: n
1644
+ }, r),
1645
+ placeholderData: s
1646
+ }),
1647
+ detail: (e) => l({
1648
+ queryKey: u.detail(e),
1649
+ queryFn: ({ signal: t }) => a.getOrder(e, t),
1650
+ enabled: !!e
1651
+ }),
1652
+ payments: (e, t, n) => l({
1653
+ queryKey: [
1654
+ ...u.detail(e),
1655
+ "payments",
1656
+ t,
1657
+ n
1658
+ ],
1659
+ queryFn: ({ signal: r }) => a.listOrderPayments(e, {
1660
+ limit: t,
1661
+ cursor: n
1662
+ }, r),
1663
+ enabled: !!e,
1664
+ placeholderData: s
1665
+ }),
1666
+ profile: (e) => l({
1667
+ queryKey: u.profile(e),
1668
+ queryFn: ({ signal: t }) => o.getInvoiceProfile(e, t),
1669
+ enabled: !!e
1670
+ })
1671
+ };
1672
+ function f(e, t) {
1673
+ let n = u.root(), r = i.customer(t);
1674
+ return c({
1675
+ mutationFn: a.applyUsageAction,
1676
+ onSettled: async () => {
1677
+ await Promise.all([e.invalidateQueries({ queryKey: n }), e.invalidateQueries({ queryKey: r })]);
1678
+ }
1679
+ });
1680
+ }
1681
+ function p(e, t) {
1682
+ let n = u.profile(t);
1683
+ return c({
1684
+ mutationFn: (e) => o.putInvoiceProfile(t, e),
1685
+ onSuccess: () => e.invalidateQueries({ queryKey: n })
1686
+ });
1687
+ }
1688
+ return {
1689
+ orderKeys: u,
1690
+ orderQueries: d,
1691
+ usageActionMutation: f,
1692
+ invoiceProfileMutation: p
1693
+ };
1694
+ }
1695
+ //#endregion
1696
+ //#region src/admin/context.tsx
1697
+ function ee(e) {
1698
+ let t = x(e), n = P(t), r = V(t, n), i = F(e.namespace);
1699
+ return {
1700
+ toast: i,
1701
+ ...I(i),
1702
+ ...t,
1703
+ ...n,
1704
+ ...r,
1705
+ ...J(t, n, r),
1706
+ ...Y(t, n),
1707
+ ...X(t, n, r)
1708
+ };
1709
+ }
1710
+ var Z = e(null);
1711
+ function Q() {
1712
+ let e = n(Z);
1713
+ if (!e) throw Error("BillingAdmin context is missing");
1714
+ return e;
1715
+ }
1716
+ var te = () => Q().services, ne = e(null), re = (e) => (window.addEventListener("popstate", e), () => window.removeEventListener("popstate", e)), ie = () => window.location.pathname + window.location.search;
1717
+ function ae({ basePath: e = "/", navigation: n, children: r }) {
1718
+ let s = o(re, ie, () => e), c = e.replace(/\/$/, ""), l = new URL(s, "http://billing.local"), u = n?.pathname ?? l.pathname, f = n?.search ?? l.search, p = u === c ? "/" : u.startsWith(c + "/") ? u.slice(c.length) : "/", [m, h] = a(() => /* @__PURE__ */ new Map()), g = t((e) => {
1719
+ if (/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(e)) return e;
1720
+ let t = new URL(e, "http://billing.local" + p + f);
1721
+ return c + t.pathname + t.search + t.hash;
1722
+ }, [
1723
+ c,
1724
+ p,
1725
+ f
1726
+ ]), _ = t((e, t = {}) => {
1727
+ if (typeof e == "number") {
1728
+ window.history.go(e);
1729
+ return;
1730
+ }
1731
+ let r = g(e);
1732
+ if (/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(r)) {
1733
+ window.location.assign(r);
1734
+ return;
1735
+ }
1736
+ h((e) => new Map(e).set(r, t.state)), n ? n.navigate(r, { replace: t.replace }) : (window.history[t.replace ? "replaceState" : "pushState"](t.state ?? null, "", r), window.dispatchEvent(new PopStateEvent("popstate")));
1737
+ }, [g, n]), v = i(() => ({
1738
+ location: {
1739
+ pathname: p,
1740
+ search: f,
1741
+ state: m.get(u + f) ?? (n ? null : window.history.state)
1742
+ },
1743
+ href: g,
1744
+ navigate: _,
1745
+ params: {}
1746
+ }), [
1747
+ p,
1748
+ u,
1749
+ f,
1750
+ g,
1751
+ _,
1752
+ n,
1753
+ m
1754
+ ]);
1755
+ return /* @__PURE__ */ d(ne.Provider, {
1756
+ value: v,
1757
+ children: r
1758
+ });
1759
+ }
1760
+ function $() {
1761
+ let e = n(ne);
1762
+ if (!e) throw Error("BillingAdmin router is missing");
1763
+ return e;
1764
+ }
1765
+ var oe = () => $().location, se = () => $().navigate, ce = () => $().params;
1766
+ function le() {
1767
+ let { location: e, navigate: t } = $();
1768
+ return [i(() => new URLSearchParams(e.search), [e.search]), (n, r) => {
1769
+ let i = new URLSearchParams(n).toString();
1770
+ t(e.pathname + (i ? "?" + i : ""), r);
1771
+ }];
1772
+ }
1773
+ function ue({ to: e, onClick: t, ...n }) {
1774
+ let { href: r, navigate: i } = $();
1775
+ return /* @__PURE__ */ d("a", {
1776
+ ...n,
1777
+ href: r(e),
1778
+ onClick: (r) => {
1779
+ t?.(r), !(r.defaultPrevented || r.button !== 0 || r.metaKey || r.ctrlKey || r.shiftKey || r.altKey || n.target || n.download) && (r.preventDefault(), i(e));
1780
+ }
1781
+ });
1782
+ }
1783
+ function de({ to: e, replace: t }) {
1784
+ let n = se();
1785
+ return r(() => n(e, { replace: t }), [
1786
+ n,
1787
+ e,
1788
+ t
1789
+ ]), null;
1790
+ }
1791
+ function fe({ params: e, children: t }) {
1792
+ let n = $();
1793
+ return /* @__PURE__ */ d(ne.Provider, {
1794
+ value: {
1795
+ ...n,
1796
+ params: e
1797
+ },
1798
+ children: t
1799
+ });
1800
+ }
1801
+ //#endregion
1802
+ //#region src/admin/lib/utils.ts
1803
+ function pe(...e) {
1804
+ return p(f(e));
1805
+ }
1806
+ //#endregion
1807
+ export { x as C, h as E, _ as S, m as T, D as _, fe as a, T as b, ce as c, ee as d, Q as f, P as g, I as h, de as i, le as l, F as m, ae as n, oe as o, te as p, ue as r, se as s, pe as t, Z as u, S as v, g as w, w as x, C as y };
1808
+
1809
+ //# sourceMappingURL=admin-utils-BK4Vh1o_.js.map