@velastack/patterns 0.6.0 → 0.7.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.
Files changed (152) hide show
  1. package/README.md +15 -3
  2. package/dist/chunks/{_layout-D-FzWqn0.js → _layout-DQhSAhfF.js} +3 -3
  3. package/dist/chunks/{_layout-D-FzWqn0.js.map → _layout-DQhSAhfF.js.map} +1 -1
  4. package/dist/chunks/{auth-pages-B52ei-4z.js → auth-pages-jsyDV1GR.js} +7 -10
  5. package/dist/chunks/{auth-pages-B52ei-4z.js.map → auth-pages-jsyDV1GR.js.map} +1 -1
  6. package/dist/chunks/{collections-B_DisSfA.js → collections-BYcVyY9O.js} +39 -35
  7. package/dist/chunks/collections-BYcVyY9O.js.map +1 -0
  8. package/dist/chunks/collections-BrEA7a62.js +309 -0
  9. package/dist/chunks/collections-BrEA7a62.js.map +1 -0
  10. package/dist/chunks/{compose-handle-BDlZ7Pif.js → compose-handle-BBlamPfx.js} +18 -22
  11. package/dist/chunks/{compose-handle-BDlZ7Pif.js.map → compose-handle-BBlamPfx.js.map} +1 -1
  12. package/dist/chunks/{config-target-rHgjaA8u.js → config-target-BgyFkbFL.js} +2 -2
  13. package/dist/chunks/{config-target-rHgjaA8u.js.map → config-target-BgyFkbFL.js.map} +1 -1
  14. package/dist/chunks/constants-Bdx8mp7v.js +6 -0
  15. package/dist/chunks/constants-Bdx8mp7v.js.map +1 -0
  16. package/dist/chunks/dedent-Gq6Krl4n.js.map +1 -1
  17. package/dist/chunks/{env-BPfk1VAw.js → env-BugddEjd.js} +5 -9
  18. package/dist/chunks/{env-BPfk1VAw.js.map → env-BugddEjd.js.map} +1 -1
  19. package/dist/chunks/{env-vars-cqQU0ECK.js → env-vars-0hvKe55u.js} +6 -11
  20. package/dist/chunks/{env-vars-cqQU0ECK.js.map → env-vars-0hvKe55u.js.map} +1 -1
  21. package/dist/chunks/generate-BOQA-Flq.js +171 -0
  22. package/dist/chunks/generate-BOQA-Flq.js.map +1 -0
  23. package/dist/chunks/{generate-CXoQPz7n.js → generate-CNabcEBx.js} +2 -2
  24. package/dist/chunks/{generate-CXoQPz7n.js.map → generate-CNabcEBx.js.map} +1 -1
  25. package/dist/chunks/{generate-jx5Iuq5w.js → generate-CO88bEvs.js} +54 -53
  26. package/dist/chunks/generate-CO88bEvs.js.map +1 -0
  27. package/dist/chunks/{generate-Bm_jOMtF.js → generate-Df7t5Nbk.js} +3 -3
  28. package/dist/chunks/{generate-Bm_jOMtF.js.map → generate-Df7t5Nbk.js.map} +1 -1
  29. package/dist/chunks/{generate-Cqwa8kD9.js → generate-DoHn_xJZ.js} +2 -2
  30. package/dist/chunks/{generate-Cqwa8kD9.js.map → generate-DoHn_xJZ.js.map} +1 -1
  31. package/dist/chunks/generate-DyV5R8NP.js.map +1 -1
  32. package/dist/chunks/{generate-D3mSFPdT.js → generate-l2JZTRKb.js} +2 -2
  33. package/dist/chunks/{generate-D3mSFPdT.js.map → generate-l2JZTRKb.js.map} +1 -1
  34. package/dist/chunks/{generate.runtime-FGYc365Q.js → generate.runtime-1ldXcpiD.js} +6 -6
  35. package/dist/chunks/{generate.runtime-FGYc365Q.js.map → generate.runtime-1ldXcpiD.js.map} +1 -1
  36. package/dist/chunks/{generate.runtime-B2r11K7S.js → generate.runtime-B53OTMcE.js} +6 -6
  37. package/dist/chunks/{generate.runtime-B2r11K7S.js.map → generate.runtime-B53OTMcE.js.map} +1 -1
  38. package/dist/chunks/{generate.runtime-DCqf7nYM.js → generate.runtime-B84ymwlD.js} +7 -7
  39. package/dist/chunks/{generate.runtime-DCqf7nYM.js.map → generate.runtime-B84ymwlD.js.map} +1 -1
  40. package/dist/chunks/{generate.runtime-Dug2UIhV.js → generate.runtime-BOl3LpPB.js} +10 -13
  41. package/dist/chunks/{generate.runtime-Dug2UIhV.js.map → generate.runtime-BOl3LpPB.js.map} +1 -1
  42. package/dist/chunks/{generate.runtime-BxDUtkpT.js → generate.runtime-BP31tAcD.js} +5 -5
  43. package/dist/chunks/{generate.runtime-BxDUtkpT.js.map → generate.runtime-BP31tAcD.js.map} +1 -1
  44. package/dist/chunks/{generate.runtime-DdcVnK8J.js → generate.runtime-BoYwV0nt.js} +133 -121
  45. package/dist/chunks/generate.runtime-BoYwV0nt.js.map +1 -0
  46. package/dist/chunks/{generate.runtime-wGRE1zwZ.js → generate.runtime-BqCbJ-No.js} +4 -4
  47. package/dist/chunks/{generate.runtime-wGRE1zwZ.js.map → generate.runtime-BqCbJ-No.js.map} +1 -1
  48. package/dist/chunks/{generate.runtime-BVavIXtX.js → generate.runtime-Bvjj3zn0.js} +6 -6
  49. package/dist/chunks/{generate.runtime-BVavIXtX.js.map → generate.runtime-Bvjj3zn0.js.map} +1 -1
  50. package/dist/chunks/{generate.runtime-_c7daMAw.js → generate.runtime-ByPcr9vJ.js} +4 -4
  51. package/dist/chunks/{generate.runtime-_c7daMAw.js.map → generate.runtime-ByPcr9vJ.js.map} +1 -1
  52. package/dist/chunks/{generate.runtime-Dmob2wFf.js → generate.runtime-C4LUUuq7.js} +5 -5
  53. package/dist/chunks/{generate.runtime-Dmob2wFf.js.map → generate.runtime-C4LUUuq7.js.map} +1 -1
  54. package/dist/chunks/{generate.runtime-wziCW3ct.js → generate.runtime-CGjDfO1P.js} +5 -5
  55. package/dist/chunks/{generate.runtime-wziCW3ct.js.map → generate.runtime-CGjDfO1P.js.map} +1 -1
  56. package/dist/chunks/{generate.runtime-DYdkrHJ1.js → generate.runtime-CHQ_MQJQ.js} +6 -6
  57. package/dist/chunks/{generate.runtime-DYdkrHJ1.js.map → generate.runtime-CHQ_MQJQ.js.map} +1 -1
  58. package/dist/chunks/{generate.runtime-aN5QWygO.js → generate.runtime-CHS5lyHL.js} +39 -36
  59. package/dist/chunks/generate.runtime-CHS5lyHL.js.map +1 -0
  60. package/dist/chunks/{generate.runtime-CyGR8VTx.js → generate.runtime-CHUCMVa2.js} +3 -3
  61. package/dist/chunks/{generate.runtime-CyGR8VTx.js.map → generate.runtime-CHUCMVa2.js.map} +1 -1
  62. package/dist/chunks/{generate.runtime-BxUGDXIK.js → generate.runtime-CVWCUn52.js} +6 -6
  63. package/dist/chunks/{generate.runtime-BxUGDXIK.js.map → generate.runtime-CVWCUn52.js.map} +1 -1
  64. package/dist/chunks/generate.runtime-C_5Ghjri.js +17 -0
  65. package/dist/chunks/generate.runtime-C_5Ghjri.js.map +1 -0
  66. package/dist/chunks/{generate.runtime-CRhD98rs.js → generate.runtime-Cv3unKap.js} +5 -5
  67. package/dist/chunks/{generate.runtime-CRhD98rs.js.map → generate.runtime-Cv3unKap.js.map} +1 -1
  68. package/dist/chunks/{generate.runtime-CkmledBw.js → generate.runtime-D677SB4v.js} +12 -20
  69. package/dist/chunks/{generate.runtime-CkmledBw.js.map → generate.runtime-D677SB4v.js.map} +1 -1
  70. package/dist/chunks/{generate.runtime-DeniHg8L.js → generate.runtime-DERcpgc-.js} +5 -5
  71. package/dist/chunks/{generate.runtime-DeniHg8L.js.map → generate.runtime-DERcpgc-.js.map} +1 -1
  72. package/dist/chunks/{generate.runtime-x-o4LS8d.js → generate.runtime-DJ5uF6EN.js} +4 -4
  73. package/dist/chunks/{generate.runtime-x-o4LS8d.js.map → generate.runtime-DJ5uF6EN.js.map} +1 -1
  74. package/dist/chunks/{generate.runtime-CYBs0JgY.js → generate.runtime-Dfz53sSK.js} +5 -5
  75. package/dist/chunks/{generate.runtime-CYBs0JgY.js.map → generate.runtime-Dfz53sSK.js.map} +1 -1
  76. package/dist/chunks/{generate.runtime-CWnIiXwV.js → generate.runtime-DiqfbDfk.js} +3 -3
  77. package/dist/chunks/{generate.runtime-CWnIiXwV.js.map → generate.runtime-DiqfbDfk.js.map} +1 -1
  78. package/dist/chunks/{generate.runtime-CHb4znYx.js → generate.runtime-Dq6yS7tN.js} +6 -6
  79. package/dist/chunks/{generate.runtime-CHb4znYx.js.map → generate.runtime-Dq6yS7tN.js.map} +1 -1
  80. package/dist/chunks/{generate.runtime-BRCzUO94.js → generate.runtime-T7JLE4Wc.js} +10 -14
  81. package/dist/chunks/{generate.runtime-BRCzUO94.js.map → generate.runtime-T7JLE4Wc.js.map} +1 -1
  82. package/dist/chunks/{generate.runtime-Du4uf98c.js → generate.runtime-WPq7bHRA.js} +3 -3
  83. package/dist/chunks/{generate.runtime-Du4uf98c.js.map → generate.runtime-WPq7bHRA.js.map} +1 -1
  84. package/dist/chunks/{generate.runtime-kpqW3dVO.js → generate.runtime-WeDv05E2.js} +8 -8
  85. package/dist/chunks/{generate.runtime-kpqW3dVO.js.map → generate.runtime-WeDv05E2.js.map} +1 -1
  86. package/dist/chunks/{generate.runtime-N1KtAG8C.js → generate.runtime-aKNvrk3M.js} +90 -175
  87. package/dist/chunks/generate.runtime-aKNvrk3M.js.map +1 -0
  88. package/dist/chunks/{generate.runtime-Bh9Z2cRN.js → generate.runtime-e_BkDyP0.js} +3 -3
  89. package/dist/chunks/{generate.runtime-Bh9Z2cRN.js.map → generate.runtime-e_BkDyP0.js.map} +1 -1
  90. package/dist/chunks/{generate.runtime-DY5vQ3aZ.js → generate.runtime-gZ4wfYBP.js} +8 -8
  91. package/dist/chunks/{generate.runtime-DY5vQ3aZ.js.map → generate.runtime-gZ4wfYBP.js.map} +1 -1
  92. package/dist/chunks/{generate.runtime-DUo-pLRr.js → generate.runtime-oUJUQRdg.js} +7 -7
  93. package/dist/chunks/{generate.runtime-DUo-pLRr.js.map → generate.runtime-oUJUQRdg.js.map} +1 -1
  94. package/dist/chunks/{generate.runtime-gFr2Gsjz.js → generate.runtime-q17D7QUT.js} +5 -5
  95. package/dist/chunks/{generate.runtime-gFr2Gsjz.js.map → generate.runtime-q17D7QUT.js.map} +1 -1
  96. package/dist/chunks/{generate.runtime-B4u9C2YH.js → generate.runtime-rLlDp4R6.js} +5 -5
  97. package/dist/chunks/{generate.runtime-B4u9C2YH.js.map → generate.runtime-rLlDp4R6.js.map} +1 -1
  98. package/dist/chunks/{generate.runtime-bpH3DB0t.js → generate.runtime-zr6uIHCd.js} +3 -3
  99. package/dist/chunks/{generate.runtime-bpH3DB0t.js.map → generate.runtime-zr6uIHCd.js.map} +1 -1
  100. package/dist/chunks/{modify-file-289rStJ2.js → modify-file-B4uJzOEj.js} +4 -4
  101. package/dist/chunks/{modify-file-289rStJ2.js.map → modify-file-B4uJzOEj.js.map} +1 -1
  102. package/dist/chunks/{modify-nav-user-B8h8WTrM.js → modify-nav-user-CJ1LevSU.js} +2 -2
  103. package/dist/chunks/{modify-nav-user-B8h8WTrM.js.map → modify-nav-user-CJ1LevSU.js.map} +1 -1
  104. package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js → modify-svelte-config-remote-CEyYydL7.js} +2 -2
  105. package/dist/chunks/{modify-svelte-config-remote-DhuRX4FI.js.map → modify-svelte-config-remote-CEyYydL7.js.map} +1 -1
  106. package/dist/chunks/{modify-user-signup-BbqTiUuA.js → modify-user-signup-DLtopazD.js} +2 -2
  107. package/dist/chunks/{modify-user-signup-BbqTiUuA.js.map → modify-user-signup-DLtopazD.js.map} +1 -1
  108. package/dist/chunks/{package-imports-Bbw3iMPg.js → package-imports-B9Asv3ZH.js} +3 -3
  109. package/dist/chunks/{package-imports-Bbw3iMPg.js.map → package-imports-B9Asv3ZH.js.map} +1 -1
  110. package/dist/chunks/{pocketbase-B017Cqjq.js → pocketbase-BtN-wL8f.js} +9 -17
  111. package/dist/chunks/{pocketbase-B017Cqjq.js.map → pocketbase-BtN-wL8f.js.map} +1 -1
  112. package/dist/chunks/{providers-CN5J5_fY.js → providers-DRwJnSzb.js} +2 -2
  113. package/dist/chunks/{providers-CN5J5_fY.js.map → providers-DRwJnSzb.js.map} +1 -1
  114. package/dist/chunks/{rolldown-runtime-DArdT4gl.js → rolldown-runtime-5HNE8Q1r.js} +1 -1
  115. package/dist/chunks/{shared-BPlAVf-T.js → shared-BbxLil4g.js} +2 -2
  116. package/dist/chunks/{shared-BPlAVf-T.js.map → shared-BbxLil4g.js.map} +1 -1
  117. package/dist/chunks/{site-DkU1-VRq.js → site-Dw2KIRJu.js} +2 -2
  118. package/dist/chunks/{site-DkU1-VRq.js.map → site-Dw2KIRJu.js.map} +1 -1
  119. package/dist/chunks/{table-core-vXEjJDYP.js → table-core-BHFT-uMX.js} +3 -3
  120. package/dist/chunks/{table-core-vXEjJDYP.js.map → table-core-BHFT-uMX.js.map} +1 -1
  121. package/dist/chunks/{taggedTemplateLiteral-CswN2AAa.js → taggedTemplateLiteral-KSUnuvOk.js} +1 -1
  122. package/dist/chunks/{test-setup-CAfgVlwc.js → test-setup-BVJwm22s.js} +5 -5
  123. package/dist/chunks/{test-setup-CAfgVlwc.js.map → test-setup-BVJwm22s.js.map} +1 -1
  124. package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js → ts-morph-helpers-CHI9wAil.js} +7 -11
  125. package/dist/chunks/{ts-morph-helpers-Bepc-Es2.js.map → ts-morph-helpers-CHI9wAil.js.map} +1 -1
  126. package/dist/chunks/{ui-CTdsenEv.js → ui-gG8i_Mzk.js} +3 -3
  127. package/dist/chunks/{ui-CTdsenEv.js.map → ui-gG8i_Mzk.js.map} +1 -1
  128. package/dist/chunks/{unmodify-load-Bl5vXQiL.js → unmodify-load-Buak-r1f.js} +2 -2
  129. package/dist/chunks/{unmodify-load-Bl5vXQiL.js.map → unmodify-load-Buak-r1f.js.map} +1 -1
  130. package/dist/chunks/{whatsapp-5qJ_xCV1.js → whatsapp-DbjOxHaZ.js} +2 -2
  131. package/dist/chunks/{whatsapp-5qJ_xCV1.js.map → whatsapp-DbjOxHaZ.js.map} +1 -1
  132. package/dist/chunks/write-result-DcqMefuP.js +499 -0
  133. package/dist/chunks/write-result-DcqMefuP.js.map +1 -0
  134. package/dist/chunks/wuchale-config-c3Q4JVSF.js +50 -0
  135. package/dist/chunks/wuchale-config-c3Q4JVSF.js.map +1 -0
  136. package/dist/index.d.ts +173 -19
  137. package/dist/index.js +2330 -2505
  138. package/dist/index.js.map +1 -1
  139. package/package.json +2 -2
  140. package/dist/chunks/collections-B_DisSfA.js.map +0 -1
  141. package/dist/chunks/constants-iej3WkEa.js +0 -6
  142. package/dist/chunks/constants-iej3WkEa.js.map +0 -1
  143. package/dist/chunks/generate-8FS2ROOJ.js +0 -170
  144. package/dist/chunks/generate-8FS2ROOJ.js.map +0 -1
  145. package/dist/chunks/generate-jx5Iuq5w.js.map +0 -1
  146. package/dist/chunks/generate.runtime-DdcVnK8J.js.map +0 -1
  147. package/dist/chunks/generate.runtime-N1KtAG8C.js.map +0 -1
  148. package/dist/chunks/generate.runtime-aN5QWygO.js.map +0 -1
  149. package/dist/chunks/shopify-page-D-VFwGxI.js +0 -11
  150. package/dist/chunks/shopify-page-D-VFwGxI.js.map +0 -1
  151. package/dist/chunks/write-result-0HYIr5a6.js +0 -511
  152. package/dist/chunks/write-result-0HYIr5a6.js.map +0 -1
