@contrail/cli 3.6.0-alpha-7-alpha.d8f5a20 → 3.6.0-alpha-8-alpha.668a0d5

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 (78) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/entities/delete.js +2 -16
  3. package/dist/commands/entities/get.js +2 -1
  4. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +31 -0
  5. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +34 -0
  6. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +10 -0
  7. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +32 -0
  8. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +117 -0
  9. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +27 -0
  10. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +2 -0
  11. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +72 -0
  12. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +11 -0
  13. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +9 -0
  14. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +54 -0
  15. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +1 -0
  16. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.js +17 -0
  17. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +10 -0
  18. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +6 -0
  19. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +2 -0
  20. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +18 -0
  21. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +10 -0
  22. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +209 -0
  23. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +48 -0
  24. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +42 -0
  25. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +1 -0
  26. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +17 -0
  27. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +12 -0
  28. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +70 -0
  29. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +1 -0
  30. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +17 -0
  31. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +1 -0
  32. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +17 -0
  33. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +15 -0
  34. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +241 -0
  35. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +101 -0
  36. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +306 -0
  37. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +9 -0
  38. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +86 -0
  39. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +6 -0
  40. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +19 -0
  41. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +5 -0
  42. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +59 -0
  43. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +3 -0
  44. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +19 -0
  45. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +3 -0
  46. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +24 -0
  47. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +19 -0
  48. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +151 -0
  49. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +1 -0
  50. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +17 -0
  51. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +10 -0
  52. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +26 -0
  53. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +1 -0
  54. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +17 -0
  55. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +16 -0
  56. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +37 -0
  57. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +1 -0
  58. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +17 -0
  59. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +12 -0
  60. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +55 -0
  61. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +9 -0
  62. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +74 -0
  63. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +2 -0
  64. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +18 -0
  65. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +18 -0
  66. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +98 -0
  67. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +19 -0
  68. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +73 -0
  69. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +42 -0
  70. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +217 -0
  71. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +64 -0
  72. package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +69 -0
  73. package/node_modules/@contrail/sdk/lib/core/request.js +6 -2
  74. package/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +2 -0
  75. package/node_modules/@contrail/sdk/lib/entities/entities.client.js +2 -0
  76. package/node_modules/@contrail/sdk/package.json +1 -1
  77. package/oclif.manifest.json +1 -1
  78. package/package.json +2 -2
@@ -0,0 +1,209 @@
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;
@@ -0,0 +1,48 @@
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 {};
@@ -0,0 +1,42 @@
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;
@@ -0,0 +1,17 @@
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);
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,70 @@
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;
@@ -0,0 +1,17 @@
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);
@@ -0,0 +1,17 @@
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);
@@ -0,0 +1,15 @@
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
+ }