@leaddreamer/inventorylogic 0.0.3-beta.4 → 0.0.3-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +1604 -9
  2. package/business/Addresses/index.js +181 -0
  3. package/business/BusinessData/index.js +300 -0
  4. package/business/Commodities/index.js +1 -1
  5. package/business/Fundamentals/index.js +184 -0
  6. package/business/LineItem/index.js +2 -2
  7. package/business/Markups/index.js +2 -2
  8. package/business/Payment/index.js +1 -1
  9. package/business/PrivateData/index.js +176 -0
  10. package/business/Product/index.js +160 -17
  11. package/business/User/index.js +2 -2
  12. package/business/Utilities/index.js +3 -1
  13. package/business/Utilities/other.js +469 -0
  14. package/business/Utilities/promise-queue/index.js +231 -0
  15. package/business/Utilities/rate-limited-queue/index.js +127 -0
  16. package/business/boilerplate/index.js +26 -3
  17. package/business/index.js +12 -9
  18. package/business/units/index.js +1 -1
  19. package/dist/InventoryLogic.05ef18c0.js +2 -0
  20. package/dist/InventoryLogic.09daaeaa.js +2 -0
  21. package/dist/InventoryLogic.0b64d0ad.js +2 -0
  22. package/dist/InventoryLogic.0ba84fa7.js +2 -0
  23. package/dist/InventoryLogic.0d599c03.js +2 -0
  24. package/dist/InventoryLogic.137e5482.js +2 -0
  25. package/dist/InventoryLogic.14a7860a.js +2 -0
  26. package/dist/InventoryLogic.14b7f292.js +2 -0
  27. package/dist/InventoryLogic.188504b1.js +2 -0
  28. package/dist/InventoryLogic.196261df.js +2 -0
  29. package/dist/InventoryLogic.1aa3d0be.js +2 -0
  30. package/dist/InventoryLogic.205007e9.js +2 -0
  31. package/dist/InventoryLogic.22a36cc8.js +2 -0
  32. package/dist/InventoryLogic.2433062e.js +2 -0
  33. package/dist/InventoryLogic.2642cf62.js +2 -0
  34. package/dist/InventoryLogic.2e2dcd29.js +2 -0
  35. package/dist/InventoryLogic.30ea2574.js +2 -0
  36. package/dist/InventoryLogic.34455124.js +2 -0
  37. package/dist/InventoryLogic.3675b133.js +2 -0
  38. package/dist/InventoryLogic.3b10ccc5.js +2 -0
  39. package/dist/InventoryLogic.3ccd3412.js +2 -0
  40. package/dist/InventoryLogic.3cd7da47.js +2 -0
  41. package/dist/InventoryLogic.415ac613.js +2 -0
  42. package/dist/InventoryLogic.421e1e7c.js +9 -0
  43. package/dist/InventoryLogic.457956a7.js +2 -0
  44. package/dist/InventoryLogic.48cfeaff.js +2 -0
  45. package/dist/InventoryLogic.4e7559ed.js +2 -0
  46. package/dist/InventoryLogic.50cb471b.js +2 -0
  47. package/dist/InventoryLogic.53279d78.js +2 -0
  48. package/dist/InventoryLogic.58dceea1.js +2 -0
  49. package/dist/InventoryLogic.5a96277c.js +2 -0
  50. package/dist/InventoryLogic.5baab4fe.js +2 -0
  51. package/dist/InventoryLogic.5c08e39a.js +2 -0
  52. package/dist/InventoryLogic.5c885f7a.js +2 -0
  53. package/dist/InventoryLogic.648c0930.js +2 -0
  54. package/dist/InventoryLogic.67c1b155.js +2 -0
  55. package/dist/InventoryLogic.69764b18.js +2 -0
  56. package/dist/InventoryLogic.6f8b7ae0.js +2 -0
  57. package/dist/InventoryLogic.708f773f.js +2 -0
  58. package/dist/InventoryLogic.724cdb7a.js +2 -0
  59. package/dist/InventoryLogic.7407f5ab.js +2 -0
  60. package/dist/InventoryLogic.7559452d.js +2 -0
  61. package/dist/InventoryLogic.81d4c177.js +2 -0
  62. package/dist/InventoryLogic.86caed3d.js +2 -0
  63. package/dist/InventoryLogic.89bc98ac.js +2 -0
  64. package/dist/InventoryLogic.8aa9c9eb.js +2 -0
  65. package/dist/InventoryLogic.926192ec.js +2 -0
  66. package/dist/InventoryLogic.95d27be0.js +2 -0
  67. package/dist/InventoryLogic.9899e841.js +2 -0
  68. package/dist/InventoryLogic.9a4b1e67.js +2 -0
  69. package/dist/InventoryLogic.9b53b460.js +2 -0
  70. package/dist/InventoryLogic.9f07806b.js +2 -0
  71. package/dist/InventoryLogic.a08adebe.js +2 -0
  72. package/dist/InventoryLogic.a4e13ed0.js +2 -0
  73. package/dist/InventoryLogic.ac0345c3.js +9 -0
  74. package/dist/InventoryLogic.aecbeacc.js +2 -0
  75. package/dist/InventoryLogic.b6a32e7a.js +2 -0
  76. package/dist/InventoryLogic.bf7b624e.js +2 -0
  77. package/dist/InventoryLogic.c44fa152.js +2 -0
  78. package/dist/InventoryLogic.c5bdd6e0.js +2 -0
  79. package/dist/InventoryLogic.c72232ce.js +2 -0
  80. package/dist/InventoryLogic.c903d27c.js +2 -0
  81. package/dist/InventoryLogic.caf3c5cd.js +2 -0
  82. package/dist/InventoryLogic.ce72ae5e.js +2 -0
  83. package/dist/InventoryLogic.d14897a2.js +2 -0
  84. package/dist/InventoryLogic.d678c3ae.js +2 -0
  85. package/dist/InventoryLogic.d76d5857.js +2 -0
  86. package/dist/InventoryLogic.dda8477e.js +2 -0
  87. package/dist/InventoryLogic.df1596da.js +2 -0
  88. package/dist/InventoryLogic.e02cbd0d.js +2 -0
  89. package/dist/InventoryLogic.e1a6db03.js +2 -0
  90. package/dist/InventoryLogic.e7e04396.js +2 -0
  91. package/dist/InventoryLogic.e92db878.js +2 -0
  92. package/dist/InventoryLogic.eaecbd8b.js +2 -0
  93. package/dist/InventoryLogic.eed8150d.js +2 -0
  94. package/dist/InventoryLogic.f27b4a7e.js +2 -0
  95. package/dist/InventoryLogic.f27e2dc7.js +2 -0
  96. package/dist/InventoryLogic.f29bd369.js +2 -0
  97. package/dist/InventoryLogic.f3361cdd.js +2 -0
  98. package/dist/InventoryLogic.fb851384.js +2 -0
  99. package/dist/InventoryLogic.fcbfca1e.js +2 -0
  100. package/dist/InventoryLogic.ff65d86c.js +2 -0
  101. package/dist/index.js +2 -0
  102. package/index.js +1 -1
  103. package/package.json +25 -8
