@shushed/helpers 0.0.220 → 0.0.222
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.
|
@@ -276,7 +276,7 @@ class CentraHelper extends env_1.default {
|
|
|
276
276
|
nextCursor = null;
|
|
277
277
|
}
|
|
278
278
|
if (campaignConnection && campaignConnection.edges?.length) {
|
|
279
|
-
for (let i =
|
|
279
|
+
for (let i = 0; i < campaignConnection.edges.length; i++) {
|
|
280
280
|
const { node } = campaignConnection.edges[i];
|
|
281
281
|
result[node.name] = node;
|
|
282
282
|
}
|
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.RedisConnectionError = exports.RateLimit = exports.setHeaders = exports.BCOrderHelper = exports.DatoHelper = exports.AirtableHelper = exports.CentraHelper = exports.BigQueryHelper = exports.JWKSHelper = exports.CloudTasksHelper = exports.Secrets = exports.SchedulerHelper = exports.Logging = exports.Runtime = exports.PubSubHelper = exports.EnvEngine = exports.validate = void 0;
|
|
20
|
+
exports.SitooHelper = exports.RedisConnectionError = exports.RateLimit = exports.setHeaders = exports.BCOrderHelper = exports.DatoHelper = exports.AirtableHelper = exports.CentraHelper = exports.BigQueryHelper = exports.JWKSHelper = exports.CloudTasksHelper = exports.Secrets = exports.SchedulerHelper = exports.Logging = exports.Runtime = exports.PubSubHelper = exports.EnvEngine = exports.validate = void 0;
|
|
21
21
|
var validate_1 = require("./validate");
|
|
22
22
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } });
|
|
23
23
|
__exportStar(require("./sanitize"), exports);
|
|
@@ -52,3 +52,5 @@ Object.defineProperty(exports, "setHeaders", { enumerable: true, get: function (
|
|
|
52
52
|
var rateLimit_1 = require("./rateLimit");
|
|
53
53
|
Object.defineProperty(exports, "RateLimit", { enumerable: true, get: function () { return __importDefault(rateLimit_1).default; } });
|
|
54
54
|
Object.defineProperty(exports, "RedisConnectionError", { enumerable: true, get: function () { return rateLimit_1.RedisConnectionError; } });
|
|
55
|
+
var sitoo_1 = require("./sitoo");
|
|
56
|
+
Object.defineProperty(exports, "SitooHelper", { enumerable: true, get: function () { return __importDefault(sitoo_1).default; } });
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const lodash_groupby_1 = __importDefault(require("lodash.groupby"));
|
|
8
|
+
const env_1 = __importDefault(require("./env"));
|
|
9
|
+
const SITOO_TR_TYPE_MANUAL_IN = 10;
|
|
10
|
+
const SITOO_TR_TYPE_MANUAL_OUT = 20;
|
|
11
|
+
const BATCH_SIZE = 900;
|
|
12
|
+
class SitooHelper extends env_1.default {
|
|
13
|
+
opts;
|
|
14
|
+
shaToken;
|
|
15
|
+
baseUrl;
|
|
16
|
+
siteId;
|
|
17
|
+
constructor(options, opts) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.opts = opts;
|
|
20
|
+
this.shaToken = crypto_1.default.createHash('sha256').update(opts.accessToken).digest('hex').slice(0, 8);
|
|
21
|
+
this.baseUrl = opts.sitooBaseUrl.replace(/\/$/, '');
|
|
22
|
+
this.siteId = opts.sitooSiteId;
|
|
23
|
+
}
|
|
24
|
+
async getSitooWarehouses() {
|
|
25
|
+
const url = `${this.baseUrl}/sites/${this.siteId}/warehouses.json`;
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: {
|
|
29
|
+
'Authorization': `Basic ${this.opts.accessToken}`,
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
35
|
+
throw new Error(`Sitoo API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
36
|
+
}
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
const nameToId = {};
|
|
39
|
+
const warehouses = {};
|
|
40
|
+
for (const warehouse of data.items) {
|
|
41
|
+
nameToId[warehouse.name] = warehouse.warehouseid;
|
|
42
|
+
warehouses[warehouse.warehouseid] = warehouse;
|
|
43
|
+
}
|
|
44
|
+
return { nameToId, warehouses };
|
|
45
|
+
}
|
|
46
|
+
async fetchWarehouseTransactionsWithFilter(params) {
|
|
47
|
+
const queryParams = new URLSearchParams();
|
|
48
|
+
queryParams.set('num', (params.num || 100).toString());
|
|
49
|
+
if (params.transactiontype !== undefined) {
|
|
50
|
+
queryParams.set('transactiontype', params.transactiontype.toString());
|
|
51
|
+
}
|
|
52
|
+
if (params.datecreatedfrom !== undefined) {
|
|
53
|
+
queryParams.set('datecreatedfrom', params.datecreatedfrom.toString());
|
|
54
|
+
}
|
|
55
|
+
if (params.start !== undefined) {
|
|
56
|
+
queryParams.set('start', params.start.toString());
|
|
57
|
+
}
|
|
58
|
+
queryParams.set('sort', params.ascending ? 'warehousetransactionid' : '-warehousetransactionid');
|
|
59
|
+
const url = `${this.baseUrl}/sites/${this.siteId}/warehouses/${params.warehouseid}/warehousetransactions.json?${queryParams.toString()}`;
|
|
60
|
+
const response = await fetch(url, {
|
|
61
|
+
method: 'GET',
|
|
62
|
+
headers: {
|
|
63
|
+
'Authorization': `Basic ${this.opts.accessToken}`,
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
69
|
+
throw new Error(`Sitoo API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
70
|
+
}
|
|
71
|
+
return await response.json();
|
|
72
|
+
}
|
|
73
|
+
async searchTransactionsInApi(warehouseId, entryNosToFind, transactionType, datecreatedfrom) {
|
|
74
|
+
const found = new Map();
|
|
75
|
+
let lowestTransactionId = undefined;
|
|
76
|
+
if (entryNosToFind.size === 0) {
|
|
77
|
+
return { found, lowestTransactionId };
|
|
78
|
+
}
|
|
79
|
+
let hasMore = true;
|
|
80
|
+
const pageSize = 100;
|
|
81
|
+
const currentDateFrom = datecreatedfrom;
|
|
82
|
+
let currentStart = 0;
|
|
83
|
+
while (hasMore && found.size < entryNosToFind.size) {
|
|
84
|
+
const envelope = await this.fetchWarehouseTransactionsWithFilter({
|
|
85
|
+
warehouseid: warehouseId,
|
|
86
|
+
datecreatedfrom: currentDateFrom,
|
|
87
|
+
transactiontype: transactionType,
|
|
88
|
+
ascending: false,
|
|
89
|
+
num: pageSize,
|
|
90
|
+
start: currentStart,
|
|
91
|
+
});
|
|
92
|
+
const transactions = envelope.items;
|
|
93
|
+
if (transactions.length === 0) {
|
|
94
|
+
hasMore = false;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
for (const transaction of transactions) {
|
|
98
|
+
if (lowestTransactionId === undefined || transaction.warehousetransactionid < lowestTransactionId) {
|
|
99
|
+
lowestTransactionId = transaction.warehousetransactionid;
|
|
100
|
+
}
|
|
101
|
+
if (transaction.description) {
|
|
102
|
+
for (const entryNo of entryNosToFind) {
|
|
103
|
+
if (!found.has(entryNo) && transaction.description.includes(`'${entryNo}'`)) {
|
|
104
|
+
found.set(entryNo, transaction);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (found.size === entryNosToFind.size) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
currentStart = currentStart ? currentStart + transactions.length : transactions.length;
|
|
113
|
+
if (transactions.length < pageSize) {
|
|
114
|
+
hasMore = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { found, lowestTransactionId };
|
|
118
|
+
}
|
|
119
|
+
async batchAddWarehouseTransactions(transactions) {
|
|
120
|
+
if (transactions.length === 0)
|
|
121
|
+
return [];
|
|
122
|
+
if (transactions.length > BATCH_SIZE) {
|
|
123
|
+
throw new Error(`Batch size exceeds maximum of ${BATCH_SIZE}. Got ${transactions.length}`);
|
|
124
|
+
}
|
|
125
|
+
const url = `${this.baseUrl}/sites/${this.siteId}/warehousetransactions.json`;
|
|
126
|
+
const response = await fetch(url, {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
headers: {
|
|
129
|
+
'Authorization': `Basic ${this.opts.accessToken}`,
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
},
|
|
132
|
+
body: JSON.stringify(transactions),
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
136
|
+
throw new Error(`Sitoo API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
137
|
+
}
|
|
138
|
+
const result = await response.json();
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
async syncWarehouseTransactions(items, options) {
|
|
142
|
+
if (items.length === 0) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
const locationCodeToWarehouse = (await this.getSitooWarehouses()).nameToId;
|
|
146
|
+
const foundEntryNos = new Map();
|
|
147
|
+
const results = {};
|
|
148
|
+
const entryNoToIdx = {};
|
|
149
|
+
const entriesByWarehouseAndTransactionType = new Map();
|
|
150
|
+
for (let i = 0; i < items.length; i++) {
|
|
151
|
+
const entry = items[i];
|
|
152
|
+
const warehouseId = locationCodeToWarehouse[entry.location_code];
|
|
153
|
+
const transactionType = entry.type === 'transfer' ? (entry.quantity > 0 ? SITOO_TR_TYPE_MANUAL_IN : SITOO_TR_TYPE_MANUAL_OUT) : undefined;
|
|
154
|
+
entryNoToIdx[entry.entry_no] = i;
|
|
155
|
+
if (transactionType === undefined) {
|
|
156
|
+
results[i] = {
|
|
157
|
+
error: false,
|
|
158
|
+
message: `Not supported transaction type: ${entry.type}`,
|
|
159
|
+
};
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (warehouseId === undefined) {
|
|
163
|
+
results[i] = {
|
|
164
|
+
error: false,
|
|
165
|
+
message: `Not supported warehouse in Sitoo: ${entry.location_code}`,
|
|
166
|
+
};
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const key = `${warehouseId}-${transactionType}`;
|
|
170
|
+
if (!entriesByWarehouseAndTransactionType.has(key)) {
|
|
171
|
+
entriesByWarehouseAndTransactionType.set(key, []);
|
|
172
|
+
}
|
|
173
|
+
entriesByWarehouseAndTransactionType.get(key).push(entry);
|
|
174
|
+
}
|
|
175
|
+
for (const [_, warehouseEntries] of entriesByWarehouseAndTransactionType) {
|
|
176
|
+
if (warehouseEntries.length > 0) {
|
|
177
|
+
let datecreatedfrom = undefined;
|
|
178
|
+
for (const entry of warehouseEntries) {
|
|
179
|
+
const entryCreatedAt = Math.floor(new Date(entry.created_at).getTime() / 1000);
|
|
180
|
+
if (datecreatedfrom === undefined || entryCreatedAt < datecreatedfrom) {
|
|
181
|
+
datecreatedfrom = entryCreatedAt;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const { found: apiFound } = await this.searchTransactionsInApi(locationCodeToWarehouse[warehouseEntries[0].location_code], new Set(warehouseEntries.map(e => e.entry_no.toString())), warehouseEntries[0].quantity > 0 ? SITOO_TR_TYPE_MANUAL_IN : SITOO_TR_TYPE_MANUAL_OUT, datecreatedfrom);
|
|
185
|
+
for (const [entryNo, transaction] of apiFound) {
|
|
186
|
+
foundEntryNos.set(entryNo, transaction.warehousetransactionid);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
for (const [entryNo, transactionId] of foundEntryNos) {
|
|
191
|
+
const idx = entryNoToIdx[entryNo];
|
|
192
|
+
results[idx] = {
|
|
193
|
+
error: false,
|
|
194
|
+
message: `Found transaction in Sitoo: ${transactionId} for the entry ${entryNo}`,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const batches = [[]];
|
|
198
|
+
for (const [_, warehouseEntries] of entriesByWarehouseAndTransactionType) {
|
|
199
|
+
for (let i = 0; i < warehouseEntries.length; i += 1) {
|
|
200
|
+
if (!foundEntryNos.has(warehouseEntries[i].entry_no)) {
|
|
201
|
+
if ((batches[batches.length - 1].length + 1) >= BATCH_SIZE) {
|
|
202
|
+
batches.push([]);
|
|
203
|
+
}
|
|
204
|
+
batches[batches.length - 1].push(warehouseEntries[i]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const hasMissingEntries = batches[0].length > 0;
|
|
209
|
+
if (!options?.preview && hasMissingEntries) {
|
|
210
|
+
for (let i = 0; i < batches.length; i++) {
|
|
211
|
+
const warehouseEntities = (0, lodash_groupby_1.default)(batches[i], e => `${locationCodeToWarehouse[e.location_code]}-${e.quantity > 0 ? 'positive' : 'negative'}`);
|
|
212
|
+
const entryNosInBatches = {};
|
|
213
|
+
const transactionsToCreate = [];
|
|
214
|
+
for (const k in warehouseEntities) {
|
|
215
|
+
const entriesToCreate = warehouseEntities[k];
|
|
216
|
+
const warehouseId = locationCodeToWarehouse[entriesToCreate[0].location_code];
|
|
217
|
+
const entryType = entriesToCreate[0].quantity > 0 ? SITOO_TR_TYPE_MANUAL_IN : SITOO_TR_TYPE_MANUAL_OUT;
|
|
218
|
+
entryNosInBatches[transactionsToCreate.length] = entriesToCreate.map(e => e.entry_no);
|
|
219
|
+
transactionsToCreate.push({
|
|
220
|
+
warehouseid: warehouseId,
|
|
221
|
+
transactiontype: entryType,
|
|
222
|
+
description: entriesToCreate.map(e => `'${e.entry_no}'`).join(', '),
|
|
223
|
+
items: entriesToCreate.map(e => ({
|
|
224
|
+
sku: [e.style_id, e.colour_id, e.size_code].filter(Boolean).join('-'),
|
|
225
|
+
decimalquantity: `${e.quantity.toFixed(3)}`,
|
|
226
|
+
moneypricein: (((e.unit_cost?.value ?? 0) / 100) * e.quantity).toFixed(2),
|
|
227
|
+
})),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const createdIds = await this.batchAddWarehouseTransactions(transactionsToCreate);
|
|
232
|
+
for (let j = 0; j < transactionsToCreate.length; j++) {
|
|
233
|
+
const transactionId = createdIds[j];
|
|
234
|
+
for (let k = 0; k < entryNosInBatches[j].length; k += 1) {
|
|
235
|
+
const entryNo = entryNosInBatches[j][k];
|
|
236
|
+
const idx = entryNoToIdx[entryNo];
|
|
237
|
+
results[idx] = {
|
|
238
|
+
entryNo: entryNo,
|
|
239
|
+
transactionId: transactionId,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
for (const entry of batches[i]) {
|
|
246
|
+
const idx = entryNoToIdx[entry.entry_no];
|
|
247
|
+
results[idx] = error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
for (let i = 0; i < batches.length; i++) {
|
|
254
|
+
for (let j = 0; j < batches[i].length; j += 1) {
|
|
255
|
+
const entry = batches[i][j];
|
|
256
|
+
const idx = entryNoToIdx[entry.entry_no];
|
|
257
|
+
const warehouseId = locationCodeToWarehouse[entry.location_code];
|
|
258
|
+
const transactionType = entry.quantity > 0 ? SITOO_TR_TYPE_MANUAL_IN : SITOO_TR_TYPE_MANUAL_OUT;
|
|
259
|
+
results[idx] = {
|
|
260
|
+
error: false,
|
|
261
|
+
message: `In Preview Mode. ${entry.entry_no} scheduled to be created as transction type: ${transactionType} in the warehouse: ${warehouseId}. Batch: ${i}`
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const resultsAsArray = [];
|
|
267
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
268
|
+
const result = results[i];
|
|
269
|
+
if (!result) {
|
|
270
|
+
resultsAsArray.push(new Error(`${items[i].entry_no} got missed in processing`));
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
resultsAsArray.push(result);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return resultsAsArray;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.default = SitooHelper;
|
package/dist/package.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@google-cloud/firestore": "^7.11.1",
|
|
8
9
|
"@hackylabs/deep-redact": "^2.2.1",
|
|
9
10
|
"ajv": "^8.17.1",
|
|
10
11
|
"ajv-formats": "^3.0.1",
|
|
@@ -12,15 +13,15 @@
|
|
|
12
13
|
"jose": "^6.0.11",
|
|
13
14
|
"lodash.chunk": "^4.2.0",
|
|
14
15
|
"lodash.clonedeep": "^4.5.0",
|
|
16
|
+
"lodash.groupby": "^4.6.0",
|
|
15
17
|
"lodash.isequal": "^4.5.0",
|
|
16
18
|
"lodash.omit": "^4.5.0",
|
|
17
19
|
"lodash.pick": "^4.4.0",
|
|
18
20
|
"mime-types": "^3.0.1",
|
|
19
21
|
"p-limit": "^7.1.1",
|
|
20
22
|
"rate-limiter-flexible": "^7.2.0",
|
|
21
|
-
"uuid": "^11.1.0",
|
|
22
23
|
"redis": "^5.6.0",
|
|
23
|
-
"
|
|
24
|
+
"uuid": "^11.1.0"
|
|
24
25
|
},
|
|
25
26
|
"files": [
|
|
26
27
|
"dist"
|
|
@@ -17,3 +17,4 @@ export { default as setHeaders } from './setHeaders';
|
|
|
17
17
|
export { type CentraError, type CentraErrors, type BasicCentraCountry, type BasicCentraMarket, type BasicCentraSizeChart, type BasicPricelist, type BasicCentraWarehouse, type BasicCentraCampaign, type BasicCentraProduct, type BasicCentraVariant, type BasicCentraDisplay } from './centra';
|
|
18
18
|
export { default as RateLimit, RedisConnectionError } from './rateLimit';
|
|
19
19
|
export { type TriggerOnCreateOptions, type TriggerOnExecuteOptions, type NodeOptions, type RNConfiguration, type TriggerExtraOptions } from './types';
|
|
20
|
+
export { default as SitooHelper, type UnitCost, type StockMovementInput, type BasicSitooWarehouse, type BasicSitooStore, type BasicWarehouseTransaction, type WarehouseTransactionEnvelope, type WarehouseTransactionSyncOptions } from './sitoo';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import EnvEngine from './env';
|
|
2
|
+
import Runtime from './runtime';
|
|
3
|
+
export interface UnitCost {
|
|
4
|
+
value: number;
|
|
5
|
+
decimal_places: number;
|
|
6
|
+
currency: string;
|
|
7
|
+
lcy_value: number;
|
|
8
|
+
lcy_currency: string;
|
|
9
|
+
lcy_decimal_places: number;
|
|
10
|
+
}
|
|
11
|
+
export interface StockMovementInput {
|
|
12
|
+
style_id: string;
|
|
13
|
+
colour_id: string;
|
|
14
|
+
size_code: string;
|
|
15
|
+
location_code: string;
|
|
16
|
+
last_updated_at?: string;
|
|
17
|
+
entry_no: string;
|
|
18
|
+
quantity: number;
|
|
19
|
+
document_no: string;
|
|
20
|
+
external_document_no?: string;
|
|
21
|
+
type: 'transfer' | 'negative adjustment' | 'positive adjustment' | 'purchase' | 'sale';
|
|
22
|
+
unit_cost?: UnitCost;
|
|
23
|
+
document_date?: string;
|
|
24
|
+
posting_date?: string;
|
|
25
|
+
created_at: string;
|
|
26
|
+
}
|
|
27
|
+
export type BasicSitooWarehouse = {
|
|
28
|
+
warehouseid: number;
|
|
29
|
+
warehousetype: string;
|
|
30
|
+
usetype: string;
|
|
31
|
+
storeid: number;
|
|
32
|
+
sellable: boolean;
|
|
33
|
+
name: string;
|
|
34
|
+
externalId: number;
|
|
35
|
+
};
|
|
36
|
+
export type BasicSitooStore = {
|
|
37
|
+
storeid: number;
|
|
38
|
+
name: string;
|
|
39
|
+
externalId: number;
|
|
40
|
+
};
|
|
41
|
+
export type BasicWarehouseTransaction = {
|
|
42
|
+
warehousetransactionid: number;
|
|
43
|
+
warehouseid: number;
|
|
44
|
+
datecreated: number;
|
|
45
|
+
transactiontype: number;
|
|
46
|
+
description: string;
|
|
47
|
+
orderdeliveryid: number | null;
|
|
48
|
+
shipmentid: number | null;
|
|
49
|
+
externalid: string | null;
|
|
50
|
+
reasoncode: string | null;
|
|
51
|
+
items: Array<{
|
|
52
|
+
decimalquantity: string;
|
|
53
|
+
decimaltotal: string;
|
|
54
|
+
moneypricein: string;
|
|
55
|
+
moneytotal: string;
|
|
56
|
+
moneyvalue: string;
|
|
57
|
+
sku: string;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
60
|
+
export type WarehouseTransactionEnvelope = {
|
|
61
|
+
totalcount: number;
|
|
62
|
+
items: BasicWarehouseTransaction[];
|
|
63
|
+
};
|
|
64
|
+
export interface WarehouseTransactionSyncOptions {
|
|
65
|
+
preview?: boolean;
|
|
66
|
+
skuGenerator?: (styleId: string, colourId: string, sizeCode: string) => string;
|
|
67
|
+
}
|
|
68
|
+
export interface WarehouseTransactionSyncResult {
|
|
69
|
+
found: Array<{
|
|
70
|
+
entryNo: string;
|
|
71
|
+
transactionId: number;
|
|
72
|
+
}>;
|
|
73
|
+
missing: string[];
|
|
74
|
+
created: Array<{
|
|
75
|
+
entryNo: string;
|
|
76
|
+
transactionId: number;
|
|
77
|
+
}>;
|
|
78
|
+
errors: Array<{
|
|
79
|
+
entryNo: string;
|
|
80
|
+
error: string;
|
|
81
|
+
}>;
|
|
82
|
+
firestoreUpdated: boolean;
|
|
83
|
+
skipped: Array<{
|
|
84
|
+
entryNo: string;
|
|
85
|
+
reason: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface FirestoreCacheDocument {
|
|
89
|
+
[entryNo: string]: number;
|
|
90
|
+
}
|
|
91
|
+
export default class SitooHelper extends EnvEngine {
|
|
92
|
+
protected opts: {
|
|
93
|
+
accessToken: string;
|
|
94
|
+
sitooBaseUrl: string;
|
|
95
|
+
sitooSiteId: number;
|
|
96
|
+
};
|
|
97
|
+
shaToken: string;
|
|
98
|
+
baseUrl: string;
|
|
99
|
+
siteId: number;
|
|
100
|
+
constructor(options: ConstructorParameters<typeof Runtime>[0], opts: {
|
|
101
|
+
accessToken: string;
|
|
102
|
+
sitooBaseUrl: string;
|
|
103
|
+
sitooSiteId: number;
|
|
104
|
+
});
|
|
105
|
+
getSitooWarehouses(): Promise<{
|
|
106
|
+
nameToId: Record<string, number>;
|
|
107
|
+
warehouses: Record<number, BasicSitooWarehouse>;
|
|
108
|
+
}>;
|
|
109
|
+
private fetchWarehouseTransactionsWithFilter;
|
|
110
|
+
private searchTransactionsInApi;
|
|
111
|
+
private batchAddWarehouseTransactions;
|
|
112
|
+
syncWarehouseTransactions(items: StockMovementInput[], options?: WarehouseTransactionSyncOptions): Promise<Array<{
|
|
113
|
+
entryNo: string;
|
|
114
|
+
transactionId: number;
|
|
115
|
+
} | Error | {
|
|
116
|
+
error: boolean;
|
|
117
|
+
message: string;
|
|
118
|
+
}>>;
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shushed/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.222",
|
|
4
4
|
"author": "",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@google-cloud/firestore": "^7.11.1",
|
|
8
9
|
"@hackylabs/deep-redact": "^2.2.1",
|
|
9
10
|
"ajv": "^8.17.1",
|
|
10
11
|
"ajv-formats": "^3.0.1",
|
|
@@ -12,15 +13,15 @@
|
|
|
12
13
|
"jose": "^6.0.11",
|
|
13
14
|
"lodash.chunk": "^4.2.0",
|
|
14
15
|
"lodash.clonedeep": "^4.5.0",
|
|
16
|
+
"lodash.groupby": "^4.6.0",
|
|
15
17
|
"lodash.isequal": "^4.5.0",
|
|
16
18
|
"lodash.omit": "^4.5.0",
|
|
17
19
|
"lodash.pick": "^4.4.0",
|
|
18
20
|
"mime-types": "^3.0.1",
|
|
19
21
|
"p-limit": "^7.1.1",
|
|
20
22
|
"rate-limiter-flexible": "^7.2.0",
|
|
21
|
-
"uuid": "^11.1.0",
|
|
22
23
|
"redis": "^5.6.0",
|
|
23
|
-
"
|
|
24
|
+
"uuid": "^11.1.0"
|
|
24
25
|
},
|
|
25
26
|
"files": [
|
|
26
27
|
"dist"
|