repzo-sap-absjo 1.0.52 → 1.0.53
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/actions/create_client.d.ts +8 -0
- package/lib/actions/create_client.js +205 -0
- package/lib/actions/index.js +3 -0
- package/lib/commands/join.js +34 -4
- package/lib/test/actions/create_client.d.ts +1 -0
- package/lib/test/actions/create_client.js +141 -0
- package/lib/test/commands/join.js +165 -84
- package/lib/types.d.ts +3 -0
- package/package.json +5 -3
- package/src/actions/create_client.ts +184 -0
- package/src/actions/index.ts +3 -0
- package/src/commands/join.ts +8 -0
- package/src/test/actions/create_client.ts +141 -0
- package/src/test/commands/join.ts +165 -84
- package/src/types.ts +1 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import Repzo from "repzo";
|
|
2
|
+
import { _create } from "../util.js";
|
|
3
|
+
import { v4 as uuid } from "uuid";
|
|
4
|
+
export const create_client = async (event, options) => {
|
|
5
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
6
|
+
const repzo = new Repzo(
|
|
7
|
+
(_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey,
|
|
8
|
+
{ env: options.env }
|
|
9
|
+
);
|
|
10
|
+
const action_sync_id =
|
|
11
|
+
((_b = event === null || event === void 0 ? void 0 : event.headers) ===
|
|
12
|
+
null || _b === void 0
|
|
13
|
+
? void 0
|
|
14
|
+
: _b.action_sync_id) || uuid();
|
|
15
|
+
const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
|
|
16
|
+
let body;
|
|
17
|
+
try {
|
|
18
|
+
// console.log("create_client");
|
|
19
|
+
await actionLog.load(action_sync_id);
|
|
20
|
+
body = event.body;
|
|
21
|
+
try {
|
|
22
|
+
if (body) body = JSON.parse(body);
|
|
23
|
+
} catch (e) {}
|
|
24
|
+
try {
|
|
25
|
+
await repzo.updateIntegrationMeta.create(
|
|
26
|
+
[
|
|
27
|
+
{ key: "sync_to_sap_started", value: true },
|
|
28
|
+
{ key: "sync_to_sap_succeeded", value: false },
|
|
29
|
+
],
|
|
30
|
+
{ _id: body._id, type: "clients" }
|
|
31
|
+
);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
}
|
|
35
|
+
await actionLog
|
|
36
|
+
.addDetail(
|
|
37
|
+
`Client - ${body === null || body === void 0 ? void 0 : body.name} => ${
|
|
38
|
+
body === null || body === void 0 ? void 0 : body.sync_id
|
|
39
|
+
}`
|
|
40
|
+
)
|
|
41
|
+
.addDetail(
|
|
42
|
+
`Repzo => SAP: Started Create Client - ${
|
|
43
|
+
body === null || body === void 0 ? void 0 : body.name
|
|
44
|
+
}`
|
|
45
|
+
)
|
|
46
|
+
.commit();
|
|
47
|
+
const SAP_HOST_URL =
|
|
48
|
+
(_c = options.data) === null || _c === void 0 ? void 0 : _c.sapHostUrl;
|
|
49
|
+
if (!SAP_HOST_URL)
|
|
50
|
+
throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
|
|
51
|
+
const repzo_client = body;
|
|
52
|
+
const channel = repzo_client.channel
|
|
53
|
+
? await repzo.channel.get(repzo_client.channel)
|
|
54
|
+
: null;
|
|
55
|
+
const paymentTerm = repzo_client.paymentTerm
|
|
56
|
+
? await repzo.paymentTerm.get(repzo_client.paymentTerm)
|
|
57
|
+
: null;
|
|
58
|
+
const price_list = repzo_client.sv_priceList
|
|
59
|
+
? await repzo.priceList.get(repzo_client.sv_priceList)
|
|
60
|
+
: null;
|
|
61
|
+
const price_list_name = (
|
|
62
|
+
(_d =
|
|
63
|
+
price_list === null || price_list === void 0
|
|
64
|
+
? void 0
|
|
65
|
+
: price_list.integration_meta) === null || _d === void 0
|
|
66
|
+
? void 0
|
|
67
|
+
: _d.id
|
|
68
|
+
)
|
|
69
|
+
? Number(price_list.integration_meta.id.split("-")[1])
|
|
70
|
+
: undefined;
|
|
71
|
+
const rep = (
|
|
72
|
+
(_e = repzo_client.assigned_to) === null || _e === void 0
|
|
73
|
+
? void 0
|
|
74
|
+
: _e.length
|
|
75
|
+
)
|
|
76
|
+
? await repzo.rep.get(repzo_client.assigned_to[0])
|
|
77
|
+
: undefined;
|
|
78
|
+
const tags = (
|
|
79
|
+
(_f = repzo_client.tags) === null || _f === void 0 ? void 0 : _f.length
|
|
80
|
+
)
|
|
81
|
+
? await repzo.tag.find({ _id: repzo_client.tags, type: "area" })
|
|
82
|
+
: null;
|
|
83
|
+
const area_tags =
|
|
84
|
+
(_g = tags === null || tags === void 0 ? void 0 : tags.data) === null ||
|
|
85
|
+
_g === void 0
|
|
86
|
+
? void 0
|
|
87
|
+
: _g.filter((t) => {
|
|
88
|
+
var _a;
|
|
89
|
+
return (
|
|
90
|
+
t.type === "area" &&
|
|
91
|
+
!t.disabled &&
|
|
92
|
+
((_a = t.integration_meta) === null || _a === void 0
|
|
93
|
+
? void 0
|
|
94
|
+
: _a.TerritoryID)
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
const sap_customer = {
|
|
98
|
+
AdditionalID: repzo_client._id,
|
|
99
|
+
CLIENTID: repzo_client.client_code,
|
|
100
|
+
CLIENTDESCF: repzo_client.local_name,
|
|
101
|
+
CLIENTCITY: repzo_client.city,
|
|
102
|
+
CLIENTCOUNTY: repzo_client.state,
|
|
103
|
+
CLIENTCOUNTRY: repzo_client.country,
|
|
104
|
+
CLIENTCONTACTPERSON: repzo_client.contact_name,
|
|
105
|
+
CLIENTPHONE1: repzo_client.phone,
|
|
106
|
+
CLIENTPHONE2: repzo_client.cell_phone,
|
|
107
|
+
CLIENTNOTE: repzo_client.comment,
|
|
108
|
+
CLIENTADDRESSID: repzo_client.formatted_address,
|
|
109
|
+
CLIENTGROUP:
|
|
110
|
+
channel === null || channel === void 0 ? void 0 : channel.name,
|
|
111
|
+
PAYMENTTERM:
|
|
112
|
+
paymentTerm === null || paymentTerm === void 0
|
|
113
|
+
? void 0
|
|
114
|
+
: paymentTerm.due_days,
|
|
115
|
+
CLIENTPRICELISTID: price_list_name,
|
|
116
|
+
SALESPERSONCODE: rep
|
|
117
|
+
? Number(rep === null || rep === void 0 ? void 0 : rep.integration_id)
|
|
118
|
+
: undefined,
|
|
119
|
+
TERRITORYID:
|
|
120
|
+
(_j =
|
|
121
|
+
(_h =
|
|
122
|
+
area_tags === null || area_tags === void 0
|
|
123
|
+
? void 0
|
|
124
|
+
: area_tags[0]) === null || _h === void 0
|
|
125
|
+
? void 0
|
|
126
|
+
: _h.integration_meta) === null || _j === void 0
|
|
127
|
+
? void 0
|
|
128
|
+
: _j.TerritoryID,
|
|
129
|
+
CLIENTCREDITCONSUMED: repzo_client.integrated_client_balance
|
|
130
|
+
? repzo_client.integrated_client_balance / 1000
|
|
131
|
+
: undefined,
|
|
132
|
+
// CLIENTMAXCHEQUEVALUE: 1500000.0,
|
|
133
|
+
CLIENTCREDITLIMIT: (
|
|
134
|
+
(_k = repzo_client.financials) === null || _k === void 0
|
|
135
|
+
? void 0
|
|
136
|
+
: _k.credit_limit
|
|
137
|
+
)
|
|
138
|
+
? ((_l = repzo_client.financials) === null || _l === void 0
|
|
139
|
+
? void 0
|
|
140
|
+
: _l.credit_limit) / 1000
|
|
141
|
+
: undefined,
|
|
142
|
+
// CardName: "ÄBD",
|
|
143
|
+
// Phone1: "0788877776",
|
|
144
|
+
// cellular: "234567",
|
|
145
|
+
// CLIENTADDRESS: null,
|
|
146
|
+
// CLIENTGROUPCODE: 113,
|
|
147
|
+
// CLIENTSTATUS: "N",
|
|
148
|
+
// DISCOUNTPERCENT: 0.0,
|
|
149
|
+
// TERRITORYNAME: null,
|
|
150
|
+
// PARENTCODE: null, // ????
|
|
151
|
+
};
|
|
152
|
+
// console.dir(sap_customer, { depth: null });
|
|
153
|
+
actionLog.addDetail(
|
|
154
|
+
`Repzo => SAP: Client - ${
|
|
155
|
+
body === null || body === void 0 ? void 0 : body.name
|
|
156
|
+
}`,
|
|
157
|
+
sap_customer
|
|
158
|
+
);
|
|
159
|
+
const result = await _create(SAP_HOST_URL, "/AddCustomer", sap_customer);
|
|
160
|
+
// console.log(result);
|
|
161
|
+
actionLog.addDetail(`SAP Responded with `, result);
|
|
162
|
+
if (
|
|
163
|
+
result.result == "Success" &&
|
|
164
|
+
result.message != "The Customer already Exists in SAP"
|
|
165
|
+
) {
|
|
166
|
+
const update_repzo_client_body = {
|
|
167
|
+
client_code: result.message,
|
|
168
|
+
"integration_meta.id": `${repzo_client.company_namespace[0]}_${result.message}`,
|
|
169
|
+
};
|
|
170
|
+
const updated_repzo_client = await repzo.client.update(
|
|
171
|
+
repzo_client._id,
|
|
172
|
+
update_repzo_client_body
|
|
173
|
+
);
|
|
174
|
+
actionLog.addDetail(
|
|
175
|
+
`Update Client Code: ${
|
|
176
|
+
body === null || body === void 0 ? void 0 : body.name
|
|
177
|
+
} in Repzo`
|
|
178
|
+
);
|
|
179
|
+
// console.log({ updated_repzo_client });
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
await repzo.updateIntegrationMeta.create(
|
|
183
|
+
[{ key: "sync_to_sap_succeeded", value: true }],
|
|
184
|
+
{ _id: body._id, type: "clients" }
|
|
185
|
+
);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
console.error(e);
|
|
188
|
+
}
|
|
189
|
+
await actionLog
|
|
190
|
+
.addDetail(
|
|
191
|
+
`Repzo => SAP: Client - ${
|
|
192
|
+
body === null || body === void 0 ? void 0 : body.name
|
|
193
|
+
}`
|
|
194
|
+
)
|
|
195
|
+
.setStatus("success")
|
|
196
|
+
.setBody(repzo_client)
|
|
197
|
+
.commit();
|
|
198
|
+
return result;
|
|
199
|
+
} catch (e) {
|
|
200
|
+
//@ts-ignore
|
|
201
|
+
console.error((e === null || e === void 0 ? void 0 : e.response) || e);
|
|
202
|
+
await actionLog.setStatus("fail", e).setBody(body).commit();
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
};
|
package/lib/actions/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { create_return_invoice } from "./create_return_invoice.js";
|
|
|
3
3
|
import { create_proforma } from "./create_proforma.js";
|
|
4
4
|
import { create_payment } from "./create_payment.js";
|
|
5
5
|
import { create_transfer } from "./create_transfer.js";
|
|
6
|
+
import { create_client } from "./create_client.js";
|
|
6
7
|
export const actions = async (event, options) => {
|
|
7
8
|
var _a, _b;
|
|
8
9
|
switch (
|
|
@@ -20,6 +21,8 @@ export const actions = async (event, options) => {
|
|
|
20
21
|
return await create_payment(event, options);
|
|
21
22
|
case "create_transfer":
|
|
22
23
|
return await create_transfer(event, options);
|
|
24
|
+
case "create_client":
|
|
25
|
+
return await create_client(event, options);
|
|
23
26
|
default:
|
|
24
27
|
throw `Route: ${
|
|
25
28
|
(_b = event.queryStringParameters) === null || _b === void 0
|
package/lib/commands/join.js
CHANGED
|
@@ -25,7 +25,11 @@ export const join = async (commandEvent) => {
|
|
|
25
25
|
_y,
|
|
26
26
|
_z,
|
|
27
27
|
_0,
|
|
28
|
-
_1
|
|
28
|
+
_1,
|
|
29
|
+
_2,
|
|
30
|
+
_3,
|
|
31
|
+
_4,
|
|
32
|
+
_5;
|
|
29
33
|
const repzo = new Repzo(
|
|
30
34
|
(_a = commandEvent.app.formData) === null || _a === void 0
|
|
31
35
|
? void 0
|
|
@@ -200,6 +204,32 @@ export const join = async (commandEvent) => {
|
|
|
200
204
|
? void 0
|
|
201
205
|
: _0.createApprovedTransferHook) || false,
|
|
202
206
|
},
|
|
207
|
+
// client
|
|
208
|
+
{
|
|
209
|
+
app: "repzo-sap-absjo",
|
|
210
|
+
app_id:
|
|
211
|
+
(_1 =
|
|
212
|
+
commandEvent === null || commandEvent === void 0
|
|
213
|
+
? void 0
|
|
214
|
+
: commandEvent.app) === null || _1 === void 0
|
|
215
|
+
? void 0
|
|
216
|
+
: _1._id,
|
|
217
|
+
action: "create_client",
|
|
218
|
+
event: "client.create",
|
|
219
|
+
join:
|
|
220
|
+
((_4 =
|
|
221
|
+
(_3 =
|
|
222
|
+
(_2 =
|
|
223
|
+
commandEvent === null || commandEvent === void 0
|
|
224
|
+
? void 0
|
|
225
|
+
: commandEvent.app) === null || _2 === void 0
|
|
226
|
+
? void 0
|
|
227
|
+
: _2.formData) === null || _3 === void 0
|
|
228
|
+
? void 0
|
|
229
|
+
: _3.client) === null || _4 === void 0
|
|
230
|
+
? void 0
|
|
231
|
+
: _4.createClientHook) || false,
|
|
232
|
+
},
|
|
203
233
|
],
|
|
204
234
|
};
|
|
205
235
|
const result = await repzo.joinActionsWebHook.update(null, body);
|
|
@@ -215,10 +245,10 @@ export const join = async (commandEvent) => {
|
|
|
215
245
|
} catch (e) {
|
|
216
246
|
//@ts-ignore
|
|
217
247
|
console.error(
|
|
218
|
-
((
|
|
219
|
-
|
|
248
|
+
((_5 = e === null || e === void 0 ? void 0 : e.response) === null ||
|
|
249
|
+
_5 === void 0
|
|
220
250
|
? void 0
|
|
221
|
-
:
|
|
251
|
+
: _5.data) || e
|
|
222
252
|
);
|
|
223
253
|
await commandLog.setStatus("fail", e).commit();
|
|
224
254
|
throw e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Actions } from "../../index.js";
|
|
2
|
+
Actions(
|
|
3
|
+
{
|
|
4
|
+
version: "2.0",
|
|
5
|
+
routeKey: "POST /actions",
|
|
6
|
+
rawPath: "/actions",
|
|
7
|
+
rawQueryString: "app=repzo-sap-absjo&action=create_client",
|
|
8
|
+
headers: {
|
|
9
|
+
action_sync_id: "Actions-0000004", // SYNC_ID
|
|
10
|
+
accept: "*/*",
|
|
11
|
+
"accept-encoding": "gzip, deflate",
|
|
12
|
+
"content-length": "3658",
|
|
13
|
+
"content-type": "application/json",
|
|
14
|
+
host: "staging.marketplace.api.repzo.me",
|
|
15
|
+
"svix-id": "msg_29I1By29ETyPiZ4SNrc99KIg7D6",
|
|
16
|
+
"svix-signature": "v1,OkktM+dibxzeb0M6383POFjBr7DX14HECpBIh17FQnU=",
|
|
17
|
+
"svix-timestamp": "1652785653",
|
|
18
|
+
"user-agent": "Svix-Webhooks/1.4",
|
|
19
|
+
"x-amzn-trace-id": "Root=1-628381f6-0b2c6f346d2eb5d207b582ee",
|
|
20
|
+
"x-forwarded-for": "52.215.16.239",
|
|
21
|
+
"x-forwarded-port": "443",
|
|
22
|
+
"x-forwarded-proto": "https",
|
|
23
|
+
},
|
|
24
|
+
queryStringParameters: {
|
|
25
|
+
action: "create_client",
|
|
26
|
+
app: "repzo-sap-absjo",
|
|
27
|
+
},
|
|
28
|
+
requestContext: {
|
|
29
|
+
accountId: "478266140170",
|
|
30
|
+
apiId: "ulkb1ikop2",
|
|
31
|
+
domainName: "staging.marketplace.api.repzo.me",
|
|
32
|
+
domainPrefix: "staging",
|
|
33
|
+
http: {
|
|
34
|
+
method: "POST",
|
|
35
|
+
path: "/actions",
|
|
36
|
+
protocol: "HTTP/1.1",
|
|
37
|
+
sourceIp: "52.215.16.239",
|
|
38
|
+
userAgent: "Svix-Webhooks/1.4",
|
|
39
|
+
},
|
|
40
|
+
requestId: "SRE-ejb6IAMEPWQ=",
|
|
41
|
+
routeKey: "POST /actions",
|
|
42
|
+
stage: "$default",
|
|
43
|
+
time: "17/May/2022:11:07:34 +0000",
|
|
44
|
+
timeEpoch: 1652785654069,
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
company_namespace: ["hassanein1"],
|
|
48
|
+
name: "علي عباس - مشتريات خاصه",
|
|
49
|
+
tags: [],
|
|
50
|
+
cell_phone: null,
|
|
51
|
+
city: null,
|
|
52
|
+
client_code: "CL01809",
|
|
53
|
+
contact_name: null,
|
|
54
|
+
contacts: [],
|
|
55
|
+
country: null,
|
|
56
|
+
disabled: false,
|
|
57
|
+
formatted_address: null,
|
|
58
|
+
geoPoint: { type: "Point", coordinates: [0, 0] },
|
|
59
|
+
lat: 0,
|
|
60
|
+
lng: 0,
|
|
61
|
+
location_verified: false,
|
|
62
|
+
phone: null,
|
|
63
|
+
state: null,
|
|
64
|
+
assigned_to: [],
|
|
65
|
+
profile_pic: null,
|
|
66
|
+
logo: null,
|
|
67
|
+
website: "",
|
|
68
|
+
email: "",
|
|
69
|
+
comment: null,
|
|
70
|
+
parent_client_id: null,
|
|
71
|
+
target_visit: 0,
|
|
72
|
+
geofencing_radius: null,
|
|
73
|
+
price_tag: null,
|
|
74
|
+
status: null,
|
|
75
|
+
job_category: [],
|
|
76
|
+
availability_msl: [],
|
|
77
|
+
territory: null,
|
|
78
|
+
sv_priceList: "68d13d4ed11f86a126325552",
|
|
79
|
+
assigned_media: [],
|
|
80
|
+
assigned_products: [],
|
|
81
|
+
assigned_product_groups: [],
|
|
82
|
+
financials: { credit_limit: 1000000000 },
|
|
83
|
+
paymentTerm: "68d13a09196089cdda21115f",
|
|
84
|
+
speciality: [],
|
|
85
|
+
channel: "68d13a05aec62a4ccf654e8e",
|
|
86
|
+
teams: [],
|
|
87
|
+
payment_type: "cash",
|
|
88
|
+
integration_meta: {
|
|
89
|
+
id: "hassanein1_CL01809",
|
|
90
|
+
PAYMENTTERM: 0,
|
|
91
|
+
CLIENTCREDITCONSUMED: 18000,
|
|
92
|
+
CLIENTMAXCHEQUEVALUE: 1500000,
|
|
93
|
+
CLIENTCREDITLIMIT: 1500000,
|
|
94
|
+
CLIENTPRICELISTID: 2,
|
|
95
|
+
},
|
|
96
|
+
integrated_client_balance: 18000000,
|
|
97
|
+
media: [],
|
|
98
|
+
invoice_balance_limit: 0,
|
|
99
|
+
payment_terms_grace_period_days: 0,
|
|
100
|
+
enable_invoice_balance_limit: false,
|
|
101
|
+
enable_payment_terms_grace_period_days: false,
|
|
102
|
+
enable_credit_limit_on_invoice: false,
|
|
103
|
+
enable_credit_limit_on_proforma: false,
|
|
104
|
+
enable_invoice_balance_limit_on_proforma: false,
|
|
105
|
+
enable_payment_terms_grace_period_days_on_proforma: false,
|
|
106
|
+
is_simplified: true,
|
|
107
|
+
retail_execution_templates: [],
|
|
108
|
+
assigned_forms_v2_templates: [],
|
|
109
|
+
_id: "68ee2dd948dd6ab6d549ee9f",
|
|
110
|
+
rep_targets: [],
|
|
111
|
+
shelf_share_targets: [],
|
|
112
|
+
jobs: [],
|
|
113
|
+
createdAt: "2025-10-14T11:02:49.674Z",
|
|
114
|
+
updatedAt: "2025-10-14T11:02:49.674Z",
|
|
115
|
+
__v: 0,
|
|
116
|
+
}),
|
|
117
|
+
isBase64Encoded: false,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
app_id: "",
|
|
121
|
+
repzoEndPoint: "",
|
|
122
|
+
serviceEndPoint: "",
|
|
123
|
+
env: "staging",
|
|
124
|
+
data: {
|
|
125
|
+
invoices: { createInvoiceHook: false, createReturnInvoiceHook: false },
|
|
126
|
+
payments: { createPaymentHook: false },
|
|
127
|
+
proformas: { createApprovedProformaHook: false },
|
|
128
|
+
transfer: { createApprovedTransferHook: false },
|
|
129
|
+
client: { createClientHook: true },
|
|
130
|
+
repzoApiKey: "SZx76pM2TiuFt9kK7fsBCLkW7oY8qA8pIjUHdmgzdZg",
|
|
131
|
+
sapHostUrl: "https://abs-dmz.b1pro.com:9001/api",
|
|
132
|
+
errorEmail: "maram.alshen@repzoapp.com",
|
|
133
|
+
serviceApiKey: "awdas",
|
|
134
|
+
warehouseDefaultUpdateDate: "",
|
|
135
|
+
DepartmentCode: "",
|
|
136
|
+
return_reason: "",
|
|
137
|
+
SalPersCode: "",
|
|
138
|
+
SalesPersonCode: "",
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
);
|