@shoper/cli 0.2.1-3 → 0.2.1-5

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.
@@ -13,4 +13,7 @@ export class CliAuthApi extends FeatureApi {
13
13
  hasCredentialsExpired() {
14
14
  return this.#cliAuthService.hasCredentialsExpired();
15
15
  }
16
+ clearCredentials() {
17
+ return this.#cliAuthService.clearCredentials();
18
+ }
16
19
  }
@@ -31,4 +31,8 @@ export class CliAuthService {
31
31
  return true;
32
32
  return this.#cliAuthTokensApi.hasTokenExpired(defaultTokenIndex);
33
33
  }
34
+ clearCredentials() {
35
+ this.#credentials = null;
36
+ this.#cliAuthTokensApi.clearTokens();
37
+ }
34
38
  }
@@ -43,4 +43,7 @@ export class CliAuthTokensApi extends FeatureApi {
43
43
  validateToken(token) {
44
44
  return this.#service.validateToken(token);
45
45
  }
46
+ clearTokens() {
47
+ this.#service.clearTokens();
48
+ }
46
49
  }
@@ -1,4 +1,5 @@
1
1
  import jwt from 'jsonwebtoken';
2
+ import differenceBy from 'lodash/differenceBy.js';
2
3
  export class CLiAuthTokensUtils {
3
4
  static getTokenPayload(token) {
4
5
  try {
@@ -33,13 +34,15 @@ export class CLiAuthTokensUtils {
33
34
  if (!decoded) {
34
35
  return { isValid: false, message: 'Failed to decode token.' };
35
36
  }
36
- const { header } = decoded;
37
37
  const payload = decoded.payload;
38
- const expectedPayloadKeys = ['sub', 'exp', 'iat', 'iss', 'nbf', 'scope', 'id', 'name', 'key'];
39
- for (const key of Object.keys(payload)) {
40
- if (!expectedPayloadKeys.includes(key)) {
41
- return { isValid: false, message: `Unexpected key in payload: ${key}` };
42
- }
38
+ const expectedPayloadKeys = ['exp', 'iat', 'iss', 'nbf', 'scope', 'id', 'name', 'key'];
39
+ const missingKeys = differenceBy(expectedPayloadKeys, Object.keys(payload));
40
+ if (missingKeys.length > 0) {
41
+ return { isValid: false, message: `Missing keys in payload: ${missingKeys.join(', ')}` };
42
+ }
43
+ const unexpectedKeys = differenceBy(Object.keys(payload), expectedPayloadKeys);
44
+ if (unexpectedKeys.length > 0) {
45
+ return { isValid: false, message: `Unexpected keys in payload: ${unexpectedKeys.join(', ')}` };
43
46
  }
44
47
  // Check if the token has expired
45
48
  const now = Math.floor(Date.now() / 1000); // Current time in seconds
@@ -86,4 +86,7 @@ export class CLiAuthTokensService {
86
86
  const tokens = this._getTokenItems();
87
87
  return tokens.map((tokenItem) => CLiAuthTokensUtils.getTokenPayload(tokenItem.token));
88
88
  }
89
+ clearTokens() {
90
+ this.#tokensStore.clear();
91
+ }
89
92
  }
@@ -8,6 +8,7 @@ export class JsonCache extends FeatureCore {
8
8
  this.#cache = new Conf({
9
9
  cwd: path,
10
10
  configName: name,
11
+ clearInvalidConfig: true,
11
12
  configFileMode,
12
13
  ...rest
13
14
  });
@@ -0,0 +1,26 @@
1
+ import { BaseCliCommand } from '../class/base_cli_command.js';
2
+ import { THEME_ACTIONS_API_NAME } from '../../theme/features/theme/actions/theme_actions_constants.js';
3
+ import { CLI_AUTH_API_NAME } from '../auth/cli_auth_constants.js';
4
+ import { renderOnce } from '../../ui/ui_utils.js';
5
+ import { Success } from '../../ui/message_box/success.js';
6
+ import React from 'react';
7
+ import { Error } from '../../ui/message_box/error.js';
8
+ import { Box } from '../../ui/box.js';
9
+ import { Text } from '../../ui/text.js';
10
+ export class CliCleanCache extends BaseCliCommand {
11
+ static summary = 'Clears all cached data';
12
+ async run() {
13
+ const themeActionsApi = this.getApi(THEME_ACTIONS_API_NAME);
14
+ const cliAuthApi = this.getApi(CLI_AUTH_API_NAME);
15
+ try {
16
+ themeActionsApi.clearAllActions();
17
+ cliAuthApi.clearCredentials();
18
+ renderOnce(React.createElement(Success, { header: "Cache cleared" }));
19
+ }
20
+ catch (err) {
21
+ renderOnce(React.createElement(Error, { header: "Error during cache cleaning" },
22
+ React.createElement(Box, null,
23
+ React.createElement(Text, null, err.toString()))));
24
+ }
25
+ }
26
+ }
@@ -7,5 +7,6 @@ export const CLI_COMMANDS_NAMES = {
7
7
  authAddToken: `${CLI_AUTH_TOPIC_NAME}:add-token`,
8
8
  authRemoveToken: `${CLI_AUTH_TOPIC_NAME}:remove-token`,
9
9
  switchToken: `${CLI_AUTH_TOPIC_NAME}:switch-token`,
10
- uiDump: 'ui-dump'
10
+ uiDump: 'ui-dump',
11
+ cleanCache: 'clean-cache'
11
12
  };
@@ -11,6 +11,8 @@ import { CliAuthInitializer } from '../auth/cli_auth_initializer.js';
11
11
  import { THEME_TOPIC_NAME } from '../../theme/commands/theme_commands_constants.js';
12
12
  import { getThemeInitializersForCommand } from '../../theme/index.js';
13
13
  import { CLI_AUTH_TOPIC_NAME, CLI_COMMANDS_NAMES } from '../commands/commands_constants.js';
14
+ import { ThemeActionsInitializer } from '../../theme/features/theme/actions/theme_actions_initializer.js';
15
+ import { ThemesListInitializer } from '../../theme/features/themes/list/themes_list_initializer.js';
14
16
  tmp.setGracefulCleanup();
15
17
  export const cliSetup = async () => {
16
18
  //TODO jakis ładny komuniakt błedu
@@ -52,12 +54,15 @@ const getCommandWithTopicBaseInitializers = () => {
52
54
  return [];
53
55
  };
54
56
  const getCommandWithoutTopicBaseInitializers = () => {
55
- const command = process.argv[3];
57
+ const command = process.argv[2];
56
58
  switch (command) {
57
59
  case CLI_COMMANDS_NAMES.version:
58
60
  case CLI_COMMANDS_NAMES.update: {
59
61
  return [CliVersionInitializer];
60
62
  }
63
+ case CLI_COMMANDS_NAMES.cleanCache: {
64
+ return [ThemesListInitializer, ThemeActionsInitializer];
65
+ }
61
66
  }
62
67
  return [];
63
68
  };
package/build/index.js CHANGED
@@ -8,6 +8,7 @@ import { CliAuthAddTokenCommand } from './cli/commands/auth/cli_auth_add_token_c
8
8
  import { CliAuthRemoveTokenCommand } from './cli/commands/auth/cli_auth_remove_token_command.js';
9
9
  import { CliAuthSwitchTokenCommand } from './cli/commands/auth/cli_auth_switch_token_command.js';
10
10
  import { CliUIDumpCommand } from './cli/commands/cli_ui_dump_command.js';
11
+ import { CliCleanCache } from './cli/commands/cli_clean_cache.js';
11
12
  //TODO
12
13
  //@ts-ignore
13
14
  if (typeof global.crypto !== 'object') {
@@ -44,43 +45,7 @@ export const COMMANDS = {
44
45
  [CLI_COMMANDS_NAMES.authRemoveToken]: CliAuthRemoveTokenCommand,
45
46
  [CLI_COMMANDS_NAMES.switchToken]: CliAuthSwitchTokenCommand,
46
47
  [CLI_COMMANDS_NAMES.uiDump]: CliUIDumpCommand,
48
+ [CLI_COMMANDS_NAMES.cleanCache]: CliCleanCache,
47
49
  ...THEME_COMMANDS
48
50
  };
49
51
  export { runCLI } from './cli/index.js';
50
- /**
51
- * Przetestowane na win
52
- * oglne
53
- * moduly:
54
- * - stworzony w admince
55
- * - pull w cli - v
56
- * - updejt modulu w adminc i pull w cli - v
57
- * - zmiana nazwy katalogu w cli, modzenie w admince i pull - v
58
- * - kopiowanie stworzonego modulu w admince i push (usuniety id i code) - v
59
- * - zminaa w cli i push - v
60
- * - tworzenie modulu w cli, min plikow i push
61
- * - aktualizowanie js/twig/settings/schema
62
- * - zmiana w adminc i pull
63
- * - usuwanie modulu z cli - v
64
- * - usuwanie modulu z adminki - v
65
- * - dodanie niedozwolonego pliku do folderu modulu
66
- * - dodanie niedozwolonego pliku do folderu modules/
67
- * - translacje - v
68
- * macro:
69
- * - dodawanie pliku do macros - v
70
- * - usuniecie macro - v
71
- * - modzneie makro - v
72
- * - dodawanie customowego macro - v
73
- * - push customowego macro - v
74
- * - modzenie w admince i pull - v
75
- * settingsy:
76
- * - uzupelniania schemy w admince, pull w cli
77
- * - uzupelnianie wartosci a admince i pull
78
- * - modzenie w cli
79
- * - usuniecie pliku w cli
80
- * styles:
81
- * - modzenie stylu w src - niedozwolone - v
82
- * - modzenie custom - v
83
- * - usuniecie custom - v
84
- * - modzenie schema i settings - v
85
- * dodanie czegos w .shoper
86
- */
@@ -19,4 +19,7 @@ export class ThemeActionsApi extends FeatureApi {
19
19
  removeThemeActions(props) {
20
20
  return this.#service.removeThemeActions(props);
21
21
  }
22
+ clearAllActions() {
23
+ return this.#service.clearAllActions();
24
+ }
22
25
  }
@@ -101,4 +101,7 @@ export class ThemeActionsService {
101
101
  }
102
102
  });
103
103
  }
104
+ clearAllActions() {
105
+ this.#themesActionsStore.clear();
106
+ }
104
107
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@shoper/cli",
3
3
  "packageManager": "yarn@3.2.0",
4
4
  "sideEffects": false,
5
- "version": "0.2.1-3",
5
+ "version": "0.2.1-5",
6
6
  "description": "CLI tool for Shoper",
7
7
  "author": "Joanna Firek",
8
8
  "license": "MIT",
@@ -40,31 +40,31 @@
40
40
  "axios": "1.8.4",
41
41
  "chalk": "5.4.1",
42
42
  "conf": "13.1.0",
43
+ "fast-glob": "3.3.3",
44
+ "figures": "6.1.0",
45
+ "fs-extra": "11.3.0",
46
+ "fs-tree-diff": "2.0.1",
43
47
  "ink": "6.0.1",
48
+ "ink-link": "4.1.0",
44
49
  "inquirer": "12.5.2",
50
+ "inquirer-select-line": "1.1.3",
45
51
  "is-hidden-file": "1.1.2",
46
52
  "jsonwebtoken": "9.0.2",
53
+ "klaw": "4.1.0",
54
+ "lodash": "4.17.21",
55
+ "log-symbols": "7.0.1",
47
56
  "memfs": "4.17.0",
48
57
  "ora": "8.2.0",
49
58
  "react": "19.1.0",
50
59
  "reflect-metadata": "0.2.2",
51
60
  "rxjs": "7.8.2",
52
61
  "semver": "7.7.1",
62
+ "strip-ansi": "7.1.0",
53
63
  "tmp-promise": "3.0.3",
54
- "yauzl": "3.2.0",
55
- "yazl": "3.3.1",
56
- "fs-tree-diff": "2.0.1",
57
- "fast-glob": "3.3.3",
58
- "klaw": "4.1.0",
59
- "walk-sync": "3.0.0",
60
- "lodash": "4.17.21",
61
64
  "uuid": "11.1.0",
62
- "fs-extra": "11.3.0",
63
- "ink-link": "4.1.0",
64
- "log-symbols": "7.0.1",
65
- "figures": "6.1.0",
66
- "strip-ansi": "7.1.0",
67
- "inquirer-select-line": "1.1.3"
65
+ "walk-sync": "3.0.0",
66
+ "yauzl": "3.2.0",
67
+ "yazl": "3.3.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@babel/core": "7.27.1",
@@ -72,29 +72,29 @@
72
72
  "@babel/preset-typescript": "7.27.1",
73
73
  "@oclif/test": "4.1.12",
74
74
  "@tsconfig/node20": "20.1.6",
75
- "@types/jest": "29.5.14",
76
75
  "@types/fs-extra": "11.0.4",
76
+ "@types/jest": "29.5.14",
77
77
  "@types/jsonwebtoken": "9.0.9",
78
+ "@types/klaw": "3.0.7",
79
+ "@types/lodash": "4.17.17",
78
80
  "@types/node": "18.19.84",
79
81
  "@types/react": "19.1.8",
80
82
  "@types/semver": "7.7.0",
81
83
  "@types/tmp": "0.2.6",
82
84
  "@types/yauzl": "2.10.3",
83
85
  "@types/yazl": "2.4.6",
84
- "@types/klaw": "3.0.7",
85
- "@types/lodash": "4.17.17",
86
86
  "@typescript-eslint/eslint-plugin": "8.29.1",
87
87
  "babel-jest": "29.7.0",
88
88
  "eslint": "9.24.0",
89
89
  "eslint-config-prettier": "10.1.1",
90
90
  "eslint-plugin-prettier": "5.2.6",
91
91
  "jest": "29.7.0",
92
+ "jest-extended": "4.0.2",
92
93
  "module-alias": "2.2.3",
93
94
  "prettier": "3.5.3",
94
95
  "rimraf": "5.0.10",
95
96
  "ts-jest": "29.3.2",
96
97
  "ts-toolbelt": "9.6.0",
97
- "typescript": "5.8.3",
98
- "jest-extended": "4.0.2"
98
+ "typescript": "5.8.3"
99
99
  }
100
100
  }