clivly 0.23.1 → 0.24.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.
Files changed (117) hide show
  1. package/README.md +42 -2
  2. package/{adapter-B4v4dwgD.d.mts → adapter--YV7du3i.d.cts} +1 -1
  3. package/{adapter-BK3gsby5.d.cts → adapter-DD3K3dCW.d.mts} +1 -1
  4. package/app-id-5cB6yioz.mjs +53 -0
  5. package/app-id-DcQ4u1c8.cjs +70 -0
  6. package/{auth-adapter-BIa-ZyVV.d.mts → auth-adapter-C17dzlzF.d.cts} +1 -1
  7. package/{auth-adapter-DwtMJb7D.d.cts → auth-adapter-CizFv7oU.d.mts} +1 -1
  8. package/auth-better-auth.d.cts +1 -1
  9. package/auth-better-auth.d.mts +1 -1
  10. package/auth-clerk.d.cts +1 -1
  11. package/auth-clerk.d.mts +1 -1
  12. package/auth-supabase.cjs +121 -0
  13. package/auth-supabase.d.cts +23 -0
  14. package/auth-supabase.d.mts +23 -0
  15. package/auth-supabase.mjs +119 -0
  16. package/auth-workos.d.cts +1 -1
  17. package/auth-workos.d.mts +1 -1
  18. package/core-adapter.d.cts +1 -1
  19. package/core-adapter.d.mts +1 -1
  20. package/core-auth-adapter.d.cts +1 -1
  21. package/core-auth-adapter.d.mts +1 -1
  22. package/core-mapping-score.d.cts +1 -0
  23. package/core-sync-engine.cjs +1 -1
  24. package/core-sync-engine.mjs +1 -1
  25. package/core-types.cjs +5 -1
  26. package/core-types.d.cts +2 -2
  27. package/core-types.d.mts +2 -2
  28. package/core-types.mjs +1 -1
  29. package/core-view-compiler.cjs +1 -1
  30. package/core-view-compiler.mjs +1 -1
  31. package/core.cjs +9 -5
  32. package/core.d.cts +6 -6
  33. package/core.d.mts +6 -6
  34. package/core.mjs +6 -6
  35. package/drizzle.cjs +121 -14
  36. package/drizzle.d.cts +8 -2
  37. package/drizzle.d.mts +8 -2
  38. package/drizzle.mjs +126 -19
  39. package/executor-CJEWurjZ.mjs +23 -0
  40. package/executor-CU-jRgpC.cjs +40 -0
  41. package/from-sql-BD7gR4bC.mjs +282 -0
  42. package/from-sql-CFgXkCe2.cjs +347 -0
  43. package/from-sql-CpGP7K3J.d.mts +70 -0
  44. package/from-sql-S8dSvU-e.d.cts +70 -0
  45. package/index-BoemTWH4.d.mts +134 -0
  46. package/index-CIupXz_w.d.cts +134 -0
  47. package/{index-Bh7o2J7K.d.mts → index-DOoX2GgI.d.mts} +3 -3
  48. package/{index-DRRTE5IJ.d.cts → index-uFDiQEjj.d.cts} +231 -5
  49. package/index.cjs +1079 -36
  50. package/index.d.cts +36 -0
  51. package/index.d.mts +35 -0
  52. package/index.mjs +1077 -34
  53. package/{internal-CdfVkh4O.d.mts → internal-D_2q2BOB.d.mts} +1 -1
  54. package/internal-adapter.d.cts +1 -1
  55. package/internal-adapter.d.mts +1 -1
  56. package/internal-auth-adapter.d.cts +1 -1
  57. package/internal-auth-adapter.d.mts +1 -1
  58. package/internal-sync-engine.cjs +1 -1
  59. package/internal-sync-engine.mjs +1 -1
  60. package/internal-types.cjs +5 -1
  61. package/internal-types.d.cts +2 -2
  62. package/internal-types.d.mts +2 -2
  63. package/internal-types.mjs +1 -1
  64. package/internal-view-compiler.cjs +1 -1
  65. package/internal-view-compiler.mjs +1 -1
  66. package/internal.cjs +9 -5
  67. package/internal.d.cts +5 -6
  68. package/internal.d.mts +6 -6
  69. package/internal.mjs +6 -6
  70. package/introspector-5w2x89RD.mjs +55 -0
  71. package/introspector-DT_Ma59k.cjs +60 -0
  72. package/kysely.cjs +56 -0
  73. package/kysely.d.cts +45 -0
  74. package/kysely.d.mts +45 -0
  75. package/kysely.mjs +54 -0
  76. package/{namespace-probe-JuHriruA.d.mts → namespace-probe-CUR2zG2l.d.mts} +41 -4
  77. package/package.json +45 -1
  78. package/projection-guard-C70l5U24.cjs +170 -0
  79. package/projection-guard-DOt_nbGn.mjs +147 -0
  80. package/{projection-sql-DQQdjw9I.mjs → projection-sql-2joBkLz2.mjs} +13 -3
  81. package/{projection-sql-BkrHR2ea.cjs → projection-sql-DS5sVTY-.cjs} +18 -2
  82. package/sdk-Bzkr24NW.cjs +207 -0
  83. package/sdk-D2WwGBzk.mjs +178 -0
  84. package/sdk.cjs +8 -6
  85. package/sdk.d.cts +7 -1
  86. package/sdk.d.mts +7 -1
  87. package/sdk.mjs +3 -2
  88. package/sql.cjs +20 -0
  89. package/sql.d.cts +3 -0
  90. package/sql.d.mts +3 -0
  91. package/sql.mjs +7 -0
  92. package/{sdk-BOarpe5I.cjs → src-CZIdwwI2.cjs} +203 -583
  93. package/{sdk-BkMDOfCk.mjs → src-tFhC1Ru2.mjs} +175 -531
  94. package/supabase-contact-3ke1KKUs.mjs +595 -0
  95. package/supabase-contact-BXQ0nnLq.cjs +624 -0
  96. package/supabase.cjs +165 -0
  97. package/supabase.d.cts +20 -0
  98. package/supabase.d.mts +20 -0
  99. package/supabase.mjs +164 -0
  100. package/sync-CdA9dgZz.cjs +519 -0
  101. package/sync-Q0O-2kFI.mjs +382 -0
  102. package/{sync-engine-yFLEyId3.mjs → sync-engine-D0mJUeqP.mjs} +1 -1
  103. package/{sync-engine-DNSoZeo0.cjs → sync-engine-hU041kXO.cjs} +1 -1
  104. package/{namespace-probe-CcL6Wj8E.d.cts → types-CzL7lUH9.d.cts} +84 -47
  105. package/types-KMH5D5Lg.mjs +32 -0
  106. package/{types-BBfwsDxe.d.cts → types-f-Vcv-pl.d.cts} +18 -2
  107. package/{types-BBfwsDxe.d.mts → types-f-Vcv-pl.d.mts} +18 -2
  108. package/types-kR1kUlmz.cjs +67 -0
  109. package/{view-compiler-CSHSqZl7.mjs → view-compiler-BhKiezRH.mjs} +1 -1
  110. package/{view-compiler-NqiortOA.cjs → view-compiler-DgZadq1F.cjs} +1 -1
  111. package/vite.d.cts +1 -1
  112. package/vite.d.mts +1 -1
  113. package/drizzle-meta-BPnRLpsB.cjs +0 -8
  114. package/drizzle-meta-D00lFvAk.mjs +0 -3
  115. package/internal-D7qVRIFb.d.cts +0 -228
  116. package/types-8KSw2AWg.mjs +0 -8
  117. package/types-B8m39L1s.cjs +0 -19
