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

magicbell

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magicbell - npm Package Compare versions

Comparing version 1.7.1 to 1.7.2

2

dist/index.js
/**
* @license magicbell v1.7.1
* @license magicbell v1.7.2
*

@@ -4,0 +4,0 @@ * Copyright (c) MagicBell Inc. and its affiliates.

/**
* @license magicbell v1.7.1
* @license magicbell v1.7.2
*

@@ -77,3 +77,3 @@ * Copyright (c) MagicBell Inc. and its affiliates.

binding: "magicbell",
binding_version: "1.7.1",
binding_version: "1.7.2",
publisher: "magicbell"

@@ -80,0 +80,0 @@ };

/**
* @license magicbell v1.7.1
* @license magicbell v1.7.2
*

@@ -10,3 +10,3 @@ * Copyright (c) MagicBell Inc. and its affiliates.

"use strict";var ge=Object.defineProperty,ye=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var xe=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var D=(e,r,t)=>r in e?ge(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,T=(e,r)=>{for(var t in r||(r={}))xe.call(r,t)&&D(e,t,r[t]);if(ee)for(var t of ee(r))be.call(r,t)&&D(e,t,r[t]);return e},L=(e,r)=>ye(e,Ee(r));var n=(e,r,t)=>(D(e,typeof r!="symbol"?r+"":r,t),t),X=(e,r,t)=>{if(!r.has(e))throw TypeError("Cannot "+t)};var x=(e,r,t)=>(X(e,r,"read from private field"),t?t.call(e):r.get(e)),b=(e,r,t)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,t)},$=(e,r,t,s)=>(X(e,r,"write to private field"),s?s.call(e,t):r.set(e,t),t);var q=(e,r,t)=>(X(e,r,"access private method"),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Te=require("axios"),_e=require("crypto"),Pe=require("eventsource"),W=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},Z=W(Te),K=W(_e),Se=W(Pe);function ne(e,r){if(!e||!r)return"";if(!K.default||!K.default.createHmac)throw new Error("This method is not available in the browser. Please provide a userHmac.");return K.default.createHmac("sha256",e).update(r).digest("base64")}function ie(){var r;const e={binding:"magicbell",binding_version:"1.7.1",publisher:"magicbell"};return typeof process>"u"?e:L(T({},e),{runtime:((r=process==null?void 0:process.release)==null?void 0:r.name)||"node",runtime_version:process.version,platform:process.platform,arch:process.arch})}function ve(e){return e!=null&&e.name?[e==null?void 0:e.name,e.version&&`/${e.version}`,e.url&&` (${e.url})`].filter(Boolean).join(""):""}function qe(e){const r=ie();return[`${r.binding}/${r.binding_version}`,"runtime"in r&&`${r.runtime}/${r.runtime_version}`,ve(e)].filter(Boolean).join(" ")}function Ae(e){return JSON.stringify(L(T({},ie()),{application:e}))}function we(e){for(const r of["code","type","status"])switch(e[r]){case"user_identifier_not_provided":return new te(e);case"invalid_request_error":return new Oe(e);case"api_error":return new $e(e);case"authentication_error":return new te(e);case"rate_limit_error":return new Ie(e);case"idempotency_error":return new Me(e);case 404:return new Be(e);case 422:return new Le(e)}return new Ue(e)}class v extends Error{constructor(t){super(t.message);n(this,"name");n(this,"message");n(this,"type");n(this,"docs_url");n(this,"code");n(this,"status");n(this,"statusText");n(this,"suggestion");this.type=this.constructor.name,this.name="MagicBellError",this.code=t.code,this.status=t.status,this.statusText=t.statusText,this.message=t.message,this.suggestion=t.suggestion,this.docs_url=t.docs_url||t.help_link}}class Oe extends v{}class Le extends v{}class $e extends v{}class te extends v{}class Ie extends v{}class Me extends v{}class Ue extends v{}class Be extends v{}function J(e){if(!e||typeof e!="object")return e;const r={};for(const t of Object.keys(e))r[ke(t)]=e[t];return r}function ke(e){const r={etag:"ETag",magicbell:"MagicBell"};return e.split("-").map(t=>r[t.toLowerCase()]||t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("-")}const A={reset:"\x1B[0m",magenta:"\x1B[35m",red:"\x1B[31m"};class Fe{constructor(){n(this,"active",!1)}debug(r){!this.active||console.log(`${A.reset}${A.magenta}magicbell:${A.reset} ${r}`)}error(r){!this.active||console.error(`${A.reset}${A.red}magicbell:${A.reset} ${r}`)}}function Ne(e){return`${e.slice(0,4)}\u2026${e.slice(-4)}`}const je=/secret|token|key|password/i;function Ge(e){return je.test(e)}function Re({method:e,baseURL:r,url:t,data:s,headers:a}){return[`curl -X ${e.toUpperCase()}`,`${r}/${t.replace(/^\//,"")}`,Object.entries(a).map(([u,o])=>`-H '${u}: ${Ge(u)?Ne(String(o)):o}'`).join(" "),s&&`-d '${JSON.stringify(s)}'`].join(" ")}const F=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);function _(e){return typeof e=="string"}function I(e){return typeof e=="boolean"}function ae(e){return Array.isArray(e)}function re(e){return Array.isArray(e)&&e.every(r=>typeof r=="string")}function Y(e){return typeof e=="number"}function w(e){return e&&typeof e=="object"}function He(e,r=!1){if(typeof e!="object")throw new Error("Argument must be an object");const t={};for(const s of Object.keys(e))e[s]!=null&&(r&&e[s]===""||(t[s]=e[s]));return t}function Ce(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.random()*16|0;return(e==="x"?r:r&3|8).toString(16)})}async function De(e){return new Promise(r=>setTimeout(r,e))}function Xe(...e){if(e.length<=2)return e.join(" and ");const r=e.slice(-1)[0];return[e.slice(0,-1).join(", "),r].join(", and ")}function Ke(...e){return["/",...e].join("/").replace(/\/+/g,"/").replace(/\/$/,"")}const oe=typeof Symbol<"u"&&Symbol.asyncIterator?Symbol.asyncIterator:"@@asyncIterator";function Je(e,r){return!F(e,"current_page")||!F(e,"per_page")?!1:F(e,"total_pages")?e.current_page<e.total_pages:r===e.per_page}function Ye(e,{data:r,params:t}){const s={currentPromise:null},a=typeof t.after<"u";let u=0,o=e({data:r,params:t});const h=i=>{const d=i.current_page+1;return e({data:r,params:L(T({},t),{page:d})})};function p(i){const d=Object.keys(i).find(c=>Array.isArray(i[c])),m=i[d]||i.data;if(!m||typeof m.length!="number")throw Error("Unexpected: MagicBell API response does not have a well-formed response.");if(u<m.length){const c=a?m.length-1-u:u,E=m[c];return u+=1,{value:E,done:!1}}return Je(i,m.length)?(u=0,o=h(i),o.then(p)):{value:void 0,done:!0}}function g(){return ze(s,(i,d)=>o.then(p).then(i).catch(d))}const y=ue(g),f=Qe(y),l={forEach:y,toArray:f,next:g,return:()=>({}),[oe]:()=>l};return Object.assign(o,l)}function ze(e,r){return e.currentPromise||(e.currentPromise=new Promise(r).then(t=>(e.currentPromise=void 0,t))),e.currentPromise}function ue(e,r){return function(s){return new Promise((a,u)=>{let o=0;function h(p){if(p.done){a();return}const g=p.value;return new Promise(y=>{y(s(g,o))}).then(y=>y===!1?(r==null||r(),h({done:!0})):(o++,e().then(h)))}e().then(h).catch(u)})}}function Qe(e){return function(t){const s=t==null?void 0:t.limit;if(!s)throw Error("You must pass a `limit` option to toArray, e.g., `toArray({ limit: 1000 });`.");if(s>1e4)throw Error("You cannot specify a limit of more than 10,000 items to fetch in `toArray`; use `forEach` to iterate through longer lists.");return new Promise((a,u)=>{const o=[];e(h=>{if(o.push(h),o.length>=s)return!1}).then(()=>{a(o)}).catch(u)})}}function We(e,r={}){let t,s,a,u;const o=[];let h;const p=f=>{o.push(f),h&&(h(),h=null)};async function g(f){!s&&!u&&(u=e.request({method:"GET",path:"/config"},f).then(c=>s=c.ws.channel));const l=await e.request({method:"POST",path:"/ws/auth"},f),{token:i}=await Z.default.post(`https://rest.ably.io/keys/${l.keyName}/requestToken`,l).then(c=>c.data);await u;const d=r.sseHost||"https://realtime.ably.io",m=new URL("sse",d);m.searchParams.append("v","1.1"),m.searchParams.append("accessToken",i),m.searchParams.append("channels",s),m.searchParams.append("heartbeats","true"),a&&m.searchParams.append("lastEvent",a),t&&t.close(),t=new Se.default(m.toString()),t.onmessage=c=>{if(c.origin!==d||(a=c.lastEventId,!("data"in c)))return;const E=JSON.parse(c.data);if(E.type==="close")return p({value:null,done:!0});E.data=E.encoding==="json"?JSON.parse(E.data):E.data,p({value:E,done:!1})},t.onerror=c=>{const E="data"in c?JSON.parse(c.data):{};E.code>=40140&&E.code<40150?(t.close(),g(f)):/invalid channel id/i.test(E.message)?(t.close(),p({value:null,done:!0})):console.log("err",c)}}function y(f){g(f);const l=async()=>{o.length||await new Promise(E=>h=E);const c=o.pop();return c.done&&t&&t.close(),c},i=()=>(t.close(),p({done:!0,value:void 0}),{done:!0,value:void 0}),m={forEach:ue(l,i),close:()=>void i(),next:l,return:i,[oe]:()=>m};return m}return y}const z={host:_,maxRetryDelay:Y,timeout:Y,apiKey:_,maxRetries:Y,userEmail:_,userExternalId:_,userHmac:_,idempotencyKey:_,telemetry:I,apiSecret:_,appInfo:w,debug:I,features:w,headers:w};function V(e){var r;if(!w(e))return!1;for(const t of Object.keys(e))if(!((r=z[t])!=null&&r.call(z,e[t])))return!1;return!0}const Q={archived:I,read:I,seen:I,categories:e=>_(e)||re(e),topics:e=>_(e)||re(e)};function Ze(e){var r;if(!w(e))return!1;for(const t of Object.keys(e))if(!((r=Q[t])!=null&&r.call(Q,e[t])))return!1;return!0}function Ve(e,r,t={encode:!0}){return e.replace(/{([\s\S]+?)}/g,(s,a)=>t.encode?encodeURIComponent(r[a]||""):r[a]||"")}function et(e){return(e.match(/{\w+}/g)||[]||[]).map(t=>t.replace(/[{}]/g,""))}function tt(e){return!ae(e)||!w(e[0])?{}:V(e[0])?{}:e.shift()}function rt(e){if(!ae(e)||e.length===0)return{};const r=e[e.length-1];return V(r)?T({},e.pop()):{}}function st({path:e,method:r,args:t}){const s=[...t].filter(l=>l!==void 0),u=et(e).reduce((l,i)=>{const d=s.shift();if(typeof d!="string")throw new Error(`MagicBell: Argument "${i}" must be a string, but got ${typeof d}: ${JSON.stringify(d)} (on API request to \`${r} ${e}\`)`);return l[i]=d,l},{}),o=Ve(e,u,{encode:!1}),h=tt(s),p=rt(s);if(s.filter(l=>l!=null).length)throw new Error(`MagicBell: Unknown arguments (${JSON.stringify(s)}). (on API request to \`${r} ${o}\`)`);let g=r==="GET";return r==="POST"&&Ze(h)&&(g=!0),{path:o,data:g?{}:h,params:g?h:{},options:p}}function se(e){return e?Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1:!0}class P{constructor(r){n(this,"path");n(this,"entity");n(this,"client");this.client=r}request({method:r,paged:t,path:s},...a){const{path:u,data:o,params:h,options:p}=st({path:Ke(this.path,s),method:r,args:a}),g=({data:y,params:f})=>{const l=this.entity||this.path;return y=se(y)?void 0:{[l]:y},f=se(f)?void 0:f,this.client.request({method:r,path:u,data:y,params:f},p).then(i=>i[l]||i)};return t?Ye(g,{data:o,params:h}):g({data:o,params:h})}assertFeatureFlag(r){if(!this.client.hasFlag(r))throw new Error(`This is a beta feature, please enable it by providing the "${r}" feature flag.`)}}class nt extends P{constructor(){super(...arguments);n(this,"path","broadcasts");n(this,"entity","notification")}list(t,s,a){return this.assertFeatureFlag("broadcasts-notifications-list"),this.request({method:"GET",path:"{broadcast_id}/notifications",paged:!0},t,s,a)}}class it extends P{constructor(){super(...arguments);n(this,"path","broadcasts");n(this,"entity","broadcast");n(this,"notifications",new nt(this.client))}list(t,s){return this.assertFeatureFlag("broadcasts-list"),this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.assertFeatureFlag("broadcasts-get"),this.request({method:"GET",path:"{broadcast_id}"},t,s)}}class at extends P{constructor(){super(...arguments);n(this,"path","imports");n(this,"entity","import")}create(t,s){return this.assertFeatureFlag("imports-create"),this.request({method:"POST"},t,s)}get(t,s){return this.assertFeatureFlag("imports-get"),this.request({method:"GET",path:"{import_id}"},t,s)}}class ot extends P{constructor(){super(...arguments);n(this,"path","notification_preferences");n(this,"entity","notification_preferences")}get(t){return this.request({method:"GET"},t)}update(t,s){return this.request({method:"PUT"},t,s)}}class ut extends P{constructor(){super(...arguments);n(this,"path","notifications");n(this,"entity","notification")}create(t,s){return this.request({method:"POST"},t,s)}list(t,s){return this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.request({method:"GET",path:"{notification_id}"},t,s)}delete(t,s){return this.request({method:"DELETE",path:"{notification_id}"},t,s)}markAsRead(t,s){return this.request({method:"POST",path:"{notification_id}/read"},t,s)}markAsUnread(t,s){return this.request({method:"POST",path:"{notification_id}/unread"},t,s)}archive(t,s){return this.request({method:"POST",path:"{notification_id}/archive"},t,s)}unarchive(t,s){return this.request({method:"DELETE",path:"{notification_id}/archive"},t,s)}markAllRead(t,s){return this.request({method:"POST",path:"read"},t,s)}markAllSeen(t,s){return this.request({method:"POST",path:"seen"},t,s)}}class ct extends P{constructor(){super(...arguments);n(this,"path","push_subscriptions");n(this,"entity","push_subscription")}create(t,s){return this.request({method:"POST"},t,s)}delete(t,s){return this.request({method:"DELETE",path:"{device_token}"},t,s)}}class lt extends P{constructor(){super(...arguments);n(this,"path","subscriptions");n(this,"entity","subscription")}list(t){return this.request({method:"GET",paged:!0},t)}create(t,s){return this.request({method:"POST"},t,s)}unsubscribe(t,s,a){return this.request({method:"POST",path:"{topic}/unsubscribe"},t,s,a)}get(t,s){return this.request({method:"GET",path:"{topic}"},t,s)}delete(t,s,a){return this.request({method:"DELETE",path:"{topic}"},t,s,a)}}class ht extends P{constructor(){super(...arguments);n(this,"path","users");n(this,"entity","push_subscription")}list(t,s,a){return this.assertFeatureFlag("users-push-subscriptions-list"),this.request({method:"GET",path:"{user_id}/push_subscriptions",paged:!0},t,s,a)}delete(t,s,a){return this.assertFeatureFlag("users-push-subscriptions-delete"),this.request({method:"DELETE",path:"{user_id}/push_subscriptions/{subscription_id}"},t,s,a)}}class dt extends P{constructor(){super(...arguments);n(this,"path","users");n(this,"entity","user");n(this,"pushSubscriptions",new ht(this.client))}create(t,s){return this.request({method:"POST"},t,s)}list(t,s){return this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.request({method:"GET",path:"{user_id}"},t,s)}update(t,s,a){return this.request({method:"PUT",path:"{user_id}"},t,s,a)}delete(t,s){return this.request({method:"DELETE",path:"{user_id}"},t,s)}updateByEmail(t,s,a){return this.request({method:"PUT",path:"email:{user_email}"},t,s,a)}deleteByEmail(t,s){return this.request({method:"DELETE",path:"email:{user_email}"},t,s)}updateByExternalId(t,s,a){return this.request({method:"PUT",path:"external_id:{external_id}"},t,s,a)}deleteByExternalId(t,s){return this.request({method:"DELETE",path:"external_id:{external_id}"},t,s)}}typeof XMLHttpRequest!="function"&&(Z.default.defaults.adapter=require("axios/lib/adapters/http"));const ft={host:"https://api.magicbell.com",timeout:3e4,maxRetries:3,maxRetryDelay:60,telemetry:!0};var M,U,S,O,B,k,N,le,j,he,G,de,R,fe,H,me,C,pe;class ce{constructor(r){b(this,N);b(this,j);b(this,G);b(this,R);b(this,H);b(this,C);b(this,M,void 0);b(this,U,void 0);b(this,S,void 0);b(this,O,new Fe);b(this,B,{});b(this,k,[]);n(this,"listen",We(this));n(this,"broadcasts",new it(this));n(this,"imports",new at(this));n(this,"notificationPreferences",new ot(this));n(this,"notifications",new ut(this));n(this,"pushSubscriptions",new ct(this));n(this,"subscriptions",new lt(this));n(this,"users",new dt(this));const t=["apiKey"].filter(s=>!F(r,s));if(t.length)throw new Error(`You haven't provided all required options, please provide ${Xe(...t)} to Client(options)`);if(!V(r))throw new Error("You have provided invalid options. Please check your client options.");$(this,S,Object.assign({},ft,r)),x(this,O).active=Boolean(x(this,S).debug),$(this,U,Ae(r.appInfo)),$(this,M,qe(r.appInfo)),$(this,B,r.features||{})}hasFlag(r){return x(this,B)[r]||!1}async request({method:r,path:t,data:s,params:a},u){var g,y,f;const o=T(T({},x(this,S)),u),h=q(this,N,le).call(this,o,r),p=Math.max(0,o.maxRetries);for(let l=1;l<=p;l++){let i,d;const m=Date.now();if(x(this,O).debug(`${r} ${t}`),await Z.default({method:r,url:t,baseURL:o.host,headers:T(T({},h),J({"X-MAGICBELL-CLIENT-TELEMETRY":q(this,G,de).call(this)})),data:s,params:a,timeout:o.timeout}).then(c=>{i=c}).catch(c=>{const E=Re({method:r,baseURL:o.host,url:t,data:s,params:a,headers:h});x(this,O).error(`${c.message}: ${E}`),d=c,i=c.response}),q(this,j,he).call(this,i,{startTime:m}),q(this,R,fe).call(this,i,l,p)){const c=Number((g=i==null?void 0:i.headers)==null?void 0:g["retry-after"]);await De(q(this,H,me).call(this,l,c,o.maxRetryDelay));continue}if(d)throw we(T({code:d.code,name:d.name,message:d.message,type:d.type,status:i==null?void 0:i.status,statusText:i==null?void 0:i.statusText},(f=(y=i==null?void 0:i.data)==null?void 0:y.errors)==null?void 0:f[0]));return i.data}}}M=new WeakMap,U=new WeakMap,S=new WeakMap,O=new WeakMap,B=new WeakMap,k=new WeakMap,N=new WeakSet,le=function(r,t){let s=r.userHmac;!s&&r.apiSecret&&(r.userExternalId||r.userEmail)&&(s=ne(r.apiSecret,r.userExternalId||r.userEmail));const a=typeof document<"u";return He(J(L(T({"Accept-Version":"v2","Idempotency-Key":r.idempotencyKey||q(this,C,pe).call(this,t,r.maxRetries)},x(this,S).headers),{"User-Agent":a?null:x(this,M),"X-MAGICBELL-API-KEY":r.apiKey,"X-MAGICBELL-API-SECRET":r.apiSecret,"X-MAGICBELL-CLIENT-USER-AGENT":x(this,U),"X-MAGICBELL-USER-EMAIL":r.userEmail,"X-MAGICBELL-USER-EXTERNAL-ID":r.userExternalId,"X-MAGICBELL-USER-HMAC":s})),!0)},j=new WeakSet,he=function(r,{startTime:t}){if(!x(this,S).telemetry||!(r!=null&&r.status))return;const s=J(r.headers);x(this,k).push({id:s["X-Request-Id"],runtime:Number(s["X-Runtime"]),duration:Date.now()-t,status:r.status})},G=new WeakSet,de=function(){const r=x(this,k).pop();return r?JSON.stringify(r):null},R=new WeakSet,fe=function(r,t,s){return t>=s?!1:r?r.headers["should-retry"]?r.headers["should-retry"]==="true":r.status===409||r.status===503||r.status>=500&&r.request.method!=="POST":!0},H=new WeakSet,me=function(r,t=null,s){let u=Math.min(.5*Math.pow(r,2),s);return u*=.75*(1+Math.random()),u=Math.min(Math.max(.5,u),s),Number.isInteger(t)&&t<=60&&(u=Math.max(u,t)),u*1e3},C=new WeakSet,pe=function(r,t){if(!(r!=="POST"||t===0))return`magicbell-retry-${Ce()}`};exports.Client=ce;exports.createHmac=ne;exports.default=ce;
"use strict";var ge=Object.defineProperty,ye=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var xe=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var D=(e,r,t)=>r in e?ge(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,T=(e,r)=>{for(var t in r||(r={}))xe.call(r,t)&&D(e,t,r[t]);if(ee)for(var t of ee(r))be.call(r,t)&&D(e,t,r[t]);return e},L=(e,r)=>ye(e,Ee(r));var n=(e,r,t)=>(D(e,typeof r!="symbol"?r+"":r,t),t),X=(e,r,t)=>{if(!r.has(e))throw TypeError("Cannot "+t)};var x=(e,r,t)=>(X(e,r,"read from private field"),t?t.call(e):r.get(e)),b=(e,r,t)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,t)},$=(e,r,t,s)=>(X(e,r,"write to private field"),s?s.call(e,t):r.set(e,t),t);var q=(e,r,t)=>(X(e,r,"access private method"),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Te=require("axios"),_e=require("crypto"),Pe=require("eventsource"),W=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},Z=W(Te),K=W(_e),Se=W(Pe);function ne(e,r){if(!e||!r)return"";if(!K.default||!K.default.createHmac)throw new Error("This method is not available in the browser. Please provide a userHmac.");return K.default.createHmac("sha256",e).update(r).digest("base64")}function ie(){var r;const e={binding:"magicbell",binding_version:"1.7.2",publisher:"magicbell"};return typeof process>"u"?e:L(T({},e),{runtime:((r=process==null?void 0:process.release)==null?void 0:r.name)||"node",runtime_version:process.version,platform:process.platform,arch:process.arch})}function ve(e){return e!=null&&e.name?[e==null?void 0:e.name,e.version&&`/${e.version}`,e.url&&` (${e.url})`].filter(Boolean).join(""):""}function qe(e){const r=ie();return[`${r.binding}/${r.binding_version}`,"runtime"in r&&`${r.runtime}/${r.runtime_version}`,ve(e)].filter(Boolean).join(" ")}function Ae(e){return JSON.stringify(L(T({},ie()),{application:e}))}function we(e){for(const r of["code","type","status"])switch(e[r]){case"user_identifier_not_provided":return new te(e);case"invalid_request_error":return new Oe(e);case"api_error":return new $e(e);case"authentication_error":return new te(e);case"rate_limit_error":return new Ie(e);case"idempotency_error":return new Me(e);case 404:return new Be(e);case 422:return new Le(e)}return new Ue(e)}class v extends Error{constructor(t){super(t.message);n(this,"name");n(this,"message");n(this,"type");n(this,"docs_url");n(this,"code");n(this,"status");n(this,"statusText");n(this,"suggestion");this.type=this.constructor.name,this.name="MagicBellError",this.code=t.code,this.status=t.status,this.statusText=t.statusText,this.message=t.message,this.suggestion=t.suggestion,this.docs_url=t.docs_url||t.help_link}}class Oe extends v{}class Le extends v{}class $e extends v{}class te extends v{}class Ie extends v{}class Me extends v{}class Ue extends v{}class Be extends v{}function J(e){if(!e||typeof e!="object")return e;const r={};for(const t of Object.keys(e))r[ke(t)]=e[t];return r}function ke(e){const r={etag:"ETag",magicbell:"MagicBell"};return e.split("-").map(t=>r[t.toLowerCase()]||t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("-")}const A={reset:"\x1B[0m",magenta:"\x1B[35m",red:"\x1B[31m"};class Fe{constructor(){n(this,"active",!1)}debug(r){!this.active||console.log(`${A.reset}${A.magenta}magicbell:${A.reset} ${r}`)}error(r){!this.active||console.error(`${A.reset}${A.red}magicbell:${A.reset} ${r}`)}}function Ne(e){return`${e.slice(0,4)}\u2026${e.slice(-4)}`}const je=/secret|token|key|password/i;function Ge(e){return je.test(e)}function Re({method:e,baseURL:r,url:t,data:s,headers:a}){return[`curl -X ${e.toUpperCase()}`,`${r}/${t.replace(/^\//,"")}`,Object.entries(a).map(([u,o])=>`-H '${u}: ${Ge(u)?Ne(String(o)):o}'`).join(" "),s&&`-d '${JSON.stringify(s)}'`].join(" ")}const F=(e,r)=>Object.prototype.hasOwnProperty.call(e,r);function _(e){return typeof e=="string"}function I(e){return typeof e=="boolean"}function ae(e){return Array.isArray(e)}function re(e){return Array.isArray(e)&&e.every(r=>typeof r=="string")}function Y(e){return typeof e=="number"}function w(e){return e&&typeof e=="object"}function He(e,r=!1){if(typeof e!="object")throw new Error("Argument must be an object");const t={};for(const s of Object.keys(e))e[s]!=null&&(r&&e[s]===""||(t[s]=e[s]));return t}function Ce(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.random()*16|0;return(e==="x"?r:r&3|8).toString(16)})}async function De(e){return new Promise(r=>setTimeout(r,e))}function Xe(...e){if(e.length<=2)return e.join(" and ");const r=e.slice(-1)[0];return[e.slice(0,-1).join(", "),r].join(", and ")}function Ke(...e){return["/",...e].join("/").replace(/\/+/g,"/").replace(/\/$/,"")}const oe=typeof Symbol<"u"&&Symbol.asyncIterator?Symbol.asyncIterator:"@@asyncIterator";function Je(e,r){return!F(e,"current_page")||!F(e,"per_page")?!1:F(e,"total_pages")?e.current_page<e.total_pages:r===e.per_page}function Ye(e,{data:r,params:t}){const s={currentPromise:null},a=typeof t.after<"u";let u=0,o=e({data:r,params:t});const h=i=>{const d=i.current_page+1;return e({data:r,params:L(T({},t),{page:d})})};function p(i){const d=Object.keys(i).find(c=>Array.isArray(i[c])),m=i[d]||i.data;if(!m||typeof m.length!="number")throw Error("Unexpected: MagicBell API response does not have a well-formed response.");if(u<m.length){const c=a?m.length-1-u:u,E=m[c];return u+=1,{value:E,done:!1}}return Je(i,m.length)?(u=0,o=h(i),o.then(p)):{value:void 0,done:!0}}function g(){return ze(s,(i,d)=>o.then(p).then(i).catch(d))}const y=ue(g),f=Qe(y),l={forEach:y,toArray:f,next:g,return:()=>({}),[oe]:()=>l};return Object.assign(o,l)}function ze(e,r){return e.currentPromise||(e.currentPromise=new Promise(r).then(t=>(e.currentPromise=void 0,t))),e.currentPromise}function ue(e,r){return function(s){return new Promise((a,u)=>{let o=0;function h(p){if(p.done){a();return}const g=p.value;return new Promise(y=>{y(s(g,o))}).then(y=>y===!1?(r==null||r(),h({done:!0})):(o++,e().then(h)))}e().then(h).catch(u)})}}function Qe(e){return function(t){const s=t==null?void 0:t.limit;if(!s)throw Error("You must pass a `limit` option to toArray, e.g., `toArray({ limit: 1000 });`.");if(s>1e4)throw Error("You cannot specify a limit of more than 10,000 items to fetch in `toArray`; use `forEach` to iterate through longer lists.");return new Promise((a,u)=>{const o=[];e(h=>{if(o.push(h),o.length>=s)return!1}).then(()=>{a(o)}).catch(u)})}}function We(e,r={}){let t,s,a,u;const o=[];let h;const p=f=>{o.push(f),h&&(h(),h=null)};async function g(f){!s&&!u&&(u=e.request({method:"GET",path:"/config"},f).then(c=>s=c.ws.channel));const l=await e.request({method:"POST",path:"/ws/auth"},f),{token:i}=await Z.default.post(`https://rest.ably.io/keys/${l.keyName}/requestToken`,l).then(c=>c.data);await u;const d=r.sseHost||"https://realtime.ably.io",m=new URL("sse",d);m.searchParams.append("v","1.1"),m.searchParams.append("accessToken",i),m.searchParams.append("channels",s),m.searchParams.append("heartbeats","true"),a&&m.searchParams.append("lastEvent",a),t&&t.close(),t=new Se.default(m.toString()),t.onmessage=c=>{if(c.origin!==d||(a=c.lastEventId,!("data"in c)))return;const E=JSON.parse(c.data);if(E.type==="close")return p({value:null,done:!0});E.data=E.encoding==="json"?JSON.parse(E.data):E.data,p({value:E,done:!1})},t.onerror=c=>{const E="data"in c?JSON.parse(c.data):{};E.code>=40140&&E.code<40150?(t.close(),g(f)):/invalid channel id/i.test(E.message)?(t.close(),p({value:null,done:!0})):console.log("err",c)}}function y(f){g(f);const l=async()=>{o.length||await new Promise(E=>h=E);const c=o.pop();return c.done&&t&&t.close(),c},i=()=>(t.close(),p({done:!0,value:void 0}),{done:!0,value:void 0}),m={forEach:ue(l,i),close:()=>void i(),next:l,return:i,[oe]:()=>m};return m}return y}const z={host:_,maxRetryDelay:Y,timeout:Y,apiKey:_,maxRetries:Y,userEmail:_,userExternalId:_,userHmac:_,idempotencyKey:_,telemetry:I,apiSecret:_,appInfo:w,debug:I,features:w,headers:w};function V(e){var r;if(!w(e))return!1;for(const t of Object.keys(e))if(!((r=z[t])!=null&&r.call(z,e[t])))return!1;return!0}const Q={archived:I,read:I,seen:I,categories:e=>_(e)||re(e),topics:e=>_(e)||re(e)};function Ze(e){var r;if(!w(e))return!1;for(const t of Object.keys(e))if(!((r=Q[t])!=null&&r.call(Q,e[t])))return!1;return!0}function Ve(e,r,t={encode:!0}){return e.replace(/{([\s\S]+?)}/g,(s,a)=>t.encode?encodeURIComponent(r[a]||""):r[a]||"")}function et(e){return(e.match(/{\w+}/g)||[]||[]).map(t=>t.replace(/[{}]/g,""))}function tt(e){return!ae(e)||!w(e[0])?{}:V(e[0])?{}:e.shift()}function rt(e){if(!ae(e)||e.length===0)return{};const r=e[e.length-1];return V(r)?T({},e.pop()):{}}function st({path:e,method:r,args:t}){const s=[...t].filter(l=>l!==void 0),u=et(e).reduce((l,i)=>{const d=s.shift();if(typeof d!="string")throw new Error(`MagicBell: Argument "${i}" must be a string, but got ${typeof d}: ${JSON.stringify(d)} (on API request to \`${r} ${e}\`)`);return l[i]=d,l},{}),o=Ve(e,u,{encode:!1}),h=tt(s),p=rt(s);if(s.filter(l=>l!=null).length)throw new Error(`MagicBell: Unknown arguments (${JSON.stringify(s)}). (on API request to \`${r} ${o}\`)`);let g=r==="GET";return r==="POST"&&Ze(h)&&(g=!0),{path:o,data:g?{}:h,params:g?h:{},options:p}}function se(e){return e?Array.isArray(e)?e.length===0:typeof e=="object"?Object.keys(e).length===0:!1:!0}class P{constructor(r){n(this,"path");n(this,"entity");n(this,"client");this.client=r}request({method:r,paged:t,path:s},...a){const{path:u,data:o,params:h,options:p}=st({path:Ke(this.path,s),method:r,args:a}),g=({data:y,params:f})=>{const l=this.entity||this.path;return y=se(y)?void 0:{[l]:y},f=se(f)?void 0:f,this.client.request({method:r,path:u,data:y,params:f},p).then(i=>i[l]||i)};return t?Ye(g,{data:o,params:h}):g({data:o,params:h})}assertFeatureFlag(r){if(!this.client.hasFlag(r))throw new Error(`This is a beta feature, please enable it by providing the "${r}" feature flag.`)}}class nt extends P{constructor(){super(...arguments);n(this,"path","broadcasts");n(this,"entity","notification")}list(t,s,a){return this.assertFeatureFlag("broadcasts-notifications-list"),this.request({method:"GET",path:"{broadcast_id}/notifications",paged:!0},t,s,a)}}class it extends P{constructor(){super(...arguments);n(this,"path","broadcasts");n(this,"entity","broadcast");n(this,"notifications",new nt(this.client))}list(t,s){return this.assertFeatureFlag("broadcasts-list"),this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.assertFeatureFlag("broadcasts-get"),this.request({method:"GET",path:"{broadcast_id}"},t,s)}}class at extends P{constructor(){super(...arguments);n(this,"path","imports");n(this,"entity","import")}create(t,s){return this.assertFeatureFlag("imports-create"),this.request({method:"POST"},t,s)}get(t,s){return this.assertFeatureFlag("imports-get"),this.request({method:"GET",path:"{import_id}"},t,s)}}class ot extends P{constructor(){super(...arguments);n(this,"path","notification_preferences");n(this,"entity","notification_preferences")}get(t){return this.request({method:"GET"},t)}update(t,s){return this.request({method:"PUT"},t,s)}}class ut extends P{constructor(){super(...arguments);n(this,"path","notifications");n(this,"entity","notification")}create(t,s){return this.request({method:"POST"},t,s)}list(t,s){return this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.request({method:"GET",path:"{notification_id}"},t,s)}delete(t,s){return this.request({method:"DELETE",path:"{notification_id}"},t,s)}markAsRead(t,s){return this.request({method:"POST",path:"{notification_id}/read"},t,s)}markAsUnread(t,s){return this.request({method:"POST",path:"{notification_id}/unread"},t,s)}archive(t,s){return this.request({method:"POST",path:"{notification_id}/archive"},t,s)}unarchive(t,s){return this.request({method:"DELETE",path:"{notification_id}/archive"},t,s)}markAllRead(t,s){return this.request({method:"POST",path:"read"},t,s)}markAllSeen(t,s){return this.request({method:"POST",path:"seen"},t,s)}}class ct extends P{constructor(){super(...arguments);n(this,"path","push_subscriptions");n(this,"entity","push_subscription")}create(t,s){return this.request({method:"POST"},t,s)}delete(t,s){return this.request({method:"DELETE",path:"{device_token}"},t,s)}}class lt extends P{constructor(){super(...arguments);n(this,"path","subscriptions");n(this,"entity","subscription")}list(t){return this.request({method:"GET",paged:!0},t)}create(t,s){return this.request({method:"POST"},t,s)}unsubscribe(t,s,a){return this.request({method:"POST",path:"{topic}/unsubscribe"},t,s,a)}get(t,s){return this.request({method:"GET",path:"{topic}"},t,s)}delete(t,s,a){return this.request({method:"DELETE",path:"{topic}"},t,s,a)}}class ht extends P{constructor(){super(...arguments);n(this,"path","users");n(this,"entity","push_subscription")}list(t,s,a){return this.assertFeatureFlag("users-push-subscriptions-list"),this.request({method:"GET",path:"{user_id}/push_subscriptions",paged:!0},t,s,a)}delete(t,s,a){return this.assertFeatureFlag("users-push-subscriptions-delete"),this.request({method:"DELETE",path:"{user_id}/push_subscriptions/{subscription_id}"},t,s,a)}}class dt extends P{constructor(){super(...arguments);n(this,"path","users");n(this,"entity","user");n(this,"pushSubscriptions",new ht(this.client))}create(t,s){return this.request({method:"POST"},t,s)}list(t,s){return this.request({method:"GET",paged:!0},t,s)}get(t,s){return this.request({method:"GET",path:"{user_id}"},t,s)}update(t,s,a){return this.request({method:"PUT",path:"{user_id}"},t,s,a)}delete(t,s){return this.request({method:"DELETE",path:"{user_id}"},t,s)}updateByEmail(t,s,a){return this.request({method:"PUT",path:"email:{user_email}"},t,s,a)}deleteByEmail(t,s){return this.request({method:"DELETE",path:"email:{user_email}"},t,s)}updateByExternalId(t,s,a){return this.request({method:"PUT",path:"external_id:{external_id}"},t,s,a)}deleteByExternalId(t,s){return this.request({method:"DELETE",path:"external_id:{external_id}"},t,s)}}typeof XMLHttpRequest!="function"&&(Z.default.defaults.adapter=require("axios/lib/adapters/http"));const ft={host:"https://api.magicbell.com",timeout:3e4,maxRetries:3,maxRetryDelay:60,telemetry:!0};var M,U,S,O,B,k,N,le,j,he,G,de,R,fe,H,me,C,pe;class ce{constructor(r){b(this,N);b(this,j);b(this,G);b(this,R);b(this,H);b(this,C);b(this,M,void 0);b(this,U,void 0);b(this,S,void 0);b(this,O,new Fe);b(this,B,{});b(this,k,[]);n(this,"listen",We(this));n(this,"broadcasts",new it(this));n(this,"imports",new at(this));n(this,"notificationPreferences",new ot(this));n(this,"notifications",new ut(this));n(this,"pushSubscriptions",new ct(this));n(this,"subscriptions",new lt(this));n(this,"users",new dt(this));const t=["apiKey"].filter(s=>!F(r,s));if(t.length)throw new Error(`You haven't provided all required options, please provide ${Xe(...t)} to Client(options)`);if(!V(r))throw new Error("You have provided invalid options. Please check your client options.");$(this,S,Object.assign({},ft,r)),x(this,O).active=Boolean(x(this,S).debug),$(this,U,Ae(r.appInfo)),$(this,M,qe(r.appInfo)),$(this,B,r.features||{})}hasFlag(r){return x(this,B)[r]||!1}async request({method:r,path:t,data:s,params:a},u){var g,y,f;const o=T(T({},x(this,S)),u),h=q(this,N,le).call(this,o,r),p=Math.max(0,o.maxRetries);for(let l=1;l<=p;l++){let i,d;const m=Date.now();if(x(this,O).debug(`${r} ${t}`),await Z.default({method:r,url:t,baseURL:o.host,headers:T(T({},h),J({"X-MAGICBELL-CLIENT-TELEMETRY":q(this,G,de).call(this)})),data:s,params:a,timeout:o.timeout}).then(c=>{i=c}).catch(c=>{const E=Re({method:r,baseURL:o.host,url:t,data:s,params:a,headers:h});x(this,O).error(`${c.message}: ${E}`),d=c,i=c.response}),q(this,j,he).call(this,i,{startTime:m}),q(this,R,fe).call(this,i,l,p)){const c=Number((g=i==null?void 0:i.headers)==null?void 0:g["retry-after"]);await De(q(this,H,me).call(this,l,c,o.maxRetryDelay));continue}if(d)throw we(T({code:d.code,name:d.name,message:d.message,type:d.type,status:i==null?void 0:i.status,statusText:i==null?void 0:i.statusText},(f=(y=i==null?void 0:i.data)==null?void 0:y.errors)==null?void 0:f[0]));return i.data}}}M=new WeakMap,U=new WeakMap,S=new WeakMap,O=new WeakMap,B=new WeakMap,k=new WeakMap,N=new WeakSet,le=function(r,t){let s=r.userHmac;!s&&r.apiSecret&&(r.userExternalId||r.userEmail)&&(s=ne(r.apiSecret,r.userExternalId||r.userEmail));const a=typeof document<"u";return He(J(L(T({"Accept-Version":"v2","Idempotency-Key":r.idempotencyKey||q(this,C,pe).call(this,t,r.maxRetries)},x(this,S).headers),{"User-Agent":a?null:x(this,M),"X-MAGICBELL-API-KEY":r.apiKey,"X-MAGICBELL-API-SECRET":r.apiSecret,"X-MAGICBELL-CLIENT-USER-AGENT":x(this,U),"X-MAGICBELL-USER-EMAIL":r.userEmail,"X-MAGICBELL-USER-EXTERNAL-ID":r.userExternalId,"X-MAGICBELL-USER-HMAC":s})),!0)},j=new WeakSet,he=function(r,{startTime:t}){if(!x(this,S).telemetry||!(r!=null&&r.status))return;const s=J(r.headers);x(this,k).push({id:s["X-Request-Id"],runtime:Number(s["X-Runtime"]),duration:Date.now()-t,status:r.status})},G=new WeakSet,de=function(){const r=x(this,k).pop();return r?JSON.stringify(r):null},R=new WeakSet,fe=function(r,t,s){return t>=s?!1:r?r.headers["should-retry"]?r.headers["should-retry"]==="true":r.status===409||r.status===503||r.status>=500&&r.request.method!=="POST":!0},H=new WeakSet,me=function(r,t=null,s){let u=Math.min(.5*Math.pow(r,2),s);return u*=.75*(1+Math.random()),u=Math.min(Math.max(.5,u),s),Number.isInteger(t)&&t<=60&&(u=Math.max(u,t)),u*1e3},C=new WeakSet,pe=function(r,t){if(!(r!=="POST"||t===0))return`magicbell-retry-${Ce()}`};exports.Client=ce;exports.createHmac=ne;exports.default=ce;
//# sourceMappingURL=magicbell.cjs.min.js.map
/**
* @license magicbell v1.7.1
* @license magicbell v1.7.2
*

@@ -71,3 +71,3 @@ * Copyright (c) MagicBell Inc. and its affiliates.

binding: "magicbell",
binding_version: "1.7.1",
binding_version: "1.7.2",
publisher: "magicbell"

@@ -74,0 +74,0 @@ };

/**
* @license magicbell v1.7.1
* @license magicbell v1.7.2
*

@@ -46,3 +46,3 @@ * Copyright (c) MagicBell Inc. and its affiliates.

binding: "magicbell",
binding_version: "1.7.1",
binding_version: "1.7.2",
publisher: "magicbell"

@@ -49,0 +49,0 @@ };

{
"name": "magicbell",
"version": "1.7.1",
"version": "1.7.2",
"description": "MagicBell API wrapper",

@@ -54,6 +54,6 @@ "author": "MagicBell <bot@magicbell.io> (https://magicbell.com)",

"devDependencies": {
"@magicbell/codegen": "^0.0.1",
"@magicbell/codegen": "^0.0.2",
"@size-limit/preset-small-lib": "^8.0.1",
"ast-types": "^0.14.2",
"json5": "^2.2.1",
"json5": "^2.2.3",
"openapi-types": "^12.0.2",

@@ -60,0 +60,0 @@ "portfinder": "^1.0.32",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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