@velastack/patterns 0.4.1 → 0.4.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 (137) hide show
  1. package/dist/chunks/{_layout-kkgN0IF7.js → _layout-D-FzWqn0.js} +2 -2
  2. package/dist/chunks/{_layout-kkgN0IF7.js.map → _layout-D-FzWqn0.js.map} +1 -1
  3. package/dist/chunks/_page-C7kGoW7_.js +6 -0
  4. package/dist/chunks/_page-C7kGoW7_.js.map +1 -0
  5. package/dist/chunks/_page-e_I-fdSR.js +6 -0
  6. package/dist/chunks/_page-e_I-fdSR.js.map +1 -0
  7. package/dist/chunks/auth-pages-B52ei-4z.js +291 -0
  8. package/dist/chunks/auth-pages-B52ei-4z.js.map +1 -0
  9. package/dist/chunks/{collections-Dz2fvKnz.js → collections-zzZ_HQxB.js} +2 -2
  10. package/dist/chunks/{collections-Dz2fvKnz.js.map → collections-zzZ_HQxB.js.map} +1 -1
  11. package/dist/chunks/{compose-handle-D_Rz3Fzo.js → compose-handle-BDlZ7Pif.js} +2 -2
  12. package/dist/chunks/{compose-handle-D_Rz3Fzo.js.map → compose-handle-BDlZ7Pif.js.map} +1 -1
  13. package/dist/chunks/{config-target-Dx3w6WSk.js → config-target-rHgjaA8u.js} +2 -2
  14. package/dist/chunks/{config-target-Dx3w6WSk.js.map → config-target-rHgjaA8u.js.map} +1 -1
  15. package/dist/chunks/{constants-BjyMU5s8.js → constants-Rq8SCXwH.js} +2 -2
  16. package/dist/chunks/{constants-BjyMU5s8.js.map → constants-Rq8SCXwH.js.map} +1 -1
  17. package/dist/chunks/dispatch-D4TN9pdW.js +6 -0
  18. package/dist/chunks/dispatch-D4TN9pdW.js.map +1 -0
  19. package/dist/chunks/{env-vars-C1NUX-bf.js → env-vars-CcE6ODqC.js} +4 -4
  20. package/dist/chunks/{env-vars-C1NUX-bf.js.map → env-vars-CcE6ODqC.js.map} +1 -1
  21. package/dist/chunks/{format-result-DZ8De8KY.js → format-result-BVoLVknk.js} +2 -2
  22. package/dist/chunks/format-result-BVoLVknk.js.map +1 -0
  23. package/dist/chunks/{generate-DeaBlnK6.js → generate-B6Odfk5f.js} +2 -2
  24. package/dist/chunks/{generate-DeaBlnK6.js.map → generate-B6Odfk5f.js.map} +1 -1
  25. package/dist/chunks/{generate-WMJo3QGZ.js → generate-Bg0E3eWm.js} +2 -2
  26. package/dist/chunks/{generate-WMJo3QGZ.js.map → generate-Bg0E3eWm.js.map} +1 -1
  27. package/dist/chunks/{generate-Gcc8iRkZ.js → generate-CFqpRi9D.js} +3 -3
  28. package/dist/chunks/{generate-Gcc8iRkZ.js.map → generate-CFqpRi9D.js.map} +1 -1
  29. package/dist/chunks/{generate-BW3l5Fxw.js → generate-CZGHByV3.js} +2 -2
  30. package/dist/chunks/{generate-BW3l5Fxw.js.map → generate-CZGHByV3.js.map} +1 -1
  31. package/dist/chunks/{generate.runtime-IlBCcXvv.js → generate.runtime-5rIc-RNL.js} +7 -7
  32. package/dist/chunks/{generate.runtime-IlBCcXvv.js.map → generate.runtime-5rIc-RNL.js.map} +1 -1
  33. package/dist/chunks/{generate.runtime-BgTz41Zg.js → generate.runtime-BK3mR0Rj.js} +92 -140
  34. package/dist/chunks/generate.runtime-BK3mR0Rj.js.map +1 -0
  35. package/dist/chunks/generate.runtime-Bcrht4M9.js +42 -0
  36. package/dist/chunks/generate.runtime-Bcrht4M9.js.map +1 -0
  37. package/dist/chunks/{generate.runtime-cwvAoKoH.js → generate.runtime-BpMN5Uq-.js} +3 -3
  38. package/dist/chunks/{generate.runtime-cwvAoKoH.js.map → generate.runtime-BpMN5Uq-.js.map} +1 -1
  39. package/dist/chunks/{generate.runtime-DD51OSuL.js → generate.runtime-CAn1qIQ_.js} +4 -4
  40. package/dist/chunks/{generate.runtime-DD51OSuL.js.map → generate.runtime-CAn1qIQ_.js.map} +1 -1
  41. package/dist/chunks/{generate.runtime-CuNhY5hn.js → generate.runtime-CEqLgLT9.js} +16 -11
  42. package/dist/chunks/generate.runtime-CEqLgLT9.js.map +1 -0
  43. package/dist/chunks/{generate.runtime-B1jVAnDI.js → generate.runtime-CK10Mum5.js} +8 -8
  44. package/dist/chunks/{generate.runtime-B1jVAnDI.js.map → generate.runtime-CK10Mum5.js.map} +1 -1
  45. package/dist/chunks/{generate.runtime-DqD3PW-W.js → generate.runtime-CZ46nkSL.js} +3 -3
  46. package/dist/chunks/{generate.runtime-DqD3PW-W.js.map → generate.runtime-CZ46nkSL.js.map} +1 -1
  47. package/dist/chunks/{generate.runtime-CslAvllQ.js → generate.runtime-CbE9RHcf.js} +5 -5
  48. package/dist/chunks/generate.runtime-CbE9RHcf.js.map +1 -0
  49. package/dist/chunks/{generate.runtime-CCr1lvo4.js → generate.runtime-CpMKXBkn.js} +7 -7
  50. package/dist/chunks/{generate.runtime-CCr1lvo4.js.map → generate.runtime-CpMKXBkn.js.map} +1 -1
  51. package/dist/chunks/{generate.runtime-6FXJM8hT.js → generate.runtime-CqncBFNg.js} +5 -5
  52. package/dist/chunks/{generate.runtime-6FXJM8hT.js.map → generate.runtime-CqncBFNg.js.map} +1 -1
  53. package/dist/chunks/{generate.runtime-C6bSvGMb.js → generate.runtime-DHHlYfTD.js} +6 -6
  54. package/dist/chunks/{generate.runtime-C6bSvGMb.js.map → generate.runtime-DHHlYfTD.js.map} +1 -1
  55. package/dist/chunks/generate.runtime-DJ9MVVPC.js +325 -0
  56. package/dist/chunks/generate.runtime-DJ9MVVPC.js.map +1 -0
  57. package/dist/chunks/generate.runtime-DJHUBL4Z.js +68 -0
  58. package/dist/chunks/generate.runtime-DJHUBL4Z.js.map +1 -0
  59. package/dist/chunks/{generate.runtime-CnPraLKv.js → generate.runtime-DVB7uuht.js} +4 -4
  60. package/dist/chunks/{generate.runtime-CnPraLKv.js.map → generate.runtime-DVB7uuht.js.map} +1 -1
  61. package/dist/chunks/{generate.runtime-kvxmTlQb.js → generate.runtime-Db0HZyj3.js} +3 -3
  62. package/dist/chunks/{generate.runtime-kvxmTlQb.js.map → generate.runtime-Db0HZyj3.js.map} +1 -1
  63. package/dist/chunks/{generate.runtime-D_sQOeQa.js → generate.runtime-Djas9UNy.js} +6 -6
  64. package/dist/chunks/{generate.runtime-D_sQOeQa.js.map → generate.runtime-Djas9UNy.js.map} +1 -1
  65. package/dist/chunks/{generate.runtime-Ce_rwzNa.js → generate.runtime-Dl6OQ7pe.js} +4 -4
  66. package/dist/chunks/{generate.runtime-Ce_rwzNa.js.map → generate.runtime-Dl6OQ7pe.js.map} +1 -1
  67. package/dist/chunks/{generate.runtime-1-91UmM8.js → generate.runtime-DoZJHtZh.js} +4 -4
  68. package/dist/chunks/{generate.runtime-1-91UmM8.js.map → generate.runtime-DoZJHtZh.js.map} +1 -1
  69. package/dist/chunks/{generate.runtime-C8zJRNYG.js → generate.runtime-E-zoeSKW.js} +5 -5
  70. package/dist/chunks/{generate.runtime-C8zJRNYG.js.map → generate.runtime-E-zoeSKW.js.map} +1 -1
  71. package/dist/chunks/{generate.runtime-pVLzzpUM.js → generate.runtime-EQnytCFL.js} +40 -40
  72. package/dist/chunks/generate.runtime-EQnytCFL.js.map +1 -0
  73. package/dist/chunks/generate.runtime-IWEhGhWY.js +218 -0
  74. package/dist/chunks/generate.runtime-IWEhGhWY.js.map +1 -0
  75. package/dist/chunks/{generate.runtime-CYagyR5c.js → generate.runtime-a3R4hqFy.js} +6 -6
  76. package/dist/chunks/{generate.runtime-CYagyR5c.js.map → generate.runtime-a3R4hqFy.js.map} +1 -1
  77. package/dist/chunks/{generate.runtime-zJpEufTc.js → generate.runtime-aQnBmH8D.js} +9 -9
  78. package/dist/chunks/generate.runtime-aQnBmH8D.js.map +1 -0
  79. package/dist/chunks/{generate.runtime-Dtgw9IQO.js → generate.runtime-axm9wcQv.js} +5 -5
  80. package/dist/chunks/{generate.runtime-Dtgw9IQO.js.map → generate.runtime-axm9wcQv.js.map} +1 -1
  81. package/dist/chunks/{generate.runtime-DHBRyMAq.js → generate.runtime-hTKzxH2M.js} +5 -5
  82. package/dist/chunks/{generate.runtime-DHBRyMAq.js.map → generate.runtime-hTKzxH2M.js.map} +1 -1
  83. package/dist/chunks/{generate.runtime-BA3tDKnn.js → generate.runtime-kciwaXxh.js} +5 -5
  84. package/dist/chunks/{generate.runtime-BA3tDKnn.js.map → generate.runtime-kciwaXxh.js.map} +1 -1
  85. package/dist/chunks/{generate.runtime-B_UVGa3q.js → generate.runtime-koQxLywh.js} +5 -5
  86. package/dist/chunks/{generate.runtime-B_UVGa3q.js.map → generate.runtime-koQxLywh.js.map} +1 -1
  87. package/dist/chunks/{generate.runtime-DM4o_QYY.js → generate.runtime-rs1ZOIET.js} +5 -5
  88. package/dist/chunks/{generate.runtime-DM4o_QYY.js.map → generate.runtime-rs1ZOIET.js.map} +1 -1
  89. package/dist/chunks/{generate.runtime-DV3WmZtb.js → generate.runtime-uLUiPgqx.js} +6 -6
  90. package/dist/chunks/{generate.runtime-DV3WmZtb.js.map → generate.runtime-uLUiPgqx.js.map} +1 -1
  91. package/dist/chunks/{modify-file-BlDeeurK.js → modify-file-DK-tCH9k.js} +3 -3
  92. package/dist/chunks/{modify-file-BlDeeurK.js.map → modify-file-DK-tCH9k.js.map} +1 -1
  93. package/dist/chunks/modify-nav-user-BLyrW2sK.js +71 -0
  94. package/dist/chunks/modify-nav-user-BLyrW2sK.js.map +1 -0
  95. package/dist/chunks/{modify-svelte-config-remote-p0TfVzxm.js → modify-svelte-config-remote-DhuRX4FI.js} +2 -2
  96. package/dist/chunks/{modify-svelte-config-remote-p0TfVzxm.js.map → modify-svelte-config-remote-DhuRX4FI.js.map} +1 -1
  97. package/dist/chunks/modify-user-signup-BbqTiUuA.js +54 -0
  98. package/dist/chunks/modify-user-signup-BbqTiUuA.js.map +1 -0
  99. package/dist/chunks/{pocketbase-Dry6ry17.js → pocketbase-CgwbH1gI.js} +2 -2
  100. package/dist/chunks/{pocketbase-Dry6ry17.js.map → pocketbase-CgwbH1gI.js.map} +1 -1
  101. package/dist/chunks/{shared-CZC4d7Uj.js → shared-Cc_ns5-y.js} +2 -2
  102. package/dist/chunks/{shared-CZC4d7Uj.js.map → shared-Cc_ns5-y.js.map} +1 -1
  103. package/dist/chunks/{site-BwCA18Sv.js → site-lj0CDdQ1.js} +2 -2
  104. package/dist/chunks/{site-BwCA18Sv.js.map → site-lj0CDdQ1.js.map} +1 -1
  105. package/dist/chunks/{table-core-AjBpYi-y.js → table-core-DhDqT03G.js} +2 -2
  106. package/dist/chunks/{table-core-AjBpYi-y.js.map → table-core-DhDqT03G.js.map} +1 -1
  107. package/dist/chunks/{test-setup-DEmWd9Ul.js → test-setup-B9fQ5L_-.js} +5 -5
  108. package/dist/chunks/{test-setup-DEmWd9Ul.js.map → test-setup-B9fQ5L_-.js.map} +1 -1
  109. package/dist/chunks/{ts-morph-helpers-CDW4lhox.js → ts-morph-helpers-Bepc-Es2.js} +27 -23
  110. package/dist/chunks/ts-morph-helpers-Bepc-Es2.js.map +1 -0
  111. package/dist/chunks/{ui-X698F10c.js → ui-CuCsupFq.js} +3 -3
  112. package/dist/chunks/{ui-X698F10c.js.map → ui-CuCsupFq.js.map} +1 -1
  113. package/dist/chunks/{unmodify-load-CyGzC1Hu.js → unmodify-load-Bl5vXQiL.js} +2 -2
  114. package/dist/chunks/{unmodify-load-CyGzC1Hu.js.map → unmodify-load-Bl5vXQiL.js.map} +1 -1
  115. package/dist/chunks/whatsapp-CguKGTtw.js +105 -0
  116. package/dist/chunks/whatsapp-CguKGTtw.js.map +1 -0
  117. package/dist/chunks/{write-result-B68lvI57.js → write-result-DiZsCS_y.js} +5 -5
  118. package/dist/chunks/{write-result-B68lvI57.js.map → write-result-DiZsCS_y.js.map} +1 -1
  119. package/dist/index.d.ts +134 -1
  120. package/dist/index.js +2240 -2005
  121. package/dist/index.js.map +1 -1
  122. package/package.json +2 -2
  123. package/dist/chunks/dispatch-CXOXPLFk.js +0 -6
  124. package/dist/chunks/dispatch-CXOXPLFk.js.map +0 -1
  125. package/dist/chunks/format-result-DZ8De8KY.js.map +0 -1
  126. package/dist/chunks/generate.runtime-BO778G0r.js +0 -188
  127. package/dist/chunks/generate.runtime-BO778G0r.js.map +0 -1
  128. package/dist/chunks/generate.runtime-BgTz41Zg.js.map +0 -1
  129. package/dist/chunks/generate.runtime-CexC1Oky.js +0 -269
  130. package/dist/chunks/generate.runtime-CexC1Oky.js.map +0 -1
  131. package/dist/chunks/generate.runtime-CslAvllQ.js.map +0 -1
  132. package/dist/chunks/generate.runtime-CuNhY5hn.js.map +0 -1
  133. package/dist/chunks/generate.runtime-pVLzzpUM.js.map +0 -1
  134. package/dist/chunks/generate.runtime-zJpEufTc.js.map +0 -1
  135. package/dist/chunks/nav-user-BRIHOOpG.js +0 -6
  136. package/dist/chunks/nav-user-BRIHOOpG.js.map +0 -1
  137. package/dist/chunks/ts-morph-helpers-CDW4lhox.js.map +0 -1
