@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.
Files changed (60) hide show
  1. package/README.md +0 -648
  2. package/business/Product/GoogleMerchantAPI.js +0 -2
  3. package/business/Utilities/index.js +0 -3
  4. package/package.json +5 -16
  5. package/business/Utilities/other.js +0 -404
  6. package/business/Utilities/promise-queue/index.js +0 -264
  7. package/business/Utilities/promise-queue/new.js +0 -231
  8. package/business/Utilities/rate-limited-queue/index.js +0 -127
  9. package/dist/InventoryLogic.0ac93278.js +0 -35
  10. package/dist/InventoryLogic.0ac93278.js.map +0 -1
  11. package/dist/InventoryLogic.31f6d549.js +0 -152
  12. package/dist/InventoryLogic.31f6d549.js.map +0 -1
  13. package/dist/InventoryLogic.35827495.js +0 -285
  14. package/dist/InventoryLogic.35827495.js.map +0 -1
  15. package/dist/InventoryLogic.37dfff3e.js +0 -72
  16. package/dist/InventoryLogic.37dfff3e.js.map +0 -1
  17. package/dist/InventoryLogic.4206cb15.js +0 -213
  18. package/dist/InventoryLogic.4206cb15.js.map +0 -1
  19. package/dist/InventoryLogic.44193a77.js +0 -35
  20. package/dist/InventoryLogic.44193a77.js.map +0 -1
  21. package/dist/InventoryLogic.46ca6768.js +0 -131
  22. package/dist/InventoryLogic.46ca6768.js.map +0 -1
  23. package/dist/InventoryLogic.4d012935.js +0 -151
  24. package/dist/InventoryLogic.4d012935.js.map +0 -1
  25. package/dist/InventoryLogic.57f24f5f.js +0 -155
  26. package/dist/InventoryLogic.57f24f5f.js.map +0 -1
  27. package/dist/InventoryLogic.59be76a4.js +0 -184
  28. package/dist/InventoryLogic.59be76a4.js.map +0 -1
  29. package/dist/InventoryLogic.70925a32.js +0 -375
  30. package/dist/InventoryLogic.70925a32.js.map +0 -1
  31. package/dist/InventoryLogic.72fcf301.js +0 -6
  32. package/dist/InventoryLogic.72fcf301.js.map +0 -1
  33. package/dist/InventoryLogic.7741caec.js +0 -375
  34. package/dist/InventoryLogic.7741caec.js.map +0 -1
  35. package/dist/InventoryLogic.78480e5e.js +0 -152
  36. package/dist/InventoryLogic.78480e5e.js.map +0 -1
  37. package/dist/InventoryLogic.80d0e568.js +0 -135
  38. package/dist/InventoryLogic.80d0e568.js.map +0 -1
  39. package/dist/InventoryLogic.8a273d2e.js +0 -110
  40. package/dist/InventoryLogic.8a273d2e.js.map +0 -1
  41. package/dist/InventoryLogic.8addb055.js +0 -202
  42. package/dist/InventoryLogic.8addb055.js.map +0 -1
  43. package/dist/InventoryLogic.9dee46ea.js +0 -6
  44. package/dist/InventoryLogic.9dee46ea.js.map +0 -1
  45. package/dist/InventoryLogic.b90f66ea.js +0 -124
  46. package/dist/InventoryLogic.b90f66ea.js.map +0 -1
  47. package/dist/InventoryLogic.bb447b4c.js +0 -39
  48. package/dist/InventoryLogic.bb447b4c.js.map +0 -1
  49. package/dist/InventoryLogic.d27e84a7.js +0 -75
  50. package/dist/InventoryLogic.d27e84a7.js.map +0 -1
  51. package/dist/InventoryLogic.d69ad127.js +0 -217
  52. package/dist/InventoryLogic.d69ad127.js.map +0 -1
  53. package/dist/InventoryLogic.e03e6b07.js +0 -245
  54. package/dist/InventoryLogic.e03e6b07.js.map +0 -1
  55. package/dist/InventoryLogic.f276f76c.js +0 -213
  56. package/dist/InventoryLogic.f276f76c.js.map +0 -1
  57. package/dist/InventoryLogic.f4627c8a.js +0 -160
  58. package/dist/InventoryLogic.f4627c8a.js.map +0 -1
  59. package/dist/index.js +0 -23
  60. package/dist/index.js.map +0 -1
