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
Finalized the finalization of typings exports 😛
  • Loading branch information
nozzlegear committed Nov 8, 2016
commit 3e92475d9268d6f4f5f8ee8d553196cfba6612be
18 changes: 0 additions & 18 deletions .tasks/add-custom-declarations.js

This file was deleted.

9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ language: node_js
node_js:
- "6.9"

before_install:
- npm install -g yarn --cache-min 999999999

install:
- cd lib && yarn

script:
- cd tests && yarn test

# safelist
branches:
only:
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ import * as Shopify from "shopify-prime";

## Typescript declarations

Using TypeScript? The TypeScript compiler will automatically pull in *most* of the Shopify Prime definitions for you when you install Shopify Prime via NPM. However, you'll also need to add `"node_modules/shopify-prime/typings"` to your tsconfig.json's `"typeRoots"` array to pull in the models, options and enum declarations. Once you've done that, you'll be able to import models from `'shopify-prime/models'`, options from `'shopify-prime/options'`, and enums from `'shopify-prime/enums'`.
Using TypeScript? The TypeScript compiler will automatically pull in Shopify Prime definitions for you when you install Shopify Prime, **as long as you're using TypeScript 2+**. Interfaces and extra types are available under the `Models`, `Enums` and `Options` exports from the main `"shopify-prime"` module.

I'm hoping to improve this one day where you won't have to modify your tsconfig.json, but the current version of the TypeScript compiler is limited in that it doesn't pick up additional custom declarations in an installed package.
```js
import { Shops } from "shopify-prime";

// Typescript interfaces — not real JS objects:
import { Models, Enums, Options } from "shopify-prime";

const shop: Models.Shop = await new Shops(shopDomain, shopAccessToken).get(shopId);
```

Finally, because Shopify Prime uses async/await and promises, you'll need to set your tsconfig.json's target to `"es6"`. While not strictly necessary, Typescript won't know about the `Promise` type and will default all services' return types to `any` if you don't set your target to es6.

Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions lib/.tasks/add-custom-declarations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require("fs");
const glob = require("glob");
const mkdir = require("mkdirp");
const parse = require("path").parse;
const resolve = require("path").resolve;
const root = process.cwd();

const collections = [
{
folder: "enums",
files: glob.sync(resolve(root, "typings/enums/**/*.d.ts")),
exports: [],
},
{
folder: "models",
files: glob.sync(resolve(root, "typings/models/**/*.d.ts")),
exports: [],
},
{
folder: "options",
files: glob.sync(resolve(root, "typings/options/**/*.d.ts")),
exports: [],
}
]
let mainDefinitionText = fs.readFileSync(resolve(root, "dist/index.d.ts")).toString();

