@things-factory/integration-base 4.3.729 → 4.3.738
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.
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.webhookHandler = void 0;
|
|
4
7
|
const webhook_1 = require("../webhook/webhook");
|
|
5
8
|
const typeorm_1 = require("typeorm");
|
|
6
9
|
const lambda_handler_1 = require("./lambda-handler");
|
|
10
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
11
|
+
const webhook_event_enums_1 = require("../webhook-event/webhook-event-enums");
|
|
12
|
+
const payload_log_mutation_1 = require("../payload-log/payload-log-mutation");
|
|
13
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
7
14
|
async function webhookHandler(data, bizplaces, event) {
|
|
8
15
|
//fetch the webhook
|
|
9
16
|
try {
|
|
@@ -45,6 +52,65 @@ async function webhookHandler(data, bizplaces, event) {
|
|
|
45
52
|
await (0, lambda_handler_1.lambdaService)('processWebhookEvent', data);
|
|
46
53
|
}
|
|
47
54
|
}
|
|
55
|
+
// IF ITS ORDER FROM POWRUP
|
|
56
|
+
if (data.source === auth_base_1.ApplicationType.POWRUP) {
|
|
57
|
+
const connection = (0, typeorm_1.getConnection)();
|
|
58
|
+
const powrup = await connection
|
|
59
|
+
.createQueryBuilder()
|
|
60
|
+
.select('p.id', 'id')
|
|
61
|
+
.addSelect('p."api_key"', 'apiKey')
|
|
62
|
+
.addSelect('p.staging', 'staging')
|
|
63
|
+
.from('powrups', 'p')
|
|
64
|
+
.where('p.platform = :platform', { platform: 'POWRUP' })
|
|
65
|
+
.andWhere('p.active = :active', { active: true })
|
|
66
|
+
.getRawOne();
|
|
67
|
+
if (powrup && (event === webhook_event_enums_1.WebhookEventsEnum.PickingStarted || event === webhook_event_enums_1.WebhookEventsEnum.LoadingStarted)) {
|
|
68
|
+
let status = '';
|
|
69
|
+
switch (event) {
|
|
70
|
+
case webhook_event_enums_1.WebhookEventsEnum.PickingStarted:
|
|
71
|
+
status = 'PICKING';
|
|
72
|
+
break;
|
|
73
|
+
case webhook_event_enums_1.WebhookEventsEnum.LoadingStarted:
|
|
74
|
+
status = 'LOADING';
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (!status) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let baseUrl = `https://api${powrup.staging ? '-test' : ''}.powrup.asia/api`;
|
|
83
|
+
const path = '/wms/update-order-status';
|
|
84
|
+
const fullPath = `${baseUrl}${path}`;
|
|
85
|
+
const payload = {
|
|
86
|
+
orderId: data.refOrderId,
|
|
87
|
+
status: status
|
|
88
|
+
};
|
|
89
|
+
const response = await (0, node_fetch_1.default)(fullPath, {
|
|
90
|
+
method: 'post',
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
'X-Authorization': powrup.apiKey
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify(payload)
|
|
96
|
+
});
|
|
97
|
+
if (response.ok) {
|
|
98
|
+
const result = await response.json();
|
|
99
|
+
if (result.code == 0) {
|
|
100
|
+
await (0, payload_log_mutation_1.createPayloadLog)(powrup.id, path, JSON.stringify(payload), JSON.stringify(result), { state: { domain: data.domain, user: null } });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const errorMessage = JSON.stringify(result);
|
|
104
|
+
await (0, payload_log_mutation_1.createPayloadLog)(powrup.id, path, JSON.stringify(payload), errorMessage, { state: { domain: data.domain, user: null } });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const errorText = await response.text();
|
|
109
|
+
const errorMessage = `(${response.status}) ${errorText}`;
|
|
110
|
+
await (0, payload_log_mutation_1.createPayloadLog)(powrup.id, path, JSON.stringify(payload), errorMessage, { state: { domain: data.domain, user: null } });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
48
114
|
}
|
|
49
115
|
catch (e) {
|
|
50
116
|
console.error(e.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-controller.js","sourceRoot":"","sources":["../../../server/service/webhook-handler/webhook-controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhook-controller.js","sourceRoot":"","sources":["../../../server/service/webhook-handler/webhook-controller.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA4C;AAC5C,qCAA0E;AAC1E,qDAAgD;AAChD,yDAA2D;AAC3D,8EAAwE;AACxE,8EAAsE;AACtE,4DAA8B;AAEvB,KAAK,UAAU,cAAc,CAAC,IAAS,EAAE,SAAyB,EAAE,KAAa;IACtF,mBAAmB;IACnB,IAAI;QACF,IAAI,EAAE,GAAgC,MAAM,IAAA,uBAAa,EAAC,iBAAO,CAAC;aAC/D,kBAAkB,CAAC,SAAS,CAAC;aAC7B,kBAAkB,CAAC,mBAAmB,EAAE,IAAI,CAAC;aAC7C,kBAAkB,CAAC,uBAAuB,EAAE,cAAc,CAAC;aAC3D,KAAK,CAAC,4BAA4B,EAAE,EAAE,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;aAC3G,QAAQ,CAAC,2BAA2B,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;aACtD,QAAQ,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QAEzD,IAAI,QAAQ,GAAG,MAAM,EAAE,CAAC,OAAO,EAAE,CAAA;QAEjC,iJAAiJ;QACjJ,IAAI,QAAQ,CAAC,MAAM,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AE,CAC/C,CAAA;iBACF;aACF;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;KACzB;AACH,CAAC;AA7HD,wCA6HC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.738",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@apollo/client": "^3.5.6",
|
|
28
28
|
"@aws-sdk/client-lambda": "3.913.0",
|
|
29
29
|
"@aws-sdk/client-sqs": "^3.46.0",
|
|
30
|
-
"@things-factory/api": "^4.3.
|
|
31
|
-
"@things-factory/auth-base": "^4.3.
|
|
32
|
-
"@things-factory/oauth2-client": "^4.3.
|
|
33
|
-
"@things-factory/shell": "^4.3.
|
|
30
|
+
"@things-factory/api": "^4.3.738",
|
|
31
|
+
"@things-factory/auth-base": "^4.3.738",
|
|
32
|
+
"@things-factory/oauth2-client": "^4.3.738",
|
|
33
|
+
"@things-factory/shell": "^4.3.738",
|
|
34
34
|
"async-mqtt": "^2.5.0",
|
|
35
35
|
"cron": "^1.7.2",
|
|
36
36
|
"cross-fetch": "^3.0.4",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"uuid": "11.0.0",
|
|
43
43
|
"vm2": "^3.9.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "4c0363d0c8fa24d07a827b9c884ad32755f3ee8c"
|
|
46
46
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Webhook } from '../webhook/webhook'
|
|
2
|
-
import { SelectQueryBuilder, getRepository } from 'typeorm'
|
|
2
|
+
import { SelectQueryBuilder, getRepository, getConnection } from 'typeorm'
|
|
3
3
|
import { lambdaService } from './lambda-handler'
|
|
4
|
+
import { ApplicationType } from '@things-factory/auth-base'
|
|
5
|
+
import { WebhookEventsEnum } from '../webhook-event/webhook-event-enums'
|
|
6
|
+
import { createPayloadLog } from '../payload-log/payload-log-mutation'
|
|
7
|
+
import fetch from 'node-fetch'
|
|
4
8
|
|
|
5
9
|
export async function webhookHandler(data: any, bizplaces: any | string[], event: String) {
|
|
6
10
|
//fetch the webhook
|
|
@@ -44,6 +48,86 @@ export async function webhookHandler(data: any, bizplaces: any | string[], event
|
|
|
44
48
|
await lambdaService('processWebhookEvent', data)
|
|
45
49
|
}
|
|
46
50
|
}
|
|
51
|
+
|
|
52
|
+
// IF ITS ORDER FROM POWRUP
|
|
53
|
+
if (data.source === ApplicationType.POWRUP) {
|
|
54
|
+
const connection = getConnection()
|
|
55
|
+
const powrup: any = await connection
|
|
56
|
+
.createQueryBuilder()
|
|
57
|
+
.select('p.id', 'id')
|
|
58
|
+
.addSelect('p."api_key"', 'apiKey')
|
|
59
|
+
.addSelect('p.staging', 'staging')
|
|
60
|
+
.from('powrups', 'p')
|
|
61
|
+
.where('p.platform = :platform', { platform: 'POWRUP' })
|
|
62
|
+
.andWhere('p.active = :active', { active: true })
|
|
63
|
+
.getRawOne()
|
|
64
|
+
|
|
65
|
+
if (powrup && (event === WebhookEventsEnum.PickingStarted || event === WebhookEventsEnum.LoadingStarted)) {
|
|
66
|
+
let status = ''
|
|
67
|
+
switch (event) {
|
|
68
|
+
case WebhookEventsEnum.PickingStarted:
|
|
69
|
+
status = 'PICKING'
|
|
70
|
+
break
|
|
71
|
+
case WebhookEventsEnum.LoadingStarted:
|
|
72
|
+
status = 'LOADING'
|
|
73
|
+
break
|
|
74
|
+
default:
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!status) { return }
|
|
79
|
+
|
|
80
|
+
let baseUrl = `https://api${powrup.staging ? '-test' : ''}.powrup.asia/api`
|
|
81
|
+
const path = '/wms/update-order-status'
|
|
82
|
+
const fullPath = `${baseUrl}${path}`
|
|
83
|
+
|
|
84
|
+
const payload = {
|
|
85
|
+
orderId: data.refOrderId,
|
|
86
|
+
status: status
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const response: any = await fetch(fullPath, {
|
|
90
|
+
method: 'post',
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
'X-Authorization': powrup.apiKey
|
|
94
|
+
},
|
|
95
|
+
body: JSON.stringify(payload)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
if (response.ok) {
|
|
99
|
+
const result = await response.json()
|
|
100
|
+
if (result.code == 0) {
|
|
101
|
+
await createPayloadLog(
|
|
102
|
+
powrup.id,
|
|
103
|
+
path,
|
|
104
|
+
JSON.stringify(payload),
|
|
105
|
+
JSON.stringify(result),
|
|
106
|
+
{ state: { domain: data.domain, user: null } }
|
|
107
|
+
)
|
|
108
|
+
} else {
|
|
109
|
+
const errorMessage = JSON.stringify(result)
|
|
110
|
+
await createPayloadLog(
|
|
111
|
+
powrup.id,
|
|
112
|
+
path,
|
|
113
|
+
JSON.stringify(payload),
|
|
114
|
+
errorMessage,
|
|
115
|
+
{ state: { domain: data.domain, user: null } }
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const errorText = await response.text()
|
|
120
|
+
const errorMessage = `(${response.status}) ${errorText}`
|
|
121
|
+
await createPayloadLog(
|
|
122
|
+
powrup.id,
|
|
123
|
+
path,
|
|
124
|
+
JSON.stringify(payload),
|
|
125
|
+
errorMessage,
|
|
126
|
+
{ state: { domain: data.domain, user: null } }
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
47
131
|
} catch (e) {
|
|
48
132
|
console.error(e.message)
|
|
49
133
|
}
|