@@ -2,24 +2,25 @@ import { t as e } from "./errors-DR3gF_7a.js";
2
2
  import { a as t, o as n } from "./util-BLYliuUK.js";
3
3
  import { a as r, c as i, l as a } from "./providers-CL9kQ4hp.js";
4
4
  import { t as o } from "./dedent-Gq6Krl4n.js";
5
- import { t as s } from "./taggedTemplateLiteral-CswN2AAa.js";
5
+ import { t as s } from "./taggedTemplateLiteral-KSUnuvOk.js";
6
6
  import { n as c } from "./logger-CQONztPm.js";
7
- import { r as l, t as u } from "./generate-8FS2ROOJ.js";
8
- import { t as d } from "./shopify-page-D-VFwGxI.js";
9
- import { i as f, n as p, t as m } from "./pocketbase-B017Cqjq.js";
10
- import { i as h, o as g, r as _, t as v } from "./site-DkU1-VRq.js";
11
- import { t as y } from "./env-BPfk1VAw.js";
12
- import { t as b } from "./ts-morph-helpers-Bepc-Es2.js";
13
- import { r as x } from "./modify-file-289rStJ2.js";
14
- import { modifyEnvVarsFiles as S } from "./env-vars-cqQU0ECK.js";
15
- import { t as C } from "./svelte-file-Dv5-bl79.js";
16
- import { t as w } from "./modify-user-signup-BbqTiUuA.js";
17
- import { r as T } from "./collections-B_DisSfA.js";
18
- import E from "node:fs";
19
- import D from "node:path";
20
- import O from "stripe";
7
+ import { r as l, t as u } from "./generate-BOQA-Flq.js";
8
+ import { a as d, i as f, r as p } from "./collections-BrEA7a62.js";
9
+ import { i as m, n as h, t as g } from "./pocketbase-BtN-wL8f.js";
10
+ import { i as _, o as v, r as y, t as b } from "./site-Dw2KIRJu.js";
11
+ import { t as x } from "./env-BugddEjd.js";
12
+ import { t as S } from "./ts-morph-helpers-CHI9wAil.js";
13
+ import { r as C } from "./modify-file-B4uJzOEj.js";
14
+ import { modifyEnvVarsFiles as w } from "./env-vars-0hvKe55u.js";
15
+ import { t as T } from "./svelte-file-Dv5-bl79.js";
16
+ import { n as E, t as D } from "./wuchale-config-c3Q4JVSF.js";
17
+ import { t as O } from "./modify-user-signup-DLtopazD.js";
18
+ import { i as k, r as A } from "./collections-BYcVyY9O.js";
19
+ import j from "node:fs";
20
+ import M from "node:path";
21
+ import N from "stripe";
21
22
  //#region src/patterns/enable/payments/runtime/setup-shopify.ts
