cloudcommerce 2.4.1 → 2.4.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.
- package/CHANGELOG.md +18 -0
- package/ecomplus-stores/barradoce/functions/many/package.json +3 -3
- package/ecomplus-stores/barradoce/functions/ssr/package.json +6 -6
- package/ecomplus-stores/barradoce/functions/ssr/src/pages/admin/index.astro +23 -0
- package/ecomplus-stores/barradoce/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/barradoce/package.json +2 -2
- package/package.json +5 -5
- package/packages/api/package.json +1 -1
- package/packages/apps/affiliate-program/package.json +2 -2
- package/packages/apps/correios/package.json +3 -3
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +2 -2
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +2 -2
- package/packages/apps/fb-conversions/package.json +2 -2
- package/packages/apps/flash-courier/package.json +2 -2
- package/packages/apps/frenet/package.json +2 -2
- package/packages/apps/galaxpay/package.json +2 -2
- package/packages/apps/google-analytics/package.json +2 -2
- package/packages/apps/jadlog/package.json +1 -1
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mandae/package.json +2 -2
- package/packages/apps/melhor-envio/package.json +2 -2
- package/packages/apps/mercadopago/package.json +2 -2
- package/packages/apps/pagarme/package.json +3 -3
- package/packages/apps/pagarme-v5/package.json +2 -2
- package/packages/apps/paghiper/package.json +2 -2
- package/packages/apps/pix/package.json +2 -2
- package/packages/apps/tiny-erp/package.json +2 -2
- package/packages/apps/webhooks/package.json +2 -2
- package/packages/cli/ci/bunny-config-base.sh +2 -0
- package/packages/cli/package.json +2 -2
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +1 -1
- package/packages/eslint/package.json +4 -4
- package/packages/events/package.json +2 -2
- package/packages/feeds/package.json +1 -1
- package/packages/firebase/package.json +4 -4
- package/packages/i18n/package.json +1 -1
- package/packages/modules/package.json +2 -2
- package/packages/passport/package.json +2 -2
- package/packages/ssr/package.json +4 -4
- package/packages/storefront/package.json +8 -8
- package/packages/storefront/src/decap-cms/gen-preview-container.ts +21 -49
- package/packages/storefront/src/decap-cms/preview/ssr-package.ts +14160 -0
- package/packages/storefront/src/decap-cms/preview/webcontainer.ts +55 -93
- package/packages/storefront/src/lib/layouts/BaseBody.astro +13 -0
- package/packages/storefront/src/lib/pages/admin.astro +0 -0
- package/packages/storefront/src/lib/scripts/decap-cms.ts +4 -16
- package/packages/test-base/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/storefront/src/decap-cms/preview/indexeddb.ts +0 -51
|
@@ -1,69 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { WebContainer } from '@webcontainer/api';
|
|
2
|
+
import { json as frozenSsrPkgJson, lock as frozenSsrPkgLock } from './ssr-package';
|
|
3
3
|
|
|
4
|
-
export const genContainerFiles = ({ repo, ghToken }: {
|
|
4
|
+
export const genContainerFiles = ({ repo, ghToken, repoDir }: {
|
|
5
5
|
repo: string,
|
|
6
6
|
ghToken?: string,
|
|
7
|
+
repoDir: string,
|
|
7
8
|
}) => ({
|
|
8
9
|
'git.js': {
|
|
9
10
|
file: {
|
|
10
11
|
contents: `
|
|
11
|
-
import { join } from 'path';
|
|
12
|
-
import { clone } from 'isomorphic-git';
|
|
13
|
-
import * as http from 'isomorphic-git/http/node/index.cjs';
|
|
14
12
|
import fs from 'node:fs';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
import { join as joinPath } from 'node:path';
|
|
14
|
+
import { clone, pull } from 'isomorphic-git';
|
|
15
|
+
import * as http from 'isomorphic-git/http/node/index.cjs';
|
|
16
|
+
const dir = joinPath(process.cwd(), '${repoDir}');
|
|
17
|
+
const isClone = process.argv.find((val) => val === '--clone');
|
|
18
|
+
const options = {
|
|
19
|
+
fs,
|
|
20
|
+
http,
|
|
21
|
+
dir,
|
|
22
|
+
singleBranch: true,
|
|
23
|
+
};
|
|
24
|
+
${(ghToken
|
|
26
25
|
? `
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
options.oauth2format = 'github';
|
|
27
|
+
options.token = '${ghToken}';`
|
|
29
28
|
: '')}
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
file: {
|
|
38
|
-
contents: `
|
|
39
|
-
import AdmZip from 'adm-zip';
|
|
40
|
-
const unzipDirectory = async (inputFilePath, outputDirectory) => {
|
|
41
|
-
const zip = new AdmZip(inputFilePath);
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
zip.extractAllToAsync(outputDirectory, true, (error) => {
|
|
44
|
-
if (error) {
|
|
45
|
-
console.error(error);
|
|
46
|
-
reject(error);
|
|
47
|
-
} else {
|
|
48
|
-
resolve();
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
await unzipDirectory('store.zip', 'store');
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
'zipper.js': {
|
|
58
|
-
file: {
|
|
59
|
-
contents: `
|
|
60
|
-
import AdmZip from 'adm-zip';
|
|
61
|
-
const zipDirectory = async (sourceDir, outputFilePath) => {
|
|
62
|
-
const zip = new AdmZip();
|
|
63
|
-
zip.addLocalFolder(sourceDir);
|
|
64
|
-
await zip.writeZipPromise(outputFilePath);
|
|
65
|
-
};
|
|
66
|
-
await zipDirectory('./store', './store.zip');
|
|
29
|
+
if (isClone) {
|
|
30
|
+
options.url = 'https://github.com/${repo}.git';
|
|
31
|
+
options.depth = 1;
|
|
32
|
+
clone(options);
|
|
33
|
+
} else {
|
|
34
|
+
pull(options);
|
|
35
|
+
}
|
|
67
36
|
`,
|
|
68
37
|
},
|
|
69
38
|
},
|
|
@@ -76,67 +45,60 @@ await zipDirectory('./store', './store.zip');
|
|
|
76
45
|
"type": "module",
|
|
77
46
|
"private": true,
|
|
78
47
|
"description": "",
|
|
79
|
-
"main": "index.js",
|
|
80
48
|
"author": "",
|
|
81
49
|
"license": "ISC",
|
|
82
50
|
"scripts": {
|
|
83
|
-
"
|
|
84
|
-
"git": "node git.js"
|
|
85
|
-
"unzipper": "node unzipper.js",
|
|
86
|
-
"zipper": "node zipper.js"
|
|
51
|
+
"git:clone": "node git.js --clone",
|
|
52
|
+
"git:pull": "node git.js --pull"
|
|
87
53
|
},
|
|
88
54
|
"dependencies": {
|
|
89
|
-
"
|
|
90
|
-
"adm-zip": "^0.5.10",
|
|
91
|
-
"axios": "^1.6.2",
|
|
92
|
-
"isomorphic-git": "^1.25.2"
|
|
55
|
+
"isomorphic-git": "^1.25.3"
|
|
93
56
|
}
|
|
94
57
|
}`,
|
|
95
58
|
},
|
|
96
59
|
},
|
|
97
60
|
});
|
|
98
61
|
|
|
99
|
-
export const initWebcontainer = async ({
|
|
100
|
-
repo,
|
|
101
|
-
ghToken,
|
|
102
|
-
WebContainer,
|
|
103
|
-
cliTextarea,
|
|
104
|
-
}: {
|
|
62
|
+
export const initWebcontainer = async ({ repo, ghToken, cliTextarea }: {
|
|
105
63
|
repo: string,
|
|
106
64
|
ghToken?: string,
|
|
107
|
-
WebContainer: Record<string, any>,
|
|
108
65
|
cliTextarea: HTMLTextAreaElement,
|
|
109
66
|
}) => {
|
|
110
|
-
const webcontainerInstance
|
|
111
|
-
const
|
|
67
|
+
const webcontainerInstance = await WebContainer.boot();
|
|
68
|
+
const repoDir = 'store';
|
|
69
|
+
const files = genContainerFiles({ repo, ghToken, repoDir });
|
|
112
70
|
await webcontainerInstance.mount(files);
|
|
113
71
|
const exec = async (command: string, args: string[]) => {
|
|
114
72
|
const cliArgs = args.reduce((acc, opt) => `${acc} ${opt}`, '');
|
|
115
73
|
const cli = `$ ${command}${cliArgs}\n`;
|
|
116
74
|
cliTextarea.value += cli;
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
75
|
+
const proc = await webcontainerInstance.spawn(command, args);
|
|
76
|
+
if (import.meta.env.DEV || (window as any).DEBUG) {
|
|
77
|
+
proc.output.pipeTo(new WritableStream({
|
|
78
|
+
write(stdout) {
|
|
79
|
+
console.debug?.('webcontainer', { stdout });
|
|
80
|
+
},
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
if (await proc.exit !== 0) {
|
|
124
84
|
throw new Error(`${command} failed`);
|
|
125
85
|
}
|
|
126
86
|
};
|
|
127
87
|
await exec('npm', ['install']);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
88
|
+
await exec('npm', ['run', 'git:clone']);
|
|
89
|
+
await exec('npm', ['--prefix', repoDir, 'ci']);
|
|
90
|
+
const ssrDir = `${repoDir}/functions/ssr`;
|
|
91
|
+
webcontainerInstance.fs.writeFile(`${ssrDir}/package.json`, frozenSsrPkgJson);
|
|
92
|
+
webcontainerInstance.fs.writeFile(`${ssrDir}/package-lock.json`, frozenSsrPkgLock);
|
|
93
|
+
await exec('npm', ['--prefix', ssrDir, 'ci']);
|
|
94
|
+
await webcontainerInstance.fs.writeFile(
|
|
95
|
+
`${ssrDir}/.env`,
|
|
96
|
+
`ECOM_STORE_ID=${window.ECOM_STORE_ID}\n`,
|
|
97
|
+
);
|
|
98
|
+
const startDevServer = async () => {
|
|
99
|
+
await exec('npm', ['--prefix', repoDir, 'run', 'dev']);
|
|
100
|
+
// Keep restarting dev server (can crash)
|
|
101
|
+
// startDevServer();
|
|
140
102
|
};
|
|
141
103
|
return {
|
|
142
104
|
webcontainerInstance,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
+
import * as url from 'node:url';
|
|
3
|
+
import { join as joinPath } from 'node:path';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
2
5
|
import '@@sf/assets/reset.css';
|
|
3
6
|
import '@@sf/assets/base.css';
|
|
4
7
|
import '@@sf/assets/forms.css';
|
|
@@ -7,6 +10,15 @@ import '@@sf/assets/tooltip.css';
|
|
|
7
10
|
// import 'uno.css';
|
|
8
11
|
import Picture from '@@sf/components/Picture.astro';
|
|
9
12
|
|
|
13
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
14
|
+
const pkgJson = readFileSync(joinPath(__dirname, '../../../package.json'), 'utf-8');
|
|
15
|
+
const {
|
|
16
|
+
name: pkgName,
|
|
17
|
+
version: pkgVersion,
|
|
18
|
+
} = JSON.parse(pkgJson);
|
|
19
|
+
const getInlineVersionLog = () => {
|
|
20
|
+
return `console.log('%c${pkgName} v${pkgVersion}', 'font-weight:bold')`;
|
|
21
|
+
};
|
|
10
22
|
const { settings } = Astro.locals.routeContext;
|
|
11
23
|
---
|
|
12
24
|
|
|
@@ -28,4 +40,5 @@ const { settings } = Astro.locals.routeContext;
|
|
|
28
40
|
hasImg={false}
|
|
29
41
|
/>
|
|
30
42
|
}
|
|
43
|
+
<script is:inline set:html={getInlineVersionLog()} />
|
|
31
44
|
</body>
|
|
File without changes
|
|
@@ -6,18 +6,9 @@ import genPreviewContainer from '../../decap-cms/gen-preview-container';
|
|
|
6
6
|
let cmsConfig: Record<string, any> = getCmsConfig();
|
|
7
7
|
let ghToken: string | undefined;
|
|
8
8
|
const initCmsWithPreview = () => {
|
|
9
|
-
const { React, CMS
|
|
10
|
-
React: any,
|
|
11
|
-
CMS: Record<string, any>,
|
|
12
|
-
WebContainer: any,
|
|
13
|
-
};
|
|
9
|
+
const { React, CMS } = window as any;
|
|
14
10
|
CMS.init({ config: cmsConfig });
|
|
15
|
-
const Preview = genPreviewContainer({
|
|
16
|
-
React,
|
|
17
|
-
WebContainer,
|
|
18
|
-
cmsConfig,
|
|
19
|
-
ghToken,
|
|
20
|
-
});
|
|
11
|
+
const Preview = genPreviewContainer({ React, cmsConfig, ghToken });
|
|
21
12
|
CMS.registerPreviewTemplate('general', Preview);
|
|
22
13
|
};
|
|
23
14
|
|
|
@@ -69,7 +60,7 @@ const authAndInitCms = async () => {
|
|
|
69
60
|
...cmsConfig.backend,
|
|
70
61
|
};
|
|
71
62
|
if (cmsConfig.backend.api_root?.startsWith('https://ecomplus.app/')) {
|
|
72
|
-
const res = await afetch('https://ecomplus.app/api/github-
|
|
63
|
+
const res = await afetch('https://ecomplus.app/api/github-installations', {
|
|
73
64
|
headers: {
|
|
74
65
|
'X-Store-ID': `${ECOM_STORE_ID}`,
|
|
75
66
|
Authorization: `Bearer ${ssoToken}`,
|
|
@@ -138,13 +129,10 @@ if (!import.meta.env.SSR) {
|
|
|
138
129
|
import(/* @vite-ignore */ 'https://esm.sh/react@^18'),
|
|
139
130
|
// @ts-ignore
|
|
140
131
|
import(/* @vite-ignore */ 'https://esm.sh/decap-cms-app@^3'),
|
|
141
|
-
// @ts-ignore
|
|
142
|
-
import(/* @vite-ignore */ 'https://esm.sh/@webcontainer/api@^1'),
|
|
143
132
|
])
|
|
144
|
-
.then(([React, { default: CMS }
|
|
133
|
+
.then(([React, { default: CMS }]) => {
|
|
145
134
|
(window as any).React = React;
|
|
146
135
|
(window as any).CMS = CMS;
|
|
147
|
-
(window as any).WebContainer = WebContainer;
|
|
148
136
|
authAndInitCms();
|
|
149
137
|
})
|
|
150
138
|
.catch((err) => {
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
let db: IDBDatabase;
|
|
2
|
-
const storeName = 'repo';
|
|
3
|
-
|
|
4
|
-
export const startingDb = new Promise<IDBDatabase>((resolve, reject) => {
|
|
5
|
-
const openRequest = indexedDB.open('ecomplus', 2);
|
|
6
|
-
openRequest.onerror = () => {
|
|
7
|
-
reject(new Error('Why didn\'t you allow my web app to use IndexedDB?!'));
|
|
8
|
-
};
|
|
9
|
-
openRequest.onsuccess = (ev) => {
|
|
10
|
-
db = (ev.target as any).result;
|
|
11
|
-
resolve(db!);
|
|
12
|
-
};
|
|
13
|
-
openRequest.onupgradeneeded = (ev) => {
|
|
14
|
-
db = (ev.target as any).result;
|
|
15
|
-
db!.createObjectStore(storeName, { keyPath: 'sha' });
|
|
16
|
-
resolve(db!);
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export class RepoDatabase {
|
|
21
|
-
objectKey = '';
|
|
22
|
-
data: any;
|
|
23
|
-
constructor(repo: string) {
|
|
24
|
-
this.objectKey = repo;
|
|
25
|
-
}
|
|
26
|
-
async put(sha: string, zip: any) {
|
|
27
|
-
await startingDb;
|
|
28
|
-
const data = this.data || {};
|
|
29
|
-
data.sha = sha;
|
|
30
|
-
data.zip = zip;
|
|
31
|
-
const tx = db.transaction([storeName], 'readwrite');
|
|
32
|
-
const objectStore = tx.objectStore(storeName);
|
|
33
|
-
console.log({ data });
|
|
34
|
-
objectStore.put(data, this.objectKey);
|
|
35
|
-
}
|
|
36
|
-
async get(sha: string) {
|
|
37
|
-
await startingDb;
|
|
38
|
-
const tx = db.transaction([storeName]);
|
|
39
|
-
const objectStore = tx.objectStore(storeName);
|
|
40
|
-
const request = objectStore.get(this.objectKey);
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
request.onerror = (error) => {
|
|
43
|
-
reject(error);
|
|
44
|
-
};
|
|
45
|
-
request.onsuccess = (ev) => {
|
|
46
|
-
this.data = (ev.target as any).result;
|
|
47
|
-
resolve(sha === this.data?.sha ? this.data.zip : null);
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|