@clivly/auth-clerk 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Clivly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @clivly/auth-clerk
2
+
3
+ [Clerk](https://clerk.com) implementation of Clivly's `ClivlyAuthAdapter`. Resolves a CRM end-user's identity from the host app's Clerk session.
4
+
5
+ `@clerk/backend` is a peer dependency.
6
+
7
+ ```ts
8
+ import { createClerkAuthAdapter } from "@clivly/auth-clerk";
9
+
10
+ const authAdapter = createClerkAuthAdapter({
11
+ secretKey: process.env.CLERK_SECRET_KEY!,
12
+ publishableKey: process.env.CLERK_PUBLISHABLE_KEY,
13
+ });
14
+
15
+ const user = await authAdapter.getUser(request); // { id, email, name } | null
16
+ ```
17
+
18
+ ## License
19
+
20
+ MIT
@@ -0,0 +1,32 @@
1
+ import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core";
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.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { createClerkClient } from "@clerk/backend";
2
+ //#region src/map.ts
3
+ function clerkUserToClivlyUser(user) {
4
+ const email = (user.emailAddresses?.find((address) => address.id === user.primaryEmailAddressId))?.emailAddress ?? user.emailAddresses?.[0]?.emailAddress;
5
+ if (!email) return null;
6
+ const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || void 0;
7
+ return {
8
+ id: user.id,
9
+ email,
10
+ name
11
+ };
12
+ }
13
+ //#endregion
14
+ //#region src/index.ts
15
+ /**
16
+ * Clerk → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the host
17
+ * app's Clerk session on each request. Answers "who is this person?" only —
18
+ * CRM authorization lives in the separate `crm_members` layer.
19
+ */
20
+ function createClerkAuthAdapter(options) {
21
+ const client = createClerkClient({
22
+ secretKey: options.secretKey,
23
+ publishableKey: options.publishableKey
24
+ });
25
+ return { async getUser(req) {
26
+ const auth = (await client.authenticateRequest(req, { authorizedParties: options.authorizedParties })).toAuth();
27
+ if (!auth?.userId) return null;
28
+ return clerkUserToClivlyUser(await client.users.getUser(auth.userId));
29
+ } };
30
+ }
31
+ //#endregion
32
+ export { clerkUserToClivlyUser, createClerkAuthAdapter };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@clivly/auth-clerk",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Clerk implementation of Clivly's ClivlyAuthAdapter.",
7
+ "license": "MIT",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "@clivly/core": "0.1.0"
23
+ },
24
+ "peerDependencies": {
25
+ "@clerk/backend": ">=1"
26
+ },
27
+ "devDependencies": {
28
+ "@clerk/backend": "^1.34.0",
29
+ "tsdown": "^0.21.9",
30
+ "typescript": "^6",
31
+ "@clivly.com/config": "0.0.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsdown",
35
+ "check-types": "tsc --noEmit"
36
+ },
37
+ "main": "./dist/index.mjs",
38
+ "types": "./dist/index.d.mts"
39
+ }