@twilio/flex-plugins-library-utils
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -32,2 +32,12 @@ # Changelog | ||
- Added new methods in `InteractionApiUtils`. | ||
- Added new methods in `PhoneNumberUtils`. | ||
- Added new methods in `PhoneNumberUtils`. | ||
## 1.1.1 | ||
**v1.1.1** of **`@twilio/flex-plugins-library-utils`**! is released | ||
Fixed bugs in post API calls | ||
### Fixed | ||
- Fix API post calls |
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
interface AxiosMethodArguments { | ||
url: string; | ||
config?: AxiosRequestConfig; | ||
params?: URLSearchParams; | ||
} | ||
export default abstract class TwilioAPI { | ||
@@ -6,6 +11,7 @@ protected api: AxiosInstance; | ||
private request; | ||
protected get<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>>; | ||
protected post<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>>; | ||
protected put<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>>; | ||
protected delete<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>>; | ||
protected get<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>>; | ||
protected post<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>>; | ||
protected put<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>>; | ||
protected delete<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>>; | ||
} | ||
export {}; |
@@ -26,7 +26,7 @@ "use strict"; | ||
} | ||
request(method, url, config) { | ||
request(method, url, config, params) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const response = yield this.api[method](url, config); | ||
const response = yield this.api[method](url, params, config); | ||
return response; | ||
@@ -40,20 +40,20 @@ } | ||
} | ||
get(url, config) { | ||
get({ url, config, params }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.request("get" /* HTTP_METHODS.GET */, url, config); | ||
return this.request("get" /* HTTP_METHODS.GET */, url, config, params); | ||
}); | ||
} | ||
post(url, config) { | ||
post({ url, config, params }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.request("post" /* HTTP_METHODS.POST */, url, config); | ||
return this.request("post" /* HTTP_METHODS.POST */, url, config, params); | ||
}); | ||
} | ||
put(url, config) { | ||
put({ url, config, params }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.request("put" /* HTTP_METHODS.PUT */, url, config); | ||
return this.request("put" /* HTTP_METHODS.PUT */, url, config, params); | ||
}); | ||
} | ||
delete(url, config) { | ||
delete({ url, config, params }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.request("delete" /* HTTP_METHODS.DELETE */, url, config); | ||
return this.request("delete" /* HTTP_METHODS.DELETE */, url, config, params); | ||
}); | ||
@@ -60,0 +60,0 @@ } |
@@ -27,7 +27,6 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = yield this.post(this.tasksBaseUrl, { | ||
data: postData, | ||
const response = yield this.post({ | ||
url: this.tasksBaseUrl, | ||
config: {}, | ||
params: attributes, | ||
}); | ||
@@ -43,3 +42,5 @@ return { | ||
const url = `${this.tasksBaseUrl}/${taskSid}`; | ||
const response = yield this.get(url); | ||
const response = yield this.get({ | ||
url | ||
}); | ||
return { | ||
@@ -54,8 +55,8 @@ data: response.data, | ||
const url = `${this.tasksBaseUrl}/${taskSid}`; | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = yield this.post(url, { | ||
data: postData, | ||
headers, | ||
const response = yield this.post({ | ||
url, | ||
config: { | ||
headers | ||
}, | ||
params: attributes, | ||
}); | ||
@@ -70,3 +71,3 @@ return { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.get(this.tasksBaseUrl); | ||
const response = yield this.get({ url: this.tasksBaseUrl }); | ||
return { | ||
@@ -80,7 +81,6 @@ data: response.data, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = yield this.post(this.workersBaseUrl, { | ||
data: postData, | ||
const response = yield this.post({ | ||
url: this.workersBaseUrl, | ||
config: {}, | ||
params: attributes, | ||
}); | ||
@@ -95,3 +95,5 @@ return { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield this.get(this.workersBaseUrl); | ||
const response = yield this.get({ | ||
url: this.workersBaseUrl | ||
}); | ||
return { | ||
@@ -98,0 +100,0 @@ data: response.data, |
{ | ||
"name": "@twilio/flex-plugins-library-utils", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Flex Plugins Library Utils", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
import { HTTP_METHODS } from '../../constants/api'; | ||
interface AxiosMethodArguments { | ||
url: string; | ||
config?: AxiosRequestConfig; | ||
params?: URLSearchParams; | ||
} | ||
export default abstract class TwilioAPI { | ||
@@ -17,5 +23,10 @@ protected api: AxiosInstance; | ||
private async request(method: string, url: string, config?: AxiosRequestConfig): Promise<AxiosResponse> { | ||
private async request( | ||
method: string, | ||
url: string, | ||
config?: AxiosRequestConfig, | ||
params?: URLSearchParams, | ||
): Promise<AxiosResponse> { | ||
try { | ||
const response = await this.api[method](url, config); | ||
const response = await this.api[method](url, params, config); | ||
return response; | ||
@@ -28,17 +39,17 @@ } catch (error) { | ||
protected async get<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.GET, url, config) as Promise<AxiosResponse<R>>; | ||
protected async get<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.GET, url, config, params) as Promise<AxiosResponse<R>>; | ||
} | ||
protected async post<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.POST, url, config) as Promise<AxiosResponse<R>>; | ||
protected async post<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.POST, url, config, params) as Promise<AxiosResponse<R>>; | ||
} | ||
protected async put<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.PUT, url, config) as Promise<AxiosResponse<R>>; | ||
protected async put<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.PUT, url, config, params) as Promise<AxiosResponse<R>>; | ||
} | ||
protected async delete<R>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.DELETE, url, config) as Promise<AxiosResponse<R>>; | ||
protected async delete<R>({ url, config, params }: AxiosMethodArguments): Promise<AxiosResponse<R>> { | ||
return this.request(HTTP_METHODS.DELETE, url, config, params) as Promise<AxiosResponse<R>>; | ||
} | ||
} |
@@ -22,8 +22,7 @@ import { AxiosHeaderValue, AxiosHeaders } from 'axios'; | ||
public async createTask(attributes: URLSearchParams): Promise<ApiResponse<TaskInstance>> { | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = await this.post<TaskInstance>(this.tasksBaseUrl, { | ||
data: postData, | ||
const response = await this.post<TaskInstance>({ | ||
url: this.tasksBaseUrl, | ||
config: {}, | ||
params: attributes, | ||
}); | ||
@@ -40,3 +39,5 @@ | ||
const response = await this.get<TaskInstance>(url); | ||
const response = await this.get<TaskInstance>({ | ||
url | ||
}); | ||
return { | ||
@@ -54,9 +55,9 @@ data: response.data, | ||
const url = `${this.tasksBaseUrl}/${taskSid}`; | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = await this.post<TaskInstance>(url, { | ||
data: postData, | ||
headers, | ||
const response = await this.post<TaskInstance>({ | ||
url, | ||
config: { | ||
headers | ||
}, | ||
params: attributes, | ||
}); | ||
@@ -71,3 +72,3 @@ | ||
public async getAllTasks(): Promise<ApiResponse<Array<TaskInstance>>> { | ||
const response = await this.get<Array<TaskInstance>>(this.tasksBaseUrl); | ||
const response = await this.get<Array<TaskInstance>>({url: this.tasksBaseUrl}); | ||
return { | ||
@@ -80,8 +81,7 @@ data: response.data, | ||
public async createWorker(attributes: URLSearchParams): Promise<ApiResponse<WorkerInstance>> { | ||
const postData = { | ||
attributes, | ||
}; | ||
const response = await this.post<WorkerInstance>(this.workersBaseUrl, { | ||
data: postData, | ||
const response = await this.post<WorkerInstance>({ | ||
url: this.workersBaseUrl, | ||
config: {}, | ||
params: attributes, | ||
}); | ||
@@ -96,3 +96,5 @@ | ||
public async getAllWorkers(): Promise<ApiResponse<Array<WorkerInstance>>> { | ||
const response = await this.get<Array<WorkerInstance>>(this.workersBaseUrl); | ||
const response = await this.get<Array<WorkerInstance>>({ | ||
url: this.workersBaseUrl | ||
}); | ||
return { | ||
@@ -99,0 +101,0 @@ data: response.data, |
@@ -593,2 +593,3 @@ import { Twilio } from 'twilio'; | ||
const updatedTaskAttributes = omitBy(merge({}, JSON.parse(task.attributes), JSON.parse(attributesUpdate)), isNil); | ||
// if-match the revision number to ensure | ||
@@ -595,0 +596,0 @@ // no update collisions |
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
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
273477
4902