Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Locations, InventoryLevels, InventoryItems and Fulfillment Support (#25)
Browse files Browse the repository at this point in the history
* Adding fulfillment support

* Removing options references

* Adding casting

* Revert "Adding casting"

This reverts commit d04956c.

* Found serious errors in my previous PR

* add product variants service and export

* Adding proper variant support

* Fixing update

* Adding inventory levels

* Adding locations

* - Updating list options for inventory levels
- Fixing exports
- Updating descriptions for inventory levels

* - Updating location api description
- Adding inventory items service
- Adding proper inventory levels list options

* Remove empty price rules options

* Clean up product options

* Fixing few bugs with inventory items

* Exporting the object property correctly

* Fixing root property for inventory levels

* Making mandatory arguments live outside of the options param

* Fixing fulfillments

* Removed wrong filter options on product variant's count function
  • Loading branch information
jdalrymple authored and nozzlegear committed Jun 11, 2018
1 parent 5adf483 commit ed5ec08
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 70 deletions.
3 changes: 3 additions & 0 deletions models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export * from "./discount";
export * from "./discount_code";
export * from "./fulfillment";
export * from "./gift_card";
export * from "./inventory_item";
export * from "./inventory_level";
export * from "./line_item";
export * from "./line_item_property";
export * from "./location";
export * from "./order";
export * from "./payment_details";
export * from "./price_rule";
Expand Down
23 changes: 23 additions & 0 deletions models/inventory_item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ShopifyObject } from "./base";

export interface InventoryItem extends ShopifyObject {
/*
* The date and time (ISO 8601 format) when the inventory item was created.
*/
created_at?: string;

/*
* The unique SKU (stock keeping unit) of the inventory item.
*/
sku?: string;

/*
* Whether the inventory item is tracked. If true, then inventory quantity changes are tracked by Shopify
*/
tracked?: boolean;

/*
* The date and time (ISO 8601 format) when the inventory item was last modified.
*/
updated_at?: number;
}
18 changes: 18 additions & 0 deletions models/inventory_level.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ShopifyObject } from "./base";

export interface InventoryLevel extends ShopifyObject {
/*
* The unique identifier of the inventory item that the inventory level belongs to
*/
inventory_item_id?: number;

/*
* The unique identifier of the location that the inventory level belongs to. In order to find the ID of the location, use the Location API.
*/
location_id?: number;

/*
* The quantity of inventory items available for sale. Returns null if the inventory item is not tracked.
*/
available?: number;
}
69 changes: 69 additions & 0 deletions models/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ShopifyObject } from './base';

export interface Location extends ShopifyObject {
/**
* The first line of the address.
*/
address1?: string;

/**
* The second line of the address.
*/
address2?: string;

/**
* The city the location is in.
*/
city?: string;

/**
* The country the location is in.
*/
country?: string;

/**
* The two-letter code (ISO 3166-1 alpha-2 format) corresponding to country the location is in.
*/
country_code?: string;

/**
* The date and time (ISO 8601 format) when the location was created.
*/
created_at?: string;

/**
* Whether this is a fulfillment service location. If true, then the location is a fulfillment service location.
* If false, then the location was created by the merchant and isn't tied to a fulfillment service.
*/
legacy?: string;

/**
* The name of the location.
*/
name?: string;

/**
* The phone number of the location. This value can contain special characters like - and +.
*/
phone?: string;

/**
* The province the location is in.
*/
province?: string;

/**
* The two-letter code corresponding to province or state the location is in.
*/
province_code?: string;

/**
* The date and time (ISO 8601 format) when the location was last updated.
*/
updated_at?: string

/**
* The zip or postal code.
*/
zip?: string
}
4 changes: 3 additions & 1 deletion options/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface ProcessedOptions {
processed_at_max?: string;
}

export interface ListOptions {
export interface BasicListOptions {
/**
* The maximum number of objects that should be returned, up to 250. Setting this parameter above 250 will result in an error.
*/
Expand All @@ -51,7 +51,9 @@ export interface ListOptions {
* The page number of the result list to retrieve. Use this in tandem with limit to page through the webhooks in a shop.
*/
page?: number;
}

export interface ListOptions extends BasicListOptions {
/**
* Restricts results to those created after the given id.
*/
Expand Down
18 changes: 0 additions & 18 deletions options/fulfillments.ts

This file was deleted.

4 changes: 2 additions & 2 deletions options/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from "./articles";
export * from "./base";
export * from "./blogs";
export * from "./fulfillments";
export * from "./gift_cards";
export * from "./inventory_items";
export * from "./inventory_levels";
export * from "./orders";
export * from "./price_rules";
export * from "./product_collection";
export * from "./products";
export * from "./redirects";
Expand Down
8 changes: 8 additions & 0 deletions options/inventory_items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BasicListOptions } from "./base";

export interface InventoryItemListOptions extends BasicListOptions {
/**
* Show only certain inventory items, specified by a comma-seperated list of IDs..
*/
ids: string;
}
13 changes: 13 additions & 0 deletions options/inventory_levels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BasicListOptions } from "./base";

export interface InventoryLevelListOptions extends BasicListOptions {
/**
* A comma-separated list of inventory item IDs.
*/
inventory_item_ids?: string;

/**
* A comma-separated list of location IDs.
*/
location_ids?: string;
}
3 changes: 0 additions & 3 deletions options/price_rules.ts

This file was deleted.

21 changes: 2 additions & 19 deletions options/products.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldOptions, ListOptions, PublishedOptions } from './base';
import { FieldOptions, ListOptions, PublishedOptions, DateOptions } from './base';

