arky-sdk 0.4.33 → 0.4.35

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.
@@ -0,0 +1,43 @@
1
+ import { Payment, InventoryLevel } from './types.cjs';
2
+
3
+ declare function convertToMajor(minorAmount: number, currency: string): number;
4
+ declare function convertToMinor(majorAmount: number, currency: string): number;
5
+ declare function getCurrencySymbol(currency: string): string;
6
+ declare function getCurrencyName(currency: string): string;
7
+ declare function formatMinor(amountMinor: number, currency: string): string;
8
+ declare function formatPayment(payment: Payment): string;
9
+
10
+ declare function isValidKey(key: string): boolean;
11
+ declare function validateKey(key: string): {
12
+ valid: boolean;
13
+ error?: string;
14
+ };
15
+ declare function toKey(input: string): string;
16
+ declare function nameToKey(name: string): string;
17
+
18
+ interface VariantWithInventory {
19
+ inventory: InventoryLevel[];
20
+ }
21
+ /**
22
+ * Get total available stock across all fulfillment centers for a variant
23
+ */
24
+ declare function getAvailableStock(variant: VariantWithInventory): number;
25
+ /**
26
+ * Get total reserved stock across all fulfillment centers for a variant
27
+ */
28
+ declare function getReservedStock(variant: VariantWithInventory): number;
29
+ /**
30
+ * Check if variant has any available stock
31
+ */
32
+ declare function hasStock(variant: VariantWithInventory, quantity?: number): boolean;
33
+ /**
34
+ * Get inventory level at a specific fulfillment center
35
+ */
36
+ declare function getInventoryAt(variant: VariantWithInventory, fulfillmentCenterId: string): InventoryLevel | undefined;
37
+ /**
38
+ * Get the first fulfillment center with available stock
39
+ * Returns the fulfillmentCenterId of the first center that has stock
40
+ */
41
+ declare function getFirstAvailableFCId(variant: VariantWithInventory, quantity?: number): string | undefined;
42
+
43
+ export { formatMinor as a, getCurrencyName as b, getAvailableStock as c, getReservedStock as d, getInventoryAt as e, formatPayment as f, getCurrencySymbol as g, hasStock as h, isValidKey as i, getFirstAvailableFCId as j, convertToMajor as k, convertToMinor as l, nameToKey as n, toKey as t, validateKey as v };
@@ -0,0 +1,43 @@
1
+ import { Payment, InventoryLevel } from './types.js';
2
+
3
+ declare function convertToMajor(minorAmount: number, currency: string): number;
4
+ declare function convertToMinor(majorAmount: number, currency: string): number;
5
+ declare function getCurrencySymbol(currency: string): string;
6
+ declare function getCurrencyName(currency: string): string;
7
+ declare function formatMinor(amountMinor: number, currency: string): string;
8
+ declare function formatPayment(payment: Payment): string;
9
+
10
+ declare function isValidKey(key: string): boolean;
11
+ declare function validateKey(key: string): {
12
+ valid: boolean;
13
+ error?: string;
14
+ };
15
+ declare function toKey(input: string): string;
16
+ declare function nameToKey(name: string): string;
17
+
18
+ interface VariantWithInventory {
19
+ inventory: InventoryLevel[];
20
+ }
21
+ /**
22
+ * Get total available stock across all fulfillment centers for a variant
23
+ */
24
+ declare function getAvailableStock(variant: VariantWithInventory): number;
25
+ /**
26
+ * Get total reserved stock across all fulfillment centers for a variant
27
+ */
28
+ declare function getReservedStock(variant: VariantWithInventory): number;
29
+ /**
30
+ * Check if variant has any available stock
31
+ */
32
+ declare function hasStock(variant: VariantWithInventory, quantity?: number): boolean;
33
+ /**
34
+ * Get inventory level at a specific fulfillment center
35
+ */
36
+ declare function getInventoryAt(variant: VariantWithInventory, fulfillmentCenterId: string): InventoryLevel | undefined;
37
+ /**
38
+ * Get the first fulfillment center with available stock
39
+ * Returns the fulfillmentCenterId of the first center that has stock
40
+ */
41
+ declare function getFirstAvailableFCId(variant: VariantWithInventory, quantity?: number): string | undefined;
42
+
43
+ export { formatMinor as a, getCurrencyName as b, getAvailableStock as c, getReservedStock as d, getInventoryAt as e, formatPayment as f, getCurrencySymbol as g, hasStock as h, isValidKey as i, getFirstAvailableFCId as j, convertToMajor as k, convertToMinor as l, nameToKey as n, toKey as t, validateKey as v };
package/dist/index.cjs CHANGED
@@ -1623,8 +1623,28 @@ function track(eventName, params) {
1623
1623
  }
1624
1624
  }
1625
1625
 
1626
+ // src/utils/inventory.ts
1627
+ function getAvailableStock(variant) {
1628
+ if (!variant?.inventory) return 0;
1629
+ return variant.inventory.reduce((sum, inv) => sum + inv.available, 0);
1630
+ }
1631
+ function getReservedStock(variant) {
1632
+ if (!variant?.inventory) return 0;
1633
+ return variant.inventory.reduce((sum, inv) => sum + inv.reserved, 0);
1634
+ }
1635
+ function hasStock(variant, quantity = 1) {
1636
+ return getAvailableStock(variant) >= quantity;
1637
+ }
1638
+ function getInventoryAt(variant, fulfillmentCenterId) {
1639
+ return variant?.inventory?.find((inv) => inv.fulfillmentCenterId === fulfillmentCenterId);
1640
+ }
1641
+ function getFirstAvailableFCId(variant, quantity = 1) {
1642
+ const inv = variant?.inventory?.find((i) => i.available >= quantity);
1643
+ return inv?.fulfillmentCenterId;
1644
+ }
1645
+
1626
1646
  // src/index.ts
1627
- var SDK_VERSION = "0.4.31";
1647
+ var SDK_VERSION = "0.4.34";
1628
1648
  var SUPPORTED_FRAMEWORKS = [
1629
1649
  "astro",
1630
1650
  "react",
@@ -1724,7 +1744,12 @@ async function createArkySDK(config) {
1724
1744
  validateKey,
1725
1745
  toKey,
1726
1746
  nameToKey,
1727
- track
1747
+ track,
1748
+ getAvailableStock,
1749
+ getReservedStock,
1750
+ hasStock,
1751
+ getInventoryAt,
1752
+ getFirstAvailableFCId
1728
1753
  },
1729
1754
  // Platform config helpers
1730
1755
  getPlatformConfig: () => platformApi.getConfigCache(),