@farm.js/workos 0.1.0-beta.21 → 0.1.0-beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import { WorkOS } from "@workos-inc/node";
1
2
  import { type FarmIntegrationLogger } from "@farm.js/core";
2
3
  import type { WorkOSRedirectResult } from "./client.js";
3
4
  export interface WorkOSIntegrationInput {
5
+ /** Existing WorkOS SDK instance. When provided, Farm does not construct its own client. */
6
+ instance?: WorkOSIntegrationInstance;
4
7
  clientId?: string;
5
8
  apiKey?: string;
6
9
  cookiePassword?: string;
@@ -13,9 +16,10 @@ export interface WorkOSIntegrationInput {
13
16
  protectedRoutes?: string | string[];
14
17
  log?: FarmIntegrationLogger;
15
18
  }
19
+ export type WorkOSIntegrationInstance = WorkOS;
16
20
  interface ResolvedWorkOSConfig {
17
21
  clientId: string;
18
- apiKey: string;
22
+ apiKey?: string;
19
23
  cookiePassword: string;
20
24
  }
21
25
  export declare function workos(input?: WorkOSIntegrationInput): import("@farm.js/core").DefinedIntegration<{
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAWhG,OAAO,KAAK,EAAuB,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AAGlG,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAA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,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAiFD,wBAAgB,MAAM,CAAC,KAAK,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAsJG,MAAM;;;;yBAoE7B,OAAO;;GAe3C"}
package/dist/index.js CHANGED
@@ -19,21 +19,21 @@ function createWorkOSApi(input) {
19
19
  });
20
20
  }
21
21
  function resolveEnv(input) {
22
- const clientId = input.clientId ?? process.env.WORKOS_CLIENT_ID ?? "";
22
+ const clientId = input.instance?.clientId ?? input.clientId ?? process.env.WORKOS_CLIENT_ID ?? "";
23
23
  const apiKey = input.apiKey ?? process.env.WORKOS_API_KEY ?? "";
24
24
  const cookiePassword = input.cookiePassword ??
25
25
  process.env.WORKOS_COOKIE_PASSWORD ??
26
26
  process.env.FARM_WORKOS_COOKIE_PASSWORD ??
27
27
  (process.env.NODE_ENV === "production" ? "" : DEV_COOKIE_PASSWORD);
28
- if (!clientId || !apiKey) {
29
- throw new Error("WorkOS integration requires WORKOS_CLIENT_ID and WORKOS_API_KEY.");
28
+ if (!clientId || (!input.instance && !apiKey)) {
29
+ throw new Error("WorkOS integration requires a client ID and either a WorkOS instance or WORKOS_API_KEY.");
30
30
  }
31
31
  if (!cookiePassword) {
32
32
  throw new Error("WorkOS integration requires WORKOS_COOKIE_PASSWORD in production.");
33
33
  }
34
34
  return {
35
35
  clientId,
36
- apiKey,
36
+ apiKey: apiKey || undefined,
37
37
  cookiePassword,
38
38
  };
39
39
  }
@@ -64,10 +64,11 @@ export function workos(input = {}) {
64
64
  const callbackPath = input.callbackPath ?? "/callback";
65
65
  const logoutPath = input.logoutPath ?? "/logout";
66
66
  const sessionPath = input.sessionPath ?? "/auth/session";
67
- const workos = new WorkOS({
68
- apiKey,
69
- clientId,
70
- });
67
+ const workos = input.instance ??
68
+ new WorkOS({
69
+ apiKey,
70
+ clientId,
71
+ });
71
72
  async function redirectToAuth(request, screenHint) {
72
73
  const requestUrl = new URL(request.url);
73
74
  const returnTo = getReturnTo(requestUrl.searchParams.get("returnTo"), "/dashboard");
@@ -103,7 +104,9 @@ export function workos(input = {}) {
103
104
  apiKey,
104
105
  cookiePassword,
105
106
  },
106
- required: ["clientId", "apiKey", "cookiePassword"],
107
+ required: input.instance
108
+ ? ["clientId", "cookiePassword"]
109
+ : ["clientId", "apiKey", "cookiePassword"],
107
110
  }),
108
111
  api: createWorkOSApi({
109
112
  loginPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/workos",
3
- "version": "0.1.0-beta.21",
3
+ "version": "0.1.0-beta.23",
4
4
  "description": "WorkOS integration for Farm.js",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@workos-inc/node": "^8.9.0",
33
- "@farm.js/core": "0.1.0-beta.21",
34
- "@farm.js/integration-utils": "0.1.0-beta.21"
33
+ "@farm.js/core": "0.1.0-beta.23",
34
+ "@farm.js/integration-utils": "0.1.0-beta.23"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",