@clivly/auth-clerk 0.1.0 → 0.3.0-next.1
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 +34 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.mts +1 -1
- package/package.json +14 -8
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _clerk_backend = require("@clerk/backend");
|
|
3
|
+
//#region src/map.ts
|
|
4
|
+
function clerkUserToClivlyUser(user) {
|
|
5
|
+
const email = (user.emailAddresses?.find((address) => address.id === user.primaryEmailAddressId))?.emailAddress ?? user.emailAddresses?.[0]?.emailAddress;
|
|
6
|
+
if (!email) return null;
|
|
7
|
+
const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || void 0;
|
|
8
|
+
return {
|
|
9
|
+
id: user.id,
|
|
10
|
+
email,
|
|
11
|
+
name
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/index.ts
|
|
16
|
+
/**
|
|
17
|
+
* Clerk → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the host
|
|
18
|
+
* app's Clerk session on each request. Answers "who is this person?" only —
|
|
19
|
+
* CRM authorization lives in the separate `crm_members` layer.
|
|
20
|
+
*/
|
|
21
|
+
function createClerkAuthAdapter(options) {
|
|
22
|
+
const client = (0, _clerk_backend.createClerkClient)({
|
|
23
|
+
secretKey: options.secretKey,
|
|
24
|
+
publishableKey: options.publishableKey
|
|
25
|
+
});
|
|
26
|
+
return { async getUser(req) {
|
|
27
|
+
const auth = (await client.authenticateRequest(req, { authorizedParties: options.authorizedParties })).toAuth();
|
|
28
|
+
if (!auth?.userId) return null;
|
|
29
|
+
return clerkUserToClivlyUser(await client.users.getUser(auth.userId));
|
|
30
|
+
} };
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.clerkUserToClivlyUser = clerkUserToClivlyUser;
|
|
34
|
+
exports.createClerkAuthAdapter = createClerkAuthAdapter;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core/auth-adapter";
|
|
2
|
+
|
|
3
|
+
//#region src/map.d.ts
|
|
4
|
+
interface ClerkLikeUser {
|
|
5
|
+
emailAddresses?: Array<{
|
|
6
|
+
id: string;
|
|
7
|
+
emailAddress: string;
|
|
8
|
+
}>;
|
|
9
|
+
firstName?: string | null;
|
|
10
|
+
id: string;
|
|
11
|
+
lastName?: string | null;
|
|
12
|
+
primaryEmailAddressId?: string | null;
|
|
13
|
+
}
|
|
14
|
+
declare function clerkUserToClivlyUser(user: ClerkLikeUser): ClivlyUser | null;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/index.d.ts
|
|
17
|
+
interface ClerkAuthAdapterOptions {
|
|
18
|
+
/** Origins allowed to make authenticated requests (CSRF protection). */
|
|
19
|
+
authorizedParties?: string[];
|
|
20
|
+
/** Clerk publishable key (pk_…) — improves handshake reliability. */
|
|
21
|
+
publishableKey?: string;
|
|
22
|
+
/** Clerk secret key (sk_…). */
|
|
23
|
+
secretKey: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Clerk → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the host
|
|
27
|
+
* app's Clerk session on each request. Answers "who is this person?" only —
|
|
28
|
+
* CRM authorization lives in the separate `crm_members` layer.
|
|
29
|
+
*/
|
|
30
|
+
declare function createClerkAuthAdapter(options: ClerkAuthAdapterOptions): ClivlyAuthAdapter;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ClerkAuthAdapterOptions, type ClerkLikeUser, clerkUserToClivlyUser, createClerkAuthAdapter };
|
package/dist/index.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clivly/auth-clerk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-next.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerk implementation of Clivly's ClivlyAuthAdapter.",
|
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
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.
|
|
28
|
+
"@clivly/core": "0.3.0-next.1"
|
|
23
29
|
},
|
|
24
30
|
"peerDependencies": {
|
|
25
31
|
"@clerk/backend": ">=1"
|
|
@@ -27,13 +33,13 @@
|
|
|
27
33
|
"devDependencies": {
|
|
28
34
|
"@clerk/backend": "^1.34.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.
|
|
38
|
-
"types": "./dist/index.d.
|
|
42
|
+
"main": "./dist/index.cjs",
|
|
43
|
+
"types": "./dist/index.d.cts",
|
|
44
|
+
"module": "./dist/index.mjs"
|
|
39
45
|
}
|