@contrail/cli 2.1.24 → 2.1.26

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.24 darwin-arm64 node-v18.13.0
20
+ @contrail/cli/2.1.26 darwin-arm64 node-v18.13.0
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -1,6 +1,7 @@
1
1
  import { Command } from '@oclif/core';
2
2
  export declare abstract class BaseCommand extends Command {
3
3
  static description: string;
4
+ skipConfirmEnv: boolean;
4
5
  static baseFlags: {
5
6
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
7
  alwaysConfirmEnv: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -9,6 +9,10 @@ const config_1 = require("./helpers/config/config");
9
9
  const auth_1 = require("@contrail/sdk/lib/auth/auth");
10
10
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
11
11
  class BaseCommand extends core_1.Command {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.skipConfirmEnv = false;
15
+ }
12
16
  async init() {
13
17
  await super.init();
14
18
  const { flags } = await this.parse({
@@ -18,7 +22,9 @@ class BaseCommand extends core_1.Command {
18
22
  strict: this.ctor.strict,
19
23
  });
20
24
  await this.setLogLevel(flags.logLevel);
21
- await this.confirmEnv(flags.alwaysConfirmEnv);
25
+ if (!this.skipConfirmEnv) {
26
+ await this.confirmEnv(flags.alwaysConfirmEnv);
27
+ }
22
28
  }
23
29
  async setLogLevel(logLevel) {
24
30
  if (logLevel) {
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from '../../../basecommand';
2
2
  export default class ListConfigEnvironment extends BaseCommand {
3
+ skipConfirmEnv: boolean;
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  run(): Promise<void>;
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_1 = require("../../../helpers/config/config");
4
4
  const basecommand_1 = require("../../../basecommand");
5
5
  class ListConfigEnvironment extends basecommand_1.BaseCommand {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.skipConfirmEnv = true;
9
+ }
6
10
  async run() {
7
11
  const { flags } = await this.parse(ListConfigEnvironment);
8
12
  await super.setLogLevel(flags.logLevel);
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from '../../../basecommand';
2
2
  export default class RemoveConfigEnvironment extends BaseCommand {
3
+ skipConfirmEnv: boolean;
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  static strict: boolean;
@@ -6,6 +6,10 @@ const basecommand_1 = require("../../../basecommand");
6
6
  const config_1 = require("../../../helpers/config/config");
7
7
  const logger_1 = tslib_1.__importDefault(require("../../../logger"));
8
8
  class RemoveConfigEnvironment extends basecommand_1.BaseCommand {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.skipConfirmEnv = true;
12
+ }
9
13
  async run() {
10
14
  const { flags } = await this.parse(RemoveConfigEnvironment);
11
15
  await super.setLogLevel(flags.logLevel);
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from '../../../basecommand';
2
2
  export default class SetConfigEnvironment extends BaseCommand {
3
+ skipConfirmEnv: boolean;
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  static flags: {
@@ -6,6 +6,10 @@ const config_1 = require("../../../helpers/config/config");
6
6
  const basecommand_1 = require("../../../basecommand");
7
7
  const logger_1 = tslib_1.__importDefault(require("../../../logger"));
8
8
  class SetConfigEnvironment extends basecommand_1.BaseCommand {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.skipConfirmEnv = true;
12
+ }
9
13
  async run() {
10
14
  const { flags } = await this.parse(SetConfigEnvironment);
11
15
  await super.setLogLevel(flags.logLevel);
@@ -1,6 +1,7 @@
1
1
  import { BaseCommand } from '../../basecommand';
2
2
  export default class ListConfig extends BaseCommand {
3
3
  static description: string;
4
+ skipConfirmEnv: boolean;
4
5
  static examples: string[];
5
6
  run(): Promise<void>;
6
7
  }
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_1 = require("../../helpers/config/config");
4
4
  const basecommand_1 = require("../../basecommand");
5
5
  class ListConfig extends basecommand_1.BaseCommand {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.skipConfirmEnv = true;
9
+ }
6
10
  async run() {
7
11
  this.log(await (0, config_1.readVibeIQConfig)());
8
12
  }
@@ -1,6 +1,7 @@
1
1
  import { BaseCommand } from '../../basecommand';
2
2
  export default class RemoveConfig extends BaseCommand {
3
3
  static description: string;
4
+ skipConfirmEnv: boolean;
4
5
  static examples: string[];
5
6
  static strict: boolean;
6
7
  static flags: {
@@ -4,6 +4,10 @@ const core_1 = require("@oclif/core");
4
4
  const config_1 = require("../../helpers/config/config");
5
5
  const basecommand_1 = require("../../basecommand");
6
6
  class RemoveConfig extends basecommand_1.BaseCommand {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.skipConfirmEnv = true;
10
+ }
7
11
  async run() {
8
12
  const { flags } = await this.parse(RemoveConfig);
9
13
  await (0, config_1.deleteConfigs)(Object.keys(flags));
@@ -1,5 +1,6 @@
1
1
  import { BaseCommand } from '../../basecommand';
2
2
  export default class SetConfig extends BaseCommand {
3
+ skipConfirmEnv: boolean;
3
4
  static description: string;
4
5
  static examples: string[];
5
6
  static flags: {
@@ -6,6 +6,10 @@ const config_1 = require("../../helpers/config/config");
6
6
  const basecommand_1 = require("../../basecommand");
7
7
  const logger_1 = tslib_1.__importDefault(require("../../logger"));
8
8
  class SetConfig extends basecommand_1.BaseCommand {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.skipConfirmEnv = true;
12
+ }
9
13
  async run() {
10
14
  const { flags } = await this.parse(SetConfig);
11
15
  const config = {};
@@ -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
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.24",
2
+ "version": "2.1.26",
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.24",
3
+ "version": "2.1.26",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",