UNPKG

wk-nmi

Version:

This is a simple utility package

433 lines (432 loc) 13.8 kB
var i = Object.defineProperty; var u = (r, t, s) => t in r ? i(r, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[t] = s; var n = (r, t, s) => (u(r, typeof t != "symbol" ? t + "" : t, s), s); class c { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async withDayConfig(t) { t.org = this.org; try { const s = await fetch( `${this.url}/subscriptions/day-frequency-config`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) } ); if (s.status === 401) throw new Error("Unauthorized access"); if (s.status === 422) return await s.json(); if (s.status === 400) return await s.json(); if (s.status === 200) return await s.json(); throw new Error(s.status.toString()); } catch (s) { throw console.log(s), new Error(s.toString()); } } async withMonthConfig(t) { t.org = this.org; try { const s = await fetch( `${this.url}/subscriptions/month-frequency-config`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) } ); if (s.status === 401) throw new Error("Unauthorized access"); if (s.status === 422) return await s.json(); if (s.status === 400) return await s.json(); if (s.status === 200) return await s.json(); throw new Error(s.status.toString()); } catch (s) { throw console.log(s), new Error(s.toString()); } } async pause(t, s) { const e = await fetch( `${this.url}/subscriptions/pause?org=${this.org}&subscription_id=${t}&pause=${s}`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } async cancel(t) { const s = await fetch( `${this.url}/subscriptions/cancel-subscription?org=${this.org}&subscription_id=${t}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async id(t) { const s = await fetch( `${this.url}/subscriptions?org=${this.org}&subscription_id=${t}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async all(t) { const s = await fetch( `${this.url}/subscriptions/by-user-id?org=${this.org}&user_id=${t}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async update_month_subscription(t, s, e) { const o = await fetch( `${this.url}/subscriptions/update-month-subscription?org=${this.org}&customer_vault_id=${s}&subscription_id=${t}`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(e) } ); return o.status === 401 ? { response: null, status: o.status, message: "Unauthorized" } : { response: await o.json(), status: o.status }; } async update_day_subscription(t, s, e) { const o = await fetch( `${this.url}/subscriptions/update-day-subscription?org=${this.org}&customer_vault_id=${s}&subscription_id=${t}`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(e) } ); return o.status === 401 ? { response: null, status: o.status, message: "Unauthorized" } : { response: await o.json(), status: o.status }; } } class p { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async all() { const t = await fetch(`${this.url}/plans/all-plans?org=${this.org}`, { headers: { Authorization: `Bearer ${this.apikey}` } }); return t.status === 401 ? { response: null, status: t.status, message: "Unauthorized" } : { response: await t.json(), status: 200, message: "Success" }; } async id(t) { const s = await fetch(`${this.url}/plans/plan-id/${t}?org=${this.org}`, { headers: { Authorization: `Bearer ${this.apikey}` } }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async withMonthConfig(t) { const s = { org: this.org, customPlan: t }, e = await fetch(`${this.url}/plans/month-frequency-config`, { method: "POST", body: JSON.stringify(s), headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } }); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } async editMonthConfig(t) { const s = { org: this.org, customPlan: t }, e = await fetch(`${this.url}/plans/edit-month-frequency-config`, { method: "PUT", body: JSON.stringify(s), headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } }); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } async withDayConfig(t) { const s = { org: this.org, customPlan: t }, e = await fetch(`${this.url}/plans/day-frequency-config`, { method: "POST", body: JSON.stringify(s), headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } }); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } async editDayConfig(t) { const s = { org: this.org, customPlan: t }, e = await fetch(`${this.url}/plans/edit-day-frequency-config`, { method: "PUT", body: JSON.stringify(s), headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } }); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } } class l { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async add(t) { t.org = this.org; const s = await fetch(`${this.url}/customer-vault/add`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } } class g { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async add(t) { t.org = this.org; const s = await fetch(`${this.url}/configs/add-config`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async update(t) { t.org = this.org; const s = await fetch(`${this.url}/configs/update-config`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async get() { const t = await fetch(`${this.url}/configs/get-config?org=${this.org}`, { headers: { Authorization: `Bearer ${this.apikey}` } }); return t.status === 401 ? { response: null, status: t.status, message: "Unauthorized" } : { response: await t.json(), status: t.status }; } async delete() { const t = await fetch( `${this.url}/configs/delete-config?org=${this.org}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return t.status === 401 ? { response: null, status: t.status, message: "Unauthorized" } : { response: await t.json(), status: t.status }; } } class d { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async add(t) { t.org = this.org; const s = await fetch(`${this.url}/billing/add`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async updateBillingInfo(t) { t.org = this.org; const s = await fetch(`${this.url}/billing/update-billing-info`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async delete(t, s) { const e = await fetch( `${this.url}/billing/delete?org=${this.org}&user_id=${t}&billing_id=${s}`, { method: "DELETE", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return e.status === 401 ? { response: null, status: e.status, message: "Unauthorized" } : { response: await e.json(), status: e.status }; } async changePriority(t) { t.org = this.org; const s = await fetch(`${this.url}/billing/change-priority`, { method: "PUT", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` }, body: JSON.stringify(t) }); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } async info(t) { const s = await fetch( `${this.url}/billing/billing-of-user?org=${this.org}&user_id=${t}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apikey}` } } ); return s.status === 401 ? { response: null, status: s.status, message: "Unauthorized" } : { response: await s.json(), status: s.status }; } } class y { constructor(t, s, e) { n(this, "url"); n(this, "org"); n(this, "apikey"); this.url = t, this.org = s, this.apikey = e; } async withCustomerVault(t) { t.org = this.org; try { const s = await fetch(`${this.url}/payment/with-customer-vault`, { method: "POST", headers: { Authorization: `Bearer ${this.apikey}`, "Content-Type": "application/json" }, body: JSON.stringify(t) }); if (s.status === 401) throw new Error("Unauthorized access"); if (s.status === 422) return await s.json(); if (s.status === 400) return await s.json(); if (s.status === 200) return await s.json(); throw new Error(s.status.toString()); } catch (s) { throw console.log(s), new Error(s.toString()); } } async withToken(t) { t.org = this.org; try { const s = await fetch(`${this.url}/payment/with-token`, { method: "POST", headers: { Authorization: `Bearer ${this.apikey}`, "Content-Type": "application/json" }, body: JSON.stringify(t) }); if (s.status === 401) throw new Error("Unauthorized access"); if (s.status === 422) return await s.json(); if (s.status === 400) return await s.json(); if (s.status === 200) return await s.json(); throw new Error(s.status.toString()); } catch (s) { throw console.log(s), new Error(s.toString()); } } } export { d as Billing, g as Config, l as CustomerVault, y as Pay, p as Plans, c as Subs };