@contrail/cli 3.6.0-alpha-8-alpha.2ad94f7 → 3.6.0-alpha-8-alpha.5396d7b

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 (84) hide show
  1. package/README.md +3 -3
  2. package/dist/auth/login.js +13 -20
  3. package/dist/basecommand.d.ts +1 -3
  4. package/dist/basecommand.js +1 -1
  5. package/dist/commands/config/set.js +1 -1
  6. package/dist/helpers/config/config.d.ts +0 -1
  7. package/dist/helpers/config/config.js +1 -8
  8. package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
  9. package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
  10. package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
  11. package/node_modules/@contrail/{org-config-migration/node_modules/@contrail/sdk/lib/assets → sdk/lib/image-search}/index.js +1 -1
  12. package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
  13. package/node_modules/@contrail/sdk/lib/index.js +1 -0
  14. package/node_modules/@contrail/sdk/package.json +1 -1
  15. package/oclif.manifest.json +2 -3
  16. package/package.json +2 -2
  17. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
  18. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
  19. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
  20. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
  21. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
  22. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
  23. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
  24. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
  25. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
  26. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
  27. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
  28. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
  29. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
  30. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
  31. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
  32. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
  33. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
  34. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
  35. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
  36. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
  37. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
  38. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
  39. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
  40. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
  41. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
  42. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
  43. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
  44. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
  45. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
  46. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
  47. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
  48. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
  49. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
  50. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
  51. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
  52. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
  53. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
  54. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
  55. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
  56. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
  57. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
  58. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
  59. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
  60. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
  61. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
  62. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
  63. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
  64. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
  65. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
  66. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
  67. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
  68. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
  69. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
  70. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
  71. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
  72. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
  73. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
  74. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
  75. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
  76. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
  77. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
  78. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
  79. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
  80. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
  81. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
  82. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
  83. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
  84. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
