@contrail/flexplm 1.1.29 → 1.1.31

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/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './flexplm-request';
2
2
  export * from './flexplm-utils';
3
3
  export * from './util/config-defaults';
4
4
  export * from './util/data-converter';
5
+ export * from './util/error-response-object';
5
6
  export * from './util/federation';
6
7
  export * from './util/flexplm-connect';
7
8
  export * from './interfaces/interfaces';
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ __exportStar(require("./flexplm-request"), exports);
18
18
  __exportStar(require("./flexplm-utils"), exports);
19
19
  __exportStar(require("./util/config-defaults"), exports);
20
20
  __exportStar(require("./util/data-converter"), exports);
21
+ __exportStar(require("./util/error-response-object"), exports);
21
22
  __exportStar(require("./util/federation"), exports);
22
23
  __exportStar(require("./util/flexplm-connect"), exports);
23
24
  __exportStar(require("./interfaces/interfaces"), exports);
@@ -12,15 +12,17 @@ class BaseProcessPublishAssortmentCallback {
12
12
  console.log("ProcessPublishAssortmentCallback-config: " + JSON.stringify(this.config));
13
13
  const statusCounts = this.config["statusCounts"];
14
14
  console.log("statusCounts: " + JSON.stringify(statusCounts));
15
- this.checkFailuresAndSendNotification(event);
15
+ const statMessage = (statusCounts)
16
+ ? await this.checkFailuresAndSendNotification(event)
17
+ : 'no statusCount';
16
18
  return {
17
- message: "Done ProcessPublishAssortmentCallback-process()",
19
+ message: "Done ProcessPublishAssortmentCallback-process(): " + statMessage,
18
20
  };
19
21
  }
