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

confetti

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

confetti - npm Package Compare versions

Comparing version 1.0.16 to 1.1.0

src/models/block.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 1.1.0
- Feature: Support including categories, pages, blocks and images for events
- Rename (debug) settings params host to apiHost and protocol to apiProtocol
# 1.0.16

@@ -2,0 +7,0 @@

2

package.json
{
"name": "confetti",
"version": "1.0.16",
"version": "1.1.0",
"description": "A Node wrapper for the Confetti API.",

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

@@ -13,18 +13,25 @@ const url = require('url')

const httpRequest = async function (method, options) {
let { path, json, filter, sort, page, raw, type } = options
let { path, json, filter, include, sort, page, raw, type } = options
if (options.apiKey) apiKey = options.apiKey
if (options.fetch) fetch = options.fetch
if (options.apiHost) apiHost = options.host
if (options.apiProtocol) apiProtocol = options.protocol
const API_HOST =
options.apiHost ||
apiHost ||
process.env.API_HOST ||
'api.confetti.events'
const API_HOST = apiHost || process.env.API_HOST || 'api.confetti.events'
const API_PROTOCOL = apiProtocol || process.env.API_PROTOCOL || 'https'
const API_PROTOCOL =
options.apiProtocol || apiProtocol || process.env.API_PROTOCOL || 'https'
if (!fetch) {
fetch = require('node-fetch')
let API_KEY = options.apiKey || apiKey
let fetchLib = options.fetch || fetch
if (!fetchLib) {
fetchLib = require('node-fetch')
}
if (!apiKey) {
if (!API_KEY) {
throw new Error('missing_api_key')
}
if (Array.isArray(include)) {
include = encodeURI(include.join(','))
}

@@ -35,3 +42,3 @@ const httpOptions = {

headers: {
Authorization: `apikey ${apiKey}`,
Authorization: `apikey ${API_KEY}`,
'Content-Type': 'application/json',

@@ -45,3 +52,3 @@ 'Accept-Encoding': 'gzip',

pathname: path,
search: qs.stringify({ filter, sort, page }),
search: qs.stringify({ filter, sort, page, include }),
})

@@ -52,3 +59,3 @@ if (json) {

const res = await fetch(fetchUrl, httpOptions)
const res = await fetchLib(fetchUrl, httpOptions)

@@ -55,0 +62,0 @@ if (res.status >= 200 && res.status < 299) {

@@ -16,4 +16,4 @@ const dotenv = require('dotenv')

fetch: settings.fetch,
apiHost: settings.host,
apiProtocol: settings.protocol,
apiHost: settings.apiHost,
apiProtocol: settings.apiProtocol,
}),

@@ -20,0 +20,0 @@ models,

@@ -104,3 +104,4 @@ module.exports = function ({ samples }) {

],
includes: ['categories', 'pages', 'pages.blocks', 'pages.blocks.images'],
}
}
const samples = require('./samples')()
module.exports = {
block: require('./block')({ samples }),
category: require('./category')({ samples }),
event: require('./event')({ samples }),
image: require('./image')({ samples }),
page: require('./page')({ samples }),
payment: require('./payment')({ samples }),

@@ -8,0 +10,0 @@ ticket: require('./ticket')({ samples }),

@@ -5,2 +5,3 @@ module.exports = function ({ adapter, models }) {

filter,
include,
sort,

@@ -17,2 +18,3 @@ page,

filter,
include,
sort,

@@ -31,6 +33,7 @@ page,

id,
{ raw, apiKey, fetch, apiHost, apiProtocol } = {}
{ include, raw, apiKey, fetch, apiHost, apiProtocol } = {}
) => {
return adapter.get({
path: `${resourceName}/${id}`,
include,
raw,

@@ -37,0 +40,0 @@ apiKey,

@@ -6,3 +6,3 @@ const Confetti = require('../../src')

describe('Adapter', function() {
describe('Adapter', function () {
afterEach(() => {

@@ -12,17 +12,39 @@ fetch.restore()

it('should make a find all request with correct url', async function() {
it('should make a find all request with correct url', async function () {
fetch.get(/.*\/events/, {})
await confetti.events.findAll()
const [url, params] = fetch.calls()[0]
expect(url).to.equal('https://api.confetti.events/events')
expect(params).to.deep.equal({
method: 'get',
timeout: 5000,
headers: {
Authorization: 'apikey my-key',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
},
})
})
it('should make a complicated find all request with correct url', async function () {
fetch.get(/.*\/events/, {})
await confetti.events.findAll({
filter: { workspaceId: 10 },
include: ['categories', 'pages.blocks'],
page: {
limit: 1,
offset: 10
}
offset: 10,
},
})
const [url, params] = fetch.calls()[0]
const [url, params] = fetch.calls()[0]
expect(url).to.equal(
'https://api.confetti.events/' +
encodeURI('events?filter[workspaceId]=10&page[limit]=1&page[offset]=10')
encodeURI(
'events?filter[workspaceId]=10&page[limit]=1&page[offset]=10&include='
) +
encodeURIComponent('categories,pages.blocks')
)

@@ -35,8 +57,8 @@ expect(params).to.deep.equal({

'Content-Type': 'application/json',
'Accept-Encoding': 'gzip'
}
'Accept-Encoding': 'gzip',
},
})
})
it('should make a find request with correct url', async function() {
it('should make a find request with correct url', async function () {
fetch.get('https://api.confetti.events/events/3', {})

@@ -52,11 +74,31 @@ await confetti.events.find(3)

'Content-Type': 'application/json',
'Accept-Encoding': 'gzip'
}
'Accept-Encoding': 'gzip',
},
})
})
it('should handle a text response', async function() {
it('should make a find request with includes with correct url', async function () {
fetch.get(/.*\/events/, {})
await confetti.events.find(3, { include: ['categories', 'pages.blocks'] })
const [url, params] = fetch.calls()[0]
expect(url).to.equal(
'https://api.confetti.events/events/3' +
encodeURI('?include=') +
encodeURIComponent('categories,pages.blocks')
)
expect(params).to.deep.equal({
method: 'get',
timeout: 5000,
headers: {
Authorization: 'apikey my-key',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
},
})
})
it('should handle a text response', async function () {
fetch.get('https://api.confetti.events/events/1', {
status: 200,
body: 'foo'
body: 'foo',
})

@@ -67,3 +109,3 @@ const res = await confetti.events.find(1)

it('should handle 404 response', async function() {
it('should handle 404 response', async function () {
fetch.get('https://api.confetti.events/events/1', {

@@ -74,4 +116,4 @@ status: 404,

type: 'event',
name: 'NotFoundError'
}
name: 'NotFoundError',
},
})

@@ -89,3 +131,3 @@ try {

it('should handle 400 response', async function() {
it('should handle 400 response', async function () {
fetch.get('https://api.confetti.events/events/1', {

@@ -100,8 +142,8 @@ status: 400,

"Name can't be blank",
'Name is too short (minimum is 3 characters)'
'Name is too short (minimum is 3 characters)',
],
email: ["Email can't be blank", 'Email is not a valid email'],
terms: ['Terms must be accepted.']
}
}
terms: ['Terms must be accepted.'],
},
},
})

@@ -119,6 +161,6 @@ try {

"Name can't be blank",
'Name is too short (minimum is 3 characters)'
'Name is too short (minimum is 3 characters)',
],
email: ["Email can't be blank", 'Email is not a valid email'],
terms: ['Terms must be accepted.']
terms: ['Terms must be accepted.'],
})

@@ -128,6 +170,6 @@ }

it('should handle 500 response', async function() {
it('should handle 500 response', async function () {
fetch.get('https://api.confetti.events/events/1', {
status: 500,
body: {}
body: {},
})

@@ -144,2 +186,49 @@ try {

})
it('should use provided api host and protocol in instance mode if avaliable', async function () {
fetch.get(/.*\/events/, {})
const confetti2 = new Confetti({
apiKey: 'my-key',
apiHost: 'localhost:3040',
apiProtocol: 'http',
fetch,
})
await confetti2.events.findAll()
const [url, params] = fetch.calls()[0]
expect(url).to.equal('http://localhost:3040/events')
expect(params).to.deep.equal({
method: 'get',
timeout: 5000,
headers: {
Authorization: 'apikey my-key',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
},
})
})
it('should use provided api host and protocol in static mode if avaliable', async function () {
fetch.get(/.*\/events/, {})
await Confetti.events.findAll({
apiKey: 'my-key',
apiHost: 'localhost:3040',
apiProtocol: 'http',
fetch,
})
const [url, params] = fetch.calls()[0]
expect(url).to.equal('http://localhost:3040/events')
expect(params).to.deep.equal({
method: 'get',
timeout: 5000,
headers: {
Authorization: 'apikey my-key',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
},
})
})
})
const Confetti = require('../../src')
const { expect } = require('../helper')
describe('Initiat', function() {
it('should initiate a Confetti api instance', function() {
describe('Initiat', function () {
it('should initiate a Confetti api instance', function () {
new Confetti({ key: 'my-key' })
})
it('should fail to call due on Confetti api instance due to missing api key', async function() {
it('should fail to call due on Confetti api instance due to missing api key', async function () {
const confetti = new Confetti()

@@ -11,0 +11,0 @@ await expect(confetti.events.findAll()).to.be.rejectedWith(

const { expect } = require('../helper')
const { events, webhooks, workspaces } = require('../../src/presenters')
describe('Presenters', function() {
it('should present a webhook with relation ids', function() {
describe('Presenters', function () {
it('should present a webhook with relation ids', function () {
const webhook = webhooks.render({

@@ -11,3 +11,3 @@ type: 'ticket.attending',

workspaceId: 57,
eventId: 2
eventId: 2,
})

@@ -20,16 +20,16 @@ expect(webhook).to.deep.equal({

url: 'https://hooks.zapier.com/hooks/standard/1337/',
provider: 'zapier'
provider: 'zapier',
},
relationships: {
event: { data: { id: '2', type: 'event' } },
workspace: { data: { id: '57', type: 'workspace' } }
}
workspace: { data: { id: '57', type: 'workspace' } },
},
},
included: [
{ id: '2', type: 'event', attributes: {} },
{ id: '57', type: 'workspace', attributes: {} }
]
{ id: '57', type: 'workspace', attributes: {} },
],
})
})
it('should present a webhook without eventId', function() {
it('should present a webhook without eventId', function () {
const webhook = webhooks.render({

@@ -39,3 +39,3 @@ type: 'ticket.attending',

provider: 'zapier',
workspaceId: 57
workspaceId: 57,
})

@@ -48,12 +48,12 @@ expect(webhook).to.deep.equal({

url: 'https://hooks.zapier.com/hooks/standard/1337/',
provider: 'zapier'
provider: 'zapier',
},
relationships: {
event: { data: null },
workspace: { data: { id: '57', type: 'workspace' } }
}
workspace: { data: { id: '57', type: 'workspace' } },
},
},
included: [{ id: '57', type: 'workspace', attributes: {} }]
included: [{ id: '57', type: 'workspace', attributes: {} }],
})
})
})

@@ -9,5 +9,5 @@ const Confetti = require('../../src')

})
describe('Instance', function() {
describe('Events', function() {
it('should request one event', async function() {
describe('Instance', function () {
describe('Events', function () {
it('should request one event', async function () {
fetch.get(

@@ -23,3 +23,3 @@ 'https://api.confetti.events/events/1',

})
it('should request multiple events', async function() {
it('should request multiple events', async function () {
fetch.get(

@@ -37,4 +37,4 @@ 'https://api.confetti.events/events',

describe('Payments', function() {
it('should request one payment', async function() {
describe('Payments', function () {
it('should request one payment', async function () {
fetch.get(

@@ -50,3 +50,3 @@ 'https://api.confetti.events/payments/1',

})
it('should request multiple payments', async function() {
it('should request multiple payments', async function () {
fetch.get(

@@ -64,4 +64,4 @@ 'https://api.confetti.events/payments',

describe('Tickets', function() {
it('should request one ticket', async function() {
describe('Tickets', function () {
it('should request one ticket', async function () {
fetch.get(

@@ -77,3 +77,3 @@ 'https://api.confetti.events/tickets/1',

})
it('should request multiple tickets', async function() {
it('should request multiple tickets', async function () {
fetch.get(

@@ -91,4 +91,4 @@ 'https://api.confetti.events/tickets',

describe('Webhooks', function() {
it('should request one webhook', async function() {
describe('Webhooks', function () {
it('should request one webhook', async function () {
fetch.get(

@@ -104,3 +104,3 @@ 'https://api.confetti.events/webhooks/1',

})
it('should request multiple webhooks', async function() {
it('should request multiple webhooks', async function () {
fetch.get(

@@ -118,4 +118,4 @@ 'https://api.confetti.events/webhooks',

describe('Workspaces', function() {
it('should request one workspace', async function() {
describe('Workspaces', function () {
it('should request one workspace', async function () {
fetch.get(

@@ -131,3 +131,3 @@ 'https://api.confetti.events/workspaces/1',

})
it('should request multiple workspaces', async function() {
it('should request multiple workspaces', async function () {
fetch.get(

@@ -146,5 +146,5 @@ 'https://api.confetti.events/workspaces',

describe('Static', function() {
describe('Events', function() {
it('should request one event', async function() {
describe('Static', function () {
describe('Events', function () {
it('should request one event', async function () {
fetch.get(

@@ -159,3 +159,3 @@ 'https://api.confetti.events/events/1',

})
it('should request multiple events', async function() {
it('should request multiple events', async function () {
fetch.get(

@@ -172,4 +172,4 @@ 'https://api.confetti.events/events',

describe('Payments', function() {
it('should request one payment', async function() {
describe('Payments', function () {
it('should request one payment', async function () {
fetch.get(

@@ -181,3 +181,3 @@ 'https://api.confetti.events/payments/1',

apiKey: 'my-key',
fetch
fetch,
})

@@ -188,3 +188,3 @@ expect(data).to.deep.equal(

})
it('should request multiple payments', async function() {
it('should request multiple payments', async function () {
fetch.get(

@@ -196,3 +196,3 @@ 'https://api.confetti.events/payments',

apiKey: 'my-key',
fetch
fetch,
})

@@ -205,4 +205,4 @@ expect(data).to.deep.equal(

describe('Tickets', function() {
it('should request one ticket', async function() {
describe('Tickets', function () {
it('should request one ticket', async function () {
fetch.get(

@@ -217,3 +217,3 @@ 'https://api.confetti.events/tickets/1',

})
it('should request multiple tickets', async function() {
it('should request multiple tickets', async function () {
fetch.get(

@@ -230,4 +230,4 @@ 'https://api.confetti.events/tickets',

describe('Webhooks', function() {
it('should request one webhook', async function() {
describe('Webhooks', function () {
it('should request one webhook', async function () {
fetch.get(

@@ -239,3 +239,3 @@ 'https://api.confetti.events/webhooks/1',

apiKey: 'my-key',
fetch
fetch,
})

@@ -246,3 +246,3 @@ expect(data).to.deep.equal(

})
it('should request multiple webhooks', async function() {
it('should request multiple webhooks', async function () {
fetch.get(

@@ -254,3 +254,3 @@ 'https://api.confetti.events/webhooks',

apiKey: 'my-key',
fetch
fetch,
})

@@ -261,3 +261,3 @@ expect(data).to.deep.equal(

})
it('should create a webhook', async function() {
it('should create a webhook', async function () {
fetch.post(

@@ -273,7 +273,7 @@ 'https://api.confetti.events/webhooks',

workspaceId: 57,
eventId: 2
eventId: 2,
},
{
apiKey: 'my-key',
fetch
fetch,
}

@@ -288,3 +288,3 @@ )

provider: 'zapier',
type: 'ticket.attending'
type: 'ticket.attending',
},

@@ -295,4 +295,4 @@ relationships: {

type: 'workspace',
id: '57'
}
id: '57',
},
},

@@ -302,6 +302,6 @@ event: {

type: 'event',
id: '2'
}
}
}
id: '2',
},
},
},
},

@@ -312,3 +312,3 @@ included: [

id: '2',
type: 'event'
type: 'event',
},

@@ -318,5 +318,5 @@ {

id: '57',
type: 'workspace'
}
]
type: 'workspace',
},
],
})

@@ -329,7 +329,7 @@

it('should delete a webhook', async function() {
it('should delete a webhook', async function () {
fetch.delete('https://api.confetti.events/webhooks/1', 204)
await Confetti.webhooks.delete(1, {
apiKey: 'my-key',
fetch
fetch,
})

@@ -342,4 +342,4 @@ const [url, options] = fetch.lastCall()

describe('Workspaces', function() {
it('should request one workspace', async function() {
describe('Workspaces', function () {
it('should request one workspace', async function () {
fetch.get(

@@ -351,3 +351,3 @@ 'https://api.confetti.events/workspaces/1',

apiKey: 'my-key',
fetch
fetch,
})

@@ -358,3 +358,3 @@ expect(data).to.deep.equal(

})
it('should request multiple workspaces', async function() {
it('should request multiple workspaces', async function () {
fetch.get(

@@ -366,3 +366,3 @@ 'https://api.confetti.events/workspaces',

apiKey: 'my-key',
fetch
fetch,
})

@@ -369,0 +369,0 @@ expect(data).to.deep.equal(

@@ -15,3 +15,3 @@ const chai = require('chai')

sinon,
fetch
fetch,
}
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