@velastack/patterns 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/_page-B6yd6_Vl.js +6 -0
- package/dist/chunks/_page-B6yd6_Vl.js.map +1 -0
- package/dist/chunks/generate-BrOPb9tW.js +175 -0
- package/dist/chunks/generate-BrOPb9tW.js.map +1 -0
- package/dist/chunks/generate.runtime-DuDcKDUl.js +162 -0
- package/dist/chunks/generate.runtime-DuDcKDUl.js.map +1 -0
- package/dist/chunks/{generate.runtime-X-uAteso.js → generate.runtime-J2lLMjDn.js} +46 -94
- package/dist/chunks/generate.runtime-J2lLMjDn.js.map +1 -0
- package/dist/chunks/generate.runtime-nyJ6v56q.js +64 -0
- package/dist/chunks/generate.runtime-nyJ6v56q.js.map +1 -0
- package/dist/chunks/modify-nav-user-iUpv2lm-.js +53 -0
- package/dist/chunks/modify-nav-user-iUpv2lm-.js.map +1 -0
- package/dist/index.d.ts +156 -2
- package/dist/index.js +1971 -1806
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/generate.runtime-X-uAteso.js.map +0 -1
|
@@ -9,11 +9,10 @@ import { a as m, i as h, r as g } from "./collections-DZOuRpvS.js";
|
|
|
9
9
|
import { i as _, n as v, t as y } from "./pocketbase-BtN-wL8f.js";
|
|
10
10
|
import { a as b, i as x, r as S, s as C, t as w } from "./site-VrqOvuiU.js";
|
|
11
11
|
import { t as T } from "./env-BugddEjd.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { a as A, r as j, s as M, t as ee } from "./root-layout.svelte-CUVbnlX-.js";
|
|
12
|
+
import { r as E } from "./modify-file-B4uJzOEj.js";
|
|
13
|
+
import { modifyEnvVarsFiles as D } from "./env-vars-0hvKe55u.js";
|
|
14
|
+
import { n as O } from "./modify-nav-user-iUpv2lm-.js";
|
|
15
|
+
import { a as k, r as A, s as j, t as M } from "./root-layout.svelte-CUVbnlX-.js";
|
|
17
16
|
import { n as N, t as P } from "./wuchale-config-c3Q4JVSF.js";
|
|
18
17
|
import { t as F } from "./modify-user-signup-DLtopazD.js";
|
|
19
18
|
import { i as I, r as L } from "./collections-BYcVyY9O.js";
|
|
@@ -40,55 +39,8 @@ async function V(e) {
|
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
//#endregion
|
|
43
|
-
//#region src/patterns/enable/payments/modifies/modify-nav-user.ts
|
|
44
|
-
var H = [
|
|
45
|
-
"import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
|
|
46
|
-
"",
|
|
47
|
-
"// Add to your navUser array:",
|
|
48
|
-
"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
|
|
49
|
-
].join("\n"), U = [
|
|
50
|
-
"Add a Billing nav item to nav-user.svelte:",
|
|
51
|
-
"",
|
|
52
|
-
H
|
|
53
|
-
].join("\n"), W = [
|
|
54
|
-
"Create nav-user.svelte with a Billing entry:",
|
|
55
|
-
"",
|
|
56
|
-
H
|
|
57
|
-
].join("\n");
|
|
58
|
-
function G(e, t, n, r, i) {
|
|
59
|
-
let a = new k(e), o = !1, s = (e) => {
|
|
60
|
-
o || e((e) => {
|
|
61
|
-
let a = E(e, t, n, r, i);
|
|
62
|
-
return a.wasAdded && (o = !0), a.source;
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
return s((e) => a.modifyModuleScript(e)), o || s((e) => a.modifyScript(e)), {
|
|
66
|
-
newNavUserSnippet: a.toString(),
|
|
67
|
-
wasAdded: o
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function K(e) {
|
|
71
|
-
if (!R.existsSync(e)) return {
|
|
72
|
-
status: "not-found",
|
|
73
|
-
message: W
|
|
74
|
-
};
|
|
75
|
-
let t = R.readFileSync(e, "utf8");
|
|
76
|
-
if (t.includes("/billing")) return {
|
|
77
|
-
status: "success",
|
|
78
|
-
changed: !1
|
|
79
|
-
};
|
|
80
|
-
let { newNavUserSnippet: n, wasAdded: r } = G(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
|
|
81
|
-
return r ? (R.writeFileSync(e, n, "utf8"), {
|
|
82
|
-
status: "success",
|
|
83
|
-
changed: !0
|
|
84
|
-
}) : {
|
|
85
|
-
status: "failed",
|
|
86
|
-
message: U
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
42
|
//#region src/patterns/enable/payments/runtime/stripe.ts
|
|
91
|
-
async function
|
|
43
|
+
async function H(e, t, n) {
|
|
92
44
|
let r = new B(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
|
|
93
45
|
total: i.length,
|
|
94
46
|
linked: o.size,
|
|
@@ -141,7 +93,7 @@ async function q(e, t, n) {
|
|
|
141
93
|
}
|
|
142
94
|
return s;
|
|
143
95
|
}
|
|
144
|
-
async function
|
|
96
|
+
async function U(e) {
|
|
145
97
|
let t = new B(e), n = await t.products.search({
|
|
146
98
|
query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
|
|
147
99
|
limit: 1
|
|
@@ -172,7 +124,7 @@ async function J(e) {
|
|
|
172
124
|
existing: !1
|
|
173
125
|
};
|
|
174
126
|
}
|
|
175
|
-
async function
|
|
127
|
+
async function W(e, t) {
|
|
176
128
|
let n = new B(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
|
|
177
129
|
return r.product = i.id, {
|
|
178
130
|
product: i,
|
|
@@ -182,8 +134,8 @@ async function Y(e, t) {
|
|
|
182
134
|
}
|
|
183
135
|
//#endregion
|
|
184
136
|
//#region src/patterns/enable/payments/runtime/setup-stripe.ts
|
|
185
|
-
var
|
|
186
|
-
async function
|
|
137
|
+
var G;
|
|
138
|
+
async function K(e, n, r, i, a = !0) {
|
|
187
139
|
if (!a) return;
|
|
188
140
|
await v();
|
|
189
141
|
let o = y(n, r, i);
|
|
@@ -194,10 +146,10 @@ async function Z(e, n, r, i, a = !0) {
|
|
|
194
146
|
status: "success"
|
|
195
147
|
});
|
|
196
148
|
}
|
|
197
|
-
function
|
|
198
|
-
return s(
|
|
149
|
+
function q(e) {
|
|
150
|
+
return s(G ||= c(["\n <script lang=\"ts\">\n import PaymentButton from '#lib/components/payments/payment-button.svelte';\n <\/script>\n\n <section data-role=\"content\">\n <PaymentButton priceId=\"", "\" />\n </section>\n "]), e);
|
|
199
151
|
}
|
|
200
|
-
async function
|
|
152
|
+
async function J(e) {
|
|
201
153
|
let t = o(e).STRIPE_SECRET_KEY ?? "", n = typeof e.input.demoId == "string" && e.input.demoId !== "" ? e.input.demoId : void 0, r = e.features.auth, i = l(e), a = [], s = [], c = (e) => {
|
|
202
154
|
e && s.push(e);
|
|
203
155
|
};
|
|
@@ -206,7 +158,7 @@ async function te(e) {
|
|
|
206
158
|
for (let t of [h, g]) {
|
|
207
159
|
i.info(`Creating ${t.name} collection`);
|
|
208
160
|
let r = await o(t);
|
|
209
|
-
await
|
|
161
|
+
await K(a, t.name, "created", e, r.created), r.created || a.push(...await I(n, t, e, i));
|
|
210
162
|
}
|
|
211
163
|
if (r) {
|
|
212
164
|
i.info("Creating stripe_customers collection");
|
|
@@ -244,7 +196,7 @@ async function te(e) {
|
|
|
244
196
|
}
|
|
245
197
|
]
|
|
246
198
|
}), s = r.collection;
|
|
247
|
-
await
|
|
199
|
+
await K(a, "stripe_customers", "created", e, r.created), i.info("Creating stripe_payment_methods collection");
|
|
248
200
|
let c = await o({
|
|
249
201
|
name: "stripe_payment_methods",
|
|
250
202
|
type: "base",
|
|
@@ -300,7 +252,7 @@ async function te(e) {
|
|
|
300
252
|
}
|
|
301
253
|
]
|
|
302
254
|
}), l = c.collection;
|
|
303
|
-
await
|
|
255
|
+
await K(a, "stripe_payment_methods", "created", e, c.created), i.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
|
|
304
256
|
{
|
|
305
257
|
name: "id",
|
|
306
258
|
pattern: "^[a-zA-Z0-9_]+$",
|
|
@@ -337,7 +289,7 @@ async function te(e) {
|
|
|
337
289
|
onUpdate: !0,
|
|
338
290
|
type: "autodate"
|
|
339
291
|
}
|
|
340
|
-
] }), await
|
|
292
|
+
] }), await K(a, "stripe_customers", "updated", e), i.info("Creating transactions collection");
|
|
341
293
|
let u = await o({
|
|
342
294
|
name: "transactions",
|
|
343
295
|
type: "base",
|
|
@@ -408,12 +360,12 @@ async function te(e) {
|
|
|
408
360
|
}
|
|
409
361
|
]
|
|
410
362
|
});
|
|
411
|
-
await
|
|
412
|
-
let d = await
|
|
363
|
+
await K(a, "transactions", "created", e, u.created), i.info("Syncing existing PocketBase users to Stripe customers");
|
|
364
|
+
let d = await H(n, t, i);
|
|
413
365
|
i.info(`Synced ${d.total} users (created ${d.created}, reused ${d.reused}, skipped ${d.skipped})`);
|
|
414
366
|
}
|
|
415
367
|
}), n ? i.info(`Fetching Stripe product/price ${n}`) : i.info("Creating test Stripe product and price");
|
|
416
|
-
let { product: u, price: d, existing: f } = n ? await
|
|
368
|
+
let { product: u, price: d, existing: f } = n ? await W(t, n) : await U(t);
|
|
417
369
|
if (f && i.info("Stripe product/price already exists, skipping creation"), i.info("Seeding Stripe product/price records"), await _(e.root, async (e) => {
|
|
418
370
|
try {
|
|
419
371
|
await e.collection("stripe_products").getOne(u.id);
|
|
@@ -442,14 +394,14 @@ async function te(e) {
|
|
|
442
394
|
}), i.info("Creating payment +page.svelte"), a.push({
|
|
443
395
|
path: "src/routes/(public)/payment/+page.svelte",
|
|
444
396
|
language: "svelte",
|
|
445
|
-
content:
|
|
397
|
+
content: q(d.id),
|
|
446
398
|
status: "success"
|
|
447
399
|
}), r) {
|
|
448
400
|
i.info("Modifying nav-user.svelte");
|
|
449
401
|
let t = z.join(e.root, "src", "lib", "components", "nav-user.svelte");
|
|
450
|
-
c(
|
|
402
|
+
c(E(t, O(t))), i.info("Modifying signup +page.server.ts");
|
|
451
403
|
let n = z.join(e.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
|
|
452
|
-
c(
|
|
404
|
+
c(E(n, F(n)));
|
|
453
405
|
}
|
|
454
406
|
return {
|
|
455
407
|
creates: a,
|
|
@@ -464,7 +416,7 @@ async function te(e) {
|
|
|
464
416
|
}
|
|
465
417
|
//#endregion
|
|
466
418
|
//#region src/patterns/enable/payments/runtime/setup-whatsapp.ts
|
|
467
|
-
async function
|
|
419
|
+
async function Y(t, n) {
|
|
468
420
|
if (!n.currency) {
|
|
469
421
|
let n = t.input.currency;
|
|
470
422
|
throw new e(n === void 0 || n === "" ? "Payments on WhatsApp need the business's currency, the one it prices in (an ISO 4217 code such as MXN or EUR). Pass --currency, or set `currency` in src/lib/site.ts." : `${String(n)} is not an ISO 4217 currency code, such as MXN or EUR.`);
|
|
@@ -472,7 +424,7 @@ async function ne(t, n) {
|
|
|
472
424
|
let r = [], i = z.join(t.root, "wuchale.config.js");
|
|
473
425
|
if (R.existsSync(i)) {
|
|
474
426
|
l(t).info("Adding src/lib/order.ts to wuchale's js adapter");
|
|
475
|
-
let e =
|
|
427
|
+
let e = E(i, N(i, P));
|
|
476
428
|
e && r.push(e);
|
|
477
429
|
}
|
|
478
430
|
return {
|
|
@@ -488,14 +440,14 @@ async function ne(t, n) {
|
|
|
488
440
|
}
|
|
489
441
|
//#endregion
|
|
490
442
|
//#region src/patterns/enable/payments/generate.runtime.ts
|
|
491
|
-
var
|
|
443
|
+
var X = /* #__PURE__ */ Object.assign({
|
|
492
444
|
"./creates-server/src/lib/currency.server.test.ts": d,
|
|
493
445
|
"./creates-server/src/lib/currency.server.ts": p
|
|
494
446
|
});
|
|
495
|
-
function
|
|
496
|
-
return Object.values(r(
|
|
447
|
+
function Z(e) {
|
|
448
|
+
return Object.values(r(X, "./creates-server/")).filter((t) => e || !t.path.endsWith(".test.ts")).sort((e, t) => e.path.localeCompare(t.path));
|
|
497
449
|
}
|
|
498
|
-
function
|
|
450
|
+
function Q(e) {
|
|
499
451
|
try {
|
|
500
452
|
let t = JSON.parse(R.readFileSync(z.join(e, "package.json"), "utf8"));
|
|
501
453
|
return !!(t.devDependencies?.vitest || t.dependencies?.vitest);
|
|
@@ -503,36 +455,36 @@ function $(e) {
|
|
|
503
455
|
return !1;
|
|
504
456
|
}
|
|
505
457
|
}
|
|
506
|
-
async function
|
|
458
|
+
async function $(e) {
|
|
507
459
|
let t = l(e), r = a(f, e), s = [], c = [], d = (e) => {
|
|
508
460
|
e && c.push(e);
|
|
509
461
|
};
|
|
510
462
|
t.info(`Writing ${r.label} credentials to .env`);
|
|
511
463
|
let p = z.join(e.root, ".env");
|
|
512
|
-
d(
|
|
513
|
-
let m =
|
|
464
|
+
d(E(p, T(p, u(r, o(e))))), t.info(`Declaring ${r.label} variables in src/env.ts`);
|
|
465
|
+
let m = D(e.root, i(r));
|
|
514
466
|
m.create && s.push(m.create), d(m.modify);
|
|
515
|
-
let { currency: h, country: g, currencies: _ } = e.input, v = R.existsSync(C(e.root)), { file: y, business:
|
|
467
|
+
let { currency: h, country: g, currencies: _ } = e.input, v = R.existsSync(C(e.root)), { file: y, business: O } = await w(e, {
|
|
516
468
|
currency: b(h) ?? void 0,
|
|
517
469
|
country: S(g) ?? void 0,
|
|
518
470
|
currencies: x(_, b(h) ?? void 0) ?? void 0
|
|
519
471
|
});
|
|
520
472
|
y && (v ? c : s).push(y), t.info("Adding the currency select to the navbar");
|
|
521
|
-
let
|
|
522
|
-
d(
|
|
523
|
-
let
|
|
524
|
-
if (R.existsSync(
|
|
473
|
+
let N = z.join(e.root, "src", "routes", "(public)", "root-layout.svelte");
|
|
474
|
+
d(E(N, M(N)));
|
|
475
|
+
let P = z.join(e.root, "src", "routes", "+layout.server.ts");
|
|
476
|
+
if (R.existsSync(P)) {
|
|
525
477
|
t.info("Resolving the visitor's currency on the server");
|
|
526
|
-
let n =
|
|
527
|
-
if (d(
|
|
478
|
+
let n = k(P);
|
|
479
|
+
if (d(E(P, n)), n.status === "success") {
|
|
528
480
|
let t = z.join(e.root, "src", "hooks.server.ts");
|
|
529
|
-
d(
|
|
481
|
+
d(E(t, j(t)));
|
|
530
482
|
let n = z.join(e.root, "src", "routes", "+layout.svelte");
|
|
531
|
-
d(
|
|
532
|
-
for (let t of
|
|
483
|
+
d(E(n, A(n)));
|
|
484
|
+
for (let t of Z(Q(e.root))) s.push(t);
|
|
533
485
|
}
|
|
534
486
|
}
|
|
535
|
-
let
|
|
487
|
+
let F = {
|
|
536
488
|
creates: s,
|
|
537
489
|
modifies: c,
|
|
538
490
|
deletes: [],
|
|
@@ -541,10 +493,10 @@ async function ae(e) {
|
|
|
541
493
|
collections: [],
|
|
542
494
|
collectionPatches: [],
|
|
543
495
|
collectionDrops: []
|
|
544
|
-
},
|
|
545
|
-
return n([
|
|
496
|
+
}, I = r.id === "stripe" ? await J(e) : r.id === "shopify" ? await V(e) : await Y(e, O);
|
|
497
|
+
return n([F, I]);
|
|
546
498
|
}
|
|
547
499
|
//#endregion
|
|
548
|
-
export {
|
|
500
|
+
export { $ as generate, Q as hasVitest };
|
|
549
501
|
|
|
550
|
-
//# sourceMappingURL=generate.runtime-
|
|
502
|
+
//# sourceMappingURL=generate.runtime-J2lLMjDn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-J2lLMjDn.js","names":["__import_glob__0_0_","__import_glob__0_1_","InvalidArgumentError","languageFromPath","mergeResults","providerEnvVars","resolveProvider","suppliedProviderEnv","dedent","_taggedTemplateLiteral","getLogger","envEditsFor","currency_server_test_default","META","currency_server_default","buyPageSnippet","STRIPE_PRODUCTS","STRIPE_PRICES","withPocketbase","migrationDelay","getMigrationFile","normalizeCurrency","normalizeCurrencies","normalizeCountry","sitePath","ensureSiteBusiness","modifyEnv","modifyOutcomeToFile","modifyNavUser","modifyLayoutServerCurrency","modifyLayoutSvelteCurrency","modifyHooksServerCurrency","modifyRootLayoutCurrencySelect","modifyWuchaleJsFiles","TRANSLATED_LIB_FILES","modifyUserSignup","ensureCollectionFields","createCollectionIdempotent","fs","path","Stripe","setupShopify","logger","options","variantId","creates","syncUsersToStripeCustomers","stripe","stripeSecretKey","users","pb","existing","linkedUserIds","c","result","user","matching","label","customer","isExistingCustomer","error","paymentMethods","paymentMethod","defaultPaymentMethod","createTestProductAndPrice","products","product","prices","getProductAndPriceById","price","priceId","_templateObject","pushMigrationCreates","created","migrationFile","collectionName","action","paymentPageSnippet","setupStripe","stripePriceId","isAppMode","modifies","pushResult","file","create","spec","customersResult","stripeCustomersCollection","paymentMethodsResult","stripePaymentMethodsCollection","transactionsResult","syncResult","navUserPath","userSignupPath","setupWhatsApp","business","given","wuchaleConfig","edit","createsServerRaw","serverCreates","filesFromGlob","unitTests","a","b","hasVitest","pkg","root","generate","provider","envPath","envVars","modifyEnvVarsFiles","siteExisted","siteFile","currency","country","currencies","layoutPath","layoutServerPath","layoutServer","hooksServerPath","rootLayoutPath","env","setup"],"sources":["../../src/patterns/enable/payments/runtime/setup-shopify.ts","../../src/patterns/enable/payments/runtime/stripe.ts","../../src/patterns/enable/payments/runtime/setup-stripe.ts","../../src/patterns/enable/payments/runtime/setup-whatsapp.ts","../../src/patterns/enable/payments/generate.runtime.ts"],"sourcesContent":["import type { Options, Result } from \"../../../../core/types\";\nimport { getLogger } from \"../../../../core/logger\";\nimport { buyPageSnippet } from \"../shopify-page\";\n\n/**\n * Shopify keeps products, customers and checkout on its side, so past the env\n * there is only the demo page, and only when a variant to sell was given.\n */\nexport async function setupShopify(options: Options) {\n const logger = getLogger(options);\n const variantId =\n typeof options.input.demoId === \"string\" ? options.input.demoId.trim() : \"\";\n\n const creates = [];\n if (variantId) {\n logger.info(\"Creating payment +page.svelte\");\n creates.push({\n path: \"src/routes/(public)/payment/+page.svelte\",\n language: \"svelte\",\n content: buyPageSnippet(variantId),\n status: \"success\" as const,\n });\n }\n\n return {\n creates,\n modifies: [],\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n","import Stripe from \"stripe\";\nimport type PocketBase from \"pocketbase\";\nimport type { Logger } from \"../../../../core/logger\";\n\nexport interface StripeTestFixture {\n product: Stripe.Product;\n price: Stripe.Price;\n existing: boolean;\n}\n\nexport interface SyncUsersResult {\n total: number;\n linked: number;\n created: number;\n reused: number;\n skipped: number;\n}\n\nexport async function syncUsersToStripeCustomers(\n pb: PocketBase,\n stripeSecretKey: string,\n logger: Logger,\n): Promise<SyncUsersResult> {\n const stripe = new Stripe(stripeSecretKey);\n const users = await pb.collection(\"users\").getFullList<{\n id: string;\n email?: string;\n name?: string;\n phone?: string;\n }>();\n\n const existing = await pb\n .collection(\"stripe_customers\")\n .getFullList<{ id: string; user: string }>();\n const linkedUserIds = new Set(existing.map((c) => c.user));\n\n const result: SyncUsersResult = {\n total: users.length,\n linked: linkedUserIds.size,\n created: 0,\n reused: 0,\n skipped: 0,\n };\n\n for (const user of users) {\n if (linkedUserIds.has(user.id)) {\n result.skipped += 1;\n continue;\n }\n\n // A user made with a phone number may have no email to match on.\n const matching = user.email\n ? await stripe.customers.list({\n email: user.email,\n limit: 1,\n expand: [\"data.invoice_settings\"],\n })\n : { data: [] };\n const label = user.email || user.id;\n\n let customer: Stripe.Customer;\n let isExistingCustomer = false;\n\n if (matching.data.length > 0) {\n customer = matching.data[0];\n isExistingCustomer = true;\n result.reused += 1;\n logger.info(`Reusing Stripe customer ${customer.id} for ${label}`);\n } else {\n customer = await stripe.customers.create(\n user.email\n ? { email: user.email }\n : { name: user.name || undefined, phone: user.phone || undefined },\n );\n result.created += 1;\n logger.info(`Created Stripe customer ${customer.id} for ${label}`);\n }\n\n try {\n await pb.collection(\"stripe_customers\").create({\n id: customer.id,\n user: user.id,\n });\n } catch (error) {\n logger.info(\n `Failed to create stripe_customers row for ${label}: ${(error as Error).message}`,\n );\n continue;\n }\n\n if (!isExistingCustomer) {\n continue;\n }\n\n const paymentMethods = await stripe.customers.listPaymentMethods(\n customer.id,\n { type: \"card\", allow_redisplay: \"always\" },\n );\n\n for (const paymentMethod of paymentMethods.data) {\n if (paymentMethod.allow_redisplay === \"unspecified\") continue;\n try {\n await pb.collection(\"stripe_payment_methods\").create({\n id: paymentMethod.id,\n customer: customer.id,\n brand: paymentMethod.card?.brand,\n last4: paymentMethod.card?.last4,\n exp_month: paymentMethod.card?.exp_month,\n exp_year: paymentMethod.card?.exp_year,\n });\n } catch {}\n }\n\n const defaultPaymentMethod =\n customer.invoice_settings?.default_payment_method;\n if (defaultPaymentMethod) {\n try {\n await pb.collection(\"stripe_customers\").update(customer.id, {\n default_payment_method:\n typeof defaultPaymentMethod === \"string\"\n ? defaultPaymentMethod\n : defaultPaymentMethod.id,\n });\n } catch {}\n }\n }\n\n return result;\n}\n\nexport async function createTestProductAndPrice(\n stripeSecretKey: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n\n const products = await stripe.products.search({\n query: `name:\"Test Product\" AND metadata[\"test\"]:\"true\"`,\n limit: 1,\n });\n\n if (products.data.length > 0) {\n const product = products.data[0];\n const prices = await stripe.prices.list({\n product: product.id,\n active: true,\n limit: 1,\n });\n if (prices.data.length > 0) {\n return { product, price: prices.data[0], existing: true };\n }\n }\n\n const product = await stripe.products.create({\n name: \"Test Product\",\n metadata: { test: \"true\" },\n });\n\n const price = await stripe.prices.create({\n product: product.id,\n unit_amount: 1000,\n currency: \"usd\",\n });\n\n return { product, price, existing: false };\n}\n\nexport async function getProductAndPriceById(\n stripeSecretKey: string,\n priceId: string,\n): Promise<StripeTestFixture> {\n const stripe = new Stripe(stripeSecretKey);\n const price = await stripe.prices.retrieve(priceId, { expand: [\"product\"] });\n const product =\n typeof price.product === \"string\"\n ? await stripe.products.retrieve(price.product)\n : (price.product as Stripe.Product);\n price.product = product.id;\n return { product, price, existing: true };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport dedent from \"dedent\";\nimport type { File, Options, Result } from \"../../../../core/types\";\nimport { getLogger } from \"../../../../core/logger\";\nimport { suppliedProviderEnv } from \"../../../../core/providers\";\nimport { languageFromPath } from \"../../../../core/util\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../../runtime/pocketbase\";\nimport {\n createCollectionIdempotent,\n ensureCollectionFields,\n} from \"../../../../runtime/collections\";\nimport { STRIPE_PRICES, STRIPE_PRODUCTS } from \"./collections\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport { modifyNavUser } from \"../modifies/modify-nav-user\";\nimport { modifyUserSignup } from \"../modifies/modify-user-signup\";\nimport {\n createTestProductAndPrice,\n getProductAndPriceById,\n syncUsersToStripeCustomers,\n} from \"./stripe\";\n\nasync function pushMigrationCreates(\n creates: File[],\n collectionName: string,\n action: \"created\" | \"updated\",\n options: Options,\n created = true,\n) {\n if (!created) return;\n await migrationDelay();\n const migrationFile = getMigrationFile(collectionName, action, options);\n if (!migrationFile) return;\n creates.push({\n path: migrationFile,\n language: languageFromPath(migrationFile),\n content: fs.readFileSync(migrationFile, \"utf8\"),\n status: \"success\",\n });\n}\n\nfunction paymentPageSnippet(priceId: string): string {\n return dedent`\n <script lang=\"ts\">\n import PaymentButton from '#lib/components/payments/payment-button.svelte';\n </script>\n\n <section data-role=\"content\">\n <PaymentButton priceId=\"${priceId}\" />\n </section>\n `;\n}\n\n/**\n * Everything Stripe needs past its env: the catalog and customer collections,\n * the existing users as Stripe customers, a product/price for the demo page,\n * and, with auth, the billing nav item and the signup link to Stripe.\n */\nexport async function setupStripe(options: Options) {\n const stripeSecretKey = suppliedProviderEnv(options).STRIPE_SECRET_KEY ?? \"\";\n const stripePriceId =\n typeof options.input.demoId === \"string\" && options.input.demoId !== \"\"\n ? options.input.demoId\n : undefined;\n\n const isAppMode = options.features.auth;\n const logger = getLogger(options);\n const creates: File[] = [];\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n await withPocketbase(options.root, async (pb) => {\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n // The catalog: created, or, when a project enabled payments before a\n // field existed, brought up to the spec (the next sync fills the field).\n for (const spec of [STRIPE_PRODUCTS, STRIPE_PRICES]) {\n logger.info(`Creating ${spec.name} collection`);\n const result = await create(spec);\n await pushMigrationCreates(\n creates,\n spec.name,\n \"created\",\n options,\n result.created,\n );\n if (!result.created) {\n creates.push(\n ...(await ensureCollectionFields(pb, spec, options, logger)),\n );\n }\n }\n\n if (isAppMode) {\n logger.info(\"Creating stripe_customers collection\");\n const customersResult = await create({\n name: \"stripe_customers\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n const stripeCustomersCollection = customersResult.collection;\n await pushMigrationCreates(\n creates,\n \"stripe_customers\",\n \"created\",\n options,\n customersResult.created,\n );\n\n logger.info(\"Creating stripe_payment_methods collection\");\n const paymentMethodsResult = await create({\n name: \"stripe_payment_methods\",\n type: \"base\",\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"brand\", required: true, type: \"text\" },\n { name: \"last4\", required: true, type: \"text\" },\n { name: \"exp_month\", required: true, type: \"number\" },\n { name: \"exp_year\", required: true, type: \"number\" },\n {\n collectionId: stripeCustomersCollection.id,\n maxSelect: 1,\n minSelect: 0,\n name: \"customer\",\n required: true,\n type: \"relation\",\n cascadeDelete: true,\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n const stripePaymentMethodsCollection = paymentMethodsResult.collection;\n await pushMigrationCreates(\n creates,\n \"stripe_payment_methods\",\n \"created\",\n options,\n paymentMethodsResult.created,\n );\n\n logger.info(\"Linking default_payment_method on stripe_customers\");\n await pb.collections.update(\"stripe_customers\", {\n fields: [\n {\n name: \"id\",\n pattern: \"^[a-zA-Z0-9_]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n {\n collectionId: stripePaymentMethodsCollection.id,\n maxSelect: 1,\n minSelect: 0,\n name: \"default_payment_method\",\n required: false,\n type: \"relation\",\n },\n {\n name: \"created\",\n onCreate: true,\n onUpdate: false,\n type: \"autodate\",\n },\n {\n name: \"updated\",\n onCreate: true,\n onUpdate: true,\n type: \"autodate\",\n },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_customers\",\n \"updated\",\n options,\n );\n\n logger.info(\"Creating transactions collection\");\n const transactionsResult = await create({\n name: \"transactions\",\n type: \"base\",\n fields: [\n {\n autogeneratePattern: \"[a-z0-9]{15}\",\n max: 15,\n min: 15,\n name: \"id\",\n pattern: \"^[a-z0-9]+$\",\n primaryKey: true,\n required: true,\n system: true,\n type: \"text\",\n },\n { name: \"stripe_payment_intent\", required: true, type: \"text\" },\n { name: \"amount\", required: true, type: \"number\" },\n { name: \"currency\", required: true, type: \"text\" },\n { name: \"last4\", required: true, type: \"text\" },\n { name: \"brand\", required: true, type: \"text\" },\n { name: \"created\", required: true, type: \"date\" },\n { name: \"stripe_charge\", required: true, type: \"text\" },\n { name: \"stripe_customer\", required: true, type: \"text\" },\n {\n collectionId: \"_pb_users_auth_\",\n maxSelect: 1,\n minSelect: 0,\n name: \"user\",\n required: true,\n type: \"relation\",\n },\n { name: \"receipt_url\", required: true, type: \"url\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"transactions\",\n \"created\",\n options,\n transactionsResult.created,\n );\n\n logger.info(\"Syncing existing PocketBase users to Stripe customers\");\n const syncResult = await syncUsersToStripeCustomers(\n pb,\n stripeSecretKey,\n logger,\n );\n logger.info(\n `Synced ${syncResult.total} users (created ${syncResult.created}, reused ${syncResult.reused}, skipped ${syncResult.skipped})`,\n );\n }\n });\n\n if (stripePriceId) {\n logger.info(`Fetching Stripe product/price ${stripePriceId}`);\n } else {\n logger.info(\"Creating test Stripe product and price\");\n }\n const { product, price, existing } = stripePriceId\n ? await getProductAndPriceById(stripeSecretKey, stripePriceId)\n : await createTestProductAndPrice(stripeSecretKey);\n\n if (existing) {\n logger.info(\"Stripe product/price already exists, skipping creation\");\n }\n\n logger.info(\"Seeding Stripe product/price records\");\n await withPocketbase(options.root, async (pb) => {\n try {\n await pb.collection(\"stripe_products\").getOne(product.id);\n } catch (error) {\n await pb.collection(\"stripe_products\").create({\n id: product.id,\n name: product.name,\n active: product.active,\n default_price: product.default_price,\n });\n }\n\n try {\n await pb.collection(\"stripe_prices\").getOne(price.id);\n } catch (error) {\n await pb.collection(\"stripe_prices\").create({\n id: price.id,\n billing_scheme: price.billing_scheme,\n currency: price.currency,\n product: price.product,\n recurring: price.recurring,\n type: price.type,\n unit_amount: price.unit_amount,\n active: price.active,\n });\n }\n });\n\n logger.info(\"Creating payment +page.svelte\");\n creates.push({\n path: \"src/routes/(public)/payment/+page.svelte\",\n language: \"svelte\",\n content: paymentPageSnippet(price.id),\n status: \"success\",\n });\n\n if (isAppMode) {\n logger.info(\"Modifying nav-user.svelte\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n pushResult(modifyOutcomeToFile(navUserPath, modifyNavUser(navUserPath)));\n\n logger.info(\"Modifying signup +page.server.ts\");\n const userSignupPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"(auth)\",\n \"signup\",\n \"+page.server.ts\",\n );\n pushResult(\n modifyOutcomeToFile(userSignupPath, modifyUserSignup(userSignupPath)),\n );\n }\n\n return {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../../core/types\";\nimport { InvalidArgumentError } from \"../../../../core/errors\";\nimport { getLogger } from \"../../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../../runtime/modify-file\";\nimport type { SiteBusiness } from \"../../../../runtime/site\";\nimport {\n modifyWuchaleJsFiles,\n TRANSLATED_LIB_FILES,\n} from \"../../../../runtime/wuchale-config\";\n\n/**\n * WhatsApp keeps nothing past the env: orders go to the business's chat, and\n * the hosted form they are recorded to is created by the CLI. Every price is\n * in `site.currency`, so a project without one can't take orders: `business`\n * is what `src/lib/site.ts` declares after the shared step wrote it.\n */\nexport async function setupWhatsApp(options: Options, business: SiteBusiness) {\n if (!business.currency) {\n const given = options.input.currency;\n throw new InvalidArgumentError(\n given === undefined || given === \"\"\n ? \"Payments on WhatsApp need the business's currency, the one it prices in (an ISO 4217 code such as MXN or EUR). Pass --currency, or set `currency` in src/lib/site.ts.\"\n : `${String(given)} is not an ISO 4217 currency code, such as MXN or EUR.`,\n );\n }\n const modifies: File[] = [];\n\n // The order message is text a visitor sends, so with wuchale on it is\n // translated like the pages: the js adapter has to be told about the module.\n const wuchaleConfig = path.join(options.root, \"wuchale.config.js\");\n if (fs.existsSync(wuchaleConfig)) {\n getLogger(options).info(\"Adding src/lib/order.ts to wuchale's js adapter\");\n const edit = modifyOutcomeToFile(\n wuchaleConfig,\n modifyWuchaleJsFiles(wuchaleConfig, TRANSLATED_LIB_FILES),\n );\n if (edit) modifies.push(edit);\n }\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n } satisfies Result;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { filesFromGlob, mergeResults } from \"../../../core/util\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport {\n ensureSiteBusiness,\n normalizeCountry,\n normalizeCurrencies,\n normalizeCurrency,\n sitePath,\n} from \"../../../runtime/site\";\nimport { envEditsFor, META } from \"./generate\";\nimport { modifyHooksServerCurrency } from \"./modifies/hooks.server\";\nimport { modifyLayoutServerCurrency } from \"./modifies/layout.server\";\nimport { modifyLayoutSvelteCurrency } from \"./modifies/layout.svelte\";\nimport { modifyRootLayoutCurrencySelect } from \"./modifies/root-layout.svelte\";\nimport { setupShopify } from \"./runtime/setup-shopify\";\nimport { setupStripe } from \"./runtime/setup-stripe\";\nimport { setupWhatsApp } from \"./runtime/setup-whatsapp\";\n\nconst createsServerRaw = import.meta.glob<string>(\"./creates-server/**\", {\n query: \"?raw\",\n import: \"default\",\n eager: true,\n});\n\n/** The server half of the currency store, for a project with a server load. */\nexport function serverCreates(unitTests: boolean): File[] {\n return Object.values(filesFromGlob(createsServerRaw, \"./creates-server/\"))\n .filter((file) => unitTests || !file.path.endsWith(\".test.ts\"))\n .sort((a, b) => a.path.localeCompare(b.path));\n}\n\n/** Whether the project can run a unit test (`vitest` in package.json). */\nexport function hasVitest(root: string): boolean {\n try {\n const pkg = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n ) as {\n dependencies?: Record<string, string>;\n devDependencies?: Record<string, string>;\n };\n return Boolean(pkg.devDependencies?.vitest || pkg.dependencies?.vitest);\n } catch {\n return false;\n }\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(`Writing ${provider.label} credentials to .env`);\n const envPath = path.join(options.root, \".env\");\n pushResult(\n modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n ),\n );\n\n // SvelteKit 3 exposes only declared variables, and only `public: true`\n // ones through `$app/env/public`.\n logger.info(`Declaring ${provider.label} variables in src/env.ts`);\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n pushResult(envVars.modify);\n\n // What the business declares in src/lib/site.ts: the currency it prices\n // in, the country it is in, and the other currencies it shows prices in.\n // Asked for by the CLI; a value already there is kept.\n const { currency, country, currencies } = options.input;\n const siteExisted = fs.existsSync(sitePath(options.root));\n const { file: siteFile, business } = await ensureSiteBusiness(options, {\n currency: normalizeCurrency(currency) ?? undefined,\n country: normalizeCountry(country) ?? undefined,\n currencies:\n normalizeCurrencies(\n currencies,\n normalizeCurrency(currency) ?? undefined,\n ) ?? undefined,\n });\n if (siteFile) (siteExisted ? modifies : creates).push(siteFile);\n\n logger.info(\"Adding the currency select to the navbar\");\n const layoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(layoutPath, modifyRootLayoutCurrencySelect(layoutPath)),\n );\n\n // With a server, the visitor's currency is decided per request and the\n // first render already shows it. A static site (a universal root load) keeps\n // the store's browser-side start.\n const layoutServerPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.server.ts\",\n );\n if (fs.existsSync(layoutServerPath)) {\n logger.info(\"Resolving the visitor's currency on the server\");\n const layoutServer = modifyLayoutServerCurrency(layoutServerPath);\n pushResult(modifyOutcomeToFile(layoutServerPath, layoutServer));\n if (layoutServer.status === \"success\") {\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(\n hooksServerPath,\n modifyHooksServerCurrency(hooksServerPath),\n ),\n );\n const rootLayoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"+layout.svelte\",\n );\n pushResult(\n modifyOutcomeToFile(\n rootLayoutPath,\n modifyLayoutSvelteCurrency(rootLayoutPath),\n ),\n );\n for (const file of serverCreates(hasVitest(options.root)))\n creates.push(file);\n }\n }\n\n const env: Result = {\n creates,\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops: [],\n };\n\n const setup =\n provider.id === \"stripe\"\n ? await setupStripe(options)\n : provider.id === \"shopify\"\n ? await setupShopify(options)\n : await setupWhatsApp(options, business);\n\n return mergeResults([env, setup]) satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAQA,eAAsByC,EAAa,GAAkB;CACnD,IAAMC,IAAShC,EAAUiC,CAAO,GAC1BC,IACJ,OAAOD,EAAQ,MAAM,UAAW,WAAWA,EAAQ,MAAM,OAAO,KAAK,IAAI,IAErEE,IAAU,CAAC;CAWjB,OAVID,MACFF,EAAO,KAAK,+BAA+B,GAC3CG,EAAQ,KAAK;EACX,MAAM;EACN,UAAU;EACV,SAAS9B,EAAe6B,CAAS;EACjC,QAAQ;CACV,CAAC,IAGI;EACL;EACA,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF;;;AChBA,eAAsBE,EACpB,GACA,GACA,GAC0B;CAC1B,IAAMC,IAAS,IAAIP,EAAOQ,CAAe,GACnCC,IAAQ,MAAMC,EAAG,WAAW,OAAO,CAAC,CAAC,YAKxC,GAEGC,IAAW,MAAMD,EACpB,WAAW,kBAAkB,CAAC,CAC9B,YAA0C,GACvCE,IAAgB,IAAI,IAAID,EAAS,KAAK,MAAME,EAAE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AAYnC,CAAO,IACzBkE,EAAS,OAAO,YACd,MAAMpE,EAAaE,CAAO,IAC1B,MAAMmD,EAAcnD,GAASoD,CAAQ;CAE7C,OAAO3F,EAAa,CAACuH,GAAKC,CAAK,CAAC;AAClC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { a as e } from "./util-BLYliuUK.js";
|
|
2
|
+
import { n as t } from "./logger-CQONztPm.js";
|
|
3
|
+
import { m as n, p as r, t as i } from "./generate-BrOPb9tW.js";
|
|
4
|
+
import { t as a } from "./shared-BbxLil4g.js";
|
|
5
|
+
import { f as o } from "./ts-morph-helpers-CHI9wAil.js";
|
|
6
|
+
import { r as s } from "./modify-file-B4uJzOEj.js";
|
|
7
|
+
import { t as c } from "./svelte-file-Dv5-bl79.js";
|
|
8
|
+
import { SUCCESS_PAGE as l, t as u } from "./generate.runtime-DuDcKDUl.js";
|
|
9
|
+
import d from "node:fs";
|
|
10
|
+
import f from "node:path";
|
|
11
|
+
//#region src/patterns/disable/orders/generate.runtime.ts
|
|
12
|
+
async function p(p) {
|
|
13
|
+
let m = t(p), h = [], g = (e) => {
|
|
14
|
+
e && h.push(e);
|
|
15
|
+
};
|
|
16
|
+
m.info("Reverting webhooks/stripe/handlers/dispatch.ts");
|
|
17
|
+
let _ = f.join(p.root, "src", "routes", "webhooks", "stripe", "handlers", "dispatch.ts");
|
|
18
|
+
g(s(_, u(_))), m.info("Reverting /checkout/success");
|
|
19
|
+
for (let [t, i] of [["+page.server.ts", n], ["+page.svelte", r]]) {
|
|
20
|
+
let n = f.join(p.root, l, t);
|
|
21
|
+
d.existsSync(n) && d.readFileSync(n, "utf8") !== i && h.push({
|
|
22
|
+
path: n,
|
|
23
|
+
language: e(n),
|
|
24
|
+
content: i,
|
|
25
|
+
status: "success"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
m.info("Removing Orders from the user menu");
|
|
29
|
+
let v = f.join(p.root, "src", "lib", "components", "nav-user.svelte");
|
|
30
|
+
if (d.existsSync(v)) {
|
|
31
|
+
let t = d.readFileSync(v, "utf8");
|
|
32
|
+
if (t.includes("'/orders'")) {
|
|
33
|
+
let n = new c(t), r = !1, i = (e) => {
|
|
34
|
+
r || e((e) => {
|
|
35
|
+
let t = o(e, "Orders", "@lucide/svelte/icons/package");
|
|
36
|
+
return t.wasRemoved && (r = !0), t.source;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
if (i((e) => n.modifyModuleScript(e)), r || i((e) => n.modifyScript(e)), r) {
|
|
40
|
+
let t = n.toString();
|
|
41
|
+
d.writeFileSync(v, t, "utf8"), h.push({
|
|
42
|
+
path: v,
|
|
43
|
+
language: e(v),
|
|
44
|
+
content: t,
|
|
45
|
+
status: "success"
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
creates: [],
|
|
52
|
+
modifies: h,
|
|
53
|
+
deletes: [],
|
|
54
|
+
components: [],
|
|
55
|
+
packages: [],
|
|
56
|
+
collections: [],
|
|
57
|
+
collectionPatches: [],
|
|
58
|
+
collectionDrops: await a([...i].reverse(), p)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { p as generate };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=generate.runtime-nyJ6v56q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.runtime-nyJ6v56q.js","names":["successServer","successSvelte","languageFromPath","getLogger","_page_server_default","_page_default","ORDER_COLLECTIONS","planDropsForCollections","removeNavItemFromScript","modifyOutcomeToFile","SvelteFile","unmodifyWebhookServer","fs","path","generate","logger","options","modifies","pushResult","file","dispatchPath","name","content","SUCCESS_PAGE","navUserPath","source","removed","tryRemove","run","result","src","fn","updated"],"sources":["../../src/patterns/disable/orders/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { languageFromPath } from \"../../../core/util\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { SvelteFile } from \"../../../runtime/svelte-file\";\nimport { removeNavItemFromScript } from \"../../../runtime/ts-morph-helpers\";\nimport { planDropsForCollections } from \"../../destroy/shared\";\nimport { ORDER_COLLECTIONS } from \"../../enable/orders/generate\";\nimport { SUCCESS_PAGE } from \"../../enable/orders/generate.runtime\";\nimport { unmodifyWebhookServer } from \"../../enable/orders/modifies/modify-webhook-server\";\n// The success page as enable-ecommerce wrote it, before orders rewrote it.\nimport successServer from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.server.ts?raw\";\nimport successSvelte from \"../../enable/ecommerce/providers/stripe/src/routes/(public)/checkout/success/+page.svelte?raw\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Reverting webhooks/stripe/handlers/dispatch.ts\");\n const dispatchPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"webhooks\",\n \"stripe\",\n \"handlers\",\n \"dispatch.ts\",\n );\n pushResult(\n modifyOutcomeToFile(dispatchPath, unmodifyWebhookServer(dispatchPath)),\n );\n\n // Back to Stripe's summary alone, as enable-ecommerce wrote the page; a\n // project without the cart has no page to restore.\n logger.info(\"Reverting /checkout/success\");\n for (const [name, content] of [\n [\"+page.server.ts\", successServer],\n [\"+page.svelte\", successSvelte],\n ] as const) {\n const file = path.join(options.root, SUCCESS_PAGE, name);\n if (!fs.existsSync(file) || fs.readFileSync(file, \"utf8\") === content) {\n continue;\n }\n modifies.push({\n path: file,\n language: languageFromPath(file),\n content,\n status: \"success\",\n });\n }\n\n logger.info(\"Removing Orders from the user menu\");\n const navUserPath = path.join(\n options.root,\n \"src\",\n \"lib\",\n \"components\",\n \"nav-user.svelte\",\n );\n if (fs.existsSync(navUserPath)) {\n const source = fs.readFileSync(navUserPath, \"utf8\");\n if (source.includes(\"'/orders'\")) {\n const file = new SvelteFile(source);\n let removed = false;\n const tryRemove = (run: (fn: (s: string) => string) => boolean) => {\n if (removed) return;\n run((src) => {\n const result = removeNavItemFromScript(\n src,\n \"Orders\",\n \"@lucide/svelte/icons/package\",\n );\n if (result.wasRemoved) removed = true;\n return result.source;\n });\n };\n tryRemove((fn) => file.modifyModuleScript(fn));\n if (!removed) tryRemove((fn) => file.modifyScript(fn));\n if (removed) {\n const updated = file.toString();\n fs.writeFileSync(navUserPath, updated, \"utf8\");\n modifies.push({\n path: navUserPath,\n language: languageFromPath(navUserPath),\n content: updated,\n status: \"success\",\n });\n }\n }\n }\n\n // Lines before orders: PocketBase refuses to drop a collection another\n // relation still points at. One never created is planned as missing.\n const collectionDrops = await planDropsForCollections(\n [...ORDER_COLLECTIONS].reverse(),\n options,\n );\n\n return {\n creates: [],\n modifies,\n deletes: [],\n components: [],\n packages: [],\n collections: [],\n collectionPatches: [],\n collectionDrops,\n } satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,eAAsBc,EAAS,GAAkB;CAC/C,IAAMC,IAASZ,EAAUa,CAAO,GAC1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAIC,KAAMF,EAAS,KAAKE,CAAI;CAC9B;CAEA,EAAO,KAAK,gDAAgD;CAC5D,IAAMC,IAAeP,EAAK,KACxBG,EAAQ,MACR,OACA,UACA,YACA,UACA,YACA,aACF;CAOA,AANAE,EACET,EAAoBW,GAAcT,EAAsBS,CAAY,CAAC,CACvE,GAIAL,EAAO,KAAK,6BAA6B;CACzC,KAAK,IAAM,CAACM,GAAMC,MAAY,CAC5B,CAAC,mBAAmBtB,CAAa,GACjC,CAAC,gBAAgBC,CAAa,CAChC,GAAY;EACV,IAAMkB,IAAON,EAAK,KAAKG,EAAQ,MAAMO,GAAcF,CAAI;EACvD,AAAKT,EAAG,WAAWO,CAAI,KAAKP,EAAG,aAAaO,GAAM,MAAM,MAAMG,KAG9DL,EAAS,KAAK;GACZ,MAAME;GACN,UAAUjB,EAAiBiB,CAAI;GAC/B;GACA,QAAQ;EACV,CAAC;CACH;CAEA,EAAO,KAAK,oCAAoC;CAChD,IAAMK,IAAcX,EAAK,KACvBG,EAAQ,MACR,OACA,OACA,cACA,iBACF;CACA,IAAIJ,EAAG,WAAWY,CAAW,GAAG;EAC9B,IAAMC,IAASb,EAAG,aAAaY,GAAa,MAAM;EAClD,IAAIC,EAAO,SAAS,WAAW,GAAG;GAChC,IAAMN,IAAO,IAAIT,EAAWe,CAAM,GAC9BC,IAAU,IACRC,KAAa,MAAgD;IACjE,AAAID,KACJE,GAAK,MAAQ;KACX,IAAMC,IAASrB,EACbsB,GACA,UACA,8BACF;KAEA,OADID,EAAO,eAAY,IAAU,KAC1BA,EAAO;IAChB,CAAC;GACH;GAGA,IAFAF,GAAW,MAAOR,EAAK,mBAAmBY,CAAE,CAAC,GACxCL,KAASC,GAAW,MAAOR,EAAK,aAAaY,CAAE,CAAC,GACjDL,GAAS;IACX,IAAMM,IAAUb,EAAK,SAAS;IAE9B,AADAP,EAAG,cAAcY,GAAaQ,GAAS,MAAM,GAC7Cf,EAAS,KAAK;KACZ,MAAMO;KACN,UAAUtB,EAAiBsB,CAAW;KACtC,SAASQ;KACT,QAAQ;IACV,CAAC;GACH;EACF;CACF;CASA,OAAO;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAA,MAb4BzB,EAC5B,CAAC,GAAGD,CAAiB,CAAC,CAAC,QAAQ,GAC/BU,CACF;CAWA;AACF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { t as e } from "./ts-morph-helpers-CHI9wAil.js";
|
|
2
|
+
import { t } from "./svelte-file-Dv5-bl79.js";
|
|
3
|
+
import n from "node:fs";
|
|
4
|
+
//#region src/patterns/enable/payments/modifies/modify-nav-user.ts
|
|
5
|
+
var r = [
|
|
6
|
+
"import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
|
|
7
|
+
"",
|
|
8
|
+
"// Add to your navUser array:",
|
|
9
|
+
"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
|
|
10
|
+
].join("\n"), i = [
|
|
11
|
+
"Add a Billing nav item to nav-user.svelte:",
|
|
12
|
+
"",
|
|
13
|
+
r
|
|
14
|
+
].join("\n"), a = [
|
|
15
|
+
"Create nav-user.svelte with a Billing entry:",
|
|
16
|
+
"",
|
|
17
|
+
r
|
|
18
|
+
].join("\n");
|
|
19
|
+
function o(n, r, i, a, o) {
|
|
20
|
+
let s = new t(n), c = !1, l = (t) => {
|
|
21
|
+
c || t((t) => {
|
|
22
|
+
let n = e(t, r, i, a, o);
|
|
23
|
+
return n.wasAdded && (c = !0), n.source;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return l((e) => s.modifyModuleScript(e)), c || l((e) => s.modifyScript(e)), {
|
|
27
|
+
newNavUserSnippet: s.toString(),
|
|
28
|
+
wasAdded: c
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function s(e) {
|
|
32
|
+
if (!n.existsSync(e)) return {
|
|
33
|
+
status: "not-found",
|
|
34
|
+
message: a
|
|
35
|
+
};
|
|
36
|
+
let t = n.readFileSync(e, "utf8");
|
|
37
|
+
if (t.includes("/billing")) return {
|
|
38
|
+
status: "success",
|
|
39
|
+
changed: !1
|
|
40
|
+
};
|
|
41
|
+
let { newNavUserSnippet: r, wasAdded: s } = o(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
|
|
42
|
+
return s ? (n.writeFileSync(e, r, "utf8"), {
|
|
43
|
+
status: "success",
|
|
44
|
+
changed: !0
|
|
45
|
+
}) : {
|
|
46
|
+
status: "failed",
|
|
47
|
+
message: i
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { s as n, o as t };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=modify-nav-user-iUpv2lm-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modify-nav-user-iUpv2lm-.js","names":["addNavItemToScript","fs","BILLING_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","SvelteFile","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet"],"sources":["../../src/patterns/enable/payments/modifies/modify-nav-user.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport { addNavItemToScript } from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nconst BILLING_NAV_SNIPPET = [\n \"import CreditCardIcon from '@lucide/svelte/icons/credit-card';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'Billing', url: '/billing', icon: CreditCardIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add a Billing nav item to nav-user.svelte:\",\n \"\",\n BILLING_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with a Billing entry:\",\n \"\",\n BILLING_NAV_SNIPPET,\n].join(\"\\n\");\n\nexport function addItemToNavUser(\n navUserSnippet: string,\n title: string,\n url: string,\n icon: string,\n iconImportPath: string,\n): { newNavUserSnippet: string; wasAdded: boolean } {\n const file = new SvelteFile(navUserSnippet);\n let wasAdded = false;\n\n const tryAdd = (run: (fn: (s: string) => string) => boolean) => {\n if (wasAdded) return;\n run((source) => {\n const result = addNavItemToScript(\n source,\n title,\n url,\n icon,\n iconImportPath,\n );\n if (result.wasAdded) wasAdded = true;\n return result.source;\n });\n };\n\n tryAdd((fn) => file.modifyModuleScript(fn));\n if (!wasAdded) tryAdd((fn) => file.modifyScript(fn));\n\n return { newNavUserSnippet: file.toString(), wasAdded };\n}\n\nexport function modifyNavUser(navUserPath: string): ModifyOutcome {\n if (!fs.existsSync(navUserPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const navUserSnippet = fs.readFileSync(navUserPath, \"utf8\");\n if (navUserSnippet.includes(\"/billing\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"Billing\",\n \"/billing\",\n \"CreditCardIcon\",\n \"@lucide/svelte/icons/credit-card\",\n );\n\n if (!wasAdded) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n fs.writeFileSync(navUserPath, newNavUserSnippet, \"utf8\");\n return { status: \"success\", changed: true };\n}\n"],"mappings":";;;;AAKA,IAAME,IAAsB;CAC1B;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI,GAELC,IAAe;CACnB;CACA;CACAD;AACF,CAAC,CAAC,KAAK,IAAI,GAELE,IAAiB;CACrB;CACA;CACAF;AACF,CAAC,CAAC,KAAK,IAAI;AAEX,SAAgBG,EACd,GACA,GACA,GACA,GACA,GACkD;CAClD,IAAMC,IAAO,IAAIC,EAAWC,CAAc,GACtCC,IAAW,IAETC,KAAU,MAAgD;EAC9D,AAAID,KACJE,GAAK,MAAW;GACd,IAAMC,IAASZ,EACba,GACAC,GACAC,GACAC,GACAC,CACF;GAEA,OADIL,EAAO,aAAU,IAAW,KACzBA,EAAO;EAChB,CAAC;CACH;CAKA,OAHAF,GAAQ,MAAOJ,EAAK,mBAAmBY,CAAE,CAAC,GACrCT,KAAUC,GAAQ,MAAOJ,EAAK,aAAaY,CAAE,CAAC,GAE5C;EAAE,mBAAmBZ,EAAK,SAAS;EAAG;CAAS;AACxD;AAEA,SAAgBa,EAAc,GAAoC;CAChE,IAAI,CAAClB,EAAG,WAAWmB,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAa,SAAShB;CAAe;CAGxD,IAAMI,IAAiBP,EAAG,aAAamB,GAAa,MAAM;CAC1D,IAAIZ,EAAe,SAAS,UAAU,GACpC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,sBAAmB,gBAAaH,EACtCG,GACA,WACA,YACA,kBACA,kCACF;CAOA,OALKC,KAILR,EAAG,cAAcmB,GAAaC,GAAmB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAU,SAASlB;CAAa;AAKrD"}
|