20
- checkFailuresAndSendNotification(event) {
22
+ async checkFailuresAndSendNotification(event) {
21
23
  const statusCounts = JSON.parse(this.config["statusCounts"]);
22
24
  if (statusCounts["INVALID"] > 0 || statusCounts["FAILURE"] > 0) {
23
- new sdk_1.Notification().Dispatch({
25
+ await new sdk_1.Notification().Dispatch({
24
26
  message: `There were errors when publishing the season data. Please review the event and config information from context.`,
25
27
  level: sdk_1.LogLevel.WARN,
26
28
  context: {
@@ -28,7 +30,9 @@ class BaseProcessPublishAssortmentCallback {
28
30
  config: this.config,
29
31
  },
30
32
  });
33
+ return 'sent notification';
31
34
  }
35
+ return 'no notification needed';
32
36
  }
33
37
  }
34
38
  exports.BaseProcessPublishAssortmentCallback = BaseProcessPublishAssortmentCallback;
@@ -6,9 +6,12 @@ export declare class DataConverter {
6
6
  private typeUtils;
7
7
  private transformMapFile;
8
8
  private useDisplayForEnumerationMatching;
9
+ private verboseDebug;
9
10
  private objRefCache;
10
11
  private userRefCache;
11
12
  constructor(config: FCConfig, mapFileUtil: MapFileUtil);
13
+ setVerboseDebug(val?: boolean): void;
14
+ isVerboseDebugOn(): boolean;
12
15
  getFlexPLMObjectDataFromEvent(event: any, dataToSkip: string[]): Promise<{}>;
13
16
  getFlexPLMObjectData(newData: any, dataToSkip: string[], inflateObjRef: boolean): Promise<{}>;
14
17
  getFlexPLMValue(prop: any, newData: any, inflateObjRef: boolean): Promise<any>;
@@ -12,18 +12,27 @@ class DataConverter {
12
12
  this.config = config;
13
13
  this.mapFileUtil = mapFileUtil;
14
14
  this.useDisplayForEnumerationMatching = false;
15
+ this.verboseDebug = false;
15
16
  this.objRefCache = {};
16
17
  this.userRefCache = {};
17
18
  this.typeUtils = new type_utils_1.TypeUtils();
18
19
  this.transformMapFile = this.config['transformMapFile'];
19
20
  this.useDisplayForEnumerationMatching = this.config['dataConverter']
20
21
  && this.config['dataConverter']['useDisplayForEnumerationMatching'];
22
+ this.verboseDebug = this.config['dataConverter']
23
+ && this.config['dataConverter']['verboseDebug'];
24
+ }
25
+ setVerboseDebug(val = false) {
26
+ this.verboseDebug = val;
27
+ }
28
+ isVerboseDebugOn() {
29
+ return this.verboseDebug && app_framework_1.Logger.isDebugOn();
21
30
  }
22
31
  async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
23
32
  return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
24
33
  }
25
34
  async getFlexPLMObjectData(newData, dataToSkip, inflateObjRef) {
26
- if (app_framework_1.Logger.isDebugOn()) {
35
+ if (this.isVerboseDebugOn()) {
27
36
  console.debug('newData: ' + JSON.stringify(newData));
28
37
  }
29
38
  dataToSkip = dataToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
@@ -42,7 +51,7 @@ class DataConverter {
42
51
  }
43
52
  data[slug] = await this.getFlexPLMValue(prop, newData, inflateObjRef);
44
53
  }
45
- if (app_framework_1.Logger.isDebugOn()) {
54
+ if (this.isVerboseDebugOn()) {
46
55
  console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
47
56
  }
48
57
  return data;
@@ -77,7 +86,7 @@ class DataConverter {
77
86
  }
78
87
  else if ('object_reference' === propertyType) {
79
88
  value = await this.getObjectReferenceValue(prop, newData, inflateObjRef);
80
- if (app_framework_1.Logger.isDebugOn()) {
89
+ if (this.isVerboseDebugOn()) {
81
90
  console.debug('object_reference: ' + JSON.stringify(value));
82
91
  }
83
92
  }
@@ -0,0 +1,4 @@
1
+ import { AppActionCallBack } from "@contrail/app-framework";
2
+ export declare class ErrorResponseObject {
3
+ static getResponse(e: any): AppActionCallBack;
4
+ }
@@ -0,0 +1,47 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,99 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.29",
3
+ "version": "1.1.31",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './flexplm-request';
2
2
  export * from './flexplm-utils';
3
3
  export * from './util/config-defaults';
4
4
  export * from './util/data-converter';
5
+ export * from './util/error-response-object';
5
6
  export * from './util/federation';
6
7
  export * from './util/flexplm-connect';
7
8
  export * from './interfaces/interfaces';
@@ -21,18 +21,20 @@ export class BaseProcessPublishAssortmentCallback {
21
21
  const statusCounts = this.config["statusCounts"];
22
22
  console.log("statusCounts: " + JSON.stringify(statusCounts));
23
23
 
24
- this.checkFailuresAndSendNotification(event);
24
+ const statMessage =(statusCounts)
25
+ ?await this.checkFailuresAndSendNotification(event)
26
+ :'no statusCount';
25
27
 
26
28
  return {
27
- message: "Done ProcessPublishAssortmentCallback-process()",
29
+ message: "Done ProcessPublishAssortmentCallback-process(): " + statMessage,
28
30
  };
29
31
  }
30
32
 
31
- private checkFailuresAndSendNotification(event) {
33
+ private async checkFailuresAndSendNotification(event): Promise<string> {
32
34
  const statusCounts = JSON.parse(this.config["statusCounts"]);
33
35
 
34
36
  if (statusCounts["INVALID"] > 0 || statusCounts["FAILURE"] > 0) {
35
- new Notification().Dispatch({
37
+ await new Notification().Dispatch({
36
38
  message: `There were errors when publishing the season data. Please review the event and config information from context.`,
37
39
  level: LogLevel.WARN,
38
40
  context: {
@@ -40,6 +42,9 @@ export class BaseProcessPublishAssortmentCallback {
40
42
  config: this.config,
41
43
  },
42
44
  });
45
+ return 'sent notification';
43
46
  }
47
+
48
+ return 'no notification needed';
44
49
  }
45
50
  }
@@ -11,6 +11,7 @@ export class DataConverter {
11
11
  private typeUtils: TypeUtils;
12
12
  private transformMapFile: string;
13
13
  private useDisplayForEnumerationMatching = false;
14
+ private verboseDebug = false;
14
15
  private objRefCache = {};
15
16
  private userRefCache = {};
16
17
  constructor(private config: FCConfig, private mapFileUtil: MapFileUtil){
@@ -18,6 +19,15 @@ export class DataConverter {
18
19
  this.transformMapFile = this.config['transformMapFile'];
19
20
  this.useDisplayForEnumerationMatching = this.config['dataConverter']
20
21
  && this.config['dataConverter']['useDisplayForEnumerationMatching'];
22
+ this.verboseDebug = this.config['dataConverter']
23
+ && this.config['dataConverter']['verboseDebug'];
24
+ }
25
+
26
+ public setVerboseDebug(val: boolean = false) {
27
+ this.verboseDebug= val;
28
+ }
29
+ public isVerboseDebugOn(): boolean {
30
+ return this.verboseDebug && Logger.isDebugOn();
21
31
  }
22
32
 
23
33
  async getFlexPLMObjectDataFromEvent(event, dataToSkip: string[]) {
@@ -25,7 +35,7 @@ export class DataConverter {
25
35
  }
26
36
 
27
37
  async getFlexPLMObjectData(newData, dataToSkip: string[], inflateObjRef: boolean) {
28
- if(Logger.isDebugOn()) {
38
+ if(this.isVerboseDebugOn()) {
29
39
  console.debug('newData: ' + JSON.stringify(newData));
30
40
  }
31
41
  //Using event to get propertyDiffs to find emptied values
@@ -51,7 +61,7 @@ export class DataConverter {
51
61
  data[slug] = await this.getFlexPLMValue(prop, newData, inflateObjRef);
52
62
  }
53
63
 
54
- if(Logger.isDebugOn()) {
64
+ if(this.isVerboseDebugOn()) {
55
65
  console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
56
66
  }
57
67
  return data;
@@ -86,7 +96,7 @@ export class DataConverter {
86
96
  value = this.getEnumerationValue(prop, nd);
87
97
  }else if('object_reference' === propertyType){
88
98
  value = await this.getObjectReferenceValue(prop, newData, inflateObjRef);
89
- if(Logger.isDebugOn()){
99
+ if(this.isVerboseDebugOn()){
90
100
  console.debug('object_reference: ' + JSON.stringify(value));
91
101
  }
92
102
  } else if ('image' === propertyType) {
@@ -0,0 +1,116 @@
1
+ import { AppActionCallbackStatus } from "@contrail/app-framework";
2
+ import { ErrorResponseObject } from "./error-response-object";
3
+
4
+ describe('getResponse() Tests', () =>{
5
+ it('no error provided', () => {
6
+ const e = undefined;
7
+
8
+ const response = ErrorResponseObject.getResponse(e);
9
+ expect(response.status).toMatch(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
+
17
+ const response = ErrorResponseObject.getResponse(e);
18
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
19
+ expect(response?.output?.message).toMatch('Test');
20
+ });
21
+
22
+ it('error with details', () => {
23
+ const details = {
24
+ message: 'Detail Message',
25
+ itemType: [
26
+ {
27
+ message: "Type 'item:product:newBalance:apparel' cannot be assigned to a property with type 'item'."
28
+ }]
29
+ };
30
+ const e = {
31
+ message: 'Test',
32
+ details
33
+
34
+ };
35
+
36
+ const response = ErrorResponseObject.getResponse(e);
37
+ expect(response).toBeTruthy();
38
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
39
+ expect(response.output.message).toMatch('Test');
40
+
41
+ const errorDetails = response.output.errorDetails;
42
+ expect(errorDetails).toBeTruthy();
43
+ expect(errorDetails.message).toMatch('Detail Message');
44
+ expect(errorDetails).toHaveProperty('itemType');
45
+ });
46
+
47
+ it('error with cause', () => {
48
+ const cause = {
49
+ code: 401,
50
+ message: 'cause message'
51
+ };
52
+ const e = {
53
+ message: 'Test',
54
+ cause
55
+ };
56
+
57
+ const response = ErrorResponseObject.getResponse(e);
58
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
59
+ expect(response?.output?.message).toMatch('Test');
60
+ const resCause = response.output.cause;
61
+
62
+ expect(resCause).toBeTruthy();
63
+ expect(resCause.code).toBe(401);
64
+ expect(resCause.message).toMatch('cause message');
65
+
66
+ });
67
+
68
+ it('error with code', () => {
69
+ const e = {
70
+ message: 'Test',
71
+ code: 404
72
+ };
73
+
74
+ const response = ErrorResponseObject.getResponse(e);
75
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
76
+ expect(response?.output?.message).toMatch('Test');
77
+ expect(response.output.code).toBe(404);
78
+ });
79
+
80
+ it('error with code', () => {
81
+ const e = {
82
+ message: 'Test',
83
+ name: 'Error'
84
+ };
85
+
86
+ const response = ErrorResponseObject.getResponse(e);
87
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
88
+ expect(response?.output?.message).toMatch('Test');
89
+ expect(response.output.errorName).toMatch('Error');
90
+ });
91
+
92
+ it('error with errno', () => {
93
+ const e = {
94
+ message: 'Test',
95
+ errno: 500
96
+ };
97
+
98
+ const response = ErrorResponseObject.getResponse(e);
99
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
100
+ expect(response?.output?.message).toMatch('Test');
101
+ expect(response.output.errno).toBe(500);
102
+ });
103
+
104
+ it('error with type', () => {
105
+ const e = {
106
+ message: 'Test',
107
+ type: 'system'
108
+ };
109
+
110
+ const response = ErrorResponseObject.getResponse(e);
111
+ expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
112
+ expect(response?.output?.message).toMatch('Test');
113
+ expect(response.output.type).toMatch('system');
114
+ });
115
+
116
+ });
@@ -0,0 +1,50 @@
1
+ import { AppActionCallBack, AppActionCallbackStatus } from "@contrail/app-framework";
2
+
3
+ export class ErrorResponseObject {
4
+
5
+ /** Returns a response, checking for multiple possible error details
6
+ *
7
+ * @param e
8
+ * @returns
9
+ */
10
+ public static getResponse(e): AppActionCallBack {
11
+ if(!e){
12
+ const response: AppActionCallBack = {
13
+ status: AppActionCallbackStatus.FAILURE,
14
+ output: {
15
+ message: 'No error provided.'
16
+ }
17
+ };
18
+ return response;
19
+ }
20
+
21
+ const response: AppActionCallBack = {
22
+ status: AppActionCallbackStatus.FAILURE,
23
+ output: {
24
+ message: e.message
25
+ }
26
+ };
27
+ const output = response.output;
28
+
29
+ //Errors when persisting in VibeIQ
30
+ if(e.details) output.errorDetails = e.details;
31
+
32
+ if(e.code) output.code = e.code;
33
+ if(e.errno) output.errno = e.errno;
34
+ if(e.type) output.type = e.type;
35
+ if(e.name) output.errorName = e.name;
36
+
37
+ //Has original cause
38
+ if(e.cause){
39
+ output.cause = {};
40
+ const cause = output.cause;
41
+ if(e.cause.code) cause.code = e.cause.code;
42
+ if(e.cause.message) cause.message = e.cause.message;
43
+ }
44
+
45
+ if(e.stack){
46
+ console.log('ErrorResponseObject.getResponse stack: ' + e.stack);
47
+ }
48
+ return response;
49
+ }
50
+ }
@@ -1,13 +0,0 @@
1
- import { AppActionCallbackStatus } from "@contrail/app-framework";
2
- import { ErrorResponseObject } from "./error-response-object";
3
-
4
- describe('getResponse() Tests', () =>{
5
- it('status set', () => {
6
- const e = {
7
- message: 'Test'
8
- };
9
-
10
- const response = ErrorResponseObject.getResponse(e);
11
- expect(response.status).toMatch(AppActionCallbackStatus.FAILURE);
12
- })
13
- });
@@ -1,38 +0,0 @@
1
- import { AppActionCallBack, AppActionCallbackStatus } from "@contrail/app-framework";
2
-
3
- export class ErrorResponseObject {
4
-
5
- /** Returns a response, checking for multiple possible error details
6
- *
7
- * @param e
8
- * @returns
9
- */
10
- public static getResponse(e): AppActionCallBack {
11
- const response: AppActionCallBack = {
12
- status: AppActionCallbackStatus.FAILURE,
13
- output: {
14
- message: e.message
15
- }
16
- };
17
- if(!e){
18
- return response;
19
- }
20
- const output = response.output;
21
-
22
- //Errors when persisting in VibeIQ
23
- if(e?.details){
24
- output.errorDetails = e.details;
25
- }
26
-
27
- //Has original cause
28
- if(e?.cause){
29
- const cause = {
30
- code: e.cause.code,
31
- message: e.cause.message,
32
- };
33
- output.cause = cause;
34
- }
35
-
36
- return response;
37
- }
38
- }