export interface ProductBaseOptions {

Expand All @@ -18,24 +18,7 @@ export interface ProductBaseOptions {
collection_id?: string;
}

export interface ProductCountOptions extends ProductBaseOptions {

/**
* Show products created after date (format: 2014-04-25T16:15:47-04:00)
*/
created_at_min?: string;

created_at_max?: string;

/**
* Show products last updated after date (format: 2014-04-25T16:15:47-04:00)
*/
updated_at_min?: string;

updated_at_max?: string;
}

export interface ProductListOptions extends ProductCountOptions {
export interface ProductListOptions extends ProductBaseOptions, DateOptions {

/**
* A comma-separated list of product ids
Expand Down
35 changes: 18 additions & 17 deletions services/fulfillments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,53 @@ export class Fulfillments extends BaseService {
* @param fulfillmentId Id of the fulfillment being retrieved.
* @param options Options for filtering the result.
*/
public get(orderId: number, id: number, options?: Options.FieldOptions) {
return this.createRequest<Fulfillment>("GET", this.getPath(orderId, `${id}.json`), "fulfillment", options);
public get(orderId: number, fulfillmentId: number, options?: Options.FieldOptions) {
return this.createRequest<Fulfillment>("GET", this.getPath(orderId, `${fulfillmentId}.json`), "fulfillment", options);
}

/**
* Lists up to 250 fulfillments for the given blog.
* Lists up to 250 fulfillments for the given order.
* @param orderId Id of the blog that the fulfillments belong to.
* @param options Options for filtering the results.
*/
public list(orderId: number, options?: Options.FulfillmentListOptions) {
public list(orderId: number, options?: Options.FieldOptions & Options.DateOptions & Options.ListOptions) {
return this.createRequest<Fulfillment[]>("GET", this.getPath(orderId, ".json"), "fulfillments", options);
}

/**
* Counts the fulfillments on the given blog.
* Counts the fulfillments on the given order.
* @param orderId Id of the blog that the fulfillments belong to.
* @param options Options for filtering the results.
*/
public count(orderId: number, options?: Options.FulfillmentCountOptions) {
public count(orderId: number, options?: Options.DateOptions) {
return this.createRequest<number>("GET", this.getPath(orderId, "count.json"), "count", options);
}

/**
* Opens a fulfillment with the given id.
* @param id The fulfillment's id.
* Opens a fulfillment with the given fulfillmentId.
* @param orderId Id of the blog that the fulfillments belong to.
* @param fulfillmentId The fulfillment's id.
*/
public open(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/open.json`), 'fulfillment');
public open(orderId: number, fulfillmentId: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${fulfillmentId}/open.json`), 'fulfillment');
}

/**
* Cancels a fulfillment with the given id.
* @param id The fulfillment's id.
* Cancels a fulfillment with the given fulfillmentId.
* @param fulfillmentId The fulfillment's id.
* @param options Options for canceling the fulfillment.
*/
public cancel(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/cancel.json`), 'fulfillment');
public cancel(orderId: number, fulfillmentId: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${fulfillmentId}/cancel.json`), 'fulfillment');
}

/**
* Complete a fulfillment with the given id.
* @param id The fulfillment's id.
* @param fulfillmentId The fulfillment's id.
* @param options Options for canceling the fulfillment.
*/
public complete(orderId: number, id: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${id}/complete.json`), 'fulfillment');
public complete(orderId: number, fulfillmentId: number) {
return this.createRequest<Fulfillment>("POST", this.getPath(orderId, `${fulfillmentId}/complete.json`), 'fulfillment');
}
}

Expand Down
3 changes: 3 additions & 0 deletions services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export * from "./custom_collections";
export * from "./discounts";
export * from "./fulfillments";
export * from "./gift_cards";
export * from "./inventory_items";
export * from "./inventory_levels";
export * from "./locations";
export * from "./orders";
export * from "./price_rule_discounts";
export * from "./price_rules";
Expand Down
40 changes: 40 additions & 0 deletions services/inventory_items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as Options from '../options';
import { BaseService } from '../infrastructure';
import { InventoryItem } from '../models';

/**
* A service for manipulating Shopify's InventoryItems API.
*/
export class InventoryItems extends BaseService {
constructor(shopDomain: string, accessToken: string) {
super(shopDomain, accessToken, "inventory_items");
}

/**
* Gets a inventory item with the given id.
* @param id Id of the inventory item being retrieved.
* @param options Options for filtering the result.
*/
public get(id: number, options?: Options.FieldOptions) {
return this.createRequest<Location>("GET", `${id}.json`, "inventory_item", options);
}

/**
* Gets a list of up to 250 of the shop's inventory items.
* @param options Options for filtering the result.
*/
public list(options: Options.InventoryItemListOptions) {
return this.createRequest<InventoryItem[]>("GET", ".json", "inventory_items", options);
}

/**
* Updates an inventory item with the given id.
* @param id The inventory items's id.
* @param inventoryItem The updated inventory item.
*/
public update(id: number, inventoryItem: InventoryItem) {
return this.createRequest<InventoryItem>("PUT", `${id}.json`, "inventory_item", { inventory_item: inventoryItem });
}
}

export default InventoryItems;
Loading

0 comments on commit ed5ec08

Please sign in to comment.