@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
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Types and functins for handling addresses
3
+ * @module Addresses
4
+ *
5
+ */
6
+
7
+ import {
8
+ writeRecord,
9
+ writeBack,
10
+ deleteRecord,
11
+ deleteRecordByRefPath,
12
+ collectRecords,
13
+ } from "@leaddreamer/firebase-wrapper";
14
+ import { Forms } from "@leaddreamer/staticforms";
15
+ import { ADDRESSES } from "../boilerplate/index.js";
16
+ import { businessDataPath } from "../BusinessData/index.js";
17
+
18
+ //////////////////////////////////////////////////////////////////////
19
+ //Constants
20
+ /**
21
+ * @typedef {object} AddressType
22
+ * @property {?string} Id - will be populated for existing record; null or
23
+ * missing for new/minimal object
24
+ * @property {?string} refPath - will be populated for existing record; null or
25
+ * missing for new/minimal object
26
+ * @property {string} address_line_1
27
+ * @property {?string} address_line_2
28
+ * @property {string} city
29
+ * @property {string} region - selected from a list of supported Cities/Regions
30
+ * @property {string} state
31
+ * @property {zip} zip
32
+ * @property {?maplink} mapLink - link to Google map location
33
+ */
34
+ /**
35
+ * @constant
36
+ * @type {AddressType}
37
+ * @default
38
+ */
39
+ export const AddressDefault = {
40
+ name: null,
41
+ tel: null,
42
+ address_line_1: null,
43
+ address_line_2: null,
44
+ city: null,
45
+ region: null,
46
+ state: null,
47
+ zip: null,
48
+ maplink: null,
49
+ };
50
+
51
+ /**
52
+ * @constant
53
+ * @type {AddressType}
54
+ * @default
55
+ */
56
+ export const AddressForm = {
57
+ name: "text::6",
58
+ tel: "tel::6",
59
+ address_line_1: "text::6",
60
+ address_line_2: "text::6",
61
+ city: "text::6",
62
+ // region: "lookup:Regions:4",
63
+ state: "text::3",
64
+ zip: "number::3",
65
+ };
66
+
67
+ export const AddressSelectForm = {
68
+ address: `lookupLink:${ADDRESSES}`,
69
+ };
70
+
71
+ /**
72
+ * @typedef {object} MapLink
73
+ * @property {?string} placeId - as defined by Google
74
+ * @property {?object} latlng - coordinates tuple
75
+ * @property {string} latlng.lat - lattitude
76
+ * @property {string} latlng.lng - longitude
77
+ * @property {?string} url - link to place/map entry
78
+ * @property {?string} formatted_address - printable string of address
79
+ */
80
+ /**
81
+ * @readonly
82
+ * @constant
83
+ * @type {MapLink}
84
+ * @default
85
+ */
86
+ export const maplink = {
87
+ placeID: null,
88
+ latlng: {
89
+ lat: null,
90
+ lng: null,
91
+ },
92
+ url: null,
93
+ formatted_address: null,
94
+ };
95
+
96
+ Forms.Base[ADDRESSES] = AddressDefault;
97
+ Forms.BaseForm[ADDRESSES] = AddressForm;
98
+ Forms.AccountForm[ADDRESSES] = AddressForm;
99
+
100
+ /**
101
+ * @external WriteBatch
102
+ * @external Transaction
103
+ * @typedef {WriteBatch|Transaction|void} ChainType
104
+ */
105
+
106
+ //////////////////////////////////////////////////////////////////////
107
+ //Business Logic
108
+
109
+ /**
110
+ * Deletes an existing address record from the database, based on it's own refPath
111
+ * @param {AddressType} address
112
+ * @param {!string} address.refPath
113
+ * @returns {Promise<void>}
114
+ */
115
+ export async function deleteAddress(address) {
116
+ //check for real reacord (i.e. refPath)
117
+ if (!address?.refPath) return null;
118
+ return deleteRecordByRefPath(address.refPath);
119
+ }
120
+
121
+ /**
122
+ * Deletes an existing address record from the database, based on it's parent
123
+ * record and Id
124
+ * @param {!string} addressId
125
+ * @param {OrganizationType} parent
126
+ * @param {!string} parent.refPath
127
+ * @param {ChainType} batch
128
+ * @returns {Promise.ChainType}
129
+ */
130
+ export async function deleteAddressByIdAndParent(
131
+ addressId,
132
+ parent,
133
+ batch = null
134
+ ) {
135
+ //check for real reacord (i.e. refPath)
136
+ return deleteRecord(ADDRESSES, addressId, parent?.refPath, batch);
137
+ }
138
+
139
+ //////////////////////////////////////////////////////////////////////
140
+ //helpers
141
+
142
+ /**
143
+ * Builds a formatted string from a provided address record
144
+ * @param {AddressType} address
145
+ * @returns {string}
146
+ */
147
+ export function formatAddress(address) {
148
+ let formattedString = address
149
+ ? (address.address_line_1 ? address.address_line_1 + ", " : "") +
150
+ (address.address_line_2 ? address.address_line_2 + ", " : "") +
151
+ (address.city ? address.city + ", " : "") +
152
+ (address.state ? address.state + " " : "") +
153
+ (address.zip ? address.zip : "") +
154
+ (address.region ? " ( " + address.region + " )" : "")
155
+ : null;
156
+ return formattedString;
157
+ }
158
+
159
+ /**
160
+ * Saves an address record to the database below the provided parentRefPath,
161
+ * whether exsiting or not
162
+ * @param {AddressType} address
163
+ * @param {?string} address.refPath - if present, writes back
164
+ * @param {string} paraentRefPath - required if new record
165
+ * @returns {Promise<AddressType>}
166
+ */
167
+ export async function saveAddress(address, parentRefPath) {
168
+ return address?.refPath
169
+ ? writeBack(address)
170
+ : writeRecord(ADDRESSES, address, parentRefPath);
171
+ }
172
+
173
+ /**
174
+ * Fetches all address records for an account
175
+ * @param {Record} account
176
+ * @param {!string} account.refPath
177
+ * @returns {Promise<Array.AddressType>}
178
+ */
179
+ export async function fetchAddresses(account) {
180
+ return collectRecords(ADDRESSES, businessDataPath(account));
181
+ }
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Functions for managing (potentially)private data for an organization.
3
+ * Unified structure as a sub-record of organization, or CityManager accounts
4
+ * @module BusinessData
5
+ */
6
+ import {
7
+ fetchRecord,
8
+ writeRecord,
9
+ typedWrite,
10
+ writeBack,
11
+ deleteRecordByRefPath,
12
+ } from "@leaddreamer/firebase-wrapper";
13
+ import {
14
+ BUSINESS,
15
+ BUSINESSDATA,
16
+ BUSINESS_TYPE,
17
+ ADDRESSES,
18
+ USER,
19
+ MCC,
20
+ } from "../boilerplate/index.js";
21
+ import { fetchAddresses } from "../Addresses/index.js";
22
+
23
+ //////////////////////////////////////////////////////////////////////
24
+ // definitions
25
+
26
+ /**
27
+ * @external AddressType
28
+ */
29
+ /**
30
+ * @typedef {object} contact
31
+ * @property {?string} contact.Id
32
+ * @property {!string} contact.first_name
33
+ * @property {!string} contact.last_name
34
+ * @property {!string} contact.tel
35
+ * @property {?string} contact.email - must be filled in to make profile public
36
+ */
37
+ /**
38
+ * @typedef {object} BusinessData
39
+ * @property {?string} email - must be filled in to make profile public
40
+ * @property {contact} contact
41
+ * @property {!string} tel
42
+ * @property {string} business_type
43
+ * @property {AddressType} business_address
44
+ * @property {AddressType} mailing_address
45
+ * @property {AddressType} billing_address
46
+ */
47
+ /**
48
+ * @constant
49
+ * @type {BusinessData}
50
+ * @default
51
+ */
52
+ const BusinessDefault = {
53
+ Id: null,
54
+ email: null,
55
+ business_type: null,
56
+ contact: null,
57
+ business_address: null,
58
+ mailing_address: null,
59
+ billing_address: null,
60
+ tel: null,
61
+ mcc: null,
62
+ tax_rate: null,
63
+ //tax_id: null,
64
+ openIssues: false,
65
+ };
66
+
67
+ /**
68
+ * @constant
69
+ * @type {BusinessData}
70
+ * @default
71
+ */
72
+ const BusinessAccountForm = {
73
+ refPath: "hidden:text",
74
+ email: "email",
75
+ business_type: `lookup:${BUSINESS_TYPE}`,
76
+ contact: `object:${USER}`,
77
+ business_address: `lookupLink:${ADDRESSES}`,
78
+ mailing_address: `lookupLink:${ADDRESSES}`,
79
+ billing_address: `lookupLink:${ADDRESSES}`,
80
+ tel: "tel",
81
+ mcc: `lookup:${MCC}`,
82
+ };
83
+
84
+ Forms.Base[BUSINESSDATA] = BusinessDefault;
85
+ Forms.BaseForm[BUSINESSDATA] = BusinessAccountForm;
86
+ Forms.AccountForm[BUSINESSDATA] = BusinessAccountForm;
87
+
88
+ //////////////////////////////////////////////////////////////////////
89
+ // Utilities
90
+
91
+ /**
92
+ * Fetches a fulll object representation of an account, including BusinessData
93
+ * @param {AccountType} account
94
+ * @returns {Promise.AccountType}
95
+ */
96
+ export async function fetchFullAccount(account) {
97
+ const BusinessData = await fetchBusinessData(account);
98
+
99
+ account.business = BusinessData;
100
+
101
+ return account;
102
+ }
103
+
104
+ /**
105
+ * Fetches the BusinessData (corporate, addresses, etc) for an account
106
+ * @param {AccountType} account
107
+ * @returns {Promise.BusinessData}
108
+ */
109
+ export async function fetchBusinessData(account) {
110
+ let addresses = [];
111
+ try {
112
+ addresses = await fetchAddresses(account);
113
+ } catch (err) {}
114
+ const addressMap = new Map();
115
+ if (addresses.length) {
116
+ addresses.forEach((address) => {
117
+ addressMap.set(address.Id, address);
118
+ });
119
+ }
120
+
121
+ const BusinessData = await fetchRecord(
122
+ BUSINESSDATA,
123
+ account.Id,
124
+ account.refPath,
125
+ );
126
+
127
+ let addressEntries = {};
128
+ ["business_address", "billing_address", "mailing_address"].forEach(
129
+ (entry) => {
130
+ const isLink =
131
+ entry && BusinessData[entry] && !BusinessData[entry]?.address_line_1;
132
+ if (isLink) {
133
+ addressEntries[entry] = {
134
+ ...addressMap.get(BusinessData[entry]),
135
+ };
136
+ }
137
+ },
138
+ ); //hacky way to repeat same effort
139
+
140
+ return {
141
+ ...BusinessData,
142
+ ...addressEntries,
143
+ };
144
+ }
145
+
146
+ /**
147
+ * Composes a URL for an "account page" from the account, and passed base URL
148
+ * @param {!AccountType} account
149
+ * @param {!string} origin base URL for the application
150
+ * @returns {string} full URL for business accouont
151
+ */
152
+ export function accountPage(account, origin) {
153
+ return `${origin}/${BUSINESS}/Account`; //Leads to LOGGED IN organization account page
154
+ }
155
+
156
+ /**
157
+ * @external WriteBatch
158
+ * @typedef {WriteBatch|Transaction|void} ChainType
159
+ */
160
+
161
+ /**
162
+ * @async
163
+ * @function
164
+ * @static
165
+ * Creates the Business information document
166
+ * @param {AccountType} account
167
+ * @param {?ChainType} batch - batching object. Transaction will be added to the batch
168
+ * @returns {Promise<ChainType>} WriteBatch, Transaction or Void
169
+ */
170
+ export async function createBusinessData(account, batch = null) {
171
+ return typedWrite(
172
+ {
173
+ ...Forms.Base[BUSINESSDATA], //base fields with defaults
174
+ ...fillForm(account, BUSINESSDATA), //sanitize passed data
175
+ }, //data
176
+ account, //parent
177
+ BUSINESSDATA, //type
178
+ batch,
179
+ );
180
+ }
181
+
182
+ /**
183
+ * Writes the "Business" data to the database
184
+ * @param {BusinessData} businessData
185
+ * @returns {Promise<BusinessData>}
186
+ */
187
+ export async function saveBusinessData(businessData, batch = null) {
188
+ return writeBack(businessData, batch);
189
+ }
190
+
191
+ /**
192
+ * Deletes a BusinessData record (rarely used if ever)
193
+ * @param {BusinessData} businessData
194
+ * @param {!string} businessData.refPath
195
+ * @returns {Promise<void>}
196
+ */
197
+ export async function deleteBusinessData(businessData, batch = null) {
198
+ return deleteRecordByRefPath(businessData.refPath, batch);
199
+ }
200
+
201
+ /**
202
+ * creates the "base path" (refPath) to store addresses based on an account (refPath)
203
+ * @param {Record} account
204
+ * @param {!string} account.refPath
205
+ * @returns {string}
206
+ */
207
+ export function businessDataPath(account) {
208
+ return `${account.refPath}/${BUSINESSDATA}/${account.Id}`;
209
+ }
210
+
211
+ /**
212
+ * verifies that all needed information has been filled in
213
+ * @param {AccountType} account
214
+ * @param {BusinessData} businessData record
215
+ * @returns {Boolean}
216
+ */
217
+ export function profileComplete(account, businessData) {
218
+ if (!businessData?.business_address) return false;
219
+ if (!businessData?.billing_address) return false;
220
+ if (!businessData?.mailing_address) return false;
221
+ if (!businessData?.email) return false;
222
+ if (!businessData?.tel) return false;
223
+ if (!account?.website) return false;
224
+ if (!(account?.name || account?.corporate)) return false;
225
+ return true;
226
+ }
227
+
228
+ /**
229
+ * verifies that all needed information has been filled in
230
+ * @param {AccountType} account
231
+ * @param {BusinessData} businessData record
232
+ * @returns {string|null}
233
+ */
234
+ export function profileIncomplete(account, businessData) {
235
+ let problem_string = "";
236
+ if (!businessData?.business_address) {
237
+ problem_string = problem_string.concat(`=> Business Address Missing\n`);
238
+ }
239
+ if (!businessData?.billing_address) {
240
+ problem_string = problem_string.concat(`=> Billing Address Missing\n`);
241
+ }
242
+ if (!businessData?.mailing_address) {
243
+ problem_string = problem_string.concat(`=> Mailing Address Missing\n`);
244
+ }
245
+ if (!businessData?.email) {
246
+ problem_string = problem_string.concat(`=> Business Email Missing\n`);
247
+ }
248
+ if (!businessData?.tel) {
249
+ problem_string = problem_string.concat(`=> Business Telephone Missing\n`);
250
+ }
251
+ if (!account?.website) {
252
+ problem_string = problem_string.concat(`=> Business Website Missing\n`);
253
+ }
254
+ if (!(account?.name || account?.corporate)) {
255
+ problem_string = problem_string.concat(
256
+ `=> Business and/or Corporate Name Missing\n`,
257
+ );
258
+ }
259
+ return problem_string.length ? problem_string : null;
260
+ }
261
+
262
+ /**
263
+ * Sets the "openIssues" flag in an account's BUSINESSDATA record
264
+ * The account's refPath is attached to the Payment system's record, and
265
+ * used here to find the Payment Account
266
+ * @param {BusinessData} businessData
267
+ * @returns {Promise.boolean}
268
+ */
269
+ export async function setOpenIssues(businessData) {
270
+ return writeRecord(
271
+ BUSINESSDATA,
272
+ {
273
+ ...businessData,
274
+ openIssues: true,
275
+ },
276
+ businessData.refPath,
277
+ null,
278
+ true,
279
+ );
280
+ }
281
+
282
+ /**
283
+ * Clears the "openIssues" flag in an account's BUSINESSDATA record
284
+ * The account's refPath is attached to the Payment system's record, and
285
+ * used here to find the Payment Account
286
+ * @param {BusinessData} businessData
287
+ * @returns {Promise.boolean}
288
+ */
289
+ export async function clearOpenIssues(businessData) {
290
+ return writeRecord(
291
+ BUSINESSDATA,
292
+ {
293
+ ...businessData,
294
+ openIssues: false,
295
+ },
296
+ businessData.refPath,
297
+ null,
298
+ true,
299
+ );
300
+ }
@@ -14,7 +14,7 @@ import {
14
14
  } from "@leaddreamer/firebase-wrapper";
