email-octopus-ts
Advanced tools
Comparing version 1.1.1 to 1.2.0
# Changelog | ||
## [1.2.0](https://github.com/kartoffelkraft/email-octopus-ts/compare/v1.1.1...v1.2.0) (2023-10-17) | ||
### Features | ||
* deleteContact ([f6b357e](https://github.com/kartoffelkraft/email-octopus-ts/commit/f6b357ec627483e90d9d8b049995db525f85e9c5)) | ||
## [1.1.1](https://github.com/kartoffelkraft/email-octopus-ts/compare/v1.1.0...v1.1.1) (2023-09-11) | ||
@@ -4,0 +11,0 @@ |
@@ -30,10 +30,5 @@ import { ApiKeyInvalidError } from "./errors/ApiKeyInvalidError"; | ||
} | undefined) => Promise<import("./types").Contact[]>; | ||
createContact: (props: { | ||
listId: string; | ||
emailAddress: string; | ||
fields?: Record<string, unknown> | undefined; | ||
tags?: string[] | undefined; | ||
status?: "SUBSCRIBED" | "UNSUBSCRIBED" | "PENDING" | undefined; | ||
}) => Promise<import("./types").Contact>; | ||
createContact: (props: import("./lists/createContact").CreateContactProps) => Promise<import("./types").Contact>; | ||
deleteContact: (props: import("./lists/deleteContact").DeleteContactProps) => Promise<void>; | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import s from"axios";class e extends Error{constructor(s){super(s||"Your API key is invalid."),this.code="API_KEY_INVALID",this.message="Your API key is invalid.",this.message=s||"Your API key is invalid.",this.name="ApiKeyInvalidError"}}class t extends Error{constructor(s){super(s||"Generic email octopus error"),this.code="EMAIL_OCTOPUS_ERROR",this.message="Generic email octopus error",this.message=s||"Generic email octopus error",this.name="EmailOctopusError"}}class r extends Error{constructor(s){super(s||"Parameters are missing or invalid."),this.code="INVALID_PARAMETERS",this.message="Parameters are missing or invalid.",this.message=s||"Parameters are missing or invalid.",this.name="InvalidParametersError"}}class a extends Error{constructor(s){super(s||"A contact already exists with the supplied email address."),this.code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",this.message="A contact already exists with the supplied email address.",this.message=s||"A contact already exists with the supplied email address.",this.name="MemberExistsWithEmailAddressError"}}class o extends Error{constructor(s){super(s||"The requested endpoint does not exist."),this.code="NOT_FOUND",this.message="The requested endpoint does not exist.",this.message=s||"The requested endpoint does not exist.",this.name="NotFoundError"}}class i extends Error{constructor(s){super(s||"You're not authorised to perform that action."),this.code="UNAUTHORISED",this.message="You're not authorised to perform that action.",this.message=s||"You're not authorised to perform that action.",this.name="UnauthorisedError"}}function n(){return n=Object.assign?Object.assign.bind():function(s){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},n.apply(this,arguments)}class c extends Error{constructor(s){super(s||"An unknown error has occurred."),this.code="UNKNOWN",this.message="An unknown error has occurred.",this.message=s||"An unknown error has occurred.",this.name="UnknownError"}}const d=(s,t)=>{if("INVALID_PARAMETERS"===s.code)throw new r(t.message);if("API_KEY_INVALID"===s.code)throw new e(t.message);if("UNAUTHORISED"===s.code)throw new i(t.message);if("NOT_FOUND"===s.code)throw new o(t.message);if("UNKNOWN"===s.code)throw new c(t.message)},l=e=>async r=>{try{return(await s.post(`https://emailoctopus.com/api/1.6/lists/${r.listId}/contacts`,n({api_key:e,email_address:r.emailAddress},r.fields&&{fields:r.fields},r.tags&&{tags:r.tags},r.status&&{status:r.status}))).data}catch(e){if(s.isAxiosError(e)&&e.response){var o;const s=null==(o=e.response)?void 0:o.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===s.code)throw new a;d(e,s)}throw new t}},h=e=>async r=>{try{return(await s.post("https://emailoctopus.com/api/1.6/lists",{api_key:e,name:r.name})).data}catch(e){if(s.isAxiosError(e)&&e.response){var a;const s=null==(a=e.response)?void 0:a.data;d(e,s)}throw new t}},u=e=>async(r,a)=>{let o=(null!=a&&a.autoPaginate?1:r.page)||1,i="next-initial",n=[];try{do{const t=await s.get(`https://emailoctopus.com/api/1.6/lists/${r.listId}/contacts`,{params:{api_key:e,limit:r.limit||100,page:o}});n.push(...t.data.data),null!=a&&a.autoPaginate?(o+=1,i=t.data.paging.next):i=null}while(null!==i)}catch(e){if(s.isAxiosError(e)&&e.response){var c;const s=null==(c=e.response)?void 0:c.data;d(e,s)}throw new t}return n},p=e=>async r=>{try{return(await s.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:e,limit:r.limit||100,page:r.page||1}})).data}catch(e){if(s.isAxiosError(e)&&e.response){var a;const s=null==(a=e.response)?void 0:a.data;d(e,s)}throw new t}};class m extends Error{constructor(s){super(s||"The list could not be found."),this.code="LIST_NOT_FOUND",this.message="The list could not be found.",this.message=s||"The list could not be found.",this.name="ListNotFoundError"}}const g=e=>async r=>{try{return(await s.get(`https://emailoctopus.com/api/1.6/lists/${r.listId}`,{params:{api_key:e}})).data}catch(e){if(s.isAxiosError(e)&&e.response){var a;const s=null==(a=e.response)?void 0:a.data;if("LIST_NOT_FOUND"===s.code)throw new m;d(e,s)}throw new t}},E=s=>({lists:{getList:g(s),getAllLists:p(s),createList:h(s),getAllContacts:u(s),createContact:l(s)}});export{e as ApiKeyInvalidError,t as EmailOctopusError,r as InvalidParametersError,a as MemberExistsWithEmailAddressError,o as NotFoundError,i as UnauthorisedError,E as emailOctopus}; | ||
import s from"axios";class e extends Error{constructor(s){super(s||"Your API key is invalid."),this.code="API_KEY_INVALID",this.message="Your API key is invalid.",this.message=s||"Your API key is invalid.",this.name="ApiKeyInvalidError"}}class t extends Error{constructor(s){super(s||"Generic email octopus error"),this.code="EMAIL_OCTOPUS_ERROR",this.message="Generic email octopus error",this.message=s||"Generic email octopus error",this.name="EmailOctopusError"}}class r extends Error{constructor(s){super(s||"Parameters are missing or invalid."),this.code="INVALID_PARAMETERS",this.message="Parameters are missing or invalid.",this.message=s||"Parameters are missing or invalid.",this.name="InvalidParametersError"}}class o extends Error{constructor(s){super(s||"A contact already exists with the supplied email address."),this.code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",this.message="A contact already exists with the supplied email address.",this.message=s||"A contact already exists with the supplied email address.",this.name="MemberExistsWithEmailAddressError"}}class a extends Error{constructor(s){super(s||"The requested endpoint does not exist."),this.code="NOT_FOUND",this.message="The requested endpoint does not exist.",this.message=s||"The requested endpoint does not exist.",this.name="NotFoundError"}}class i extends Error{constructor(s){super(s||"You're not authorised to perform that action."),this.code="UNAUTHORISED",this.message="You're not authorised to perform that action.",this.message=s||"You're not authorised to perform that action.",this.name="UnauthorisedError"}}function n(){return n=Object.assign?Object.assign.bind():function(s){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},n.apply(this,arguments)}class c extends Error{constructor(s){super(s||"An unknown error has occurred."),this.code="UNKNOWN",this.message="An unknown error has occurred.",this.message=s||"An unknown error has occurred.",this.name="UnknownError"}}const d=(s,t)=>{if("INVALID_PARAMETERS"===t.code)throw new r(t.message);if("API_KEY_INVALID"===t.code)throw new e(t.message);if("UNAUTHORISED"===t.code)throw new i(t.message);if("NOT_FOUND"===t.code)throw new a(t.message);if("UNKNOWN"===t.code)throw new c(t.message)},l=e=>async r=>{try{return(await s.post(`https://emailoctopus.com/api/1.6/lists/${r.listId}/contacts`,n({api_key:e,email_address:r.emailAddress},r.fields&&{fields:r.fields},r.tags&&{tags:r.tags},r.status&&{status:r.status}))).data}catch(e){if(s.isAxiosError(e)&&e.response){var a;const s=null==(a=e.response)?void 0:a.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===s.code)throw new o;d(0,s)}throw new t}},h=e=>async r=>{try{return(await s.post("https://emailoctopus.com/api/1.6/lists",{api_key:e,name:r.name})).data}catch(e){if(s.isAxiosError(e)&&e.response){var o;const s=null==(o=e.response)?void 0:o.data;d(0,s)}throw new t}},u=e=>async(r,o)=>{let a=(null!=o&&o.autoPaginate?1:r.page)||1,i="next-initial",n=[];try{do{const t=await s.get(`https://emailoctopus.com/api/1.6/lists/${r.listId}/contacts`,{params:{api_key:e,limit:r.limit||100,page:a}});n.push(...t.data.data),null!=o&&o.autoPaginate?(a+=1,i=t.data.paging.next):i=null}while(null!==i)}catch(e){if(s.isAxiosError(e)&&e.response){var c;const s=null==(c=e.response)?void 0:c.data;d(0,s)}throw new t}return n},p=e=>async r=>{try{return(await s.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:e,limit:r.limit||100,page:r.page||1}})).data}catch(e){if(s.isAxiosError(e)&&e.response){var o;const s=null==(o=e.response)?void 0:o.data;d(0,s)}throw new t}};class m extends Error{constructor(s){super(s||"The list could not be found."),this.code="LIST_NOT_FOUND",this.message="The list could not be found.",this.message=s||"The list could not be found.",this.name="ListNotFoundError"}}const E=e=>async r=>{try{return(await s.get(`https://emailoctopus.com/api/1.6/lists/${r.listId}`,{params:{api_key:e}})).data}catch(e){if(s.isAxiosError(e)&&e.response){var o;const s=null==(o=e.response)?void 0:o.data;if("LIST_NOT_FOUND"===s.code)throw new m;d(0,s)}throw new t}};class g extends Error{constructor(s){super(s||"The contact could not be found."),this.code="MEMBER_NOT_FOUND",this.message="The contact could not be found.",this.message=s||"The contact could not be found.",this.name="MemberNotFoundError"}}const w=e=>async r=>{try{return void await s.post(`https://emailoctopus.com/api/1.6/lists/${r.listId}/contacts/${r.memberId}`,{api_key:e})}catch(e){if(s.isAxiosError(e)&&e.response){var o;const s=null==(o=e.response)?void 0:o.data;if("MEMBER_NOT_FOUND"===s.code)throw new g;d(0,s)}throw new t}},A=s=>({lists:{getList:E(s),getAllLists:p(s),createList:h(s),getAllContacts:u(s),createContact:l(s),deleteContact:w(s)}});export{e as ApiKeyInvalidError,t as EmailOctopusError,r as InvalidParametersError,o as MemberExistsWithEmailAddressError,a as NotFoundError,i as UnauthorisedError,A as emailOctopus}; | ||
//# sourceMappingURL=emailOctopus.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import t from"axios";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},e.apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function s(t,e,r){return s=i()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&o(i,r.prototype),i},s.apply(null,arguments)}function a(t){var e="function"==typeof Map?new Map:void 0;return a=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return s(t,arguments,n(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},a(t)}var u=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Your API key is invalid.")||this).code="API_KEY_INVALID",r.message="Your API key is invalid.",r.message=e||"Your API key is invalid.",r.name="ApiKeyInvalidError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),c=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Generic email octopus error")||this).code="EMAIL_OCTOPUS_ERROR",r.message="Generic email octopus error",r.message=e||"Generic email octopus error",r.name="EmailOctopusError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),f=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Parameters are missing or invalid.")||this).code="INVALID_PARAMETERS",r.message="Parameters are missing or invalid.",r.message=e||"Parameters are missing or invalid.",r.name="InvalidParametersError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),l=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"A contact already exists with the supplied email address.")||this).code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",r.message="A contact already exists with the supplied email address.",r.message=e||"A contact already exists with the supplied email address.",r.name="MemberExistsWithEmailAddressError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),h=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The requested endpoint does not exist.")||this).code="NOT_FOUND",r.message="The requested endpoint does not exist.",r.message=e||"The requested endpoint does not exist.",r.name="NotFoundError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),d=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"You're not authorised to perform that action.")||this).code="UNAUTHORISED",r.message="You're not authorised to perform that action.",r.message=e||"You're not authorised to perform that action.",r.name="UnauthorisedError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),p=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"An unknown error has occurred.")||this).code="UNKNOWN",r.message="An unknown error has occurred.",r.message=e||"An unknown error has occurred.",r.name="UnknownError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),v=function(t,e){if("INVALID_PARAMETERS"===t.code)throw new f(e.message);if("API_KEY_INVALID"===t.code)throw new u(e.message);if("UNAUTHORISED"===t.code)throw new d(e.message);if("NOT_FOUND"===t.code)throw new h(e.message);if("UNKNOWN"===t.code)throw new p(e.message)},m=function(r){return function(n){try{return Promise.resolve(function(o,i){try{var s=Promise.resolve(t.post("https://emailoctopus.com/api/1.6/lists/"+n.listId+"/contacts",e({api_key:r,email_address:n.emailAddress},n.fields&&{fields:n.fields},n.tags&&{tags:n.tags},n.status&&{status:n.status}))).then(function(t){return t.data})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===n.code)throw new l;v(e,n)}throw new c}))}catch(t){return Promise.reject(t)}}},y=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.post("https://emailoctopus.com/api/1.6/lists",{api_key:e,name:r.name})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;v(e,n)}throw new c}))}catch(t){return Promise.reject(t)}}};function g(t,e,r){if(!t.s){if(r instanceof E){if(!r.s)return void(r.o=g.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(g.bind(null,t,e),g.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}var E=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){var n=new t,o=this.s;if(o){var i=1&o?e:r;if(i){try{g(n,1,i(this.v))}catch(t){g(n,2,t)}return n}return this}return this.o=function(t){try{var o=t.v;1&t.s?g(n,1,e?e(o):o):r?g(n,1,r(o)):g(n,2,o)}catch(t){g(n,2,t)}},n},t}();function w(t){return t instanceof E&&1&t.s}var A=function(e){return function(r,n){try{var o=(null!=n&&n.autoPaginate?1:r.page)||1,i="next-initial",s=[],a=function(a,u){try{var c=function(){var a=function(t,e){var r;do{var n=t();if(n&&n.then){if(!w(n)){r=!0;break}n=n.v}var o=e();if(w(o)&&(o=o.v),!o)return n}while(!o.then);var i=new E,s=g.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;w(o=e())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=t())&&n.then){if(!w(n))return void n.then(a).then(void 0,s);n=n.v}}g(i,1,n)}function u(r){if(r){do{if((n=t())&&n.then){if(!w(n))return void n.then(a).then(void 0,s);n=n.v}if(w(r=e())&&(r=r.v),!r)return void g(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else g(i,1,n)}}(function(){return Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists/"+r.listId+"/contacts",{params:{api_key:e,limit:r.limit||100,page:o}})).then(function(t){s.push.apply(s,t.data.data),null!=n&&n.autoPaginate?(o+=1,i=t.data.paging.next):i=null})},function(){return null!==i});if(a&&a.then)return a.then(function(){})}()}catch(t){return u(t)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;v(e,n)}throw new c});return Promise.resolve(a&&a.then?a.then(function(t){return s}):s)}catch(t){return Promise.reject(t)}}},P=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:e,limit:r.limit||100,page:r.page||1}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;v(e,n)}throw new c}))}catch(t){return Promise.reject(t)}}},_=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The list could not be found.")||this).code="LIST_NOT_FOUND",r.message="The list could not be found.",r.message=e||"The list could not be found.",r.name="ListNotFoundError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),O=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists/"+r.listId,{params:{api_key:e}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;if("LIST_NOT_FOUND"===n.code)throw new _;v(e,n)}throw new c}))}catch(t){return Promise.reject(t)}}},I=function(t){return{lists:{getList:O(t),getAllLists:P(t),createList:y(t),getAllContacts:A(t),createContact:m(t)}}};export{u as ApiKeyInvalidError,c as EmailOctopusError,f as InvalidParametersError,l as MemberExistsWithEmailAddressError,h as NotFoundError,d as UnauthorisedError,I as emailOctopus}; | ||
import t from"axios";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},e.apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function s(t,e,r){return s=i()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var i=new(Function.bind.apply(t,n));return r&&o(i,r.prototype),i},s.apply(null,arguments)}function a(t){var e="function"==typeof Map?new Map:void 0;return a=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return s(t,arguments,n(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,t)},a(t)}var u=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Your API key is invalid.")||this).code="API_KEY_INVALID",r.message="Your API key is invalid.",r.message=e||"Your API key is invalid.",r.name="ApiKeyInvalidError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),c=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Generic email octopus error")||this).code="EMAIL_OCTOPUS_ERROR",r.message="Generic email octopus error",r.message=e||"Generic email octopus error",r.name="EmailOctopusError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),f=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Parameters are missing or invalid.")||this).code="INVALID_PARAMETERS",r.message="Parameters are missing or invalid.",r.message=e||"Parameters are missing or invalid.",r.name="InvalidParametersError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),l=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"A contact already exists with the supplied email address.")||this).code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",r.message="A contact already exists with the supplied email address.",r.message=e||"A contact already exists with the supplied email address.",r.name="MemberExistsWithEmailAddressError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),h=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The requested endpoint does not exist.")||this).code="NOT_FOUND",r.message="The requested endpoint does not exist.",r.message=e||"The requested endpoint does not exist.",r.name="NotFoundError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),d=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"You're not authorised to perform that action.")||this).code="UNAUTHORISED",r.message="You're not authorised to perform that action.",r.message=e||"You're not authorised to perform that action.",r.name="UnauthorisedError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),p=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"An unknown error has occurred.")||this).code="UNKNOWN",r.message="An unknown error has occurred.",r.message=e||"An unknown error has occurred.",r.name="UnknownError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),m=function(t,e){if("INVALID_PARAMETERS"===e.code)throw new f(e.message);if("API_KEY_INVALID"===e.code)throw new u(e.message);if("UNAUTHORISED"===e.code)throw new d(e.message);if("NOT_FOUND"===e.code)throw new h(e.message);if("UNKNOWN"===e.code)throw new p(e.message)},v=function(r){return function(n){try{return Promise.resolve(function(o,i){try{var s=Promise.resolve(t.post("https://emailoctopus.com/api/1.6/lists/"+n.listId+"/contacts",e({api_key:r,email_address:n.emailAddress},n.fields&&{fields:n.fields},n.tags&&{tags:n.tags},n.status&&{status:n.status}))).then(function(t){return t.data})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===n.code)throw new l;m(0,n)}throw new c}))}catch(t){return Promise.reject(t)}}},y=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.post("https://emailoctopus.com/api/1.6/lists",{api_key:e,name:r.name})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;m(0,n)}throw new c}))}catch(t){return Promise.reject(t)}}};function E(t,e,r){if(!t.s){if(r instanceof g){if(!r.s)return void(r.o=E.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(E.bind(null,t,e),E.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}var g=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){var n=new t,o=this.s;if(o){var i=1&o?e:r;if(i){try{E(n,1,i(this.v))}catch(t){E(n,2,t)}return n}return this}return this.o=function(t){try{var o=t.v;1&t.s?E(n,1,e?e(o):o):r?E(n,1,r(o)):E(n,2,o)}catch(t){E(n,2,t)}},n},t}();function w(t){return t instanceof g&&1&t.s}var _=function(e){return function(r,n){try{var o=(null!=n&&n.autoPaginate?1:r.page)||1,i="next-initial",s=[],a=function(a,u){try{var c=function(){var a=function(t,e){var r;do{var n=t();if(n&&n.then){if(!w(n)){r=!0;break}n=n.v}var o=e();if(w(o)&&(o=o.v),!o)return n}while(!o.then);var i=new g,s=E.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;w(o=e())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=t())&&n.then){if(!w(n))return void n.then(a).then(void 0,s);n=n.v}}E(i,1,n)}function u(r){if(r){do{if((n=t())&&n.then){if(!w(n))return void n.then(a).then(void 0,s);n=n.v}if(w(r=e())&&(r=r.v),!r)return void E(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else E(i,1,n)}}(function(){return Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists/"+r.listId+"/contacts",{params:{api_key:e,limit:r.limit||100,page:o}})).then(function(t){s.push.apply(s,t.data.data),null!=n&&n.autoPaginate?(o+=1,i=t.data.paging.next):i=null})},function(){return null!==i});if(a&&a.then)return a.then(function(){})}()}catch(t){return u(t)}return c&&c.then?c.then(void 0,u):c}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;m(0,n)}throw new c});return Promise.resolve(a&&a.then?a.then(function(t){return s}):s)}catch(t){return Promise.reject(t)}}},P=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:e,limit:r.limit||100,page:r.page||1}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;m(0,n)}throw new c}))}catch(t){return Promise.reject(t)}}},O=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The list could not be found.")||this).code="LIST_NOT_FOUND",r.message="The list could not be found.",r.message=e||"The list could not be found.",r.name="ListNotFoundError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),A=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.get("https://emailoctopus.com/api/1.6/lists/"+r.listId,{params:{api_key:e}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;if("LIST_NOT_FOUND"===n.code)throw new O;m(0,n)}throw new c}))}catch(t){return Promise.reject(t)}}},b=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The contact could not be found.")||this).code="MEMBER_NOT_FOUND",r.message="The contact could not be found.",r.message=e||"The contact could not be found.",r.name="MemberNotFoundError",r}return r(e,t),e}(/*#__PURE__*/a(Error)),I=function(e){return function(r){try{return Promise.resolve(function(n,o){try{var i=Promise.resolve(t.post("https://emailoctopus.com/api/1.6/lists/"+r.listId+"/contacts/"+r.memberId,{api_key:e})).then(function(){})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(t.isAxiosError(e)&&e.response){var r,n=null==(r=e.response)?void 0:r.data;if("MEMBER_NOT_FOUND"===n.code)throw new b;m(0,n)}throw new c}))}catch(t){return Promise.reject(t)}}},N=function(t){return{lists:{getList:A(t),getAllLists:P(t),createList:y(t),getAllContacts:_(t),createContact:v(t),deleteContact:I(t)}}};export{u as ApiKeyInvalidError,c as EmailOctopusError,f as InvalidParametersError,l as MemberExistsWithEmailAddressError,h as NotFoundError,d as UnauthorisedError,N as emailOctopus}; | ||
//# sourceMappingURL=emailOctopus.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],e):e((t||self).emailOctopusTs={},t.axios)}(this,function(t,e){function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=/*#__PURE__*/r(e);function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o.apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function c(t,e,r){return c=u()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&a(o,r.prototype),o},c.apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,s(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),a(r,t)},f(t)}var l=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Your API key is invalid.")||this).code="API_KEY_INVALID",r.message="Your API key is invalid.",r.message=e||"Your API key is invalid.",r.name="ApiKeyInvalidError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),d=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Generic email octopus error")||this).code="EMAIL_OCTOPUS_ERROR",r.message="Generic email octopus error",r.message=e||"Generic email octopus error",r.name="EmailOctopusError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),h=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Parameters are missing or invalid.")||this).code="INVALID_PARAMETERS",r.message="Parameters are missing or invalid.",r.message=e||"Parameters are missing or invalid.",r.name="InvalidParametersError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),p=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"A contact already exists with the supplied email address.")||this).code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",r.message="A contact already exists with the supplied email address.",r.message=e||"A contact already exists with the supplied email address.",r.name="MemberExistsWithEmailAddressError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),m=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The requested endpoint does not exist.")||this).code="NOT_FOUND",r.message="The requested endpoint does not exist.",r.message=e||"The requested endpoint does not exist.",r.name="NotFoundError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),v=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"You're not authorised to perform that action.")||this).code="UNAUTHORISED",r.message="You're not authorised to perform that action.",r.message=e||"You're not authorised to perform that action.",r.name="UnauthorisedError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),y=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"An unknown error has occurred.")||this).code="UNKNOWN",r.message="An unknown error has occurred.",r.message=e||"An unknown error has occurred.",r.name="UnknownError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),E=function(t,e){if("INVALID_PARAMETERS"===t.code)throw new h(e.message);if("API_KEY_INVALID"===t.code)throw new l(e.message);if("UNAUTHORISED"===t.code)throw new v(e.message);if("NOT_FOUND"===t.code)throw new m(e.message);if("UNKNOWN"===t.code)throw new y(e.message)},g=function(t){return function(e){try{return Promise.resolve(function(r,i){try{var s=Promise.resolve(n.default.post("https://emailoctopus.com/api/1.6/lists/"+e.listId+"/contacts",o({api_key:t,email_address:e.emailAddress},e.fields&&{fields:e.fields},e.tags&&{tags:e.tags},e.status&&{status:e.status}))).then(function(t){return t.data})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===r.code)throw new p;E(t,r)}throw new d}))}catch(t){return Promise.reject(t)}}},w=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.post("https://emailoctopus.com/api/1.6/lists",{api_key:t,name:e.name})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;E(t,r)}throw new d}))}catch(t){return Promise.reject(t)}}};function A(t,e,r){if(!t.s){if(r instanceof O){if(!r.s)return void(r.o=A.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(A.bind(null,t,e),A.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}var O=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){var n=new t,o=this.s;if(o){var i=1&o?e:r;if(i){try{A(n,1,i(this.v))}catch(t){A(n,2,t)}return n}return this}return this.o=function(t){try{var o=t.v;1&t.s?A(n,1,e?e(o):o):r?A(n,1,r(o)):A(n,2,o)}catch(t){A(n,2,t)}},n},t}();function P(t){return t instanceof O&&1&t.s}var _=function(t){return function(e,r){try{var o=(null!=r&&r.autoPaginate?1:e.page)||1,i="next-initial",s=[],a=function(a,u){try{var c=function(){var a=function(t,e){var r;do{var n=t();if(n&&n.then){if(!P(n)){r=!0;break}n=n.v}var o=e();if(P(o)&&(o=o.v),!o)return n}while(!o.then);var i=new O,s=A.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;P(o=e())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=t())&&n.then){if(!P(n))return void n.then(a).then(void 0,s);n=n.v}}A(i,1,n)}function u(r){if(r){do{if((n=t())&&n.then){if(!P(n))return void n.then(a).then(void 0,s);n=n.v}if(P(r=e())&&(r=r.v),!r)return void A(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else A(i,1,n)}}(function(){return Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists/"+e.listId+"/contacts",{params:{api_key:t,limit:e.limit||100,page:o}})).then(function(t){s.push.apply(s,t.data.data),null!=r&&r.autoPaginate?(o+=1,i=t.data.paging.next):i=null})},function(){return null!==i});if(a&&a.then)return a.then(function(){})}()}catch(t){return u(t)}return c&&c.then?c.then(void 0,u):c}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;E(t,r)}throw new d});return Promise.resolve(a&&a.then?a.then(function(t){return s}):s)}catch(t){return Promise.reject(t)}}},b=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:t,limit:e.limit||100,page:e.page||1}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;E(t,r)}throw new d}))}catch(t){return Promise.reject(t)}}},I=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The list could not be found.")||this).code="LIST_NOT_FOUND",r.message="The list could not be found.",r.message=e||"The list could not be found.",r.name="ListNotFoundError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),T=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists/"+e.listId,{params:{api_key:t}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;if("LIST_NOT_FOUND"===r.code)throw new I;E(t,r)}throw new d}))}catch(t){return Promise.reject(t)}}};t.ApiKeyInvalidError=l,t.EmailOctopusError=d,t.InvalidParametersError=h,t.MemberExistsWithEmailAddressError=p,t.NotFoundError=m,t.UnauthorisedError=v,t.emailOctopus=function(t){return{lists:{getList:T(t),getAllLists:b(t),createList:w(t),getAllContacts:_(t),createContact:g(t)}}}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("axios")):"function"==typeof define&&define.amd?define(["exports","axios"],e):e((t||self).emailOctopusTs={},t.axios)}(this,function(t,e){function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=/*#__PURE__*/r(e);function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o.apply(this,arguments)}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function c(t,e,r){return c=u()?Reflect.construct.bind():function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&a(o,r.prototype),o},c.apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return c(t,arguments,s(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),a(r,t)},f(t)}var l=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Your API key is invalid.")||this).code="API_KEY_INVALID",r.message="Your API key is invalid.",r.message=e||"Your API key is invalid.",r.name="ApiKeyInvalidError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),d=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Generic email octopus error")||this).code="EMAIL_OCTOPUS_ERROR",r.message="Generic email octopus error",r.message=e||"Generic email octopus error",r.name="EmailOctopusError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),h=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"Parameters are missing or invalid.")||this).code="INVALID_PARAMETERS",r.message="Parameters are missing or invalid.",r.message=e||"Parameters are missing or invalid.",r.name="InvalidParametersError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),p=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"A contact already exists with the supplied email address.")||this).code="MEMBER_EXISTS_WITH_EMAIL_ADDRESS",r.message="A contact already exists with the supplied email address.",r.message=e||"A contact already exists with the supplied email address.",r.name="MemberExistsWithEmailAddressError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),m=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The requested endpoint does not exist.")||this).code="NOT_FOUND",r.message="The requested endpoint does not exist.",r.message=e||"The requested endpoint does not exist.",r.name="NotFoundError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),v=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"You're not authorised to perform that action.")||this).code="UNAUTHORISED",r.message="You're not authorised to perform that action.",r.message=e||"You're not authorised to perform that action.",r.name="UnauthorisedError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),E=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"An unknown error has occurred.")||this).code="UNKNOWN",r.message="An unknown error has occurred.",r.message=e||"An unknown error has occurred.",r.name="UnknownError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),y=function(t,e){if("INVALID_PARAMETERS"===e.code)throw new h(e.message);if("API_KEY_INVALID"===e.code)throw new l(e.message);if("UNAUTHORISED"===e.code)throw new v(e.message);if("NOT_FOUND"===e.code)throw new m(e.message);if("UNKNOWN"===e.code)throw new E(e.message)},g=function(t){return function(e){try{return Promise.resolve(function(r,i){try{var s=Promise.resolve(n.default.post("https://emailoctopus.com/api/1.6/lists/"+e.listId+"/contacts",o({api_key:t,email_address:e.emailAddress},e.fields&&{fields:e.fields},e.tags&&{tags:e.tags},e.status&&{status:e.status}))).then(function(t){return t.data})}catch(t){return i(t)}return s&&s.then?s.then(void 0,i):s}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;if("MEMBER_EXISTS_WITH_EMAIL_ADDRESS"===r.code)throw new p;y(0,r)}throw new d}))}catch(t){return Promise.reject(t)}}},w=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.post("https://emailoctopus.com/api/1.6/lists",{api_key:t,name:e.name})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;y(0,r)}throw new d}))}catch(t){return Promise.reject(t)}}};function O(t,e,r){if(!t.s){if(r instanceof _){if(!r.s)return void(r.o=O.bind(null,t,e));1&e&&(e=r.s),r=r.v}if(r&&r.then)return void r.then(O.bind(null,t,e),O.bind(null,t,2));t.s=e,t.v=r;const n=t.o;n&&n(t)}}var _=/*#__PURE__*/function(){function t(){}return t.prototype.then=function(e,r){var n=new t,o=this.s;if(o){var i=1&o?e:r;if(i){try{O(n,1,i(this.v))}catch(t){O(n,2,t)}return n}return this}return this.o=function(t){try{var o=t.v;1&t.s?O(n,1,e?e(o):o):r?O(n,1,r(o)):O(n,2,o)}catch(t){O(n,2,t)}},n},t}();function P(t){return t instanceof _&&1&t.s}var A=function(t){return function(e,r){try{var o=(null!=r&&r.autoPaginate?1:e.page)||1,i="next-initial",s=[],a=function(a,u){try{var c=function(){var a=function(t,e){var r;do{var n=t();if(n&&n.then){if(!P(n)){r=!0;break}n=n.v}var o=e();if(P(o)&&(o=o.v),!o)return n}while(!o.then);var i=new _,s=O.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;P(o=e())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=t())&&n.then){if(!P(n))return void n.then(a).then(void 0,s);n=n.v}}O(i,1,n)}function u(r){if(r){do{if((n=t())&&n.then){if(!P(n))return void n.then(a).then(void 0,s);n=n.v}if(P(r=e())&&(r=r.v),!r)return void O(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else O(i,1,n)}}(function(){return Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists/"+e.listId+"/contacts",{params:{api_key:t,limit:e.limit||100,page:o}})).then(function(t){s.push.apply(s,t.data.data),null!=r&&r.autoPaginate?(o+=1,i=t.data.paging.next):i=null})},function(){return null!==i});if(a&&a.then)return a.then(function(){})}()}catch(t){return u(t)}return c&&c.then?c.then(void 0,u):c}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;y(0,r)}throw new d});return Promise.resolve(a&&a.then?a.then(function(t){return s}):s)}catch(t){return Promise.reject(t)}}},b=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists",{params:{api_key:t,limit:e.limit||100,page:e.page||1}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;y(0,r)}throw new d}))}catch(t){return Promise.reject(t)}}},I=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The list could not be found.")||this).code="LIST_NOT_FOUND",r.message="The list could not be found.",r.message=e||"The list could not be found.",r.name="ListNotFoundError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),T=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.get("https://emailoctopus.com/api/1.6/lists/"+e.listId,{params:{api_key:t}})).then(function(t){return t.data})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;if("LIST_NOT_FOUND"===r.code)throw new I;y(0,r)}throw new d}))}catch(t){return Promise.reject(t)}}},N=/*#__PURE__*/function(t){function e(e){var r;return(r=t.call(this,e||"The contact could not be found.")||this).code="MEMBER_NOT_FOUND",r.message="The contact could not be found.",r.message=e||"The contact could not be found.",r.name="MemberNotFoundError",r}return i(e,t),e}(/*#__PURE__*/f(Error)),x=function(t){return function(e){try{return Promise.resolve(function(r,o){try{var i=Promise.resolve(n.default.post("https://emailoctopus.com/api/1.6/lists/"+e.listId+"/contacts/"+e.memberId,{api_key:t})).then(function(){})}catch(t){return o(t)}return i&&i.then?i.then(void 0,o):i}(0,function(t){if(n.default.isAxiosError(t)&&t.response){var e,r=null==(e=t.response)?void 0:e.data;if("MEMBER_NOT_FOUND"===r.code)throw new N;y(0,r)}throw new d}))}catch(t){return Promise.reject(t)}}};t.ApiKeyInvalidError=l,t.EmailOctopusError=d,t.InvalidParametersError=h,t.MemberExistsWithEmailAddressError=p,t.NotFoundError=m,t.UnauthorisedError=v,t.emailOctopus=function(t){return{lists:{getList:T(t),getAllLists:b(t),createList:w(t),getAllContacts:A(t),createContact:g(t),deleteContact:x(t)}}}}); | ||
//# sourceMappingURL=emailOctopus.umd.js.map |
@@ -0,0 +0,0 @@ export declare class ApiKeyInvalidError extends Error { |
@@ -0,0 +0,0 @@ export declare class EmailOctopusError extends Error { |
@@ -0,0 +0,0 @@ export declare class InvalidParametersError extends Error { |
@@ -0,0 +0,0 @@ export declare class ListNotFoundError extends Error { |
@@ -0,0 +0,0 @@ export declare class MemberExistsWithEmailAddressError extends Error { |
@@ -0,0 +0,0 @@ export declare class NotFoundError extends Error { |
@@ -0,0 +0,0 @@ export declare class UnauthorisedError extends Error { |
@@ -0,0 +0,0 @@ export declare class UnknownError extends Error { |
@@ -1,3 +0,3 @@ | ||
import { Contact } from "src/types"; | ||
declare type CreateContactProps = { | ||
import { Contact } from "../types"; | ||
export type CreateContactProps = { | ||
listId: string; | ||
@@ -10,2 +10,1 @@ emailAddress: string; | ||
export declare const createContact: (apiKey: string) => (props: CreateContactProps) => Promise<Contact>; | ||
export {}; |
import { List } from "./types"; | ||
declare type CreateListProps = { | ||
type CreateListProps = { | ||
name: string; | ||
@@ -4,0 +4,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
import { Contact } from "src/types"; | ||
declare type GetAllContactsProps = { | ||
import { Contact } from "../types"; | ||
type GetAllContactsProps = { | ||
listId: string; | ||
@@ -7,3 +7,3 @@ limit?: number; | ||
}; | ||
declare type GetAllContactsOptions = { | ||
type GetAllContactsOptions = { | ||
autoPaginate?: boolean; | ||
@@ -10,0 +10,0 @@ }; |
import { List, Paging } from "./types"; | ||
declare type GetAllListProps = { | ||
type GetAllListProps = { | ||
limit?: number; | ||
page?: number; | ||
}; | ||
declare type AllLists = { | ||
type AllLists = { | ||
data: Array<List>; | ||
@@ -8,0 +8,0 @@ paging: Paging; |
import { List } from "./types"; | ||
declare type GetListProps = { | ||
type GetListProps = { | ||
listId: string; | ||
@@ -4,0 +4,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
declare type Field = { | ||
type Field = { | ||
tag: string; | ||
@@ -7,3 +7,3 @@ type: string; | ||
}; | ||
declare type Counts = { | ||
type Counts = { | ||
pending: number; | ||
@@ -13,3 +13,3 @@ subscribed: number; | ||
}; | ||
export declare type List = { | ||
export type List = { | ||
id: string; | ||
@@ -22,3 +22,3 @@ name: string; | ||
}; | ||
export declare type Paging = { | ||
export type Paging = { | ||
previous: string | null; | ||
@@ -25,0 +25,0 @@ next: string | null; |
@@ -1,6 +0,6 @@ | ||
export declare type ApiWideErrorResponses = { | ||
export type ApiWideErrorResponses = { | ||
code: "INVALID_PARAMETERS" | "API_KEY_INVALID" | "UNAUTHORISED" | "NOT_FOUND" | "UNKNOWN"; | ||
message: string; | ||
}; | ||
export declare type Contact = { | ||
export type Contact = { | ||
id: string; | ||
@@ -7,0 +7,0 @@ email_address: string; |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"type": "module", | ||
@@ -24,13 +24,20 @@ "source": "src/emailOctopus.ts", | ||
"dev": "microbundle watch", | ||
"prepare": "husky install" | ||
"prepare": "husky install", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.4", | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^20.8.6", | ||
"axios-mock-adapter": "^1.22.0", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^14.0.1", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^15.0.2", | ||
"microbundle": "^0.15.1", | ||
"prettier": "^3.0.3" | ||
"prettier": "^3.0.3", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.5.0" | ||
"axios": "^1.5.1" | ||
}, | ||
@@ -37,0 +44,0 @@ "lint-staged": { |
@@ -12,2 +12,3 @@ import { ApiKeyInvalidError } from "./errors/ApiKeyInvalidError"; | ||
import { getList } from "./lists/getList"; | ||
import { deleteContact } from "./lists/deleteContact" | ||
@@ -31,4 +32,5 @@ export { | ||
createContact: createContact(apiKey), | ||
deleteContact: deleteContact(apiKey), | ||
}, | ||
}; | ||
}; |
import axios from "axios"; | ||
import { EmailOctopusError } from "src/errors/EmailOctopusError"; | ||
import { MemberExistsWithEmailAddressError } from "src/errors/MemberExistsWithEmailAddressError"; | ||
import { handleApiGlobalErrors } from "src/handlers/apiGlobalErrorHandler"; | ||
import { ApiWideErrorResponses, Contact } from "src/types"; | ||
import { | ||
MemberExistsWithEmailAddressError, | ||
EmailOctopusError, | ||
} from "../emailOctopus"; | ||
import { handleApiGlobalAxiosErrors } from "../handlers/apiGlobalAxiosErrorHandler"; | ||
import { Contact, ApiWideErrorResponses } from "../types"; | ||
type CreateContactProps = { | ||
export type CreateContactProps = { | ||
listId: string; | ||
@@ -36,3 +38,4 @@ emailAddress: string; | ||
} catch (error) { | ||
if (axios.isAxiosError(error) && error.response) { | ||
const isAxiosError = axios.isAxiosError(error); | ||
if (isAxiosError && error.response) { | ||
const errorData = error.response?.data as | ||
@@ -44,3 +47,3 @@ | ApiWideErrorResponses | ||
} | ||
handleApiGlobalErrors(error, errorData); | ||
handleApiGlobalAxiosErrors(error, errorData); | ||
} | ||
@@ -47,0 +50,0 @@ throw new EmailOctopusError(); |
import axios from "axios"; | ||
import { EmailOctopusError } from "src/errors/EmailOctopusError"; | ||
import { handleApiGlobalErrors } from "src/handlers/apiGlobalErrorHandler"; | ||
import { ApiWideErrorResponses } from "src/types"; | ||
import { List } from "./types"; | ||
import { EmailOctopusError } from "../emailOctopus"; | ||
import { handleApiGlobalAxiosErrors } from "../handlers/apiGlobalAxiosErrorHandler"; | ||
import { ApiWideErrorResponses } from "../types"; | ||
@@ -26,3 +26,3 @@ type CreateListProps = { | ||
const errorData = error.response?.data as ApiWideErrorResponses; | ||
handleApiGlobalErrors(error, errorData); | ||
handleApiGlobalAxiosErrors(error, errorData); | ||
} | ||
@@ -29,0 +29,0 @@ throw new EmailOctopusError(); |
import axios from "axios"; | ||
import { handleApiGlobalErrors } from "src/handlers/apiGlobalErrorHandler"; | ||
import { ApiWideErrorResponses, Contact } from "src/types"; | ||
import { EmailOctopusError } from "../errors/EmailOctopusError"; | ||
import { Paging } from "./types"; | ||
import { handleApiGlobalAxiosErrors } from "../handlers/apiGlobalAxiosErrorHandler"; | ||
import { Contact, ApiWideErrorResponses } from "../types"; | ||
@@ -56,3 +56,3 @@ type GetAllContactsProps = { | ||
const errorData = error.response?.data as ApiWideErrorResponses; | ||
handleApiGlobalErrors(error, errorData); | ||
handleApiGlobalAxiosErrors(error, errorData); | ||
} | ||
@@ -59,0 +59,0 @@ throw new EmailOctopusError(); |
import axios from "axios"; | ||
import { EmailOctopusError } from "src/emailOctopus"; | ||
import { handleApiGlobalErrors } from "src/handlers/apiGlobalErrorHandler"; | ||
import { ApiWideErrorResponses } from "src/types"; | ||
import { List, Paging } from "./types"; | ||
import { EmailOctopusError } from "../emailOctopus"; | ||
import { handleApiGlobalAxiosErrors } from "../handlers/apiGlobalAxiosErrorHandler"; | ||
import { ApiWideErrorResponses } from "../types"; | ||
@@ -36,3 +36,3 @@ type GetAllListProps = { | ||
handleApiGlobalErrors(error, errorData); | ||
handleApiGlobalAxiosErrors(error, errorData); | ||
} | ||
@@ -39,0 +39,0 @@ throw new EmailOctopusError(); |
import axios from "axios"; | ||
import { EmailOctopusError } from "src/errors/EmailOctopusError"; | ||
import { ListNotFoundError } from "src/errors/ListNotFoundError"; | ||
import { handleApiGlobalErrors } from "src/handlers/apiGlobalErrorHandler"; | ||
import { ApiWideErrorResponses } from "src/types"; | ||
import { List } from "./types"; | ||
import { EmailOctopusError } from "../emailOctopus"; | ||
import { ListNotFoundError } from "../errors/ListNotFoundError"; | ||
import { handleApiGlobalAxiosErrors } from "../handlers/apiGlobalAxiosErrorHandler"; | ||
import { ApiWideErrorResponses } from "../types"; | ||
@@ -38,3 +38,3 @@ type GetListProps = { | ||
} | ||
handleApiGlobalErrors(error, errorData); | ||
handleApiGlobalAxiosErrors(error, errorData); | ||
} | ||
@@ -41,0 +41,0 @@ throw new EmailOctopusError(); |
@@ -17,4 +17,3 @@ { | ||
"types": ["@types/jest"], | ||
"incremental": true, | ||
"baseUrl": "." | ||
"incremental": true | ||
}, | ||
@@ -21,0 +20,0 @@ "include": ["./src/**/*.ts", "./src/**/*.tsx", "./src/*.js", "./src/**/*.js"], |
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
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
167024
65
1485
11
1
Updatedaxios@^1.5.1