@@ -1 +0,0 @@
1
- {"mappings":";;;;AAAA;;;;CAIC;;;AAMD,sEAAsE;AACtE,YAAY;AACZ;;;;;;;CAOC,GACD;;;;;;CAMC,GAED;;;;;CAKC,GACD,MAAM,wCAAkB;IACtB,CAAC,CAAA,GAAA,yCAAG,EAAE,EAAE;IACR,CAAC,CAAA,GAAA,yCAAQ,EAAE,EAAE;IACb,CAAC,CA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C,GACD,CAAA,GAAA,YAAI,EAAE,OAAO,CAAC,GAAA,0CAAM,GAAG;AAEvB;;;;CAIC,GACD,CAAA,GAAA,YAAI,EAAE,OAAO,CAAC,GAAA,0CAAS,GAAG;AAE1B,sEAAsE;AACtE,oBAAoB;AACpB;;;;;CAKC,GACD,eAAe,oCAAc,OAAO,EAAE,SAAS,IAAI;IACjD,OAAO,CAAA,GAAA,mBAAW,EAChB,CAAA,GAAA,eAAO,EAAE,SAAS,CAAA,GAAA,yCAAM,IACxB,QACA,CAAA,GAAA,yCAAM;AAEV","sources":["business/Markups/index.js"],"sourcesContent":["/**\n * Typedefs, constants, support functions and database operations related to product creation stages\n * users\n * @module Markups\n */\nimport { updateRecord } from \"@leaddreamer/firebase-wrapper\"; \nimport { Forms, fillForm } from \"@leaddreamer/staticforms\";\n\nimport { MARKUPS, STAGE, FABRICATION, WHOLESALE, RETAIL, BASE, HIGHVALUE, SERVICE, MATERIAL } from \"../boilerplate/index.js\";\n\n//////////////////////////////////////////////////////////////////////\n// Constants\n/**\n * Database Structure\n * Product or User or Fundamentals (document)\n * \\-> Markups (collection)\n * \\-> [ParentId] (sole document)\n * \\-> [Stage Name(s)] (field, object)\n * \\-> [Material Name(s)] (field, value [Markup])\n */\n/**\n * @typedef {number} Markup\n * @typedef {\"base\"|\"highValue\"|\"service\"} MaterialLevels\n * @typedef {\"fabrication\"|\"wholesale\"|\"retail\"} StageLevels\n * @typedef {Object.<MaterialLevels, Markup>} Material\n * @typedef {Object.<StageLevels, Material>} Markups\n */\n\n/**\n * @readonly\n * @constant\n * @type {Material}\n * @default\n */\nconst MaterialDefault = {\n [BASE]: 1.0,\n [HIGHVALUE]: 1.0,\n [SERVICE]: 1.0,\n};\n\n/**\n * @readonly\n * @constant\n * @type {Markups}\n * @default\n */\nconst MarkupsDefault = {\n [FABRICATION]: {\n [BASE]: 1.0,\n [HIGHVALUE]: 1.0,\n [SERVICE]: 1.0,\n },\n [WHOLESALE]: {\n [BASE]: 1.0,\n [HIGHVALUE]: 1.0,\n [SERVICE]: 1.0,\n },\n [RETAIL]: {\n [BASE]: 1.0,\n [HIGHVALUE]: 1.0,\n [SERVICE]: 1.0,\n },\n};\n\n/**\n * @readonly\n * @constant\n * @type {Material}\n * @default\n */\nconst MaterialDefaultForm = {\n [BASE]: \"number\",\n [HIGHVALUE]: \"number\",\n [SERVICE]: \"number\",\n};\n\n/**\n * @readonly\n * @constant\n * @type {Stage}\n * @default\n */\nconst MarkupsDefaultForm = {\n [FABRICATION]: `subrecord:${MATERIAL}`,\n [WHOLESALE]: `subrecord:${MATERIAL}`,\n [RETAIL]: `subrecord:${MATERIAL}`,\n};\n\nForms.Base[MATERIAL] = MaterialDefaultForm;\nForms.BaseForm[MATERIAL] = MaterialDefaultForm;\nForms.CreateForm[MATERIAL] = MaterialDefaultForm;\n//Forms.Save[MATERIAL] = updateMaterial;\nForms.SearchBy[MATERIAL] = MATERIAL;\n\nForms.Base[MARKUPS] = MarkupsDefault;\nForms.BaseForm[MARKUPS] = MarkupsDefaultForm;\nForms.CreateForm[MARKUPS] = MarkupsDefaultForm;\nForms.Save[MARKUPS] = updateMarkups;\n\n/**\n * @readonly\n * @constant\n * @default\n * \n */\nexport const MaterialChoices = {\n [BASE]: {\n Id: BASE,\n label: BASE,\n description: \"Base\",\n order: 1,\n },\n [HIGHVALUE]: {\n Id: HIGHVALUE,\n label: HIGHVALUE,\n description: \"High Value\",\n order: 2,\n },\n [SERVICE]: {\n Id: SERVICE,\n label: SERVICE,\n description: \"Service\",\n order: 3,\n },\n};\n\n/**\n * @readonly\n * @constant\n * @default\n */\nexport const StageChoices = {\n [FABRICATION]: {\n Id: FABRICATION,\n label: FABRICATION,\n description: \"Fabrication Stage\",\n order: 1,\n },\n [WHOLESALE]: {\n Id: WHOLESALE,\n label: WHOLESALE,\n description: \"Wholesale Stage\",\n order: 2,\n },\n [RETAIL]: {\n Id: RETAIL,\n label: RETAIL,\n description: \"Retail Stage\",\n order: 3,\n },\n};\n\n/**\n * @readonly\n * @constant\n * @default\n */\nForms.Choices[STAGE] = StageChoices;\n\n/**\n * @readonly\n * @constant\n * @default\n */\nForms.Choices[MATERIAL] = MaterialChoices\n\n//////////////////////////////////////////////////////////////////////\n// record operations\n/**\n * writes record back to database. Assumes only Id is valid\n * @param {Markups} markups a partially-populated product record for updates\n * @param {Record} parent minimal record of product, user (or none) this stage belongs to\n * @returns {promise.LineItem} a copy of the data written\n */\nasync function updateMarkups(markups, parent = null) {\n return updateRecord(\n fillForm(markups, MARKUPS), //saves only APPROPRIATE fields -does NOT populate missing fields\n parent,\n MARKUPS\n );\n}\n\n\n"],"names":[],"version":3,"file":"InventoryLogic.4d012935.js.map"}
@@ -1,155 +0,0 @@
1
- import {ADDRESSES as $fefa9c41cb73ae0b$export$6890d3564b1f252d, BUSINESS as $fefa9c41cb73ae0b$export$6f454e69bce3a691, BUSINESS_TYPE as $fefa9c41cb73ae0b$export$1bd589465335bb9d, BUSINESSDATA as $fefa9c41cb73ae0b$export$e651cf32bc3f78a4, MCC as $fefa9c41cb73ae0b$export$af5764009005aa8e, USER as $fefa9c41cb73ae0b$export$ff09b90989b21a8} from "./InventoryLogic.d27e84a7.js";
2
- import {fetchAddresses as $5e875028eacae923$export$c9b8cb1768a98d34} from "./InventoryLogic.37dfff3e.js";
3
- import {fetchRecord as $lNnOJ$fetchRecord, typedWrite as $lNnOJ$typedWrite, writeBack as $lNnOJ$writeBack, deleteRecordByRefPath as $lNnOJ$deleteRecordByRefPath, writeRecord as $lNnOJ$writeRecord} from "@leaddreamer/firebase-wrapper";
4
- import {Forms as $lNnOJ$Forms, fillForm as $lNnOJ$fillForm} from "@leaddreamer/staticforms";
5
-
6
- /**
7
- * Functions for managing (potentially)private data for an organization.
8
- * Unified structure as a sub-record of organization, or CityManager accounts
9
- * @module BusinessData
10
- */
11
-
12
-
13
-
14
- //////////////////////////////////////////////////////////////////////
15
- // definitions
16
- /**
17
- * @external AddressType
18
- */ /**
19
- * @typedef {object} contact
20
- * @property {?string} contact.Id
21
- * @property {!string} contact.first_name
22
- * @property {!string} contact.last_name
23
- * @property {!string} contact.tel
24
- * @property {?string} contact.email - must be filled in to make profile public
25
- */ /**
26
- * @typedef {object} BusinessData
27
- * @property {?string} email - must be filled in to make profile public
28
- * @property {contact} contact
29
- * @property {!string} tel
30
- * @property {string} business_type
31
- * @property {AddressType} business_address
32
- * @property {AddressType} mailing_address
33
- * @property {AddressType} billing_address
34
- */ /**
35
- * @constant
36
- * @type {BusinessData}
37
- * @default
38
- */ const $852adca6ae24886c$var$BusinessDefault = {
39
- Id: null,
40
- email: null,
41
- business_type: null,
42
- contact: null,
43
- business_address: null,
44
- mailing_address: null,
45
- billing_address: null,
46
- tel: null,
47
- mcc: null,
48
- tax_rate: null,
49
- //tax_id: null,
50
- openIssues: false
51
- };
52
- /**
53
- * @constant
54
- * @type {BusinessData}
55
- * @default
56
- */ const $852adca6ae24886c$var$BusinessAccountForm = {
57
- refPath: "hidden:text",
58
- email: "email",
59
- business_type: `lookup:${(0, $fefa9c41cb73ae0b$export$1bd589465335bb9d)}`,
60
- contact: `object:${(0, $fefa9c41cb73ae0b$export$ff09b90989b21a8)}`,
61
- business_address: `lookupLink:${(0, $fefa9c41cb73ae0b$export$6890d3564b1f252d)}`,
62
- mailing_address: `lookupLink:${(0, $fefa9c41cb73ae0b$export$6890d3564b1f252d)}`,
63
- billing_address: `lookupLink:${(0, $fefa9c41cb73ae0b$export$6890d3564b1f252d)}`,
64
- tel: "tel",
65
- mcc: `lookup:${(0, $fefa9c41cb73ae0b$export$af5764009005aa8e)}`
66
- };
67
- (0, $lNnOJ$Forms).Base[0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4] = $852adca6ae24886c$var$BusinessDefault;
68
- (0, $lNnOJ$Forms).BaseForm[0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4] = $852adca6ae24886c$var$BusinessAccountForm;
69
- (0, $lNnOJ$Forms).AccountForm[0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4] = $852adca6ae24886c$var$BusinessAccountForm;
70
- async function $852adca6ae24886c$export$aeea048b1874c987(account) {
71
- const BusinessData = await $852adca6ae24886c$export$a273004aea0035e0(account);
72
- account.business = BusinessData;
73
- return account;
74
- }
75
- async function $852adca6ae24886c$export$a273004aea0035e0(account) {
76
- let addresses = [];
77
- try {
78
- addresses = await (0, $5e875028eacae923$export$c9b8cb1768a98d34)(account);
79
- } catch (err) {}
80
- const addressMap = new Map();
81
- if (addresses.length) addresses.forEach((address)=>{
82
- addressMap.set(address.Id, address);
83
- });
84
- const BusinessData = await (0, $lNnOJ$fetchRecord)((0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4), account.Id, account.refPath);
85
- let addressEntries = {};
86
- [
87
- "business_address",
88
- "billing_address",
89
- "mailing_address"
90
- ].forEach((entry)=>{
91
- const isLink = entry && BusinessData[entry] && !BusinessData[entry]?.address_line_1;
92
- if (isLink) addressEntries[entry] = {
93
- ...addressMap.get(BusinessData[entry])
94
- };
95
- }); //hacky way to repeat same effort
96
- return {
97
- ...BusinessData,
98
- ...addressEntries
99
- };
100
- }
101
- function $852adca6ae24886c$export$f81f3e9fae10e6db(account, origin) {
102
- return `${origin}/${0, $fefa9c41cb73ae0b$export$6f454e69bce3a691}/Account`; //Leads to LOGGED IN organization account page
103
- }
104
- async function $852adca6ae24886c$export$ca4306a1b5762f0e(account, batch = null) {
105
- return (0, $lNnOJ$typedWrite)({
106
- ...(0, $lNnOJ$Forms).Base[0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4],
107
- ...(0, $lNnOJ$fillForm)(account, (0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4))
108
- }, account, (0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4), batch);
109
- }
110
- async function $852adca6ae24886c$export$4bb3a8bbe6017432(businessData, batch = null) {
111
- return (0, $lNnOJ$writeBack)(businessData, batch);
112
- }
113
- async function $852adca6ae24886c$export$b8447d25d283e6cc(businessData, batch = null) {
114
- return (0, $lNnOJ$deleteRecordByRefPath)(businessData.refPath, batch);
115
- }
116
- function $852adca6ae24886c$export$8c755753b01b12f(account) {
117
- return `${account.refPath}/${0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4}/${account.Id}`;
118
- }
119
- function $852adca6ae24886c$export$1e2f140c95101692(account, businessData) {
120
- if (!businessData?.business_address) return false;
121
- if (!businessData?.billing_address) return false;
122
- if (!businessData?.mailing_address) return false;
123
- if (!businessData?.email) return false;
124
- if (!businessData?.tel) return false;
125
- if (!account?.website) return false;
126
- if (!(account?.name || account?.corporate)) return false;
127
- return true;
128
- }
129
- function $852adca6ae24886c$export$f9e1390aa5941c3f(account, businessData) {
130
- let problem_string = "";
131
- if (!businessData?.business_address) problem_string = problem_string.concat(`=> Business Address Missing\n`);
132
- if (!businessData?.billing_address) problem_string = problem_string.concat(`=> Billing Address Missing\n`);
133
- if (!businessData?.mailing_address) problem_string = problem_string.concat(`=> Mailing Address Missing\n`);
134
- if (!businessData?.email) problem_string = problem_string.concat(`=> Business Email Missing\n`);
135
- if (!businessData?.tel) problem_string = problem_string.concat(`=> Business Telephone Missing\n`);
136
- if (!account?.website) problem_string = problem_string.concat(`=> Business Website Missing\n`);
137
- if (!(account?.name || account?.corporate)) problem_string = problem_string.concat(`=> Business and/or Corporate Name Missing\n`);
138
- return problem_string.length ? problem_string : null;
139
- }
140
- async function $852adca6ae24886c$export$89c9bbe01d357e36(businessData) {
141
- return (0, $lNnOJ$writeRecord)((0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4), {
142
- ...businessData,
143
- openIssues: true
144
- }, businessData.refPath, null, true);
145
- }
146
- async function $852adca6ae24886c$export$45379be9a22c2a97(businessData) {
147
- return (0, $lNnOJ$writeRecord)((0, $fefa9c41cb73ae0b$export$e651cf32bc3f78a4), {
148
- ...businessData,
149
- openIssues: false
150
- }, businessData.refPath, null, true);
151
- }
152
-
153
-
154
- export {$852adca6ae24886c$export$aeea048b1874c987 as fetchFullAccount, $852adca6ae24886c$export$a273004aea0035e0 as fetchBusinessData, $852adca6ae24886c$export$f81f3e9fae10e6db as accountPage, $852adca6ae24886c$export$ca4306a1b5762f0e as createBusinessData, $852adca6ae24886c$export$4bb3a8bbe6017432 as saveBusinessData, $852adca6ae24886c$export$b8447d25d283e6cc as deleteBusinessData, $852adca6ae24886c$export$8c755753b01b12f as businessDataPath, $852adca6ae24886c$export$1e2f140c95101692 as profileComplete, $852adca6ae24886c$export$f9e1390aa5941c3f as profileIncomplete, $852adca6ae24886c$export$89c9bbe01d357e36 as setOpenIssues, $852adca6ae24886c$export$45379be9a22c2a97 as clearOpenIssues};
155
- //# sourceMappingURL=InventoryLogic.57f24f5f.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;AAAA;;;;CAIC;;;;AAmBD,sEAAsE;AACtE,cAAc;AAEd;;CAEC,GACD;;;;;;;CAOC,GACD;;;;;;;;;CASC,GACD;;;;CAIC,GACD,MAAM,wCAAkB;IACtB,IAAI;IACJ,OAAO;IACP,eAAe;IACf,SAAS;IACT,kBAAkB;IAClB,iBAAiB;IACjB,iBAAiB;IACjB,KAAK;IACL,KAAK;IACL,UAAU;IACV,eAAe;IACf,YAAY;AACd;AAEA;;;;CAIC,GACD,MAAM,4CAAsB;IAC1B,SAAS;IACT,OAAO;IACP,eAAe,CAAC,OAAO,EAAE,CAAA,GAAA,yCAAY,GAAG;IACxC,SAAS,CAAC,OAAO,EAAE,CAAA,GAAA,wCAAG,GAAG;IACzB,kBAAkB,CAAC,WAAW,EAAE,CAAA,GAAA,yCAAQ,GAAG;IAC3C,iBAAiB,CAAC,WAAW,EAAE,CAAA,GAAA,yCAAQ,GAAG;IAC1C,iBAAiB,CAAC,WAAW,EAAE,CAAA,GAAA,yCAAQ,GAAG;IAC1C,KAAK;IACL,KAAK,CAAC,OAAO,EAAE,CAAA,GAAA,yCAAE,GAAG;AACtB;AAEA,CAAA,GAAA,YAAI,EAAE,IAAI,CAAC,GAAA,0CAAa,GAAG;AAC3B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AAC,SAAS,SACZ,iBAAiB,eAAe,MAAM,CAAC,CAAC,6BAA6B,CAAC;IAExE,IAAI,CAAE,CAAA,SAAS,QAAQ,SAAS,SAAQ,GACtC,iBAAiB,eAAe,MAAM,CACpC,CAAC,2CAA2C,CAAC;IAGjD,OAAO,eAAe,MAAM,GAAG,iBAAiB;AAClD;AASO,eAAe,0CAAc,YAAY;IAC9C,OAAO,CAAA,GAAA,kBAAU,EACf,CAAA,GAAA,yCAAW,GACX;QACE,GAAG,YAAY;QACf,YAAY;IACd,GACA,aAAa,OAAO,EACpB,MACA;AAEJ;AASO,eAAe,0CAAgB,YAAY;IAChD,OAAO,CAAA,GAAA,kBAAU,EACf,CAAA,GAAA,yCAAW,GACX;QACE,GAAG,YAAY;QACf,YAAY;IACd,GACA,aAAa,OAAO,EACpB,MACA;AAEJ","sources":["business/BusinessData/index.js"],"sourcesContent":["/**\n * Functions for managing (potentially)private data for an organization.\n * Unified structure as a sub-record of organization, or CityManager accounts\n * @module BusinessData\n */\nimport {\n fetchRecord,\n writeRecord,\n typedWrite,\n writeBack,\n deleteRecordByRefPath,\n} from \"@leaddreamer/firebase-wrapper\";\nimport { Forms, fillForm } from \"@leaddreamer/staticforms\";\nimport {\n BUSINESS,\n BUSINESSDATA,\n BUSINESS_TYPE,\n ADDRESSES,\n USER,\n MCC,\n} from \"../boilerplate/index.js\";\nimport { fetchAddresses } from \"../Addresses/index.js\";\n\n//////////////////////////////////////////////////////////////////////\n// definitions\n\n/**\n * @external AddressType\n */\n/**\n * @typedef {object} contact\n * @property {?string} contact.Id\n * @property {!string} contact.first_name\n * @property {!string} contact.last_name\n * @property {!string} contact.tel\n * @property {?string} contact.email - must be filled in to make profile public\n */\n/**\n * @typedef {object} BusinessData\n * @property {?string} email - must be filled in to make profile public\n * @property {contact} contact\n * @property {!string} tel\n * @property {string} business_type\n * @property {AddressType} business_address\n * @property {AddressType} mailing_address\n * @property {AddressType} billing_address\n */\n/**\n * @constant\n * @type {BusinessData}\n * @default\n */\nconst BusinessDefault = {\n Id: null,\n email: null,\n business_type: null,\n contact: null,\n business_address: null,\n mailing_address: null,\n billing_address: null,\n tel: null,\n mcc: null,\n tax_rate: null,\n //tax_id: null,\n openIssues: false,\n};\n\n/**\n * @constant\n * @type {BusinessData}\n * @default\n */\nconst BusinessAccountForm = {\n refPath: \"hidden:text\",\n email: \"email\",\n business_type: `lookup:${BUSINESS_TYPE}`,\n contact: `object:${USER}`,\n business_address: `lookupLink:${ADDRESSES}`,\n mailing_address: `lookupLink:${ADDRESSES}`,\n billing_address: `lookupLink:${ADDRESSES}`,\n tel: \"tel\",\n mcc: `lookup:${MCC}`,\n};\n\nForms.Base[BUSINESSDATA] = BusinessDefault;\nForms.BaseForm[BUSINESSDATA] = BusinessAccountForm;\nForms.AccountForm[BUSINESSDATA] = BusinessAccountForm;\n\n//////////////////////////////////////////////////////////////////////\n// Utilities\n\n/**\n * Fetches a fulll object representation of an account, including BusinessData\n * @param {AccountType} account\n * @returns {Promise.AccountType}\n */\nexport async function fetchFullAccount(account) {\n const BusinessData = await fetchBusinessData(account);\n\n account.business = BusinessData;\n\n return account;\n}\n\n/**\n * Fetches the BusinessData (corporate, addresses, etc) for an account\n * @param {AccountType} account\n * @returns {Promise.BusinessData}\n */\nexport async function fetchBusinessData(account) {\n let addresses = [];\n try {\n addresses = await fetchAddresses(account);\n } catch (err) {}\n const addressMap = new Map();\n if (addresses.length) {\n addresses.forEach((address) => {\n addressMap.set(address.Id, address);\n });\n }\n\n const BusinessData = await fetchRecord(\n BUSINESSDATA,\n account.Id,\n account.refPath,\n );\n\n let addressEntries = {};\n [\"business_address\", \"billing_address\", \"mailing_address\"].forEach(\n (entry) => {\n const isLink =\n entry && BusinessData[entry] && !BusinessData[entry]?.address_line_1;\n if (isLink) {\n addressEntries[entry] = {\n ...addressMap.get(BusinessData[entry]),\n };\n }\n },\n ); //hacky way to repeat same effort\n\n return {\n ...BusinessData,\n ...addressEntries,\n };\n}\n\n/**\n * Composes a URL for an \"account page\" from the account, and passed base URL\n * @param {!AccountType} account\n * @param {!string} origin base URL for the application\n * @returns {string} full URL for business accouont\n */\nexport function accountPage(account, origin) {\n return `${origin}/${BUSINESS}/Account`; //Leads to LOGGED IN organization account page\n}\n\n/**\n * @external WriteBatch\n * @typedef {WriteBatch|Transaction|void} ChainType\n */\n\n/**\n * @async\n * @function\n * @static\n * Creates the Business information document\n * @param {AccountType} account\n * @param {?ChainType} batch - batching object. Transaction will be added to the batch\n * @returns {Promise<ChainType>} WriteBatch, Transaction or Void\n */\nexport async function createBusinessData(account, batch = null) {\n return typedWrite(\n {\n ...Forms.Base[BUSINESSDATA], //base fields with defaults\n ...fillForm(account, BUSINESSDATA), //sanitize passed data\n }, //data\n account, //parent\n BUSINESSDATA, //type\n batch,\n );\n}\n\n/**\n * Writes the \"Business\" data to the database\n * @param {BusinessData} businessData\n * @returns {Promise<BusinessData>}\n */\nexport async function saveBusinessData(businessData, batch = null) {\n return writeBack(businessData, batch);\n}\n\n/**\n * Deletes a BusinessData record (rarely used if ever)\n * @param {BusinessData} businessData\n * @param {!string} businessData.refPath\n * @returns {Promise<void>}\n */\nexport async function deleteBusinessData(businessData, batch = null) {\n return deleteRecordByRefPath(businessData.refPath, batch);\n}\n\n/**\n * creates the \"base path\" (refPath) to store addresses based on an account (refPath)\n * @param {Record} account\n * @param {!string} account.refPath\n * @returns {string}\n */\nexport function businessDataPath(account) {\n return `${account.refPath}/${BUSINESSDATA}/${account.Id}`;\n}\n\n/**\n * verifies that all needed information has been filled in\n * @param {AccountType} account\n * @param {BusinessData} businessData record\n * @returns {Boolean}\n */\nexport function profileComplete(account, businessData) {\n if (!businessData?.business_address) return false;\n if (!businessData?.billing_address) return false;\n if (!businessData?.mailing_address) return false;\n if (!businessData?.email) return false;\n if (!businessData?.tel) return false;\n if (!account?.website) return false;\n if (!(account?.name || account?.corporate)) return false;\n return true;\n}\n\n/**\n * verifies that all needed information has been filled in\n * @param {AccountType} account\n * @param {BusinessData} businessData record\n * @returns {string|null}\n */\nexport function profileIncomplete(account, businessData) {\n let problem_string = \"\";\n if (!businessData?.business_address) {\n problem_string = problem_string.concat(`=> Business Address Missing\\n`);\n }\n if (!businessData?.billing_address) {\n problem_string = problem_string.concat(`=> Billing Address Missing\\n`);\n }\n if (!businessData?.mailing_address) {\n problem_string = problem_string.concat(`=> Mailing Address Missing\\n`);\n }\n if (!businessData?.email) {\n problem_string = problem_string.concat(`=> Business Email Missing\\n`);\n }\n if (!businessData?.tel) {\n problem_string = problem_string.concat(`=> Business Telephone Missing\\n`);\n }\n if (!account?.website) {\n problem_string = problem_string.concat(`=> Business Website Missing\\n`);\n }\n if (!(account?.name || account?.corporate)) {\n problem_string = problem_string.concat(\n `=> Business and/or Corporate Name Missing\\n`,\n );\n }\n return problem_string.length ? problem_string : null;\n}\n\n/**\n * Sets the \"openIssues\" flag in an account's BUSINESSDATA record\n * The account's refPath is attached to the Payment system's record, and\n * used here to find the Payment Account\n * @param {BusinessData} businessData\n * @returns {Promise.boolean}\n */\nexport async function setOpenIssues(businessData) {\n return writeRecord(\n BUSINESSDATA,\n {\n ...businessData,\n openIssues: true,\n },\n businessData.refPath,\n null,\n true,\n );\n}\n\n/**\n * Clears the \"openIssues\" flag in an account's BUSINESSDATA record\n * The account's refPath is attached to the Payment system's record, and\n * used here to find the Payment Account\n * @param {BusinessData} businessData\n * @returns {Promise.boolean}\n */\nexport async function clearOpenIssues(businessData) {\n return writeRecord(\n BUSINESSDATA,\n {\n ...businessData,\n openIssues: false,\n },\n businessData.refPath,\n null,\n true,\n );\n}\n"],"names":[],"version":3,"file":"InventoryLogic.57f24f5f.js.map"}
@@ -1,184 +0,0 @@
1
- /**
2
- * Typedefs, constants, support functions and database operations related to Promise getQueueSize
3
- * Thes are useful for scheduling large serial asynchronous operations
4
- * @module PromiseQueue
5
- */ /**
6
- * Creates a new rate limited queue. The queue is created with stopped state, i.e. you have to call start() to run jobs.
7
- * @class
8
- */ class $d403d40112d3687c$export$e869d3bcedcd9592 {
9
- /**
10
- * @param {number} maxCallsPerSecond - The rate limit of this queue in maximum calls per seconds which may be executed at any time. Pass values less than 1 to have less than one call per second, e.g. 1/3 for 3 one call in three seconds at maximum.
11
- * @param {callback} logger optional logger function for errors
12
- * @constructor
13
- */ constructor(maxCallsPerSecond = 1, logger){
14
- /**
15
- * The rate limit of this queue in maximum calls per seconds
16
- * which may be executed at any time. Pass values less than 1
17
- * to have less than one call per second, e.g. 1/3 for 3 one
18
- * call in three seconds at maximum.
19
- * @type {float}
20
- */ this.maxCallsPerSecond = typeof maxCallsPerSecond === "undefined" ? 1 : maxCallsPerSecond;
21
- /**
22
- * optional logger function for errors
23
- * @type {callback}
24
- */ this.logger = logger;
25
- /**
26
- * lists of tasks to be processed, in order, in the queue
27
- * @type {Array.callback}
28
- */ this.tasks = [];
29
- /**
30
- * flag to indicate queue processing is active
31
- * @type {boolean}
32
- */ this.isActive = false;
33
- /**
34
- * pacing for queue processing / rate limiting
35
- * @type {float}
36
- */ this.jobIntervalMillis = 1000 / maxCallsPerSecond;
37
- /**
38
- * timestamp of start of last task
39
- * @type {time}
40
- */ this.lastTaskTimestamp = null;
41
- /**
42
- * @type {string}
43
- */ this.currentTaskTimeoutId = null;
44
- }
45
- /**
46
- * Processes the next task and returns the id of the time used to wait for the next invocation of this method.
47
- * @private
48
- */ updateTaskSchedule() {
49
- if (this.logger && this.logger.debug) this.logger.debug("PromiseQueue.updateTaskSchedule");
50
- if (this.isEmpty() || this.isStopped()) return;
51
- const queue = this;
52
- function processNextTask() {
53
- if (queue.logger && queue.logger.debug) queue.logger.debug("PromiseQueue.processNextTask", queue.tasks.length);
54
- var nextTaskItem = queue.tasks.shift();
55
- if (nextTaskItem) try {
56
- const result = nextTaskItem.task.call();
57
- if (queue.logger && queue.logger.debug) queue.logger.debug("Resolving queued promise", result, result instanceof Promise);
58
- nextTaskItem.resolve(result);
59
- } catch (e) {
60
- queue.logger.info("rejecting queued promise result", e);
61
- nextTaskItem.reject(e);
62
- }
63
- }
64
- function scheduleNext(timeoutMillisOverride) {
65
- if (queue.logger && queue.logger.debug) queue.logger.debug("PromiseQueue.scheduleNext", timeoutMillisOverride);
66
- if (queue.isEmpty()) {
67
- queue.currentTaskTimeoutId = null;
68
- return;
69
- }
70
- queue.currentTaskTimeoutId = setTimeout(function() {
71
- queue.lastTaskTimestamp = Date.now();
72
- processNextTask();
73
- scheduleNext(queue.jobIntervalMillis);
74
- }, timeoutMillisOverride);
75
- }
76
- if (this.currentTaskTimeoutId == null) {
77
- if (this.lastTaskTimestamp) {
78
- let passedTime = Date.now() - this.lastTaskTimestamp;
79
- if (passedTime > this.jobIntervalMillis) scheduleNext(this.jobIntervalMillis);
80
- else scheduleNext(Math.max(0, this.jobIntervalMillis - passedTime));
81
- } else scheduleNext(0);
82
- }
83
- }
84
- /**
85
- * Starts the task processing of this queue.
86
- *
87
- * If it is already started, then false will be returned.
88
- * If it is not yet started then the first task will be processed in the background and true will be returned.
89
- *
90
- * @return {boolean} true if this queue wasn't started before and now started to process tasks.
91
- */ start() {
92
- if (this.isActive) return false;
93
- this.isActive = true;
94
- this.updateTaskSchedule();
95
- return true;
96
- }
97
- /**
98
- * Stops the processing of this queue.
99
- * @return true if the queue was started and is now stopped. false if it was already stopped.
100
- */ stop() {
101
- if (this.isActive) {
102
- this.isActive = false;
103
- if (this.currentTaskTimeoutId) {
104
- clearInterval(this.currentTaskTimeoutId);
105
- this.currentTaskTimeoutId = null;
106
- this.lastTaskTimestamp = null;
107
- }
108
- }
109
- }
110
- getMaxCallsPerSecond() {
111
- return this.maxCallsPerSecond;
112
- }
113
- isStarted() {
114
- return this.isActive;
115
- }
116
- isStopped() {
117
- return !this.isStarted();
118
- }
119
- /**
120
- * @returns {boolean} true if this queue is currently empty, i.e. if it has no tasks in the queue.
121
- */ isEmpty() {
122
- return this.tasks.length === 0;
123
- }
124
- /**
125
- * @returns {boolean} true if this queue has one or more entries.
126
- */ isNotEmpty() {
127
- return !this.isEmpty();
128
- }
129
- /**
130
- * @param {function} task - The task to add.
131
- * @param {boolean} append - if the task should be appended or prepended to the list of queued tasks
132
- * @return {Promise} A promise which is resolved/rejected when the task was executed by the queue.
133
- */ async add(task, append) {
134
- var self = this;
135
- var promise = new Promise(function(resolve, reject) {
136
- var newTaskItem = {
137
- task: task,
138
- resolve: resolve,
139
- reject: reject
140
- };
141
- if (self.isEmpty() || append) self.tasks.push(newTaskItem);
142
- else self.tasks.unshift(newTaskItem);
143
- });
144
- self.updateTaskSchedule();
145
- return promise;
146
- }
147
- /**
148
- * Appends a new task at the end of the queue.
149
- * @param {function} task - The task to perform. This function will be called with no arguments.
150
- * @return {Promise} A promise which is resolved/rejected When the task was executed by the queue
151
- */ async append(task) {
152
- return this.add(task, true);
153
- }
154
- /**
155
- * Adds a new task as first item in the queue.
156
- * @param task
157
- * @return {Promise} A promise which is resolved/rejected When the task was executed by the queue
158
- */ async prepend(task) {
159
- return this.add(task, false);
160
- }
161
- /**
162
- * Removes the task from the qeueue. If the task is contained more than one time then all occurrences will be removed.
163
- * @param {function} task - The task to remove.
164
- * @return {number} - The number of items which were removed.
165
- */ remove(task) {
166
- if (this.isEmpty()) return 0;
167
- var removedItems = 0;
168
- for(var i = this.tasks.length - 1; i >= 0; i--)if (this.tasks[i].task === task) {
169
- this.tasks.splice(i, 1);
170
- removedItems++;
171
- }
172
- return removedItems;
173
- }
174
- /**
175
- * @returns {Number} - The number of queued/waiting tasks in the queue.
176
- */ getQueueSize() {
177
- return this.tasks.length;
178
- }
179
- }
180
- var $d403d40112d3687c$export$2e2bcd8739ae039 = PromiseQueue = new $d403d40112d3687c$export$e869d3bcedcd9592(1, null);
181
-
182
-
183
- export {$d403d40112d3687c$export$e869d3bcedcd9592 as PromiseQueueClass, $d403d40112d3687c$export$2e2bcd8739ae039 as default};
184
- //# sourceMappingURL=InventoryLogic.59be76a4.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA;;;;CAIC,GACD;;;CAGC,GACM,MAAM;IACT;;;;KA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AI,IAAI,EAAE,MAAM,EAAE;QAClB,IAAI,OAAO,IAAI;QAEf,IAAI,UAAU,IAAI,QAAQ,SAAU,OAAO,EAAE,MAAM;YAC/C,IAAI,cAAc;gBAAE,MAAM;gBAAM,SAAS;gBAAS,QAAQ;YAAO;YAEjE,IAAI,KAAK,OAAO,MAAM,QAClB,KAAK,KAAK,CAAC,IAAI,CAAC;iBAEhB,KAAK,KAAK,CAAC,OAAO,CAAC;QAE3B;QAEA,KAAK,kBAAkB;QAEvB,OAAO;IACX;IAEF;;;;GAIC,GACD,MAAM,OAAO,IAAI,EAAE;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM;IAC1B;IAEF;;;;GAIC,GACF,MAAM,QAAQ,IAAI,EAAE;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM;IAC1B;IAEF;;;;GAIC,GACD,OAAO,IAAI,EAAE;QACP,IAAI,IAAI,CAAC,OAAO,IACZ,OAAO;QAGX,IAAI,eAAe;QACnB,IAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,KAAK,GAAG,IACxC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,MAAM;YAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG;YACrB;QACJ;QAGJ,OAAO;IACX;IAEF;;GAEC,GACD,eAAe;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM;IAC5B;AAEJ;IAEA,2CAAe,eAAe,IAAI,0CAAkB,GAAG","sources":["business/Utilities/promise-queue/index.js"],"sourcesContent":["/**\n * Typedefs, constants, support functions and database operations related to Promise getQueueSize\n * Thes are useful for scheduling large serial asynchronous operations\n * @module PromiseQueue\n */\n/**\n * Creates a new rate limited queue. The queue is created with stopped state, i.e. you have to call start() to run jobs.\n * @class\n */\nexport class PromiseQueueClass {\n /**\n * @param {number} maxCallsPerSecond - The rate limit of this queue in maximum calls per seconds which may be executed at any time. Pass values less than 1 to have less than one call per second, e.g. 1/3 for 3 one call in three seconds at maximum.\n * @param {callback} logger optional logger function for errors\n * @constructor\n */\n constructor(maxCallsPerSecond=1, logger) {\n /**\n * The rate limit of this queue in maximum calls per seconds\n * which may be executed at any time. Pass values less than 1\n * to have less than one call per second, e.g. 1/3 for 3 one\n * call in three seconds at maximum.\n * @type {float}\n */\n this.maxCallsPerSecond =\n typeof maxCallsPerSecond === \"undefined\" ? 1 : maxCallsPerSecond;\n /**\n * optional logger function for errors\n * @type {callback}\n */\n this.logger = logger;\n\n /**\n * lists of tasks to be processed, in order, in the queue\n * @type {Array.callback}\n */\n this.tasks = [];\n /**\n * flag to indicate queue processing is active\n * @type {boolean}\n */\n this.isActive = false;\n /**\n * pacing for queue processing / rate limiting\n * @type {float}\n */\n this.jobIntervalMillis = 1000 / maxCallsPerSecond;\n /**\n * timestamp of start of last task\n * @type {time}\n */\n this.lastTaskTimestamp = null;\n /**\n * @type {string}\n */\n this.currentTaskTimeoutId = null;\n }\n\n /**\n * Processes the next task and returns the id of the time used to wait for the next invocation of this method.\n * @private\n */\n updateTaskSchedule() {\n if (this.logger && this.logger.debug) {\n this.logger.debug(\"PromiseQueue.updateTaskSchedule\");\n }\n\n if (this.isEmpty() || this.isStopped()) {\n return;\n }\n\n const queue = this;\n\n function processNextTask() {\n if (queue.logger && queue.logger.debug) {\n queue.logger.debug(\"PromiseQueue.processNextTask\", queue.tasks.length);\n }\n\n var nextTaskItem = queue.tasks.shift();\n if (nextTaskItem) {\n try {\n const result = nextTaskItem.task.call();\n\n if (queue.logger && queue.logger.debug) {\n queue.logger.debug(\n \"Resolving queued promise\",\n result,\n result instanceof Promise\n );\n }\n\n nextTaskItem.resolve(result);\n } catch (e) {\n queue.logger.info(\"rejecting queued promise result\", e);\n nextTaskItem.reject(e);\n }\n }\n }\n\n function scheduleNext(timeoutMillisOverride) {\n if (queue.logger && queue.logger.debug) {\n queue.logger.debug(\"PromiseQueue.scheduleNext\", timeoutMillisOverride);\n }\n\n if (queue.isEmpty()) {\n queue.currentTaskTimeoutId = null;\n return;\n }\n\n queue.currentTaskTimeoutId = setTimeout(function () {\n queue.lastTaskTimestamp = Date.now();\n processNextTask();\n\n scheduleNext(queue.jobIntervalMillis);\n }, timeoutMillisOverride);\n }\n\n if (this.currentTaskTimeoutId == null) {\n if (this.lastTaskTimestamp) {\n let passedTime = Date.now() - this.lastTaskTimestamp;\n if (passedTime > this.jobIntervalMillis) {\n scheduleNext(this.jobIntervalMillis);\n } else {\n scheduleNext(Math.max(0, this.jobIntervalMillis - passedTime));\n }\n } else {\n scheduleNext(0);\n }\n }\n };\n\n /**\n * Starts the task processing of this queue.\n *\n * If it is already started, then false will be returned.\n * If it is not yet started then the first task will be processed in the background and true will be returned.\n *\n * @return {boolean} true if this queue wasn't started before and now started to process tasks.\n */\n start() {\n if (this.isActive) {\n return false;\n }\n\n this.isActive = true;\n\n this.updateTaskSchedule();\n\n return true;\n };\n\n /**\n * Stops the processing of this queue.\n * @return true if the queue was started and is now stopped. false if it was already stopped.\n */\n stop() {\n if (this.isActive) {\n this.isActive = false;\n\n if (this.currentTaskTimeoutId) {\n clearInterval(this.currentTaskTimeoutId);\n this.currentTaskTimeoutId = null;\n this.lastTaskTimestamp = null;\n }\n }\n };\n\n getMaxCallsPerSecond() {\n return this.maxCallsPerSecond;\n };\n\n isStarted() {\n return this.isActive;\n };\n\n isStopped() {\n return !this.isStarted();\n };\n\n /**\n * @returns {boolean} true if this queue is currently empty, i.e. if it has no tasks in the queue.\n */\n isEmpty() {\n return this.tasks.length === 0;\n };\n\n /**\n * @returns {boolean} true if this queue has one or more entries.\n */\n isNotEmpty() {\n return !this.isEmpty();\n };\n\n /**\n * @param {function} task - The task to add.\n * @param {boolean} append - if the task should be appended or prepended to the list of queued tasks\n * @return {Promise} A promise which is resolved/rejected when the task was executed by the queue.\n */\n async add(task, append) {\n var self = this;\n\n var promise = new Promise(function (resolve, reject) {\n var newTaskItem = { task: task, resolve: resolve, reject: reject };\n\n if (self.isEmpty() || append) {\n self.tasks.push(newTaskItem);\n } else {\n self.tasks.unshift(newTaskItem);\n }\n });\n\n self.updateTaskSchedule();\n\n return promise;\n };\n\n /**\n * Appends a new task at the end of the queue.\n * @param {function} task - The task to perform. This function will be called with no arguments.\n * @return {Promise} A promise which is resolved/rejected When the task was executed by the queue\n */\n async append(task) {\n return this.add(task, true);\n };\n\n /**\n * Adds a new task as first item in the queue.\n * @param task\n * @return {Promise} A promise which is resolved/rejected When the task was executed by the queue\n */\n async prepend(task) {\n return this.add(task, false);\n };\n\n /**\n * Removes the task from the qeueue. If the task is contained more than one time then all occurrences will be removed.\n * @param {function} task - The task to remove.\n * @return {number} - The number of items which were removed.\n */\n remove(task) {\n if (this.isEmpty()) {\n return 0;\n }\n\n var removedItems = 0;\n for (var i = this.tasks.length - 1; i >= 0; i--) {\n if (this.tasks[i].task === task) {\n this.tasks.splice(i, 1);\n removedItems++;\n }\n }\n\n return removedItems;\n };\n\n /**\n * @returns {Number} - The number of queued/waiting tasks in the queue.\n */\n getQueueSize() {\n return this.tasks.length;\n };\n\n};\n\nexport default PromiseQueue = new PromiseQueueClass(1, null);\n"],"names":[],"version":3,"file":"InventoryLogic.59be76a4.js.map"}