@contrail/flexplm 1.5.1-alpha.64caad7 → 1.6.0-alpha.6f15d4e

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 (111) hide show
  1. package/lib/cli/commands/compile.d.ts +4 -0
  2. package/lib/cli/commands/compile.js +73 -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 +5 -0
  6. package/lib/cli/commands/create.js +77 -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 +17 -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 +5 -0
  14. package/lib/cli/index.js +70 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +85 -0
  17. package/lib/cli/template/mapping-template.ts.template +62 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +65 -0
  19. package/lib/entity-processor/base-entity-processor.js +71 -0
  20. package/lib/entity-processor/base-entity-processor.spec.js +1 -0
  21. package/lib/index.d.ts +1 -0
  22. package/lib/index.js +1 -0
  23. package/lib/interfaces/mapping-file.d.ts +460 -0
  24. package/lib/interfaces/mapping-file.js +2 -0
  25. package/lib/publish/base-process-publish-assortment.d.ts +25 -1
  26. package/lib/publish/base-process-publish-assortment.js +67 -48
  27. package/lib/publish/base-process-publish-assortment.spec.js +22 -143
  28. package/lib/publish/mockData.js +5 -0
  29. package/lib/transform/identifier-conversion-spec-mockData.js +34 -6
  30. package/lib/transform/identifier-conversion.d.ts +36 -0
  31. package/lib/transform/identifier-conversion.js +36 -0
  32. package/lib/transform/identifier-conversion.spec.js +4 -0
  33. package/lib/util/config-defaults.js +3 -0
  34. package/lib/util/config-defaults.spec.js +9 -0
  35. package/lib/util/data-converter-spec-mockData.js +17 -3
  36. package/lib/util/data-converter.d.ts +97 -0
  37. package/lib/util/data-converter.js +127 -1
  38. package/lib/util/data-converter.spec.js +2 -0
  39. package/lib/util/error-response-object.d.ts +5 -0
  40. package/lib/util/error-response-object.js +7 -0
  41. package/lib/util/event-short-message-status.js +1 -0
  42. package/lib/util/federation.js +8 -0
  43. package/lib/util/flexplm-connect.d.ts +7 -0
  44. package/lib/util/flexplm-connect.js +14 -0
  45. package/lib/util/logger-config.js +1 -0
  46. package/lib/util/map-util-spec-mockData.js +17 -3
  47. package/lib/util/map-utils.d.ts +27 -0
  48. package/lib/util/map-utils.js +27 -0
  49. package/lib/util/thumbnail-util.d.ts +21 -0
  50. package/lib/util/thumbnail-util.js +28 -1
  51. package/lib/util/thumbnail-util.spec.js +6 -0
  52. package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
  53. package/lib/util/type-conversion-utils.d.ts +151 -0
  54. package/lib/util/type-conversion-utils.js +154 -0
  55. package/lib/util/type-defaults.d.ts +66 -0
  56. package/lib/util/type-defaults.js +66 -0
  57. package/lib/util/type-defaults.spec.js +5 -5
  58. package/lib/util/type-utils.d.ts +21 -0
  59. package/lib/util/type-utils.js +23 -0
  60. package/lib/util/type-utils.spec.js +2 -0
  61. package/package.json +21 -6
  62. package/scripts/copy-template.js +10 -0
  63. package/.github/pull_request_template.md +0 -31
  64. package/.github/workflows/flexplm-lib.yml +0 -27
  65. package/.github/workflows/publish-to-npm.yml +0 -121
  66. package/CHANGELOG.md +0 -49
  67. package/publish.bat +0 -5
  68. package/publish.sh +0 -5
  69. package/src/entity-processor/base-entity-processor.spec.ts +0 -689
  70. package/src/entity-processor/base-entity-processor.ts +0 -583
  71. package/src/flexplm-request.ts +0 -28
  72. package/src/flexplm-utils.spec.ts +0 -27
  73. package/src/flexplm-utils.ts +0 -29
  74. package/src/index.ts +0 -22
  75. package/src/interfaces/interfaces.ts +0 -122
  76. package/src/interfaces/item-family-changes.ts +0 -67
  77. package/src/interfaces/publish-change-data.ts +0 -43
  78. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  79. package/src/publish/base-process-publish-assortment.spec.ts +0 -2154
  80. package/src/publish/base-process-publish-assortment.ts +0 -1173
  81. package/src/publish/mockData.ts +0 -4561
  82. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  83. package/src/transform/identifier-conversion.spec.ts +0 -386
  84. package/src/transform/identifier-conversion.ts +0 -282
  85. package/src/util/config-defaults.spec.ts +0 -445
  86. package/src/util/config-defaults.ts +0 -106
  87. package/src/util/data-converter-spec-mockData.ts +0 -231
  88. package/src/util/data-converter.spec.ts +0 -1622
  89. package/src/util/data-converter.ts +0 -819
  90. package/src/util/error-response-object.spec.ts +0 -116
  91. package/src/util/error-response-object.ts +0 -50
  92. package/src/util/event-short-message-status.ts +0 -22
  93. package/src/util/federation.ts +0 -172
  94. package/src/util/flexplm-connect.spec.ts +0 -132
  95. package/src/util/flexplm-connect.ts +0 -208
  96. package/src/util/logger-config.ts +0 -20
  97. package/src/util/map-util-spec-mockData.ts +0 -231
  98. package/src/util/map-utils.spec.ts +0 -103
  99. package/src/util/map-utils.ts +0 -41
  100. package/src/util/mockData.ts +0 -101
  101. package/src/util/thumbnail-util.spec.ts +0 -508
  102. package/src/util/thumbnail-util.ts +0 -272
  103. package/src/util/type-conversion-utils-spec-mockData.ts +0 -272
  104. package/src/util/type-conversion-utils.spec.ts +0 -1031
  105. package/src/util/type-conversion-utils.ts +0 -490
  106. package/src/util/type-defaults.spec.ts +0 -797
  107. package/src/util/type-defaults.ts +0 -320
  108. package/src/util/type-utils.spec.ts +0 -227
  109. package/src/util/type-utils.ts +0 -144
  110. package/tsconfig.json +0 -24
  111. package/tslint.json +0 -57
