@farm.js/workos 0.1.0-beta.98 → 0.1.0
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/README.md +2 -2
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
WorkOS integration for Farm.js
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
See [Stability and Support](https://farmjs.dev/docs/stability) for what this package guarantees.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @farm.js/workos
|
|
8
|
+
npm install @farm.js/workos
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
See the [Farm.js repository](https://github.com/farming-labs/farm.js) for documentation, examples, and support.
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export interface WorkOSIntegrationInput {
|
|
|
14
14
|
logoutPath?: string;
|
|
15
15
|
sessionPath?: string;
|
|
16
16
|
protectedRoutes?: string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* Additional origins allowed to post the sign-out route, using the same
|
|
19
|
+
* pattern syntax as `serverActions.allowedOrigins`. The app's own origin is
|
|
20
|
+
* always trusted.
|
|
21
|
+
*/
|
|
22
|
+
allowedOrigins?: string[];
|
|
17
23
|
log?: FarmIntegrationLogger;
|
|
18
24
|
}
|
|
19
25
|
export type WorkOSIntegrationInstance = WorkOS;
|
|
@@ -30,7 +36,7 @@ export declare function workos(input?: WorkOSIntegrationInput): import("@farm.js
|
|
|
30
36
|
apiKey: string;
|
|
31
37
|
protectedRoutes: string[];
|
|
32
38
|
};
|
|
33
|
-
config: import("@farm.js/core").FarmIntegrationConfigDefinition<ResolvedWorkOSConfig, import("@farm.js/core").
|
|
39
|
+
config: import("@farm.js/core").FarmIntegrationConfigDefinition<ResolvedWorkOSConfig, import("@farm.js/core").FarmSchema | undefined>;
|
|
34
40
|
api: {
|
|
35
41
|
[x: string]: {
|
|
36
42
|
get: {
|
|
@@ -89,9 +95,9 @@ export declare function workos(input?: WorkOSIntegrationInput): import("@farm.js
|
|
|
89
95
|
documentNavigations: {
|
|
90
96
|
matcher: string[];
|
|
91
97
|
}[];
|
|
92
|
-
routes: (import("@farm.js/core").FarmTypedIntegrationRoute<string, never, any, unknown, false, "GET", import("@farm.js/core").
|
|
98
|
+
routes: (import("@farm.js/core").FarmTypedIntegrationRoute<string, never, any, unknown, false, "GET", import("@farm.js/core").FarmSchema | undefined> | import("@farm.js/core").FarmTypedIntegrationRoute<string, {
|
|
93
99
|
returnTo?: string;
|
|
94
|
-
}, never, WorkOSRedirectResult, false, "POST", import("@farm.js/core").
|
|
100
|
+
}, never, WorkOSRedirectResult, false, "POST", import("@farm.js/core").FarmSchema | undefined>)[];
|
|
95
101
|
middleware: {
|
|
96
102
|
matcher: string[];
|
|
97
103
|
handler(request: Request): Promise<Response | undefined>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAgBhG,OAAO,KAAK,EAAuB,oBAAoB,EAAuB,MAAM,aAAa,CAAC;AAQlG,MAAM,WAAW,sBAAsB;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,yBAAyB,CAAC;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,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,GAAG,CAAC,EAAE,qBAAqB,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAc/C,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAqFD,wBAAgB,MAAM,CAAC,KAAK,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAoOG,MAAM;;;;yBAyE7B,OAAO;;GAe3C"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import { WorkOS } from "@workos-inc/node";
|
|
3
3
|
import { defineIntegration, integrationRoute } from "@farm.js/core";
|
|
4
|
+
import { describeIntegrationOriginRejection, resolveIntegrationAllowedOrigins, validateIntegrationRequestOrigin, } from "@farm.js/core/integrations";
|
|
4
5
|
import { clearRequestCookie, createPathInferredClientApi, createDocumentNavigationMatchers, createRequestCookie, getCookieValue, getReturnTo, integrationConfig, normalizeMatchers, } from "@farm.js/integration-utils";
|
|
5
6
|
import { workosClient } from "./client.js";
|
|
6
7
|
const DEV_COOKIE_PASSWORD = "farmjs-workos-cookie-password-development-2026";
|
|
@@ -76,6 +77,7 @@ export function workos(input = {}) {
|
|
|
76
77
|
const callbackPath = input.callbackPath ?? "/callback";
|
|
77
78
|
const logoutPath = input.logoutPath ?? "/logout";
|
|
78
79
|
const sessionPath = input.sessionPath ?? "/auth/session";
|
|
80
|
+
const allowedOrigins = resolveIntegrationAllowedOrigins(input.allowedOrigins, "workos.allowedOrigins");
|
|
79
81
|
const workos = input.instance ??
|
|
80
82
|
new WorkOS({
|
|
81
83
|
apiKey,
|
|
@@ -118,6 +120,27 @@ export function workos(input = {}) {
|
|
|
118
120
|
return null;
|
|
119
121
|
}
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Reject a sign-out request that did not come from this app. Returns the
|
|
125
|
+
* response to send, or null when the request may proceed.
|
|
126
|
+
*/
|
|
127
|
+
function rejectForeignOrigin(request) {
|
|
128
|
+
const result = validateIntegrationRequestOrigin(request, {
|
|
129
|
+
allowedOrigins,
|
|
130
|
+
requireOriginMetadata: request.method === "POST",
|
|
131
|
+
});
|
|
132
|
+
if (result.ok) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const message = describeIntegrationOriginRejection(result.reason);
|
|
136
|
+
if (request.headers.get("x-farm-integration-client") === "1") {
|
|
137
|
+
return Response.json({ error: message }, { status: 403 });
|
|
138
|
+
}
|
|
139
|
+
return new Response(message, {
|
|
140
|
+
status: 403,
|
|
141
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
142
|
+
});
|
|
143
|
+
}
|
|
121
144
|
async function redirectToAuth(request, screenHint) {
|
|
122
145
|
const requestUrl = new URL(request.url);
|
|
123
146
|
const returnTo = getReturnTo(requestUrl.searchParams.get("returnTo"), "/dashboard");
|
|
@@ -243,6 +266,10 @@ export function workos(input = {}) {
|
|
|
243
266
|
integrationRoute.post(logoutPath, {
|
|
244
267
|
responseFormat: "json",
|
|
245
268
|
async handler(request) {
|
|
269
|
+
const rejected = rejectForeignOrigin(request);
|
|
270
|
+
if (rejected) {
|
|
271
|
+
return rejected;
|
|
272
|
+
}
|
|
246
273
|
const requestUrl = new URL(request.url);
|
|
247
274
|
const sessionState = await getSession(workos, request, cookieName, cookiePassword);
|
|
248
275
|
const headers = new Headers();
|
|
@@ -302,7 +329,7 @@ export function workos(input = {}) {
|
|
|
302
329
|
const requestUrl = new URL(request.url);
|
|
303
330
|
const loginUrl = new URL(loginPath, request.url);
|
|
304
331
|
loginUrl.searchParams.set("returnTo", `${requestUrl.pathname}${requestUrl.search}`);
|
|
305
|
-
return Response.redirect(loginUrl,
|
|
332
|
+
return Response.redirect(loginUrl, 303); // 303 (See Other) mandates a GET on the GET-only login route regardless of the original method (RFC 7231 §6.4.4)
|
|
306
333
|
},
|
|
307
334
|
},
|
|
308
335
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/workos",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
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/
|
|
34
|
-
"@farm.js/
|
|
33
|
+
"@farm.js/integration-utils": "0.1.0",
|
|
34
|
+
"@farm.js/core": "0.1.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc",
|