repzo-sap-absjo 1.0.9 → 1.0.10

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 (73) hide show
  1. package/lib/actions/create_invoice.d.ts +13 -19
  2. package/lib/actions/create_invoice.js +206 -363
  3. package/lib/actions/create_payment.d.ts +1 -4
  4. package/lib/actions/create_payment.js +117 -200
  5. package/lib/actions/create_proforma.d.ts +1 -4
  6. package/lib/actions/create_proforma.js +155 -290
  7. package/lib/actions/create_return_invoice.d.ts +1 -4
  8. package/lib/actions/create_return_invoice.js +169 -321
  9. package/lib/actions/create_transfer.d.ts +1 -4
  10. package/lib/actions/create_transfer.js +136 -220
  11. package/lib/actions/index.js +15 -23
  12. package/lib/commands/adjust_inventory.d.ts +2 -4
  13. package/lib/commands/adjust_inventory.js +160 -290
  14. package/lib/commands/bank.d.ts +2 -4
  15. package/lib/commands/bank.js +157 -279
  16. package/lib/commands/basic.js +47 -66
  17. package/lib/commands/category.d.ts +1 -3
  18. package/lib/commands/category.js +104 -178
  19. package/lib/commands/channel.d.ts +1 -3
  20. package/lib/commands/channel.js +117 -198
  21. package/lib/commands/client.d.ts +32 -34
  22. package/lib/commands/client.js +244 -404
  23. package/lib/commands/client_disabled.d.ts +1 -3
  24. package/lib/commands/client_disabled.js +94 -163
  25. package/lib/commands/index.d.ts +11 -15
  26. package/lib/commands/index.js +60 -60
  27. package/lib/commands/join.js +66 -192
  28. package/lib/commands/measureunit.d.ts +14 -19
  29. package/lib/commands/measureunit.js +191 -289
  30. package/lib/commands/measureunit_family.d.ts +8 -10
  31. package/lib/commands/measureunit_family.js +138 -250
  32. package/lib/commands/payment_term.d.ts +1 -3
  33. package/lib/commands/payment_term.js +123 -202
  34. package/lib/commands/price_list.d.ts +15 -15
  35. package/lib/commands/price_list.js +326 -612
  36. package/lib/commands/product.d.ts +30 -32
  37. package/lib/commands/product.js +243 -425
  38. package/lib/commands/product_disabled.d.ts +1 -3
  39. package/lib/commands/product_disabled.js +94 -164
  40. package/lib/commands/rep.js +141 -221
  41. package/lib/commands/tag.js +109 -174
  42. package/lib/commands/tax.js +112 -177
  43. package/lib/commands/warehouse.d.ts +1 -3
  44. package/lib/commands/warehouse.js +119 -207
  45. package/lib/index.d.ts +12 -21
  46. package/lib/test/actions/create_invoice.js +188 -193
  47. package/lib/test/actions/create_payment.js +107 -112
  48. package/lib/test/actions/create_proforma.js +216 -220
  49. package/lib/test/actions/create_return_invoice.js +200 -205
  50. package/lib/test/actions/create_transfer.js +115 -120
  51. package/lib/test/commands/adjust_inventory.js +90 -90
  52. package/lib/test/commands/bank.js +90 -90
  53. package/lib/test/commands/basic.js +327 -328
  54. package/lib/test/commands/category.js +90 -90
  55. package/lib/test/commands/channel.js +90 -90
  56. package/lib/test/commands/client.js +353 -355
  57. package/lib/test/commands/client_disabled.js +90 -90
  58. package/lib/test/commands/join.js +327 -328
  59. package/lib/test/commands/measureunit.js +90 -90
  60. package/lib/test/commands/measureunit_family.js +90 -90
  61. package/lib/test/commands/payment_term.js +90 -90
  62. package/lib/test/commands/price_list.js +334 -337
  63. package/lib/test/commands/product.js +90 -90
  64. package/lib/test/commands/product_disabled.js +90 -90
  65. package/lib/test/commands/rep.js +344 -346
  66. package/lib/test/commands/tag.js +90 -90
  67. package/lib/test/commands/tax.js +90 -90
  68. package/lib/test/commands/warehouse.js +90 -90
  69. package/lib/types.d.ts +60 -83
  70. package/lib/util.d.ts +19 -70
  71. package/lib/util.js +144 -170
  72. package/package.json +1 -1
  73. package/src/actions/create_transfer.ts +2 -2