@@ -1,445 +0,0 @@
1
- import { ConfigDefaults } from './config-defaults';
2
- import { FCConfig } from '../interfaces/interfaces';
3
- import { TypeDefaults } from './type-defaults';
4
-
5
- let entityObject = {};
6
- jest.mock('@contrail/sdk', () => {
7
- return {
8
- Entities: class {
9
- get() {
10
- return entityObject;
11
- }
12
- }
13
- };
14
- });
15
-
16
- let fetchJson = {};
17
- global.fetch = jest.fn().mockImplementation(() => {
18
- return Promise.resolve({
19
- json: () => Promise.resolve(fetchJson)
20
- });
21
-
22
- });
23
-
24
- describe('all tests', () => {
25
- describe('setConfigDefaults - required values', () => {
26
- it('missing apiHost', async () => {
27
- const config = {
28
- //apiHost: 'http://test.com',
29
- userName: 'vibeiq',
30
- password: 'vibeiq',
31
- plmEnviornment: 'SB'
32
- };
33
-
34
- try {
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
36
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(config);
37
-
38
- } catch (e) {
39
- expect(e.message).toEqual(ConfigDefaults.NEED_CONFIG_VALUES);
40
- }
41
- });
42
- it('missing userName', async () => {
43
- const config = {
44
- apiHost: 'http://test.com',
45
- //userName: 'vibeiq',
46
- password: 'vibeiq',
47
- plmEnviornment: 'SB'
48
- };
49
-
50
- try {
51
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
52
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(config);
53
-
54
- } catch (e) {
55
- expect(e.message).toEqual(ConfigDefaults.NEED_CONFIG_VALUES);
56
- }
57
- });
58
-
59
- it('missing password', async () => {
60
- const config = {
61
- apiHost: 'http://test.com',
62
- userName: 'vibeiq',
63
- //password: 'vibeiq',
64
- plmEnviornment: 'SB'
65
- };
66
-
67
- try {
68
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
69
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(config);
70
-
71
- } catch (e) {
72
- expect(e.message).toEqual(ConfigDefaults.NEED_CONFIG_VALUES);
73
- }
74
- });
75
-
76
- it('missing plmEnviornment', async () => {
77
- const config = {
78
- apiHost: 'http://test.com',
79
- userName: 'vibeiq',
80
- password: 'vibeiq',
81
- //plmEnviornment: 'SB'
82
- };
83
-
84
- try {
85
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-vars
86
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(config);
87
-
88
- } catch (e) {
89
- expect(e.message).toEqual(ConfigDefaults.NEED_CONFIG_VALUES);
90
- }
91
- });
92
-
93
- });
94
-
95
- describe('userName & password as functions', () =>{
96
- const config = {
97
- apiHost: 'http://test.com',
98
- userName: 'vibeiq',
99
- password: 'vibeiq',
100
- plmEnviornment: 'SB'
101
- };
102
- it('userName as function', async () =>{
103
- const startConfig = Object.assign({}, config, { userName: 'newName' });
104
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
105
- expect(fcConfig.userName()).toEqual('newName');
106
-
107
- });
108
- it('password as function', async () =>{
109
- const startConfig = Object.assign({}, config, { password: 'strange' });
110
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
111
- expect(fcConfig.password()).toEqual('strange');
112
-
113
- });
114
- });
115
-
116
- describe('setConfigDefaults-setting defaults', () => {
117
- const config = {
118
- apiHost: 'http://test.com',
119
- userName: 'vibeiq',
120
- password: 'vibeiq',
121
- plmEnviornment: 'SB'
122
- };
123
- it('urlContext-get default', async () => {
124
- const startConfig = Object.assign({}, config);
125
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
126
- expect(fcConfig.urlContext).toEqual('/Windchill');
127
- });
128
-
129
- it('urlContext-set value', async () => {
130
- const startConfig = Object.assign({}, config);
131
- startConfig['urlContext'] = '/FlexPLM';
132
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
133
- expect(fcConfig.urlContext).toEqual('/FlexPLM');
134
- });
135
-
136
- it('sendMode-ASYNC_PUBLISH_SEASON-get default', async () => {
137
- const startConfig = Object.assign({}, config);
138
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
139
- expect(fcConfig['sendMode']['ASYNC_PUBLISH_SEASON']).toEqual('vibeiqfile');
140
- });
141
-
142
- it('sendMode-ASYNC_PUBLISH_SEASON-set value', async () => {
143
- const startConfig = Object.assign({}, config);
144
- startConfig['sendMode'] = { ASYNC_PUBLISH_SEASON: 'vibeiqfile-dontsendtoflexplm' };
145
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
146
- expect(fcConfig['sendMode']['ASYNC_PUBLISH_SEASON']).toEqual('vibeiqfile-dontsendtoflexplm');
147
- });
148
-
149
- it('sendMode-NO_DEFAULT-get default', async () => {
150
- const startConfig = Object.assign({}, config);
151
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
152
- expect(fcConfig['sendMode']['NO_DEFAULT']).toBeUndefined();
153
- });
154
-
155
- it('sendMode-NO_DEFAULT-set value', async () => {
156
- const startConfig = Object.assign({}, config);
157
- startConfig['sendMode'] = { NO_DEFAULT: 'vibeiqfile-dontsendtoflexplm' };
158
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
159
- expect(fcConfig['sendMode']['NO_DEFAULT']).toEqual('vibeiqfile-dontsendtoflexplm');
160
- });
161
-
162
- it('itemPreDevelopmentLifecycleStages-get default', async () => {
163
- const startConfig = Object.assign({}, config);
164
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
165
- expect(fcConfig['itemPreDevelopmentLifecycleStages']).toEqual(['concept']);
166
- });
167
-
168
- it('itemPreDevelopmentLifecycleStages-set value', async () => {
169
- const startConfig = Object.assign({}, config);
170
- const concept = 'concept';
171
- const development = 'development';
172
- startConfig['itemPreDevelopmentLifecycleStages'] = concept + ',' + development;
173
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
174
- const itemPreDevelopmentLifecycleStages = fcConfig['itemPreDevelopmentLifecycleStages'];
175
- expect(itemPreDevelopmentLifecycleStages instanceof Array).toBeTruthy();
176
- expect(itemPreDevelopmentLifecycleStages.length).toBe(2);
177
- expect(itemPreDevelopmentLifecycleStages.includes(concept));
178
- expect(itemPreDevelopmentLifecycleStages.includes(development));
179
- });
180
-
181
- it('itemPreDevelopmentLifecycleStages-set value with space', async () => {
182
- const startConfig = Object.assign({}, config);
183
- const concept = 'concept';
184
- const development = 'development';
185
- startConfig['itemPreDevelopmentLifecycleStages'] = concept + ', ' + development;
186
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
187
- const itemPreDevelopmentLifecycleStages = fcConfig['itemPreDevelopmentLifecycleStages'];
188
- expect(itemPreDevelopmentLifecycleStages instanceof Array).toBeTruthy();
189
- expect(itemPreDevelopmentLifecycleStages.length).toBe(2);
190
- expect(itemPreDevelopmentLifecycleStages.includes(concept));
191
- expect(itemPreDevelopmentLifecycleStages.includes(development));
192
- });
193
-
194
- it('itemPreDevelopmentLifecycleStages as empty string', async () => {
195
- console.log('itemPreDevelopmentLifecycleStages as empty string');
196
- const concept = 'concept';
197
- const startConfig = Object.assign({}, config);
198
- startConfig['itemPreDevelopmentLifecycleStages'] = '';
199
- console.log('startConfig: ' + JSON.stringify(startConfig));
200
-
201
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
202
- console.log('fcConfig: ' + JSON.stringify(fcConfig));
203
- const itemPreDevelopmentLifecycleStages = fcConfig['itemPreDevelopmentLifecycleStages'];
204
- expect(itemPreDevelopmentLifecycleStages instanceof Array).toBeTruthy();
205
- expect(itemPreDevelopmentLifecycleStages.length).toBe(1);
206
- expect(itemPreDevelopmentLifecycleStages.includes(concept));
207
-
208
- });
209
-
210
- it('itemPreDevelopmentLifecycleStages as empty array', async () => {
211
- console.log('itemPreDevelopmentLifecycleStages as empty string');
212
- const concept = 'concept';
213
- const startConfig = Object.assign({}, config);
214
- startConfig['itemPreDevelopmentLifecycleStages'] = [];
215
- console.log('startConfig: ' + JSON.stringify(startConfig));
216
-
217
- const fcConfig: FCConfig = await ConfigDefaults.setConfigDefaults(startConfig);
218
- console.log('fcConfig: ' + JSON.stringify(fcConfig));
219
- const itemPreDevelopmentLifecycleStages = fcConfig['itemPreDevelopmentLifecycleStages'];
220
- expect(itemPreDevelopmentLifecycleStages instanceof Array).toBeTruthy();
221
- expect(itemPreDevelopmentLifecycleStages.length).toBe(1);
222
- expect(itemPreDevelopmentLifecycleStages.includes(concept));
223
-
224
- });
225
- it('identifierAtts-LCSProduct-get default', async () => {
226
- const startConfig = Object.assign({}, config);
227
- const objectClass = 'LCSProduct';
228
- const expectedAtts = ['name'];
229
-
230
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
231
- const identifierAtts = fcConfig.identifierAtts[objectClass];
232
- expect(identifierAtts instanceof Array).toBeTruthy();
233
- expect(identifierAtts.length).toBe(expectedAtts.length);
234
- for (const att of expectedAtts) {
235
- expect(identifierAtts.includes(att));
236
- }
237
- });
238
-
239
- it('identifierAtts-LCSProduct-set value', async () => {
240
- const startConfig = Object.assign({}, config);
241
- const objectClass = 'LCSProduct';
242
- const expectedAtts = ['val1', 'val2'];
243
- startConfig['identifierAtts'] = {};
244
- startConfig['identifierAtts'][objectClass] = expectedAtts;
245
-
246
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
247
- const identifierAtts = fcConfig.identifierAtts[objectClass];
248
- expect(identifierAtts instanceof Array).toBeTruthy();
249
- expect(identifierAtts.length).toBe(expectedAtts.length);
250
- for (const att of expectedAtts) {
251
- expect(identifierAtts.includes(att));
252
- }
253
- });
254
-
255
- it('identifierAtts-LCSSeason-get default', async () => {
256
- const startConfig = Object.assign({}, config);
257
- const objectClass = 'LCSSeason';
258
- const expectedAtts = ['flexPLMSeasonName'];
259
- // const expectedAtts =['seasonType', 'seasonYear'];
260
-
261
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
262
- const identifierAtts = fcConfig.identifierAtts[objectClass];
263
- expect(identifierAtts instanceof Array).toBeTruthy();
264
- expect(identifierAtts.length).toBe(expectedAtts.length);
265
- for (const att of expectedAtts) {
266
- expect(identifierAtts.includes(att));
267
- }
268
- });
269
-
270
- it('identifierAtts-LCSSeason-set value', async () => {
271
- const startConfig = Object.assign({}, config);
272
- const objectClass = 'LCSSeason';
273
- const expectedAtts = ['val1', 'val2'];
274
- startConfig['identifierAtts'] = {};
275
- startConfig['identifierAtts'][objectClass] = expectedAtts;
276
-
277
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
278
- const identifierAtts = fcConfig.identifierAtts[objectClass];
279
- expect(identifierAtts instanceof Array).toBeTruthy();
280
- expect(identifierAtts.length).toBe(expectedAtts.length);
281
- for (const att of expectedAtts) {
282
- expect(identifierAtts.includes(att));
283
- }
284
- });
285
-
286
- it('identifierAtts-LCSSKU-get default', async () => {
287
- const startConfig = Object.assign({}, config);
288
- const objectClass = 'LCSSKU';
289
- const expectedAtts = ['optionName'];
290
-
291
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
292
- const identifierAtts = fcConfig.identifierAtts[objectClass];
293
- expect(identifierAtts instanceof Array).toBeTruthy();
294
- expect(identifierAtts.length).toBe(expectedAtts.length);
295
- for (const att of expectedAtts) {
296
- expect(identifierAtts.includes(att));
297
- }
298
- });
299
-
300
- it('identifierAtts-LCSSKU-set value', async () => {
301
- const startConfig = Object.assign({}, config);
302
- const objectClass = 'LCSSKU';
303
- const expectedAtts = ['val1', 'val2'];
304
- startConfig['identifierAtts'] = {};
305
- startConfig['identifierAtts'][objectClass] = expectedAtts;
306
-
307
- const fcConfig = await ConfigDefaults.setConfigDefaults(startConfig);
308
- const identifierAtts = fcConfig.identifierAtts[objectClass];
309
- expect(identifierAtts instanceof Array).toBeTruthy();
310
- expect(identifierAtts.length).toBe(expectedAtts.length);
311
- for (const att of expectedAtts) {
312
- expect(identifierAtts.includes(att));
313
- }
314
- });
315
-
316
- });
317
-
318
- describe('isPropertyTrue', () => {
319
- it('returns true for boolean true', () => {
320
- expect(ConfigDefaults.isPropertyTrue(true)).toBe(true);
321
- });
322
-
323
- it('returns true for string true', () => {
324
- expect(ConfigDefaults.isPropertyTrue('true')).toBe(true);
325
- });
326
-
327
- it('returns true for string TRUE', () => {
328
- expect(ConfigDefaults.isPropertyTrue('TRUE')).toBe(true);
329
- });
330
-
331
- it('returns true for string True', () => {
332
- expect(ConfigDefaults.isPropertyTrue('True')).toBe(true);
333
- });
334
-
335
- it('returns false for boolean false', () => {
336
- expect(ConfigDefaults.isPropertyTrue(false)).toBe(false);
337
- });
338
-
339
- it('returns false for string false', () => {
340
- expect(ConfigDefaults.isPropertyTrue('false')).toBe(false);
341
- });
342
-
343
- it('returns false for null', () => {
344
- expect(ConfigDefaults.isPropertyTrue(null)).toBe(false);
345
- });
346
-
347
- it('returns false for undefined', () => {
348
- expect(ConfigDefaults.isPropertyTrue(undefined)).toBe(false);
349
- });
350
-
351
- it('returns false for empty string', () => {
352
- expect(ConfigDefaults.isPropertyTrue('')).toBe(false);
353
- });
354
-
355
- it('returns false for number 1', () => {
356
- expect(ConfigDefaults.isPropertyTrue(1)).toBe(false);
357
- });
358
- });
359
-
360
- describe('getDefaultConfig', () => {
361
- it('returns LCSMaterial.processAsItem=false by default', () => {
362
- const dc: any = ConfigDefaults.getDefaultConfig();
363
- expect(dc.LCSMaterial).toBeDefined();
364
- expect(dc.LCSMaterial.processAsItem).toBe(false);
365
- });
366
-
367
- it('returns a fresh object each call (no shared reference)', () => {
368
- const a: any = ConfigDefaults.getDefaultConfig();
369
- const b: any = ConfigDefaults.getDefaultConfig();
370
- expect(a).not.toBe(b);
371
- expect(a.LCSMaterial).not.toBe(b.LCSMaterial);
372
- a.LCSMaterial.processAsItem = true;
373
- expect(b.LCSMaterial.processAsItem).toBe(false);
374
- });
375
- });
376
-
377
- describe('setConfigDefaults - LCSMaterial', () => {
378
- const config = {
379
- apiHost: 'http://test.com',
380
- userName: 'vibeiq',
381
- password: 'vibeiq'
382
- };
383
-
384
- it('LCSMaterial.processAsItem-get default', async () => {
385
- const startConfig = Object.assign({}, config);
386
- const fcConfig: any = await ConfigDefaults.setConfigDefaults(startConfig);
387
- expect(fcConfig.LCSMaterial.processAsItem).toBe(false);
388
- });
389
-
390
- it('LCSMaterial.processAsItem-override', async () => {
391
- const startConfig: any = Object.assign({}, config);
392
- startConfig.LCSMaterial = { processAsItem: true };
393
- const fcConfig: any = await ConfigDefaults.setConfigDefaults(startConfig);
394
- expect(fcConfig.LCSMaterial.processAsItem).toBe(true);
395
- });
396
-
397
- it('applies LCSMaterial.processAsItem to TypeDefaults', async () => {
398
- try {
399
- const startConfig: any = Object.assign({}, config, { LCSMaterial: { processAsItem: true } });
400
- await ConfigDefaults.setConfigDefaults(startConfig);
401
- expect(TypeDefaults.processLCSMaterialAsItem).toBe(true);
402
-
403
- const defaultStart: any = Object.assign({}, config);
404
- await ConfigDefaults.setConfigDefaults(defaultStart);
405
- expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
406
- } finally {
407
- TypeDefaults.applyConfig({});
408
- }
409
- });
410
- });
411
-
412
- describe('getConfigFile', () => {
413
- beforeEach(() => {
414
- ConfigDefaults.clearConfigCache();
415
- });
416
-
417
- it('response has test var', async () => {
418
- fetchJson = { testVar: true };
419
- entityObject = { downloadUrl: 'http://sss.com' };
420
-
421
- const config = await ConfigDefaults.getConfigFile('id-1');
422
- expect(config).toBeDefined();
423
- expect(config['testVar']).toBeTruthy();
424
- });
425
-
426
- it('undefined file object', async () => {
427
- fetchJson = { testVar: true };
428
- entityObject = undefined;
429
-
430
- const config = await ConfigDefaults.getConfigFile('id-1');
431
- expect(config).toBeDefined();
432
- expect(Object.keys(config).length).toEqual(0);
433
- });
434
-
435
- it('response no downloadUrl', async () => {
436
- fetchJson = { testVar: true };
437
- entityObject = { };
438
-
439
- const config = await ConfigDefaults.getConfigFile('id-1');
440
- expect(config).toBeDefined();
441
- expect(Object.keys(config).length).toEqual(0);
442
- });
443
-
444
- });
445
- });
@@ -1,106 +0,0 @@
1
- import { Entities } from '@contrail/sdk';
2
- import { FCConfig } from '../interfaces/interfaces';
3
- import { ObjectUtil } from '@contrail/util';
4
- import { TypeDefaults } from './type-defaults';
5
-
6
- export class ConfigDefaults {
7
- static NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
8
- static STATIC_CONFIG_CACHE = {};
9
- static async setConfigDefaults(config): Promise<FCConfig> {
10
- //Validate config
11
- if (!config.apiHost || !config.userName || !config.password) {
12
- throw new Error(ConfigDefaults.NEED_CONFIG_VALUES);
13
- }
14
-
15
- //List will be comma separated list in UI, so convert to array
16
- if(config?.itemPreDevelopmentLifecycleStages && !(config?.itemPreDevelopmentLifecycleStages instanceof Array)){
17
- config.itemPreDevelopmentLifecycleStages = config.itemPreDevelopmentLifecycleStages.split(',');
18
- } else if(Object.keys(config).includes('itemPreDevelopmentLifecycleStages')){
19
- delete config['itemPreDevelopmentLifecycleStages'];
20
- }
21
-
22
- const configArr = [ConfigDefaults.getDefaultConfig()];
23
-
24
- if(config.configFile){
25
- const fileConfig = await ConfigDefaults.getConfigFile(config.configFile);
26
- configArr.push(fileConfig);
27
- }
28
- configArr.push(config);
29
- const outputConfig = ObjectUtil.mergeDeep({}, ...configArr);
30
- const uName = outputConfig.userName;
31
- const pass = outputConfig.password;
32
- outputConfig.userName = () => uName;
33
- outputConfig.password = () => pass;
34
-
35
- //Don't allow overwriting this.
36
- outputConfig['OOBvibeEventEndpoint'] = '/rfa/vibeiq/vibeEvents';
37
-
38
- TypeDefaults.applyConfig(outputConfig);
39
-
40
- console.log('outputConfig: ' + JSON.stringify(outputConfig));
41
- return outputConfig as FCConfig;
42
- }
43
-
44
- static getDefaultConfig() {
45
- return {
46
- urlContext: '/Windchill',
47
- sendMode: {
48
- ASYNC_PUBLISH_SEASON: 'vibeiqfile'
49
- },
50
- itemPreDevelopmentLifecycleStages: ['concept'],
51
- identifierAtts: {
52
- LCSProduct: ['itemNumber'],
53
- LCSSeason: ['flexPLMSeasonName'],
54
- LCSSKU: ['itemNumber']
55
- },
56
- LCSMaterial: {
57
- processAsItem: false
58
- },
59
- csrfEndpoint: '/servlet/rest/security/csrf',
60
- vibeEventEndpoint: '/rfa/vibeiq/vibeEvents',
61
- payloadDefaultAsArray: true
62
- };
63
- }
64
-
65
- static async getConfigFile(fileId: string) {
66
- try {
67
-
68
- if(ConfigDefaults.STATIC_CONFIG_CACHE[fileId]){
69
- console.debug('returning cached config file: ' + fileId);
70
- return ConfigDefaults.STATIC_CONFIG_CACHE[fileId];
71
- }
72
- const options = {
73
- entityName: 'file',
74
- id: fileId,
75
- };
76
- const file = await new Entities().get(options);
77
- if (!file){
78
- console.log('failed to find file with id: ' + fileId);
79
- return {};
80
- }
81
- const downloadUrl = file['downloadUrl'];
82
-
83
- if(!downloadUrl){
84
- console.log('file didnt have downloadUrl. fileId: ' + fileId);
85
- return {};
86
- }
87
- const response = await fetch(downloadUrl);
88
- const config = await response.json();
89
- if(config){
90
- ConfigDefaults.STATIC_CONFIG_CACHE[fileId] = config;
91
- }
92
- return config ? config: {};
93
- }catch(e){
94
- console.log('Error getting config file: ' + fileId + '- ' +e.message);
95
- return {};
96
- }
97
- }
98
-
99
- static isPropertyTrue(value: any): boolean {
100
- return value === true || (typeof value === 'string' && value.toLowerCase() === 'true');
101
- }
102
-
103
- static clearConfigCache(){
104
- ConfigDefaults.STATIC_CONFIG_CACHE = {};
105
- }
106
- }