Skip to content

Commit

Permalink
feat: add typings, and ability to import typings, to package (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandersmanning authored Jun 4, 2021
1 parent 39fd900 commit f80c4ee
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 1,120 deletions.
1,254 changes: 160 additions & 1,094 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"type": "module",
"main": "./dist/index.js",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc --project tsconfig.json",
"clean": "rm -rf .eslintcache coverage/ dist/",
Expand Down Expand Up @@ -133,5 +132,8 @@
}
]
]
},
"dependencies": {
"@square/web-payments-sdk-types": "^1.1.1"
}
}
11 changes: 0 additions & 11 deletions src/index.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './payments';
export * from '@square/web-payments-sdk-types';
2 changes: 1 addition & 1 deletion src/load.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='../types/index.d.ts' />
import { Square } from '@square/web-payments-sdk-types';

function findScript(src: string): HTMLScriptElement | null {
return document.querySelector<HTMLScriptElement>(`script[src="${src}"]`);
Expand Down
13 changes: 11 additions & 2 deletions src/payments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { loadSquare } from './load';
import { Payments } from '@square/web-payments-sdk-types';

const Version = 'v0';

type PaymentInitialization = (
applicationId: string,
locationId: string
) => Promise<Payments | null>;

class InvalidApplicationIdError extends Error {
constructor(
message = "The Payment 'applicationId' option is not in the correct format."
Expand Down Expand Up @@ -31,7 +37,8 @@ function getSrcForApplicationId(applicationId: string): string {
return src;
}

export async function payments(
// eslint-disable-next-line func-style
const payments: PaymentInitialization = async function (
applicationId: string,
locationId?: string,
overrides?: {
Expand All @@ -50,4 +57,6 @@ export async function payments(
}

return maybeSquare.payments(applicationId, locationId);
}
};

export { payments };
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"typeRoots": ["./node_modules/@square/web-payments-sdk-types"],
"module": "ESNext",
"moduleResolution": "node",
"outDir": "dist/",
Expand Down
11 changes: 0 additions & 11 deletions types/index.d.ts

This file was deleted.

0 comments on commit f80c4ee

Please sign in to comment.