@contrail/cli 3.6.0-alpha.f45f126 → 3.6.0

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 (91) hide show
  1. package/README.md +182 -26
  2. package/dist/api/types.d.ts +35 -0
  3. package/dist/api/types.js +49 -1
  4. package/dist/auth/login.d.ts +0 -4
  5. package/dist/auth/login.js +52 -115
  6. package/dist/auth/login.spec.js +0 -98
  7. package/dist/basecommand.js +2 -2
  8. package/dist/commands/app/getApiKey.js +2 -2
  9. package/dist/commands/entities/create.d.ts +49 -0
  10. package/dist/commands/entities/create.js +618 -0
  11. package/dist/commands/entities/create.spec.js +581 -0
  12. package/dist/commands/entities/delete.d.ts +20 -0
  13. package/dist/commands/entities/delete.js +146 -0
  14. package/dist/commands/entities/get.d.ts +25 -0
  15. package/dist/commands/entities/get.js +298 -0
  16. package/dist/commands/entities/grammar.spec.d.ts +1 -0
  17. package/dist/commands/entities/grammar.spec.js +79 -0
  18. package/dist/commands/entities/output.spec.d.ts +1 -0
  19. package/dist/commands/entities/output.spec.js +72 -0
  20. package/dist/commands/entities/update.d.ts +32 -0
  21. package/dist/commands/entities/update.js +212 -0
  22. package/dist/commands/webhooks/delete.js +2 -3
  23. package/dist/common.d.ts +10 -1
  24. package/dist/common.js +37 -1
  25. package/dist/common.spec.d.ts +1 -0
  26. package/dist/common.spec.js +40 -0
  27. package/dist/helpers/config/config.d.ts +3 -3
  28. package/dist/helpers/config/config.js +3 -3
  29. package/dist/helpers/entities/assortment-items.d.ts +11 -0
  30. package/dist/helpers/entities/assortment-items.js +76 -0
  31. package/dist/helpers/entities/batchFetch.d.ts +11 -0
  32. package/dist/helpers/entities/batchFetch.js +50 -0
  33. package/dist/helpers/entities/index.d.ts +3 -0
  34. package/dist/helpers/entities/index.js +6 -0
  35. package/dist/helpers/entities/items.d.ts +6 -0
  36. package/dist/helpers/entities/items.js +60 -0
  37. package/dist/helpers/entities/items.spec.d.ts +1 -0
  38. package/dist/helpers/entities/items.spec.js +19 -0
  39. package/dist/helpers/entities/project-items.d.ts +2 -0
  40. package/dist/helpers/entities/project-items.js +44 -0
  41. package/dist/helpers/file-helpers.d.ts +1 -0
  42. package/dist/helpers/file-helpers.js +20 -3
  43. package/dist/helpers/propertySpecifications/dateRanges.d.ts +34 -0
  44. package/dist/helpers/propertySpecifications/dateRanges.js +91 -0
  45. package/dist/helpers/propertySpecifications/dateRanges.spec.d.ts +1 -0
  46. package/dist/helpers/propertySpecifications/dateRanges.spec.js +97 -0
  47. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +39 -0
  48. package/dist/helpers/propertySpecifications/propertySpecifications.js +102 -0
  49. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +1 -0
  50. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +387 -0
  51. package/dist/helpers/propertySpecifications/propertyValues.d.ts +31 -0
  52. package/dist/helpers/propertySpecifications/propertyValues.js +132 -0
  53. package/dist/helpers/propertySpecifications/propertyValues.spec.d.ts +1 -0
  54. package/dist/helpers/propertySpecifications/propertyValues.spec.js +156 -0
  55. package/dist/logger.js +4 -1
  56. package/dist/logger.spec.d.ts +1 -0
  57. package/dist/logger.spec.js +12 -0
  58. package/node_modules/@contrail/entity-compare/package.json +6 -3
  59. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  60. package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
  61. package/node_modules/@contrail/loader/lib/constants.js +1 -9
  62. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
  63. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
  64. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
  65. package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
  66. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
  67. package/node_modules/@contrail/loader/package.json +2 -2
  68. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +1 -4
  69. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  70. package/node_modules/@contrail/sdk/lib/config/config.d.ts +3 -0
  71. package/node_modules/@contrail/sdk/lib/config/config.js +13 -7
  72. package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
  73. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
  74. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +3 -1
  75. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +1 -0
  76. package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
  77. package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
  78. package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
  79. package/node_modules/@contrail/sdk/lib/image-search/index.js +17 -0
  80. package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
  81. package/node_modules/@contrail/sdk/lib/index.js +1 -0
  82. package/node_modules/@contrail/sdk/package.json +1 -1
  83. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
  84. package/oclif.manifest.json +449 -50
  85. package/package.json +6 -12
  86. package/dist/auth/sso.d.ts +0 -36
  87. package/dist/auth/sso.js +0 -168
  88. package/dist/auth/sso.spec.js +0 -138
  89. package/dist/commands/login.d.ts +0 -12
  90. package/dist/commands/login.js +0 -25
  91. /package/dist/{auth/sso.spec.d.ts → commands/entities/create.spec.d.ts} +0 -0
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const amazon_cognito_identity_js_1 = require("amazon-cognito-identity-js");
5
4
  const sdk_1 = require("@contrail/sdk");
