Skip to content

Commit 0bf7a1a

Browse files
jharrellstainless-app[bot]
authored andcommitted
fix(api): migrate custom code to TypeScript
1 parent 2ab57eb commit 0bf7a1a

File tree

7 files changed

+100
-414
lines changed

7 files changed

+100
-414
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"lint": "./scripts/lint",
2727
"fix": "./scripts/format"
2828
},
29-
"dependencies": {},
29+
"dependencies": {
30+
"@noble/hashes": "^2.0.1"
31+
},
3032
"devDependencies": {
3133
"@arethetypeswrong/cli": "^0.17.0",
3234
"@swc/core": "^1.3.102",

src/client.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,41 @@ export class Finch {
845845
sandbox: API.Sandbox = new API.Sandbox(this);
846846
payroll: API.Payroll = new API.Payroll(this);
847847
connect: API.Connect = new API.Connect(this);
848+
849+
/**
850+
* Returns the authorization url which can be visited in order to obtain an
851+
* authorization code from Finch. The authorization code can then be exchanged for
852+
* an access token for the Finch api by calling get_access_token().
853+
*/
854+
getAuthURL({
855+
products,
856+
redirectUri,
857+
sandbox,
858+
}: {
859+
products: string;
860+
redirectUri: string;
861+
sandbox: boolean;
862+
}): string {
863+
if (!this.clientID) {
864+
throw new Error('Expected `clientID` to be set in order to call getAuthUrl');
865+
}
866+
const url = new URL('/authorize', 'https://connect.tryfinch.com/authorize');
867+
url.search = this.stringifyQuery({
868+
client_id: this.clientID,
869+
products,
870+
redirect_uri: redirectUri,
871+
sandbox,
872+
});
873+
return url.toString();
874+
}
875+
876+
/**
877+
* Returns a copy of the current Finch client with the given access token for
878+
* authentication.
879+
*/
880+
withAccessToken(accessToken: string): Finch {
881+
return new Finch({ ...this._options, accessToken });
882+
}
848883
}
849884

850885
Finch.AccessTokens = AccessTokens;

0 commit comments

Comments
 (0)