@@ -17,7 +17,7 @@ import {
17
17
  } from "@leaddreamer/firebase-wrapper";
18
18
 
19
19
  import { Forms, cleanType } from "@leaddreamer/staticforms";
20
- import { PAYMENT, RECEIPTS, CARDS } from "../boilerplate";
20
+ import { PAYMENT, RECEIPTS, CARDS } from "../boilerplate/index.js";
21
21
 
22
22
  //////////////////////////////////////////////////////////////////////
23
23
  // definitions
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Functions for managing (potentially)private data for a user or organization.
3
+ * Unified structure as a sub-record of fan, organization, or CityManager accounts
4
+ * @module PrivateData
5
+ */
6
+ import {
7
+ fetchRecord,
8
+ typedWrite,
9
+ writeBack,
10
+ deleteRecordByRefPath,
11
+ } from "@leaddreamer/firebase-wrapper";
12
+ import { Forms, fillForm } from "@leaddreamer/staticforms";
13
+ import { PRIVATEDATA, ADDRESSES, USER, MCC } from "../boilerplate/index.js";
14
+ import { fetchAddresses } from "../Addresses/index.js";
15
+
16
+ //////////////////////////////////////////////////////////////////////
17
+ // definitions
18
+
19
+ /**
20
+ * @external AddressType
21
+ */
22
+ /**
23
+ * @typedef {object} contact
24
+ * @property {?string} contact.Id
25
+ * @property {!string} contact.first_name
26
+ * @property {!string} contact.last_name
27
+ * @property {!string} contact.tel
28
+ * @property {?string} contact.email - must be filled in to make profile public
29
+ */
30
+ /**
31
+ * @typedef {object} PrivateData
32
+ * @property {?string} email - must be filled in to make profile public
33
+ * @property {contact} contact
34
+ * @property {!string} tel
35
+ * @property {AddressType} business_address
36
+ * @property {AddressType} mailing_address
37
+ * @property {AddressType} billing_address
38
+ */
39
+ /**
40
+ * @constant
41
+ * @type {PrivateData}
42
+ * @default
43
+ */
44
+ const PrivateDefault = {
45
+ Id: null,
46
+ email: null,
47
+ contact: null,
48
+ business_address: null,
49
+ mailing_address: null,
50
+ billing_address: null,
51
+ tel: null,
52
+ tax_rate: null,
53
+ //tax_id: null,
54
+ openIssues: false,
55
+ };
56
+
57
+ /**
58
+ * @constant
59
+ * @type {PrivateData}
60
+ * @default
61
+ */
62
+ const PrivateAccountForm = {
63
+ refPath: "hidden:text",
64
+ email: "email",
65
+ contact: `object:${USER}`,
66
+ business_address: `lookupLink:${ADDRESSES}`,
67
+ mailing_address: `lookupLink:${ADDRESSES}`,
68
+ billing_address: `lookupLink:${ADDRESSES}`,
69
+ tel: "tel",
70
+ };
71
+
72
+ Forms.Base[PRIVATEDATA] = PrivateDefault;
73
+ Forms.BaseForm[PRIVATEDATA] = PrivateAccountForm;
74
+ Forms.AccountForm[PRIVATEDATA] = PrivateAccountForm;
75
+
76
+ //////////////////////////////////////////////////////////////////////
77
+ // Utilities
78
+
79
+ /**
80
+ * Fecthes the PrivateData (email, tel, addresses, etc) for a Fan account
81
+ * @param {AccountType} account
82
+ * @returns {Promise.PrivateData}
83
+ */
84
+ export async function fetchPrivateData(account) {
85
+ let addresses = [];
86
+ try {
87
+ addresses = await fetchAddresses(account);
88
+ } catch (err) {}
89
+ const addressMap = new Map();
90
+ if (addresses.length) {
91
+ addresses.forEach((address) => {
92
+ addressMap.set(address.Id, address);
93
+ });
94
+ }
95
+
96
+ let privateData = await fetchRecord(
97
+ PRIVATEDATA,
98
+ account.Id,
99
+ account.refPath,
100
+ );
101
+
102
+ let addressEntries = {};
103
+ ["business_address", "billing_address", "mailing_address"].forEach(
104
+ (entry) => {
105
+ const isLink =
106
+ entry && privateData[entry] && !privateData[entry]?.address_line_1;
107
+ if (isLink) {
108
+ addressEntries[entry] = {
109
+ ...addressMap.get(privateData[entry]),
110
+ };
111
+ }
112
+ },
113
+ ); //hacky way to repeat same effort
114
+
115
+ privateData = {
116
+ ...privateData,
117
+ ...addressEntries
118
+ };
119
+
120
+ return privateData;
121
+ }
122
+
123
+ /**
124
+ * @external WriteBatch
125
+ * @typedef {WriteBatch|Transaction|void} ChainType
126
+ */
127
+
128
+ /**
129
+ * @async
130
+ * @function
131
+ * @static
132
+ * Creates the Business information document
133
+ * @param {AccountType} account
134
+ * @param {?ChainType} batch - batching object. Transaction will be added to the batch
135
+ * @returns {Promise<ChainType>} WriteBatch, Transaction or Void
136
+ */
137
+ export async function createPrivateData(account, batch = null) {
138
+ return typedWrite(
139
+ {
140
+ ...Forms.Base[PRIVATEDATA],
141
+ ...fillForm(account, PRIVATEDATA), //sanitize
142
+ }, //data
143
+ account, //parent
144
+ PRIVATEDATA, //type
145
+ batch,
146
+ );
147
+ }
148
+
149
+ /**
150
+ * Writes the "private" data to the database
151
+ * @param {PrivateData} privateData
152
+ * @returns {Promise<PrivateData>}
153
+ */
154
+ export async function savePrivateData(privateData, batch = null) {
155
+ return writeBack(privateData, batch);
156
+ }
157
+
158
+ /**
159
+ * Deletes a PrivateData record (rarely used if ever)
160
+ * @param {PrivateData} privateData
161
+ * @param {!string} privateData.refPath
162
+ * @returns {Promise<void>}
163
+ */
164
+ export async function deletePrivateData(privateData, batch = null) {
165
+ return deleteRecordByRefPath(privateData.refPath, batch);
166
+ }
167
+
168
+ /**
169
+ * creates the "base path" (refPath) to store addresses based on an account (refPath)
170
+ * @param {Record} account
171
+ * @param {!string} account.refPath
172
+ * @returns {string}
173
+ */
174
+ export function privateDataPath(account) {
175
+ return `${account.refPath}/${PRIVATEDATA}/${account.Id}`;
176
+ }
@@ -5,23 +5,148 @@
5
5
  import { updateRecord} from "@leaddreamer/firebase-wrapper";
