cloudcommerce 0.16.1 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +19 -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 +88 -8
  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 +100 -8
  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,25 @@
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.3](https://github.com/ecomplus/cloud-commerce/compare/v0.16.2...v0.16.3) (2023-07-11)
6
+
7
+
8
+ ### Features
9
+
10
+ * **ssr:** Handle new optional `SSR_CACHE_MAXAGE` and `SSR_CACHE_SWR` (bool) env vars ([f92155a](https://github.com/ecomplus/cloud-commerce/commit/f92155a9374ff9fa1337969c2097f4ebda93cb0f))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **ssr:** Properly write response body even with headers sent ([b4cd667](https://github.com/ecomplus/cloud-commerce/commit/b4cd667fd500bbfd72946423f3f316f3236a86ec))
16
+
17
+ ### [0.16.2](https://github.com/ecomplus/cloud-commerce/compare/v0.16.1...v0.16.2) (2023-07-11)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **ssr:** Use `writeHead` middleware to set X-SSR-Took header ([cdee5c5](https://github.com/ecomplus/cloud-commerce/commit/cdee5c54680ca5f28d48a286f407946781eebc14))
23
+
5
24
  ### [0.16.1](https://github.com/ecomplus/cloud-commerce/compare/v0.16.0...v0.16.1) (2023-07-11)
6
25
 
7
26
 
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
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.3",
5
5
  "description": "E-Com Plus Cloud Commerce customers authentication (passport) API",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,14 +1,21 @@
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
- const { STOREFRONT_BASE_DIR } = process.env;
6
+ const { STOREFRONT_BASE_DIR, SSR_CACHE_MAXAGE, SSR_CACHE_SWR } = process.env;
6
7
  const baseDir = STOREFRONT_BASE_DIR || process.cwd();
8
+ const cacheMaxAge = SSR_CACHE_MAXAGE ? Number(SSR_CACHE_MAXAGE) : 1000 * 60 * 2;
9
+ const isCacheSWR = SSR_CACHE_SWR ? String(SSR_CACHE_SWR).toLowerCase() === 'true' : true;
7
10
  const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
8
11
  let imagesManifest;
9
12
  const builtImages = [];
10
13
 
11
- export default (req, res) => {
14
+ export default async (req, res) => {
15
+ if (req.path.startsWith('/~partytown')) {
16
+ res.sendStatus(404);
17
+ return;
18
+ }
12
19
  res.set('X-XSS-Protection', '1; mode=block');
13
20
  const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
14
21
  const setStatusAndCache = (status, cacheControl) => {
@@ -69,20 +76,93 @@ export default (req, res) => {
69
76
  res.sendStatus(400);
70
77
  return;
71
78
  }
72
- const ssrStartedAt = Date.now();
73
- const _end = res.end;
79
+ const startedAt = Date.now();
80
+ let ssrStartedAt;
81
+ let status;
82
+ let headers = {};
83
+ const chunks = [];
84
+ /*
85
+ Check Response methods used by Astro Node.js integration:
86
+ https://github.com/withastro/astro/blob/main/packages/integrations/node/src/nodeMiddleware.ts
87
+ */
88
+ const _writeHead = res.writeHead;
74
89
  /* eslint-disable prefer-rest-params */
75
90
  // @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);
91
+ res.writeHead = function writeHead(_status, _headers) {
92
+ _headers['X-Function-Took'] = String(Date.now() - startedAt);
93
+ if (ssrStartedAt) {
94
+ _headers['X-SSR-Took'] = String(Date.now() - ssrStartedAt);
95
+ }
96
+ if (!res.headersSent) {
97
+ // @ts-ignore
98
+ _writeHead.apply(res, arguments);
99
+ }
100
+ status = _status;
101
+ headers = _headers;
102
+ };
103
+ let cacheRef;
104
+ let isBodySent = false;
105
+ if (!req.query.__noCache && req.path.charAt(1) !== '~') {
106
+ try {
107
+ const firestore = getFirestore();
108
+ const cacheKey = req.path.slice(1).replace(/\//g, '_') || '__home';
109
+ cacheRef = firestore.doc(`ssrCache/${cacheKey}`);
110
+ const cacheDoc = await cacheRef.get();
111
+ if (cacheDoc.exists) {
112
+ const {
113
+ headers: cachedHeaders, status: cachedStatus, body: cachedBody, __timestamp,
114
+ } = cacheDoc.data();
115
+ const isFresh = (Timestamp.now().toMillis() - __timestamp.toMillis()) < cacheMaxAge;
116
+ if (isFresh || isCacheSWR) {
117
+ cachedHeaders['X-SWR-Date'] = (isFresh ? 'fresh ' : '')
118
+ + __timestamp.toDate().toISOString();
119
+ res.writeHead(cachedStatus || 200, cachedHeaders);
120
+ res.send(cachedBody);
121
+ isBodySent = true;
122
+ }
123
+ if (isFresh) {
124
+ return;
125
+ }
126
+ }
127
+ } catch (err) {
128
+ cacheRef = null;
129
+ logger.warn(err);
130
+ }
131
+ }
132
+ const _write = res.write;
133
+ // @ts-ignore
134
+ res.write = function write(chunk) {
135
+ if (!isBodySent) {
136
+ // @ts-ignore
137
+ _write.apply(res, arguments);
138
+ }
139
+ chunks.push(chunk);
140
+ };
141
+ const _end = res.end;
142
+ // @ts-ignore
143
+ res.end = function end() {
144
+ if (!isBodySent) {
145
+ // @ts-ignore
146
+ _end.apply(res, arguments);
147
+ }
148
+ if (!status) {
149
+ status = res.statusCode;
150
+ }
151
+ if (cacheRef && status === 200) {
152
+ cacheRef.set({
153
+ headers,
154
+ status,
155
+ body: Buffer.concat(chunks).toString('utf8'),
156
+ __timestamp: Timestamp.now(),
157
+ }).catch(logger.warn);
158
+ }
80
159
  };
81
160
  /*
82
161
  https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
83
162
  import { handler as renderStorefront } from '../dist/server/entry.mjs';
84
163
  global.$renderStorefront = renderStorefront;
85
164
  */
165
+ ssrStartedAt = Date.now();
86
166
  global.$renderStorefront(req, res, async (err) => {
87
167
  if (err) {
88
168
  if (res.headersSent) {
@@ -1 +1 @@
1
- {"version":3,"file":"serve-storefront.js","sourceRoot":"","sources":["../../src/firebase/serve-storefront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G,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.3",
5
5
  "description": "E-Com Plus Cloud Commerce storefront SSR",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -1,6 +1,9 @@
1
+ import type { OutgoingHttpHeaders } from 'node:http';
1
2
  import type { Request, Response } from 'firebase-functions';
3
+ import type { DocumentReference } from 'firebase-admin/firestore';
2
4
  import { join as joinPath } from 'node:path';
3
5
  import { readFile } from 'node:fs/promises';
6
+ import { getFirestore, Timestamp } from 'firebase-admin/firestore';
4
7
  import logger from 'firebase-functions/logger';
5
8
 
6
9
  declare global {
@@ -12,14 +15,25 @@ declare global {
12
15
  ) => Promise<any>;
13
16
  }
14
17
 
15
- const { STOREFRONT_BASE_DIR } = process.env;
18
+ const {
19
+ STOREFRONT_BASE_DIR,
20
+ SSR_CACHE_MAXAGE,
21
+ SSR_CACHE_SWR,
22
+ } = process.env;
16
23
  const baseDir = STOREFRONT_BASE_DIR || process.cwd();
24
+ const cacheMaxAge = SSR_CACHE_MAXAGE ? Number(SSR_CACHE_MAXAGE) : 1000 * 60 * 2;
25
+ const isCacheSWR = SSR_CACHE_SWR ? String(SSR_CACHE_SWR).toLowerCase() === 'true' : true;
26
+
17
27
  const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
18
28
  let imagesManifest: string;
19
29
  type BuiltImage = { filename: string, width: number, height: number };
20
30
  const builtImages: BuiltImage[] = [];
21
31
 
22
- export default (req: Request, res: Response) => {
32
+ export default async (req: Request, res: Response) => {
33
+ if (req.path.startsWith('/~partytown')) {
34
+ res.sendStatus(404);
35
+ return;
36
+ }
23
37
  res.set('X-XSS-Protection', '1; mode=block');
24
38
  const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
25
39
 
@@ -84,14 +98,91 @@ export default (req: Request, res: Response) => {
84
98
  return;
85
99
  }
86
100
 
87
- const ssrStartedAt = Date.now();
88
- const _end = res.end;
101
+ const startedAt = Date.now();
102
+ let ssrStartedAt: number | undefined;
103
+ let status: number;
104
+ let headers: OutgoingHttpHeaders = {};
105
+ const chunks: any[] = [];
106
+ /*
107
+ Check Response methods used by Astro Node.js integration:
108
+ https://github.com/withastro/astro/blob/main/packages/integrations/node/src/nodeMiddleware.ts
109
+ */
110
+ const _writeHead = res.writeHead;
89
111
  /* eslint-disable prefer-rest-params */
90
112
  // @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);
113
+ res.writeHead = function writeHead(_status: number, _headers: OutgoingHttpHeaders) {
114
+ _headers['X-Function-Took'] = String(Date.now() - startedAt);
115
+ if (ssrStartedAt) {
116
+ _headers['X-SSR-Took'] = String(Date.now() - ssrStartedAt);
117
+ }
118
+ if (!res.headersSent) {
119
+ // @ts-ignore
120
+ _writeHead.apply(res, arguments);
121
+ }
122
+ status = _status;
123
+ headers = _headers;
124
+ };
125
+
126
+ let cacheRef: DocumentReference<any> | undefined | null;
127
+ let isBodySent = false;
128
+ if (!req.query.__noCache && req.path.charAt(1) !== '~') {
129
+ try {
130
+ const firestore = getFirestore();
131
+ const cacheKey = req.path.slice(1).replace(/\//g, '_') || '__home';
132
+ cacheRef = firestore.doc(`ssrCache/${cacheKey}`);
133
+ const cacheDoc = await cacheRef.get();
134
+ if (cacheDoc.exists) {
135
+ const {
136
+ headers: cachedHeaders,
137
+ status: cachedStatus,
138
+ body: cachedBody,
139
+ __timestamp,
140
+ } = cacheDoc.data();
141
+ const isFresh = (Timestamp.now().toMillis() - __timestamp.toMillis()) < cacheMaxAge;
142
+ if (isFresh || isCacheSWR) {
143
+ cachedHeaders['X-SWR-Date'] = (isFresh ? 'fresh ' : '')
144
+ + __timestamp.toDate().toISOString();
145
+ res.writeHead(cachedStatus || 200, cachedHeaders);
146
+ res.send(cachedBody);
147
+ isBodySent = true;
148
+ }
149
+ if (isFresh) {
150
+ return;
151
+ }
152
+ }
153
+ } catch (err) {
154
+ cacheRef = null;
155
+ logger.warn(err);
156
+ }
157
+ }
158
+
159
+ const _write = res.write;
160
+ // @ts-ignore
161
+ res.write = function write(chunk: any) {
162
+ if (!isBodySent) {
163
+ // @ts-ignore
164
+ _write.apply(res, arguments);
165
+ }
166
+ chunks.push(chunk);
167
+ };
168
+ const _end = res.end;
169
+ // @ts-ignore
170
+ res.end = function end() {
171
+ if (!isBodySent) {
172
+ // @ts-ignore
173
+ _end.apply(res, arguments);
174
+ }
175
+ if (!status) {
176
+ status = res.statusCode;
177
+ }
178
+ if (cacheRef && status === 200) {
179
+ cacheRef.set({
180
+ headers,
181
+ status,
182
+ body: Buffer.concat(chunks).toString('utf8'),
183
+ __timestamp: Timestamp.now(),
184
+ }).catch(logger.warn);
185
+ }
95
186
  };
96
187
 
97
188
  /*
@@ -99,6 +190,7 @@ export default (req: Request, res: Response) => {
99
190
  import { handler as renderStorefront } from '../dist/server/entry.mjs';
100
191
  global.$renderStorefront = renderStorefront;
101
192
  */
193
+ ssrStartedAt = Date.now();
102
194
  global.$renderStorefront(req, res, async (err: any) => {
103
195
  if (err) {
104
196
  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","/home/leo/code/ecomplus/cloud-commerce/node_modules/workbox-window/build/workbox-window.prod.es5.mjs":"_astro/workbox-window.prod.es5.a7b12eab.js","@astrojs/vue/client.js":"_astro/client.2d950540.js","~/components/PitchBar.vue":"_astro/PitchBar.c53e6d0b.js","/astro/hoisted.js?q=0":"_astro/hoisted.9d9d7ac4.js","~/components/HeroSlider.vue":"_astro/HeroSlider.3d4a1d1c.js","~/components/ProductShelf.vue":"_astro/ProductShelf.f013b3ee.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.3",
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.3",
5
5
  "description": "E-Com Plus Cloud Commerce reusable type definitions",
6
6
  "main": "index.ts",
7
7
  "repository": {