Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/endpoints/mli-locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { buildURL } from '../utils/helpers'
import RequestFactory from '../factories/request'

class InventoryLocationsEndpoint {
constructor(endpoint) {
this.request = new RequestFactory(endpoint)

this.endpoint = 'inventories/locations'
}

All() {
const { filter, limit, offset } = this
return this.request.send(
buildURL(this.endpoint, {
filter,
limit,
offset
}),
'GET'
)
}

Get(locationId) {
return this.request.send(`${this.endpoint}/${locationId}`, 'GET')
}

Create(body) {
return this.request.send(this.endpoint, 'POST', {
type: 'inventory_location',
attributes: body
})
}

Update(locationId, body) {
return this.request.send(`${this.endpoint}/${locationId}`, 'PUT', {
type: 'inventory_location',
attributes: body
})
}

Delete(locationId) {
return this.request.send(`${this.endpoint}/${locationId}`, 'DELETE')
}

Limit(value) {
this.limit = value
return this
}

Offset(value) {
this.offset = value
return this
}
}

export default InventoryLocationsEndpoint
57 changes: 57 additions & 0 deletions src/endpoints/multi-location-inventories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import RequestFactory from '../factories/request'
import { buildURL } from '../utils/helpers'
import InventoryLocationsEndpoint from './mli-locations'

class MultiLocationInventories {
constructor(endpoint) {
const config = { ...endpoint }
config.headers = {
...config.headers,
'ep-inventories-multi-location': true
}
this.request = new RequestFactory(endpoint)

this.Locations = new InventoryLocationsEndpoint(config)

this.endpoint = 'inventories'
}

All() {
const { filter, limit, offset } = this
return this.request.send(
buildURL(this.endpoint, {
filter,
limit,
offset
}),
'GET'
)
}

Get(productId) {
return this.request.send(`${this.endpoint}/${productId}`, 'GET')
}

Create(body) {
return this.request.send(`${this.endpoint}}`, 'POST', {
type: 'stock',
attributes: body
})
}

Delete(productId) {
return this.request.send(`${this.endpoint}/${productId}`, 'DELETE')
}

Limit(value) {
this.limit = value
return this
}

Offset(value) {
this.offset = value
return this
}
}

export default MultiLocationInventories
4 changes: 4 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { SubscriptionDunningRulesEndpoint } from './types/subscription-dunning-r
import { SubscriptionProrationPoliciesEndpoint } from './types/subscription-proration-policies'
import { SubscriptionInvoicesEndpoint } from './types/subscription-invoices'
import { CustomRelationshipsEndpoint } from './types/custom-relationships'
import { MultiLocationInventoriesEndpoint } from './types/multi-location-inventories'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -149,6 +150,8 @@ export * from './types/subscription-proration-policies'
export * from './types/subscription-invoices'
export * from './types/custom-relationships'
export * from './types/pcm-custom-relationship'
export * from './types/mli-locations'
export * from './types/multi-location-inventories'

// UMD
export as namespace elasticpath
Expand Down Expand Up @@ -219,6 +222,7 @@ export class ElasticPath {
SubscriptionProrationPolicies: SubscriptionProrationPoliciesEndpoint
SubscriptionInvoices: SubscriptionInvoicesEndpoint
CustomRelationships: CustomRelationshipsEndpoint
MultiLocationInventories: MultiLocationInventoriesEndpoint

Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
constructor(config: Config)
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import SubscriptionDunningRulesEndpoint from './endpoints/subscription-dunning-r
import SubscriptionProrationPoliciesEndpoint from './endpoints/subscription-proration-policies'
import SubscriptionInvoicesEndpoint from './endpoints/subscription-invoices'
import CustomRelationshipsEndpoint from './endpoints/custom-relationships'
import MultiLocationInventoriesEndpoint from './endpoints/multi-location-inventories'

import {
cartIdentifier,
Expand Down Expand Up @@ -150,6 +151,7 @@ export default class ElasticPath {
new SubscriptionProrationPoliciesEndpoint(config)
this.SubscriptionInvoices = new SubscriptionInvoicesEndpoint(config)
this.CustomRelationships = new CustomRelationshipsEndpoint(config)
this.MultiLocationInventories = new MultiLocationInventoriesEndpoint(config)
}

// Expose `Cart` class on ElasticPath class
Expand Down
83 changes: 83 additions & 0 deletions src/types/mli-locations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Inventory Locations
*/
import { Identifiable, Resource, ResourcePage } from './core'

type InventoryLocationType = 'inventory_location'

export interface GeolocationDetails {
lat: number
lon: number
}
export interface LocationAttributes {
name: string
external_ref?: string
description?: string
address: string[]
geolocation: GeolocationDetails
}
export interface LocationMeta {
timestamps: {
created_at: string
updated_at: string
}
}

/**
* Core Location Base Interface
*/
export interface LocationBase {
type: InventoryLocationType
attributes: LocationAttributes
meta: LocationMeta
}

export interface Location extends Identifiable, LocationBase {}

export interface CreateLocationBody extends LocationAttributes {}

export interface UpdateLocationBody extends Identifiable, LocationAttributes {}

/**
* Location Endpoints
*/
export interface LocationsEndpoint {
endpoint: 'inventory/locations'

/**
* List All Locations
*/
All(): Promise<ResourcePage<Location>>

/**
* Get Location
* @param locationId - The ID of the Location.
*/
Get(locationId: string): Promise<Resource<Location>>

/**
* Create Location
* @param body - The base attributes of the Locations
*/
Create(body: CreateLocationBody): Promise<Resource<Location>>

/**
* Update Location
* @param locationId - The ID of the Location.
* @param body - The base attributes of the Locations.
*/
Update(
locationId: string,
body: UpdateLocationBody
): Promise<Resource<Location>>

/**
* Delete Location
* @param locationId - The ID of the Location.
*/
Delete(locationId: string): Promise<{}>

Limit(value: number): LocationsEndpoint

Offset(value: number): LocationsEndpoint
}
79 changes: 79 additions & 0 deletions src/types/multi-location-inventories.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Multi Location Inventory
*/
import { LocationsEndpoint } from './mli-locations'
import { Identifiable, Resource, ResourcePage } from './core'

type StockType = 'stock'

export interface StockMeta {
timestamps: {
created_at: string
updated_at: string
}
}

export interface StockBaseLocations {
[key: string]: {
available: number
}
}

export interface StockBaseAttributes {
product_id: string
locations: StockBaseLocations
}

export interface StockResponseLocations {
[key: string]: {
available: number
allocated: number
total: number
}
}
export interface StockResponseAttributes extends StockBaseAttributes {
allocated: number
total: number
locations: StockResponseLocations
}

export interface StockResponse extends Identifiable, StockMeta {
type: StockType
attributes: StockResponseAttributes
}

/**
* Multi Location Inventories Endpoints
*/
export interface MultiLocationInventoriesEndpoint {
endpoint: 'inventory'

Locations: LocationsEndpoint

/**
* Get Stock for all Products
*/
All(): Promise<ResourcePage<StockResponse>>

/**
* Get Stock for Product
* @param productId The ID of the product.
*/
Get(productId: string): Promise<Resource<StockResponse>>

/**
* Create Stock for Product
* @param body - The base attributes of the inventory stock.
*/
Create(body: StockBaseAttributes): Promise<Resource<StockResponse>>

/**
* Delete Stock for Product
* @param productId The ID of the product.
*/
Delete(productId: string): Promise<{}>

Limit(value: number): MultiLocationInventoriesEndpoint

Offset(value: number): MultiLocationInventoriesEndpoint
}