@commercelayer/sdk 5.18.1 → 5.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/lib/cjs/api.d.ts +3 -3
  2. package/lib/cjs/commercelayer.d.ts +2 -2
  3. package/lib/cjs/commercelayer.js +1 -1
  4. package/lib/cjs/model.d.ts +3 -3
  5. package/lib/cjs/resources/inventory_models.d.ts +3 -0
  6. package/lib/cjs/resources/payment_methods.d.ts +3 -3
  7. package/lib/cjs/resources/payment_options.d.ts +2 -2
  8. package/lib/cjs/resources/shipments.d.ts +38 -5
  9. package/lib/cjs/resources/shipments.js +19 -0
  10. package/lib/cjs/resources/stock_line_items.d.ts +37 -7
  11. package/lib/cjs/resources/stock_line_items.js +9 -0
  12. package/lib/cjs/resources/stock_reservations.d.ts +19 -3
  13. package/lib/cjs/resources/stock_reservations.js +12 -0
  14. package/lib/cjs/resources/stock_transfers.d.ts +3 -1
  15. package/lib/cjs/resources/stock_transfers.js +3 -0
  16. package/lib/esm/api.d.ts +3 -3
  17. package/lib/esm/commercelayer.d.ts +2 -2
  18. package/lib/esm/commercelayer.js +1 -1
  19. package/lib/esm/model.d.ts +3 -3
  20. package/lib/esm/resources/inventory_models.d.ts +3 -0
  21. package/lib/esm/resources/payment_methods.d.ts +3 -3
  22. package/lib/esm/resources/payment_options.d.ts +2 -2
  23. package/lib/esm/resources/shipments.d.ts +38 -5
  24. package/lib/esm/resources/shipments.js +19 -0
  25. package/lib/esm/resources/stock_line_items.d.ts +37 -7
  26. package/lib/esm/resources/stock_line_items.js +9 -0
  27. package/lib/esm/resources/stock_reservations.d.ts +19 -3
  28. package/lib/esm/resources/stock_reservations.js +12 -0
  29. package/lib/esm/resources/stock_transfers.d.ts +3 -1
  30. package/lib/esm/resources/stock_transfers.js +3 -0
  31. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  32. package/lib/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +3 -3
@@ -92,7 +92,7 @@ export type { ReturnLineItem, ReturnLineItemCreate, ReturnLineItemUpdate } from
92
92
  export type { Return, ReturnCreate, ReturnUpdate } from './resources/returns';
93
93
  export type { SatispayGateway, SatispayGatewayCreate, SatispayGatewayUpdate } from './resources/satispay_gateways';
94
94
  export type { SatispayPayment, SatispayPaymentCreate, SatispayPaymentUpdate } from './resources/satispay_payments';
95
- export type { Shipment, ShipmentUpdate } from './resources/shipments';
95
+ export type { Shipment, ShipmentCreate, ShipmentUpdate } from './resources/shipments';
96
96
  export type { ShippingCategory, ShippingCategoryCreate, ShippingCategoryUpdate } from './resources/shipping_categories';
97
97
  export type { ShippingMethodTier } from './resources/shipping_method_tiers';
98
98
  export type { ShippingMethod, ShippingMethodCreate, ShippingMethodUpdate } from './resources/shipping_methods';
@@ -104,9 +104,9 @@ export type { SkuList, SkuListCreate, SkuListUpdate } from './resources/sku_list
104
104
  export type { SkuOption, SkuOptionCreate, SkuOptionUpdate } from './resources/sku_options';
105
105
  export type { Sku, SkuCreate, SkuUpdate } from './resources/skus';
106
106
  export type { StockItem, StockItemCreate, StockItemUpdate } from './resources/stock_items';
107
- export type { StockLineItem } from './resources/stock_line_items';
107
+ export type { StockLineItem, StockLineItemCreate, StockLineItemUpdate } from './resources/stock_line_items';
108
108
  export type { StockLocation, StockLocationCreate, StockLocationUpdate } from './resources/stock_locations';