15
15
  import { Forms, fillForm } from "@leaddreamer/staticforms";
16
16
 
17
- import { UNITS, MATERIAL, COMMODITIES, COMMODITY, COMPONENT_RANGE } from "../boilerplate";
17
+ import { UNITS, MATERIAL, COMMODITIES, COMMODITY, COMPONENT_RANGE } from "../boilerplate/index.js";
18
18
 
19
19
  //////////////////////////////////////////////////////////////////////
20
20
  // Constants
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Typedefs, constants, support functions and database operations related to Fundamental
3
+ * setting from the Database *
4
+ * @module Fundamentals
5
+ */
6
+ import { collectRecords } from "@leaddreamer/firebase-wrapper";
7
+ import { Forms, fillForm } from "@leaddreamer/staticforms";
8
+ import {
9
+ FUNDAMENTALS,
10
+ RATES,
11
+ PAYOUTRATES,
12
+ MCC,
13
+ BUSINESS_TYPE,
14
+ } from "../boilerplate/index.js";
15
+
16
+ //////////////////////////////////////////////////////////////////////
17
+ // constants
18
+
19
+ /**
20
+ * @typedef {object} OrganizationFundamentals
21
+ * @property {Array.string} Types Allowed organization types
22
+ */
23
+
24
+ /**
25
+ * @typedef {object} Rates
26
+ * @property {string} Id
27
+ * @property {object} service_charge
28
+ * @property {number} service_charge.minimum
29
+ * @property {number} service_charge.rate - percentage
30
+ * @property {number} service_charge.rounding_factor
31
+ */
32
+ /**
33
+ * @constant
34
+ * @type {Rates}
35
+ * @default
36
+ */
37
+ const Rates = {
38
+ Id: null,
39
+ service_charge: {
40
+ minimum: 0,
41
+ rate: 0,
42
+ rounding_factor: 4,
43
+ },
44
+ };
45
+
46
+ /**
47
+ * @typedef {object} PaymentProcessor
48
+ * @property {number} connected_active allowed active connections
49
+ * @property {number} processing_concurrency
50
+ * @property {number} processing_rate
51
+ * @property {number} processing_time_window
52
+ * @property {number} per_payout
53
+ * @property {number} rate_payout
54
+ * @property {number} rate_payout_scale
55
+ */
56
+ //For Stripe, all below are in "CENTS"
57
+ /**
58
+ * @constant
59
+ * @type {PaymentProcessor}
60
+ * @default
61
+ */
62
+ const paymentProcessor = {
63
+ connected_active: 200,
64
+ processing_concurrency: 10,
65
+ processing_rate: 25,
66
+ processing_time_window: 1000,
67
+ per_payout: 25,
68
+ rate_payout: 25,
69
+ rate_payout_scale: 10000,
70
+ };
71
+
72
+ /**
73
+ * @typedef {object} MCCType
74
+ * @property {string} Id
75
+ * @property {string} MCC - Merchant Class Code
76
+ * @property {string} name - Merchant Class Code
77
+ * @property {string} description - description of Merchant Class Code
78
+ * @property {string} long - long description of Merchant Class Code
79
+ * @property {string} type - Applicable business model - "Artists", "Venues" or "Brands"
80
+ */
81
+ /**
82
+ * @constant
83
+ * @type {MCCType}
84
+ * @default
85
+ */
86
+ const MCCDefault = {
87
+ Id: null,
88
+ MCC: null,
89
+ name: null,
90
+ description: null,
91
+ long: null,
92
+ type: null,
93
+ };
94
+
95
+ /**
96
+ * @typedef {object} BusinessType
97
+ * @property {string} Id
98
+ * @property {string} business_type - allowed business type value
99
+ * @property {string} name -business type value
100
+ * @property {string} description - description ofbusiness type value
101
+ */
102
+ /**
103
+ * @constant
104
+ * @type {BusinessType}
105
+ * @default
106
+ */
107
+ const BusinessTypeDefault = {
108
+ Id: null,
109
+ business_type: null,
110
+ name: null,
111
+ description: null,
112
+ };
113
+
114
+ /**
115
+ * @typedef {object} Fundamentals
116
+ * @property {Rates} Rates
117
+ * @property {PaymentProcessor} PaymentProcessor
118
+ * @property {object} Defaults
119
+ * @property {MCCType} Defaults.MCC
120
+ * @property {OrganizationFundamentals} Organizations
121
+ * @property {Array.string} Organizations.Types Allowed organization types
122
+ */
123
+
124
+ Forms.Base[RATES] = Rates;
125
+ Forms.Base[PAYOUTRATES] = paymentProcessor;
126
+ Forms.Base[MCC] = MCCDefault;
127
+ Forms.Base[BUSINESS_TYPE] = BusinessTypeDefault;
128
+
129
+ //////////////////////////////////////////////////////////
130
+ // fetches
131
+
132
+ /**
133
+ * returns a Promise which resolves with an
134
+ * array of all Fundamentals Objects (or err)
135
+ * @returns {Promise<Fundamentals>}
136
+ */
137
+ export async function fetchFundamentals() {
138
+ const fundamentals = await collectRecords(FUNDAMENTALS);
139
+ const fundamental_records = fundamentals.reduce((output, record) => {
140
+ const recordName = record.Id;
141
+ return record
142
+ ? {
143
+ ...output,
144
+ [recordName]: record,
145
+ }
146
+ : output;
147
+ }, {});
148
+ return fundamental_records;
149
+ }
150
+
151
+ /**
152
+ * returns a Promise that resolves with the Rates record from the database
153
+ * @returns {Promise<Rates>}
154
+ */
155
+ export async function fetchRates() {
156
+ const fundamentals = await fetchFundamentals();
157
+ return fundamentals[RATES];
158
+ }
159
+
160
+ /**
161
+ * returns a Promise that resolves with the Rates record from the database
162
+ * @returns {Promise<PaymentProcessor>}
163
+ */
164
+ export async function fetchPayoutRates() {
165
+ const fundamental_records = await fetchFundamentals();
166
+
167
+ return fundamental_records[PAYOUTRATES];
168
+ }
169
+
170
+ /**
171
+ * returns an array of all MCC (Merchant Commerce Code) available
172
+ * @returns {Promise<Array.MCCType>}
173
+ */
174
+ export async function fetchMCCs() {
175
+ return collectRecords(MCC, `${FUNDAMENTALS}/Defaults`);
176
+ }
177
+
178
+ /**
179
+ * returns an array of all MCC (Merchant Commerce Code) available
180
+ * @returns {Promise<Array.BusinessType>}
181
+ */
182
+ export async function fetchBusinessTypes() {
183
+ return collectRecords(BUSINESS_TYPE, `${FUNDAMENTALS}/Defaults`);
184
+ }
@@ -21,8 +21,8 @@ import {
21
21
  UNITS,
22
22
  COMPONENT_RANGE,
23
23
  COMPONENT_COUNT_RANGE,
24
- } from "../boilerplate";
25
- import {StageLevels, MaterialLevels} from "../Markups";
24
+ } from "../boilerplate/index.js";
25
+ //import {StageLevels, MaterialLevels} from "../Markups/index.js";
26
26
 
27
27
  //////////////////////////////////////////////////////////////////////
28
28
  // Constants
@@ -3,10 +3,10 @@
3
3
  * users
4
4
  * @module Markups
5
5
  */
6
- import { updateRecord } from "@leaddreamer/firebase-wrapper";
6
+ import { updateRecord } from "@leaddreamer/firebase-wrapper";
7
7
  import { Forms, fillForm } from "@leaddreamer/staticforms";
8
8
 
9
- import { MARKUPS, STAGE, FABRICATION, WHOLESALE, RETAIL, BASE, HIGHVALUE, SERVICE, MATERIAL } from "../boilerplate";
9
+ import { MARKUPS, STAGE, FABRICATION, WHOLESALE, RETAIL, BASE, HIGHVALUE, SERVICE, MATERIAL } from "../boilerplate/index.js";
10
10
 
11
11
  //////////////////////////////////////////////////////////////////////
12
12
  // Constants