clivly 0.1.0 → 0.2.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.
Files changed (117) hide show
  1. package/README.md +63 -3
  2. package/adapter-nLfZpgIG.d.cts +40 -0
  3. package/adapter-xs04z0KX.d.mts +40 -0
  4. package/auth-adapter-CBOKDhlc.cjs +11 -0
  5. package/auth-adapter-FEOR1nx-.d.mts +30 -0
  6. package/auth-adapter-wqnnEjo3.mjs +6 -0
  7. package/auth-adapter-wvfGKsOJ.d.cts +30 -0
  8. package/auth-better-auth.cjs +28 -0
  9. package/auth-better-auth.d.cts +33 -0
  10. package/auth-better-auth.d.mts +33 -0
  11. package/auth-better-auth.mjs +26 -0
  12. package/auth-clerk.cjs +34 -0
  13. package/auth-clerk.d.cts +32 -0
  14. package/auth-clerk.d.mts +32 -0
  15. package/auth-clerk.mjs +32 -0
  16. package/auth-workos.cjs +47 -0
  17. package/auth-workos.d.cts +30 -0
  18. package/auth-workos.d.mts +30 -0
  19. package/auth-workos.mjs +45 -0
  20. package/core-adapter.cjs +0 -0
  21. package/core-adapter.d.cts +2 -0
  22. package/core-adapter.d.mts +2 -0
  23. package/core-adapter.mjs +1 -0
  24. package/core-auth-adapter.cjs +3 -0
  25. package/core-auth-adapter.d.cts +2 -0
  26. package/core-auth-adapter.d.mts +2 -0
  27. package/core-auth-adapter.mjs +2 -0
  28. package/core-drizzle.cjs +32 -0
  29. package/core-drizzle.d.cts +21 -0
  30. package/core-drizzle.d.mts +21 -0
  31. package/core-drizzle.mjs +31 -0
  32. package/core-entity-config.cjs +13 -0
  33. package/core-entity-config.d.cts +2 -0
  34. package/core-entity-config.d.mts +2 -0
  35. package/core-entity-config.mjs +2 -0
  36. package/core-entity-heuristics.cjs +442 -0
  37. package/core-entity-heuristics.d.cts +68 -0
  38. package/core-entity-heuristics.d.mts +68 -0
  39. package/core-entity-heuristics.mjs +431 -0
  40. package/core-mapping-form.cjs +5 -0
  41. package/core-mapping-form.d.cts +2 -0
  42. package/core-mapping-form.d.mts +2 -0
  43. package/core-mapping-form.mjs +2 -0
  44. package/core-mapping-score.cjs +12 -0
  45. package/core-mapping-score.d.cts +2 -0
  46. package/core-mapping-score.d.mts +2 -0
  47. package/core-mapping-score.mjs +2 -0
  48. package/core-mappings-config.cjs +3 -0
  49. package/core-mappings-config.d.cts +2 -0
  50. package/core-mappings-config.d.mts +2 -0
  51. package/core-mappings-config.mjs +2 -0
  52. package/core-sync-engine.cjs +6 -0
  53. package/core-sync-engine.d.cts +2 -0
  54. package/core-sync-engine.d.mts +2 -0
  55. package/core-sync-engine.mjs +2 -0
  56. package/core-types.cjs +0 -0
  57. package/core-types.d.cts +2 -0
  58. package/core-types.d.mts +2 -0
  59. package/core-types.mjs +1 -0
  60. package/core-view-compiler.cjs +5 -0
  61. package/core-view-compiler.d.cts +2 -0
  62. package/core-view-compiler.d.mts +2 -0
  63. package/core-view-compiler.mjs +2 -0
  64. package/core.cjs +27 -0
  65. package/core.d.cts +9 -0
  66. package/core.d.mts +9 -0
  67. package/core.mjs +7 -0
  68. package/drizzle-meta-BGn0BqGb.cjs +9 -0
  69. package/drizzle-meta-CnC336L-.mjs +4 -0
  70. package/drizzle.cjs +107 -0
  71. package/drizzle.d.cts +28 -0
  72. package/drizzle.d.mts +28 -0
  73. package/drizzle.mjs +105 -0
  74. package/entity-config-Cvjo1cpv.cjs +4598 -0
  75. package/entity-config-D1DFyeUp.d.mts +2403 -0
  76. package/entity-config-DoR0khce.mjs +4533 -0
  77. package/entity-config-GczjD3y8.d.cts +2403 -0
  78. package/index.cjs +926 -0
  79. package/index.d.cts +56 -0
  80. package/index.d.mts +56 -0
  81. package/index.mjs +925 -0
  82. package/mapping-form-BHtPexzI.mjs +47 -0
  83. package/mapping-form-CUlFVfG8.d.cts +35 -0
  84. package/mapping-form-DdmDebC3.cjs +64 -0
  85. package/mapping-form-kjSiJaCX.d.mts +35 -0
  86. package/mapping-score-A2lRnlpk.d.mts +49 -0
  87. package/mapping-score-BJNe0lFn.mjs +87 -0
  88. package/mapping-score-BcjC0ZQs.d.cts +49 -0
  89. package/mapping-score-D9gfhtRu.cjs +146 -0
  90. package/mappings-config-CYPrzB3K.mjs +99 -0
  91. package/mappings-config-DTu_2cyx.cjs +104 -0
  92. package/mappings-config-DjRLCb2Q.d.cts +42 -0
  93. package/mappings-config-GxiYsSBQ.d.mts +42 -0
  94. package/namespace-probe-BtS0nXcr.d.cts +299 -0
  95. package/namespace-probe-CYMie-BI.d.mts +299 -0
  96. package/package.json +224 -21
  97. package/sdk-BZUn6wzs.mjs +764 -0
  98. package/sdk-CP_mYZa5.cjs +793 -0
  99. package/sdk.cjs +7 -0
  100. package/sdk.d.cts +33 -0
  101. package/sdk.d.mts +33 -0
  102. package/sdk.mjs +2 -0
  103. package/sync-engine-DUc0qWgo.cjs +230 -0
  104. package/sync-engine-DWnQPjV3.d.mts +183 -0
  105. package/sync-engine-DedXngop.mjs +207 -0
  106. package/sync-engine-uhfzKM-e.d.cts +183 -0
  107. package/types-C4POUcvk.d.mts +158 -0
  108. package/types-LJTBhkcN.d.cts +158 -0
  109. package/view-compiler-B4UYTvRM.d.cts +71 -0
  110. package/view-compiler-BHzbI9b7.cjs +202 -0
  111. package/view-compiler-CosFGar8.mjs +185 -0
  112. package/view-compiler-i_xFf-L0.d.mts +71 -0
  113. package/vite.cjs +38 -0
  114. package/vite.d.cts +23 -0
  115. package/vite.d.mts +23 -0
  116. package/vite.mjs +37 -0
  117. package/dist/index.mjs +0 -193