109
- export type { StockReservation } from './resources/stock_reservations';
109
+ export type { StockReservation, StockReservationCreate, StockReservationUpdate } from './resources/stock_reservations';
110
110
  export type { StockTransfer, StockTransferCreate, StockTransferUpdate } from './resources/stock_transfers';
111
111
  export type { StripeGateway, StripeGatewayCreate, StripeGatewayUpdate } from './resources/stripe_gateways';
112
112
  export type { StripePayment, StripePaymentCreate, StripePaymentUpdate } from './resources/stripe_payments';
@@ -15,6 +15,7 @@ interface InventoryModel extends Resource {
15
15
  strategy?: string | null;
16
16
  stock_locations_cutoff?: number | null;
17
17
  stock_reservation_cutoff?: number | null;
18
+ put_stock_transfers_on_hold?: boolean | null;
18
19
  inventory_stock_locations?: InventoryStockLocation[] | null;
19
20
  inventory_return_locations?: InventoryReturnLocation[] | null;
20
21
  attachments?: Attachment[] | null;
@@ -25,12 +26,14 @@ interface InventoryModelCreate extends ResourceCreate {
25
26
  strategy?: string | null;
26
27
  stock_locations_cutoff?: number | null;
27
28
  stock_reservation_cutoff?: number | null;
29
+ put_stock_transfers_on_hold?: boolean | null;
28
30
  }
29
31
  interface InventoryModelUpdate extends ResourceUpdate {
30
32
  name?: string | null;
31
33
  strategy?: string | null;
32
34
  stock_locations_cutoff?: number | null;
33
35
  stock_reservation_cutoff?: number | null;
36
+ put_stock_transfers_on_hold?: boolean | null;
34
37
  }
35
38
  declare class InventoryModels extends ApiResource<InventoryModel> {
36
39
  static readonly TYPE: InventoryModelType;
@@ -18,7 +18,7 @@ type PaymentGatewayRel = ResourceRel & {
18
18
  interface PaymentMethod extends Resource {
19
19
  readonly type: PaymentMethodType;
20
20
  name?: string | null;
21
- payment_source_type: 'adyen_payment' | 'axerve_payment' | 'braintree_payment' | 'checkout_com_payment' | 'credit_card' | 'external_payment' | 'klarna_payment' | 'paypal_payment' | 'satispay_payment' | 'stripe_payment' | 'wire_transfer';
21
+ payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'credit_cards' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
22
22
  currency_code?: string | null;
23
23
  moto?: boolean | null;
24
24
  require_capture?: boolean | null;
@@ -36,7 +36,7 @@ interface PaymentMethod extends Resource {
36
36
  versions?: Version[] | null;
37
37
  }
38
38
  interface PaymentMethodCreate extends ResourceCreate {
39
- payment_source_type: 'adyen_payment' | 'axerve_payment' | 'braintree_payment' | 'checkout_com_payment' | 'credit_card' | 'external_payment' | 'klarna_payment' | 'paypal_payment' | 'satispay_payment' | 'stripe_payment' | 'wire_transfer';
39
+ payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'credit_cards' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
40
40
  currency_code?: string | null;
41
41
  moto?: boolean | null;
42
42
  require_capture?: boolean | null;
@@ -47,7 +47,7 @@ interface PaymentMethodCreate extends ResourceCreate {
47
47
  payment_gateway: PaymentGatewayRel;
48
48
  }
49
49
  interface PaymentMethodUpdate extends ResourceUpdate {
50
- payment_source_type?: 'adyen_payment' | 'axerve_payment' | 'braintree_payment' | 'checkout_com_payment' | 'credit_card' | 'external_payment' | 'klarna_payment' | 'paypal_payment' | 'satispay_payment' | 'stripe_payment' | 'wire_transfer' | null;
50
+ payment_source_type?: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'credit_cards' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers' | null;
51
51
  currency_code?: string | null;
52
52
  moto?: boolean | null;
53
53
  require_capture?: boolean | null;
@@ -13,14 +13,14 @@ type OrderRel = ResourceRel & {
13
13
  interface PaymentOption extends Resource {
14
14
  readonly type: PaymentOptionType;
15
15
  name?: string | null;
16
- payment_source_type: 'adyen_payment' | 'axerve_payment' | 'braintree_payment' | 'checkout_com_payment' | 'credit_card' | 'external_payment' | 'klarna_payment' | 'paypal_payment' | 'satispay_payment' | 'stripe_payment' | 'wire_transfer';
16
+ payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'credit_cards' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
17
17
  data: Record<string, any>;
18
18
  order?: Order | null;
19
19
  attachments?: Attachment[] | null;
20
20
  }
21
21
  interface PaymentOptionCreate extends ResourceCreate {
22
22
  name?: string | null;
23
- payment_source_type: 'adyen_payment' | 'axerve_payment' | 'braintree_payment' | 'checkout_com_payment' | 'credit_card' | 'external_payment' | 'klarna_payment' | 'paypal_payment' | 'satispay_payment' | 'stripe_payment' | 'wire_transfer';
23
+ payment_source_type: 'adyen_payments' | 'axerve_payments' | 'braintree_payments' | 'checkout_com_payments' | 'credit_cards' | 'external_payments' | 'klarna_payments' | 'paypal_payments' | 'satispay_payments' | 'stripe_payments' | 'wire_transfers';
24
24
  data: Record<string, any>;
25
25
  order: OrderRel;
26
26
  }
@@ -1,10 +1,11 @@
1
1
  import { ApiResource } from '../resource';
2
- import type { Resource, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel, ListResponse } from '../resource';
2
+ import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel, ListResponse } from '../resource';
3
3
  import type { QueryParamsRetrieve, QueryParamsList } from '../query';
4
- import type { Order } from './orders';
5
- import type { ShippingCategory } from './shipping_categories';
4
+ import type { Order, OrderType } from './orders';
5
+ import type { ShippingCategory, ShippingCategoryType } from './shipping_categories';
6
+ import type { InventoryStockLocation, InventoryStockLocationType } from './inventory_stock_locations';
6
7
  import type { StockLocation } from './stock_locations';
7
- import type { Address } from './addresses';
8
+ import type { Address, AddressType } from './addresses';
8
9
  import type { ShippingMethod, ShippingMethodType } from './shipping_methods';
9
10
  import type { DeliveryLeadTime } from './delivery_lead_times';
10
11
  import type { StockLineItem } from './stock_line_items';
@@ -18,6 +19,18 @@ type ShipmentType = 'shipments';
18
19
  type ShipmentRel = ResourceRel & {
19
20
  type: ShipmentType;
20
21
  };
22
+ type OrderRel = ResourceRel & {
23
+ type: OrderType;
24
+ };
25
+ type ShippingCategoryRel = ResourceRel & {
26
+ type: ShippingCategoryType;
27
+ };
28
+ type InventoryStockLocationRel = ResourceRel & {
29
+ type: InventoryStockLocationType;
30
+ };
31
+ type AddressRel = ResourceRel & {
32
+ type: AddressType;
33
+ };
21
34
  type ShippingMethodRel = ResourceRel & {
22
35
  type: ShippingMethodType;
23
36
  };
@@ -47,6 +60,7 @@ interface Shipment extends Resource {
47
60
  shipped_at?: string | null;
48
61
  order?: Order | null;
49
62
  shipping_category?: ShippingCategory | null;
63
+ inventory_stock_location?: InventoryStockLocation | null;
50
64
  stock_location?: StockLocation | null;
51
65
  origin_address?: Address | null;
52
66
  shipping_address?: Address | null;
@@ -65,22 +79,38 @@ interface Shipment extends Resource {
65
79
  events?: Event[] | null;
66
80
  versions?: Version[] | null;
67
81
  }
82
+ interface ShipmentCreate extends ResourceCreate {
83
+ order: OrderRel;
84
+ shipping_category?: ShippingCategoryRel | null;
85
+ inventory_stock_location?: InventoryStockLocationRel | null;
86
+ shipping_address?: AddressRel | null;
87
+ shipping_method?: ShippingMethodRel | null;
88
+ }
68
89
  interface ShipmentUpdate extends ResourceUpdate {
69
90
  _on_hold?: boolean | null;
70
91
  _picking?: boolean | null;
71
92
  _packing?: boolean | null;
72
93
  _ready_to_ship?: boolean | null;
73
94
  _ship?: boolean | null;
95
+ _reserve_stock?: boolean | null;
96
+ _release_stock?: boolean | null;
97
+ _decrement_stock?: boolean | null;
74
98
  _get_rates?: boolean | null;
75
99
  selected_rate_id?: string | null;
76
100
  _purchase?: boolean | null;
101
+ shipping_category?: ShippingCategoryRel | null;
102
+ inventory_stock_location?: InventoryStockLocationRel | null;
103
+ shipping_address?: AddressRel | null;
77
104
  shipping_method?: ShippingMethodRel | null;
78
105
  }
79
106
  declare class Shipments extends ApiResource<Shipment> {
80
107
  static readonly TYPE: ShipmentType;
108
+ create(resource: ShipmentCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
81
109
  update(resource: ShipmentUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
110
+ delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
82
111
  order(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Order>;
83
112
  shipping_category(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<ShippingCategory>;
113
+ inventory_stock_location(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<InventoryStockLocation>;
84
114
  stock_location(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockLocation>;
85
115
  origin_address(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Address>;
86
116
  shipping_address(shipmentId: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Address>;
@@ -99,6 +129,9 @@ declare class Shipments extends ApiResource<Shipment> {
99
129
  _packing(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
100
130
  _ready_to_ship(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
101
131
  _ship(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
132
+ _reserve_stock(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
133
+ _release_stock(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
134
+ _decrement_stock(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
102
135
  _get_rates(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
103
136
  _purchase(id: string | Shipment, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
104
137
  isShipment(resource: any): resource is Shipment;
@@ -106,4 +139,4 @@ declare class Shipments extends ApiResource<Shipment> {
106
139
  type(): ShipmentType;
107
140
  }
108
141
  export default Shipments;
109
- export type { Shipment, ShipmentUpdate, ShipmentType };
142
+ export type { Shipment, ShipmentCreate, ShipmentUpdate, ShipmentType };
@@ -1,8 +1,14 @@
1
1
  import { ApiResource } from '../resource';
2
2
  class Shipments extends ApiResource {
3
+ async create(resource, params, options) {
4
+ return this.resources.create({ ...resource, type: Shipments.TYPE }, params, options);
5
+ }
3
6
  async update(resource, params, options) {
4
7
  return this.resources.update({ ...resource, type: Shipments.TYPE }, params, options);
5
8
  }
9
+ async delete(id, options) {
10
+ await this.resources.delete((typeof id === 'string') ? { id, type: Shipments.TYPE } : id, options);
11
+ }
6
12
  async order(shipmentId, params, options) {
7
13
  const _shipmentId = shipmentId.id || shipmentId;
8
14
  return this.resources.fetch({ type: 'orders' }, `shipments/${_shipmentId}/order`, params, options);
@@ -11,6 +17,10 @@ class Shipments extends ApiResource {
11
17
  const _shipmentId = shipmentId.id || shipmentId;
12
18
  return this.resources.fetch({ type: 'shipping_categories' }, `shipments/${_shipmentId}/shipping_category`, params, options);
13
19
  }
20
+ async inventory_stock_location(shipmentId, params, options) {
21
+ const _shipmentId = shipmentId.id || shipmentId;
22
+ return this.resources.fetch({ type: 'inventory_stock_locations' }, `shipments/${_shipmentId}/inventory_stock_location`, params, options);
23
+ }
14
24
  async stock_location(shipmentId, params, options) {
15
25
  const _shipmentId = shipmentId.id || shipmentId;
16
26
  return this.resources.fetch({ type: 'stock_locations' }, `shipments/${_shipmentId}/stock_location`, params, options);
@@ -78,6 +88,15 @@ class Shipments extends ApiResource {
78
88
  async _ship(id, params, options) {
79
89
  return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: Shipments.TYPE, _ship: true }, params, options);
80
90
  }
91
+ async _reserve_stock(id, params, options) {
92
+ return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: Shipments.TYPE, _reserve_stock: true }, params, options);
93
+ }
94
+ async _release_stock(id, params, options) {
95
+ return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: Shipments.TYPE, _release_stock: true }, params, options);
96
+ }
97
+ async _decrement_stock(id, params, options) {
98
+ return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: Shipments.TYPE, _decrement_stock: true }, params, options);
99
+ }
81
100
  async _get_rates(id, params, options) {
82
101
  return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: Shipments.TYPE, _get_rates: true }, params, options);
83
102
  }
@@ -1,19 +1,30 @@
1
1
  import { ApiResource } from '../resource';
2
- import type { Resource, ResourceId, ResourcesConfig, ResourceRel, ListResponse } from '../resource';
2
+ import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel, ListResponse } from '../resource';
3
3
  import type { QueryParamsRetrieve, QueryParamsList } from '../query';
4
- import type { Shipment } from './shipments';
5
- import type { LineItem } from './line_items';
6
- import type { StockItem } from './stock_items';
7
- import type { Sku } from './skus';
4
+ import type { Shipment, ShipmentType } from './shipments';
5
+ import type { LineItem, LineItemType } from './line_items';
6
+ import type { StockItem, StockItemType } from './stock_items';
7
+ import type { Sku, SkuType } from './skus';
8
8
  import type { Version } from './versions';
9
9
  type StockLineItemType = 'stock_line_items';
10
10
  type StockLineItemRel = ResourceRel & {
11
11
  type: StockLineItemType;
12
12
  };
13
+ type ShipmentRel = ResourceRel & {
14
+ type: ShipmentType;
15
+ };
16
+ type LineItemRel = ResourceRel & {
17
+ type: LineItemType;
18
+ };
19
+ type StockItemRel = ResourceRel & {
20
+ type: StockItemType;
21
+ };
22
+ type SkuRel = ResourceRel & {
23
+ type: SkuType;
24
+ };
13
25
  interface StockLineItem extends Resource {
14
26
  readonly type: StockLineItemType;
15
27
  sku_code?: string | null;
16
- bundle_code?: string | null;
17
28
  quantity: number;
18
29
  shipment?: Shipment | null;
19
30
  line_item?: LineItem | null;
@@ -21,8 +32,27 @@ interface StockLineItem extends Resource {
21
32
  sku?: Sku | null;
22
33
  versions?: Version[] | null;
23
34
  }
35
+ interface StockLineItemCreate extends ResourceCreate {
36
+ sku_code?: string | null;
37
+ quantity: number;
38
+ shipment?: ShipmentRel | null;
39
+ line_item?: LineItemRel | null;
40
+ stock_item?: StockItemRel | null;
41
+ sku?: SkuRel | null;
42
+ }
43
+ interface StockLineItemUpdate extends ResourceUpdate {
44
+ sku_code?: string | null;
45
+ quantity?: number | null;
46
+ shipment?: ShipmentRel | null;
47
+ line_item?: LineItemRel | null;
48
+ stock_item?: StockItemRel | null;
49
+ sku?: SkuRel | null;
50
+ }
24
51
  declare class StockLineItems extends ApiResource<StockLineItem> {
25
52
  static readonly TYPE: StockLineItemType;
53
+ create(resource: StockLineItemCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockLineItem>;
54
+ update(resource: StockLineItemUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockLineItem>;
55
+ delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
26
56
  shipment(stockLineItemId: string | StockLineItem, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Shipment>;
27
57
  line_item(stockLineItemId: string | StockLineItem, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<LineItem>;
28
58
  stock_item(stockLineItemId: string | StockLineItem, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockItem>;
@@ -33,4 +63,4 @@ declare class StockLineItems extends ApiResource<StockLineItem> {
33
63
  type(): StockLineItemType;
34
64
  }
35
65
  export default StockLineItems;
36
- export type { StockLineItem, StockLineItemType };
66
+ export type { StockLineItem, StockLineItemCreate, StockLineItemUpdate, StockLineItemType };
@@ -1,5 +1,14 @@
1
1
  import { ApiResource } from '../resource';
2
2
  class StockLineItems extends ApiResource {
3
+ async create(resource, params, options) {
4
+ return this.resources.create({ ...resource, type: StockLineItems.TYPE }, params, options);
5
+ }
6
+ async update(resource, params, options) {
7
+ return this.resources.update({ ...resource, type: StockLineItems.TYPE }, params, options);
8
+ }
9
+ async delete(id, options) {
10
+ await this.resources.delete((typeof id === 'string') ? { id, type: StockLineItems.TYPE } : id, options);
11
+ }
3
12
  async shipment(stockLineItemId, params, options) {
4
13
  const _stockLineItemId = stockLineItemId.id || stockLineItemId;
5
14
  return this.resources.fetch({ type: 'shipments' }, `stock_line_items/${_stockLineItemId}/shipment`, params, options);
@@ -1,15 +1,18 @@
1
1
  import { ApiResource } from '../resource';
2
- import type { Resource, ResourceId, ResourcesConfig, ResourceRel } from '../resource';
2
+ import type { Resource, ResourceCreate, ResourceUpdate, ResourceId, ResourcesConfig, ResourceRel } from '../resource';
3
3
  import type { QueryParamsRetrieve } from '../query';
4
4
  import type { LineItem } from './line_items';
5
5
  import type { Order } from './orders';
6
- import type { StockItem } from './stock_items';
6
+ import type { StockItem, StockItemType } from './stock_items';
7
7
  import type { ReservedStock } from './reserved_stocks';
8
8
  import type { Sku } from './skus';
9
9
  type StockReservationType = 'stock_reservations';
10
10
  type StockReservationRel = ResourceRel & {
11
11
  type: StockReservationType;
12
12
  };
13
+ type StockItemRel = ResourceRel & {
14
+ type: StockItemType;
15
+ };
13
16
  interface StockReservation extends Resource {
14
17
  readonly type: StockReservationType;
15
18
  status: 'draft' | 'pending';
@@ -21,16 +24,29 @@ interface StockReservation extends Resource {
21
24
  reserved_stock?: ReservedStock | null;
22
25
  sku?: Sku | null;
23
26
  }
27
+ interface StockReservationCreate extends ResourceCreate {
28
+ quantity: number;
29
+ stock_item: StockItemRel;
30
+ }
31
+ interface StockReservationUpdate extends ResourceUpdate {
32
+ quantity?: number | null;
33
+ _pending?: boolean | null;
34
+ stock_item?: StockItemRel | null;
35
+ }
24
36
  declare class StockReservations extends ApiResource<StockReservation> {
25
37
  static readonly TYPE: StockReservationType;
38
+ create(resource: StockReservationCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockReservation>;
39
+ update(resource: StockReservationUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockReservation>;
40
+ delete(id: string | ResourceId, options?: ResourcesConfig): Promise<void>;
26
41
  line_item(stockReservationId: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<LineItem>;
27
42
  order(stockReservationId: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Order>;
28
43
  stock_item(stockReservationId: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockItem>;
29
44
  reserved_stock(stockReservationId: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<ReservedStock>;
30
45
  sku(stockReservationId: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Sku>;
46
+ _pending(id: string | StockReservation, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockReservation>;
31
47
  isStockReservation(resource: any): resource is StockReservation;
32
48
  relationship(id: string | ResourceId | null): StockReservationRel;
33
49
  type(): StockReservationType;
34
50
  }
35
51
  export default StockReservations;
36
- export type { StockReservation, StockReservationType };
52
+ export type { StockReservation, StockReservationCreate, StockReservationUpdate, StockReservationType };
@@ -1,5 +1,14 @@
1
1
  import { ApiResource } from '../resource';
2
2
  class StockReservations extends ApiResource {
3
+ async create(resource, params, options) {
4
+ return this.resources.create({ ...resource, type: StockReservations.TYPE }, params, options);
5
+ }
6
+ async update(resource, params, options) {
7
+ return this.resources.update({ ...resource, type: StockReservations.TYPE }, params, options);
8
+ }
9
+ async delete(id, options) {
10
+ await this.resources.delete((typeof id === 'string') ? { id, type: StockReservations.TYPE } : id, options);
11
+ }
3
12
  async line_item(stockReservationId, params, options) {
4
13
  const _stockReservationId = stockReservationId.id || stockReservationId;
5
14
  return this.resources.fetch({ type: 'line_items' }, `stock_reservations/${_stockReservationId}/line_item`, params, options);
@@ -20,6 +29,9 @@ class StockReservations extends ApiResource {
20
29
  const _stockReservationId = stockReservationId.id || stockReservationId;
21
30
  return this.resources.fetch({ type: 'skus' }, `stock_reservations/${_stockReservationId}/sku`, params, options);
22
31
  }
32
+ async _pending(id, params, options) {
33
+ return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: StockReservations.TYPE, _pending: true }, params, options);
34
+ }
23
35
  isStockReservation(resource) {
24
36
  return resource.type && (resource.type === StockReservations.TYPE);
25
37
  }
@@ -26,7 +26,7 @@ type LineItemRel = ResourceRel & {
26
26
  interface StockTransfer extends Resource {
27
27
  readonly type: StockTransferType;
28
28
  sku_code?: string | null;
29
- status: 'draft' | 'upcoming' | 'picking' | 'in_transit' | 'completed' | 'cancelled';
29
+ status: 'draft' | 'upcoming' | 'on_hold' | 'picking' | 'in_transit' | 'completed' | 'cancelled';
30
30
  quantity: number;
31
31
  completed_at?: string | null;
32
32
  cancelled_at?: string | null;
@@ -50,6 +50,7 @@ interface StockTransferCreate extends ResourceCreate {
50
50
  interface StockTransferUpdate extends ResourceUpdate {
51
51
  sku_code?: string | null;
52
52
  _upcoming?: boolean | null;
53
+ _on_hold?: boolean | null;
53
54
  _picking?: boolean | null;
54
55
  _in_transit?: boolean | null;
55
56
  _complete?: boolean | null;
@@ -71,6 +72,7 @@ declare class StockTransfers extends ApiResource<StockTransfer> {
71
72
  events(stockTransferId: string | StockTransfer, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Event>>;
72
73
  versions(stockTransferId: string | StockTransfer, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Version>>;
73
74
  _upcoming(id: string | StockTransfer, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockTransfer>;
75
+ _on_hold(id: string | StockTransfer, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockTransfer>;
74
76
  _picking(id: string | StockTransfer, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockTransfer>;
75
77
  _in_transit(id: string | StockTransfer, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockTransfer>;
76
78
  _complete(id: string | StockTransfer, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<StockTransfer>;
@@ -40,6 +40,9 @@ class StockTransfers extends ApiResource {
40
40
  async _upcoming(id, params, options) {
41
41
  return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: StockTransfers.TYPE, _upcoming: true }, params, options);
42
42
  }
43
+ async _on_hold(id, params, options) {
44
+ return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: StockTransfers.TYPE, _on_hold: true }, params, options);
45
+ }
43
46
  async _picking(id, params, options) {
44
47
  return this.resources.update({ id: (typeof id === 'string') ? id : id.id, type: StockTransfers.TYPE, _picking: true }, params, options);
45
48
  }