@contrail/flexplm 1.1.67-alpha.4 → 1.3.0-alpha.0

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 (89) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/package.json +1 -1
  3. package/scripts/output.png +0 -0
  4. package/scripts/test-get-request.ts +35 -0
  5. package/src/util/flexplm-connect.spec.ts +132 -0
  6. package/src/util/flexplm-connect.ts +14 -5
  7. package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
  8. package/src/util/type-conversion-utils.spec.ts +184 -0
  9. package/src/util/type-conversion-utils.ts +74 -0
  10. package/lib/entity-processor/base-entity-processor.d.ts +0 -42
  11. package/lib/entity-processor/base-entity-processor.js +0 -363
  12. package/lib/entity-processor/base-entity-processor.spec.d.ts +0 -1
  13. package/lib/entity-processor/base-entity-processor.spec.js +0 -302
  14. package/lib/flexplm-request.d.ts +0 -3
  15. package/lib/flexplm-request.js +0 -34
  16. package/lib/flexplm-utils.d.ts +0 -5
  17. package/lib/flexplm-utils.js +0 -33
  18. package/lib/flexplm-utils.spec.d.ts +0 -1
  19. package/lib/flexplm-utils.spec.js +0 -26
  20. package/lib/index.d.ts +0 -22
  21. package/lib/index.js +0 -38
  22. package/lib/interfaces/interfaces.d.ts +0 -105
  23. package/lib/interfaces/interfaces.js +0 -2
  24. package/lib/interfaces/item-family-changes.d.ts +0 -20
  25. package/lib/interfaces/item-family-changes.js +0 -56
  26. package/lib/interfaces/publish-change-data.d.ts +0 -19
  27. package/lib/interfaces/publish-change-data.js +0 -32
  28. package/lib/publish/base-process-publish-assortment-callback.d.ts +0 -9
  29. package/lib/publish/base-process-publish-assortment-callback.js +0 -38
  30. package/lib/publish/base-process-publish-assortment.d.ts +0 -93
  31. package/lib/publish/base-process-publish-assortment.js +0 -944
  32. package/lib/publish/base-process-publish-assortment.spec.d.ts +0 -1
  33. package/lib/publish/base-process-publish-assortment.spec.js +0 -1670
  34. package/lib/publish/mockData.d.ts +0 -1389
  35. package/lib/publish/mockData.js +0 -4519
  36. package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
  37. package/lib/transform/identifier-conversion-spec-mockData.js +0 -444
  38. package/lib/transform/identifier-conversion.d.ts +0 -15
  39. package/lib/transform/identifier-conversion.js +0 -212
  40. package/lib/transform/identifier-conversion.spec.d.ts +0 -1
  41. package/lib/transform/identifier-conversion.spec.js +0 -339
  42. package/lib/util/config-defaults.d.ts +0 -8
  43. package/lib/util/config-defaults.js +0 -85
  44. package/lib/util/config-defaults.spec.d.ts +0 -1
  45. package/lib/util/config-defaults.spec.js +0 -293
  46. package/lib/util/data-converter-spec-mockData.d.ts +0 -0
  47. package/lib/util/data-converter-spec-mockData.js +0 -205
  48. package/lib/util/data-converter.d.ts +0 -39
  49. package/lib/util/data-converter.js +0 -592
  50. package/lib/util/data-converter.spec.d.ts +0 -1
  51. package/lib/util/data-converter.spec.js +0 -904
  52. package/lib/util/error-response-object.d.ts +0 -4
  53. package/lib/util/error-response-object.js +0 -47
  54. package/lib/util/error-response-object.spec.d.ts +0 -1
  55. package/lib/util/error-response-object.spec.js +0 -99
  56. package/lib/util/event-short-message-status.d.ts +0 -18
  57. package/lib/util/event-short-message-status.js +0 -22
  58. package/lib/util/federation.d.ts +0 -15
  59. package/lib/util/federation.js +0 -149
  60. package/lib/util/flexplm-connect.d.ts +0 -18
  61. package/lib/util/flexplm-connect.js +0 -171
  62. package/lib/util/logger-config.d.ts +0 -1
  63. package/lib/util/logger-config.js +0 -26
  64. package/lib/util/map-util-spec-mockData.d.ts +0 -0
  65. package/lib/util/map-util-spec-mockData.js +0 -205
  66. package/lib/util/map-utils.d.ts +0 -6
  67. package/lib/util/map-utils.js +0 -15
  68. package/lib/util/map-utils.spec.d.ts +0 -1
  69. package/lib/util/map-utils.spec.js +0 -89
  70. package/lib/util/mockData.d.ts +0 -79
  71. package/lib/util/mockData.js +0 -99
  72. package/lib/util/thumbnail-util.d.ts +0 -19
  73. package/lib/util/thumbnail-util.js +0 -114
  74. package/lib/util/thumbnail-util.spec.d.ts +0 -1
  75. package/lib/util/thumbnail-util.spec.js +0 -242
  76. package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
  77. package/lib/util/type-conversion-utils-spec-mockData.js +0 -241
  78. package/lib/util/type-conversion-utils.d.ts +0 -21
  79. package/lib/util/type-conversion-utils.js +0 -223
  80. package/lib/util/type-conversion-utils.spec.d.ts +0 -1
  81. package/lib/util/type-conversion-utils.spec.js +0 -708
  82. package/lib/util/type-defaults.d.ts +0 -16
  83. package/lib/util/type-defaults.js +0 -221
  84. package/lib/util/type-defaults.spec.d.ts +0 -1
  85. package/lib/util/type-defaults.spec.js +0 -516
  86. package/lib/util/type-utils.d.ts +0 -13
  87. package/lib/util/type-utils.js +0 -114
  88. package/lib/util/type-utils.spec.d.ts +0 -1
  89. package/lib/util/type-utils.spec.js +0 -190
