@nextblock-cms/ecom 0.10.1 → 0.10.3

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 (34) hide show
  1. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  2. package/lib/components/CustomerProfileForm.es.js +162 -159
  3. package/lib/freemius-coupons.cjs.js +1 -1
  4. package/lib/freemius-coupons.es.js +51 -49
  5. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  6. package/lib/pages/cms/payments/PaymentsClient.d.ts +4 -1
  7. package/lib/pages/cms/payments/PaymentsClient.es.js +255 -127
  8. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  9. package/lib/pages/cms/payments/PaymentsPage.es.js +20 -16
  10. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  11. package/lib/pages/cms/payments/actions.d.ts +1 -0
  12. package/lib/pages/cms/payments/actions.es.js +41 -13
  13. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  14. package/lib/pages/cms/payments/queries.es.js +13 -24
  15. package/lib/payment-config.cjs.js +1 -0
  16. package/lib/payment-config.d.ts +57 -0
  17. package/lib/payment-config.es.js +137 -0
  18. package/lib/providers/freemius.cjs.js +2 -2
  19. package/lib/providers/freemius.es.js +108 -107
  20. package/lib/providers/stripe.cjs.js +1 -1
  21. package/lib/providers/stripe.es.js +167 -167
  22. package/lib/stripe/checkout.cjs.js +1 -1
  23. package/lib/stripe/checkout.es.js +14 -14
  24. package/lib/stripe/client.cjs.js +1 -1
  25. package/lib/stripe/client.d.ts +1 -1
  26. package/lib/stripe/client.es.js +8 -5
  27. package/lib/stripe/order-sync.cjs.js +1 -1
  28. package/lib/stripe/order-sync.es.js +50 -50
  29. package/lib/stripe/webhooks.cjs.js +1 -1
  30. package/lib/stripe/webhooks.es.js +12 -10
  31. package/package.json +4 -4
  32. package/server.cjs.js +1 -1
  33. package/server.d.ts +1 -0
  34. package/server.es.js +188 -178
@@ -1,188 +1,316 @@
1
1
  'use client';
2
2
  import { jsxs as r, jsx as e } from "react/jsx-runtime";
