Skip to content

Commit dfbdcd2

Browse files
committed
expose get token method for fetch adapter
1 parent 8e6d5c1 commit dfbdcd2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.changeset/wild-poets-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@proofgeist/fmdapi": patch
3+
---
4+
5+
Expose the getToken method for the fetch adapter

op.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ DIFFERENT_OTTO_API_KEY="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco
1515
FM_SERVER="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco4m/1Password env Values/FM_SERVER"
1616
FM_DATABASE="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco4m/1Password env Values/FM_DATABASE"
1717
OTTO_API_KEY="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco4m/1Password env Values/OTTO_API_KEY"
18+
FM_USERNAME="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco4m/username"
19+
FM_PASSWORD="op://xrs5sehh2gm36me62rlfpmsyde/ztcjgvgc4i5aa6cjh5vudpco4m/password"

src/adapters/fetch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ export class FetchAdapter extends BaseFetchAdapter {
3333
if (this.password === "") throw new Error("Password is required");
3434
}
3535

36-
protected override getToken = async (
36+
/**
37+
* Gets a FileMaker Data API token for authentication.
38+
*
39+
* This token is **NOT** guaranteed to be valid, since it expires 15 minutes after the last use. Pass `refresh=true` to forcibly get a fresh token
40+
*
41+
* @param args.refresh - If true, forces getting a new token instead of using cached token
42+
* @internal This method is intended for internal use, you should not need to use it in most cases.
43+
*/
44+
public override getToken = async (
3745
args?: GetTokenArguments,
3846
): Promise<string> => {
3947
const { refresh = false } = args ?? {};

test/setup.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { OttoFMSAPIKey } from "../src/adapters/otto";
2-
import { DataApi, OttoAdapter } from "../src/index";
2+
import { DataApi, FetchAdapter, OttoAdapter } from "../src/index";
33

44
import dotenv from "dotenv";
55
dotenv.config({ path: ".env.local" });
@@ -13,6 +13,9 @@ if (
1313
"FM_SERVER, FM_DATABASE, and OTTO_API_KEY must be set in the environment",
1414
);
1515

16+
if (!process.env.FM_USERNAME || !process.env.FM_PASSWORD)
17+
throw new Error("FM_USERNAME and FM_PASSWORD must be set in the environment");
18+
1619
export const config = {
1720
auth: { apiKey: process.env.OTTO_API_KEY as OttoFMSAPIKey },
1821
db: process.env.FM_DATABASE,
@@ -54,3 +57,14 @@ export const containerClient = DataApi<
5457
}),
5558
layout: "container",
5659
});
60+
61+
export const fetchClient = DataApi({
62+
adapter: new FetchAdapter({
63+
auth: {
64+
password: process.env.FM_PASSWORD as string,
65+
username: process.env.FM_USERNAME as string,
66+
},
67+
db: config.db,
68+
server: config.server,
69+
}),
70+
});

0 commit comments

Comments
 (0)