getsafepay / safepay-node

Safepay node.js client
MIT License
6 stars 3 forks source link

Add TypeScript #2

Open wajeehmisbahkhan opened 3 years ago

wajeehmisbahkhan commented 3 years ago

I have cloned the project and converted all files to TS in a src directory and created an interfaces.ts in the utils folder where all the interfaces are centralized:

interface ServerResponseData {
  status: { errors: string[] };
}

interface ServerResponse {
  status: number;
  data: ServerResponseData;
}

export interface ServerError {
  response: ServerResponse;
  request: ClientRequest;
  message: any;
}

interface SafePayConfig {
  apiKey: string;
  apiSecret: string;
  baseUrl: string;
}

export interface SafePayOptions {
  environment?: environment;
  sandbox?: SafePayConfig;
  production?: SafePayConfig;
}

export interface ApiOptions extends SafePayConfig {
  environment: string;
}

export interface CheckoutParams {
  orderId?: string;
  tracker: string;
  redirectUrl: string;
  cancelUrl: string;
}

export interface OrderParams {
  apiKey?: string;
  amount?: number;
  currency?: currency;
  environment?: environment;
}

export interface ConstructQueryParamsOptions {
  env: string;
  tracker: string;
  orderId?: string;
  source: string;
  redirectUrl: string;
  cancelUrl: string;
}

I also created a types.ts file containing the following types:

export type environment = 'sandbox' | 'production';

export type currency = 'PKR' | 'USD';

Followed this tutorial

I can create a PR for this but it might have breaking changes - not sure because I'm used to Front End development and only recently got into Node. I thought I should first open an issue to get your thoughts.

alizahid commented 2 years ago

I wrote some types for my TypeScript project https://gist.github.com/alizahid/ff3beec5e74c187ab06592778508295f

However, they don't cover the entire SDK. Only the types I needed for my project.