@clivly/auth-workos 0.1.0 → 0.2.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/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _workos_inc_node = require("@workos-inc/node");
3
+ //#region src/map.ts
4
+ function workosUserToClivlyUser(user) {
5
+ if (!user.email) return null;
6
+ const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || void 0;
7
+ return {
8
+ id: user.id,
9
+ email: user.email,
10
+ name
11
+ };
12
+ }
13
+ function readCookie(req, name) {
14
+ const header = req.headers.get("cookie");
15
+ if (!header) return null;
16
+ for (const part of header.split(";")) {
17
+ const eq = part.indexOf("=");
18
+ if (eq === -1) continue;
19
+ if (part.slice(0, eq).trim() === name) return decodeURIComponent(part.slice(eq + 1).trim());
20
+ }
21
+ return null;
22
+ }
23
+ //#endregion
24
+ //#region src/index.ts
25
+ const DEFAULT_COOKIE_NAME = "wos-session";
26
+ /**
27
+ * WorkOS → ClivlyAuthAdapter. Unseals the host app's AuthKit session cookie and
28
+ * resolves the CRM end-user's identity. Answers "who is this person?" only —
29
+ * CRM authorization lives in the separate `crm_members` layer.
30
+ */
31
+ function createWorkOSAuthAdapter(options) {
32
+ const workos = new _workos_inc_node.WorkOS(options.apiKey, { clientId: options.clientId });
33
+ const cookieName = options.cookieName ?? DEFAULT_COOKIE_NAME;
34
+ return { async getUser(req) {
35
+ const sessionData = readCookie(req, cookieName);
36
+ if (!sessionData) return null;
37
+ const result = await workos.userManagement.loadSealedSession({
38
+ sessionData,
39
+ cookiePassword: options.cookiePassword
40
+ }).authenticate();
41
+ if (!result.authenticated) return null;
42
+ return workosUserToClivlyUser(result.user);
43
+ } };
44
+ }
45
+ //#endregion
46
+ exports.createWorkOSAuthAdapter = createWorkOSAuthAdapter;
47
+ exports.workosUserToClivlyUser = workosUserToClivlyUser;
@@ -0,0 +1,30 @@
1
+ import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core";
2
+
3
+ //#region src/map.d.ts
4
+ interface WorkOSLikeUser {
5
+ email: string;
6
+ firstName?: string | null;
7
+ id: string;
8
+ lastName?: string | null;
9
+ }
10
+ declare function workosUserToClivlyUser(user: WorkOSLikeUser): ClivlyUser | null;
11
+ //#endregion
12
+ //#region src/index.d.ts
13
+ interface WorkOSAuthAdapterOptions {
14
+ /** WorkOS API key (sk_…). */
15
+ apiKey: string;
16
+ /** WorkOS client ID (client_…). */
17
+ clientId: string;
18
+ /** Session cookie name. Defaults to `wos-session`. */
19
+ cookieName?: string;
20
+ /** Password used to unseal the AuthKit session cookie. */
21
+ cookiePassword: string;
22
+ }
23
+ /**
24
+ * WorkOS → ClivlyAuthAdapter. Unseals the host app's AuthKit session cookie and
25
+ * resolves the CRM end-user's identity. Answers "who is this person?" only —
26
+ * CRM authorization lives in the separate `crm_members` layer.
27
+ */
28
+ declare function createWorkOSAuthAdapter(options: WorkOSAuthAdapterOptions): ClivlyAuthAdapter;
29
+ //#endregion
30
+ export { WorkOSAuthAdapterOptions, type WorkOSLikeUser, createWorkOSAuthAdapter, workosUserToClivlyUser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clivly/auth-workos",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "WorkOS implementation of Clivly's ClivlyAuthAdapter.",
@@ -8,8 +8,14 @@
8
8
  "sideEffects": false,
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.mts",
12
- "import": "./dist/index.mjs"
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
13
19
  }
14
20
  },
15
21
  "files": [
@@ -19,7 +25,7 @@
19
25
  "access": "public"
20
26
  },
21
27
  "dependencies": {
22
- "@clivly/core": "0.1.0"
28
+ "@clivly/core": "0.2.0"
23
29
  },
24
30
  "peerDependencies": {
25
31
  "@workos-inc/node": ">=7"
@@ -27,13 +33,13 @@
27
33
  "devDependencies": {
28
34
  "@workos-inc/node": "^7.75.0",
29
35
  "tsdown": "^0.21.9",
30
- "typescript": "^6",
31
- "@clivly.com/config": "0.0.0"
36
+ "typescript": "^6"
32
37
  },
33
38
  "scripts": {
34
39
  "build": "tsdown",
35
40
  "check-types": "tsc --noEmit"
36
41
  },
37
- "main": "./dist/index.mjs",
38
- "types": "./dist/index.d.mts"
42
+ "main": "./dist/index.cjs",
43
+ "types": "./dist/index.d.cts",
44
+ "module": "./dist/index.mjs"
39
45
  }