@@ -1,228 +1,144 @@
1
1
  import Repzo from "repzo";
2
- import { _create, send_command_to_marketplace } from "../util.js";
2
+ import { _create, send_command_to_marketplace, } from "../util.js";
3
3
  import { v4 as uuid } from "uuid";
4
4
  export const create_transfer = async (event, options) => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
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_transfer");
19
- await actionLog.load(action_sync_id);
20
- body = event.body;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
+ const repzo = new Repzo((_a = options.data) === null || _a === void 0 ? void 0 : _a.repzoApiKey, { env: options.env });
7
+ const action_sync_id = ((_b = event === null || event === void 0 ? void 0 : event.headers) === null || _b === void 0 ? void 0 : _b.action_sync_id) || uuid();
8
+ const actionLog = new Repzo.ActionLogs(repzo, action_sync_id);
9
+ let body;
21
10
  try {
22
- if (body) body = JSON.parse(body);
23
- } catch (e) {}
24
- const repzo_serial_number =
25
- (_c = body === null || body === void 0 ? void 0 : body.serial_number) ===
26
- null || _c === void 0
27
- ? void 0
28
- : _c.formatted;
29
- // try {
30
- // if (body?._id) {
31
- // body.integration_meta = body?.integration_meta || {};
32
- // body.integration_meta.sync_to_sap_started = true;
33
- // body.integration_meta.sync_to_sap_succeeded =
34
- // body.integration_meta.sync_to_sap_succeeded || false;
35
- // await repzo.transfer.update(body._id, {
36
- // integration_meta: body.integration_meta,
37
- // });
38
- // }
39
- // } catch (e) {
40
- // console.error(e);
41
- // }
42
- await actionLog
43
- .addDetail(
44
- `Transfer - ${repzo_serial_number} => ${
45
- body === null || body === void 0 ? void 0 : body.sync_id
46
- }`
47
- )
48
- .addDetail(
49
- `Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`
50
- )
51
- .commit();
52
- const SAP_HOST_URL =
53
- (_d = options.data) === null || _d === void 0 ? void 0 : _d.sapHostUrl;
54
- if (!SAP_HOST_URL)
55
- throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
56
- const repzo_transfer = body;
57
- // Get Repzo Rep
58
- let repzo_rep;
59
- if (repzo_transfer.creator.type == "rep") {
60
- repzo_rep = await repzo.rep.get(
61
- (_e =
62
- repzo_transfer === null || repzo_transfer === void 0
63
- ? void 0
64
- : repzo_transfer.creator) === null || _e === void 0
65
- ? void 0
66
- : _e._id
67
- );
68
- if (!repzo_rep)
69
- throw `Rep with _id: ${repzo_transfer.creator._id} not found in Repzo`;
70
- }
71
- // Get Repzo Products with its own Populated MeasureUnit
72
- const repzo_product_ids = {};
73
- (_f = repzo_transfer.variants) === null || _f === void 0
74
- ? void 0
75
- : _f.forEach((item) => {
76
- if (item === null || item === void 0 ? void 0 : item.product_id) {
77
- repzo_product_ids[item.product_id.toString()] = true;
78
- }
11
+ // console.log("create_transfer");
12
+ body = event.body;
13
+ try {
14
+ if (body)
15
+ body = JSON.parse(body);
16
+ }
17
+ catch (e) { }
18
+ if ((_c = body === null || body === void 0 ? void 0 : body.integration_meta) === null || _c === void 0 ? void 0 : _c.sync_to_sap_started)
19
+ return;
20
+ await actionLog.load(action_sync_id);
21
+ const repzo_serial_number = (_d = body === null || body === void 0 ? void 0 : body.serial_number) === null || _d === void 0 ? void 0 : _d.formatted;
22
+ // try {
23
+ // if (body?._id) {
24
+ // body.integration_meta = body?.integration_meta || {};
25
+ // body.integration_meta.sync_to_sap_started = true;
26
+ // body.integration_meta.sync_to_sap_succeeded =
27
+ // body.integration_meta.sync_to_sap_succeeded || false;
28
+ // await repzo.transfer.update(body._id, {
29
+ // integration_meta: body.integration_meta,
30
+ // });
31
+ // }
32
+ // } catch (e) {
33
+ // console.error(e);
34
+ // }
35
+ await actionLog
36
+ .addDetail(`Transfer - ${repzo_serial_number} => ${body === null || body === void 0 ? void 0 : body.sync_id}`)
37
+ .addDetail(`Repzo => SAP: Started Create Transfer - ${repzo_serial_number}`)
38
+ .commit();
39
+ const SAP_HOST_URL = (_e = options.data) === null || _e === void 0 ? void 0 : _e.sapHostUrl;
40
+ if (!SAP_HOST_URL)
41
+ throw `SAP Host Url is missing and Required: ${SAP_HOST_URL}`;
42
+ const repzo_transfer = body;
43
+ // Get Repzo Rep
44
+ let repzo_rep;
45
+ if (repzo_transfer.creator.type == "rep") {
46
+ repzo_rep = await repzo.rep.get((_f = repzo_transfer === null || repzo_transfer === void 0 ? void 0 : repzo_transfer.creator) === null || _f === void 0 ? void 0 : _f._id);
47
+ if (!repzo_rep)
48
+ throw `Rep with _id: ${repzo_transfer.creator._id} not found in Repzo`;
49
+ }
50
+ // Get Repzo Products with its own Populated MeasureUnit
51
+ const repzo_product_ids = {};
52
+ (_g = repzo_transfer.variants) === null || _g === void 0 ? void 0 : _g.forEach((item) => {
53
+ if (item === null || item === void 0 ? void 0 : item.product_id) {
54
+ repzo_product_ids[item.product_id.toString()] = true;
55
+ }
79
56
  });
80
- const repzo_products = await repzo.patchAction.create(
81
- {
82
- slug: "product",
83
- readQuery: [
84
- {
85
- key: "_id",
86
- value: Object.keys(repzo_product_ids),
87
- operator: "in",
88
- },
89
- ],
90
- },
91
- { per_page: 50000, populatedKeys: ["measureunit"] }
92
- );
93
- // Prepare Transfer Items
94
- const variants = [];
95
- for (
96
- let i = 0;
97
- i <
98
- ((_g = repzo_transfer.variants) === null || _g === void 0
99
- ? void 0
100
- : _g.length);
101
- i++
102
- ) {
103
- const repzo_transfer_item = repzo_transfer.variants[i];
104
- const repzo_product =
105
- (_h =
106
- repzo_products === null || repzo_products === void 0
107
- ? void 0
108
- : repzo_products.data) === null || _h === void 0
109
- ? void 0
110
- : _h.find(
111
- //@ts-ignore
112
- (p) => {
113
- var _a;
114
- return (
115
- p._id.toString() ==
116
- ((_a = repzo_transfer_item.product_id) === null ||
117
- _a === void 0
118
- ? void 0
119
- : _a.toString())
120
- );
121
- }
122
- );
123
- if (!repzo_product) {
124
- // console.log(
125
- // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
126
- // );
127
- throw new Error(
128
- `Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`
129
- );
130
- }
131
- const repzo_measure_unit = repzo_product.sv_measureUnit;
132
- if (
133
- !(repzo_measure_unit === null || repzo_measure_unit === void 0
134
- ? void 0
135
- : repzo_measure_unit._id)
136
- ) {
137
- // console.log(
138
- // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
139
- // );
140
- throw new Error(
141
- `Measureunit with _id: ${
142
- (_j = repzo_product.sv_measureUnit) === null || _j === void 0
143
- ? void 0
144
- : _j.toString()
145
- } was not found`
146
- );
147
- }
148
- variants.push({
149
- //@ts-ignore
150
- ItemCode: repzo_transfer_item.variant_name,
151
- Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
152
- //@ts-ignore
153
- FromWarehouse:
154
- (_k = repzo_transfer.from) === null || _k === void 0
155
- ? void 0
156
- : _k.code,
157
- //@ts-ignore
158
- ToWarehouse:
159
- (_l = repzo_transfer.to) === null || _l === void 0 ? void 0 : _l.code,
160
- });
57
+ const repzo_products = await repzo.patchAction.create({
58
+ slug: "product",
59
+ readQuery: [
60
+ {
61
+ key: "_id",
62
+ value: Object.keys(repzo_product_ids),
63
+ operator: "in",
64
+ },
65
+ ],
66
+ }, { per_page: 50000, populatedKeys: ["measureunit"] });
67
+ // Prepare Transfer Items
68
+ const variants = [];
69
+ for (let i = 0; i < ((_h = repzo_transfer.variants) === null || _h === void 0 ? void 0 : _h.length); i++) {
70
+ const repzo_transfer_item = repzo_transfer.variants[i];
71
+ const repzo_product = (_j = repzo_products === null || repzo_products === void 0 ? void 0 : repzo_products.data) === null || _j === void 0 ? void 0 : _j.find(
72
+ //@ts-ignore
73
+ (p) => { var _a; return p._id.toString() == ((_a = repzo_transfer_item.product_id) === null || _a === void 0 ? void 0 : _a.toString()); });
74
+ if (!repzo_product) {
75
+ // console.log(
76
+ // `Product with _id: ${repzo_transfer_item.product_id} was not found In Repzo`,
77
+ // );
78
+ throw new Error(`Product with _id: ${repzo_transfer_item.product_id} was not found in Repzo`);
79
+ }
80
+ const repzo_measure_unit = repzo_product.sv_measureUnit;
81
+ if (!(repzo_measure_unit === null || repzo_measure_unit === void 0 ? void 0 : repzo_measure_unit._id)) {
82
+ // console.log(
83
+ // `Measureunit with _id: ${repzo_product.sv_measureUnit?.toString()} was not found`,
84
+ // );
85
+ throw new Error(`Measureunit with _id: ${(_k = repzo_product.sv_measureUnit) === null || _k === void 0 ? void 0 : _k.toString()} was not found`);
86
+ }
87
+ variants.push({
88
+ //@ts-ignore
89
+ ItemCode: repzo_transfer_item.variant_name,
90
+ Quantity: repzo_transfer_item.qty / Number(repzo_measure_unit.factor),
91
+ //@ts-ignore
92
+ FromWarehouse: (_l = repzo_transfer.from) === null || _l === void 0 ? void 0 : _l.code,
93
+ //@ts-ignore
94
+ ToWarehouse: (_m = repzo_transfer.to) === null || _m === void 0 ? void 0 : _m.code,
95
+ });
96
+ }
97
+ const sap_transfer = {
98
+ StockTransferID: body.serial_number.formatted,
99
+ SalesPersonCode: repzo_rep
100
+ ? repzo_rep.integration_id
101
+ : (_o = options.data) === null || _o === void 0 ? void 0 : _o.SalesPersonCode,
102
+ FromWarehouse: body.from.code,
103
+ ToWarehouse: body.to.code,
104
+ RepzoStockTransferLines: variants,
105
+ };
106
+ // console.dir(sap_transfer, { depth: null });
107
+ actionLog.addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`, sap_transfer);
108
+ const result = await _create(SAP_HOST_URL, "/AddStockTransfer", sap_transfer);
109
+ // console.log(result);
110
+ try {
111
+ // if (body?._id) {
112
+ // body.integration_meta = body?.integration_meta || {};
113
+ // body.integration_meta.sync_to_sap_succeeded = true;
114
+ // await repzo.transfer.update(body._id, {
115
+ // integration_meta: body.integration_meta,
116
+ // });
117
+ // }
118
+ }
119
+ catch (e) {
120
+ console.error(e);
121
+ }
122
+ await actionLog
123
+ .addDetail(`SAP Responded with `, result)
124
+ .addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`)
125
+ .setStatus("success")
126
+ .setBody(body)
127
+ .commit();
128
+ return result;
161
129
  }
162
- const sap_transfer = {
163
- StockTransferID: body.serial_number.formatted,
164
- SalesPersonCode: repzo_rep
165
- ? repzo_rep.integration_id
166
- : (_m = options.data) === null || _m === void 0
167
- ? void 0
168
- : _m.SalesPersonCode,
169
- FromWarehouse: body.from.code,
170
- ToWarehouse: body.to.code,
171
- RepzoStockTransferLines: variants,
172
- };
173
- // console.dir(sap_transfer, { depth: null });
174
- actionLog.addDetail(
175
- `Repzo => SAP: Transfer - ${repzo_serial_number}`,
176
- sap_transfer
177
- );
178
- const result = await _create(
179
- SAP_HOST_URL,
180
- "/AddStockTransfer",
181
- sap_transfer
182
- );
183
- // console.log(result);
184
- try {
185
- // if (body?._id) {
186
- // body.integration_meta = body?.integration_meta || {};
187
- // body.integration_meta.sync_to_sap_succeeded = true;
188
- // await repzo.transfer.update(body._id, {
189
- // integration_meta: body.integration_meta,
190
- // });
191
- // }
192
- } catch (e) {
193
- console.error(e);
194
- }
195
- await actionLog
196
- .addDetail(`SAP Responded with `, result)
197
- .addDetail(`Repzo => SAP: Transfer - ${repzo_serial_number}`)
198
- .setStatus("success")
199
- .setBody(body)
200
- .commit();
201
- return result;
202
- } catch (e) {
203
- //@ts-ignore
204
- console.error((e === null || e === void 0 ? void 0 : e.response) || e);
205
- await actionLog.setStatus("fail", e).setBody(body).commit();
206
- if (
207
- (_p =
208
- (_o =
209
- options === null || options === void 0 ? void 0 : options.data) ===
210
- null || _o === void 0
211
- ? void 0
212
- : _o.transfers) === null || _p === void 0
213
- ? void 0
214
- : _p.adjustInventoryInFailedTransfer
215
- ) {
216
- send_command_to_marketplace({
217
- command: "adjust_inventory",
218
- app_id: options.app_id,
219
- env: options.env,
220
- repzoApiKey:
221
- (_q = options.data) === null || _q === void 0
222
- ? void 0
223
- : _q.repzoApiKey,
224
- });
130
+ catch (e) {
131
+ //@ts-ignore
132
+ console.error((e === null || e === void 0 ? void 0 : e.response) || e);
133
+ await actionLog.setStatus("fail", e).setBody(body).commit();
134
+ if ((_q = (_p = options === null || options === void 0 ? void 0 : options.data) === null || _p === void 0 ? void 0 : _p.transfers) === null || _q === void 0 ? void 0 : _q.adjustInventoryInFailedTransfer) {
135
+ send_command_to_marketplace({
136
+ command: "adjust_inventory",
137
+ app_id: options.app_id,
138
+ env: options.env,
139
+ repzoApiKey: (_r = options.data) === null || _r === void 0 ? void 0 : _r.repzoApiKey,
140
+ });
141
+ }
142
+ throw e;
225
143
  }
226
- throw e;
227
- }
228
144
  };
