shoplazza-cli 1.0.7-beta.1 → 1.0.7-beta.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 (99) hide show
  1. package/bin/shoplazza +5 -1
  2. package/lib/app/api/index.js +2 -2
  3. package/lib/app/commands/build.js +4 -4
  4. package/lib/app/commands/connect.js +73 -0
  5. package/lib/app/commands/create.js +1 -1
  6. package/lib/app/commands/deploy.js +4 -3
  7. package/lib/app/commands/release.js +59 -0
  8. package/lib/app/commands/serve.js +12 -11
  9. package/lib/app/commands/versions.js +10 -7
  10. package/lib/app/index.js +3 -0
  11. package/lib/app/template/basic-app/theme-app/blocks/index.liquid +3 -3
  12. package/lib/app/template/basic-app/theme-app/locales/ar-SA.json +1 -0
  13. package/lib/app/template/basic-app/theme-app/locales/de-DE.json +1 -0
  14. package/lib/app/template/basic-app/theme-app/locales/en-US.json +6 -0
  15. package/lib/app/template/basic-app/theme-app/locales/es-ES.json +1 -0
  16. package/lib/app/template/basic-app/theme-app/locales/fr-FR.json +1 -0
  17. package/lib/app/template/basic-app/theme-app/locales/id-ID.json +1 -0
  18. package/lib/app/template/basic-app/theme-app/locales/it-IT.json +1 -0
  19. package/lib/app/template/basic-app/theme-app/locales/ja-JP.json +1 -0
  20. package/lib/app/template/basic-app/theme-app/locales/ko-KR.json +1 -0
  21. package/lib/app/template/basic-app/theme-app/locales/nl-NL.json +1 -0
  22. package/lib/app/template/basic-app/theme-app/locales/pl-PL.json +1 -0
  23. package/lib/app/template/basic-app/theme-app/locales/pt-PT.json +1 -0
  24. package/lib/app/template/basic-app/theme-app/locales/ru-RU.json +1 -0
  25. package/lib/app/template/basic-app/theme-app/locales/th-TH.json +1 -0
  26. package/lib/app/template/basic-app/theme-app/locales/zh-CN.json +6 -0
  27. package/lib/app/template/basic-app/theme-app/locales/zh-TW.json +1 -0
  28. package/lib/app/template/basic-app/theme-app/snippets/index.liquid +1 -1
  29. package/lib/app/template/embed-app/theme-app/blocks/index.liquid +4 -4
  30. package/lib/app/template/embed-app/theme-app/locales/ar-SA.json +1 -3
  31. package/lib/app/template/embed-app/theme-app/locales/de-DE.json +1 -3
  32. package/lib/app/template/embed-app/theme-app/locales/en-US.json +4 -1
  33. package/lib/app/template/embed-app/theme-app/locales/es-ES.json +1 -3
  34. package/lib/app/template/embed-app/theme-app/locales/fr-FR.json +1 -3
  35. package/lib/app/template/embed-app/theme-app/locales/id-ID.json +1 -3
  36. package/lib/app/template/embed-app/theme-app/locales/it-IT.json +1 -3
  37. package/lib/app/template/embed-app/theme-app/locales/ja-JP.json +1 -3
  38. package/lib/app/template/embed-app/theme-app/locales/ko-KR.json +1 -3
  39. package/lib/app/template/embed-app/theme-app/locales/nl-NL.json +1 -3
  40. package/lib/app/template/embed-app/theme-app/locales/pl-PL.json +1 -3
  41. package/lib/app/template/embed-app/theme-app/locales/pt-PT.json +1 -3
  42. package/lib/app/template/embed-app/theme-app/locales/ru-RU.json +1 -3
  43. package/lib/app/template/embed-app/theme-app/locales/th-TH.json +1 -3
  44. package/lib/app/template/embed-app/theme-app/locales/zh-CN.json +4 -1
  45. package/lib/app/template/embed-app/theme-app/locales/zh-TW.json +1 -3
  46. package/lib/app/template/embed-app/theme-app/snippets/index.liquid +1 -1
  47. package/lib/app/utils/config.js +3 -3
  48. package/lib/app/utils/index.js +8 -8
  49. package/lib/auth/getCode.js +2 -2
  50. package/lib/auth/index.js +2 -2
  51. package/lib/check.js +26 -0
  52. package/lib/checkout/api.js +1 -2
  53. package/lib/checkout/build.js +1 -1
  54. package/lib/checkout/create.js +1 -1
  55. package/lib/checkout/deploy.js +1 -1
  56. package/lib/checkout/dev/index.js +1 -1
  57. package/lib/checkout/fields.js +1 -1
  58. package/lib/checkout/preview.js +1 -1
  59. package/lib/checkout/push.js +1 -1
  60. package/lib/checkout/undeploy.js +1 -1
  61. package/lib/checkout/util.js +1 -1
  62. package/lib/checkout/verify.js +1 -1
  63. package/lib/commands/theme/delete.js +1 -1
  64. package/lib/commands/theme/package.js +1 -1
  65. package/lib/commands/theme/publish.js +1 -1
  66. package/lib/commands/theme/pull.js +1 -1
  67. package/lib/commands/theme/push.js +1 -1
  68. package/lib/commands/theme/serve.js +2 -2
  69. package/lib/common/login.js +1 -1
  70. package/lib/function/bin/index.js +20 -0
  71. package/lib/function/bin/javy/javy-arm-linux-v5.0.1 +0 -0
  72. package/lib/function/bin/javy/javy-arm-macos-v5.0.1 +0 -0
  73. package/lib/function/bin/javy/javy-x86_64-linux-v5.0.1 +0 -0
  74. package/lib/function/bin/javy/javy-x86_64-macos-v5.0.1 +0 -0
  75. package/lib/function/bin/javy/javy-x86_64-windows-v5.0.1 +0 -0
  76. package/lib/function/commands/compile.js +42 -0
  77. package/lib/function/commands/create.js +77 -0
  78. package/lib/function/commands/list.js +18 -0
  79. package/lib/function/commands/release.js +69 -0
  80. package/lib/function/index.js +24 -0
  81. package/lib/function/template/js/README.md +37 -0
  82. package/lib/function/template/js/_gitignore +4 -0
  83. package/lib/function/template/js/extension.config.json +5 -0
  84. package/lib/function/template/js/package.json +17 -0
  85. package/lib/function/template/js/src/index.js +64 -0
  86. package/lib/function/utils.js +29 -0
  87. package/lib/openAPI/api.js +1 -1
  88. package/lib/openAPI/index.js +0 -1
  89. package/lib/partner-api/axios.js +67 -0
  90. package/lib/partner-api/index.js +79 -0
  91. package/lib/{checkout → utils}/console.js +3 -2
  92. package/lib/utils/env.js +17 -0
  93. package/lib/utils/file.js +48 -0
  94. package/lib/utils/platform.js +37 -0
  95. package/lib/{utils.js → utils/utils.js} +2 -2
  96. package/package.json +1 -1
  97. /package/lib/app/template/basic-app/{theme-extension.config.json → extension.config.json} +0 -0
  98. /package/lib/app/template/embed-app/{theme-extension.config.json → extension.config.json} +0 -0
  99. /package/lib/{config.js → utils/config.js} +0 -0