collections.forEach((collection, index) => {
const exportName = collection.folder.substring(0, 1).toUpperCase() + collection.folder.substring(1);
const dir = resolve(root, "dist/typings", collection.folder);

mkdir.sync(dir);

collection.files.forEach(file => {
const text = fs.readFileSync(file).toString();
const filename = parse(file).base;

try {
const lines = text.replace(/(\r\n)|\r|\n/g, '\n').split(/\n+/g);

collection.exports.push(...lines.reduce((result, line) => {
const matches = /export +(?:interface|type|class) +(\w*) *(?:{|=|extends|implements)/ig.exec(line);

// When executing a regex, the matches are all array results except for 0.
if (matches && matches.length > 1) {
result.push(`export { ${matches.slice(1).join(", ")} } from "./${filename.split(/\.d\.ts/)[0]}";`);
}

return result;
}, []));
} catch (e) {
console.warn(`Failed to find exports in ${file}`, e);
}

fs.writeFileSync(resolve(root, "dist/typings", collection.folder, filename), text);
});

// Create an index.d.ts file for this collection and write its exports
fs.writeFileSync(resolve(root, "dist/typings", collection.folder, "index.d.ts"), collection.exports.join("\n"));

mainDefinitionText += `import * as ${exportName} from './typings/${collection.folder}';\nexport {${exportName}};\n`;
});

fs.writeFileSync(resolve(root, "dist/index.d.ts"), mainDefinitionText);
File renamed without changes.
File renamed without changes.
21 changes: 4 additions & 17 deletions package.json → lib/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
{
"name": "shopify-prime",
"version": "2.0.0-2",
"version": "2.0.0-3",
"description": "Shopify Prime is a NodeJS library built to help developers easily authenticate and make calls against the Shopify API. It was inspired by and borrows heavily from ShopifySharp.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "node ./node_modules/.bin/tsc -p . && npm run declarations",
"prepublish": "npm run test",
"declarations": "node ./.tasks/add-custom-declarations",
"test": "npm run build && node ./node_modules/.bin/mocha dist/tests",
"test:auth": "node ./node_modules/.bin/mocha dist/tests/authorization.js",
"test:charges": "node ./node_modules/.bin/mocha dist/tests/charges.js",
"test:errors": "node ./node_modules/.bin/mocha dist/tests/shopify_error.js",
"test:orders": "node ./node_modules/.bin/mocha dist/tests/orders.js",
"test:recurring_charges": "node ./node_modules/.bin/mocha dist/tests/recurring_charges.js",
"test:script_tags": "node ./node_modules/.bin/mocha dist/tests/script_tags.js",
"test:shops": "node ./node_modules/.bin/mocha dist/tests/shops.js",
"test:usage_charges": "node ./node_modules/.bin/mocha dist/tests/usage_charges.js",
"test:webhooks": "node ./node_modules/.bin/mocha dist/tests/webhooks.js"
"prepublish": "npm run test",
"test": "cd ../tests && npm run test"
},
"repository": {
"type": "git",
Expand All @@ -41,16 +32,12 @@
"node-fetch": "^1.6.3"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/crypto-js": "^3.1.32",
"@types/jsuri": "^1.3.28",
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.46",
"@types/node-fetch": "^1.6.5",
"chai": "^3.5.0",
"glob": "^7.1.1",
"mkdirp": "^0.5.1",
"mocha": "^2.5.3",
"typescript": "^2.0.6"
"typescript": "2.0.8"
}
}
2 changes: 1 addition & 1 deletion services/auth.ts → lib/services/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uri = require("jsuri");
import fetch from "node-fetch";
import * as crypto from "crypto-js";
import { AuthScope } from "shopify-prime/enums";
import { AuthScope } from "../typings/enums/auth_scope";
import BaseService from "../infrastructure/base_service";

/**
Expand Down
4 changes: 2 additions & 2 deletions services/charges.ts → lib/services/charges.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Charge } from "shopify-prime/models";
import { Charge } from "../typings/models/charge";
import BaseService from "../infrastructure/base_service";
import { FieldOptions, ListOptions, DateOptions } from "shopify-prime/options";
import { FieldOptions, ListOptions, DateOptions } from "../typings/options/base";

/**
* A service for manipulating Shopify's ApplicationCharge API.
Expand Down
8 changes: 6 additions & 2 deletions services/orders.ts → lib/services/orders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Order } from "../typings/models/order";
import BaseService from "../infrastructure/base_service";
import { Order, Transaction } from "shopify-prime/models";
import { OrderCountOptions, OrderListOptions, FieldOptions, OrderCreateOptions } from "shopify-prime/options";
import { Transaction } from "../typings/models/transaction";

// Enums
import { FieldOptions } from "../typings/options/base";
import { OrderCountOptions, OrderListOptions, OrderCreateOptions } from "../typings/options/orders";

export default class Orders extends BaseService {
constructor(shopDomain: string, accessToken: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Charge } from "shopify-prime/models";
import BaseService from "../infrastructure/base_service";
import { FieldOptions, ListOptions, DateOptions } from "shopify-prime/options";
import { RecurringCharge } from "../typings/models/recurring_charge";
import { FieldOptions, ListOptions, DateOptions } from "../typings/options/base";

/**
* A service for manipulating Shopify's RecurringCharge API.
Expand Down Expand Up @@ -49,44 +49,4 @@ export default class RecurringCharges extends BaseService {
public delete(id: number): Promise<void> {
return this.createRequest<void>("DELETE", `${id}.json`);
}
}

/**
* Represents a recurring (e.g. monthly subscription) application charge.
*/
export interface RecurringCharge extends Charge {
/**
* The date and time the customer activated the charge. Will be null if the charge has not been activated.
*/
activated_on?: string;

/**
* The date and time the customer will be billed. Will be null if the charge has not been activated.
*/
billing_on?: string;

/**
* The date and time the customer cancelled their recurring charge. Will be null if the charge has not been cancelled.
*/
cancelled_on?: string;

/**
* The capped amount is the limit a customer can be charged for usage based billing.
*/
capped_amount?: number;

/**
* tates the terms and conditions of usage based billing charges. Must be present in order to create usage charges. These are presented to the merchant when they approve the usage charges for your app.
*/
terms?: string;

/**
* Number of days the customer is eligible for a free trial.
*/
trial_days: number;

/**
* The date and time the customer's free trial ends. Will be null if the charge has not been activated.
*/
trial_ends_on?: string;
}
7 changes: 5 additions & 2 deletions services/script_tags.ts → lib/services/script_tags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { ScriptTag } from "shopify-prime/models";
import { ScriptTag } from "../typings/models/script_tag";
import BaseService from "../infrastructure/base_service";
import { FieldOptions, ListOptions, DateOptions, ScriptTagOptions } from "shopify-prime/options";

