@contrail/cli 2.1.25 → 2.1.27

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/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/2.1.25 darwin-arm64 node-v18.13.0
20
+ @contrail/cli/2.1.27 darwin-arm64 node-v18.13.0
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -7,3 +7,15 @@ export default class LoadProject extends BaseCommand {
7
7
  };
8
8
  run(): Promise<void>;
9
9
  }
10
+ interface CheckerFunction {
11
+ (key: string, value: any): boolean;
12
+ }
13
+ interface ApplyFunction {
14
+ (key: string, value: any): Promise<void>;
15
+ }
16
+ export interface Transformer {
17
+ checker: CheckerFunction;
18
+ recursive: boolean;
19
+ apply: ApplyFunction;
20
+ }
21
+ export {};
@@ -8,6 +8,7 @@ const helpers_1 = require("../../helpers/projects/helpers");
8
8
  const core_1 = require("@oclif/core");
9
9
  const basecommand_1 = require("../../basecommand");
10
10
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
11
+ const types_1 = require("@contrail/types");
11
12
  class LoadProject extends basecommand_1.BaseCommand {
12
13
  async run() {
13
14
  const { args } = await this.parse(LoadProject);
@@ -42,6 +43,8 @@ LoadProject.args = {
42
43
  async function uploadProject(templateFileLocation) {
43
44
  const projectConfigurationFromFile = (0, helpers_1.getProjectFile)(templateFileLocation);
44
45
  const projectConfiguration = getProjectConfiguration(projectConfigurationFromFile);
46
+ logger_1.default.info('Checking for object and type references');
47
+ await transformProject(projectConfiguration);
45
48
  logger_1.default.info('Configuring Project.');
46
49
  await sdk_1.Request.request('/project-configurator', {
47
50
  method: 'POST',
@@ -111,3 +114,85 @@ function parseToProjectConfiguration(projectConfigurationFromFile) {
111
114
  }
112
115
  return projectConfiguration;
113
116
  }
117
+ /**
118
+ * recursively traverse all the project nodes and transforms any
119
+ * entities that need transformation.
120
+ */
121
+ async function transformProject(projectConfiguration) {
122
+ const transformers = [
123
+ {
124
+ checker: (k, v) => k === 'assortments' && Array.isArray(v),
125
+ recursive: false,
126
+ apply: transformAssortmentObjectReferences,
127
+ },
128
+ ];
129
+ for (const transformer of transformers) {
130
+ // recurse through the project config and check all nodes
131
+ for (const [k, v] of Object.entries(projectConfiguration)) {
132
+ if (transformer.checker(k, v)) {
133
+ await transformer.apply(k, v);
134
+ if (transformer.recursive) {
135
+ await transformProject(projectConfiguration[k]);
136
+ }
137
+ }
138
+ else if (typeof projectConfiguration[k] === 'object') {
139
+ // recurse for all properties because nested properties
140
+ // might need to be transformed
141
+ await transformProject(projectConfiguration[k]);
142
+ }
143
+ }
144
+ }
145
+ }
146
+ /**
147
+ * Hydrates object reference and type references in the assortment attributes.
148
+ * @param _ unused parameter for keys
149
+ * @param assortments The expected node value passed ot this function is a list of assortments
150
+ */
151
+ async function transformAssortmentObjectReferences(_, assortments) {
152
+ var _a, _b, _c, _d, _e;
153
+ const typesClient = new sdk_1.Types();
154
+ const assortmentType = await typesClient.getType({
155
+ path: 'assortment',
156
+ relations: ['typeProperties'],
157
+ });
158
+ const assortmentProperties = assortmentType.typeProperties;
159
+ for (const assortment of assortments !== null && assortments !== void 0 ? assortments : []) {
160
+ const attributes = JSON.parse(JSON.stringify((_a = assortment === null || assortment === void 0 ? void 0 : assortment.assortmentAtts) !== null && _a !== void 0 ? _a : {}));
161
+ if (!((_b = Object.keys(attributes)) === null || _b === void 0 ? void 0 : _b.length)) {
162
+ continue;
163
+ }
164
+ for (const [attributeKey, attributeValue] of Object.entries(attributes)) {
165
+ const property = assortmentProperties.find((x) => x.slug === attributeKey);
166
+ // if not a reference
167
+ if (!property || !property.referencedTypePath) {
168
+ continue;
169
+ }
170
+ if (property.propertyType === types_1.PropertyType.TypeReference) {
171
+ logger_1.default.debug(`found type reference!${attributeKey}${attributeValue}`);
172
+ // special case: handle type references
173
+ const type = (_c = (await new sdk_1.Types().getType({ path: attributeValue }))) === null || _c === void 0 ? void 0 : _c.id;
174
+ logger_1.default.debug(`found type ${type}`);
175
+ logger_1.default.info(`replacing ${attributeKey}:${attributeValue} with ${attributeKey}Id:${type}`);
176
+ assortment.assortmentAtts[`${attributeKey}Id`] = type;
177
+ }
178
+ else if (property.propertyType === types_1.PropertyType.ObjectReference) {
179
+ logger_1.default.debug(`found object reference!${attributeKey}${attributeValue}`);
180
+ let allEntities = [];
181
+ if (property.referencedTypePath.startsWith('custom-entity')) {
182
+ allEntities = await new sdk_1.Entities().get({
183
+ entityName: 'custom-entity',
184
+ criteria: { typePath: property.referencedTypePath },
185
+ });
186
+ }
187
+ else {
188
+ allEntities = await new sdk_1.Entities().get({ entityName: property.referencedTypePath });
189
+ }
190
+ // special case: handle type references
191
+ const foundAttribute = (_e = (_d = allEntities.find((x) => x.name === attributeValue)) === null || _d === void 0 ? void 0 : _d.id) !== null && _e !== void 0 ? _e : attributeKey;
192
+ logger_1.default.debug(`found attribute ${foundAttribute}`);
193
+ logger_1.default.info(`replacing ${attributeKey}:${attributeValue} with ${attributeKey}Id:${foundAttribute}`);
194
+ assortment.assortmentAtts[`${attributeKey}Id`] = foundAttribute;
195
+ }
196
+ }
197
+ }
198
+ }
@@ -22,14 +22,23 @@ async function getLocalColors() {
22
22
  exports.getLocalColors = getLocalColors;
23
23
  async function getExistingColors() {
24
24
  logger_1.default.info('%s Getting Existing Colors', chalk_1.default.yellow.bold('COLORS'));
25
+ const colors = [];
25
26
  try {
26
- const result = await new sdk_1.Entities().get({ entityName: 'color', take: 3000 }); //, useSearch: false }); Not in EntitiesClientGetOptions yet
27
- logger_1.default.info('Found %s existing colors', result.length);
28
- return result;
27
+ let nextPageKey = null;
28
+ do {
29
+ const result = await new sdk_1.Entities().get({
30
+ entityName: 'color',
31
+ nextPageKey,
32
+ apiVersion: sdk_1.API_VERSION.V2,
33
+ });
34
+ colors.push(...result.results);
35
+ nextPageKey = result.nextPageKey;
36
+ } while (nextPageKey);
29
37
  }
30
38
  catch (e) {
31
39
  throw new Error(`ERROR DOWNLOADING COLORS: ${e}`);
32
40
  }
41
+ return colors;
33
42
  }
34
43
  exports.getExistingColors = getExistingColors;
35
44
  async function deleteColor(color) {
@@ -8,5 +8,6 @@ export declare class WorkflowTemplateDefinitionDeployer {
8
8
  private createNewWorkflowDefinition;
9
9
  private populateActionIds;
10
10
  private updateWorkflowTemplateDefinition;
11
- getWorkflowDeclarationIdentifier(actionKey: any, app: App): string;
11
+ getActionDeclarationIdentifier(actionKey: any, app: App): string;
12
+ getWorkflowDeclarationIdentifier(workflowKey: any, app: App): string;
12
13
  }
@@ -147,6 +147,10 @@ class WorkflowTemplateDefinitionDeployer {
147
147
  throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
148
148
  }
149
149
  actionConfiguration.id = action.id;
150
+ actionConfiguration.identifier = (0, actions_deployer_1.getActionDeclarationIdentifier)(actionKey, app);
151
+ if (!actionConfiguration.identifier) {
152
+ throw new Error(`Could not create action identifier for action ${actionKey} workflow definition ${workflowDefinition.name}`);
153
+ }
150
154
  }
151
155
  }
152
156
  }
@@ -168,8 +172,11 @@ class WorkflowTemplateDefinitionDeployer {
168
172
  logger_1.default.info(`%s Updated existing workflow definition: ${updatedWorkflowDefinition.identifier}`, chalk_1.default.yellow.bold('WORKFLOW DEFINITION'));
169
173
  return updatedWorkflowDefinition;
170
174
  }
171
- getWorkflowDeclarationIdentifier(actionKey, app) {
175
+ getActionDeclarationIdentifier(actionKey, app) {
172
176
  return `${app.identifier}@${app.latestAppVersionId}:${actionKey}`;
173
177
  }
178
+ getWorkflowDeclarationIdentifier(workflowKey, app) {
179
+ return `${app.identifier}@${app.latestAppVersionId}:${workflowKey}`;
180
+ }
174
181
  }
175
182
  exports.WorkflowTemplateDefinitionDeployer = WorkflowTemplateDefinitionDeployer;
@@ -114,6 +114,7 @@ export interface ActionDefinitionConfig {
114
114
  [key: string]: any;
115
115
  };
116
116
  id?: string;
117
+ identifier?: string;
117
118
  }
118
119
  export interface App {
119
120
  id: string;
@@ -0,0 +1,47 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "eslint:recommended",
9
+ "plugin:@typescript-eslint/eslint-recommended",
10
+ "plugin:@typescript-eslint/recommended"
11
+ ],
12
+ "ignorePatterns": ["node_modules/", "dist/"],
13
+ "parser": "@typescript-eslint/parser",
14
+ "parserOptions": {
15
+ "ecmaVersion": "latest",
16
+ "sourceType": "module"
17
+ },
18
+ "plugins": ["@typescript-eslint", "unused-imports"],
19
+ "rules": {
20
+ "indent": ["error", 2],
21
+ "linebreak-style": ["error", "unix"],
22
+ "quote-props": ["error", "as-needed"],
23
+ "quotes": ["error", "single"],
24
+ "semi": ["error", "always"],
25
+ "no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
26
+ "no-trailing-spaces": "error",
27
+ "no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
28
+ "@typescript-eslint/no-empty-function": [
29
+ "error",
30
+ { "allow": ["arrowFunctions"] }
31
+ ],
32
+ "@typescript-eslint/no-explicit-any": "off",
33
+ "@typescript-eslint/no-var-requires": "warn",
34
+ "no-unused-vars": "off",
35
+ "@typescript-eslint/no-unused-vars": "off",
36
+ "unused-imports/no-unused-imports": "error",
37
+ "unused-imports/no-unused-vars": [
38
+ "warn",
39
+ {
40
+ "vars": "all",
41
+ "varsIgnorePattern": "^_",
42
+ "args": "after-used",
43
+ "argsIgnorePattern": "^_"
44
+ }
45
+ ]
46
+ }
47
+ }
@@ -36,6 +36,9 @@
36
36
  "nodemon": "^1.19.4",
37
37
  "ts-jest": "^29.0.3",
38
38
  "ts-node": "^7.0.1",
39
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
40
+ "eslint": "^8.53.0",
41
+ "eslint-plugin-unused-imports": "^3.0.0",
39
42
  "typescript": "^4.7.4"
40
43
  }
41
44
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.25",
2
+ "version": "2.1.27",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "2.1.25",
3
+ "version": "2.1.27",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@contrail/entity-types": "^1.1.17",
26
- "@contrail/sdk": "^1.2.3",
26
+ "@contrail/sdk": "^1.2.17",
27
27
  "@contrail/types": "^3.0.20",
28
28
  "@contrail/util": "^1.0.41",
29
29
  "@oclif/core": "^2",