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

Major release: 2.0 #6

Merged
merged 53 commits into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d92bedc
Restructure files
nozzlegear Sep 22, 2016
930ee04
Switch to using @types
nozzlegear Oct 27, 2016
5d86951
Add Yarn
nozzlegear Oct 27, 2016
e59f0da
Ignore dist file on compilation
nozzlegear Oct 27, 2016
9fe14d5
Do not check in built files.
nozzlegear Oct 27, 2016
a722b02
Removed gulp, use tsc and mocha-cli instead.
nozzlegear Oct 27, 2016
330f5ea
Do not distribute test files.
nozzlegear Oct 27, 2016
ab65d28
Use node 6.9
nozzlegear Oct 27, 2016
4ba1dfe
Generate declaration files.
nozzlegear Oct 27, 2016
8ecbe38
Update node-fetch and fix usage bugs.
nozzlegear Oct 27, 2016
22e0e6b
Fix formatting
nozzlegear Oct 27, 2016
dbd0cf5
[Travis-CI] Only build master branch
nozzlegear Oct 27, 2016
4f4cc70
Change exports to export default
nozzlegear Oct 27, 2016
1bdcc22
Add address model.
nozzlegear Oct 27, 2016
c8fc8f4
Restructuring interface declarations
nozzlegear Oct 27, 2016
15328e0
Finalized declaration structure.
nozzlegear Oct 28, 2016
3405b43
Add ClientDetails declarations
nozzlegear Oct 28, 2016
740e460
Add discount code declaration.
nozzlegear Oct 28, 2016
1b2c90d
Add payment details declaration
nozzlegear Oct 28, 2016
cd3b7c0
Completed Order declaration
nozzlegear Oct 28, 2016
08829a3
Added Order service
nozzlegear Oct 28, 2016
cfc8ef9
Adding tests for Orders service
nozzlegear Oct 28, 2016
cf1e478
Add typings distribution script
nozzlegear Oct 28, 2016
b45ffbf
Use installed tsc to build project
nozzlegear Oct 30, 2016
3f85699
Don't export Enums, Models and Options
nozzlegear Oct 30, 2016
7fddbf9
Finalized custom typings export
nozzlegear Oct 30, 2016
0576d93
Add fulfillment status declaration
nozzlegear Oct 31, 2016
a83b15d
Add customer declaration
nozzlegear Oct 31, 2016
edb60d5
Add transaction declaration.
nozzlegear Oct 31, 2016
98d3f68
Allow adding transactions to order creation.
nozzlegear Oct 31, 2016
2c37fa2
Create test order object.
nozzlegear Oct 31, 2016
4730ceb
Change 'fields' to a string, not string array.
nozzlegear Nov 1, 2016
4dc5f35
Add test for orders
nozzlegear Nov 1, 2016
edd9405
2.0.1-0
nozzlegear Nov 1, 2016
68a8b24
2.0.0 prerelease
nozzlegear Nov 1, 2016
024f99e
2.0.0-1
nozzlegear Nov 1, 2016
e7e7ea6
2.0.0-2
nozzlegear Nov 1, 2016
bffa465
Bugfix: increase test timeout to 30 seconds.
nozzlegear Nov 1, 2016
8b73b16
Add a .apiRateLimitReached flag
nozzlegear Nov 1, 2016
ef5cfdd
Add scripts for all test types
nozzlegear Nov 1, 2016
dd0b1c5
Added handling for 'oauth code used' errors.
nozzlegear Nov 1, 2016
9486b3a
Update readme
nozzlegear Nov 1, 2016
8ece2eb
Update readme
nozzlegear Nov 1, 2016
3e92475
Finalized the finalization of typings exports 😛
nozzlegear Nov 8, 2016
caeb77e
Bugfix: webhooks.list should use FieldOptions
nozzlegear Nov 8, 2016
081f133
Add readme when publishing to npm
nozzlegear Nov 8, 2016
8202dc9
Allow building 2.0
nozzlegear Nov 14, 2016
07b83fb
Add pauses to tests to help empty the API rate limit bucket
nozzlegear Nov 14, 2016
310268a
Only create one webhook for list and count tests
nozzlegear Nov 14, 2016
568920f
Fix prepublish command to only run when actually publishing
nozzlegear Nov 14, 2016
575523a
Add test script to travis build
nozzlegear Nov 14, 2016
7473f80
Attempt fixing tests
nozzlegear Nov 14, 2016
d9e89b7
Bump to 2.0.0
nozzlegear Nov 14, 2016
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
Prev Previous commit
Next Next commit
Fix formatting
  • Loading branch information
