@contrail/flexplm 1.0.3 → 1.0.5

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.
@@ -0,0 +1,151 @@
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.FlexPLMConnect = void 0;
13
+ const app_framework_1 = require("@contrail/app-framework");
14
+ class FlexPLMConnect {
15
+ constructor(_config, endPoint = undefined, payloadAsArray = undefined) {
16
+ this.vibeEventEndpoint = '';
17
+ this.payloadSendAsArray = true;
18
+ this.config = _config;
19
+ this.vibeEventEndpoint = (endPoint)
20
+ ? endPoint
21
+ : this.config.vibeEventEndpoint;
22
+ this.payloadSendAsArray = (payloadAsArray != undefined)
23
+ ? payloadAsArray
24
+ : this.config['payloadDefaultAsArray'];
25
+ }
26
+ getRequestOptions(method) {
27
+ var _a;
28
+ const csrfOptions = {
29
+ method,
30
+ headers: {
31
+ 'Content-Type': 'application/json',
32
+ PLM_ENV: this.config.plmEnviornment,
33
+ Authorization: 'Basic ' + Buffer.from(`${this.config.userName()}:${this.config.password()}`, 'binary').toString('base64')
34
+ }
35
+ };
36
+ if (app_framework_1.Logger.isInfoOn()) {
37
+ const logOptions = JSON.parse(JSON.stringify(csrfOptions));
38
+ logOptions['headers']['Authorization'] = (_a = logOptions === null || logOptions === void 0 ? void 0 : logOptions.headers) === null || _a === void 0 ? void 0 : _a.Authorization.substring(0, 9);
39
+ console.info('csrfOptions: ' + JSON.stringify(logOptions));
40
+ }
41
+ return csrfOptions;
42
+ }
43
+ getCSRF() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const urlContext = this.config.urlContext;
46
+ const csrfEndpoint = this.config.csrfEndpoint;
47
+ const csrfURL = this.config.apiHost + urlContext + csrfEndpoint;
48
+ console.info('csrfURL: ' + csrfURL);
49
+ const csrfOptions = this.getRequestOptions('GET');
50
+ const response = yield fetch(csrfURL, csrfOptions);
51
+ if (response.status >= 300) {
52
+ const message = 'Error connecting to FlexPLM:status: ' + response.status;
53
+ console.error(message);
54
+ console.error(yield response.text());
55
+ throw new Error(message);
56
+ }
57
+ try {
58
+ const body = yield response.json();
59
+ const nonce_key = body.items[0].attributes.nonce_key;
60
+ const nonce = body.items[0].attributes.nonce;
61
+ console.info('nonce_key: ' + nonce_key);
62
+ console.info('nonce: ' + nonce);
63
+ return {
64
+ nonce_key,
65
+ nonce
66
+ };
67
+ }
68
+ catch (e) {
69
+ const message = 'Error connecting to FlexPLM: ' + e.message;
70
+ console.error(message);
71
+ console.error(yield response.text());
72
+ throw new Error(message);
73
+ }
74
+ });
75
+ }
76
+ sendRequest(csrf, payload) {
77
+ var _a;
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ if (this.payloadSendAsArray && !Array.isArray(payload)) {
80
+ payload = [payload];
81
+ }
82
+ const xferOptions = this.getRequestOptions('POST');
83
+ xferOptions['body'] = JSON.stringify(payload);
84
+ xferOptions.headers[csrf.nonce_key] = csrf.nonce;
85
+ const urlContext = this.config.urlContext;
86
+ const vibeEventsURL = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
87
+ if (app_framework_1.Logger.isInfoOn()) {
88
+ console.info('Request:');
89
+ console.info('vibeEventsURL: ' + vibeEventsURL);
90
+ const logOptions = JSON.parse(JSON.stringify(xferOptions));
91
+ logOptions['headers']['Authorization'] = (_a = logOptions === null || logOptions === void 0 ? void 0 : logOptions.headers) === null || _a === void 0 ? void 0 : _a.Authorization.substring(0, 9);
92
+ console.info('csrfOptions: ' + JSON.stringify(logOptions));
93
+ console.info('Making call to xfer data to FlexPLM');
94
+ }
95
+ const eventResponse = yield fetch(vibeEventsURL, xferOptions);
96
+ return eventResponse;
97
+ });
98
+ }
99
+ processRequest(payload) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ if (!payload) {
102
+ const message = 'No payload to send to FlexPLM';
103
+ console.error(message);
104
+ throw new Error(message);
105
+ }
106
+ if (app_framework_1.Logger.isInfoOn()) {
107
+ console.info('payload: ' + JSON.stringify(payload));
108
+ }
109
+ const csrf = yield this.getCSRF();
110
+ if (!csrf) {
111
+ const message = 'Failed to get CSRF nonce';
112
+ console.error(message);
113
+ throw new Error(message);
114
+ }
115
+ const response = yield this.sendRequest(csrf, payload);
116
+ const status = response.status;
117
+ if (status >= 300) {
118
+ const message = 'Error sending data to FlexPLM:status: ' + response.status;
119
+ console.error(message);
120
+ console.error(yield response.text());
121
+ throw new Error(message);
122
+ }
123
+ try {
124
+ const data = yield response.json();
125
+ const res = {
126
+ status,
127
+ data
128
+ };
129
+ console.log('eventResponse.status: ' + status);
130
+ return res;
131
+ }
132
+ catch (e) {
133
+ const message = 'Error getting json data from FlexPLM: ' + e.message;
134
+ console.error(message);
135
+ console.error(yield response.text());
136
+ throw new Error(message);
137
+ }
138
+ });
139
+ }
140
+ sendToFlexPLM(payload) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ return yield this.processRequest(payload);
143
+ });
144
+ }
145
+ sendMultipleToFlexPLM(payload) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return yield this.processRequest(payload);
148
+ });
149
+ }
150
+ }
151
+ exports.FlexPLMConnect = FlexPLMConnect;
@@ -0,0 +1,91 @@
1
+ export interface FCConfig {
2
+ apiKey?: string;
3
+ orgSlug?: string;
4
+ action?: string;
5
+ configFile?: string;
6
+ eventObjectClassParam?: string;
7
+ eventFlexTypePathParam?: string;
8
+ taskId?: string;
9
+ apiHost: string;
10
+ userName(): string;
11
+ password(): string;
12
+ plmEnviornment?: string;
13
+ urlContext: string;
14
+ vibeEventEndpoint: string;
15
+ csrfEndpoint: string;
16
+ itemPreDevelopmentLifecycleStages: string[];
17
+ identifierAtts?: {
18
+ [key: string]: string[];
19
+ };
20
+ propertyMapping?: object;
21
+ }
22
+ export interface ProductFederation {
23
+ entityReference: string;
24
+ objectClass: 'LCSProduct';
25
+ federatedId?: string;
26
+ vibeIQIdentifier?: string;
27
+ }
28
+ export interface ProductData extends ProductFederation {
29
+ data: object;
30
+ productSeason: {
31
+ data: object;
32
+ };
33
+ }
34
+ export interface SeasonFederation {
35
+ entityReference: string;
36
+ objectClass: 'LCSSeason';
37
+ flexPLMSeasonName?: string;
38
+ federationId?: string;
39
+ }
40
+ export interface SkuFederation {
41
+ entityReference: string;
42
+ objectClass: 'LCSSKU';
43
+ LCSProduct?: ProductFederation;
44
+ federatedId?: string;
45
+ vibeIQIdentifier?: string;
46
+ }
47
+ export interface SkuData extends SkuFederation {
48
+ data: object;
49
+ }
50
+ export interface PayloadType {
51
+ eventType: string;
52
+ objectClass: string;
53
+ }
54
+ export interface AsyncPayloadType extends PayloadType {
55
+ taskId: string;
56
+ }
57
+ export interface AsyncEventsPayloadType extends AsyncPayloadType {
58
+ events?: PayloadType[];
59
+ eventsFileId?: string;
60
+ eventsDownloadLink?: string;
61
+ }
62
+ export interface EntityPayloadType extends PayloadType {
63
+ entityReference: string;
64
+ federatedId?: string;
65
+ flexPLMTypePath?: string;
66
+ data: object;
67
+ }
68
+ export interface ItemPayloadType extends EntityPayloadType {
69
+ LCSProduct?: ProductFederation;
70
+ }
71
+ export interface SeasonalPayload extends EntityPayloadType {
72
+ eventType: 'UPSERT_ON_SEASON' | 'REMOVE_FROM_SEASON';
73
+ objectClass: 'LCSProductSeasonLink' | 'LCSSKUSeasonLink';
74
+ LCSSeason: SeasonFederation;
75
+ LCSProduct?: ProductFederation;
76
+ LCSSKU?: SkuFederation;
77
+ }
78
+ export interface ExportPayloadType extends AsyncPayloadType {
79
+ flexPLMTypePath: string;
80
+ }
81
+ export interface FederationRecord {
82
+ reference: string;
83
+ mappedReference: string;
84
+ appIdentifier: string;
85
+ federationSchema: string;
86
+ }
87
+ export interface FlexPLMResponseData {
88
+ status: number;
89
+ data?: object;
90
+ error?: string;
91
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function setLoggerConfig(appConfig: any): Promise<void>;
@@ -0,0 +1,37 @@
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.setLoggerConfig = void 0;
13
+ const app_framework_1 = require("@contrail/app-framework");
14
+ function setLoggerConfig(appConfig) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ let logLevel = app_framework_1.LogLevel.INFO;
17
+ if (!appConfig.logLevel) {
18
+ }
19
+ else if (appConfig.logLevel === 'error') {
20
+ logLevel = app_framework_1.LogLevel.ERROR;
21
+ }
22
+ else if (appConfig.logLevel === 'warn') {
23
+ logLevel = app_framework_1.LogLevel.WARN;
24
+ }
25
+ else if (appConfig.logLevel === 'info') {
26
+ logLevel = app_framework_1.LogLevel.INFO;
27
+ }
28
+ else if (appConfig.logLevel === 'debug') {
29
+ logLevel = app_framework_1.LogLevel.DEBUG;
30
+ }
31
+ else {
32
+ console.log('could not parse log level:', appConfig);
33
+ }
34
+ app_framework_1.Logger.setConfig({ logLevel: logLevel });
35
+ });
36
+ }
37
+ exports.setLoggerConfig = setLoggerConfig;
@@ -0,0 +1,39 @@
1
+ export declare const empty_custom_sizes: any[];
2
+ export declare const four_custom_sizes: {
3
+ size: number;
4
+ id: string;
5
+ slug: string;
6
+ }[];
7
+ export declare const thumbnail_content_entity: {
8
+ fileName: string;
9
+ primaryFileId: string;
10
+ primaryFileUrl: string;
11
+ tinyViewableId: string;
12
+ tinyViewableUrl: string;
13
+ smallViewableId: string;
14
+ smallViewableUrl: string;
15
+ mediumViewableId: string;
16
+ mediumViewableUrl: string;
17
+ largeViewableId: string;
18
+ largeViewableUrl: string;
19
+ CS_300Id: string;
20
+ CS_300Url: string;
21
+ CS_500Id: string;
22
+ CS_500Url: string;
23
+ CS_800Id: string;
24
+ CS_800Url: string;
25
+ CS_1000Id: string;
26
+ CS_1000Url: string;
27
+ createdOn: string;
28
+ orgId: string;
29
+ id: string;
30
+ contentType: string;
31
+ createdById: string;
32
+ updatedById: string;
33
+ fileSize: number;
34
+ };
35
+ export declare const cuRficeyoStwTF_f_fileEntities: {
36
+ fileName: string;
37
+ id: string;
38
+ size: number;
39
+ }[];
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cuRficeyoStwTF_f_fileEntities = exports.thumbnail_content_entity = exports.four_custom_sizes = exports.empty_custom_sizes = void 0;
4
+ exports.empty_custom_sizes = [];
5
+ exports.four_custom_sizes = [
6
+ {
7
+ size: 1000,
8
+ id: '-QwFOWnCs0Gb5jkA',
9
+ slug: 'CS_1000'
10
+ },
11
+ {
12
+ size: 300,
13
+ id: 'AKXOowvhJRnkerG8',
14
+ slug: 'CS_300'
15
+ },
16
+ {
17
+ size: 500,
18
+ id: '9asQ65N188RIYgnh',
19
+ slug: 'CS_500'
20
+ },
21
+ {
22
+ size: 800,
23
+ id: 'xkzhwE4nJ6iRwfvP',
24
+ slug: 'CS_800'
25
+ }
26
+ ];
27
+ exports.thumbnail_content_entity = {
28
+ fileName: 'JACKET 300_SOLDIER OLIVE.png',
29
+ primaryFileId: 'yn2d5oHD4rXHRzyB',
30
+ primaryFileUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Ff646d3cd-e23a-4689-bd16-0301d2036720.png',
31
+ tinyViewableId: '6HWzJrQ-Jx1iefmj',
32
+ tinyViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb68f8652-f33f-452f-ae34-25397b4521eb.png',
33
+ smallViewableId: 'D3WRW4iRmjLzp5VX',
34
+ smallViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F541c53f8-fd85-418e-ae28-ad7410658b90.png',
35
+ mediumViewableId: 'AsRvJenpeqxksUNW',
36
+ mediumViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fe803c2d3-3e1b-4d9c-9bb9-2c488f1f295b.png',
37
+ largeViewableId: 'vo4N4mCd-tFrw101',
38
+ largeViewableUrl: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fb1b7a55c-b8ba-4857-be4e-e1c3f11d8e9a.png',
39
+ CS_300Id: '6A5AG33nVu3Z6ogO',
40
+ CS_300Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F3f2ea306-a77f-4cc3-a49a-75fb5d8b113c.png',
41
+ CS_500Id: 'rBaHc1J2xdOWdbhI',
42
+ CS_500Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F979c8c65-b63f-4220-aa2e-11520f2f68bf.png',
43
+ CS_800Id: 'ZPAeYI3JiqjQ7unY',
44
+ CS_800Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2Fc58eeffa-2592-4698-a058-19281cda447c.png',
45
+ CS_1000Id: 'Hg_CthwsD4ozopCb',
46
+ CS_1000Url: 'https://api.vibeiq.com/prod/api/files/downloadUrl/5LZnKVTNxvwMqufy%2Fcontent:cuRficeyoStwTF-f%2F2c827c7b-361b-4e05-b77d-4280294f9d9c.png',
47
+ createdOn: '2023-07-05T15:02:13.950Z',
48
+ orgId: '5LZnKVTNxvwMqufy',
49
+ id: 'cuRficeyoStwTF-f',
50
+ contentType: 'image/png',
51
+ createdById: 'SWIFPZeZzkBvrSLD',
52
+ updatedById: 'SWIFPZeZzkBvrSLD',
53
+ fileSize: 1757973
54
+ };
55
+ exports.cuRficeyoStwTF_f_fileEntities = [
56
+ {
57
+ fileName: 'JACKET 300_SOLDIER OLIVE.png',
58
+ id: 'yn2d5oHD4rXHRzyB',
59
+ size: 1757973
60
+ },
61
+ {
62
+ fileName: 'JACKET 300_SOLDIER OLIVE_tiny.png',
63
+ id: '6HWzJrQ-Jx1iefmj',
64
+ size: 1784
65
+ },
66
+ {
67
+ fileName: 'JACKET 300_SOLDIER OLIVE_small.png',
68
+ id: 'D3WRW4iRmjLzp5VX',
69
+ size: 8699
70
+ },
71
+ {
72
+ fileName: 'JACKET 300_SOLDIER OLIVE_medium.png',
73
+ id: 'AsRvJenpeqxksUNW',
74
+ size: 77558
75
+ },
76
+ {
77
+ fileName: 'JACKET 300_SOLDIER OLIVE_large.png',
78
+ id: 'vo4N4mCd-tFrw101',
79
+ size: 1781538
80
+ },
81
+ {
82
+ fileName: 'JACKET 300_SOLDIER OLIVE_CS_300.png',
83
+ id: '6A5AG33nVu3Z6ogO',
84
+ size: 141153
85
+ },
86
+ {
87
+ fileName: 'JACKET 300_SOLDIER OLIVE_CS_500.png',
88
+ id: 'rBaHc1J2xdOWdbhI',
89
+ size: 382057
90
+ },
91
+ {
92
+ fileName: 'JACKET 300_SOLDIER OLIVE_CS_800.png',
93
+ id: 'ZPAeYI3JiqjQ7unY',
94
+ size: 1008702
95
+ }, {
96
+ fileName: 'JACKET 300_SOLDIER OLIVE_CS_1000.png',
97
+ id: 'Hg_CthwsD4ozopCb',
98
+ size: 1605889
99
+ }
100
+ ];
@@ -0,0 +1,15 @@
1
+ import { FCConfig } from './interfaces';
2
+ export declare class ThumbnailUtil {
3
+ private config;
4
+ private max_thumbnail_size;
5
+ private entities;
6
+ static NEW_THUMBNAIL_ID: string;
7
+ static EXISTING_THUMBNAIL_ID: string;
8
+ static REMOVE_THUMBNAIL: string;
9
+ constructor(config: FCConfig);
10
+ setOutboundThumbnail(data: any, event: any): Promise<any>;
11
+ getFileId(primaryViewableId: string): Promise<string>;
12
+ getCustomSizes(): Promise<any[]>;
13
+ getContentEntity(primaryViewableId: any): Promise<any>;
14
+ getFileEntities(fileEntityIds: any[]): Promise<any>;
15
+ }
@@ -0,0 +1,132 @@
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.ThumbnailUtil = void 0;
13
+ const app_framework_1 = require("@contrail/app-framework");
14
+ const sdk_1 = require("@contrail/sdk");
15
+ class ThumbnailUtil {
16
+ constructor(config) {
17
+ this.config = config;
18
+ this.max_thumbnail_size = 5 * 1024 * 1024;
19
+ this.entities = new sdk_1.Entities();
20
+ if (this.config['max_thumbnail_size']) {
21
+ this.max_thumbnail_size = this.config['max_thumbnail_size'];
22
+ }
23
+ }
24
+ setOutboundThumbnail(data, event) {
25
+ var _a, _b, _c, _d, _e, _f, _g;
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ if (((_a = event === null || event === void 0 ? void 0 : event.newData) === null || _a === void 0 ? void 0 : _a.primaryViewableId) && ((_b = event === null || event === void 0 ? void 0 : event.newData) === null || _b === void 0 ? void 0 : _b.largeViewableDownloadUrl)) {
28
+ const primaryViewableId = event.newData.primaryViewableId;
29
+ const fileId = yield this.getFileId(primaryViewableId);
30
+ if (fileId) {
31
+ const key = ((_c = event === null || event === void 0 ? void 0 : event.propertyDiffs) === null || _c === void 0 ? void 0 : _c.largeViewableDownloadUrl)
32
+ ? ThumbnailUtil.NEW_THUMBNAIL_ID
33
+ : ThumbnailUtil.EXISTING_THUMBNAIL_ID;
34
+ data[key] = fileId;
35
+ }
36
+ }
37
+ else if (((_e = (_d = event === null || event === void 0 ? void 0 : event.propertyDiffs) === null || _d === void 0 ? void 0 : _d.largeViewableDownloadUrl) === null || _e === void 0 ? void 0 : _e.oldValue) && !((_g = (_f = event === null || event === void 0 ? void 0 : event.propertyDiffs) === null || _f === void 0 ? void 0 : _f.largeViewableDownloadUrl) === null || _g === void 0 ? void 0 : _g.newValue)) {
38
+ data[ThumbnailUtil.NEW_THUMBNAIL_ID] = ThumbnailUtil.REMOVE_THUMBNAIL;
39
+ }
40
+ return data;
41
+ });
42
+ }
43
+ getFileId(primaryViewableId) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ console.info('getFileId()-' + primaryViewableId);
46
+ const sizes = yield this.getCustomSizes();
47
+ const OOBSizes = [{ slug: 'largeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
48
+ sizes.push(...OOBSizes);
49
+ console.info('sizes: ' + JSON.stringify(sizes));
50
+ const content = yield this.getContentEntity(primaryViewableId);
51
+ if (app_framework_1.Logger.isDebugOn()) {
52
+ console.debug('content: ' + JSON.stringify(content));
53
+ }
54
+ if (!content) {
55
+ return undefined;
56
+ }
57
+ const contentKeys = Object.getOwnPropertyNames(content);
58
+ const fileEntityIds = [];
59
+ for (const size of sizes) {
60
+ const key = size.slug + 'Id';
61
+ if (contentKeys.includes(key) && !fileEntityIds.includes(content[key])) {
62
+ fileEntityIds.push(content[key]);
63
+ size['fileId'] = content[key];
64
+ }
65
+ }
66
+ const fileResults = yield this.getFileEntities(fileEntityIds);
67
+ if (app_framework_1.Logger.isDebugOn()) {
68
+ console.debug('fileResults: ' + JSON.stringify(fileResults));
69
+ }
70
+ let fileId = undefined;
71
+ let tempFileSize = 0;
72
+ const isDebugOn = app_framework_1.Logger.isDebugOn();
73
+ for (const sizeObj of sizes) {
74
+ if (isDebugOn) {
75
+ console.debug('size: ' + JSON.stringify(sizeObj));
76
+ }
77
+ if (sizeObj['fileId']) {
78
+ const file = fileResults.find(f => f['id'] === sizeObj['fileId']);
79
+ if (file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
80
+ tempFileSize = file['size'];
81
+ fileId = file['id'];
82
+ if (isDebugOn) {
83
+ console.debug('fileId: ' + fileId);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ console.info('getFileId(): returning-' + fileId);
89
+ return fileId;
90
+ });
91
+ }
92
+ getCustomSizes() {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ const customSizes = yield this.entities.get({
95
+ entityName: 'content-custom-size'
96
+ });
97
+ const sizes = [];
98
+ sizes.push(...customSizes);
99
+ return sizes;
100
+ });
101
+ }
102
+ getContentEntity(primaryViewableId) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const criteria = {
105
+ id: primaryViewableId
106
+ };
107
+ const contentResults = yield this.entities.get({
108
+ entityName: 'content',
109
+ criteria
110
+ });
111
+ console.info('contentResults: ' + JSON.stringify(contentResults));
112
+ const content = (contentResults && contentResults[0]) ? contentResults[0] : undefined;
113
+ return content;
114
+ });
115
+ }
116
+ getFileEntities(fileEntityIds) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const criteria = {
119
+ ids: fileEntityIds
120
+ };
121
+ const fileResults = yield this.entities.get({
122
+ entityName: 'file',
123
+ criteria
124
+ });
125
+ return fileResults;
126
+ });
127
+ }
128
+ }
129
+ exports.ThumbnailUtil = ThumbnailUtil;
130
+ ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
131
+ ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
132
+ ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
@@ -0,0 +1,12 @@
1
+ import { TypeClientOptions } from '@contrail/sdk';
2
+ import { TypeProperty } from '@contrail/types';
3
+ export declare class TypeUtils {
4
+ private typesObj;
5
+ constructor();
6
+ getTypeById(id: any): Promise<import("@contrail/types").Type>;
7
+ getByRootAndPath(options: TypeClientOptions): Promise<import("@contrail/types").Type>;
8
+ static getFlexPLMTypePath(entity: any): any;
9
+ getEventObjectClass(entityType: string, newData: any): string;
10
+ getEntityTypeClientOptions(objectClass: string, data: any): TypeClientOptions;
11
+ filterTypeProperties(type: any, newData: any): TypeProperty[];
12
+ }