clivly 0.23.1 → 0.24.0-next.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 +28 -0
- package/{adapter-B4v4dwgD.d.mts → adapter--YV7du3i.d.cts} +1 -1
- package/{adapter-BK3gsby5.d.cts → adapter-DD3K3dCW.d.mts} +1 -1
- package/{auth-adapter-BIa-ZyVV.d.mts → auth-adapter-C17dzlzF.d.cts} +1 -1
- package/{auth-adapter-DwtMJb7D.d.cts → auth-adapter-CizFv7oU.d.mts} +1 -1
- package/auth-better-auth.d.cts +1 -1
- package/auth-better-auth.d.mts +1 -1
- package/auth-clerk.d.cts +1 -1
- package/auth-clerk.d.mts +1 -1
- package/auth-supabase.cjs +121 -0
- package/auth-supabase.d.cts +23 -0
- package/auth-supabase.d.mts +23 -0
- package/auth-supabase.mjs +119 -0
- package/auth-workos.d.cts +1 -1
- package/auth-workos.d.mts +1 -1
- package/core-adapter.d.cts +1 -1
- package/core-adapter.d.mts +1 -1
- package/core-auth-adapter.d.cts +1 -1
- package/core-auth-adapter.d.mts +1 -1
- package/core-mapping-score.d.cts +1 -0
- package/core-sync-engine.cjs +1 -1
- package/core-sync-engine.mjs +1 -1
- package/core-types.cjs +5 -1
- package/core-types.d.cts +2 -2
- package/core-types.d.mts +2 -2
- package/core-types.mjs +1 -1
- package/core-view-compiler.cjs +1 -1
- package/core-view-compiler.mjs +1 -1
- package/core.cjs +9 -5
- package/core.d.cts +6 -6
- package/core.d.mts +6 -6
- package/core.mjs +6 -6
- package/discover-BZIPXl23.cjs +200 -0
- package/discover-CFIi43Qn.mjs +195 -0
- package/drizzle.cjs +1 -1
- package/drizzle.d.cts +2 -2
- package/drizzle.d.mts +2 -2
- package/drizzle.mjs +1 -1
- package/executor-CJEWurjZ.mjs +23 -0
- package/executor-CU-jRgpC.cjs +40 -0
- package/index-CZkp8TV4.d.cts +108 -0
- package/index-Cnrz4ywf.d.mts +108 -0
- package/{index-Bh7o2J7K.d.mts → index-DOoX2GgI.d.mts} +3 -3
- package/{index-DRRTE5IJ.d.cts → index-uFDiQEjj.d.cts} +231 -5
- package/index.cjs +903 -30
- package/index.d.cts +27 -0
- package/index.d.mts +26 -0
- package/index.mjs +901 -28
- package/{internal-CdfVkh4O.d.mts → internal-D_2q2BOB.d.mts} +1 -1
- package/internal-adapter.d.cts +1 -1
- package/internal-adapter.d.mts +1 -1
- package/internal-auth-adapter.d.cts +1 -1
- package/internal-auth-adapter.d.mts +1 -1
- package/internal-sync-engine.cjs +1 -1
- package/internal-sync-engine.mjs +1 -1
- package/internal-types.cjs +5 -1
- package/internal-types.d.cts +2 -2
- package/internal-types.d.mts +2 -2
- package/internal-types.mjs +1 -1
- package/internal-view-compiler.cjs +1 -1
- package/internal-view-compiler.mjs +1 -1
- package/internal.cjs +9 -5
- package/internal.d.cts +5 -6
- package/internal.d.mts +6 -6
- package/internal.mjs +6 -6
- package/introspector-BwYgHGcS.cjs +363 -0
- package/introspector-Bz52xOUr.mjs +334 -0
- package/{namespace-probe-JuHriruA.d.mts → namespace-probe--GvxJ06J.d.mts} +8 -1
- package/package.json +31 -1
- package/projection-guard-7AMY0aCk.mjs +389 -0
- package/projection-guard-D8VUhCz7.cjs +508 -0
- package/{projection-sql-DQQdjw9I.mjs → projection-sql-2joBkLz2.mjs} +13 -3
- package/{projection-sql-BkrHR2ea.cjs → projection-sql-DS5sVTY-.cjs} +18 -2
- package/sdk-Bzkr24NW.cjs +207 -0
- package/sdk-D2WwGBzk.mjs +178 -0
- package/sdk.cjs +8 -6
- package/sdk.d.cts +7 -1
- package/sdk.d.mts +7 -1
- package/sdk.mjs +3 -2
- package/sql.cjs +13 -0
- package/sql.d.cts +2 -0
- package/sql.d.mts +2 -0
- package/sql.mjs +4 -0
- package/{sdk-BkMDOfCk.mjs → src-Dq2nY1Sj.mjs} +36 -495
- package/{sdk-BOarpe5I.cjs → src-X0-yIA3O.cjs} +63 -546
- package/supabase.cjs +255 -0
- package/supabase.d.cts +19 -0
- package/supabase.d.mts +19 -0
- package/supabase.mjs +254 -0
- package/{sync-engine-yFLEyId3.mjs → sync-engine-D0mJUeqP.mjs} +1 -1
- package/{sync-engine-DNSoZeo0.cjs → sync-engine-hU041kXO.cjs} +1 -1
- package/types-KMH5D5Lg.mjs +32 -0
- package/{namespace-probe-CcL6Wj8E.d.cts → types-UR-tT4c1.d.cts} +52 -45
- package/{types-BBfwsDxe.d.cts → types-f-Vcv-pl.d.cts} +18 -2
- package/{types-BBfwsDxe.d.mts → types-f-Vcv-pl.d.mts} +18 -2
- package/types-kR1kUlmz.cjs +67 -0
- package/{view-compiler-CSHSqZl7.mjs → view-compiler-BhKiezRH.mjs} +1 -1
- package/{view-compiler-NqiortOA.cjs → view-compiler-DgZadq1F.cjs} +1 -1
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
- package/internal-D7qVRIFb.d.cts +0 -228
- package/types-8KSw2AWg.mjs +0 -8
- package/types-B8m39L1s.cjs +0 -19
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { C as NamespaceIntrospector, b as SyncSource, t as AppIdStore } from "./types-UR-tT4c1.cjs";
|
|
2
|
+
import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
|
|
3
|
+
import "./index-uFDiQEjj.cjs";
|
|
4
|
+
/** The one raw-SQL seam: every host driver is adapted to this. */
|
|
5
|
+
interface SqlExecutor {
|
|
6
|
+
query(text: string, params?: readonly unknown[]): Promise<Record<string, unknown>[]>;
|
|
7
|
+
}
|
|
8
|
+
interface PgLikeClient {
|
|
9
|
+
query(text: string, params?: unknown[]): Promise<{
|
|
10
|
+
rows: Record<string, unknown>[];
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
interface PostgresJsLike {
|
|
14
|
+
unsafe(text: string, params?: unknown[]): Promise<unknown[]>;
|
|
15
|
+
}
|
|
16
|
+
/** Covers pg.Pool, pg.Client and PGlite. */
|
|
17
|
+
declare function pgExecutor(client: PgLikeClient): SqlExecutor;
|
|
18
|
+
declare function postgresJsExecutor(sql: PostgresJsLike): SqlExecutor;
|
|
19
|
+
/**
|
|
20
|
+
* The postgres.js factory is injected so the SDK takes no dependency on it.
|
|
21
|
+
* `prepare: false` keeps it working behind transaction-mode poolers.
|
|
22
|
+
*/
|
|
23
|
+
declare function connectPostgresJs(url: string, postgres: (url: string, opts: {
|
|
24
|
+
prepare: false;
|
|
25
|
+
max: number;
|
|
26
|
+
}) => unknown): SqlExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
|
|
29
|
+
* one-row `crm_clivly_app` table, created on first use. The only write Clivly
|
|
30
|
+
* ever makes to a host database.
|
|
31
|
+
*/
|
|
32
|
+
declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
|
|
33
|
+
interface DiscoverFromSqlOptions {
|
|
34
|
+
/** Defaults to `[current_schema()]`. */
|
|
35
|
+
includeAuthUsers?: boolean;
|
|
36
|
+
schemas?: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
|
|
40
|
+
* returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
|
|
41
|
+
* the default schema and `schema.table` elsewhere. `auth.users` is reported
|
|
42
|
+
* with only its allowlisted columns; every other `auth.*` table is omitted.
|
|
43
|
+
*/
|
|
44
|
+
declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
|
|
45
|
+
interface FromSqlOptions {
|
|
46
|
+
/** Columns to read; defaults to every column. Ignored for `auth.users`. */
|
|
47
|
+
columns?: string[];
|
|
48
|
+
/** Column holding when a row changed; defaults to `updated_at` when present. */
|
|
49
|
+
cursorField?: string;
|
|
50
|
+
entity: string;
|
|
51
|
+
/** Unique tie-breaker column; defaults to the table's single-column PK. */
|
|
52
|
+
idField?: string;
|
|
53
|
+
/** This table's entry from `discoverFromSql`. */
|
|
54
|
+
meta: DiscoveredSchemaTable;
|
|
55
|
+
objectType?: string;
|
|
56
|
+
pushSource?: string;
|
|
57
|
+
table: string;
|
|
58
|
+
/** A trusted SQL predicate ANDed into every page query. */
|
|
59
|
+
where?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The raw-SQL twin of `fromDrizzle`: a keyset-paginated `SyncSource` over one
|
|
63
|
+
* table, for apps with no ORM. Read-only. With no cursor column the source
|
|
64
|
+
* pages by id alone and reports `mode: "full"`.
|
|
65
|
+
*/
|
|
66
|
+
declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions & {
|
|
67
|
+
objectType: string;
|
|
68
|
+
}): SyncSource & {
|
|
69
|
+
objectType: string;
|
|
70
|
+
};
|
|
71
|
+
declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions): SyncSource;
|
|
72
|
+
/**
|
|
73
|
+
* Whether `fromSql` would sync at least one row for `table`: one
|
|
74
|
+
* `exists(... limit 1)` under `buildPredicate`, the predicate every page query
|
|
75
|
+
* uses, so the `auth.users` anonymous exclusion cannot drift. The projection
|
|
76
|
+
* path (`baseGuard` in projection.ts) applies the same `isAnonymousFilter`;
|
|
77
|
+
* keep the two in step. A boolean on purpose: `/clivly/connect` is a public GET,
|
|
78
|
+
* so it must not reveal how many users exist or run a full count.
|
|
79
|
+
*/
|
|
80
|
+
declare function existsFromSql(executor: SqlExecutor, opts: {
|
|
81
|
+
table: string;
|
|
82
|
+
where?: string;
|
|
83
|
+
}): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
|
|
86
|
+
* Read-only: every statement here is a SELECT.
|
|
87
|
+
*/
|
|
88
|
+
declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
|
|
89
|
+
interface FromSqlProjectionOptions {
|
|
90
|
+
/** The base table's primary key, for a `base_pk` identity with no column. */
|
|
91
|
+
basePkColumn?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
|
|
94
|
+
* a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
|
|
95
|
+
*/
|
|
96
|
+
cursorField?: string | ProjectionRef;
|
|
97
|
+
entity: string;
|
|
98
|
+
objectType: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
|
|
102
|
+
* projection's joins. Rows are keyed by ref token. Read-only. Without a
|
|
103
|
+
* `cursorField` it pages by identity and reports `mode: "full"`.
|
|
104
|
+
*/
|
|
105
|
+
declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
|
|
106
|
+
objectType: string;
|
|
107
|
+
};
|
|
108
|
+
export { discoverFromSql as a, connectPostgresJs as c, fromSql as i, pgExecutor as l, sqlIntrospector as n, sqlAppIdStore as o, existsFromSql as r, SqlExecutor as s, fromSqlProjection as t, postgresJsExecutor as u };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe--GvxJ06J.mjs";
|
|
2
|
+
import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.mjs";
|
|
3
|
+
import "./index-DOoX2GgI.mjs";
|
|
4
|
+
/** The one raw-SQL seam: every host driver is adapted to this. */
|
|
5
|
+
interface SqlExecutor {
|
|
6
|
+
query(text: string, params?: readonly unknown[]): Promise<Record<string, unknown>[]>;
|
|
7
|
+
}
|
|
8
|
+
interface PgLikeClient {
|
|
9
|
+
query(text: string, params?: unknown[]): Promise<{
|
|
10
|
+
rows: Record<string, unknown>[];
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
interface PostgresJsLike {
|
|
14
|
+
unsafe(text: string, params?: unknown[]): Promise<unknown[]>;
|
|
15
|
+
}
|
|
16
|
+
/** Covers pg.Pool, pg.Client and PGlite. */
|
|
17
|
+
declare function pgExecutor(client: PgLikeClient): SqlExecutor;
|
|
18
|
+
declare function postgresJsExecutor(sql: PostgresJsLike): SqlExecutor;
|
|
19
|
+
/**
|
|
20
|
+
* The postgres.js factory is injected so the SDK takes no dependency on it.
|
|
21
|
+
* `prepare: false` keeps it working behind transaction-mode poolers.
|
|
22
|
+
*/
|
|
23
|
+
declare function connectPostgresJs(url: string, postgres: (url: string, opts: {
|
|
24
|
+
prepare: false;
|
|
25
|
+
max: number;
|
|
26
|
+
}) => unknown): SqlExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
|
|
29
|
+
* one-row `crm_clivly_app` table, created on first use. The only write Clivly
|
|
30
|
+
* ever makes to a host database.
|
|
31
|
+
*/
|
|
32
|
+
declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
|
|
33
|
+
interface DiscoverFromSqlOptions {
|
|
34
|
+
/** Defaults to `[current_schema()]`. */
|
|
35
|
+
includeAuthUsers?: boolean;
|
|
36
|
+
schemas?: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
|
|
40
|
+
* returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
|
|
41
|
+
* the default schema and `schema.table` elsewhere. `auth.users` is reported
|
|
42
|
+
* with only its allowlisted columns; every other `auth.*` table is omitted.
|
|
43
|
+
*/
|
|
44
|
+
declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
|
|
45
|
+
interface FromSqlOptions {
|
|
46
|
+
/** Columns to read; defaults to every column. Ignored for `auth.users`. */
|
|
47
|
+
columns?: string[];
|
|
48
|
+
/** Column holding when a row changed; defaults to `updated_at` when present. */
|
|
49
|
+
cursorField?: string;
|
|
50
|
+
entity: string;
|
|
51
|
+
/** Unique tie-breaker column; defaults to the table's single-column PK. */
|
|
52
|
+
idField?: string;
|
|
53
|
+
/** This table's entry from `discoverFromSql`. */
|
|
54
|
+
meta: DiscoveredSchemaTable;
|
|
55
|
+
objectType?: string;
|
|
56
|
+
pushSource?: string;
|
|
57
|
+
table: string;
|
|
58
|
+
/** A trusted SQL predicate ANDed into every page query. */
|
|
59
|
+
where?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The raw-SQL twin of `fromDrizzle`: a keyset-paginated `SyncSource` over one
|
|
63
|
+
* table, for apps with no ORM. Read-only. With no cursor column the source
|
|
64
|
+
* pages by id alone and reports `mode: "full"`.
|
|
65
|
+
*/
|
|
66
|
+
declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions & {
|
|
67
|
+
objectType: string;
|
|
68
|
+
}): SyncSource & {
|
|
69
|
+
objectType: string;
|
|
70
|
+
};
|
|
71
|
+
declare function fromSql(executor: SqlExecutor, opts: FromSqlOptions): SyncSource;
|
|
72
|
+
/**
|
|
73
|
+
* Whether `fromSql` would sync at least one row for `table`: one
|
|
74
|
+
* `exists(... limit 1)` under `buildPredicate`, the predicate every page query
|
|
75
|
+
* uses, so the `auth.users` anonymous exclusion cannot drift. The projection
|
|
76
|
+
* path (`baseGuard` in projection.ts) applies the same `isAnonymousFilter`;
|
|
77
|
+
* keep the two in step. A boolean on purpose: `/clivly/connect` is a public GET,
|
|
78
|
+
* so it must not reveal how many users exist or run a full count.
|
|
79
|
+
*/
|
|
80
|
+
declare function existsFromSql(executor: SqlExecutor, opts: {
|
|
81
|
+
table: string;
|
|
82
|
+
where?: string;
|
|
83
|
+
}): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
|
|
86
|
+
* Read-only: every statement here is a SELECT.
|
|
87
|
+
*/
|
|
88
|
+
declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
|
|
89
|
+
interface FromSqlProjectionOptions {
|
|
90
|
+
/** The base table's primary key, for a `base_pk` identity with no column. */
|
|
91
|
+
basePkColumn?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
|
|
94
|
+
* a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
|
|
95
|
+
*/
|
|
96
|
+
cursorField?: string | ProjectionRef;
|
|
97
|
+
entity: string;
|
|
98
|
+
objectType: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
|
|
102
|
+
* projection's joins. Rows are keyed by ref token. Read-only. Without a
|
|
103
|
+
* `cursorField` it pages by identity and reports `mode: "full"`.
|
|
104
|
+
*/
|
|
105
|
+
declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
|
|
106
|
+
objectType: string;
|
|
107
|
+
};
|
|
108
|
+
export { discoverFromSql as a, connectPostgresJs as c, fromSql as i, pgExecutor as l, sqlIntrospector as n, sqlAppIdStore as o, existsFromSql as r, SqlExecutor as s, fromSqlProjection as t, postgresJsExecutor as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import "./auth-adapter-
|
|
3
|
-
import "./adapter-
|
|
1
|
+
import "./types-f-Vcv-pl.mjs";
|
|
2
|
+
import "./auth-adapter-CizFv7oU.mjs";
|
|
3
|
+
import "./adapter-DD3K3dCW.mjs";
|
|
4
4
|
import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.mjs";
|
|
5
5
|
import "./mapping-form-KHUlnC7A.mjs";
|
|
6
6
|
import "./mappings-config-wAe-p1rG.mjs";
|
|
@@ -1,11 +1,154 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./auth-adapter-
|
|
3
|
-
import "./
|
|
1
|
+
import "./adapter--YV7du3i.cjs";
|
|
2
|
+
import "./auth-adapter-C17dzlzF.cjs";
|
|
3
|
+
import "./types-f-Vcv-pl.cjs";
|
|
4
4
|
import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.cjs";
|
|
5
5
|
import "./mapping-form-Bg_hgNoL.cjs";
|
|
6
6
|
import "./mappings-config-DNo_Cum_.cjs";
|
|
7
|
-
import "./view-compiler-BDD93Luw.cjs";
|
|
8
7
|
import "./sync-engine-DCjTr2XQ.cjs";
|
|
8
|
+
import "./view-compiler-BDD93Luw.cjs";
|
|
9
|
+
/**
|
|
10
|
+
* Value derived as a flat fee plus a per-seat price that depends on the plan.
|
|
11
|
+
*
|
|
12
|
+
* Every field name is configuration and every plan key is data, so a second
|
|
13
|
+
* subscription business configures this without a code change. The formula is
|
|
14
|
+
* fixed with named slots rather than an expression language — the same choice
|
|
15
|
+
* D8 made for stage-rule conditions.
|
|
16
|
+
*/
|
|
17
|
+
interface PerSeatValueSource {
|
|
18
|
+
/** Flat fee in cents, using the same price basis as the plan prices. */
|
|
19
|
+
baseFeeCents?: number;
|
|
20
|
+
/** Mapped column holding "month" or "year". Absent means always monthly. */
|
|
21
|
+
intervalField?: string;
|
|
22
|
+
kind: "per_seat";
|
|
23
|
+
/** Mapped column holding the plan key. */
|
|
24
|
+
planField: string;
|
|
25
|
+
/** Unit price in cents, keyed by the value found in `planField`. */
|
|
26
|
+
plans: Record<string, number>;
|
|
27
|
+
/** Monthly rates or amounts charged each billing period. Omitted preserves legacy behaviour. */
|
|
28
|
+
priceBasis?: "monthly" | "billing_interval";
|
|
29
|
+
/** Mapped column holding the seat count. */
|
|
30
|
+
seatField: string;
|
|
31
|
+
/**
|
|
32
|
+
* Annual flat fee in cents, for rows billed yearly at a yearly price. When
|
|
33
|
+
* absent, an annual row with a yearly plan price uses twelve times
|
|
34
|
+
* `baseFeeCents`, which is a monthly fee.
|
|
35
|
+
*/
|
|
36
|
+
yearlyBaseFeeCents?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Annual list price per seat in cents, keyed like `plans`. A row billed
|
|
39
|
+
* yearly whose plan has one is valued at (annual fee + seats × this) ÷ 12.
|
|
40
|
+
* One `plans` map cannot be both a monthly and a yearly price, which is why
|
|
41
|
+
* an annual plan that is not simply twelve months needs its own number.
|
|
42
|
+
*/
|
|
43
|
+
yearlyPlans?: Record<string, number>;
|
|
44
|
+
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
45
|
+
zeroInStageTypes?: string[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Value read from an amount the host's billing system already knows.
|
|
49
|
+
*
|
|
50
|
+
* The recommended source whenever the host has it: negotiated prices,
|
|
51
|
+
* discounts and multi-item subscriptions are all already in the billed
|
|
52
|
+
* amount, so Clivly does not have to model a price book to get them right.
|
|
53
|
+
*/
|
|
54
|
+
interface MappedAmountValueSource {
|
|
55
|
+
/** Mapped column holding the amount charged each billing period. */
|
|
56
|
+
amountField: string;
|
|
57
|
+
/**
|
|
58
|
+
* How the amount is written: `cents` for minor units (Stripe's `amount`,
|
|
59
|
+
* `1250`), `units` for a decimal amount (`12.50`).
|
|
60
|
+
*/
|
|
61
|
+
amountUnit: "cents" | "units";
|
|
62
|
+
/**
|
|
63
|
+
* Mapped column holding how many intervals one charge covers (Stripe's
|
|
64
|
+
* `interval_count`: 3 with `month` is quarterly). Absent means 1.
|
|
65
|
+
*/
|
|
66
|
+
intervalCountField?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Mapped column holding the billing interval: month, quarter, year or week.
|
|
69
|
+
* Absent means every amount is already monthly.
|
|
70
|
+
*/
|
|
71
|
+
intervalField?: string;
|
|
72
|
+
kind: "mapped_amount";
|
|
73
|
+
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
74
|
+
zeroInStageTypes?: string[];
|
|
75
|
+
}
|
|
76
|
+
type DealValueSource = PerSeatValueSource | MappedAmountValueSource;
|
|
77
|
+
/**
|
|
78
|
+
* The value one deal should have, in cents, or null to leave it alone.
|
|
79
|
+
*
|
|
80
|
+
* Returning null rather than 0 for unusable input is deliberate (D33). A
|
|
81
|
+
* renamed column would otherwise zero an entire pipeline silently, and a zeroed
|
|
82
|
+
* board reads as a business problem rather than a configuration problem. The
|
|
83
|
+
* unmapped case is surfaced through the rule-health warning surface instead of
|
|
84
|
+
* being written into the data — the same fail-safe `matchesCondition` applies.
|
|
85
|
+
*/
|
|
86
|
+
declare function computeDealValue(source: DealValueSource, fields: Record<string, string | null>, mappedFields: Set<string>, stageType: string): number | null;
|
|
87
|
+
/**
|
|
88
|
+
* Which fields a CRM record lets a user edit.
|
|
89
|
+
*
|
|
90
|
+
* A record synced from the host app carries a `sourceRef`. Its identity fields
|
|
91
|
+
* are rewritten from the host view on every sync run, so an edit to one would
|
|
92
|
+
* be silently reverted minutes later — the user sees their change accepted,
|
|
93
|
+
* then gone, with nothing explaining why. That is worse than refusing it.
|
|
94
|
+
*
|
|
95
|
+
* So host-owned fields are rejected at the API, not merely disabled in the UI:
|
|
96
|
+
* the UI is not the security boundary, and the SDK and any future public API
|
|
97
|
+
* reach the same routers.
|
|
98
|
+
*
|
|
99
|
+
* Records created inside the CRM have no `sourceRef` and are fully editable —
|
|
100
|
+
* nothing else owns them.
|
|
101
|
+
*
|
|
102
|
+
* This is the cheap half of a capability matrix. It answers "may a user write
|
|
103
|
+
* this?" but not "may the sync engine write this?", which stays implicit
|
|
104
|
+
* because sync bypasses these routers entirely. An override model (the
|
|
105
|
+
* `stageOverrideAt` pattern on `crm_deals`) can replace this later without
|
|
106
|
+
* changing callers.
|
|
107
|
+
*/
|
|
108
|
+
/** Contact fields the host view owns when the row is synced. */
|
|
109
|
+
declare const HOST_OWNED_CONTACT_FIELDS: readonly ["email", "name"];
|
|
110
|
+
/**
|
|
111
|
+
* Company fields the host view owns when the row is synced.
|
|
112
|
+
*
|
|
113
|
+
* `email` and `phone` joined this list in the same change that made them
|
|
114
|
+
* mappable (migration 0048). They are not identity fields, but ownership here
|
|
115
|
+
* follows what sync rewrites, not what feels identity-like: both flow from the
|
|
116
|
+
* host view on every run, exactly as `email` does for contacts above. Widening
|
|
117
|
+
* `CANONICAL_FIELDS.company` without widening this list is the specific bug
|
|
118
|
+
* this module's doc comment calls worse than refusing the edit.
|
|
119
|
+
*
|
|
120
|
+
* `primaryContactId` is deliberately absent: it is a CRM-side judgement about
|
|
121
|
+
* who to talk to, never sourced from the host, so it stays editable on synced
|
|
122
|
+
* rows.
|
|
123
|
+
*/
|
|
124
|
+
declare const HOST_OWNED_COMPANY_FIELDS: readonly ["domain", "name", "email", "phone"];
|
|
125
|
+
type HostOwnedContactField = (typeof HOST_OWNED_CONTACT_FIELDS)[number];
|
|
126
|
+
type HostOwnedCompanyField = (typeof HOST_OWNED_COMPANY_FIELDS)[number];
|
|
127
|
+
/** The subset of a record this module needs to make its decision. */
|
|
128
|
+
interface SourcedRecord {
|
|
129
|
+
sourceRef?: string | null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* True when the record is owned by a host view rather than by the CRM.
|
|
133
|
+
*
|
|
134
|
+
* Deliberately keyed on `sourceRef` and not `entityRole`: `entityRole` is a
|
|
135
|
+
* mapping label that can be absent on a synced row, while `sourceRef` is the
|
|
136
|
+
* identity the sync engine reconciles against and is set for exactly the rows
|
|
137
|
+
* sync will rewrite.
|
|
138
|
+
*/
|
|
139
|
+
declare function isHostOwned(record: SourcedRecord): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Host-owned contact fields this patch would change, or `[]` when the patch is
|
|
142
|
+
* allowed. Callers turn a non-empty result into a 400 naming the fields.
|
|
143
|
+
*/
|
|
144
|
+
declare function rejectedContactFields(contact: SourcedRecord, patch: Readonly<Record<string, unknown>>): HostOwnedContactField[];
|
|
145
|
+
/** Host-owned company fields this patch would change, or `[]`. */
|
|
146
|
+
declare function rejectedCompanyFields(company: SourcedRecord, patch: Readonly<Record<string, unknown>>): HostOwnedCompanyField[];
|
|
147
|
+
/**
|
|
148
|
+
* The message shown when a write is refused. Names the fields and says where
|
|
149
|
+
* they come from, so the reason is actionable rather than a bare "forbidden".
|
|
150
|
+
*/
|
|
151
|
+
declare function hostOwnedFieldMessage(fields: readonly string[]): string;
|
|
9
152
|
declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
|
|
10
153
|
type StepId = (typeof INTEGRATION_STEPS)[number];
|
|
11
154
|
/** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
|
|
@@ -305,4 +448,87 @@ type RichMetaTable = DiscoveredSchemaTable & {
|
|
|
305
448
|
* never whether the table has keys. Absent metadata stays UNKNOWN.
|
|
306
449
|
*/
|
|
307
450
|
declare function hasRichMeta(table: DiscoveredSchemaTable): table is RichMetaTable;
|
|
308
|
-
|
|
451
|
+
/**
|
|
452
|
+
* The one `slugify`.
|
|
453
|
+
*
|
|
454
|
+
* Three byte-identical copies existed before this module — in `@clivly/api`
|
|
455
|
+
* (the custom object-type slug), in `apps/web`'s onboarding route (the
|
|
456
|
+
* organisation slug), and in `@clivly/sdk`. The first two now import this; the
|
|
457
|
+
* SDK's copy stays where it is on purpose, because `@clivly/sdk` cannot depend
|
|
458
|
+
* on this package and its own comment records that its pattern is deliberately
|
|
459
|
+
* kept in step with the server's by hand.
|
|
460
|
+
*
|
|
461
|
+
* Note that the two callers this replaces slug *different things* — an
|
|
462
|
+
* object type and an organisation. They share a transform, not a namespace.
|
|
463
|
+
* Sharing the function stops the transform drifting; it does not make those two
|
|
464
|
+
* identifiers the same identifier.
|
|
465
|
+
*/
|
|
466
|
+
/**
|
|
467
|
+
* Lowercase, trim, collapse every run of non-alphanumerics to one hyphen, and
|
|
468
|
+
* drop leading/trailing hyphens. `"Participant Info"` becomes
|
|
469
|
+
* `"participant-info"`.
|
|
470
|
+
*
|
|
471
|
+
* The result is NOT guaranteed to be an acceptable slug. Both
|
|
472
|
+
* `OBJECT_TYPE_SLUG_PATTERN` (server) and `PROJECTION_KEY_PATTERN` (this
|
|
473
|
+
* package) require a leading letter, and this function happily returns
|
|
474
|
+
* `"2024-invoices"` for `"2024 Invoices"`. Callers that need an
|
|
475
|
+
* acceptance-guaranteed identifier want `toObjectTypeSlug`.
|
|
476
|
+
*/
|
|
477
|
+
declare function slugify(value: string): string;
|
|
478
|
+
/**
|
|
479
|
+
* A slug the server will accept, derived from a display name.
|
|
480
|
+
*
|
|
481
|
+
* `slugify` alone is not enough: the server's `OBJECT_TYPE_SLUG_PATTERN`
|
|
482
|
+
* (`apps/server/src/index.ts`) demands a leading letter, so a name beginning
|
|
483
|
+
* with a digit slugs to something the platform rejects at push time — long
|
|
484
|
+
* after the object was authored. `@clivly/sdk`'s `custom-slug.ts` already knows
|
|
485
|
+
* this case and deliberately withholds `"2024-invoices"` as a suggestion
|
|
486
|
+
* because it would be rejected too.
|
|
487
|
+
*
|
|
488
|
+
* The prefix is applied ONLY when the derived slug does not already start with
|
|
489
|
+
* a letter, so the overwhelmingly common name is untouched.
|
|
490
|
+
*
|
|
491
|
+
* This value must be shown to whoever authored the name. It is the identifier
|
|
492
|
+
* the host app declares as its `objectType`, so a slug derived silently is a
|
|
493
|
+
* slug the developer cannot copy into their config.
|
|
494
|
+
*
|
|
495
|
+
* Returns an empty string for a name with no alphanumerics at all — the caller
|
|
496
|
+
* decides whether that is "keep typing" or an error, since only it knows
|
|
497
|
+
* whether the field is still being edited.
|
|
498
|
+
*/
|
|
499
|
+
declare function toObjectTypeSlug(displayName: string): string;
|
|
500
|
+
type ConditionOp = "is_empty" | "is_not_empty" | "equals" | "not_equals" | "greater_than" | "less_than" | "before" | "after";
|
|
501
|
+
interface Condition {
|
|
502
|
+
field: string;
|
|
503
|
+
op: ConditionOp;
|
|
504
|
+
value?: string;
|
|
505
|
+
}
|
|
506
|
+
interface EvaluableRule {
|
|
507
|
+
conditions: Condition[];
|
|
508
|
+
id: string;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Whether one condition holds for a host row.
|
|
512
|
+
*
|
|
513
|
+
* `mappedFields` is the set of columns the organization actually exposed. A
|
|
514
|
+
* condition naming anything outside it never matches, whatever the operator: a
|
|
515
|
+
* rule referencing a dropped column must fail safe, because treating the field
|
|
516
|
+
* as null would make `is_empty` match every deal.
|
|
517
|
+
*/
|
|
518
|
+
declare function matchesCondition(condition: Condition, fields: Record<string, string | null>, mappedFields: Set<string>): boolean;
|
|
519
|
+
/**
|
|
520
|
+
* The id of the first rule whose conditions all hold, or null when none do.
|
|
521
|
+
*
|
|
522
|
+
* Returns a rule id rather than a stage key because the caller needs the
|
|
523
|
+
* matched rule's `allowClose` before it may move a deal into a closed stage.
|
|
524
|
+
*
|
|
525
|
+
* `rules` must arrive already ordered — stage position first, then rule
|
|
526
|
+
* position within a stage. Sorting needs stage rows this module deliberately
|
|
527
|
+
* does not see.
|
|
528
|
+
*
|
|
529
|
+
* A rule with no conditions never matches: an empty list would otherwise
|
|
530
|
+
* vacuously AND to true and capture every deal, which is the opposite of what
|
|
531
|
+
* a half-written rule should do.
|
|
532
|
+
*/
|
|
533
|
+
declare function evaluateStage(rules: EvaluableRule[], fields: Record<string, string | null>, mappedFields: Set<string>): string | null;
|
|
534
|
+
export { StepProblem as A, MappedAmountValueSource as B, ConnectionLiveness as C, IntegrationStep as D, IntegrationStatus as E, hostOwnedFieldMessage as F, computeDealValue as H, isHostOwned as I, rejectedCompanyFields as L, HostOwnedCompanyField as M, HostOwnedContactField as N, NextAction as O, SourcedRecord as P, rejectedContactFields as R, joinFansOut as S, IntegrationState as T, PerSeatValueSource as V, compileProjectionJoins as _, matchesCondition as a, quoteIdent as b, columnMetaFor as c, primaryKeyColumns as d, validateProjection as f, compileProjectionIdentity as g, compileProjectionFrom as h, evaluateStage as i, StepState as j, StepId as k, coversUniqueKey as l, PREVIEW_MAX_ROWS as m, ConditionOp as n, slugify as o, validateProjectionFilter as p, EvaluableRule as r, toObjectTypeSlug as s, Condition as t, hasRichMeta as u, compileProjectionPreview as v, IntegrationFacts as w, fanOutJoins as x, compileProjectionSelect as y, DealValueSource as z };
|