@simpleapps-com/augur-api 0.1.4 → 0.1.6
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 +2004 -405
- package/dist/cjs/core/client.d.ts +1 -0
- package/dist/cjs/core/client.d.ts.map +1 -1
- package/dist/cjs/core/client.js +5 -1
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/core/common-schemas.d.ts +2 -2
- package/dist/cjs/core/config.d.ts +2 -0
- package/dist/cjs/core/config.d.ts.map +1 -1
- package/dist/cjs/core/config.js.map +1 -1
- package/dist/cjs/core/response-capturer.d.ts +58 -0
- package/dist/cjs/core/response-capturer.d.ts.map +1 -0
- package/dist/cjs/core/response-capturer.js +167 -0
- package/dist/cjs/core/response-capturer.js.map +1 -0
- package/dist/cjs/core/schema-factories.d.ts +4 -4
- package/dist/cjs/core/schemas.d.ts +4 -4
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/agr-site/client.d.ts +97 -92
- package/dist/cjs/services/agr-site/client.d.ts.map +1 -1
- package/dist/cjs/services/agr-site/client.js +20 -4
- package/dist/cjs/services/agr-site/client.js.map +1 -1
- package/dist/cjs/services/agr-site/schemas/ai.d.ts +34 -34
- package/dist/cjs/services/agr-site/schemas/ai.js +5 -5
- package/dist/cjs/services/agr-site/schemas/ai.js.map +1 -1
- package/dist/cjs/services/agr-site/schemas/content.d.ts +310 -244
- package/dist/cjs/services/agr-site/schemas/content.d.ts.map +1 -1
- package/dist/cjs/services/agr-site/schemas/content.js +50 -35
- package/dist/cjs/services/agr-site/schemas/content.js.map +1 -1
- package/dist/cjs/services/agr-site/schemas/settings.d.ts +140 -153
- package/dist/cjs/services/agr-site/schemas/settings.d.ts.map +1 -1
- package/dist/cjs/services/agr-site/schemas/settings.js +24 -20
- package/dist/cjs/services/agr-site/schemas/settings.js.map +1 -1
- package/dist/cjs/services/commerce/client.d.ts +240 -35
- package/dist/cjs/services/commerce/client.d.ts.map +1 -1
- package/dist/cjs/services/commerce/client.js +1 -1
- package/dist/cjs/services/commerce/client.js.map +1 -1
- package/dist/cjs/services/commerce/schemas/cart.d.ts +134 -96
- package/dist/cjs/services/commerce/schemas/cart.d.ts.map +1 -1
- package/dist/cjs/services/commerce/schemas/cart.js +43 -33
- package/dist/cjs/services/commerce/schemas/cart.js.map +1 -1
- package/dist/cjs/services/commerce/schemas/checkout.d.ts +2139 -81
- package/dist/cjs/services/commerce/schemas/checkout.d.ts.map +1 -1
- package/dist/cjs/services/commerce/schemas/checkout.js +191 -12
- package/dist/cjs/services/commerce/schemas/checkout.js.map +1 -1
- package/dist/cjs/services/commerce/schemas/recommendations.d.ts +434 -18
- package/dist/cjs/services/commerce/schemas/recommendations.d.ts.map +1 -1
- package/dist/cjs/services/commerce/schemas/recommendations.js +50 -4
- package/dist/cjs/services/commerce/schemas/recommendations.js.map +1 -1
- package/dist/cjs/services/customers/client.d.ts +365 -203
- package/dist/cjs/services/customers/client.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/addresses.d.ts +422 -200
- package/dist/cjs/services/customers/schemas/addresses.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/addresses.js +35 -20
- package/dist/cjs/services/customers/schemas/addresses.js.map +1 -1
- package/dist/cjs/services/customers/schemas/contacts.d.ts +10 -10
- package/dist/cjs/services/customers/schemas/customers.d.ts +615 -534
- package/dist/cjs/services/customers/schemas/customers.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/customers.js +75 -57
- package/dist/cjs/services/customers/schemas/customers.js.map +1 -1
- package/dist/cjs/services/customers/schemas/index.d.ts +1 -0
- package/dist/cjs/services/customers/schemas/index.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/index.js +1 -0
- package/dist/cjs/services/customers/schemas/index.js.map +1 -1
- package/dist/cjs/services/customers/schemas/invoices.d.ts +643 -343
- package/dist/cjs/services/customers/schemas/invoices.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/invoices.js +58 -24
- package/dist/cjs/services/customers/schemas/invoices.js.map +1 -1
- package/dist/cjs/services/customers/schemas/orders.d.ts +1789 -177
- package/dist/cjs/services/customers/schemas/orders.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/orders.js +134 -10
- package/dist/cjs/services/customers/schemas/orders.js.map +1 -1
- package/dist/cjs/services/customers/schemas/purchased-items.d.ts +122 -0
- package/dist/cjs/services/customers/schemas/purchased-items.d.ts.map +1 -0
- package/dist/cjs/services/customers/schemas/purchased-items.js +32 -0
- package/dist/cjs/services/customers/schemas/purchased-items.js.map +1 -0
- package/dist/cjs/services/customers/schemas/quotes.d.ts +1925 -331
- package/dist/cjs/services/customers/schemas/quotes.d.ts.map +1 -1
- package/dist/cjs/services/customers/schemas/quotes.js +113 -23
- package/dist/cjs/services/customers/schemas/quotes.js.map +1 -1
- package/dist/cjs/services/items/client.d.ts +845 -117
- package/dist/cjs/services/items/client.d.ts.map +1 -1
- package/dist/cjs/services/items/client.js +241 -58
- package/dist/cjs/services/items/client.js.map +1 -1
- package/dist/cjs/services/items/schemas/alternateCode.d.ts +123 -0
- package/dist/cjs/services/items/schemas/alternateCode.d.ts.map +1 -0
- package/dist/cjs/services/items/schemas/alternateCode.js +26 -0
- package/dist/cjs/services/items/schemas/alternateCode.js.map +1 -0
- package/dist/cjs/services/items/schemas/attributeGroups.d.ts +295 -0
- package/dist/cjs/services/items/schemas/attributeGroups.d.ts.map +1 -0
- package/dist/cjs/services/items/schemas/attributeGroups.js +60 -0
- package/dist/cjs/services/items/schemas/attributeGroups.js.map +1 -0
- package/dist/cjs/services/items/schemas/attributes.d.ts +14 -290
- package/dist/cjs/services/items/schemas/attributes.d.ts.map +1 -1
- package/dist/cjs/services/items/schemas/attributes.js +1 -11
- package/dist/cjs/services/items/schemas/attributes.js.map +1 -1
- package/dist/cjs/services/items/schemas/brands.d.ts +150 -89
- package/dist/cjs/services/items/schemas/brands.d.ts.map +1 -1
- package/dist/cjs/services/items/schemas/brands.js +28 -12
- package/dist/cjs/services/items/schemas/brands.js.map +1 -1
- package/dist/cjs/services/items/schemas/categories.d.ts +505 -4
- package/dist/cjs/services/items/schemas/categories.d.ts.map +1 -1
- package/dist/cjs/services/items/schemas/categories.js +71 -2
- package/dist/cjs/services/items/schemas/categories.js.map +1 -1
- package/dist/cjs/services/items/schemas/index.d.ts +3 -0
- package/dist/cjs/services/items/schemas/index.d.ts.map +1 -1
- package/dist/cjs/services/items/schemas/index.js +3 -0
- package/dist/cjs/services/items/schemas/index.js.map +1 -1
- package/dist/cjs/services/items/schemas/invLoc.d.ts +444 -0
- package/dist/cjs/services/items/schemas/invLoc.d.ts.map +1 -0
- package/dist/cjs/services/items/schemas/invLoc.js +45 -0
- package/dist/cjs/services/items/schemas/invLoc.js.map +1 -0
- package/dist/cjs/services/items/schemas/products.d.ts +978 -45
- package/dist/cjs/services/items/schemas/products.d.ts.map +1 -1
- package/dist/cjs/services/items/schemas/products.js +140 -8
- package/dist/cjs/services/items/schemas/products.js.map +1 -1
- package/dist/cjs/services/joomla/client.d.ts +38 -26
- package/dist/cjs/services/joomla/client.d.ts.map +1 -1
- package/dist/cjs/services/joomla/client.js +22 -0
- package/dist/cjs/services/joomla/client.js.map +1 -1
- package/dist/cjs/services/joomla/schemas/content.d.ts +6 -6
- package/dist/cjs/services/joomla/schemas/groups.d.ts +25 -2
- package/dist/cjs/services/joomla/schemas/groups.d.ts.map +1 -1
- package/dist/cjs/services/joomla/schemas/groups.js +3 -1
- package/dist/cjs/services/joomla/schemas/groups.js.map +1 -1
- package/dist/cjs/services/joomla/schemas/users.d.ts +455 -441
- package/dist/cjs/services/joomla/schemas/users.d.ts.map +1 -1
- package/dist/cjs/services/joomla/schemas/users.js +82 -58
- package/dist/cjs/services/joomla/schemas/users.js.map +1 -1
- package/dist/cjs/services/legacy/client.d.ts +81 -81
- package/dist/cjs/services/legacy/client.d.ts.map +1 -1
- package/dist/cjs/services/legacy/schemas/inventory.d.ts +1071 -422
- package/dist/cjs/services/legacy/schemas/inventory.d.ts.map +1 -1
- package/dist/cjs/services/legacy/schemas/inventory.js +141 -48
- package/dist/cjs/services/legacy/schemas/inventory.js.map +1 -1
- package/dist/cjs/services/legacy/schemas/orders.d.ts +4 -44
- package/dist/cjs/services/legacy/schemas/orders.d.ts.map +1 -1
- package/dist/cjs/services/legacy/schemas/orders.js +2 -7
- package/dist/cjs/services/legacy/schemas/orders.js.map +1 -1
- package/dist/cjs/services/legacy/schemas/states.d.ts +264 -264
- package/dist/cjs/services/legacy/schemas/states.d.ts.map +1 -1
- package/dist/cjs/services/legacy/schemas/states.js +32 -25
- package/dist/cjs/services/legacy/schemas/states.js.map +1 -1
- package/dist/cjs/services/nexus/client.d.ts +6 -6
- package/dist/cjs/services/nexus/schemas/bin-transfers.d.ts +2 -2
- package/dist/cjs/services/nexus/schemas/receiving.d.ts +4 -4
- package/dist/cjs/services/nexus/schemas/transfers.d.ts +6 -6
- package/dist/cjs/services/open-search/client.d.ts +139 -41
- package/dist/cjs/services/open-search/client.d.ts.map +1 -1
- package/dist/cjs/services/open-search/client.js +17 -11
- package/dist/cjs/services/open-search/client.js.map +1 -1
- package/dist/cjs/services/open-search/index.d.ts +1 -1
- package/dist/cjs/services/open-search/index.d.ts.map +1 -1
- package/dist/cjs/services/open-search/schemas/attributes.d.ts +110 -41
- package/dist/cjs/services/open-search/schemas/attributes.d.ts.map +1 -1
- package/dist/cjs/services/open-search/schemas/attributes.js +13 -2
- package/dist/cjs/services/open-search/schemas/attributes.js.map +1 -1
- package/dist/cjs/services/open-search/schemas/items.d.ts +953 -146
- package/dist/cjs/services/open-search/schemas/items.d.ts.map +1 -1
- package/dist/cjs/services/open-search/schemas/items.js +84 -22
- package/dist/cjs/services/open-search/schemas/items.js.map +1 -1
- package/dist/cjs/services/open-search/schemas/search.d.ts +299 -95
- package/dist/cjs/services/open-search/schemas/search.d.ts.map +1 -1
- package/dist/cjs/services/open-search/schemas/search.js +19 -7
- package/dist/cjs/services/open-search/schemas/search.js.map +1 -1
- package/dist/cjs/services/orders/client.d.ts +19 -19
- package/dist/cjs/services/orders/schemas/orders.d.ts +60 -60
- package/dist/cjs/services/orders/schemas/purchase-orders.d.ts +44 -44
- package/dist/cjs/services/orders/schemas/salesrep.d.ts +12 -12
- package/dist/cjs/services/p21-pim/client.d.ts +129 -134
- package/dist/cjs/services/p21-pim/client.d.ts.map +1 -1
- package/dist/cjs/services/p21-pim/client.js +4 -2
- package/dist/cjs/services/p21-pim/client.js.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/ai-suggestions.d.ts +152 -8
- package/dist/cjs/services/p21-pim/schemas/ai-suggestions.d.ts.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/ai-suggestions.js +28 -6
- package/dist/cjs/services/p21-pim/schemas/ai-suggestions.js.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/inventory.d.ts +663 -308
- package/dist/cjs/services/p21-pim/schemas/inventory.d.ts.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/inventory.js +63 -41
- package/dist/cjs/services/p21-pim/schemas/inventory.js.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/podcasts.d.ts +139 -120
- package/dist/cjs/services/p21-pim/schemas/podcasts.d.ts.map +1 -1
- package/dist/cjs/services/p21-pim/schemas/podcasts.js +32 -16
- package/dist/cjs/services/p21-pim/schemas/podcasts.js.map +1 -1
- package/dist/cjs/services/payments/client.d.ts +5 -5
- package/dist/cjs/services/payments/schemas/element.d.ts +4 -4
- package/dist/cjs/services/payments/schemas/unified.d.ts +40 -40
- package/dist/cjs/services/pricing/client.d.ts +1 -1
- package/dist/cjs/services/pricing/schemas/job-pricing.d.ts +24 -24
- package/dist/cjs/services/pricing/schemas/pricing.d.ts +14 -14
- package/dist/cjs/services/pricing/schemas/tax.d.ts +14 -14
- package/dist/cjs/services/vmi/client.d.ts +6 -6
- package/dist/cjs/services/vmi/schemas/inventory.d.ts +18 -18
- package/dist/cjs/services/vmi/schemas/products.d.ts +16 -16
- package/dist/cjs/services/vmi/schemas/profiles.d.ts +4 -4
- package/dist/cjs/services/vmi/schemas/restock.d.ts +14 -14
- package/dist/cjs/services/vmi/schemas/warehouse.d.ts +10 -10
- package/dist/cjs/utils/cross-site-auth.d.ts +88 -0
- package/dist/cjs/utils/cross-site-auth.d.ts.map +1 -0
- package/dist/cjs/utils/cross-site-auth.js +107 -0
- package/dist/cjs/utils/cross-site-auth.js.map +1 -0
- package/dist/esm/core/client.d.ts +1 -0
- package/dist/esm/core/client.d.ts.map +1 -1
- package/dist/esm/core/client.js +5 -1
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/core/common-schemas.d.ts +2 -2
- package/dist/esm/core/config.d.ts +2 -0
- package/dist/esm/core/config.d.ts.map +1 -1
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/response-capturer.d.ts +58 -0
- package/dist/esm/core/response-capturer.d.ts.map +1 -0
- package/dist/esm/core/response-capturer.js +130 -0
- package/dist/esm/core/response-capturer.js.map +1 -0
- package/dist/esm/core/schema-factories.d.ts +4 -4
- package/dist/esm/core/schemas.d.ts +4 -4
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/agr-site/client.d.ts +97 -92
- package/dist/esm/services/agr-site/client.d.ts.map +1 -1
- package/dist/esm/services/agr-site/client.js +21 -5
- package/dist/esm/services/agr-site/client.js.map +1 -1
- package/dist/esm/services/agr-site/schemas/ai.d.ts +34 -34
- package/dist/esm/services/agr-site/schemas/ai.js +5 -5
- package/dist/esm/services/agr-site/schemas/ai.js.map +1 -1
- package/dist/esm/services/agr-site/schemas/content.d.ts +310 -244
- package/dist/esm/services/agr-site/schemas/content.d.ts.map +1 -1
- package/dist/esm/services/agr-site/schemas/content.js +49 -34
- package/dist/esm/services/agr-site/schemas/content.js.map +1 -1
- package/dist/esm/services/agr-site/schemas/settings.d.ts +140 -153
- package/dist/esm/services/agr-site/schemas/settings.d.ts.map +1 -1
- package/dist/esm/services/agr-site/schemas/settings.js +24 -20
- package/dist/esm/services/agr-site/schemas/settings.js.map +1 -1
- package/dist/esm/services/commerce/client.d.ts +240 -35
- package/dist/esm/services/commerce/client.d.ts.map +1 -1
- package/dist/esm/services/commerce/client.js +2 -2
- package/dist/esm/services/commerce/client.js.map +1 -1
- package/dist/esm/services/commerce/schemas/cart.d.ts +134 -96
- package/dist/esm/services/commerce/schemas/cart.d.ts.map +1 -1
- package/dist/esm/services/commerce/schemas/cart.js +42 -32
- package/dist/esm/services/commerce/schemas/cart.js.map +1 -1
- package/dist/esm/services/commerce/schemas/checkout.d.ts +2139 -81
- package/dist/esm/services/commerce/schemas/checkout.d.ts.map +1 -1
- package/dist/esm/services/commerce/schemas/checkout.js +190 -11
- package/dist/esm/services/commerce/schemas/checkout.js.map +1 -1
- package/dist/esm/services/commerce/schemas/recommendations.d.ts +434 -18
- package/dist/esm/services/commerce/schemas/recommendations.d.ts.map +1 -1
- package/dist/esm/services/commerce/schemas/recommendations.js +49 -3
- package/dist/esm/services/commerce/schemas/recommendations.js.map +1 -1
- package/dist/esm/services/customers/client.d.ts +365 -203
- package/dist/esm/services/customers/client.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/addresses.d.ts +422 -200
- package/dist/esm/services/customers/schemas/addresses.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/addresses.js +34 -19
- package/dist/esm/services/customers/schemas/addresses.js.map +1 -1
- package/dist/esm/services/customers/schemas/contacts.d.ts +10 -10
- package/dist/esm/services/customers/schemas/customers.d.ts +615 -534
- package/dist/esm/services/customers/schemas/customers.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/customers.js +74 -56
- package/dist/esm/services/customers/schemas/customers.js.map +1 -1
- package/dist/esm/services/customers/schemas/index.d.ts +1 -0
- package/dist/esm/services/customers/schemas/index.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/index.js +1 -0
- package/dist/esm/services/customers/schemas/index.js.map +1 -1
- package/dist/esm/services/customers/schemas/invoices.d.ts +643 -343
- package/dist/esm/services/customers/schemas/invoices.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/invoices.js +58 -24
- package/dist/esm/services/customers/schemas/invoices.js.map +1 -1
- package/dist/esm/services/customers/schemas/orders.d.ts +1789 -177
- package/dist/esm/services/customers/schemas/orders.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/orders.js +133 -10
- package/dist/esm/services/customers/schemas/orders.js.map +1 -1
- package/dist/esm/services/customers/schemas/purchased-items.d.ts +122 -0
- package/dist/esm/services/customers/schemas/purchased-items.d.ts.map +1 -0
- package/dist/esm/services/customers/schemas/purchased-items.js +29 -0
- package/dist/esm/services/customers/schemas/purchased-items.js.map +1 -0
- package/dist/esm/services/customers/schemas/quotes.d.ts +1925 -331
- package/dist/esm/services/customers/schemas/quotes.d.ts.map +1 -1
- package/dist/esm/services/customers/schemas/quotes.js +113 -23
- package/dist/esm/services/customers/schemas/quotes.js.map +1 -1
- package/dist/esm/services/items/client.d.ts +845 -117
- package/dist/esm/services/items/client.d.ts.map +1 -1
- package/dist/esm/services/items/client.js +251 -64
- package/dist/esm/services/items/client.js.map +1 -1
- package/dist/esm/services/items/schemas/alternateCode.d.ts +123 -0
- package/dist/esm/services/items/schemas/alternateCode.d.ts.map +1 -0
- package/dist/esm/services/items/schemas/alternateCode.js +23 -0
- package/dist/esm/services/items/schemas/alternateCode.js.map +1 -0
- package/dist/esm/services/items/schemas/attributeGroups.d.ts +295 -0
- package/dist/esm/services/items/schemas/attributeGroups.d.ts.map +1 -0
- package/dist/esm/services/items/schemas/attributeGroups.js +57 -0
- package/dist/esm/services/items/schemas/attributeGroups.js.map +1 -0
- package/dist/esm/services/items/schemas/attributes.d.ts +14 -290
- package/dist/esm/services/items/schemas/attributes.d.ts.map +1 -1
- package/dist/esm/services/items/schemas/attributes.js +0 -10
- package/dist/esm/services/items/schemas/attributes.js.map +1 -1
- package/dist/esm/services/items/schemas/brands.d.ts +150 -89
- package/dist/esm/services/items/schemas/brands.d.ts.map +1 -1
- package/dist/esm/services/items/schemas/brands.js +27 -11
- package/dist/esm/services/items/schemas/brands.js.map +1 -1
- package/dist/esm/services/items/schemas/categories.d.ts +505 -4
- package/dist/esm/services/items/schemas/categories.d.ts.map +1 -1
- package/dist/esm/services/items/schemas/categories.js +70 -1
- package/dist/esm/services/items/schemas/categories.js.map +1 -1
- package/dist/esm/services/items/schemas/index.d.ts +3 -0
- package/dist/esm/services/items/schemas/index.d.ts.map +1 -1
- package/dist/esm/services/items/schemas/index.js +3 -0
- package/dist/esm/services/items/schemas/index.js.map +1 -1
- package/dist/esm/services/items/schemas/invLoc.d.ts +444 -0
- package/dist/esm/services/items/schemas/invLoc.d.ts.map +1 -0
- package/dist/esm/services/items/schemas/invLoc.js +42 -0
- package/dist/esm/services/items/schemas/invLoc.js.map +1 -0
- package/dist/esm/services/items/schemas/products.d.ts +978 -45
- package/dist/esm/services/items/schemas/products.d.ts.map +1 -1
- package/dist/esm/services/items/schemas/products.js +139 -7
- package/dist/esm/services/items/schemas/products.js.map +1 -1
- package/dist/esm/services/joomla/client.d.ts +38 -26
- package/dist/esm/services/joomla/client.d.ts.map +1 -1
- package/dist/esm/services/joomla/client.js +23 -1
- package/dist/esm/services/joomla/client.js.map +1 -1
- package/dist/esm/services/joomla/schemas/content.d.ts +6 -6
- package/dist/esm/services/joomla/schemas/groups.d.ts +25 -2
- package/dist/esm/services/joomla/schemas/groups.d.ts.map +1 -1
- package/dist/esm/services/joomla/schemas/groups.js +2 -0
- package/dist/esm/services/joomla/schemas/groups.js.map +1 -1
- package/dist/esm/services/joomla/schemas/users.d.ts +455 -441
- package/dist/esm/services/joomla/schemas/users.d.ts.map +1 -1
- package/dist/esm/services/joomla/schemas/users.js +82 -58
- package/dist/esm/services/joomla/schemas/users.js.map +1 -1
- package/dist/esm/services/legacy/client.d.ts +81 -81
- package/dist/esm/services/legacy/client.d.ts.map +1 -1
- package/dist/esm/services/legacy/schemas/inventory.d.ts +1071 -422
- package/dist/esm/services/legacy/schemas/inventory.d.ts.map +1 -1
- package/dist/esm/services/legacy/schemas/inventory.js +141 -48
- package/dist/esm/services/legacy/schemas/inventory.js.map +1 -1
- package/dist/esm/services/legacy/schemas/orders.d.ts +4 -44
- package/dist/esm/services/legacy/schemas/orders.d.ts.map +1 -1
- package/dist/esm/services/legacy/schemas/orders.js +2 -7
- package/dist/esm/services/legacy/schemas/orders.js.map +1 -1
- package/dist/esm/services/legacy/schemas/states.d.ts +264 -264
- package/dist/esm/services/legacy/schemas/states.d.ts.map +1 -1
- package/dist/esm/services/legacy/schemas/states.js +32 -25
- package/dist/esm/services/legacy/schemas/states.js.map +1 -1
- package/dist/esm/services/nexus/client.d.ts +6 -6
- package/dist/esm/services/nexus/schemas/bin-transfers.d.ts +2 -2
- package/dist/esm/services/nexus/schemas/receiving.d.ts +4 -4
- package/dist/esm/services/nexus/schemas/transfers.d.ts +6 -6
- package/dist/esm/services/open-search/client.d.ts +139 -41
- package/dist/esm/services/open-search/client.d.ts.map +1 -1
- package/dist/esm/services/open-search/client.js +18 -12
- package/dist/esm/services/open-search/client.js.map +1 -1
- package/dist/esm/services/open-search/index.d.ts +1 -1
- package/dist/esm/services/open-search/index.d.ts.map +1 -1
- package/dist/esm/services/open-search/schemas/attributes.d.ts +110 -41
- package/dist/esm/services/open-search/schemas/attributes.d.ts.map +1 -1
- package/dist/esm/services/open-search/schemas/attributes.js +13 -2
- package/dist/esm/services/open-search/schemas/attributes.js.map +1 -1
- package/dist/esm/services/open-search/schemas/items.d.ts +953 -146
- package/dist/esm/services/open-search/schemas/items.d.ts.map +1 -1
- package/dist/esm/services/open-search/schemas/items.js +83 -21
- package/dist/esm/services/open-search/schemas/items.js.map +1 -1
- package/dist/esm/services/open-search/schemas/search.d.ts +299 -95
- package/dist/esm/services/open-search/schemas/search.d.ts.map +1 -1
- package/dist/esm/services/open-search/schemas/search.js +19 -7
- package/dist/esm/services/open-search/schemas/search.js.map +1 -1
- package/dist/esm/services/orders/client.d.ts +19 -19
- package/dist/esm/services/orders/schemas/orders.d.ts +60 -60
- package/dist/esm/services/orders/schemas/purchase-orders.d.ts +44 -44
- package/dist/esm/services/orders/schemas/salesrep.d.ts +12 -12
- package/dist/esm/services/p21-pim/client.d.ts +129 -134
- package/dist/esm/services/p21-pim/client.d.ts.map +1 -1
- package/dist/esm/services/p21-pim/client.js +5 -3
- package/dist/esm/services/p21-pim/client.js.map +1 -1
- package/dist/esm/services/p21-pim/schemas/ai-suggestions.d.ts +152 -8
- package/dist/esm/services/p21-pim/schemas/ai-suggestions.d.ts.map +1 -1
- package/dist/esm/services/p21-pim/schemas/ai-suggestions.js +27 -5
- package/dist/esm/services/p21-pim/schemas/ai-suggestions.js.map +1 -1
- package/dist/esm/services/p21-pim/schemas/inventory.d.ts +663 -308
- package/dist/esm/services/p21-pim/schemas/inventory.d.ts.map +1 -1
- package/dist/esm/services/p21-pim/schemas/inventory.js +63 -41
- package/dist/esm/services/p21-pim/schemas/inventory.js.map +1 -1
- package/dist/esm/services/p21-pim/schemas/podcasts.d.ts +139 -120
- package/dist/esm/services/p21-pim/schemas/podcasts.d.ts.map +1 -1
- package/dist/esm/services/p21-pim/schemas/podcasts.js +32 -16
- package/dist/esm/services/p21-pim/schemas/podcasts.js.map +1 -1
- package/dist/esm/services/payments/client.d.ts +5 -5
- package/dist/esm/services/payments/schemas/element.d.ts +4 -4
- package/dist/esm/services/payments/schemas/unified.d.ts +40 -40
- package/dist/esm/services/pricing/client.d.ts +1 -1
- package/dist/esm/services/pricing/schemas/job-pricing.d.ts +24 -24
- package/dist/esm/services/pricing/schemas/pricing.d.ts +14 -14
- package/dist/esm/services/pricing/schemas/tax.d.ts +14 -14
- package/dist/esm/services/vmi/client.d.ts +6 -6
- package/dist/esm/services/vmi/schemas/inventory.d.ts +18 -18
- package/dist/esm/services/vmi/schemas/products.d.ts +16 -16
- package/dist/esm/services/vmi/schemas/profiles.d.ts +4 -4
- package/dist/esm/services/vmi/schemas/restock.d.ts +14 -14
- package/dist/esm/services/vmi/schemas/warehouse.d.ts +10 -10
- package/dist/esm/utils/cross-site-auth.d.ts +88 -0
- package/dist/esm/utils/cross-site-auth.d.ts.map +1 -0
- package/dist/esm/utils/cross-site-auth.js +103 -0
- package/dist/esm/utils/cross-site-auth.js.map +1 -0
- package/dist/types/core/client.d.ts +1 -0
- package/dist/types/core/client.d.ts.map +1 -1
- package/dist/types/core/common-schemas.d.ts +2 -2
- package/dist/types/core/config.d.ts +2 -0
- package/dist/types/core/config.d.ts.map +1 -1
- package/dist/types/core/response-capturer.d.ts +58 -0
- package/dist/types/core/response-capturer.d.ts.map +1 -0
- package/dist/types/core/schema-factories.d.ts +4 -4
- package/dist/types/core/schemas.d.ts +4 -4
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/agr-site/client.d.ts +97 -92
- package/dist/types/services/agr-site/client.d.ts.map +1 -1
- package/dist/types/services/agr-site/schemas/ai.d.ts +34 -34
- package/dist/types/services/agr-site/schemas/content.d.ts +310 -244
- package/dist/types/services/agr-site/schemas/content.d.ts.map +1 -1
- package/dist/types/services/agr-site/schemas/settings.d.ts +140 -153
- package/dist/types/services/agr-site/schemas/settings.d.ts.map +1 -1
- package/dist/types/services/commerce/client.d.ts +240 -35
- package/dist/types/services/commerce/client.d.ts.map +1 -1
- package/dist/types/services/commerce/schemas/cart.d.ts +134 -96
- package/dist/types/services/commerce/schemas/cart.d.ts.map +1 -1
- package/dist/types/services/commerce/schemas/checkout.d.ts +2139 -81
- package/dist/types/services/commerce/schemas/checkout.d.ts.map +1 -1
- package/dist/types/services/commerce/schemas/recommendations.d.ts +434 -18
- package/dist/types/services/commerce/schemas/recommendations.d.ts.map +1 -1
- package/dist/types/services/customers/client.d.ts +365 -203
- package/dist/types/services/customers/client.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/addresses.d.ts +422 -200
- package/dist/types/services/customers/schemas/addresses.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/contacts.d.ts +10 -10
- package/dist/types/services/customers/schemas/customers.d.ts +615 -534
- package/dist/types/services/customers/schemas/customers.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/index.d.ts +1 -0
- package/dist/types/services/customers/schemas/index.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/invoices.d.ts +643 -343
- package/dist/types/services/customers/schemas/invoices.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/orders.d.ts +1789 -177
- package/dist/types/services/customers/schemas/orders.d.ts.map +1 -1
- package/dist/types/services/customers/schemas/purchased-items.d.ts +122 -0
- package/dist/types/services/customers/schemas/purchased-items.d.ts.map +1 -0
- package/dist/types/services/customers/schemas/quotes.d.ts +1925 -331
- package/dist/types/services/customers/schemas/quotes.d.ts.map +1 -1
- package/dist/types/services/items/client.d.ts +845 -117
- package/dist/types/services/items/client.d.ts.map +1 -1
- package/dist/types/services/items/schemas/alternateCode.d.ts +123 -0
- package/dist/types/services/items/schemas/alternateCode.d.ts.map +1 -0
- package/dist/types/services/items/schemas/attributeGroups.d.ts +295 -0
- package/dist/types/services/items/schemas/attributeGroups.d.ts.map +1 -0
- package/dist/types/services/items/schemas/attributes.d.ts +14 -290
- package/dist/types/services/items/schemas/attributes.d.ts.map +1 -1
- package/dist/types/services/items/schemas/brands.d.ts +150 -89
- package/dist/types/services/items/schemas/brands.d.ts.map +1 -1
- package/dist/types/services/items/schemas/categories.d.ts +505 -4
- package/dist/types/services/items/schemas/categories.d.ts.map +1 -1
- package/dist/types/services/items/schemas/index.d.ts +3 -0
- package/dist/types/services/items/schemas/index.d.ts.map +1 -1
- package/dist/types/services/items/schemas/invLoc.d.ts +444 -0
- package/dist/types/services/items/schemas/invLoc.d.ts.map +1 -0
- package/dist/types/services/items/schemas/products.d.ts +978 -45
- package/dist/types/services/items/schemas/products.d.ts.map +1 -1
- package/dist/types/services/joomla/client.d.ts +38 -26
- package/dist/types/services/joomla/client.d.ts.map +1 -1
- package/dist/types/services/joomla/schemas/content.d.ts +6 -6
- package/dist/types/services/joomla/schemas/groups.d.ts +25 -2
- package/dist/types/services/joomla/schemas/groups.d.ts.map +1 -1
- package/dist/types/services/joomla/schemas/users.d.ts +455 -441
- package/dist/types/services/joomla/schemas/users.d.ts.map +1 -1
- package/dist/types/services/legacy/client.d.ts +81 -81
- package/dist/types/services/legacy/client.d.ts.map +1 -1
- package/dist/types/services/legacy/schemas/inventory.d.ts +1071 -422
- package/dist/types/services/legacy/schemas/inventory.d.ts.map +1 -1
- package/dist/types/services/legacy/schemas/orders.d.ts +4 -44
- package/dist/types/services/legacy/schemas/orders.d.ts.map +1 -1
- package/dist/types/services/legacy/schemas/states.d.ts +264 -264
- package/dist/types/services/legacy/schemas/states.d.ts.map +1 -1
- package/dist/types/services/nexus/client.d.ts +6 -6
- package/dist/types/services/nexus/schemas/bin-transfers.d.ts +2 -2
- package/dist/types/services/nexus/schemas/receiving.d.ts +4 -4
- package/dist/types/services/nexus/schemas/transfers.d.ts +6 -6
- package/dist/types/services/open-search/client.d.ts +139 -41
- package/dist/types/services/open-search/client.d.ts.map +1 -1
- package/dist/types/services/open-search/index.d.ts +1 -1
- package/dist/types/services/open-search/index.d.ts.map +1 -1
- package/dist/types/services/open-search/schemas/attributes.d.ts +110 -41
- package/dist/types/services/open-search/schemas/attributes.d.ts.map +1 -1
- package/dist/types/services/open-search/schemas/items.d.ts +953 -146
- package/dist/types/services/open-search/schemas/items.d.ts.map +1 -1
- package/dist/types/services/open-search/schemas/search.d.ts +299 -95
- package/dist/types/services/open-search/schemas/search.d.ts.map +1 -1
- package/dist/types/services/orders/client.d.ts +19 -19
- package/dist/types/services/orders/schemas/orders.d.ts +60 -60
- package/dist/types/services/orders/schemas/purchase-orders.d.ts +44 -44
- package/dist/types/services/orders/schemas/salesrep.d.ts +12 -12
- package/dist/types/services/p21-pim/client.d.ts +129 -134
- package/dist/types/services/p21-pim/client.d.ts.map +1 -1
- package/dist/types/services/p21-pim/schemas/ai-suggestions.d.ts +152 -8
- package/dist/types/services/p21-pim/schemas/ai-suggestions.d.ts.map +1 -1
- package/dist/types/services/p21-pim/schemas/inventory.d.ts +663 -308
- package/dist/types/services/p21-pim/schemas/inventory.d.ts.map +1 -1
- package/dist/types/services/p21-pim/schemas/podcasts.d.ts +139 -120
- package/dist/types/services/p21-pim/schemas/podcasts.d.ts.map +1 -1
- package/dist/types/services/payments/client.d.ts +5 -5
- package/dist/types/services/payments/schemas/element.d.ts +4 -4
- package/dist/types/services/payments/schemas/unified.d.ts +40 -40
- package/dist/types/services/pricing/client.d.ts +1 -1
- package/dist/types/services/pricing/schemas/job-pricing.d.ts +24 -24
- package/dist/types/services/pricing/schemas/pricing.d.ts +14 -14
- package/dist/types/services/pricing/schemas/tax.d.ts +14 -14
- package/dist/types/services/vmi/client.d.ts +6 -6
- package/dist/types/services/vmi/schemas/inventory.d.ts +18 -18
- package/dist/types/services/vmi/schemas/products.d.ts +16 -16
- package/dist/types/services/vmi/schemas/profiles.d.ts +4 -4
- package/dist/types/services/vmi/schemas/restock.d.ts +14 -14
- package/dist/types/services/vmi/schemas/warehouse.d.ts +10 -10
- package/dist/types/utils/cross-site-auth.d.ts +88 -0
- package/dist/types/utils/cross-site-auth.d.ts.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,346 +1,501 @@
|
|
|
1
1
|
# Augur API Client Library
|
|
2
2
|
|
|
3
|
-
A TypeScript client library for accessing Augur microservices with type safety, runtime validation, and excellent developer experience.
|
|
3
|
+
A comprehensive TypeScript client library for accessing Augur microservices with type safety, runtime validation, edge caching, and excellent developer experience.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Features](#features)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Getting Started](#getting-started)
|
|
11
|
+
- [Authentication & Security](#authentication--security)
|
|
12
|
+
- [API Documentation](#api-documentation)
|
|
13
|
+
- [Advanced Features](#advanced-features)
|
|
14
|
+
- [Integration Guides](#integration-guides)
|
|
15
|
+
- [Error Handling](#error-handling)
|
|
16
|
+
- [Configuration](#configuration)
|
|
17
|
+
- [Performance Optimization](#performance-optimization)
|
|
18
|
+
- [Development](#development)
|
|
19
|
+
- [Contributing](#contributing)
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
The Augur API Client Library provides a unified TypeScript SDK for accessing Augur's microservices ecosystem. Built with modern web development in mind, it offers seamless integration with React, React Native, Next.js, and Node.js applications.
|
|
24
|
+
|
|
25
|
+
### Key Capabilities
|
|
26
|
+
|
|
27
|
+
- **13 Microservice Clients**: Comprehensive coverage of Joomla, Commerce, Pricing, VMI, OpenSearch, Items, Legacy, Nexus, AGR Site, Customers, Orders, P21 PIM, and Payments services
|
|
28
|
+
- **Type-Safe Operations**: Full TypeScript support with auto-generated types from Zod schemas
|
|
29
|
+
- **Edge Caching**: Built-in Cloudflare integration for optimal performance
|
|
30
|
+
- **Cross-Site Authentication**: Support for multi-tenant applications
|
|
31
|
+
- **Runtime Validation**: Zod schemas validate all requests and responses
|
|
32
|
+
- **Developer Experience**: Rich JSDoc documentation and IntelliSense support
|
|
4
33
|
|
|
5
34
|
## Features
|
|
6
35
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
✅ **Simple API** - Intuitive method names following REST conventions
|
|
37
|
+
✅ **Type Safe** - Full TypeScript support with auto-completion
|
|
38
|
+
✅ **Runtime Validation** - Zod schemas validate all requests and responses
|
|
39
|
+
✅ **Automatic Retries** - Built-in retry logic for failed requests
|
|
40
|
+
✅ **Smart Authentication** - Handles JWT tokens and site IDs automatically
|
|
41
|
+
✅ **Edge Caching** - Cloudflare integration for sub-100ms response times
|
|
42
|
+
✅ **Multi-Platform** - Works in React Native, React, Next.js, Node.js, and Electron
|
|
43
|
+
✅ **Great DX** - Helpful error messages and comprehensive JSDoc documentation
|
|
44
|
+
✅ **Cross-Site Auth** - Multi-tenant authentication support
|
|
13
45
|
|
|
14
46
|
## Installation
|
|
15
47
|
|
|
16
48
|
```bash
|
|
17
|
-
npm install @augur
|
|
49
|
+
npm install @simpleapps-com/augur-api
|
|
18
50
|
# or
|
|
19
|
-
yarn add @augur
|
|
51
|
+
yarn add @simpleapps-com/augur-api
|
|
52
|
+
# or
|
|
53
|
+
pnpm add @simpleapps-com/augur-api
|
|
20
54
|
```
|
|
21
55
|
|
|
22
|
-
|
|
56
|
+
### System Requirements
|
|
57
|
+
|
|
58
|
+
- Node.js >= 16.0.0
|
|
59
|
+
- TypeScript >= 4.5.0 (for TypeScript projects)
|
|
60
|
+
|
|
61
|
+
## Getting Started
|
|
62
|
+
|
|
63
|
+
### Basic Setup
|
|
23
64
|
|
|
24
65
|
```typescript
|
|
25
|
-
import { AugurAPI } from '@augur
|
|
66
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
26
67
|
|
|
27
68
|
// Initialize the client
|
|
28
69
|
const api = new AugurAPI({
|
|
29
|
-
siteId: 'your-site-id',
|
|
30
|
-
bearerToken: 'your-jwt-token',
|
|
70
|
+
siteId: 'your-site-id', // Required for all endpoints
|
|
71
|
+
bearerToken: 'your-jwt-token', // Required except for health checks
|
|
31
72
|
});
|
|
32
73
|
|
|
33
|
-
// Make API
|
|
34
|
-
const users = await api.joomla.users.list(
|
|
35
|
-
|
|
74
|
+
// Make your first API call
|
|
75
|
+
const users = await api.joomla.users.list({
|
|
76
|
+
limit: 10,
|
|
77
|
+
edgeCache: 2 // Cache for 2 hours
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log(`Found ${users.data.length} users`);
|
|
36
81
|
```
|
|
37
82
|
|
|
38
|
-
|
|
83
|
+
### Environment Setup
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// .env file
|
|
87
|
+
AUGUR_SITE_ID=your-site-id
|
|
88
|
+
AUGUR_JWT_TOKEN=your-jwt-token
|
|
39
89
|
|
|
40
|
-
|
|
90
|
+
// app.ts
|
|
91
|
+
const api = new AugurAPI({
|
|
92
|
+
siteId: process.env.AUGUR_SITE_ID!,
|
|
93
|
+
bearerToken: process.env.AUGUR_JWT_TOKEN!,
|
|
94
|
+
});
|
|
95
|
+
```
|
|
41
96
|
|
|
42
|
-
|
|
43
|
-
2. **Bearer Token** (required for all endpoints except `/health-check`): JWT token in Authorization header
|
|
97
|
+
### Quick Example: E-commerce Operations
|
|
44
98
|
|
|
45
99
|
```typescript
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
100
|
+
// Get product recommendations
|
|
101
|
+
const recommendations = await api.commerce.alsoBought.get({
|
|
102
|
+
itemId: 'WIRE-123',
|
|
103
|
+
customerId: 12345,
|
|
104
|
+
edgeCache: 4 // Cache recommendations for 4 hours
|
|
49
105
|
});
|
|
50
106
|
|
|
51
|
-
//
|
|
52
|
-
const
|
|
107
|
+
// Get real-time pricing
|
|
108
|
+
const pricing = await api.pricing.getPrice({
|
|
109
|
+
customerId: 12345,
|
|
110
|
+
itemId: 'WIRE-123',
|
|
111
|
+
quantity: 100,
|
|
112
|
+
edgeCache: 3 // Cache standard pricing for 3 hours
|
|
113
|
+
});
|
|
53
114
|
|
|
54
|
-
//
|
|
55
|
-
const
|
|
115
|
+
// Search for products
|
|
116
|
+
const searchResults = await api.opensearch.itemSearch.search({
|
|
117
|
+
q: 'electrical wire 12 AWG',
|
|
118
|
+
searchType: 'query',
|
|
119
|
+
size: 20,
|
|
120
|
+
edgeCache: 2 // Cache search results for 2 hours
|
|
121
|
+
});
|
|
56
122
|
```
|
|
57
123
|
|
|
58
|
-
##
|
|
124
|
+
## Authentication & Security
|
|
59
125
|
|
|
60
|
-
|
|
126
|
+
### Dual Authentication System
|
|
61
127
|
|
|
62
|
-
|
|
128
|
+
The Augur API uses a dual authentication system:
|
|
63
129
|
|
|
64
|
-
|
|
130
|
+
1. **Site ID** (`x-site-id` header) - Required for ALL endpoints
|
|
131
|
+
2. **Bearer Token** (JWT) - Required for all endpoints EXCEPT health checks
|
|
65
132
|
|
|
66
133
|
```typescript
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
limit: 20
|
|
134
|
+
const api = new AugurAPI({
|
|
135
|
+
siteId: 'your-site-id', // Always required
|
|
136
|
+
bearerToken: 'your-jwt-token', // Required except for health checks
|
|
71
137
|
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Health Checks (No Authentication Required)
|
|
72
141
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
142
|
+
```typescript
|
|
143
|
+
// Health checks work without bearer token
|
|
144
|
+
const api = new AugurAPI({
|
|
145
|
+
siteId: 'your-site-id',
|
|
146
|
+
// No bearerToken needed
|
|
76
147
|
});
|
|
77
148
|
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
149
|
+
const health = await api.joomla.getHealthCheck();
|
|
150
|
+
const pricing = await api.pricing.getHealthCheck();
|
|
151
|
+
const vmiPing = await api.vmi.health.ping();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Cross-Site Authentication
|
|
155
|
+
|
|
156
|
+
Enable multi-tenant authentication using the special `augur_info` site:
|
|
157
|
+
|
|
158
|
+
#### Option 1: Streamlined Utility Function (Recommended)
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { authenticateUserForSite } from '@simpleapps-com/augur-api';
|
|
162
|
+
|
|
163
|
+
// Simple one-function approach
|
|
164
|
+
const result = await authenticateUserForSite({
|
|
165
|
+
targetSiteId: 'tenant_site_1',
|
|
166
|
+
username: 'user@tenant.com',
|
|
167
|
+
password: 'userpassword',
|
|
168
|
+
augurInfoToken: 'admin-jwt-token' // JWT with augur_info admin privileges
|
|
82
169
|
});
|
|
170
|
+
|
|
171
|
+
if (result.success) {
|
|
172
|
+
// Ready-to-use API client for the target site
|
|
173
|
+
const userData = await result.targetSiteAPI!.joomla.users.get(result.userId!);
|
|
174
|
+
console.log('User authenticated:', result.username);
|
|
175
|
+
console.log('User data:', userData);
|
|
176
|
+
} else {
|
|
177
|
+
console.error('Authentication failed:', result.error);
|
|
178
|
+
}
|
|
83
179
|
```
|
|
84
180
|
|
|
85
|
-
|
|
181
|
+
#### Option 2: Reusable Authenticator
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { createCrossSiteAuthenticator } from '@simpleapps-com/augur-api';
|
|
185
|
+
|
|
186
|
+
// Create reusable authenticator
|
|
187
|
+
const crossSiteAuth = createCrossSiteAuthenticator('admin-jwt-token');
|
|
188
|
+
|
|
189
|
+
// Use for multiple sites
|
|
190
|
+
const result1 = await crossSiteAuth('tenant_site_1', 'user1@tenant.com', 'pass1');
|
|
191
|
+
const result2 = await crossSiteAuth('tenant_site_2', 'user2@tenant.com', 'pass2');
|
|
86
192
|
|
|
87
|
-
|
|
193
|
+
if (result1.success) {
|
|
194
|
+
const tenantData = await result1.targetSiteAPI!.joomla.content.list({ limit: 10 });
|
|
195
|
+
}
|
|
196
|
+
```
|
|
88
197
|
|
|
89
|
-
|
|
90
|
-
- `2` - 2 hour cache
|
|
91
|
-
- `3` - 3 hour cache
|
|
92
|
-
- `4` - 4 hour cache
|
|
93
|
-
- `5` - 5 hour cache
|
|
94
|
-
- `8` - 8 hour cache
|
|
198
|
+
#### Option 3: Manual Approach
|
|
95
199
|
|
|
96
200
|
```typescript
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
201
|
+
// Manual approach using the API client directly
|
|
202
|
+
const crossSiteAPI = new AugurAPI({
|
|
203
|
+
siteId: 'augur_info', // Special site for cross-site operations
|
|
204
|
+
bearerToken: 'admin-jwt-token', // JWT token with augur_info admin privileges
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Authenticate user against a different site
|
|
208
|
+
const authResult = await crossSiteAPI.joomla.users.verifyPassword({
|
|
209
|
+
username: 'user@tenant.com',
|
|
210
|
+
password: 'userpassword',
|
|
211
|
+
siteId: 'tenant_site_1' // Target site for authentication
|
|
212
|
+
});
|
|
101
213
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
214
|
+
if (authResult.data.isVerified) {
|
|
215
|
+
// Create API instance for the target site
|
|
216
|
+
const tenantAPI = new AugurAPI({
|
|
217
|
+
siteId: 'tenant_site_1',
|
|
218
|
+
bearerToken: authResult.data.token, // Token scoped to tenant site
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const userData = await tenantAPI.joomla.users.get(authResult.data.id);
|
|
222
|
+
}
|
|
105
223
|
```
|
|
106
224
|
|
|
107
|
-
###
|
|
225
|
+
### Dynamic Authentication Updates
|
|
108
226
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
227
|
+
```typescript
|
|
228
|
+
// Update credentials at runtime
|
|
229
|
+
api.setAuthToken('new-jwt-token');
|
|
230
|
+
api.setSiteId('new-site-id');
|
|
113
231
|
|
|
114
|
-
|
|
232
|
+
// Useful for token refresh scenarios
|
|
233
|
+
async function refreshTokenIfNeeded() {
|
|
234
|
+
try {
|
|
235
|
+
await api.joomla.users.list({ limit: 1 });
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error instanceof AuthenticationError) {
|
|
238
|
+
const newToken = await refreshJWTToken();
|
|
239
|
+
api.setAuthToken(newToken);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
115
244
|
|
|
116
|
-
|
|
245
|
+
### Security Best Practices
|
|
117
246
|
|
|
118
|
-
|
|
247
|
+
1. **Environment Variables**: Store credentials in environment variables
|
|
248
|
+
2. **Token Rotation**: Implement regular token rotation in production
|
|
249
|
+
3. **HTTPS Only**: All API requests use HTTPS in production
|
|
250
|
+
4. **Secure Storage**: Never store tokens in localStorage for web apps
|
|
251
|
+
5. **Minimal Permissions**: Use tokens with minimal required permissions
|
|
119
252
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
253
|
+
```typescript
|
|
254
|
+
// ✅ Good: Environment-based configuration
|
|
255
|
+
const api = new AugurAPI({
|
|
256
|
+
siteId: process.env.AUGUR_SITE_ID!,
|
|
257
|
+
bearerToken: getSecurelyStoredToken(), // From secure storage
|
|
258
|
+
});
|
|
124
259
|
|
|
125
|
-
|
|
260
|
+
// ❌ Bad: Hardcoded credentials
|
|
261
|
+
const api = new AugurAPI({
|
|
262
|
+
siteId: 'hardcoded-site-id',
|
|
263
|
+
bearerToken: 'hardcoded-token', // Never do this!
|
|
264
|
+
});
|
|
265
|
+
```
|
|
126
266
|
|
|
127
|
-
|
|
128
|
-
- **User-specific data** that must be current
|
|
129
|
-
- **Create/Update operations** (POST/PUT endpoints don't support caching)
|
|
130
|
-
- **Sensitive operations** requiring fresh data
|
|
267
|
+
## API Documentation
|
|
131
268
|
|
|
132
|
-
|
|
269
|
+
### Service Overview
|
|
133
270
|
|
|
134
|
-
|
|
271
|
+
| Service | Purpose | Key Features |
|
|
272
|
+
|---------|---------|--------------|
|
|
273
|
+
| **Joomla** | Content & User Management | Articles, users, groups, tags, menu items |
|
|
274
|
+
| **Commerce** | E-commerce Operations | Cart management, checkout, recommendations |
|
|
275
|
+
| **Pricing** | Dynamic Pricing | Price calculations, job pricing, tax engine |
|
|
276
|
+
| **VMI** | Inventory Management | Warehouses, stock levels, replenishment |
|
|
277
|
+
| **OpenSearch** | Product Search | Full-text search, faceting, similarity matching |
|
|
278
|
+
| **Items** | Product Catalog | Products, categories, attributes, brands |
|
|
279
|
+
| **Customers** | Customer Data | Customer profiles, contacts, addresses, orders |
|
|
280
|
+
| **Orders** | Order Management | Order lookup, documents, purchase orders |
|
|
281
|
+
| **Payments** | Payment Processing | Transaction setup, payment validation |
|
|
282
|
+
| **Legacy** | Legacy Systems | State data, inventory lookups |
|
|
283
|
+
| **Nexus** | Warehouse Operations | Bin transfers, receiving, shipping |
|
|
284
|
+
| **P21 PIM** | Product Information | Product data management, AI suggestions |
|
|
285
|
+
| **AGR Site** | Site Management | Settings, notifications, transcripts |
|
|
135
286
|
|
|
136
|
-
###
|
|
287
|
+
### Complete Endpoint Reference
|
|
137
288
|
|
|
138
|
-
|
|
289
|
+
#### Joomla Service
|
|
139
290
|
|
|
140
|
-
#### Content Management
|
|
141
291
|
```typescript
|
|
142
|
-
//
|
|
143
|
-
const
|
|
144
|
-
categoryIdList: '1,2,3',
|
|
292
|
+
// Content Management
|
|
293
|
+
const articles = await api.joomla.content.list({
|
|
294
|
+
categoryIdList: '1,2,3', // Filter by categories
|
|
295
|
+
tagsList: 'featured,new', // Filter by tags
|
|
145
296
|
limit: 20,
|
|
146
297
|
offset: 0,
|
|
147
298
|
orderBy: 'created|DESC',
|
|
148
299
|
q: 'search term',
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// List content with 4-hour edge caching
|
|
153
|
-
const cachedContents = await api.joomla.content.list({
|
|
154
|
-
categoryIdList: '1,2,3',
|
|
155
|
-
edgeCache: 4, // Cache for 4 hours
|
|
156
|
-
limit: 20
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Get single content
|
|
160
|
-
const content = await api.joomla.content.get('content-id', {
|
|
161
|
-
alias: 'optional-alias',
|
|
162
|
-
catid: 5
|
|
300
|
+
edgeCache: 6 // Cache articles for 6 hours
|
|
163
301
|
});
|
|
164
302
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
303
|
+
const article = await api.joomla.content.get('123', {
|
|
304
|
+
alias: 'article-alias',
|
|
305
|
+
catid: 5,
|
|
306
|
+
edgeCache: 8 // Cache single articles for 8 hours
|
|
168
307
|
});
|
|
169
308
|
|
|
170
|
-
|
|
171
|
-
const doc = await api.joomla.content.getDoc('content-id');
|
|
172
|
-
```
|
|
309
|
+
const articleDoc = await api.joomla.content.getDoc('123');
|
|
173
310
|
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
// List users
|
|
311
|
+
// User Management
|
|
177
312
|
const users = await api.joomla.users.list({
|
|
178
|
-
limit:
|
|
313
|
+
limit: 50,
|
|
179
314
|
offset: 0,
|
|
180
315
|
orderBy: 'username|ASC',
|
|
181
|
-
q: '
|
|
316
|
+
q: 'john',
|
|
317
|
+
edgeCache: 2 // Cache user lists for 2 hours
|
|
182
318
|
});
|
|
183
319
|
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
edgeCache: 2, // Cache for 2 hours
|
|
187
|
-
limit: 20,
|
|
188
|
-
orderBy: 'username|ASC'
|
|
189
|
-
});
|
|
320
|
+
const user = await api.joomla.users.get('456');
|
|
321
|
+
const userDoc = await api.joomla.users.getDoc('456');
|
|
190
322
|
|
|
191
|
-
//
|
|
192
|
-
const
|
|
323
|
+
// Create new user
|
|
324
|
+
const newUser = await api.joomla.users.create({
|
|
325
|
+
username: 'newuser',
|
|
326
|
+
email: 'user@example.com',
|
|
327
|
+
name: 'New User',
|
|
328
|
+
password: 'securepassword'
|
|
329
|
+
});
|
|
193
330
|
|
|
194
|
-
//
|
|
195
|
-
const
|
|
196
|
-
|
|
331
|
+
// Update user
|
|
332
|
+
const updatedUser = await api.joomla.users.update('456', {
|
|
333
|
+
email: 'newemail@example.com'
|
|
197
334
|
});
|
|
198
335
|
|
|
199
|
-
//
|
|
200
|
-
|
|
336
|
+
// Block/unblock user
|
|
337
|
+
await api.joomla.users.block('456');
|
|
201
338
|
|
|
202
|
-
//
|
|
203
|
-
const
|
|
204
|
-
|
|
339
|
+
// User Groups
|
|
340
|
+
const userGroups = await api.joomla.users.groups.list('456', {
|
|
341
|
+
limit: 10,
|
|
342
|
+
edgeCache: 4 // Cache group memberships for 4 hours
|
|
205
343
|
});
|
|
206
|
-
```
|
|
207
344
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const groups = await api.joomla.userGroups.list();
|
|
345
|
+
const groupMapping = await api.joomla.users.groups.createMapping('456', {
|
|
346
|
+
groupId: 789
|
|
347
|
+
});
|
|
212
348
|
|
|
213
|
-
//
|
|
214
|
-
const
|
|
215
|
-
|
|
349
|
+
// System Groups
|
|
350
|
+
const allGroups = await api.joomla.userGroups.list({
|
|
351
|
+
orderBy: 'title|ASC',
|
|
352
|
+
parentIdList: '1,2',
|
|
353
|
+
edgeCache: 8 // Cache group hierarchy for 8 hours
|
|
216
354
|
});
|
|
217
355
|
|
|
356
|
+
const groupDetails = await api.joomla.userGroups.get('789');
|
|
357
|
+
|
|
218
358
|
// Tags
|
|
219
359
|
const tags = await api.joomla.tags.list({
|
|
220
|
-
|
|
221
|
-
|
|
360
|
+
categoryId: 1,
|
|
361
|
+
parentId: 0,
|
|
362
|
+
q: 'tech',
|
|
363
|
+
limit: 50,
|
|
364
|
+
edgeCache: 6 // Cache tags for 6 hours
|
|
222
365
|
});
|
|
223
366
|
|
|
224
|
-
//
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
367
|
+
// Authentication
|
|
368
|
+
const authResult = await api.joomla.users.verifyPassword({
|
|
369
|
+
username: 'user@example.com',
|
|
370
|
+
password: 'userpassword',
|
|
371
|
+
siteId: 'optional-cross-site-id' // For cross-site auth when using augur_info
|
|
229
372
|
});
|
|
230
373
|
|
|
231
|
-
|
|
232
|
-
|
|
374
|
+
if (authResult.data.isVerified) {
|
|
375
|
+
console.log('User authenticated:', authResult.data.username);
|
|
376
|
+
console.log('User ID:', authResult.data.id);
|
|
377
|
+
console.log('JWT Token:', authResult.data.token);
|
|
378
|
+
}
|
|
233
379
|
|
|
234
|
-
// Health
|
|
380
|
+
// Health Check
|
|
235
381
|
const health = await api.joomla.getHealthCheck();
|
|
236
382
|
```
|
|
237
383
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
E-commerce cart and checkout operations:
|
|
384
|
+
#### Commerce Service
|
|
241
385
|
|
|
242
|
-
#### Cart Management
|
|
243
386
|
```typescript
|
|
244
|
-
//
|
|
245
|
-
const carts = await api.commerce.cartHeaders.list({
|
|
387
|
+
// Cart Management
|
|
388
|
+
const carts = await api.commerce.cartHeaders.list({
|
|
246
389
|
userId: 123,
|
|
247
|
-
edgeCache: 1 //
|
|
390
|
+
edgeCache: 1 // Cache cart data for 1 hour max
|
|
248
391
|
});
|
|
249
392
|
|
|
250
|
-
// Lookup or create cart
|
|
251
393
|
const cart = await api.commerce.cartHeaders.lookup({
|
|
252
394
|
userId: 123,
|
|
253
395
|
customerId: 456,
|
|
254
396
|
contactId: 789
|
|
255
397
|
});
|
|
256
398
|
|
|
257
|
-
|
|
258
|
-
const cartLines = await api.commerce.cartLines.get(cartHdrUid);
|
|
259
|
-
```
|
|
399
|
+
const cartLines = await api.commerce.cartLines.get(cart.data.cart_hdr_uid);
|
|
260
400
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
401
|
+
// Product Recommendations
|
|
402
|
+
const alsoBought = await api.commerce.alsoBought.get({
|
|
403
|
+
itemId: 'WIRE-123',
|
|
404
|
+
customerId: 12345,
|
|
405
|
+
edgeCache: 6 // Cache recommendations for 6 hours
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// Checkout Operations
|
|
264
409
|
const checkout = await api.commerce.checkout.get(checkoutUid, {
|
|
265
|
-
edgeCache: 2 //
|
|
410
|
+
edgeCache: 2 // Cache checkout data for 2 hours
|
|
266
411
|
});
|
|
267
412
|
|
|
268
|
-
// Get checkout documentation
|
|
269
413
|
const checkoutDoc = await api.commerce.checkout.getDoc(checkoutUid, {
|
|
270
|
-
cartHdrUid:
|
|
271
|
-
edgeCache: 4 //
|
|
414
|
+
cartHdrUid: cart.data.cart_hdr_uid,
|
|
415
|
+
edgeCache: 4 // Cache checkout documents for 4 hours
|
|
272
416
|
});
|
|
273
417
|
|
|
274
|
-
// Health
|
|
418
|
+
// Health Check
|
|
275
419
|
const health = await api.commerce.getHealthCheck();
|
|
276
420
|
```
|
|
277
421
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
Product pricing and job price management:
|
|
422
|
+
#### Pricing Service
|
|
281
423
|
|
|
282
|
-
#### Price Engine
|
|
283
424
|
```typescript
|
|
284
|
-
//
|
|
425
|
+
// Price Engine
|
|
285
426
|
const pricing = await api.pricing.getPrice({
|
|
286
|
-
customerId:
|
|
427
|
+
customerId: 12345,
|
|
287
428
|
itemId: 'ITEM-001',
|
|
288
429
|
quantity: 10,
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// Pricing with specific parameters
|
|
293
|
-
const customPricing = await api.pricing.getPrice({
|
|
294
|
-
customerId: 123,
|
|
295
|
-
itemId: 'ITEM-002',
|
|
296
|
-
quantity: 5,
|
|
297
|
-
shipToId: 456,
|
|
298
|
-
unitOfMeasure: 'EA',
|
|
299
|
-
edgeCache: 2
|
|
430
|
+
shipToId: 'SHIP-001', // Optional
|
|
431
|
+
unitOfMeasure: 'EA', // Optional
|
|
432
|
+
edgeCache: 3 // Cache standard pricing for 3 hours
|
|
300
433
|
});
|
|
301
|
-
```
|
|
302
434
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// List job price headers with caching
|
|
306
|
-
const jobPrices = await api.pricing.jobPriceHeaders.list({
|
|
435
|
+
// Job Price Management
|
|
436
|
+
const jobPriceHeaders = await api.pricing.jobPriceHeaders.list({
|
|
307
437
|
limit: 20,
|
|
308
438
|
orderBy: 'job_price_hdr_uid|DESC',
|
|
309
|
-
edgeCache: 4 //
|
|
439
|
+
edgeCache: 4 // Cache job listings for 4 hours
|
|
310
440
|
});
|
|
311
441
|
|
|
312
|
-
|
|
313
|
-
const jobPrice = await api.pricing.jobPriceHeaders.get(jobPriceHdrUid);
|
|
442
|
+
const jobPriceHeader = await api.pricing.jobPriceHeaders.get(12345);
|
|
314
443
|
|
|
315
|
-
|
|
316
|
-
const priceLines = await api.pricing.jobPriceLines.list(jobPriceHdrUid, {
|
|
444
|
+
const jobPriceLines = await api.pricing.jobPriceLines.list(12345, {
|
|
317
445
|
limit: 50,
|
|
318
|
-
edgeCache: 4 // 4
|
|
446
|
+
edgeCache: 4 // Cache price lines for 4 hours
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const jobPriceLine = await api.pricing.jobPriceLines.get(12345, 67890);
|
|
450
|
+
|
|
451
|
+
// Tax Engine
|
|
452
|
+
const taxCalculation = await api.pricing.calculateTax({
|
|
453
|
+
customer_id: 12345,
|
|
454
|
+
ship_to_id: 'SHIP-001',
|
|
455
|
+
items: [
|
|
456
|
+
{
|
|
457
|
+
item_id: 'ITEM-001',
|
|
458
|
+
quantity: 10,
|
|
459
|
+
unit_price: 25.50,
|
|
460
|
+
extended_price: 255.00
|
|
461
|
+
}
|
|
462
|
+
],
|
|
463
|
+
addresses: {
|
|
464
|
+
origin: {
|
|
465
|
+
street: '123 Main St',
|
|
466
|
+
city: 'Anytown',
|
|
467
|
+
state: 'CA',
|
|
468
|
+
zip: '90210'
|
|
469
|
+
},
|
|
470
|
+
destination: {
|
|
471
|
+
street: '456 Oak Ave',
|
|
472
|
+
city: 'Other City',
|
|
473
|
+
state: 'NY',
|
|
474
|
+
zip: '10001'
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
edgeCache: 1 // Cache tax calculations for 1 hour
|
|
319
478
|
});
|
|
320
479
|
|
|
321
|
-
//
|
|
322
|
-
const
|
|
480
|
+
// Health Checks
|
|
481
|
+
const ping = await api.pricing.ping();
|
|
323
482
|
const health = await api.pricing.getHealthCheck();
|
|
324
483
|
```
|
|
325
484
|
|
|
326
|
-
|
|
485
|
+
#### VMI (Vendor Managed Inventory) Service
|
|
327
486
|
|
|
328
|
-
Warehouse and inventory management operations:
|
|
329
|
-
|
|
330
|
-
#### Warehouse Management
|
|
331
487
|
```typescript
|
|
332
|
-
//
|
|
488
|
+
// Warehouse Management
|
|
333
489
|
const warehouses = await api.vmi.warehouses.list({
|
|
334
490
|
customerId: 12345,
|
|
335
491
|
limit: 10,
|
|
336
492
|
q: 'distribution',
|
|
337
|
-
usersId: 456
|
|
493
|
+
usersId: 456,
|
|
494
|
+
edgeCache: 4 // Cache warehouse data for 4 hours
|
|
338
495
|
});
|
|
339
496
|
|
|
340
|
-
// Get specific warehouse
|
|
341
497
|
const warehouse = await api.vmi.warehouses.get(123);
|
|
342
498
|
|
|
343
|
-
// Create new warehouse
|
|
344
499
|
const newWarehouse = await api.vmi.warehouses.create({
|
|
345
500
|
warehouse_name: 'New Distribution Center',
|
|
346
501
|
warehouse_desc: 'Primary warehouse for west coast operations',
|
|
@@ -348,25 +503,20 @@ const newWarehouse = await api.vmi.warehouses.create({
|
|
|
348
503
|
inv_profile_hdr_uid: 1
|
|
349
504
|
});
|
|
350
505
|
|
|
351
|
-
// Update warehouse
|
|
352
506
|
const updatedWarehouse = await api.vmi.warehouses.update(123, {
|
|
353
|
-
warehouse_name: 'Updated Warehouse Name'
|
|
354
|
-
warehouse_desc: 'Updated description'
|
|
507
|
+
warehouse_name: 'Updated Warehouse Name'
|
|
355
508
|
});
|
|
356
509
|
|
|
357
510
|
// Enable/disable warehouse
|
|
358
|
-
await api.vmi.warehouses.enable(123, { status_cd: 705 }); // Disable
|
|
359
511
|
await api.vmi.warehouses.enable(123, { status_cd: 704 }); // Enable
|
|
360
|
-
|
|
512
|
+
await api.vmi.warehouses.enable(123, { status_cd: 705 }); // Disable
|
|
361
513
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
// Check inventory availability
|
|
365
|
-
const inventory = await api.vmi.inventory.checkAvailability(123, {
|
|
514
|
+
// Inventory Operations
|
|
515
|
+
const availability = await api.vmi.inventory.checkAvailability(123, {
|
|
366
516
|
q: 'wire' // Search for items containing 'wire'
|
|
367
517
|
});
|
|
368
518
|
|
|
369
|
-
// Adjust inventory
|
|
519
|
+
// Adjust inventory (sets absolute values)
|
|
370
520
|
await api.vmi.inventory.adjust(123, {
|
|
371
521
|
adjustments: [
|
|
372
522
|
{
|
|
@@ -391,7 +541,8 @@ await api.vmi.inventory.receive(123, {
|
|
|
391
541
|
|
|
392
542
|
// Get replenishment information
|
|
393
543
|
const replenishment = await api.vmi.inventory.getReplenishmentInfo(123, {
|
|
394
|
-
distributorsUid: 789
|
|
544
|
+
distributorsUid: 789,
|
|
545
|
+
edgeCache: 2 // Cache replenishment info for 2 hours
|
|
395
546
|
});
|
|
396
547
|
|
|
397
548
|
// Execute replenishment
|
|
@@ -437,17 +588,16 @@ await api.vmi.inventory.recordUsage(123, {
|
|
|
437
588
|
}
|
|
438
589
|
]
|
|
439
590
|
});
|
|
440
|
-
```
|
|
441
591
|
|
|
442
|
-
|
|
443
|
-
```typescript
|
|
444
|
-
// List distributors
|
|
592
|
+
// Distributor Management
|
|
445
593
|
const distributors = await api.vmi.distributors.list({
|
|
446
594
|
customerId: 12345,
|
|
447
|
-
statusCd: 704 // Active distributors only
|
|
595
|
+
statusCd: 704, // Active distributors only
|
|
596
|
+
edgeCache: 8 // Cache distributor data for 8 hours
|
|
448
597
|
});
|
|
449
598
|
|
|
450
|
-
|
|
599
|
+
const distributor = await api.vmi.distributors.get(789);
|
|
600
|
+
|
|
451
601
|
const newDistributor = await api.vmi.distributors.create({
|
|
452
602
|
distributor_name: 'ABC Supply Co',
|
|
453
603
|
distributor_desc: 'Primary electrical supplier',
|
|
@@ -456,100 +606,40 @@ const newDistributor = await api.vmi.distributors.create({
|
|
|
456
606
|
contact_phone: '555-1234'
|
|
457
607
|
});
|
|
458
608
|
|
|
459
|
-
//
|
|
460
|
-
const
|
|
461
|
-
contact_email: 'newemail@abcsupply.com'
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
// Enable/disable distributor
|
|
465
|
-
await api.vmi.distributors.enable(789, { status_cd: 705 }); // Disable
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
#### Product Management
|
|
469
|
-
```typescript
|
|
470
|
-
// Find products and items across both VMI and Prophet 21
|
|
471
|
-
const items = await api.vmi.products.find({
|
|
609
|
+
// Product Management
|
|
610
|
+
const products = await api.vmi.products.find({
|
|
472
611
|
customerId: 12345,
|
|
473
|
-
prefix: 'WIRE'
|
|
612
|
+
prefix: 'WIRE',
|
|
613
|
+
edgeCache: 6 // Cache product catalogs for 6 hours
|
|
474
614
|
});
|
|
475
615
|
|
|
476
|
-
|
|
477
|
-
const products = await api.vmi.products.list({
|
|
616
|
+
const productList = await api.vmi.products.list({
|
|
478
617
|
customerId: 12345,
|
|
479
618
|
distributorsUid: 789,
|
|
480
619
|
prefix: 'WIRE',
|
|
481
|
-
limit: 20
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
// Create product for distributor
|
|
485
|
-
const newProduct = await api.vmi.products.createForDistributor(789, {
|
|
486
|
-
product_id: 'PROD-001',
|
|
487
|
-
product_name: 'Custom Wire Product',
|
|
488
|
-
product_desc: 'Specialized wire for industrial use',
|
|
489
|
-
distributors_uid: 789,
|
|
490
|
-
customer_id: 12345
|
|
491
|
-
});
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
#### Inventory Profile Management
|
|
495
|
-
```typescript
|
|
496
|
-
// List inventory profile headers
|
|
497
|
-
const profileHeaders = await api.vmi.inventoryProfiles.headers.list({
|
|
498
|
-
customerId: 12345
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// Create inventory profile header
|
|
502
|
-
const profileHeader = await api.vmi.inventoryProfiles.headers.create({
|
|
503
|
-
inv_profile_hdr_desc: 'Standard Office Setup Profile',
|
|
504
|
-
customer_id: 12345
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
// List profile lines for a header
|
|
508
|
-
const profileLines = await api.vmi.inventoryProfiles.lines.list(1, {
|
|
509
|
-
limit: 20
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
// Create inventory profile line (defines min/max/reorder quantities)
|
|
513
|
-
const profileLine = await api.vmi.inventoryProfiles.lines.create(1, {
|
|
514
|
-
inv_mast_uid: 456,
|
|
515
|
-
inv_profile_line_type: 'prophet21',
|
|
516
|
-
min_qty: 50.0,
|
|
517
|
-
max_qty: 200.0,
|
|
518
|
-
reorder_qty: 100.0
|
|
620
|
+
limit: 20,
|
|
621
|
+
edgeCache: 6
|
|
519
622
|
});
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
#### Health Monitoring
|
|
523
|
-
```typescript
|
|
524
|
-
// Simple ping (no authentication required)
|
|
525
|
-
const pong = await api.vmi.health.ping();
|
|
526
623
|
|
|
527
|
-
//
|
|
624
|
+
// Health Monitoring
|
|
625
|
+
const ping = await api.vmi.health.ping();
|
|
528
626
|
const health = await api.vmi.health.check();
|
|
529
627
|
```
|
|
530
628
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
Advanced product search and discovery operations:
|
|
629
|
+
#### OpenSearch Service
|
|
534
630
|
|
|
535
|
-
#### Item Search
|
|
536
631
|
```typescript
|
|
537
|
-
//
|
|
632
|
+
// Item Search
|
|
538
633
|
const searchResults = await api.opensearch.itemSearch.search({
|
|
539
|
-
q: 'electrical wire',
|
|
540
|
-
searchType: 'query',
|
|
541
|
-
size: 20
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Advanced search with filtering
|
|
545
|
-
const filteredSearch = await api.opensearch.itemSearch.search({
|
|
546
|
-
q: 'power tools',
|
|
547
|
-
searchType: 'query',
|
|
548
|
-
size: 50,
|
|
549
|
-
operator: 'AND',
|
|
634
|
+
q: 'electrical wire 12 AWG',
|
|
635
|
+
searchType: 'query', // 'query' | 'similarity'
|
|
636
|
+
size: 20,
|
|
637
|
+
operator: 'AND', // 'AND' | 'OR'
|
|
550
638
|
itemCategoryUidList: '123,456,789',
|
|
551
|
-
filters: JSON.stringify([
|
|
552
|
-
|
|
639
|
+
filters: JSON.stringify([
|
|
640
|
+
{ attributeUid: 123, attributeValueUid: 456 }
|
|
641
|
+
]),
|
|
642
|
+
edgeCache: 2 // Cache search results for 2 hours
|
|
553
643
|
});
|
|
554
644
|
|
|
555
645
|
// Similarity search for recommendations
|
|
@@ -557,194 +647,1703 @@ const similarItems = await api.opensearch.itemSearch.search({
|
|
|
557
647
|
q: 'CAT5e network cable 100ft blue',
|
|
558
648
|
searchType: 'similarity',
|
|
559
649
|
size: 15,
|
|
560
|
-
edgeCache: 4 //
|
|
650
|
+
edgeCache: 4 // Cache similarity results for 4 hours
|
|
561
651
|
});
|
|
562
652
|
|
|
563
653
|
// Get search facets for filtering
|
|
564
654
|
const attributes = await api.opensearch.itemSearch.getAttributes({
|
|
565
655
|
q: 'LED bulbs',
|
|
566
656
|
searchType: 'query',
|
|
567
|
-
edgeCache: 6 //
|
|
657
|
+
edgeCache: 6 // Cache facet structure for 6 hours
|
|
568
658
|
});
|
|
569
|
-
```
|
|
570
659
|
|
|
571
|
-
|
|
572
|
-
```typescript
|
|
573
|
-
// List items from search index
|
|
660
|
+
// Items Management
|
|
574
661
|
const items = await api.opensearch.items.list({
|
|
575
|
-
itemId: 'WIRE',
|
|
576
|
-
online: 'Y',
|
|
577
|
-
statusCd: 704,
|
|
662
|
+
itemId: 'WIRE', // Prefix filter
|
|
663
|
+
online: 'Y', // Only online items
|
|
664
|
+
statusCd: 704, // Active items only
|
|
578
665
|
limit: 100,
|
|
579
666
|
offset: 0,
|
|
580
|
-
edgeCache: 3
|
|
667
|
+
edgeCache: 3 // Cache item data for 3 hours
|
|
581
668
|
});
|
|
582
669
|
|
|
583
|
-
// Get detailed item information
|
|
584
670
|
const itemDetail = await api.opensearch.items.get(123456);
|
|
585
671
|
|
|
586
|
-
//
|
|
672
|
+
// Index management operations (no caching for real-time operations)
|
|
587
673
|
const refreshResult = await api.opensearch.items.refresh(123456);
|
|
588
|
-
|
|
589
|
-
// Update item in search index
|
|
590
674
|
const updateResult = await api.opensearch.items.update(123456);
|
|
591
|
-
|
|
592
|
-
// Batch refresh all items
|
|
593
675
|
const batchRefresh = await api.opensearch.items.refreshAll();
|
|
676
|
+
|
|
677
|
+
// Health Monitoring
|
|
678
|
+
const ping = await api.opensearch.health.ping();
|
|
679
|
+
const health = await api.opensearch.health.check();
|
|
594
680
|
```
|
|
595
681
|
|
|
596
|
-
|
|
682
|
+
### Response Format
|
|
683
|
+
|
|
684
|
+
All Augur microservices follow a unified response pattern:
|
|
685
|
+
|
|
597
686
|
```typescript
|
|
598
|
-
|
|
599
|
-
|
|
687
|
+
interface BaseResponse<T> {
|
|
688
|
+
status: number; // HTTP status code (200 for success)
|
|
689
|
+
message?: string; // Status message (optional - omitted in health checks)
|
|
690
|
+
data: T; // Response data of type T
|
|
691
|
+
totalResults?: number; // Total count (optional - present in paginated responses)
|
|
692
|
+
count?: number; // Item count (optional - present in some responses)
|
|
693
|
+
options?: Array<Record<string, unknown>>; // Optional array of key-value pairs
|
|
694
|
+
}
|
|
600
695
|
|
|
601
|
-
//
|
|
602
|
-
const
|
|
696
|
+
// Example response
|
|
697
|
+
const usersResponse = await api.joomla.users.list({ limit: 10 });
|
|
698
|
+
// usersResponse = {
|
|
699
|
+
// status: 200,
|
|
700
|
+
// message: "Ok",
|
|
701
|
+
// data: [...users...],
|
|
702
|
+
// totalResults: 150
|
|
703
|
+
// }
|
|
704
|
+
|
|
705
|
+
// Access the actual data
|
|
706
|
+
const users = usersResponse.data;
|
|
707
|
+
const totalCount = usersResponse.totalResults;
|
|
603
708
|
```
|
|
604
709
|
|
|
605
|
-
|
|
710
|
+
### HTTP Methods and URL Patterns
|
|
711
|
+
|
|
712
|
+
| Method | Pattern | Client Method | Example |
|
|
713
|
+
|--------|---------|---------------|---------|
|
|
714
|
+
| GET | `/users` | `listUsers()` | List multiple resources |
|
|
715
|
+
| GET | `/user/{id}` | `getUser()` | Get single resource |
|
|
716
|
+
| POST | `/user` | `createUser()` | Create new resource |
|
|
717
|
+
| PUT | `/user/{id}` | `updateUser()` | Update existing resource |
|
|
718
|
+
| DELETE | `/user/{id}` | `deleteUser()` | Delete resource |
|
|
606
719
|
|
|
607
|
-
|
|
720
|
+
### Error Handling
|
|
608
721
|
|
|
609
722
|
```typescript
|
|
723
|
+
import {
|
|
724
|
+
AugurAPIError,
|
|
725
|
+
AuthenticationError,
|
|
726
|
+
ValidationError,
|
|
727
|
+
NotFoundError,
|
|
728
|
+
RateLimitError
|
|
729
|
+
} from '@simpleapps-com/augur-api';
|
|
730
|
+
|
|
610
731
|
try {
|
|
611
732
|
const user = await api.joomla.users.get('user-id');
|
|
612
733
|
} catch (error) {
|
|
613
|
-
if (error instanceof
|
|
614
|
-
console.error(
|
|
734
|
+
if (error instanceof AuthenticationError) {
|
|
735
|
+
console.error('Authentication failed:', error.message);
|
|
736
|
+
// Handle auth error - refresh token or redirect to login
|
|
615
737
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
738
|
+
} else if (error instanceof ValidationError) {
|
|
739
|
+
console.error('Request validation failed:', error.validationErrors);
|
|
740
|
+
// Handle validation errors - check request parameters
|
|
741
|
+
|
|
742
|
+
} else if (error instanceof NotFoundError) {
|
|
743
|
+
console.error('Resource not found:', error.message);
|
|
744
|
+
// Handle not found - show user-friendly message
|
|
745
|
+
|
|
746
|
+
} else if (error instanceof RateLimitError) {
|
|
747
|
+
console.error('Rate limit exceeded:', error.message);
|
|
748
|
+
// Handle rate limiting - implement backoff strategy
|
|
749
|
+
|
|
750
|
+
} else if (error instanceof AugurAPIError) {
|
|
751
|
+
console.error('API error:', error.code, error.message);
|
|
752
|
+
// Handle other API errors
|
|
631
753
|
}
|
|
632
754
|
}
|
|
633
755
|
```
|
|
634
756
|
|
|
635
|
-
##
|
|
757
|
+
## Advanced Features
|
|
758
|
+
|
|
759
|
+
### Edge Caching with Cloudflare
|
|
760
|
+
|
|
761
|
+
The client provides built-in edge caching that dramatically improves performance by serving cached responses from Cloudflare's global edge network.
|
|
762
|
+
|
|
763
|
+
#### Supported Cache Durations
|
|
764
|
+
|
|
765
|
+
Only specific cache durations are supported and validated:
|
|
766
|
+
|
|
767
|
+
| Value | Duration | Best For |
|
|
768
|
+
|-------|----------|----------|
|
|
769
|
+
| `1` | 1 hour | Frequently changing data, cart contents |
|
|
770
|
+
| `2` | 2 hours | User lists, moderate volatility data |
|
|
771
|
+
| `3` | 3 hours | Standard pricing, product information |
|
|
772
|
+
| `4` | 4 hours | Recommendations, warehouse data |
|
|
773
|
+
| `5` | 5 hours | Tags, categories, reference data |
|
|
774
|
+
| `8` | 8 hours | Static content, distributor information |
|
|
775
|
+
|
|
776
|
+
#### Cache Implementation
|
|
777
|
+
|
|
778
|
+
```typescript
|
|
779
|
+
// How it works internally:
|
|
780
|
+
// edgeCache: 4 → adds URL parameter: cacheSiteId4=your-site-id
|
|
781
|
+
// This triggers Cloudflare cache rules for 4-hour TTL
|
|
782
|
+
|
|
783
|
+
const users = await api.joomla.users.list({
|
|
784
|
+
limit: 20,
|
|
785
|
+
edgeCache: 4 // Cached at edge for 4 hours
|
|
786
|
+
});
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
#### Caching Best Practices
|
|
790
|
+
|
|
791
|
+
```typescript
|
|
792
|
+
// ✅ Good: Cache stable reference data
|
|
793
|
+
const categories = await api.items.categories.list({
|
|
794
|
+
edgeCache: 8 // Categories rarely change
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
// ✅ Good: Cache with appropriate TTL
|
|
798
|
+
const pricing = await api.pricing.getPrice({
|
|
799
|
+
customerId: 12345,
|
|
800
|
+
itemId: 'STANDARD-ITEM',
|
|
801
|
+
quantity: 10,
|
|
802
|
+
edgeCache: 3 // Standard pricing changes infrequently
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// ✅ Good: Short cache for volatile data
|
|
806
|
+
const cart = await api.commerce.cartHeaders.list({
|
|
807
|
+
userId: 123,
|
|
808
|
+
edgeCache: 1 // Cart data changes frequently
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
// ❌ Bad: Don't cache real-time operations
|
|
812
|
+
const auth = await api.joomla.users.verifyPassword({
|
|
813
|
+
username: 'user',
|
|
814
|
+
password: 'pass'
|
|
815
|
+
// No edgeCache - authentication must be real-time
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
// ❌ Bad: Don't cache user-specific data too long
|
|
819
|
+
const userSpecificData = await api.vmi.inventory.checkAvailability(warehouseId, {
|
|
820
|
+
q: 'search',
|
|
821
|
+
edgeCache: 8 // Too long for inventory data
|
|
822
|
+
});
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
### Request Cancellation
|
|
826
|
+
|
|
827
|
+
```typescript
|
|
828
|
+
const controller = new AbortController();
|
|
829
|
+
|
|
830
|
+
// Start a request
|
|
831
|
+
const usersPromise = api.joomla.users.list(
|
|
832
|
+
{ limit: 100 },
|
|
833
|
+
{ signal: controller.signal } // Pass abort signal
|
|
834
|
+
);
|
|
835
|
+
|
|
836
|
+
// Cancel the request if needed
|
|
837
|
+
setTimeout(() => {
|
|
838
|
+
controller.abort();
|
|
839
|
+
}, 5000);
|
|
840
|
+
|
|
841
|
+
try {
|
|
842
|
+
const users = await usersPromise;
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (error.name === 'AbortError') {
|
|
845
|
+
console.log('Request was cancelled');
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
### Custom Headers and Timeouts
|
|
851
|
+
|
|
852
|
+
```typescript
|
|
853
|
+
// Per-request configuration
|
|
854
|
+
const users = await api.joomla.users.list(
|
|
855
|
+
{ limit: 20 },
|
|
856
|
+
{
|
|
857
|
+
timeout: 10000, // 10 second timeout
|
|
858
|
+
headers: {
|
|
859
|
+
'X-Custom-Header': 'value',
|
|
860
|
+
'X-Request-ID': 'unique-id'
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
);
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
### Batch Operations
|
|
867
|
+
|
|
868
|
+
```typescript
|
|
869
|
+
// Execute multiple operations in parallel
|
|
870
|
+
const [users, articles, tags] = await Promise.all([
|
|
871
|
+
api.joomla.users.list({ limit: 10, edgeCache: 2 }),
|
|
872
|
+
api.joomla.content.list({ limit: 5, edgeCache: 6 }),
|
|
873
|
+
api.joomla.tags.list({ limit: 20, edgeCache: 8 })
|
|
874
|
+
]);
|
|
875
|
+
|
|
876
|
+
// Process results
|
|
877
|
+
console.log(`Found ${users.data.length} users`);
|
|
878
|
+
console.log(`Found ${articles.data.length} articles`);
|
|
879
|
+
console.log(`Found ${tags.data.length} tags`);
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
### Middleware Integration
|
|
636
883
|
|
|
637
884
|
```typescript
|
|
885
|
+
// Add global request/response interceptors
|
|
638
886
|
const api = new AugurAPI({
|
|
639
|
-
// Required
|
|
640
887
|
siteId: 'your-site-id',
|
|
888
|
+
bearerToken: 'your-token',
|
|
641
889
|
|
|
642
|
-
//
|
|
643
|
-
bearerToken: 'your-jwt-token',
|
|
644
|
-
apiKey: 'alternative-auth-method',
|
|
645
|
-
|
|
646
|
-
// Optional settings
|
|
647
|
-
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
648
|
-
retries: 3, // Number of retries (default: 3)
|
|
649
|
-
retryDelay: 1000, // Delay between retries in ms (default: 1000)
|
|
650
|
-
|
|
651
|
-
// Interceptors
|
|
890
|
+
// Request interceptor
|
|
652
891
|
onRequest: (config) => {
|
|
653
|
-
console.log(
|
|
892
|
+
console.log(`Making request to: ${config.url}`);
|
|
893
|
+
config.headers['X-Request-Timestamp'] = Date.now().toString();
|
|
654
894
|
return config;
|
|
655
895
|
},
|
|
896
|
+
|
|
897
|
+
// Response interceptor
|
|
656
898
|
onResponse: (response) => {
|
|
657
|
-
console.log(
|
|
899
|
+
console.log(`Response status: ${response.status}`);
|
|
658
900
|
return response;
|
|
659
901
|
},
|
|
902
|
+
|
|
903
|
+
// Error interceptor
|
|
660
904
|
onError: (error) => {
|
|
661
|
-
console.error('Error:', error);
|
|
905
|
+
console.error('API Error:', error.message);
|
|
906
|
+
// Custom error handling logic
|
|
662
907
|
throw error;
|
|
663
908
|
}
|
|
664
909
|
});
|
|
665
910
|
```
|
|
666
911
|
|
|
667
|
-
##
|
|
912
|
+
## Integration Guides
|
|
668
913
|
|
|
669
|
-
|
|
914
|
+
### React Integration
|
|
670
915
|
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
|
|
916
|
+
```tsx
|
|
917
|
+
import React, { useState, useEffect } from 'react';
|
|
918
|
+
import { AugurAPI, User, AugurAPIError } from '@simpleapps-com/augur-api';
|
|
674
919
|
|
|
675
|
-
//
|
|
676
|
-
|
|
677
|
-
|
|
920
|
+
// Custom hook for Augur API
|
|
921
|
+
function useAugurAPI() {
|
|
922
|
+
const [api] = useState(() => new AugurAPI({
|
|
923
|
+
siteId: process.env.REACT_APP_AUGUR_SITE_ID!,
|
|
924
|
+
bearerToken: getStoredToken()
|
|
925
|
+
}));
|
|
926
|
+
|
|
927
|
+
return api;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// Component using the API
|
|
931
|
+
const UserList: React.FC = () => {
|
|
932
|
+
const api = useAugurAPI();
|
|
933
|
+
const [users, setUsers] = useState<User[]>([]);
|
|
934
|
+
const [loading, setLoading] = useState(true);
|
|
935
|
+
const [error, setError] = useState<string | null>(null);
|
|
936
|
+
|
|
937
|
+
useEffect(() => {
|
|
938
|
+
async function fetchUsers() {
|
|
939
|
+
try {
|
|
940
|
+
setLoading(true);
|
|
941
|
+
setError(null);
|
|
942
|
+
|
|
943
|
+
const response = await api.joomla.users.list({
|
|
944
|
+
limit: 50,
|
|
945
|
+
edgeCache: 2 // Cache for 2 hours
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
setUsers(response.data);
|
|
949
|
+
} catch (err) {
|
|
950
|
+
if (err instanceof AugurAPIError) {
|
|
951
|
+
setError(`API Error: ${err.message}`);
|
|
952
|
+
} else {
|
|
953
|
+
setError('An unexpected error occurred');
|
|
954
|
+
}
|
|
955
|
+
} finally {
|
|
956
|
+
setLoading(false);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
678
959
|
|
|
679
|
-
|
|
960
|
+
fetchUsers();
|
|
961
|
+
}, [api]);
|
|
962
|
+
|
|
963
|
+
if (loading) return <div>Loading users...</div>;
|
|
964
|
+
if (error) return <div>Error: {error}</div>;
|
|
965
|
+
|
|
966
|
+
return (
|
|
967
|
+
<div>
|
|
968
|
+
<h2>Users ({users.length})</h2>
|
|
969
|
+
<ul>
|
|
970
|
+
{users.map(user => (
|
|
971
|
+
<li key={user.id}>
|
|
972
|
+
{user.name} ({user.username}) - {user.email}
|
|
973
|
+
</li>
|
|
974
|
+
))}
|
|
975
|
+
</ul>
|
|
976
|
+
</div>
|
|
977
|
+
);
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
export default UserList;
|
|
981
|
+
```
|
|
680
982
|
|
|
681
|
-
|
|
983
|
+
### React Native Integration
|
|
682
984
|
|
|
683
985
|
```typescript
|
|
684
|
-
import
|
|
986
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
987
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
685
988
|
|
|
686
|
-
|
|
687
|
-
|
|
989
|
+
class AugurService {
|
|
990
|
+
private api: AugurAPI;
|
|
688
991
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
992
|
+
constructor() {
|
|
993
|
+
this.api = new AugurAPI({
|
|
994
|
+
siteId: 'your-site-id',
|
|
995
|
+
bearerToken: '', // Will be set after loading from storage
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
this.loadCredentials();
|
|
999
|
+
}
|
|
692
1000
|
|
|
693
|
-
|
|
1001
|
+
private async loadCredentials() {
|
|
1002
|
+
try {
|
|
1003
|
+
const token = await AsyncStorage.getItem('augur_token');
|
|
1004
|
+
const siteId = await AsyncStorage.getItem('augur_site_id');
|
|
1005
|
+
|
|
1006
|
+
if (token) this.api.setAuthToken(token);
|
|
1007
|
+
if (siteId) this.api.setSiteId(siteId);
|
|
1008
|
+
} catch (error) {
|
|
1009
|
+
console.error('Failed to load credentials:', error);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
694
1012
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
1013
|
+
async login(username: string, password: string): Promise<boolean> {
|
|
1014
|
+
try {
|
|
1015
|
+
const response = await this.api.joomla.users.verifyPassword({
|
|
1016
|
+
username,
|
|
1017
|
+
password
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
if (response.data.isVerified && response.data.token) {
|
|
1021
|
+
await AsyncStorage.setItem('augur_token', response.data.token);
|
|
1022
|
+
this.api.setAuthToken(response.data.token);
|
|
1023
|
+
return true;
|
|
1024
|
+
}
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
console.error('Login failed:', error);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
707
1031
|
|
|
708
|
-
|
|
1032
|
+
async getProducts(searchTerm: string) {
|
|
1033
|
+
return this.api.opensearch.itemSearch.search({
|
|
1034
|
+
q: searchTerm,
|
|
1035
|
+
searchType: 'query',
|
|
1036
|
+
size: 20,
|
|
1037
|
+
edgeCache: 3 // Cache search results
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
709
1040
|
|
|
710
|
-
|
|
1041
|
+
async logout() {
|
|
1042
|
+
await AsyncStorage.multiRemove(['augur_token', 'augur_site_id']);
|
|
1043
|
+
this.api.setAuthToken('');
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
711
1046
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
- GET `/user/:id` → `getUser()`
|
|
715
|
-
- POST `/user` → `createUser()` (coming soon)
|
|
716
|
-
- PUT `/user/:id` → `updateUser()` (coming soon)
|
|
717
|
-
- DELETE `/user/:id` → `deleteUser()` (coming soon)
|
|
1047
|
+
export const augurService = new AugurService();
|
|
1048
|
+
```
|
|
718
1049
|
|
|
719
|
-
|
|
720
|
-
- Fields ending with `Uid` are numbers
|
|
721
|
-
- Fields ending with `Id` are strings
|
|
1050
|
+
### Next.js Integration
|
|
722
1051
|
|
|
723
|
-
|
|
1052
|
+
```typescript
|
|
1053
|
+
// lib/augur.ts
|
|
1054
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
1055
|
+
|
|
1056
|
+
// Server-side API instance
|
|
1057
|
+
export function createServerAPI() {
|
|
1058
|
+
return new AugurAPI({
|
|
1059
|
+
siteId: process.env.AUGUR_SITE_ID!,
|
|
1060
|
+
bearerToken: process.env.AUGUR_SERVICE_TOKEN!, // Service token for server-side
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
724
1063
|
|
|
725
|
-
|
|
1064
|
+
// Client-side API instance
|
|
1065
|
+
export function createClientAPI(userToken: string) {
|
|
1066
|
+
return new AugurAPI({
|
|
1067
|
+
siteId: process.env.NEXT_PUBLIC_AUGUR_SITE_ID!,
|
|
1068
|
+
bearerToken: userToken, // User token for client-side
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
726
1071
|
|
|
727
|
-
|
|
1072
|
+
// pages/api/products/search.ts
|
|
1073
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
1074
|
+
import { createServerAPI } from '../../../lib/augur';
|
|
728
1075
|
|
|
729
|
-
|
|
1076
|
+
export default async function handler(
|
|
1077
|
+
req: NextApiRequest,
|
|
1078
|
+
res: NextApiResponse
|
|
1079
|
+
) {
|
|
1080
|
+
if (req.method !== 'GET') {
|
|
1081
|
+
return res.status(405).json({ error: 'Method not allowed' });
|
|
1082
|
+
}
|
|
730
1083
|
|
|
731
|
-
|
|
1084
|
+
const { q } = req.query;
|
|
1085
|
+
if (!q || typeof q !== 'string') {
|
|
1086
|
+
return res.status(400).json({ error: 'Search query required' });
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
try {
|
|
1090
|
+
const api = createServerAPI();
|
|
1091
|
+
const searchResults = await api.opensearch.itemSearch.search({
|
|
1092
|
+
q,
|
|
1093
|
+
searchType: 'query',
|
|
1094
|
+
size: 20,
|
|
1095
|
+
edgeCache: 4 // Cache search results for 4 hours
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
res.status(200).json(searchResults);
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
console.error('Search failed:', error);
|
|
1101
|
+
res.status(500).json({ error: 'Search failed' });
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// pages/products.tsx
|
|
1106
|
+
import { GetServerSideProps } from 'next';
|
|
1107
|
+
import { createServerAPI } from '../lib/augur';
|
|
1108
|
+
import type { ItemSearchResponse } from '@simpleapps-com/augur-api';
|
|
1109
|
+
|
|
1110
|
+
interface ProductsPageProps {
|
|
1111
|
+
initialProducts: ItemSearchResponse;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
export default function ProductsPage({ initialProducts }: ProductsPageProps) {
|
|
1115
|
+
return (
|
|
1116
|
+
<div>
|
|
1117
|
+
<h1>Products</h1>
|
|
1118
|
+
<div>
|
|
1119
|
+
{initialProducts.data.items.map(item => (
|
|
1120
|
+
<div key={item.inv_mast_uid}>
|
|
1121
|
+
{item.item_id} - {item.item_desc}
|
|
1122
|
+
</div>
|
|
1123
|
+
))}
|
|
1124
|
+
</div>
|
|
1125
|
+
</div>
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
732
1128
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1129
|
+
export const getServerSideProps: GetServerSideProps = async () => {
|
|
1130
|
+
try {
|
|
1131
|
+
const api = createServerAPI();
|
|
1132
|
+
const products = await api.opensearch.itemSearch.search({
|
|
1133
|
+
q: 'electrical',
|
|
1134
|
+
searchType: 'query',
|
|
1135
|
+
size: 20,
|
|
1136
|
+
edgeCache: 6 // Cache for 6 hours
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
return {
|
|
1140
|
+
props: {
|
|
1141
|
+
initialProducts: products,
|
|
1142
|
+
},
|
|
1143
|
+
};
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
console.error('Failed to fetch products:', error);
|
|
1146
|
+
return {
|
|
1147
|
+
props: {
|
|
1148
|
+
initialProducts: { data: { items: [] }, status: 500 },
|
|
1149
|
+
},
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
```
|
|
737
1154
|
|
|
738
|
-
###
|
|
1155
|
+
### Node.js Service Integration
|
|
739
1156
|
|
|
740
|
-
|
|
1157
|
+
```typescript
|
|
1158
|
+
// services/AugurService.ts
|
|
1159
|
+
import { AugurAPI, AugurAPIError } from '@simpleapps-com/augur-api';
|
|
1160
|
+
|
|
1161
|
+
export class AugurService {
|
|
1162
|
+
private api: AugurAPI;
|
|
1163
|
+
|
|
1164
|
+
constructor() {
|
|
1165
|
+
const siteId = process.env.AUGUR_SITE_ID;
|
|
1166
|
+
const bearerToken = process.env.AUGUR_SERVICE_TOKEN;
|
|
1167
|
+
|
|
1168
|
+
if (!siteId || !bearerToken) {
|
|
1169
|
+
throw new Error('Augur credentials not configured');
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
this.api = new AugurAPI({
|
|
1173
|
+
siteId,
|
|
1174
|
+
bearerToken,
|
|
1175
|
+
timeout: 30000,
|
|
1176
|
+
retries: 3,
|
|
1177
|
+
retryDelay: 1000,
|
|
1178
|
+
|
|
1179
|
+
// Add comprehensive logging
|
|
1180
|
+
onRequest: (config) => {
|
|
1181
|
+
console.log(`[Augur] ${config.method?.toUpperCase()} ${config.url}`, {
|
|
1182
|
+
headers: config.headers,
|
|
1183
|
+
params: config.params
|
|
1184
|
+
});
|
|
1185
|
+
return config;
|
|
1186
|
+
},
|
|
1187
|
+
|
|
1188
|
+
onResponse: (response) => {
|
|
1189
|
+
console.log(`[Augur] Response ${response.status}`, {
|
|
1190
|
+
url: response.config?.url,
|
|
1191
|
+
cached: response.headers?.['cf-cache-status'] === 'HIT'
|
|
1192
|
+
});
|
|
1193
|
+
return response;
|
|
1194
|
+
},
|
|
1195
|
+
|
|
1196
|
+
onError: (error) => {
|
|
1197
|
+
if (error instanceof AugurAPIError) {
|
|
1198
|
+
console.error(`[Augur] API Error ${error.code}:`, {
|
|
1199
|
+
message: error.message,
|
|
1200
|
+
service: error.service,
|
|
1201
|
+
endpoint: error.endpoint,
|
|
1202
|
+
statusCode: error.statusCode
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
throw error;
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// User management
|
|
1211
|
+
async getUsers(limit = 50) {
|
|
1212
|
+
return this.api.joomla.users.list({
|
|
1213
|
+
limit,
|
|
1214
|
+
edgeCache: 2
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
async getUserById(id: string) {
|
|
1219
|
+
return this.api.joomla.users.get(id);
|
|
1220
|
+
}
|
|
741
1221
|
|
|
742
|
-
|
|
1222
|
+
// Product search
|
|
1223
|
+
async searchProducts(query: string, size = 20) {
|
|
1224
|
+
return this.api.opensearch.itemSearch.search({
|
|
1225
|
+
q: query,
|
|
1226
|
+
searchType: 'query',
|
|
1227
|
+
size,
|
|
1228
|
+
edgeCache: 3
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// Inventory management
|
|
1233
|
+
async getWarehouseInventory(warehouseId: number, searchTerm?: string) {
|
|
1234
|
+
return this.api.vmi.inventory.checkAvailability(warehouseId, {
|
|
1235
|
+
q: searchTerm
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
async replenishInventory(warehouseId: number, items: Array<{
|
|
1240
|
+
inv_mast_uid: number;
|
|
1241
|
+
qty_to_order: number;
|
|
1242
|
+
}>) {
|
|
1243
|
+
return this.api.vmi.inventory.replenish(warehouseId, {
|
|
1244
|
+
distributor_uid: 1, // Default distributor
|
|
1245
|
+
restock_items: items
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// Pricing
|
|
1250
|
+
async getProductPrice(customerId: number, itemId: string, quantity: number) {
|
|
1251
|
+
return this.api.pricing.getPrice({
|
|
1252
|
+
customerId,
|
|
1253
|
+
itemId,
|
|
1254
|
+
quantity,
|
|
1255
|
+
edgeCache: 3 // Cache pricing for 3 hours
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// Health monitoring
|
|
1260
|
+
async checkAllServices() {
|
|
1261
|
+
const services = [
|
|
1262
|
+
'joomla', 'commerce', 'pricing', 'vmi', 'opensearch',
|
|
1263
|
+
'items', 'customers', 'orders', 'payments'
|
|
1264
|
+
];
|
|
1265
|
+
|
|
1266
|
+
const healthChecks = await Promise.allSettled(
|
|
1267
|
+
services.map(async (service) => {
|
|
1268
|
+
try {
|
|
1269
|
+
// Different services have different health check methods
|
|
1270
|
+
let health;
|
|
1271
|
+
if (service === 'vmi') {
|
|
1272
|
+
health = await this.api.vmi.health.check();
|
|
1273
|
+
} else if (service === 'opensearch') {
|
|
1274
|
+
health = await this.api.opensearch.health.check();
|
|
1275
|
+
} else {
|
|
1276
|
+
health = await (this.api as any)[service].getHealthCheck();
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
return { service, status: 'healthy', data: health };
|
|
1280
|
+
} catch (error) {
|
|
1281
|
+
return {
|
|
1282
|
+
service,
|
|
1283
|
+
status: 'unhealthy',
|
|
1284
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
})
|
|
1288
|
+
);
|
|
1289
|
+
|
|
1290
|
+
return healthChecks.map((result, index) => ({
|
|
1291
|
+
service: services[index],
|
|
1292
|
+
...(result.status === 'fulfilled' ? result.value : result.reason)
|
|
1293
|
+
}));
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// Usage in Express.js app
|
|
1298
|
+
import express from 'express';
|
|
1299
|
+
import { AugurService } from './services/AugurService';
|
|
1300
|
+
|
|
1301
|
+
const app = express();
|
|
1302
|
+
const augurService = new AugurService();
|
|
1303
|
+
|
|
1304
|
+
// Get users endpoint
|
|
1305
|
+
app.get('/api/users', async (req, res) => {
|
|
1306
|
+
try {
|
|
1307
|
+
const users = await augurService.getUsers();
|
|
1308
|
+
res.json(users);
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
console.error('Failed to fetch users:', error);
|
|
1311
|
+
res.status(500).json({ error: 'Failed to fetch users' });
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
// Product search endpoint
|
|
1316
|
+
app.get('/api/products/search', async (req, res) => {
|
|
1317
|
+
const { q } = req.query;
|
|
1318
|
+
if (!q || typeof q !== 'string') {
|
|
1319
|
+
return res.status(400).json({ error: 'Search query required' });
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
try {
|
|
1323
|
+
const products = await augurService.searchProducts(q);
|
|
1324
|
+
res.json(products);
|
|
1325
|
+
} catch (error) {
|
|
1326
|
+
console.error('Product search failed:', error);
|
|
1327
|
+
res.status(500).json({ error: 'Product search failed' });
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
// Health check endpoint
|
|
1332
|
+
app.get('/api/health', async (req, res) => {
|
|
1333
|
+
try {
|
|
1334
|
+
const healthStatus = await augurService.checkAllServices();
|
|
1335
|
+
const allHealthy = healthStatus.every(service => service.status === 'healthy');
|
|
1336
|
+
|
|
1337
|
+
res.status(allHealthy ? 200 : 503).json({
|
|
1338
|
+
status: allHealthy ? 'healthy' : 'degraded',
|
|
1339
|
+
services: healthStatus,
|
|
1340
|
+
timestamp: new Date().toISOString()
|
|
1341
|
+
});
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
console.error('Health check failed:', error);
|
|
1344
|
+
res.status(500).json({
|
|
1345
|
+
status: 'error',
|
|
1346
|
+
error: 'Health check failed'
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
743
1350
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
1351
|
+
app.listen(3000, () => {
|
|
1352
|
+
console.log('Server running on port 3000');
|
|
1353
|
+
});
|
|
1354
|
+
```
|
|
1355
|
+
|
|
1356
|
+
### Electron Integration
|
|
1357
|
+
|
|
1358
|
+
```typescript
|
|
1359
|
+
// main/services/AugurService.ts
|
|
1360
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
1361
|
+
import { app } from 'electron';
|
|
1362
|
+
import path from 'path';
|
|
1363
|
+
import fs from 'fs';
|
|
1364
|
+
|
|
1365
|
+
export class ElectronAugurService {
|
|
1366
|
+
private api: AugurAPI;
|
|
1367
|
+
private configPath: string;
|
|
1368
|
+
|
|
1369
|
+
constructor() {
|
|
1370
|
+
this.configPath = path.join(app.getPath('userData'), 'augur-config.json');
|
|
1371
|
+
this.api = this.initializeAPI();
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
private initializeAPI(): AugurAPI {
|
|
1375
|
+
const config = this.loadConfig();
|
|
1376
|
+
|
|
1377
|
+
return new AugurAPI({
|
|
1378
|
+
siteId: config.siteId,
|
|
1379
|
+
bearerToken: config.bearerToken,
|
|
1380
|
+
|
|
1381
|
+
// Electron-specific configuration
|
|
1382
|
+
timeout: 45000, // Longer timeout for desktop app
|
|
1383
|
+
|
|
1384
|
+
onRequest: (config) => {
|
|
1385
|
+
console.log(`[Augur Desktop] ${config.method} ${config.url}`);
|
|
1386
|
+
return config;
|
|
1387
|
+
},
|
|
1388
|
+
|
|
1389
|
+
onError: (error) => {
|
|
1390
|
+
// Show desktop notification for errors
|
|
1391
|
+
this.showErrorNotification(error.message);
|
|
1392
|
+
throw error;
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
private loadConfig() {
|
|
1398
|
+
try {
|
|
1399
|
+
if (fs.existsSync(this.configPath)) {
|
|
1400
|
+
return JSON.parse(fs.readFileSync(this.configPath, 'utf8'));
|
|
1401
|
+
}
|
|
1402
|
+
} catch (error) {
|
|
1403
|
+
console.error('Failed to load config:', error);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// Default configuration
|
|
1407
|
+
return {
|
|
1408
|
+
siteId: process.env.AUGUR_SITE_ID || '',
|
|
1409
|
+
bearerToken: process.env.AUGUR_BEARER_TOKEN || ''
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
saveConfig(config: { siteId: string; bearerToken: string }) {
|
|
1414
|
+
try {
|
|
1415
|
+
fs.writeFileSync(this.configPath, JSON.stringify(config, null, 2));
|
|
1416
|
+
this.api.setSiteId(config.siteId);
|
|
1417
|
+
this.api.setAuthToken(config.bearerToken);
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
console.error('Failed to save config:', error);
|
|
1420
|
+
throw error;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
private showErrorNotification(message: string) {
|
|
1425
|
+
// Implementation depends on your notification system
|
|
1426
|
+
console.error('Augur API Error:', message);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// Exposed API methods
|
|
1430
|
+
async getUsers() {
|
|
1431
|
+
return this.api.joomla.users.list({
|
|
1432
|
+
limit: 100,
|
|
1433
|
+
edgeCache: 2
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
async searchProducts(query: string) {
|
|
1438
|
+
return this.api.opensearch.itemSearch.search({
|
|
1439
|
+
q: query,
|
|
1440
|
+
searchType: 'query',
|
|
1441
|
+
size: 50,
|
|
1442
|
+
edgeCache: 4
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
async getWarehouseData() {
|
|
1447
|
+
return this.api.vmi.warehouses.list({
|
|
1448
|
+
customerId: 12345,
|
|
1449
|
+
edgeCache: 4
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// renderer/hooks/useAugur.ts
|
|
1455
|
+
import { useEffect, useState } from 'react';
|
|
1456
|
+
|
|
1457
|
+
export function useAugur() {
|
|
1458
|
+
const [augurService, setAugurService] = useState(null);
|
|
1459
|
+
|
|
1460
|
+
useEffect(() => {
|
|
1461
|
+
// Get service from main process via IPC
|
|
1462
|
+
window.electronAPI.getAugurService().then(setAugurService);
|
|
1463
|
+
}, []);
|
|
1464
|
+
|
|
1465
|
+
return augurService;
|
|
1466
|
+
}
|
|
1467
|
+
```
|
|
1468
|
+
|
|
1469
|
+
## Error Handling
|
|
1470
|
+
|
|
1471
|
+
### Error Types
|
|
1472
|
+
|
|
1473
|
+
The library provides specific error types for different failure scenarios:
|
|
1474
|
+
|
|
1475
|
+
```typescript
|
|
1476
|
+
import {
|
|
1477
|
+
AugurAPIError, // Base error class
|
|
1478
|
+
AuthenticationError, // 401 errors
|
|
1479
|
+
ValidationError, // Request validation failures
|
|
1480
|
+
NotFoundError, // 404 errors
|
|
1481
|
+
RateLimitError, // 429 errors
|
|
1482
|
+
NetworkError // Network/connectivity issues
|
|
1483
|
+
} from '@simpleapps-com/augur-api';
|
|
1484
|
+
```
|
|
1485
|
+
|
|
1486
|
+
### Comprehensive Error Handling
|
|
1487
|
+
|
|
1488
|
+
```typescript
|
|
1489
|
+
async function handleAPICall() {
|
|
1490
|
+
try {
|
|
1491
|
+
const result = await api.joomla.users.list({ limit: 10 });
|
|
1492
|
+
return result;
|
|
1493
|
+
|
|
1494
|
+
} catch (error) {
|
|
1495
|
+
// Handle specific error types
|
|
1496
|
+
if (error instanceof AuthenticationError) {
|
|
1497
|
+
console.error('Authentication failed:', error.message);
|
|
1498
|
+
|
|
1499
|
+
// Specific auth error scenarios
|
|
1500
|
+
switch (error.statusCode) {
|
|
1501
|
+
case 401:
|
|
1502
|
+
// Token expired or invalid
|
|
1503
|
+
await refreshToken();
|
|
1504
|
+
break;
|
|
1505
|
+
default:
|
|
1506
|
+
redirectToLogin();
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
} else if (error instanceof ValidationError) {
|
|
1510
|
+
console.error('Request validation failed:', error.validationErrors);
|
|
1511
|
+
|
|
1512
|
+
// Handle field-specific validation errors
|
|
1513
|
+
error.validationErrors?.forEach(validationError => {
|
|
1514
|
+
console.error(`Field ${validationError.path}: ${validationError.message}`);
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
} else if (error instanceof NotFoundError) {
|
|
1518
|
+
console.error('Resource not found:', error.message);
|
|
1519
|
+
|
|
1520
|
+
// Show user-friendly not found message
|
|
1521
|
+
showNotFoundMessage(error.endpoint);
|
|
1522
|
+
|
|
1523
|
+
} else if (error instanceof RateLimitError) {
|
|
1524
|
+
console.error('Rate limit exceeded:', error.message);
|
|
1525
|
+
|
|
1526
|
+
// Implement exponential backoff
|
|
1527
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
1528
|
+
return handleAPICall(); // Retry
|
|
1529
|
+
|
|
1530
|
+
} else if (error instanceof AugurAPIError) {
|
|
1531
|
+
console.error('API error:', {
|
|
1532
|
+
code: error.code,
|
|
1533
|
+
message: error.message,
|
|
1534
|
+
service: error.service,
|
|
1535
|
+
endpoint: error.endpoint,
|
|
1536
|
+
statusCode: error.statusCode,
|
|
1537
|
+
requestId: error.requestId
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
// Handle by status code
|
|
1541
|
+
switch (error.statusCode) {
|
|
1542
|
+
case 500:
|
|
1543
|
+
showErrorMessage('Server error. Please try again later.');
|
|
1544
|
+
break;
|
|
1545
|
+
case 503:
|
|
1546
|
+
showErrorMessage('Service temporarily unavailable.');
|
|
1547
|
+
break;
|
|
1548
|
+
default:
|
|
1549
|
+
showErrorMessage(`API error: ${error.message}`);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
} else {
|
|
1553
|
+
console.error('Unexpected error:', error);
|
|
1554
|
+
showErrorMessage('An unexpected error occurred.');
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
throw error; // Re-throw if needed
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
```
|
|
1561
|
+
|
|
1562
|
+
### Retry Logic with Exponential Backoff
|
|
1563
|
+
|
|
1564
|
+
```typescript
|
|
1565
|
+
async function apiCallWithRetry<T>(
|
|
1566
|
+
operation: () => Promise<T>,
|
|
1567
|
+
maxRetries = 3,
|
|
1568
|
+
baseDelay = 1000
|
|
1569
|
+
): Promise<T> {
|
|
1570
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
1571
|
+
try {
|
|
1572
|
+
return await operation();
|
|
1573
|
+
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
// Don't retry on authentication or validation errors
|
|
1576
|
+
if (error instanceof AuthenticationError ||
|
|
1577
|
+
error instanceof ValidationError) {
|
|
1578
|
+
throw error;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Don't retry on final attempt
|
|
1582
|
+
if (attempt === maxRetries) {
|
|
1583
|
+
throw error;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
// Calculate delay with exponential backoff
|
|
1587
|
+
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
1588
|
+
console.log(`Attempt ${attempt} failed, retrying in ${delay}ms...`);
|
|
1589
|
+
|
|
1590
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
throw new Error('All retry attempts exhausted');
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// Usage
|
|
1598
|
+
const users = await apiCallWithRetry(() =>
|
|
1599
|
+
api.joomla.users.list({ limit: 10 })
|
|
1600
|
+
);
|
|
1601
|
+
```
|
|
1602
|
+
|
|
1603
|
+
### Global Error Handler
|
|
1604
|
+
|
|
1605
|
+
```typescript
|
|
1606
|
+
class ErrorHandler {
|
|
1607
|
+
static handle(error: unknown, context?: string): void {
|
|
1608
|
+
const contextPrefix = context ? `[${context}] ` : '';
|
|
1609
|
+
|
|
1610
|
+
if (error instanceof AuthenticationError) {
|
|
1611
|
+
console.error(`${contextPrefix}Authentication failed:`, error.message);
|
|
1612
|
+
this.handleAuthError(error);
|
|
1613
|
+
|
|
1614
|
+
} else if (error instanceof ValidationError) {
|
|
1615
|
+
console.error(`${contextPrefix}Validation failed:`, error.validationErrors);
|
|
1616
|
+
this.handleValidationError(error);
|
|
1617
|
+
|
|
1618
|
+
} else if (error instanceof AugurAPIError) {
|
|
1619
|
+
console.error(`${contextPrefix}API error:`, {
|
|
1620
|
+
service: error.service,
|
|
1621
|
+
endpoint: error.endpoint,
|
|
1622
|
+
code: error.code,
|
|
1623
|
+
message: error.message
|
|
1624
|
+
});
|
|
1625
|
+
this.handleAPIError(error);
|
|
1626
|
+
|
|
1627
|
+
} else {
|
|
1628
|
+
console.error(`${contextPrefix}Unexpected error:`, error);
|
|
1629
|
+
this.handleUnknownError(error);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
private static handleAuthError(error: AuthenticationError): void {
|
|
1634
|
+
// Implement auth error handling
|
|
1635
|
+
if (typeof window !== 'undefined') {
|
|
1636
|
+
// Browser environment
|
|
1637
|
+
localStorage.removeItem('authToken');
|
|
1638
|
+
window.location.href = '/login';
|
|
1639
|
+
} else {
|
|
1640
|
+
// Node.js environment
|
|
1641
|
+
process.exit(1);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
private static handleValidationError(error: ValidationError): void {
|
|
1646
|
+
// Show validation errors to user
|
|
1647
|
+
console.error('Please check your input:', error.validationErrors);
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
private static handleAPIError(error: AugurAPIError): void {
|
|
1651
|
+
// Handle different API error codes
|
|
1652
|
+
switch (error.code) {
|
|
1653
|
+
case 'RATE_LIMIT_EXCEEDED':
|
|
1654
|
+
console.log('Please wait before making more requests');
|
|
1655
|
+
break;
|
|
1656
|
+
case 'SERVICE_UNAVAILABLE':
|
|
1657
|
+
console.log('Service is temporarily unavailable');
|
|
1658
|
+
break;
|
|
1659
|
+
default:
|
|
1660
|
+
console.log(`Service error: ${error.message}`);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
private static handleUnknownError(error: unknown): void {
|
|
1665
|
+
console.error('An unexpected error occurred:', error);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
// Use in API calls
|
|
1670
|
+
try {
|
|
1671
|
+
const result = await api.joomla.users.list();
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
ErrorHandler.handle(error, 'UserList');
|
|
1674
|
+
}
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
## Configuration
|
|
1678
|
+
|
|
1679
|
+
### Basic Configuration
|
|
1680
|
+
|
|
1681
|
+
```typescript
|
|
1682
|
+
import { AugurAPI } from '@simpleapps-com/augur-api';
|
|
1683
|
+
|
|
1684
|
+
const api = new AugurAPI({
|
|
1685
|
+
// Required
|
|
1686
|
+
siteId: 'your-site-id',
|
|
1687
|
+
|
|
1688
|
+
// Authentication (required for most endpoints)
|
|
1689
|
+
bearerToken: 'your-jwt-token',
|
|
1690
|
+
|
|
1691
|
+
// Optional HTTP settings
|
|
1692
|
+
timeout: 30000, // Request timeout in ms (default: 30000)
|
|
1693
|
+
retries: 3, // Number of retries (default: 3)
|
|
1694
|
+
retryDelay: 1000, // Delay between retries in ms (default: 1000)
|
|
1695
|
+
|
|
1696
|
+
// Response capture for debugging
|
|
1697
|
+
captureResponses: true, // Enable response capture (default: false)
|
|
1698
|
+
capturePath: './captured-responses/', // Path for captured responses
|
|
1699
|
+
|
|
1700
|
+
// Request/Response interceptors
|
|
1701
|
+
onRequest: (config) => {
|
|
1702
|
+
console.log('Making request:', config.url);
|
|
1703
|
+
return config;
|
|
1704
|
+
},
|
|
1705
|
+
|
|
1706
|
+
onResponse: (response) => {
|
|
1707
|
+
console.log('Received response:', response.status);
|
|
1708
|
+
return response;
|
|
1709
|
+
},
|
|
1710
|
+
|
|
1711
|
+
onError: (error) => {
|
|
1712
|
+
console.error('Request failed:', error.message);
|
|
1713
|
+
throw error;
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
```
|
|
1717
|
+
|
|
1718
|
+
### Environment-Based Configuration
|
|
1719
|
+
|
|
1720
|
+
```typescript
|
|
1721
|
+
// config/augur.ts
|
|
1722
|
+
interface AugurConfig {
|
|
1723
|
+
siteId: string;
|
|
1724
|
+
bearerToken?: string;
|
|
1725
|
+
timeout: number;
|
|
1726
|
+
retries: number;
|
|
1727
|
+
captureResponses: boolean;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
const environments = {
|
|
1731
|
+
development: {
|
|
1732
|
+
siteId: process.env.AUGUR_DEV_SITE_ID!,
|
|
1733
|
+
bearerToken: process.env.AUGUR_DEV_TOKEN,
|
|
1734
|
+
timeout: 45000, // Longer timeout for dev
|
|
1735
|
+
retries: 1, // Fewer retries for faster feedback
|
|
1736
|
+
captureResponses: true, // Enable response capture in dev
|
|
1737
|
+
},
|
|
1738
|
+
|
|
1739
|
+
staging: {
|
|
1740
|
+
siteId: process.env.AUGUR_STAGING_SITE_ID!,
|
|
1741
|
+
bearerToken: process.env.AUGUR_STAGING_TOKEN,
|
|
1742
|
+
timeout: 30000,
|
|
1743
|
+
retries: 2,
|
|
1744
|
+
captureResponses: false,
|
|
1745
|
+
},
|
|
1746
|
+
|
|
1747
|
+
production: {
|
|
1748
|
+
siteId: process.env.AUGUR_PROD_SITE_ID!,
|
|
1749
|
+
bearerToken: process.env.AUGUR_PROD_TOKEN,
|
|
1750
|
+
timeout: 30000,
|
|
1751
|
+
retries: 3,
|
|
1752
|
+
captureResponses: false,
|
|
1753
|
+
}
|
|
1754
|
+
} as const;
|
|
1755
|
+
|
|
1756
|
+
export function getAugurConfig(): AugurConfig {
|
|
1757
|
+
const env = process.env.NODE_ENV || 'development';
|
|
1758
|
+
const config = environments[env as keyof typeof environments];
|
|
1759
|
+
|
|
1760
|
+
if (!config) {
|
|
1761
|
+
throw new Error(`No Augur configuration found for environment: ${env}`);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
if (!config.siteId) {
|
|
1765
|
+
throw new Error(`Augur site ID not configured for environment: ${env}`);
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
return config;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
// Usage
|
|
1772
|
+
import { getAugurConfig } from './config/augur';
|
|
1773
|
+
|
|
1774
|
+
const api = new AugurAPI(getAugurConfig());
|
|
1775
|
+
```
|
|
1776
|
+
|
|
1777
|
+
### Configuration Validation
|
|
1778
|
+
|
|
1779
|
+
```typescript
|
|
1780
|
+
import { z } from 'zod';
|
|
1781
|
+
|
|
1782
|
+
const AugurConfigSchema = z.object({
|
|
1783
|
+
siteId: z.string().min(1, 'Site ID is required'),
|
|
1784
|
+
bearerToken: z.string().optional(),
|
|
1785
|
+
timeout: z.number().positive().optional(),
|
|
1786
|
+
retries: z.number().int().min(0).max(10).optional(),
|
|
1787
|
+
captureResponses: z.boolean().optional(),
|
|
1788
|
+
capturePath: z.string().optional(),
|
|
1789
|
+
});
|
|
1790
|
+
|
|
1791
|
+
export function createValidatedAugurAPI(config: unknown): AugurAPI {
|
|
1792
|
+
const validatedConfig = AugurConfigSchema.parse(config);
|
|
1793
|
+
return new AugurAPI(validatedConfig);
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
// Usage with validation
|
|
1797
|
+
try {
|
|
1798
|
+
const api = createValidatedAugurAPI({
|
|
1799
|
+
siteId: process.env.AUGUR_SITE_ID,
|
|
1800
|
+
bearerToken: process.env.AUGUR_TOKEN,
|
|
1801
|
+
timeout: 30000,
|
|
1802
|
+
retries: 3
|
|
1803
|
+
});
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
if (error instanceof z.ZodError) {
|
|
1806
|
+
console.error('Configuration validation failed:', error.errors);
|
|
1807
|
+
process.exit(1);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
```
|
|
1811
|
+
|
|
1812
|
+
### Dynamic Configuration Updates
|
|
1813
|
+
|
|
1814
|
+
```typescript
|
|
1815
|
+
class ManagedAugurAPI {
|
|
1816
|
+
private api: AugurAPI;
|
|
1817
|
+
private config: AugurConfig;
|
|
1818
|
+
|
|
1819
|
+
constructor(initialConfig: AugurConfig) {
|
|
1820
|
+
this.config = initialConfig;
|
|
1821
|
+
this.api = new AugurAPI(initialConfig);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
updateConfig(newConfig: Partial<AugurConfig>): void {
|
|
1825
|
+
this.config = { ...this.config, ...newConfig };
|
|
1826
|
+
|
|
1827
|
+
// Update specific properties that can be changed at runtime
|
|
1828
|
+
if (newConfig.bearerToken !== undefined) {
|
|
1829
|
+
this.api.setAuthToken(newConfig.bearerToken);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
if (newConfig.siteId !== undefined) {
|
|
1833
|
+
this.api.setSiteId(newConfig.siteId);
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
// For other config changes, recreate the API instance
|
|
1837
|
+
if (newConfig.timeout || newConfig.retries) {
|
|
1838
|
+
this.api = new AugurAPI(this.config);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
getAPI(): AugurAPI {
|
|
1843
|
+
return this.api;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
getCurrentConfig(): AugurConfig {
|
|
1847
|
+
return { ...this.config };
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
// Usage
|
|
1852
|
+
const managedAPI = new ManagedAugurAPI({
|
|
1853
|
+
siteId: 'initial-site',
|
|
1854
|
+
bearerToken: 'initial-token'
|
|
1855
|
+
});
|
|
1856
|
+
|
|
1857
|
+
// Update token after authentication
|
|
1858
|
+
managedAPI.updateConfig({
|
|
1859
|
+
bearerToken: 'new-token-after-auth'
|
|
1860
|
+
});
|
|
1861
|
+
|
|
1862
|
+
// Switch to different site
|
|
1863
|
+
managedAPI.updateConfig({
|
|
1864
|
+
siteId: 'different-site',
|
|
1865
|
+
bearerToken: 'site-specific-token'
|
|
1866
|
+
});
|
|
1867
|
+
```
|
|
1868
|
+
|
|
1869
|
+
## Performance Optimization
|
|
1870
|
+
|
|
1871
|
+
### Caching Strategies
|
|
1872
|
+
|
|
1873
|
+
```typescript
|
|
1874
|
+
// Cache strategy based on data volatility
|
|
1875
|
+
class CacheStrategy {
|
|
1876
|
+
static getDuration(dataType: string, context?: Record<string, any>): number | undefined {
|
|
1877
|
+
const strategies = {
|
|
1878
|
+
// Static reference data - cache for 8 hours
|
|
1879
|
+
reference: 8,
|
|
1880
|
+
categories: 8,
|
|
1881
|
+
tags: 6,
|
|
1882
|
+
distributors: 8,
|
|
1883
|
+
|
|
1884
|
+
// Moderate volatility - cache for 2-4 hours
|
|
1885
|
+
users: context?.isLargeOrg ? 4 : 2,
|
|
1886
|
+
products: 6,
|
|
1887
|
+
warehouses: 4,
|
|
1888
|
+
recommendations: 4,
|
|
1889
|
+
|
|
1890
|
+
// High volatility - cache for 1-2 hours
|
|
1891
|
+
pricing: context?.isStandardItem ? 3 : 1,
|
|
1892
|
+
inventory: context?.isHighVolume ? 1 : 2,
|
|
1893
|
+
cart: 1,
|
|
1894
|
+
|
|
1895
|
+
// Real-time data - no caching
|
|
1896
|
+
authentication: undefined,
|
|
1897
|
+
validation: undefined,
|
|
1898
|
+
checkout: undefined,
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
return strategies[dataType as keyof typeof strategies];
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// Usage
|
|
1906
|
+
const duration = CacheStrategy.getDuration('pricing', { isStandardItem: true });
|
|
1907
|
+
const pricing = await api.pricing.getPrice({
|
|
1908
|
+
customerId: 12345,
|
|
1909
|
+
itemId: 'STANDARD-ITEM',
|
|
1910
|
+
quantity: 10,
|
|
1911
|
+
edgeCache: duration // Will be 3 hours
|
|
1912
|
+
});
|
|
1913
|
+
```
|
|
1914
|
+
|
|
1915
|
+
### Request Batching
|
|
1916
|
+
|
|
1917
|
+
```typescript
|
|
1918
|
+
// Batch related requests for better performance
|
|
1919
|
+
async function loadDashboardData() {
|
|
1920
|
+
// Execute all requests in parallel
|
|
1921
|
+
const [users, products, inventory, pricing] = await Promise.allSettled([
|
|
1922
|
+
api.joomla.users.list({ limit: 10, edgeCache: 2 }),
|
|
1923
|
+
api.opensearch.itemSearch.search({
|
|
1924
|
+
q: 'featured',
|
|
1925
|
+
searchType: 'query',
|
|
1926
|
+
size: 5,
|
|
1927
|
+
edgeCache: 4
|
|
1928
|
+
}),
|
|
1929
|
+
api.vmi.warehouses.list({
|
|
1930
|
+
customerId: 12345,
|
|
1931
|
+
limit: 5,
|
|
1932
|
+
edgeCache: 4
|
|
1933
|
+
}),
|
|
1934
|
+
api.pricing.jobPriceHeaders.list({
|
|
1935
|
+
limit: 5,
|
|
1936
|
+
edgeCache: 6
|
|
1937
|
+
})
|
|
1938
|
+
]);
|
|
1939
|
+
|
|
1940
|
+
// Handle results
|
|
1941
|
+
return {
|
|
1942
|
+
users: users.status === 'fulfilled' ? users.value : null,
|
|
1943
|
+
products: products.status === 'fulfilled' ? products.value : null,
|
|
1944
|
+
inventory: inventory.status === 'fulfilled' ? inventory.value : null,
|
|
1945
|
+
pricing: pricing.status === 'fulfilled' ? pricing.value : null,
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
```
|
|
1949
|
+
|
|
1950
|
+
### Connection Pooling
|
|
1951
|
+
|
|
1952
|
+
```typescript
|
|
1953
|
+
// Configure HTTP client for optimal performance
|
|
1954
|
+
const api = new AugurAPI({
|
|
1955
|
+
siteId: 'your-site-id',
|
|
1956
|
+
bearerToken: 'your-token',
|
|
1957
|
+
|
|
1958
|
+
// Optimize for high-throughput scenarios
|
|
1959
|
+
timeout: 15000, // Shorter timeout for better user experience
|
|
1960
|
+
retries: 2, // Fewer retries for faster failure detection
|
|
1961
|
+
|
|
1962
|
+
onRequest: (config) => {
|
|
1963
|
+
// Add keep-alive headers for connection reuse
|
|
1964
|
+
config.headers['Connection'] = 'keep-alive';
|
|
1965
|
+
config.headers['Keep-Alive'] = 'timeout=5, max=1000';
|
|
1966
|
+
return config;
|
|
1967
|
+
}
|
|
1968
|
+
});
|
|
1969
|
+
```
|
|
1970
|
+
|
|
1971
|
+
### Memory Management
|
|
1972
|
+
|
|
1973
|
+
```typescript
|
|
1974
|
+
// Efficient memory usage patterns
|
|
1975
|
+
class EfficientAugurUsage {
|
|
1976
|
+
private api: AugurAPI;
|
|
1977
|
+
private cache = new Map<string, { data: any; timestamp: number; ttl: number }>();
|
|
1978
|
+
|
|
1979
|
+
constructor(config: AugurAPIConfig) {
|
|
1980
|
+
this.api = new AugurAPI(config);
|
|
1981
|
+
|
|
1982
|
+
// Clean up expired cache entries every 5 minutes
|
|
1983
|
+
setInterval(() => this.cleanupCache(), 5 * 60 * 1000);
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
async getCachedData<T>(
|
|
1987
|
+
key: string,
|
|
1988
|
+
fetcher: () => Promise<T>,
|
|
1989
|
+
ttlSeconds = 300
|
|
1990
|
+
): Promise<T> {
|
|
1991
|
+
const cached = this.cache.get(key);
|
|
1992
|
+
const now = Date.now();
|
|
1993
|
+
|
|
1994
|
+
if (cached && (now - cached.timestamp) < (cached.ttl * 1000)) {
|
|
1995
|
+
return cached.data;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
const data = await fetcher();
|
|
1999
|
+
this.cache.set(key, {
|
|
2000
|
+
data,
|
|
2001
|
+
timestamp: now,
|
|
2002
|
+
ttl: ttlSeconds
|
|
2003
|
+
});
|
|
2004
|
+
|
|
2005
|
+
return data;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
private cleanupCache(): void {
|
|
2009
|
+
const now = Date.now();
|
|
2010
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
2011
|
+
if ((now - entry.timestamp) >= (entry.ttl * 1000)) {
|
|
2012
|
+
this.cache.delete(key);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
async getUsers(useCache = true): Promise<any> {
|
|
2018
|
+
if (!useCache) {
|
|
2019
|
+
return this.api.joomla.users.list({ limit: 50 });
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
return this.getCachedData(
|
|
2023
|
+
'users-list',
|
|
2024
|
+
() => this.api.joomla.users.list({ limit: 50, edgeCache: 2 }),
|
|
2025
|
+
600 // 10 minutes local cache
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
destroy(): void {
|
|
2030
|
+
this.cache.clear();
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
```
|
|
2034
|
+
|
|
2035
|
+
### Performance Monitoring
|
|
2036
|
+
|
|
2037
|
+
```typescript
|
|
2038
|
+
// Monitor API performance
|
|
2039
|
+
class PerformanceMonitor {
|
|
2040
|
+
private metrics = {
|
|
2041
|
+
requests: 0,
|
|
2042
|
+
errors: 0,
|
|
2043
|
+
totalTime: 0,
|
|
2044
|
+
cacheHits: 0,
|
|
2045
|
+
cacheMisses: 0
|
|
2046
|
+
};
|
|
2047
|
+
|
|
2048
|
+
createMonitoredAPI(config: AugurAPIConfig): AugurAPI {
|
|
2049
|
+
return new AugurAPI({
|
|
2050
|
+
...config,
|
|
2051
|
+
|
|
2052
|
+
onRequest: (config) => {
|
|
2053
|
+
// Track request start time
|
|
2054
|
+
(config as any).startTime = Date.now();
|
|
2055
|
+
this.metrics.requests++;
|
|
2056
|
+
return config;
|
|
2057
|
+
},
|
|
2058
|
+
|
|
2059
|
+
onResponse: (response) => {
|
|
2060
|
+
// Calculate request duration
|
|
2061
|
+
const startTime = (response.config as any)?.startTime;
|
|
2062
|
+
if (startTime) {
|
|
2063
|
+
const duration = Date.now() - startTime;
|
|
2064
|
+
this.metrics.totalTime += duration;
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// Track cache performance
|
|
2068
|
+
const cacheStatus = response.headers?.['cf-cache-status'];
|
|
2069
|
+
if (cacheStatus === 'HIT') {
|
|
2070
|
+
this.metrics.cacheHits++;
|
|
2071
|
+
} else if (cacheStatus === 'MISS') {
|
|
2072
|
+
this.metrics.cacheMisses++;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
return response;
|
|
2076
|
+
},
|
|
2077
|
+
|
|
2078
|
+
onError: (error) => {
|
|
2079
|
+
this.metrics.errors++;
|
|
2080
|
+
console.error('API Error metrics:', this.getMetrics());
|
|
2081
|
+
throw error;
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
getMetrics() {
|
|
2087
|
+
const avgResponseTime = this.metrics.requests > 0
|
|
2088
|
+
? this.metrics.totalTime / this.metrics.requests
|
|
2089
|
+
: 0;
|
|
2090
|
+
|
|
2091
|
+
const errorRate = this.metrics.requests > 0
|
|
2092
|
+
? (this.metrics.errors / this.metrics.requests) * 100
|
|
2093
|
+
: 0;
|
|
2094
|
+
|
|
2095
|
+
const cacheHitRate = (this.metrics.cacheHits + this.metrics.cacheMisses) > 0
|
|
2096
|
+
? (this.metrics.cacheHits / (this.metrics.cacheHits + this.metrics.cacheMisses)) * 100
|
|
2097
|
+
: 0;
|
|
2098
|
+
|
|
2099
|
+
return {
|
|
2100
|
+
totalRequests: this.metrics.requests,
|
|
2101
|
+
totalErrors: this.metrics.errors,
|
|
2102
|
+
errorRate: errorRate.toFixed(2) + '%',
|
|
2103
|
+
avgResponseTime: avgResponseTime.toFixed(2) + 'ms',
|
|
2104
|
+
cacheHitRate: cacheHitRate.toFixed(2) + '%',
|
|
2105
|
+
totalCacheHits: this.metrics.cacheHits,
|
|
2106
|
+
totalCacheMisses: this.metrics.cacheMisses
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
reset(): void {
|
|
2111
|
+
this.metrics = {
|
|
2112
|
+
requests: 0,
|
|
2113
|
+
errors: 0,
|
|
2114
|
+
totalTime: 0,
|
|
2115
|
+
cacheHits: 0,
|
|
2116
|
+
cacheMisses: 0
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// Usage
|
|
2122
|
+
const monitor = new PerformanceMonitor();
|
|
2123
|
+
const api = monitor.createMonitoredAPI({
|
|
2124
|
+
siteId: 'your-site-id',
|
|
2125
|
+
bearerToken: 'your-token'
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
// After some API calls, check performance
|
|
2129
|
+
setTimeout(() => {
|
|
2130
|
+
console.log('Performance metrics:', monitor.getMetrics());
|
|
2131
|
+
}, 60000);
|
|
2132
|
+
```
|
|
2133
|
+
|
|
2134
|
+
## Development
|
|
2135
|
+
|
|
2136
|
+
### Building from Source
|
|
2137
|
+
|
|
2138
|
+
```bash
|
|
2139
|
+
# Clone the repository
|
|
2140
|
+
git clone https://github.com/your-org/augur-api-client.git
|
|
2141
|
+
cd augur-api-client/packages/augur-api
|
|
2142
|
+
|
|
2143
|
+
# Install dependencies
|
|
2144
|
+
npm install
|
|
2145
|
+
|
|
2146
|
+
# Build the library
|
|
2147
|
+
npm run build
|
|
2148
|
+
|
|
2149
|
+
# Run tests
|
|
2150
|
+
npm test
|
|
2151
|
+
|
|
2152
|
+
# Run tests with coverage
|
|
2153
|
+
npm run test:coverage
|
|
2154
|
+
|
|
2155
|
+
# Run E2E tests (requires API credentials)
|
|
2156
|
+
npm run test:e2e
|
|
2157
|
+
|
|
2158
|
+
# Lint code
|
|
2159
|
+
npm run lint
|
|
2160
|
+
|
|
2161
|
+
# Type check
|
|
2162
|
+
npm run typecheck
|
|
2163
|
+
```
|
|
2164
|
+
|
|
2165
|
+
### Development Scripts
|
|
2166
|
+
|
|
2167
|
+
```bash
|
|
2168
|
+
# Development workflow
|
|
2169
|
+
npm run dev # Watch mode for development
|
|
2170
|
+
npm run test:watch # Watch mode for tests
|
|
2171
|
+
npm run build:watch # Watch mode for building
|
|
2172
|
+
|
|
2173
|
+
# Code quality
|
|
2174
|
+
npm run lint:fix # Auto-fix linting issues
|
|
2175
|
+
npm run format # Format code with Prettier
|
|
2176
|
+
npm run format:check # Check code formatting
|
|
2177
|
+
|
|
2178
|
+
# Release workflow
|
|
2179
|
+
npm run clean # Clean build artifacts
|
|
2180
|
+
npm run prepublish # Build and prepare for publishing
|
|
2181
|
+
```
|
|
2182
|
+
|
|
2183
|
+
### Testing
|
|
2184
|
+
|
|
2185
|
+
The library maintains >85% test coverage across all components:
|
|
2186
|
+
|
|
2187
|
+
```typescript
|
|
2188
|
+
// Example test
|
|
2189
|
+
import { AugurAPI, AuthenticationError } from '../src';
|
|
2190
|
+
|
|
2191
|
+
describe('AugurAPI', () => {
|
|
2192
|
+
let api: AugurAPI;
|
|
2193
|
+
|
|
2194
|
+
beforeEach(() => {
|
|
2195
|
+
api = new AugurAPI({
|
|
2196
|
+
siteId: 'test-site',
|
|
2197
|
+
bearerToken: 'test-token'
|
|
2198
|
+
});
|
|
2199
|
+
});
|
|
2200
|
+
|
|
2201
|
+
it('should create service clients lazily', () => {
|
|
2202
|
+
// Service clients are created on first access
|
|
2203
|
+
const joomla1 = api.joomla;
|
|
2204
|
+
const joomla2 = api.joomla;
|
|
2205
|
+
|
|
2206
|
+
expect(joomla1).toBe(joomla2); // Same instance
|
|
2207
|
+
});
|
|
2208
|
+
|
|
2209
|
+
it('should reset clients when auth token changes', () => {
|
|
2210
|
+
const joomla1 = api.joomla;
|
|
2211
|
+
|
|
2212
|
+
api.setAuthToken('new-token');
|
|
2213
|
+
|
|
2214
|
+
const joomla2 = api.joomla;
|
|
2215
|
+
expect(joomla1).not.toBe(joomla2); // Different instances
|
|
2216
|
+
});
|
|
2217
|
+
|
|
2218
|
+
it('should handle authentication errors', async () => {
|
|
2219
|
+
// Mock failed authentication
|
|
2220
|
+
mockAPI.joomla.users.list.mockRejectedValue(
|
|
2221
|
+
new AuthenticationError({
|
|
2222
|
+
message: 'Invalid token',
|
|
2223
|
+
service: 'joomla',
|
|
2224
|
+
endpoint: '/users'
|
|
2225
|
+
})
|
|
2226
|
+
);
|
|
2227
|
+
|
|
2228
|
+
await expect(api.joomla.users.list()).rejects.toThrow(AuthenticationError);
|
|
2229
|
+
});
|
|
2230
|
+
});
|
|
2231
|
+
```
|
|
2232
|
+
|
|
2233
|
+
### API Response Capture
|
|
2234
|
+
|
|
2235
|
+
For debugging and development, enable response capture:
|
|
2236
|
+
|
|
2237
|
+
```typescript
|
|
2238
|
+
const api = new AugurAPI({
|
|
2239
|
+
siteId: 'your-site-id',
|
|
2240
|
+
bearerToken: 'your-token',
|
|
2241
|
+
captureResponses: true,
|
|
2242
|
+
capturePath: './captured-responses/'
|
|
2243
|
+
});
|
|
2244
|
+
|
|
2245
|
+
// Responses will be saved to files for inspection
|
|
2246
|
+
const users = await api.joomla.users.list();
|
|
2247
|
+
// Saved to: ./captured-responses/joomla-users-list-[timestamp].json
|
|
2248
|
+
```
|
|
2249
|
+
|
|
2250
|
+
### Code Generation
|
|
2251
|
+
|
|
2252
|
+
The library uses code generation from Postman collections:
|
|
2253
|
+
|
|
2254
|
+
```bash
|
|
2255
|
+
# Generate client code from Postman collections
|
|
2256
|
+
npm run generate:clients
|
|
2257
|
+
|
|
2258
|
+
# Update schemas from API responses
|
|
2259
|
+
npm run generate:schemas
|
|
2260
|
+
|
|
2261
|
+
# Generate TypeScript types
|
|
2262
|
+
npm run generate:types
|
|
2263
|
+
```
|
|
2264
|
+
|
|
2265
|
+
### Contributing Guidelines
|
|
2266
|
+
|
|
2267
|
+
1. **Follow TypeScript best practices**
|
|
2268
|
+
2. **Maintain >85% test coverage**
|
|
2269
|
+
3. **Add comprehensive JSDoc documentation**
|
|
2270
|
+
4. **Follow existing naming conventions**
|
|
2271
|
+
5. **Update documentation for new features**
|
|
2272
|
+
6. **Run all tests before submitting PRs**
|
|
2273
|
+
|
|
2274
|
+
```typescript
|
|
2275
|
+
// Example contribution - adding a new method
|
|
2276
|
+
/**
|
|
2277
|
+
* Get user profile with additional details
|
|
2278
|
+
* @description Retrieves comprehensive user profile including preferences and settings
|
|
2279
|
+
*
|
|
2280
|
+
* @param userId - The unique identifier for the user
|
|
2281
|
+
* @param options - Additional options for profile retrieval
|
|
2282
|
+
* @returns Promise resolving to user profile data
|
|
2283
|
+
* @throws AuthenticationError When user token is invalid
|
|
2284
|
+
* @throws NotFoundError When user does not exist
|
|
2285
|
+
*
|
|
2286
|
+
* @example
|
|
2287
|
+
* ```typescript
|
|
2288
|
+
* const profile = await api.joomla.users.getProfile('user-123', {
|
|
2289
|
+
* includePreferences: true,
|
|
2290
|
+
* edgeCache: 2
|
|
2291
|
+
* });
|
|
2292
|
+
*
|
|
2293
|
+
* console.log(profile.data.username);
|
|
2294
|
+
* console.log(profile.data.preferences);
|
|
2295
|
+
* ```
|
|
2296
|
+
*/
|
|
2297
|
+
async getProfile(userId: string, options?: ProfileOptions): Promise<UserProfileResponse> {
|
|
2298
|
+
const params = ProfileOptionsSchema.parse(options || {});
|
|
2299
|
+
const response = await this.http.get(`/user/${userId}/profile`, params);
|
|
2300
|
+
return UserProfileResponseSchema.parse(response);
|
|
2301
|
+
}
|
|
2302
|
+
```
|
|
747
2303
|
|
|
748
2304
|
## Contributing
|
|
749
2305
|
|
|
750
|
-
|
|
2306
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
2307
|
+
|
|
2308
|
+
### Quick Contributing Steps
|
|
2309
|
+
|
|
2310
|
+
1. Fork the repository
|
|
2311
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
2312
|
+
3. Make your changes with tests
|
|
2313
|
+
4. Ensure all tests pass: `npm test`
|
|
2314
|
+
5. Commit changes: `git commit -m 'Add amazing feature'`
|
|
2315
|
+
6. Push to branch: `git push origin feature/amazing-feature`
|
|
2316
|
+
7. Submit a Pull Request
|
|
2317
|
+
|
|
2318
|
+
### Development Setup
|
|
2319
|
+
|
|
2320
|
+
```bash
|
|
2321
|
+
# Clone your fork
|
|
2322
|
+
git clone https://github.com/your-username/augur-api-client.git
|
|
2323
|
+
cd augur-api-client/packages/augur-api
|
|
2324
|
+
|
|
2325
|
+
# Install dependencies
|
|
2326
|
+
npm install
|
|
2327
|
+
|
|
2328
|
+
# Set up development credentials
|
|
2329
|
+
cp .env.example .env
|
|
2330
|
+
# Edit .env with your API credentials
|
|
2331
|
+
|
|
2332
|
+
# Run tests to verify setup
|
|
2333
|
+
npm test
|
|
2334
|
+
```
|
|
2335
|
+
|
|
2336
|
+
## License
|
|
2337
|
+
|
|
2338
|
+
MIT License - see [LICENSE](./LICENSE) file for details.
|
|
2339
|
+
|
|
2340
|
+
## Support
|
|
2341
|
+
|
|
2342
|
+
- **Documentation**: [User Guide](../../docs/packages/augur-api/user/README.md)
|
|
2343
|
+
- **Developer Docs**: [Developer Guide](../../docs/packages/augur-api/dev/README.md)
|
|
2344
|
+
- **Issues**: [GitHub Issues](https://github.com/your-org/augur-api-client/issues)
|
|
2345
|
+
- **Discord**: [Community Chat](https://discord.gg/augur-api)
|
|
2346
|
+
|
|
2347
|
+
---
|
|
2348
|
+
|
|
2349
|
+
**Built with ❤️ by the Augur team**
|