cloudcommerce 2.8.7 → 2.9.0

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 (63) hide show
  1. package/.github/workflows/test-apps.yml +2 -2
  2. package/CHANGELOG.md +21 -0
  3. package/action.yml +2 -2
  4. package/ecomplus-stores/barradoce/functions/many/package.json +3 -3
  5. package/ecomplus-stores/barradoce/functions/ssr/package.json +6 -6
  6. package/ecomplus-stores/barradoce/functions/with-apps/package.json +3 -3
  7. package/ecomplus-stores/barradoce/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/lib/cli.js +3 -3
  34. package/packages/cli/package.json +1 -1
  35. package/packages/cli/src/cli.ts +3 -3
  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/package.json +1 -1
  44. package/packages/passport/package.json +1 -1
  45. package/packages/ssr/lib/lib/serve-storefront.js +1 -1
  46. package/packages/ssr/lib/lib/serve-storefront.js.map +1 -1
  47. package/packages/ssr/package.json +1 -1
  48. package/packages/ssr/src/lib/serve-storefront.ts +1 -1
  49. package/packages/storefront/astro.config.mjs +6 -9
  50. package/packages/storefront/client.d.ts +2 -1
  51. package/packages/storefront/config/astro/client-sf-directive.mjs +2 -3
  52. package/packages/storefront/config/astro/node-middleware.mjs +8 -0
  53. package/packages/storefront/package.json +1 -1
  54. package/packages/storefront/src/lib/components/globals/ALink.vue +20 -10
  55. package/packages/storefront/src/lib/composables/use-sku-selector.ts +1 -1
  56. package/packages/storefront/src/lib/layouts/Base.astro +5 -0
  57. package/packages/storefront/src/lib/layouts/BaseHead.astro +1 -6
  58. package/packages/storefront/src/lib/ssr-context.ts +7 -4
  59. package/packages/storefront/src/lib/state/use-analytics.ts +0 -1
  60. package/packages/test-base/package.json +1 -1
  61. package/packages/types/package.json +1 -1
  62. package/packages/storefront/config/astro/vue-server.mjs +0 -64
  63. package/packages/storefront/src/lib/components/ViewTransitions.astro +0 -426
@@ -304,7 +304,7 @@ export default async (req: Request, res: Response) => {
304
304
  }
305
305
  if (headers && BUNNYNET_API_KEY && DEPLOY_RAND) {
306
306
  // Tag for CDN cache purge
307
- headers['CDN-Tag'] = `-d:${DEPLOY_RAND}-`;
307
+ headers['CDN-Tag'] = `[${DEPLOY_RAND}]`;
308
308
  }
309
309
  _writeHead.apply(res, [status, headers]);
310
310
  };
@@ -146,10 +146,7 @@ const _vitePWAOptions = {
146
146
  },
147
147
  };
148
148
 
