cloudcommerce 0.0.67 → 0.0.70
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.
- package/CHANGELOG.md +29 -0
- package/package.json +1 -1
- package/packages/api/lib/api.js +8 -8
- package/packages/api/lib/api.js.map +1 -1
- package/packages/api/package.json +1 -1
- package/packages/api/src/api.ts +8 -8
- package/packages/apps/correios/package.json +3 -3
- package/packages/apps/custom-shipping/package.json +3 -3
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/cli/config/firebase.json +6 -6
- package/packages/cli/package.json +1 -1
- package/packages/config/lib/config.js +4 -1
- package/packages/config/lib/config.js.map +1 -1
- package/packages/config/lib/env.js +4 -1
- package/packages/config/lib/env.js.map +1 -1
- package/packages/config/package.json +1 -1
- package/packages/config/src/config.ts +7 -3
- package/packages/config/src/env.ts +4 -1
- package/packages/events/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/passport/package.json +1 -1
- package/packages/ssr/lib/firebase/serve-storefront.js +67 -0
- package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -0
- package/packages/ssr/lib/firebase.js +4 -3
- package/packages/ssr/lib/firebase.js.map +1 -1
- package/packages/ssr/lib/index.js +3 -0
- package/packages/ssr/lib/index.js.map +1 -1
- package/packages/ssr/package.json +1 -2
- package/packages/ssr/src/firebase/serve-storefront.ts +78 -0
- package/packages/ssr/src/firebase.ts +4 -3
- package/packages/ssr/src/index.ts +3 -0
- package/packages/storefront/astro.config.mjs +5 -0
- package/packages/storefront/dist/client/assets/{_...d4aa8aff.css → 404-_...d4aa8aff.css} +0 -0
- package/packages/storefront/dist/client/assets/404-index.d9230d24.css +1 -0
- package/packages/storefront/dist/client/assets/{_...0b5ebd52.css → 404.530428e5.css} +1 -1
- package/packages/storefront/dist/client/assets/_...98510c96.css +1 -0
- package/packages/storefront/dist/client/assets/index.53a3a3e0.css +1 -0
- package/packages/storefront/dist/server/entry.mjs +275 -135
- package/packages/storefront/example.env +2 -0
- package/packages/storefront/package.json +8 -2
- package/packages/storefront/src/layouts/Layout.astro +7 -0
- package/packages/storefront/src/pages/404.astro +74 -0
- package/packages/storefront/src/pages/[...slug].astro +11 -5
- package/packages/{ssr/src/firebase/.gitkeep → storefront/src/pages/app/index.astro} +0 -0
- package/packages/storefront/src/pages/index.astro +2 -2
- package/packages/storefront/src/types.ts +18 -0
- package/packages/storefront/storefront.config.mjs +41 -0
- package/packages/types/package.json +1 -1
- package/turbo.json +6 -0
- package/packages/storefront/content/blog.json +0 -18
- package/packages/storefront/content/brands.json +0 -24
- package/packages/storefront/content/categories.json +0 -24
- package/packages/storefront/content/code.json +0 -5
- package/packages/storefront/content/collections.json +0 -24
- package/packages/storefront/content/contacts.json +0 -13
- package/packages/storefront/content/footer.json +0 -46
- package/packages/storefront/content/header.json +0 -27
- package/packages/storefront/content/home.json +0 -45
- package/packages/storefront/content/info.json +0 -18
- package/packages/storefront/content/maintenance.json +0 -6
- package/packages/storefront/content/menu.json +0 -6
- package/packages/storefront/content/pages/contato.json +0 -6
- package/packages/storefront/content/pages/entrega.json +0 -6
- package/packages/storefront/content/pages/faq.json +0 -6
- package/packages/storefront/content/pages/pagamentos.json +0 -6
- package/packages/storefront/content/pages/privacidade.json +0 -6
- package/packages/storefront/content/pages/sobre-nos.json +0 -6
- package/packages/storefront/content/pages/termos.json +0 -6
- package/packages/storefront/content/pages/trocas.json +0 -6
- package/packages/storefront/content/posts/esta-loja-e-um-pwa.json +0 -9
- package/packages/storefront/content/products.json +0 -32
- package/packages/storefront/content/search.json +0 -8
- package/packages/storefront/content/settings.json +0 -25
- package/packages/storefront/content/social.json +0 -5
- package/packages/storefront/content/widgets/analytics.json +0 -11
- package/packages/storefront/content/widgets/compre-confie.json +0 -11
- package/packages/storefront/content/widgets/ebit.json +0 -11
- package/packages/storefront/content/widgets/fb-pixel.json +0 -12
- package/packages/storefront/content/widgets/gmc-ratings.json +0 -12
- package/packages/storefront/content/widgets/minicart.json +0 -6
- package/packages/storefront/content/widgets/offers-notification.json +0 -11
- package/packages/storefront/content/widgets/opinioes-verificadas.json +0 -18
- package/packages/storefront/content/widgets/product-card.json +0 -10
- package/packages/storefront/content/widgets/product.json +0 -13
- package/packages/storefront/content/widgets/search-engine.json +0 -8
- package/packages/storefront/content/widgets/search.json +0 -6
- package/packages/storefront/content/widgets/tag-manager.json +0 -12
- package/packages/storefront/content/widgets/tawkto.json +0 -12
- package/packages/storefront/content/widgets/trustvox.json +0 -15
- package/packages/storefront/content/widgets/user.json +0 -5
- package/packages/storefront/dist/client/assets/index.5608ba47.css +0 -1
- package/packages/storefront/src/storefront-config.ts +0 -28
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
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.0.70](https://github.com/ecomplus/cloud-commerce/compare/v0.0.69...v0.0.70) (2022-09-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **storefront:** Replace pre/post pack scripts with pre/post release on `package.json` ([a9b28a9](https://github.com/ecomplus/cloud-commerce/commit/a9b28a96c41223c81c2b6979c9feffeb9879b8c8))
|
|
11
|
+
|
|
12
|
+
### [0.0.69](https://github.com/ecomplus/cloud-commerce/compare/v0.0.68...v0.0.69) (2022-09-07)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* **storefront:** Use `getConfig` function to properly handle env vars on `storefront.config.mjs` ([5bfdaea](https://github.com/ecomplus/cloud-commerce/commit/5bfdaea8454d8e2bdbd64bfbc49d6fbf798c2d9d))
|
|
18
|
+
|
|
19
|
+
### [0.0.68](https://github.com/ecomplus/cloud-commerce/compare/v0.0.67...v0.0.68) (2022-09-07)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **ssr:** Setup SSR handler from `@ecomplus/storefron-renderer` ([0370347](https://github.com/ecomplus/cloud-commerce/commit/0370347fad1e03e0f5cb2bf9067dd8f438d8dd45))
|
|
25
|
+
* **storefront:** Load CMS content from Store dir ([1ad443c](https://github.com/ecomplus/cloud-commerce/commit/1ad443cbbf03bc3da7cee27ae085c751239eda12))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **cli:** Update Hosting public dir to Astro build default client output ([900de0d](https://github.com/ecomplus/cloud-commerce/commit/900de0d95517ac06ee101812d1b5330bca534ae8))
|
|
31
|
+
* **cli:** Update SSR function predeploy to also run `astro build` ([547e698](https://github.com/ecomplus/cloud-commerce/commit/547e698af86f69099d5f5bf37d52af394cc80838))
|
|
32
|
+
* **env:** Test `import.meta.env` to support Astro/Vite env variables ([bbfef3d](https://github.com/ecomplus/cloud-commerce/commit/bbfef3d92ed2bf8073279461613270709b3e76f5))
|
|
33
|
+
|
|
5
34
|
### [0.0.67](https://github.com/ecomplus/cloud-commerce/compare/v0.0.66...v0.0.67) (2022-09-05)
|
|
6
35
|
|
|
7
36
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcommerce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.70",
|
|
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>",
|
package/packages/api/lib/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
const
|
|
3
|
-
|| (typeof process === 'object' && process
|
|
4
|
-
||
|
|
2
|
+
const _env = import.meta.env
|
|
3
|
+
|| (typeof process === 'object' && process?.env)
|
|
4
|
+
|| globalThis;
|
|
5
5
|
class ApiError extends Error {
|
|
6
6
|
constructor(config, response, msg, isTimeout = false) {
|
|
7
7
|
if (response) {
|
|
@@ -24,8 +24,8 @@ const def = {
|
|
|
24
24
|
// eslint-disable-next-line dot-notation
|
|
25
25
|
headers['Authorization'] = `Bearer ${config.accessToken}`;
|
|
26
26
|
} else {
|
|
27
|
-
const authenticationId = config.authenticationId ||
|
|
28
|
-
const apiKey = config.apiKey ||
|
|
27
|
+
const authenticationId = config.authenticationId || _env.ECOM_AUTHENTICATION_ID;
|
|
28
|
+
const apiKey = config.apiKey || _env.ECOM_API_KEY;
|
|
29
29
|
if (authenticationId && apiKey) {
|
|
30
30
|
const rawAuth = `${authenticationId}:${apiKey}`;
|
|
31
31
|
const base64Auth = typeof Buffer === 'function'
|
|
@@ -35,18 +35,18 @@ const def = {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
let url = config.baseUrl ||
|
|
38
|
+
let url = config.baseUrl || _env.API_BASE_URL || 'https://ecomplus.io/v2';
|
|
39
39
|
const { endpoint, params } = config;
|
|
40
40
|
if (endpoint !== 'login'
|
|
41
41
|
&& endpoint !== 'authenticate'
|
|
42
42
|
&& endpoint !== 'ask-auth-callback'
|
|
43
43
|
&& endpoint !== 'check-username') {
|
|
44
|
-
const storeId = config.storeId ||
|
|
44
|
+
const storeId = config.storeId || _env.ECOM_STORE_ID;
|
|
45
45
|
if (!storeId) {
|
|
46
46
|
throw new Error('`storeId` must be set in config or `ECOM_STORE_ID` env var');
|
|
47
47
|
}
|
|
48
48
|
url += `/:${storeId}`;
|
|
49
|
-
const lang = config.lang ||
|
|
49
|
+
const lang = config.lang || _env.ECOM_LANG;
|
|
50
50
|
if (lang) {
|
|
51
51
|
url += `,lang:${lang}`;
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["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C,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;AAChB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;AAClB,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC;AACd,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;AAEjB,eAAe,GAAG,CAAC;AAEnB,OAAO,EACL,aAAa,EACb,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,QAAQ,GACT,CAAC"}
|
package/packages/api/src/api.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type {
|
|
|
8
8
|
} from './types';
|
|
9
9
|
|
|
10
10
|
// @ts-ignore
|
|
11
|
-
const
|
|
12
|
-
|| (typeof process === 'object' && process
|
|
13
|
-
||
|
|
11
|
+
const _env: Record<string, string> = import.meta.env
|
|
12
|
+
|| (typeof process === 'object' && process?.env)
|
|
13
|
+
|| globalThis;
|
|
14
14
|
|
|
15
15
|
class ApiError extends Error {
|
|
16
16
|
config: Config;
|
|
@@ -45,8 +45,8 @@ const def = {
|
|
|
45
45
|
// eslint-disable-next-line dot-notation
|
|
46
46
|
headers['Authorization'] = `Bearer ${config.accessToken}`;
|
|
47
47
|
} else {
|
|
48
|
-
const authenticationId = config.authenticationId ||
|
|
49
|
-
const apiKey = config.apiKey ||
|
|
48
|
+
const authenticationId = config.authenticationId || _env.ECOM_AUTHENTICATION_ID;
|
|
49
|
+
const apiKey = config.apiKey || _env.ECOM_API_KEY;
|
|
50
50
|
if (authenticationId && apiKey) {
|
|
51
51
|
const rawAuth = `${authenticationId}:${apiKey}`;
|
|
52
52
|
const base64Auth = typeof Buffer === 'function'
|
|
@@ -56,7 +56,7 @@ const def = {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
let url = config.baseUrl ||
|
|
59
|
+
let url = config.baseUrl || _env.API_BASE_URL || 'https://ecomplus.io/v2';
|
|
60
60
|
const { endpoint, params } = config;
|
|
61
61
|
if (
|
|
62
62
|
endpoint !== 'login'
|
|
@@ -64,12 +64,12 @@ const def = {
|
|
|
64
64
|
&& endpoint !== 'ask-auth-callback'
|
|
65
65
|
&& endpoint !== 'check-username'
|
|
66
66
|
) {
|
|
67
|
-
const storeId = config.storeId ||
|
|
67
|
+
const storeId = config.storeId || _env.ECOM_STORE_ID;
|
|
68
68
|
if (!storeId) {
|
|
69
69
|
throw new Error('`storeId` must be set in config or `ECOM_STORE_ID` env var');
|
|
70
70
|
}
|
|
71
71
|
url += `/:${storeId}`;
|
|
72
|
-
const lang = config.lang ||
|
|
72
|
+
const lang = config.lang || _env.ECOM_LANG;
|
|
73
73
|
if (lang) {
|
|
74
74
|
url += `,lang:${lang}`;
|
|
75
75
|
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-correios",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.70",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app for Correios shipping calculation",
|
|
6
6
|
"main": "lib/correios.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
10
|
-
"directory": "packages/correios"
|
|
10
|
+
"directory": "packages/apps/correios"
|
|
11
11
|
},
|
|
12
12
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
13
13
|
"license": "Apache 2.0 with Commons Clause",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/ecomplus/cloud-commerce/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/correios#readme",
|
|
17
|
+
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/correios#readme",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "sh ../../../scripts/build-lib.sh"
|
|
20
20
|
},
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/app-custom-shipping",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.70",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce app for custom shipping methods",
|
|
6
6
|
"main": "lib/custom-shipping.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/ecomplus/cloud-commerce.git",
|
|
10
|
-
"directory": "packages/custom-shipping"
|
|
10
|
+
"directory": "packages/apps/custom-shipping"
|
|
11
11
|
},
|
|
12
12
|
"author": "E-Com Club Softwares para E-commerce <ti@e-com.club>",
|
|
13
13
|
"license": "Apache 2.0 with Commons Clause",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/ecomplus/cloud-commerce/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/custom-shipping#readme",
|
|
17
|
+
"homepage": "https://github.com/ecomplus/cloud-commerce/tree/main/packages/apps/custom-shipping#readme",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "sh ../../../scripts/build-lib.sh"
|
|
20
20
|
},
|
|
@@ -5,33 +5,33 @@
|
|
|
5
5
|
},
|
|
6
6
|
"functions": [
|
|
7
7
|
{
|
|
8
|
-
"predeploy": "npm run build -- --codebase core
|
|
8
|
+
"predeploy": "npm run build -- --codebase core",
|
|
9
9
|
"source": "functions/core",
|
|
10
10
|
"codebase": "core"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
|
-
"predeploy": "npm run build -- --codebase events
|
|
13
|
+
"predeploy": "npm run build -- --codebase events",
|
|
14
14
|
"source": "functions/events",
|
|
15
15
|
"codebase": "events"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
"predeploy": "npm run build -- --codebase modules
|
|
18
|
+
"predeploy": "npm run build -- --codebase modules",
|
|
19
19
|
"source": "functions/modules",
|
|
20
20
|
"codebase": "modules"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
"predeploy": "npm run build -- --codebase passport
|
|
23
|
+
"predeploy": "npm run build -- --codebase passport",
|
|
24
24
|
"source": "functions/passport",
|
|
25
25
|
"codebase": "passport"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
|
-
"predeploy": "npm run build -- --codebase ssr
|
|
28
|
+
"predeploy": "npm --prefix \"$RESOURCE_DIR\" run build && npm run build -- --codebase ssr",
|
|
29
29
|
"source": "functions/ssr",
|
|
30
30
|
"codebase": "ssr"
|
|
31
31
|
}
|
|
32
32
|
],
|
|
33
33
|
"hosting": {
|
|
34
|
-
"public": "
|
|
34
|
+
"public": "functions/ssr/dist/client",
|
|
35
35
|
"ignore": [
|
|
36
36
|
"firebase.json",
|
|
37
37
|
"**/.*",
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
DEFAULT_LANG, DEFAULT_CURRENCY, DEFAULT_CURRENCY_SYMBOL, DEFAULT_COUNTRY_CODE,
|
|
4
4
|
} from './defaults.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const _env = import.meta.env
|
|
8
|
+
|| (typeof process === 'object' && process?.env)
|
|
9
|
+
|| globalThis;
|
|
7
10
|
const deepmerge = Deepmerge();
|
|
8
11
|
const self = globalThis.__cloudCommerce || {
|
|
9
12
|
config: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAUpB,aAAa;AACb,MAAM,IAAI,GAAwB,MAAM,CAAC,IAAI,CAAC,GAAG;OAC5C,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,EAAE,GAAG,CAAC;OAC7C,UAAU,CAAC;AAEhB,MAAM,SAAS,GAAG,SAAS,EAAE,CAAC;AAE9B,MAAM,IAAI,GAA2B,UAAU,CAAC,eAAe,IAAI;IACjE,MAAM,EAAE;QACN,IAAI,EAAE,IAAI,CAAC,SAAS,IAAI,YAAY;QACpC,QAAQ,EAAE,IAAI,CAAC,aAAa,IAAI,gBAAgB;QAChD,cAAc,EAAE,IAAI,CAAC,oBAAoB,IAAI,uBAAuB;QACpE,WAAW,EAAE,IAAI,CAAC,iBAAiB,IAAI,oBAAoB;QAC3D,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC;KACpC;CACF,CAAC;AACF,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC;AAElC,eAAe;IACb,GAAG;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,GAAG,CAAC,MAAM;QACR,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7C,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;SACrC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AASA,MAAM,IAAI,GAAwB,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AASA,aAAa;AACb,MAAM,IAAI,GAAwB,MAAM,CAAC,IAAI,CAAC,GAAG;OAC5C,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,EAAE,GAAG,CAAC;OAC7C,UAAU,CAAC;AAEhB,eAAe,GAAG,EAAE;IAClB,MAAM,EACJ,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,YAAY,GACb,GAAG,IAAI,CAAC;IACT,MAAM,OAAO,GAAG,aAAa,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;KAC7D;IACD,IAAI,CAAC,sBAAsB,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;KAC5C;IACD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;IAChD,MAAM,MAAM,GAAG,YAAY,CAAC;IAC5B,MAAM,WAAW,GAAG,YAAY,CAAC;IACjC,MAAM,GAAG,GAAQ;QACf,OAAO;QACP,OAAO,EAAE;YACP,gBAAgB;YAChB,MAAM;SACP;QACD,WAAW;KACZ,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -6,9 +6,6 @@ import {
|
|
|
6
6
|
DEFAULT_COUNTRY_CODE,
|
|
7
7
|
} from './defaults';
|
|
8
8
|
|
|
9
|
-
const _env: Record<string, any> = (typeof process === 'object' && process?.env) || globalThis;
|
|
10
|
-
const deepmerge = Deepmerge();
|
|
11
|
-
|
|
12
9
|
type BaseConfig = {
|
|
13
10
|
lang: string,
|
|
14
11
|
currency: string,
|
|
@@ -17,6 +14,13 @@ type BaseConfig = {
|
|
|
17
14
|
storeId: number,
|
|
18
15
|
};
|
|
19
16
|
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const _env: Record<string, any> = import.meta.env
|
|
19
|
+
|| (typeof process === 'object' && process?.env)
|
|
20
|
+
|| globalThis;
|
|
21
|
+
|
|
22
|
+
const deepmerge = Deepmerge();
|
|
23
|
+
|
|
20
24
|
const self: { config: BaseConfig } = globalThis.__cloudCommerce || {
|
|
21
25
|
config: {
|
|
22
26
|
lang: _env.ECOM_LANG || DEFAULT_LANG,
|
|
@@ -7,7 +7,10 @@ type Env = {
|
|
|
7
7
|
githubToken?: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
const _env: Record<string, any> = import.meta.env
|
|
12
|
+
|| (typeof process === 'object' && process?.env)
|
|
13
|
+
|| globalThis;
|
|
11
14
|
|
|
12
15
|
export default () => {
|
|
13
16
|
const {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { join as joinPath } from 'path';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
|
|
4
|
+
const { STOREFRONT_BASE_DIR, STOREFRONT_LONG_CACHE } = process.env;
|
|
5
|
+
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
6
|
+
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
7
|
+
const isLongCache = String(STOREFRONT_LONG_CACHE).toLowerCase() === 'true';
|
|
8
|
+
|
|
9
|
+
export default (req, res) => {
|
|
10
|
+
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
11
|
+
const setStatusAndCache = (status, defaultCache) => {
|
|
12
|
+
return res.status(status)
|
|
13
|
+
.set('X-SSR-ID', `v1/${Math.random()}`)
|
|
14
|
+
.set('Cache-Control', (typeof global.cache_control === 'function' && global.cache_control(status))
|
|
15
|
+
|| defaultCache);
|
|
16
|
+
};
|
|
17
|
+
const redirect = (toUrl, status = 302) => {
|
|
18
|
+
let sMaxAge = status === 301 ? 360 : 12;
|
|
19
|
+
if (isLongCache) {
|
|
20
|
+
sMaxAge *= 10;
|
|
21
|
+
}
|
|
22
|
+
let cacheControl = `public, max-age=30, s-maxage=${sMaxAge}`;
|
|
23
|
+
if (status === 302) {
|
|
24
|
+
cacheControl += ', proxy-revalidate';
|
|
25
|
+
}
|
|
26
|
+
setStatusAndCache(status, cacheControl)
|
|
27
|
+
.set('Location', toUrl).end();
|
|
28
|
+
};
|
|
29
|
+
const fallback = (status = 404) => {
|
|
30
|
+
if (url.slice(-1) === '/') {
|
|
31
|
+
redirect(url.slice(0, -1));
|
|
32
|
+
} else if (url !== '/404' && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
33
|
+
setStatusAndCache(status, `public, max-age=${(isLongCache ? 120 : 30)}`)
|
|
34
|
+
.send('<html><head>'
|
|
35
|
+
+ `<meta http-equiv="refresh" content="0; url=/404?url=${encodeURIComponent(url)}"/>`
|
|
36
|
+
+ '</head><body></body></html>');
|
|
37
|
+
} else {
|
|
38
|
+
setStatusAndCache(status, isLongCache
|
|
39
|
+
? 'public, max-age=60, s-maxage=86400'
|
|
40
|
+
: 'public, max-age=60, s-maxage=300')
|
|
41
|
+
.end();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/*
|
|
45
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
46
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
47
|
+
global.ssr_handler = ssrHandler;
|
|
48
|
+
*/
|
|
49
|
+
global.ssr_handler(req, res, async (err) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
res.set('X-SSR-ERROR', err.stack);
|
|
52
|
+
fallback(500);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
56
|
+
try {
|
|
57
|
+
const data = await readFile(local);
|
|
58
|
+
setStatusAndCache(200, isLongCache
|
|
59
|
+
? 'public, max-age=60, s-maxage=604800'
|
|
60
|
+
: 'public, max-age=60, s-maxage=600, stale-while-revalidate=2592000')
|
|
61
|
+
.send(data);
|
|
62
|
+
} catch {
|
|
63
|
+
fallback();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
// # sourceMappingURL=serve-storefront.js.map
|
|
@@ -0,0 +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,MAAM,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,EACJ,mBAAmB,EACnB,qBAAqB,GACtB,GAAG,OAAO,CAAC,GAAG,CAAC;AAEhB,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,MAAM,WAAW,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AAE3E,eAAe,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;IAC7C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEhE,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,YAAoB,EAAE,EAAE;QACjE,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;aACtB,GAAG,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;aACtC,GAAG,CACF,eAAe,EACf,CAAC,OAAO,MAAM,CAAC,aAAa,KAAK,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;eACvE,YAAY,CAClB,CAA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CAAC;IAEF;;;;MAIE;IACF,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAQ,EAAE,EAAE;QAC9C,IAAI,GAAG,EAAE;YACP,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YAClC,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,WAAW;gBAChC,CAAC,CAAC,qCAAqC;gBACvC,CAAC,CAAC,kEAAkE,CAAC;iBACpE,IAAI,CAAC,IAAI,CAAC,CAAC;SACf;QAAC,MAAM;YACN,QAAQ,EAAE,CAAC;SACZ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -3,10 +3,11 @@ import '@cloudcommerce/firebase/lib/init';
|
|
|
3
3
|
// eslint-disable-next-line import/no-unresolved
|
|
4
4
|
import { onRequest } from 'firebase-functions/v2/https';
|
|
5
5
|
import config from '@cloudcommerce/firebase/lib/config';
|
|
6
|
+
import serveStorefront from './firebase/serve-storefront.js';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const { httpsFunctionOptions } = config.get();
|
|
8
9
|
|
|
9
|
-
export const ssr = onRequest(
|
|
10
|
-
|
|
10
|
+
export const ssr = onRequest(httpsFunctionOptions, (req, res) => {
|
|
11
|
+
serveStorefront(req, res);
|
|
11
12
|
});
|
|
12
13
|
// # sourceMappingURL=firebase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,MAAM,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../src/firebase.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,kCAAkC,CAAC;AAC1C,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;AAE9C,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS,CAAC,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9D,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,6BAA6B,CAAC;AAE1D,eAAe,eAAe,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.70",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront SSR",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@cloudcommerce/api": "workspace:*",
|
|
27
27
|
"@cloudcommerce/firebase": "workspace:*",
|
|
28
|
-
"@cloudcommerce/storefront": "workspace:*",
|
|
29
28
|
"firebase-admin": "^11.0.1",
|
|
30
29
|
"firebase-functions": "^3.23.0",
|
|
31
30
|
"source-map-support": "^0.5.21"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Request, Response } from 'firebase-functions';
|
|
2
|
+
import { join as joinPath } from 'path';
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
STOREFRONT_BASE_DIR,
|
|
7
|
+
STOREFRONT_LONG_CACHE,
|
|
8
|
+
} = process.env;
|
|
9
|
+
|
|
10
|
+
const baseDir = STOREFRONT_BASE_DIR || process.cwd();
|
|
11
|
+
const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url);
|
|
12
|
+
const isLongCache = String(STOREFRONT_LONG_CACHE).toLowerCase() === 'true';
|
|
13
|
+
|
|
14
|
+
export default (req: Request, res: Response) => {
|
|
15
|
+
const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, '');
|
|
16
|
+
|
|
17
|
+
const setStatusAndCache = (status: number, defaultCache: string) => {
|
|
18
|
+
return res.status(status)
|
|
19
|
+
.set('X-SSR-ID', `v1/${Math.random()}`)
|
|
20
|
+
.set(
|
|
21
|
+
'Cache-Control',
|
|
22
|
+
(typeof global.cache_control === 'function' && global.cache_control(status))
|
|
23
|
+
|| defaultCache,
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const redirect = (toUrl: string, status = 302) => {
|
|
28
|
+
let sMaxAge = status === 301 ? 360 : 12;
|
|
29
|
+
if (isLongCache) {
|
|
30
|
+
sMaxAge *= 10;
|
|
31
|
+
}
|
|
32
|
+
let cacheControl = `public, max-age=30, s-maxage=${sMaxAge}`;
|
|
33
|
+
if (status === 302) {
|
|
34
|
+
cacheControl += ', proxy-revalidate';
|
|
35
|
+
}
|
|
36
|
+
setStatusAndCache(status, cacheControl)
|
|
37
|
+
.set('Location', toUrl).end();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const fallback = (status = 404) => {
|
|
41
|
+
if (url.slice(-1) === '/') {
|
|
42
|
+
redirect(url.slice(0, -1));
|
|
43
|
+
} else if (url !== '/404' && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) {
|
|
44
|
+
setStatusAndCache(status, `public, max-age=${(isLongCache ? 120 : 30)}`)
|
|
45
|
+
.send('<html><head>'
|
|
46
|
+
+ `<meta http-equiv="refresh" content="0; url=/404?url=${encodeURIComponent(url)}"/>`
|
|
47
|
+
+ '</head><body></body></html>');
|
|
48
|
+
} else {
|
|
49
|
+
setStatusAndCache(status, isLongCache
|
|
50
|
+
? 'public, max-age=60, s-maxage=86400'
|
|
51
|
+
: 'public, max-age=60, s-maxage=300')
|
|
52
|
+
.end();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
https://github.com/withastro/astro/blob/main/examples/ssr/server/server.mjs
|
|
58
|
+
import { handler as ssrHandler } from '../dist/server/entry.mjs';
|
|
59
|
+
global.ssr_handler = ssrHandler;
|
|
60
|
+
*/
|
|
61
|
+
global.ssr_handler(req, res, async (err: any) => {
|
|
62
|
+
if (err) {
|
|
63
|
+
res.set('X-SSR-ERROR', err.stack);
|
|
64
|
+
fallback(500);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const local = new URL(`.${url}`, clientRoot);
|
|
68
|
+
try {
|
|
69
|
+
const data = await readFile(local);
|
|
70
|
+
setStatusAndCache(200, isLongCache
|
|
71
|
+
? 'public, max-age=60, s-maxage=604800'
|
|
72
|
+
: 'public, max-age=60, s-maxage=600, stale-while-revalidate=2592000')
|
|
73
|
+
.send(data);
|
|
74
|
+
} catch {
|
|
75
|
+
fallback();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|