repzo-sap-absjo 1.0.52 → 1.0.54

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 (41) hide show
  1. package/lib/actions/create_client.d.ts +8 -0
  2. package/lib/actions/create_client.js +206 -0
  3. package/lib/actions/create_invoice.d.ts +1 -1
  4. package/lib/actions/create_payment.d.ts +1 -1
  5. package/lib/actions/create_proforma.d.ts +1 -1
  6. package/lib/actions/create_return_invoice.d.ts +1 -1
  7. package/lib/actions/create_transfer.d.ts +1 -1
  8. package/lib/actions/index.d.ts +1 -1
  9. package/lib/actions/index.js +3 -0
  10. package/lib/commands/join.js +34 -4
  11. package/lib/index.d.ts +1 -1
  12. package/lib/test/actions/create_client.d.ts +1 -0
  13. package/lib/test/actions/create_client.js +141 -0
  14. package/lib/test/commands/join.js +165 -84
  15. package/lib/types.d.ts +3 -0
  16. package/lib/util.d.ts +4 -4
  17. package/package.json +5 -3
  18. package/src/actions/create_client.ts +185 -0
  19. package/src/actions/create_invoice.ts +2 -2
  20. package/src/actions/index.ts +3 -0
  21. package/src/commands/adjust_inventory.ts +2 -2
  22. package/src/commands/bank.ts +5 -1
  23. package/src/commands/brand.ts +2 -2
  24. package/src/commands/category.ts +2 -2
  25. package/src/commands/channel.ts +2 -2
  26. package/src/commands/client.ts +2 -2
  27. package/src/commands/client_disabled.ts +2 -2
  28. package/src/commands/join.ts +8 -0
  29. package/src/commands/measureunit.ts +2 -2
  30. package/src/commands/payment_term.ts +2 -2
  31. package/src/commands/price_list.ts +2 -2
  32. package/src/commands/price_list_disabled.ts +2 -2
  33. package/src/commands/product.ts +8 -4
  34. package/src/commands/product_disabled.ts +8 -4
  35. package/src/commands/rep.ts +1 -1
  36. package/src/commands/tag.ts +2 -2
  37. package/src/commands/tax.ts +2 -2
  38. package/src/commands/warehouse.ts +2 -2
  39. package/src/test/actions/create_client.ts +141 -0
  40. package/src/test/commands/join.ts +165 -84
  41. package/src/types.ts +1 -0
