From fe22fb39399a3efa9d4d3fc439be9ab6ade4dcf6 Mon Sep 17 00:00:00 2001 From: Paolo Tiu Date: Thu, 8 Jul 2021 14:50:19 +0800 Subject: [PATCH] add typescript declarations --- .eslintrc | 9 +++--- dist/index.d.ts | 32 +++++++++++++++++++ dist/index.js | 2 +- dist/payment-intents/index.d.ts | 1 + dist/payment-intents/payment-intents.d.ts | 13 ++++++++ dist/payment-methods/index.d.ts | 1 + dist/payment-methods/payment-methods.d.ts | 6 ++++ .../payment-methods/payment-methods.spec.d.ts | 1 + dist/payments/index.d.ts | 1 + dist/payments/payments.d.ts | 12 +++++++ dist/payments/payments.spec.d.ts | 1 + dist/sources/index.d.ts | 1 + dist/sources/sources.d.ts | 12 +++++++ dist/sources/sources.spec.d.ts | 1 + dist/tokens/index.d.ts | 1 + dist/tokens/tokens.d.ts | 9 ++++++ dist/tokens/tokens.spec.d.ts | 1 + dist/utils/rest.d.ts | 1 + dist/webhooks/index.d.ts | 1 + dist/webhooks/webhooks.d.ts | 9 ++++++ dist/webhooks/webhooks.spec.d.ts | 1 + package.json | 7 ++-- tsconfig.json | 17 ++++++++++ yarn.lock | 5 +++ 24 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 dist/index.d.ts create mode 100644 dist/payment-intents/index.d.ts create mode 100644 dist/payment-intents/payment-intents.d.ts create mode 100644 dist/payment-methods/index.d.ts create mode 100644 dist/payment-methods/payment-methods.d.ts create mode 100644 dist/payment-methods/payment-methods.spec.d.ts create mode 100644 dist/payments/index.d.ts create mode 100644 dist/payments/payments.d.ts create mode 100644 dist/payments/payments.spec.d.ts create mode 100644 dist/sources/index.d.ts create mode 100644 dist/sources/sources.d.ts create mode 100644 dist/sources/sources.spec.d.ts create mode 100644 dist/tokens/index.d.ts create mode 100644 dist/tokens/tokens.d.ts create mode 100644 dist/tokens/tokens.spec.d.ts create mode 100644 dist/utils/rest.d.ts create mode 100644 dist/webhooks/index.d.ts create mode 100644 dist/webhooks/webhooks.d.ts create mode 100644 dist/webhooks/webhooks.spec.d.ts create mode 100644 tsconfig.json diff --git a/.eslintrc b/.eslintrc index d24c6a4..a833a07 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,9 +2,10 @@ "rules": { "semi": [2, "always"], "space-before-function-paren": [2, "always"], - "keyword-spacing": [2, {"before": true, "after": true}], + "keyword-spacing": [2, { "before": true, "after": true }], "space-before-blocks": [2, "always"], - "comma-dangle": [2, "always-multiline"], + "comma-dangle": [2, "always-multiline"] }, - "parser": "babel-eslint" -} \ No newline at end of file + "parser": "babel-eslint", + "ignorePatterns": "*.d.ts" +} diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..f83bb0e --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,32 @@ +export default class Paymongo { + constructor(secret: any); + secret: any; + paymentMethods: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + }; + paymentIntents: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + attach: (id: any, data: any) => Promise; + }; + sources: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + }; + payments: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + list: () => Promise; + }; + tokens: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + }; + webhooks: { + create: (data: any) => Promise; + retrieve: (id: any) => Promise; + list: () => Promise; + toggle: (id: any, action: any) => Promise; + }; +} diff --git a/dist/index.js b/dist/index.js index 686fbb6..576572a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var _classCallCheck=_interopDefault(require("@babel/runtime/helpers/classCallCheck")),_regeneratorRuntime=_interopDefault(require("@babel/runtime/regenerator")),_defineProperty=_interopDefault(require("@babel/runtime/helpers/defineProperty")),_slicedToArray=_interopDefault(require("@babel/runtime/helpers/slicedToArray")),_asyncToGenerator=_interopDefault(require("@babel/runtime/helpers/asyncToGenerator")),bent=_interopDefault(require("bent"));function ownKeys(r,e){var t,n=Object.keys(r);return Object.getOwnPropertySymbols&&(t=Object.getOwnPropertySymbols(r),e&&(t=t.filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})),n.push.apply(n,t)),n}function _objectSpread(r){for(var t,e=1;e; +export function retrievePaymentIntent(secret: string, id: string): Promise; +export function attachToPaymentIntent(secret: string, id: string, data: { + attributes: { + payment_method: string; + }; +}): Promise; diff --git a/dist/payment-methods/index.d.ts b/dist/payment-methods/index.d.ts new file mode 100644 index 0000000..cd29a5d --- /dev/null +++ b/dist/payment-methods/index.d.ts @@ -0,0 +1 @@ +export * from "./payment-methods"; diff --git a/dist/payment-methods/payment-methods.d.ts b/dist/payment-methods/payment-methods.d.ts new file mode 100644 index 0000000..6c0c2bb --- /dev/null +++ b/dist/payment-methods/payment-methods.d.ts @@ -0,0 +1,6 @@ +export function createPaymentMethod(secret: string, data: { + attributes: { + type: string; + }; +}): Promise; +export function retrievePaymentMethod(secret: string, id: string): Promise; diff --git a/dist/payment-methods/payment-methods.spec.d.ts b/dist/payment-methods/payment-methods.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/payment-methods/payment-methods.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/payments/index.d.ts b/dist/payments/index.d.ts new file mode 100644 index 0000000..8e922b1 --- /dev/null +++ b/dist/payments/index.d.ts @@ -0,0 +1 @@ +export * from "./payments"; diff --git a/dist/payments/payments.d.ts b/dist/payments/payments.d.ts new file mode 100644 index 0000000..3be0eea --- /dev/null +++ b/dist/payments/payments.d.ts @@ -0,0 +1,12 @@ +export function createPayment(secret: string, data: { + attributes: { + amount: number; + currency: number; + source: { + id: string; + type: string; + }; + }; +}): Promise; +export function retrievePayment(secret: string, id: string): Promise; +export function listPayments(secret: string): Promise; diff --git a/dist/payments/payments.spec.d.ts b/dist/payments/payments.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/payments/payments.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/sources/index.d.ts b/dist/sources/index.d.ts new file mode 100644 index 0000000..7ccab97 --- /dev/null +++ b/dist/sources/index.d.ts @@ -0,0 +1 @@ +export * from "./sources"; diff --git a/dist/sources/sources.d.ts b/dist/sources/sources.d.ts new file mode 100644 index 0000000..8c96362 --- /dev/null +++ b/dist/sources/sources.d.ts @@ -0,0 +1,12 @@ +export function createSource(secret: string, data: { + attributes: { + type: string; + amount: number; + currency: string; + redirect: { + success: string; + failed: string; + }; + }; +}): Promise; +export function retrieveSource(secret: string, id: string): Promise; diff --git a/dist/sources/sources.spec.d.ts b/dist/sources/sources.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/sources/sources.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/tokens/index.d.ts b/dist/tokens/index.d.ts new file mode 100644 index 0000000..d1ea1d7 --- /dev/null +++ b/dist/tokens/index.d.ts @@ -0,0 +1 @@ +export * from "./tokens"; diff --git a/dist/tokens/tokens.d.ts b/dist/tokens/tokens.d.ts new file mode 100644 index 0000000..ed61beb --- /dev/null +++ b/dist/tokens/tokens.d.ts @@ -0,0 +1,9 @@ +export function createToken(secret: string, data: { + attributes: { + number: string; + exp_month: number; + exp_year: number; + cvc: string; + }; +}): Promise; +export function retrieveToken(secret: string, id: string): Promise; diff --git a/dist/tokens/tokens.spec.d.ts b/dist/tokens/tokens.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/tokens/tokens.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/dist/utils/rest.d.ts b/dist/utils/rest.d.ts new file mode 100644 index 0000000..8a29c87 --- /dev/null +++ b/dist/utils/rest.d.ts @@ -0,0 +1 @@ +export function makeRequest(opts: any): Promise; diff --git a/dist/webhooks/index.d.ts b/dist/webhooks/index.d.ts new file mode 100644 index 0000000..b861055 --- /dev/null +++ b/dist/webhooks/index.d.ts @@ -0,0 +1 @@ +export * from "./webhooks"; diff --git a/dist/webhooks/webhooks.d.ts b/dist/webhooks/webhooks.d.ts new file mode 100644 index 0000000..88ef748 --- /dev/null +++ b/dist/webhooks/webhooks.d.ts @@ -0,0 +1,9 @@ +export function createWebhook(secret: string, data: { + attributes: { + url: string; + events: string[]; + }; +}): Promise; +export function retrieveWebhook(secret: string, id: string): Promise; +export function listWebhooks(secret: string): Promise; +export function toggleWebhook(secret: string, id: string, action: string): Promise; diff --git a/dist/webhooks/webhooks.spec.d.ts b/dist/webhooks/webhooks.spec.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/dist/webhooks/webhooks.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/package.json b/package.json index 36138e9..7cd6073 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "test": "jest", "lint": "npx eslint src --fix -c .eslintrc", "prebuild": "rimraf dist && npm run test", - "build": "rollup -c", - "build:only": "rollup -c", + "build": "rollup -c && tsc", + "build:only": "rollup -c && tsc", "try": "node tester.js" }, "repository": { @@ -40,7 +40,8 @@ "rimraf": "^3.0.2", "rollup": "^1.32.1", "rollup-plugin-babel": "^4.4.0", - "rollup-plugin-uglify": "^6.0.4" + "rollup-plugin-uglify": "^6.0.4", + "typescript": "^4.3.5" }, "dependencies": { "bent": "^7.3.1" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e6a662f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "include": ["src/**/*"], + "compilerOptions": { + // Tells TypeScript to read JS files, as + // normally they are ignored as source files + "allowJs": true, + // Generate d.ts files + "declaration": true, + // This compiler run should + // only output d.ts files + "emitDeclarationOnly": true, + // Types should go into this directory. + // Removing this would place the .d.ts files + // next to the .js files + "outDir": "dist" + } +} diff --git a/yarn.lock b/yarn.lock index 9b5b882..99cd41d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5134,6 +5134,11 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== +typescript@^4.3.5: + version "4.3.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" + integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== + uglify-js@^3.4.9: version "3.9.3" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.9.3.tgz#4a285d1658b8a2ebaef9e51366b3a0f7acd79ec2"