@leaddreamer/inventorylogic 0.0.3-beta.75 → 0.0.3-beta.76
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/README.md +36 -21
- package/business/Brands/index.js +0 -0
- package/business/Markups/index.js +1 -1
- package/business/Product/Squarespace.js +83 -47
- package/business/Product/SquarespaceSample.js +4905 -0
- package/business/Product/index.js +54 -43
- package/dist/InventoryLogic.0fde24a4.js +2 -0
- package/dist/InventoryLogic.30338491.js +2 -0
- package/dist/InventoryLogic.54795c52.js +2 -0
- package/dist/InventoryLogic.62b5247c.js +2 -0
- package/dist/InventoryLogic.6479c130.js +2 -0
- package/dist/InventoryLogic.7852e007.js +2 -0
- package/dist/InventoryLogic.78e43b62.js +2 -0
- package/dist/InventoryLogic.7dcc3eeb.js +2 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1185,7 +1185,7 @@ users
|
|
|
1185
1185
|
* [~MarkupsDefault](#module_Markups..MarkupsDefault) : <code>Markups</code>
|
|
1186
1186
|
* [~MaterialDefaultForm](#module_Markups..MaterialDefaultForm) : <code>Material</code>
|
|
1187
1187
|
* [~MarkupsDefaultForm](#module_Markups..MarkupsDefaultForm) : <code>Stage</code>
|
|
1188
|
-
* [~updateMarkups(
|
|
1188
|
+
* [~updateMarkups(markups, parent)](#module_Markups..updateMarkups) ⇒ <code>promise.LineItem</code>
|
|
1189
1189
|
* [~Markups](#module_Markups..Markups) : <code>number</code>
|
|
1190
1190
|
|
|
1191
1191
|
<a name="module_Markups.MaterialChoices"></a>
|
|
@@ -1224,16 +1224,16 @@ users
|
|
|
1224
1224
|
**Read only**: true
|
|
1225
1225
|
<a name="module_Markups..updateMarkups"></a>
|
|
1226
1226
|
|
|
1227
|
-
### Markups~updateMarkups(
|
|
1227
|
+
### Markups~updateMarkups(markups, parent) ⇒ <code>promise.LineItem</code>
|
|
1228
1228
|
writes record back to database. Assumes only Id is valid
|
|
1229
1229
|
|
|
1230
1230
|
**Kind**: inner method of [<code>Markups</code>](#module_Markups)
|
|
1231
1231
|
**Returns**: <code>promise.LineItem</code> - a copy of the data written
|
|
1232
1232
|
|
|
1233
|
-
| Param | Type | Description |
|
|
1234
|
-
| --- | --- | --- |
|
|
1235
|
-
|
|
|
1236
|
-
| parent | <code>Record</code> | minimal record of product, user (or none) this stage belongs to |
|
|
1233
|
+
| Param | Type | Default | Description |
|
|
1234
|
+
| --- | --- | --- | --- |
|
|
1235
|
+
| markups | <code>Markups</code> | | a partially-populated product record for updates |
|
|
1236
|
+
| parent | <code>Record</code> | <code></code> | minimal record of product, user (or none) this stage belongs to |
|
|
1237
1237
|
|
|
1238
1238
|
<a name="module_Markups..Markups"></a>
|
|
1239
1239
|
|
|
@@ -2638,6 +2638,7 @@ Typedefs, constants, support functions and database operations related to Produc
|
|
|
2638
2638
|
|
|
2639
2639
|
|
|
2640
2640
|
* [SquarespaceProduct](#module_SquarespaceProduct)
|
|
2641
|
+
* [~recursiveMapWalk(thisObject, labels)](#module_SquarespaceProduct..recursiveMapWalk)
|
|
2641
2642
|
* [~AttributeList](#module_SquarespaceProduct..AttributeList) : <code>Array.String</code>
|
|
2642
2643
|
* [~AttributeValue](#module_SquarespaceProduct..AttributeValue) : <code>object</code>
|
|
2643
2644
|
* [~ProductImage](#module_SquarespaceProduct..ProductImage) : <code>object</code>
|
|
@@ -2655,6 +2656,18 @@ Typedefs, constants, support functions and database operations related to Produc
|
|
|
2655
2656
|
* [~PhysicalProductVariant](#module_SquarespaceProduct..PhysicalProductVariant) : <code>object</code>
|
|
2656
2657
|
* [~PhysicalProduct](#module_SquarespaceProduct..PhysicalProduct) : <code>object</code>
|
|
2657
2658
|
|
|
2659
|
+
<a name="module_SquarespaceProduct..recursiveMapWalk"></a>
|
|
2660
|
+
|
|
2661
|
+
### SquarespaceProduct~recursiveMapWalk(thisObject, labels)
|
|
2662
|
+
Uses an array of object member labels to insert a value into an object
|
|
2663
|
+
|
|
2664
|
+
**Kind**: inner method of [<code>SquarespaceProduct</code>](#module_SquarespaceProduct)
|
|
2665
|
+
|
|
2666
|
+
| Param | Type |
|
|
2667
|
+
| --- | --- |
|
|
2668
|
+
| thisObject | <code>object</code> |
|
|
2669
|
+
| labels | <code>Array.string</code> |
|
|
2670
|
+
|
|
2658
2671
|
<a name="module_SquarespaceProduct..AttributeList"></a>
|
|
2659
2672
|
|
|
2660
2673
|
### SquarespaceProduct~AttributeList : <code>Array.String</code>
|
|
@@ -2933,19 +2946,23 @@ Creates a new Blank Product
|
|
|
2933
2946
|
|
|
2934
2947
|
### Product~ProductDefault : <code>Product</code>
|
|
2935
2948
|
**Kind**: inner constant of [<code>Product</code>](#module_Product)
|
|
2936
|
-
**Default**: <code>{"
|
|
2949
|
+
**Default**: <code>{"platformIds":"","platformData":"","name":null,"short_name":null,"description":null,"short_description":null,"google_product_category":null,"product_type":null,"brand":"","demographics":"","attributes":"","recipe":"","mediaObject":"","mobileInfo":null,"isVisible":true,"type":"PHYSICAL","seoOptions":"","tags":"","materials":"","patterns":"","URL":null,"urlSlug":null,"variantAttributes":"","variants":""}</code>
|
|
2937
2950
|
**Read only**: true
|
|
2938
2951
|
<a name="module_Product..ProductDataForm"></a>
|
|
2939
2952
|
|
|
2940
2953
|
### Product~ProductDataForm : <code>Product</code>
|
|
2954
|
+
Form to create test data
|
|
2955
|
+
|
|
2941
2956
|
**Kind**: inner constant of [<code>Product</code>](#module_Product)
|
|
2942
2957
|
**Default**: <code>{"Id":"","refPath":null,"name":"","description":"","sku":"","markups":"","projectQ":""}</code>
|
|
2943
2958
|
**Read only**: true
|
|
2944
2959
|
<a name="module_Product..ProductDefaultForm"></a>
|
|
2945
2960
|
|
|
2946
2961
|
### Product~ProductDefaultForm : <code>Product</code>
|
|
2962
|
+
Form to enter MINIMAL product data to start creation
|
|
2963
|
+
|
|
2947
2964
|
**Kind**: inner constant of [<code>Product</code>](#module_Product)
|
|
2948
|
-
**Default**: <code>{"Id":"","refPath":"","name":"text","description":"textarea","sku":"text"
|
|
2965
|
+
**Default**: <code>{"Id":"","refPath":"","name":"text","description":"textarea","sku":"text"}</code>
|
|
2949
2966
|
**Read only**: true
|
|
2950
2967
|
<a name="module_Product..updateProduct"></a>
|
|
2951
2968
|
|
|
@@ -2957,8 +2974,8 @@ writes record back to database. Assumes only Id is valid
|
|
|
2957
2974
|
|
|
2958
2975
|
| Param | Type | Default | Description |
|
|
2959
2976
|
| --- | --- | --- | --- |
|
|
2960
|
-
| product | <code>
|
|
2961
|
-
| user | <code>
|
|
2977
|
+
| product | <code>Product</code> | | a partially-populated product record for updates |
|
|
2978
|
+
| user | <code>User</code> | <code></code> | minimal record of user this product belongs to |
|
|
2962
2979
|
|
|
2963
2980
|
<a name="module_Product..summarizeProduct"></a>
|
|
2964
2981
|
|
|
@@ -3034,6 +3051,8 @@ a Brand Object
|
|
|
3034
3051
|
|
|
3035
3052
|
| Name | Type | Description |
|
|
3036
3053
|
| --- | --- | --- |
|
|
3054
|
+
| Id | <code>string</code> | Database Id of document (redundant for convenience) |
|
|
3055
|
+
| refPath | <code>string</code> | if from database, full path to document |
|
|
3037
3056
|
| aggregateRating | <code>AggregateRatingsValue</code> | |
|
|
3038
3057
|
| logo | <code>URL</code> \| <code>ImageObject</code> | |
|
|
3039
3058
|
| review | <code>ReviewObject</code> | A review of the item. Supersedes reviews |
|
|
@@ -3201,7 +3220,7 @@ Demographics characteristics
|
|
|
3201
3220
|
|
|
3202
3221
|
| Name | Type |
|
|
3203
3222
|
| --- | --- |
|
|
3204
|
-
|
|
|
3223
|
+
| adultOriented | <code>boolean</code> |
|
|
3205
3224
|
| age_group | <code>AgeGroupEnum</code> |
|
|
3206
3225
|
| gender | <code>GenderEnum</code> |
|
|
3207
3226
|
|
|
@@ -3215,9 +3234,9 @@ List of product ID's for various platforms
|
|
|
3215
3234
|
|
|
3216
3235
|
| Name | Type |
|
|
3217
3236
|
| --- | --- |
|
|
3218
|
-
|
|
|
3219
|
-
|
|
|
3220
|
-
|
|
|
3237
|
+
| squarespaceId | <code>Text</code> |
|
|
3238
|
+
| googleMerchantId | <code>Text</code> |
|
|
3239
|
+
| shopifyId | <code>Text</code> |
|
|
3221
3240
|
|
|
3222
3241
|
<a name="module_Product..SquarespaceDataObject"></a>
|
|
3223
3242
|
|
|
@@ -3261,8 +3280,6 @@ List of Platform Specific Data
|
|
|
3261
3280
|
| custom_label_2 | <code>string</code> |
|
|
3262
3281
|
| custom_label_3 | <code>string</code> |
|
|
3263
3282
|
| custom_label_4 | <code>string</code> |
|
|
3264
|
-
| createdOn | <code>Date</code> |
|
|
3265
|
-
| modifiedOn | <code>Date</code> |
|
|
3266
3283
|
|
|
3267
3284
|
<a name="module_Product..VideoImage"></a>
|
|
3268
3285
|
|
|
@@ -3294,7 +3311,7 @@ Media Related Data
|
|
|
3294
3311
|
|
|
3295
3312
|
| Name | Type |
|
|
3296
3313
|
| --- | --- |
|
|
3297
|
-
| images | <code>Array
|
|
3314
|
+
| images | <code>Array.ProductImage</code> |
|
|
3298
3315
|
| video_image | <code>VideoImage</code> |
|
|
3299
3316
|
| virtual_model | <code>VirtualModel</code> |
|
|
3300
3317
|
|
|
@@ -3308,7 +3325,7 @@ variant record (including inventory and pricing)
|
|
|
3308
3325
|
|
|
3309
3326
|
| Name | Type | Description |
|
|
3310
3327
|
| --- | --- | --- |
|
|
3311
|
-
|
|
|
3328
|
+
| platformIds | <code>PlatformIDs</code> | |
|
|
3312
3329
|
| sku | <code>string</code> | |
|
|
3313
3330
|
| image | <code>ProductImage</code> | Image associated with this variant |
|
|
3314
3331
|
| pricing | <code>FullProductPricing</code> | |
|
|
@@ -3335,9 +3352,7 @@ a product record
|
|
|
3335
3352
|
| Id | <code>string</code> | Database Id of document (redundant for convenience) |
|
|
3336
3353
|
| refPath | <code>string</code> | if from database, full path to document |
|
|
3337
3354
|
| platformIds | <code>PlatformIDs</code> | |
|
|
3338
|
-
| platformData | <code>
|
|
3339
|
-
| squarespaceData | <code>SquarespaceDataObject</code> | |
|
|
3340
|
-
| storePageId | <code>Text</code> | |
|
|
3355
|
+
| platformData | <code>PlatformData</code> | |
|
|
3341
3356
|
| name | <code>string</code> | name for the Product |
|
|
3342
3357
|
| short_name | <code>string</code> | name for the Product |
|
|
3343
3358
|
| description | <code>string</code> | Basic description of the product |
|
|
File without changes
|
|
@@ -168,7 +168,7 @@ Forms.Choices[MATERIAL] = MaterialChoices
|
|
|
168
168
|
// record operations
|
|
169
169
|
/**
|
|
170
170
|
* writes record back to database. Assumes only Id is valid
|
|
171
|
-
* @param {
|
|
171
|
+
* @param {Markups} markups a partially-populated product record for updates
|
|
172
172
|
* @param {Record} parent minimal record of product, user (or none) this stage belongs to
|
|
173
173
|
* @returns {promise.LineItem} a copy of the data written
|
|
174
174
|
*/
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
//import { PRODUCT, MARKUPS, ISBN_LENGTH } from "../boilerplate/index.js";
|
|
8
8
|
|
|
9
|
+
//import {SampleJSON, feedSample} from "./SquarespaceSample.js"
|
|
10
|
+
import SampleJSON from './SampleJSON.json' with { type: 'json' };
|
|
11
|
+
import feedSample from './feedSample.json' with { type: 'json' };
|
|
9
12
|
//////////////////////////////////////////////////////////////////////
|
|
10
13
|
// Constants
|
|
11
14
|
|
|
@@ -150,59 +153,92 @@
|
|
|
150
153
|
//////////////////////////////////////////////////////////////////////
|
|
151
154
|
// utilities
|
|
152
155
|
|
|
153
|
-
const
|
|
156
|
+
const SquarespaceVariantMap = {
|
|
157
|
+
"id": {target: "platformIds.SquarespaceId"},
|
|
158
|
+
"sku": {target: "sku"},
|
|
159
|
+
"image": {target: "image"},
|
|
160
|
+
"pricing": {target: "price"},
|
|
161
|
+
"stock": {target: "stock"},
|
|
162
|
+
"attributes": {target: "attributes"},
|
|
163
|
+
"shippingMeasurements": {target: "shippingMeasurements"},
|
|
164
|
+
"gtin": {target: "gtin"},
|
|
165
|
+
"mpn": {target: "mpn"},
|
|
166
|
+
//other fields not used
|
|
167
|
+
};
|
|
154
168
|
|
|
155
169
|
const SquarespaceProductMap = {
|
|
156
|
-
"id": "platformIds.SquarespaceId",
|
|
157
|
-
"type": "
|
|
158
|
-
"name": "name",
|
|
159
|
-
"description": "description",
|
|
160
|
-
"storePageId": "platformData.squarespaceData.storePageId",
|
|
161
|
-
"url": "URL",
|
|
162
|
-
"urlSlug": "urlSlug",
|
|
163
|
-
"images":
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"
|
|
170
|
+
"id": {target: "platformIds.SquarespaceId"},
|
|
171
|
+
"type": {target:"product_type"},
|
|
172
|
+
"name": {target: "name"},
|
|
173
|
+
"description": {target: "description"},
|
|
174
|
+
"storePageId": {target: "platformData.squarespaceData.storePageId"},
|
|
175
|
+
"url": {target: "URL"},
|
|
176
|
+
"urlSlug": {target: "urlSlug"},
|
|
177
|
+
"images": {target: "mediaObject.images"},
|
|
178
|
+
"tags": {target: "attributes.tags"},
|
|
179
|
+
"seoOptions": {target: "seoOptions"},
|
|
180
|
+
"createdOn": {target: "recipe.createdOn"},
|
|
181
|
+
"modifiedOn": {target: "recipe.modifiedOn"},
|
|
182
|
+
"variants": {
|
|
183
|
+
target: "variants",
|
|
184
|
+
formatter: SquarespaceVariantMap
|
|
185
|
+
},
|
|
186
|
+
"variantAttributes": {target: "variantAttributes"},
|
|
187
|
+
"isVisible": {target: "isVisible"},
|
|
173
188
|
};
|
|
174
189
|
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const incomingProduct = JSON.parse(productJSON);
|
|
180
|
-
console.log("incomingProduct");
|
|
181
|
-
console.dir(incomingProduct, {depth: null});
|
|
182
|
-
|
|
183
|
-
let properties = Object.getOwnPropertyNames(incomingProduct);
|
|
184
|
-
console.log("properties: ", properties);
|
|
185
|
-
let storageProduct = properties.reduce((outbound, property) => {
|
|
186
|
-
const formatString = SquarespaceProductMap[property];
|
|
187
|
-
console.log(property, ": ", formatString);
|
|
188
|
-
}, {})
|
|
189
|
-
};
|
|
190
|
+
function JSONtoItemMapping(itemJSON, itemMap) {
|
|
191
|
+
const incomingItem = JSON.parse(itemJSON);
|
|
192
|
+
return ItemToItemMapping(incomingItem, itemMap);
|
|
193
|
+
}
|
|
190
194
|
|
|
191
|
-
|
|
195
|
+
export function JSONProductFeedToItemMapping(feedJSON) {
|
|
196
|
+
const incomingFeed = JSON.parse(feedJSON);
|
|
197
|
+
return incomingFeed.products.map(product => {
|
|
198
|
+
return ItemToItemMapping(product, SquarespaceProductMap);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
192
201
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
function ItemToItemMapping(incomingItem, itemMap) {
|
|
203
|
+
|
|
204
|
+
let properties = Object.getOwnPropertyNames(incomingItem);
|
|
205
|
+
let outputItem = properties.reduce((outbound, property) => {
|
|
206
|
+
const target = itemMap[property]?.target
|
|
207
|
+
const formatter = itemMap[property]?.formatter;
|
|
208
|
+
let saveValue = Array.isArray(incomingItem[property])
|
|
209
|
+
? incomingItem[property].map((entry) => {
|
|
210
|
+
return formatter
|
|
211
|
+
? ItemToItemMapping(entry, formatter)
|
|
212
|
+
: entry;
|
|
213
|
+
})
|
|
214
|
+
: incomingItem[property];
|
|
215
|
+
|
|
216
|
+
const labels = target.split(".");
|
|
217
|
+
return recursiveMapWalk(outbound, labels, saveValue);
|
|
218
|
+
|
|
219
|
+
}, {}) ;
|
|
220
|
+
|
|
221
|
+
return outputItem;
|
|
204
222
|
};
|
|
205
223
|
|
|
206
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Uses an array of object member labels to insert a value into an object
|
|
226
|
+
* @param {object} thisObject
|
|
227
|
+
* @param {Array.string} labels
|
|
228
|
+
*/
|
|
229
|
+
function recursiveMapWalk(thisObject, labels, value) {
|
|
230
|
+
if (labels.length < 1) {
|
|
231
|
+
return value;
|
|
232
|
+
} else {
|
|
233
|
+
const downObject = thisObject[labels[0]] ? thisObject[labels[0]] : {};
|
|
234
|
+
return {
|
|
235
|
+
...thisObject,
|
|
236
|
+
//labels[0] as recursively passed to this level
|
|
237
|
+
[labels[0]]: recursiveMapWalk(downObject, labels.slice(1), value)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
207
241
|
|
|
208
|
-
|
|
242
|
+
export function squarespaceFeedTest () {
|
|
243
|
+
return JSONProductFeedToItemMapping(feedSample);
|
|
244
|
+
}
|