nozzlegear committed Oct 27, 2016
commit 22e0e6b48a5f655a8286d98729a8bfc6bfa3ee07
5 changes: 2 additions & 3 deletions enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

export {AuthScope} from "./auth_scope";
export {WebhookTopic} from "./webhook_topic";
export { AuthScope } from "./auth_scope";
export { WebhookTopic } from "./webhook_topic";
8 changes: 4 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Options from "./options";
import * as Infrastructure from "./infrastructure";

export {
Enums,
Models,
Options,
Enums,
Models,
Options,
Infrastructure,
};

Expand All @@ -30,7 +30,7 @@ export {

// Export auth functions at the top level
export {
authorize,
authorize,
buildAuthorizationUrl,
isAuthenticProxyRequest,
isAuthenticRequest,
Expand Down
73 changes: 30 additions & 43 deletions infrastructure/base_service.ts
Original file line number Diff line number Diff line change
@@ -1,90 +1,77 @@
import uri = require("jsuri");
import fetch from "node-fetch";
import {ShopifyError} from "./shopify_error";

declare var require: any;
import { resolve } from "path";
import { ShopifyError } from "./shopify_error";

//Get package.json from 2-levels up as this file will be in dist/infrastructure.
const version = require("../../package.json").version;
const version = require(resolve(__dirname, "../../package.json")).version;

export class BaseService
{
constructor(private shopDomain: string, private accessToken: string, private resource: string)
{
export class BaseService {
constructor(private shopDomain: string, private accessToken: string, private resource: string) {
//Ensure resource starts with admin/
if (! /^[\/]?admin\//ig.test(resource))
{
if (! /^[\/]?admin\//ig.test(resource)) {
this.resource = "admin/" + resource;
}
}

public static buildDefaultHeaders()
{

public static buildDefaultHeaders() {
const headers = {
"Accept": "application/json",
"User-Agent": `Shopify Prime ${version} (https://github.com/nozzlegear/shopify-prime)`
}

return headers;
}

protected async createRequest<T>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, rootElement?: string, payload?: Object)
{

protected async createRequest<T>(method: "GET" | "POST" | "PUT" | "DELETE", path: string, rootElement?: string, payload?: Object) {
method = method.toUpperCase() as any;

const options = {
headers: BaseService.buildDefaultHeaders(),
method: method,
body: undefined as string,
};

if (this.accessToken)
{

if (this.accessToken) {
options.headers["X-Shopify-Access-Token"] = this.accessToken;
}

const url = new uri(this.shopDomain);
url.protocol("https");

//Ensure no erroneous double slashes in path and that it doesn't end in /.json
url.path(`${this.resource}/${path}`.replace(/\/+/ig, "/").replace(/\/\.json/ig, ".json"));

if ((method === "GET" || method === "DELETE") && payload)
{
for (const prop in payload)
{

if ((method === "GET" || method === "DELETE") && payload) {
for (const prop in payload) {
const value = payload[prop];

//Shopify expects qs array values to be joined by a comma, e.g. fields=field1,field2,field3
url.addQueryParam(prop, Array.isArray(value) ? value.join(",") : value);
}
}
else if (payload)
{
else if (payload) {
options.body = JSON.stringify(payload);

options.headers["Content-Type"] = "application/json";
}

//Fetch will only throw an exception when there is a network-related error, not when Shopify returns a non-200 response.
const result = await fetch(url.toString(), options);
let json = await result.text() as any;

try
{

try {
json = JSON.parse(json);
}
catch (e)
{
catch (e) {
//Set ok to false to throw an error with the body's text.
result.ok = false;
}

if (!result.ok)
{

if (!result.ok) {
throw new ShopifyError(result, json);
}
return rootElement ? json[rootElement] as T : json as T;

return rootElement ? json[rootElement] as T : json as T;
}
}
6 changes: 3 additions & 3 deletions infrastructure/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export {BaseService} from "./base_service";
export {ShopifyError} from "./shopify_error";
export {ShopifyObject} from "./shopify_object";
export { BaseService } from "./base_service";
export { ShopifyError } from "./shopify_error";
export { ShopifyObject } from "./shopify_object";
45 changes: 19 additions & 26 deletions infrastructure/shopify_error.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
import {Response as Response} from "node-fetch";
import { Response as Response } from "node-fetch";

export class ShopifyError extends Error
{
constructor(response: Response, public body: {errors: string | {[index: string] : string | string[]}})
{
export class ShopifyError extends Error {
constructor(response: Response, public body: { errors: string | { [index: string]: string | string[] } }) {
super();

this.statusCode = response.status;
this.statusText = response.statusText;
this.message = `[Shopify Prime] ${this.statusCode} ${this.statusText}. `;

// Errors can be any of the following:
// 1. { errors: "some error message"}
// 2. { errors: { "order" : "some error message" } }
// 3. { errors: { "order" : [ "some error message" ] } }

let errors = body.errors;

if (!errors)
{

if (!errors) {
return;
}

if (typeof errors === "string")
{

if (typeof errors === "string") {
// errors is #1
this.errors["generic"] = [errors];
}
else if (typeof errors === "object")
{
for (const property in errors)
{
else if (typeof errors === "object") {
for (const property in errors) {
const value = errors[property];

this.errors[property] = Array.isArray(value) ? value : [value];
}
}
}

public get isShopifyPrime()
{

public get isShopifyPrime() {
return true;
}

public statusCode: number;

public statusText: string;
public errors: {[index: string]: string[]} = {};

public errors: { [index: string]: string[] } = {};
}
3 changes: 1 addition & 2 deletions infrastructure/shopify_object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface ShopifyObject
{
export interface ShopifyObject {
/**
* The object's id.
*/
Expand Down
16 changes: 8 additions & 8 deletions models/charge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ShopifyObject} from "../infrastructure";
import { ShopifyObject } from "../infrastructure";

/**
* Represents a one-time application charge.
Expand All @@ -8,37 +8,37 @@ export interface Charge extends ShopifyObject {
* The URL that the customer should be sent to, to accept or decline the application charge.
*/
confirmation_url?: string;

/**
* The date and time when the application charge was created.
*/
created_at?: string;

/**
* The name of the application charge, e.g. "Super Expensive One-time Charge".
*/
name: string;

/**
* The price of the application charge. Note: Shopify returns this value as a string.
*/
price: string | number;

/**
* The URL the customer is sent to once they accept/decline a charge.
*/
return_url?: string;

/**
* The status of the charge.
*/
status?: "pending" | "accepted" | "active" | "cancelled" | "declined" | "expired";

/**
* Whether or not the application charge is a test transaction.
*/
test?: boolean;

/**
* The date and time when the recurring application charge was last updated.
*/
Expand Down
12 changes: 6 additions & 6 deletions models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {Shop} from "./shop";
export {Order} from "./order";
export {Charge} from "./charge";
export {Webhook} from "./webhook";
export {ScriptTag} from "./script_tag";
export {UsageCharge} from "./usage_charge";
export { Shop } from "./shop";
export { Order } from "./order";
export { Charge } from "./charge";
export { Webhook } from "./webhook";
export { ScriptTag } from "./script_tag";
export { UsageCharge } from "./usage_charge";
Loading