package/README.md CHANGED
@@ -1,15 +1,75 @@
1
1
  # clivly
2
2
 
3
- Scaffold [Clivly](https://clivly.com) — the CRM that lives inside your app.
3
+ Configure and integrate [Clivly](https://clivly.com) — the CRM that lives inside
4
+ your app.
5
+
6
+ For the full integration path, including when to use `start()` versus
7
+ `runScheduled()` / `createClivlyHandler()`, see
8
+ [`docs/guides/connecting-to-clivly-cloud.md`](../../docs/guides/connecting-to-clivly-cloud.md).
4
9
 
5
10
  ## Usage
6
11
 
7
12
  ```bash
8
- npx clivly init # detect your stack and print the scaffold plan
13
+ npm install clivly
14
+
15
+ npx clivly init # detect your Drizzle schema and print the config plan
9
16
  npx clivly init --write # write clivly.config.ts
17
+ npx clivly ping # verify CLIVLY_API_KEY + reachability
18
+ npx clivly doctor # verify clivly.config.ts end-to-end
19
+ ```
20
+
21
+ ## Imports
22
+
23
+ `clivly` is the consolidated public package. The CLI remains available as
24
+ `npx clivly`, while application code imports from typed subpaths:
25
+
26
+ ```ts
27
+ import { defineClivlyConfig } from "clivly/core";
28
+ import { createClivlySDK } from "clivly/sdk";
29
+ import { fromDrizzle } from "clivly/drizzle";
30
+ import { clivlyVite } from "clivly/vite";
31
+ import { createClerkAuthAdapter } from "clivly/auth/clerk";
32
+ import { createWorkOSAuthAdapter } from "clivly/auth/workos";
33
+ import { createBetterAuthAdapter } from "clivly/auth/better-auth";
34
+ ```
35
+
36
+ Provider and framework integrations use optional peer dependencies. Install only
37
+ what your app actually uses, such as `drizzle-orm`, `vite`, `@clerk/backend`, or
38
+ `@workos-inc/node`.
39
+
40
+ `clivly init` detects your framework from `package.json`, locates your Drizzle
41
+ schema, and generates a `clivly.config.ts` that maps likely contact and company
42
+ tables. The init command currently generates config for Drizzle only; Prisma and
43
+ Kysely projects should use a hand-written `fetchPage` source for now.
44
+
45
+ Use `--schema <path>` when your Drizzle schema is not in a common location or in
46
+ `drizzle.config.ts`. Re-run with `--force` to overwrite an existing config.
47
+
48
+ `clivly ping` reads `CLIVLY_API_KEY` from the environment, sends one heartbeat, and prints a clear ✅/❌ with the resolved org or the failure reason — so you can confirm a connection from the terminal without writing any code. Point it at a non-default backend with `--api-url <url>` (or `CLIVLY_API_URL`).
49
+
50
+ ```bash
51
+ CLIVLY_API_KEY=sk_live_… npx clivly ping
52
+ #
53
+ # Clivly ping
54
+ # ✅ Connected to Clivly
55
+ # Org: Acme (org_1)
10
56
  ```
11
57
 
12
- `clivly init` detects your framework (Next.js, TanStack Start, SvelteKit, Remix, Nuxt) and ORM (Drizzle, Prisma, Kysely) from `package.json`, then reports the routes and schema fragment it will scaffold.
58
+ `clivly doctor` loads your config and runs the same read-only checks as
59
+ `await clivly.doctor()`: API key, entity config, sources, Drizzle cursor/id
60
+ columns, sample fetch, and heartbeat.
61
+
62
+ ```bash
63
+ npx clivly doctor
64
+ npx clivly doctor --config ./apps/web/clivly.config.ts
65
+ ```
66
+
67
+ ## More docs
68
+
69
+ - Onboarding guide:
70
+ [`docs/guides/connecting-to-clivly-cloud.md`](../../docs/guides/connecting-to-clivly-cloud.md)
71
+ - SDK docs: [`../sdk/README.md`](../sdk/README.md)
72
+ - Release notes: [`../../CHANGELOG.md`](../../CHANGELOG.md)
13
73
 
14
74
  ## License
15
75
 
@@ -0,0 +1,40 @@
1
+ import { C as UpdateDealInput, S as UpdateContactInput, _ as Task, a as ContactFilters, c as CreateCompanyInput, d as CreateTaskInput, g as RecordSource, i as Contact, l as CreateContactInput, p as Deal, r as Company, s as CreateActivityInput, t as Activity, u as CreateDealInput, w as UpdateTaskInput, y as TaskFilters } from "./types-LJTBhkcN.cjs";
2
+
3
+ //#region ../core/src/adapter.d.ts
4
+ /**
5
+ * The contract every ORM implementation fulfils. `packages/drizzle` is the first
6
+ * implementation; Prisma/Kysely/TypeORM can follow without changes to consumers.
7
+ *
8
+ * Every method is scoped to a single organization (`orgId`) — the adapter is the
9
+ * one place tenant isolation is enforced for CRM data. Implementations only ever
10
+ * read/write Clivly-owned `crm_*` tables; they never mutate host business tables.
11
+ */
12
+ interface CRMAdapter {
13
+ archiveTask(orgId: string, id: string): Promise<Task>;
14
+ completeTask(orgId: string, id: string): Promise<Task>;
15
+ createActivity(orgId: string, data: CreateActivityInput): Promise<Activity>;
16
+ createCompany(orgId: string, data: CreateCompanyInput): Promise<Company>;
17
+ createContact(orgId: string, data: CreateContactInput): Promise<Contact>;
18
+ createDeal(orgId: string, data: CreateDealInput): Promise<Deal>;
19
+ createTask(orgId: string, data: CreateTaskInput): Promise<Task>;
20
+ deleteDeal(orgId: string, id: string): Promise<Deal | null>;
21
+ getActivities(orgId: string, contactId: string): Promise<Activity[]>;
22
+ getCompanies(orgId: string, filters?: {
23
+ source?: RecordSource;
24
+ }): Promise<Company[]>;
25
+ getContact(orgId: string, id: string): Promise<Contact | null>;
26
+ getContacts(orgId: string, filters?: ContactFilters): Promise<Contact[]>;
27
+ getDeal(orgId: string, id: string): Promise<Deal | null>;
28
+ getDeals(orgId: string, filters?: {
29
+ source?: RecordSource;
30
+ }): Promise<Deal[]>;
31
+ getTasks(orgId: string, filters?: TaskFilters): Promise<Task[]>;
32
+ reopenTask(orgId: string, id: string): Promise<Task>;
33
+ updateContact(orgId: string, id: string, data: UpdateContactInput): Promise<Contact>;
34
+ updateDeal(orgId: string, id: string, data: UpdateDealInput): Promise<Deal>;
35
+ updateDealStage(orgId: string, id: string, stage: Deal["stage"]): Promise<Deal>;
36
+ updateTask(orgId: string, id: string, data: UpdateTaskInput): Promise<Task>;
37
+ updateTaskStatus(orgId: string, id: string, status: Task["status"]): Promise<Task>;
38
+ }
39
+ //#endregion
40
+ export { CRMAdapter as t };
@@ -0,0 +1,40 @@
1
+ import { C as UpdateDealInput, S as UpdateContactInput, _ as Task, a as ContactFilters, c as CreateCompanyInput, d as CreateTaskInput, g as RecordSource, i as Contact, l as CreateContactInput, p as Deal, r as Company, s as CreateActivityInput, t as Activity, u as CreateDealInput, w as UpdateTaskInput, y as TaskFilters } from "./types-C4POUcvk.mjs";
2
+
3
+ //#region ../core/src/adapter.d.ts
4
+ /**
5
+ * The contract every ORM implementation fulfils. `packages/drizzle` is the first
6
+ * implementation; Prisma/Kysely/TypeORM can follow without changes to consumers.
7
+ *
8
+ * Every method is scoped to a single organization (`orgId`) — the adapter is the
9
+ * one place tenant isolation is enforced for CRM data. Implementations only ever
10
+ * read/write Clivly-owned `crm_*` tables; they never mutate host business tables.
11
+ */
12
+ interface CRMAdapter {
13
+ archiveTask(orgId: string, id: string): Promise<Task>;
14
+ completeTask(orgId: string, id: string): Promise<Task>;
15
+ createActivity(orgId: string, data: CreateActivityInput): Promise<Activity>;
16
+ createCompany(orgId: string, data: CreateCompanyInput): Promise<Company>;
17
+ createContact(orgId: string, data: CreateContactInput): Promise<Contact>;
18
+ createDeal(orgId: string, data: CreateDealInput): Promise<Deal>;
19
+ createTask(orgId: string, data: CreateTaskInput): Promise<Task>;
20
+ deleteDeal(orgId: string, id: string): Promise<Deal | null>;
21
+ getActivities(orgId: string, contactId: string): Promise<Activity[]>;
22
+ getCompanies(orgId: string, filters?: {
23
+ source?: RecordSource;
24
+ }): Promise<Company[]>;
25
+ getContact(orgId: string, id: string): Promise<Contact | null>;
26
+ getContacts(orgId: string, filters?: ContactFilters): Promise<Contact[]>;
27
+ getDeal(orgId: string, id: string): Promise<Deal | null>;
28
+ getDeals(orgId: string, filters?: {
29
+ source?: RecordSource;
30
+ }): Promise<Deal[]>;
31
+ getTasks(orgId: string, filters?: TaskFilters): Promise<Task[]>;
32
+ reopenTask(orgId: string, id: string): Promise<Task>;
33
+ updateContact(orgId: string, id: string, data: UpdateContactInput): Promise<Contact>;
34
+ updateDeal(orgId: string, id: string, data: UpdateDealInput): Promise<Deal>;
35
+ updateDealStage(orgId: string, id: string, stage: Deal["stage"]): Promise<Deal>;
36
+ updateTask(orgId: string, id: string, data: UpdateTaskInput): Promise<Task>;
37
+ updateTaskStatus(orgId: string, id: string, status: Task["status"]): Promise<Task>;
38
+ }
39
+ //#endregion
40
+ export { CRMAdapter as t };
@@ -0,0 +1,11 @@
1
+ //#region ../core/src/auth-adapter.ts
2
+ function authCustom(resolver) {
3
+ return { getUser: async (req) => await resolver(req) };
4
+ }
5
+ //#endregion
6
+ Object.defineProperty(exports, "authCustom", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return authCustom;
10
+ }
11
+ });
@@ -0,0 +1,30 @@
1
+ import { f as CrmRole } from "./types-C4POUcvk.mjs";
2
+
3
+ //#region ../core/src/auth-adapter.d.ts
4
+ interface ClivlyUser {
5
+ email: string;
6
+ id: string;
7
+ name?: string;
8
+ }
9
+ /**
10
+ * Bridges any host auth system into Clivly. Ship adapters wrap a concrete SDK
11
+ * (`@clivly/auth-clerk`, `@clivly/auth-workos`), and `authCustom` wraps an
12
+ * arbitrary `(req) => user` resolver.
13
+ *
14
+ * This answers "who is this person?" only. Authorization ("what can they do in
15
+ * this org?") is the separate `crm_members` layer — see `MembershipResolver`.
16
+ */
17
+ interface ClivlyAuthAdapter {
18
+ getUser(req: Request): Promise<ClivlyUser | null>;
19
+ }
20
+ declare function authCustom(resolver: (req: Request) => Promise<ClivlyUser | null> | ClivlyUser | null): ClivlyAuthAdapter;
21
+ interface CrmMembership {
22
+ orgId: string;
23
+ role: CrmRole;
24
+ userId: string;
25
+ }
26
+ interface MembershipResolver {
27
+ getMembership(userId: string, orgId: string): Promise<CrmMembership | null>;
28
+ }
29
+ //#endregion
30
+ export { authCustom as a, MembershipResolver as i, ClivlyUser as n, CrmMembership as r, ClivlyAuthAdapter as t };
@@ -0,0 +1,6 @@
1
+ //#region ../core/src/auth-adapter.ts
2
+ function authCustom(resolver) {
3
+ return { getUser: async (req) => await resolver(req) };
4
+ }
5
+ //#endregion
6
+ export { authCustom as t };
@@ -0,0 +1,30 @@
1
+ import { f as CrmRole } from "./types-LJTBhkcN.cjs";
2
+
3
+ //#region ../core/src/auth-adapter.d.ts
4
+ interface ClivlyUser {
5
+ email: string;
6
+ id: string;
7
+ name?: string;
8
+ }
9
+ /**
10
+ * Bridges any host auth system into Clivly. Ship adapters wrap a concrete SDK
11
+ * (`@clivly/auth-clerk`, `@clivly/auth-workos`), and `authCustom` wraps an
12
+ * arbitrary `(req) => user` resolver.
13
+ *
14
+ * This answers "who is this person?" only. Authorization ("what can they do in
15
+ * this org?") is the separate `crm_members` layer — see `MembershipResolver`.
16
+ */
17
+ interface ClivlyAuthAdapter {
18
+ getUser(req: Request): Promise<ClivlyUser | null>;
19
+ }
20
+ declare function authCustom(resolver: (req: Request) => Promise<ClivlyUser | null> | ClivlyUser | null): ClivlyAuthAdapter;
21
+ interface CrmMembership {
22
+ orgId: string;
23
+ role: CrmRole;
24
+ userId: string;
25
+ }
26
+ interface MembershipResolver {
27
+ getMembership(userId: string, orgId: string): Promise<CrmMembership | null>;
28
+ }
29
+ //#endregion
30
+ export { authCustom as a, MembershipResolver as i, ClivlyUser as n, CrmMembership as r, ClivlyAuthAdapter as t };
@@ -0,0 +1,28 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region ../auth-better-auth/src/map.ts
3
+ function betterAuthUserToClivlyUser(user) {
4
+ if (!user.email) return null;
5
+ return {
6
+ id: user.id,
7
+ email: user.email,
8
+ name: user.name ?? void 0
9
+ };
10
+ }
11
+ //#endregion
12
+ //#region ../auth-better-auth/src/index.ts
13
+ /**
14
+ * better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
15
+ * host app's better-auth session on each request, via `auth.api.getSession`.
16
+ * Answers "who is this person?" only — CRM authorization lives in the separate
17
+ * `crm_members` layer.
18
+ */
19
+ function createBetterAuthAdapter(options) {
20
+ return { async getUser(req) {
21
+ const session = await options.auth.api.getSession({ headers: req.headers });
22
+ if (!session?.user) return null;
23
+ return betterAuthUserToClivlyUser(session.user);
24
+ } };
25
+ }
26
+ //#endregion
27
+ exports.betterAuthUserToClivlyUser = betterAuthUserToClivlyUser;
28
+ exports.createBetterAuthAdapter = createBetterAuthAdapter;
@@ -0,0 +1,33 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-wvfGKsOJ.cjs";
2
+
3
+ //#region ../auth-better-auth/src/map.d.ts
4
+ interface BetterAuthLikeUser {
5
+ email?: string | null;
6
+ id: string;
7
+ name?: string | null;
8
+ }
9
+ declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
10
+ //#endregion
11
+ //#region ../auth-better-auth/src/index.d.ts
12
+ interface BetterAuthLike {
13
+ api: {
14
+ getSession(args: {
15
+ headers: Headers;
16
+ }): Promise<{
17
+ user: BetterAuthLikeUser;
18
+ } | null>;
19
+ };
20
+ }
21
+ interface BetterAuthAdapterOptions {
22
+ /** Your better-auth instance (the object returned by `betterAuth({...})`). */
23
+ auth: BetterAuthLike;
24
+ }
25
+ /**
26
+ * better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
27
+ * host app's better-auth session on each request, via `auth.api.getSession`.
28
+ * Answers "who is this person?" only — CRM authorization lives in the separate
29
+ * `crm_members` layer.
30
+ */
31
+ declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
32
+ //#endregion
33
+ export { BetterAuthAdapterOptions, BetterAuthLike, type BetterAuthLikeUser, betterAuthUserToClivlyUser, createBetterAuthAdapter };
@@ -0,0 +1,33 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-FEOR1nx-.mjs";
2
+
3
+ //#region ../auth-better-auth/src/map.d.ts
4
+ interface BetterAuthLikeUser {
5
+ email?: string | null;
6
+ id: string;
7
+ name?: string | null;
8
+ }
9
+ declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
10
+ //#endregion
11
+ //#region ../auth-better-auth/src/index.d.ts
12
+ interface BetterAuthLike {
13
+ api: {
14
+ getSession(args: {
15
+ headers: Headers;
16
+ }): Promise<{
17
+ user: BetterAuthLikeUser;
18
+ } | null>;
19
+ };
20
+ }
21
+ interface BetterAuthAdapterOptions {
22
+ /** Your better-auth instance (the object returned by `betterAuth({...})`). */
23
+ auth: BetterAuthLike;
24
+ }
25
+ /**
26
+ * better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
27
+ * host app's better-auth session on each request, via `auth.api.getSession`.
28
+ * Answers "who is this person?" only — CRM authorization lives in the separate
29
+ * `crm_members` layer.
30
+ */
31
+ declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
32
+ //#endregion
33
+ export { BetterAuthAdapterOptions, BetterAuthLike, type BetterAuthLikeUser, betterAuthUserToClivlyUser, createBetterAuthAdapter };
@@ -0,0 +1,26 @@
1
+ //#region ../auth-better-auth/src/map.ts
2
+ function betterAuthUserToClivlyUser(user) {
3
+ if (!user.email) return null;
4
+ return {
5
+ id: user.id,
6
+ email: user.email,
7
+ name: user.name ?? void 0
8
+ };
9
+ }
10
+ //#endregion
11
+ //#region ../auth-better-auth/src/index.ts
12
+ /**
13
+ * better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
14
+ * host app's better-auth session on each request, via `auth.api.getSession`.
15
+ * Answers "who is this person?" only — CRM authorization lives in the separate
16
+ * `crm_members` layer.
17
+ */
18
+ function createBetterAuthAdapter(options) {
19
+ return { async getUser(req) {
20
+ const session = await options.auth.api.getSession({ headers: req.headers });
21
+ if (!session?.user) return null;
22
+ return betterAuthUserToClivlyUser(session.user);
23
+ } };
24
+ }
25
+ //#endregion
26
+ export { betterAuthUserToClivlyUser, createBetterAuthAdapter };
package/auth-clerk.cjs ADDED
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _clerk_backend = require("@clerk/backend");
3
+ //#region ../auth-clerk/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 ../auth-clerk/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;
@@ -0,0 +1,32 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-wvfGKsOJ.cjs";
2
+
3
+ //#region ../auth-clerk/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 ../auth-clerk/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 };
@@ -0,0 +1,32 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-FEOR1nx-.mjs";
2
+
3
+ //#region ../auth-clerk/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 ../auth-clerk/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/auth-clerk.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { createClerkClient } from "@clerk/backend";
2
+ //#region ../auth-clerk/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 ../auth-clerk/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 };
@@ -0,0 +1,47 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _workos_inc_node = require("@workos-inc/node");
3
+ //#region ../auth-workos/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 ../auth-workos/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 { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-wvfGKsOJ.cjs";
2
+
3
+ //#region ../auth-workos/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 ../auth-workos/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 };
@@ -0,0 +1,30 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-FEOR1nx-.mjs";
2
+
3
+ //#region ../auth-workos/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 ../auth-workos/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 };
@@ -0,0 +1,45 @@
1
+ import { WorkOS } from "@workos-inc/node";
2
+ //#region ../auth-workos/src/map.ts
3
+ function workosUserToClivlyUser(user) {
4
+ if (!user.email) return null;
5
+ const name = [user.firstName, user.lastName].filter(Boolean).join(" ") || void 0;
6
+ return {
7
+ id: user.id,
8
+ email: user.email,
9
+ name
10
+ };
11
+ }
12
+ function readCookie(req, name) {
13
+ const header = req.headers.get("cookie");
14
+ if (!header) return null;
15
+ for (const part of header.split(";")) {
16
+ const eq = part.indexOf("=");
17
+ if (eq === -1) continue;
18
+ if (part.slice(0, eq).trim() === name) return decodeURIComponent(part.slice(eq + 1).trim());
19
+ }
20
+ return null;
21
+ }
22
+ //#endregion
23
+ //#region ../auth-workos/src/index.ts
24
+ const DEFAULT_COOKIE_NAME = "wos-session";
25
+ /**
26
+ * WorkOS → ClivlyAuthAdapter. Unseals the host app's AuthKit session cookie and
27
+ * resolves the CRM end-user's identity. Answers "who is this person?" only —
28
+ * CRM authorization lives in the separate `crm_members` layer.
29
+ */
30
+ function createWorkOSAuthAdapter(options) {
31
+ const workos = new WorkOS(options.apiKey, { clientId: options.clientId });
32
+ const cookieName = options.cookieName ?? DEFAULT_COOKIE_NAME;
33
+ return { async getUser(req) {
34
+ const sessionData = readCookie(req, cookieName);
35
+ if (!sessionData) return null;
36
+ const result = await workos.userManagement.loadSealedSession({
37
+ sessionData,
38
+ cookiePassword: options.cookiePassword
39
+ }).authenticate();
40
+ if (!result.authenticated) return null;
41
+ return workosUserToClivlyUser(result.user);
42
+ } };
43
+ }
44
+ //#endregion
45
+ export { createWorkOSAuthAdapter, workosUserToClivlyUser };
File without changes
@@ -0,0 +1,2 @@
1
+ import { t as CRMAdapter } from "./adapter-nLfZpgIG.cjs";
2
+ export { CRMAdapter };