package/README.md CHANGED
@@ -178,6 +178,44 @@ section of the guide.
178
178
  Use `--schema` when your Drizzle schema is not in a common location or in
179
179
  `drizzle.config.ts`.
180
180
 
181
+ #### Apps without an ORM (Supabase, raw SQL)
182
+
183
+ When the app has no Drizzle schema, `init` takes one of two paths.
184
+
185
+ - **Server apps** (Next.js, TanStack Start and others), when `init` can read the
186
+ schema: it writes `clivly.config.ts` using `fromSql`, `discoverFromSql`,
187
+ `sqlIntrospector` and `sqlAppIdStore` from `clivly/sql`, with `pgExecutor`
188
+ or `connectPostgresJs` as the client. A Supabase Auth contact is read through
189
+ `supabaseContactSource`, which joins `public.profiles` when its id
190
+ references `auth.users` and gives each contact a flat `full_name`. It reads
191
+ the schema from `DATABASE_URL` or `SUPABASE_DB_URL` (environment,
192
+ `.env.local` or `.env`; never printed or stored), which uses your app's
193
+ `postgres` or `pg`, or from the linked Supabase CLI
194
+ (`supabase db query --linked --output json`, falling back to
195
+ `npx --yes supabase`), which needs no driver. The CLI runs only once the
196
+ project is linked (`supabase/.temp/project-ref` exists); otherwise `init`
197
+ prints the `npx supabase link` hint and downloads nothing. If the app has
198
+ neither driver,
199
+ `init` installs `postgres` for the generated config. The config reads
200
+ `DATABASE_URL || SUPABASE_DB_URL`; with neither set the app builds, but at
201
+ runtime it logs one error and never contacts Clivly.
202
+ - **Browser-only apps** (Vite SPA, Lovable, Bolt), or when no schema could be
203
+ read: it writes `supabase/functions/clivly/index.ts`, `deno.json` and a
204
+ `[functions.clivly] verify_jwt = false` block in `supabase/config.toml`. In
205
+ this order: set `CLIVLY_SECRET_KEY` as a function secret, deploy with
206
+ `npx supabase functions deploy clivly`, run `npx clivly connect --supabase`
207
+ (`--project-url` overrides detection; it succeeds only when at least one
208
+ contact would sync, and sends the first heartbeat), then generate the trigger
209
+ secret at Connections → Setup → "Clivly can start a sync" and set it with
210
+ `npx supabase secrets set CLIVLY_SYNC_TRIGGER_SECRET=…` (no redeploy).
211
+ Start the first sync: Clivly dashboard → Connections → Setup →
212
+ "Run the first sync".
213
+
214
+ `auth.users` contributes only `id`, `email`, `phone`, `created_at`,
215
+ `updated_at`, `last_sign_in_at` and `full_name`, `name` and `avatar_url` from
216
+ `raw_user_meta_data`; anonymous users are excluded. See
217
+ [Connect a Supabase app](https://clivly.com/docs/guides/connect-a-supabase-app).
218
+
181
219
  #### Monorepos
182
220
 
183
221
  In a workspace, `init` reads your `pnpm-workspace.yaml` (or `workspaces` array)
@@ -272,7 +310,7 @@ the CLI requires pairing.
272
310
  | Value | Where to get it | Notes |
273
311
  | --- | --- | --- |
274
312
  | `CLIVLY_SECRET_KEY` | Dashboard → **Connect app**, or **Settings → API keys** | **Shown once.** Copy it immediately; you cannot retrieve it later, only regenerate. Regenerating **revokes the previous key**, so redeploy after rotating. The legacy name `CLIVLY_API_KEY` is still accepted as a fallback |
275
- | `CLIVLY_SYNC_TRIGGER_SECRET` | Dashboard → **Integrations → Remote sync** | Must match the value in your app's env exactly. A mismatch surfaces as a `401` on the signed trigger |
313
+ | `CLIVLY_SYNC_TRIGGER_SECRET` | Dashboard → **Connections → Setup → "Clivly can start a sync"** (Generate secret; unlocks after the first heartbeat) | Must match the value in your app's env exactly. A mismatch surfaces as a `401` on the signed trigger |
276
314
  | `CLIVLY_SYNC_TRIGGER_URL` | Your own deployment | The public URL of your mounted tick route. `init` and `login` leave the variable empty and add a commented `https://<yourDomain.com>/api/clivly/tick` example. Most platforms derive it automatically; uncomment and replace the example only when needed. Optional until you deploy — push-only setups can leave it empty |
277
315
  | `CLIVLY_PUBLISHABLE_KEY` | Same place as the secret key | Only needed for the chat widget. Safe to expose in client code |
278
316
 
@@ -424,7 +462,7 @@ Clivly push-schema
424
462
  ✅ Schema reported to Clivly.
425
463
  ✅ Created 1 custom object: client_accounts.
426
464
  ✅ Mapped 2 entities: clients, advisors.
427
- Open Integrations → Mapping to review them.
465
+ Open Clivly dashboard → Connections → What syncs to review them.
428
466
  ```
429
467
 
430
468
  **Exits `1` if Clivly refuses your config** — most often because an entity would
@@ -567,6 +605,7 @@ import {
567
605
  import { clivlyVite } from "clivly/vite";
568
606
  import { createClerkAuthAdapter } from "clivly/auth/clerk";
569
607
  import { createWorkOSAuthAdapter } from "clivly/auth/workos";
608
+ import { createSupabaseAuthAdapter } from "clivly/auth/supabase";
570
609
  import { createBetterAuthAdapter } from "clivly/auth/better-auth";
571
610
  ```
572
611
 
@@ -610,6 +649,7 @@ only what your app actually uses:
610
649
  | `clivly/vite` | `vite` |
611
650
  | `clivly/auth/clerk` | `@clerk/backend` |
612
651
  | `clivly/auth/workos` | `@workos-inc/node` |
652
+ | `clivly/auth/supabase` | none — uses `fetch` only |
613
653
  | `clivly/auth/better-auth` | none — you pass your own `betterAuth({...})` instance |
614
654
 
615
655
  `clivly/core/*` is deprecated in favour of `clivly/internal/*`. It still
@@ -1,4 +1,4 @@
1
- import { E as Task, M as UpdateContactInput, N as UpdateDealInput, O as TaskFilters, P as UpdateTaskInput, a as Contact, b as PageRequest, d as CreateContactInput, f as CreateDealInput, h as Deal, i as CompanyFilters, j as UpdateCompanyInput, l as CreateActivityInput, o as ContactFilters, p as CreateTaskInput, r as Company, t as Activity, u as CreateCompanyInput, w as RecordSource, y as Page } from "./types-BBfwsDxe.mjs";
1
+ import { A as TaskFilters, E as RecordSource, F as UpdateDealInput, I as UpdateTaskInput, N as UpdateCompanyInput, O as Task, P as UpdateContactInput, S as PageRequest, a as CompanyFilters, d as CreateCompanyInput, f as CreateContactInput, g as Deal, i as Company, m as CreateTaskInput, o as Contact, p as CreateDealInput, s as ContactFilters, t as Activity, u as CreateActivityInput, x as Page } from "./types-f-Vcv-pl.cjs";
2
2
  /**
3
3
  * The contract every ORM implementation fulfils. `packages/drizzle` is the first
4
4
  * implementation; Prisma/Kysely/TypeORM can follow without changes to consumers.
@@ -1,4 +1,4 @@
1
- import { E as Task, M as UpdateContactInput, N as UpdateDealInput, O as TaskFilters, P as UpdateTaskInput, a as Contact, b as PageRequest, d as CreateContactInput, f as CreateDealInput, h as Deal, i as CompanyFilters, j as UpdateCompanyInput, l as CreateActivityInput, o as ContactFilters, p as CreateTaskInput, r as Company, t as Activity, u as CreateCompanyInput, w as RecordSource, y as Page } from "./types-BBfwsDxe.cjs";
1
+ import { A as TaskFilters, E as RecordSource, F as UpdateDealInput, I as UpdateTaskInput, N as UpdateCompanyInput, O as Task, P as UpdateContactInput, S as PageRequest, a as CompanyFilters, d as CreateCompanyInput, f as CreateContactInput, g as Deal, i as Company, m as CreateTaskInput, o as Contact, p as CreateDealInput, s as ContactFilters, t as Activity, u as CreateActivityInput, x as Page } from "./types-f-Vcv-pl.mjs";
2
2
  /**
3
3
  * The contract every ORM implementation fulfils. `packages/drizzle` is the first
4
4
  * implementation; Prisma/Kysely/TypeORM can follow without changes to consumers.
@@ -0,0 +1,53 @@
1
+ import { d as postgresDialect } from "./from-sql-BD7gR4bC.mjs";
2
+ // ../sdk/src/sql/app-id.ts
3
+ /** The one-row host table that keeps the ID Clivly issued this app. */
4
+ const APP_ID_TABLE = "crm_clivly_app";
5
+ /** Roles Supabase's Data API serves as. Plain Postgres has neither. */
6
+ const DATA_API_ROLES = ["anon", "authenticated"];
7
+ /**
8
+ * Keeps `crm_clivly_app` off Supabase's Data API. Supabase grants `anon` and
9
+ * `authenticated` ALL on every new `public` table, and the anon key ships in
10
+ * every frontend, so without this anyone could read or rewrite the app ID
11
+ * over `/rest/v1/crm_clivly_app` (and Security Advisor flags "RLS disabled in
12
+ * public"). Enabling RLS with no policies hides the rows from both roles; the
13
+ * revoke removes the grant itself. The SDK connects as the table's owner, so
14
+ * neither affects it.
15
+ *
16
+ * One `do` block, safe to run on every boot: each role is revoked only when
17
+ * `pg_roles` has it, so plain Postgres is untouched, and a connection that
18
+ * does not own the table (it was created by another role) skips the RLS step
19
+ * with a warning instead of failing the heartbeat.
20
+ */
21
+ function appIdLockdownSql(quotedTable) {
22
+ const revokes = DATA_API_ROLES.map((role) => `if exists (select 1 from pg_roles where rolname = '${role}') then revoke all on table ${quotedTable} from ${role}; end if;`).join(" ");
23
+ return `do $clivly$ begin begin alter table ${quotedTable} enable row level security; exception when insufficient_privilege then raise warning 'clivly: could not enable row level security on ${quotedTable.replaceAll("\"", "")}'; end; ${revokes} end $clivly$`;
24
+ }
25
+ /**
26
+ * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
27
+ * one-row `crm_clivly_app` table, created on first use. The only write Clivly
28
+ * ever makes to a host database.
29
+ */
30
+ function sqlAppIdStore(executor) {
31
+ const { quoteIdent, param } = postgresDialect;
32
+ const table = quoteIdent(APP_ID_TABLE);
33
+ let ready = null;
34
+ const ensureTable = () => {
35
+ ready ??= executor.query(`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).then(() => executor.query(appIdLockdownSql(table))).catch((error) => {
36
+ ready = null;
37
+ throw error;
38
+ });
39
+ return ready;
40
+ };
41
+ return {
42
+ async get() {
43
+ await ensureTable();
44
+ const value = (await executor.query(`select app_id from ${table} order by created_at limit 1`))[0]?.app_id;
45
+ return typeof value === "string" ? value : null;
46
+ },
47
+ async set(appId) {
48
+ await ensureTable();
49
+ await executor.query(`insert into ${table} (app_id) select ${param(1)} where not exists (select 1 from ${table})`, [appId]);
50
+ }
51
+ };
52
+ }
53
+ export { appIdLockdownSql as n, sqlAppIdStore as r, APP_ID_TABLE as t };
@@ -0,0 +1,70 @@
1
+ const require_from_sql = require("./from-sql-CFgXkCe2.cjs");
2
+ // ../sdk/src/sql/app-id.ts
3
+ /** The one-row host table that keeps the ID Clivly issued this app. */
4
+ const APP_ID_TABLE = "crm_clivly_app";
5
+ /** Roles Supabase's Data API serves as. Plain Postgres has neither. */
6
+ const DATA_API_ROLES = ["anon", "authenticated"];
7
+ /**
8
+ * Keeps `crm_clivly_app` off Supabase's Data API. Supabase grants `anon` and
9
+ * `authenticated` ALL on every new `public` table, and the anon key ships in
10
+ * every frontend, so without this anyone could read or rewrite the app ID
11
+ * over `/rest/v1/crm_clivly_app` (and Security Advisor flags "RLS disabled in
12
+ * public"). Enabling RLS with no policies hides the rows from both roles; the
13
+ * revoke removes the grant itself. The SDK connects as the table's owner, so
14
+ * neither affects it.
15
+ *
16
+ * One `do` block, safe to run on every boot: each role is revoked only when
17
+ * `pg_roles` has it, so plain Postgres is untouched, and a connection that
18
+ * does not own the table (it was created by another role) skips the RLS step
19
+ * with a warning instead of failing the heartbeat.
20
+ */
21
+ function appIdLockdownSql(quotedTable) {
22
+ const revokes = DATA_API_ROLES.map((role) => `if exists (select 1 from pg_roles where rolname = '${role}') then revoke all on table ${quotedTable} from ${role}; end if;`).join(" ");
23
+ return `do $clivly$ begin begin alter table ${quotedTable} enable row level security; exception when insufficient_privilege then raise warning 'clivly: could not enable row level security on ${quotedTable.replaceAll("\"", "")}'; end; ${revokes} end $clivly$`;
24
+ }
25
+ /**
26
+ * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
27
+ * one-row `crm_clivly_app` table, created on first use. The only write Clivly
28
+ * ever makes to a host database.
29
+ */
30
+ function sqlAppIdStore(executor) {
31
+ const { quoteIdent, param } = require_from_sql.postgresDialect;
32
+ const table = quoteIdent(APP_ID_TABLE);
33
+ let ready = null;
34
+ const ensureTable = () => {
35
+ ready ??= executor.query(`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).then(() => executor.query(appIdLockdownSql(table))).catch((error) => {
36
+ ready = null;
37
+ throw error;
38
+ });
39
+ return ready;
40
+ };
41
+ return {
42
+ async get() {
43
+ await ensureTable();
44
+ const value = (await executor.query(`select app_id from ${table} order by created_at limit 1`))[0]?.app_id;
45
+ return typeof value === "string" ? value : null;
46
+ },
47
+ async set(appId) {
48
+ await ensureTable();
49
+ await executor.query(`insert into ${table} (app_id) select ${param(1)} where not exists (select 1 from ${table})`, [appId]);
50
+ }
51
+ };
52
+ }
53
+ Object.defineProperty(exports, "APP_ID_TABLE", {
54
+ enumerable: true,
55
+ get: function() {
56
+ return APP_ID_TABLE;
57
+ }
58
+ });
59
+ Object.defineProperty(exports, "appIdLockdownSql", {
60
+ enumerable: true,
61
+ get: function() {
62
+ return appIdLockdownSql;
63
+ }
64
+ });
65
+ Object.defineProperty(exports, "sqlAppIdStore", {
66
+ enumerable: true,
67
+ get: function() {
68
+ return sqlAppIdStore;
69
+ }
70
+ });
@@ -1,4 +1,4 @@
1
- import { m as CrmRole } from "./types-BBfwsDxe.mjs";
1
+ import { h as CrmRole } from "./types-f-Vcv-pl.cjs";
2
2
  interface ClivlyUser {
3
3
  email: string;
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { m as CrmRole } from "./types-BBfwsDxe.cjs";
1
+ import { h as CrmRole } from "./types-f-Vcv-pl.mjs";
2
2
  interface ClivlyUser {
3
3
  email: string;
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-DwtMJb7D.cjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
2
2
  interface BetterAuthLikeUser {
3
3
  email?: string | null;
4
4
  id: string;
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-BIa-ZyVV.mjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
2
2
  interface BetterAuthLikeUser {
3
3
  email?: string | null;
4
4
  id: string;
package/auth-clerk.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-DwtMJb7D.cjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
2
2
  interface ClerkLikeUser {
3
3
  emailAddresses?: Array<{
4
4
  id: string;
package/auth-clerk.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-BIa-ZyVV.mjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
2
2
  interface ClerkLikeUser {
3
3
  emailAddresses?: Array<{
4
4
  id: string;
@@ -0,0 +1,121 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ // ../auth-supabase/src/map.ts
3
+ const asNonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
4
+ function supabaseUserToClivlyUser(user) {
5
+ if (!(user.email && user.id)) return null;
6
+ const meta = user.user_metadata ?? {};
7
+ const name = asNonEmptyString(meta.full_name) ?? asNonEmptyString(meta.name);
8
+ return {
9
+ id: user.id,
10
+ email: user.email,
11
+ name
12
+ };
13
+ }
14
+ // ../auth-supabase/src/index.ts
15
+ const BEARER = /^Bearer\s+(\S+)$/i;
16
+ const SUPABASE_HOST = /^([a-z0-9]+)\.supabase\.(?:co|in)$/i;
17
+ const AUTH_COOKIE = /^sb-.+-auth-token$/;
18
+ const CHUNKED_COOKIE = /^(sb-.+-auth-token)\.(\d+)$/;
19
+ const BASE64_PREFIX = "base64-";
20
+ const TRAILING_SLASHES = /\/+$/;
21
+ const DASH = /-/g;
22
+ const UNDERSCORE = /_/g;
23
+ const BASE64_CHARS = /^[A-Za-z0-9+/]*={0,2}$/;
24
+ function projectRef(supabaseUrl) {
25
+ try {
26
+ return SUPABASE_HOST.exec(new URL(supabaseUrl).hostname)?.[1];
27
+ } catch {
28
+ return;
29
+ }
30
+ }
31
+ function parseCookies(header) {
32
+ const jar = /* @__PURE__ */ new Map();
33
+ for (const part of header.split(";")) {
34
+ const eq = part.indexOf("=");
35
+ if (eq > 0) jar.set(part.slice(0, eq).trim(), part.slice(eq + 1).trim());
36
+ }
37
+ return jar;
38
+ }
39
+ function joinCookie(jar, base) {
40
+ const whole = jar.get(base);
41
+ if (whole !== void 0) return whole;
42
+ let out = "";
43
+ for (let i = 0; jar.has(`${base}.${i}`); i++) out += jar.get(`${base}.${i}`);
44
+ return out || null;
45
+ }
46
+ function candidateBases(jar, ref) {
47
+ if (ref) return [`sb-${ref}-auth-token`];
48
+ const bases = /* @__PURE__ */ new Set();
49
+ for (const key of jar.keys()) {
50
+ const chunk = CHUNKED_COOKIE.exec(key);
51
+ if (chunk?.[1]) bases.add(chunk[1]);
52
+ else if (AUTH_COOKIE.test(key)) bases.add(key);
53
+ }
54
+ return [...bases];
55
+ }
56
+ function decodeCookieValue(raw) {
57
+ let value = raw;
58
+ try {
59
+ value = decodeURIComponent(raw);
60
+ } catch {}
61
+ if (!value.startsWith(BASE64_PREFIX)) return value;
62
+ const b64 = value.slice(7).replace(DASH, "+").replace(UNDERSCORE, "/");
63
+ if (!BASE64_CHARS.test(b64)) return null;
64
+ try {
65
+ return new TextDecoder().decode(Uint8Array.from(atob(b64), (c) => c.charCodeAt(0)));
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ function tokenFromCookies(header, ref) {
71
+ const jar = parseCookies(header);
72
+ for (const base of candidateBases(jar, ref)) {
73
+ const raw = joinCookie(jar, base);
74
+ const json = raw === null ? null : decodeCookieValue(raw);
75
+ if (json === null) continue;
76
+ try {
77
+ const parsed = JSON.parse(json);
78
+ const token = parsed && typeof parsed === "object" ? parsed.access_token : void 0;
79
+ if (typeof token === "string" && token.length > 0) return token;
80
+ } catch {}
81
+ }
82
+ return null;
83
+ }
84
+ function extractToken(req, ref) {
85
+ const bearer = BEARER.exec(req.headers.get("authorization") ?? "");
86
+ if (bearer?.[1]) return bearer[1];
87
+ const cookie = req.headers.get("cookie");
88
+ return cookie ? tokenFromCookies(cookie, ref) : null;
89
+ }
90
+ /**
91
+ * Supabase Auth → ClivlyAuthAdapter. Takes the access token from an
92
+ * `Authorization: Bearer` header, else the `sb-<ref>-auth-token` cookie, and
93
+ * verifies it by asking Supabase (`GET /auth/v1/user`). The JWT is never
94
+ * decoded or trusted locally. Answers "who is this person?" only.
95
+ */
96
+ function createSupabaseAuthAdapter(options) {
97
+ const base = options.supabaseUrl.replace(TRAILING_SLASHES, "");
98
+ const ref = projectRef(base);
99
+ const doFetch = options.fetch ?? fetch;
100
+ return { async getUser(req) {
101
+ const token = extractToken(req, ref);
102
+ if (!token) return null;
103
+ let res;
104
+ try {
105
+ res = await doFetch(`${base}/auth/v1/user`, { headers: {
106
+ apikey: options.anonKey,
107
+ authorization: `Bearer ${token}`
108
+ } });
109
+ } catch {
110
+ return null;
111
+ }
112
+ if (res.status !== 200) return null;
113
+ try {
114
+ return supabaseUserToClivlyUser(await res.json());
115
+ } catch {
116
+ return null;
117
+ }
118
+ } };
119
+ }
120
+ exports.createSupabaseAuthAdapter = createSupabaseAuthAdapter;
121
+ exports.supabaseUserToClivlyUser = supabaseUserToClivlyUser;
@@ -0,0 +1,23 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
2
+ interface SupabaseLikeUser {
3
+ email?: string | null;
4
+ id: string;
5
+ user_metadata?: Record<string, unknown> | null;
6
+ }
7
+ export declare function supabaseUserToClivlyUser(user: SupabaseLikeUser): ClivlyUser | null;
8
+ export interface SupabaseAuthAdapterOptions {
9
+ /** The project's anon (publishable) key, sent as the `apikey` header. */
10
+ anonKey: string;
11
+ /** Override fetch (tests, custom runtimes). */
12
+ fetch?: typeof fetch;
13
+ /** Project URL, e.g. https://<ref>.supabase.co (or a custom domain). */
14
+ supabaseUrl: string;
15
+ }
16
+ /**
17
+ * Supabase Auth → ClivlyAuthAdapter. Takes the access token from an
18
+ * `Authorization: Bearer` header, else the `sb-<ref>-auth-token` cookie, and
19
+ * verifies it by asking Supabase (`GET /auth/v1/user`). The JWT is never
20
+ * decoded or trusted locally. Answers "who is this person?" only.
21
+ */
22
+ export declare function createSupabaseAuthAdapter(options: SupabaseAuthAdapterOptions): ClivlyAuthAdapter;
23
+ export type { SupabaseLikeUser };
@@ -0,0 +1,23 @@
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
2
+ interface SupabaseLikeUser {
3
+ email?: string | null;
4
+ id: string;
5
+ user_metadata?: Record<string, unknown> | null;
6
+ }
7
+ export declare function supabaseUserToClivlyUser(user: SupabaseLikeUser): ClivlyUser | null;
8
+ export interface SupabaseAuthAdapterOptions {
9
+ /** The project's anon (publishable) key, sent as the `apikey` header. */
10
+ anonKey: string;
11
+ /** Override fetch (tests, custom runtimes). */
12
+ fetch?: typeof fetch;
13
+ /** Project URL, e.g. https://<ref>.supabase.co (or a custom domain). */
14
+ supabaseUrl: string;
15
+ }
16
+ /**
17
+ * Supabase Auth → ClivlyAuthAdapter. Takes the access token from an
18
+ * `Authorization: Bearer` header, else the `sb-<ref>-auth-token` cookie, and
19
+ * verifies it by asking Supabase (`GET /auth/v1/user`). The JWT is never
20
+ * decoded or trusted locally. Answers "who is this person?" only.
21
+ */
22
+ export declare function createSupabaseAuthAdapter(options: SupabaseAuthAdapterOptions): ClivlyAuthAdapter;
23
+ export type { SupabaseLikeUser };
@@ -0,0 +1,119 @@
1
+ // ../auth-supabase/src/map.ts
2
+ const asNonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
3
+ function supabaseUserToClivlyUser(user) {
4
+ if (!(user.email && user.id)) return null;
5
+ const meta = user.user_metadata ?? {};
6
+ const name = asNonEmptyString(meta.full_name) ?? asNonEmptyString(meta.name);
7
+ return {
8
+ id: user.id,
9
+ email: user.email,
10
+ name
11
+ };
12
+ }
13
+ // ../auth-supabase/src/index.ts
14
+ const BEARER = /^Bearer\s+(\S+)$/i;
15
+ const SUPABASE_HOST = /^([a-z0-9]+)\.supabase\.(?:co|in)$/i;
16
+ const AUTH_COOKIE = /^sb-.+-auth-token$/;
17
+ const CHUNKED_COOKIE = /^(sb-.+-auth-token)\.(\d+)$/;
18
+ const BASE64_PREFIX = "base64-";
19
+ const TRAILING_SLASHES = /\/+$/;
20
+ const DASH = /-/g;
21
+ const UNDERSCORE = /_/g;
22
+ const BASE64_CHARS = /^[A-Za-z0-9+/]*={0,2}$/;
23
+ function projectRef(supabaseUrl) {
24
+ try {
25
+ return SUPABASE_HOST.exec(new URL(supabaseUrl).hostname)?.[1];
26
+ } catch {
27
+ return;
28
+ }
29
+ }
30
+ function parseCookies(header) {
31
+ const jar = /* @__PURE__ */ new Map();
32
+ for (const part of header.split(";")) {
33
+ const eq = part.indexOf("=");
34
+ if (eq > 0) jar.set(part.slice(0, eq).trim(), part.slice(eq + 1).trim());
35
+ }
36
+ return jar;
37
+ }
38
+ function joinCookie(jar, base) {
39
+ const whole = jar.get(base);
40
+ if (whole !== void 0) return whole;
41
+ let out = "";
42
+ for (let i = 0; jar.has(`${base}.${i}`); i++) out += jar.get(`${base}.${i}`);
43
+ return out || null;
44
+ }
45
+ function candidateBases(jar, ref) {
46
+ if (ref) return [`sb-${ref}-auth-token`];
47
+ const bases = /* @__PURE__ */ new Set();
48
+ for (const key of jar.keys()) {
49
+ const chunk = CHUNKED_COOKIE.exec(key);
50
+ if (chunk?.[1]) bases.add(chunk[1]);
51
+ else if (AUTH_COOKIE.test(key)) bases.add(key);
52
+ }
53
+ return [...bases];
54
+ }
55
+ function decodeCookieValue(raw) {
56
+ let value = raw;
57
+ try {
58
+ value = decodeURIComponent(raw);
59
+ } catch {}
60
+ if (!value.startsWith(BASE64_PREFIX)) return value;
61
+ const b64 = value.slice(7).replace(DASH, "+").replace(UNDERSCORE, "/");
62
+ if (!BASE64_CHARS.test(b64)) return null;
63
+ try {
64
+ return new TextDecoder().decode(Uint8Array.from(atob(b64), (c) => c.charCodeAt(0)));
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+ function tokenFromCookies(header, ref) {
70
+ const jar = parseCookies(header);
71
+ for (const base of candidateBases(jar, ref)) {
72
+ const raw = joinCookie(jar, base);
73
+ const json = raw === null ? null : decodeCookieValue(raw);
74
+ if (json === null) continue;
75
+ try {
76
+ const parsed = JSON.parse(json);
77
+ const token = parsed && typeof parsed === "object" ? parsed.access_token : void 0;
78
+ if (typeof token === "string" && token.length > 0) return token;
79
+ } catch {}
80
+ }
81
+ return null;
82
+ }
83
+ function extractToken(req, ref) {
84
+ const bearer = BEARER.exec(req.headers.get("authorization") ?? "");
85
+ if (bearer?.[1]) return bearer[1];
86
+ const cookie = req.headers.get("cookie");
87
+ return cookie ? tokenFromCookies(cookie, ref) : null;
88
+ }
89
+ /**
90
+ * Supabase Auth → ClivlyAuthAdapter. Takes the access token from an
91
+ * `Authorization: Bearer` header, else the `sb-<ref>-auth-token` cookie, and
92
+ * verifies it by asking Supabase (`GET /auth/v1/user`). The JWT is never
93
+ * decoded or trusted locally. Answers "who is this person?" only.
94
+ */
95
+ function createSupabaseAuthAdapter(options) {
96
+ const base = options.supabaseUrl.replace(TRAILING_SLASHES, "");
97
+ const ref = projectRef(base);
98
+ const doFetch = options.fetch ?? fetch;
99
+ return { async getUser(req) {
100
+ const token = extractToken(req, ref);
101
+ if (!token) return null;
102
+ let res;
103
+ try {
104
+ res = await doFetch(`${base}/auth/v1/user`, { headers: {
105
+ apikey: options.anonKey,
106
+ authorization: `Bearer ${token}`
107
+ } });
108
+ } catch {
109
+ return null;
110
+ }
111
+ if (res.status !== 200) return null;
112
+ try {
113
+ return supabaseUserToClivlyUser(await res.json());
114
+ } catch {
115
+ return null;
116
+ }
117
+ } };
118
+ }
119
+ export { createSupabaseAuthAdapter, supabaseUserToClivlyUser };
package/auth-workos.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-DwtMJb7D.cjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
2
2
  interface WorkOSLikeUser {
3
3
  email: string;
4
4
  firstName?: string | null;
package/auth-workos.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-BIa-ZyVV.mjs";
1
+ import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
2
2
  interface WorkOSLikeUser {
3
3
  email: string;
4
4
  firstName?: string | null;
@@ -1,3 +1,3 @@
1
- import { t as CRMAdapter } from "./adapter-BK3gsby5.cjs";
1
+ import { t as CRMAdapter } from "./adapter--YV7du3i.cjs";
2
2
  import "./internal-adapter.cjs";
3
3
  export { CRMAdapter };
@@ -1,3 +1,3 @@
1
- import { t as CRMAdapter } from "./adapter-B4v4dwgD.mjs";
1
+ import { t as CRMAdapter } from "./adapter-DD3K3dCW.mjs";
2
2
  import "./internal-adapter.mjs";
3
3
  export { CRMAdapter };
@@ -1,3 +1,3 @@
1
- import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-DwtMJb7D.cjs";
1
+ import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
2
2
  import "./internal-auth-adapter.cjs";
3
3
  export { ClivlyAuthAdapter, ClivlyUser, CrmMembership, MembershipResolver, authCustom };
@@ -1,3 +1,3 @@
1
- import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-BIa-ZyVV.mjs";
1
+ import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
2
2
  import "./internal-auth-adapter.mjs";
3
3
  export { ClivlyAuthAdapter, ClivlyUser, CrmMembership, MembershipResolver, authCustom };
@@ -1,2 +1,3 @@
1
1
  import { a as Scored, c as W, d as isTextLike, f as isTimestampLike, i as RELATIONSHIP_TIERS, l as isAmbiguous, n as CONCEPT_TIERS, o as Thresholds, p as tierFor, r as FIELD_TIERS, s as Tier, t as AMBIGUITY_MARGIN, u as isNumericLike } from "./mapping-score-BKrxddz0.cjs";
2
+ import "./internal-mapping-score.cjs";
2
3
  export { AMBIGUITY_MARGIN, CONCEPT_TIERS, FIELD_TIERS, RELATIONSHIP_TIERS, Scored, Thresholds, Tier, W, isAmbiguous, isNumericLike, isTextLike, isTimestampLike, tierFor };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sync_engine = require("./sync-engine-DNSoZeo0.cjs");
2
+ const require_sync_engine = require("./sync-engine-hU041kXO.cjs");
3
3
  const require_deprecate_subpath = require("./deprecate-subpath-dGwDiHKV.cjs");
4
4
  require("./internal-sync-engine.cjs");
5
5
  // src/core-sync-engine.ts
@@ -1,4 +1,4 @@
1
- export { t as computeSampleWarnings, n as isRemovalAction, r as previewSync, i as reconcile, a as resolveActions, o as runSync } from "./sync-engine-yFLEyId3.mjs";
1
+ export { t as computeSampleWarnings, n as isRemovalAction, r as previewSync, i as reconcile, a as resolveActions, o as runSync } from "./sync-engine-D0mJUeqP.mjs";
2
2
  import { t as warnDeprecatedSubpath } from "./deprecate-subpath-CK37DKXH.mjs";
3
3
  import "./internal-sync-engine.mjs";
4
4
  // src/core-sync-engine.ts
package/core-types.cjs CHANGED
@@ -1,8 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_types = require("./types-B8m39L1s.cjs");
2
+ const require_types = require("./types-kR1kUlmz.cjs");
3
3
  const require_deprecate_subpath = require("./deprecate-subpath-dGwDiHKV.cjs");
4
4
  require("./internal-types.cjs");
5
5
  // src/core-types.ts
6
6
  require_deprecate_subpath.warnDeprecatedSubpath("clivly/core/types", "clivly/internal/types");
7
+ exports.CONTACT_STATUSES = require_types.CONTACT_STATUSES;
8
+ exports.LIFECYCLE_STATUSES = require_types.LIFECYCLE_STATUSES;
7
9
  exports.OPEN_STAGE_TYPE = require_types.OPEN_STAGE_TYPE;
10
+ exports.VENDOR_STATUS = require_types.VENDOR_STATUS;
8
11
  exports.isClosedStageType = require_types.isClosedStageType;
12
+ exports.isContactStatus = require_types.isContactStatus;
package/core-types.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { A as TaskStatus, C as PipelineStageConfig, D as TaskEntityType, E as Task, F as ValueInterval, I as isClosedStageType, M as UpdateContactInput, N as UpdateDealInput, O as TaskFilters, P as UpdateTaskInput, S as PipelineKind, T as StageType, _ as Note, a as Contact, b as PageRequest, c as ContactStatus, d as CreateContactInput, f as CreateDealInput, g as DealStage, h as Deal, i as CompanyFilters, j as UpdateCompanyInput, k as TaskPriority, l as CreateActivityInput, m as CrmRole, n as ActivityType, o as ContactFilters, p as CreateTaskInput, r as Company, s as ContactSource, t as Activity, u as CreateCompanyInput, v as OPEN_STAGE_TYPE, w as RecordSource, x as PipelineConfig, y as Page } from "./types-BBfwsDxe.cjs";
1
+ import { A as TaskFilters, B as isContactStatus, C as PipelineConfig, D as StageType, E as RecordSource, F as UpdateDealInput, I as UpdateTaskInput, L as VENDOR_STATUS, M as TaskStatus, N as UpdateCompanyInput, O as Task, P as UpdateContactInput, R as ValueInterval, S as PageRequest, T as PipelineStageConfig, _ as DealStage, a as CompanyFilters, b as OPEN_STAGE_TYPE, c as ContactSource, d as CreateCompanyInput, f as CreateContactInput, g as Deal, h as CrmRole, i as Company, j as TaskPriority, k as TaskEntityType, l as ContactStatus, m as CreateTaskInput, n as ActivityType, o as Contact, p as CreateDealInput, r as CONTACT_STATUSES, s as ContactFilters, t as Activity, u as CreateActivityInput, v as LIFECYCLE_STATUSES, w as PipelineKind, x as Page, y as Note, z as isClosedStageType } from "./types-f-Vcv-pl.cjs";
2
2
  import "./internal-types.cjs";
3
- export { Activity, ActivityType, Company, CompanyFilters, Contact, ContactFilters, ContactSource, ContactStatus, CreateActivityInput, CreateCompanyInput, CreateContactInput, CreateDealInput, CreateTaskInput, CrmRole, Deal, DealStage, Note, OPEN_STAGE_TYPE, Page, PageRequest, PipelineConfig, PipelineKind, PipelineStageConfig, RecordSource, StageType, Task, TaskEntityType, TaskFilters, TaskPriority, TaskStatus, UpdateCompanyInput, UpdateContactInput, UpdateDealInput, UpdateTaskInput, ValueInterval, isClosedStageType };
3
+ export { Activity, ActivityType, CONTACT_STATUSES, Company, CompanyFilters, Contact, ContactFilters, ContactSource, ContactStatus, CreateActivityInput, CreateCompanyInput, CreateContactInput, CreateDealInput, CreateTaskInput, CrmRole, Deal, DealStage, LIFECYCLE_STATUSES, Note, OPEN_STAGE_TYPE, Page, PageRequest, PipelineConfig, PipelineKind, PipelineStageConfig, RecordSource, StageType, Task, TaskEntityType, TaskFilters, TaskPriority, TaskStatus, UpdateCompanyInput, UpdateContactInput, UpdateDealInput, UpdateTaskInput, VENDOR_STATUS, ValueInterval, isClosedStageType, isContactStatus };