@@ -1,4 +0,0 @@
1
- import { AppActionCallBack } from "@contrail/app-framework";
2
- export declare class ErrorResponseObject {
3
- static getResponse(e: any): AppActionCallBack;
4
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ErrorResponseObject = void 0;
4
- const app_framework_1 = require("@contrail/app-framework");
5
- class ErrorResponseObject {
6
- static getResponse(e) {
7
- if (!e) {
8
- const response = {
9
- status: app_framework_1.AppActionCallbackStatus.FAILURE,
10
- output: {
11
- message: 'No error provided.'
12
- }
13
- };
14
- return response;
15
- }
16
- const response = {
17
- status: app_framework_1.AppActionCallbackStatus.FAILURE,
18
- output: {
19
- message: e.message
20
- }
21
- };
22
- const output = response.output;
23
- if (e.details)
24
- output.errorDetails = e.details;
25
- if (e.code)
26
- output.code = e.code;
27
- if (e.errno)
28
- output.errno = e.errno;
29
- if (e.type)
30
- output.type = e.type;
31
- if (e.name)
32
- output.errorName = e.name;
33
- if (e.cause) {
34
- output.cause = {};
35
- const cause = output.cause;
36
- if (e.cause.code)
37
- cause.code = e.cause.code;
38
- if (e.cause.message)
39
- cause.message = e.cause.message;
40
- }
41
- if (e.stack) {
42
- console.log('ErrorResponseObject.getResponse stack: ' + e.stack);
43
- }
44
- return response;
45
- }
46
- }
47
- exports.ErrorResponseObject = ErrorResponseObject;
@@ -1 +0,0 @@
1
- export {};
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_framework_1 = require("@contrail/app-framework");
4
- const error_response_object_1 = require("./error-response-object");
5
- describe('getResponse() Tests', () => {
6
- it('no error provided', () => {
7
- const e = undefined;
8
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
9
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
10
- expect(response?.output?.message).toMatch('No error provided');
11
- });
12
- it('error with message', () => {
13
- const e = {
14
- message: 'Test'
15
- };
16
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
17
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
18
- expect(response?.output?.message).toMatch('Test');
19
- });
20
- it('error with details', () => {
21
- const details = {
22
- message: 'Detail Message',
23
- itemType: [
24
- {
25
- message: "Type 'item:product:newBalance:apparel' cannot be assigned to a property with type 'item'."
26
- }
27
- ]
28
- };
29
- const e = {
30
- message: 'Test',
31
- details
32
- };
33
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
34
- expect(response).toBeTruthy();
35
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
36
- expect(response.output.message).toMatch('Test');
37
- const errorDetails = response.output.errorDetails;
38
- expect(errorDetails).toBeTruthy();
39
- expect(errorDetails.message).toMatch('Detail Message');
40
- expect(errorDetails).toHaveProperty('itemType');
41
- });
42
- it('error with cause', () => {
43
- const cause = {
44
- code: 401,
45
- message: 'cause message'
46
- };
47
- const e = {
48
- message: 'Test',
49
- cause
50
- };
51
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
52
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
53
- expect(response?.output?.message).toMatch('Test');
54
- const resCause = response.output.cause;
55
- expect(resCause).toBeTruthy();
56
- expect(resCause.code).toBe(401);
57
- expect(resCause.message).toMatch('cause message');
58
- });
59
- it('error with code', () => {
60
- const e = {
61
- message: 'Test',
62
- code: 404
63
- };
64
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
65
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
66
- expect(response?.output?.message).toMatch('Test');
67
- expect(response.output.code).toBe(404);
68
- });
69
- it('error with code', () => {
70
- const e = {
71
- message: 'Test',
72
- name: 'Error'
73
- };
74
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
75
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
76
- expect(response?.output?.message).toMatch('Test');
77
- expect(response.output.errorName).toMatch('Error');
78
- });
79
- it('error with errno', () => {
80
- const e = {
81
- message: 'Test',
82
- errno: 500
83
- };
84
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
85
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
86
- expect(response?.output?.message).toMatch('Test');
87
- expect(response.output.errno).toBe(500);
88
- });
89
- it('error with type', () => {
90
- const e = {
91
- message: 'Test',
92
- type: 'system'
93
- };
94
- const response = error_response_object_1.ErrorResponseObject.getResponse(e);
95
- expect(response.status).toMatch(app_framework_1.AppActionCallbackStatus.FAILURE);
96
- expect(response?.output?.message).toMatch('Test');
97
- expect(response.output.type).toMatch('system');
98
- });
99
- });
@@ -1,18 +0,0 @@
1
- export declare enum EventShortMessageStatus {
2
- SUCCESS = "Success",
3
- FAILURE = "Failure",
4
- CREATED = "Created",
5
- ITEM_FAMILY_ID_MISSING = "Item_family_id_missing",
6
- ITEM_FAMILY_NOT_FOUND = "Item_family_not_found",
7
- PROJECT_ITEM_NOT_FOUND = "Project_item_not_found",
8
- MISSING_IDENTIFIER_PROPERTIES = "Missing_identifier_properties",
9
- MISSING_INPUT = "Missing_input",
10
- NOT_CREATABLE = "Not_creatable",
11
- NO_CHANGES = "No_Changes",
12
- TOO_MANY_ENTITIES_FOUND = "Too_Many_Entities_Found",
13
- UPDATED = "Updated",
14
- NOT_PUBLISHABLE = "Not_Publishable",
15
- NO_FEDERATION_INFO = "No_Federation_Information",
16
- NO_EVENTS_TO_SEND = "No_Events_to_Send",
17
- SENDING_EVENTS = "Sending_Events"
18
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventShortMessageStatus = void 0;
4
- var EventShortMessageStatus;
5
- (function (EventShortMessageStatus) {
6
- EventShortMessageStatus["SUCCESS"] = "Success";
7
- EventShortMessageStatus["FAILURE"] = "Failure";
8
- EventShortMessageStatus["CREATED"] = "Created";
9
- EventShortMessageStatus["ITEM_FAMILY_ID_MISSING"] = "Item_family_id_missing";
10
- EventShortMessageStatus["ITEM_FAMILY_NOT_FOUND"] = "Item_family_not_found";
11
- EventShortMessageStatus["PROJECT_ITEM_NOT_FOUND"] = "Project_item_not_found";
12
- EventShortMessageStatus["MISSING_IDENTIFIER_PROPERTIES"] = "Missing_identifier_properties";
13
- EventShortMessageStatus["MISSING_INPUT"] = "Missing_input";
14
- EventShortMessageStatus["NOT_CREATABLE"] = "Not_creatable";
15
- EventShortMessageStatus["NO_CHANGES"] = "No_Changes";
16
- EventShortMessageStatus["TOO_MANY_ENTITIES_FOUND"] = "Too_Many_Entities_Found";
17
- EventShortMessageStatus["UPDATED"] = "Updated";
18
- EventShortMessageStatus["NOT_PUBLISHABLE"] = "Not_Publishable";
19
- EventShortMessageStatus["NO_FEDERATION_INFO"] = "No_Federation_Information";
20
- EventShortMessageStatus["NO_EVENTS_TO_SEND"] = "No_Events_to_Send";
21
- EventShortMessageStatus["SENDING_EVENTS"] = "Sending_Events";
22
- })(EventShortMessageStatus = exports.EventShortMessageStatus || (exports.EventShortMessageStatus = {}));
@@ -1,15 +0,0 @@
1
- import { FederationRecord } from '../interfaces/interfaces';
2
- export declare class Federation {
3
- private CHUNK_SIZE;
4
- getFederatedMappedRefId(entityType: string, entityId: string): Promise<string>;
5
- createFederatedRecord(eventBody: any): Promise<any>;
6
- getFederationRecordFromMappedRefId(mappedRefId: string): Promise<FederationRecord>;
7
- static getEntityId(fedRecord: FederationRecord): {
8
- entityType: string;
9
- entityId: string;
10
- };
11
- getEntityFromMappedRefId(mappedRefId: string): Promise<any>;
12
- getFederationRecordsFromIds(ids: string[]): Promise<FederationRecord[]>;
13
- getFederationRecordsFromIdsBulk(ids: string[]): Promise<FederationRecord[]>;
14
- splitIntoChunksByLen(arr: any, len: any): any[];
15
- }
@@ -1,149 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Federation = void 0;
7
- const sdk_1 = require("@contrail/sdk");
8
- const p_limit_1 = __importDefault(require("p-limit"));
9
- const limit = (0, p_limit_1.default)(30);
10
- const FED_CONFIG = {
11
- appIdentifier: '@vibeiq/flexplm-connector',
12
- federationSchema: 'DEFAULT'
13
- };
14
- class Federation {
15
- constructor() {
16
- this.CHUNK_SIZE = 50;
17
- }
18
- async getFederatedMappedRefId(entityType, entityId) {
19
- const criteria = {
20
- reference: entityType + ':' + entityId,
21
- appIdentifier: FED_CONFIG.appIdentifier,
22
- federationSchema: FED_CONFIG.federationSchema
23
- };
24
- console.log('getFederatedMappedRefId: ' + JSON.stringify(criteria));
25
- const fedRecords = await new sdk_1.Entities().get({
26
- entityName: 'federation',
27
- criteria
28
- });
29
- const federatedId = (fedRecords[0])
30
- ? fedRecords[0]['mappedReference']
31
- : '';
32
- return federatedId;
33
- }
34
- async createFederatedRecord(eventBody) {
35
- const itemResults = eventBody.payload;
36
- for (let i = 0; i < itemResults.length; i++) {
37
- if (!itemResults[i].federatedId) {
38
- continue;
39
- }
40
- const payload = {
41
- appIdentifier: FED_CONFIG.appIdentifier,
42
- reference: itemResults[i].entityReference,
43
- mappedReference: itemResults[i].federatedId,
44
- federationSchema: FED_CONFIG.federationSchema
45
- };
46
- try {
47
- const results = await new sdk_1.Entities().create({ entityName: 'federation', object: payload });
48
- return results;
49
- }
50
- catch (error) {
51
- console.log('createFederatedRecord-error: ', error);
52
- throw new Error('Error creating federation record: ' + error.message);
53
- }
54
- }
55
- }
56
- async getFederationRecordFromMappedRefId(mappedRefId) {
57
- const criteria = {
58
- appIdentifier: FED_CONFIG.appIdentifier,
59
- mappedReference: mappedRefId,
60
- federationSchema: FED_CONFIG.federationSchema
61
- };
62
- try {
63
- const fedRecords = await new sdk_1.Entities().get({
64
- entityName: 'federation',
65
- criteria
66
- });
67
- return (fedRecords && fedRecords[0]) ? fedRecords[0] : undefined;
68
- }
69
- catch (e) {
70
- console.log('getFederationData-error: ' + e.message);
71
- }
72
- return undefined;
73
- }
74
- static getEntityId(fedRecord) {
75
- const entityString = fedRecord['reference'];
76
- const entitySplit = entityString.split(':');
77
- const entityType = entitySplit[0];
78
- const entityId = entitySplit[1];
79
- return { entityType, entityId };
80
- }
81
- async getEntityFromMappedRefId(mappedRefId) {
82
- const fedRecord = await this.getFederationRecordFromMappedRefId(mappedRefId);
83
- console.log('fedRecord: ' + JSON.stringify(fedRecord));
84
- if (!fedRecord) {
85
- console.log('Federation Record doesnt exist. Cant get entity!');
86
- return;
87
- }
88
- const { entityType, entityId } = Federation.getEntityId(fedRecord);
89
- const criteria = {
90
- id: entityId
91
- };
92
- const entities = await new sdk_1.Entities().get({
93
- entityName: entityType,
94
- criteria
95
- });
96
- const entity = (entities && entities[0]) ? entities[0] : undefined;
97
- return entity;
98
- }
99
- async getFederationRecordsFromIds(ids) {
100
- const fedRecords = [];
101
- for (let i = 0; i < ids.length; i++) {
102
- const criteria = {
103
- reference: ids[i],
104
- appIdentifier: FED_CONFIG.appIdentifier,
105
- federationSchema: FED_CONFIG.federationSchema
106
- };
107
- const recs = await new sdk_1.Entities().get({
108
- entityName: 'federation',
109
- criteria
110
- });
111
- if (recs[0]) {
112
- fedRecords.push(recs[0]);
113
- }
114
- }
115
- return fedRecords;
116
- }
117
- async getFederationRecordsFromIdsBulk(ids) {
118
- const chunks = this.splitIntoChunksByLen(ids, this.CHUNK_SIZE);
119
- const fedRecords = [];
120
- const federatedPromises = [];
121
- const entities = new sdk_1.Entities();
122
- for (const chunk of chunks) {
123
- const fedPromise = limit(async () => {
124
- const criteria = {
125
- references: chunk,
126
- appIdentifier: FED_CONFIG.appIdentifier,
127
- federationSchema: FED_CONFIG.federationSchema
128
- };
129
- const records = await entities.get({
130
- entityName: 'federation',
131
- criteria
132
- });
133
- fedRecords.push(...records);
134
- });
135
- federatedPromises.push(fedPromise);
136
- }
137
- await Promise.all(federatedPromises);
138
- return fedRecords;
139
- }
140
- splitIntoChunksByLen(arr, len) {
141
- const chunks = [], n = arr?.length;
142
- let i = 0;
143
- while (i < n) {
144
- chunks.push(arr.slice(i, i += len));
145
- }
146
- return chunks;
147
- }
148
- }
149
- exports.Federation = Federation;
@@ -1,18 +0,0 @@
1
- import { FCConfig, FlexPLMResponseData, PayloadType } from '../interfaces/interfaces';
2
- export declare class FlexPLMConnect {
3
- private config;
4
- private vibeEventEndpoint;
5
- private staticHeaders;
6
- payloadSendAsArray: boolean;
7
- constructor(_config: FCConfig, endPoint?: any, payloadAsArray?: any);
8
- private getRequestOptions;
9
- getCSRF(): Promise<{
10
- nonce_key: any;
11
- nonce: any;
12
- }>;
13
- sendRequest(csrf: any, payload: any): Promise<Response>;
14
- protected processRequest(payload: any): Promise<FlexPLMResponseData>;
15
- sendToFlexPLM(payload: PayloadType): Promise<FlexPLMResponseData>;
16
- sendMultipleToFlexPLM(payload: PayloadType[]): Promise<FlexPLMResponseData>;
17
- getRequest(): Promise<any>;
18
- }
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlexPLMConnect = void 0;
4
- const app_framework_1 = require("@contrail/app-framework");
5
- class FlexPLMConnect {
6
- constructor(_config, endPoint = undefined, payloadAsArray = undefined) {
7
- this.vibeEventEndpoint = '';
8
- this.staticHeaders = undefined;
9
- this.payloadSendAsArray = true;
10
- this.config = _config;
11
- this.vibeEventEndpoint = (endPoint)
12
- ? endPoint
13
- : this.config.vibeEventEndpoint;
14
- this.payloadSendAsArray = (payloadAsArray != undefined)
15
- ? payloadAsArray
16
- : this.config['payloadDefaultAsArray'];
17
- if (this.config?.flexplmConnect?.staticHeaders) {
18
- this.staticHeaders = this.config?.flexplmConnect?.staticHeaders;
19
- }
20
- }
21
- getRequestOptions(method) {
22
- const csrfOptions = {
23
- method,
24
- headers: {
25
- 'Content-Type': 'application/json',
26
- PLM_ENV: this.config.plmEnviornment,
27
- Authorization: 'Basic ' + Buffer.from(`${this.config.userName()}:${this.config.password()}`, 'binary').toString('base64')
28
- }
29
- };
30
- if (this.staticHeaders) {
31
- Object.assign(csrfOptions.headers, this.staticHeaders);
32
- }
33
- if (app_framework_1.Logger.isInfoOn()) {
34
- const logOptions = JSON.parse(JSON.stringify(csrfOptions));
35
- logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
36
- console.info('csrfOptions: ' + JSON.stringify(logOptions));
37
- }
38
- return csrfOptions;
39
- }
40
- async getCSRF() {
41
- const urlContext = this.config.urlContext;
42
- const csrfEndpoint = this.config.csrfEndpoint;
43
- const csrfURL = this.config.apiHost + urlContext + csrfEndpoint;
44
- console.info('csrfURL: ' + csrfURL);
45
- const csrfOptions = this.getRequestOptions('GET');
46
- const response = await fetch(csrfURL, csrfOptions);
47
- if (response.status >= 300) {
48
- const message = 'Error connecting to FlexPLM:status: ' + response.status;
49
- console.error(message);
50
- console.error(await response.text());
51
- const e = new Error(message);
52
- e['httpResponseStatus'] = response.status;
53
- throw e;
54
- }
55
- try {
56
- const body = await response.json();
57
- const nonce_key = body.items[0].attributes.nonce_key;
58
- const nonce = body.items[0].attributes.nonce;
59
- console.info('nonce_key: ' + nonce_key);
60
- console.info('nonce: ' + nonce);
61
- return {
62
- nonce_key,
63
- nonce
64
- };
65
- }
66
- catch (e) {
67
- const message = 'Error connecting to FlexPLM: ' + e.message;
68
- console.error(message);
69
- console.error(await response.text());
70
- throw new Error(message);
71
- }
72
- }
73
- async sendRequest(csrf, payload) {
74
- if (this.payloadSendAsArray && !Array.isArray(payload)) {
75
- payload = [payload];
76
- }
77
- const xferOptions = this.getRequestOptions('POST');
78
- xferOptions['body'] = JSON.stringify(payload);
79
- xferOptions.headers[csrf.nonce_key] = csrf.nonce;
80
- const urlContext = this.config.urlContext;
81
- const vibeEventsURL = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
82
- if (app_framework_1.Logger.isInfoOn()) {
83
- console.info('Request:');
84
- console.info('vibeEventsURL: ' + vibeEventsURL);
85
- const logOptions = JSON.parse(JSON.stringify(xferOptions));
86
- logOptions['headers']['Authorization'] = logOptions?.headers?.Authorization.substring(0, 9);
87
- console.info('csrfOptions: ' + JSON.stringify(logOptions));
88
- console.info('Making call to xfer data to FlexPLM');
89
- }
90
- const eventResponse = await fetch(vibeEventsURL, xferOptions);
91
- return eventResponse;
92
- }
93
- async processRequest(payload) {
94
- if (!payload) {
95
- const message = 'No payload to send to FlexPLM';
96
- console.error(message);
97
- throw new Error(message);
98
- }
99
- if (app_framework_1.Logger.isInfoOn()) {
100
- console.info('payload: ' + JSON.stringify(payload));
101
- }
102
- const csrf = await this.getCSRF();
103
- if (!csrf) {
104
- const message = 'Failed to get CSRF nonce';
105
- console.error(message);
106
- throw new Error(message);
107
- }
108
- const response = await this.sendRequest(csrf, payload);
109
- const status = response.status;
110
- if (status >= 300) {
111
- const message = 'Error sending data to FlexPLM:status: ' + response.status;
112
- console.error(message);
113
- console.error(await response.text());
114
- const e = new Error(message);
115
- e['httpResponseStatus'] = status;
116
- throw e;
117
- }
118
- try {
119
- const res = {
120
- status,
121
- };
122
- if (![204, 205].includes(status)) {
123
- try {
124
- const data = await response.json();
125
- res.data = data;
126
- }
127
- catch (e) {
128
- console.error('Error getting response body. Setting {} body: ' + e);
129
- res.data = {};
130
- }
131
- }
132
- console.log('eventResponse.status: ' + status);
133
- return res;
134
- }
135
- catch (e) {
136
- const message = 'Error getting json data from FlexPLM: ' + e.message;
137
- console.error(message);
138
- console.error(await response.text());
139
- throw new Error(message);
140
- }
141
- }
142
- async sendToFlexPLM(payload) {
143
- return await this.processRequest(payload);
144
- }
145
- async sendMultipleToFlexPLM(payload) {
146
- return await this.processRequest(payload);
147
- }
148
- async getRequest() {
149
- const urlContext = this.config.urlContext;
150
- const vibeEventsURL = this.config.apiHost + urlContext + '/servlet/rest' + this.vibeEventEndpoint;
151
- const csrfOptions = this.getRequestOptions('GET');
152
- const response = await fetch(vibeEventsURL, csrfOptions);
153
- if (response.status >= 300) {
154
- const message = 'Error connecting to FlexPLM:status: ' + response.status;
155
- console.error(message);
156
- console.error(await response.text());
157
- throw new Error(message);
158
- }
159
- try {
160
- const data = await response.json();
161
- return data;
162
- }
163
- catch (e) {
164
- const message = 'Error getting json data from FlexPLM: ' + e.message;
165
- console.error(message);
166
- console.error(await response.text());
167
- throw new Error(message);
168
- }
169
- }
170
- }
171
- exports.FlexPLMConnect = FlexPLMConnect;
@@ -1 +0,0 @@
1
- export declare function setLoggerConfig(appConfig: any): Promise<void>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setLoggerConfig = void 0;
4
- const app_framework_1 = require("@contrail/app-framework");
5
- async function setLoggerConfig(appConfig) {
6
- let logLevel = app_framework_1.LogLevel.INFO;
7
- if (!appConfig.logLevel) {
8
- }
9
- else if (appConfig.logLevel === 'error') {
10
- logLevel = app_framework_1.LogLevel.ERROR;
11
- }
12
- else if (appConfig.logLevel === 'warn') {
13
- logLevel = app_framework_1.LogLevel.WARN;
14
- }
15
- else if (appConfig.logLevel === 'info') {
16
- logLevel = app_framework_1.LogLevel.INFO;
17
- }
18
- else if (appConfig.logLevel === 'debug') {
19
- logLevel = app_framework_1.LogLevel.DEBUG;
20
- }
21
- else {
22
- console.log('could not parse log level:', appConfig);
23
- }
24
- app_framework_1.Logger.setConfig({ logLevel: logLevel });
25
- }
26
- exports.setLoggerConfig = setLoggerConfig;
File without changes