@@ -3,114 +3,67 @@ import { t } from "./dedent-Gq6Krl4n.js";
3
3
  import { t as n } from "./taggedTemplateLiteral-CswN2AAa.js";
4
4
  import { n as r } from "./logger-CQONztPm.js";
5
5
  import { t as i } from "./env-BPfk1VAw.js";
6
- import { o as a, t as o } from "./ts-morph-helpers-CDW4lhox.js";
7
- import { modifyOutcomeToFile as s } from "./modify-file-BlDeeurK.js";
8
- import { modifyEnvVarsFiles as c } from "./env-vars-C1NUX-bf.js";
9
- import { t as l } from "./svelte-file-B3RfgVdt.js";
10
- import { i as u, n as d, t as f } from "./pocketbase-Dry6ry17.js";
11
- import { t as p } from "./env-vars-De0Xs0L2.js";
12
- import { createCollectionIdempotent as m } from "./collections-Dz2fvKnz.js";
6
+ import { t as a } from "./ts-morph-helpers-Bepc-Es2.js";
7
+ import { modifyOutcomeToFile as o } from "./modify-file-DK-tCH9k.js";
8
+ import { modifyEnvVarsFiles as s } from "./env-vars-CcE6ODqC.js";
9
+ import { t as c } from "./svelte-file-B3RfgVdt.js";
10
+ import { i as l, n as u, t as d } from "./pocketbase-CgwbH1gI.js";
11
+ import { t as f } from "./env-vars-De0Xs0L2.js";
12
+ import { t as p } from "./modify-user-signup-BbqTiUuA.js";
13
+ import { createCollectionIdempotent as m } from "./collections-zzZ_HQxB.js";
13
14
  import h from "node:fs";
