@proofgeist/fmdapi
Version:
FileMaker Data API client
39 lines • 1.29 kB
JavaScript
import { BaseFetchAdapter } from "./fetch-base.js";
export function isOtto3APIKey(key) {
return key.startsWith("KEY_");
}
export function isOttoFMSAPIKey(key) {
return key.startsWith("dk_");
}
export function isOttoAPIKey(key) {
return isOtto3APIKey(key) || isOttoFMSAPIKey(key);
}
export function isOttoAuth(auth) {
if (typeof auth !== "object" || auth === null)
return false;
return "apiKey" in auth;
}
export class OttoAdapter extends BaseFetchAdapter {
apiKey;
port;
constructor(options) {
super({ ...options, refreshToken: false });
this.apiKey = options.auth.apiKey;
this.port = options.auth.ottoPort;
if (this.apiKey.startsWith("KEY_")) {
// otto v3 uses port 3030
this.baseUrl.port = (this.port ?? 3030).toString();
}
else if (this.apiKey.startsWith("dk_")) {
// otto v4 uses default port, but with /otto prefix
this.baseUrl.pathname = `otto/${this.baseUrl.pathname.replace(/^\/+|\/+$/g, "")}`;
}
else {
throw new Error("Invalid Otto API key format. Must start with 'KEY_' (Otto v3) or 'dk_' (OttoFMS)");
}
}
getToken = async () => {
return this.apiKey;
};
}
//# sourceMappingURL=otto.js.map