@@ -0,0 +1,8 @@
1
+ import { EVENT, Config } from "../types";
2
+ export declare const create_client: (
3
+ event: EVENT,
4
+ options: Config
5
+ ) => Promise<{
6
+ result: "Success";
7
+ message: string | "The Customer already Exists in SAP";
8
+ }>;
@@ -0,0 +1,206 @@
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
+ CardName: repzo_client.name,
99
+ AdditionalID: repzo_client._id,
100
+ CLIENTID: repzo_client.client_code,
101
+ CLIENTDESCF: repzo_client.local_name,
102
+ CLIENTCITY: repzo_client.city,
103
+ CLIENTCOUNTY: repzo_client.state,
104
+ CLIENTCOUNTRY: repzo_client.country,
105
+ CLIENTCONTACTPERSON: repzo_client.contact_name,
106
+ CLIENTPHONE1: repzo_client.phone,
107
+ CLIENTPHONE2: repzo_client.cell_phone,
108
+ CLIENTNOTE: repzo_client.comment,
109
+ CLIENTADDRESSID: repzo_client.formatted_address,
110
+ CLIENTGROUP:
111
+ channel === null || channel === void 0 ? void 0 : channel.name,
112
+ PAYMENTTERM:
113
+ paymentTerm === null || paymentTerm === void 0
114
+ ? void 0
115
+ : paymentTerm.due_days,
116
+ CLIENTPRICELISTID: price_list_name,
117
+ SALESPERSONCODE: rep
118
+ ? Number(rep === null || rep === void 0 ? void 0 : rep.integration_id)
119
+ : undefined,
120
+ TERRITORYID:
121
+ (_j =
122
+ (_h =
123
+ area_tags === null || area_tags === void 0
124
+ ? void 0
125
+ : area_tags[0]) === null || _h === void 0
126
+ ? void 0
127
+ : _h.integration_meta) === null || _j === void 0
128
+ ? void 0
129
+ : _j.TerritoryID,
130
+ CLIENTCREDITCONSUMED: repzo_client.integrated_client_balance
131
+ ? repzo_client.integrated_client_balance / 1000
132
+ : undefined,
133
+ // CLIENTMAXCHEQUEVALUE: 1500000.0,
134
+ CLIENTCREDITLIMIT: (
135
+ (_k = repzo_client.financials) === null || _k === void 0
136
+ ? void 0
137
+ : _k.credit_limit
138
+ )
139
+ ? ((_l = repzo_client.financials) === null || _l === void 0
140
+ ? void 0
141
+ : _l.credit_limit) / 1000
142
+ : undefined,
143
+ // CardName: "ÄBD",
144
+ // Phone1: "0788877776",
145
+ // cellular: "234567",
146
+ // CLIENTADDRESS: null,
147
+ // CLIENTGROUPCODE: 113,
148
+ // CLIENTSTATUS: "N",
149
+ // DISCOUNTPERCENT: 0.0,
150
+ // TERRITORYNAME: null,
151
+ // PARENTCODE: null, // ????
152
+ };
153
+ // console.dir(sap_customer, { depth: null });
154
+ actionLog.addDetail(
155
+ `Repzo => SAP: Client - ${
156
+ body === null || body === void 0 ? void 0 : body.name
157
+ }`,
158
+ sap_customer
159
+ );
160
+ const result = await _create(SAP_HOST_URL, "/AddCustomer", sap_customer);
161
+ // console.log(result);
162
+ actionLog.addDetail(`SAP Responded with `, result);
163
+ if (
164
+ result.result == "Success" &&
165
+ result.message != "The Customer already Exists in SAP"
166
+ ) {
167
+ const update_repzo_client_body = {
168
+ client_code: result.message,
169
+ "integration_meta.id": `${repzo_client.company_namespace[0]}_${result.message}`,
170
+ };
171
+ const updated_repzo_client = await repzo.client.update(
172
+ repzo_client._id,
173
+ update_repzo_client_body
174
+ );
175
+ actionLog.addDetail(
176
+ `Update Client Code: ${
177
+ body === null || body === void 0 ? void 0 : body.name
178
+ } in Repzo`
179
+ );
180
+ // console.log({ updated_repzo_client });
181
+ }
182
+ try {
183
+ await repzo.updateIntegrationMeta.create(
184
+ [{ key: "sync_to_sap_succeeded", value: true }],
185
+ { _id: body._id, type: "clients" }
186
+ );
187
+ } catch (e) {
188
+ console.error(e);
189
+ }
190
+ await actionLog
191
+ .addDetail(
192
+ `Repzo => SAP: Client - ${
193
+ body === null || body === void 0 ? void 0 : body.name
194
+ }`
195
+ )
196
+ .setStatus("success")
197
+ .setBody(repzo_client)
198
+ .commit();
199
+ return result;
200
+ } catch (e) {
201
+ //@ts-ignore
202
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
203
+ await actionLog.setStatus("fail", e).setBody(body).commit();
204
+ throw e;
205
+ }
206
+ };
@@ -14,7 +14,7 @@ export interface SAPOpenInvoice {
14
14
  export declare const create_invoice: (
15
15
  event: EVENT,
16
16
  options: Config
17
- ) => Promise<any>;
17
+ ) => Promise<unknown>;
18
18
  export declare const get_invoice_from_sap: (
19
19
  serviceEndPoint: string,
20
20
  query?: {
@@ -2,4 +2,4 @@ import { EVENT, Config } from "../types";
2
2
  export declare const create_payment: (
3
3
  event: EVENT,
4
4
  options: Config
5
- ) => Promise<any>;
5
+ ) => Promise<unknown>;
@@ -2,4 +2,4 @@ import { EVENT, Config } from "../types";
2
2
  export declare const create_proforma: (
3
3
  event: EVENT,
4
4
  options: Config
5
- ) => Promise<any>;
5
+ ) => Promise<unknown>;
@@ -2,4 +2,4 @@ import { EVENT, Config } from "../types";
2
2
  export declare const create_return_invoice: (
3
3
  event: EVENT,
4
4
  options: Config
5
- ) => Promise<any>;
5
+ ) => Promise<unknown>;
@@ -2,4 +2,4 @@ import { EVENT, Config } from "../types";
2
2
  export declare const create_transfer: (
3
3
  event: EVENT,
4
4
  options: Config
5
- ) => Promise<any>;
5
+ ) => Promise<unknown>;
@@ -1,3 +1,3 @@
1
1
  import { Config, Action } from "../types";
2
- export declare const actions: (event: any, options: Config) => Promise<any>;
2
+ export declare const actions: (event: any, options: Config) => Promise<unknown>;
3
3
  export declare const actionsList: Action[];
@@ -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
@@ -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
- ((_1 = e === null || e === void 0 ? void 0 : e.response) === null ||
219
- _1 === void 0
248
+ ((_5 = e === null || e === void 0 ? void 0 : e.response) === null ||
249
+ _5 === void 0
220
250
  ? void 0
221
- : _1.data) || e
251
+ : _5.data) || e
222
252
  );
223
253
  await commandLog.setStatus("fail", e).commit();
224
254
  throw e;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare const Actions: (
2
2
  event: any,
3
3
  options: import("./types.js").Config
4
- ) => Promise<any>;
4
+ ) => Promise<unknown>;
5
5
  export declare const ActionsList: import("./types.js").Action[];
6
6
  export declare const Commands: (
7
7
  CommandEvent: import("./types.js").CommandEvent
@@ -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
+ );