From d3487eab0ccaa26a5fa66b03a05830ef44cc7ffd Mon Sep 17 00:00:00 2001 From: QuisEgoSum Date: Fri, 24 Jun 2022 19:27:21 +0300 Subject: [PATCH] Update index.d.ts, update the typescript version from ^4.0.3 to ^4.1.5 to support Lowercase and Uppercase --- dist/index.d.ts | 186 ++++++++++++++++++++++++++++++++++++++++++++---- index.d.ts | 186 ++++++++++++++++++++++++++++++++++++++++++++---- package.json | 4 +- 3 files changed, 347 insertions(+), 29 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index cada0c1..51134b2 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,22 +1,180 @@ -enum APIVersion { - V1 = "V1", +type SnakeToCamelCase = S extends `${infer P1}_${infer P2}${infer P3}` + ? `${Lowercase}${Uppercase}${SnakeToCamelCase}` + : Lowercase + +type ObjectSnakeToCamelCase = { + [K in keyof T as SnakeToCamelCase]: T[K] extends Record ? ObjectSnakeToCamelCase : T[K] } -interface GreenSMSRequestConfig { - username?: string; - password?: string; - token?: string; - useTokenForRequests?: boolean; - version?: APIVersion; +declare enum APIVersion { + V1 = "V1", } -declare class GreenSMS { +/** + * @summary Initialize GreenSMS Client Options + */ +export interface GreenSMSOptions { + /** + * @summary Username. Required when AuthToken is not passed + */ + user?: string | null + /** + * @summary Password. Request when AuthToken is not passed + */ + pass?: string | null /** - * Creates a GreenSMS Client Object - * @constructor - * @param GreenSMSOptions + * @summary AuthToken. Required when Username/Password not passed */ - constructor(GreenSMSOptions); + token?: string | null + /** + * @summary Create Auth Token after login and use for subsequent requests + */ + useTokenForRequests?: boolean + /** + * @summary API Version to be used + */ + version?: APIVersion + /** + * @summary Lead the response properties to camel case + */ + camelCaseResponse?: CC +} + +export type StatusCode = 0 | 1 | 2 | 4 | 8 | 16 | 34 + +export type HlrStatus = 1 | 2 | 4 | 8 | 16 + +declare enum Status { + "Status not ready" = "Status not ready", + "Call success" = "Call success", + "Call failure" = "Call failure", + "Call buffered" = "Call buffered", + "Call accepted" = "Call accepted", + "Call rejected" = "Call rejected", + "Status request expired" = "Status request expired" +} + +export interface StatusResponse { + time: string, + status_code: StatusCode, + status: Status +} + +export interface RequestIdResponse { + request_id: string +} + +export interface ToParams { + to: string +} + +export interface StatusParams { + id: string + extended: boolean +} + +export interface AccountTokenParams { + expire?: number +} + +export interface AccountTokenResponse { + access_token: string +} + +export interface CallSendResponse { + request_id: string + code: string + request_status: string +} + +export interface WhoisLookupResponse { + def: number + begin: number + end: number + capacity: number + operator: string + region: string + is_transferred: boolean +} + +export interface HlrStatusResponse { + status: HlrStatus + imsi: number + msc: number + mcc: number + mnc: number + cn: string + net: string +} + +export interface VoiceSendParams { + to: string + txt: string + lang?: 'ru' | 'en' +} + +export interface PaySendParams { + to: string + amount: number + tag?: string +} + +export interface SMSSendParams { + to: string + txt: string + from?: string + tag?: string + hidden?: string +} + +export interface ViberSendParams { + to: string + txt: string + from?: string + cascade?: 'sms' | 'voice' +} + +declare class GreenSMS { + + account: { + token: (params?: AccountTokenParams) => Promise : AccountTokenResponse> + } + + call: { + send: (params: ToParams) => Promise : CallSendResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + whois: { + lookup: (params: ToParams) => Promise : WhoisLookupResponse> + } + + hlr: { + send: (params: ToParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : HlrStatusResponse> + } + + voice: { + send: (params: VoiceSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + pay: { + send: (params: PaySendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + sms: { + send: (params: SMSSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + viber: { + send: (params: ViberSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + constructor(options: GreenSMSOptions) } -export { GreenSMS, GreenSMSRequestConfig }; +export default GreenSMS diff --git a/index.d.ts b/index.d.ts index b212f8d..51134b2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,20 +1,180 @@ -enum APIVersion { - V1 = "V1", +type SnakeToCamelCase = S extends `${infer P1}_${infer P2}${infer P3}` + ? `${Lowercase}${Uppercase}${SnakeToCamelCase}` + : Lowercase + +type ObjectSnakeToCamelCase = { + [K in keyof T as SnakeToCamelCase]: T[K] extends Record ? ObjectSnakeToCamelCase : T[K] } -export interface GreenSMSRequestConfig { - username?: string; - password?: string; - token?: string; - useTokenForRequests?: boolean; - version?: APIVersion; +declare enum APIVersion { + V1 = "V1", } -export declare class GreenSMS { +/** + * @summary Initialize GreenSMS Client Options + */ +export interface GreenSMSOptions { + /** + * @summary Username. Required when AuthToken is not passed + */ + user?: string | null + /** + * @summary Password. Request when AuthToken is not passed + */ + pass?: string | null /** - * Creates a GreenSMS Client Object - * @constructor - * @param GreenSMSOptions + * @summary AuthToken. Required when Username/Password not passed */ - constructor(GreenSMSOptions); + token?: string | null + /** + * @summary Create Auth Token after login and use for subsequent requests + */ + useTokenForRequests?: boolean + /** + * @summary API Version to be used + */ + version?: APIVersion + /** + * @summary Lead the response properties to camel case + */ + camelCaseResponse?: CC +} + +export type StatusCode = 0 | 1 | 2 | 4 | 8 | 16 | 34 + +export type HlrStatus = 1 | 2 | 4 | 8 | 16 + +declare enum Status { + "Status not ready" = "Status not ready", + "Call success" = "Call success", + "Call failure" = "Call failure", + "Call buffered" = "Call buffered", + "Call accepted" = "Call accepted", + "Call rejected" = "Call rejected", + "Status request expired" = "Status request expired" +} + +export interface StatusResponse { + time: string, + status_code: StatusCode, + status: Status +} + +export interface RequestIdResponse { + request_id: string } + +export interface ToParams { + to: string +} + +export interface StatusParams { + id: string + extended: boolean +} + +export interface AccountTokenParams { + expire?: number +} + +export interface AccountTokenResponse { + access_token: string +} + +export interface CallSendResponse { + request_id: string + code: string + request_status: string +} + +export interface WhoisLookupResponse { + def: number + begin: number + end: number + capacity: number + operator: string + region: string + is_transferred: boolean +} + +export interface HlrStatusResponse { + status: HlrStatus + imsi: number + msc: number + mcc: number + mnc: number + cn: string + net: string +} + +export interface VoiceSendParams { + to: string + txt: string + lang?: 'ru' | 'en' +} + +export interface PaySendParams { + to: string + amount: number + tag?: string +} + +export interface SMSSendParams { + to: string + txt: string + from?: string + tag?: string + hidden?: string +} + +export interface ViberSendParams { + to: string + txt: string + from?: string + cascade?: 'sms' | 'voice' +} + +declare class GreenSMS { + + account: { + token: (params?: AccountTokenParams) => Promise : AccountTokenResponse> + } + + call: { + send: (params: ToParams) => Promise : CallSendResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + whois: { + lookup: (params: ToParams) => Promise : WhoisLookupResponse> + } + + hlr: { + send: (params: ToParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : HlrStatusResponse> + } + + voice: { + send: (params: VoiceSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + pay: { + send: (params: PaySendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + sms: { + send: (params: SMSSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + viber: { + send: (params: ViberSendParams) => Promise : RequestIdResponse> + status: (params: StatusParams) => Promise : StatusResponse> + } + + constructor(options: GreenSMSOptions) +} + +export default GreenSMS diff --git a/package.json b/package.json index 2d57007..fffcac3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "greensms", - "version": "1.0.2", + "version": "1.0.3", "description": "GREENSMS API: SMS, Viber, Voce, Call, HLR, Pay", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", @@ -71,7 +71,7 @@ "rollup-plugin-filesize": "^9.0.2", "rollup-plugin-terser": "^7.0.2", "supertest": "^5.0.0", - "typescript": "^4.0.3" + "typescript": "^4.1.5" }, "settings": { "moduleName": "greensms",