6
6
  import { Forms, fillForm } from "@leaddreamer/staticforms";
7
7
 
8
- import { PRODUCT, MARKUPS, ISBN_LENGTH } from "../boilerplate";
9
- import { typedRecordFromChild } from "../Utilities"
8
+ import { PRODUCT, MARKUPS, ISBN_LENGTH } from "../boilerplate/index.js";
9
+ import { typedRecordFromChild } from "../Utilities/index.js"
10
10
 
11
11
  //////////////////////////////////////////////////////////////////////
12
12
  // Constants
13
+
14
+ /**
15
+ * "recipe" related values - build-stage markups, product/project Flag, created/modified dates
16
+ * @typedef {object} Recipe_Data
17
+ * @property {module:Markups~Stage} markups
18
+ * @property {boolean} projectQ flag for product/project
19
+ * @property {dateTime} created
20
+ * @property {dateTime} modified
21
+ */
22
+
23
+ /**
24
+ * A list of attributes for a product
25
+ * @typedef {Array.String} AttributeList
26
+ */
27
+
28
+ /**
29
+ * Array of attribute name/value pairs
30
+ * @typedef {object} AttributeValue
31
+ * @property {string} attibuteName attribute name from attribute list
32
+ * @property {string} value value for the particular attribute
33
+ */
34
+
35
+ /**
36
+ * Image Descriptor
37
+ * @typedef {object} ProductImage
38
+ * @property {string} altText alt text for the image - SEO etc
39
+ * @property {Array.string} availableFormats Available image sizes.
40
+ * @property {string} id unique id for this productImage
41
+ * @property {integer} orderIndex Position of the image in the product's image list.
42
+ * @property {object} originalSize Image size when first uploaded.
43
+ * @property {MetaData} seoOptions
44
+ * @property {string} URL Absolute URL of the hosted image.
45
+ */
46
+
47
+ /**
48
+ * Currency Description ISO 4217 currency code
49
+ * @typedef {object} CurrencyDescription
50
+ * @property {string} currencyCode
51
+ * @property {integer} defaultFractionDigits
52
+ * @property {string} displayName
53
+ * @property {string} numericCodeAsString
54
+ * @property {string} symbol
55
+ */
56
+
57
+ /**
58
+ * Monetary Value Specification
59
+ * @typedef {object} MonetaryValue
60
+ * @property {CurrencyDescription}
61
+ * @property {decimal} value Decimal monetary value
62
+ */
63
+
64
+ /**
65
+ * Pricing Object
66
+ * @typedef {object} FullProductPricing
67
+ * @property {MonetaryValue} basePrice
68
+ * @property {boolean} onSale
69
+ * @property {MonetaryValue} salePrice
70
+ */
71
+
72
+ /**
73
+ * Dimensions Object
74
+ * @typedef {object} ProductDimensions
75
+ * @property {float} height
76
+ * @property {float} width
77
+ * @property {float} length
78
+ * @property {text} unit //​ProductDimensionsUnit
79
+ */
80
+
13
81
  /**
14
- * a record
82
+ * Price Object
83
+ * @typedef {object} PriceObject
84
+ *
85
+ */
86
+
87
+ /**
88
+ * Weight Object
89
+ * @typedef {object} ProductWeight
90
+ * @property {text} unit //​ProductWeightUnitEnum
91
+ * @property {float} value
92
+ */
93
+
94
+ /**
95
+ * Measurements of the variant when it's shipped. Present for PHYSICAL products only.
96
+ * @typedef {object} ProductMeasurements
97
+ * @property {ProductDimensions} dimensions
98
+ * @property {ProductWeight} weight
99
+ */
100
+
101
+ /**
102
+ * Available stock for the variant. Present for PHYSICAL products only.
103
+ * @typedef {object} ProductStock
104
+ * @property {integer} quantity
105
+ * @property {boolean} unlimited
106
+ */
107
+
108
+
109
+ /**
110
+ * variant record (including inventory and pricing)
111
+ * @typedef {object} PhysicalProductVariant
112
+ * @property {Array.AttributeValue} attributes array of attribute/value pairs for a variant
113
+ * @property {string} sku
114
+ * @property {string} mpn manufacturer part number
115
+ * @property {string} gtin Global Trade Item Number
116
+ * @property {string} id unique ID for product variant
117
+ * @property {ProductImage} image Image associated with this variant
118
+ * @property {ProductMeasurements} shippingMeasurements
119
+ * @property {ProductStock} stock
120
+ */
121
+
122
+ /**
123
+ * Meta Information for SEO
124
+ * @typedef {object} MetaData
125
+ * @property {string} title
126
+ * @property {string} description
127
+ */
128
+
129
+ /**
130
+ * a product record
15
131
  * @typedef {object} Product
16
- * @property {?string} Id Id of document (redundant for convenience)
132
+ * @property {?string} Id Database Id of document (redundant for convenience)
17
133
  * @property {?string} refPath if from database, full path to document
18
134
  * @property {string} name name for the Product
19
- * @property {string} description
20
- * @property {string} sku
21
- * @property {module:Markups~Stage} markups
22
- * @property {boolean} projectQ flag for product/project
23
- * @property {dateTime} created
24
- * @property {dateTime} modified
135
+ * @property {string} description Basic description of the product
136
+ * @property {Recipe_Data} recipe pricing and fabrication data
137
+ * @property {Array:ImageLinks} image_links
138
+ * @property {text} type //​ProductTypeV2Enum
139
+ * @property {boolean} isVisible
140
+ * @property {MetaData} seoOptions
141
+ * @property {string} name name for the Product
142
+ * @property {MetaData} seoOptions
143
+ * @property {Array.string} tags
144
+ * @property {Array.string} materials
145
+ * @property {Array.string} patterns
146
+ * @property {string} URL
147
+ * @property {string} urlSlug
148
+ * @property {Array.string} variantAttributes
149
+ * @property {Array.PhysicalProductVariant} variants
25
150
  */
