├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── dist └── index.js ├── package-lock.json ├── package.json ├── src ├── index.js ├── order.js ├── product.js └── webhook.js ├── webpack.config.js ├── webpack.development.js └── webpack.production.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "targets": { 7 | "esmodules": true 8 | } 9 | } 10 | ] 11 | ] 12 | 13 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | .vscode 3 | *.rar 4 | *.zip 5 | .svn/* 6 | obj/* 7 | *.bak 8 | config.js 9 | test.js 10 | .log 11 | note.txt 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Nasa Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Printify API 4 | 5 | Printify's REST API allows your application to manage a Printify shop on behalf of a Printify Merchant. Create products, submit orders, and more... 6 | 7 | ### API Usage Guidelines 8 | 9 | [developers.printify.com](https://developers.printify.com) 10 | 11 | ### If you don't know Node.js 12 | 13 | [Node.js Tutorial for Beginners in 2020](https://morioh.com/p/0907cef2141c) 14 | 15 | [How To Build a Blog with Nest.js, MongoDB, and Vue.js](https://morioh.com/p/74ffc8a798bb) 16 | 17 | [Machine Learning In Node.js With TensorFlow.js](https://morioh.com/p/a517bc403340) 18 | 19 | ### Install 20 | 21 | ```js 22 | npm i printify-api --save 23 | ``` 24 | 25 | ### Example 26 | 27 | ```js 28 | 29 | var Printify = require('printify-api'); 30 | 31 | var API = new Printify({ 32 | shop_id: 123456, // global query by shop_id, if not set you must set each function 33 | access_token:'xxxxxxxxxxxxxxxxxxxxxxxxxx' 34 | }); 35 | 36 | ``` 37 | 38 | ```js 39 | 40 | // Retrieve a list of all products 41 | API.Product.fetch().then(data =>{ 42 | console.log(data); 43 | }); 44 | 45 | // support async 46 | var result = await API.Product.fetch(); 47 | 48 | // or custom shop_id 49 | var result = await API.Product.fetch(shop_id); 50 | 51 | 52 | ``` 53 | 54 | ```js 55 | 56 | // Retrieve a product 57 | var result = await API.Product.info(product_id); 58 | 59 | // or custom shop_id 60 | var result = await API.Product.info(product_id, shop_id); 61 | 62 | ``` 63 | 64 | ```js 65 | // Create a new product 66 | var data = { 67 | "title": "Product", 68 | "description": "Good product", 69 | "blueprint_id": 384, 70 | "print_provider_id": 1, 71 | "variants": [ 72 | { 73 | "id": 45740, 74 | "price": 400 75 | }, 76 | { 77 | "id": 45742, 78 | "price": 400 79 | }, 80 | { 81 | "id": 45744, 82 | "price": 400 83 | }, 84 | { 85 | "id": 45746 , 86 | "price": 400 87 | } 88 | ], 89 | "print_areas": [ 90 | { 91 | "variant_ids": [45740,45742,45744,45746], 92 | "placeholders": [ 93 | { 94 | "position": "front", 95 | "images": [ 96 | { 97 | "id": "5d15ca551163cde90d7b2203", 98 | "x": 0.5, 99 | "y": 0.5, 100 | "scale": 1, 101 | "angle": 0 102 | } 103 | ] 104 | } 105 | ] 106 | } 107 | ], 108 | }; 109 | 110 | var result = API.Product.create(data); 111 | 112 | // or 113 | var result = API.Product.create(data, shop_id); 114 | 115 | ``` 116 | 117 | ```js 118 | // Update a product 119 | var data = { 120 | id: 1234, 121 | title:'Product 1' 122 | }; 123 | 124 | var result = await API.Product.update(data); 125 | 126 | // or 127 | var result = await API.Product.update(data, shop_id); 128 | 129 | ``` 130 | 131 | ```js 132 | // Delete a product 133 | var result = await API.Product.delete(1234); 134 | 135 | ``` 136 | 137 | ```js 138 | // Publish a product 139 | var result = await API.Product.publish(1234); 140 | 141 | // Notify that a product was successfully published 142 | var result = await API.Product.publish(1234, 'success'); 143 | 144 | // Notify that a product publishing has failed 145 | var result = await API.Product.publish(1234, 'error'); 146 | 147 | ``` 148 | 149 | ```js 150 | // Retrieve a list of orders 151 | var result = await API.Order.fetch(); 152 | 153 | // or custom shop_id 154 | var result = await API.Order.fetch(shop_id); 155 | 156 | ``` 157 | 158 | ```js 159 | // Get order details by id 160 | var result = await API.Order.info(order_id); 161 | 162 | // or custom shop_id 163 | var result = await API.Order.fetch(order_id, shop_id); 164 | 165 | ``` 166 | 167 | ```js 168 | // Submit an order 169 | 170 | var data = { 171 | "external_id": "2750e210-39bb-11e9-a503-452618153e4a", 172 | "line_items": [ 173 | { 174 | "product_id": "5bfd0b66a342bcc9b5563216", 175 | "variant_id": 17887, 176 | "quantity": 1 177 | } 178 | ], 179 | "shipping_method": 1, 180 | "send_shipping_notification": false, 181 | "address_to": { 182 | "first_name": "John", 183 | "last_name": "Smith", 184 | "email": "example@msn.com", 185 | "phone": "0574 69 21 90", 186 | "country": "BE", 187 | "region": "", 188 | "address1": "ExampleBaan 121", 189 | "address2": "45", 190 | "city": "Retie", 191 | "zip": "2470" 192 | } 193 | }; 194 | 195 | var result = await API.Order.create(data); 196 | 197 | // or custom shop_id 198 | var result = await API.Order.create(data, shop_id); 199 | 200 | ``` 201 | 202 | ```js 203 | // Send an existing order to production 204 | var result = await API.Order.publish(order_id); 205 | 206 | // or custom shop_id 207 | var result = await API.Order.publish(order_id, shop_id); 208 | 209 | ``` 210 | ```js 211 | // Calculate the shipping cost of an order 212 | 213 | var order = { 214 | "line_items": [{ 215 | "product_id": "5bfd0b66a342bcc9b5563216", 216 | "variant_id": 17887, 217 | "quantity": 1 218 | },{ 219 | "print_provider_id": 5, 220 | "blueprint_id": 9, 221 | "variant_id": 17887, 222 | "quantity": 1 223 | },{ 224 | "sku": "MY-SKU", 225 | "quantity": 1 226 | }], 227 | "address_to": { 228 | "first_name": "John", // not required 229 | "last_name": "Smith", // not required 230 | "email": "example@msn.com", // not required 231 | "phone": "0574 69 21 90", // not required 232 | "country": "BE", 233 | "region": "", 234 | "address1": "ExampleBaan 121", 235 | "address2": "45", 236 | "city": "Retie", 237 | "zip": "2470" 238 | } 239 | }; 240 | 241 | var result = await API.Order.shipping_cost(order); 242 | 243 | // or custom shop_id 244 | var result = await API.Order.shipping_cost(order, shop_id); 245 | 246 | ``` 247 | 248 | ```js 249 | // Retrieve a list of webhooks 250 | var result = await API.Webhook.fetch(); 251 | 252 | // or custom shop_id 253 | var result = await API.Webhook.fetch(shop_id); 254 | 255 | ``` 256 | 257 | 258 | ```js 259 | // Retrieve a webhook 260 | var result = await API.Webhook.info(webhook_id); 261 | 262 | // or custom shop_id 263 | var result = await API.Webhook.info(webhook_id, shop_id); 264 | 265 | ``` 266 | 267 | 268 | ```js 269 | // Create a new webhook 270 | var data = { 271 | "topic": "order:created", 272 | "url": "https://morioh.com/webhooks/order/created" 273 | } 274 | 275 | var result = await API.Webhook.create(data); 276 | 277 | // or custom shop_id 278 | var result = await API.Webhook.create(data, shop_id); 279 | 280 | ``` 281 | 282 | ```js 283 | // Modify a webhook 284 | var data = { 285 | id: 12345, 286 | "url": "https://othersite.com/callback/order/created" 287 | }; 288 | var result = await API.Webhook.update(data); 289 | 290 | // or custom shop_id 291 | var result = await API.Webhook.update(data, shop_id); 292 | 293 | ``` 294 | 295 | 296 | ```js 297 | // Events, no test 298 | // The product was deleted. 299 | API.on('product:deleted', function(err, res){ 300 | console.log(res); 301 | }); 302 | 303 | // The product publishing was started. 304 | API.on('product:publish:started', function(err, res){ 305 | console.log(res); 306 | }); 307 | 308 | // The product published successfully. 309 | API.on('product:publish:succeeded', function(err, res){ 310 | console.log(res); 311 | }); 312 | 313 | // The product publishing has failed. 314 | API.on('product:publish:failed', function(err, res){ 315 | console.log(res); 316 | }); 317 | 318 | // The order was created. 319 | API.on('order:created', function(err, res){ 320 | console.log(res); 321 | }); 322 | 323 | // The order was updated. 324 | API.on('order:updated', function(err, res){ 325 | console.log(res); 326 | }); 327 | 328 | // The order was sent to production. 329 | API.on('order:sent-to-production', function(err, res){ 330 | console.log(res); 331 | }); 332 | 333 | // Some/all items have been fulfilled. 334 | API.on('order:shipment:created', function(err, res){ 335 | console.log(res); 336 | }); 337 | 338 | // Some/all items have been delivered 339 | API.on('order:shipment:delivered', function(err, res){ 340 | console.log(res); 341 | }); 342 | 343 | // see more: https://developers.printify.com/#events 344 | 345 | ``` 346 | 347 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | module.exports=function(t){var o={};function s(n){if(o[n])return o[n].exports;var i=o[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=t,s.c=o,s.d=function(t,o,n){s.o(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:n})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,o){if(1&o&&(t=s(t)),8&o)return t;if(4&o&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&o&&"string"!=typeof t)for(var i in t)s.d(n,i,function(o){return t[o]}.bind(null,i));return n},s.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(o,"a",o),o},s.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},s.p="",s(s.s=0)}([function(t,o,s){"use strict";var n=s(1),i=s(2),e=s(3).EventEmitter,r=s(4),c=s(5),u=s(6);function a(t){e.call(this),this.opts=Object.assign({version:"v1",access_token:"",shop_id:""},t||{}),this.baseURL=["https://api.printify.com",this.opts.version].join("/"),this.axios=i.create({baseURL:this.baseURL,headers:{Authorization:"Bearer "+this.opts.access_token}}),this.axios.interceptors.response.use((function(t){return t&&t.data?t.data:null}),(function(t){return console.log(n.inspect(t)),Promise.reject(t&&t.response?t.response.data:t)})),this.Product=new r(this.axios,this.opts.shop_id),this.Order=new u(this.axios,this.opts.shop_id),this.Webhook=new c(this.axios,this.opts.shop_id)}a.prototype={shops:function(){return this.axios.get("shops.json")},catalogues:function(){return this.axios.get("catalog/blueprints.json")},catalog:function(t){return this.axios.get("catalog/blueprints/".concat(t,".json"))},providers:function(t){return t?this.axios.get("catalog/blueprints/".concat(t,"/print_providers.json")):this.axios.get("catalog/print_providers.json")},provider:function(t){return this.axios.get("catalog/print_providers/".concat(t,".json"))},variants:function(t,o){return this.axios.get("catalog/blueprints/".concat(t,"/print_providers/").concat(o,"/variants.json"))},shipping:function(t,o){return this.axios.get("catalog/blueprints/".concat(t,"/print_providers/").concat(o,"/shipping.json"))},upload:function(t){return this.axios.post("uploads/images.json",t)}},n.inherits(a,e),t.exports=a},function(t,o){t.exports=require("util")},function(t,o){t.exports=require("axios")},function(t,o){t.exports=require("events")},function(t,o){var s=function(t,o){this.axios=t,this.shop_id=o};s.prototype={id:function(t){return t||this.shop_id},fetch:function(t,o){return o=this.id(o),this.axios.get("shops/".concat(o,"/products.json"),t)},lists:function(t,o){return this.fetch(t,o)},info:function(t,o){return o=this.id(o),this.axios.get("shops/".concat(o,"/products/").concat(t,".json"))},create:function(t,o){return o=this.id(o),this.axios.post("shops/".concat(o,"/products.json"),t)},update:function(t,o){o=this.id(o);var s=t.id;return this.axios.put("shops/".concat(o,"/products/").concat(s,".json"))},delete:function(t,o){return o=this.id(o),this.axios.delete("shops/".concat(o,"/products/").concat(t,".json"),data)},publish:function(t,o,s){switch(s=this.id(s),o){case"success":return this.axios.post("shops/".concat(s,"/products/").concat(t,"/publishing_succeeded.json"));case"error":return this.axios.post("shops/".concat(s,"/products/").concat(t,"/publishing_failed.json"));default:return this.axios.post("shops/".concat(s,"/products/").concat(t,"/publish.json"))}}},t.exports=s},function(t,o){var s=function(t,o){this.axios=t,this.shop_id=o};s.prototype={id:function(t){return t||this.shop_id},fetch:function(t){return t=this.id(t),this.axios.get("shops/".concat(t,"/webhooks.json"))},lists:function(t){return this.fetch(t)},info:function(t,o){return o=this.id(o),this.axios.get("shops/".concat(o,"/webhooks/").concat(t,".json"))},create:function(t,o){return o=this.id(o),this.axios.post("shops/".concat(o,"/webhooks.json"),t)},update:function(t,o){o=this.id(o);var s=t.id;return this.axios.post("shops/".concat(o,"/webhooks/").concat(s,".json"),t)},delete:function(t,o){return o=this.id(o),this.axios.delete("shops/".concat(o,"/webhooks/").concat(t,".json"))}},t.exports=s},function(t,o){var s=function(t,o){this.axios=t,this.shop_id=o};s.prototype={id:function(t){return t||this.shop_id},fetch:function(t){return t=this.id(t),this.axios.get("shops/".concat(t,"/orders.json"))},lists:function(t){return this.fetch(t)},info:function(t,o){return o=this.id(o),this.axios.get("shops/".concat(o,"/orders/").concat(t,".json"))},create:function(t,o){return o=this.id(o),this.axios.post("shops/".concat(o,"/orders.json"),t)},send_to_production:function(t,o){return o=this.id(o),this.axios.post("shops/".concat(o,"/orders/").concat(t,"/send_to_production.json"))},publish:function(t,o){return this.send_to_production(t,o)},shipping_cost:function(t,o){return o=this.id(o),this.axios.post("shops/".concat(o,"/orders/shipping.json"),t)}},t.exports=s}]); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "printify-api", 3 | "version": "0.1.2", 4 | "description": "Printify's REST API allows your application to manage a Printify shop on behalf of a Printify Merchant. Create products, submit orders, and more...", 5 | "main": "dist/index.js", 6 | "author": "Nasa8x", 7 | "license": "MIT", 8 | "dependencies": { 9 | "axios": "^0.19.0" 10 | }, 11 | "scripts": { 12 | "dev": "cross-env NODE_ENV=development webpack --progress --watch --colors", 13 | "prod": "cross-env NODE_ENV=production webpack -p --progress --colors", 14 | "test": "node ./test.js" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/nasa8x/printify-api.git" 19 | }, 20 | "bugs": { 21 | "url": "https://github.com/nasa8x/printify-api/issues" 22 | }, 23 | "homepage": "https://github.com/nasa8x/printify-api", 24 | "keywords": [ 25 | "printify", 26 | "printify api", 27 | "printify client", 28 | "printify rest api" 29 | ], 30 | "devDependencies": { 31 | "@babel/core": "^7.6.2", 32 | "@babel/preset-env": "^7.6.2", 33 | "babel-loader": "^8.0.6", 34 | "clean-webpack-plugin": "^3.0.0", 35 | "cross-env": "^6.0.0", 36 | "webpack": "^4.39.3", 37 | "webpack-cli": "^3.3.8", 38 | "webpack-node-externals": "^1.6.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // Invoke 'strict' JavaScript mode 2 | 'use strict'; 3 | var util = require('util'), 4 | axios = require('axios'), 5 | EventEmitter = require('events').EventEmitter, 6 | Product = require('./product'), 7 | Webhook = require('./webhook'), 8 | Order = require('./order'); 9 | 10 | 11 | function Printify(option) { 12 | EventEmitter.call(this); 13 | this.opts = Object.assign({ version: 'v1', access_token: '', shop_id: '' }, option || {}); 14 | this.baseURL = ['https://api.printify.com', this.opts.version].join('/'); 15 | 16 | this.axios = axios.create({ 17 | baseURL: this.baseURL, 18 | headers: { 'Authorization': 'Bearer ' + this.opts.access_token } 19 | }); 20 | 21 | this.axios.interceptors.response.use(function (response) { 22 | // Do something with response data 23 | //console.log(response); 24 | return response && response.data ? response.data : null; 25 | }, function (error) { 26 | // Do something with response error 27 | console.log(util.inspect(error)); 28 | return Promise.reject(error && error.response ? error.response.data : error); 29 | }); 30 | 31 | this.Product = new Product(this.axios, this.opts.shop_id); 32 | this.Order = new Order(this.axios, this.opts.shop_id); 33 | this.Webhook = new Webhook(this.axios, this.opts.shop_id); 34 | 35 | } 36 | 37 | Printify.prototype = { 38 | 39 | shops: function () { 40 | return this.axios.get('shops.json'); 41 | }, 42 | // Retrieve a list of all available blueprints 43 | catalogues: function () { 44 | return this.axios.get('catalog/blueprints.json'); 45 | }, 46 | // Retrieve a specific blueprint 47 | catalog: function (id) { 48 | return this.axios.get(`catalog/blueprints/${id}.json`); 49 | }, 50 | 51 | // Retrieve a list of all print providers that fulfill orders for a specific blueprint 52 | // if id is undefined Retrieve a list of all available print-providers 53 | providers: function (id) { 54 | return id ? this.axios.get(`catalog/blueprints/${id}/print_providers.json`) : this.axios.get('catalog/print_providers.json'); 55 | }, 56 | // Retrieve a specific print-provider and a list of associated blueprint offerings 57 | provider: function (id) { 58 | return this.axios.get(`catalog/print_providers/${id}.json`); 59 | }, 60 | 61 | // Retrieve a list of all variants of a blueprint from a specific print provider 62 | variants: function (cid, pid) { 63 | return this.axios.get(`catalog/blueprints/${cid}/print_providers/${pid}/variants.json`); 64 | }, 65 | 66 | // Retrieve the shipping information for all variants of a blueprint from a specific print provider 67 | shipping: function (cid, pid) { 68 | return this.axios.get(`catalog/blueprints/${cid}/print_providers/${pid}/shipping.json`); 69 | }, 70 | 71 | // Upload artwork to a Printify account's media library 72 | upload: function (data) { 73 | return this.axios.post('uploads/images.json', data); 74 | } 75 | 76 | }; 77 | 78 | util.inherits(Printify, EventEmitter); 79 | 80 | module.exports = Printify; -------------------------------------------------------------------------------- /src/order.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var Order = function (axios, shop_id) { 4 | this.axios = axios; 5 | this.shop_id = shop_id; 6 | }; 7 | 8 | Order.prototype = { 9 | id: function (id) { 10 | return id ? id : this.shop_id; 11 | }, 12 | // Retrieve a list of orders 13 | fetch: function (shop_id) { 14 | shop_id = this.id(shop_id); 15 | return this.axios.get(`shops/${shop_id}/orders.json`); 16 | }, 17 | 18 | lists: function (shop_id) { 19 | return this.fetch(shop_id); 20 | }, 21 | 22 | // Get order details by id 23 | info: function (id, shop_id) { 24 | shop_id = this.id(shop_id); 25 | return this.axios.get(`shops/${shop_id}/orders/${id}.json`); 26 | }, 27 | 28 | // Submit an order 29 | create: function (data, shop_id) { 30 | shop_id = this.id(shop_id); 31 | return this.axios.post(`shops/${shop_id}/orders.json`, data); 32 | }, 33 | 34 | // Send an existing order to production 35 | send_to_production: function (id, shop_id) { 36 | shop_id = this.id(shop_id); 37 | return this.axios.post(`shops/${shop_id}/orders/${id}/send_to_production.json`); 38 | }, 39 | 40 | publish: function(id, shop_id){ 41 | return this.send_to_production(id, shop_id); 42 | }, 43 | 44 | // Calculate the shipping cost of an order 45 | shipping_cost: function (order, shop_id) { 46 | shop_id = this.id(shop_id); 47 | return this.axios.post(`shops/${shop_id}/orders/shipping.json`, order); 48 | } 49 | } 50 | 51 | module.exports = Order; -------------------------------------------------------------------------------- /src/product.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var Product = function (axios, shop_id) { 4 | this.axios = axios; 5 | this.shop_id = shop_id; 6 | } 7 | 8 | Product.prototype = { 9 | 10 | id: function (id) { 11 | return id ? id : this.shop_id; 12 | }, 13 | // Retrieve a list of all products 14 | fetch: function (payload, shop_id) { 15 | shop_id = this.id(shop_id); 16 | return this.axios.get(`shops/${shop_id}/products.json`, payload); 17 | }, 18 | 19 | lists: function (payload, shop_id) { 20 | return this.fetch(payload, shop_id); 21 | }, 22 | 23 | // Retrieve a product 24 | info: function (id, shop_id) { 25 | shop_id = this.id(shop_id); 26 | return this.axios.get(`shops/${shop_id}/products/${id}.json`); 27 | }, 28 | 29 | // Create a new product 30 | create: function (data, shop_id) { 31 | shop_id = this.id(shop_id); 32 | return this.axios.post(`shops/${shop_id}/products.json`, data); 33 | }, 34 | 35 | // Update a product 36 | update: function (data, shop_id) { 37 | shop_id = this.id(shop_id); 38 | var id = data.id; 39 | return this.axios.put(`shops/${shop_id}/products/${id}.json`); 40 | }, 41 | 42 | // Delete a product 43 | delete: function (id, shop_id) { 44 | shop_id = this.id(shop_id); 45 | return this.axios.delete(`shops/${shop_id}/products/${id}.json`, data); 46 | }, 47 | // Publish a product 48 | publish: function (id, notify, shop_id) { 49 | shop_id = this.id(shop_id); 50 | switch (notify) { 51 | case "success": 52 | return this.axios.post(`shops/${shop_id}/products/${id}/publishing_succeeded.json`); 53 | break; 54 | 55 | case "error": 56 | return this.axios.post(`shops/${shop_id}/products/${id}/publishing_failed.json`); 57 | break; 58 | 59 | default: 60 | return this.axios.post(`shops/${shop_id}/products/${id}/publish.json`); 61 | break; 62 | } 63 | 64 | } 65 | } 66 | 67 | module.exports = Product; -------------------------------------------------------------------------------- /src/webhook.js: -------------------------------------------------------------------------------- 1 | 2 | var Webhook = function (axios, shop_id) { 3 | this.axios = axios; 4 | this.shop_id = shop_id; 5 | } 6 | 7 | Webhook.prototype = { 8 | 9 | id: function (id) { 10 | return id ? id : this.shop_id; 11 | }, 12 | 13 | // Retrieve a list of webhooks 14 | fetch: function (shop_id) { 15 | shop_id = this.id(shop_id); 16 | return this.axios.get(`shops/${shop_id}/webhooks.json`); 17 | }, 18 | 19 | lists: function (shop_id) { 20 | return this.fetch(shop_id); 21 | }, 22 | 23 | // Retrieve a webhook 24 | info: function (id, shop_id) { 25 | shop_id = this.id(shop_id); 26 | return this.axios.get(`shops/${shop_id}/webhooks/${id}.json`); 27 | }, 28 | 29 | // Create a new webhook 30 | create: function (data, shop_id) { 31 | shop_id = this.id(shop_id); 32 | return this.axios.post(`shops/${shop_id}/webhooks.json`, data); 33 | }, 34 | 35 | // Modify a webhook 36 | update: function (data, shop_id) { 37 | shop_id = this.id(shop_id); 38 | var id = data.id; 39 | return this.axios.post(`shops/${shop_id}/webhooks/${id}.json`, data); 40 | 41 | }, 42 | 43 | // Delete a webhook 44 | delete: function (id, shop_id) { 45 | shop_id = this.id(shop_id); 46 | return this.axios.delete(`shops/${shop_id}/webhooks/${id}.json`); 47 | }, 48 | 49 | 50 | 51 | } 52 | 53 | module.exports = Webhook; -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./webpack.' + process.env.NODE_ENV + '.js')(); -------------------------------------------------------------------------------- /webpack.development.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | var nodeExternals = require('webpack-node-externals'); 4 | 5 | module.exports = function (env) { 6 | return [ 7 | 8 | 9 | ///---------------------------- 10 | { 11 | 12 | mode: 'development', 13 | target: 'node', 14 | devtool: '#source-map', 15 | node: { 16 | __dirname: true, 17 | __filename: true, 18 | }, 19 | entry: { 20 | 21 | 'index': './src/index.js', 22 | 23 | 24 | }, 25 | output: { 26 | libraryTarget: 'commonjs2', 27 | path: path.join(__dirname, './dist'), 28 | filename: '[name].js', 29 | 30 | }, 31 | module: { 32 | rules: [ 33 | 34 | 35 | { 36 | test: /\.js$/, 37 | loader: 'babel-loader', 38 | //exclude: /node_modules/ 39 | }, 40 | { 41 | test: /\.html$/, 42 | loader: 'html-loader', 43 | query: { 44 | minimize: false 45 | } 46 | }, 47 | 48 | 49 | ] 50 | }, 51 | //externals: [/^(?!\.|\/).+/i,], 52 | externals: [nodeExternals()], 53 | plugins: [ 54 | new webpack.DefinePlugin({ 55 | 'process.env': { NODE_ENV: JSON.stringify(process.env.NODE_ENV || "development") } 56 | }), 57 | ] 58 | }, 59 | 60 | 61 | ] 62 | } 63 | -------------------------------------------------------------------------------- /webpack.production.js: -------------------------------------------------------------------------------- 1 | 2 | var { CleanWebpackPlugin } = require('clean-webpack-plugin'); 3 | //var JavaScriptObfuscator = require('webpack-obfuscator'); 4 | 5 | 6 | module.exports = function () { 7 | 8 | var configs = require('./webpack.development.js')(); 9 | 10 | configs.forEach(function (config) { 11 | config.devtool = false; 12 | config.plugins.push(new CleanWebpackPlugin({ cleanOnceBeforeBuildPatterns: ['./dist/*'] })); 13 | 14 | }); 15 | 16 | return configs; 17 | } --------------------------------------------------------------------------------