@@ -0,0 +1,64 @@
1
+ const input = readInput();
2
+ const result = run(input);
3
+ writeOutput(object);
4
+
5
+ function run(input) {
6
+ const runResult = {
7
+ operations: {
8
+ update: []
9
+ }
10
+ };
11
+
12
+ input.cart.line_items.forEach((lineItem) => {
13
+ lineItem.product.metafields.forEach((metafield) => {
14
+ // key是自己定义的metafield名。如果有同名的key,可用namespace用于区分
15
+ if (metafield.namespace === 'custom-option' && metafield.key === 'adjust-10-price') {
16
+ runResult.operations.update.push({
17
+ id: lineItem.id,
18
+ price: {
19
+ adjustment_fixed_price: '10' // 设置定制的价格10元
20
+ }
21
+ });
22
+ }
23
+ });
24
+ });
25
+ return runResult;
26
+ }
27
+
28
+ function readInput() {
29
+ const chunkSize = 1024;
30
+ const inputChunks = [];
31
+ let totalBytes = 0;
32
+ // Read all the available bytes
33
+ while (1) {
34
+ const buffer = new Uint8Array(chunkSize);
35
+ // Stdin file descriptor
36
+ const fd = 0;
37
+ const bytesRead = Javy.IO.readSync(fd, buffer);
38
+ totalBytes += bytesRead;
39
+ if (bytesRead === 0) {
40
+ break;
41
+ }
42
+ inputChunks.push(buffer.subarray(0, bytesRead));
43
+ }
44
+ // Assemble input into a single Uint8Array
45
+ const { finalBuffer } = inputChunks.reduce(
46
+ (context, chunk) => {
47
+ context.finalBuffer.set(chunk, context.bufferOffset);
48
+ context.bufferOffset += chunk.length;
49
+ return context;
50
+ },
51
+ { bufferOffset: 0, finalBuffer: new Uint8Array(totalBytes) }
52
+ );
53
+
54
+ return JSON.parse(new TextDecoder().decode(finalBuffer));
55
+ }
56
+
57
+ // Write output to stdout
58
+ function writeOutput(output) {
59
+ const encodedOutput = new TextEncoder().encode(JSON.stringify(output));
60
+ const buffer = new Uint8Array(encodedOutput);
61
+ // Stdout file descriptor
62
+ const fd = 1;
63
+ Javy.IO.writeSync(fd, buffer);
64
+ }
@@ -0,0 +1,29 @@
1
+ const inquirer = require('inquirer');
2
+ const { getConfigJson, updateConfigJson } = require('../utils/file');
3
+
4
+ async function requestAppSecretWhenNotExist() {
5
+ const config = getConfigJson();
6
+ if (!config.appId || !config.appSecret) {
7
+ const { appId, appSecret } = await inquirer.prompt([
8
+ {
9
+ type: 'input',
10
+ name: 'appId',
11
+ message: 'Enter client id of app:',
12
+ prefix: '*'
13
+ },
14
+ {
15
+ type: 'input',
16
+ name: 'appSecret',
17
+ message: 'Enter client secret of app:',
18
+ prefix: '*'
19
+ }
20
+ ]);
21
+ config.appId = appId;
22
+ config.appSecret = appSecret;
23
+ updateConfigJson(config);
24
+ }
25
+ }
26
+
27
+ module.exports = {
28
+ requestAppSecretWhenNotExist
29
+ };
@@ -1,6 +1,6 @@
1
1
  const fs = require('fs-extra');
