@contrail/flexplm 1.3.0 → 1.3.1-alpha.56221f6
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.
- package/lib/cli/commands/compile.d.ts +1 -0
- package/lib/cli/commands/compile.js +71 -0
- package/lib/cli/commands/compile.spec.d.ts +1 -0
- package/lib/cli/commands/compile.spec.js +80 -0
- package/lib/cli/commands/create.d.ts +1 -0
- package/lib/cli/commands/create.js +75 -0
- package/lib/cli/commands/create.spec.d.ts +1 -0
- package/lib/cli/commands/create.spec.js +78 -0
- package/lib/cli/commands/upload.d.ts +10 -0
- package/lib/cli/commands/upload.js +219 -0
- package/lib/cli/commands/upload.spec.d.ts +1 -0
- package/lib/cli/commands/upload.spec.js +88 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +64 -0
- package/lib/cli/index.spec.d.ts +1 -0
- package/lib/cli/index.spec.js +79 -0
- package/lib/cli/template/mapping-template.ts.template +18 -0
- package/lib/entity-processor/base-entity-processor.d.ts +89 -42
- package/lib/entity-processor/base-entity-processor.js +438 -385
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
- package/lib/entity-processor/base-entity-processor.spec.js +398 -397
- package/lib/flexplm-request.d.ts +3 -3
- package/lib/flexplm-request.js +34 -34
- package/lib/flexplm-utils.d.ts +5 -5
- package/lib/flexplm-utils.js +33 -33
- package/lib/flexplm-utils.spec.d.ts +1 -1
- package/lib/flexplm-utils.spec.js +26 -26
- package/lib/index.d.ts +23 -22
- package/lib/index.js +39 -38
- package/lib/interfaces/interfaces.d.ts +105 -105
- package/lib/interfaces/interfaces.js +2 -2
- package/lib/interfaces/item-family-changes.d.ts +20 -20
- package/lib/interfaces/item-family-changes.js +56 -56
- package/lib/interfaces/mapping-file.d.ts +429 -0
- package/lib/interfaces/mapping-file.js +2 -0
- package/lib/interfaces/publish-change-data.d.ts +19 -19
- package/lib/interfaces/publish-change-data.js +32 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
- package/lib/publish/base-process-publish-assortment-callback.js +38 -38
- package/lib/publish/base-process-publish-assortment.d.ts +118 -93
- package/lib/publish/base-process-publish-assortment.js +998 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
- package/lib/publish/mockData.d.ts +1389 -1389
- package/lib/publish/mockData.js +4524 -4519
- package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
- package/lib/transform/identifier-conversion.d.ts +51 -15
- package/lib/transform/identifier-conversion.js +248 -212
- package/lib/transform/identifier-conversion.spec.d.ts +1 -1
- package/lib/transform/identifier-conversion.spec.js +343 -339
- package/lib/util/config-defaults.d.ts +8 -8
- package/lib/util/config-defaults.js +88 -85
- package/lib/util/config-defaults.spec.d.ts +1 -1
- package/lib/util/config-defaults.spec.js +302 -293
- package/lib/util/data-converter-spec-mockData.js +219 -205
- package/lib/util/data-converter.d.ts +136 -39
- package/lib/util/data-converter.js +718 -592
- package/lib/util/data-converter.spec.d.ts +1 -1
- package/lib/util/data-converter.spec.js +906 -904
- package/lib/util/error-response-object.d.ts +9 -4
- package/lib/util/error-response-object.js +54 -47
- package/lib/util/error-response-object.spec.d.ts +1 -1
- package/lib/util/error-response-object.spec.js +99 -99
- package/lib/util/event-short-message-status.d.ts +19 -19
- package/lib/util/event-short-message-status.js +24 -23
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +157 -149
- package/lib/util/flexplm-connect.d.ts +29 -22
- package/lib/util/flexplm-connect.js +190 -176
- package/lib/util/flexplm-connect.spec.d.ts +1 -1
- package/lib/util/flexplm-connect.spec.js +88 -88
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +27 -26
- package/lib/util/map-util-spec-mockData.js +219 -205
- package/lib/util/map-utils.d.ts +33 -6
- package/lib/util/map-utils.js +42 -15
- package/lib/util/map-utils.spec.d.ts +1 -1
- package/lib/util/map-utils.spec.js +89 -89
- package/lib/util/mockData.d.ts +80 -80
- package/lib/util/mockData.js +103 -103
- package/lib/util/thumbnail-util.d.ts +55 -34
- package/lib/util/thumbnail-util.js +242 -215
- package/lib/util/thumbnail-util.spec.d.ts +1 -1
- package/lib/util/thumbnail-util.spec.js +440 -434
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
- package/lib/util/type-conversion-utils.d.ts +163 -23
- package/lib/util/type-conversion-utils.js +408 -265
- package/lib/util/type-conversion-utils.spec.d.ts +1 -1
- package/lib/util/type-conversion-utils.spec.js +868 -868
- package/lib/util/type-defaults.d.ts +74 -16
- package/lib/util/type-defaults.js +279 -221
- package/lib/util/type-defaults.spec.d.ts +1 -1
- package/lib/util/type-defaults.spec.js +516 -516
- package/lib/util/type-utils.d.ts +34 -13
- package/lib/util/type-utils.js +137 -114
- package/lib/util/type-utils.spec.d.ts +1 -1
- package/lib/util/type-utils.spec.js +192 -190
- package/package.json +21 -6
- package/scripts/copy-template.js +10 -0
- package/.claude/settings.local.json +0 -8
- package/.github/pull_request_template.md +0 -31
- package/.github/workflows/flexplm-lib.yml +0 -27
- package/.github/workflows/publish-to-npm.yml +0 -124
- package/CHANGELOG.md +0 -32
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/entity-processor/base-entity-processor.spec.ts +0 -460
- package/src/entity-processor/base-entity-processor.ts +0 -515
- package/src/flexplm-request.ts +0 -28
- package/src/flexplm-utils.spec.ts +0 -27
- package/src/flexplm-utils.ts +0 -29
- package/src/index.ts +0 -22
- package/src/interfaces/interfaces.ts +0 -122
- package/src/interfaces/item-family-changes.ts +0 -67
- package/src/interfaces/publish-change-data.ts +0 -43
- package/src/publish/base-process-publish-assortment-callback.ts +0 -50
- package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
- package/src/publish/base-process-publish-assortment.ts +0 -1134
- package/src/publish/mockData.ts +0 -4561
- package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
- package/src/transform/identifier-conversion.spec.ts +0 -354
- package/src/transform/identifier-conversion.ts +0 -282
- package/src/util/config-defaults.spec.ts +0 -350
- package/src/util/config-defaults.ts +0 -93
- package/src/util/data-converter-spec-mockData.ts +0 -231
- package/src/util/data-converter.spec.ts +0 -1041
- package/src/util/data-converter.ts +0 -762
- package/src/util/error-response-object.spec.ts +0 -116
- package/src/util/error-response-object.ts +0 -50
- package/src/util/event-short-message-status.ts +0 -22
- package/src/util/federation.ts +0 -172
- package/src/util/flexplm-connect.spec.ts +0 -132
- package/src/util/flexplm-connect.ts +0 -208
- package/src/util/logger-config.ts +0 -20
- package/src/util/map-util-spec-mockData.ts +0 -231
- package/src/util/map-utils.spec.ts +0 -103
- package/src/util/map-utils.ts +0 -41
- package/src/util/mockData.ts +0 -101
- package/src/util/thumbnail-util.spec.ts +0 -508
- package/src/util/thumbnail-util.ts +0 -272
- package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
- package/src/util/type-conversion-utils.spec.ts +0 -968
- package/src/util/type-conversion-utils.ts +0 -460
- package/src/util/type-defaults.spec.ts +0 -669
- package/src/util/type-defaults.ts +0 -281
- package/src/util/type-utils.spec.ts +0 -227
- package/src/util/type-utils.ts +0 -144
- package/tsconfig.json +0 -29
- package/tslint.json +0 -57
|
@@ -1,215 +1,242 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThumbnailUtil = void 0;
|
|
4
|
-
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
-
const sdk_1 = require("@contrail/sdk");
|
|
6
|
-
const flexplm_connect_1 = require("./flexplm-connect");
|
|
7
|
-
;
|
|
8
|
-
class ThumbnailUtil {
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.config = config;
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThumbnailUtil = void 0;
|
|
4
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
5
|
+
const sdk_1 = require("@contrail/sdk");
|
|
6
|
+
const flexplm_connect_1 = require("./flexplm-connect");
|
|
7
|
+
;
|
|
8
|
+
class ThumbnailUtil {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
/** The max_thumbnail_size is for limiting the size of the thumbnail being sent to FlexPLM. It is used when checking the size of the auto generated thumbnails (smallViewable, tinyViewable, etc.). */
|
|
12
|
+
this.max_thumbnail_size = 5 * 1024 * 1024;
|
|
13
|
+
this.entities = new sdk_1.Entities();
|
|
14
|
+
if (this.config['max_thumbnail_size']) {
|
|
15
|
+
this.max_thumbnail_size = this.config['max_thumbnail_size'];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async setOutboundThumbnail(data, event) {
|
|
19
|
+
if (event?.newData?.primaryViewableId && event?.newData?.largeViewableDownloadUrl) {
|
|
20
|
+
const primaryViewableId = event.newData.primaryViewableId;
|
|
21
|
+
//get custom sizes
|
|
22
|
+
const fileId = await this.getFileId(primaryViewableId);
|
|
23
|
+
if (fileId) {
|
|
24
|
+
const customSizes = await this.getCustomSizes();
|
|
25
|
+
const key = (this.isThumbnailNew(event, customSizes))
|
|
26
|
+
? ThumbnailUtil.NEW_THUMBNAIL_ID
|
|
27
|
+
: ThumbnailUtil.EXISTING_THUMBNAIL_ID;
|
|
28
|
+
data[key] = fileId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (event?.propertyDiffs?.largeViewableDownloadUrl?.oldValue && !event?.propertyDiffs?.largeViewableDownloadUrl?.newValue) {
|
|
32
|
+
data[ThumbnailUtil.NEW_THUMBNAIL_ID] = ThumbnailUtil.REMOVE_THUMBNAIL;
|
|
33
|
+
}
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
/** Determines if a new image has been generated. If any viewable is new, there might be a better
|
|
37
|
+
* sized image. So send the fileId as new.
|
|
38
|
+
*/
|
|
39
|
+
isThumbnailNew(event, customSizes) {
|
|
40
|
+
const propertyDiffs = event?.propertyDiffs;
|
|
41
|
+
if (propertyDiffs) {
|
|
42
|
+
const diffKeys = Object.keys(propertyDiffs);
|
|
43
|
+
const sizeKeys = ThumbnailUtil.OOB_SIZES.map(s => s.slug + 'DownloadUrl');
|
|
44
|
+
if (customSizes) {
|
|
45
|
+
sizeKeys.push(...customSizes.map(s => s.slug + 'Url'));
|
|
46
|
+
}
|
|
47
|
+
sizeKeys.push('primaryFileUrl');
|
|
48
|
+
console.info('diffKeys: ' + JSON.stringify(diffKeys));
|
|
49
|
+
console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
|
|
50
|
+
return diffKeys.some(s => sizeKeys.includes(s));
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
async getFileId(primaryViewableId) {
|
|
55
|
+
console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
|
|
56
|
+
const sizes = await this.getCustomSizes();
|
|
57
|
+
const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
|
|
58
|
+
sizes.push(...OOBSizes);
|
|
59
|
+
console.info('sizes: ' + JSON.stringify(sizes));
|
|
60
|
+
//get Content
|
|
61
|
+
const content = await this.getContentEntity(primaryViewableId, sizes);
|
|
62
|
+
if (!content) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const contentKeys = Object.getOwnPropertyNames(content);
|
|
66
|
+
const isDebugOn = app_framework_1.Logger.isDebugOn();
|
|
67
|
+
let fileId = undefined;
|
|
68
|
+
let tempFileSize = 0;
|
|
69
|
+
for (const size of sizes) {
|
|
70
|
+
const slug = size?.slug;
|
|
71
|
+
if (contentKeys.includes(slug)) {
|
|
72
|
+
const file = content[slug];
|
|
73
|
+
if (isDebugOn) {
|
|
74
|
+
console.debug('size: ' + slug);
|
|
75
|
+
console.debug('fileId: ' + file['id']);
|
|
76
|
+
}
|
|
77
|
+
if (file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
|
|
78
|
+
tempFileSize = file['size'];
|
|
79
|
+
fileId = file['id'];
|
|
80
|
+
if (isDebugOn) {
|
|
81
|
+
console.debug('fileId: ' + fileId);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
|
|
87
|
+
return fileId;
|
|
88
|
+
}
|
|
89
|
+
async getCustomSizes() {
|
|
90
|
+
const customSizes = await this.entities.get({
|
|
91
|
+
entityName: 'content-custom-size'
|
|
92
|
+
});
|
|
93
|
+
const sizes = [];
|
|
94
|
+
sizes.push(...customSizes);
|
|
95
|
+
return sizes;
|
|
96
|
+
}
|
|
97
|
+
async getContentEntity(primaryViewableId, sizes) {
|
|
98
|
+
const relations = sizes.map(s => s.slug);
|
|
99
|
+
relations.push('primaryFile');
|
|
100
|
+
const content = await this.entities.get({
|
|
101
|
+
entityName: 'content',
|
|
102
|
+
id: primaryViewableId,
|
|
103
|
+
relations
|
|
104
|
+
});
|
|
105
|
+
this.logContentResults(content, relations);
|
|
106
|
+
return content;
|
|
107
|
+
}
|
|
108
|
+
/** This outputs the content entity, without the inflated file entities.
|
|
109
|
+
* To help debugging issues with sending the thumbnail info.
|
|
110
|
+
* The inflated entities are removed, because are large and cause
|
|
111
|
+
* problems with log file size limits.
|
|
112
|
+
*
|
|
113
|
+
* @param content: the content with inflated objects
|
|
114
|
+
* @param relations: string[] of the slugs for inflated objects
|
|
115
|
+
*/
|
|
116
|
+
logContentResults(content, relations) {
|
|
117
|
+
if (app_framework_1.Logger.isDebugOn() && content && relations) {
|
|
118
|
+
const contentCopy = JSON.parse(JSON.stringify(content));
|
|
119
|
+
relations.forEach(r => {
|
|
120
|
+
delete contentCopy[r];
|
|
121
|
+
});
|
|
122
|
+
console.debug('content: ' + JSON.stringify(contentCopy));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Syncs the thumbnail from FlexPLM to VibeIQ. Handles creating, replacing, or removing
|
|
126
|
+
* the primary viewable content and persists the updates directly to the entity.
|
|
127
|
+
*
|
|
128
|
+
* @param entityId - The ID of the entity to update with thumbnail properties.
|
|
129
|
+
* @param primaryViewableId - The existing primary viewable content ID, if any.
|
|
130
|
+
* @param event - The inbound event containing thumbnail data (NEW_THUMBNAIL_ID / EXISTING_THUMBNAIL_ID).
|
|
131
|
+
* @param entityName - The entity type name (e.g. 'item', 'color') used for API calls.
|
|
132
|
+
* @returns The updated entity, or undefined if no thumbnail changes were needed.
|
|
133
|
+
*/
|
|
134
|
+
async syncThumbnailToVibeIQ({ entityId, primaryViewableId, event, entityName }) {
|
|
135
|
+
console.debug(`syncThumbnailToVibeIQ: entityId=${entityId}, primaryViewableId=${primaryViewableId}, entityName=${entityName}`);
|
|
136
|
+
const eventData = event.data || {};
|
|
137
|
+
const newThumbnailId = eventData[ThumbnailUtil.NEW_THUMBNAIL_ID];
|
|
138
|
+
const existingThumbnailId = eventData[ThumbnailUtil.EXISTING_THUMBNAIL_ID];
|
|
139
|
+
const thumbnailUrl = newThumbnailId || existingThumbnailId;
|
|
140
|
+
// Case 1: REMOVE_THUMBNAIL
|
|
141
|
+
if (newThumbnailId === ThumbnailUtil.REMOVE_THUMBNAIL) {
|
|
142
|
+
if (primaryViewableId) {
|
|
143
|
+
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
144
|
+
}
|
|
145
|
+
const clearUpdates = await this.getClearPrimaryViewableUpdates();
|
|
146
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: clearUpdates });
|
|
147
|
+
console.debug(`syncThumbnailToVibeIQ: applied clear updates for entityId=${entityId}`);
|
|
148
|
+
return updatedEntity;
|
|
149
|
+
}
|
|
150
|
+
// Early return if no thumbnail URL
|
|
151
|
+
if (!thumbnailUrl) {
|
|
152
|
+
console.debug(`syncThumbnailToVibeIQ: no thumbnail URL for entityId=${entityId}`);
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
// Case 2: No existing primaryViewableId — create new content
|
|
156
|
+
if (!primaryViewableId) {
|
|
157
|
+
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
158
|
+
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
159
|
+
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
160
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
161
|
+
console.debug(`syncThumbnailToVibeIQ: created new content ${content.id} for entityId=${entityId}`);
|
|
162
|
+
return updatedEntity;
|
|
163
|
+
}
|
|
164
|
+
// Case 3: Has primaryViewableId — check if thumbnail changed
|
|
165
|
+
const primaryViewable = await this.entities.get({ entityName: 'content', id: primaryViewableId });
|
|
166
|
+
if (primaryViewable?.flexplmThumbnailUrl === thumbnailUrl) {
|
|
167
|
+
console.debug(`syncThumbnailToVibeIQ: thumbnail already synced for entityId=${entityId}`);
|
|
168
|
+
return undefined; // Already synced
|
|
169
|
+
}
|
|
170
|
+
const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
|
|
171
|
+
await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
|
|
172
|
+
const primaryUpdates = await this.getPrimaryViewableUpdates(content);
|
|
173
|
+
const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
|
|
174
|
+
await this.entities.delete({ entityName: 'content', id: primaryViewableId });
|
|
175
|
+
console.debug(`syncThumbnailToVibeIQ: replaced content ${primaryViewableId} with ${content.id} for entityId=${entityId}`);
|
|
176
|
+
return updatedEntity;
|
|
177
|
+
}
|
|
178
|
+
async createContentFromFlexPLM(thumbnailUrl, entityId, entityName) {
|
|
179
|
+
const urlParts = thumbnailUrl.split('/');
|
|
180
|
+
const fileName = urlParts[urlParts.length - 1] || 'thumbnail';
|
|
181
|
+
const encodedUrl = urlParts.map(part => encodeURIComponent(part)).join('/');
|
|
182
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
183
|
+
const response = await flexPLMConnect.getRequest({
|
|
184
|
+
urlPath: encodedUrl,
|
|
185
|
+
includeUrlContext: false,
|
|
186
|
+
returnFullResponse: true,
|
|
187
|
+
});
|
|
188
|
+
const fileBuffer = await response.arrayBuffer();
|
|
189
|
+
const buffer = Buffer.from(fileBuffer);
|
|
190
|
+
const contentTypeHeader = response.headers.get('content-type');
|
|
191
|
+
const contentType = contentTypeHeader ? contentTypeHeader.split(';')[0] : 'application/octet-stream';
|
|
192
|
+
const contentHolderReference = `${entityName}:${entityId}`;
|
|
193
|
+
const content = await new sdk_1.Content().create({
|
|
194
|
+
fileBuffer: buffer,
|
|
195
|
+
fileName,
|
|
196
|
+
contentType,
|
|
197
|
+
contentHolderReference,
|
|
198
|
+
});
|
|
199
|
+
return content;
|
|
200
|
+
}
|
|
201
|
+
async getPrimaryViewableUpdates(content) {
|
|
202
|
+
const updates = {
|
|
203
|
+
primaryViewableId: content.id,
|
|
204
|
+
contentType: content.contentType,
|
|
205
|
+
fileName: content.fileName,
|
|
206
|
+
primaryFileUrl: content.primaryFileUrl,
|
|
207
|
+
largeViewableDownloadUrl: content.largeViewableUrl || content.primaryFileUrl,
|
|
208
|
+
mediumLargeViewableDownloadUrl: content.mediumLargeViewableUrl || content.primaryFileUrl,
|
|
209
|
+
mediumViewableDownloadUrl: content.mediumViewableUrl || content.primaryFileUrl,
|
|
210
|
+
smallViewableDownloadUrl: content.smallViewableUrl || content.primaryFileUrl,
|
|
211
|
+
tinyViewableDownloadUrl: content.tinyViewableUrl || content.primaryFileUrl,
|
|
212
|
+
};
|
|
213
|
+
const customSizes = await this.getCustomSizes();
|
|
214
|
+
for (const size of customSizes) {
|
|
215
|
+
updates[`${size.slug}DownloadUrl`] = content[`${size.slug}Url`] || content.primaryFileUrl;
|
|
216
|
+
}
|
|
217
|
+
return updates;
|
|
218
|
+
}
|
|
219
|
+
async getClearPrimaryViewableUpdates() {
|
|
220
|
+
const updates = {
|
|
221
|
+
primaryViewableId: null,
|
|
222
|
+
contentType: null,
|
|
223
|
+
fileName: null,
|
|
224
|
+
primaryFileUrl: null,
|
|
225
|
+
largeViewableDownloadUrl: null,
|
|
226
|
+
mediumLargeViewableDownloadUrl: null,
|
|
227
|
+
mediumViewableDownloadUrl: null,
|
|
228
|
+
smallViewableDownloadUrl: null,
|
|
229
|
+
tinyViewableDownloadUrl: null,
|
|
230
|
+
};
|
|
231
|
+
const customSizes = await this.getCustomSizes();
|
|
232
|
+
for (const size of customSizes) {
|
|
233
|
+
updates[`${size.slug}DownloadUrl`] = null;
|
|
234
|
+
}
|
|
235
|
+
return updates;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.ThumbnailUtil = ThumbnailUtil;
|
|
239
|
+
ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
|
|
240
|
+
ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
|
|
241
|
+
ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
|
|
242
|
+
ThumbnailUtil.OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|