149
- const viteAlias = [{
150
- find: '@astrojs/vue/server.js',
151
- replacement: joinPath(__dirname, 'config/astro/vue-server.mjs'),
152
- }];
149
+ const viteAlias = [];
153
150
  if (isToServerless) {
154
151
  viteAlias.push({
155
152
  find: '@@sf/components/Picture.astro',
@@ -196,15 +193,15 @@ const genAstroConfig = ({
196
193
  {
197
194
  name: 'client:context',
198
195
  hooks: {
199
- 'astro:config:setup': ({ addClientDirective }) => {
200
- addClientDirective({
201
- name: 'context',
202
- entrypoint: joinPath(__dirname, 'config/astro/client-sf-directive.mjs'),
203
- });
196
+ 'astro:config:setup': ({ addClientDirective, addMiddleware }) => {
204
197
  addClientDirective({
205
198
  name: 'sf',
206
199
  entrypoint: joinPath(__dirname, 'config/astro/client-sf-directive.mjs'),
207
200
  });
201
+ addMiddleware({
202
+ entrypoint: joinPath(__dirname, 'config/astro/node-middleware.mjs'),
203
+ order: 'pre',
204
+ });
208
205
  },
209
206
  },
210
207
  },
@@ -37,8 +37,9 @@ interface Window {
37
37
  $storefront?: import('@@sf/$storefront').$Storefront & {
38
38
  modulesInfoPreset?: Partial<typeof import('./src/lib/state/modules-info').default>,
39
39
  };
40
- $isCmsPreview?: boolean;
40
+ $firstInteraction?: Promise<void>;
41
41
  $prefetch?: typeof import('astro:prefetch').prefetch;
42
+ $isCmsPreview?: boolean;
42
43
  }
43
44
 
44
45
  declare module 'gtag.js';
@@ -28,11 +28,13 @@ const firstInteraction = new Promise((resolve) => {
28
28
  () => {
29
29
  resolve();
30
30
  controller.abort();
31
+ window.dispatchEvent(new Event('firstInteraction'));
31
32
  },
32
33
  { once: true, passive: true, signal: controller.signal },
33
34
  );
34
35
  });
35
36
  });
37
+ window.$firstInteraction = firstInteraction;
36
38
 
37
39
  /**
38
40
  * Hydrate on context script executed (`$storefront.apiContext` ready)
@@ -88,9 +90,6 @@ export default (load, opts, el) => {
88
90
  const id = window.$storefront?.apiContext?.doc._id || null;
89
91
  if (window._firstLoadContextId === id && window._emitedContextId === id) {
90
92
  next();
91
- document.addEventListener('astro:beforeload', () => {
92
- delete window._firstLoadContextId;
93
- }, { once: true });
94
93
  return;
95
94
  }
96
95
  window.addEventListener('storefront:apiContext', next, { once: true });
@@ -0,0 +1,8 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+
3
+ export const asyncLocalStorage = new AsyncLocalStorage();
4
+
5
+ /* eslint-disable import/prefer-default-export */
6
+ export function onRequest(ctx, next) {
7
+ return asyncLocalStorage.run({ sid: `${Date.now() + Math.random()}` }, next);
8
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/storefront",
3
3
  "type": "module",
4
- "version": "2.8.7",
4
+ "version": "2.9.0",
5
5
  "description": "E-Com Plus Cloud Commerce storefront with Astro",
6
6
  "bin": {
7
7
  "storefront": "./scripts/build-prod.sh"
@@ -37,25 +37,35 @@ const prefetchHref = computed(() => {
37
37
  return pathname;
38
38
  });
39
39
  if (prefetchHref.value) {
40
+ const prefetchOnNext = () => {
41
+ requestIdleCallback(() => {
42
+ const next = () => {
43
+ if (!prefetchHref.value) return;
44
+ window.$prefetch!(prefetchHref.value);
45
+ };
46
+ if (!window.$firstInteraction) {
47
+ window.addEventListener('firstInteraction', next, { once: true });
48
+ } else {
49
+ window.$firstInteraction.then(next);
50
+ }
51
+ });
52
+ };
40
53
  onMounted(() => {
41
54
  const { prefetch } = props;
42
55
  const isOnHover = prefetch === 'hover';
43
56
  if (isMobile && isOnHover) return;
44
57
  const isOnVisible = prefetch === 'visible';
45
- const use = isOnVisible
58
+ const useElementEv = isOnVisible
46
59
  ? useElementVisibility
47
60
  : isOnHover && useElementHover;
48
- if (!use) return;
49
- const is = use(link.value);
50
- const unwatch = watch(is, (_is) => {
51
- if (!_is || !window.$prefetch) return;
61
+ if (!useElementEv) return;
62
+ const isActive = useElementEv(link.value);
63
+ const unwatch = watch(isActive, (_isActive) => {
64
+ if (!_isActive || !window.$prefetch) return;
52
65
  unwatch();
53
66
  setTimeout(() => {
54
- if (isOnVisible && !is.value) return;
55
- requestIdleCallback(() => {
56
- if (!prefetchHref.value) return;
57
- window.$prefetch!(prefetchHref.value);
58
- });
67
+ if (isOnVisible && !isActive.value) return;
68
+ prefetchOnNext();
59
69
  }, isOnVisible ? 100 : 1);
60
70
  }, {
61
71
  immediate: true,
@@ -27,7 +27,7 @@ const useSkuSelector = (props: Props) => {
27
27
  || [],
28
28
  );
29
29
  if (!grids.length && !import.meta.env.SSR) {
30
- window.addEventListener('storefront:data:data', () => {
30
+ window.addEventListener('storefront:data:grids', () => {
31
31
  globalThis.$storefront.data.grids?.forEach((grid) => grids.push(grid));
32
32
  }, { once: true });
33
33
  }
@@ -21,6 +21,11 @@ const { customCode } = await getContent('layout');
21
21
  <slot name="base-body-scripts">
22
22
  <script src="../scripts/session-utm"></script>
23
23
  <script src="../scripts/push-analytics-events"></script>
24
+ <script>
25
+ /* eslint-disable */
26
+ import { prefetch } from 'astro:prefetch';
27
+ window.$prefetch = prefetch;
28
+ </script>
24
29
  </slot>
25
30
  <slot name="before-body-end" />
26
31
  </BaseBody>
@@ -206,12 +206,7 @@ const generator = `e-com.plus @cloudcommerce/storefront, ${Astro.generator}`;
206
206
  && <link rel="manifest" href="/manifest.webmanifest" />}
207
207
  </>}
208
208
 
209
- <script is:inline set:html={inlineClientJS} transition:persist />
209
+ <script is:inline set:html={inlineClientJS} />
210
210
  <script is:inline type="application/ld+json" set:html={inlineJSONLd} />
211
211
 
212
- <script>
213
- /* eslint-disable */
214
- import { prefetch } from 'astro:prefetch';
215
- window.$prefetch = prefetch;
216
- </script>
217
212
  {contextInlineClientJS && <script is:inline set:html={contextInlineClientJS} />}
@@ -1,3 +1,4 @@
1
+ import type { AsyncLocalStorage } from 'node:async_hooks';
1
2
  import type { AstroGlobal } from 'astro';
2
3
  import type { BaseConfig } from '@cloudcommerce/config';
3
4
  import type { ApiError, ApiEndpoint } from '@cloudcommerce/api';
@@ -5,8 +6,8 @@ import type { ResourceId, CategoriesList, BrandsList } from '@cloudcommerce/api/
5
6
  import type { ContentGetter, SettingsContent, PageContent } from '@@sf/content';
6
7
  import type { StorefrontApiContext } from '@@sf/$storefront';
7
8
  import { EventEmitter } from 'node:events';
8
- import { inject, getCurrentInstance } from 'vue';
9
9
  import api from '@cloudcommerce/api';
10
+ import { asyncLocalStorage as _als } from '../../config/astro/node-middleware.mjs';
10
11
  import _getConfig from '../../config/storefront.config.mjs';
11
12
  import { termify } from '../helpers/sf-utils';
12
13
 
@@ -23,6 +24,8 @@ export type StorefrontConfig = {
23
24
  getContent: ContentGetter,
24
25
  };
25
26
 
27
+ export const asyncLocalStorage = _als as AsyncLocalStorage<{ sid: string }>;
28
+
26
29
  const emitter = new EventEmitter();
27
30
  const getConfig: () => StorefrontConfig = _getConfig;
28
31
 
@@ -54,8 +57,8 @@ if (!globalThis.$storefront) {
54
57
  // @ts-expect-error: URL is retrived from `target.getSession().url`
55
58
  url: undefined,
56
59
  getSession(sid?: string) {
57
- if (!sid && !!getCurrentInstance()) {
58
- sid = inject('sid');
60
+ if (!sid) {
61
+ sid = asyncLocalStorage.getStore()?.sid;
59
62
  }
60
63
  const {
61
64
  url,
@@ -112,7 +115,7 @@ const loadRouteContext = async (
112
115
  apiPrefetchEndpoints?: ApiPrefetchEndpoints;
113
116
  } = {},
114
117
  ) => {
115
- const sid = `${Date.now() + Math.random()}`;
118
+ const sid = asyncLocalStorage.getStore()?.sid || `${Date.now()}`;
116
119
  sessions[sid] = { url: Astro.url };
117
120
  global.__sfSession = sessions[sid];
118
121
  const startedAt = Date.now();
@@ -229,7 +229,6 @@ export const useAnalytics = ({
229
229
  }: {
230
230
  experimentId?: string,
231
231
  } = {}) => {
232
- document.addEventListener('astro:beforeload', resetPageViewPromise);
233
232
  const {
234
233
  gtag,
235
234
  GTAG_TAG_ID,
@@ -2,7 +2,7 @@
2
2
  "name": "@cloudcommerce/test-base",
3
3
  "private": true,
4
4
  "type": "module",
5
- "version": "2.8.7",
5
+ "version": "2.9.0",
6
6
  "description": "E-Com Plus Cloud Commerce basic setup for testing",
7
7
  "main": "lib/index.js",
8
8
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/types",
3
3
  "type": "module",
4
- "version": "2.8.7",
4
+ "version": "2.9.0",
5
5
  "description": "E-Com Plus Cloud Commerce reusable type definitions",
6
6
  "main": "index.ts",
7
7
  "repository": {
@@ -1,64 +0,0 @@
1
- /* eslint-disable no-restricted-syntax */
2
- import { h, createSSRApp, defineComponent } from 'vue';
3
- import { renderToString } from 'vue/server-renderer';
4
- import { setup } from 'virtual:@astrojs/vue/app';
5
-
6
- /**
7
- * Astro passes `children` as a string of HTML, so we need
8
- * a wrapper `div` to render that content as VNodes.
9
- *
10
- * This is the Vue + JSX equivalent of using `<div v-html="value" />`
11
- */
12
- const StaticHtml = defineComponent({
13
- props: {
14
- value: String,
15
- name: String,
16
- hydrate: {
17
- type: Boolean,
18
- default: true,
19
- },
20
- },
21
- setup({ name, value, hydrate }) {
22
- if (!value) return () => null;
23
- const tagName = hydrate ? 'astro-slot' : 'astro-static-slot';
24
- return () => h(tagName, { name, innerHTML: value });
25
- },
26
- });
27
-
28
- /**
29
- * Other frameworks have `shouldComponentUpdate` in order to signal
30
- * that this subtree is entirely static and will not be updated
31
- *
32
- * Fortunately, Vue is smart enough to figure that out without any
33
- * help from us, so this just works out of the box!
34
- */
35
-
36
- function check(Component) {
37
- return !!Component.ssrRender || !!Component.__ssrInlineRender;
38
- }
39
-
40
- async function renderToStaticMarkup(Component, inputProps, slotted, metadata) {
41
- const slots = {};
42
- const props = { ...inputProps };
43
- delete props.slot;
44
- const sid = this.result?.cookies?.get('sid')?.value;
45
- for (const [key, value] of Object.entries(slotted)) {
46
- slots[key] = () => h(StaticHtml, {
47
- value,
48
- name: key === 'default' ? undefined : key,
49
- // Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
50
- hydrate: metadata.astroStaticSlot ? !!metadata.hydrate : true,
51
- });
52
- }
53
- const app = createSSRApp({ render: () => h(Component, props, slots) });
54
- app.provide('sid', sid);
55
- await setup(app);
56
- const html = await renderToString(app);
57
- return { html };
58
- }
59
-
60
- export default {
61
- check,
62
- renderToStaticMarkup,
63
- supportsAstroStaticSlot: true,
64
- };