3
- import { useState as u } from "react";
4
- import { Card as b, CardHeader as f, CardTitle as g, CardDescription as v, CardContent as x, Checkbox as y, Label as N, Button as C } from "@nextblock-cms/ui";
5
- import { CheckCircle2 as m, AlertCircle as k } from "lucide-react";
6
- import { useFormStatus as P } from "react-dom";
7
- function j({
8
- initialEnabledProviders: i,
3
+ import { useState as P } from "react";
4
+ import { Card as v, CardHeader as y, CardTitle as g, CardDescription as x, CardContent as N, Checkbox as w, Label as k, Button as S, Input as K } from "@nextblock-cms/ui";
5
+ import { CheckCircle2 as u, AlertCircle as _ } from "lucide-react";
6
+ import { useFormStatus as I } from "react-dom";
7
+ function T({
8
+ initialEnabledProviders: s,
9
9
  configStatus: t,
10
- saveAction: d
10
+ credentials: i,
11
+ saveAction: a,
12
+ saveCredentialsAction: l
11
13
  }) {
12
- const [s, a] = u(i), n = t?.stripe?.hasKeys, l = t?.freemius?.hasKeys;
13
- return /* @__PURE__ */ r("form", { action: d, className: "space-y-6 max-w-3xl p-8", children: [
14
- /* @__PURE__ */ e(
15
- "input",
16
- {
17
- type: "hidden",
18
- name: "stripe_enabled",
19
- value: s.stripe ? "true" : "false"
20
- }
21
- ),
22
- /* @__PURE__ */ e(
23
- "input",
24
- {
25
- type: "hidden",
26
- name: "freemius_enabled",
27
- value: s.freemius ? "true" : "false"
28
- }
29
- ),
14
+ const [d, m] = P(s), c = t?.stripe?.hasKeys, o = t?.freemius?.hasKeys;
15
+ return /* @__PURE__ */ r("div", { className: "space-y-6 max-w-3xl p-8", children: [
30
16
  /* @__PURE__ */ r("div", { children: [
31
17
  /* @__PURE__ */ e("h1", { className: "text-3xl font-bold tracking-tight", children: "Payment Settings" }),
32
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Enable the payment providers your store needs. Physical products use Stripe and digital products use Freemius." })
18
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Enter your provider API keys, then enable the providers your store needs. Physical products use Stripe and digital products use Freemius." })
33
19
  ] }),
34
- /* @__PURE__ */ r(b, { children: [
35
- /* @__PURE__ */ r(f, { children: [
36
- /* @__PURE__ */ e(g, { children: "Payment Providers" }),
37
- /* @__PURE__ */ e(v, { children: "You can run both providers at the same time. Each product picks its provider from its product type." })
38
- ] }),
39
- /* @__PURE__ */ r(x, { className: "space-y-6", children: [
40
- /* @__PURE__ */ e(
41
- h,
42
- {
43
- id: "stripe-enabled",
44
- label: "Stripe for Physical Products",
45
- description: "Use Stripe Checkout for physical merchandise and other shippable goods.",
46
- checked: s.stripe,
47
- disabled: !n,
48
- onCheckedChange: (o) => a((c) => ({
49
- ...c,
50
- stripe: o
51
- })),
52
- ready: n,
53
- children: n ? /* @__PURE__ */ r("div", { className: "mt-2 text-sm text-green-600 flex items-center gap-2", children: [
54
- /* @__PURE__ */ e(m, { className: "w-4 h-4" }),
55
- /* @__PURE__ */ e("span", { children: "Ready to process physical product checkout" })
56
- ] }) : /* @__PURE__ */ e(
57
- p,
58
- {
59
- provider: "Stripe",
60
- missingKeys: t.stripe.missing,
61
- docsUrl: "https://dashboard.stripe.com/apikeys",
62
- docsLabel: "Stripe Dashboard -> Developers -> API Keys"
63
- }
64
- )
65
- }
66
- ),
67
- /* @__PURE__ */ e(
68
- h,
69
- {
70
- id: "freemius-enabled",
71
- label: "Freemius for Digital Products",
72
- description: "Use Freemius for software licenses, SaaS plans, and other digital products.",
73
- checked: s.freemius,
74
- disabled: !l,
75
- onCheckedChange: (o) => a((c) => ({
76
- ...c,
77
- freemius: o
78
- })),
79
- ready: l,
80
- children: l ? /* @__PURE__ */ r("div", { className: "mt-2 text-sm text-green-600 flex items-center gap-2", children: [
81
- /* @__PURE__ */ e(m, { className: "w-4 h-4" }),
82
- /* @__PURE__ */ e("span", { children: "Ready to process digital product checkout" })
83
- ] }) : /* @__PURE__ */ e(
84
- p,
85
- {
86
- provider: "Freemius",
87
- missingKeys: t.freemius.missing,
88
- docsUrl: "https://dashboard.freemius.com/",
89
- docsLabel: "Freemius Dashboard -> Developers -> Credentials"
90
- }
91
- )
92
- }
93
- ),
94
- /* @__PURE__ */ e("div", { className: "flex justify-end pt-4", children: /* @__PURE__ */ e(w, {}) })
20
+ /* @__PURE__ */ e(F, { credentials: i, saveAction: l }),
21
+ /* @__PURE__ */ r("form", { action: a, className: "space-y-6", children: [
22
+ /* @__PURE__ */ e(
23
+ "input",
24
+ {
25
+ type: "hidden",
26
+ name: "stripe_enabled",
27
+ value: d.stripe ? "true" : "false"
28
+ }
29
+ ),
30
+ /* @__PURE__ */ e(
31
+ "input",
32
+ {
33
+ type: "hidden",
34
+ name: "freemius_enabled",
35
+ value: d.freemius ? "true" : "false"
36
+ }
37
+ ),
38
+ /* @__PURE__ */ r(v, { children: [
39
+ /* @__PURE__ */ r(y, { children: [
40
+ /* @__PURE__ */ e(g, { children: "Payment Providers" }),
41
+ /* @__PURE__ */ e(x, { children: "You can run both providers at the same time. Each product picks its provider from its product type." })
42
+ ] }),
43
+ /* @__PURE__ */ r(N, { className: "space-y-6", children: [
44
+ /* @__PURE__ */ e(
45
+ b,
46
+ {
47
+ id: "stripe-enabled",
48
+ label: "Stripe for Physical Products",
49
+ description: "Use Stripe Checkout for physical merchandise and other shippable goods.",
50
+ checked: d.stripe,
51
+ disabled: !c,
52
+ onCheckedChange: (p) => m((h) => ({
53
+ ...h,
54
+ stripe: p
55
+ })),
56
+ ready: c,
57
+ children: c ? /* @__PURE__ */ r("div", { className: "mt-2 text-sm text-green-600 flex items-center gap-2", children: [
58
+ /* @__PURE__ */ e(u, { className: "w-4 h-4" }),
59
+ /* @__PURE__ */ e("span", { children: "Ready to process physical product checkout" })
60
+ ] }) : /* @__PURE__ */ e(
61
+ f,
62
+ {
63
+ provider: "Stripe",
64
+ missingKeys: t.stripe.missing,
65
+ docsUrl: "https://dashboard.stripe.com/apikeys",
66
+ docsLabel: "Stripe Dashboard -> Developers -> API Keys"
67
+ }
68
+ )
69
+ }
70
+ ),
71
+ /* @__PURE__ */ e(
72
+ b,
73
+ {
74
+ id: "freemius-enabled",
75
+ label: "Freemius for Digital Products",
76
+ description: "Use Freemius for software licenses, SaaS plans, and other digital products.",
77
+ checked: d.freemius,
78
+ disabled: !o,
79
+ onCheckedChange: (p) => m((h) => ({
80
+ ...h,
81
+ freemius: p
82
+ })),
83
+ ready: o,
84
+ children: o ? /* @__PURE__ */ r("div", { className: "mt-2 text-sm text-green-600 flex items-center gap-2", children: [
85
+ /* @__PURE__ */ e(u, { className: "w-4 h-4" }),
86
+ /* @__PURE__ */ e("span", { children: "Ready to process digital product checkout" })
87
+ ] }) : /* @__PURE__ */ e(
88
+ f,
89
+ {
90
+ provider: "Freemius",
91
+ missingKeys: t.freemius.missing,
92
+ docsUrl: "https://dashboard.freemius.com/",
93
+ docsLabel: "Freemius Dashboard -> Developers -> Credentials"
94
+ }
95
+ )
96
+ }
97
+ ),
98
+ /* @__PURE__ */ e("div", { className: "flex justify-end pt-4", children: /* @__PURE__ */ e(C, {}) })
99
+ ] })
95
100
  ] })
96
101
  ] })
97
102
  ] });
98
103
  }
99
- function w() {
100
- const { pending: i } = P();
101
- return /* @__PURE__ */ e(C, { type: "submit", disabled: i, children: i ? "Saving..." : "Save Changes" });
104
+ function C() {
105
+ const { pending: s } = I();
106
+ return /* @__PURE__ */ e(S, { type: "submit", disabled: s, children: s ? "Saving..." : "Save Changes" });
102
107
  }
103
- function h({
104
- id: i,
108
+ function n({
109
+ id: s,
105
110
  label: t,
106
- description: d,
107
- checked: s,
108
- disabled: a,
109
- ready: n,
110
- onCheckedChange: l,
111
- children: o
111
+ type: i = "text",
112
+ defaultValue: a,
113
+ placeholder: l,
114
+ hint: d
115
+ }) {
116
+ return /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
117
+ /* @__PURE__ */ e(k, { htmlFor: s, children: t }),
118
+ /* @__PURE__ */ e(
119
+ K,
120
+ {
121
+ id: s,
122
+ name: s,
123
+ type: i,
124
+ defaultValue: a,
125
+ placeholder: l,
126
+ autoComplete: i === "password" ? "new-password" : "off"
127
+ }
128
+ ),
129
+ d && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: d })
130
+ ] });
131
+ }
132
+ function F({
133
+ credentials: s,
134
+ saveAction: t
135
+ }) {
136
+ const i = "•••••••• (stored — leave blank to keep)";
137
+ return /* @__PURE__ */ r(v, { children: [
138
+ /* @__PURE__ */ r(y, { children: [
139
+ /* @__PURE__ */ e(g, { children: "Provider API Keys" }),
140
+ /* @__PURE__ */ r(x, { children: [
141
+ "Keys are encrypted at rest and used DB-first (these override any ",
142
+ /* @__PURE__ */ e("code", { children: ".env" }),
143
+ " ",
144
+ "values). Leave a secret blank to keep the stored value."
145
+ ] })
146
+ ] }),
147
+ /* @__PURE__ */ e(N, { children: /* @__PURE__ */ r("form", { action: t, className: "space-y-6", children: [
148
+ /* @__PURE__ */ r("div", { className: "space-y-4", children: [
149
+ /* @__PURE__ */ e("h3", { className: "text-sm font-semibold", children: "Stripe (physical products)" }),
150
+ /* @__PURE__ */ r("div", { className: "grid gap-4 sm:grid-cols-2", children: [
151
+ /* @__PURE__ */ e(
152
+ n,
153
+ {
154
+ id: "stripe_publishableKey",
155
+ label: "Publishable key",
156
+ defaultValue: s.stripe.publishableKey,
157
+ placeholder: "pk_live_…"
158
+ }
159
+ ),
160
+ /* @__PURE__ */ e(
161
+ n,
162
+ {
163
+ id: "stripe_secretKey",
164
+ label: "Secret key",
165
+ type: "password",
166
+ placeholder: s.stripe.hasSecretKey ? i : "sk_live_…"
167
+ }
168
+ ),
169
+ /* @__PURE__ */ e(
170
+ n,
171
+ {
172
+ id: "stripe_webhookSecret",
173
+ label: "Webhook signing secret",
174
+ type: "password",
175
+ placeholder: s.stripe.hasWebhookSecret ? i : "whsec_…"
176
+ }
177
+ )
178
+ ] })
179
+ ] }),
180
+ /* @__PURE__ */ r("div", { className: "space-y-4", children: [
181
+ /* @__PURE__ */ e("h3", { className: "text-sm font-semibold", children: "Freemius (digital products)" }),
182
+ /* @__PURE__ */ r("div", { className: "grid gap-4 sm:grid-cols-2", children: [
183
+ /* @__PURE__ */ e(
184
+ n,
185
+ {
186
+ id: "freemius_developerId",
187
+ label: "Developer ID",
188
+ defaultValue: s.freemius.developerId
189
+ }
190
+ ),
191
+ /* @__PURE__ */ e(
192
+ n,
193
+ {
194
+ id: "freemius_productId",
195
+ label: "Product ID",
196
+ defaultValue: s.freemius.productId
197
+ }
198
+ ),
199
+ /* @__PURE__ */ e(
200
+ n,
201
+ {
202
+ id: "freemius_publicKey",
203
+ label: "Public key",
204
+ defaultValue: s.freemius.publicKey,
205
+ placeholder: "pk_…"
206
+ }
207
+ ),
208
+ /* @__PURE__ */ e(
209
+ n,
210
+ {
211
+ id: "freemius_secretKey",
212
+ label: "Secret key",
213
+ type: "password",
214
+ placeholder: s.freemius.hasSecretKey ? i : "sk_…"
215
+ }
216
+ ),
217
+ /* @__PURE__ */ e(
218
+ n,
219
+ {
220
+ id: "freemius_apiKey",
221
+ label: "API key",
222
+ type: "password",
223
+ placeholder: s.freemius.hasApiKey ? i : "API key"
224
+ }
225
+ )
226
+ ] })
227
+ ] }),
228
+ s.envFallbackActive && /* @__PURE__ */ e("p", { className: "text-xs text-amber-700", children: "Stripe keys are currently read from environment variables. Saving here moves them into the database and takes precedence." }),
229
+ /* @__PURE__ */ e("div", { className: "flex justify-end", children: /* @__PURE__ */ e(C, {}) })
230
+ ] }) })
231
+ ] });
232
+ }
233
+ function b({
234
+ id: s,
235
+ label: t,
236
+ description: i,
237
+ checked: a,
238
+ disabled: l,
239
+ ready: d,
240
+ onCheckedChange: m,
241
+ children: c
112
242
  }) {
113
243
  return /* @__PURE__ */ e("div", { className: "rounded-md border p-4", children: /* @__PURE__ */ r("div", { className: "flex items-start gap-3", children: [
114
244
  /* @__PURE__ */ e(
115
- y,
245
+ w,
116
246
  {
117
- id: i,
118
- checked: s,
119
- disabled: a,
120
- onCheckedChange: (c) => l(!!c),
247
+ id: s,
248
+ checked: a,
249
+ disabled: l,
250
+ onCheckedChange: (o) => m(!!o),
121
251
  className: "mt-1"
122
252
  }
123
253
  ),
124
254
  /* @__PURE__ */ r("div", { className: "grid gap-1.5 leading-none w-full", children: [
125
255
  /* @__PURE__ */ r("div", { className: "flex items-center justify-between gap-3 flex-wrap", children: [
126
- /* @__PURE__ */ e(N, { htmlFor: i, className: "font-semibold text-base cursor-pointer", children: t }),
256
+ /* @__PURE__ */ e(k, { htmlFor: s, className: "font-semibold text-base cursor-pointer", children: t }),
127
257
  /* @__PURE__ */ e(
128
258
  "span",
129
259
  {
130
- className: `text-xs font-medium ${s ? "text-foreground" : "text-muted-foreground"}`,
131
- children: s ? "Enabled" : "Disabled"
260
+ className: `text-xs font-medium ${a ? "text-foreground" : "text-muted-foreground"}`,
261
+ children: a ? "Enabled" : "Disabled"
132
262
  }
133
263
  )
134
264
  ] }),
135
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: d }),
136
- !n && /* @__PURE__ */ e("p", { className: "text-xs text-amber-700", children: "This provider cannot be enabled until all required environment variables are present." }),
137
- o
265
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: i }),
266
+ !d && /* @__PURE__ */ e("p", { className: "text-xs text-amber-700", children: "This provider cannot be enabled until all required environment variables are present." }),
267
+ c
138
268
  ] })
139
269
  ] }) });
140
270
  }
141
- function p({
142
- provider: i,
271
+ function f({
272
+ provider: s,
143
273
  missingKeys: t,
144
- docsUrl: d,
145
- docsLabel: s
274
+ docsUrl: i,
275
+ docsLabel: a
146
276
  }) {
147
277
  return /* @__PURE__ */ r("div", { className: "mt-3 text-sm p-4 rounded-md border border-destructive/20 bg-destructive/5 text-foreground", children: [
148
278
  /* @__PURE__ */ r("div", { className: "flex items-center gap-2 font-semibold text-destructive mb-2", children: [
149
- /* @__PURE__ */ e(k, { className: "w-4 h-4" }),
279
+ /* @__PURE__ */ e(_, { className: "w-4 h-4" }),
150
280
  /* @__PURE__ */ e("span", { children: "Configuration Required" })
151
281
  ] }),
152
282
  /* @__PURE__ */ r("p", { className: "mb-2", children: [
153
283
  "The ",
154
- i,
155
- " integration is missing the following environment variables:"
284
+ s,
285
+ " integration still needs the following:"
156
286
  ] }),
157
- /* @__PURE__ */ e("ul", { className: "list-disc list-inside bg-white/50 dark:bg-black/20 p-2 rounded mb-3 font-mono text-xs", children: t.map((a) => /* @__PURE__ */ e("li", { children: a }, a)) }),
287
+ /* @__PURE__ */ e("ul", { className: "list-disc list-inside bg-white/50 dark:bg-black/20 p-2 rounded mb-3 text-xs", children: t.map((l) => /* @__PURE__ */ e("li", { children: l }, l)) }),
158
288
  /* @__PURE__ */ e("p", { className: "mb-2", children: /* @__PURE__ */ e("strong", { children: "How to fix:" }) }),
159
289
  /* @__PURE__ */ r("ol", { className: "list-decimal list-inside space-y-1 ml-1 mb-3", children: [
160
290
  /* @__PURE__ */ r("li", { children: [
161
- "Go to",
291
+ "Get your API keys from",
162
292
  " ",
163
293
  /* @__PURE__ */ e(
164
294
  "a",
165
295
  {
166
- href: d,
296
+ href: i,
167
297
  target: "_blank",
168
298
  rel: "noopener noreferrer",
169
299
  className: "underline font-medium hover:text-destructive/80",
170
- children: s
300
+ children: a
171
301
  }
172
302
  ),
173
303
  "."
174
304
  ] }),
175
- /* @__PURE__ */ e("li", { children: "Copy your API keys." }),
176
305
  /* @__PURE__ */ r("li", { children: [
177
- "Open your ",
178
- /* @__PURE__ */ e("code", { children: ".env" }),
179
- " (or variables settings in Vercel/Railway)."
306
+ "Enter them in the ",
307
+ /* @__PURE__ */ e("strong", { children: "Provider API Keys" }),
308
+ " section above and save."
180
309
  ] }),
181
- /* @__PURE__ */ e("li", { children: "Add the keys listed above." }),
182
- /* @__PURE__ */ e("li", { children: "Restart your development server." })
310
+ /* @__PURE__ */ e("li", { children: "This provider can then be enabled." })
183
311
  ] })
184
312
  ] });
185
313
  }
186
314
  export {
187
- j as PaymentsClient
315
+ T as PaymentsClient
188
316
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),u=require("./actions.cjs.js"),s=require("./queries.cjs.js"),o=require("./PaymentsClient.cjs.js");async function c(){const[n,e]=await Promise.all([s.getEnabledPaymentProviders(),s.getStoreConfigStatus()]);async function i(t){"use server";const r={stripe:t.get("stripe_enabled")==="true"&&e.stripe.hasKeys,freemius:t.get("freemius_enabled")==="true"&&e.freemius.hasKeys};await u.updatePaymentSettings(r)}return a.jsx(o.PaymentsClient,{initialEnabledProviders:n,configStatus:e,saveAction:i})}exports.PaymentsPage=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),n=require("./actions.cjs.js"),s=require("./queries.cjs.js"),c=require("../../../payment-config.cjs.js"),l=require("./PaymentsClient.cjs.js");async function y(){const[i,e,a]=await Promise.all([s.getEnabledPaymentProviders(),s.getStoreConfigStatus(),c.getPaymentCredentialsView()]);async function r(t){"use server";const o={stripe:t.get("stripe_enabled")==="true"&&e.stripe.hasKeys,freemius:t.get("freemius_enabled")==="true"&&e.freemius.hasKeys};await n.updatePaymentSettings(o)}return u.jsx(l.PaymentsClient,{initialEnabledProviders:i,configStatus:e,credentials:a,saveAction:r,saveCredentialsAction:n.savePaymentProviderCredentials})}exports.PaymentsPage=y;
@@ -1,29 +1,33 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { updatePaymentSettings as a } from "./actions.es.js";
3
- import { getEnabledPaymentProviders as o, getStoreConfigStatus as m } from "./queries.es.js";
4
- import { PaymentsClient as u } from "./PaymentsClient.es.js";
5
- async function P() {
6
- const [s, e] = await Promise.all([
7
- o(),
8
- m()
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import { savePaymentProviderCredentials as o, updatePaymentSettings as m } from "./actions.es.js";
3
+ import { getEnabledPaymentProviders as d, getStoreConfigStatus as l } from "./queries.es.js";
4
+ import { getPaymentCredentialsView as u } from "../../../payment-config.es.js";
5
+ import { PaymentsClient as P } from "./PaymentsClient.es.js";
6
+ async function v() {
7
+ const [i, e, s] = await Promise.all([
8
+ d(),
9
+ l(),
10
+ u()
9
11
  ]);
10
- async function i(t) {
12
+ async function n(t) {
11
13
  "use server";
12
- const n = {
14
+ const r = {
13
15
  stripe: t.get("stripe_enabled") === "true" && e.stripe.hasKeys,
14
16
  freemius: t.get("freemius_enabled") === "true" && e.freemius.hasKeys
15
17
  };
16
- await a(n);
18
+ await m(r);
17
19
  }
18
- return /* @__PURE__ */ r(
19
- u,
20
+ return /* @__PURE__ */ a(
21
+ P,
20
22
  {
21
- initialEnabledProviders: s,
23
+ initialEnabledProviders: i,
22
24
  configStatus: e,
23
- saveAction: i
25
+ credentials: s,
26
+ saveAction: n,
27
+ saveCredentialsAction: o
24
28
  }
25
29
  );
26
30
  }
27
31
  export {
28
- P as PaymentsPage
32
+ v as PaymentsPage
29
33
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),t=require("next/cache");async function n(o){const e=await i.createClient(),{data:{user:r}}=await e.auth.getUser();if(!r)throw new Error("Unauthorized");const{data:a}=await e.from("profiles").select("role").eq("id",r.id).single();if(!a||a.role!=="ADMIN")throw new Error("Forbidden");const{error:s}=await e.from("site_settings").upsert({key:"enabled_payment_providers",value:o});if(s)throw console.error("Error updating payment providers:",s),new Error("Failed to update settings");return t.revalidatePath("/cms/payments"),t.revalidatePath("/cms/taxes"),t.revalidatePath("/","layout"),{success:!0}}exports.updatePaymentSettings=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@nextblock-cms/db/server"),i=require("next/cache"),o=require("../../../payment-config.cjs.js");async function d(){const e=await n.createClient(),{data:{user:t}}=await e.auth.getUser();if(!t)throw new Error("Unauthorized");const{data:r}=await e.from("profiles").select("role").eq("id",t.id).single();if(!r||r.role!=="ADMIN")throw new Error("Forbidden")}async function c(e){await d(),await o.savePaymentCredentials({stripe:{publishableKey:String(e.get("stripe_publishableKey")??""),secretKey:String(e.get("stripe_secretKey")??""),webhookSecret:String(e.get("stripe_webhookSecret")??"")},freemius:{developerId:String(e.get("freemius_developerId")??""),publicKey:String(e.get("freemius_publicKey")??""),productId:String(e.get("freemius_productId")??""),secretKey:String(e.get("freemius_secretKey")??""),apiKey:String(e.get("freemius_apiKey")??"")}}),i.revalidatePath("/cms/payments")}async function u(e){const t=await n.createClient(),{data:{user:r}}=await t.auth.getUser();if(!r)throw new Error("Unauthorized");const{data:s}=await t.from("profiles").select("role").eq("id",r.id).single();if(!s||s.role!=="ADMIN")throw new Error("Forbidden");const{error:a}=await t.from("site_settings").upsert({key:"enabled_payment_providers",value:e});if(a)throw console.error("Error updating payment providers:",a),new Error("Failed to update settings");return i.revalidatePath("/cms/payments"),i.revalidatePath("/cms/taxes"),i.revalidatePath("/","layout"),{success:!0}}exports.savePaymentProviderCredentials=c;exports.updatePaymentSettings=u;
@@ -1,4 +1,5 @@
1
1
  import { EnabledPaymentProviders } from '../../../types';
2
+ export declare function savePaymentProviderCredentials(formData: FormData): Promise<void>;
2
3
  export declare function updatePaymentSettings(enabledProviders: EnabledPaymentProviders): Promise<{
3
4
  success: boolean;
4
5
  }>;
@@ -1,23 +1,51 @@
1
1
  'use server';
2
- import { createClient as i } from "@nextblock-cms/db/server";
3
- import { revalidatePath as r } from "next/cache";
4
- async function p(s) {
5
- const e = await i(), {
6
- data: { user: t }
2
+ import { createClient as o } from "@nextblock-cms/db/server";
3
+ import { revalidatePath as i } from "next/cache";
4
+ import { savePaymentCredentials as a } from "../../../payment-config.es.js";
5
+ async function d() {
6
+ const e = await o(), {
7
+ data: { user: r }
7
8
  } = await e.auth.getUser();
9
+ if (!r)
10
+ throw new Error("Unauthorized");
11
+ const { data: t } = await e.from("profiles").select("role").eq("id", r.id).single();
12
+ if (!t || t.role !== "ADMIN")
13
+ throw new Error("Forbidden");
14
+ }
15
+ async function l(e) {
16
+ await d(), await a({
17
+ stripe: {
18
+ publishableKey: String(e.get("stripe_publishableKey") ?? ""),
19
+ secretKey: String(e.get("stripe_secretKey") ?? ""),
20
+ webhookSecret: String(e.get("stripe_webhookSecret") ?? "")
21
+ },
22
+ freemius: {
23
+ developerId: String(e.get("freemius_developerId") ?? ""),
24
+ publicKey: String(e.get("freemius_publicKey") ?? ""),
25
+ productId: String(e.get("freemius_productId") ?? ""),
26
+ secretKey: String(e.get("freemius_secretKey") ?? ""),
27
+ apiKey: String(e.get("freemius_apiKey") ?? "")
28
+ }
29
+ }), i("/cms/payments");
30
+ }
31
+ async function g(e) {
32
+ const r = await o(), {
33
+ data: { user: t }
34
+ } = await r.auth.getUser();
8
35
  if (!t)
9
36
  throw new Error("Unauthorized");
10
- const { data: a } = await e.from("profiles").select("role").eq("id", t.id).single();
11
- if (!a || a.role !== "ADMIN")
37
+ const { data: s } = await r.from("profiles").select("role").eq("id", t.id).single();
38
+ if (!s || s.role !== "ADMIN")
12
39
  throw new Error("Forbidden");
13
- const { error: o } = await e.from("site_settings").upsert({
40
+ const { error: n } = await r.from("site_settings").upsert({
14
41
  key: "enabled_payment_providers",
15
- value: s
42
+ value: e
16
43
  });
17
- if (o)
18
- throw console.error("Error updating payment providers:", o), new Error("Failed to update settings");
19
- return r("/cms/payments"), r("/cms/taxes"), r("/", "layout"), { success: !0 };
44
+ if (n)
45
+ throw console.error("Error updating payment providers:", n), new Error("Failed to update settings");
46
+ return i("/cms/payments"), i("/cms/taxes"), i("/", "layout"), { success: !0 };
20
47
  }
21
48
  export {
22
- p as updatePaymentSettings
49
+ l as savePaymentProviderCredentials,
50
+ g as updatePaymentSettings
23
51
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),t=require("../../../types.cjs.js");async function E(){const e=[];process.env.STRIPE_SECRET_KEY||e.push("STRIPE_SECRET_KEY"),process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY||e.push("NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY"),process.env.STRIPE_WEBHOOK_SECRET||e.push("STRIPE_WEBHOOK_SECRET");const s=[];return process.env.FREEMIUS_PUBLIC_KEY||s.push("FREEMIUS_PUBLIC_KEY"),process.env.FREEMIUS_SECRET_KEY||s.push("FREEMIUS_SECRET_KEY"),{stripe:{hasKeys:e.length===0,missing:e},freemius:{hasKeys:s.length===0,missing:s}}}async function n(){const e=i.createClient(),{data:s,error:r}=await e.from("site_settings").select("value").eq("key","enabled_payment_providers").maybeSingle();return r||!s?{...t.DEFAULT_ENABLED_PAYMENT_PROVIDERS}:t.normalizeEnabledPaymentProviders(s.value)}async function a(){const e=await n();return e.stripe?"stripe":e.freemius?"freemius":"stripe"}exports.getEnabledPaymentProviders=n;exports.getPaymentSettings=a;exports.getStoreConfigStatus=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@nextblock-cms/db/server"),r=require("../../../types.cjs.js"),s=require("../../../payment-config.cjs.js");async function o(){return s.getPaymentConfigStatus()}async function n(){const e=a.createClient(),{data:t,error:i}=await e.from("site_settings").select("value").eq("key","enabled_payment_providers").maybeSingle();return i||!t?{...r.DEFAULT_ENABLED_PAYMENT_PROVIDERS}:r.normalizeEnabledPaymentProviders(t.value)}async function u(){const e=await n();return e.stripe?"stripe":e.freemius?"freemius":"stripe"}exports.getEnabledPaymentProviders=n;exports.getPaymentSettings=u;exports.getStoreConfigStatus=o;
@@ -1,30 +1,19 @@
1
- import { createClient as r } from "@nextblock-cms/db/server";
2
- import { DEFAULT_ENABLED_PAYMENT_PROVIDERS as n, normalizeEnabledPaymentProviders as t } from "../../../types.es.js";
3
- async function o() {
4
- const e = [];
5
- process.env.STRIPE_SECRET_KEY || e.push("STRIPE_SECRET_KEY"), process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY || e.push("NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY"), process.env.STRIPE_WEBHOOK_SECRET || e.push("STRIPE_WEBHOOK_SECRET");
6
- const s = [];
7
- return process.env.FREEMIUS_PUBLIC_KEY || s.push("FREEMIUS_PUBLIC_KEY"), process.env.FREEMIUS_SECRET_KEY || s.push("FREEMIUS_SECRET_KEY"), {
8
- stripe: {
9
- hasKeys: e.length === 0,
10
- missing: e
11
- },
12
- freemius: {
13
- hasKeys: s.length === 0,
14
- missing: s
15
- }
16
- };
1
+ import { createClient as n } from "@nextblock-cms/db/server";
2
+ import { DEFAULT_ENABLED_PAYMENT_PROVIDERS as i, normalizeEnabledPaymentProviders as a } from "../../../types.es.js";
3
+ import { getPaymentConfigStatus as s } from "../../../payment-config.es.js";
4
+ async function c() {
5
+ return s();
17
6
  }
18
- async function i() {
19
- const e = r(), { data: s, error: E } = await e.from("site_settings").select("value").eq("key", "enabled_payment_providers").maybeSingle();
20
- return E || !s ? { ...n } : t(s.value);
7
+ async function o() {
8
+ const e = n(), { data: t, error: r } = await e.from("site_settings").select("value").eq("key", "enabled_payment_providers").maybeSingle();
9
+ return r || !t ? { ...i } : a(t.value);
21
10
  }
22
- async function S() {
23
- const e = await i();
11
+ async function l() {
12
+ const e = await o();
24
13
  return e.stripe ? "stripe" : e.freemius ? "freemius" : "stripe";
25
14
  }
26
15
  export {
27
- i as getEnabledPaymentProviders,
28
- S as getPaymentSettings,
29
- o as getStoreConfigStatus
16
+ o as getEnabledPaymentProviders,
17
+ l as getPaymentSettings,
18
+ c as getStoreConfigStatus
30
19
  };