@shushed/helpers 0.0.223-redis-fix-20251222110722 → 0.0.223
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/dist/cjs/contracts/index.js +5 -1
- package/dist/cjs/contracts/purchase-orderline.schema.json +124 -0
- package/dist/cjs/contracts/stock-movement.schema.json +144 -0
- package/dist/cjs/dist-dereferenced/index.js +5 -1
- package/dist/cjs/dist-dereferenced/purchase-orderline.js +4 -0
- package/dist/cjs/dist-dereferenced/stock-movement.js +4 -0
- package/dist/cjs/dist-types/purchase-orderline.js +2 -0
- package/dist/cjs/dist-types/stock-movement.js +2 -0
- package/dist/cjs/src-public/airtable.js +96 -59
- package/dist/cjs/src-public/centra.js +56 -5
- package/dist/cjs/src-public/env.js +3 -6
- package/dist/cjs/src-public/index.js +3 -1
- package/dist/cjs/src-public/sitoo.js +279 -0
- package/dist/package.json +3 -2
- package/dist/types/contracts/index.d.ts +2 -0
- package/dist/types/dist-dereferenced/index.d.ts +2 -0
- package/dist/types/dist-dereferenced/purchase-orderline.d.ts +110 -0
- package/dist/types/dist-dereferenced/stock-movement.d.ts +110 -0
- package/dist/types/dist-types/index.d.ts +2 -0
- package/dist/types/dist-types/purchase-orderline.d.ts +30 -0
- package/dist/types/dist-types/stock-movement.d.ts +30 -0
- package/dist/types/src-public/airtable.d.ts +0 -9
- package/dist/types/src-public/centra.d.ts +3 -0
- package/dist/types/src-public/index.d.ts +1 -0
- package/dist/types/src-public/sitoo.d.ts +119 -0
- package/package.json +4 -3
|
@@ -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.Order = exports.MarketingPref = exports.CustomerSegment = exports.Asset = exports.DevelopmentColour = exports.Category = exports.ProductCategory = exports.Product = exports.ProductDraft = exports.Total = exports.Money = exports.Country = exports.Currency = void 0;
|
|
20
|
+
exports.Order = exports.PurchaseOrderline = exports.StockMovement = exports.MarketingPref = exports.CustomerSegment = exports.Asset = exports.DevelopmentColour = exports.Category = exports.ProductCategory = exports.Product = exports.ProductDraft = exports.Total = exports.Money = exports.Country = exports.Currency = void 0;
|
|
21
21
|
var currency_schema_json_1 = require("./currency.schema.json");
|
|
22
22
|
Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return __importDefault(currency_schema_json_1).default; } });
|
|
23
23
|
var country_schema_json_1 = require("./country.schema.json");
|
|
@@ -42,6 +42,10 @@ var customer_segment_schema_json_1 = require("./customer-segment.schema.json");
|
|
|
42
42
|
Object.defineProperty(exports, "CustomerSegment", { enumerable: true, get: function () { return __importDefault(customer_segment_schema_json_1).default; } });
|
|
43
43
|
var marketing_preferences_schema_json_1 = require("./marketing-preferences.schema.json");
|
|
44
44
|
Object.defineProperty(exports, "MarketingPref", { enumerable: true, get: function () { return __importDefault(marketing_preferences_schema_json_1).default; } });
|
|
45
|
+
var stock_movement_schema_json_1 = require("./stock-movement.schema.json");
|
|
46
|
+
Object.defineProperty(exports, "StockMovement", { enumerable: true, get: function () { return __importDefault(stock_movement_schema_json_1).default; } });
|
|
47
|
+
var purchase_orderline_schema_json_1 = require("./purchase-orderline.schema.json");
|
|
48
|
+
Object.defineProperty(exports, "PurchaseOrderline", { enumerable: true, get: function () { return __importDefault(purchase_orderline_schema_json_1).default; } });
|
|
45
49
|
__exportStar(require("./order"), exports);
|
|
46
50
|
var order_schema_json_1 = require("./order.schema.json");
|
|
47
51
|
Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return __importDefault(order_schema_json_1).default; } });
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://shushed.example.com/stock-move.schema.json",
|
|
4
|
+
"title": "Stock Movement Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"style_id": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"minLength": 1,
|
|
11
|
+
"faker": {
|
|
12
|
+
"custom.style": []
|
|
13
|
+
},
|
|
14
|
+
"description": "Style Code - Example: 000697"
|
|
15
|
+
},
|
|
16
|
+
"colour_id": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1,
|
|
19
|
+
"faker": {
|
|
20
|
+
"custom.color": []
|
|
21
|
+
},
|
|
22
|
+
"description": "Colour Code - Example: 3203"
|
|
23
|
+
},
|
|
24
|
+
"product_id": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"minLength": 1,
|
|
27
|
+
"description": "Combination of style_id and colour_id"
|
|
28
|
+
},
|
|
29
|
+
"size_code": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"minLength": 1,
|
|
32
|
+
"description": "Variant code, e.g., XS, M, XL, ONE, or numeric like 10, 37, 40"
|
|
33
|
+
},
|
|
34
|
+
"sku": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"minLength": 1,
|
|
37
|
+
"description": "Full sku of the product_id + size_code"
|
|
38
|
+
},
|
|
39
|
+
"season_id": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "Code must match format like 'AW20'"
|
|
42
|
+
},
|
|
43
|
+
"drop": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "Code for the drop i.e. AUGUST"
|
|
46
|
+
},
|
|
47
|
+
"document_line_no": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Line number for the document of the Purchase Line"
|
|
50
|
+
},
|
|
51
|
+
"document_no": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"description": "Document No for this purchase line"
|
|
54
|
+
},
|
|
55
|
+
"created_at": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"format": "date-time",
|
|
58
|
+
"description": "Date time of the creation of the record. Preferably creation time of the item ledger entry",
|
|
59
|
+
"faker": {
|
|
60
|
+
"date.between": [
|
|
61
|
+
"2024-01-01T00:00:00.000Z",
|
|
62
|
+
"2025-04-30T00:00:00.000Z"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"location_code": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"description": "Valid location code like 001-DR, JL200, HEADOFFICE"
|
|
69
|
+
},
|
|
70
|
+
"quantity": {
|
|
71
|
+
"type": "number"
|
|
72
|
+
},
|
|
73
|
+
"quantity_received": {
|
|
74
|
+
"type": "number"
|
|
75
|
+
},
|
|
76
|
+
"quantity_to_receive": {
|
|
77
|
+
"type": "number"
|
|
78
|
+
},
|
|
79
|
+
"last_modified_at": {
|
|
80
|
+
"type": "string",
|
|
81
|
+
"format": "date-time",
|
|
82
|
+
"description": "Datetime of the last created_at in the history",
|
|
83
|
+
"faker": {
|
|
84
|
+
"date.between": [
|
|
85
|
+
"2024-01-01T00:00:00.000Z",
|
|
86
|
+
"2025-04-30T00:00:00.000Z"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"expected_date": {
|
|
91
|
+
"type": "string",
|
|
92
|
+
"format": "date-time",
|
|
93
|
+
"description": "Datetime of item expected date in the inventory. Since the day is expected always keep to the ISO 00:00 of any day",
|
|
94
|
+
"faker": {
|
|
95
|
+
"date.between": [
|
|
96
|
+
"2024-01-01T00:00:00.000Z",
|
|
97
|
+
"2025-04-30T00:00:00.000Z"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"unit_price": {
|
|
102
|
+
"oneOf": [
|
|
103
|
+
{
|
|
104
|
+
"$ref": "https://shushed.example.com/money.schema.json"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"type": "null"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"description": "Cost/Price of unit, can be null"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"required": [
|
|
114
|
+
"document_no",
|
|
115
|
+
"document_line_no",
|
|
116
|
+
"style_id",
|
|
117
|
+
"colour_id",
|
|
118
|
+
"size_code",
|
|
119
|
+
"sku",
|
|
120
|
+
"product_id",
|
|
121
|
+
"season_id",
|
|
122
|
+
"drop"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://shushed.example.com/stock-move.schema.json",
|
|
4
|
+
"title": "Stock Movement Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"style_id": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"minLength": 1,
|
|
11
|
+
"faker": {
|
|
12
|
+
"custom.style": []
|
|
13
|
+
},
|
|
14
|
+
"description": "Style Code - Example: 000697"
|
|
15
|
+
},
|
|
16
|
+
"colour_id": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1,
|
|
19
|
+
"faker": {
|
|
20
|
+
"custom.color": []
|
|
21
|
+
},
|
|
22
|
+
"description": "Colour Code - Example: 3203"
|
|
23
|
+
},
|
|
24
|
+
"size_code": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"minLength": 1,
|
|
27
|
+
"description": "Variant code, e.g., XS, M, XL, ONE, or numeric like 10, 37, 40"
|
|
28
|
+
},
|
|
29
|
+
"location_code": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"pattern": "^\\d{3}-[A-Z]+$|^[A-Z]{2,}-?[A-Z]*$|^[A-Z]{2,}\\d{3}$",
|
|
32
|
+
"description": "Valid location code like 001-DR, JL200, HEADOFFICE"
|
|
33
|
+
},
|
|
34
|
+
"source_system": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": [
|
|
37
|
+
"bc",
|
|
38
|
+
"centra",
|
|
39
|
+
"sitoo"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"quantity": {
|
|
43
|
+
"type": "integer",
|
|
44
|
+
"minimum": 0,
|
|
45
|
+
"description": "Quantity of stock available on hand"
|
|
46
|
+
},
|
|
47
|
+
"description": {
|
|
48
|
+
"type": "string"
|
|
49
|
+
},
|
|
50
|
+
"entry_no": {
|
|
51
|
+
"type": "string",
|
|
52
|
+
"description": "BC Entry no. Should be empty for other systems"
|
|
53
|
+
},
|
|
54
|
+
"external_entry_no": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"description": "External Entry no. Might be empty for other systems"
|
|
57
|
+
},
|
|
58
|
+
"document_no": {
|
|
59
|
+
"type": "string",
|
|
60
|
+
"description": "BC Document no. Should be empty for other systems"
|
|
61
|
+
},
|
|
62
|
+
"external_document_no": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "Original document i.e. Sitoo ID that caused the change"
|
|
65
|
+
},
|
|
66
|
+
"type": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"enum": [
|
|
69
|
+
"transfer",
|
|
70
|
+
"negative adjustment",
|
|
71
|
+
"positive adjustment",
|
|
72
|
+
"purchase",
|
|
73
|
+
"sale"
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
"unit_cost": {
|
|
77
|
+
"oneOf": [
|
|
78
|
+
{
|
|
79
|
+
"$ref": "https://shushed.example.com/money.schema.json"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"type": "null"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
"description": "Cost per unit, can be null"
|
|
86
|
+
},
|
|
87
|
+
"document_date": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"format": "date",
|
|
90
|
+
"description": "Date of the creation of the document. Preferably creation time of the item ledger entry",
|
|
91
|
+
"faker": {
|
|
92
|
+
"date.between": [
|
|
93
|
+
"2024-01-01",
|
|
94
|
+
"2025-04-30"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"posting_date": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"format": "date",
|
|
101
|
+
"description": "Date of posting the record in BC. This should be empty for non-BC systems. Preferably creation time of the item ledger entry",
|
|
102
|
+
"faker": {
|
|
103
|
+
"date.between": [
|
|
104
|
+
"2024-01-01",
|
|
105
|
+
"2025-04-30"
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"created_at": {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"format": "date-time",
|
|
112
|
+
"description": "Date time of the creation of the record. Preferably creation time of the item ledger entry",
|
|
113
|
+
"faker": {
|
|
114
|
+
"date.between": [
|
|
115
|
+
"2024-01-01T00:00:00.000Z",
|
|
116
|
+
"2025-04-30T00:00:00.000Z"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"last_modified_at": {
|
|
121
|
+
"type": "string",
|
|
122
|
+
"format": "date-time",
|
|
123
|
+
"description": "Datetime of the last created_at in the history",
|
|
124
|
+
"faker": {
|
|
125
|
+
"date.between": [
|
|
126
|
+
"2024-01-01T00:00:00.000Z",
|
|
127
|
+
"2025-04-30T00:00:00.000Z"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"required": [
|
|
133
|
+
"style_id",
|
|
134
|
+
"source_system",
|
|
135
|
+
"location_code",
|
|
136
|
+
"colour_id",
|
|
137
|
+
"size_code",
|
|
138
|
+
"last_modified_at",
|
|
139
|
+
"quantity",
|
|
140
|
+
"created_at",
|
|
141
|
+
"document_date",
|
|
142
|
+
"type"
|
|
143
|
+
]
|
|
144
|
+
}
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Order = exports.Messages = exports.Total = exports.Stock = exports.Product = exports.ProductDraft = exports.ProductCategory = exports.Price = exports.Money = exports.MarketingPreferences = exports.DevelopmentColour = exports.CustomerSegment = exports.Currency = exports.Country = exports.Category = exports.Asset = void 0;
|
|
39
|
+
exports.Order = exports.Messages = exports.Total = exports.Stock = exports.StockMovement = exports.PurchaseOrderline = exports.Product = exports.ProductDraft = exports.ProductCategory = exports.Price = exports.Money = exports.MarketingPreferences = exports.DevelopmentColour = exports.CustomerSegment = exports.Currency = exports.Country = exports.Category = exports.Asset = void 0;
|
|
40
40
|
var asset_1 = require("./asset");
|
|
41
41
|
Object.defineProperty(exports, "Asset", { enumerable: true, get: function () { return __importDefault(asset_1).default; } });
|
|
42
42
|
var category_1 = require("./category");
|
|
@@ -61,6 +61,10 @@ var product_draft_1 = require("./product-draft");
|
|
|
61
61
|
Object.defineProperty(exports, "ProductDraft", { enumerable: true, get: function () { return __importDefault(product_draft_1).default; } });
|
|
62
62
|
var product_1 = require("./product");
|
|
63
63
|
Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return __importDefault(product_1).default; } });
|
|
64
|
+
var purchase_orderline_1 = require("./purchase-orderline");
|
|
65
|
+
Object.defineProperty(exports, "PurchaseOrderline", { enumerable: true, get: function () { return __importDefault(purchase_orderline_1).default; } });
|
|
66
|
+
var stock_movement_1 = require("./stock-movement");
|
|
67
|
+
Object.defineProperty(exports, "StockMovement", { enumerable: true, get: function () { return __importDefault(stock_movement_1).default; } });
|
|
64
68
|
var stock_1 = require("./stock");
|
|
65
69
|
Object.defineProperty(exports, "Stock", { enumerable: true, get: function () { return __importDefault(stock_1).default; } });
|
|
66
70
|
var total_1 = require("./total");
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Stock Movement Schema", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": "string", "minLength": 1 }, "colour_id": { "type": "string", "minLength": 1 }, "product_id": { "type": "string", "minLength": 1 }, "size_code": { "type": "string", "minLength": 1 }, "sku": { "type": "string", "minLength": 1 }, "season_id": { "type": "string" }, "drop": { "type": "string" }, "document_line_no": { "type": "string" }, "document_no": { "type": "string" }, "created_at": { "type": "string", "format": "date-time" }, "location_code": { "type": "string" }, "quantity": { "type": "number" }, "quantity_received": { "type": "number" }, "quantity_to_receive": { "type": "number" }, "last_modified_at": { "type": "string", "format": "date-time" }, "expected_date": { "type": "string", "format": "date-time" }, "unit_price": { "oneOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Money", "type": "object", "additionalProperties": false, "properties": { "value": { "type": "integer", "minimum": 0 }, "decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_value": { "type": "integer", "minimum": 0 }, "lcy_currency": { "title": "LCY Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 } }, "required": ["value", "currency", "lcy_value", "lcy_currency", "decimal_places", "lcy_decimal_places"] }, { "type": "null" }] } }, "required": ["document_no", "document_line_no", "style_id", "colour_id", "size_code", "sku", "product_id", "season_id", "drop"], "$id": "https://shushed.example.com/stock-move.schema.json" };
|
|
4
|
+
exports.default = schema;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Stock Movement Schema", "type": "object", "additionalProperties": false, "properties": { "style_id": { "type": "string", "minLength": 1 }, "colour_id": { "type": "string", "minLength": 1 }, "size_code": { "type": "string", "minLength": 1 }, "location_code": { "type": "string", "pattern": "^\\d{3}-[A-Z]+$|^[A-Z]{2,}-?[A-Z]*$|^[A-Z]{2,}\\d{3}$" }, "source_system": { "type": "string", "enum": ["bc", "centra", "sitoo"] }, "quantity": { "type": "integer", "minimum": 0 }, "entry_no": { "type": "string" }, "external_entry_no": { "type": "string" }, "document_no": { "type": "string" }, "external_document_no": { "type": "string" }, "type": { "type": "string", "enum": ["transfer", "negative adjustment", "positive adjustment", "purchase", "sale"] }, "unit_cost": { "oneOf": [{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Money", "type": "object", "additionalProperties": false, "properties": { "value": { "type": "integer", "minimum": 0 }, "decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 }, "currency": { "title": "Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_value": { "type": "integer", "minimum": 0 }, "lcy_currency": { "title": "LCY Currency", "$schema": "http://json-schema.org/draft-07/schema#", "type": "string", "enum": ["AFN", "ALL", "DZD", "USD", "EUR", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "BTN", "INR", "BOB", "BOV", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLF", "CLP", "CNY", "COP", "COU", "KMF", "CDF", "NZD", "CRC", "CUC", "CUP", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "XDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "XUA", "MXN", "MXV", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "MKD", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLE", "SGD", "XSU", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "CHE", "CHW", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "USN", "UYI", "UYU", "UZS", "VUV", "VEF", "VED", "VND", "YER", "ZMW", "ZWL"] }, "lcy_decimal_places": { "type": "integer", "minimum": 0, "maximum": 4 } }, "required": ["value", "currency", "lcy_value", "lcy_currency", "decimal_places", "lcy_decimal_places"] }, { "type": "null" }] }, "document_date": { "type": "string", "format": "date" }, "posting_date": { "type": "string", "format": "date" }, "created_at": { "type": "string", "format": "date-time" }, "last_modified_at": { "type": "string", "format": "date-time" } }, "required": ["style_id", "source_system", "location_code", "colour_id", "size_code", "last_modified_at", "quantity", "created_at", "document_date", "type"], "$id": "https://shushed.example.com/stock-move.schema.json" };
|
|
4
|
+
exports.default = schema;
|
|
@@ -42,71 +42,107 @@ class AirtableHelper extends runtime_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
return existingRecord;
|
|
44
44
|
}
|
|
45
|
-
async updateMultiple(payload, options = {}
|
|
46
|
-
updatedRecords: [],
|
|
47
|
-
createdRecords: [],
|
|
48
|
-
records: []
|
|
49
|
-
}) {
|
|
45
|
+
async updateMultiple(payload, options = {}) {
|
|
50
46
|
let response = null;
|
|
51
47
|
const tableUrl = `https://api.airtable.com/v0/${this.baseId}/${this.tableId}`;
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return record;
|
|
79
|
-
})
|
|
80
|
-
}),
|
|
48
|
+
const batchSize = 10;
|
|
49
|
+
let collectedResult = {
|
|
50
|
+
updatedRecords: [],
|
|
51
|
+
createdRecords: [],
|
|
52
|
+
records: []
|
|
53
|
+
};
|
|
54
|
+
const fieldsToMergeOn = (options.fieldsToMergeOn || [this.primaryKeyFieldName]);
|
|
55
|
+
const fieldsToMergeOnIds = fieldsToMergeOn.map(x => this.dictionary[x] || x);
|
|
56
|
+
let callIdx = 0;
|
|
57
|
+
const payloadDeduplicated = payload.filter((x, idx, self) => idx === self.findIndex((t) => fieldsToMergeOn.every(field => (0, lodash_isequal_1.default)(t[field], x[field]))));
|
|
58
|
+
const maxCallIdx = Math.ceil(payloadDeduplicated.length / batchSize);
|
|
59
|
+
while (callIdx < maxCallIdx) {
|
|
60
|
+
const currentBatch = payloadDeduplicated.slice(callIdx * batchSize, (callIdx + 1) * batchSize);
|
|
61
|
+
const recordsInBatch = currentBatch.map(x => {
|
|
62
|
+
const recordId = x.$recordId;
|
|
63
|
+
const fieldsWithoutRecordId = { ...x };
|
|
64
|
+
delete fieldsWithoutRecordId.$recordId;
|
|
65
|
+
const record = {
|
|
66
|
+
fields: AirtableHelper.convertToDictionary(this.dictionary, this.primaryKeyWritable === false
|
|
67
|
+
? AirtableHelper.removePrimaryKey(fieldsWithoutRecordId, this.primaryKeyFieldName)
|
|
68
|
+
: fieldsWithoutRecordId),
|
|
69
|
+
};
|
|
70
|
+
if (recordId) {
|
|
71
|
+
record.id = recordId;
|
|
72
|
+
}
|
|
73
|
+
return record;
|
|
81
74
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
try {
|
|
76
|
+
response = await fetch(`${tableUrl}`, {
|
|
77
|
+
method: "PATCH",
|
|
78
|
+
headers: {
|
|
79
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
performUpsert: {
|
|
84
|
+
fieldsToMergeOn: fieldsToMergeOnIds,
|
|
85
|
+
},
|
|
86
|
+
returnFieldsByFieldId: true,
|
|
87
|
+
typecast: options.typecast || false,
|
|
88
|
+
records: recordsInBatch
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok && response) {
|
|
92
|
+
const text = await response.text().catch(() => `${response?.status || 'unknown'}`);
|
|
93
|
+
throw new Error(text);
|
|
94
|
+
}
|
|
95
|
+
const resp = (await response.json());
|
|
96
|
+
collectedResult = {
|
|
97
|
+
updatedRecords: collectedResult.updatedRecords.concat(resp.updatedRecords),
|
|
98
|
+
createdRecords: collectedResult.createdRecords.concat(resp.createdRecords),
|
|
99
|
+
records: collectedResult.records.concat(resp.records.map(x => AirtableHelper.translateFields(this.dictionary, x)))
|
|
100
|
+
};
|
|
85
101
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
catch (err) {
|
|
103
|
+
const errorMessage = `Failed to update records in ${this.tableId} table (baseId: ${this.baseId}). Status: ${response?.status || 'unknown'}. Error: ${err.message}`;
|
|
104
|
+
const batchErrors = currentBatch.map(() => new Error(errorMessage));
|
|
105
|
+
collectedResult = {
|
|
106
|
+
updatedRecords: collectedResult.updatedRecords,
|
|
107
|
+
createdRecords: collectedResult.createdRecords,
|
|
108
|
+
records: collectedResult.records.concat(batchErrors)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
callIdx += 1;
|
|
94
113
|
}
|
|
95
|
-
return nextCollectedResult;
|
|
96
114
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
const resultInOrder = [];
|
|
116
|
+
for (let i = 0; i < payload.length; i++) {
|
|
117
|
+
let j = 0;
|
|
118
|
+
let foundMatchingRecord = null;
|
|
119
|
+
while (j < collectedResult.records.length && foundMatchingRecord === null) {
|
|
120
|
+
let isMatching = true;
|
|
121
|
+
let k = 0;
|
|
122
|
+
while (k < fieldsToMergeOn.length && isMatching) {
|
|
123
|
+
const field = fieldsToMergeOn[k];
|
|
124
|
+
if (!(0, lodash_isequal_1.default)(collectedResult.records[j].fields[field], payload[i][field])) {
|
|
125
|
+
isMatching = false;
|
|
126
|
+
}
|
|
127
|
+
k += 1;
|
|
128
|
+
}
|
|
129
|
+
if (isMatching) {
|
|
130
|
+
foundMatchingRecord = j;
|
|
131
|
+
}
|
|
132
|
+
j += 1;
|
|
133
|
+
}
|
|
134
|
+
if (foundMatchingRecord !== null) {
|
|
135
|
+
resultInOrder.push(collectedResult.records[foundMatchingRecord]);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
resultInOrder.push(new Error(`Record ${payload[i][this.primaryKeyFieldName]} does not match any record in the response`));
|
|
107
139
|
}
|
|
108
|
-
return nextCollectedResult;
|
|
109
140
|
}
|
|
141
|
+
return {
|
|
142
|
+
updatedRecords: collectedResult.updatedRecords,
|
|
143
|
+
createdRecords: collectedResult.createdRecords,
|
|
144
|
+
records: resultInOrder
|
|
145
|
+
};
|
|
110
146
|
}
|
|
111
147
|
async upsert(payload) {
|
|
112
148
|
const existingRecord = await this.getExistingRecord(payload);
|
|
@@ -258,9 +294,10 @@ class AirtableHelper extends runtime_1.default {
|
|
|
258
294
|
const escapeFormulaValue = (value) => {
|
|
259
295
|
return value.replace(/"/g, '\\"');
|
|
260
296
|
};
|
|
297
|
+
const dedupedKeys = keys.filter((x, idx, self) => self.indexOf(x) === idx);
|
|
261
298
|
const batchSize = 50;
|
|
262
|
-
for (let i = 0; i <
|
|
263
|
-
const batch =
|
|
299
|
+
for (let i = 0; i < dedupedKeys.length; i += batchSize) {
|
|
300
|
+
const batch = dedupedKeys.slice(i, i + batchSize);
|
|
264
301
|
const orConditions = batch.map(key => `${this.dictionary[this.primaryKeyFieldName]} = "${escapeFormulaValue(key)}"`).join(', ');
|
|
265
302
|
const formula = `OR(${orConditions})`;
|
|
266
303
|
const records = await this.getExistingRecords(formula);
|