@contrail/cli 3.6.0-alpha-8-alpha.2ab4f80 → 3.6.0-alpha.aae3e70

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 (163) hide show
  1. package/README.md +45 -151
  2. package/dist/api/feature-flags.d.ts +3 -0
  3. package/dist/api/feature-flags.js +29 -0
  4. package/dist/api/types.d.ts +0 -35
  5. package/dist/api/types.js +1 -49
  6. package/dist/api/users.d.ts +1 -0
  7. package/dist/api/users.js +10 -1
  8. package/dist/auth/login.d.ts +4 -0
  9. package/dist/auth/login.js +169 -94
  10. package/dist/auth/login.spec.js +305 -0
  11. package/dist/auth/sso.d.ts +36 -0
  12. package/dist/auth/sso.js +164 -0
  13. package/dist/auth/sso.spec.js +119 -0
  14. package/dist/basecommand.d.ts +1 -3
  15. package/dist/basecommand.js +4 -4
  16. package/dist/commands/app/getApiKey.js +2 -2
  17. package/dist/commands/config/set.js +1 -1
  18. package/dist/commands/feature-flags/export.d.ts +19 -0
  19. package/dist/commands/feature-flags/export.js +66 -0
  20. package/dist/commands/feature-flags/export.spec.js +109 -0
  21. package/dist/commands/feature-flags/import.d.ts +42 -0
  22. package/dist/commands/feature-flags/import.js +191 -0
  23. package/dist/commands/feature-flags/import.spec.js +194 -0
  24. package/dist/commands/instance/export.d.ts +9 -0
  25. package/dist/commands/instance/export.js +18 -3
  26. package/dist/commands/instance/export.spec.js +32 -0
  27. package/dist/commands/instance/import.d.ts +3 -0
  28. package/dist/commands/instance/import.js +5 -0
  29. package/dist/commands/instance/import.spec.js +4 -0
  30. package/dist/commands/login.d.ts +12 -0
  31. package/dist/commands/login.js +25 -0
  32. package/dist/common.d.ts +1 -4
  33. package/dist/common.js +1 -18
  34. package/dist/helpers/config/config.d.ts +5 -4
  35. package/dist/helpers/config/config.js +10 -12
  36. package/dist/helpers/file-helpers.d.ts +0 -1
  37. package/dist/helpers/file-helpers.js +3 -20
  38. package/dist/logger.js +1 -4
  39. package/node_modules/@contrail/entity-compare/package.json +3 -6
  40. package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
  41. package/node_modules/@contrail/loader/lib/constants.d.ts +8 -0
  42. package/node_modules/@contrail/loader/lib/constants.js +9 -1
  43. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +4 -0
  44. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +57 -0
  45. package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +492 -34
  46. package/node_modules/@contrail/loader/lib/pipeline/validate.js +2 -52
  47. package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +0 -85
  48. package/node_modules/@contrail/loader/package.json +2 -2
  49. package/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +4 -1
  50. package/node_modules/@contrail/sdk/lib/auth/login.js +1 -1
  51. package/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -3
  52. package/node_modules/@contrail/sdk/lib/config/config.js +7 -13
  53. package/node_modules/@contrail/sdk/lib/core/request.js +2 -6
  54. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -2
  55. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +1 -3
  56. package/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -1
  57. package/node_modules/@contrail/sdk/package.json +1 -1
  58. package/oclif.manifest.json +75 -365
  59. package/package.json +15 -5
  60. package/dist/commands/entities/create.d.ts +0 -49
  61. package/dist/commands/entities/create.js +0 -643
  62. package/dist/commands/entities/create.spec.js +0 -545
  63. package/dist/commands/entities/delete.d.ts +0 -20
  64. package/dist/commands/entities/delete.js +0 -137
  65. package/dist/commands/entities/get.d.ts +0 -25
  66. package/dist/commands/entities/get.js +0 -276
  67. package/dist/commands/entities/grammar.spec.js +0 -80
  68. package/dist/commands/entities/output.spec.js +0 -72
  69. package/dist/commands/entities/update.d.ts +0 -32
  70. package/dist/commands/entities/update.js +0 -160
  71. package/dist/helpers/entities/assortment-items.d.ts +0 -12
  72. package/dist/helpers/entities/assortment-items.js +0 -87
  73. package/dist/helpers/entities/batchFetch.d.ts +0 -8
  74. package/dist/helpers/entities/batchFetch.js +0 -49
  75. package/dist/helpers/entities/index.d.ts +0 -3
  76. package/dist/helpers/entities/index.js +0 -6
  77. package/dist/helpers/entities/items.d.ts +0 -10
  78. package/dist/helpers/entities/items.js +0 -102
  79. package/dist/helpers/entities/project-items.d.ts +0 -3
  80. package/dist/helpers/entities/project-items.js +0 -65
  81. package/dist/helpers/propertySpecifications/dateRanges.d.ts +0 -38
  82. package/dist/helpers/propertySpecifications/dateRanges.js +0 -89
  83. package/dist/helpers/propertySpecifications/dateRanges.spec.js +0 -95
  84. package/dist/helpers/propertySpecifications/propertySpecifications.d.ts +0 -40
  85. package/dist/helpers/propertySpecifications/propertySpecifications.js +0 -109
  86. package/dist/helpers/propertySpecifications/propertySpecifications.spec.d.ts +0 -1
  87. package/dist/helpers/propertySpecifications/propertySpecifications.spec.js +0 -373
  88. package/dist/logger.spec.d.ts +0 -1
  89. package/dist/logger.spec.js +0 -12
  90. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
  91. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
  92. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
  93. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
  94. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
  95. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
  96. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
  97. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
  98. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
  99. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
  100. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
  101. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
  102. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.js +0 -17
  103. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
  104. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
  105. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
  106. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
  107. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
  108. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
  109. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
  110. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
  111. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
  112. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
  113. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
  114. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
  115. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
  116. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
  117. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
  118. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
  119. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
  120. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
  121. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
  122. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
  123. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
  124. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
  125. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
  126. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
  127. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
  128. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
  129. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
  130. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
  131. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
  132. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
  133. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
  134. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
  135. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
  136. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
  137. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
  138. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
  139. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
  140. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
  141. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
  142. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
  143. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
  144. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
  145. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
  146. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
  147. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
  148. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
  149. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
  150. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
  151. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
  152. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
  153. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
  154. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
  155. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
  156. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
  157. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
  158. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  159. package/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
  160. /package/dist/{commands/entities/create.spec.d.ts → auth/sso.spec.d.ts} +0 -0
  161. /package/dist/commands/{entities/grammar.spec.d.ts → feature-flags/export.spec.d.ts} +0 -0
  162. /package/dist/commands/{entities/output.spec.d.ts → feature-flags/import.spec.d.ts} +0 -0
  163. /package/dist/{helpers/propertySpecifications/dateRanges.spec.d.ts → commands/instance/export.spec.d.ts} +0 -0