// Enums
import { ScriptTagOptions } from "../typings/options/script_tags";
import { FieldOptions, ListOptions, DateOptions } from "../typings/options/base";

/**
* A service for manipulating Shopify script tags.
Expand Down
4 changes: 2 additions & 2 deletions services/shops.ts → lib/services/shops.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Shop } from "shopify-prime/models";
import { Shop } from "../typings/models/shop";
import BaseService from "../infrastructure/base_service";
import { FieldOptions, ListOptions } from "shopify-prime/options";
import { FieldOptions, ListOptions } from "../typings/options/base";

/**
* A service for manipulating Shopify shops.
Expand Down
4 changes: 2 additions & 2 deletions services/usage_charges.ts → lib/services/usage_charges.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UsageCharge } from "shopify-prime/models";
import { FieldOptions } from "shopify-prime/options";
import { FieldOptions } from "../typings/options/base";
import BaseService from "../infrastructure/base_service";
import { UsageCharge } from "../typings/models/usage_charge";

/**
* A service for manipulating Shopify's UsageCharges API.
Expand Down
7 changes: 5 additions & 2 deletions services/webhooks.ts → lib/services/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Webhook } from "shopify-prime/models";
import { Webhook } from "../typings/models/webhook";
import BaseService from "../infrastructure/base_service";
import { FieldOptions, ListOptions, DateOptions, WebhookOptions } from "shopify-prime/options";

// Enums
import { WebhookOptions } from "../typings/options/webhooks";
import { FieldOptions, ListOptions, DateOptions } from "../typings/options/base";

/**
* A service for manipulating Shopify webhooks.
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions lib/typings/enums/auth_scope.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type AuthScope = (
"read_content" |
"write_content" |
"read_themes" |
"write_themes" |
"read_products" |
"write_products" |
"read_customers" |
"write_customers" |
"read_orders" |
"write_orders" |
"read_script_tags" |
"write_script_tags" |
"read_fulfillments" |
"write_fulfillments" |
"read_shipping" |
"write_shipping" |
"read_analytics" |
"read_users" |
"write_users" |
string
);
12 changes: 12 additions & 0 deletions lib/typings/enums/financial_status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type FinancialStatus = (
"authorized" |
"pending" |
"paid" |
"partially_paid" |
"refunded" |
"voided" |
"partially_refunded" |
"unpaid" |
"any" |
string
);
7 changes: 7 additions & 0 deletions lib/typings/enums/fulfillment_status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type FulfillmentStatus = (
"shipped" |
"partial" |
"unshipped" |
"any" |
string
);
6 changes: 6 additions & 0 deletions lib/typings/enums/inventory_behavior.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type InventoryBehavior = (
"bypass" |
"decrement_ignoring_policy" |
"decrement_obeying_policy" |
string
);
7 changes: 7 additions & 0 deletions lib/typings/enums/order_status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type OrderStatus = (
"open" |
"closed" |
"cancelled" |
"any" |
string
);
8 changes: 8 additions & 0 deletions lib/typings/enums/transaction_kind.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type TransactionKind = (
"authorization" |
"capture" |
"sale" |
"void" |
"refund" |
string
);
7 changes: 7 additions & 0 deletions lib/typings/enums/transaction_status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type TransactionStatus = (
"pending" |
"failure" |
"success" |
"error" |
string
)
Loading