cloudcommerce 2.2.3 → 2.3.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 (170) hide show
  1. package/.github/workflows/test-apps.yml +3 -3
  2. package/CHANGELOG.md +29 -0
  3. package/action.yml +6 -6
  4. package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
  5. package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
  6. package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
  7. package/ecomplus-stores/barra-doce/package.json +2 -2
  8. package/package.json +2 -2
  9. package/packages/api/package.json +1 -1
  10. package/packages/apps/affiliate-program/package.json +1 -1
  11. package/packages/apps/correios/package.json +1 -1
  12. package/packages/apps/custom-payment/package.json +1 -1
  13. package/packages/apps/custom-shipping/package.json +1 -1
  14. package/packages/apps/datafrete/package.json +1 -1
  15. package/packages/apps/discounts/package.json +1 -1
  16. package/packages/apps/emails/package.json +1 -1
  17. package/packages/apps/fb-conversions/package.json +1 -1
  18. package/packages/apps/flash-courier/package.json +1 -1
  19. package/packages/apps/frenet/package.json +1 -1
  20. package/packages/apps/galaxpay/package.json +1 -1
  21. package/packages/apps/google-analytics/package.json +1 -1
  22. package/packages/apps/jadlog/package.json +1 -1
  23. package/packages/apps/loyalty-points/package.json +1 -1
  24. package/packages/apps/mandae/package.json +1 -1
  25. package/packages/apps/melhor-envio/package.json +1 -1
  26. package/packages/apps/mercadopago/package.json +1 -1
  27. package/packages/apps/pagarme/package.json +1 -1
  28. package/packages/apps/pagarme-v5/package.json +1 -1
  29. package/packages/apps/paghiper/package.json +1 -1
  30. package/packages/apps/pix/package.json +1 -1
  31. package/packages/apps/tiny-erp/package.json +1 -1
  32. package/packages/apps/webhooks/package.json +1 -1
  33. package/packages/cli/ci/bunny-config-base.sh +4 -2
  34. package/packages/cli/config/firestore.rules +3 -0
  35. package/packages/cli/package.json +1 -1
  36. package/packages/config/package.json +1 -1
  37. package/packages/emails/package.json +1 -1
  38. package/packages/eslint/package.json +1 -1
  39. package/packages/events/package.json +1 -1
  40. package/packages/feeds/package.json +1 -1
  41. package/packages/firebase/package.json +1 -1
  42. package/packages/i18n/package.json +1 -1
  43. package/packages/modules/lib/firebase/handle-module.js +28 -7
  44. package/packages/modules/lib/firebase/handle-module.js.map +1 -1
  45. package/packages/modules/package.json +1 -1
  46. package/packages/modules/src/firebase/handle-module.ts +37 -9
  47. package/packages/passport/package.json +1 -1
  48. package/packages/ssr/lib/lib/cron-ssr-save-views.js +17 -5
  49. package/packages/ssr/lib/lib/cron-ssr-save-views.js.map +1 -1
  50. package/packages/ssr/package.json +3 -3
  51. package/packages/ssr/src/lib/cron-ssr-save-views.ts +17 -8
  52. package/packages/storefront/dist/client/_astro/AccountPage.3-eqV6OR.js +1 -0
  53. package/packages/storefront/dist/client/_astro/CartSidebar.-Gy6eqIy.js +1 -0
  54. package/packages/storefront/dist/client/_astro/HeroSlider.ju9TsLrJ.js +1 -0
  55. package/packages/storefront/dist/client/_astro/PitchBar.yqD9ycx5.js +1 -0
  56. package/packages/storefront/dist/client/_astro/Prices.xI1rdM1e.js +1 -0
  57. package/packages/storefront/dist/client/_astro/ProductDetails.ATGXfGhG.js +7 -0
  58. package/packages/storefront/dist/client/_astro/ProductShelf.b77WjhZZ.js +1 -0
  59. package/packages/storefront/dist/client/_astro/ProductShelf.qbTNzuvn.js +1 -0
  60. package/packages/storefront/dist/client/_astro/QuantitySelector.v7L8EYOR.js +1 -0
  61. package/packages/storefront/dist/client/_astro/SearchModal.WzDMBjqi.js +1 -0
  62. package/packages/storefront/dist/client/_astro/SearchShowcase.9gIA4Cq0.js +1 -0
  63. package/packages/storefront/dist/client/_astro/ShopHeader.Ee4OJr3q.js +7 -0
  64. package/packages/storefront/dist/client/_astro/{_plugin-vue_export-helper.SO-0jCqa.js → _plugin-vue_export-helper.xATGHWd9.js} +2 -2
  65. package/packages/storefront/dist/client/_astro/{_slug_.4W7qhV-L.css → _slug_.WkuZ8tvp.css} +1 -1
  66. package/packages/storefront/dist/client/_astro/afetch.OifQZgwR.js +1 -0
  67. package/packages/storefront/dist/client/_astro/client.YJ00ta5M.js +1 -0
  68. package/packages/storefront/dist/client/_astro/customer-session.dSYHWdP4.js +7 -0
  69. package/packages/storefront/dist/client/_astro/format-money.1_HtF5S2.js +1 -0
  70. package/packages/storefront/dist/client/_astro/grid-title.pK2Nn3i-.js +1 -0
  71. package/packages/storefront/dist/client/_astro/hoisted.d2SGwVMl.js +1 -0
  72. package/packages/storefront/dist/client/_astro/hoisted.x1b7VHef.js +1 -0
  73. package/packages/storefront/dist/client/_astro/hoisted.xTPkED8g.js +1 -0
  74. package/packages/storefront/dist/client/_astro/i18n.zhlBzJt8.js +1 -0
  75. package/packages/storefront/dist/client/_astro/img.AnjeGdy_.js +1 -0
  76. package/packages/storefront/dist/client/_astro/index.KfrHdfOH.js +1 -0
  77. package/packages/storefront/dist/client/_astro/index.ShNlAyu1.js +1 -0
  78. package/packages/storefront/dist/client/_astro/modules-info.HP6478mG.js +1 -0
  79. package/packages/storefront/dist/client/_astro/name.VA3MEpe0.js +1 -0
  80. package/packages/storefront/dist/client/_astro/server-data.4C60Esyt.js +1 -0
  81. package/packages/storefront/dist/client/_astro/sf-utils.c42cbZ9W.js +13 -0
  82. package/packages/storefront/dist/client/_astro/shopping-cart.v-dB3kHB.js +1 -0
  83. package/packages/storefront/dist/client/_astro/use-analytics._ef6TM4P.js +1 -0
  84. package/packages/storefront/dist/client/_astro/use-product-card.nNtSJVtB.js +1 -0
  85. package/packages/storefront/dist/client/_astro/use-text-value.0OP9HCfP.js +4 -0
  86. package/packages/storefront/dist/client/{~fallback/index.html → ~fallback.html} +5 -5
  87. package/packages/storefront/dist/client/{index.html → ~index.html} +7 -7
  88. package/packages/storefront/dist/server/_noop-middleware.mjs +3 -0
  89. package/packages/storefront/dist/server/chunks/{CartSidebar_yYIzwp_R.mjs → CartSidebar_blvgfFa-.mjs} +1 -1
  90. package/packages/storefront/dist/server/chunks/{SearchModal_GvRUZ6ce.mjs → SearchModal_Sktaq643.mjs} +1 -1
  91. package/packages/storefront/dist/server/chunks/_.._yTK2xBRC.mjs +5 -0
  92. package/packages/storefront/dist/server/chunks/_page__9PfWVh79.mjs +5 -0
  93. package/packages/storefront/dist/server/chunks/account_R4bpY7O1.mjs +5 -0
  94. package/packages/storefront/dist/server/chunks/astro/{assets-service_yXRChsFH.mjs → assets-service_oQ4-9MNg.mjs} +1 -1
  95. package/packages/storefront/dist/server/chunks/{astro_F4pl3toV.mjs → astro_ECsNQeA2.mjs} +18 -14
  96. package/packages/storefront/dist/server/chunks/index__PeYBuja.mjs +5 -0
  97. package/packages/storefront/dist/server/chunks/node_njrZIjT6.mjs +5 -0
  98. package/packages/storefront/dist/server/chunks/pages/{__z8Igc_-f.mjs → __XOsz50la.mjs} +994 -922
  99. package/packages/storefront/dist/server/chunks/pages/{_page__-V1Q-Ymk.mjs → _page__cIw_KTpN.mjs} +14 -12
  100. package/packages/storefront/dist/server/chunks/pages/{account_frSUn7gD.mjs → account_l-FHyDJd.mjs} +3 -2
  101. package/packages/storefront/dist/server/chunks/pages/{index_QqJiJpFy.mjs → index_KP7Gn0ld.mjs} +3 -2
  102. package/packages/storefront/dist/server/chunks/pages/{node_FoDIj_f7.mjs → node_FoLtkdH1.mjs} +4 -4
  103. package/packages/storefront/dist/server/chunks/pages/{~fallback_t0lNhRm9.mjs → ~fallback_KPp6Nh_p.mjs} +3 -2
  104. package/packages/storefront/dist/server/chunks/~fallback_p7P7NIL5.mjs +5 -0
  105. package/packages/storefront/dist/server/entry.mjs +289 -166
  106. package/packages/storefront/dist/server/manifest_E6KbHQrT.mjs +202 -0
  107. package/packages/storefront/dist/server/renderers.mjs +1 -1
  108. package/packages/storefront/dist/server/static-builds.csv +34 -34
  109. package/packages/storefront/package.json +3 -3
  110. package/packages/storefront/src/helpers/afetch.ts +22 -5
  111. package/packages/storefront/src/lib/composables/use-pagination.ts +1 -1
  112. package/packages/storefront/src/lib/composables/use-shipping-calculator.ts +273 -0
  113. package/packages/storefront/src/lib/scripts/git-cms-auth.ts +3 -0
  114. package/packages/storefront/src/lib/scripts/push-analytics-events.ts +7 -2
  115. package/packages/storefront/src/lib/scripts/sso-ecom.ts +0 -0
  116. package/packages/storefront/src/lib/ssr-context.ts +3 -1
  117. package/packages/storefront/src/lib/state/modules-info.ts +34 -10
  118. package/packages/test-base/package.json +1 -1
  119. package/packages/types/index.ts +82 -53
  120. package/packages/types/package.json +1 -1
  121. package/packages/storefront/dist/client/_astro/AccountPage.HcKW6HTE.js +0 -1
  122. package/packages/storefront/dist/client/_astro/CartSidebar.osvr0MUo.js +0 -1
  123. package/packages/storefront/dist/client/_astro/HeroSlider.I5mC8JdX.js +0 -1
  124. package/packages/storefront/dist/client/_astro/PitchBar.xC4J7MDy.js +0 -1
  125. package/packages/storefront/dist/client/_astro/Prices.Jt09rVKv.js +0 -1
  126. package/packages/storefront/dist/client/_astro/ProductDetails.oouZY3cL.js +0 -7
  127. package/packages/storefront/dist/client/_astro/ProductShelf.dYlXuNId.js +0 -1
  128. package/packages/storefront/dist/client/_astro/ProductShelf.vGE0E3Qf.js +0 -1
  129. package/packages/storefront/dist/client/_astro/QuantitySelector.OL4MN-C_.js +0 -1
  130. package/packages/storefront/dist/client/_astro/SearchModal.d8lbvLay.js +0 -1
  131. package/packages/storefront/dist/client/_astro/SearchShowcase.ynowXX4j.js +0 -1
  132. package/packages/storefront/dist/client/_astro/ShopHeader.l4KJGvUd.js +0 -7
  133. package/packages/storefront/dist/client/_astro/afetch.5c8VmT0-.js +0 -1
  134. package/packages/storefront/dist/client/_astro/client.ZhEmw4hZ.js +0 -1
  135. package/packages/storefront/dist/client/_astro/customer-session.TRPGDX3c.js +0 -7
  136. package/packages/storefront/dist/client/_astro/format-money.iK5LGydz.js +0 -1
  137. package/packages/storefront/dist/client/_astro/grid-title.vGKBy72g.js +0 -1
  138. package/packages/storefront/dist/client/_astro/hoisted.8pwSenCN.js +0 -1
  139. package/packages/storefront/dist/client/_astro/hoisted.SLwcAI01.js +0 -1
  140. package/packages/storefront/dist/client/_astro/hoisted.gqV7f6f3.js +0 -1
  141. package/packages/storefront/dist/client/_astro/i18n.Lxnz1oF-.js +0 -1
  142. package/packages/storefront/dist/client/_astro/img.WnsidxCx.js +0 -1
  143. package/packages/storefront/dist/client/_astro/index.R7A-Pg5V.js +0 -1
  144. package/packages/storefront/dist/client/_astro/index.q6KIyKlJ.js +0 -1
  145. package/packages/storefront/dist/client/_astro/modules-info.WWsUqEPZ.js +0 -1
  146. package/packages/storefront/dist/client/_astro/name.urFqJ5yn.js +0 -1
  147. package/packages/storefront/dist/client/_astro/runtime-core.esm-bundler.XTSAdOlw.js +0 -13
  148. package/packages/storefront/dist/client/_astro/sf-utils.luvTU5uS.js +0 -1
  149. package/packages/storefront/dist/client/_astro/shopping-cart.ATTXCPd0.js +0 -1
  150. package/packages/storefront/dist/client/_astro/use-analytics.WpkjGsWi.js +0 -1
  151. package/packages/storefront/dist/client/_astro/use-product-card.BhUXhJIp.js +0 -1
  152. package/packages/storefront/dist/client/_astro/use-text-value.XE_A2nDM.js +0 -4
  153. package/packages/storefront/dist/client/app/account/index.html +0 -58
  154. package/packages/storefront/dist/client/app/index.html +0 -98
  155. package/packages/storefront/dist/client/blog/1/index.html +0 -86
  156. package/packages/storefront/dist/client/macbook-apple-pro-15.4-intel-core-i7-2.6ghz-ram-16gb-ssd-512gb-mr972ll/a-prata/index.html +0 -93
  157. package/packages/storefront/dist/client/monitores-gamer/index.html +0 -95
  158. package/packages/storefront/dist/client/mouse-gamer-corsair-optico-harpoon-rgb-ch-9301011-na/index.html +0 -93
  159. package/packages/storefront/dist/client/p/contato/index.html +0 -90
  160. package/packages/storefront/dist/client/p/terms/index.html +0 -101
  161. package/packages/storefront/dist/client/posts/3/index.html +0 -101
  162. package/packages/storefront/dist/client/posts/4/index.html +0 -101
  163. package/packages/storefront/dist/server/_empty-middleware.mjs +0 -3
  164. package/packages/storefront/dist/server/chunks/_.._Lq3r7hpv.mjs +0 -6
  165. package/packages/storefront/dist/server/chunks/_page__LqbeNfr1.mjs +0 -6
  166. package/packages/storefront/dist/server/chunks/account_4n4rpirV.mjs +0 -6
  167. package/packages/storefront/dist/server/chunks/index_SwXtE1IM.mjs +0 -6
  168. package/packages/storefront/dist/server/chunks/node_Nzz44v5l.mjs +0 -6
  169. package/packages/storefront/dist/server/chunks/~fallback_EWqi0UyU.mjs +0 -6
  170. package/packages/storefront/dist/server/manifest_ZHJUD8_m.mjs +0 -196
