@contrail/flexplm 1.3.0 → 1.3.1-alpha.3507ab6

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 (149) hide show
  1. package/lib/cli/commands/compile.d.ts +1 -0
  2. package/lib/cli/commands/compile.js +71 -0
  3. package/lib/cli/commands/compile.spec.d.ts +1 -0
  4. package/lib/cli/commands/compile.spec.js +80 -0
  5. package/lib/cli/commands/create.d.ts +1 -0
  6. package/lib/cli/commands/create.js +75 -0
  7. package/lib/cli/commands/create.spec.d.ts +1 -0
  8. package/lib/cli/commands/create.spec.js +78 -0
  9. package/lib/cli/commands/upload.d.ts +10 -0
  10. package/lib/cli/commands/upload.js +228 -0
  11. package/lib/cli/commands/upload.spec.d.ts +1 -0
  12. package/lib/cli/commands/upload.spec.js +88 -0
  13. package/lib/cli/index.d.ts +2 -0
  14. package/lib/cli/index.js +64 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +79 -0
  17. package/lib/cli/template/mapping-template.ts.template +62 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +89 -42
  19. package/lib/entity-processor/base-entity-processor.js +438 -385
  20. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  21. package/lib/entity-processor/base-entity-processor.spec.js +398 -397
  22. package/lib/flexplm-request.d.ts +3 -3
  23. package/lib/flexplm-request.js +34 -34
  24. package/lib/flexplm-utils.d.ts +5 -5
  25. package/lib/flexplm-utils.js +33 -33
  26. package/lib/flexplm-utils.spec.d.ts +1 -1
  27. package/lib/flexplm-utils.spec.js +26 -26
  28. package/lib/index.d.ts +23 -22
  29. package/lib/index.js +39 -38
  30. package/lib/interfaces/interfaces.d.ts +105 -105
  31. package/lib/interfaces/interfaces.js +2 -2
  32. package/lib/interfaces/item-family-changes.d.ts +20 -20
  33. package/lib/interfaces/item-family-changes.js +56 -56
  34. package/lib/interfaces/mapping-file.d.ts +460 -0
  35. package/lib/interfaces/mapping-file.js +2 -0
  36. package/lib/interfaces/publish-change-data.d.ts +19 -19
  37. package/lib/interfaces/publish-change-data.js +32 -32
  38. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  39. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  40. package/lib/publish/base-process-publish-assortment.d.ts +118 -93
  41. package/lib/publish/base-process-publish-assortment.js +998 -944
  42. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  43. package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
  44. package/lib/publish/mockData.d.ts +1389 -1389
  45. package/lib/publish/mockData.js +4524 -4519
  46. package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
  47. package/lib/transform/identifier-conversion.d.ts +51 -15
  48. package/lib/transform/identifier-conversion.js +248 -212
  49. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  50. package/lib/transform/identifier-conversion.spec.js +343 -339
  51. package/lib/util/config-defaults.d.ts +8 -8
  52. package/lib/util/config-defaults.js +88 -85
  53. package/lib/util/config-defaults.spec.d.ts +1 -1
  54. package/lib/util/config-defaults.spec.js +302 -293
  55. package/lib/util/data-converter-spec-mockData.js +219 -205
  56. package/lib/util/data-converter.d.ts +136 -39
  57. package/lib/util/data-converter.js +718 -592
  58. package/lib/util/data-converter.spec.d.ts +1 -1
  59. package/lib/util/data-converter.spec.js +906 -904
  60. package/lib/util/error-response-object.d.ts +9 -4
  61. package/lib/util/error-response-object.js +54 -47
  62. package/lib/util/error-response-object.spec.d.ts +1 -1
  63. package/lib/util/error-response-object.spec.js +99 -99
  64. package/lib/util/event-short-message-status.d.ts +19 -19
  65. package/lib/util/event-short-message-status.js +24 -23
  66. package/lib/util/federation.d.ts +15 -15
  67. package/lib/util/federation.js +157 -149
  68. package/lib/util/flexplm-connect.d.ts +29 -22
  69. package/lib/util/flexplm-connect.js +190 -176
  70. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  71. package/lib/util/flexplm-connect.spec.js +88 -88
  72. package/lib/util/logger-config.d.ts +1 -1
  73. package/lib/util/logger-config.js +27 -26
  74. package/lib/util/map-util-spec-mockData.js +219 -205
  75. package/lib/util/map-utils.d.ts +33 -6
  76. package/lib/util/map-utils.js +42 -15
  77. package/lib/util/map-utils.spec.d.ts +1 -1
  78. package/lib/util/map-utils.spec.js +89 -89
  79. package/lib/util/mockData.d.ts +80 -80
  80. package/lib/util/mockData.js +103 -103
  81. package/lib/util/thumbnail-util.d.ts +55 -34
  82. package/lib/util/thumbnail-util.js +242 -215
  83. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  84. package/lib/util/thumbnail-util.spec.js +440 -434
  85. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  86. package/lib/util/type-conversion-utils.d.ts +163 -23
  87. package/lib/util/type-conversion-utils.js +408 -265
  88. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  89. package/lib/util/type-conversion-utils.spec.js +868 -868
  90. package/lib/util/type-defaults.d.ts +74 -16
  91. package/lib/util/type-defaults.js +279 -221
  92. package/lib/util/type-defaults.spec.d.ts +1 -1
  93. package/lib/util/type-defaults.spec.js +516 -516
  94. package/lib/util/type-utils.d.ts +34 -13
  95. package/lib/util/type-utils.js +137 -114
  96. package/lib/util/type-utils.spec.d.ts +1 -1
  97. package/lib/util/type-utils.spec.js +192 -190
  98. package/package.json +21 -6
  99. package/scripts/copy-template.js +10 -0
  100. package/.claude/settings.local.json +0 -8
  101. package/.github/pull_request_template.md +0 -31
  102. package/.github/workflows/flexplm-lib.yml +0 -27
  103. package/.github/workflows/publish-to-npm.yml +0 -124
  104. package/CHANGELOG.md +0 -32
  105. package/publish.bat +0 -5
  106. package/publish.sh +0 -5
  107. package/src/entity-processor/base-entity-processor.spec.ts +0 -460
  108. package/src/entity-processor/base-entity-processor.ts +0 -515
  109. package/src/flexplm-request.ts +0 -28
  110. package/src/flexplm-utils.spec.ts +0 -27
  111. package/src/flexplm-utils.ts +0 -29
  112. package/src/index.ts +0 -22
  113. package/src/interfaces/interfaces.ts +0 -122
  114. package/src/interfaces/item-family-changes.ts +0 -67
  115. package/src/interfaces/publish-change-data.ts +0 -43
  116. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  117. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  118. package/src/publish/base-process-publish-assortment.ts +0 -1134
  119. package/src/publish/mockData.ts +0 -4561
  120. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  121. package/src/transform/identifier-conversion.spec.ts +0 -354
  122. package/src/transform/identifier-conversion.ts +0 -282
  123. package/src/util/config-defaults.spec.ts +0 -350
  124. package/src/util/config-defaults.ts +0 -93
  125. package/src/util/data-converter-spec-mockData.ts +0 -231
  126. package/src/util/data-converter.spec.ts +0 -1041
  127. package/src/util/data-converter.ts +0 -762
  128. package/src/util/error-response-object.spec.ts +0 -116
  129. package/src/util/error-response-object.ts +0 -50
  130. package/src/util/event-short-message-status.ts +0 -22
  131. package/src/util/federation.ts +0 -172
  132. package/src/util/flexplm-connect.spec.ts +0 -132
  133. package/src/util/flexplm-connect.ts +0 -208
  134. package/src/util/logger-config.ts +0 -20
  135. package/src/util/map-util-spec-mockData.ts +0 -231
  136. package/src/util/map-utils.spec.ts +0 -103
  137. package/src/util/map-utils.ts +0 -41
  138. package/src/util/mockData.ts +0 -101
  139. package/src/util/thumbnail-util.spec.ts +0 -508
  140. package/src/util/thumbnail-util.ts +0 -272
  141. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  142. package/src/util/type-conversion-utils.spec.ts +0 -968
  143. package/src/util/type-conversion-utils.ts +0 -460
  144. package/src/util/type-defaults.spec.ts +0 -669
  145. package/src/util/type-defaults.ts +0 -281
  146. package/src/util/type-utils.spec.ts +0 -227
  147. package/src/util/type-utils.ts +0 -144
  148. package/tsconfig.json +0 -29
  149. 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
