cloudcommerce 0.16.1 → 0.16.2

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 (41) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -1
  3. package/packages/api/package.json +1 -1
  4. package/packages/apps/affilate-program/package.json +1 -1
  5. package/packages/apps/correios/package.json +1 -1
  6. package/packages/apps/custom-payment/package.json +1 -1
  7. package/packages/apps/custom-shipping/package.json +1 -1
  8. package/packages/apps/datafrete/package.json +1 -1
  9. package/packages/apps/discounts/package.json +1 -1
  10. package/packages/apps/emails/package.json +1 -1
  11. package/packages/apps/fb-conversions/package.json +1 -1
  12. package/packages/apps/flash-courier/package.json +1 -1
  13. package/packages/apps/frenet/package.json +1 -1
  14. package/packages/apps/galaxpay/package.json +1 -1
  15. package/packages/apps/google-analytics/package.json +1 -1
  16. package/packages/apps/infinitepay/package.json +1 -1
  17. package/packages/apps/jadlog/package.json +1 -1
  18. package/packages/apps/loyalty-points/package.json +1 -1
  19. package/packages/apps/melhor-envio/package.json +1 -1
  20. package/packages/apps/mercadopago/package.json +1 -1
  21. package/packages/apps/pagarme/package.json +1 -1
  22. package/packages/apps/paghiper/package.json +1 -1
  23. package/packages/apps/pix/package.json +1 -1
  24. package/packages/apps/tiny-erp/package.json +1 -1
  25. package/packages/apps/webhooks/package.json +1 -1
  26. package/packages/cli/package.json +1 -1
  27. package/packages/config/package.json +1 -1
  28. package/packages/emails/package.json +1 -1
  29. package/packages/events/package.json +1 -1
  30. package/packages/feeds/package.json +1 -1
  31. package/packages/firebase/package.json +1 -1
  32. package/packages/i18n/package.json +1 -1
  33. package/packages/modules/package.json +1 -1
  34. package/packages/passport/package.json +1 -1
  35. package/packages/ssr/lib/firebase/serve-storefront.js +83 -7
  36. package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -1
  37. package/packages/ssr/package.json +1 -1
  38. package/packages/ssr/src/firebase/serve-storefront.ts +91 -7
  39. package/packages/storefront/dist/server/entry.mjs +1 -1
  40. package/packages/storefront/package.json +1 -1
  41. package/packages/types/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.16.2](https://github.com/ecomplus/cloud-commerce/compare/v0.16.1...v0.16.2) (2023-07-11)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **ssr:** Use `writeHead` middleware to set X-SSR-Took header ([cdee5c5](https://github.com/ecomplus/cloud-commerce/commit/cdee5c54680ca5f28d48a286f407946781eebc14))
11
+
5
12
  ### [0.16.1](https://github.com/ecomplus/cloud-commerce/compare/v0.16.0...v0.16.1) (2023-07-11)
6
13
 
7
14
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloudcommerce",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "Open fair-code headless commerce platform: API-first, microservices based, event driven and cloud native",
6
6
  "main": "packages/api/lib/index.js",
7
7
  "author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/api",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce APIs client/adapter",
6
6
  "main": "lib/api.js",
7
7
  "types": "lib/api.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-affilate-program",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for simple affiliate program",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-correios",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for Correios shipping calculation",
6
6
  "main": "lib/correios.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-custom-payment",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for simple custom payment methods",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-custom-shipping",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for custom shipping methods",
6
6
  "main": "lib/custom-shipping.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-datafrete",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Datafrete shipping gateway ",
6
6
  "main": "lib/datafrete.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for complex discount rules",
6
6
  "main": "lib/discounts.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-emails",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce default transactional email app",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-fb-conversions",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to send carts/orders to Facebook Conversions API",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-flash-courier",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Flash Courier",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-frenet",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for Frenet shipping calculation",
6
6
  "main": "lib/frenet.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-galaxpay",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Galax Pay for recurring payments",
6
6
  "main": "lib/galaxpay.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-google-analytics",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to send carts/orders events to GA Measurement Protocol",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-infinitepay",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate InfinitePay",
6
6
  "main": "lib/infinitepay.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-jadlog",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for Jadlog shipping calculation",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-loyalty-points",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to handle simple loyalty points programs",
6
6
  "main": "lib/loyalty-points.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-melhor-envio",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Melhor Envio",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-mercadopago",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Mercado Pago",
6
6
  "main": "lib/mercadopago.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pagarme",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pagar.me",
6
6
  "main": "lib/pagarme.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-paghiper",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate PagHiper",
6
6
  "main": "lib/paghiper.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-pix",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app to integrate Pix API (Bacen)",
6
6
  "main": "lib/pix.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-tiny-erp",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for Tiny ERP",
6
6
  "main": "lib/tiny-erp.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-webhooks",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app for general order webhooks",
6
6
  "main": "lib/index.js",
7
7
  "repository": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/cli",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce CLI tools",
6
6
  "bin": {
7
7
  "cloudcommerce": "./bin/run.mjs"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/config",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce base config",
6
6
  "main": "lib/config.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/emails",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce email sender",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/events",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce app events",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/feeds",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce catalog feeds",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/firebase",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce on Firebase",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/i18n",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce i18n",
6
6
  "main": "lib/all.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/modules",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce modules API",
6
6
  "main": "lib/index.cjs",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/passport",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce customers authentication (passport) API",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,5 +1,6 @@
1
1
  import { join as joinPath } from 'node:path';
2
2
  import { readFile } from 'node:fs/promises';
3
+ import { getFirestore, Timestamp } from 'firebase-admin/firestore';
3
4
  import logger from 'firebase-functions/logger';
4
5
 
5
6
  const { STOREFRONT_BASE_DIR } = process.env;
@@ -8,7 +9,11 @@ const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
8
9
  let imagesManifest;
9
10
  const builtImages = [];
10
11
 
11
- export default (req, res) => {
12
+ export default async (req, res) => {
13
+ if (req.path.startsWith('/~partytown')) {
14
+ res.sendStatus(404);
15
+ return;
16
+ }
12
17
  res.set('X-XSS-Protection', '1; mode=block');
13
18
  const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
14
19
  const setStatusAndCache = (status, cacheControl) => {
@@ -69,20 +74,91 @@ export default (req, res) => {
69
74
  res.sendStatus(400);
70
75
  return;
71
76
  }
72
- const ssrStartedAt = Date.now();
73
- const _end = res.end;
77
+ const startedAt = Date.now();
78
+ let ssrStartedAt;
79
+ let status;
80
+ let headers = {};
81
+ const chunks = [];
82
+ /*
83
+ Check Response methods used by Astro Node.js integration:
84
+ https://github.com/withastro/astro/blob/main/packages/integrations/node/src/nodeMiddleware.ts
85
+ */
86
+ const _writeHead = res.writeHead;
74
87
  /* eslint-disable prefer-rest-params */
75
88
  // @ts-ignore
76
- res.end = function resEnd() {
77
- res.set('X-SSR-Took', String(Date.now() - ssrStartedAt));
78
- // @ts-ignore
79
- _end.apply(res, arguments);
89
+ res.writeHead = function writeHead(_status, _headers) {
90
+ _headers['X-Function-Took'] = String(Date.now() - startedAt);
91
+ if (ssrStartedAt) {
92
+ _headers['X-SSR-Took'] = String(Date.now() - ssrStartedAt);
93
+ }
94
+ if (!res.headersSent) {
95
+ // @ts-ignore
96
+ _writeHead.apply(res, arguments);
97
+ }
98
+ status = _status;
99
+ headers = _headers;
100
+ };
101
+ let cacheRef;
102
+ if (!req.query.__noCache && req.path.charAt(1) !== '~') {
103
+ try {
104
+ const firestore = getFirestore();
105
+ cacheRef = firestore.doc(`ssrCache/${req.path.slice(1).replace(/\//g, '_')}`);
106
+ const cacheDoc = await cacheRef.get();
107
+ if (cacheDoc.exists) {
108
+ const {
109
+ headers: cachedHeaders, status: cachedStatus, chunks: cachedChunks, __timestamp,
110
+ } = cacheDoc.data();
111
+ const isFresh = (Timestamp.now().toMillis() - __timestamp.toMillis()) < 1000 * 60 * 2;
112
+ cachedHeaders['X-SWR-Date'] = (isFresh ? 'fresh ' : '')
113
+ + __timestamp.toDate().toISOString();
114
+ res.writeHead(cachedStatus || 200, cachedHeaders);
115
+ cachedChunks.forEach((chunk) => {
116
+ res.write(chunk);
117
+ });
118
+ res.end();
119
+ if (isFresh) {
120
+ return;
121
+ }
122
+ }
123
+ } catch (err) {
124
+ cacheRef = null;
125
+ logger.warn(err);
126
+ }
127
+ }
128
+ const _write = res.write;
129
+ // @ts-ignore
130
+ res.write = function write(chunk) {
131
+ if (!res.headersSent) {
132
+ // @ts-ignore
133
+ _write.apply(res, arguments);
134
+ }
135
+ chunks.push(chunk);
136
+ };
137
+ const _end = res.end;
138
+ // @ts-ignore
139
+ res.end = function end() {
140
+ if (!res.headersSent) {
141
+ // @ts-ignore
142
+ _end.apply(res, arguments);
143
+ }
144
+ if (!status) {
145
+ status = res.statusCode;
146
+ }
147
+ if (cacheRef && status === 200) {
148
+ cacheRef.set({
149
+ headers,
150
+ status,
151
+ chunks,
152
+ __timestamp: Timestamp.now(),
153
+ }).catch(logger.warn);
154
+ }
80
155
  };
81
156
  /*
82
157
  https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
83
158
  import { handler as renderStorefront } from '../dist/server/entry.mjs';
84
159
  global.$renderStorefront = renderStorefront;
85
160
  */
161
+ ssrStartedAt = Date.now();
86
162
  global.$renderStorefront(req, res, async (err) => {
87
163
  if (err) {
88
164
  if (res.headersSent) {
@@ -1 +1 @@
1
- {"version":3,"file":"serve-storefront.js","sourceRoot":"","sources":["../../src/firebase/serve-storefront.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAW/C,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAC5C,MAAM,OAAO,GAAG,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AACrD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/E,IAAI,cAAsB,CAAC;AAE3B,MAAM,WAAW,GAAiB,EAAE,CAAC;AAErC,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,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EAAE;gBACnB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClB,GAAG,CAAC,GAAG,EAAE,CAAC;gBACV,OAAO;aACR;YACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;YACpC,GAAG,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YACxC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACd,OAAO;SACR;QACD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;QAC7C,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnC,iBAAiB,CAAC,GAAG,EAAE,kCAAkC,CAAC;iBACvD,IAAI,CAAC,IAAI,CAAC,CAAC;SACf;QAAC,OAAO,CAAC,EAAE;YACV,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAClB;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/ssr",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce storefront SSR",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,6 +1,10 @@
1
+ import type { OutgoingHttpHeaders } from 'node:http';
2
+ import type { Readable } from 'node:stream';
1
3
  import type { Request, Response } from 'firebase-functions';
4
+ import type { DocumentReference } from 'firebase-admin/firestore';
2
5
  import { join as joinPath } from 'node:path';
3
6
  import { readFile } from 'node:fs/promises';
7
+ import { getFirestore, Timestamp } from 'firebase-admin/firestore';
4
8
  import logger from 'firebase-functions/logger';
5
9
 
6
10
  declare global {
@@ -19,7 +23,11 @@ let imagesManifest: string;
19
23
  type BuiltImage = { filename: string, width: number, height: number };
20
24
  const builtImages: BuiltImage[] = [];
21
25
 
22
- export default (req: Request, res: Response) => {
26
+ export default async (req: Request, res: Response) => {
27
+ if (req.path.startsWith('/~partytown')) {
28
+ res.sendStatus(404);
29
+ return;
30
+ }
23
31
  res.set('X-XSS-Protection', '1; mode=block');
24
32
  const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
25
33
 
@@ -84,14 +92,89 @@ export default (req: Request, res: Response) => {
84
92
  return;
85
93
  }
86
94
 
87
- const ssrStartedAt = Date.now();
88
- const _end = res.end;
95
+ const startedAt = Date.now();
96
+ let ssrStartedAt: number | undefined;
97
+ let status: number;
98
+ let headers: OutgoingHttpHeaders = {};
99
+ const chunks: Readable[] = [];
100
+ /*
101
+ Check Response methods used by Astro Node.js integration:
102
+ https://github.com/withastro/astro/blob/main/packages/integrations/node/src/nodeMiddleware.ts
103
+ */
104
+ const _writeHead = res.writeHead;
89
105
  /* eslint-disable prefer-rest-params */
90
106
  // @ts-ignore
91
- res.end = function resEnd() {
92
- res.set('X-SSR-Took', String(Date.now() - ssrStartedAt));
93
- // @ts-ignore
94
- _end.apply(res, arguments);
107
+ res.writeHead = function writeHead(_status: number, _headers: OutgoingHttpHeaders) {
108
+ _headers['X-Function-Took'] = String(Date.now() - startedAt);
109
+ if (ssrStartedAt) {
110
+ _headers['X-SSR-Took'] = String(Date.now() - ssrStartedAt);
111
+ }
112
+ if (!res.headersSent) {
113
+ // @ts-ignore
114
+ _writeHead.apply(res, arguments);
115
+ }
116
+ status = _status;
117
+ headers = _headers;
118
+ };
119
+
120
+ let cacheRef: DocumentReference<any> | undefined | null;
121
+ if (!req.query.__noCache && req.path.charAt(1) !== '~') {
122
+ try {
123
+ const firestore = getFirestore();
124
+ cacheRef = firestore.doc(`ssrCache/${req.path.slice(1).replace(/\//g, '_')}`);
125
+ const cacheDoc = await cacheRef.get();
126
+ if (cacheDoc.exists) {
127
+ const {
128
+ headers: cachedHeaders,
129
+ status: cachedStatus,
130
+ chunks: cachedChunks,
131
+ __timestamp,
132
+ } = cacheDoc.data();
133
+ const isFresh = (Timestamp.now().toMillis() - __timestamp.toMillis()) < 1000 * 60 * 2;
134
+ cachedHeaders['X-SWR-Date'] = (isFresh ? 'fresh ' : '')
135
+ + __timestamp.toDate().toISOString();
136
+ res.writeHead(cachedStatus || 200, cachedHeaders);
137
+ cachedChunks.forEach((chunk: Readable) => {
138
+ res.write(chunk);
139
+ });
140
+ res.end();
141
+ if (isFresh) {
142
+ return;
143
+ }
144
+ }
145
+ } catch (err) {
146
+ cacheRef = null;
147
+ logger.warn(err);
148
+ }
149
+ }
150
+
151
+ const _write = res.write;
152
+ // @ts-ignore
153
+ res.write = function write(chunk: Readable) {
154
+ if (!res.headersSent) {
155
+ // @ts-ignore
156
+ _write.apply(res, arguments);
157
+ }
158
+ chunks.push(chunk);
159
+ };
160
+ const _end = res.end;
161
+ // @ts-ignore
162
+ res.end = function end() {
163
+ if (!res.headersSent) {
164
+ // @ts-ignore
165
+ _end.apply(res, arguments);
166
+ }
167
+ if (!status) {
168
+ status = res.statusCode;
169
+ }
170
+ if (cacheRef && status === 200) {
171
+ cacheRef.set({
172
+ headers,
173
+ status,
174
+ chunks,
175
+ __timestamp: Timestamp.now(),
176
+ }).catch(logger.warn);
177
+ }
95
178
  };
96
179
 
97
180
  /*
@@ -99,6 +182,7 @@ export default (req: Request, res: Response) => {
99
182
  import { handler as renderStorefront } from '../dist/server/entry.mjs';
100
183
  global.$renderStorefront = renderStorefront;
101
184
  */
185
+ ssrStartedAt = Date.now();
102
186
  global.$renderStorefront(req, res, async (err: any) => {
103
187
  if (err) {
104
188
  if (res.headersSent) {
@@ -2830,7 +2830,7 @@ const _page2 = () => import('./chunks/fallback@_@astro.6c7c4acd.mjs');
2830
2830
  const _page3 = () => import('./chunks/index@_@astro.f7e2409d.mjs');
2831
2831
  const _page4 = () => import('./chunks/account@_@astro.d58b2d34.mjs');
2832
2832
  const _page5 = () => import('./chunks/_...06f412d0.mjs');const pageMap = new Map([["../../node_modules/.pnpm/@astrojs+image@0.17.2_astro@2.8.0_sharp@0.32.1/node_modules/@astrojs/image/dist/endpoint.js", _page0],["src/pages/index.astro", _page1],["src/pages/fallback.astro", _page2],["src/pages/app/index.astro", _page3],["src/pages/app/account.astro", _page4],["src/pages/[...slug].astro", _page5]]);
2833
- const _manifest = Object.assign(deserializeManifest({"adapterName":"@astrojs/node","routes":[{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"type":"endpoint","route":"/_image","pattern":"^\\/_image$","segments":[[{"content":"_image","dynamic":false,"spread":false}]],"params":[],"component":"../../node_modules/.pnpm/@astrojs+image@0.17.2_astro@2.8.0_sharp@0.32.1/node_modules/@astrojs/image/dist/endpoint.js","pathname":"/_image","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/","type":"page","pattern":"^\\/$","segments":[],"params":[],"component":"src/pages/index.astro","pathname":"/","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/fallback","type":"page","pattern":"^\\/fallback\\/?$","segments":[[{"content":"fallback","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/fallback.astro","pathname":"/fallback","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"route":"/app","type":"page","pattern":"^\\/app\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/index.astro","pathname":"/app","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"route":"/app/account","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,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/[...slug]","type":"page","pattern":"^(?:\\/(.*?))?\\/?$","segments":[[{"content":"...slug","dynamic":true,"spread":true}]],"params":["...slug"],"component":"src/pages/[...slug].astro","prerender":false,"_meta":{"trailingSlash":"ignore"}}}],"site":"https://ecom2-demo.web.app","base":"/","compressHTML":false,"markdown":{"drafts":false,"syntaxHighlight":"shiki","shikiConfig":{"langs":[],"theme":"github-dark","wrap":false},"remarkPlugins":[],"rehypePlugins":[],"remarkRehype":{},"gfm":true,"smartypants":true},"componentMetadata":[["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/[...slug].astro",{"propagation":"none","containsHead":true}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/fallback.astro",{"propagation":"none","containsHead":true}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/index.astro",{"propagation":"none","containsHead":true}]],"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 r=(i,c,n)=>{let s=async()=>{await(await i())()},t=new IntersectionObserver(e=>{for(let o of e)if(o.isIntersecting){t.disconnect(),s();break}});for(let e of n.children)t.observe(e)};(self.Astro||(self.Astro={})).visible=r;window.dispatchEvent(new Event(\"astro:visible\"));})();"]],"entryModules":{"\u0000@astrojs-ssr-virtual-entry":"_@astrojs-ssr-virtual-entry.mjs","\u0000@astro-renderers":"renderers.mjs","\u0000empty-middleware":"_empty-middleware.mjs","/src/pages/app/account.astro":"chunks/pages/account.astro.f630663e.mjs","/src/pages/fallback.astro":"chunks/pages/fallback.astro.42f81a9a.mjs","\u0000@astro-page:../../node_modules/.pnpm/@astrojs+image@0.17.2_astro@2.8.0_sharp@0.32.1/node_modules/@astrojs/image/dist/endpoint@_@js":"chunks/endpoint@_@js.ce919661.mjs","\u0000@astro-page:src/pages/index@_@astro":"chunks/index@_@astro.8e359cb4.mjs","\u0000@astro-page:src/pages/fallback@_@astro":"chunks/fallback@_@astro.6c7c4acd.mjs","\u0000@astro-page:src/pages/app/index@_@astro":"chunks/index@_@astro.f7e2409d.mjs","\u0000@astro-page:src/pages/app/account@_@astro":"chunks/account@_@astro.d58b2d34.mjs","\u0000@astro-page:src/pages/[...slug]@_@astro":"chunks/_...06f412d0.mjs","/home/leo/code/ecomplus/cloud-commerce/node_modules/workbox-window/build/workbox-window.prod.es5.mjs":"_astro/workbox-window.prod.es5.a7b12eab.js","/astro/hoisted.js?q=0":"_astro/hoisted.9d9d7ac4.js","@astrojs/vue/client.js":"_astro/client.2d950540.js","~/components/Prices.vue":"_astro/Prices.de6df3cb.js","~/components/HeroSlider.vue":"_astro/HeroSlider.3d4a1d1c.js","~/components/PitchBar.vue":"_astro/PitchBar.c53e6d0b.js","~/components/ProductShelf.vue":"_astro/ProductShelf.f013b3ee.js","~/components/ShopHeader.vue":"_astro/ShopHeader.c0ba5061.js","/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/lib/scripts/firebase-app.ts":"_astro/firebase-app.84207480.js","astro:scripts/before-hydration.js":""},"assets":["/_astro/_...slug_.45bc69ca.css","/manifest.webmanifest","/robots.txt","/sw.js","/workbox-5e0bf4e4.js","/_astro/Carousel.f39be3c0.js","/_astro/HeroSlider.3d4a1d1c.js","/_astro/PitchBar.c53e6d0b.js","/_astro/Prices.de6df3cb.js","/_astro/ProductShelf.f013b3ee.js","/_astro/ShopHeader.c0ba5061.js","/_astro/_plugin-vue_export-helper.d3aaeb0d.js","/_astro/api.7f62c1ff.js","/_astro/client.2d950540.js","/_astro/firebase-app.84207480.js","/_astro/format-money.3b884fcb.js","/_astro/hoisted.9d9d7ac4.js","/_astro/idle-callback.889bf0ea.js","/_astro/img.517fec8e.js","/_astro/index.33347cbd.js","/_astro/modules-info.ad27b027.js","/_astro/preload-helper.cf010ec4.js","/_astro/runtime-dom.esm-bundler.00b967e0.js","/_astro/session-utm.744b0db3.js","/_astro/workbox-window.prod.es5.a7b12eab.js","/assets/cms-preview.css","/assets/cms.css","/assets/cvv.png","/assets/img-placeholder.png","/assets/payments.png","/assets/ssl-safe.png","/img/icon.png","/img/large-icon.png","/img/uploads/banner1.png","/img/uploads/banner2.png","/img/uploads/banner2.webp","/img/uploads/ecom-icon.png","/img/uploads/favicon.png","/img/uploads/headless.png","/img/uploads/headphone.png","/img/uploads/headphone.webp","/img/uploads/logo.png","/img/uploads/og-image.png","/img/uploads/passion.png","/img/uploads/passion.webp","/img/uploads/pwa-reliable.png","/img/uploads/rect8589.png","/img/uploads/rect859.png","/img/uploads/rect89.png","/img/uploads/rect89.webp","/img/uploads/ssl-safe.png"]}), {
2833
+ const _manifest = Object.assign(deserializeManifest({"adapterName":"@astrojs/node","routes":[{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"type":"endpoint","route":"/_image","pattern":"^\\/_image$","segments":[[{"content":"_image","dynamic":false,"spread":false}]],"params":[],"component":"../../node_modules/.pnpm/@astrojs+image@0.17.2_astro@2.8.0_sharp@0.32.1/node_modules/@astrojs/image/dist/endpoint.js","pathname":"/_image","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/","type":"page","pattern":"^\\/$","segments":[],"params":[],"component":"src/pages/index.astro","pathname":"/","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/fallback","type":"page","pattern":"^\\/fallback\\/?$","segments":[[{"content":"fallback","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/fallback.astro","pathname":"/fallback","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"route":"/app","type":"page","pattern":"^\\/app\\/?$","segments":[[{"content":"app","dynamic":false,"spread":false}]],"params":[],"component":"src/pages/app/index.astro","pathname":"/app","prerender":false,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[],"styles":[],"routeData":{"route":"/app/account","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,"_meta":{"trailingSlash":"ignore"}}},{"file":"","links":[],"scripts":[{"type":"external","value":"/_astro/hoisted.9d9d7ac4.js"}],"styles":[{"type":"external","src":"/_astro/_...slug_.45bc69ca.css"}],"routeData":{"route":"/[...slug]","type":"page","pattern":"^(?:\\/(.*?))?\\/?$","segments":[[{"content":"...slug","dynamic":true,"spread":true}]],"params":["...slug"],"component":"src/pages/[...slug].astro","prerender":false,"_meta":{"trailingSlash":"ignore"}}}],"site":"https://ecom2-demo.web.app","base":"/","compressHTML":false,"markdown":{"drafts":false,"syntaxHighlight":"shiki","shikiConfig":{"langs":[],"theme":"github-dark","wrap":false},"remarkPlugins":[],"rehypePlugins":[],"remarkRehype":{},"gfm":true,"smartypants":true},"componentMetadata":[["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/[...slug].astro",{"propagation":"none","containsHead":true}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/fallback.astro",{"propagation":"none","containsHead":true}],["/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/pages/index.astro",{"propagation":"none","containsHead":true}]],"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 r=(i,c,n)=>{let s=async()=>{await(await i())()},t=new IntersectionObserver(e=>{for(let o of e)if(o.isIntersecting){t.disconnect(),s();break}});for(let e of n.children)t.observe(e)};(self.Astro||(self.Astro={})).visible=r;window.dispatchEvent(new Event(\"astro:visible\"));})();"]],"entryModules":{"\u0000@astrojs-ssr-virtual-entry":"_@astrojs-ssr-virtual-entry.mjs","\u0000@astro-renderers":"renderers.mjs","\u0000empty-middleware":"_empty-middleware.mjs","/src/pages/app/account.astro":"chunks/pages/account.astro.f630663e.mjs","/src/pages/fallback.astro":"chunks/pages/fallback.astro.42f81a9a.mjs","\u0000@astro-page:../../node_modules/.pnpm/@astrojs+image@0.17.2_astro@2.8.0_sharp@0.32.1/node_modules/@astrojs/image/dist/endpoint@_@js":"chunks/endpoint@_@js.ce919661.mjs","\u0000@astro-page:src/pages/index@_@astro":"chunks/index@_@astro.8e359cb4.mjs","\u0000@astro-page:src/pages/fallback@_@astro":"chunks/fallback@_@astro.6c7c4acd.mjs","\u0000@astro-page:src/pages/app/index@_@astro":"chunks/index@_@astro.f7e2409d.mjs","\u0000@astro-page:src/pages/app/account@_@astro":"chunks/account@_@astro.d58b2d34.mjs","\u0000@astro-page:src/pages/[...slug]@_@astro":"chunks/_...06f412d0.mjs","~/components/HeroSlider.vue":"_astro/HeroSlider.3d4a1d1c.js","/astro/hoisted.js?q=0":"_astro/hoisted.9d9d7ac4.js","~/components/PitchBar.vue":"_astro/PitchBar.c53e6d0b.js","~/components/ProductShelf.vue":"_astro/ProductShelf.f013b3ee.js","@astrojs/vue/client.js":"_astro/client.2d950540.js","/home/leo/code/ecomplus/cloud-commerce/node_modules/workbox-window/build/workbox-window.prod.es5.mjs":"_astro/workbox-window.prod.es5.a7b12eab.js","~/components/Prices.vue":"_astro/Prices.de6df3cb.js","~/components/ShopHeader.vue":"_astro/ShopHeader.c0ba5061.js","/home/leo/code/ecomplus/cloud-commerce/packages/storefront/src/lib/scripts/firebase-app.ts":"_astro/firebase-app.84207480.js","astro:scripts/before-hydration.js":""},"assets":["/_astro/_...slug_.45bc69ca.css","/manifest.webmanifest","/robots.txt","/sw.js","/workbox-5e0bf4e4.js","/_astro/Carousel.f39be3c0.js","/_astro/HeroSlider.3d4a1d1c.js","/_astro/PitchBar.c53e6d0b.js","/_astro/Prices.de6df3cb.js","/_astro/ProductShelf.f013b3ee.js","/_astro/ShopHeader.c0ba5061.js","/_astro/_plugin-vue_export-helper.d3aaeb0d.js","/_astro/api.7f62c1ff.js","/_astro/client.2d950540.js","/_astro/firebase-app.84207480.js","/_astro/format-money.3b884fcb.js","/_astro/hoisted.9d9d7ac4.js","/_astro/idle-callback.889bf0ea.js","/_astro/img.517fec8e.js","/_astro/index.33347cbd.js","/_astro/modules-info.ad27b027.js","/_astro/preload-helper.cf010ec4.js","/_astro/runtime-dom.esm-bundler.00b967e0.js","/_astro/session-utm.744b0db3.js","/_astro/workbox-window.prod.es5.a7b12eab.js","/assets/cms-preview.css","/assets/cms.css","/assets/cvv.png","/assets/img-placeholder.png","/assets/payments.png","/assets/ssl-safe.png","/img/icon.png","/img/large-icon.png","/img/uploads/banner1.png","/img/uploads/banner2.png","/img/uploads/banner2.webp","/img/uploads/ecom-icon.png","/img/uploads/favicon.png","/img/uploads/headless.png","/img/uploads/headphone.png","/img/uploads/headphone.webp","/img/uploads/logo.png","/img/uploads/og-image.png","/img/uploads/passion.png","/img/uploads/passion.webp","/img/uploads/pwa-reliable.png","/img/uploads/rect8589.png","/img/uploads/rect859.png","/img/uploads/rect89.png","/img/uploads/rect89.webp","/img/uploads/ssl-safe.png"]}), {
2834
2834
  pageMap,
2835
2835
  renderers,
2836
2836
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/storefront",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce storefront with Astro",
6
6
  "bin": {
7
7
  "storefront": "./scripts/build-prod.sh"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloudcommerce/types",
3
3
  "type": "module",
4
- "version": "0.16.1",
4
+ "version": "0.16.2",
5
5
  "description": "E-Com Plus Cloud Commerce reusable type definitions",
6
6
  "main": "index.ts",
7
7
  "repository": {