6
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
5
  const config_1 = require("../helpers/config/config");
8
- const logger_1 = tslib_1.__importDefault(require("../logger"));
9
6
  const login_1 = require("./login");
10
7
  const mockAuthenticateUser = jest.fn();
11
8
  jest.mock('amazon-cognito-identity-js', () => ({
@@ -212,101 +209,6 @@ describe('authUser with stored tokens', () => {
212
209
  expect(mockAuthenticateUser).not.toHaveBeenCalled();
213
210
  });
214
211
  });
215
- describe('signIn with SSO', () => {
216
- const originalFetch = global.fetch;
217
- const originalEmail = process.env.CONTRAIL_CLI_EMAIL;
218
- const originalPassword = process.env.CONTRAIL_CLI_PASSWORD;
219
- const DEV_COGNITO_DOMAIN = 'https://dev-vibeiq.auth.us-east-1.amazoncognito.com';
220
- let fetchMock;
221
- let promptSpy;
222
- function pasteCodeFromPrintedSignInUrl() {
223
- promptSpy.mockImplementation(async () => {
224
- const printed = logger_1.default.info.mock.calls.map(([message]) => message).join('\n');
225
- const signInUrl = new URL(printed.match(/https:\/\/\S+oauth2\/authorize\S+/)[0]);
226
- return { signInCode: `pasted-code#${signInUrl.searchParams.get('state')}` };
227
- });
228
- }
229
- beforeEach(() => {
230
- jest.clearAllMocks();
231
- process.env.CONTRAIL_CLI_EMAIL = 'dev@vibeiq.com';
232
- delete process.env.CONTRAIL_CLI_PASSWORD;
233
- config_1.getConfig.mockResolvedValue({ apiGateway: DEV_GATEWAY, orgSlug: 'adam-zone-1' });
234
- sdk_1.getCurrentUser.mockResolvedValue({ id: 'user-1' });
235
- mockAuthenticateUser.mockImplementation((_details, callbacks) => callbacks.onSuccess({ idToken: { jwtToken: 'cognito-id-token' } }));
236
- promptSpy = jest.spyOn(inquirer_1.default, 'prompt');
237
- pasteCodeFromPrintedSignInUrl();
238
- fetchMock = jest.fn();
239
- global.fetch = fetchMock;
240
- });
241
- afterEach(() => {
242
- promptSpy.mockRestore();
243
- global.fetch = originalFetch;
244
- restoreEnv('CONTRAIL_CLI_EMAIL', originalEmail);
245
- restoreEnv('CONTRAIL_CLI_PASSWORD', originalPassword);
246
- });
247
- it('should sign in through the domain identity provider with a pasted code', async () => {
248
- fetchMock
249
- .mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }))
250
- .mockResolvedValueOnce(jsonResponse(200, { access_token: 'cognito-access', refresh_token: 'cognito-refresh' }));
251
- const context = await (0, login_1.signIn)({ openBrowser: false });
252
- expect(fetchMock.mock.calls[0][0]).toBe(`${DEV_GATEWAY}/sso-login/domain-check/vibeiq.com`);
253
- const [tokenUrl, tokenRequest] = fetchMock.mock.calls[1];
254
- const tokenForm = new URLSearchParams(tokenRequest.body);
255
- expect(tokenUrl).toBe(`${DEV_COGNITO_DOMAIN}/oauth2/token`);
256
- expect(tokenForm.get('code')).toBe('pasted-code');
257
- expect(tokenForm.get('redirect_uri')).toBe('https://login.dev.vibeiq.com/cli');
258
- expect(context).toEqual({
259
- apiUserToken: 'cognito-access',
260
- apiRefreshToken: 'cognito-refresh',
261
- apiGateway: DEV_GATEWAY,
262
- orgSlug: 'adam-zone-1',
263
- });
264
- expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'sso' });
265
- });
266
- it('should reject a pasted code from a different sign-in attempt without saving tokens', async () => {
267
- fetchMock.mockResolvedValueOnce(jsonResponse(200, { identityProvider: 'sso-vibeiq-com' }));
268
- promptSpy.mockResolvedValue({ signInCode: 'pasted-code#another-state' });
269
- await expect((0, login_1.signIn)({ openBrowser: false })).rejects.toThrow('That sign-in code is not from this login attempt.');
270
- expect(config_1.storeConfig).not.toHaveBeenCalled();
271
- });
272
- it('should ask for a password when the email domain has no SSO', async () => {
273
- fetchMock
274
- .mockResolvedValueOnce(new Response('', { status: 200 }))
275
- .mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
276
- promptSpy.mockResolvedValue({ password: 'secret' });
277
- const context = await (0, login_1.signIn)({ openBrowser: false });
278
- expect(mockAuthenticateUser).toHaveBeenCalled();
279
- expect(context.apiUserToken).toBe('vibe-access');
280
- expect(config_1.storeConfig).toHaveBeenCalledWith({ ...context, signInMethod: 'password' });
281
- });
282
- it('should ask for a password when the email domain uses SSO the CLI cannot open', async () => {
283
- fetchMock
284
- .mockResolvedValueOnce(jsonResponse(200, { identityProvider: '', url: 'legacy' }))
285
- .mockResolvedValueOnce(jsonResponse(200, { accessToken: 'vibe-access', refreshToken: 'vibe-refresh' }));
286
- promptSpy.mockResolvedValue({ password: 'secret' });
287
- const context = await (0, login_1.signIn)({ openBrowser: false });
288
- expect(context.apiUserToken).toBe('vibe-access');
289
- expect(logger_1.default.info).toHaveBeenCalledWith(expect.stringContaining('The CLI does not support your SSO provider yet.'));
290
- });
291
- it('should refresh a stored SSO token through Cognito instead of the VibeIQ refresh endpoint', async () => {
292
- config_1.getConfig.mockResolvedValue({
293
- apiUserToken: 'expired-access',
294
- apiRefreshToken: 'cognito-refresh',
295
- apiGateway: DEV_GATEWAY,
296
- orgSlug: 'adam-zone-1',
297
- signInMethod: 'sso',
298
- });
299
- sdk_1.getCurrentUser
300
- .mockRejectedValueOnce(new Error('Failed to fetch current user. Unauthorized'))
301
- .mockResolvedValueOnce({ id: 'user-1' });
302
- fetchMock.mockResolvedValueOnce(jsonResponse(200, { access_token: 'refreshed-access' }));
303
- const context = await (0, login_1.authUser)();
304
- const [tokenUrl, tokenRequest] = fetchMock.mock.calls[0];
305
- expect(tokenUrl).toBe(`${DEV_COGNITO_DOMAIN}/oauth2/token`);
306
- expect(new URLSearchParams(tokenRequest.body).get('refresh_token')).toBe('cognito-refresh');
307
- expect(context.apiUserToken).toBe('refreshed-access');
308
- });
309
- });
310
212
  describe('getVersionFromPackageJson', () => {
311
213
  it('should return the version value from package.json', () => {
312
214
  const version = (0, login_1.getVersionFromPackageJson)();
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
+ const common_1 = require("./common");
6
7
  const logger_1 = tslib_1.__importDefault(require("./logger"));
7
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
8
  const config_1 = require("./helpers/config/config");
9
9
  const lodash_1 = require("lodash");
10
10
  const login_1 = require("./auth/login");
@@ -73,7 +73,7 @@ class BaseCommand extends core_1.Command {
73
73
  choices: ['yes', 'no'],
74
74
  default: 'no',
75
75
  });
76
- const { confirm } = await inquirer_1.default.prompt(questions);
76
+ const { confirm } = await (0, common_1.promptOnStderr)(questions);
77
77
  if (confirm === 'no') {
78
78
  logger_1.default.info('Please use `contrail config use` command to choose the configuration or `contrail config set --environment=prod` to set different environment.');
79
79
  this.exit(1);
@@ -35,7 +35,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
35
35
  },
36
36
  ];
37
37
  const answers = await inquirer_1.default.prompt(questions);
38
- logger_1.default.info(`App API key: (app:${answers.appApiKey})`);
38
+ this.log(`App API key: (app:${answers.appApiKey})`);
39
39
  }
40
40
  else {
41
41
  const appFound = installedApps.find((x) => x.app.identifier === this.flags.appIdentifier);
@@ -43,7 +43,7 @@ class GetAPIKeyApp extends basecommand_1.BaseCommand {
43
43
  logger_1.default.info('You do not have such an app installed');
44
44
  return;
45
45
  }
46
- logger_1.default.info(`App API key: (app:${appFound.apiKey.apiKey})`);
46
+ this.log(`App API key: (app:${appFound.apiKey.apiKey})`);
47
47
  }
48
48
  }