- this.max_thumbnail_size = 5 * 1024 * 1024;
12
- this.entities = new sdk_1.Entities();
13
- if (this.config['max_thumbnail_size']) {
14
- this.max_thumbnail_size = this.config['max_thumbnail_size'];
15
- }
16
- }
17
- async setOutboundThumbnail(data, event) {
18
- if (event?.newData?.primaryViewableId && event?.newData?.largeViewableDownloadUrl) {
19
- const primaryViewableId = event.newData.primaryViewableId;
20
- const fileId = await this.getFileId(primaryViewableId);
21
- if (fileId) {
22
- const customSizes = await this.getCustomSizes();
23
- const key = (this.isThumbnailNew(event, customSizes))
24
- ? ThumbnailUtil.NEW_THUMBNAIL_ID
25
- : ThumbnailUtil.EXISTING_THUMBNAIL_ID;
26
- data[key] = fileId;
27
- }
28
- }
29
- else if (event?.propertyDiffs?.largeViewableDownloadUrl?.oldValue && !event?.propertyDiffs?.largeViewableDownloadUrl?.newValue) {
30
- data[ThumbnailUtil.NEW_THUMBNAIL_ID] = ThumbnailUtil.REMOVE_THUMBNAIL;
31
- }
32
- return data;
33
- }
34
- isThumbnailNew(event, customSizes) {
35
- const propertyDiffs = event?.propertyDiffs;
36
- if (propertyDiffs) {
37
- const diffKeys = Object.keys(propertyDiffs);
38
- const sizeKeys = ThumbnailUtil.OOB_SIZES.map(s => s.slug + 'DownloadUrl');
39
- if (customSizes) {
40
- sizeKeys.push(...customSizes.map(s => s.slug + 'Url'));
41
- }
42
- sizeKeys.push('primaryFileUrl');
43
- console.info('diffKeys: ' + JSON.stringify(diffKeys));
44
- console.info('sizeKeys: ' + JSON.stringify(sizeKeys));
45
- return diffKeys.some(s => sizeKeys.includes(s));
46
- }
47
- return false;
48
- }
49
- async getFileId(primaryViewableId) {
50
- console.info('ThumbnailUtil.getFileId()-' + primaryViewableId);
51
- const sizes = await this.getCustomSizes();
52
- const OOBSizes = JSON.parse(JSON.stringify(ThumbnailUtil.OOB_SIZES));
53
- sizes.push(...OOBSizes);
54
- console.info('sizes: ' + JSON.stringify(sizes));
55
- const content = await this.getContentEntity(primaryViewableId, sizes);
56
- if (!content) {
57
- return undefined;
58
- }
59
- const contentKeys = Object.getOwnPropertyNames(content);
60
- const isDebugOn = app_framework_1.Logger.isDebugOn();
61
- let fileId = undefined;
62
- let tempFileSize = 0;
63
- for (const size of sizes) {
64
- const slug = size?.slug;
65
- if (contentKeys.includes(slug)) {
66
- const file = content[slug];
67
- if (isDebugOn) {
68
- console.debug('size: ' + slug);
69
- console.debug('fileId: ' + file['id']);
70
- }
71
- if (file && file['size'] > tempFileSize && file['size'] < this.max_thumbnail_size) {
72
- tempFileSize = file['size'];
73
- fileId = file['id'];
74
- if (isDebugOn) {
75
- console.debug('fileId: ' + fileId);
76
- }
77
- }
78
- }
79
- }
80
- console.info('ThumbnailUtil.getFileId(): returning-' + fileId);
81
- return fileId;
82
- }
83
- async getCustomSizes() {
84
- const customSizes = await this.entities.get({
85
- entityName: 'content-custom-size'
86
- });
87
- const sizes = [];
88
- sizes.push(...customSizes);
89
- return sizes;
90
- }
91
- async getContentEntity(primaryViewableId, sizes) {
92
- const relations = sizes.map(s => s.slug);
93
- relations.push('primaryFile');
94
- const content = await this.entities.get({
95
- entityName: 'content',
96
- id: primaryViewableId,
97
- relations
98
- });
99
- this.logContentResults(content, relations);
100
- return content;
101
- }
102
- logContentResults(content, relations) {
103
- if (app_framework_1.Logger.isDebugOn() && content && relations) {
104
- const contentCopy = JSON.parse(JSON.stringify(content));
105
- relations.forEach(r => {
106
- delete contentCopy[r];
107
- });
108
- console.debug('content: ' + JSON.stringify(contentCopy));
109
- }
110
- }
111
- async syncThumbnailToVibeIQ({ entityId, primaryViewableId, event, entityName }) {
112
- console.debug(`syncThumbnailToVibeIQ: entityId=${entityId}, primaryViewableId=${primaryViewableId}, entityName=${entityName}`);
113
- const eventData = event.data || {};
114
- const newThumbnailId = eventData[ThumbnailUtil.NEW_THUMBNAIL_ID];
115
- const existingThumbnailId = eventData[ThumbnailUtil.EXISTING_THUMBNAIL_ID];
116
- const thumbnailUrl = newThumbnailId || existingThumbnailId;
117
- if (newThumbnailId === ThumbnailUtil.REMOVE_THUMBNAIL) {
118
- if (primaryViewableId) {
119
- await this.entities.delete({ entityName: 'content', id: primaryViewableId });
120
- }
121
- const clearUpdates = await this.getClearPrimaryViewableUpdates();
122
- const updatedEntity = await this.entities.update({ entityName, id: entityId, object: clearUpdates });
123
- console.debug(`syncThumbnailToVibeIQ: applied clear updates for entityId=${entityId}`);
124
- return updatedEntity;
125
- }
126
- if (!thumbnailUrl) {
127
- console.debug(`syncThumbnailToVibeIQ: no thumbnail URL for entityId=${entityId}`);
128
- return undefined;
129
- }
130
- if (!primaryViewableId) {
131
- const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
132
- await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
133
- const primaryUpdates = await this.getPrimaryViewableUpdates(content);
134
- const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
135
- console.debug(`syncThumbnailToVibeIQ: created new content ${content.id} for entityId=${entityId}`);
136
- return updatedEntity;
137
- }
138
- const primaryViewable = await this.entities.get({ entityName: 'content', id: primaryViewableId });
139
- if (primaryViewable?.flexplmThumbnailUrl === thumbnailUrl) {
140
- console.debug(`syncThumbnailToVibeIQ: thumbnail already synced for entityId=${entityId}`);
141
- return undefined;
142
- }
143
- const content = await this.createContentFromFlexPLM(thumbnailUrl, entityId, entityName);
144
- await this.entities.update({ entityName: 'content', id: content.id, object: { flexplmThumbnailUrl: thumbnailUrl } });
145
- const primaryUpdates = await this.getPrimaryViewableUpdates(content);
146
- const updatedEntity = await this.entities.update({ entityName, id: entityId, object: primaryUpdates });
147
- await this.entities.delete({ entityName: 'content', id: primaryViewableId });
148
- console.debug(`syncThumbnailToVibeIQ: replaced content ${primaryViewableId} with ${content.id} for entityId=${entityId}`);
149
- return updatedEntity;
150
- }
151
- async createContentFromFlexPLM(thumbnailUrl, entityId, entityName) {
152
- const urlParts = thumbnailUrl.split('/');
153
- const fileName = urlParts[urlParts.length - 1] || 'thumbnail';
154
- const encodedUrl = urlParts.map(part => encodeURIComponent(part)).join('/');
155
- const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
156
- const response = await flexPLMConnect.getRequest({
157
- urlPath: encodedUrl,
158
- includeUrlContext: false,
159
- returnFullResponse: true,
160
- });
161
- const fileBuffer = await response.arrayBuffer();
162
- const buffer = Buffer.from(fileBuffer);
163
- const contentTypeHeader = response.headers.get('content-type');
164
- const contentType = contentTypeHeader ? contentTypeHeader.split(';')[0] : 'application/octet-stream';
165
- const contentHolderReference = `${entityName}:${entityId}`;
166
- const content = await new sdk_1.Content().create({
167
- fileBuffer: buffer,
168
- fileName,
169
- contentType,
170
- contentHolderReference,
171
- });
172
- return content;
173
- }
174
- async getPrimaryViewableUpdates(content) {
175
- const updates = {
176
- primaryViewableId: content.id,
177
- contentType: content.contentType,
178
- fileName: content.fileName,
179
- primaryFileUrl: content.primaryFileUrl,
180
- largeViewableDownloadUrl: content.largeViewableUrl || content.primaryFileUrl,
181
- mediumLargeViewableDownloadUrl: content.mediumLargeViewableUrl || content.primaryFileUrl,
182
- mediumViewableDownloadUrl: content.mediumViewableUrl || content.primaryFileUrl,
183
- smallViewableDownloadUrl: content.smallViewableUrl || content.primaryFileUrl,
184
- tinyViewableDownloadUrl: content.tinyViewableUrl || content.primaryFileUrl,
185
- };
186
- const customSizes = await this.getCustomSizes();
187
- for (const size of customSizes) {
188
- updates[`${size.slug}DownloadUrl`] = content[`${size.slug}Url`] || content.primaryFileUrl;
189
- }
190
- return updates;
191
- }
192
- async getClearPrimaryViewableUpdates() {
193
- const updates = {
194
- primaryViewableId: null,
195
- contentType: null,
196
- fileName: null,
197
- primaryFileUrl: null,
198
- largeViewableDownloadUrl: null,
199
- mediumLargeViewableDownloadUrl: null,
200
- mediumViewableDownloadUrl: null,
201
- smallViewableDownloadUrl: null,
202
- tinyViewableDownloadUrl: null,
203
- };
204
- const customSizes = await this.getCustomSizes();
205
- for (const size of customSizes) {
206
- updates[`${size.slug}DownloadUrl`] = null;
207
- }
208
- return updates;
209
- }
210
- }
211
- exports.ThumbnailUtil = ThumbnailUtil;
212
- ThumbnailUtil.NEW_THUMBNAIL_ID = 'NEW_THUMBNAIL_ID';
213
- ThumbnailUtil.EXISTING_THUMBNAIL_ID = 'EXISTING_THUMBNAIL_ID';
214
- ThumbnailUtil.REMOVE_THUMBNAIL = 'REMOVE_THUMBNAIL';
215
- ThumbnailUtil.OOB_SIZES = [{ slug: 'largeViewable' }, { slug: 'mediumLargeViewable' }, { slug: 'mediumViewable' }, { slug: 'smallViewable' }, { slug: 'tinyViewable' }];
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 {};