diff --git a/README.md b/README.md index e0245d6..7c2c031 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ const userClient = new OneSignal.UserClient('userAuthKey', { apiRoot: 'https://o https://documentation.onesignal.com/reference/create-notification ```ts -.createNotification(body: CreateNotificationBody): Promise +.createNotification(body: CreateNotificationBody, customOptions?: ): Promise ``` Please read the sections above to learn how to create a `Client` object. @@ -137,9 +137,13 @@ const notification = { ] }; +const customOptions = { + timeout: 7000, +} + // using async/await try { - const response = await client.createNotification(notification); + const response = await client.createNotification(notification, customOptions); console.log(response.body.id); } catch (e) { if (e instanceof OneSignal.HTTPError) { diff --git a/src/client.ts b/src/client.ts index 1e184d2..bf14934 100644 --- a/src/client.ts +++ b/src/client.ts @@ -34,6 +34,8 @@ import { EditTagsBody, } from './types'; +import { Options as requestOptions } from 'request'; + export class Client { public appId: string; public apiKey: string; @@ -54,11 +56,11 @@ export class Client { * @param {CreateNotificationBody} body Request body. * @returns {Promise} Http response of One Signal server. */ - public createNotification(body: CreateNotificationBody): Promise { + public createNotification(body: CreateNotificationBody, customOptions?: Partial): Promise { // eslint-disable-next-line @typescript-eslint/camelcase const postBody = { ...{ [APP_ID_FIELD_NAME]: this.appId }, ...body }; const uri = `${this.options.apiRoot}/${NOTIFICATIONS_PATH}`; - return basicAuthRequest(uri, 'POST', this.apiKey, postBody); + return basicAuthRequest(uri, 'POST', this.apiKey, postBody, customOptions); } /** diff --git a/src/utils.ts b/src/utils.ts index 502827b..d83e969 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -76,6 +76,7 @@ export const basicAuthRequest = function basicAuthHTTPRequest( method: string, authKey: string, body?: {}, + customOptions?: Partial, ): Promise { const options: request.Options = { uri, @@ -85,6 +86,7 @@ export const basicAuthRequest = function basicAuthHTTPRequest( Authorization: `Basic ${authKey}`, }, json: true, + ...customOptions, }; if (body) {