New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

celery-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

celery-js - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

9

index.js

@@ -15,3 +15,10 @@ 'use strict'

this.host = options.host || 'api.trycelery.com'
if (options.host) {
this.host = options.host
} else if (this.sandbox === true) {
this.host = 'api-sandbox.trycelery.com'
} else {
this.host = 'api.trycelery.com'
}
this.endpoint = options.endpoint || '/v2'

@@ -18,0 +25,0 @@ this.protocol = options.protocol || 'https:'

2

lib/build.js

@@ -60,3 +60,3 @@ 'use strict'

let err
debug('input parameters verify', this.params, pathParams)
if (this.params.length !== pathParams.length) {

@@ -63,0 +63,0 @@ err = new Error(`Invalid number of params in path (expected ${pathParams.length}, got ${this.params.length})`)

@@ -39,4 +39,2 @@ 'use strict'

let self = this
if (typeof data === 'function' && !cb) {

@@ -53,3 +51,4 @@ cb = data

this.headers = {
'Authorization': this.apiKey
'Authorization': this.apiKey,
'Content-Type': 'application/json'
}

@@ -61,8 +60,7 @@

} else {
this.headers['Content-Type'] = 'application/json'
this.payload = qs.stringify(params)
this.payload = JSON.stringify(params)
let length = this.payload ? Buffer.byteLength(this.payload) : 0
this.headers['Content-Length'] = length
}
debug('REQ', path, params, this.payload, this.headers)

@@ -76,3 +74,4 @@ let opts = {

headers: this.headers,
timeout: this.timeout
timeout: this.timeout,
agent: false
}

@@ -113,3 +112,3 @@

if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
if (this.payload && (method === 'POST' || method === 'PUT' || method === 'PATCH')) {
req.write(this.payload)

@@ -126,3 +125,3 @@ }

if (isOk(data[key])) {
let value = getDataValue(key, data[key])
let value = getDataValue(data[key])
if (isOk(value)) {

@@ -157,3 +156,3 @@ params[key] = value

if (chunks && !error) {
if (chunks && !error && res.headers['content-type'].indexOf('application/json') >= 0) {
try {

@@ -168,3 +167,3 @@ body = JSON.parse(chunks)

debug(`response error: ${body}`)
let msg = (body.meta && body.meta.error && body.meta.error.message) ? body.meta.error.message : body || chunks
let msg = (body && body.meta && body.meta.error && body.meta.error.message) ? body.meta.error.message : body || chunks
error = new Error(msg)

@@ -171,0 +170,0 @@ error.statusCode = res.statusCode

@@ -30,2 +30,81 @@ module.exports = {

},
'coupon': {
'description': 'API for coupon',
'links': [
{
'description': 'Create a Coupon',
'href': '/coupons',
'method': 'POST',
'title': 'create',
'properties': {
'type': {
'type': 'string'
},
'code': {
'type': 'string'
},
'filter': {
'type': 'string'
},
'apply': {
'type': 'string'
},
'product_id': {
'type': 'string'
},
'enabled': {
'type': 'boolean'
},
'free_shipping': {
'type': 'boolean'
},
'amount': {
'type': 'number'
},
'order_minimum': {
'type': 'number'
},
'quantity': {
'type': 'number'
},
'begins': {
'type': 'number'
},
'expires': {
'type': 'number'
}
},
'required': ['type', 'code', 'filter', 'apply', 'free_shipping', 'amount']
},
{
'description': 'Retrieve a List of Coupons',
'href': '/coupons',
'method': 'GET',
'title': 'list',
'properties': {
'sort': {
'type': 'string'
},
'order': {
'type': 'string'
},
'offset': {
'type': 'string'
},
'page': {
'type': 'number'
},
'limit': {
'type': 'string'
}
}
},
{
'description': 'Retrieve a Coupon',
'href': '/coupons/{id}',
'method': 'GET',
'title': 'info'
}
]
},
'user': {

@@ -32,0 +111,0 @@ 'description': 'API for users resources',

{
"name": "celery-js",
"version": "0.0.1",
"version": "0.0.2",
"description": "Celery API wrapper inspired by mailgun-js",

@@ -5,0 +5,0 @@ "main": "index.js",

const Celery = require('./')({
apiKey: '44aea5eaf148dbabee4236553f2d805a598d7d175d073ec7da931fdd5eca823d430f1703a91e1f3de9e9d3fbe41f1ed2',
sandbox: false
apiKey: '44aea5eaf148dbabee4236553f2d805aab41db4192eb354b2da9b3fa190940f063f6095347d6f3e3667d726d4cda9e15',
sandbox: true
})
Celery.users('55d6ba894460b5030097728e').taxRates().info({
shipping_country: 'us'
}, (err, result) => {
console.log("!!")
console.log(err, result)
// Celery.users('55d6ba894460b5030097728e').taxRates().info({
// shipping_country: 'us'
// }, (err, result) => {
// console.log(err, result)
// })
// Celery.coupons().list((err, coupons) => {
// console.log(err, coupons)
// })
Celery.coupons('55f62ddf106c5b0300cc0492').info((err, coupons) => {
console.log(err, coupons)
})

@@ -6,6 +6,13 @@ 'use strict'

const ENV = 'sandbox'
const APIKEY = auth[ENV]['apiKey']
const USERID = auth[ENV]['userId']
const celery = require('../index.js')({
apiKey: auth.apiKey
apiKey: APIKEY,
sandbox: true
})
let createCouponId
module.exports = {

@@ -19,3 +26,3 @@

celery.products().list((err, body) => {
assert.equal(err, null)
assert.equal(err, undefined)
assert.ok(body.data)

@@ -27,6 +34,43 @@ assert.ok(Array.isArray(body.data))

'test coupons.create()': function (done) {
let CODE = 'aabbccdd'
celery.coupons().create({
'type': 'flat',
'code': CODE,
'filter': 'order',
'apply': 'once',
'free_shipping': true,
'amount': 100
}, (err, coupon) => {
assert.equal(err, undefined)
assert.ok(coupon.data)
assert.ok(typeof coupon.data === 'object')
assert.equal(coupon.data['code'], CODE)
createCouponId = coupon.data['_id']
done()
})
},
'test coupons.list()': function (done) {
celery.coupons().list((err, coupons) => {
assert.equal(err, undefined)
assert.ok(coupons.data)
assert.ok(Array.isArray(coupons.data))
done()
})
},
'test coupons.info()': function (done) {
celery.coupons(createCouponId).info((err, coupon) => {
assert.equal(err, undefined)
assert.ok(coupon.data)
assert.equal(coupon.data['_id'], createCouponId)
done()
})
},
'test users.taxRates.info()': function (done) {
let msg = { 'shipping_country': 'us' }
celery.users(auth.userId).taxRates().info(msg, (err, body) => {
assert.equal(err, null)
celery.users(USERID).taxRates().info(msg, (err, body) => {
assert.equal(err, undefined)
assert.ok('base' in body.data)

@@ -33,0 +77,0 @@ done()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc