@kustomer/apps-common
Advanced tools
Comparing version 0.1.39 to 0.1.40
@@ -13,3 +13,3 @@ import { AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
readonly logger?: KLogger; | ||
readonly proxy?: string; | ||
readonly proxy?: boolean; | ||
} | ||
@@ -16,0 +16,0 @@ export declare class APIBase { |
@@ -31,13 +31,5 @@ import axios from 'axios'; | ||
new Logger(`kapp:${this.options.app}:${this.name}`); | ||
const axiosOptions = {}; | ||
if (this.options.proxy) { | ||
const proxy = new URL(this.options.proxy); | ||
const protocol = proxy.protocol.replace(/:/g, ''); | ||
axiosOptions.proxy = { | ||
protocol, | ||
host: proxy.host, | ||
port: protocol === 'http' ? 80 : 433 | ||
}; | ||
} | ||
this.axios = axios.create(axiosOptions); | ||
this.axios = axios.create({ | ||
baseURL: this.options.proxy ? undefined : this.baseUrls.api | ||
}); | ||
this.axios.interceptors.request.use(this._onRequest.bind(this)); | ||
@@ -44,0 +36,0 @@ } |
@@ -12,5 +12,5 @@ import { namespace } from '../utils'; | ||
const fullName = `${this.options.app}.app.${namespace(name, this.options)}`; | ||
const res = await this.axios.post(`${this.baseUrls.api}/v1/commands/${fullName}/run`, body); | ||
const res = await this.axios.post(`/v1/commands/${fullName}/run`, body); | ||
return res.data.data.attributes; | ||
} | ||
} |
@@ -25,2 +25,7 @@ import { WithID } from '../common'; | ||
locale?: string | undefined; | ||
/** | ||
* get a customer by phone | ||
* @param phone customer phone (unique) | ||
* @returns | ||
*/ | ||
timeZone?: string | undefined; | ||
@@ -27,0 +32,0 @@ tags?: string[] | undefined; |
@@ -13,3 +13,3 @@ import { namespace } from '../utils'; | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/customers/id=${id}`); | ||
const res = await this.axios.get(`/v1/customers/id=${id}`); | ||
return { | ||
@@ -32,3 +32,3 @@ id: res.data.data.id, | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/customers/externalId=${externalId}`); | ||
const res = await this.axios.get(`/v1/customers/externalId=${externalId}`); | ||
return { | ||
@@ -51,3 +51,3 @@ id: res.data.data.id, | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/customers/email=${email}`); | ||
const res = await this.axios.get(`/v1/customers/email=${email}`); | ||
return { | ||
@@ -71,3 +71,3 @@ id: res.data.data.id, | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/customers/phone=${phone}`); | ||
const res = await this.axios.get(`/v1/customers/phone=${phone}`); | ||
return { | ||
@@ -88,3 +88,3 @@ id: res.data.data.id, | ||
async create(args) { | ||
const res = await this.axios.post(`${this.baseUrls.api}/v1/customers`, args); | ||
const res = await this.axios.post(`/v1/customers`, args); | ||
return { | ||
@@ -100,3 +100,3 @@ id: res.data.data.id, | ||
async update(id, args) { | ||
const res = await this.axios.patch(`${this.baseUrls.api}/v1/customers/${id}`, args); | ||
const res = await this.axios.patch(`/v1/customers/${id}`, args); | ||
return { | ||
@@ -113,3 +113,3 @@ id: res.data.data.id, | ||
async createKObject(id, klass, object) { | ||
const res = await this.axios.post(`${this.baseUrls.api}/v1/customers/${id}/klasses/${namespace(klass, this.options)}`, object); | ||
const res = await this.axios.post(`/v1/customers/${id}/klasses/${namespace(klass, this.options)}`, object); | ||
return { | ||
@@ -116,0 +116,0 @@ id: res.data.data.id, |
@@ -14,3 +14,3 @@ import { namespace } from '../utils'; | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/klasses/${namespace(klass, this.options)}/externalId=${externalId}`); | ||
const res = await this.axios.get(`/v1/klasses/${namespace(klass, this.options)}/externalId=${externalId}`); | ||
return { | ||
@@ -33,3 +33,3 @@ id: res.data.data.id, | ||
async update(id, klass, args) { | ||
const res = await this.axios.put(`${this.baseUrls.api}/v1/klasses/${namespace(klass, this.options)}/${id}`, args); | ||
const res = await this.axios.put(`/v1/klasses/${namespace(klass, this.options)}/${id}`, args); | ||
return { | ||
@@ -36,0 +36,0 @@ id: res.data.data.id, |
@@ -34,3 +34,3 @@ import { APIBase } from './base'; | ||
this._log[level](message); | ||
await this.axios.post(`${this.baseUrls.api}/v1/logs`, { | ||
await this.axios.post('/v1/logs', { | ||
level, | ||
@@ -37,0 +37,0 @@ code: `${options?.code || 111}`, |
@@ -12,3 +12,3 @@ import { APIBase } from './base'; | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/messages/${id}`); | ||
const res = await this.axios.get(`/v1/messages/${id}`); | ||
return { | ||
@@ -15,0 +15,0 @@ id: res.data.data.id, |
@@ -29,3 +29,3 @@ import { APIBase } from './base'; | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/orgs/current`); | ||
const res = await this.axios.get('/v1/orgs/current'); | ||
return { | ||
@@ -48,3 +48,3 @@ id: res.data.data.id, | ||
try { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/orgs/${id}`); | ||
const res = await this.axios.get(`/v1/orgs/${id}`); | ||
return { | ||
@@ -51,0 +51,0 @@ id: res.data.data.id, |
@@ -10,3 +10,3 @@ import { APIBase } from './base'; | ||
async get() { | ||
const res = await this.axios.get(`${this.baseUrls.api}/v1/apps/settings`); | ||
const res = await this.axios.get('/v1/apps/settings'); | ||
const settings = {}; | ||
@@ -26,4 +26,4 @@ Object.keys(res.data.data).map((category) => { | ||
async set(settings) { | ||
await this.axios.put(`${this.baseUrls.api}/v1/apps/settings`, settings); | ||
await this.axios.put('/v1/apps/settings', settings); | ||
} | ||
} |
{ | ||
"name": "@kustomer/apps-common", | ||
"version": "0.1.39", | ||
"version": "0.1.40", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
130145
1563