@@ -4,28 +4,20 @@ 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
6
  export const actions = async (event, options) => {
7
- var _a, _b;
8
- switch (
9
- (_a = event.queryStringParameters) === null || _a === void 0
10
- ? void 0
11
- : _a.action
12
- ) {
13
- case "create_invoice":
14
- return await create_invoice(event, options);
15
- case "create_return_invoice":
16
- return await create_return_invoice(event, options);
17
- case "create_proforma":
18
- return await create_proforma(event, options);
19
- case "create_payment":
20
- return await create_payment(event, options);
21
- case "create_transfer":
22
- return await create_transfer(event, options);
23
- default:
24
- throw `Route: ${
25
- (_b = event.queryStringParameters) === null || _b === void 0
26
- ? void 0
27
- : _b.action
28
- } not found`;
29
- }
7
+ var _a, _b;
8
+ switch ((_a = event.queryStringParameters) === null || _a === void 0 ? void 0 : _a.action) {
9
+ case "create_invoice":
10
+ return await create_invoice(event, options);
11
+ case "create_return_invoice":
12
+ return await create_return_invoice(event, options);
13
+ case "create_proforma":
14
+ return await create_proforma(event, options);
15
+ case "create_payment":
16
+ return await create_payment(event, options);
17
+ case "create_transfer":
18
+ return await create_transfer(event, options);
19
+ default:
20
+ throw `Route: ${(_b = event.queryStringParameters) === null || _b === void 0 ? void 0 : _b.action} not found`;
21
+ }
30
22
  };
31
23
  export const actionsList = [];
@@ -1,6 +1,4 @@
1
1
  import { CommandEvent, Result } from "../types";
2
- export declare const adjust_inventory: (commandEvent: CommandEvent) => Promise<
3
- Result & {
2
+ export declare const adjust_inventory: (commandEvent: CommandEvent) => Promise<Result & {
4
3
  items_failed: number;
5
- }
6
- >;
4
+ }>;