@leaddreamer/inventorylogic 0.0.3-beta.81 → 0.0.3-beta.83
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 +0 -648
- package/business/Product/GoogleMerchantAPI.js +0 -2
- package/business/Utilities/index.js +0 -3
- package/package.json +5 -16
- package/business/Utilities/other.js +0 -404
- package/business/Utilities/promise-queue/index.js +0 -264
- package/business/Utilities/promise-queue/new.js +0 -231
- package/business/Utilities/rate-limited-queue/index.js +0 -127
- package/dist/InventoryLogic.0ac93278.js +0 -35
- package/dist/InventoryLogic.0ac93278.js.map +0 -1
- package/dist/InventoryLogic.31f6d549.js +0 -152
- package/dist/InventoryLogic.31f6d549.js.map +0 -1
- package/dist/InventoryLogic.35827495.js +0 -285
- package/dist/InventoryLogic.35827495.js.map +0 -1
- package/dist/InventoryLogic.37dfff3e.js +0 -72
- package/dist/InventoryLogic.37dfff3e.js.map +0 -1
- package/dist/InventoryLogic.4206cb15.js +0 -213
- package/dist/InventoryLogic.4206cb15.js.map +0 -1
- package/dist/InventoryLogic.44193a77.js +0 -35
- package/dist/InventoryLogic.44193a77.js.map +0 -1
- package/dist/InventoryLogic.46ca6768.js +0 -131
- package/dist/InventoryLogic.46ca6768.js.map +0 -1
- package/dist/InventoryLogic.4d012935.js +0 -151
- package/dist/InventoryLogic.4d012935.js.map +0 -1
- package/dist/InventoryLogic.57f24f5f.js +0 -155
- package/dist/InventoryLogic.57f24f5f.js.map +0 -1
- package/dist/InventoryLogic.59be76a4.js +0 -184
- package/dist/InventoryLogic.59be76a4.js.map +0 -1
- package/dist/InventoryLogic.70925a32.js +0 -375
- package/dist/InventoryLogic.70925a32.js.map +0 -1
- package/dist/InventoryLogic.72fcf301.js +0 -6
- package/dist/InventoryLogic.72fcf301.js.map +0 -1
- package/dist/InventoryLogic.7741caec.js +0 -375
- package/dist/InventoryLogic.7741caec.js.map +0 -1
- package/dist/InventoryLogic.78480e5e.js +0 -152
- package/dist/InventoryLogic.78480e5e.js.map +0 -1
- package/dist/InventoryLogic.80d0e568.js +0 -135
- package/dist/InventoryLogic.80d0e568.js.map +0 -1
- package/dist/InventoryLogic.8a273d2e.js +0 -110
- package/dist/InventoryLogic.8a273d2e.js.map +0 -1
- package/dist/InventoryLogic.8addb055.js +0 -202
- package/dist/InventoryLogic.8addb055.js.map +0 -1
- package/dist/InventoryLogic.9dee46ea.js +0 -6
- package/dist/InventoryLogic.9dee46ea.js.map +0 -1
- package/dist/InventoryLogic.b90f66ea.js +0 -124
- package/dist/InventoryLogic.b90f66ea.js.map +0 -1
- package/dist/InventoryLogic.bb447b4c.js +0 -39
- package/dist/InventoryLogic.bb447b4c.js.map +0 -1
- package/dist/InventoryLogic.d27e84a7.js +0 -75
- package/dist/InventoryLogic.d27e84a7.js.map +0 -1
- package/dist/InventoryLogic.d69ad127.js +0 -217
- package/dist/InventoryLogic.d69ad127.js.map +0 -1
- package/dist/InventoryLogic.e03e6b07.js +0 -245
- package/dist/InventoryLogic.e03e6b07.js.map +0 -1
- package/dist/InventoryLogic.f276f76c.js +0 -213
- package/dist/InventoryLogic.f276f76c.js.map +0 -1
- package/dist/InventoryLogic.f4627c8a.js +0 -160
- package/dist/InventoryLogic.f4627c8a.js.map +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import "./InventoryLogic.9dee46ea.js";
|
|
2
|
-
import $lLPyq$InventoryLogic72fcf301js from "./InventoryLogic.72fcf301.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function $parcel$interopDefault(a) {
|
|
6
|
-
return a && a.__esModule ? a.default : a;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Typedefs, constants, support functions and database operations related to Products
|
|
10
|
-
* @module SquarespaceProduct
|
|
11
|
-
*/ //import { Forms, fillForm } from "@leaddreamer/staticforms";
|
|
12
|
-
//import { PRODUCT, MARKUPS, ISBN_LENGTH } from "../boilerplate/index.js";
|
|
13
|
-
//import {SampleJSON, feedSample} from "./SquarespaceSample.js"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//////////////////////////////////////////////////////////////////////
|
|
17
|
-
// Constants
|
|
18
|
-
/**
|
|
19
|
-
* A list of attributes for a product
|
|
20
|
-
* @typedef {Array.String} AttributeList
|
|
21
|
-
*/ /**
|
|
22
|
-
* Array of attribute name/value pairs
|
|
23
|
-
* @typedef {object} AttributeValue
|
|
24
|
-
* @property {string} AttibuteName attribute name from attribute list
|
|
25
|
-
* @property {string} value value for the particular attribute
|
|
26
|
-
*/ /**
|
|
27
|
-
* Image Descriptor
|
|
28
|
-
* @typedef {object} ProductImage
|
|
29
|
-
* @property {string} altText alt text for the image - SEO etc
|
|
30
|
-
* @property {Array.string} availableFormats Available image sizes.
|
|
31
|
-
* @property {string} id unique id for this productImage
|
|
32
|
-
* @property {integer} orderIndex Position of the image in the product's image list.
|
|
33
|
-
* @property {object} originalSize Image size when first uploaded.
|
|
34
|
-
* @property {string} URL Absolute URL of the image hosted on Squarespace.
|
|
35
|
-
*/ /**
|
|
36
|
-
* Currency Description ISO 4217 currency code
|
|
37
|
-
* @typedef {object} CurrencyDescription
|
|
38
|
-
* @property {string} currencyCode
|
|
39
|
-
* @property {integer} defaultFractionDigits
|
|
40
|
-
* @property {string} displayName
|
|
41
|
-
* @property {string} numericCodeAsString
|
|
42
|
-
* @property {string} symbol
|
|
43
|
-
*/ /**
|
|
44
|
-
* Monetary Value Specification
|
|
45
|
-
* @typedef {object} MonetaryValue
|
|
46
|
-
* @property {CurrencyDescription}
|
|
47
|
-
* @property {decimal} value Decimal monetary value
|
|
48
|
-
*/ /**
|
|
49
|
-
* Pricing Object
|
|
50
|
-
* @typedef {object} FullProductPricing
|
|
51
|
-
* @property {MonetaryValue} basePrice
|
|
52
|
-
* @property {boolean} onSale
|
|
53
|
-
* @property {MonetaryValue} salePrice
|
|
54
|
-
*/ /**
|
|
55
|
-
* @typedef {object} ProductDimensionsUnit
|
|
56
|
-
* @property {Text} name
|
|
57
|
-
* @property {Text} value
|
|
58
|
-
*/ /**
|
|
59
|
-
* Dimensions Object
|
|
60
|
-
* @typedef {object} ProductDimensions
|
|
61
|
-
* @property {float} height
|
|
62
|
-
* @property {float} width
|
|
63
|
-
* @property {float} length
|
|
64
|
-
* @property {ProductDimensionsUnit} unit
|
|
65
|
-
*/ /**
|
|
66
|
-
* @typedef {"KILOGRAM" | "POUND"} ProductWeightUnitEnum
|
|
67
|
-
*/ /**
|
|
68
|
-
* Weight Object
|
|
69
|
-
* @typedef {object} ProductWeight
|
|
70
|
-
* @property {"KILOGRAM" | "POUND"} unit
|
|
71
|
-
* @property {float} value
|
|
72
|
-
*/ /**
|
|
73
|
-
* Measurements of the variant when it's shipped. Present for PHYSICAL products only.
|
|
74
|
-
* @typedef {object} ProductMeasurements
|
|
75
|
-
* @property {ProductDimensions} dimensions
|
|
76
|
-
* @property {ProductWeight} weight
|
|
77
|
-
*/ /**
|
|
78
|
-
* Available stock for the variant. Present for PHYSICAL products only.
|
|
79
|
-
* @typedef {object} ProductStock
|
|
80
|
-
* @property {integer} quantity
|
|
81
|
-
* @property {boolean} unlimited
|
|
82
|
-
*/ /**
|
|
83
|
-
* Meta Information for SEO
|
|
84
|
-
* @typedef {object} MetaData
|
|
85
|
-
* @property {string} title
|
|
86
|
-
* @property {string} description
|
|
87
|
-
*/ /**
|
|
88
|
-
* @typedef {"PHYSICAL" | "SERVICE" | "GIFT_CARD" | "DIGITAL"} ProductTypeV2Enum
|
|
89
|
-
*/ /**
|
|
90
|
-
* variant record (including inventory and pricing)
|
|
91
|
-
* @typedef {object} PhysicalProductVariant
|
|
92
|
-
* @property {Array.AttributeValue} attributes array of attribute/value pairs for a variant
|
|
93
|
-
* @property {string} gtin Global Trade Item Number
|
|
94
|
-
* @property {string} id unique ID for product variant
|
|
95
|
-
* @property {ProductImage} image Image associated with this variant
|
|
96
|
-
* @property {string} mpn manufacturer part number
|
|
97
|
-
* @property {ProductMeasurements} shippingMeasurements
|
|
98
|
-
* @property {string} sku
|
|
99
|
-
* @property {ProductStock} stock
|
|
100
|
-
*/ /**
|
|
101
|
-
* a Square product record
|
|
102
|
-
* @typedef {object} PhysicalProduct
|
|
103
|
-
* @property {dateTime} createdOn
|
|
104
|
-
* @property {?string} id Id of document (redundant for convenience)
|
|
105
|
-
* @property {dateTime} modifiedOn
|
|
106
|
-
* @property {string} storePageId
|
|
107
|
-
* @property {"PHYSICAL" | "SERVICE" | "GIFT_CARD" | "DIGITAL"} type
|
|
108
|
-
* @property {string} description Basic description of the product
|
|
109
|
-
* @property {Array.ProductImage} images Image associated with this variant
|
|
110
|
-
* @property {boolean} isVisible
|
|
111
|
-
* @property {string} name name for the Product
|
|
112
|
-
* @property {MetaData} seoOptions
|
|
113
|
-
* @property {Array.string} tags
|
|
114
|
-
* @property {string} URL
|
|
115
|
-
* @property {string} urlSlug
|
|
116
|
-
* @property {Array.string} variantAttributes
|
|
117
|
-
* @property {Array.PhysicalProductVariant} variants
|
|
118
|
-
*/ //////////////////////////////////////////////////////////////////////
|
|
119
|
-
// business operations
|
|
120
|
-
//////////////////////////////////////////////////////////////////////
|
|
121
|
-
// record operations
|
|
122
|
-
//////////////////////////////////////////////////////////////////////
|
|
123
|
-
// utilities
|
|
124
|
-
const $63eb266a363bf697$var$SquarespaceVariantMap = {
|
|
125
|
-
"id": {
|
|
126
|
-
target: "platformIds.SquarespaceId"
|
|
127
|
-
},
|
|
128
|
-
"sku": {
|
|
129
|
-
target: "sku"
|
|
130
|
-
},
|
|
131
|
-
"image": {
|
|
132
|
-
target: "image"
|
|
133
|
-
},
|
|
134
|
-
"pricing": {
|
|
135
|
-
target: "price"
|
|
136
|
-
},
|
|
137
|
-
"stock": {
|
|
138
|
-
target: "stock"
|
|
139
|
-
},
|
|
140
|
-
"attributes": {
|
|
141
|
-
target: "attributes"
|
|
142
|
-
},
|
|
143
|
-
"shippingMeasurements": {
|
|
144
|
-
target: "shippingMeasurements"
|
|
145
|
-
},
|
|
146
|
-
"gtin": {
|
|
147
|
-
target: "gtin"
|
|
148
|
-
},
|
|
149
|
-
"mpn": {
|
|
150
|
-
target: "mpn"
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const $63eb266a363bf697$var$SquarespaceProductMap = {
|
|
154
|
-
"id": {
|
|
155
|
-
target: "platformIds.SquarespaceId"
|
|
156
|
-
},
|
|
157
|
-
"type": {
|
|
158
|
-
target: "product_type"
|
|
159
|
-
},
|
|
160
|
-
"name": {
|
|
161
|
-
target: "name"
|
|
162
|
-
},
|
|
163
|
-
"description": {
|
|
164
|
-
target: "description"
|
|
165
|
-
},
|
|
166
|
-
"storePageId": {
|
|
167
|
-
target: "platformData.squarespaceData.storePageId"
|
|
168
|
-
},
|
|
169
|
-
"url": {
|
|
170
|
-
target: "URL"
|
|
171
|
-
},
|
|
172
|
-
"urlSlug": {
|
|
173
|
-
target: "urlSlug"
|
|
174
|
-
},
|
|
175
|
-
"images": {
|
|
176
|
-
target: "mediaObject.images"
|
|
177
|
-
},
|
|
178
|
-
"tags": {
|
|
179
|
-
target: "attributes.tags"
|
|
180
|
-
},
|
|
181
|
-
"seoOptions": {
|
|
182
|
-
target: "seoOptions"
|
|
183
|
-
},
|
|
184
|
-
"createdOn": {
|
|
185
|
-
target: "recipe.createdOn"
|
|
186
|
-
},
|
|
187
|
-
"modifiedOn": {
|
|
188
|
-
target: "recipe.modifiedOn"
|
|
189
|
-
},
|
|
190
|
-
"variants": {
|
|
191
|
-
target: "variants",
|
|
192
|
-
formatter: $63eb266a363bf697$var$SquarespaceVariantMap
|
|
193
|
-
},
|
|
194
|
-
"variantAttributes": {
|
|
195
|
-
target: "variantAttributes"
|
|
196
|
-
},
|
|
197
|
-
"isVisible": {
|
|
198
|
-
target: "isVisible"
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
function $63eb266a363bf697$var$JSONtoItemMapping(itemJSON, itemMap) {
|
|
202
|
-
const incomingItem = JSON.parse(itemJSON);
|
|
203
|
-
return $63eb266a363bf697$var$ItemToItemMapping(incomingItem, itemMap);
|
|
204
|
-
}
|
|
205
|
-
function $63eb266a363bf697$export$8f68ab01093b41d6(feedJSON) {
|
|
206
|
-
const incomingFeed = JSON.parse(feedJSON);
|
|
207
|
-
return incomingFeed.products.map((product)=>{
|
|
208
|
-
return $63eb266a363bf697$var$ItemToItemMapping(product, $63eb266a363bf697$var$SquarespaceProductMap);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
function $63eb266a363bf697$var$ItemToItemMapping(incomingItem, itemMap) {
|
|
212
|
-
let properties = Object.getOwnPropertyNames(incomingItem);
|
|
213
|
-
let outputItem = properties.reduce((outbound, property)=>{
|
|
214
|
-
const target = itemMap[property]?.target;
|
|
215
|
-
const formatter = itemMap[property]?.formatter;
|
|
216
|
-
let saveValue = Array.isArray(incomingItem[property]) ? incomingItem[property].map((entry)=>{
|
|
217
|
-
return formatter ? $63eb266a363bf697$var$ItemToItemMapping(entry, formatter) : entry;
|
|
218
|
-
}) : incomingItem[property];
|
|
219
|
-
const labels = target.split(".");
|
|
220
|
-
return $63eb266a363bf697$var$recursiveMapWalk(outbound, labels, saveValue);
|
|
221
|
-
}, {});
|
|
222
|
-
return outputItem;
|
|
223
|
-
}
|
|
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
|
-
*/ function $63eb266a363bf697$var$recursiveMapWalk(thisObject, labels, value) {
|
|
229
|
-
if (labels.length < 1) return value;
|
|
230
|
-
else {
|
|
231
|
-
const downObject = thisObject[labels[0]] ? thisObject[labels[0]] : {};
|
|
232
|
-
return {
|
|
233
|
-
...thisObject,
|
|
234
|
-
//labels[0] as recursively passed to this level
|
|
235
|
-
[labels[0]]: $63eb266a363bf697$var$recursiveMapWalk(downObject, labels.slice(1), value)
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function $63eb266a363bf697$export$c736243f342fb27b() {
|
|
240
|
-
return $63eb266a363bf697$export$8f68ab01093b41d6((0, ($parcel$interopDefault($lLPyq$InventoryLogic72fcf301js))));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
export {$63eb266a363bf697$export$8f68ab01093b41d6 as JSONProductFeedToItemMapping, $63eb266a363bf697$export$c736243f342fb27b as squarespaceFeedTest};
|
|
245
|
-
//# sourceMappingURL=InventoryLogic.e03e6b07.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AAAA;;;CAGC,GACD,6DAA6D;AAE7D,0EAA0E;AAE1E,+DAA+D;;;AAG/D,sEAAsE;AACtE,YAAY;AAEZ;;;CAGC,GAED;;;;;CAKC,GAED;;;;;;;;;CASC,GAED;;;;;;;;CAQC,GAED;;;;;CAKC,GAED;;;;;;CAMC,GAED;;;;CAIC,GAED;;;;;;;CAOC,GAED;;CAEC,GAED;;;;;CAKC,GAED;;;;;CAKC,GAED;;;;;CAKC,GAED;;;;;CAKC,GAED;;CAEC,GAED;;;;;;;;;;;CAWC,GAED;;;;;;;;;;;;;;;;;;CAkBC,GAED,sEAAsE;AACtE,sBAAsB;AAEtB,sEAAsE;AACtE,oBAAoB;AAEpB,sEAAsE;AACtE,YAAY;AAEZ,MAAM,8CAAwB;IAC1B,MAAM;QAAC,QAAQ;IAA2B;IAC1C,OAAO;QAAC,QAAQ;IAAK;IACrB,SAAS;QAAC,QAAQ;IAAO;IACzB,WAAW;QAAC,QAAQ;IAAO;IAC3B,SAAS;QAAC,QAAQ;IAAO;IACzB,cAAc;QAAC,QAAQ;IAAY;IACnC,wBAAwB;QAAC,QAAQ;IAAsB;IACvD,QAAQ;QAAC,QAAQ;IAAM;IACvB,OAAO;QAAC,QAAQ;IAAK;AAEzB;AAEA,MAAM,8CAAwB;IAC1B,MAAM;QAAC,QAAQ;IAA2B;IAC1C,QAAQ;QAAC,QAAO;IAA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,EAAE,MAAM,EAAE,KAAK;IAC/C,IAAI,OAAO,MAAM,GAAG,GAChB,OAAO;SACJ;QACH,MAAM,aAAa,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC;QACpE,OAAO;YACH,GAAG,UAAU;YACb,+CAA+C;YAC/C,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,uCAAiB,YAAY,OAAO,KAAK,CAAC,IAAI;QAC/D;IACJ;AACJ;AAEO,SAAS;IACZ,OAAO,0CAA6B,CAAA,GAAA,0EAAS;AACjD","sources":["business/Product/Squarespace.js"],"sourcesContent":["/**\n * Typedefs, constants, support functions and database operations related to Products\n * @module SquarespaceProduct\n */\n//import { Forms, fillForm } from \"@leaddreamer/staticforms\";\n\n//import { PRODUCT, MARKUPS, ISBN_LENGTH } from \"../boilerplate/index.js\";\n\n//import {SampleJSON, feedSample} from \"./SquarespaceSample.js\"\nimport SampleJSON from './SampleJSON.json' with { type: 'json' };\nimport feedSample from './feedSample.json' with { type: 'json' };\n//////////////////////////////////////////////////////////////////////\n// Constants\n\n/**\n * A list of attributes for a product\n * @typedef {Array.String} AttributeList\n */\n\n/**\n * Array of attribute name/value pairs\n * @typedef {object} AttributeValue\n * @property {string} AttibuteName attribute name from attribute list\n * @property {string} value value for the particular attribute\n */\n\n/**\n * Image Descriptor\n * @typedef {object} ProductImage\n * @property {string} altText alt text for the image - SEO etc\n * @property {Array.string} availableFormats Available image sizes.\n * @property {string} id unique id for this productImage\n * @property {integer} orderIndex Position of the image in the product's image list.\n * @property {object} originalSize Image size when first uploaded.\n * @property {string} URL Absolute URL of the image hosted on Squarespace.\n */\n\n/**\n * Currency Description ISO 4217 currency code\n * @typedef {object} CurrencyDescription\n * @property {string} currencyCode\n * @property {integer} defaultFractionDigits\n * @property {string} displayName\n * @property {string} numericCodeAsString\n * @property {string} symbol\n */\n\n/**\n * Monetary Value Specification\n * @typedef {object} MonetaryValue\n * @property {CurrencyDescription}\n * @property {decimal} value Decimal monetary value\n */\n\n/**\n * Pricing Object\n * @typedef {object} FullProductPricing\n * @property {MonetaryValue} basePrice\n * @property {boolean} onSale\n * @property {MonetaryValue} salePrice\n */\n\n/**\n * @typedef {object} ProductDimensionsUnit\n * @property {Text} name\n * @property {Text} value\n */\n\n/**\n * Dimensions Object\n * @typedef {object} ProductDimensions\n * @property {float} height \n * @property {float} width \n * @property {float} length\n * @property {ProductDimensionsUnit} unit\n */\n\n/**\n * @typedef {\"KILOGRAM\" | \"POUND\"} ProductWeightUnitEnum\n */\n\n/**\n * Weight Object\n * @typedef {object} ProductWeight\n * @property {\"KILOGRAM\" | \"POUND\"} unit\n * @property {float} value\n */\n\n/**\n * Measurements of the variant when it's shipped. Present for PHYSICAL products only.\n * @typedef {object} ProductMeasurements\n * @property {ProductDimensions} dimensions\n * @property {ProductWeight} weight\n */\n\n/**\n * Available stock for the variant. Present for PHYSICAL products only.\n * @typedef {object} ProductStock\n * @property {integer} quantity\n * @property {boolean} unlimited\n */\n\n/**\n * Meta Information for SEO\n * @typedef {object} MetaData\n * @property {string} title\n * @property {string} description\n */\n\n/**\n * @typedef {\"PHYSICAL\" | \"SERVICE\" | \"GIFT_CARD\" | \"DIGITAL\"} ProductTypeV2Enum\n */\n\n/**\n * variant record (including inventory and pricing)\n * @typedef {object} PhysicalProductVariant\n * @property {Array.AttributeValue} attributes array of attribute/value pairs for a variant\n * @property {string} gtin Global Trade Item Number\n * @property {string} id unique ID for product variant\n * @property {ProductImage} image Image associated with this variant\n * @property {string} mpn manufacturer part number\n * @property {ProductMeasurements} shippingMeasurements\n * @property {string} sku\n * @property {ProductStock} stock\n */\n\n/**\n * a Square product record\n * @typedef {object} PhysicalProduct\n * @property {dateTime} createdOn\n * @property {?string} id Id of document (redundant for convenience)\n * @property {dateTime} modifiedOn\n * @property {string} storePageId\n * @property {\"PHYSICAL\" | \"SERVICE\" | \"GIFT_CARD\" | \"DIGITAL\"} type\n * @property {string} description Basic description of the product\n * @property {Array.ProductImage} images Image associated with this variant\n * @property {boolean} isVisible\n * @property {string} name name for the Product\n * @property {MetaData} seoOptions\n * @property {Array.string} tags\n * @property {string} URL\n * @property {string} urlSlug\n * @property {Array.string} variantAttributes\n * @property {Array.PhysicalProductVariant} variants\n */\n\n//////////////////////////////////////////////////////////////////////\n// business operations\n\n//////////////////////////////////////////////////////////////////////\n// record operations\n\n//////////////////////////////////////////////////////////////////////\n// utilities\n\nconst SquarespaceVariantMap = {\n \"id\": {target: \"platformIds.SquarespaceId\"},\n \"sku\": {target: \"sku\"},\n \"image\": {target: \"image\"},\n \"pricing\": {target: \"price\"},\n \"stock\": {target: \"stock\"},\n \"attributes\": {target: \"attributes\"},\n \"shippingMeasurements\": {target: \"shippingMeasurements\"},\n \"gtin\": {target: \"gtin\"},\n \"mpn\": {target: \"mpn\"},\n //other fields not used\n};\n\nconst SquarespaceProductMap = {\n \"id\": {target: \"platformIds.SquarespaceId\"},\n \"type\": {target:\"product_type\"},\n \"name\": {target: \"name\"},\n \"description\": {target: \"description\"},\n \"storePageId\": {target: \"platformData.squarespaceData.storePageId\"},\n \"url\": {target: \"URL\"},\n \"urlSlug\": {target: \"urlSlug\"},\n \"images\": {target: \"mediaObject.images\"},\n \"tags\": {target: \"attributes.tags\"},\n \"seoOptions\": {target: \"seoOptions\"},\n \"createdOn\": {target: \"recipe.createdOn\"},\n \"modifiedOn\": {target: \"recipe.modifiedOn\"},\n \"variants\": {\n target: \"variants\",\n formatter: SquarespaceVariantMap\n },\n \"variantAttributes\": {target: \"variantAttributes\"},\n \"isVisible\": {target: \"isVisible\"},\n};\n\nfunction JSONtoItemMapping(itemJSON, itemMap) {\n const incomingItem = JSON.parse(itemJSON);\n return ItemToItemMapping(incomingItem, itemMap);\n}\n\nexport function JSONProductFeedToItemMapping(feedJSON) {\n const incomingFeed = JSON.parse(feedJSON);\n return incomingFeed.products.map(product => {\n return ItemToItemMapping(product, SquarespaceProductMap);\n });\n}\n\nfunction ItemToItemMapping(incomingItem, itemMap) {\n \n let properties = Object.getOwnPropertyNames(incomingItem);\n let outputItem = properties.reduce((outbound, property) => {\n const target = itemMap[property]?.target\n const formatter = itemMap[property]?.formatter;\n let saveValue = Array.isArray(incomingItem[property])\n ? incomingItem[property].map((entry) => {\n return formatter\n ? ItemToItemMapping(entry, formatter)\n : entry;\n })\n : incomingItem[property];\n\n const labels = target.split(\".\");\n return recursiveMapWalk(outbound, labels, saveValue);\n\n }, {}) ;\n\n return outputItem;\n};\n\n/**\n * Uses an array of object member labels to insert a value into an object\n * @param {object} thisObject \n * @param {Array.string} labels \n */\nfunction recursiveMapWalk(thisObject, labels, value) {\n if (labels.length < 1) {\n return value;\n } else {\n const downObject = thisObject[labels[0]] ? thisObject[labels[0]] : {};\n return {\n ...thisObject,\n //labels[0] as recursively passed to this level\n [labels[0]]: recursiveMapWalk(downObject, labels.slice(1), value)\n };\n }\n};\n\nexport function squarespaceFeedTest () {\n return JSONProductFeedToItemMapping(feedSample);\n}\n"],"names":[],"version":3,"file":"InventoryLogic.e03e6b07.js.map"}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import {USER as $fefa9c41cb73ae0b$export$ff09b90989b21a8, USERS as $fefa9c41cb73ae0b$export$5a898dd3a28f57e9} from "./InventoryLogic.d27e84a7.js";
|
|
2
|
-
import {typedRecordFromChild as $9ab66828811feaa2$export$9536a88c96a1be48} from "./InventoryLogic.31f6d549.js";
|
|
3
|
-
import $5Osbf$lodashclonedeep from "lodash.clonedeep";
|
|
4
|
-
import {deleteRecord as $5Osbf$deleteRecord, writeRecord as $5Osbf$writeRecord, writeBack as $5Osbf$writeBack, collectRecords as $5Osbf$collectRecords, PaginateFetch as $5Osbf$PaginateFetch, documentId as $5Osbf$documentId, fetchRecord as $5Osbf$fetchRecord, collectRecordsByFilter as $5Osbf$collectRecordsByFilter, typedFetchFromChild as $5Osbf$typedFetchFromChild} from "@leaddreamer/firebase-wrapper";
|
|
5
|
-
import {Forms as $5Osbf$Forms} from "@leaddreamer/staticforms";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Typedefs, constants, support functions and database operations related to individual
|
|
9
|
-
* users
|
|
10
|
-
* @module User
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//////////////////////////////////////////////////////////////////////
|
|
17
|
-
// Constants
|
|
18
|
-
/**
|
|
19
|
-
* @typedef {object} UserObject
|
|
20
|
-
* @property {?string} Id Id of document from storage
|
|
21
|
-
* @property {?string} refPath if from database, full path to document
|
|
22
|
-
* @property {!string} first_name could be "Anonymous"
|
|
23
|
-
* @property {?string} last_name
|
|
24
|
-
* @property {boolean} isAnonymous flag indicating auto-generated Anonymous user account
|
|
25
|
-
* @property {url} image URL (possibly in app storage) of User image
|
|
26
|
-
* @property {string} region User home region, from fixed list
|
|
27
|
-
* @property {?url} [social_links] array of user social account links
|
|
28
|
-
* @property {?string} bio user-maintained biography
|
|
29
|
-
* @property {?url} website URL to user user website
|
|
30
|
-
* @property {?string} payment_method summary string of user payment
|
|
31
|
-
* method. Not secure, not source-of-truth
|
|
32
|
-
* @property {?PaymentData} payment when "full account"
|
|
33
|
-
*/ /**
|
|
34
|
-
* @readonly
|
|
35
|
-
* @constant
|
|
36
|
-
* @type {UserObject}
|
|
37
|
-
* @default
|
|
38
|
-
*/ const $aeb56590b68e5483$var$UserDefault = {
|
|
39
|
-
Id: null,
|
|
40
|
-
refPath: null,
|
|
41
|
-
name: null,
|
|
42
|
-
email: null,
|
|
43
|
-
tel: null,
|
|
44
|
-
isAnonymous: true,
|
|
45
|
-
payment_method: null,
|
|
46
|
-
admin_status: null
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* @readonly
|
|
50
|
-
* @constant
|
|
51
|
-
* @type {UserObject}
|
|
52
|
-
* @default
|
|
53
|
-
*/ const $aeb56590b68e5483$var$UserData = {
|
|
54
|
-
Id: `string.uuid`,
|
|
55
|
-
refPath: null,
|
|
56
|
-
name: `person.fullName`,
|
|
57
|
-
email: `internet.email`,
|
|
58
|
-
tel: `phone.number`,
|
|
59
|
-
isAnonymous: `datatype.boolean`,
|
|
60
|
-
payment_method: null,
|
|
61
|
-
admin_status: null
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* @readonly
|
|
65
|
-
* @constant
|
|
66
|
-
* @type {UserObject}
|
|
67
|
-
* @default
|
|
68
|
-
*/ const $aeb56590b68e5483$var$UserDefaultForm = {
|
|
69
|
-
name: "text",
|
|
70
|
-
email: "email",
|
|
71
|
-
tel: "tel"
|
|
72
|
-
};
|
|
73
|
-
(0, $5Osbf$Forms).Base[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = $aeb56590b68e5483$var$UserDefault;
|
|
74
|
-
(0, $5Osbf$Forms).BaseForm[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = $aeb56590b68e5483$var$UserDefaultForm;
|
|
75
|
-
(0, $5Osbf$Forms).AccountForm[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = $aeb56590b68e5483$var$UserDefaultForm;
|
|
76
|
-
(0, $5Osbf$Forms).Data[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = $aeb56590b68e5483$var$UserData;
|
|
77
|
-
(0, $5Osbf$Forms).Summarize[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = $aeb56590b68e5483$export$7822bd6f88cc1494;
|
|
78
|
-
(0, $5Osbf$Forms).SearchBy[0, $fefa9c41cb73ae0b$export$ff09b90989b21a8] = "name";
|
|
79
|
-
async function $aeb56590b68e5483$export$7d0f10f273c0438a(user) {
|
|
80
|
-
return (0, $5Osbf$deleteRecord)(user, (0, $fefa9c41cb73ae0b$export$ff09b90989b21a8));
|
|
81
|
-
}
|
|
82
|
-
async function $aeb56590b68e5483$export$1eb857e02349d4c8(user) {
|
|
83
|
-
if (!user?.Id) return Promise.reject;
|
|
84
|
-
return (0, $5Osbf$deleteRecord)(user, (0, $fefa9c41cb73ae0b$export$ff09b90989b21a8));
|
|
85
|
-
}
|
|
86
|
-
const $aeb56590b68e5483$export$3493b8991d49f558 = (user)=>{
|
|
87
|
-
//need a "no duplicate" function - whatever that means in this context
|
|
88
|
-
return (0, $5Osbf$writeRecord)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8), user);
|
|
89
|
-
};
|
|
90
|
-
async function $aeb56590b68e5483$export$2cccdc7105e5f652(user) {
|
|
91
|
-
let newUser = (0, $5Osbf$lodashclonedeep)((0, $5Osbf$Forms).Base[0, $fefa9c41cb73ae0b$export$5a898dd3a28f57e9]);
|
|
92
|
-
if (user.isAnonymous) //signin anonymous worked
|
|
93
|
-
newUser = {
|
|
94
|
-
...newUser,
|
|
95
|
-
Id: user.uid,
|
|
96
|
-
isAnonymous: true,
|
|
97
|
-
name: "Anonymous"
|
|
98
|
-
};
|
|
99
|
-
else newUser = {
|
|
100
|
-
...newUser,
|
|
101
|
-
Id: user.uid,
|
|
102
|
-
isAnonymous: false,
|
|
103
|
-
name: user?.displayName,
|
|
104
|
-
email: user?.email,
|
|
105
|
-
tel: user?.phoneNumber
|
|
106
|
-
};
|
|
107
|
-
return $aeb56590b68e5483$export$3493b8991d49f558(newUser);
|
|
108
|
-
}
|
|
109
|
-
async function $aeb56590b68e5483$export$3c10411f5368919b(user) {
|
|
110
|
-
// will update just the fields provided
|
|
111
|
-
return (0, $5Osbf$writeBack)({
|
|
112
|
-
...user,
|
|
113
|
-
refPath: `/${(0, $fefa9c41cb73ae0b$export$ff09b90989b21a8)}/${user.Id}`
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
async function $aeb56590b68e5483$export$e3ac7a5d19605772(user) {
|
|
117
|
-
return (0, $5Osbf$writeBack)({
|
|
118
|
-
...user,
|
|
119
|
-
refPath: user?.refPath || `/${0, $fefa9c41cb73ae0b$export$ff09b90989b21a8}/${user.Id}`
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
async function $aeb56590b68e5483$export$e1980ceaf83ba89(Id) {
|
|
123
|
-
let exists = true;
|
|
124
|
-
try {
|
|
125
|
-
await $aeb56590b68e5483$export$6cf10d295bf9320e(Id);
|
|
126
|
-
} catch (err) {
|
|
127
|
-
exists = false;
|
|
128
|
-
}
|
|
129
|
-
return exists;
|
|
130
|
-
}
|
|
131
|
-
async function $aeb56590b68e5483$export$2bb8333a9210be15() {
|
|
132
|
-
return (0, $5Osbf$collectRecords)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8));
|
|
133
|
-
}
|
|
134
|
-
async function $aeb56590b68e5483$export$db873fddb7c8685b(pageSize) {
|
|
135
|
-
return new (0, $5Osbf$PaginateFetch)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8), null, [
|
|
136
|
-
{
|
|
137
|
-
fieldRef: "first_name",
|
|
138
|
-
dirStr: "asc"
|
|
139
|
-
}
|
|
140
|
-
], null, pageSize);
|
|
141
|
-
}
|
|
142
|
-
async function $aeb56590b68e5483$export$8cc74b74b196db4a(pageSize) {
|
|
143
|
-
return new (0, $5Osbf$PaginateFetch)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8), [
|
|
144
|
-
{
|
|
145
|
-
fieldRef: "first_name",
|
|
146
|
-
opStr: "==",
|
|
147
|
-
value: "Anonymous"
|
|
148
|
-
}
|
|
149
|
-
], [
|
|
150
|
-
{
|
|
151
|
-
fieldRef: (0, $5Osbf$documentId),
|
|
152
|
-
dirStr: "asc"
|
|
153
|
-
}
|
|
154
|
-
], null, pageSize);
|
|
155
|
-
}
|
|
156
|
-
async function $aeb56590b68e5483$export$6cf10d295bf9320e(userId) {
|
|
157
|
-
return (0, $5Osbf$fetchRecord)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8), userId);
|
|
158
|
-
}
|
|
159
|
-
async function $aeb56590b68e5483$export$32d6fa31f0d8a28(userId) {
|
|
160
|
-
const user = await $aeb56590b68e5483$export$6cf10d295bf9320e(userId);
|
|
161
|
-
return $aeb56590b68e5483$export$7822bd6f88cc1494(user);
|
|
162
|
-
}
|
|
163
|
-
async function $aeb56590b68e5483$export$53755dbf7eaa9f86(userId) {
|
|
164
|
-
const user = await $aeb56590b68e5483$export$6cf10d295bf9320e($aeb56590b68e5483$export$e1ca85ff667d230a(userId));
|
|
165
|
-
return user.email;
|
|
166
|
-
}
|
|
167
|
-
async function $aeb56590b68e5483$export$85df9b940b8f75fd(userID) {
|
|
168
|
-
const account = $aeb56590b68e5483$export$e1ca85ff667d230a(userID);
|
|
169
|
-
return fetchPayment(account);
|
|
170
|
-
}
|
|
171
|
-
async function $aeb56590b68e5483$export$747404941cf39e5f(email) {
|
|
172
|
-
let them = await (0, $5Osbf$collectRecordsByFilter)((0, $fefa9c41cb73ae0b$export$ff09b90989b21a8), [
|
|
173
|
-
{
|
|
174
|
-
fieldRef: "email",
|
|
175
|
-
opStr: "==",
|
|
176
|
-
value: email
|
|
177
|
-
}
|
|
178
|
-
], null, null);
|
|
179
|
-
//Not at all efficient, but rarely called. If this ends up used for any bulk searches
|
|
180
|
-
//de-normalize the database instead.
|
|
181
|
-
return them;
|
|
182
|
-
}
|
|
183
|
-
async function $aeb56590b68e5483$export$3f848cf621800fba(userIdentifier) {
|
|
184
|
-
let user, payment;
|
|
185
|
-
const userId = userIdentifier.Id ? userIdentifier.Id : userIdentifier;
|
|
186
|
-
user = await $aeb56590b68e5483$export$6cf10d295bf9320e(userId);
|
|
187
|
-
try {
|
|
188
|
-
payment = await fetchPayment(user);
|
|
189
|
-
} catch (err) {
|
|
190
|
-
payment = null; //Just a flag - not really a failure as such
|
|
191
|
-
}
|
|
192
|
-
user.payment = payment;
|
|
193
|
-
return user;
|
|
194
|
-
}
|
|
195
|
-
function $aeb56590b68e5483$export$7822bd6f88cc1494(user) {
|
|
196
|
-
return `${user?.name}`;
|
|
197
|
-
}
|
|
198
|
-
async function $aeb56590b68e5483$export$127de379ac0a4e64(child) {
|
|
199
|
-
return (0, $5Osbf$typedFetchFromChild)(child, (0, $fefa9c41cb73ae0b$export$ff09b90989b21a8));
|
|
200
|
-
}
|
|
201
|
-
function $aeb56590b68e5483$export$e1ca85ff667d230a(userId) {
|
|
202
|
-
return {
|
|
203
|
-
Id: userId,
|
|
204
|
-
refPath: `/${0, $fefa9c41cb73ae0b$export$ff09b90989b21a8}/${userId}`
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function $aeb56590b68e5483$export$a081e2667846200b(child) {
|
|
208
|
-
return (0, $9ab66828811feaa2$export$9536a88c96a1be48)(child, (0, $fefa9c41cb73ae0b$export$ff09b90989b21a8));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
export {$aeb56590b68e5483$export$7822bd6f88cc1494 as summarizeUser, $aeb56590b68e5483$export$7d0f10f273c0438a as deleteUser, $aeb56590b68e5483$export$1eb857e02349d4c8 as deleteUserById, $aeb56590b68e5483$export$3493b8991d49f558 as createUser, $aeb56590b68e5483$export$2cccdc7105e5f652 as buildUserRecords, $aeb56590b68e5483$export$3c10411f5368919b as updateUserByID, $aeb56590b68e5483$export$e3ac7a5d19605772 as updateUser, $aeb56590b68e5483$export$e1980ceaf83ba89 as knownUser, $aeb56590b68e5483$export$6cf10d295bf9320e as fetchUser, $aeb56590b68e5483$export$2bb8333a9210be15 as fetchUsers, $aeb56590b68e5483$export$db873fddb7c8685b as fetchUsersPaginated, $aeb56590b68e5483$export$8cc74b74b196db4a as fetchAnonymousPaginated, $aeb56590b68e5483$export$32d6fa31f0d8a28 as fetchUserName, $aeb56590b68e5483$export$53755dbf7eaa9f86 as fetchUserEmail, $aeb56590b68e5483$export$e1ca85ff667d230a as userFromId, $aeb56590b68e5483$export$85df9b940b8f75fd as fetchUserPaymentById, $aeb56590b68e5483$export$747404941cf39e5f as fetchUserByEmail, $aeb56590b68e5483$export$3f848cf621800fba as fetchFullUser, $aeb56590b68e5483$export$127de379ac0a4e64 as fetchUserFromChild, $aeb56590b68e5483$export$a081e2667846200b as makeUserFromChild};
|
|
213
|
-
//# source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;QACJ,SAAS,CAAC,CAAC,EAAE,GAAA,yCAAK,CAAC,EAAE,QAAQ;IAC/B;AACF;AAMO,SAAS,0CAAkB,KAAK;IACrC,OAAO,CAAA,GAAA,yCAAmB,EAAE,OAAO,CAAA,GAAA,wCAAG;AACxC","sources":["business/User/index.js"],"sourcesContent":["/**\n * Typedefs, constants, support functions and database operations related to individual\n * users\n * @module User\n */\nimport cloneDeep from \"lodash.clonedeep\";\nimport {\n documentId,\n writeRecord,\n writeBack,\n fetchRecord,\n collectRecords,\n collectRecordsByFilter,\n deleteRecord,\n PaginateFetch,\n typedFetchFromChild,\n} from \"@leaddreamer/firebase-wrapper\";\nimport { Forms } from \"@leaddreamer/staticforms\";\n\nimport { USER, USERS } from \"../boilerplate/index.js\";\nimport { typedRecordFromChild } from \"../Utilities/index.js\"\n\n//////////////////////////////////////////////////////////////////////\n// Constants\n\n/**\n * @typedef {object} UserObject\n * @property {?string} Id Id of document from storage\n * @property {?string} refPath if from database, full path to document\n * @property {!string} first_name could be \"Anonymous\"\n * @property {?string} last_name\n * @property {boolean} isAnonymous flag indicating auto-generated Anonymous user account\n * @property {url} image URL (possibly in app storage) of User image\n * @property {string} region User home region, from fixed list\n * @property {?url} [social_links] array of user social account links\n * @property {?string} bio user-maintained biography\n * @property {?url} website URL to user user website\n * @property {?string} payment_method summary string of user payment\n * method. Not secure, not source-of-truth\n * @property {?PaymentData} payment when \"full account\"\n */\n\n/**\n * @readonly\n * @constant\n * @type {UserObject}\n * @default\n */\nconst UserDefault = {\n Id: null,\n refPath: null,\n name: null,\n email: null,\n tel: null,\n isAnonymous: true,\n payment_method: null,\n admin_status: null,\n};\n\n/**\n * @readonly\n * @constant\n * @type {UserObject}\n * @default\n */\nconst UserData = {\n Id: `string.uuid`,\n refPath: null,\n name: `person.fullName`,\n email: `internet.email`,\n tel: `phone.number`,\n isAnonymous: `datatype.boolean`,\n payment_method: null,\n admin_status: null,\n};\n\n/**\n * @readonly\n * @constant\n * @type {UserObject}\n * @default\n */\nconst UserDefaultForm = {\n name: \"text\",\n email: \"email\",\n tel: \"tel\",\n};\n\nForms.Base[USER] = UserDefault;\nForms.BaseForm[USER] = UserDefaultForm;\nForms.AccountForm[USER] = UserDefaultForm;\nForms.Data[USER] = UserData;\nForms.Summarize[USER] = summarizeUser;\nForms.SearchBy[USER] = \"name\";\n\n//////////////////////////////////////////////////////////////////////\n// record operations\n/**\n * @param {UserObject} user\n * @returns {Promise<void>}\n */\nexport async function deleteUser(user) {\n return deleteRecord(user, USER);\n}\n\n/**\n * @param {UserObject} user minimal record of user account\n * @param {!string} user.Id record Id of account\n * @returns {Promise<void>}\n */\nexport async function deleteUserById(user) {\n if (!user?.Id) return Promise.reject;\n\n return deleteRecord(user, USER);\n}\n\n/**\n * @param {UserObject} user minimal record of user account\n * @returns {Promise.UserObject}\n */\nexport const createUser = (user) => {\n //need a \"no duplicate\" function - whatever that means in this context\n return writeRecord(USER, user);\n};\n\n/**\n * Builds a User record from the authentication \"user\" data\n * @param {User} user\n * @param {boolean} user.isAnonymous\n * @param {?string} user.displayName\n * @param {?string} user.photoURL\n * @param {?string} user.email\n * @param {?string} user.phoneNumber\n * @returns {Promise<void>}\n */\nexport async function buildUserRecords(user) {\n let newUser = cloneDeep(Forms.Base[USERS]);\n if (user.isAnonymous) {\n //signin anonymous worked\n newUser = {\n ...newUser,\n Id: user.uid,\n isAnonymous: true,\n name: \"Anonymous\",\n };\n } else {\n newUser = {\n ...newUser,\n Id: user.uid,\n isAnonymous: false,\n name: user?.displayName,\n email: user?.email,\n tel: user?.phoneNumber,\n };\n }\n return createUser(newUser);\n}\n\n/**\n * writes record back to database. Assumes only Id is valid\n * @param {UserObject} user a partially-populated user record for updates\n * @returns {promise.UserObject} a copy of the data written\n */\nexport async function updateUserByID(user) {\n // will update just the fields provided\n return writeBack({\n ...user,\n refPath: `/${USER}/${user.Id}`,\n });\n}\n\n/**\n * writes record back to database. Assumes only Id is valid\n * @param {UserObject} user a p[artially-populated user record for updates]\n * @returns {promise.UserObject} a copy of the data written\n */\nexport async function updateUser(user) {\n return writeBack({\n ...user,\n refPath: user?.refPath || `/${USER}/${user.Id}`,\n });\n}\n\n//////////////////////////////////////////////////////////////////////\n// fetches\n\n/**\n * Checks if this is a known UserObject Id\n * @param {!string} Id Id value to check\n * @returns {Promise.boolean} true is this Id is in database\n */\nexport async function knownUser(Id) {\n let exists = true;\n try {\n await fetchUser(Id);\n } catch (err) {\n exists = false;\n }\n return exists;\n}\n\n//////////////////////////////////////////////////////////////////////\n// fetches\n\n/**\n * Fetches ALL user records. Not very useful\n * @returns {Array.UserObject}\n */\nexport async function fetchUsers() {\n return collectRecords(USER);\n}\n\n/**\n * An object to allow for paginating a table read from Firestore. REQUIRES a sorting choice\n * @typedef {object} PaginatedFetch\n * @property {Query} Query that forms basis for the table read\n * @property {number} limit page size\n * @property {QuerySnapshot} snapshot last successful snapshot/page fetched\n * @property {enum} status status of pagination object\n * @property {method} PageForward pages the fetch forward\n * @property {method} PageBack pages the fetch backward\n\n */\n\n/**\n * Fetchs an object to fetch pages of user data, ascending by name, \"limit\" at a time\n * @param {number} limit\n * @returns {PaginatedFetch} object with pagination methods\n */\n\nexport async function fetchUsersPaginated(pageSize) {\n return new PaginateFetch(\n USER,\n null, //filter\n [{ fieldRef: \"first_name\", dirStr: \"asc\" }], //sort\n null, //ref\n pageSize,\n );\n}\n\n/**\n * Fetchs an object to fetch pages of anonymous user data, ascending by name, \"limit\" at a time\n * @param {number} limit\n * @returns {PaginatedFetch} object with pagination methods\n */\nexport async function fetchAnonymousPaginated(pageSize) {\n return new PaginateFetch(\n USER,\n [{ fieldRef: \"first_name\", opStr: \"==\", value: \"Anonymous\" }], //filter only anonymous users\n [{ fieldRef: documentId, dirStr: \"asc\" }], //sort by uid\n null, //ref\n pageSize,\n );\n}\n\n/**\n * Fetches a single UserObject record by Id\n * @param {!string} userId\n * @returns {Promise.UserObject}\n */\nexport async function fetchUser(userId) {\n return fetchRecord(USER, userId);\n}\n\n/**\n * Fetches and returns the summarized name from a UserObject record\n * @param {!string} userId\n * @returns {Promise.string} the summarized name from the record\n */\nexport async function fetchUserName(userId) {\n const user = await fetchUser(userId);\n return summarizeUser(user);\n}\n\n/**\n * Fetches and returns the email from a UserObject record\n * @param {!string} userId\n * @returns {Promise.string} the email from the record\n */\nexport async function fetchUserEmail(userId) {\n const user = await fetchUser(userFromId(userId));\n return user.email;\n}\n\n/**\n * Fetches the PaymentRecord for a user using just the ID\n * @param {!string} userId\n * @returns {Promise.PaymentData}\n */\nexport async function fetchUserPaymentById(userID) {\n const account = userFromId(userID);\n return fetchPayment(account);\n}\n\n/**\n * Fetch a User record by their email\n * @param {!string} email\n * @returns {Promise.UserObject}\n */\nexport async function fetchUserByEmail(email) {\n let them = await collectRecordsByFilter(\n USER,\n [{ fieldRef: \"email\", opStr: \"==\", value: email }], //filter only anonymous users\n null,\n null,\n );\n //Not at all efficient, but rarely called. If this ends up used for any bulk searches\n //de-normalize the database instead.\n return them;\n}\n\n/**\n * fetches a full user object (address, payment, private, etc) given EITHER\n * just the Id, OR a UserObject\n * @param {string|UserObject} userIdentifier\n * @param {?string} userIdentifier.Id\n * @returns {Promise.UserObject}\n */\nexport async function fetchFullUser(userIdentifier) {\n let user, payment;\n const userId = userIdentifier.Id ? userIdentifier.Id : userIdentifier;\n user = await fetchUser(userId);\n\n try {\n payment = await fetchPayment(user);\n } catch (err) {\n payment = null; //Just a flag - not really a failure as such\n }\n\n user.payment = payment;\n return user;\n}\n\n//////////////////////////////////////////////////////////////////////\n// utilities\n/**\n * Returns a standardized formatted name string\n * @param {UserObject}\n * @returns {string} formatted name string\n */\nexport function summarizeUser(user) {\n return `${user?.name}`;\n}\n\n/**\n * Fetches a UserObject from any child record in any branch\n * @param {RecordDocument} child\n * @returns {Promise.UserObject}\n */\nexport async function fetchUserFromChild(child) {\n return typedFetchFromChild(child, USER);\n}\n\n/**\n * builds a minimal UserObject from an Id\n * @param {!string} userId\n * @returns {UserObject}\n */\nexport function userFromId(userId) {\n return {\n Id: userId,\n refPath: `/${USER}/${userId}`,\n };\n}\n\n/**\n * @param {Record} child a record assumed to be a leaf/child\n * @returns {Record}\n */\nexport function makeUserFromChild(child) {\n return typedRecordFromChild(child, USER);\n}\n"],"names":[],"version":3,"file":"InventoryLogic.f276f76c.js.map"}
|