paddle-sdk
Advanced tools
Comparing version 1.3.0 to 2.0.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [2.0.0](https://github.com/avaly/paddle-sdk/compare/v1.3.0...v2.0.0) (2019-12-27) | ||
### ⚠ BREAKING CHANGES | ||
* Requires node v10+ | ||
### Features | ||
* Upgrade all dependencies ([ce2d240](https://github.com/avaly/paddle-sdk/commit/ce2d2401681d1564e1c77f7904a98de0186fb85a)) | ||
## [1.3.0](https://github.com/avaly/paddle-sdk/compare/v1.2.2...v1.3.0) (2019-11-12) | ||
@@ -7,0 +18,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint no-prototype-builtins: 0 */ | ||
// Source: https://github.com/kvz/locutus/blob/master/src/php/var/serialize.js | ||
@@ -2,0 +4,0 @@ function serialize(mixedValue) { |
{ | ||
"name": "paddle-sdk", | ||
"description": "The Paddle.com Node.js SDK", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"main": "sdk.js", | ||
@@ -20,3 +20,3 @@ "author": "Valentin Agachi <github-com@agachi.name>", | ||
"engines": { | ||
"node": ">=8.5.0" | ||
"node": ">=10.0.0" | ||
}, | ||
@@ -39,13 +39,13 @@ "files": [ | ||
"dependencies": { | ||
"got": "^9.6.0" | ||
"got": "^10.2.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.16.0", | ||
"husky": "^2.4.1", | ||
"jest": "^24.8.0", | ||
"jsdoc-to-markdown": "^5.0.0", | ||
"lint-staged": "^8.2.1", | ||
"nock": "^10.0.6", | ||
"prettier": "^1.18.2", | ||
"standard-version": "^6.0.1", | ||
"eslint": "^6.8.0", | ||
"husky": "^3.1.0", | ||
"jest": "^24.9.0", | ||
"jsdoc-to-markdown": "^5.0.3", | ||
"lint-staged": "^9.5.0", | ||
"nock": "^11.7.0", | ||
"prettier": "^1.19.1", | ||
"standard-version": "^7.0.1", | ||
"validate-commit-msg": "^2.14.0" | ||
@@ -52,0 +52,0 @@ }, |
76
sdk.js
@@ -35,33 +35,39 @@ const crypto = require('crypto'); | ||
* @param {string} url - url to do request | ||
* @param {object} body - body parameters / object | ||
* @param {object} [headers] - header parameters | ||
* @param {boolean} [form] - form parameter (ref: got package) | ||
* @param {boolean} [json] - json parameter (ref: got package) | ||
* @param {object} options | ||
* @param {object} [options.body] - body parameters / object | ||
* @param {object} [options.headers] - header parameters | ||
* @param {boolean} [options.form] - form parameter (ref: got package) | ||
* @param {boolean} [options.json] - json parameter (ref: got package) | ||
*/ | ||
_request(path, body = {}, headers = {}, form = true, json = true) { | ||
_request(path, { body = {}, headers = {}, form = true, json = false } = {}) { | ||
const url = this.server + path; | ||
const fullBody = Object.assign(body, this._getDefaultBody()); | ||
const options = { | ||
body: Object.assign(body, this._getDefaultBody()), | ||
form, | ||
headers: this._getDefaultHeaders(headers), | ||
json, | ||
method: 'POST', | ||
}; | ||
if (form) { | ||
options.form = fullBody; | ||
} | ||
if (json) { | ||
options.json = fullBody; | ||
} | ||
// console.log('options', options); | ||
return got(url, options).then(response => { | ||
const { body } = response; | ||
return got(url, options) | ||
.json() | ||
.then(body => { | ||
if (typeof body.success === 'boolean') { | ||
if (body.success) { | ||
return body.response || body; | ||
} | ||
if (typeof body.success === 'boolean') { | ||
if (body.success) { | ||
return body.response || body; | ||
throw new Error( | ||
`Request ${url} returned an error! response=${JSON.stringify(body)}` | ||
); | ||
} | ||
throw new Error( | ||
`Request ${url} returned an error! response=${JSON.stringify(body)}` | ||
); | ||
} | ||
return body; | ||
}); | ||
return body; | ||
}); | ||
} | ||
@@ -117,3 +123,5 @@ | ||
getProductCoupons(productID) { | ||
return this._request('/product/list_coupons', { product_id: productID }); | ||
return this._request('/product/list_coupons', { | ||
body: { product_id: productID }, | ||
}); | ||
} | ||
@@ -133,3 +141,5 @@ | ||
getProductPlans(productID) { | ||
return this._request('/subscription/plans', { product_id: productID }); | ||
return this._request('/subscription/plans', { | ||
body: { product_id: productID }, | ||
}); | ||
} | ||
@@ -149,3 +159,5 @@ | ||
getPlanUsers(planID) { | ||
return this._request('/subscription/users', { plan: planID }); | ||
return this._request('/subscription/users', { | ||
body: { plan: planID }, | ||
}); | ||
} | ||
@@ -165,3 +177,5 @@ | ||
getPlanPayments(planID) { | ||
return this._request('/subscription/payments', { plan: planID }); | ||
return this._request('/subscription/payments', { | ||
body: { plan: planID }, | ||
}); | ||
} | ||
@@ -308,3 +322,3 @@ | ||
return this._request('/subscription/users_cancel', { | ||
subscription_id: subscriptionID, | ||
body: { subscription_id: subscriptionID }, | ||
}); | ||
@@ -314,3 +328,3 @@ } | ||
/** | ||
* Generate a custom pay link | ||
* Generate a custom pay link | ||
* | ||
@@ -320,3 +334,3 @@ * @method | ||
* @returns {Promise} | ||
* @fulfil {object} - The new pay link url | ||
* @fulfil {object} - The new pay link url | ||
* | ||
@@ -331,6 +345,10 @@ * @example | ||
* ] | ||
* }); | ||
* }); | ||
*/ | ||
generatePayLink(body) { | ||
return this._request('/product/generate_pay_link', body, {}, false); | ||
return this._request('/product/generate_pay_link', { | ||
body, | ||
form: false, | ||
json: true, | ||
}); | ||
} | ||
@@ -337,0 +355,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17642
447
+ Added@sindresorhus/is@2.1.1(transitive)
+ Added@szmarczak/http-timer@4.0.6(transitive)
+ Added@types/cacheable-request@6.0.3(transitive)
+ Added@types/http-cache-semantics@4.0.4(transitive)
+ Added@types/keyv@3.1.4(transitive)
+ Added@types/node@22.7.4(transitive)
+ Added@types/responselike@1.0.3(transitive)
+ Addedcacheable-lookup@2.0.1(transitive)
+ Addedcacheable-request@7.0.4(transitive)
+ Addeddecompress-response@5.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedgot@10.7.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addednormalize-url@6.1.0(transitive)
+ Addedp-cancelable@2.1.1(transitive)
+ Addedp-event@4.2.0(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-timeout@3.2.0(transitive)
+ Addedresponselike@2.0.1(transitive)
+ Addedto-readable-stream@2.1.0(transitive)
+ Addedtype-fest@0.10.0(transitive)
+ Addedundici-types@6.19.8(transitive)
- Removed@sindresorhus/is@0.14.0(transitive)
- Removed@szmarczak/http-timer@1.1.2(transitive)
- Removedcacheable-request@6.1.0(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddefer-to-connect@1.1.3(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedgot@9.6.0(transitive)
- Removedjson-buffer@3.0.0(transitive)
- Removedkeyv@3.1.0(transitive)
- Removedlowercase-keys@1.0.1(transitive)
- Removednormalize-url@4.5.1(transitive)
- Removedp-cancelable@1.1.0(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedresponselike@1.0.2(transitive)
- Removedto-readable-stream@1.0.0(transitive)
- Removedurl-parse-lax@3.0.0(transitive)
Updatedgot@^10.2.0