@@ -1,11 +0,0 @@
1
- <svg width="635" height="433" viewBox="0 0 635 433" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <g clip-path="url(#clip0_309_15692)">
3
- <path d="M656.604 384.076C457.662 384.076 414.538 48.9114 216.574 48.9114C172.144 48.9339 129.54 66.5999 98.1308 98.0252C66.7213 129.451 49.077 172.063 49.077 216.494" stroke="#202532" stroke-width="97.8221" stroke-miterlimit="10"/>
4
- <path d="M49.077 216.494C49.077 309.04 128.454 384.076 216.66 384.076C415.601 384.076 457.747 48.9114 656.689 48.9114C701.134 48.9114 743.76 66.5673 775.188 97.9952C806.615 129.423 824.272 172.048 824.272 216.494C824.272 260.94 806.615 303.565 775.188 334.993C743.76 366.421 701.134 384.076 656.689 384.076" stroke="#00ABE9" stroke-width="97.8221" stroke-miterlimit="10"/>
5
- </g>
6
- <defs>
7
- <clipPath id="clip0_309_15692">
8
- <rect width="873.016" height="432.987" fill="white" transform="translate(0.166809)"/>
9
- </clipPath>
10
- </defs>
11
- </svg>
@@ -1,9 +0,0 @@
1
- export interface CreateAssetOptions {
2
- file?: File;
3
- contentHolderReference?: string;
4
- fileId?: string;
5
- workspaceId?: string;
6
- }
7
- export declare class Assets {
8
- create(options: CreateAssetOptions): Promise<any>;
9
- }
@@ -1,54 +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.Assets = void 0;
13
- const entities_1 = require("../entities");
14
- const file_type_helper_1 = require("../files/file-type-helper");
15
- const files_1 = require("../files/files");
16
- class Assets {
17
- create(options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- let asset = null;
20
- if (options.file) {
21
- const file = options.file;
22
- if (!file) {
23
- throw Error(`Must specify file in create.`);
24
- }
25
- const contentType = file.type || file_type_helper_1.FileTypeHelper.getContentType(file);
26
- asset = yield new entities_1.Entities().create({
27
- entityName: 'asset',
28
- object: {
29
- contentHolderReference: options.contentHolderReference,
30
- fileName: file.name,
31
- contentType,
32
- workspaceId: options.workspaceId,
33
- },
34
- });
35
- yield new files_1.Files().uploadFile(asset.content.primaryFile.uploadPost, file);
36
- }
37
- else if (options.fileId) {
38
- asset = yield new entities_1.Entities().create({
39
- entityName: 'asset',
40
- object: {
41
- contentHolderReference: options.contentHolderReference,
42
- copyFileId: options.fileId,
43
- workspaceId: options.workspaceId,
44
- },
45
- });
46
- }
47
- else {
48
- throw new Error('Must specify file or fileId');
49
- }
50
- return asset;
51
- });
52
- }
53
- }
54
- exports.Assets = Assets;
@@ -1,10 +0,0 @@
1
- export interface AuthContext {
2
- apiUserToken: string;
3
- apiRefreshToken?: string;
4
- apiGateway?: string;
5
- orgSlug?: string;
6
- orgId?: string;
7
- }
8
- export declare class Auth {
9
- static config: AuthContext;
10
- }
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Auth = void 0;
4
- class Auth {
5
- }
6
- exports.Auth = Auth;
@@ -1,2 +0,0 @@
1
- export * from './login';
2
- export * from './auth';
@@ -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("./login"), exports);
18
- __exportStar(require("./auth"), exports);
@@ -1,10 +0,0 @@
1
- import { AuthContext } from './auth';
2
- export interface LoginCredentials {
3
- orgSlug: string;
4
- email?: string;
5
- password?: string;
6
- apiKey?: string;
7
- }
8
- export declare function setAppCredentials(apiKey: string, orgSlug: string): Promise<AuthContext>;
9
- export declare function login(credentials: LoginCredentials): Promise<AuthContext>;
10
- export declare function getCurrentUser(): Promise<any>;
@@ -1,209 +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.getCurrentUser = exports.login = exports.setAppCredentials = void 0;
13
- const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
14
- const config_1 = require("../config");
15
- const auth_1 = require("./auth");
16
- const DEV_CONFIGURATION = {
17
- userPoolId: 'us-east-1_e2cA0nJWu',
18
- clientId: '209s9c62o165cqab0fu5ihjtu9',
19
- apiGateway: 'https://api.dev.vibeiq.com/dev/api',
20
- };
21
- const PROD_CONFIGURATION = {
22
- userPoolId: 'us-east-1_qIaNZdUfm',
23
- clientId: '7knkt34gfacbgd0ghnuspefdfg',
24
- apiGateway: 'https://api.vibeiq.com/prod/api',
25
- };
26
- const NIKE_CONFIGURATION = {
27
- apiGateway: 'https://api.nike.vibeiq.com/nike/api',
28
- };
29
- let CONFIGURATION = PROD_CONFIGURATION;
30
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_CLI_ENV) === 'DEV') {
31
- CONFIGURATION = DEV_CONFIGURATION;
32
- }
33
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_ENV) === 'DEV') {
34
- CONFIGURATION = DEV_CONFIGURATION;
35
- }
36
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_CLI_ENV) === 'NIKE') {
37
- CONFIGURATION = NIKE_CONFIGURATION;
38
- }
39
- if ((process === null || process === void 0 ? void 0 : process.env.CONTRAIL_ENV) === 'NIKE') {
40
- CONFIGURATION = NIKE_CONFIGURATION;
41
- }
42
- function setAppCredentials(apiKey, orgSlug) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- let apiGateway = CONFIGURATION.apiGateway;
45
- auth_1.Auth.config = {
46
- apiUserToken: apiKey,
47
- apiGateway,
48
- orgSlug: orgSlug,
49
- };
50
- (0, config_1.setConfig)(auth_1.Auth.config);
51
- return Object.assign({}, auth_1.Auth.config);
52
- });
53
- }
54
- exports.setAppCredentials = setAppCredentials;
55
- function login(credentials) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- if (!credentials.orgSlug) {
58
- console.log("Missing authentication credentials. 'orgSlug' is required.");
59
- }
60
- if (!(credentials.apiKey || (credentials.email && credentials.password))) {
61
- console.log('Missing authentication credentials. Provide an orgSlug and either apiKey or username and password.');
62
- }
63
- if (credentials.apiKey) {
64
- return yield setAuthContext(credentials.apiKey, credentials.orgSlug);
65
- }
66
- else {
67
- return yield usernameAuthentication(credentials.email, credentials.password, credentials.orgSlug);
68
- }
69
- });
70
- }
71
- exports.login = login;
72
- function usernameAuthentication(email, password, orgSlug) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- if (!email || !password) {
75
- throw new Error('Email and Password required');
76
- }
77
- const poolData = {
78
- UserPoolId: CONFIGURATION === null || CONFIGURATION === void 0 ? void 0 : CONFIGURATION.userPoolId,
79
- ClientId: CONFIGURATION === null || CONFIGURATION === void 0 ? void 0 : CONFIGURATION.clientId,
80
- };
81
- const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
82
- const authData = {
83
- Username: email,
84
- Password: password,
85
- };
86
- const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
87
- const userData = {
88
- Username: email,
89
- Pool: userPool,
90
- };
91
- const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
92
- return new Promise((resolve, reject) => {
93
- cognitoUser.authenticateUser(authDetails, {
94
- onSuccess: (result) => __awaiter(this, void 0, void 0, function* () {
95
- const user = result;
96
- const cognitoAccessToken = user.idToken.jwtToken;
97
- try {
98
- const apiTokens = yield exchangeCognitoTokensForApiTokens(cognitoAccessToken);
99
- const config = yield setAuthContext(apiTokens.accessToken, orgSlug, apiTokens.refreshToken);
100
- resolve(config);
101
- }
102
- catch (error) {
103
- console.error('Failed to process Cognito token:', error);
104
- reject(error);
105
- }
106
- }),
107
- onFailure: (err) => {
108
- reject(err);
109
- },
110
- });
111
- });
112
- });
113
- }
114
- function exchangeCognitoTokensForApiTokens(cognitoAccessToken) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const apiGateway = CONFIGURATION.apiGateway;
117
- const url = apiGateway + '/auth/cognito/';
118
- const response = yield fetch(url, {
119
- method: 'POST',
120
- headers: {
121
- Accept: 'application/json',
122
- 'Content-Type': 'application/json',
123
- },
124
- body: JSON.stringify({
125
- accessToken: cognitoAccessToken,
126
- }),
127
- });
128
- if (!response.ok) {
129
- throw new Error(`Failed to authenticate with Cognito token: ${response.status}`);
130
- }
131
- const data = yield response.json();
132
- if (!data.accessToken) {
133
- throw new Error('Response from /auth/cognito/ missing required field: accessToken');
134
- }
135
- if (!data.refreshToken) {
136
- throw new Error('Response from /auth/cognito/ missing required field: refreshToken');
137
- }
138
- return {
139
- accessToken: data.accessToken,
140
- refreshToken: data.refreshToken,
141
- };
142
- });
143
- }
144
- function setAuthContext(bearerToken, orgSlug, apiRefreshToken) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- let apiGateway = CONFIGURATION.apiGateway;
147
- auth_1.Auth.config = {
148
- apiUserToken: bearerToken,
149
- apiRefreshToken: apiRefreshToken,
150
- apiGateway,
151
- orgSlug,
152
- };
153
- (0, config_1.setConfig)(auth_1.Auth.config);
154
- const user = yield getCurrentUser();
155
- if (!user) {
156
- throw Error('Login Error: User not found in platform.');
157
- }
158
- const org = user.orgs.find((o) => o.orgSlug === auth_1.Auth.config.orgSlug);
159
- if (!user) {
160
- throw Error('Login Error: User does not have access to specified org.');
161
- }
162
- if (org) {
163
- auth_1.Auth.config.orgId = org.orgId || org.id;
164
- }
165
- else {
166
- throw new Error(`User does not have access to ${auth_1.Auth.config.orgSlug}`);
167
- }
168
- console.log(`Login Success as ${user.email} in ${org.orgSlug} [${auth_1.Auth.config.orgId}]`);
169
- return Object.assign({}, auth_1.Auth.config);
170
- });
171
- }
172
- function getCurrentUser() {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- const config = (0, config_1.getConfig)();
175
- if (!(config === null || config === void 0 ? void 0 : config.apiUserToken) || !(config === null || config === void 0 ? void 0 : config.apiGateway)) {
176
- throw new Error('The user is not authenticated');
177
- }
178
- function getApiKey() {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- const config = (0, config_1.getConfig)();
181
- if (config.authTokenResolver) {
182
- return yield config.authTokenResolver.resolveAuthToken();
183
- }
184
- else if (config.apiUserToken) {
185
- return config.apiUserToken;
186
- }
187
- });
188
- }
189
- const params = { method: 'get' };
190
- const API_GATEWAY = config.apiGateway;
191
- const url = API_GATEWAY + '/users/current';
192
- const apiKey = yield getApiKey();
193
- const isAppToken = apiKey.startsWith('app:');
194
- const orgSlug = config.orgSlug;
195
- params.headers = {
196
- 'X-Api-Key': apiKey,
197
- 'X-Api-Org': isAppToken ? orgSlug : 'NONE',
198
- Accept: 'application/json',
199
- 'Content-Type': 'application/json',
200
- };
201
- const currentUserResponse = yield fetch(url, params);
202
- if (currentUserResponse.status !== 200) {
203
- const responseBody = yield currentUserResponse.json().catch(() => null);
204
- throw new Error(`Failed to fetch current user. ${(responseBody === null || responseBody === void 0 ? void 0 : responseBody.message) || ''}`);
205
- }
206
- return currentUserResponse.json();
207
- });
208
- }
209
- exports.getCurrentUser = getCurrentUser;
@@ -1,48 +0,0 @@
1
- interface AuthTokenResolver {
2
- resolveAuthToken: () => Promise<string>;
3
- }
4
- export interface RequestDetails {
5
- url: string;
6
- method?: string;
7
- headers?: Record<string, string>;
8
- body?: string;
9
- }
10
- interface ErrorHandler {
11
- handle: (responeObject: any, errorJson: Record<string, unknown> | string, retryCallback: any, requestObject?: RequestDetails) => Promise<any>;
12
- }
13
- interface NetworkErrorHandler {
14
- handle: (error: Error) => Promise<any>;
15
- }
16
- export interface ContrailConfig {
17
- apiGateway?: string;
18
- orgId?: string;
19
- orgSlug?: string;
20
- apiUserToken?: string;
21
- apiSystemUserId?: string;
22
- apiSystemOrgSlug?: string;
23
- apiSystemUserEmail?: string;
24
- apiSystemUserRole?: string;
25
- authTokenResolver?: AuthTokenResolver;
26
- errorHandler?: ErrorHandler;
27
- networkErrorHandler?: NetworkErrorHandler;
28
- }
29
- declare global {
30
- var __CONTRAIL_SDK_CONFIG__: ContrailConfig | undefined;
31
- }
32
- export declare const CONTRAIL_CONFIG: ContrailConfig;
33
- export declare function setConfig(config: ContrailConfig): void;
34
- export declare function getConfig(): ContrailConfig;
35
- export interface InvocationContext {
36
- user?: any;
37
- orgId: string;
38
- orgSlug: string;
39
- orgRole: any;
40
- app?: any;
41
- requestOptions?: {
42
- useNativeFetch?: boolean;
43
- };
44
- }
45
- export declare function setFromContext(ctx: InvocationContext): void;
46
- export declare function setGlobalContext(context: InvocationContext): void;
47
- export declare function getGlobalContext(): InvocationContext;
48
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGlobalContext = exports.setGlobalContext = exports.setFromContext = exports.getConfig = exports.setConfig = exports.CONTRAIL_CONFIG = void 0;
4
- function getOrInitGlobalConfig() {
5
- var _a, _b;
6
- if (!globalThis.__CONTRAIL_SDK_CONFIG__) {
7
- globalThis.__CONTRAIL_SDK_CONFIG__ = {
8
- apiGateway: ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.API_GATEWAY) || 'http://localhost:3000/api',
9
- orgId: (_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.ORG_ID,
10
- };
11
- }
12
- return globalThis.__CONTRAIL_SDK_CONFIG__;
13
- }
14
- exports.CONTRAIL_CONFIG = getOrInitGlobalConfig();
15
- function setConfig(config) {
16
- Object.assign(getOrInitGlobalConfig(), config);
17
- }
18
- exports.setConfig = setConfig;
19
- function getConfig() {
20
- return getOrInitGlobalConfig();
21
- }
22
- exports.getConfig = getConfig;
23
- function setFromContext(ctx) {
24
- const params = {
25
- apiSystemUserRole: ctx.orgRole,
26
- apiSystemUserId: ctx.user.id,
27
- apiSystemOrgSlug: ctx.orgSlug,
28
- orgId: ctx.orgId,
29
- apiSystemUserEmail: ctx.user.email,
30
- };
31
- setConfig(params);
32
- }
33
- exports.setFromContext = setFromContext;
34
- let CONTEXT;
35
- function setGlobalContext(context) {
36
- CONTEXT = context;
37
- }
38
- exports.setGlobalContext = setGlobalContext;
39
- function getGlobalContext() {
40
- return CONTEXT;
41
- }
42
- exports.getGlobalContext = getGlobalContext;
@@ -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("./config"), exports);
@@ -1,12 +0,0 @@
1
- export interface CreateContentOptions {
2
- file?: File;
3
- fileBuffer?: any;
4
- contentHolderReference: string;
5
- fileId?: string;
6
- fileName?: string;
7
- contentType?: string;
8
- entityPolicyIds?: string[];
9
- }
10
- export declare class Content {
11
- create(options: CreateContentOptions): Promise<any>;
12
- }
@@ -1,70 +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.Content = void 0;
13
- const entities_1 = require("../entities");
14
- const file_type_helper_1 = require("../files/file-type-helper");
15
- const files_1 = require("../files/files");
16
- class Content {
17
- create(options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- let content = null;
20
- if (options.file) {
21
- const file = options.file;
22
- if (!file) {
23
- throw Error(`Must specify file in create.`);
24
- }
25
- const contentType = file.type || file_type_helper_1.FileTypeHelper.getContentType(file);
26
- content = yield new entities_1.Entities().create({
27
- entityName: 'content',
28
- object: {
29
- contentHolderReference: options.contentHolderReference,
30
- fileName: file.name,
31
- contentType,
32
- entityPolicyIds: options.entityPolicyIds,
33
- },
34
- });
35
- yield new files_1.Files().uploadFile(content.primaryFile.uploadPost, file);
36
- }
37
- else if (options.fileBuffer && options.fileName && options.contentType) {
38
- const fileBuffer = options.fileBuffer;
39
- const contentType = options.contentType;
40
- content = yield new entities_1.Entities().create({
41
- entityName: 'content',
42
- object: {
43
- contentHolderReference: options.contentHolderReference,
44
- fileName: options.fileName,
45
- contentType,
46
- entityPolicyIds: options.entityPolicyIds,
47
- },
48
- });
49
- yield new files_1.Files().uploadFileAsStream(content.primaryFile.uploadPost, fileBuffer, {
50
- contentType: options.contentType,
51
- });
52
- }
53
- else if (options.fileId) {
54
- content = yield new entities_1.Entities().create({
55
- entityName: 'content',
56
- object: {
57
- contentHolderReference: options.contentHolderReference,
58
- copyFileId: options.fileId,
59
- entityPolicyIds: options.entityPolicyIds,
60
- },
61
- });
62
- }
63
- else {
64
- throw new Error('Must specify file or fileId');
65
- }
66
- return content;
67
- });
68
- }
69
- }
70
- exports.Content = Content;
@@ -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("./content"), exports);
@@ -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("./request"), exports);
@@ -1,15 +0,0 @@
1
- import { InvocationContext } from '../config/config';
2
- export declare const AUTH_TOKEN_REQUIRED = "Authentication token must be set to make a contrail call.";
3
- export declare function _resetTokenRefreshPromise(): void;
4
- export declare class Request {
5
- private static MAX_RETRIES;
6
- private static RETRY_DELAY;
7
- static request(resource: any, params?: any, ctx?: InvocationContext): Promise<any>;
8
- private static requestWithRetries;
9
- private static isTokenExpiredError;
10
- private static delay;
11
- static logError(error: {}, resource: any, params?: {}): void;
12
- static sanitizeParametersString(params: any): string;
13
- private static getHeaders;
14
- private static tryParseStringIntoObject;
15
- }