clivly 0.2.0 → 0.2.2
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 +54 -3
- package/adapter-Cd6D_3JD.d.mts +46 -0
- package/adapter-Cy4q2CLs.d.cts +46 -0
- package/auth-adapter-CBOKDhlc.cjs +11 -0
- package/auth-adapter-CRBW4elj.d.mts +30 -0
- package/auth-adapter-CdLODn2p.d.cts +30 -0
- package/auth-adapter-wqnnEjo3.mjs +6 -0
- package/auth-better-auth.cjs +28 -0
- package/auth-better-auth.d.cts +33 -0
- package/auth-better-auth.d.mts +33 -0
- package/auth-better-auth.mjs +26 -0
- package/auth-clerk.cjs +34 -0
- package/auth-clerk.d.cts +32 -0
- package/auth-clerk.d.mts +32 -0
- package/auth-clerk.mjs +32 -0
- package/auth-workos.cjs +47 -0
- package/auth-workos.d.cts +30 -0
- package/auth-workos.d.mts +30 -0
- package/auth-workos.mjs +45 -0
- package/core-adapter.cjs +0 -0
- package/core-adapter.d.cts +2 -0
- package/core-adapter.d.mts +2 -0
- package/core-adapter.mjs +1 -0
- package/core-auth-adapter.cjs +3 -0
- package/core-auth-adapter.d.cts +2 -0
- package/core-auth-adapter.d.mts +2 -0
- package/core-auth-adapter.mjs +2 -0
- package/core-drizzle.cjs +32 -0
- package/core-drizzle.d.cts +21 -0
- package/core-drizzle.d.mts +21 -0
- package/core-drizzle.mjs +31 -0
- package/core-entity-config.cjs +13 -0
- package/core-entity-config.d.cts +2 -0
- package/core-entity-config.d.mts +2 -0
- package/core-entity-config.mjs +2 -0
- package/core-entity-heuristics.cjs +442 -0
- package/core-entity-heuristics.d.cts +68 -0
- package/core-entity-heuristics.d.mts +68 -0
- package/core-entity-heuristics.mjs +431 -0
- package/core-mapping-form.cjs +5 -0
- package/core-mapping-form.d.cts +2 -0
- package/core-mapping-form.d.mts +2 -0
- package/core-mapping-form.mjs +2 -0
- package/core-mapping-score.cjs +12 -0
- package/core-mapping-score.d.cts +2 -0
- package/core-mapping-score.d.mts +2 -0
- package/core-mapping-score.mjs +2 -0
- package/core-mappings-config.cjs +3 -0
- package/core-mappings-config.d.cts +2 -0
- package/core-mappings-config.d.mts +2 -0
- package/core-mappings-config.mjs +2 -0
- package/core-sync-engine.cjs +6 -0
- package/core-sync-engine.d.cts +2 -0
- package/core-sync-engine.d.mts +2 -0
- package/core-sync-engine.mjs +2 -0
- package/core-types.cjs +0 -0
- package/core-types.d.cts +2 -0
- package/core-types.d.mts +2 -0
- package/core-types.mjs +1 -0
- package/core-view-compiler.cjs +5 -0
- package/core-view-compiler.d.cts +2 -0
- package/core-view-compiler.d.mts +2 -0
- package/core-view-compiler.mjs +2 -0
- package/core.cjs +27 -0
- package/core.d.cts +9 -0
- package/core.d.mts +9 -0
- package/core.mjs +7 -0
- package/drizzle-meta-BGn0BqGb.cjs +9 -0
- package/drizzle-meta-CnC336L-.mjs +4 -0
- package/drizzle.cjs +107 -0
- package/drizzle.d.cts +28 -0
- package/drizzle.d.mts +28 -0
- package/drizzle.mjs +105 -0
- package/entity-config-Cvjo1cpv.cjs +4598 -0
- package/entity-config-D1DFyeUp.d.mts +2403 -0
- package/entity-config-DoR0khce.mjs +4533 -0
- package/entity-config-GczjD3y8.d.cts +2403 -0
- package/index.cjs +961 -0
- package/index.d.cts +57 -0
- package/index.d.mts +57 -0
- package/index.mjs +960 -0
- package/mapping-form-BHtPexzI.mjs +47 -0
- package/mapping-form-CUlFVfG8.d.cts +35 -0
- package/mapping-form-DdmDebC3.cjs +64 -0
- package/mapping-form-kjSiJaCX.d.mts +35 -0
- package/mapping-score-A2lRnlpk.d.mts +49 -0
- package/mapping-score-BJNe0lFn.mjs +87 -0
- package/mapping-score-BcjC0ZQs.d.cts +49 -0
- package/mapping-score-D9gfhtRu.cjs +146 -0
- package/mappings-config-CYPrzB3K.mjs +99 -0
- package/mappings-config-DTu_2cyx.cjs +104 -0
- package/mappings-config-DjRLCb2Q.d.cts +42 -0
- package/mappings-config-GxiYsSBQ.d.mts +42 -0
- package/namespace-probe-BtS0nXcr.d.cts +299 -0
- package/namespace-probe-CYMie-BI.d.mts +299 -0
- package/package.json +244 -21
- package/sdk-BZUn6wzs.mjs +764 -0
- package/sdk-CP_mYZa5.cjs +793 -0
- package/sdk.cjs +7 -0
- package/sdk.d.cts +33 -0
- package/sdk.d.mts +33 -0
- package/sdk.mjs +2 -0
- package/sync-engine-DUc0qWgo.cjs +230 -0
- package/sync-engine-DWnQPjV3.d.mts +183 -0
- package/sync-engine-DedXngop.mjs +207 -0
- package/sync-engine-uhfzKM-e.d.cts +183 -0
- package/types-BpsKVccL.d.cts +159 -0
- package/types-_qbJXMt_.d.mts +159 -0
- package/view-compiler-B4UYTvRM.d.cts +71 -0
- package/view-compiler-BHzbI9b7.cjs +202 -0
- package/view-compiler-CosFGar8.mjs +185 -0
- package/view-compiler-i_xFf-L0.d.mts +71 -0
- package/vite.cjs +38 -0
- package/vite.d.cts +23 -0
- package/vite.d.mts +23 -0
- package/vite.mjs +37 -0
- package/dist/index.mjs +0 -542
package/README.md
CHANGED
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
# clivly
|
|
2
2
|
|
|
3
|
-
|
|
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 the
|
|
8
|
+
[connecting to Clivly Cloud guide](https://github.com/amani-joseph/clivly.com/blob/master/docs/guides/connecting-to-clivly-cloud.md).
|
|
4
9
|
|
|
5
10
|
## Usage
|
|
6
11
|
|
|
7
12
|
```bash
|
|
8
|
-
|
|
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
|
|
10
17
|
npx clivly ping # verify CLIVLY_API_KEY + reachability
|
|
18
|
+
npx clivly doctor # verify clivly.config.ts end-to-end
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
|
|
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.
|
|
14
47
|
|
|
15
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`).
|
|
16
49
|
|
|
@@ -22,6 +55,24 @@ CLIVLY_API_KEY=sk_live_… npx clivly ping
|
|
|
22
55
|
# Org: Acme (org_1)
|
|
23
56
|
```
|
|
24
57
|
|
|
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
|
+
[connecting to Clivly Cloud](https://github.com/amani-joseph/clivly.com/blob/master/docs/guides/connecting-to-clivly-cloud.md)
|
|
71
|
+
- SDK docs:
|
|
72
|
+
[`@clivly/sdk` README](https://github.com/amani-joseph/clivly.com/blob/master/packages/sdk/README.md)
|
|
73
|
+
- Release notes:
|
|
74
|
+
[CHANGELOG](https://github.com/amani-joseph/clivly.com/blob/master/CHANGELOG.md)
|
|
75
|
+
|
|
25
76
|
## License
|
|
26
77
|
|
|
27
78
|
MIT
|
|
@@ -0,0 +1,46 @@
|
|
|
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-_qbJXMt_.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
|
+
/**
|
|
35
|
+
* Move a deal to `stage` and reorder it directly after `afterId` (null = top
|
|
36
|
+
* of the column). The adapter computes the fractional `position` from the
|
|
37
|
+
* target column's current order; callers never pass a numeric position.
|
|
38
|
+
*/
|
|
39
|
+
moveDeal(orgId: string, id: string, stage: Deal["stage"], afterId: string | null): Promise<Deal>;
|
|
40
|
+
updateDeal(orgId: string, id: string, data: UpdateDealInput): Promise<Deal>;
|
|
41
|
+
updateDealStage(orgId: string, id: string, stage: Deal["stage"]): Promise<Deal>;
|
|
42
|
+
updateTask(orgId: string, id: string, data: UpdateTaskInput): Promise<Task>;
|
|
43
|
+
updateTaskStatus(orgId: string, id: string, status: Task["status"]): Promise<Task>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CRMAdapter as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
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-BpsKVccL.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
|
+
/**
|
|
35
|
+
* Move a deal to `stage` and reorder it directly after `afterId` (null = top
|
|
36
|
+
* of the column). The adapter computes the fractional `position` from the
|
|
37
|
+
* target column's current order; callers never pass a numeric position.
|
|
38
|
+
*/
|
|
39
|
+
moveDeal(orgId: string, id: string, stage: Deal["stage"], afterId: string | null): Promise<Deal>;
|
|
40
|
+
updateDeal(orgId: string, id: string, data: UpdateDealInput): Promise<Deal>;
|
|
41
|
+
updateDealStage(orgId: string, id: string, stage: Deal["stage"]): Promise<Deal>;
|
|
42
|
+
updateTask(orgId: string, id: string, data: UpdateTaskInput): Promise<Task>;
|
|
43
|
+
updateTaskStatus(orgId: string, id: string, status: Task["status"]): Promise<Task>;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
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-_qbJXMt_.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,30 @@
|
|
|
1
|
+
import { f as CrmRole } from "./types-BpsKVccL.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-CdLODn2p.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-CRBW4elj.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;
|
package/auth-clerk.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CdLODn2p.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 };
|
package/auth-clerk.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CRBW4elj.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 };
|
package/auth-workos.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 ../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-CdLODn2p.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-CRBW4elj.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 };
|