14
15
  import g from "node:path";
15
- import { Project as _, QuoteKind as v, SyntaxKind as y } from "ts-morph";
16
- import b from "stripe";
16
+ import _ from "stripe";
17
17
  //#region src/patterns/enable/payments/modifies/modify-nav-user.ts
18
- var x = [
18
+ var v = [
19
19
  "import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
20
20
  "",
21
21
  "// Add to your navUser array:",
22
22
  "{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
23
- ].join("\n"), S = [
23
+ ].join("\n"), y = [
24
24
  "Add a Billing nav item to nav-user.svelte:",
25
25
  "",
26
- x
27
- ].join("\n"), C = [
26
+ v
27
+ ].join("\n"), b = [
28
28
  "Create nav-user.svelte with a Billing entry:",
29
29
  "",
30
- x
30
+ v
31
31
  ].join("\n");
32
- function w(e, t, n, r, i) {
33
- let a = new l(e), s = !1, c = (e) => {
32
+ function x(e, t, n, r, i) {
33
+ let o = new c(e), s = !1, l = (e) => {
34
34
  s || e((e) => {
35
- let a = o(e, t, n, r, i);
36
- return a.wasAdded && (s = !0), a.source;
35
+ let o = a(e, t, n, r, i);
36
+ return o.wasAdded && (s = !0), o.source;
37
37
  });
38
38
  };
39
- return c((e) => a.modifyModuleScript(e)), s || c((e) => a.modifyScript(e)), {
40
- newNavUserSnippet: a.toString(),
39
+ return l((e) => o.modifyModuleScript(e)), s || l((e) => o.modifyScript(e)), {
40
+ newNavUserSnippet: o.toString(),
41
41
  wasAdded: s
42
42
  };
43
43
  }
44
- function T(e) {
44
+ function S(e) {
45
45
  if (!h.existsSync(e)) return {
46
46
  status: "not-found",
47
- message: C
47
+ message: b
48
48
  };
49
49
  let t = h.readFileSync(e, "utf8");
50
50
  if (t.includes("/billing")) return {
51
51
  status: "success",
52
52
  changed: !1
53
53
  };
54
- let { newNavUserSnippet: n, wasAdded: r } = w(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
54
+ let { newNavUserSnippet: n, wasAdded: r } = x(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
55
55
  return r ? (h.writeFileSync(e, n, "utf8"), {
56
56
  status: "success",
57
57
  changed: !0
58
58
  }) : {
59
59
  status: "failed",
60
- message: S
61
- };
62
- }
63
- //#endregion
64
- //#region src/patterns/enable/payments/modifies/modify-user-signup.ts
65
- var E = "#lib/workflows/link-stripe-customer.js", D = t`
66
- // Queued here, done in the background: the Stripe calls retry on their own,
67
- // and the key means a retry never makes a second customer for this user.
68
- await linkStripeCustomer.run(
69
- { userId: user.id, email: form.data.email },
70
- { idempotencyKey: user.id }
71
- );
72
- `, O = [
73
- "Could not locate the requestVerification call in signup +page.server.ts.",
74
- "Start the workflow once the user exists:",
75
- "",
76
- `import { linkStripeCustomer } from '${E}';`,
77
- "",
78
- D
79
- ].join("\n"), k = ["Create src/routes/(public)/(auth)/signup/+page.server.ts before enabling payments."].join("\n");
80
- function A(e) {
81
- if (!h.existsSync(e)) return {
82
- status: "not-found",
83
- message: k
84
- };
85
- let t = h.readFileSync(e, "utf8");
86
- if (t.includes("linkStripeCustomer")) return {
87
- status: "success",
88
- changed: !1
89
- };
90
- let n = new _({ manipulationSettings: { quoteKind: v.Single } }).addSourceFileAtPath(e), r = n.getDescendantsOfKind(y.CallExpression).find((e) => {
91
- let t = e.getExpression();
92
- return t.getKind() === y.PropertyAccessExpression && t.getText().includes("requestVerification");
93
- });
94
- if (!r) return {
95
- status: "failed",
96
- message: O
97
- };
98
- let i = r.getFirstAncestorByKind(y.ExpressionStatement);
99
- return i ? (n.addImportDeclaration({
100
- namedImports: ["linkStripeCustomer"],
101
- moduleSpecifier: E
102
- }), i.replaceWithText(D + "\n\n" + i.getText()), a(n), n.saveSync(), {
103
- status: "success",
104
- changed: n.getFullText() !== t
105
- }) : {
106
- status: "failed",
107
- message: O
60
+ message: y
108
61
  };
109
62
  }
110
63
  //#endregion
111
64
  //#region src/patterns/enable/payments/runtime/stripe.ts
112
- async function j(e, t, n) {
113
- 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 = {
65
+ async function C(e, t, n) {
66
+ let r = new _(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
114
67
  total: i.length,
115
68
  linked: o.size,
116
69
  created: 0,
@@ -122,49 +75,48 @@ async function j(e, t, n) {
122
75
  s.skipped += 1;
123
76
  continue;
124
77
  }
125
- if (!t.email) {
126
- n.info(`Skipping user ${t.id} with no email`), s.skipped += 1;
127
- continue;
128
- }
129
- let i = await r.customers.list({
78
+ let i = t.email ? await r.customers.list({
130
79
  email: t.email,
131
80
  limit: 1,
132
81
  expand: ["data.invoice_settings"]
133
- }), a, c = !1;
134
- i.data.length > 0 ? (a = i.data[0], c = !0, s.reused += 1, n.info(`Reusing Stripe customer ${a.id} for ${t.email}`)) : (a = await r.customers.create({ email: t.email }), s.created += 1, n.info(`Created Stripe customer ${a.id} for ${t.email}`));
82
+ }) : { data: [] }, a = t.email || t.id, c, l = !1;
83
+ i.data.length > 0 ? (c = i.data[0], l = !0, s.reused += 1, n.info(`Reusing Stripe customer ${c.id} for ${a}`)) : (c = await r.customers.create(t.email ? { email: t.email } : {
84
+ name: t.name || void 0,
85
+ phone: t.phone || void 0
86
+ }), s.created += 1, n.info(`Created Stripe customer ${c.id} for ${a}`));
135
87
  try {
136
88
  await e.collection("stripe_customers").create({
137
- id: a.id,
89
+ id: c.id,
138
90
  user: t.id
139
91
  });
140
92
  } catch (e) {
141
- n.info(`Failed to create stripe_customers row for ${t.email}: ${e.message}`);
93
+ n.info(`Failed to create stripe_customers row for ${a}: ${e.message}`);
142
94
  continue;
143
95
  }
144
- if (!c) continue;
145
- let l = await r.customers.listPaymentMethods(a.id, {
96
+ if (!l) continue;
97
+ let u = await r.customers.listPaymentMethods(c.id, {
146
98
  type: "card",
147
99
  allow_redisplay: "always"
148
100
  });
149
- for (let t of l.data) if (t.allow_redisplay !== "unspecified") try {
101
+ for (let t of u.data) if (t.allow_redisplay !== "unspecified") try {
150
102
  await e.collection("stripe_payment_methods").create({
151
103
  id: t.id,
152
- customer: a.id,
104
+ customer: c.id,
153
105
  brand: t.card?.brand,
154
106
  last4: t.card?.last4,
155
107
  exp_month: t.card?.exp_month,
156
108
  exp_year: t.card?.exp_year
157
109
  });
158
110
  } catch {}
159
- let u = a.invoice_settings?.default_payment_method;
160
- if (u) try {
161
- await e.collection("stripe_customers").update(a.id, { default_payment_method: typeof u == "string" ? u : u.id });
111
+ let d = c.invoice_settings?.default_payment_method;
112
+ if (d) try {
113
+ await e.collection("stripe_customers").update(c.id, { default_payment_method: typeof d == "string" ? d : d.id });
162
114
  } catch {}
163
115
  }
164
116
  return s;
165
117
  }
166
- async function M(e) {
167
- let t = new b(e), n = await t.products.search({
118
+ async function w(e) {
119
+ let t = new _(e), n = await t.products.search({
168
120
  query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
169
121
  limit: 1
170
122
  });
@@ -194,8 +146,8 @@ async function M(e) {
194
146
  existing: !1
195
147
  };
196
148
  }
197
- async function N(e, t) {
198
- 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;
149
+ async function T(e, t) {
150
+ let n = new _(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
199
151
  return r.product = i.id, {
200
152
  product: i,
201
153
  price: r,
@@ -204,11 +156,11 @@ async function N(e, t) {
204
156
  }
205
157
  //#endregion
206
158
  //#region src/patterns/enable/payments/generate.runtime.ts
207
- var P;
208
- async function F(t, n, r, i, a = !0) {
159
+ var E;
160
+ async function D(t, n, r, i, a = !0) {
209
161
  if (!a) return;
210
- await d();
211
- let o = f(n, r, i);
162
+ await u();
163
+ let o = d(n, r, i);
212
164
  o && t.push({
213
165
  path: o,
214
166
  language: e(o),
@@ -216,15 +168,15 @@ async function F(t, n, r, i, a = !0) {
216
168
  status: "success"
217
169
  });
218
170
  }
219
- function I(e) {
220
- return t(P ||= n(["\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);
171
+ function O(e) {
172
+ return t(E ||= n(["\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);
221
173
  }
222
- async function L(e) {
223
- let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: a, stripePriceId: o } = e.input, l = e.features.auth, d = r(e), f = [], h = [], _ = (e) => {
224
- e && h.push(e);
174
+ async function k(e) {
175
+ let { stripeSecretKey: t, stripePublishableKey: n, stripeWebhookSecret: a, stripePriceId: c } = e.input, u = e.features.auth, d = r(e), h = [], _ = [], v = (e) => {
176
+ e && _.push(e);
225
177
  };
226
178
  d.info("Writing Stripe credentials to .env");
227
- let v = [
179
+ let y = [
228
180
  {
229
181
  type: "comment",
230
182
  key: "Stripe credentials"
@@ -244,10 +196,10 @@ async function L(e) {
244
196
  key: "STRIPE_WEBHOOK_SECRET",
245
197
  value: a
246
198
  }
247
- ], y = g.join(e.root, ".env");
248
- _(s(y, i(y, v))), d.info("Declaring Stripe variables in src/env.ts");
249
- let b = c(e.root, p);
250
- b.create && f.push(b.create), _(b.modify), await u(e.root, async (n) => {
199
+ ], b = g.join(e.root, ".env");
200
+ v(o(b, i(b, y))), d.info("Declaring Stripe variables in src/env.ts");
201
+ let x = s(e.root, f);
202
+ x.create && h.push(x.create), v(x.modify), await l(e.root, async (n) => {
251
203
  let r = (e) => m(n, e, d);
252
204
  d.info("Creating stripe_products collection");
253
205
  let i = await r({
@@ -291,7 +243,7 @@ async function L(e) {
291
243
  }
292
244
  ]
293
245
  });
294
- await F(f, "stripe_products", "created", e, i.created), d.info("Creating stripe_prices collection");
246
+ await D(h, "stripe_products", "created", e, i.created), d.info("Creating stripe_prices collection");
295
247
  let a = await r({
296
248
  name: "stripe_prices",
297
249
  type: "base",
@@ -353,7 +305,7 @@ async function L(e) {
353
305
  }
354
306
  ]
355
307
  });
356
- if (await F(f, "stripe_prices", "created", e, a.created), l) {
308
+ if (await D(h, "stripe_prices", "created", e, a.created), u) {
357
309
  d.info("Creating stripe_customers collection");
358
310
  let i = await r({
359
311
  name: "stripe_customers",
@@ -389,7 +341,7 @@ async function L(e) {
389
341
  }
390
342
  ]
391
343
  }), a = i.collection;
392
- await F(f, "stripe_customers", "created", e, i.created), d.info("Creating stripe_payment_methods collection");
344
+ await D(h, "stripe_customers", "created", e, i.created), d.info("Creating stripe_payment_methods collection");
393
345
  let o = await r({
394
346
  name: "stripe_payment_methods",
395
347
  type: "base",
@@ -445,7 +397,7 @@ async function L(e) {
445
397
  }
446
398
  ]
447
399
  }), s = o.collection;
448
- await F(f, "stripe_payment_methods", "created", e, o.created), d.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
400
+ await D(h, "stripe_payment_methods", "created", e, o.created), d.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
449
401
  {
450
402
  name: "id",
451
403
  pattern: "^[a-zA-Z0-9_]+$",
@@ -482,7 +434,7 @@ async function L(e) {
482
434
  onUpdate: !0,
483
435
  type: "autodate"
484
436
  }
485
- ] }), await F(f, "stripe_customers", "updated", e), d.info("Creating transactions collection");
437
+ ] }), await D(h, "stripe_customers", "updated", e), d.info("Creating transactions collection");
486
438
  let c = await r({
487
439
  name: "transactions",
488
440
  type: "base",
@@ -553,52 +505,52 @@ async function L(e) {
553
505
  }
554
506
  ]
555
507
  });
556
- await F(f, "transactions", "created", e, c.created), d.info("Syncing existing PocketBase users to Stripe customers");
557
- let l = await j(n, t, d);
508
+ await D(h, "transactions", "created", e, c.created), d.info("Syncing existing PocketBase users to Stripe customers");
509
+ let l = await C(n, t, d);
558
510
  d.info(`Synced ${l.total} users (created ${l.created}, reused ${l.reused}, skipped ${l.skipped})`);
559
511
  }
560
- }), o ? d.info(`Fetching Stripe product/price ${o}`) : d.info("Creating test Stripe product and price");
561
- let { product: x, price: S, existing: C } = o ? await N(t, o) : await M(t);
562
- if (C && d.info("Stripe product/price already exists, skipping creation"), d.info("Seeding Stripe product/price records"), await u(e.root, async (e) => {
512
+ }), c ? d.info(`Fetching Stripe product/price ${c}`) : d.info("Creating test Stripe product and price");
513
+ let { product: E, price: k, existing: A } = c ? await T(t, c) : await w(t);
514
+ if (A && d.info("Stripe product/price already exists, skipping creation"), d.info("Seeding Stripe product/price records"), await l(e.root, async (e) => {
563
515
  try {
564
- await e.collection("stripe_products").getOne(x.id);
516
+ await e.collection("stripe_products").getOne(E.id);
565
517
  } catch {
566
518
  await e.collection("stripe_products").create({
567
- id: x.id,
568
- name: x.name,
569
- active: x.active,
570
- default_price: x.default_price
519
+ id: E.id,
520
+ name: E.name,
521
+ active: E.active,
522
+ default_price: E.default_price
571
523
  });
572
524
  }
573
525
  try {
574
- await e.collection("stripe_prices").getOne(S.id);
526
+ await e.collection("stripe_prices").getOne(k.id);
575
527
  } catch {
576
528
  await e.collection("stripe_prices").create({
577
- id: S.id,
578
- billing_scheme: S.billing_scheme,
579
- currency: S.currency,
580
- product: S.product,
581
- recurring: S.recurring,
582
- type: S.type,
583
- unit_amount: S.unit_amount,
584
- active: S.active
529
+ id: k.id,
530
+ billing_scheme: k.billing_scheme,
531
+ currency: k.currency,
532
+ product: k.product,
533
+ recurring: k.recurring,
534
+ type: k.type,
535
+ unit_amount: k.unit_amount,
536
+ active: k.active
585
537
  });
586
538
  }
587
- }), d.info("Creating payment +page.svelte"), f.push({
539
+ }), d.info("Creating payment +page.svelte"), h.push({
588
540
  path: "src/routes/(public)/payment/+page.svelte",
589
541
  language: "svelte",
590
- content: I(S.id),
542
+ content: O(k.id),
591
543
  status: "success"
592
- }), l) {
544
+ }), u) {
593
545
  d.info("Modifying nav-user.svelte");
594
546
  let t = g.join(e.root, "src", "lib", "components", "nav-user.svelte");
595
- _(s(t, T(t))), d.info("Modifying signup +page.server.ts");
547
+ v(o(t, S(t))), d.info("Modifying signup +page.server.ts");
596
548
  let n = g.join(e.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
597
- _(s(n, A(n)));
549
+ v(o(n, p(n)));
598
550
  }
599
551
  return {
600
- creates: f,
601
- modifies: h,
552
+ creates: h,
553
+ modifies: _,
602
554
  deletes: [],
603
555
  components: [],
604
556
  packages: [],
@@ -608,6 +560,6 @@ async function L(e) {
608
560
  };
609
561
  }
610
562
  //#endregion
611
- export { L as generate };
563
+ export { k as generate };
612
564
 
613
- //# sourceMappingURL=generate.runtime-BgTz41Zg.js.map
565
+ //# sourceMappingURL=generate.runtime-BK3mR0Rj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-BK3mR0Rj.js","names":["languageFromPath","_taggedTemplateLiteral","getLogger","modifyEnv","addNavItemToScript","SvelteFile","withPocketbase","migrationDelay","getMigrationFile","STRIPE_ENV_VARS","modifyUserSignup","fs","path","Stripe","BILLING_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet","syncUsersToStripeCustomers","stripe","stripeSecretKey","users","pb","existing","linkedUserIds","c","user","matching","label","customer","isExistingCustomer","logger","error","paymentMethods","paymentMethod","defaultPaymentMethod","createTestProductAndPrice","products","product","prices","getProductAndPriceById","price","priceId","_templateObject","pushMigrationCreates","created","migrationFile","collectionName","action","options","creates","paymentPageSnippet","dedent","generate","isAppMode","modifies","pushResult","envEdits","stripePublishableKey","stripeWebhookSecret","envPath","modifyOutcomeToFile","envVars","modifyEnvVarsFiles","create","createCollectionIdempotent","spec","productsResult","pricesResult","customersResult","stripeCustomersCollection","paymentMethodsResult","stripePaymentMethodsCollection","transactionsResult","syncResult","stripePriceId","userSignupPath"],"sources":["../../src/patterns/enable/payments/modifies/modify-nav-user.ts","../../src/patterns/enable/payments/runtime/stripe.ts","../../src/patterns/enable/payments/generate.runtime.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","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 { languageFromPath } from \"../../../core/util\";\nimport {\n getMigrationFile,\n migrationDelay,\n withPocketbase,\n} from \"../../../runtime/pocketbase\";\nimport { createCollectionIdempotent } from \"../../../runtime/collections\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { STRIPE_ENV_VARS } from \"./runtime/env-vars\";\nimport { modifyNavUser } from \"./modifies/modify-nav-user\";\nimport { modifyUserSignup } from \"./modifies/modify-user-signup\";\nimport { modifyEnv, type EnvEdit } from \"./modifies/modify-env\";\nimport {\n createTestProductAndPrice,\n getProductAndPriceById,\n syncUsersToStripeCustomers,\n} from \"./runtime/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\nexport async function generate(options: Options) {\n const {\n stripeSecretKey,\n stripePublishableKey,\n stripeWebhookSecret,\n stripePriceId,\n } = options.input as {\n stripeSecretKey: string;\n stripePublishableKey: string;\n stripeWebhookSecret: string;\n stripePriceId?: string;\n };\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 logger.info(\"Writing Stripe credentials to .env\");\n const envEdits: EnvEdit[] = [\n { type: \"comment\", key: \"Stripe credentials\" },\n { type: \"var\", key: \"STRIPE_SECRET_KEY\", value: stripeSecretKey },\n {\n type: \"var\",\n key: \"PUBLIC_STRIPE_PUBLISHABLE_KEY\",\n value: stripePublishableKey,\n },\n { type: \"var\", key: \"STRIPE_WEBHOOK_SECRET\", value: stripeWebhookSecret },\n ];\n\n const envPath = path.join(options.root, \".env\");\n pushResult(modifyOutcomeToFile(envPath, modifyEnv(envPath, envEdits)));\n\n logger.info(\"Declaring Stripe variables in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, STRIPE_ENV_VARS);\n if (envVars.create) creates.push(envVars.create);\n pushResult(envVars.modify);\n\n await withPocketbase(options.root, async (pb) => {\n const create = (spec: Parameters<typeof createCollectionIdempotent>[1]) =>\n createCollectionIdempotent(pb, spec, logger);\n\n logger.info(\"Creating stripe_products collection\");\n const productsResult = await create({\n name: \"stripe_products\",\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: \"name\", required: false, type: \"text\" },\n { name: \"active\", required: false, type: \"text\" },\n { name: \"default_price\", required: false, type: \"text\" },\n { name: \"created\", onCreate: true, onUpdate: false, type: \"autodate\" },\n { name: \"updated\", onCreate: true, onUpdate: true, type: \"autodate\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_products\",\n \"created\",\n options,\n productsResult.created,\n );\n\n logger.info(\"Creating stripe_prices collection\");\n const pricesResult = await create({\n name: \"stripe_prices\",\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: \"billing_scheme\", required: false, type: \"text\" },\n { name: \"currency\", required: false, type: \"text\" },\n { name: \"product\", required: false, type: \"text\" },\n { name: \"recurring\", required: false, type: \"json\" },\n { name: \"type\", required: false, type: \"text\" },\n { name: \"unit_amount\", required: false, type: \"number\" },\n { name: \"active\", required: false, type: \"bool\" },\n { name: \"created\", onCreate: true, onUpdate: false, type: \"autodate\" },\n { name: \"updated\", onCreate: true, onUpdate: true, type: \"autodate\" },\n ],\n });\n await pushMigrationCreates(\n creates,\n \"stripe_prices\",\n \"created\",\n options,\n pricesResult.created,\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"],"mappings":";;;;;;;;;;;;;;;;;AAKA,IAAMc,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,IAAIb,EAAWc,CAAc,GACtCC,IAAW,IAETC,KAAU,MAAgD;EAC9D,AAAID,KACJE,GAAK,MAAW;GACd,IAAMC,IAASnB,EACboB,GACAC,GACAC,GACAC,GACAC,CACF;GAEA,OADIL,EAAO,aAAU,IAAW,KACzBA,EAAO;EAChB,CAAC;CACH;CAKA,OAHAF,GAAQ,MAAOH,EAAK,mBAAmBW,CAAE,CAAC,GACrCT,KAAUC,GAAQ,MAAOH,EAAK,aAAaW,CAAE,CAAC,GAE5C;EAAE,mBAAmBX,EAAK,SAAS;EAAG;CAAS;AACxD;AAEA,SAAgBY,EAAc,GAAoC;CAChE,IAAI,CAACnB,EAAG,WAAWoB,CAAW,GAC5B,OAAO;EAAE,QAAQ;EAAa,SAASf;CAAe;CAGxD,IAAMG,IAAiBR,EAAG,aAAaoB,GAAa,MAAM;CAC1D,IAAIZ,EAAe,SAAS,UAAU,GACpC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,sBAAmB,gBAAaF,EACtCE,GACA,WACA,YACA,kBACA,kCACF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,CAAC,OAAO;IAC5C,IAAIgB,EAAQ;IACZ,MAAMA,EAAQ;IACd,QAAQA,EAAQ;IAChB,eAAeA,EAAQ;GACzB,CAAC;EACH;EAEA,IAAI;GACF,MAAMhB,EAAG,WAAW,eAAe,CAAC,CAAC,OAAOmB,EAAM,EAAE;EACtD,QAAgB;GACd,MAAMnB,EAAG,WAAW,eAAe,CAAC,CAAC,OAAO;IAC1C,IAAImB,EAAM;IACV,gBAAgBA,EAAM;IACtB,UAAUA,EAAM;IAChB,SAASA,EAAM;IACf,WAAWA,EAAM;IACjB,MAAMA,EAAM;IACZ,aAAaA,EAAM;IACnB,QAAQA,EAAM;GAChB,CAAC;EACH;CACF,CAAC,GAEDV,EAAO,KAAK,+BAA+B,GAC3CmB,EAAQ,KAAK;EACX,MAAM;EACN,UAAU;EACV,SAASC,EAAmBV,EAAM,EAAE;EACpC,QAAQ;CACV,CAAC,GAEGa,GAAW;EACb,EAAO,KAAK,2BAA2B;EACvC,IAAMtC,IAAcnB,EAAK,KACvBoD,EAAQ,MACR,OACA,OACA,cACA,iBACF;EAGA,AAFAO,EAAWK,EAAoB7C,GAAaD,EAAcC,CAAW,CAAC,CAAC,GAEvEe,EAAO,KAAK,kCAAkC;EAC9C,IAAM6C,IAAiB/E,EAAK,KAC1BoD,EAAQ,MACR,OACA,UACA,YACA,UACA,UACA,iBACF;EACA,EACEY,EAAoBe,GAAgBjF,EAAiBiF,CAAc,CAAC,CACtE;CACF;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -0,0 +1,42 @@
1
+ import { n as e } from "./logger-CQONztPm.js";
2
+ import { modifyOutcomeToFile as t } from "./modify-file-DK-tCH9k.js";
3
+ import { i as n, n as r } from "./pocketbase-CgwbH1gI.js";
4
+ import { i, n as a, o } from "./whatsapp-CguKGTtw.js";
5
+ import { swapAuthPages as s } from "./auth-pages-B52ei-4z.js";
6
+ import c from "node:fs";
7
+ import l from "node:path";
8
+ //#region src/patterns/disable/whatsapp/generate.runtime.ts
9
+ var u = "https://velastack.dev/docs/disable/whatsapp";
10
+ async function d(d) {
11
+ let f = e(d), p = [];
12
+ await n(d.root, async (e) => {
13
+ if (!await i(e)) return;
14
+ f.info("Turning off WhatsApp sign-in for users"), await a(e), await r();
15
+ let t = o(d, !1);
16
+ t && p.push({
17
+ path: t,
18
+ language: "js",
19
+ content: c.readFileSync(t, "utf8"),
20
+ status: "success"
21
+ });
22
+ }), f.info("Keeping the phone fields on users, and email optional: they hold your users' data"), f.info("Taking WhatsApp off the login and signup pages");
23
+ let m = [], h = await s(d.root, "disable", (e) => `${l.relative(d.root, e)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of it by hand: ${u}`);
24
+ for (let [e, n] of h) {
25
+ let r = t(e, n);
26
+ r && m.push(r);
27
+ }
28
+ return {
29
+ creates: p,
30
+ modifies: m,
31
+ deletes: [],
32
+ components: [],
33
+ packages: [],
34
+ collections: [],
35
+ collectionPatches: [],
36
+ collectionDrops: []
37
+ };
38
+ }
39
+ //#endregion
40
+ export { d as generate };
41
+
42
+ //# sourceMappingURL=generate.runtime-Bcrht4M9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-Bcrht4M9.js","names":["getLogger","withPocketbase","migrationDelay","disableWhatsAppAuth","fs","path","DOCS_URL","generate","logger","options","creates","hasWhatsAppPlugin","pb","file","writeWhatsAppConfigMigration","modifies","outcomes","swapAuthPages","filePath","outcome","modifyOutcomeToFile"],"sources":["../../src/patterns/disable/whatsapp/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 { migrationDelay, withPocketbase } from \"../../../runtime/pocketbase\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport {\n disableWhatsAppAuth,\n hasWhatsAppPlugin,\n writeWhatsAppConfigMigration,\n} from \"../../enable/whatsapp/runtime/whatsapp\";\nimport { swapAuthPages } from \"../../enable/whatsapp/modifies/auth-pages\";\n\nconst DOCS_URL = \"https://velastack.dev/docs/disable/whatsapp\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const creates: File[] = [];\n\n await withPocketbase(options.root, async (pb) => {\n // Without the plugin there is no WhatsApp sign-in to turn off.\n if (!(await hasWhatsAppPlugin(pb))) return;\n\n logger.info(\"Turning off WhatsApp sign-in for users\");\n await disableWhatsAppAuth(pb);\n await migrationDelay();\n const file = writeWhatsAppConfigMigration(options, false);\n if (!file) return;\n creates.push({\n path: file,\n language: \"js\",\n content: fs.readFileSync(file, \"utf8\"),\n status: \"success\",\n });\n });\n logger.info(\n \"Keeping the phone fields on users, and email optional: they hold your users' data\",\n );\n\n logger.info(\"Taking WhatsApp off the login and signup pages\");\n const modifies: File[] = [];\n const outcomes = await swapAuthPages(\n options.root,\n \"disable\",\n (filePath) =>\n `${path.relative(options.root, filePath)} is not the page enable-whatsapp wrote, so it was left as it is. Take the WhatsApp option out of it by hand: ${DOCS_URL}`,\n );\n for (const [filePath, outcome] of outcomes) {\n const file = modifyOutcomeToFile(filePath, outcome);\n if (file) modifies.push(file);\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":";;;;;;;;AAaA,IAAMM,IAAW;AAEjB,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASR,EAAUS,CAAO,GAC1BC,IAAkB,CAAC;CAsBzB,AApBA,MAAMT,EAAeQ,EAAQ,MAAM,OAAO,MAAO;EAE/C,IAAI,CAAE,MAAME,EAAkBC,CAAE,GAAI;EAIpC,AAFAJ,EAAO,KAAK,wCAAwC,GACpD,MAAML,EAAoBS,CAAE,GAC5B,MAAMV,EAAe;EACrB,IAAMW,IAAOC,EAA6BL,GAAS,EAAK;EACxD,AAAKI,KACLH,EAAQ,KAAK;GACX,MAAMG;GACN,UAAU;GACV,SAAST,EAAG,aAAaS,GAAM,MAAM;GACrC,QAAQ;EACV,CAAC;CACH,CAAC,GACDL,EAAO,KACL,mFACF,GAEAA,EAAO,KAAK,gDAAgD;CAC5D,IAAMO,IAAmB,CAAC,GACpBC,IAAW,MAAMC,EACrBR,EAAQ,MACR,YACC,MACC,GAAGJ,EAAK,SAASI,EAAQ,MAAMS,CAAQ,EAAE,+GAA+GZ,GAC5J;CACA,KAAK,IAAM,CAACY,GAAUC,MAAYH,GAAU;EAC1C,IAAMH,IAAOO,EAAoBF,GAAUC,CAAO;EAClD,AAAIN,KAAME,EAAS,KAAKF,CAAI;CAC9B;CAEA,OAAO;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "./dedent-Gq6Krl4n.js";
2
2
  import { n as t } from "./logger-CQONztPm.js";
3
- import { o as n, t as r } from "./ts-morph-helpers-CDW4lhox.js";
4
- import { modifyOutcomeToFile as i } from "./modify-file-BlDeeurK.js";
3
+ import { o as n, t as r } from "./ts-morph-helpers-Bepc-Es2.js";
4
+ import { modifyOutcomeToFile as i } from "./modify-file-DK-tCH9k.js";
5
5
  import { t as a } from "./svelte-file-B3RfgVdt.js";
6
6
  import { t as o } from "./modify-utils-Cw-on_cL.js";
7
7
  import s from "node:fs";
@@ -160,4 +160,4 @@ async function y(e) {
160
160
  //#endregion
161
161
  export { y as generate };
162
162
 
163
- //# sourceMappingURL=generate.runtime-cwvAoKoH.js.map
163
+ //# sourceMappingURL=generate.runtime-BpMN5Uq-.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-cwvAoKoH.js","names":["FAILURE_HINT","NOT_FOUND_HINT","dedent","getLogger","formatLikeSource","addNavItemToScript","SvelteFile","modifyUtils","fs","path","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","args","firstArg","optionsObj","apiProp","apiInit","apiObj","apiKeysProp","keysInit","keysObj","API_KEYS_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet","generate","logger","options","modifies","pushResult","modifyOutcomeToFile","utilsPath"],"sources":["../../src/patterns/enable/api-keys/modifies/hooks.server.ts","../../src/patterns/enable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/enable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with API keys in hooks.server.ts:\n\n handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(\n 0,\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n optionsObj.addPropertyAssignment({\n name: \"api\",\n initializer: `{ enabled: true, apiKeys: { enabled: true } }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (apiProp.getKind() === SyntaxKind.PropertyAssignment) {\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (apiInit && apiInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const enabledProp = apiObj.getProperty(\"enabled\");\n if (!enabledProp) {\n apiObj.addPropertyAssignment({ name: \"enabled\", initializer: \"true\" });\n }\n\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n apiObj.addPropertyAssignment({\n name: \"apiKeys\",\n initializer: `{ enabled: true }`,\n });\n } else if (apiKeysProp.getKind() === SyntaxKind.PropertyAssignment) {\n const keysInit = (\n apiKeysProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (\n keysInit &&\n keysInit.getKind() === SyntaxKind.ObjectLiteralExpression\n ) {\n const keysObj =\n keysInit as import(\"ts-morph\").ObjectLiteralExpression;\n const keysEnabled = keysObj.getProperty(\"enabled\");\n if (!keysEnabled) {\n keysObj.addPropertyAssignment({\n name: \"enabled\",\n initializer: \"true\",\n });\n }\n } else {\n (apiKeysProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `{ enabled: true }`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","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 API_KEYS_NAV_SNIPPET = [\n \"import KeyRoundIcon from '@lucide/svelte/icons/key-round';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'API Keys', url: '/api-keys', icon: KeyRoundIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add an API Keys nav item to nav-user.svelte:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with an API Keys entry:\",\n \"\",\n API_KEYS_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(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"API Keys\",\n \"/api-keys\",\n \"KeyRoundIcon\",\n \"@lucide/svelte/icons/key-round\",\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","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyNavUser } from \"./modifies/nav-user.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, modifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Modifying nav-user\");\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 utils.ts\");\n const utilsPath = path.join(options.root, \"src\", \"lib\", \"utils.ts\");\n pushResult(modifyOutcomeToFile(utilsPath, modifyUtils(utilsPath)));\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":";;;;;;;;;;AAMA,IAAMA,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;;;;;AAa7B,SAAgBW,EA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EAAG,aAAasC,GAAa,MAAM;CAC1D,IAAIZ,EAAe,SAAS,WAAW,GACrC,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,IAAM,EAAE,sBAAmB,gBAAaF,EACtCE,GACA,YACA,aACA,gBACA,gCACF;CAOA,OALKC,KAIL3B,EAAG,cAAcsC,GAAaC,GAAmB,MAAM,GAChD;EAAE,QAAQ;EAAW,SAAS;CAAK,KAJjC;EAAE,QAAQ;EAAU,SAASjB;CAAa;AAKrD;;;ACvEA,eAAsBkB,EAAS,GAAkB;CAC/C,IAAMC,IAAS9C,EAAU+C,CAAO,GAE1BC,IAAmB,CAAC,GACpBC,KAAc,MAAsB;EACxC,AAAInB,KAAMkB,EAAS,KAAKlB,CAAI;CAC9B;CAEA,EAAO,KAAK,2BAA2B;CACvC,IAAMpB,IAAkBJ,EAAK,KAAKyC,EAAQ,MAAM,OAAO,iBAAiB;CAKxE,AAJAE,EACEC,EAAoBxC,GAAiBD,EAAkBC,CAAe,CAAC,CACzE,GAEAoC,EAAO,KAAK,oBAAoB;CAChC,IAAMH,IAAcrC,EAAK,KACvByC,EAAQ,MACR,OACA,OACA,cACA,iBACF;CAGA,AAFAE,EAAWC,EAAoBP,GAAaD,EAAcC,CAAW,CAAC,CAAC,GAEvEG,EAAO,KAAK,oBAAoB;CAChC,IAAMK,IAAY7C,EAAK,KAAKyC,EAAQ,MAAM,OAAO,OAAO,UAAU;CAGlE,OAFAE,EAAWC,EAAoBC,GAAW/C,EAAY+C,CAAS,CAAC,CAAC,GAE1D;EACL,SAAS,CAAC;EACV;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
1
+ {"version":3,"file":"generate.runtime-BpMN5Uq-.js","names":["FAILURE_HINT","NOT_FOUND_HINT","dedent","getLogger","formatLikeSource","addNavItemToScript","SvelteFile","modifyUtils","fs","path","FAILURE_HINT$1","NOT_FOUND_HINT$1","modifyHooksServer","hooksServerPath","originalSource","sourceFile","Project","callExpr","SyntaxKind","ce","args","firstArg","optionsObj","apiProp","apiInit","apiObj","apiKeysProp","keysInit","keysObj","API_KEYS_NAV_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","addItemToNavUser","file","navUserSnippet","wasAdded","tryAdd","run","result","source","title","url","icon","iconImportPath","fn","modifyNavUser","navUserPath","newNavUserSnippet","generate","logger","options","modifies","pushResult","modifyOutcomeToFile","utilsPath"],"sources":["../../src/patterns/enable/api-keys/modifies/hooks.server.ts","../../src/patterns/enable/api-keys/modifies/nav-user.svelte.ts","../../src/patterns/enable/api-keys/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { Project, SyntaxKind } from \"ts-morph\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\nimport { formatLikeSource } from \"../../../../runtime/ts-morph-helpers\";\n\nconst FAILURE_HINT = dedent`\n Configure handlePocketbase() with API keys in hooks.server.ts:\n\n handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Create src/hooks.server.ts with handlePocketbase:\n\n import { handlePocketbase } from 'velastack/handle';\n\n export const handle = handlePocketbase({\n api: {\n enabled: true,\n apiKeys: { enabled: true },\n },\n });\n`;\n\nexport function modifyHooksServer(hooksServerPath: string): ModifyOutcome {\n if (!fs.existsSync(hooksServerPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const originalSource = fs.readFileSync(hooksServerPath, \"utf8\");\n const project = new Project();\n const sourceFile = project.addSourceFileAtPath(hooksServerPath);\n\n const callExpr = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((ce) => ce.getExpression().getText() === \"handlePocketbase\");\n\n if (!callExpr) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n\n const args = callExpr.getArguments();\n if (args.length === 0) {\n callExpr.addArgument(\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const firstArg = args[0];\n if (firstArg.getKind() !== SyntaxKind.ObjectLiteralExpression) {\n callExpr.insertArgument(\n 0,\n `{ api: { enabled: true, apiKeys: { enabled: true } } }`,\n );\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n const optionsObj = firstArg.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);\n\n const apiProp = optionsObj.getProperty(\"api\");\n if (!apiProp) {\n optionsObj.addPropertyAssignment({\n name: \"api\",\n initializer: `{ enabled: true, apiKeys: { enabled: true } }`,\n });\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return { status: \"success\", changed: true };\n }\n\n if (apiProp.getKind() === SyntaxKind.PropertyAssignment) {\n const apiInit = (\n apiProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (apiInit && apiInit.getKind() === SyntaxKind.ObjectLiteralExpression) {\n const apiObj = apiInit as import(\"ts-morph\").ObjectLiteralExpression;\n const enabledProp = apiObj.getProperty(\"enabled\");\n if (!enabledProp) {\n apiObj.addPropertyAssignment({ name: \"enabled\", initializer: \"true\" });\n }\n\n const apiKeysProp = apiObj.getProperty(\"apiKeys\");\n if (!apiKeysProp) {\n apiObj.addPropertyAssignment({\n name: \"apiKeys\",\n initializer: `{ enabled: true }`,\n });\n } else if (apiKeysProp.getKind() === SyntaxKind.PropertyAssignment) {\n const keysInit = (\n apiKeysProp as import(\"ts-morph\").PropertyAssignment\n ).getInitializer();\n if (\n keysInit &&\n keysInit.getKind() === SyntaxKind.ObjectLiteralExpression\n ) {\n const keysObj =\n keysInit as import(\"ts-morph\").ObjectLiteralExpression;\n const keysEnabled = keysObj.getProperty(\"enabled\");\n if (!keysEnabled) {\n keysObj.addPropertyAssignment({\n name: \"enabled\",\n initializer: \"true\",\n });\n }\n } else {\n (apiKeysProp as import(\"ts-morph\").PropertyAssignment).setInitializer(\n `{ enabled: true }`,\n );\n }\n }\n }\n }\n\n formatLikeSource(sourceFile);\n sourceFile.saveSync();\n return {\n status: \"success\",\n changed: sourceFile.getFullText() !== originalSource,\n };\n}\n","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 API_KEYS_NAV_SNIPPET = [\n \"import KeyRoundIcon from '@lucide/svelte/icons/key-round';\",\n \"\",\n \"// Add to your navUser array:\",\n \"{ title: 'API Keys', url: '/api-keys', icon: KeyRoundIcon }\",\n].join(\"\\n\");\n\nconst FAILURE_HINT = [\n \"Add an API Keys nav item to nav-user.svelte:\",\n \"\",\n API_KEYS_NAV_SNIPPET,\n].join(\"\\n\");\n\nconst NOT_FOUND_HINT = [\n \"Create nav-user.svelte with an API Keys entry:\",\n \"\",\n API_KEYS_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(\"/api-keys\")) {\n return { status: \"success\", changed: false };\n }\n\n const { newNavUserSnippet, wasAdded } = addItemToNavUser(\n navUserSnippet,\n \"API Keys\",\n \"/api-keys\",\n \"KeyRoundIcon\",\n \"@lucide/svelte/icons/key-round\",\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","import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { getLogger } from \"../../../core/logger\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyUtils } from \"../../../runtime/modify-utils\";\nimport { modifyHooksServer } from \"./modifies/hooks.server\";\nimport { modifyNavUser } from \"./modifies/nav-user.svelte\";\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n\n const modifies: File[] = [];\n const pushResult = (file: File | null) => {\n if (file) modifies.push(file);\n };\n\n logger.info(\"Modifying hooks.server.ts\");\n const hooksServerPath = path.join(options.root, \"src\", \"hooks.server.ts\");\n pushResult(\n modifyOutcomeToFile(hooksServerPath, modifyHooksServer(hooksServerPath)),\n );\n\n logger.info(\"Modifying nav-user\");\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 utils.ts\");\n const utilsPath = path.join(options.root, \"src\", \"lib\", \"utils.ts\");\n pushResult(modifyOutcomeToFile(utilsPath, modifyUtils(utilsPath)));\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":";;;;;;;;;;AAMA,IAAMA,IAAe,CAAM;;;;;;;;;GAWrBC,IAAiB,CAAM;;;;;;;;;;;;AAa7B,SAAgBW,EAAkB,GAAwC;CACxE,IAAI,CAACJ,EAAG,WAAWK,CAAe,GAChC,OAAO;E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