26
151
 
27
152
  /**
@@ -31,15 +156,33 @@ import { typedRecordFromChild } from "../Utilities"
31
156
  * @default
32
157
  */
33
158
  const ProductDefault = {
34
- Id: null,
35
- refPath: null,
36
159
  name: `A Product`,
37
160
  description: null,
38
- sku: null,
39
- markups: null,
40
- projectQ: false,
41
- created: null,
42
- modified: null,
161
+ recipe: {
162
+ markups: null,
163
+ projectQ: false,
164
+ created: null,
165
+ modified: null,
166
+ },
167
+ image_links: [],
168
+ type: "",
169
+ google_product_type: "",
170
+ shipping_time: 0,
171
+ condition: "",
172
+ adultQ: false,
173
+ age_group: "adult",
174
+ color: [""],
175
+ material: [""],
176
+ gender: "unisex",
177
+ attributes_gemstones: [""],
178
+ pattern: "",
179
+ size: "",
180
+ weight: 0,
181
+ shippingMeasurements: {
182
+ shipping_length: 0,
183
+ shippin_width: 0,
184
+ shipping_height: 0
185
+ }
43
186
  };
44
187
 
45
188
  /**
@@ -17,8 +17,8 @@ import {
17
17
  } from "@leaddreamer/firebase-wrapper";
18
18
  import { Forms } from "@leaddreamer/staticforms";
19
19
 
20
- import { USER, USERS } from "../boilerplate";
21
- import { typedRecordFromChild } from "../Utilities"
20
+ import { USER, USERS } from "../boilerplate/index.js";
21
+ import { typedRecordFromChild } from "../Utilities/index.js"
22
22
 
23
23
  //////////////////////////////////////////////////////////////////////
24
24
  // Constants
@@ -13,7 +13,7 @@ import {
13
13
  writeRecord,
14
14
  } from "@leaddreamer/firebase-wrapper";
15
15
  import { Forms } from "@leaddreamer/staticforms";
16
- import { ADDRESSES } from "../boilerplate";
16
+ import { ADDRESSES } from "../boilerplate/index.js";
17
17
 
18
18
  //////////////////////////////////////////////////////////////////////
19
19
 
@@ -334,3 +334,5 @@ export function choicesForm(fieldname) {
334
334
  ? Forms.Choices[fieldname]
335
335
  : {};
336
336
  }
337
+
338
+ export * from "./other.js";