clivly 0.24.0-next.1 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -7
- package/{app-id-DcQ4u1c8.cjs → app-id-C2F25WhK.cjs} +1 -1
- package/{app-id-5cB6yioz.mjs → app-id-CMMadyIC.mjs} +1 -1
- package/auth-better-auth.cjs +51 -0
- package/auth-better-auth.d.cts +51 -1
- package/auth-better-auth.d.mts +51 -1
- package/auth-better-auth.mjs +51 -1
- package/auth-clerk.cjs +53 -0
- package/auth-clerk.d.cts +12 -1
- package/auth-clerk.d.mts +12 -1
- package/auth-clerk.mjs +53 -1
- package/auth-supabase.cjs +10 -0
- package/auth-supabase.d.cts +17 -1
- package/auth-supabase.d.mts +17 -1
- package/auth-supabase.mjs +10 -1
- package/auth-webhook-3if7gY6b.mjs +162 -0
- package/auth-webhook-BihEUc9C.cjs +197 -0
- package/auth-webhook-DKdaCZrW.d.cts +30 -0
- package/auth-webhook-DKdaCZrW.d.mts +30 -0
- package/auth-workos.cjs +43 -0
- package/auth-workos.d.cts +12 -1
- package/auth-workos.d.mts +12 -1
- package/auth-workos.mjs +43 -1
- package/drizzle.cjs +264 -17
- package/drizzle.d.cts +23 -3
- package/drizzle.d.mts +23 -3
- package/drizzle.mjs +265 -19
- package/{from-sql-CFgXkCe2.cjs → from-sql-Dw2ipynp.cjs} +7 -1
- package/{from-sql-S8dSvU-e.d.cts → from-sql-MyPE5elx.d.cts} +1 -1
- package/{from-sql-CpGP7K3J.d.mts → from-sql-YW6LfdVK.d.mts} +1 -1
- package/{from-sql-BD7gR4bC.mjs → from-sql-kqs9CbQ-.mjs} +7 -1
- package/{index-CIupXz_w.d.cts → index-B4kWWHYm.d.cts} +2 -2
- package/{index-BoemTWH4.d.mts → index-CKElWhvq.d.mts} +2 -2
- package/index.cjs +3354 -2829
- package/index.d.cts +3 -3
- package/index.d.mts +3 -3
- package/index.mjs +3354 -2829
- package/{introspector-5w2x89RD.mjs → introspector-B1S7qmvy.mjs} +4 -4
- package/{introspector-DT_Ma59k.cjs → introspector-DRmEXDai.cjs} +4 -4
- package/kysely.cjs +163 -2
- package/kysely.d.cts +16 -3
- package/kysely.d.mts +16 -3
- package/kysely.mjs +163 -3
- package/{namespace-probe-CUR2zG2l.d.mts → namespace-probe-LKC4OU5X.d.mts} +54 -19
- package/package.json +1 -1
- package/{projection-guard-DOt_nbGn.mjs → projection-guard-CADdAdzg.mjs} +1 -1
- package/{projection-guard-C70l5U24.cjs → projection-guard-yhVTvx37.cjs} +1 -1
- package/sdk.cjs +1 -1
- package/sdk.d.cts +1 -1
- package/sdk.d.mts +1 -1
- package/sdk.mjs +1 -1
- package/sql.cjs +5 -5
- package/sql.d.cts +2 -2
- package/sql.d.mts +2 -2
- package/sql.mjs +5 -5
- package/{src-CZIdwwI2.cjs → src-BQasv4EL.cjs} +368 -38
- package/{src-tFhC1Ru2.mjs → src-CAn-zrEl.mjs} +368 -38
- package/{supabase-contact-BXQ0nnLq.cjs → supabase-contact-0GmBVpiQ.cjs} +24 -15
- package/{supabase-contact-3ke1KKUs.mjs → supabase-contact-D-oDC4Qk.mjs} +24 -15
- package/supabase.cjs +39 -9
- package/supabase.d.cts +3 -2
- package/supabase.d.mts +3 -2
- package/supabase.mjs +39 -9
- package/{sync-Q0O-2kFI.mjs → sync-CnWT5juF.mjs} +65 -5
- package/{sync-CdA9dgZz.cjs → sync-R0iVlooB.cjs} +94 -4
- package/track-writes-4yyZbTZX.d.cts +17 -0
- package/track-writes-BJSWg8wg.d.mts +17 -0
- package/track-writes-BnZAig2Y.mjs +77 -0
- package/track-writes-C22_e_W-.cjs +112 -0
- package/{types-CzL7lUH9.d.cts → types-BPG4l-oM.d.cts} +53 -18
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
package/README.md
CHANGED
|
@@ -48,7 +48,9 @@ npm run dev # starting the app runs the generated boot hook
|
|
|
48
48
|
`clivly init` writes a `clivly.config.ts` you own, two route files Clivly
|
|
49
49
|
owns, and a framework boot hook where it can safely do so. Starting the app is
|
|
50
50
|
what connects it; `clivly status` is a read-only diagnostic. It creates no
|
|
51
|
-
database tables and does not modify your ORM schema.
|
|
51
|
+
database tables and does not modify your ORM schema. On Supabase you can
|
|
52
|
+
separately choose to add a trigger to `auth.users`, so sign-ups arrive at once;
|
|
53
|
+
see [`clivly add instant-push`](#clivly-add-instant-push).
|
|
52
54
|
|
|
53
55
|
---
|
|
54
56
|
|
|
@@ -60,6 +62,7 @@ database tables and does not modify your ORM schema.
|
|
|
60
62
|
| [`clivly login`](#clivly-login) | Pair this machine and write credentials to your env file |
|
|
61
63
|
| [`clivly status`](#clivly-status) | Check your setup, step by step. Read-only |
|
|
62
64
|
| [`clivly add widget`](#clivly-add-widget) | Scaffold the chat-session route |
|
|
65
|
+
| [`clivly add instant-push`](#clivly-add-instant-push) | Send Clerk, WorkOS or Supabase sign-ups to Clivly at once |
|
|
63
66
|
| [`clivly push-schema`](#clivly-push-schema) | Push your schema, custom objects and mappings to Clivly without deploying |
|
|
64
67
|
| [`clivly dev`](#clivly-dev) | Tunnel localhost so remote sync can reach you |
|
|
65
68
|
| `clivly --version` | Print the installed `clivly` version |
|
|
@@ -99,12 +102,11 @@ is what lets your app run a **derived object** authored in Clivly's dashboard
|
|
|
99
102
|
scaffolding it by default is what makes such an object sync with no further code
|
|
100
103
|
on your side. It costs nothing if you never author one.
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
configs are left unchanged; add the line yourself to opt in.
|
|
105
|
+
Instant push is always on. With Drizzle, `init` wraps your database client in
|
|
106
|
+
`trackDrizzle` from `clivly/drizzle`, so a signup shows up in Clivly within
|
|
107
|
+
seconds, an edit updates and a deleted row's record is archived. It edits only a
|
|
108
|
+
plain `export const db = drizzle(...)`; anything else is left alone and the line
|
|
109
|
+
to add is printed. Writes that bypass the client arrive with the scheduled sync.
|
|
108
110
|
|
|
109
111
|
From `0.23.0` the scaffolded config sets `appIdStore: drizzleAppIdStore(db)`
|
|
110
112
|
and imports everything from `clivly/drizzle` in one statement. The store keeps
|
|
@@ -439,6 +441,31 @@ for the full flow.
|
|
|
439
441
|
|
|
440
442
|
---
|
|
441
443
|
|
|
444
|
+
### `clivly add instant-push`
|
|
445
|
+
|
|
446
|
+
```bash
|
|
447
|
+
npx clivly add instant-push [--yes] [--force] [--dry-run]
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
For apps whose auth provider writes users where a wrapped database client cannot
|
|
451
|
+
see them.
|
|
452
|
+
|
|
453
|
+
- **Clerk and WorkOS:** writes a webhook route and prints the dashboard steps.
|
|
454
|
+
The route checks the provider's signature. The secret stays in your app.
|
|
455
|
+
- **Supabase Auth:** needs two triggers on `auth.users`. The command prints all
|
|
456
|
+
of the SQL and asks. Only if you agree does it write a migration, which does
|
|
457
|
+
nothing until you apply it. The SQL includes how to remove it.
|
|
458
|
+
|
|
459
|
+
| Flag | Effect |
|
|
460
|
+
| --- | --- |
|
|
461
|
+
| `--dry-run` | Show what would be written; write nothing |
|
|
462
|
+
| `--force` | Overwrite the route if it already exists |
|
|
463
|
+
| `--yes` | Agree to the Supabase SQL without being asked |
|
|
464
|
+
| `--url` | Your deployed app's address (Supabase with your own server) |
|
|
465
|
+
| `--project-url` | Your Supabase project's address (Edge Function) |
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
442
469
|
### `clivly push-schema`
|
|
443
470
|
|
|
444
471
|
```bash
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as postgresDialect } from "./from-sql-
|
|
1
|
+
import { d as postgresDialect } from "./from-sql-kqs9CbQ-.mjs";
|
|
2
2
|
// ../sdk/src/sql/app-id.ts
|
|
3
3
|
/** The one-row host table that keeps the ID Clivly issued this app. */
|
|
4
4
|
const APP_ID_TABLE = "crm_clivly_app";
|
package/auth-better-auth.cjs
CHANGED
|
@@ -8,6 +8,56 @@ function betterAuthUserToClivlyUser(user) {
|
|
|
8
8
|
name: user.name ?? void 0
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
// ../auth-better-auth/src/instant-push.ts
|
|
12
|
+
const MAX_HOLD_MS = 2e3;
|
|
13
|
+
/** `work`, but never longer than MAX_HOLD_MS. */
|
|
14
|
+
async function heldBriefly(work) {
|
|
15
|
+
let timer;
|
|
16
|
+
const timeout = new Promise((resolve) => {
|
|
17
|
+
timer = setTimeout(resolve, MAX_HOLD_MS);
|
|
18
|
+
});
|
|
19
|
+
await Promise.race([work, timeout]);
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* better-auth plugin: a new, changed or deleted user reaches Clivly right
|
|
24
|
+
* away. Runs after better-auth has written the row, and never fails the
|
|
25
|
+
* sign-up: a push that does not arrive is left to the next sync.
|
|
26
|
+
*/
|
|
27
|
+
function clivlyInstantPush(options) {
|
|
28
|
+
const { clivly, waitUntil, entity = "user" } = options;
|
|
29
|
+
const run = async (push, context) => {
|
|
30
|
+
const work = (async () => {
|
|
31
|
+
try {
|
|
32
|
+
await push();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.warn(`Clivly instant push failed for "${entity}": ${error instanceof Error ? error.message : String(error)}. It will still sync on the next delta run.`);
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
try {
|
|
38
|
+
const background = waitUntil ?? context?.context?.runInBackground;
|
|
39
|
+
if (background) {
|
|
40
|
+
background(work);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
await heldBriefly(work);
|
|
45
|
+
};
|
|
46
|
+
const changed = async (user, context) => {
|
|
47
|
+
if (user?.id) await run(() => clivly.pushById(entity, [user.id]), context);
|
|
48
|
+
};
|
|
49
|
+
const deleted = async (user, context) => {
|
|
50
|
+
if (user?.id) await run(() => clivly.pushDelete(entity, [user.id]), context);
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
id: "clivly-instant-push",
|
|
54
|
+
init: () => ({ options: { databaseHooks: { user: {
|
|
55
|
+
create: { after: changed },
|
|
56
|
+
update: { after: changed },
|
|
57
|
+
delete: { after: deleted }
|
|
58
|
+
} } } })
|
|
59
|
+
};
|
|
60
|
+
}
|
|
11
61
|
// ../auth-better-auth/src/index.ts
|
|
12
62
|
/**
|
|
13
63
|
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
@@ -23,4 +73,5 @@ function createBetterAuthAdapter(options) {
|
|
|
23
73
|
} };
|
|
24
74
|
}
|
|
25
75
|
exports.betterAuthUserToClivlyUser = betterAuthUserToClivlyUser;
|
|
76
|
+
exports.clivlyInstantPush = clivlyInstantPush;
|
|
26
77
|
exports.createBetterAuthAdapter = createBetterAuthAdapter;
|
package/auth-better-auth.d.cts
CHANGED
|
@@ -5,6 +5,56 @@ interface BetterAuthLikeUser {
|
|
|
5
5
|
name?: string | null;
|
|
6
6
|
}
|
|
7
7
|
export declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
|
|
8
|
+
/** The two SDK calls the plugin makes; a `createClivlySDK` result satisfies it. */
|
|
9
|
+
interface InstantPushSDK {
|
|
10
|
+
pushById(entity: string, ids: readonly (string | number)[]): Promise<unknown>;
|
|
11
|
+
pushDelete(entity: string, ids: readonly (string | number)[]): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface ClivlyInstantPushOptions {
|
|
14
|
+
/** Your Clivly SDK (the object returned by `createClivlySDK({...})`). */
|
|
15
|
+
clivly: InstantPushSDK;
|
|
16
|
+
/** The entity key in your Clivly config that maps users. Default `"user"`. */
|
|
17
|
+
entity?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Keeps the runtime alive after the response (Vercel `waitUntil`, Workers
|
|
20
|
+
* `ctx.waitUntil`). Without it, better-auth's own background runner is used
|
|
21
|
+
* when configured; without either, a sign-up waits up to two seconds.
|
|
22
|
+
*/
|
|
23
|
+
waitUntil?: (work: Promise<void>) => void;
|
|
24
|
+
}
|
|
25
|
+
interface HookUser {
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
interface HookContext {
|
|
29
|
+
context?: {
|
|
30
|
+
runInBackground?: (work: Promise<void>) => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* better-auth plugin: a new, changed or deleted user reaches Clivly right
|
|
35
|
+
* away. Runs after better-auth has written the row, and never fails the
|
|
36
|
+
* sign-up: a push that does not arrive is left to the next sync.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clivlyInstantPush(options: ClivlyInstantPushOptions): {
|
|
39
|
+
id: "clivly-instant-push";
|
|
40
|
+
init: () => {
|
|
41
|
+
options: {
|
|
42
|
+
databaseHooks: {
|
|
43
|
+
user: {
|
|
44
|
+
create: {
|
|
45
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
update: {
|
|
48
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
delete: {
|
|
51
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
8
58
|
export interface BetterAuthLike {
|
|
9
59
|
api: {
|
|
10
60
|
getSession(args: {
|
|
@@ -25,4 +75,4 @@ export interface BetterAuthAdapterOptions {
|
|
|
25
75
|
* `crm_members` layer.
|
|
26
76
|
*/
|
|
27
77
|
export declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
|
|
28
|
-
export type { BetterAuthLikeUser };
|
|
78
|
+
export type { BetterAuthLikeUser, ClivlyInstantPushOptions, InstantPushSDK };
|
package/auth-better-auth.d.mts
CHANGED
|
@@ -5,6 +5,56 @@ interface BetterAuthLikeUser {
|
|
|
5
5
|
name?: string | null;
|
|
6
6
|
}
|
|
7
7
|
export declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
|
|
8
|
+
/** The two SDK calls the plugin makes; a `createClivlySDK` result satisfies it. */
|
|
9
|
+
interface InstantPushSDK {
|
|
10
|
+
pushById(entity: string, ids: readonly (string | number)[]): Promise<unknown>;
|
|
11
|
+
pushDelete(entity: string, ids: readonly (string | number)[]): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface ClivlyInstantPushOptions {
|
|
14
|
+
/** Your Clivly SDK (the object returned by `createClivlySDK({...})`). */
|
|
15
|
+
clivly: InstantPushSDK;
|
|
16
|
+
/** The entity key in your Clivly config that maps users. Default `"user"`. */
|
|
17
|
+
entity?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Keeps the runtime alive after the response (Vercel `waitUntil`, Workers
|
|
20
|
+
* `ctx.waitUntil`). Without it, better-auth's own background runner is used
|
|
21
|
+
* when configured; without either, a sign-up waits up to two seconds.
|
|
22
|
+
*/
|
|
23
|
+
waitUntil?: (work: Promise<void>) => void;
|
|
24
|
+
}
|
|
25
|
+
interface HookUser {
|
|
26
|
+
id: string;
|
|
27
|
+
}
|
|
28
|
+
interface HookContext {
|
|
29
|
+
context?: {
|
|
30
|
+
runInBackground?: (work: Promise<void>) => void;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* better-auth plugin: a new, changed or deleted user reaches Clivly right
|
|
35
|
+
* away. Runs after better-auth has written the row, and never fails the
|
|
36
|
+
* sign-up: a push that does not arrive is left to the next sync.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clivlyInstantPush(options: ClivlyInstantPushOptions): {
|
|
39
|
+
id: "clivly-instant-push";
|
|
40
|
+
init: () => {
|
|
41
|
+
options: {
|
|
42
|
+
databaseHooks: {
|
|
43
|
+
user: {
|
|
44
|
+
create: {
|
|
45
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
update: {
|
|
48
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
delete: {
|
|
51
|
+
after: (user: HookUser | null | undefined, context?: HookContext | null) => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
8
58
|
export interface BetterAuthLike {
|
|
9
59
|
api: {
|
|
10
60
|
getSession(args: {
|
|
@@ -25,4 +75,4 @@ export interface BetterAuthAdapterOptions {
|
|
|
25
75
|
* `crm_members` layer.
|
|
26
76
|
*/
|
|
27
77
|
export declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
|
|
28
|
-
export type { BetterAuthLikeUser };
|
|
78
|
+
export type { BetterAuthLikeUser, ClivlyInstantPushOptions, InstantPushSDK };
|
package/auth-better-auth.mjs
CHANGED
|
@@ -7,6 +7,56 @@ function betterAuthUserToClivlyUser(user) {
|
|
|
7
7
|
name: user.name ?? void 0
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
+
// ../auth-better-auth/src/instant-push.ts
|
|
11
|
+
const MAX_HOLD_MS = 2e3;
|
|
12
|
+
/** `work`, but never longer than MAX_HOLD_MS. */
|
|
13
|
+
async function heldBriefly(work) {
|
|
14
|
+
let timer;
|
|
15
|
+
const timeout = new Promise((resolve) => {
|
|
16
|
+
timer = setTimeout(resolve, MAX_HOLD_MS);
|
|
17
|
+
});
|
|
18
|
+
await Promise.race([work, timeout]);
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* better-auth plugin: a new, changed or deleted user reaches Clivly right
|
|
23
|
+
* away. Runs after better-auth has written the row, and never fails the
|
|
24
|
+
* sign-up: a push that does not arrive is left to the next sync.
|
|
25
|
+
*/
|
|
26
|
+
function clivlyInstantPush(options) {
|
|
27
|
+
const { clivly, waitUntil, entity = "user" } = options;
|
|
28
|
+
const run = async (push, context) => {
|
|
29
|
+
const work = (async () => {
|
|
30
|
+
try {
|
|
31
|
+
await push();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn(`Clivly instant push failed for "${entity}": ${error instanceof Error ? error.message : String(error)}. It will still sync on the next delta run.`);
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
try {
|
|
37
|
+
const background = waitUntil ?? context?.context?.runInBackground;
|
|
38
|
+
if (background) {
|
|
39
|
+
background(work);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
} catch {}
|
|
43
|
+
await heldBriefly(work);
|
|
44
|
+
};
|
|
45
|
+
const changed = async (user, context) => {
|
|
46
|
+
if (user?.id) await run(() => clivly.pushById(entity, [user.id]), context);
|
|
47
|
+
};
|
|
48
|
+
const deleted = async (user, context) => {
|
|
49
|
+
if (user?.id) await run(() => clivly.pushDelete(entity, [user.id]), context);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
id: "clivly-instant-push",
|
|
53
|
+
init: () => ({ options: { databaseHooks: { user: {
|
|
54
|
+
create: { after: changed },
|
|
55
|
+
update: { after: changed },
|
|
56
|
+
delete: { after: deleted }
|
|
57
|
+
} } } })
|
|
58
|
+
};
|
|
59
|
+
}
|
|
10
60
|
// ../auth-better-auth/src/index.ts
|
|
11
61
|
/**
|
|
12
62
|
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
@@ -21,4 +71,4 @@ function createBetterAuthAdapter(options) {
|
|
|
21
71
|
return betterAuthUserToClivlyUser(session.user);
|
|
22
72
|
} };
|
|
23
73
|
}
|
|
24
|
-
export { betterAuthUserToClivlyUser, createBetterAuthAdapter };
|
|
74
|
+
export { betterAuthUserToClivlyUser, clivlyInstantPush, createBetterAuthAdapter };
|
package/auth-clerk.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_auth_webhook = require("./auth-webhook-BihEUc9C.cjs");
|
|
2
3
|
let _clerk_backend = require("@clerk/backend");
|
|
3
4
|
// ../auth-clerk/src/map.ts
|
|
4
5
|
function clerkUserToClivlyUser(user) {
|
|
@@ -11,6 +12,57 @@ function clerkUserToClivlyUser(user) {
|
|
|
11
12
|
name
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
// ../auth-clerk/src/instant-push.ts
|
|
16
|
+
const SECRET_PREFIX = "whsec_";
|
|
17
|
+
const MS_PER_SECOND = 1e3;
|
|
18
|
+
const USER_EVENTS = /* @__PURE__ */ new Set([
|
|
19
|
+
"user.created",
|
|
20
|
+
"user.updated",
|
|
21
|
+
"user.deleted"
|
|
22
|
+
]);
|
|
23
|
+
const fromBase64 = (text) => Uint8Array.from(atob(text), (char) => char.charCodeAt(0));
|
|
24
|
+
const matches = (candidate, expected) => {
|
|
25
|
+
const [version, signature] = candidate.split(",");
|
|
26
|
+
if (version !== "v1" || !signature) return false;
|
|
27
|
+
try {
|
|
28
|
+
return require_auth_webhook.sameBytes(fromBase64(signature), expected);
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const verifySvix = async (secret, headers, body, now) => {
|
|
34
|
+
const id = headers.get("svix-id");
|
|
35
|
+
const timestamp = headers.get("svix-timestamp");
|
|
36
|
+
const signatures = headers.get("svix-signature");
|
|
37
|
+
if (!(secret && id && timestamp && signatures)) return false;
|
|
38
|
+
if (!(Math.abs(now - Number(timestamp) * MS_PER_SECOND) <= 3e5)) return false;
|
|
39
|
+
const key = fromBase64(secret.startsWith(SECRET_PREFIX) ? secret.slice(6) : secret);
|
|
40
|
+
if (key.length === 0) return false;
|
|
41
|
+
const expected = await require_auth_webhook.hmacSha256(key, `${id}.${timestamp}.${body}`);
|
|
42
|
+
return signatures.split(" ").some((one) => matches(one, expected));
|
|
43
|
+
};
|
|
44
|
+
const parse = (payload) => {
|
|
45
|
+
const event = payload;
|
|
46
|
+
const id = event?.data?.id;
|
|
47
|
+
if (!(typeof event?.type === "string" && USER_EVENTS.has(event.type)) || typeof id !== "string") return null;
|
|
48
|
+
return {
|
|
49
|
+
at: require_auth_webhook.eventTime(event.timestamp),
|
|
50
|
+
deleted: event.type === "user.deleted",
|
|
51
|
+
id
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A Clerk webhook endpoint that pushes a user to Clivly the moment they sign
|
|
56
|
+
* up, change or are deleted. Subscribe it to `user.created`, `user.updated`
|
|
57
|
+
* and `user.deleted`.
|
|
58
|
+
*/
|
|
59
|
+
function createClerkPushHandler({ signingSecret, ...options }) {
|
|
60
|
+
return require_auth_webhook.createUserPushHandler({
|
|
61
|
+
...options,
|
|
62
|
+
parse,
|
|
63
|
+
verify: (headers, body, now) => verifySvix(signingSecret, headers, body, now)
|
|
64
|
+
});
|
|
65
|
+
}
|
|
14
66
|
// ../auth-clerk/src/index.ts
|
|
15
67
|
/**
|
|
16
68
|
* Clerk → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the host
|
|
@@ -30,3 +82,4 @@ function createClerkAuthAdapter(options) {
|
|
|
30
82
|
}
|
|
31
83
|
exports.clerkUserToClivlyUser = clerkUserToClivlyUser;
|
|
32
84
|
exports.createClerkAuthAdapter = createClerkAuthAdapter;
|
|
85
|
+
exports.createClerkPushHandler = createClerkPushHandler;
|
package/auth-clerk.d.cts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
|
|
2
|
+
import { n as UserPushOptions, r as UserPushSDK, t as InstantPushOutcome } from "./auth-webhook-DKdaCZrW.cjs";
|
|
3
|
+
interface ClerkPushOptions extends UserPushOptions {
|
|
4
|
+
/** The endpoint's signing secret from the Clerk dashboard (`whsec_…`). */
|
|
5
|
+
signingSecret: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A Clerk webhook endpoint that pushes a user to Clivly the moment they sign
|
|
9
|
+
* up, change or are deleted. Subscribe it to `user.created`, `user.updated`
|
|
10
|
+
* and `user.deleted`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createClerkPushHandler({ signingSecret, ...options }: ClerkPushOptions): (request: Request) => Promise<Response>;
|
|
2
13
|
interface ClerkLikeUser {
|
|
3
14
|
emailAddresses?: Array<{
|
|
4
15
|
id: string;
|
|
@@ -24,4 +35,4 @@ export interface ClerkAuthAdapterOptions {
|
|
|
24
35
|
* CRM authorization lives in the separate `crm_members` layer.
|
|
25
36
|
*/
|
|
26
37
|
export declare function createClerkAuthAdapter(options: ClerkAuthAdapterOptions): ClivlyAuthAdapter;
|
|
27
|
-
export type { ClerkLikeUser };
|
|
38
|
+
export type { ClerkLikeUser, ClerkPushOptions, InstantPushOutcome, UserPushSDK };
|
package/auth-clerk.d.mts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
|
|
2
|
+
import { n as UserPushOptions, r as UserPushSDK, t as InstantPushOutcome } from "./auth-webhook-DKdaCZrW.mjs";
|
|
3
|
+
interface ClerkPushOptions extends UserPushOptions {
|
|
4
|
+
/** The endpoint's signing secret from the Clerk dashboard (`whsec_…`). */
|
|
5
|
+
signingSecret: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A Clerk webhook endpoint that pushes a user to Clivly the moment they sign
|
|
9
|
+
* up, change or are deleted. Subscribe it to `user.created`, `user.updated`
|
|
10
|
+
* and `user.deleted`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createClerkPushHandler({ signingSecret, ...options }: ClerkPushOptions): (request: Request) => Promise<Response>;
|
|
2
13
|
interface ClerkLikeUser {
|
|
3
14
|
emailAddresses?: Array<{
|
|
4
15
|
id: string;
|
|
@@ -24,4 +35,4 @@ export interface ClerkAuthAdapterOptions {
|
|
|
24
35
|
* CRM authorization lives in the separate `crm_members` layer.
|
|
25
36
|
*/
|
|
26
37
|
export declare function createClerkAuthAdapter(options: ClerkAuthAdapterOptions): ClivlyAuthAdapter;
|
|
27
|
-
export type { ClerkLikeUser };
|
|
38
|
+
export type { ClerkLikeUser, ClerkPushOptions, InstantPushOutcome, UserPushSDK };
|
package/auth-clerk.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { a as hmacSha256, i as eventTime, o as sameBytes, r as createUserPushHandler } from "./auth-webhook-3if7gY6b.mjs";
|
|
1
2
|
import { createClerkClient } from "@clerk/backend";
|
|
2
3
|
// ../auth-clerk/src/map.ts
|
|
3
4
|
function clerkUserToClivlyUser(user) {
|
|
@@ -10,6 +11,57 @@ function clerkUserToClivlyUser(user) {
|
|
|
10
11
|
name
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
// ../auth-clerk/src/instant-push.ts
|
|
15
|
+
const SECRET_PREFIX = "whsec_";
|
|
16
|
+
const MS_PER_SECOND = 1e3;
|
|
17
|
+
const USER_EVENTS = /* @__PURE__ */ new Set([
|
|
18
|
+
"user.created",
|
|
19
|
+
"user.updated",
|
|
20
|
+
"user.deleted"
|
|
21
|
+
]);
|
|
22
|
+
const fromBase64 = (text) => Uint8Array.from(atob(text), (char) => char.charCodeAt(0));
|
|
23
|
+
const matches = (candidate, expected) => {
|
|
24
|
+
const [version, signature] = candidate.split(",");
|
|
25
|
+
if (version !== "v1" || !signature) return false;
|
|
26
|
+
try {
|
|
27
|
+
return sameBytes(fromBase64(signature), expected);
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const verifySvix = async (secret, headers, body, now) => {
|
|
33
|
+
const id = headers.get("svix-id");
|
|
34
|
+
const timestamp = headers.get("svix-timestamp");
|
|
35
|
+
const signatures = headers.get("svix-signature");
|
|
36
|
+
if (!(secret && id && timestamp && signatures)) return false;
|
|
37
|
+
if (!(Math.abs(now - Number(timestamp) * MS_PER_SECOND) <= 3e5)) return false;
|
|
38
|
+
const key = fromBase64(secret.startsWith(SECRET_PREFIX) ? secret.slice(6) : secret);
|
|
39
|
+
if (key.length === 0) return false;
|
|
40
|
+
const expected = await hmacSha256(key, `${id}.${timestamp}.${body}`);
|
|
41
|
+
return signatures.split(" ").some((one) => matches(one, expected));
|
|
42
|
+
};
|
|
43
|
+
const parse = (payload) => {
|
|
44
|
+
const event = payload;
|
|
45
|
+
const id = event?.data?.id;
|
|
46
|
+
if (!(typeof event?.type === "string" && USER_EVENTS.has(event.type)) || typeof id !== "string") return null;
|
|
47
|
+
return {
|
|
48
|
+
at: eventTime(event.timestamp),
|
|
49
|
+
deleted: event.type === "user.deleted",
|
|
50
|
+
id
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* A Clerk webhook endpoint that pushes a user to Clivly the moment they sign
|
|
55
|
+
* up, change or are deleted. Subscribe it to `user.created`, `user.updated`
|
|
56
|
+
* and `user.deleted`.
|
|
57
|
+
*/
|
|
58
|
+
function createClerkPushHandler({ signingSecret, ...options }) {
|
|
59
|
+
return createUserPushHandler({
|
|
60
|
+
...options,
|
|
61
|
+
parse,
|
|
62
|
+
verify: (headers, body, now) => verifySvix(signingSecret, headers, body, now)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
13
65
|
// ../auth-clerk/src/index.ts
|
|
14
66
|
/**
|
|
15
67
|
* Clerk → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the host
|
|
@@ -27,4 +79,4 @@ function createClerkAuthAdapter(options) {
|
|
|
27
79
|
return clerkUserToClivlyUser(await client.users.getUser(auth.userId));
|
|
28
80
|
} };
|
|
29
81
|
}
|
|
30
|
-
export { clerkUserToClivlyUser, createClerkAuthAdapter };
|
|
82
|
+
export { clerkUserToClivlyUser, createClerkAuthAdapter, createClerkPushHandler };
|
package/auth-supabase.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_auth_webhook = require("./auth-webhook-BihEUc9C.cjs");
|
|
2
3
|
// ../auth-supabase/src/map.ts
|
|
3
4
|
const asNonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
4
5
|
function supabaseUserToClivlyUser(user) {
|
|
@@ -11,6 +12,14 @@ function supabaseUserToClivlyUser(user) {
|
|
|
11
12
|
name
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
// ../auth-supabase/src/instant-push.ts
|
|
16
|
+
/**
|
|
17
|
+
* The endpoint Clivly's optional trigger on `auth.users` calls, for a Supabase
|
|
18
|
+
* app with its own server. Apps on the Edge Function already have it.
|
|
19
|
+
*/
|
|
20
|
+
function createSupabasePushHandler(options) {
|
|
21
|
+
return require_auth_webhook.createTokenPushHandler(options);
|
|
22
|
+
}
|
|
14
23
|
// ../auth-supabase/src/index.ts
|
|
15
24
|
const BEARER = /^Bearer\s+(\S+)$/i;
|
|
16
25
|
const SUPABASE_HOST = /^([a-z0-9]+)\.supabase\.(?:co|in)$/i;
|
|
@@ -118,4 +127,5 @@ function createSupabaseAuthAdapter(options) {
|
|
|
118
127
|
} };
|
|
119
128
|
}
|
|
120
129
|
exports.createSupabaseAuthAdapter = createSupabaseAuthAdapter;
|
|
130
|
+
exports.createSupabasePushHandler = createSupabasePushHandler;
|
|
121
131
|
exports.supabaseUserToClivlyUser = supabaseUserToClivlyUser;
|
package/auth-supabase.d.cts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-C17dzlzF.cjs";
|
|
2
|
+
import { r as UserPushSDK, t as InstantPushOutcome } from "./auth-webhook-DKdaCZrW.cjs";
|
|
3
|
+
interface SupabasePushOptions {
|
|
4
|
+
/** Your Clivly SDK (the object returned by `createClivlySDK({...})`). */
|
|
5
|
+
clivly: UserPushSDK;
|
|
6
|
+
/** The entity key in your Clivly config that maps users. Default `"contacts"`. */
|
|
7
|
+
entity?: string;
|
|
8
|
+
/** The Vault secret `clivly_push_token` that the trigger sends. */
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
/** Lets the runtime finish the push after the response. */
|
|
11
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The endpoint Clivly's optional trigger on `auth.users` calls, for a Supabase
|
|
15
|
+
* app with its own server. Apps on the Edge Function already have it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSupabasePushHandler(options: SupabasePushOptions): (request: Request) => Promise<Response>;
|
|
2
18
|
interface SupabaseLikeUser {
|
|
3
19
|
email?: string | null;
|
|
4
20
|
id: string;
|
|
@@ -20,4 +36,4 @@ export interface SupabaseAuthAdapterOptions {
|
|
|
20
36
|
* decoded or trusted locally. Answers "who is this person?" only.
|
|
21
37
|
*/
|
|
22
38
|
export declare function createSupabaseAuthAdapter(options: SupabaseAuthAdapterOptions): ClivlyAuthAdapter;
|
|
23
|
-
export type { SupabaseLikeUser };
|
|
39
|
+
export type { InstantPushOutcome, SupabaseLikeUser, SupabasePushOptions, UserPushSDK };
|
package/auth-supabase.d.mts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { n as ClivlyUser, t as ClivlyAuthAdapter } from "./auth-adapter-CizFv7oU.mjs";
|
|
2
|
+
import { r as UserPushSDK, t as InstantPushOutcome } from "./auth-webhook-DKdaCZrW.mjs";
|
|
3
|
+
interface SupabasePushOptions {
|
|
4
|
+
/** Your Clivly SDK (the object returned by `createClivlySDK({...})`). */
|
|
5
|
+
clivly: UserPushSDK;
|
|
6
|
+
/** The entity key in your Clivly config that maps users. Default `"contacts"`. */
|
|
7
|
+
entity?: string;
|
|
8
|
+
/** The Vault secret `clivly_push_token` that the trigger sends. */
|
|
9
|
+
token: string | undefined;
|
|
10
|
+
/** Lets the runtime finish the push after the response. */
|
|
11
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The endpoint Clivly's optional trigger on `auth.users` calls, for a Supabase
|
|
15
|
+
* app with its own server. Apps on the Edge Function already have it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSupabasePushHandler(options: SupabasePushOptions): (request: Request) => Promise<Response>;
|
|
2
18
|
interface SupabaseLikeUser {
|
|
3
19
|
email?: string | null;
|
|
4
20
|
id: string;
|
|
@@ -20,4 +36,4 @@ export interface SupabaseAuthAdapterOptions {
|
|
|
20
36
|
* decoded or trusted locally. Answers "who is this person?" only.
|
|
21
37
|
*/
|
|
22
38
|
export declare function createSupabaseAuthAdapter(options: SupabaseAuthAdapterOptions): ClivlyAuthAdapter;
|
|
23
|
-
export type { SupabaseLikeUser };
|
|
39
|
+
export type { InstantPushOutcome, SupabaseLikeUser, SupabasePushOptions, UserPushSDK };
|
package/auth-supabase.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { n as createTokenPushHandler } from "./auth-webhook-3if7gY6b.mjs";
|
|
1
2
|
// ../auth-supabase/src/map.ts
|
|
2
3
|
const asNonEmptyString = (value) => typeof value === "string" && value.length > 0 ? value : void 0;
|
|
3
4
|
function supabaseUserToClivlyUser(user) {
|
|
@@ -10,6 +11,14 @@ function supabaseUserToClivlyUser(user) {
|
|
|
10
11
|
name
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
// ../auth-supabase/src/instant-push.ts
|
|
15
|
+
/**
|
|
16
|
+
* The endpoint Clivly's optional trigger on `auth.users` calls, for a Supabase
|
|
17
|
+
* app with its own server. Apps on the Edge Function already have it.
|
|
18
|
+
*/
|
|
19
|
+
function createSupabasePushHandler(options) {
|
|
20
|
+
return createTokenPushHandler(options);
|
|
21
|
+
}
|
|
13
22
|
// ../auth-supabase/src/index.ts
|
|
14
23
|
const BEARER = /^Bearer\s+(\S+)$/i;
|
|
15
24
|
const SUPABASE_HOST = /^([a-z0-9]+)\.supabase\.(?:co|in)$/i;
|
|
@@ -116,4 +125,4 @@ function createSupabaseAuthAdapter(options) {
|
|
|
116
125
|
}
|
|
117
126
|
} };
|
|
118
127
|
}
|
|
119
|
-
export { createSupabaseAuthAdapter, supabaseUserToClivlyUser };
|
|
128
|
+
export { createSupabaseAuthAdapter, createSupabasePushHandler, supabaseUserToClivlyUser };
|