49
49
  }
@@ -0,0 +1,49 @@
1
+ import { PropertyLevel } from '@contrail/types';
2
+ import { ColonDelimited, TypeProperty as ExtendedTypeProperty, TypeReferencesCacheByPath } from '../../api/types';
3
+ import { TypeWithProperties } from '../../api/types';
4
+ import { BaseCommand } from '../../basecommand';
5
+ import { Role } from '../../helpers/entities';
6
+ export default class CreateEntity extends BaseCommand {
7
+ static description: string;
8
+ static examples: string[];
9
+ static flags: {
10
+ count: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ dryRun: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
12
+ inputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ outputFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ generateValues: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ readableIds: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
16
+ skipHydrateRelationships: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ suffix: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
18
+ apiVersion: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
19
+ alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
20
+ logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
+ };
22
+ static args: {
23
+ typePath: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
24
+ };
25
+ static strict: boolean;
26
+ init(): Promise<void>;
27
+ run(): Promise<void>;
28
+ }
29
+ export type CreateSummary = {
30
+ created: any[];
31
+ failed: {
32
+ input: any;
33
+ error: string;
34
+ }[];
35
+ };
36
+ export declare function summarizeSettledCreates(inputs: any[], settled: PromiseSettledResult<any>[]): CreateSummary;
37
+ export declare function pickRandomPropertyValues(type: TypeWithProperties, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath, roles?: Role[], suppliedSlugs?: Set<string>): any;
38
+ export type WithId = {
39
+ id: string;
40
+ [key: string]: any;
41
+ };
42
+ export type ObjectReferenceCache = Map<string, WithId>;
43
+ type ObjectReferenceCachesByTypePath = Map<string, ObjectReferenceCache>;
44
+ export declare function pickRandomValueForProperty(property: ExtendedTypeProperty, objectReferencesCache: ObjectReferenceCachesByTypePath, typeReferencesCache: TypeReferencesCacheByPath): number | string | string[] | boolean | null;
45
+ export declare function getReferencedObjectPaths(type: TypeWithProperties): ColonDelimited[];
46
+ export declare function buildObjectReferenceCache(entities: any[]): ObjectReferenceCache;
47
+ export declare function selectRandomObject(cache: ObjectReferenceCache): WithId;
48
+ export declare function doesPropertyLevelMatchRole(propertyLevel: PropertyLevel, role: Role): boolean;
49
+ export {};