2
2
  const FormData = require('form-data');
3
- const { getThemeFilenameTypeAndLocation } = require('../utils');
3
+ const { getThemeFilenameTypeAndLocation } = require('../utils/utils');
4
4
  const openAPI = require('./index');
5
5
 
6
6
  exports.getShopDetail = (config = {}) => {
@@ -3,7 +3,6 @@ const fs = require('fs-extra');
3
3
  const chalk = require('chalk');
4
4
  const Sentry = require('@sentry/node');
5
5
  const { get, set } = require('../db/user');
6
- const { getThemeFilenameTypeAndLocation } = require('../utils');
7
6
  const { postExchangeToken } = require('../auth');
8
7
  const log = require('../log');
9
8
 
@@ -0,0 +1,67 @@
1
+ const axios = require('axios');
2
+ const { isDevDebug, isStgDebug } = require('../utils/env');
3
+ const { consoleError } = require('../utils/console');
4
+ const { updateConfigJson, getConfigJson } = require('../utils/file');
5
+
6
+ const baseUrl = `https://partners.${isDevDebug() ? 'dev.' : isStgDebug() ? 'stg.' : ''}shoplazza.com`;
7
+
8
+ const instance = axios.create({
9
+ baseURL: baseUrl + '/openapi/2024-07'
10
+ });
11
+
12
+ instance.interceptors.request.use(
13
+ async (config) => {
14
+ const extConfig = getConfigJson();
15
+ let token = extConfig.accessToken;
16
+ if (!token) {
17
+ token = await refreshAccessToken();
18
+ }
19
+ config.headers['Access-Token'] = token;
20
+ config.headers['app-client-id'] = extConfig.appId;
21
+ return config;
22
+ },
23
+ (error) => {
24
+ consoleError(`[REQUEST ERROR] ${error.message}`);
25
+ return Promise.reject(error);
26
+ }
27
+ );
28
+
29
+ instance.interceptors.response.use(
30
+ function (response) {
31
+ return response;
32
+ },
33
+ async function (error) {
34
+ const { config, response } = error || {};
35
+ if (response?.status === 403 && !config._retry) {
36
+ config._retry = true;
37
+ await refreshAccessToken();
38
+ return instance(config);
39
+ }
40
+ error.response &&
41
+ consoleError(
42
+ `[RESPONSE ERROR] ${error.response.status} ${error.response.config.baseURL}${error.response.config.url}`
43
+ );
44
+ return Promise.reject(error);
45
+ }
46
+ );
47
+
48
+ function refreshAccessToken() {
49
+ const extensionConfig = getConfigJson();
50
+ if (!extensionConfig.appId || !extensionConfig.appSecret) {
51
+ consoleError(`must provide 'appId' and 'appSecret' in extension.config.json `);
52
+ process.exit(-1);
53
+ }
54
+ return axios
55
+ .post(baseUrl + '/partner/oauth/token', {
56
+ client_id: extensionConfig.appId,
57
+ client_secret: extensionConfig.appSecret,
58
+ grant_type: 'client_credentials'
59
+ })
60
+ .then((res) => {
61
+ const token = res.data.access_token;
62
+ updateConfigJson({ accessToken: token });
63
+ return token;
64
+ });
65
+ }
66
+
67
+ module.exports = instance;
@@ -0,0 +1,79 @@
1
+ const axios = require('./axios');
2
+ // const Aaxios = require('axios');
3
+
4
+ // const axios = Aaxios.create({
5
+ // baseURL: 'http://igw-traefik.internal.svc.cluster.local/service/functions-api/api/partner-openapi/2025-03',
6
+ // headers: {
7
+ // 'x-rf': 'feature-ymq',
8
+ // 'app-client-id': '123123'
9
+ // }
10
+ // });
11
+
12
+ function createFunctionExtension(form) {
13
+ return axios
14
+ .post('/functions', form, {
15
+ headers: {
16
+ ...form.getHeaders()
17
+ }
18
+ })
19
+ .then((res) => res.data?.data);
20
+ }
21
+
22
+ function updateFunctionExtension(functionId, form) {
23
+ return axios
24
+ .patch(`/functions/${functionId}`, form, {
25
+ headers: {
26
+ ...form.getHeaders()
27
+ }
28
+ })
29
+ .then((res) => res.data?.data);
30
+ }
31
+
32
+ function getFunctionList(params = { page: 1, limit: 1000 }) {
33
+ return axios
34
+ .get(
35
+ '/functions',
36
+ { params },
37
+ {
38
+ headers: {
39
+ 'Content-Type': 'application/ x-www-form-urlencoded',
40
+ }
41
+ }
42
+ )
43
+ .then((res) => res.data?.data);
44
+ }
45
+
46
+ /**
47
+ * 连接App
48
+ */
49
+ async function toConnectApp(data) {
50
+ return axios.post(
51
+ '/theme-extensions/connection',
52
+ {
53
+ extension_id: data.extensionId,
54
+ type: data.type || 'link'
55
+ }
56
+ );
57
+ }
58
+
59
+ /**
60
+ * 应用主题插件到App
61
+ */
62
+ async function toReleaseApp(data) {
63
+ return axios.post(
64
+ '/theme-extensions/publications',
65
+ {
66
+ extension_id: data.extensionId,
67
+ version_id: data.versionId,
68
+ type: data.type || 'enable'
69
+ }
70
+ );
71
+ }
72
+
73
+ module.exports = {
74
+ createFunctionExtension,
75
+ updateFunctionExtension,
76
+ getFunctionList,
77
+ toConnectApp,
78
+ toReleaseApp
79
+ };
@@ -6,9 +6,10 @@ function isDebug() {
6
6
 
7
7
  function consoleError(...args) {
8
8
  if (isDebug()) {
9
- console.trace(args);
9
+ console.trace(colors.red(args));
10
+ } else {
11
+ console.log(colors.red(args.join(' ')));
10
12
  }
11
- console.log(colors.red(args.join(' ')));
12
13
  }
13
14
 
14
15
  function consoleBlue(...args) {
@@ -0,0 +1,17 @@
1
+ function isDebug() {
2
+ return process.argv.indexOf('--debug') >= 0;
3
+ }
4
+
5
+ function isDevDebug() {
6
+ return process.argv.join('').indexOf('--debugdev') >= 0;
7
+ }
8
+ function isStgDebug() {
9
+ return process.argv.join('').indexOf('--debugstg') >= 0;
10
+ }
11
+
12
+ module.exports = {
13
+ isDebug,
14
+ isDevDebug,
15
+ isStgDebug
16
+ };
17
+
@@ -0,0 +1,48 @@
1
+ const path = require('path');
2
+ const fs = require('fs-extra');
3
+ const { getFileJson } = require('../checkout/util');
4
+
5
+ function copyDir(srcDir, destDir) {
6
+ fs.mkdirSync(destDir, { recursive: true });
7
+ for (const file of fs.readdirSync(srcDir)) {
8
+ const srcFile = path.resolve(srcDir, file);
9
+ const destFile = path.resolve(destDir, file);
10
+ copy(srcFile, destFile);
11
+ }
12
+ }
13
+
14
+ function copy(src, dest) {
15
+ const stat = fs.statSync(src);
16
+ if (stat.isDirectory()) {
17
+ copyDir(src, dest);
18
+ } else {
19
+ fs.copyFileSync(src, dest);
20
+ }
21
+ }
22
+
23
+ function getJsonFileContent(file) {
24
+ const content = fs.readFileSync(file, { encoding: 'utf-8' });
25
+ return JSON.parse(content);
26
+ }
27
+
28
+ const CONFIG_FILE = 'extension.config.json';
29
+
30
+ function getConfigJson(name = CONFIG_FILE) {
31
+ const _path = path.join(process.cwd(), name);
32
+ return getJsonFileContent(_path);
33
+ }
34
+
35
+ function updateConfigJson(_config, name = CONFIG_FILE) {
36
+ const config = getConfigJson();
37
+ Object.assign(config, _config);
38
+ const _path = path.join(process.cwd(), name);
39
+ fs.writeFileSync(_path, JSON.stringify(config, null, 2), { encoding: 'utf-8' });
40
+ }
41
+
42
+ module.exports = {
43
+ copy,
44
+ copyDir,
45
+ getFileJson,
46
+ getConfigJson,
47
+ updateConfigJson
48
+ };
@@ -0,0 +1,37 @@
1
+ function getArchPlatform() {
2
+ let platform;
3
+ let arch;
4
+ switch (process.platform.toLowerCase()) {
5
+ case 'darwin':
6
+ platform = 'macos';
7
+ break;
8
+ case 'linux':
9
+ platform = 'linux';
10
+ break;
11
+ case 'win32':
12
+ platform = 'windows';
13
+ break;
14
+ default:
15
+ throw Error(`Unsupported platform ${processPlatform}`);
16
+ }
17
+ switch (process.arch.toLowerCase()) {
18
+ case 'arm':
19
+ case 'arm64':
20
+ arch = 'arm';
21
+ break;
22
+ // A 32 bit arch likely needs that someone has 32bit Node installed on a
23
+ // 64 bit system, and wasmtime doesn't support 32bit anyway.
24
+ case 'ia32':
25
+ case 'x64':
26
+ arch = 'x86_64';
27
+ break;
28
+ default:
29
+ throw Error(`Unsupported architecture ${processArch}`);
30
+ }
31
+
32
+ return `${arch}-${platform}`;
33
+ }
34
+
35
+ module.exports = {
36
+ getArchPlatform
37
+ };
@@ -143,12 +143,12 @@ exports.watchWorkspace = (workspace, options = {}) => {
143
143
  });
144
144
 
145
145
  watcher.on('change', (filePath) => {
146
- console.log(chalk.yellow(`[CHANGE] ${filePath}`));
146
+ console.log(chalk.cyan(`[CHANGE] ${filePath}`));
147
147
  onChange(filePath);
148
148
  });
149
149
 
150
150
  watcher.on('unlink', (filePath) => {
151
- console.log(chalk.red(`[DELETE] ${filePath}`));
151
+ console.log(chalk.cyan(`[DELETE] ${filePath}`));
152
152
  onDelete(filePath);
153
153
  });
154
154
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoplazza-cli",
3
- "version": "1.0.7-beta.1",
3
+ "version": "1.0.7-beta.2",
4
4
  "description": "",
5
5
  "main": "bin/shoplazza",
6
6
  "engines": {
File without changes