22
- async function k(e) {
23
+ async function P(e) {
23
24
  let t = c(e), n = typeof e.input.demoId == "string" ? e.input.demoId.trim() : "", r = [];
24
25
  return n && (t.info("Creating payment +page.svelte"), r.push({
25
26
  path: "src/routes/(public)/payment/+page.svelte",
@@ -39,24 +40,24 @@ async function k(e) {
39
40
  }
40
41
  //#endregion
41
42
  //#region src/patterns/enable/payments/modifies/modify-nav-user.ts
42
- var A = [
43
+ var F = [
43
44
  "import CreditCardIcon from '@lucide/svelte/icons/credit-card';",
44
45
  "",
45
46
  "// Add to your navUser array:",
46
47
  "{ title: 'Billing', url: '/billing', icon: CreditCardIcon }"
47
- ].join("\n"), j = [
48
+ ].join("\n"), I = [
48
49
  "Add a Billing nav item to nav-user.svelte:",
49
50
  "",
50
- A
51
- ].join("\n"), M = [
51
+ F
52
+ ].join("\n"), L = [
52
53
  "Create nav-user.svelte with a Billing entry:",
53
54
  "",
54
- A
55
+ F
55
56
  ].join("\n");
56
- function N(e, t, n, r, i) {
57
- let a = new C(e), o = !1, s = (e) => {
57
+ function R(e, t, n, r, i) {
58
+ let a = new T(e), o = !1, s = (e) => {
58
59
  o || e((e) => {
59
- let a = b(e, t, n, r, i);
60
+ let a = S(e, t, n, r, i);
60
61
  return a.wasAdded && (o = !0), a.source;
61
62
  });
62
63
  };
@@ -65,29 +66,29 @@ function N(e, t, n, r, i) {
65
66
  wasAdded: o
66
67
  };
67
68
  }
68
- function P(e) {
69
- if (!E.existsSync(e)) return {
69
+ function z(e) {
70
+ if (!j.existsSync(e)) return {
70
71
  status: "not-found",
71
- message: M
72
+ message: L
72
73
  };
73
- let t = E.readFileSync(e, "utf8");
74
+ let t = j.readFileSync(e, "utf8");
74
75
  if (t.includes("/billing")) return {
75
76
  status: "success",
76
77
  changed: !1
77
78
  };
78
- let { newNavUserSnippet: n, wasAdded: r } = N(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
79
- return r ? (E.writeFileSync(e, n, "utf8"), {
79
+ let { newNavUserSnippet: n, wasAdded: r } = R(t, "Billing", "/billing", "CreditCardIcon", "@lucide/svelte/icons/credit-card");
80
+ return r ? (j.writeFileSync(e, n, "utf8"), {
80
81
  status: "success",
81
82
  changed: !0
82
83
  }) : {
83
84
  status: "failed",
84
- message: j
85
+ message: I
85
86
  };
86
87
  }
87
88
  //#endregion
88
89
  //#region src/patterns/enable/payments/runtime/stripe.ts
89
- async function F(e, t, n) {
90
- let r = new O(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
90
+ async function B(e, t, n) {
91
+ let r = new N(t), i = await e.collection("users").getFullList(), a = await e.collection("stripe_customers").getFullList(), o = new Set(a.map((e) => e.user)), s = {
91
92
  total: i.length,
92
93
  linked: o.size,
93
94
  created: 0,
@@ -139,8 +140,8 @@ async function F(e, t, n) {
139
140
  }
140
141
  return s;
141
142
  }
142
- async function I(e) {
143
- let t = new O(e), n = await t.products.search({
143
+ async function V(e) {
144
+ let t = new N(e), n = await t.products.search({
144
145
  query: "name:\"Test Product\" AND metadata[\"test\"]:\"true\"",
145
146
  limit: 1
146
147
  });
@@ -170,8 +171,8 @@ async function I(e) {
170
171
  existing: !1
171
172
  };
172
173
  }
173
- async function L(e, t) {
174
- let n = new O(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
174
+ async function H(e, t) {
175
+ let n = new N(e), r = await n.prices.retrieve(t, { expand: ["product"] }), i = typeof r.product == "string" ? await n.products.retrieve(r.product) : r.product;
175
176
  return r.product = i.id, {
176
177
  product: i,
177
178
  price: r,
@@ -180,132 +181,33 @@ async function L(e, t) {
180
181
  }
181
182
  //#endregion
182
183
  //#region src/patterns/enable/payments/runtime/setup-stripe.ts
183
- var R;
184
- async function z(e, n, r, i, a = !0) {
184
+ var U;
185
+ async function W(e, n, r, i, a = !0) {
185
186
  if (!a) return;
186
- await p();
187
- let o = m(n, r, i);
187
+ await h();
188
+ let o = g(n, r, i);
188
189
  o && e.push({
189
190
  path: o,
190
191
  language: t(o),
191
- content: E.readFileSync(o, "utf8"),
192
+ content: j.readFileSync(o, "utf8"),
192
193
  status: "success"
193
194
  });
194
195
  }
195
- function B(e) {
196
- return o(R ||= s(["\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);
196
+ function G(e) {
197
+ return o(U ||= s(["\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);
197
198
  }
198
- async function V(e) {
199
+ async function K(e) {
199
200
  let t = a(e).STRIPE_SECRET_KEY ?? "", n = typeof e.input.demoId == "string" && e.input.demoId !== "" ? e.input.demoId : void 0, r = e.features.auth, i = c(e), o = [], s = [], l = (e) => {
200
201
  e && s.push(e);
201
202
  };
202
- await f(e.root, async (n) => {
203
- let a = (e) => T(n, e, i);
204
- i.info("Creating stripe_products collection");
205
- let s = await a({
206
- name: "stripe_products",
207
- type: "base",
208
- fields: [
209
- {
210
- name: "id",
211
- pattern: "^[a-zA-Z0-9_]+$",
212
- primaryKey: !0,
213
- required: !0,
214
- system: !0,
215
- type: "text"
216
- },
217
- {
218
- name: "name",
219
- required: !1,
220
- type: "text"
221
- },
222
- {
223
- name: "active",
224
- required: !1,
225
- type: "text"
226
- },
227
- {
228
- name: "default_price",
229
- required: !1,
230
- type: "text"
231
- },
232
- {
233
- name: "created",
234
- onCreate: !0,
235
- onUpdate: !1,
236
- type: "autodate"
237
- },
238
- {
239
- name: "updated",
240
- onCreate: !0,
241
- onUpdate: !0,
242
- type: "autodate"
243
- }
244
- ]
245
- });
246
- await z(o, "stripe_products", "created", e, s.created), i.info("Creating stripe_prices collection");
247
- let c = await a({
248
- name: "stripe_prices",
249
- type: "base",
250
- fields: [
251
- {
252
- name: "id",
253
- pattern: "^[a-zA-Z0-9_]+$",
254
- primaryKey: !0,
255
- required: !0,
256
- system: !0,
257
- type: "text"
258
- },
259
- {
260
- name: "billing_scheme",
261
- required: !1,
262
- type: "text"
263
- },
264
- {
265
- name: "currency",
266
- required: !1,
267
- type: "text"
268
- },
269
- {
270
- name: "product",
271
- required: !1,
272
- type: "text"
273
- },
274
- {
275
- name: "recurring",
276
- required: !1,
277
- type: "json"
278
- },
279
- {
280
- name: "type",
281
- required: !1,
282
- type: "text"
283
- },
284
- {
285
- name: "unit_amount",
286
- required: !1,
287
- type: "number"
288
- },
289
- {
290
- name: "active",
291
- required: !1,
292
- type: "bool"
293
- },
294
- {
295
- name: "created",
296
- onCreate: !0,
297
- onUpdate: !1,
298
- type: "autodate"
299
- },
300
- {
301
- name: "updated",
302
- onCreate: !0,
303
- onUpdate: !0,
304
- type: "autodate"
305
- }
306
- ]
307
- });
308
- if (await z(o, "stripe_prices", "created", e, c.created), r) {
203
+ await m(e.root, async (n) => {
204
+ let a = (e) => A(n, e, i);
205
+ for (let t of [f, p]) {
206
+ i.info(`Creating ${t.name} collection`);
207
+ let r = await a(t);
208
+ await W(o, t.name, "created", e, r.created), r.created || o.push(...await k(n, t, e, i));
209
+ }
210
+ if (r) {
309
211
  i.info("Creating stripe_customers collection");
310
212
  let r = await a({
311
213
  name: "stripe_customers",
@@ -341,7 +243,7 @@ async function V(e) {
341
243
  }
342
244
  ]
343
245
  }), s = r.collection;
344
- await z(o, "stripe_customers", "created", e, r.created), i.info("Creating stripe_payment_methods collection");
246
+ await W(o, "stripe_customers", "created", e, r.created), i.info("Creating stripe_payment_methods collection");
345
247
  let c = await a({
346
248
  name: "stripe_payment_methods",
347
249
  type: "base",
@@ -397,7 +299,7 @@ async function V(e) {
397
299
  }
398
300
  ]
399
301
  }), l = c.collection;
400
- await z(o, "stripe_payment_methods", "created", e, c.created), i.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
302
+ await W(o, "stripe_payment_methods", "created", e, c.created), i.info("Linking default_payment_method on stripe_customers"), await n.collections.update("stripe_customers", { fields: [
401
303
  {
402
304
  name: "id",
403
305
  pattern: "^[a-zA-Z0-9_]+$",
@@ -434,7 +336,7 @@ async function V(e) {
434
336
  onUpdate: !0,
435
337
  type: "autodate"
436
338
  }
437
- ] }), await z(o, "stripe_customers", "updated", e), i.info("Creating transactions collection");
339
+ ] }), await W(o, "stripe_customers", "updated", e), i.info("Creating transactions collection");
438
340
  let u = await a({
439
341
  name: "transactions",
440
342
  type: "base",
@@ -505,13 +407,13 @@ async function V(e) {
505
407
  }
506
408
  ]
507
409
  });
508
- await z(o, "transactions", "created", e, u.created), i.info("Syncing existing PocketBase users to Stripe customers");
509
- let d = await F(n, t, i);
410
+ await W(o, "transactions", "created", e, u.created), i.info("Syncing existing PocketBase users to Stripe customers");
411
+ let d = await B(n, t, i);
510
412
  i.info(`Synced ${d.total} users (created ${d.created}, reused ${d.reused}, skipped ${d.skipped})`);
511
413
  }
512
414
  }), n ? i.info(`Fetching Stripe product/price ${n}`) : i.info("Creating test Stripe product and price");
513
- let { product: u, price: d, existing: p } = n ? await L(t, n) : await I(t);
514
- if (p && i.info("Stripe product/price already exists, skipping creation"), i.info("Seeding Stripe product/price records"), await f(e.root, async (e) => {
415
+ let { product: u, price: d, existing: h } = n ? await H(t, n) : await V(t);
416
+ if (h && i.info("Stripe product/price already exists, skipping creation"), i.info("Seeding Stripe product/price records"), await m(e.root, async (e) => {
515
417
  try {
516
418
  await e.collection("stripe_products").getOne(u.id);
517
419
  } catch {
@@ -539,14 +441,14 @@ async function V(e) {
539
441
  }), i.info("Creating payment +page.svelte"), o.push({
540
442
  path: "src/routes/(public)/payment/+page.svelte",
541
443
  language: "svelte",
542
- content: B(d.id),
444
+ content: G(d.id),
543
445
  status: "success"
544
446
  }), r) {
545
447
  i.info("Modifying nav-user.svelte");
546
- let t = D.join(e.root, "src", "lib", "components", "nav-user.svelte");
547
- l(x(t, P(t))), i.info("Modifying signup +page.server.ts");
548
- let n = D.join(e.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
549
- l(x(n, w(n)));
448
+ let t = M.join(e.root, "src", "lib", "components", "nav-user.svelte");
449
+ l(C(t, z(t))), i.info("Modifying signup +page.server.ts");
450
+ let n = M.join(e.root, "src", "routes", "(public)", "(auth)", "signup", "+page.server.ts");
451
+ l(C(n, O(n)));
550
452
  }
551
453
  return {
552
454
  creates: o,
@@ -561,13 +463,18 @@ async function V(e) {
561
463
  }
562
464
  //#endregion
563
465
  //#region src/patterns/enable/payments/runtime/setup-whatsapp.ts
564
- async function H(t) {
565
- let n = t.input.currency, r = _(n) ?? h(t.root);
466
+ async function q(t) {
467
+ let n = t.input.currency, r = y(n) ?? _(t.root);
566
468
  if (!r) 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.`);
567
- let i = E.existsSync(g(t.root)), { file: a } = await v(t, r);
469
+ let i = j.existsSync(v(t.root)), { file: a } = await b(t, r), o = a && i ? [a] : [], s = M.join(t.root, "wuchale.config.js");
470
+ if (j.existsSync(s)) {
471
+ c(t).info("Adding src/lib/order.ts to wuchale's js adapter");
472
+ let e = C(s, E(s, D));
473
+ e && o.push(e);
474
+ }
568
475
  return {
569
476
  creates: a && !i ? [a] : [],
570
- modifies: a && i ? [a] : [],
477
+ modifies: o,
571
478
  deletes: [],
572
479
  components: [],
573
480
  packages: [],
@@ -578,14 +485,22 @@ async function H(t) {
578
485
  }
579
486
  //#endregion
580
487
  //#region src/patterns/enable/payments/generate.runtime.ts
581
- async function U(e) {
488
+ function J(e) {
489
+ try {
490
+ let t = JSON.parse(j.readFileSync(M.join(e, "package.json"), "utf8"));
491
+ return !!(t.devDependencies?.vitest || t.dependencies?.vitest);
492
+ } catch {
493
+ return !1;
494
+ }
495
+ }
496
+ async function Y(e) {
582
497
  let t = c(e), o = i(u, e), s = [], d = [], f = (e) => {
583
498
  e && d.push(e);
584
499
  };
585
500
  t.info(`Writing ${o.label} credentials to .env`);
586
- let p = D.join(e.root, ".env");
587
- f(x(p, y(p, l(o, a(e))))), t.info(`Declaring ${o.label} variables in src/env.ts`);
588
- let m = S(e.root, r(o));
501
+ let p = M.join(e.root, ".env");
502
+ f(C(p, x(p, l(o, a(e))))), t.info(`Declaring ${o.label} variables in src/env.ts`);
503
+ let m = w(e.root, r(o));
589
504
  m.create && s.push(m.create), f(m.modify);
590
505
  let h = {
591
506
  creates: s,
@@ -596,10 +511,10 @@ async function U(e) {
596
511
  collections: [],
597
512
  collectionPatches: [],
598
513
  collectionDrops: []
599
- }, g = o.id === "stripe" ? await V(e) : o.id === "shopify" ? await k(e) : await H(e);
514
+ }, g = o.id === "stripe" ? await K(e) : o.id === "shopify" ? await P(e) : await q(e);
600
515
  return n([h, g]);
601
516
  }
602
517
  //#endregion
603
- export { U as generate };
518
+ export { Y as generate, J as hasVitest };
604
519
 
605
- //# sourceMappingURL=generate.runtime-N1KtAG8C.js.map
520
+ //# sourceMappingURL=generate.runtime-aKNvrk3M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.runtime-aKNvrk3M.js","names":["InvalidArgumentError","languageFromPath","mergeResults","providerEnvVars","resolveProvider","suppliedProviderEnv","dedent","_taggedTemplateLiteral","getLogger","envEditsFor","META","buyPageSnippet","STRIPE_PRODUCTS","STRIPE_PRICES","withPocketbase","migrationDelay","getMigrationFile","siteCurrency","sitePath","normalizeCurrency","ensureSiteCurrency","modifyEnv","addNavItemToScript","modifyOutcomeToFile","SvelteFile","modifyWuchaleJsFiles","TRANSLATED_LIB_FILES","modifyUserSignup","ensureCollectionFields","createCollectionIdempotent","fs","path","Stripe","setupShopify","logger","options","variantId","creates","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","error","paymentMethods","paymentMethod","defaultPaymentMethod","createTestProductAndPrice","products","product","prices","getProductAndPriceById","price","priceId","_templateObject","pushMigrationCreates","created","migrationFile","collectionName","action","paymentPageSnippet","setupStripe","stripePriceId","isAppMode","modifies","pushResult","create","spec","customersResult","stripeCustomersCollection","paymentMethodsResult","stripePaymentMethodsCollection","transactionsResult","syncResult","userSignupPath","setupWhatsApp","given","currency","existed","wuchaleConfig","edit","hasVitest","pkg","root","generate","provider","envPath","envVars","modifyEnvVarsFiles","env","setup"],"sources":["../../src/patterns/enable/payments/runtime/setup-shopify.ts","../../src/patterns/enable/payments/modifies/modify-nav-user.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 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 { 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 {\n modifyWuchaleJsFiles,\n TRANSLATED_LIB_FILES,\n} from \"../../../../runtime/wuchale-config\";\nimport {\n ensureSiteCurrency,\n normalizeCurrency,\n siteCurrency,\n sitePath,\n} from \"../../../../runtime/site\";\n\n/**\n * WhatsApp keeps nothing past the env and the business's currency: orders go\n * to the business's chat, and the hosted form they are recorded to is\n * created by the CLI. Every price is in `site.currency`, the currency the\n * business quotes in, so it is written once into `src/lib/site.ts`.\n */\nexport async function setupWhatsApp(options: Options) {\n const given = options.input.currency;\n const currency = normalizeCurrency(given) ?? siteCurrency(options.root);\n if (!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 existed = fs.existsSync(sitePath(options.root));\n const { file } = await ensureSiteCurrency(options, currency);\n const modifies: File[] = file && existed ? [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: file && !existed ? [file] : [],\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 { mergeResults } from \"../../../core/util\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { envEditsFor, META } from \"./generate\";\nimport { setupShopify } from \"./runtime/setup-shopify\";\nimport { setupStripe } from \"./runtime/setup-stripe\";\nimport { setupWhatsApp } from \"./runtime/setup-whatsapp\";\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 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);\n\n return mergeResults([env, setup]) satisfies Result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAQA,eAAsBiC,EAAa,GAAkB;CACnD,IAAMC,IAAS1B,EAAU2B,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,SAAS1B,EAAeyB,CAAS;EACjC,QAAQ;CACV,CAAC,IAGI;EACL;EACA,UAAU,CAAC;EACX,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAA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EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB,GAEMC,IACJL,EAAS,OAAO,WACZ,MAAMxB,EAAYrD,CAAO,IACzB6E,EAAS,OAAO,YACd,MAAM/E,EAAaE,CAAO,IAC1B,MAAMmE,EAAcnE,CAAO;CAEnC,OAAOjC,EAAa,CAACkH,GAAKC,CAAK,CAAC;AAClC"}
@@ -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 { _ as n, r } from "./ts-morph-helpers-Bepc-Es2.js";
4
- import { r as i } from "./modify-file-289rStJ2.js";
3
+ import { _ as n, r } from "./ts-morph-helpers-CHI9wAil.js";
4
+ import { r as i } from "./modify-file-B4uJzOEj.js";
5
5
  import { t as a } from "./svelte-file-Dv5-bl79.js";
6
6
  import o from "node:fs";
7
7
  import s from "node:path";
@@ -79,4 +79,4 @@ async function h(e) {
79
79
  //#endregion
80
80
  export { h as generate, m as hasStripeCustomer };
81
81
 
82
- //# sourceMappingURL=generate.runtime-Bh9Z2cRN.js.map
82
+ //# sourceMappingURL=generate.runtime-e_BkDyP0.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-Bh9Z2cRN.js","names":["dedent","getLogger","withInMemoryScript","modifyOutcomeToFile","SvelteFile","fs","path","CART_BUTTON_MODULE","CART_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyRootLayoutSvelte","layoutPath","file","out","source","sf","authItem","items","lastItem","hasStripeCustomer","root","generate","logger","options","modifies"],"sources":["../../src/patterns/enable/ecommerce/modifies/root-layout.svelte.ts","../../src/patterns/enable/ecommerce/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport const CART_BUTTON_MODULE = \"#lib/components/cart/cart-button.svelte\";\n\nconst CART_NAVBAR_ITEM = \"<Navbar.Item>\\n\\t<CartButton />\\n</Navbar.Item>\";\n\nconst IMPORT_SNIPPET = `import CartButton from '${CART_BUTTON_MODULE}';`;\n\nconst FAILURE_HINT = dedent`\n Add the cart button inside your <Navbar.List> in the root layout.\n\n Import to add to the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup to add inside <Navbar.List>:\n\n ${CART_NAVBAR_ITEM}\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Add the cart button to the layout your public pages share.\n\n Import for the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup, wherever your navigation is:\n\n <CartButton />\n`;\n\n/**\n * Puts the cart button in the navbar: left of the account menu when auth\n * added one, else after the last item.\n */\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"CartButton\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"CartButton\", moduleSpecifier: CART_BUTTON_MODULE },\n ]);\n });\n return out;\n });\n\n const authItem = file.findElementContaining(\"Navbar.Item\", \"AuthMenu.Root\");\n const items = file.childElements(\"Navbar.List\", \"Navbar.Item\");\n const lastItem = items[items.length - 1];\n if (authItem) {\n file.insertBeforeElement(authItem, CART_NAVBAR_ITEM);\n } else if (lastItem) {\n file.insertAfterElement(lastItem, CART_NAVBAR_ITEM);\n } else {\n file.insertBeforeClosingTag(\n \"Navbar.List\",\n `\\n\\t\\t${CART_NAVBAR_ITEM.replace(/\\n/g, \"\\n\\t\\t\")}\\n\\t`,\n );\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\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 { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\n\n/** Created by enable-payments for Stripe when auth was already on. */\nexport function hasStripeCustomer(root: string): boolean {\n return fs.existsSync(\n path.join(root, \"src\", \"lib\", \"server\", \"stripe-customer.ts\"),\n );\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Adding the cart to the navbar\");\n const layoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n const file = modifyOutcomeToFile(\n layoutPath,\n modifyRootLayoutSvelte(layoutPath),\n );\n if (file) modifies.push(file);\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":";;;;;;;;AASA,IAAaO,IAAqB,2CAE5BC,IAAmB,kDAEnBC,IAAiB,2BAA2BF,EAAmB,KAE/DG,IAAe,CAAM;;;;;IAKvBD,EAAe;;;;IAIfD,EAAiB;GAGfG,IAAiB,CAAM;;;;;IAKzBF,EAAe;;;;;;AAWnB,SAAgBG,EAAuB,GAAmC;CACxE,IAAI,CAACP,EAAG,WAAWQ,CAAU,GAC3B,OAAO;EAAE,QAAQ;EAAa,SAASF;CAAe;CAGxD,IAAMG,IAAOV,EAAW,SAASS,CAAU;CAC3C,IAAI,CAACC,EAAK,WAAW,aAAa,GAChC,OAAO;EAAE,QAAQ;EAAU,SAASJ;CAAa;CAEnD,IAAII,EAAK,WAAW,YAAY,GAC9B,OAAO;EAAE,QAAQ;EAAW,SAAS;CAAM;CAG7C,EAAK,cAAc,MAAW;EAC5B,IAAM,EAAE,QAAQC,MAAQb,EAAmBc,IAAS,MAAO;GACzD,EAAcC,GAAI,CAChB;IAAE,eAAe;IAAc,iBAAiBV;GAAmB,CACrE,CAAC;EACH,CAAC;EACD,OAAOQ;CACT,CAAC;CAED,IAAMG,IAAWJ,EAAK,sBAAsB,eAAe,eAAe,GACpEK,IAAQL,EAAK,cAAc,eAAe,aAAa,GACvDM,IAAWD,EAAMA,EAAM,SAAS;CAatC,OAZID,IACFJ,EAAK,oBAAoBI,GAAUV,CAAgB,IAC1CY,IACTN,EAAK,mBAAmBM,GAAUZ,CAAgB,IAElDM,EAAK,uBACH,eACA,SAASN,EAAiB,QAAQ,OAAO,MAAQ,EAAE,KACrD,GAGFM,EAAK,QAAQD,CAAU,GAChB;EAAE,QAAQ;EAAW,SAASC,EAAK,WAAW;CAAE;AACzD;;;ACzEA,SAAgBO,EAAkB,GAAuB;CACvD,OAAOhB,EAAG,WACRC,EAAK,KAAKgB,GAAM,OAAO,OAAO,UAAU,oBAAoB,CAC9D;AACF;AAEA,eAAsBC,EAAS,GAAkB;CAC/C,IAAMC,IAASvB,EAAUwB,CAAO,GAC1BC,IAAmB,CAAC;CAE1B,EAAO,KAAK,+BAA+B;CAC3C,IAAMb,IAAaP,EAAK,KACtBmB,EAAQ,MACR,OACA,UACA,YACA,oBACF,GACMX,IAAOX,EACXU,GACAD,EAAuBC,CAAU,CACnC;CAGA,OAFIC,KAAMY,EAAS,KAAKZ,CAAI,GAErB;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-e_BkDyP0.js","names":["dedent","getLogger","withInMemoryScript","modifyOutcomeToFile","SvelteFile","fs","path","CART_BUTTON_MODULE","CART_NAVBAR_ITEM","IMPORT_SNIPPET","FAILURE_HINT","NOT_FOUND_HINT","modifyRootLayoutSvelte","layoutPath","file","out","source","sf","authItem","items","lastItem","hasStripeCustomer","root","generate","logger","options","modifies"],"sources":["../../src/patterns/enable/ecommerce/modifies/root-layout.svelte.ts","../../src/patterns/enable/ecommerce/generate.runtime.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport dedent from \"dedent\";\nimport { SvelteFile } from \"../../../../runtime/svelte-file\";\nimport {\n ensureImports,\n withInMemoryScript,\n} from \"../../../../runtime/ts-morph-helpers\";\nimport type { ModifyOutcome } from \"../../../../core/types\";\n\nexport const CART_BUTTON_MODULE = \"#lib/components/cart/cart-button.svelte\";\n\nconst CART_NAVBAR_ITEM = \"<Navbar.Item>\\n\\t<CartButton />\\n</Navbar.Item>\";\n\nconst IMPORT_SNIPPET = `import CartButton from '${CART_BUTTON_MODULE}';`;\n\nconst FAILURE_HINT = dedent`\n Add the cart button inside your <Navbar.List> in the root layout.\n\n Import to add to the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup to add inside <Navbar.List>:\n\n ${CART_NAVBAR_ITEM}\n`;\n\nconst NOT_FOUND_HINT = dedent`\n Add the cart button to the layout your public pages share.\n\n Import for the <script> tag:\n\n ${IMPORT_SNIPPET}\n\n Markup, wherever your navigation is:\n\n <CartButton />\n`;\n\n/**\n * Puts the cart button in the navbar: left of the account menu when auth\n * added one, else after the last item.\n */\nexport function modifyRootLayoutSvelte(layoutPath: string): ModifyOutcome {\n if (!fs.existsSync(layoutPath)) {\n return { status: \"not-found\", message: NOT_FOUND_HINT };\n }\n\n const file = SvelteFile.fromPath(layoutPath);\n if (!file.hasElement(\"Navbar.List\")) {\n return { status: \"failed\", message: FAILURE_HINT };\n }\n if (file.hasElement(\"CartButton\")) {\n return { status: \"success\", changed: false };\n }\n\n file.modifyScript((source) => {\n const { source: out } = withInMemoryScript(source, (sf) => {\n ensureImports(sf, [\n { defaultImport: \"CartButton\", moduleSpecifier: CART_BUTTON_MODULE },\n ]);\n });\n return out;\n });\n\n const authItem = file.findElementContaining(\"Navbar.Item\", \"AuthMenu.Root\");\n const items = file.childElements(\"Navbar.List\", \"Navbar.Item\");\n const lastItem = items[items.length - 1];\n if (authItem) {\n file.insertBeforeElement(authItem, CART_NAVBAR_ITEM);\n } else if (lastItem) {\n file.insertAfterElement(lastItem, CART_NAVBAR_ITEM);\n } else {\n file.insertBeforeClosingTag(\n \"Navbar.List\",\n `\\n\\t\\t${CART_NAVBAR_ITEM.replace(/\\n/g, \"\\n\\t\\t\")}\\n\\t`,\n );\n }\n\n file.writeTo(layoutPath);\n return { status: \"success\", changed: file.hasChanged() };\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 { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { modifyRootLayoutSvelte } from \"./modifies/root-layout.svelte\";\n\n/** Created by enable-payments for Stripe when auth was already on. */\nexport function hasStripeCustomer(root: string): boolean {\n return fs.existsSync(\n path.join(root, \"src\", \"lib\", \"server\", \"stripe-customer.ts\"),\n );\n}\n\nexport async function generate(options: Options) {\n const logger = getLogger(options);\n const modifies: File[] = [];\n\n logger.info(\"Adding the cart to the navbar\");\n const layoutPath = path.join(\n options.root,\n \"src\",\n \"routes\",\n \"(public)\",\n \"root-layout.svelte\",\n );\n const file = modifyOutcomeToFile(\n layoutPath,\n modifyRootLayoutSvelte(layoutPath),\n );\n if (file) modifies.push(file);\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":";;;;;;;;AASA,IAAaO,IAAqB,2CAE5BC,IAAmB,kDAEnBC,IAAiB,2BAA2BF,EAAmB,KAE/DG,IAAe,CAAM;;;;;IAKvBD,EAAe;;;;IAIfD,EAAiB;GAGfG,IAAiB,CAAM;;;;;IAKzBF,EAAe;;;;;;AAWnB,SAA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CAAI,GAErB;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,13 +1,13 @@
1
1
  import { t as e } from "./errors-DR3gF_7a.js";
2
- import { n as t } from "./constants-iej3WkEa.js";
2
+ import { n as t } from "./constants-Bdx8mp7v.js";
3
3
  import { a as n, c as r, l as i } from "./providers-CL9kQ4hp.js";
4
- import { n as a, s as o } from "./generate-D3mSFPdT.js";
4
+ import { n as a, s as o } from "./generate-l2JZTRKb.js";
5
5
  import { n as s } from "./logger-CQONztPm.js";
6
- import { t as c } from "./env-BPfk1VAw.js";
7
- import { r as l } from "./modify-file-289rStJ2.js";
8
- import { modifyEnvVarsFiles as u } from "./env-vars-cqQU0ECK.js";
9
- import { o as d } from "./config-target-rHgjaA8u.js";
10
- import { c as f } from "./write-result-0HYIr5a6.js";
6
+ import { t as c } from "./env-BugddEjd.js";
7
+ import { r as l } from "./modify-file-B4uJzOEj.js";
8
+ import { modifyEnvVarsFiles as u } from "./env-vars-0hvKe55u.js";
9
+ import { o as d } from "./config-target-BgyFkbFL.js";
10
+ import { c as f } from "./write-result-DcqMefuP.js";
11
11
  import p from "node:path";
12
12
  //#region src/patterns/enable/ai/generate.runtime.ts
13
13
  var m = f(t), h = [
@@ -40,4 +40,4 @@ async function _(t) {
40
40
  //#endregion
41
41
  export { _ as generate };
42
42
 
43
- //# sourceMappingURL=generate.runtime-DY5vQ3aZ.js.map
43
+ //# sourceMappingURL=generate.runtime-gZ4wfYBP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.runtime-DY5vQ3aZ.js","names":["ADAPTER_STATIC_SPEC","InvalidArgumentError","ADAPTER_STATIC$1","providerEnvVars","resolveProvider","suppliedProviderEnv","META","envEditsFor","getLogger","modifyEnv","modifyOutcomeToFile","resolveConfigTarget","packageName","path","ADAPTER_STATIC","STATIC_ADAPTER_MESSAGE","usesStaticAdapter","res","root","decl","generate","options","logger","provider","creates","modifies","envVars","modifyEnvVarsFiles","envPath","envFile"],"sources":["../../src/patterns/enable/ai/generate.runtime.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { getLogger } from \"../../../core/logger\";\nimport { ADAPTER_STATIC as ADAPTER_STATIC_SPEC } from \"../../../core/constants\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { resolveConfigTarget } from \"../../../runtime/config-target\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { packageName } from \"../../../runtime/write-result\";\nimport { envEditsFor, META } from \"./generate\";\n\n// The config imports the package, not the versioned spec the constant installs.\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\n\nexport const STATIC_ADAPTER_MESSAGE = [\n `AI needs a server, and this project builds with ${ADAPTER_STATIC}.`,\n \"The chat endpoint streams each reply from the server with a private API key, which a static site cannot do.\",\n \"Switch to a server adapter first: `vela enable backend` moves the project to @sveltejs/adapter-node.\",\n].join(\"\\n\");\n\n/**\n * Whether the SvelteKit config the project builds with imports\n * adapter-static. A config that cannot be resolved does not count: the\n * pattern only refuses what it can see.\n */\nexport function usesStaticAdapter(root: string): boolean {\n const res = resolveConfigTarget(root);\n if (res.status !== \"resolved\") return false;\n return res.target.sourceFile\n .getImportDeclarations()\n .some((decl) => decl.getModuleSpecifierValue() === ADAPTER_STATIC);\n}\n\nexport async function generate(options: Options) {\n if (usesStaticAdapter(options.root)) {\n throw new InvalidArgumentError(STATIC_ADAPTER_MESSAGE);\n }\n\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n // SvelteKit 3 exposes only declared variables: `src/lib/server/ai.ts`\n // imports the provider's key from `$app/env/private`.\n logger.info(\"Declaring the API key in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n const envFile = modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n );\n if (envFile) modifies.push(envFile);\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":";;;;;;;;;;;;AAkBA,IAAMc,IAAiBF,EAAYZ,CAAmB,GAEzCe,IAAyB;CACpC,mDAAmDD,EAAe;CAClE;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBE,EAAkB,GAAuB;CACvD,IAAMC,IAAMN,EAAoBO,CAAI;CAEpC,OADID,EAAI,WAAW,cACZA,EAAI,OAAO,WACf,sBAAsB,CAAC,CACvB,MAAM,MAASE,EAAK,wBAAwB,MAAML,CAAc;AACrE;AAEA,eAAsBM,EAAS,GAAkB;CAC/C,IAAIJ,EAAkBK,EAAQ,IAAI,GAChC,MAAM,IAAIpB,EAAqBc,CAAsB;CAGvD,IAAMO,IAASd,EAAUa,CAAO,GAC1BE,IAAWnB,EAAgBE,GAAMe,CAAO,GACxCG,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAI1B,EAAO,KAAK,qCAAqC;CACjD,IAAMC,IAAUC,EAAmBN,EAAQ,MAAMlB,EAAgBoB,CAAQ,CAAC;CAI1E,AAHIG,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAC3CA,EAAQ,UAAQD,EAAS,KAAKC,EAAQ,MAAM,GAEhDJ,EAAO,KAAK,eAAe;CAC3B,IAAMM,IAAUf,EAAK,KAAKQ,EAAQ,MAAM,MAAM,GACxCQ,IAAUnB,EACdkB,GACAnB,EAAUmB,GAASrB,EAAYgB,GAAUlB,EAAoBgB,CAAO,CAAC,CAAC,CACxE;CAGA,OAFIQ,KAASJ,EAAS,KAAKI,CAAO,GAE3B;EACL;EACA;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-gZ4wfYBP.js","names":["ADAPTER_STATIC_SPEC","InvalidArgumentError","ADAPTER_STATIC$1","providerEnvVars","resolveProvider","suppliedProviderEnv","META","envEditsFor","getLogger","modifyEnv","modifyOutcomeToFile","resolveConfigTarget","packageName","path","ADAPTER_STATIC","STATIC_ADAPTER_MESSAGE","usesStaticAdapter","res","root","decl","generate","options","logger","provider","creates","modifies","envVars","modifyEnvVarsFiles","envPath","envFile"],"sources":["../../src/patterns/enable/ai/generate.runtime.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { File, Options, Result } from \"../../../core/types\";\nimport { InvalidArgumentError } from \"../../../core/errors\";\nimport { getLogger } from \"../../../core/logger\";\nimport { ADAPTER_STATIC as ADAPTER_STATIC_SPEC } from \"../../../core/constants\";\nimport {\n providerEnvVars,\n resolveProvider,\n suppliedProviderEnv,\n} from \"../../../core/providers\";\nimport { resolveConfigTarget } from \"../../../runtime/config-target\";\nimport { modifyEnv } from \"../../../runtime/env\";\nimport { modifyEnvVarsFiles } from \"../../../runtime/env-vars\";\nimport { modifyOutcomeToFile } from \"../../../runtime/modify-file\";\nimport { packageName } from \"../../../runtime/write-result\";\nimport { envEditsFor, META } from \"./generate\";\n\n// The config imports the package, not the versioned spec the constant installs.\nconst ADAPTER_STATIC = packageName(ADAPTER_STATIC_SPEC);\n\nexport const STATIC_ADAPTER_MESSAGE = [\n `AI needs a server, and this project builds with ${ADAPTER_STATIC}.`,\n \"The chat endpoint streams each reply from the server with a private API key, which a static site cannot do.\",\n \"Switch to a server adapter first: `vela enable backend` moves the project to @sveltejs/adapter-node.\",\n].join(\"\\n\");\n\n/**\n * Whether the SvelteKit config the project builds with imports\n * adapter-static. A config that cannot be resolved does not count: the\n * pattern only refuses what it can see.\n */\nexport function usesStaticAdapter(root: string): boolean {\n const res = resolveConfigTarget(root);\n if (res.status !== \"resolved\") return false;\n return res.target.sourceFile\n .getImportDeclarations()\n .some((decl) => decl.getModuleSpecifierValue() === ADAPTER_STATIC);\n}\n\nexport async function generate(options: Options) {\n if (usesStaticAdapter(options.root)) {\n throw new InvalidArgumentError(STATIC_ADAPTER_MESSAGE);\n }\n\n const logger = getLogger(options);\n const provider = resolveProvider(META, options);\n const creates: File[] = [];\n const modifies: File[] = [];\n\n // SvelteKit 3 exposes only declared variables: `src/lib/server/ai.ts`\n // imports the provider's key from `$app/env/private`.\n logger.info(\"Declaring the API key in src/env.ts\");\n const envVars = modifyEnvVarsFiles(options.root, providerEnvVars(provider));\n if (envVars.create) creates.push(envVars.create);\n if (envVars.modify) modifies.push(envVars.modify);\n\n logger.info(\"Updating .env\");\n const envPath = path.join(options.root, \".env\");\n const envFile = modifyOutcomeToFile(\n envPath,\n modifyEnv(envPath, envEditsFor(provider, suppliedProviderEnv(options))),\n );\n if (envFile) modifies.push(envFile);\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":";;;;;;;;;;;;AAkBA,IAAMc,IAAiBF,EAAYZ,CAAmB,GAEzCe,IAAyB;CACpC,mDAAmDD,EAAe;CAClE;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAOX,SAAgBE,EAAkB,GAAuB;CACvD,IAAMC,IAAMN,EAAoBO,CAAI;CAEpC,OADID,EAAI,WAAW,cACZA,EAAI,OAAO,WACf,sBAAsB,CAAC,CACvB,MAAM,MAASE,EAAK,wBAAwB,MAAML,CAAc;AACrE;AAEA,eAAsBM,EAAS,GAAkB;CAC/C,IAAIJ,EAAkBK,EAAQ,IAAI,GAChC,MAAM,IAAIpB,EAAqBc,CAAsB;CAGvD,IAAMO,IAASd,EAAUa,CAAO,GAC1BE,IAAWnB,EAAgBE,GAAMe,CAAO,GACxCG,IAAkB,CAAC,GACnBC,IAAmB,CAAC;CAI1B,EAAO,KAAK,qCAAqC;CACjD,IAAMC,IAAUC,EAAmBN,EAAQ,MAAMlB,EAAgBoB,CAAQ,CAAC;CAI1E,AAHIG,EAAQ,UAAQF,EAAQ,KAAKE,EAAQ,MAAM,GAC3CA,EAAQ,UAAQD,EAAS,KAAKC,EAAQ,MAAM,GAEhDJ,EAAO,KAAK,eAAe;CAC3B,IAAMM,IAAUf,EAAK,KAAKQ,EAAQ,MAAM,MAAM,GACxCQ,IAAUnB,EACdkB,GACAnB,EAAUmB,GAASrB,EAAYgB,GAAUlB,EAAoBgB,CAAO,CAAC,CAAC,CACxE;CAGA,OAFIQ,KAASJ,EAAS,KAAKI,CAAO,GAE3B;EACL;EACA;EACA,SAAS,CAAC;EACV,YAAY,CAAC;EACb,UAAU,CAAC;EACX,aAAa,CAAC;EACd,mBAAmB,CAAC;EACpB,iBAAiB,CAAC;CACpB;AACF"}
@@ -1,10 +1,10 @@
1
- import { o as e } from "./generate-D3mSFPdT.js";
1
+ import { o as e } from "./generate-l2JZTRKb.js";
2
2
  import { n as t } from "./logger-CQONztPm.js";
3
- import { n } from "./shared-BPlAVf-T.js";
4
- import { n as r, r as i, t as a } from "./generate-Bm_jOMtF.js";
5
- import { n as o } from "./env-BPfk1VAw.js";
6
- import { t as s } from "./modify-file-289rStJ2.js";
7
- import { unmodifyEnvVarsFiles as c } from "./env-vars-cqQU0ECK.js";
3
+ import { n } from "./shared-BbxLil4g.js";
4
+ import { n as r, r as i, t as a } from "./generate-Df7t5Nbk.js";
5
+ import { n as o } from "./env-BugddEjd.js";
6
+ import { t as s } from "./modify-file-B4uJzOEj.js";
7
+ import { unmodifyEnvVarsFiles as c } from "./env-vars-0hvKe55u.js";
8
8
  import l from "node:fs";
9
9
  import u from "node:path";
10
10
  //#region src/patterns/disable/ai/generate.runtime.ts
@@ -32,4 +32,4 @@ async function d(d) {
32
32
  //#endregion
33
33
  export { d as generate };
34
34
 
35
- //# sourceMappingURL=generate.runtime-DUo-pLRr.js.map
35
+ //# sourceMappingURL=generate.runtime-oUJUQRdg.js.map