@@ -1,151 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Files = void 0;
16
- const node_fetch_1 = __importDefault(require("node-fetch"));
17
- const entities_1 = require("../entities");
18
- const FormData = require('form-data');
19
- const file_type_helper_1 = require("./file-type-helper");
20
- const RETRYABLE_HTTP_STATUSES = new Set([408, 429, 500, 502, 503, 504]);
21
- class NonRetryableError extends Error {
22
- constructor(cause) {
23
- super(cause.message);
24
- this.cause = cause;
25
- }
26
- }
27
- class Files {
28
- constructor(ctx) {
29
- this.ctx = ctx;
30
- }
31
- createAndUploadFile(file, ownedByReference = null, ttl = null) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- if (!ownedByReference && !ttl) {
34
- throw new Error('You must specify either an ownedByReference or a ttl');
35
- }
36
- const contentType = file.type || file_type_helper_1.FileTypeHelper.getContentType(file);
37
- const object = {
38
- contentType,
39
- fileName: file.name,
40
- };
41
- if (ownedByReference) {
42
- object.ownedByReference = ownedByReference;
43
- }
44
- if (ttl) {
45
- object.ttl = ttl;
46
- }
47
- const fileEntity = yield new entities_1.Entities(this.ctx).create({ entityName: 'file', object });
48
- yield this.uploadFile(fileEntity.uploadPost, file);
49
- return fileEntity;
50
- });
51
- }
52
- createAndUploadFileFromBuffer(buffer, contentType, fileName, ownedByReference = null, ttl = null) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- if (!ownedByReference && !ttl) {
55
- throw new Error('You must specify either an ownedByReference or a ttl');
56
- }
57
- const object = {
58
- contentType,
59
- fileName,
60
- };
61
- if (ownedByReference) {
62
- object.ownedByReference = ownedByReference;
63
- }
64
- if (ttl) {
65
- object.ttl = ttl;
66
- }
67
- const fileEntity = yield new entities_1.Entities(this.ctx).create({ entityName: 'file', object });
68
- const fileDetails = {
69
- contentType,
70
- name: 'file',
71
- filename: fileName,
72
- };
73
- yield this.uploadFileAsStream(fileEntity.uploadPost, buffer, fileDetails);
74
- return fileEntity;
75
- });
76
- }
77
- uploadFile(uploadPost, file) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- return this.withRetry(() => __awaiter(this, void 0, void 0, function* () {
80
- const formData = new FormData();
81
- formData.append('Content-Type', file.type || file_type_helper_1.FileTypeHelper.getContentType(file));
82
- this.appendUploadHeaders(uploadPost, formData);
83
- formData.append('file', file);
84
- const response = yield (0, node_fetch_1.default)(uploadPost.url, { method: 'POST', body: formData });
85
- if (!response.ok) {
86
- const errorText = yield response.text();
87
- const error = new Error(`File upload failed with status ${response.status}: ${errorText}`);
88
- if (!RETRYABLE_HTTP_STATUSES.has(response.status))
89
- throw new NonRetryableError(error);
90
- throw error;
91
- }
92
- yield response.text();
93
- }), 'Files.uploadFile', () => console.error(`[Files.uploadFile: Max attempts reached] file: ${file.name}, size: ${file.size}`));
94
- });
95
- }
96
- uploadFileAsStream(uploadPost, buffer, options) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- return this.withRetry(() => __awaiter(this, void 0, void 0, function* () {
99
- const formData = new FormData();
100
- if (options === null || options === void 0 ? void 0 : options.contentType) {
101
- formData.append('Content-Type', options.contentType);
102
- }
103
- this.appendUploadHeaders(uploadPost, formData);
104
- formData.append('file', buffer);
105
- const contentLength = yield new Promise((resolve, reject) => {
106
- formData.getLength((err, length) => (err ? reject(new NonRetryableError(err)) : resolve(length)));
107
- });
108
- const response = yield (0, node_fetch_1.default)(uploadPost.url, {
109
- method: 'POST',
110
- body: formData,
111
- headers: { 'Content-Length': contentLength },
112
- });
113
- if (!response.ok) {
114
- const errorText = yield response.text();
115
- const error = new Error(`File upload failed with status ${response.status}: ${errorText}`);
116
- if (!RETRYABLE_HTTP_STATUSES.has(response.status))
117
- throw new NonRetryableError(error);
118
- throw error;
119
- }
120
- yield response.text();
121
- }), 'Files.uploadFileAsStream', () => console.error(`[Files.uploadFileAsStream: Max attempts reached] size: ${'size' in buffer ? buffer.size : buffer.length}`));
122
- });
123
- }
124
- withRetry(operation, context, onExhausted) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- const MAX_ATTEMPTS = 3;
127
- const RETRY_DELAY_MS = 1000;
128
- for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
129
- try {
130
- return yield operation();
131
- }
132
- catch (error) {
133
- if (error instanceof NonRetryableError)
134
- throw error.cause;
135
- console.error(`[Attempt ${attempt}][${context}: Error]`, error);
136
- if (attempt >= MAX_ATTEMPTS) {
137
- onExhausted();
138
- throw error;
139
- }
140
- yield new Promise((resolve) => setTimeout(resolve, attempt * RETRY_DELAY_MS));
141
- }
142
- }
143
- });
144
- }
145
- appendUploadHeaders(uploadPost, formData) {
146
- Object.entries(uploadPost.fields).forEach(([k, v]) => {
147
- formData.append(k, v);
148
- });
149
- }
150
- }
151
- exports.Files = Files;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./files"), exports);
@@ -1,10 +0,0 @@
1
- export * from './types';
2
- export * from './config';
3
- export * from './core';
4
- export * from './entities';
5
- export * from './content';
6
- export * from './files';
7
- export * from './auth';
8
- export * from './policies';
9
- export * from './assets';
10
- export * from './notifications';
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./config"), exports);
19
- __exportStar(require("./core"), exports);
20
- __exportStar(require("./entities"), exports);
21
- __exportStar(require("./content"), exports);
22
- __exportStar(require("./files"), exports);
23
- __exportStar(require("./auth"), exports);
24
- __exportStar(require("./policies"), exports);
25
- __exportStar(require("./assets"), exports);
26
- __exportStar(require("./notifications"), exports);
@@ -1 +0,0 @@
1
- export * from './notifications-dispatcher';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./notifications-dispatcher"), exports);
@@ -1,16 +0,0 @@
1
- import { InvocationContext } from '../config';
2
- export declare enum LogLevel {
3
- WARN = "WARN",
4
- ERROR = "ERROR",
5
- INFO = "INFO"
6
- }
7
- export interface NotificationDispatchOptions {
8
- message: string;
9
- level: LogLevel;
10
- context?: any;
11
- }
12
- export declare class Notification {
13
- private ctx;
14
- constructor(ctx?: InvocationContext);
15
- Dispatch(options: NotificationDispatchOptions): Promise<any>;
16
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Notification = exports.LogLevel = void 0;
13
- const entities_1 = require("../entities");
14
- var LogLevel;
15
- (function (LogLevel) {
16
- LogLevel["WARN"] = "WARN";
17
- LogLevel["ERROR"] = "ERROR";
18
- LogLevel["INFO"] = "INFO";
19
- })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
20
- class Notification {
21
- constructor(ctx) {
22
- this.ctx = ctx;
23
- }
24
- Dispatch(options) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return yield new entities_1.Entities(this.ctx).create({
27
- entityName: 'system-notification',
28
- object: {
29
- message: options.message,
30
- level: options.level,
31
- context: options.context,
32
- },
33
- });
34
- });
35
- }
36
- }
37
- exports.Notification = Notification;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./policies.client"), exports);
@@ -1,12 +0,0 @@
1
- import { InvocationContext } from '../config';
2
- import { Policy } from '@contrail/policies';
3
- export declare class PoliciesCache {
4
- getPolicy(policyIdentifier: string, ctx?: InvocationContext): Promise<Policy>;
5
- setPolicy(policy: Policy, ctx?: InvocationContext): Promise<null>;
6
- clearLocal(): void;
7
- getOrgId(ctx?: InvocationContext): string;
8
- private getLocalCacheKey;
9
- private getHashKey;
10
- private get;
11
- private set;
12
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PoliciesCache = void 0;
13
- let LOCAL_CACHE = {};
14
- class PoliciesCache {
15
- getPolicy(policyIdentifier, ctx) {
16
- return this.get(policyIdentifier, ctx);
17
- }
18
- setPolicy(policy, ctx) {
19
- return this.set(policy, ctx);
20
- }
21
- clearLocal() {
22
- LOCAL_CACHE = {};
23
- }
24
- getOrgId(ctx) {
25
- if (!(ctx === null || ctx === void 0 ? void 0 : ctx.orgId)) {
26
- throw new Error('orgId required on ctx');
27
- }
28
- return ctx.orgId;
29
- }
30
- getLocalCacheKey(policyIdentifier, ctx) {
31
- const orgId = this.getOrgId(ctx);
32
- const policyKey = `org:${orgId}|${policyIdentifier}`;
33
- return policyKey;
34
- }
35
- getHashKey(ctx) {
36
- return `org:${this.getOrgId(ctx)}|Policies_HASH`;
37
- }
38
- get(policyIdentifier, ctx) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const policyKey = this.getLocalCacheKey(policyIdentifier, ctx);
41
- console.log('PoliciesCache: get [LOCAL CACHE] ', policyIdentifier);
42
- return LOCAL_CACHE[policyKey];
43
- });
44
- }
45
- set(policy, ctx) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const policyOwnerReference = policy.ownerReference;
48
- const policyKey = this.getLocalCacheKey(policy, ctx);
49
- console.log('PoliciesCache: set [LOCAL CACHE] ', policyKey);
50
- LOCAL_CACHE[this.getLocalCacheKey(policyOwnerReference, ctx)] = policy;
51
- return;
52
- });
53
- }
54
- }
55
- exports.PoliciesCache = PoliciesCache;
@@ -1,9 +0,0 @@
1
- import { Operation } from '@contrail/policies';
2
- import { InvocationContext } from '../config';
3
- export declare class PoliciesClient {
4
- private ctx;
5
- constructor(ctx: InvocationContext);
6
- static clearPoliciesCache(): void;
7
- verifyRequest(policyOwnerType: string, policyOwnerId: string, operation: Operation): Promise<boolean>;
8
- }
9
- export declare function getPrincipalReferences(ctx: InvocationContext): string[];
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getPrincipalReferences = exports.PoliciesClient = void 0;
13
- const policies_cache_1 = require("./policies-cache");
14
- const policies_1 = require("@contrail/policies");
15
- const entities_1 = require("../entities");
16
- const CACHE = new policies_cache_1.PoliciesCache();
17
- class InvalidPolicyError extends Error {
18
- }
19
- class PoliciesClient {
20
- constructor(ctx) {
21
- this.ctx = ctx;
22
- }
23
- static clearPoliciesCache() {
24
- CACHE.clearLocal();
25
- }
26
- verifyRequest(policyOwnerType, policyOwnerId, operation) {
27
- var _a, _b, _c;
28
- return __awaiter(this, void 0, void 0, function* () {
29
- if (!policyOwnerType || !policyOwnerId || !operation) {
30
- throw new InvalidPolicyError(`Cannot verify request, Missing params. policyOwnerType:${policyOwnerType}, policyOwnerId:${policyOwnerId}, operation:${operation}`);
31
- }
32
- if (((_b = (_a = this.ctx) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.role) === 'GUEST' || ((_c = this.ctx) === null || _c === void 0 ? void 0 : _c.isLambdaCaller)) {
33
- console.log('Policies: Skipping policy check');
34
- return true;
35
- }
36
- const policy = yield getPolicy(this.ctx, policyOwnerType, policyOwnerId);
37
- if (!policy) {
38
- throw new InvalidPolicyError(`No policy found for: policyOwnerType:${policyOwnerType}, policyOwnerId:${policyOwnerId}`);
39
- }
40
- const principalReferences = getPrincipalReferences(this.ctx);
41
- return (0, policies_1.checkPermission)(principalReferences, policy, operation);
42
- });
43
- }
44
- }
45
- exports.PoliciesClient = PoliciesClient;
46
- function getPolicy(ctx, policyOwnerType, policyOwnerId) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const policyKey = policyOwnerType + ':' + policyOwnerId;
49
- const cachedPolicy = yield CACHE.getPolicy(policyKey, ctx);
50
- if (cachedPolicy) {
51
- console.log('Policies: Cache hit for: ', policyKey);
52
- return Promise.resolve(cachedPolicy);
53
- }
54
- console.log('Policies: Cache miss for: ', policyKey);
55
- const policies = yield new entities_1.Entities(ctx).get({
56
- entityName: 'policy',
57
- criteria: { ownerReference: policyOwnerType + ':' + policyOwnerId },
58
- });
59
- let policy;
60
- if (policies === null || policies === void 0 ? void 0 : policies.length) {
61
- policy = policies[0];
62
- CACHE.setPolicy(policy, ctx);
63
- }
64
- return policy;
65
- });
66
- }
67
- function getPrincipalReferences(ctx) {
68
- var _a, _b;
69
- if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.user) === null || _a === void 0 ? void 0 : _a.principalReferences) {
70
- return ctx.user.principalReferences;
71
- }
72
- return ['user:' + ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.user) === null || _b === void 0 ? void 0 : _b.id)];
73
- }
74
- exports.getPrincipalReferences = getPrincipalReferences;
@@ -1,2 +0,0 @@
1
- export * from './types.client';
2
- export * from './sub-types-helper';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types.client"), exports);
18
- __exportStar(require("./sub-types-helper"), exports);
@@ -1,18 +0,0 @@
1
- import { Type } from '@contrail/types';
2
- export interface TypeListEntry {
3
- label: string;
4
- id: string;
5
- pathLabel: string;
6
- typePath: string;
7
- parentId: string;
8
- }
9
- export declare class SubTypesHelper {
10
- static getSubTypesFromPath(typePath: any): Promise<any>;
11
- static getTypeListFromPath(typePath: string, options?: {
12
- includeParentTypes?: boolean;
13
- }): Promise<TypeListEntry[]>;
14
- static getTypeListFromTypes(types: Type[], options?: {
15
- includeParentTypes?: boolean;
16
- }): Array<TypeListEntry>;
17
- static clearCache(): Promise<void>;
18
- }
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SubTypesHelper = void 0;
13
- const entities_1 = require("../entities");
14
- const types_client_1 = require("./types.client");
15
- let CACHE = {};
16
- class SubTypesHelper {
17
- static getSubTypesFromPath(typePath) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- let cached = CACHE[typePath];
20
- if (cached) {
21
- return cached;
22
- }
23
- const type = yield new types_client_1.Types().getByRootAndPath({ path: typePath });
24
- let types = yield new entities_1.Entities().get({
25
- entityName: 'type',
26
- criteria: { typeRootId: type.typeRootId },
27
- });
28
- types = types.filter((type) => type.typePath.includes(typePath));
29
- CACHE[typePath] = types;
30
- return types;
31
- });
32
- }
33
- static getTypeListFromPath(typePath, options) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const types = yield this.getSubTypesFromPath(typePath);
36
- return this.getTypeListFromTypes(types, options);
37
- });
38
- }
39
- static getTypeListFromTypes(types, options) {
40
- const pathMap = {};
41
- const leafNodes = {};
42
- const idMap = {};
43
- let list = [];
44
- for (let type of types) {
45
- pathMap[type.typePath] = type;
46
- leafNodes[type.typePath] = type;
47
- idMap[type.id] = type;
48
- }
49
- const shouldRemoveTypesWithChildren = !options || !options.includeParentTypes;
50
- if (shouldRemoveTypesWithChildren) {
51
- for (const type of types) {
52
- const parentPath = type.typePath.substring(0, type.typePath.lastIndexOf(':'));
53
- if (pathMap[parentPath]) {
54
- delete leafNodes[parentPath];
55
- }
56
- }
57
- }
58
- function addLabel(path, array) {
59
- let typeForLevel = pathMap[path];
60
- if (typeForLevel) {
61
- array.push(typeForLevel.label);
62
- }
63
- }
64
- const leafNodeList = Object.values(leafNodes);
65
- for (let type of leafNodeList) {
66
- let labelArray = [];
67
- let path = type.typePath;
68
- while (path.indexOf(':') > 0) {
69
- addLabel(path, labelArray);
70
- path = path.substring(0, path.lastIndexOf(':'));
71
- }
72
- addLabel(path, labelArray);
73
- let labelPath;
74
- if (labelArray.length > 1) {
75
- labelPath = labelArray.reverse().join('\\');
76
- }
77
- else if (labelArray.length === 1) {
78
- labelPath = labelArray[0];
79
- }
80
- const entry = {
81
- label: type.label,
82
- typePath: type.typePath,
83
- id: type.id,
84
- parentId: type.parentid,
85
- pathLabel: labelPath,
86
- };
87
- list.push(entry);
88
- }
89
- list = list.sort((o1, o2) => (o1.typePath > o2.typePath ? 1 : -1));
90
- return list;
91
- }
92
- static clearCache() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- CACHE = {};
95
- });
96
- }
97
- }
98
- exports.SubTypesHelper = SubTypesHelper;
@@ -1,19 +0,0 @@
1
- import { InvocationContext } from '../config';
2
- import { Type } from '@contrail/types';
3
- interface GetPropertyParams {
4
- typeId: string;
5
- propertySlug: string;
6
- }
7
- export declare class TypesCache {
8
- constructor();
9
- getType(typeIdentifier: string, ctx?: InvocationContext): Promise<Type>;
10
- setType(typeIdentifier: any, type: Type, ctx?: InvocationContext): Promise<null>;
11
- setTypePropertyMap(type: Type): void;
12
- getProperty(params: GetPropertyParams): any;
13
- clearLocal(): void;
14
- private getOrgSlug;
15
- private getLocalCacheKey;
16
- private get;
17
- private set;
18
- }
19
- export {};