@flipdish/orgmanagement
This package provides a TypeScript/JavaScript client for Flipdish's Organisation Management APIs over HTTP.
It is generated with Hey API and uses the native fetch API, so it has no runtime dependencies. It works in Node.js 18+, Bun, Deno and browsers, and ships both ES modules and CommonJS.
Example code
import { createFlipdishClient, SDK_INFO } from "@flipdish/orgmanagement";
import { describe, expect, test } from "@jest/globals";
const orgManagement = createFlipdishClient({
baseUrl: "https://api-prod-staging.flipdishdev.com",
// to get the API key, you should follow these docs:
// https://developers.flipdish.com/docs/getting-started
accessToken: process.env.FLIPDISH_BEARER_TOKEN,
// optional: identifies your app in the X-Flipdish-Client header,
// and in User-Agent outside browsers. Defaults to env vars such as DD_SERVICE.
clientName: "sdk-test-app",
});
describe("Org Management Tests", () => {
describe("Orgs", () => {
// test("Get org by id", async () => {
// const { data, error } = await orgManagement.getOrgById({
// path: { orgId: "org12345" },
// });
// expect(error).toBeUndefined();
// expect(data?.data.orgId).toBe("org12345");
// });
test("client is created", () => {
expect(orgManagement.getAllOrgs).toBeInstanceOf(Function);
});
});
describe("Client identity", () => {
test("sends User-Agent and X-Flipdish-Client in Node", async () => {
let sent: Request | undefined;
const sdk = createFlipdishClient({
clientName: "sdk-test-app",
clientVersion: "1.2.3",
fetch: async (input) => {
sent = input as Request;
return new Response(JSON.stringify({ data: [] }), {
headers: { "content-type": "application/json" },
});
},
});
await sdk.getAllOrgs();
const expected = `Flipdish-orgmanagement-ts/${SDK_INFO.version} sdk-test-app/1.2.3`;
expect(sent?.headers.get("user-agent")).toMatch(
new RegExp(`^${expected.replace(/[.+]/g, "\\$&")} `),
);
expect(sent?.headers.get("x-flipdish-client")).toBe(
sent?.headers.get("user-agent"),
);
});
});
});
Client identity
Every request carries an X-Flipdish-Client header identifying the SDK and the app using it. Outside browsers the same value is also sent as User-Agent, for example:
Flipdish-orgmanagement-ts/2.0.1 menu-service/2.3.1 env/production node/22.18.0
Each part can be set in code or with an environment variable. The first one that is set wins, with the option checked first:
| Part | Option | Environment variables |
|---|---|---|
| App name | clientName | FLIPDISH_CLIENT_NAME, DD_SERVICE, AWS_LAMBDA_FUNCTION_NAME, npm_package_name |
| App version | clientVersion | FLIPDISH_CLIENT_VERSION, DD_VERSION, npm_package_version |
| Environment | clientEnvironment | FLIPDISH_CLIENT_ENVIRONMENT, DD_ENV, NODE_ENV |
| Runtime | runtime | FLIPDISH_CLIENT_RUNTIME, then the detected Node.js, Bun or Deno version |
| Suffix | userAgentSuffix | FLIPDISH_CLIENT_USER_AGENT_SUFFIX |
Pass the options to createFlipdishClient, or call configureClientIdentity to set them on the default client:
import { configureClientIdentity } from "@flipdish/orgmanagement";
configureClientIdentity({ clientName: "menu-service", clientVersion: "2.3.1", clientEnvironment: "production" });
Browsers have no environment variables, so set at least clientName in code there. Anything passed in headers overrides these values.