@@ -0,0 +1,202 @@
1
+ import '@astrojs/internal-helpers/path';
2
+ import 'cookie';
3
+ import { bold, red, yellow, dim, blue } from 'kleur/colors';
4
+ import 'string-width';
5
+ import './chunks/astro_ECsNQeA2.mjs';
6
+ import 'clsx';
7
+ import 'cssesc';
8
+ import { compile } from 'path-to-regexp';
9
+
10
+ const dateTimeFormat = new Intl.DateTimeFormat([], {
11
+ hour: "2-digit",
12
+ minute: "2-digit",
13
+ second: "2-digit",
14
+ hour12: false
15
+ });
16
+ const levels = {
17
+ debug: 20,
18
+ info: 30,
19
+ warn: 40,
20
+ error: 50,
21
+ silent: 90
22
+ };
23
+ function log(opts, level, label, message, newLine = true) {
24
+ const logLevel = opts.level;
25
+ const dest = opts.dest;
26
+ const event = {
27
+ label,
28
+ level,
29
+ message,
30
+ newLine
31
+ };
32
+ if (!isLogLevelEnabled(logLevel, level)) {
33
+ return;
34
+ }
35
+ dest.write(event);
36
+ }
37
+ function isLogLevelEnabled(configuredLogLevel, level) {
38
+ return levels[configuredLogLevel] <= levels[level];
39
+ }
40
+ function info(opts, label, message, newLine = true) {
41
+ return log(opts, "info", label, message, newLine);
42
+ }
43
+ function warn(opts, label, message, newLine = true) {
44
+ return log(opts, "warn", label, message, newLine);
45
+ }
46
+ function error(opts, label, message, newLine = true) {
47
+ return log(opts, "error", label, message, newLine);
48
+ }
49
+ function debug(...args) {
50
+ if ("_astroGlobalDebug" in globalThis) {
51
+ globalThis._astroGlobalDebug(...args);
52
+ }
53
+ }
54
+ function getEventPrefix({ level, label }) {
55
+ const timestamp = `${dateTimeFormat.format(/* @__PURE__ */ new Date())}`;
56
+ const prefix = [];
57
+ if (level === "error" || level === "warn") {
58
+ prefix.push(bold(timestamp));
59
+ prefix.push(`[${level.toUpperCase()}]`);
60
+ } else {
61
+ prefix.push(timestamp);
62
+ }
63
+ if (label) {
64
+ prefix.push(`[${label}]`);
65
+ }
66
+ if (level === "error") {
67
+ return red(prefix.join(" "));
68
+ }
69
+ if (level === "warn") {
70
+ return yellow(prefix.join(" "));
71
+ }
72
+ if (prefix.length === 1) {
73
+ return dim(prefix[0]);
74
+ }
75
+ return dim(prefix[0]) + " " + blue(prefix.splice(1).join(" "));
76
+ }
77
+ if (typeof process !== "undefined") {
78
+ let proc = process;
79
+ if ("argv" in proc && Array.isArray(proc.argv)) {
80
+ if (proc.argv.includes("--verbose")) ; else if (proc.argv.includes("--silent")) ; else ;
81
+ }
82
+ }
83
+ class Logger {
84
+ options;
85
+ constructor(options) {
86
+ this.options = options;
87
+ }
88
+ info(label, message, newLine = true) {
89
+ info(this.options, label, message, newLine);
90
+ }
91
+ warn(label, message, newLine = true) {
92
+ warn(this.options, label, message, newLine);
93
+ }
94
+ error(label, message, newLine = true) {
95
+ error(this.options, label, message, newLine);
96
+ }
97
+ debug(label, ...messages) {
98
+ debug(label, ...messages);
99
+ }
100
+ level() {
101
+ return this.options.level;
102
+ }
103
+ forkIntegrationLogger(label) {
104
+ return new AstroIntegrationLogger(this.options, label);
105
+ }
106
+ }
107
+ class AstroIntegrationLogger {
108
+ options;
109
+ label;
110
+ constructor(logging, label) {
111
+ this.options = logging;
112
+ this.label = label;
113
+ }
114
+ /**
115
+ * Creates a new logger instance with a new label, but the same log options.
116
+ */
117
+ fork(label) {
118
+ return new AstroIntegrationLogger(this.options, label);
119
+ }
120
+ info(message) {
121
+ info(this.options, this.label, message);
122
+ }
123
+ warn(message) {
124
+ warn(this.options, this.label, message);
125
+ }
126
+ error(message) {
127
+ error(this.options, this.label, message);
128
+ }
129
+ debug(message) {
130
+ debug(this.label, message);
131
+ }
132
+ }
133
+
134
+ function getRouteGenerator(segments, addTrailingSlash) {
135
+ const template = segments.map((segment) => {
136
+ return "/" + segment.map((part) => {
137
+ if (part.spread) {
138
+ return `:${part.content.slice(3)}(.*)?`;
139
+ } else if (part.dynamic) {
140
+ return `:${part.content}`;
141
+ } else {
142
+ return part.content.normalize().replace(/\?/g, "%3F").replace(/#/g, "%23").replace(/%5B/g, "[").replace(/%5D/g, "]").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
143
+ }
144
+ }).join("");
145
+ }).join("");
146
+ let trailing = "";
147
+ if (addTrailingSlash === "always" && segments.length) {
148
+ trailing = "/";
149
+ }
150
+ const toPath = compile(template + trailing);
151
+ return toPath;
152
+ }
153
+
154
+ function deserializeRouteData(rawRouteData) {
155
+ return {
156
+ route: rawRouteData.route,
157
+ type: rawRouteData.type,
158
+ pattern: new RegExp(rawRouteData.pattern),
159
+ params: rawRouteData.params,
160
+ component: rawRouteData.component,
161
+ generate: getRouteGenerator(rawRouteData.segments, rawRouteData._meta.trailingSlash),
162
+ pathname: rawRouteData.pathname || void 0,
163
+ segments: rawRouteData.segments,
164
+ prerender: rawRouteData.prerender,
165
+ redirect: rawRouteData.redirect,
166
+ redirectRoute: rawRouteData.redirectRoute ? deserializeRouteData(rawRouteData.redirectRoute) : void 0,
167
+ fallbackRoutes: rawRouteData.fallbackRoutes.map((fallback) => {
168
+ return deserializeRouteData(fallback);
169
+ }),
170
+ isIndex: rawRouteData.isIndex
171
+ };
172
+ }
173
+
174
+ function deserializeManifest(serializedManifest) {
175
+ const routes = [];
176
+ for (const serializedRoute of serializedManifest.routes) {
177
+ routes.push({
178
+ ...serializedRoute,
179
+ routeData: deserializeRouteData(serializedRoute.routeData)
180
+ });
181
+ const route = serializedRoute;
182
+ route.routeData = deserializeRouteData(serializedRoute.routeData);
183
+ }
184
+ const assets = new Set(serializedManifest.assets);
185
+ const componentMetadata = new Map(serializedManifest.componentMetadata);
186
+ const clientDirectives = new Map(serializedManifest.clientDirectives);
187
+ return {
188
+ // in case user middleware exists, this no-op middleware will be reassigned (see plugin-ssr.ts)
189
+ middleware(_, next) {
190
+ return next();
191
+ },
192
+ ...serializedManifest,
193
+ assets,
194
+ componentMetadata,
195
+ clientDirectives,
196
+ routes
197
+ };
198
+ }
199
+
200
+ const manifest = deserializeManifest({"adapterName":"@astrojs/node","routes":[{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"type":"endpoint","isIndex":false,"route":"/_image","pattern":"^\\/_image$","segments":[[{"content":"_image","dynamic":false,"spread":false}]],"params":[],"component":"../../node_modules/.pnpm/astro@4.3.1_@types+node@18.19.10_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js","pathname":"/_image","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.x1b7VHef.js"}],"styles":[{"type":"external","src":"/_astro/_slug_.WkuZ8tvp.css"}],"routeData":{"route":"/~fallback","isIndex":false,"type":"page","pattern":"^\\/~fallback\\/?$","segments":[[{"content":"~fallback","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/~fallback.astro","pathname":"/~fallback","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.xTPkED8g.js"}],"styles":[{"type":"external","src":"/_astro/_slug_.WkuZ8tvp.css"}],"routeData":{"route":"/app","isIndex":true,"type":"page","pattern":"^\\/app\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/index.astro","pathname":"/app","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.d2SGwVMl.js"}],"styles":[{"type":"external","src":"/_astro/_slug_.WkuZ8tvp.css"}],"routeData":{"route":"/app/account","isIndex":false,"type":"page","pattern":"^\\/app\\/account\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}],[{"content":"account","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/account.astro","pathname":"/app/account","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.d2SGwVMl.js"}],"styles":[{"type":"external","src":"/_astro/_slug_.WkuZ8tvp.css"}],"routeData":{"route":"/blog/[page]","isIndex":false,"type":"page","pattern":"^\\/blog\\/([^/]+?)\\/?$","segments":[[{"content":"blog","dynamic":false,"spread":false}],[{"content":"page","dynamic":true,"spread":false}]],"params":["page"],"component":"src/pages/blog/[page].astro","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.d2SGwVMl.js"}],"styles":[{"type":"external","src":"/_astro/_slug_.WkuZ8tvp.css"}],"routeData":{"route":"/[...slug]","isIndex":false,"type":"page","pattern":"^(?:\\/(.*?))?\\/?$","segments":[[{"content":"...slug","dynamic":true,"spread":true}]],"params":["...slug"],"component":"src/pages/[...slug].astro","prerender":false,"fallbackRoutes":[],"_meta":{"trailingSlash":"ignore"}}}],"site":"https://demo.ecomplus.app","base":"/","trailingSlash":"ignore","compressHTML":true,"componentMetadata":[["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/lib/layouts/BaseHead.astro",{"propagation":"in-tree","containsHead":false}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/[...slug].astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astro-page:src/pages/[...slug]@_@astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astrojs-ssr-virtual-entry",{"propagation":"in-tree","containsHead":false}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/app/account.astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astro-page:src/pages/app/account@_@astro",{"propagation":"in-tree","containsHead":false}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/app/index.astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astro-page:src/pages/app/index@_@astro",{"propagation":"in-tree","containsHead":false}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/blog/[page].astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astro-page:src/pages/blog/[page]@_@astro",{"propagation":"in-tree","containsHead":false}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/~fallback.astro",{"propagation":"in-tree","containsHead":false}],["\u0000@astro-page:src/pages/~fallback@_@astro",{"propagation":"in-tree","containsHead":false}]],"renderers":[],"clientDirectives":[["idle","(()=>{var i=t=>{let e=async()=>{await(await t())()};\"requestIdleCallback\"in window?window.requestIdleCallback(e):setTimeout(e,200)};(self.Astro||(self.Astro={})).idle=i;window.dispatchEvent(new Event(\"astro:idle\"));})();"],["load","(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).load=e;window.dispatchEvent(new Event(\"astro:load\"));})();"],["media","(()=>{var s=(i,t)=>{let a=async()=>{await(await i())()};if(t.value){let e=matchMedia(t.value);e.matches?a():e.addEventListener(\"change\",a,{once:!0})}};(self.Astro||(self.Astro={})).media=s;window.dispatchEvent(new Event(\"astro:media\"));})();"],["only","(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).only=e;window.dispatchEvent(new Event(\"astro:only\"));})();"],["visible","(()=>{var l=(s,i,o)=>{let r=async()=>{await(await s())()},t=typeof i.value==\"object\"?i.value:void 0,c={rootMargin:t==null?void 0:t.rootMargin},n=new IntersectionObserver(e=>{for(let a of e)if(a.isIntersecting){n.disconnect(),r();break}},c);for(let e of o.children)n.observe(e)};(self.Astro||(self.Astro={})).visible=l;window.dispatchEvent(new Event(\"astro:visible\"));})();"],["context","(()=>{var a=(s,o)=>{let n=async()=>{await(await s())()},r=()=>{let t=Array.isArray(o.value)?o.value:[o.value];for(let e=0;e<t.length;e++)if(typeof t[e]==\"string\"&&t[e].startsWith(\"data:\")){let d=t[e].substring(5);if(!window.$storefront?.data?.[d]){window.addEventListener(`storefront:data:${d}`,r,{once:!0});return}}if(t.includes(\"idle\")){if(typeof window.requestIdleCallback==\"function\"){setTimeout(()=>window.requestIdleCallback(n),9);return}setTimeout(n,200);return}n()},i=window.$storefront?.apiContext?.doc._id||null;if(window._firstLoadContextId===i&&window._emitedContextId===i){console.log(\"[ctx] first load\"),r(),document.addEventListener(\"astro:beforeload\",()=>{delete window._firstLoadContextId},{once:!0});return}window.addEventListener(\"storefront:apiContext\",r,{once:!0})};(self.Astro||(self.Astro={})).context=a;window.dispatchEvent(new Event(\"astro:context\"));})();\n"]],"entryModules":{"\u0000@astrojs-ssr-virtual-entry":"entry.mjs","\u0000@astro-renderers":"renderers.mjs","\u0000noop-middleware":"_noop-middleware.mjs","/src/pages/blog/[page].astro":"chunks/pages/_page__cIw_KTpN.mjs","/src/pages/app/account.astro":"chunks/pages/account_l-FHyDJd.mjs","/src/pages/app/index.astro":"chunks/pages/index_KP7Gn0ld.mjs","/../../node_modules/.pnpm/astro@4.3.1_@types+node@18.19.10_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node.js":"chunks/pages/node_FoLtkdH1.mjs","/src/pages/~fallback.astro":"chunks/pages/~fallback_KPp6Nh_p.mjs","\u0000@astrojs-manifest":"manifest_E6KbHQrT.mjs","\u0000@astro-page:../../node_modules/.pnpm/astro@4.3.1_@types+node@18.19.10_typescript@5.2.2/node_modules/astro/dist/assets/endpoint/node@_@js":"chunks/node_njrZIjT6.mjs","\u0000@astro-page:src/pages/~fallback@_@astro":"chunks/~fallback_p7P7NIL5.mjs","\u0000@astro-page:src/pages/app/index@_@astro":"chunks/index__PeYBuja.mjs","\u0000@astro-page:src/pages/app/account@_@astro":"chunks/account_R4bpY7O1.mjs","\u0000@astro-page:src/pages/blog/[page]@_@astro":"chunks/_page__9PfWVh79.mjs","\u0000@astro-page:src/pages/[...slug]@_@astro":"chunks/_.._yTK2xBRC.mjs","/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/components/SearchModal.vue":"_astro/SearchModal.WzDMBjqi.js","/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/components/CartSidebar.vue":"_astro/CartSidebar.-Gy6eqIy.js","/home/leo/code/ecomplus/cloud-commerce/node_modules/photoswipe/dist/photoswipe.css?inline":"_astro/photoswipe.0V7m2jWu.js","/astro/hoisted.js?q=1":"_astro/hoisted.x1b7VHef.js","~/components/AccountPage.vue":"_astro/AccountPage.3-eqV6OR.js","~/components/HeroSlider.vue":"_astro/HeroSlider.ju9TsLrJ.js","/astro/hoisted.js?q=0":"_astro/hoisted.xTPkED8g.js","/home/leo/code/ecomplus/cloud-commerce/node_modules/photoswipe/dist/photoswipe-lightbox.esm.js":"_astro/photoswipe-lightbox.esm.dZBqKD9u.js","~/components/PitchBar.vue":"_astro/PitchBar.yqD9ycx5.js","/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/lib/scripts/firebase-app.ts":"_astro/firebase-app.VduCDgof.js","~/components/ProductShelf.vue":"_astro/ProductShelf.b77WjhZZ.js","/astro/hoisted.js?q=2":"_astro/hoisted.d2SGwVMl.js","/home/leo/code/ecomplus/cloud-commerce/node_modules/photoswipe/dist/photoswipe.esm.js":"_astro/photoswipe.esm.Ylh9TGkz.js","~/components/ProductDetails.vue":"_astro/ProductDetails.ATGXfGhG.js","~/components/ShopHeader.vue":"_astro/ShopHeader.Ee4OJr3q.js","@astrojs/vue/client.js":"_astro/client.YJ00ta5M.js","~/components/SearchShowcase.vue":"_astro/SearchShowcase.9gIA4Cq0.js","astro:scripts/before-hydration.js":""},"assets":["/_astro/_slug_.WkuZ8tvp.css","/robots.txt","/_astro/AccountPage.3-eqV6OR.js","/_astro/CartSidebar.-Gy6eqIy.js","/_astro/HeroSlider.ju9TsLrJ.js","/_astro/PitchBar.yqD9ycx5.js","/_astro/Prices.xI1rdM1e.js","/_astro/ProductDetails.ATGXfGhG.js","/_astro/ProductShelf.b77WjhZZ.js","/_astro/ProductShelf.qbTNzuvn.js","/_astro/QuantitySelector.v7L8EYOR.js","/_astro/SearchModal.WzDMBjqi.js","/_astro/SearchShowcase.9gIA4Cq0.js","/_astro/ShopHeader.Ee4OJr3q.js","/_astro/_plugin-vue_export-helper.xATGHWd9.js","/_astro/afetch.OifQZgwR.js","/_astro/client.YJ00ta5M.js","/_astro/customer-session.dSYHWdP4.js","/_astro/firebase-app.VduCDgof.js","/_astro/format-money.1_HtF5S2.js","/_astro/grid-title.pK2Nn3i-.js","/_astro/hoisted.d2SGwVMl.js","/_astro/hoisted.x1b7VHef.js","/_astro/hoisted.xTPkED8g.js","/_astro/i18n.zhlBzJt8.js","/_astro/img-sizes.gxAI9JNh.js","/_astro/img.AnjeGdy_.js","/_astro/index-dd468b12.fl8bpn8l.js","/_astro/index.KfrHdfOH.js","/_astro/index.ShNlAyu1.js","/_astro/modules-info.HP6478mG.js","/_astro/name.VA3MEpe0.js","/_astro/photoswipe-lightbox.esm.dZBqKD9u.js","/_astro/photoswipe.0V7m2jWu.js","/_astro/photoswipe.esm.Ylh9TGkz.js","/_astro/price.Easct8WC.js","/_astro/server-data.4C60Esyt.js","/_astro/sf-utils.c42cbZ9W.js","/_astro/shopping-cart.v-dB3kHB.js","/_astro/use-analytics._ef6TM4P.js","/_astro/use-product-card.nNtSJVtB.js","/_astro/use-text-value.0OP9HCfP.js","/img/icon.png","/img/large-icon.png","/img/uploads/banner2.webp","/img/uploads/ecom-icon.png","/img/uploads/headphone.webp","/img/uploads/logo.png","/img/uploads/og-image.png","/img/uploads/passion.webp","/img/uploads/rect8589.png","/img/uploads/rect859.png","/img/uploads/rect89.webp"],"buildFormat":"directory"});
201
+
202
+ export { AstroIntegrationLogger as A, Logger as L, getEventPrefix as g, levels as l, manifest };
@@ -1,6 +1,6 @@
1
1
  import { defineComponent, h, createSSRApp } from 'vue';
2
2
  import { renderToString } from 'vue/server-renderer';
3
- import { m as mod, n as createApp } from './chunks/pages/__z8Igc_-f.mjs';
3
+ import { m as mod, n as createApp } from './chunks/pages/__XOsz50la.mjs';
4
4
 
5
5
  const setup = async (app) => {
6
6
  if ('default' in mod) {
@@ -1,44 +1,44 @@
1
- /_astro/AccountPage.89hLh9p2.js
2
- /_astro/afetch.5c8VmT0-.js
3
- /_astro/CartSidebar.G25ZUnKP.js
4
- /_astro/client.ZhEmw4hZ.js
5
- /_astro/customer-session.AcETMuhI.js
1
+ /_astro/AccountPage.3-eqV6OR.js
2
+ /_astro/afetch.OifQZgwR.js
3
+ /_astro/CartSidebar.-Gy6eqIy.js
4
+ /_astro/client.YJ00ta5M.js
5
+ /_astro/customer-session.dSYHWdP4.js
6
6
  /_astro/ecom-icon_12falx.png
7
7
  /_astro/ecom-icon_15pqnO.png
8
8
  /_astro/ecom-icon_t3guw.png
9
9
  /_astro/firebase-app.VduCDgof.js
10
- /_astro/format-money.iK5LGydz.js
11
- /_astro/grid-title.vGKBy72g.js
10
+ /_astro/format-money.1_HtF5S2.js
11
+ /_astro/grid-title.pK2Nn3i-.js
12
12
  /_astro/headphone_T2Jjc.avif
13
13
  /_astro/headphone_Z1CG18r.webp
14
- /_astro/HeroSlider.XZb2xsyV.js
15
- /_astro/hoisted.PxLuJZKI.js
16
- /_astro/hoisted.WBjTfX6e.js
17
- /_astro/hoisted.Wi6YpdWJ.js
18
- /_astro/i18n.Lxnz1oF-.js
14
+ /_astro/HeroSlider.ju9TsLrJ.js
15
+ /_astro/hoisted.d2SGwVMl.js
16
+ /_astro/hoisted.x1b7VHef.js
17
+ /_astro/hoisted.xTPkED8g.js
18
+ /_astro/i18n.zhlBzJt8.js
19
+ /_astro/img.AnjeGdy_.js
19
20
  /_astro/img-sizes.gxAI9JNh.js
20
- /_astro/img.WnsidxCx.js
21
21
  /_astro/index-dd468b12.fl8bpn8l.js
22
- /_astro/index.q6KIyKlJ.js
23
- /_astro/index.R7A-Pg5V.js
22
+ /_astro/index.KfrHdfOH.js
23
+ /_astro/index.ShNlAyu1.js
24
24
  /_astro/logo_1UBsBq.webp
25
25
  /_astro/logo_Z1K5PE9.png
26
26
  /_astro/logo_Z1KIIl1.avif
27
- /_astro/modules-info.tVRhvxNm.js
28
- /_astro/name.urFqJ5yn.js
27
+ /_astro/modules-info.HP6478mG.js
28
+ /_astro/name.VA3MEpe0.js
29
29
  /_astro/passion_LHbe9.webp
30
30
  /_astro/passion_Z23MeUb.avif
31
31
  /_astro/photoswipe.0V7m2jWu.js
32
32
  /_astro/photoswipe.esm.Ylh9TGkz.js
33
33
  /_astro/photoswipe-lightbox.esm.dZBqKD9u.js
34
- /_astro/PitchBar.Nr7T3S3T.js
35
- /_astro/_plugin-vue_export-helper.SO-0jCqa.js
34
+ /_astro/PitchBar.yqD9ycx5.js
35
+ /_astro/_plugin-vue_export-helper.xATGHWd9.js
36
36
  /_astro/price.Easct8WC.js
37
- /_astro/Prices.Ye-m2HTo.js
38
- /_astro/ProductDetails.ntFWLjla.js
39
- /_astro/ProductShelf.PPitdYxI.js
40
- /_astro/ProductShelf.xSxmHkTe.js
41
- /_astro/QuantitySelector.tumfWDjC.js
37
+ /_astro/Prices.xI1rdM1e.js
38
+ /_astro/ProductDetails.ATGXfGhG.js
39
+ /_astro/ProductShelf.b77WjhZZ.js
40
+ /_astro/ProductShelf.qbTNzuvn.js
41
+ /_astro/QuantitySelector.v7L8EYOR.js
42
42
  /_astro/rect8589_1f5opX.webp
43
43
  /_astro/rect8589_1TtOHY.png
44
44
  /_astro/rect8589_IUskt.webp
@@ -59,13 +59,13 @@
59
59
  /_astro/rect859_ZkpPFI.webp
60
60
  /_astro/rect89_1TSfW7.avif
61
61
  /_astro/rect89_Z1re32x.webp
62
- /_astro/runtime-core.esm-bundler.XTSAdOlw.js
63
- /_astro/SearchModal.R55jFaBZ.js
64
- /_astro/SearchShowcase.I1PPFu_n.js
65
- /_astro/sf-utils.Z4H-dRBJ.js
66
- /_astro/ShopHeader.OLf0l4Ot.js
67
- /_astro/shopping-cart.dJsZkyuD.js
68
- /_astro/_slug_.Hc-dqhcW.css
69
- /_astro/use-analytics.uqK_2k_k.js
70
- /_astro/use-product-card.WRVLjenR.js
71
- /_astro/use-text-value.XE_A2nDM.js
62
+ /_astro/SearchModal.WzDMBjqi.js
63
+ /_astro/SearchShowcase.9gIA4Cq0.js
64
+ /_astro/server-data.4C60Esyt.js
65
+ /_astro/sf-utils.c42cbZ9W.js
66
+ /_astro/ShopHeader.Ee4OJr3q.js
67
+ /_astro/shopping-cart.v-dB3kHB.js
68
+ /_astro/_slug_.WkuZ8tvp.css
69
+ /_astro/use-analytics._ef6TM4P.js
70
+ /_astro/use-product-card.nNtSJVtB.js
71
+ /_astro/use-text-value.0OP9HCfP.js
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/storefront",
3
3
  "type": "module",
4
- "version": "2.2.3",
4
+ "version": "2.3.1",
5
5
  "description": "E-Com Plus Cloud Commerce storefront with Astro",
6
6
  "bin": {
7
7
  "storefront": "./scripts/build-prod.sh"
@@ -30,7 +30,7 @@
30
30
  "lint:fix": "eslint -c ../eslint/storefront.staged.eslintrc.cjs src/lib/**/*.{ts,vue,astro} --fix"
31
31
  },
32
32
  "dependencies": {
33
- "@astrojs/node": "8.1.0",
33
+ "@astrojs/node": "8.2.0",
34
34
  "@astrojs/vue": "4.0.8",
35
35
  "@cloudcommerce/api": "workspace:*",
36
36
  "@cloudcommerce/config": "workspace:*",
@@ -43,7 +43,7 @@
43
43
  "@types/gtag.js": "^0.0.18",
44
44
  "@vite-pwa/astro": "^0.2.0",
45
45
  "@vueuse/core": "10.7.2",
46
- "astro": "4.2.7",
46
+ "astro": "4.3.1",
47
47
  "astro-capo": "^0.0.1",
48
48
  "chroma-js": "^2.4.2",
49
49
  "dotenv": "^16.4.1",
@@ -1,12 +1,12 @@
1
1
  type FetchParams = Parameters<typeof fetch>;
2
2
  type RequestInit = Exclude<FetchParams[1], undefined>;
3
3
  type BodyInit = RequestInit['body'] | Record<string, any> | Array<any>;
4
+ type AFetchInit = Omit<RequestInit, 'body'> & {
5
+ body?: BodyInit,
6
+ params?: Record<string, string | number | (string | number)[]>,
7
+ };
4
8
 
5
- const afetch = (
6
- url: FetchParams[0],
7
- init?: Omit<RequestInit, 'body'> & { body?: BodyInit },
8
- timeout = 10000,
9
- ) => {
9
+ const afetch = (url: FetchParams[0], init?: AFetchInit, timeout = 10000) => {
10
10
  let abortController: AbortController | undefined;
11
11
  let timer: NodeJS.Timeout | undefined;
12
12
  if (timeout) {
@@ -28,6 +28,23 @@ const afetch = (
28
28
  body = init.body;
29
29
  }
30
30
  }
31
+ if (init?.params && typeof url === 'string') {
32
+ let query = '';
33
+ Object.keys(init.params).forEach((key) => {
34
+ const value: string | number | (string | number)[] = init.params![key];
35
+ if (Array.isArray(value)) {
36
+ value.forEach((val) => {
37
+ query += `&${key}=${val}`;
38
+ });
39
+ return;
40
+ }
41
+ query += `&${key}=${value}`;
42
+ });
43
+ if (query) {
44
+ if (!url.includes('?')) url += `?${query.slice(1)}`;
45
+ else url += query;
46
+ }
47
+ }
31
48
  const promise = fetch(url, {
32
49
  ...init,
33
50
  body,
@@ -56,7 +56,7 @@ const usePagination = (props: Props) => {
56
56
  });
57
57
 
58
58
  const baseUrl = ref('');
59
- watch(toRef(props.isUrlPath), () => {
59
+ watch(toRef(props, 'isUrlPath'), () => {
60
60
  const url = import.meta.env.SSR
61
61
  ? global.astroUrl
62
62
  : new URL(window.location.toString());
@@ -0,0 +1,273 @@
1
+ import type { Ref } from 'vue';
2
+ import type {
3
+ Products,
4
+ Carts,
5
+ CalculateShippingParams,
6
+ CalculateShippingResponse,
7
+ ModuleApiResult,
8
+ } from '@cloudcommerce/types';
9
+ import {
10
+ ref,
11
+ computed,
12
+ shallowReactive,
13
+ watch,
14
+ toRef,
15
+ } from 'vue';
16
+ import { useDebounceFn, watchOnce } from '@vueuse/core';
17
+ import { price as getPrice } from '@ecomplus/utils';
18
+ import config from '@cloudcommerce/config';
19
+ import { fetchModule } from '@@sf/state/modules-info';
20
+
21
+ export type ShippedItem = Exclude<CalculateShippingParams['items'], undefined>[0];
22
+
23
+ export type ShippingService = CalculateShippingResponse['shipping_services'][0];
24
+
25
+ type CartOrProductItem = Carts['items'][0] | (Partial<Products> & {
26
+ product_id: string & { length: 24 },
27
+ price: number,
28
+ quantity: number,
29
+ });
30
+
31
+ export interface Props {
32
+ zipInput?: Ref<HTMLInputElement | null>;
33
+ zipCode?: string;
34
+ canSelectService?: boolean;
35
+ countryCode?: string;
36
+ shippedItems?: (ShippedItem | CartOrProductItem)[];
37
+ shippingResult?: ModuleApiResult<'calculate_shipping'>['result'];
38
+ baseParams?: Partial<CalculateShippingParams>;
39
+ skippedAppIds?: number[];
40
+ appIdsOrder?: number[];
41
+ }
42
+
43
+ const localStorage = typeof window === 'object' && window.localStorage;
44
+
45
+ export const ZIP_STORAGE_KEY = 'shipping-to-zip';
46
+
47
+ const sortApps = (results: any, order: number[]) => {
48
+ return results.sort((a: any, b: any) => {
49
+ if (a.app_id === b.app_id) {
50
+ return 0;
51
+ }
52
+ const indexA = order.indexOf(a.app_id);
53
+ const indexB = order.indexOf(b.app_id);
54
+ if (indexA > -1) {
55
+ if (indexB > -1) {
56
+ return indexA < indexB ? -1 : 1;
57
+ }
58
+ return -1;
59
+ }
60
+ if (indexB > -1) return 1;
61
+ return 0;
62
+ });
63
+ };
64
+ const reduceItemBody = (itemOrProduct: Record<string, any>) => {
65
+ const shippedItem = {};
66
+ const fields: (keyof ShippedItem)[] = [
67
+ 'product_id',
68
+ 'variation_id',
69
+ 'sku',
70
+ 'name',
71
+ 'quantity',
72
+ 'inventory',
73
+ 'currency_id',
74
+ 'currency_symbol',
75
+ 'price',
76
+ 'final_price',
77
+ 'dimensions',
78
+ 'weight',
79
+ ];
80
+ fields.forEach((field) => {
81
+ if (itemOrProduct[field] !== undefined) {
82
+ shippedItem[field] = itemOrProduct[field];
83
+ }
84
+ });
85
+ return shippedItem as ShippedItem;
86
+ };
87
+
88
+ export const useShippingCalculator = (props: Props) => {
89
+ const localZipCode = ref(props.zipCode);
90
+ const zipCode = ref<string | null>(null);
91
+ if (!localZipCode.value && localStorage) {
92
+ const storedZip = localStorage.getItem(ZIP_STORAGE_KEY);
93
+ if (storedZip) {
94
+ localZipCode.value = storedZip;
95
+ }
96
+ }
97
+ const countryCode = props.countryCode || config.get().countryCode;
98
+ const _shippedItems = toRef(props, 'shippedItems');
99
+ const shippedItems = computed(() => {
100
+ return _shippedItems.value?.map(reduceItemBody) || [];
101
+ });
102
+ const amountSubtotal = computed(() => {
103
+ return shippedItems.value.reduce((subtotal, item) => {
104
+ return subtotal + getPrice(item) * item.quantity;
105
+ }, 0);
106
+ });
107
+
108
+ const isFetching = ref(false);
109
+ const fetchShippingServices = useDebounceFn((isRetry?: boolean) => {
110
+ if (isFetching.value) {
111
+ watchOnce((isFetching), (_isFetching) => {
112
+ if (!_isFetching) fetchShippingServices();
113
+ });
114
+ return;
115
+ }
116
+ const body: CalculateShippingParams = {
117
+ ...props.baseParams,
118
+ to: {
119
+ ...props.baseParams?.to,
120
+ zip: localZipCode.value!,
121
+ },
122
+ };
123
+ if (shippedItems.value.length) {
124
+ body.items = shippedItems.value;
125
+ body.subtotal = amountSubtotal.value;
126
+ }
127
+ isFetching.value = true;
128
+ fetchModule('calculate_shipping', {
129
+ method: 'POST',
130
+ params: {
131
+ skip_ids: props.skippedAppIds,
132
+ },
133
+ body,
134
+ })
135
+ .then(async (response) => {
136
+ const data = await response.json();
137
+ // eslint-disable-next-line no-use-before-define
138
+ parseShippingResult(data.result, isRetry);
139
+ })
140
+ .catch((err) => {
141
+ if (!isRetry) {
142
+ // eslint-disable-next-line no-use-before-define
143
+ scheduleRetry(4000);
144
+ }
145
+ console.error(err);
146
+ })
147
+ .finally(() => {
148
+ isFetching.value = false;
149
+ });
150
+ }, 100);
151
+ let retryTimer: NodeJS.Timeout | null = null;
152
+ const scheduleRetry = (timeout = 10000) => {
153
+ if (retryTimer) clearTimeout(retryTimer);
154
+ retryTimer = setTimeout(() => {
155
+ fetchShippingServices(true);
156
+ }, timeout);
157
+ };
158
+
159
+ const shippingServices = shallowReactive<(ShippingService & { app_id: number })[]>([]);
160
+ const freeFromValue = ref<number | null>(null);
161
+ const hasPaidOption = ref<boolean | undefined>();
162
+ const parseShippingResult = (
163
+ shippingResult: ModuleApiResult<'calculate_shipping'>['result'] = [],
164
+ isRetry = false,
165
+ ) => {
166
+ freeFromValue.value = null;
167
+ shippingServices.splice(0);
168
+ if (shippingResult.length) {
169
+ let hasSomeFailedApp = false;
170
+ shippingResult.forEach((appResult) => {
171
+ const { validated, error, response } = appResult;
172
+ if (!validated || error) {
173
+ hasSomeFailedApp = true;
174
+ return;
175
+ }
176
+ if (props.skippedAppIds?.includes(appResult.app_id)) {
177
+ return;
178
+ }
179
+ response.shipping_services.forEach((service) => {
180
+ shippingServices.push({
181
+ app_id: appResult.app_id,
182
+ ...service,
183
+ });
184
+ });
185
+ const freeShippingFromValue = response.free_shipping_from_value;
186
+ if (
187
+ freeShippingFromValue
188
+ && (!freeFromValue.value || freeFromValue.value > freeShippingFromValue)
189
+ ) {
190
+ freeFromValue.value = freeShippingFromValue;
191
+ }
192
+ });
193
+ if (!shippingServices.length) {
194
+ if (hasSomeFailedApp) {
195
+ if (!isRetry) {
196
+ fetchShippingServices(true);
197
+ } else {
198
+ scheduleRetry();
199
+ }
200
+ }
201
+ return;
202
+ }
203
+ shippingServices.sort((a, b) => {
204
+ const lineA = a.shipping_line;
205
+ const lineB = b.shipping_line;
206
+ const priceDiff = lineA.total_price! - lineB.total_price!;
207
+ if (priceDiff < 0) return -1;
208
+ if (priceDiff > 0) return 1;
209
+ return lineA.delivery_time?.days! < lineB.delivery_time?.days!
210
+ ? -1 : 1;
211
+ });
212
+ hasPaidOption.value = Boolean(shippingServices.find((service) => {
213
+ return service.shipping_line.total_price || service.shipping_line.price;
214
+ }));
215
+ const appIdsOrder = props.appIdsOrder || globalThis.ecomShippingApps || [];
216
+ if (Array.isArray(appIdsOrder) && appIdsOrder.length) {
217
+ sortApps(shippingServices, appIdsOrder);
218
+ }
219
+ }
220
+ };
221
+
222
+ const submitZipCode = () => {
223
+ const _zipCode = localZipCode.value;
224
+ if (countryCode === 'BR') {
225
+ if (_zipCode?.replace(/\D/g, '').length !== 8) return;
226
+ } else if (!_zipCode) {
227
+ return;
228
+ }
229
+ zipCode.value = _zipCode;
230
+ if (localStorage) {
231
+ localStorage.setItem(ZIP_STORAGE_KEY, zipCode.value);
232
+ }
233
+ fetchShippingServices();
234
+ };
235
+ watch(localZipCode, submitZipCode, {
236
+ immediate: !props.shippingResult,
237
+ });
238
+ watch(toRef(props, 'shippingResult'), (shippingResult) => {
239
+ if (!shippingResult?.length) return;
240
+ if (localZipCode.value) zipCode.value = localZipCode.value;
241
+ parseShippingResult(shippingResult);
242
+ }, {
243
+ immediate: true,
244
+ });
245
+ const zipInput = props.zipInput?.value;
246
+ if (zipInput) {
247
+ zipInput.addEventListener('input', (ev) => {
248
+ const value = (ev.target as HTMLInputElement).value;
249
+ if (value.length) {
250
+ if (countryCode === 'BR') {
251
+ const fmt = value.replace(/\D/g, '').padEnd(8, '_');
252
+ zipInput.innerHTML = fmt.substring(0, 5) + '-' + fmt.substring(5, 8);
253
+ } else {
254
+ zipInput.innerHTML = value.substring(0, 30);
255
+ }
256
+ }
257
+ localZipCode.value = value;
258
+ });
259
+ }
260
+
261
+ return {
262
+ zipCode,
263
+ shippedItems,
264
+ amountSubtotal,
265
+ submitZipCode,
266
+ fetchShippingServices,
267
+ freeFromValue,
268
+ shippingServices,
269
+ parseShippingResult,
270
+ };
271
+ };
272
+
273
+ export default useShippingCalculator;