clivly 0.21.0 → 0.23.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/core.cjs +1 -1
- package/core.d.cts +2 -2
- package/core.d.mts +2 -2
- package/core.mjs +1 -1
- package/drizzle.cjs +37 -0
- package/drizzle.d.cts +14 -1
- package/drizzle.d.mts +14 -1
- package/drizzle.mjs +36 -1
- package/index.cjs +56 -9
- package/index.mjs +56 -9
- package/{internal-DWpLw0t5.mjs → internal-BAw1MCMV.mjs} +94 -5
- package/{internal-C8TGcv_X.d.mts → internal-CdfVkh4O.d.mts} +45 -2
- package/{internal-Nrhf76Jn.d.cts → internal-D7qVRIFb.d.cts} +45 -2
- package/{internal-G5tXjqwl.cjs → internal-D88LTRlu.cjs} +94 -5
- package/internal.cjs +1 -1
- package/internal.d.cts +2 -2
- package/internal.d.mts +2 -2
- package/internal.mjs +1 -1
- package/{namespace-probe-Dh6LFwfo.d.cts → namespace-probe-CcL6Wj8E.d.cts} +17 -1
- package/{namespace-probe-xESu83KG.d.mts → namespace-probe-JuHriruA.d.mts} +17 -1
- package/package.json +1 -1
- package/{sdk-oUjl5HNU.cjs → sdk-BOarpe5I.cjs} +25 -2
- package/{sdk-DfdHv-S9.mjs → sdk-BkMDOfCk.mjs} +25 -2
- package/sdk.cjs +1 -1
- package/sdk.d.cts +2 -2
- package/sdk.d.mts +2 -2
- package/sdk.mjs +1 -1
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
package/core.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const require_projection = require("./projection-w4Z6vSL2.cjs");
|
|
|
3
3
|
const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
|
|
4
4
|
const require_mappings_config = require("./mappings-config-CC-vltWb.cjs");
|
|
5
5
|
const require_auth_adapter = require("./auth-adapter-CNVuxT9W.cjs");
|
|
6
|
-
const require_internal = require("./internal-
|
|
6
|
+
const require_internal = require("./internal-D88LTRlu.cjs");
|
|
7
7
|
const require_mapping_form = require("./mapping-form-Bs6JQurC.cjs");
|
|
8
8
|
const require_projection_sql = require("./projection-sql-BkrHR2ea.cjs");
|
|
9
9
|
const require_view_compiler = require("./view-compiler-NqiortOA.cjs");
|
package/core.d.cts
CHANGED
|
@@ -6,6 +6,6 @@ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as
|
|
|
6
6
|
import { i as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-DNo_Cum_.cjs";
|
|
7
7
|
import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-BDD93Luw.cjs";
|
|
8
8
|
import { c as SyncAction, f as isRemovalAction, g as runSync, h as resolveActions, l as SyncResult, m as reconcile, n as MirrorRecord, o as ResolvedMembership, r as PersistAction, s as SourceRow, t as EntitySyncResult, u as SyncStore } from "./sync-engine-DCjTr2XQ.cjs";
|
|
9
|
-
import { a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as
|
|
9
|
+
import { _ as PerSeatValueSource, a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as MappedAmountValueSource, h as DealValueSource, i as evaluateStage, l as HostOwnedContactField, m as rejectedContactFields, n as ConditionOp, o as slugify, p as rejectedCompanyFields, r as EvaluableRule, s as toObjectTypeSlug, t as Condition, u as SourcedRecord, v as computeDealValue } from "./internal-D7qVRIFb.cjs";
|
|
10
10
|
import { C as StepProblem, S as StepId, _ as IntegrationFacts, a as validateProjection, b as IntegrationStep, c as compileProjectionFrom, d as compileProjectionPreview, f as compileProjectionSelect, g as ConnectionLiveness, h as joinFansOut, i as primaryKeyColumns, l as compileProjectionIdentity, m as fanOutJoins, n as coversUniqueKey, o as validateProjectionFilter, p as quoteIdent, r as hasRichMeta, s as PREVIEW_MAX_ROWS, t as columnMetaFor, u as compileProjectionJoins, v as IntegrationState, w as StepState, x as NextAction, y as IntegrationStatus } from "./index-DRRTE5IJ.cjs";
|
|
11
|
-
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
|
11
|
+
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DealValueSource, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MappedAmountValueSource, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
package/core.d.mts
CHANGED
|
@@ -6,6 +6,6 @@ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as
|
|
|
6
6
|
import { i as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-wAe-p1rG.mjs";
|
|
7
7
|
import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-CSNhmCY2.mjs";
|
|
8
8
|
import { c as SyncAction, f as isRemovalAction, g as runSync, h as resolveActions, l as SyncResult, m as reconcile, n as MirrorRecord, o as ResolvedMembership, r as PersistAction, s as SourceRow, t as EntitySyncResult, u as SyncStore } from "./sync-engine-UNORma7f.mjs";
|
|
9
|
-
import { a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as
|
|
9
|
+
import { _ as PerSeatValueSource, a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as MappedAmountValueSource, h as DealValueSource, i as evaluateStage, l as HostOwnedContactField, m as rejectedContactFields, n as ConditionOp, o as slugify, p as rejectedCompanyFields, r as EvaluableRule, s as toObjectTypeSlug, t as Condition, u as SourcedRecord, v as computeDealValue } from "./internal-CdfVkh4O.mjs";
|
|
10
10
|
import { C as StepProblem, S as StepId, _ as IntegrationFacts, a as validateProjection, b as IntegrationStep, c as compileProjectionFrom, d as compileProjectionPreview, f as compileProjectionSelect, g as ConnectionLiveness, h as joinFansOut, i as primaryKeyColumns, l as compileProjectionIdentity, m as fanOutJoins, n as coversUniqueKey, o as validateProjectionFilter, p as quoteIdent, r as hasRichMeta, s as PREVIEW_MAX_ROWS, t as columnMetaFor, u as compileProjectionJoins, v as IntegrationState, w as StepState, x as NextAction, y as IntegrationStatus } from "./index-Bh7o2J7K.mjs";
|
|
11
|
-
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
|
11
|
+
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DealValueSource, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MappedAmountValueSource, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
package/core.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { i as projectionSchema, n as PROJECTION_KEY_PATTERN, r as identityRefs,
|
|
|
2
2
|
import { C as hasRichMeta, S as coversUniqueKey, _ as validateProjection, a as MATERIALIZING_CONCEPTS, b as joinFansOut, c as defineClivlyConfig, d as missingRequiredFields, f as projectionFields, g as validateEntitiesConfig, h as requiredFieldsFor, i as ClivlyConfigError, l as entitiesConfigSchema, m as relationshipsSchema, n as CRM_CONCEPTS, o as REQUIRED_FIELDS, p as relationshipSchema, t as CANONICAL_FIELDS, u as filterSchema, v as validateProjectionFilter, w as primaryKeyColumns, x as columnMetaFor, y as fanOutJoins } from "./entity-config-CI5CGfaN.mjs";
|
|
3
3
|
import { n as mappingsToEntitiesConfig } from "./mappings-config-Opw7ZM6Y.mjs";
|
|
4
4
|
import { t as authCustom } from "./auth-adapter-u91PByaw.mjs";
|
|
5
|
-
import { a as hostOwnedFieldMessage, c as rejectedContactFields, i as toObjectTypeSlug, l as computeDealValue, n as matchesCondition, o as isHostOwned, r as slugify, s as rejectedCompanyFields, t as evaluateStage, u as contactSegmentSchema } from "./internal-
|
|
5
|
+
import { a as hostOwnedFieldMessage, c as rejectedContactFields, i as toObjectTypeSlug, l as computeDealValue, n as matchesCondition, o as isHostOwned, r as slugify, s as rejectedCompanyFields, t as evaluateStage, u as contactSegmentSchema } from "./internal-BAw1MCMV.mjs";
|
|
6
6
|
import { n as buildRelationships, r as relationshipViaSignature, t as buildFilterFromDiscriminator } from "./mapping-form-C7kDMWzp.mjs";
|
|
7
7
|
import { a as compileProjectionPreview, i as compileProjectionJoins, n as compileProjectionFrom, o as compileProjectionSelect, r as compileProjectionIdentity, s as quoteIdent, t as PREVIEW_MAX_ROWS } from "./projection-sql-DQQdjw9I.mjs";
|
|
8
8
|
import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-CSHSqZl7.mjs";
|
package/drizzle.cjs
CHANGED
|
@@ -224,6 +224,41 @@ function insertAndPush(clivly, db, table, opts) {
|
|
|
224
224
|
return created;
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
+
/** The one-row host table that keeps the ID Clivly issued this app. */
|
|
228
|
+
const APP_ID_TABLE = "crm_clivly_app";
|
|
229
|
+
/**
|
|
230
|
+
* An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
|
|
231
|
+
* created on first use. Clivly issues the ID on the first heartbeat and uses
|
|
232
|
+
* it to recognise the same app in another workspace (an app gets its free
|
|
233
|
+
* months once). Losing the row is harmless: Clivly hands this workspace back
|
|
234
|
+
* the same ID.
|
|
235
|
+
*
|
|
236
|
+
* If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
|
|
237
|
+
* your drizzle config so push does not offer to drop the table.
|
|
238
|
+
*/
|
|
239
|
+
function drizzleAppIdStore(db) {
|
|
240
|
+
const client = db;
|
|
241
|
+
const table = drizzle_orm.sql.identifier(APP_ID_TABLE);
|
|
242
|
+
let ready = null;
|
|
243
|
+
const ensureTable = () => {
|
|
244
|
+
ready ??= client.execute(drizzle_orm.sql`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).catch((error) => {
|
|
245
|
+
ready = null;
|
|
246
|
+
throw error;
|
|
247
|
+
});
|
|
248
|
+
return ready;
|
|
249
|
+
};
|
|
250
|
+
return {
|
|
251
|
+
async get() {
|
|
252
|
+
await ensureTable();
|
|
253
|
+
const value = (await client.execute(drizzle_orm.sql`select app_id from ${table} order by created_at limit 1`)).rows[0]?.app_id;
|
|
254
|
+
return typeof value === "string" ? value : null;
|
|
255
|
+
},
|
|
256
|
+
async set(appId) {
|
|
257
|
+
await ensureTable();
|
|
258
|
+
await client.execute(drizzle_orm.sql`insert into ${table} (app_id) select ${appId} where not exists (select 1 from ${table})`);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
227
262
|
/**
|
|
228
263
|
* Build a `NamespaceIntrospector` from any Drizzle client that exposes
|
|
229
264
|
* `.execute()`. Reads `information_schema` in the connection's default schema
|
|
@@ -300,9 +335,11 @@ function deleteAndPush(clivly, db, table, opts) {
|
|
|
300
335
|
return deleted;
|
|
301
336
|
};
|
|
302
337
|
}
|
|
338
|
+
exports.APP_ID_TABLE = APP_ID_TABLE;
|
|
303
339
|
exports.buildUniqueConstraints = require_drizzle.buildUniqueConstraints;
|
|
304
340
|
exports.deleteAndPush = deleteAndPush;
|
|
305
341
|
exports.discoverFromDrizzle = require_drizzle.discoverFromDrizzle;
|
|
342
|
+
exports.drizzleAppIdStore = drizzleAppIdStore;
|
|
306
343
|
exports.drizzleIntrospector = drizzleIntrospector;
|
|
307
344
|
exports.fromDrizzle = fromDrizzle;
|
|
308
345
|
exports.fromDrizzleProjection = fromDrizzleProjection;
|
package/drizzle.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe-CcL6Wj8E.cjs";
|
|
3
3
|
import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-BNHGQXiY.cjs";
|
|
4
4
|
import "./index-DRRTE5IJ.cjs";
|
|
5
5
|
import { Table } from "drizzle-orm";
|
|
@@ -163,6 +163,19 @@ export declare function toColumnKeyedRow(table: Table, row: Record<string, unkno
|
|
|
163
163
|
export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
|
|
164
164
|
entity: string;
|
|
165
165
|
}): (values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>>;
|
|
166
|
+
/** The one-row host table that keeps the ID Clivly issued this app. */
|
|
167
|
+
export declare const APP_ID_TABLE = "crm_clivly_app";
|
|
168
|
+
/**
|
|
169
|
+
* An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
|
|
170
|
+
* created on first use. Clivly issues the ID on the first heartbeat and uses
|
|
171
|
+
* it to recognise the same app in another workspace (an app gets its free
|
|
172
|
+
* months once). Losing the row is harmless: Clivly hands this workspace back
|
|
173
|
+
* the same ID.
|
|
174
|
+
*
|
|
175
|
+
* If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
|
|
176
|
+
* your drizzle config so push does not offer to drop the table.
|
|
177
|
+
*/
|
|
178
|
+
export declare function drizzleAppIdStore(db: unknown): AppIdStore;
|
|
166
179
|
/**
|
|
167
180
|
* Build a `NamespaceIntrospector` from any Drizzle client that exposes
|
|
168
181
|
* `.execute()`. Reads `information_schema` in the connection's default schema
|
package/drizzle.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-CXpGowQa.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe-JuHriruA.mjs";
|
|
3
3
|
import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-DFe7ILmd.mjs";
|
|
4
4
|
import "./index-Bh7o2J7K.mjs";
|
|
5
5
|
import { Table } from "drizzle-orm";
|
|
@@ -163,6 +163,19 @@ export declare function toColumnKeyedRow(table: Table, row: Record<string, unkno
|
|
|
163
163
|
export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
|
|
164
164
|
entity: string;
|
|
165
165
|
}): (values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>>;
|
|
166
|
+
/** The one-row host table that keeps the ID Clivly issued this app. */
|
|
167
|
+
export declare const APP_ID_TABLE = "crm_clivly_app";
|
|
168
|
+
/**
|
|
169
|
+
* An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
|
|
170
|
+
* created on first use. Clivly issues the ID on the first heartbeat and uses
|
|
171
|
+
* it to recognise the same app in another workspace (an app gets its free
|
|
172
|
+
* months once). Losing the row is harmless: Clivly hands this workspace back
|
|
173
|
+
* the same ID.
|
|
174
|
+
*
|
|
175
|
+
* If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
|
|
176
|
+
* your drizzle config so push does not offer to drop the table.
|
|
177
|
+
*/
|
|
178
|
+
export declare function drizzleAppIdStore(db: unknown): AppIdStore;
|
|
166
179
|
/**
|
|
167
180
|
* Build a `NamespaceIntrospector` from any Drizzle client that exposes
|
|
168
181
|
* `.execute()`. Reads `information_schema` in the connection's default schema
|
package/drizzle.mjs
CHANGED
|
@@ -223,6 +223,41 @@ function insertAndPush(clivly, db, table, opts) {
|
|
|
223
223
|
return created;
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
+
/** The one-row host table that keeps the ID Clivly issued this app. */
|
|
227
|
+
const APP_ID_TABLE = "crm_clivly_app";
|
|
228
|
+
/**
|
|
229
|
+
* An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
|
|
230
|
+
* created on first use. Clivly issues the ID on the first heartbeat and uses
|
|
231
|
+
* it to recognise the same app in another workspace (an app gets its free
|
|
232
|
+
* months once). Losing the row is harmless: Clivly hands this workspace back
|
|
233
|
+
* the same ID.
|
|
234
|
+
*
|
|
235
|
+
* If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
|
|
236
|
+
* your drizzle config so push does not offer to drop the table.
|
|
237
|
+
*/
|
|
238
|
+
function drizzleAppIdStore(db) {
|
|
239
|
+
const client = db;
|
|
240
|
+
const table = sql.identifier(APP_ID_TABLE);
|
|
241
|
+
let ready = null;
|
|
242
|
+
const ensureTable = () => {
|
|
243
|
+
ready ??= client.execute(sql`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).catch((error) => {
|
|
244
|
+
ready = null;
|
|
245
|
+
throw error;
|
|
246
|
+
});
|
|
247
|
+
return ready;
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
async get() {
|
|
251
|
+
await ensureTable();
|
|
252
|
+
const value = (await client.execute(sql`select app_id from ${table} order by created_at limit 1`)).rows[0]?.app_id;
|
|
253
|
+
return typeof value === "string" ? value : null;
|
|
254
|
+
},
|
|
255
|
+
async set(appId) {
|
|
256
|
+
await ensureTable();
|
|
257
|
+
await client.execute(sql`insert into ${table} (app_id) select ${appId} where not exists (select 1 from ${table})`);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
226
261
|
/**
|
|
227
262
|
* Build a `NamespaceIntrospector` from any Drizzle client that exposes
|
|
228
263
|
* `.execute()`. Reads `information_schema` in the connection's default schema
|
|
@@ -299,4 +334,4 @@ function deleteAndPush(clivly, db, table, opts) {
|
|
|
299
334
|
return deleted;
|
|
300
335
|
};
|
|
301
336
|
}
|
|
302
|
-
export { buildUniqueConstraints, deleteAndPush, discoverFromDrizzle, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow, updateAndPush };
|
|
337
|
+
export { APP_ID_TABLE, buildUniqueConstraints, deleteAndPush, discoverFromDrizzle, drizzleAppIdStore, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow, updateAndPush };
|
package/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
|
|
4
4
|
const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
|
|
5
5
|
require("./mapping-score-D2TCQiOr.cjs");
|
|
6
|
-
const require_sdk = require("./sdk-
|
|
6
|
+
const require_sdk = require("./sdk-BOarpe5I.cjs");
|
|
7
7
|
let node_child_process = require("node:child_process");
|
|
8
8
|
let node_fs = require("node:fs");
|
|
9
9
|
let node_module = require("node:module");
|
|
@@ -2193,6 +2193,30 @@ function nodeOnlyDrivers(dependencies) {
|
|
|
2193
2193
|
if (!dependencies) return [];
|
|
2194
2194
|
return Object.keys(dependencies).filter((name) => NODE_ONLY_DRIVERS.has(name)).sort();
|
|
2195
2195
|
}
|
|
2196
|
+
const NEXT_EDGE_BUNDLES_DRIVERS_MAJOR = 16;
|
|
2197
|
+
/**
|
|
2198
|
+
* Does this Next.js version need the edge-externals step?
|
|
2199
|
+
*
|
|
2200
|
+
* Only Next <= 15. Next 16 builds with Turbopack by default, and a post-init
|
|
2201
|
+
* Next 16.3 + `pg` app builds clean under Turbopack AND under `next build
|
|
2202
|
+
* --webpack` with no next.config help (verified 2026-11-12). Worse, handing
|
|
2203
|
+
* Turbopack a `webpack` block with no `turbopack` block FAILS the build, so on
|
|
2204
|
+
* 16 the step would break the very app it meant to fix. A version we cannot
|
|
2205
|
+
* read ("latest", "canary") resolves to 16 or later today, so it gets no step.
|
|
2206
|
+
*/
|
|
2207
|
+
function nextNeedsEdgeExternals(versionRange) {
|
|
2208
|
+
const major = versionRange ? LEADING_MAJOR.exec(versionRange)?.[1] : void 0;
|
|
2209
|
+
return major !== void 0 && Number(major) < NEXT_EDGE_BUNDLES_DRIVERS_MAJOR;
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Does this next.config already externalise every driver on the edge pass?
|
|
2213
|
+
* A text check, not a parse: the developer owns the file and its shape varies,
|
|
2214
|
+
* so it asks only whether the edge branch is there and names each driver.
|
|
2215
|
+
*/
|
|
2216
|
+
function nextConfigExternalisesDrivers(source, drivers) {
|
|
2217
|
+
if (!(source?.includes("nextRuntime") && source.includes("externals"))) return false;
|
|
2218
|
+
return drivers.every((d) => source.includes(`"${d}"`) || source.includes(`'${d}'`));
|
|
2219
|
+
}
|
|
2196
2220
|
/** The next.config step an app needs when its config reaches a Node driver. */
|
|
2197
2221
|
function nextEdgeExternalsStep(drivers) {
|
|
2198
2222
|
const list = drivers.map((d) => `"${d}"`).join(", ");
|
|
@@ -2288,9 +2312,7 @@ function guessDbImportPath(schemaImportPath) {
|
|
|
2288
2312
|
function renderImports(plan) {
|
|
2289
2313
|
const lines = [
|
|
2290
2314
|
"import { createClivlySDK, defineClivlyConfig } from \"clivly/sdk\";",
|
|
2291
|
-
"import {
|
|
2292
|
-
"import { discoverFromDrizzle } from \"clivly/drizzle\";",
|
|
2293
|
-
"import { drizzleIntrospector } from \"clivly/drizzle\";",
|
|
2315
|
+
"import {\n discoverFromDrizzle,\n drizzleAppIdStore,\n drizzleIntrospector,\n fromDrizzle,\n} from \"clivly/drizzle\";",
|
|
2294
2316
|
`import * as schema from "${plan.importPath}";`
|
|
2295
2317
|
];
|
|
2296
2318
|
if (plan.db === null) {
|
|
@@ -2326,6 +2348,10 @@ export default createClivlySDK({
|
|
|
2326
2348
|
// Lets derived objects authored in the dashboard run against this database.
|
|
2327
2349
|
// Without it they are fetched, validated and then skipped.
|
|
2328
2350
|
introspector: drizzleIntrospector(${dbExpr}),
|
|
2351
|
+
// Keeps the ID Clivly issues this app in a one-row \`crm_clivly_app\` table,
|
|
2352
|
+
// created on first use. With drizzle-kit push, add
|
|
2353
|
+
// \`tablesFilter: ["!crm_clivly_app"]\` so push leaves it alone.
|
|
2354
|
+
appIdStore: drizzleAppIdStore(${dbExpr}),
|
|
2329
2355
|
source: {
|
|
2330
2356
|
// Keyed by CRM concept — contacts/companies/deals/custom.
|
|
2331
2357
|
// NOT by your entity key. The entity's own \`source:\` above is a table name.
|
|
@@ -2773,16 +2799,37 @@ function declaredNextVersion(args) {
|
|
|
2773
2799
|
function declaredDependencies(args) {
|
|
2774
2800
|
return hostManifest(args).dependencies;
|
|
2775
2801
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2802
|
+
const NEXT_CONFIG_CANDIDATES$1 = [
|
|
2803
|
+
"next.config.ts",
|
|
2804
|
+
"next.config.mjs",
|
|
2805
|
+
"next.config.js",
|
|
2806
|
+
"next.config.cjs",
|
|
2807
|
+
"next.config.mts"
|
|
2808
|
+
];
|
|
2809
|
+
function nextConfigSource(args) {
|
|
2810
|
+
for (const candidate of NEXT_CONFIG_CANDIDATES$1) {
|
|
2811
|
+
const source = args.readFile((0, node_path.join)(args.cwd, candidate));
|
|
2812
|
+
if (source !== null) return source;
|
|
2813
|
+
}
|
|
2814
|
+
return null;
|
|
2815
|
+
}
|
|
2816
|
+
/**
|
|
2817
|
+
* The edge-externals step, or null when it does not apply: no Node-only driver,
|
|
2818
|
+
* Next >= 16 (whose edge pass bundles the driver unaided), or a next.config that already has
|
|
2819
|
+
* the edge externals in place.
|
|
2820
|
+
*/
|
|
2821
|
+
function edgeExternalsStepFor(args) {
|
|
2822
|
+
const drivers = nodeOnlyDrivers(declaredDependencies(args));
|
|
2823
|
+
if (drivers.length === 0) return null;
|
|
2824
|
+
if (!nextNeedsEdgeExternals(declaredNextVersion(args))) return null;
|
|
2825
|
+
if (nextConfigExternalisesDrivers(nextConfigSource(args), drivers)) return null;
|
|
2826
|
+
return nextEdgeExternalsStep(drivers);
|
|
2780
2827
|
}
|
|
2781
2828
|
function planBootPatch(args) {
|
|
2782
2829
|
if (bootHookPath(args.framework, args.layout) !== null) return {
|
|
2783
2830
|
file: null,
|
|
2784
2831
|
manual: args.framework === "nextjs" && nextNeedsInstrumentationFlag(declaredNextVersion(args)) ? NEXT_INSTRUMENTATION_FLAG_STEP : null,
|
|
2785
|
-
extra: args.framework === "nextjs" ? edgeExternalsStepFor(
|
|
2832
|
+
extra: args.framework === "nextjs" ? edgeExternalsStepFor(args) : null
|
|
2786
2833
|
};
|
|
2787
2834
|
if (args.framework === "remix") return {
|
|
2788
2835
|
file: null,
|
package/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { t as CANONICAL_FIELDS } from "./entity-config-CI5CGfaN.mjs";
|
|
3
3
|
import { d as suggestCursorField, i as isFrameworkTable, l as scoreFieldMap, n as hasDefiningColumn, o as matchesConcept, p as toFieldMap, s as requiredFieldsFor, u as scoreRelationships } from "./entity-heuristics-DAxqagJA.mjs";
|
|
4
4
|
import "./mapping-score-CS-MTDL9.mjs";
|
|
5
|
-
import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-
|
|
5
|
+
import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-BkMDOfCk.mjs";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
8
|
import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "node:fs";
|
|
@@ -2192,6 +2192,30 @@ function nodeOnlyDrivers(dependencies) {
|
|
|
2192
2192
|
if (!dependencies) return [];
|
|
2193
2193
|
return Object.keys(dependencies).filter((name) => NODE_ONLY_DRIVERS.has(name)).sort();
|
|
2194
2194
|
}
|
|
2195
|
+
const NEXT_EDGE_BUNDLES_DRIVERS_MAJOR = 16;
|
|
2196
|
+
/**
|
|
2197
|
+
* Does this Next.js version need the edge-externals step?
|
|
2198
|
+
*
|
|
2199
|
+
* Only Next <= 15. Next 16 builds with Turbopack by default, and a post-init
|
|
2200
|
+
* Next 16.3 + `pg` app builds clean under Turbopack AND under `next build
|
|
2201
|
+
* --webpack` with no next.config help (verified 2026-11-12). Worse, handing
|
|
2202
|
+
* Turbopack a `webpack` block with no `turbopack` block FAILS the build, so on
|
|
2203
|
+
* 16 the step would break the very app it meant to fix. A version we cannot
|
|
2204
|
+
* read ("latest", "canary") resolves to 16 or later today, so it gets no step.
|
|
2205
|
+
*/
|
|
2206
|
+
function nextNeedsEdgeExternals(versionRange) {
|
|
2207
|
+
const major = versionRange ? LEADING_MAJOR.exec(versionRange)?.[1] : void 0;
|
|
2208
|
+
return major !== void 0 && Number(major) < NEXT_EDGE_BUNDLES_DRIVERS_MAJOR;
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Does this next.config already externalise every driver on the edge pass?
|
|
2212
|
+
* A text check, not a parse: the developer owns the file and its shape varies,
|
|
2213
|
+
* so it asks only whether the edge branch is there and names each driver.
|
|
2214
|
+
*/
|
|
2215
|
+
function nextConfigExternalisesDrivers(source, drivers) {
|
|
2216
|
+
if (!(source?.includes("nextRuntime") && source.includes("externals"))) return false;
|
|
2217
|
+
return drivers.every((d) => source.includes(`"${d}"`) || source.includes(`'${d}'`));
|
|
2218
|
+
}
|
|
2195
2219
|
/** The next.config step an app needs when its config reaches a Node driver. */
|
|
2196
2220
|
function nextEdgeExternalsStep(drivers) {
|
|
2197
2221
|
const list = drivers.map((d) => `"${d}"`).join(", ");
|
|
@@ -2287,9 +2311,7 @@ function guessDbImportPath(schemaImportPath) {
|
|
|
2287
2311
|
function renderImports(plan) {
|
|
2288
2312
|
const lines = [
|
|
2289
2313
|
"import { createClivlySDK, defineClivlyConfig } from \"clivly/sdk\";",
|
|
2290
|
-
"import {
|
|
2291
|
-
"import { discoverFromDrizzle } from \"clivly/drizzle\";",
|
|
2292
|
-
"import { drizzleIntrospector } from \"clivly/drizzle\";",
|
|
2314
|
+
"import {\n discoverFromDrizzle,\n drizzleAppIdStore,\n drizzleIntrospector,\n fromDrizzle,\n} from \"clivly/drizzle\";",
|
|
2293
2315
|
`import * as schema from "${plan.importPath}";`
|
|
2294
2316
|
];
|
|
2295
2317
|
if (plan.db === null) {
|
|
@@ -2325,6 +2347,10 @@ export default createClivlySDK({
|
|
|
2325
2347
|
// Lets derived objects authored in the dashboard run against this database.
|
|
2326
2348
|
// Without it they are fetched, validated and then skipped.
|
|
2327
2349
|
introspector: drizzleIntrospector(${dbExpr}),
|
|
2350
|
+
// Keeps the ID Clivly issues this app in a one-row \`crm_clivly_app\` table,
|
|
2351
|
+
// created on first use. With drizzle-kit push, add
|
|
2352
|
+
// \`tablesFilter: ["!crm_clivly_app"]\` so push leaves it alone.
|
|
2353
|
+
appIdStore: drizzleAppIdStore(${dbExpr}),
|
|
2328
2354
|
source: {
|
|
2329
2355
|
// Keyed by CRM concept — contacts/companies/deals/custom.
|
|
2330
2356
|
// NOT by your entity key. The entity's own \`source:\` above is a table name.
|
|
@@ -2772,16 +2798,37 @@ function declaredNextVersion(args) {
|
|
|
2772
2798
|
function declaredDependencies(args) {
|
|
2773
2799
|
return hostManifest(args).dependencies;
|
|
2774
2800
|
}
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2801
|
+
const NEXT_CONFIG_CANDIDATES$1 = [
|
|
2802
|
+
"next.config.ts",
|
|
2803
|
+
"next.config.mjs",
|
|
2804
|
+
"next.config.js",
|
|
2805
|
+
"next.config.cjs",
|
|
2806
|
+
"next.config.mts"
|
|
2807
|
+
];
|
|
2808
|
+
function nextConfigSource(args) {
|
|
2809
|
+
for (const candidate of NEXT_CONFIG_CANDIDATES$1) {
|
|
2810
|
+
const source = args.readFile(join(args.cwd, candidate));
|
|
2811
|
+
if (source !== null) return source;
|
|
2812
|
+
}
|
|
2813
|
+
return null;
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* The edge-externals step, or null when it does not apply: no Node-only driver,
|
|
2817
|
+
* Next >= 16 (whose edge pass bundles the driver unaided), or a next.config that already has
|
|
2818
|
+
* the edge externals in place.
|
|
2819
|
+
*/
|
|
2820
|
+
function edgeExternalsStepFor(args) {
|
|
2821
|
+
const drivers = nodeOnlyDrivers(declaredDependencies(args));
|
|
2822
|
+
if (drivers.length === 0) return null;
|
|
2823
|
+
if (!nextNeedsEdgeExternals(declaredNextVersion(args))) return null;
|
|
2824
|
+
if (nextConfigExternalisesDrivers(nextConfigSource(args), drivers)) return null;
|
|
2825
|
+
return nextEdgeExternalsStep(drivers);
|
|
2779
2826
|
}
|
|
2780
2827
|
function planBootPatch(args) {
|
|
2781
2828
|
if (bootHookPath(args.framework, args.layout) !== null) return {
|
|
2782
2829
|
file: null,
|
|
2783
2830
|
manual: args.framework === "nextjs" && nextNeedsInstrumentationFlag(declaredNextVersion(args)) ? NEXT_INSTRUMENTATION_FLAG_STEP : null,
|
|
2784
|
-
extra: args.framework === "nextjs" ? edgeExternalsStepFor(
|
|
2831
|
+
extra: args.framework === "nextjs" ? edgeExternalsStepFor(args) : null
|
|
2785
2832
|
};
|
|
2786
2833
|
if (args.framework === "remix") return {
|
|
2787
2834
|
file: null,
|
|
@@ -32,8 +32,57 @@ const contactSegmentSchema = z.array(z.object({
|
|
|
32
32
|
})).max(20);
|
|
33
33
|
// ../core/src/deal-value.ts
|
|
34
34
|
const MONTHS_PER_YEAR = 12;
|
|
35
|
+
const MONTHS_PER_QUARTER = 3;
|
|
36
|
+
const WEEKS_PER_YEAR = 52;
|
|
35
37
|
/** Only two decimal-free seat counts make sense; anything else is bad data. */
|
|
36
38
|
const SEAT_COUNT_REGEX = /^\d+$/;
|
|
39
|
+
const WHOLE_NUMBER_REGEX = /^\d+$/;
|
|
40
|
+
const DECIMAL_AMOUNT_REGEX = /^(\d+)(?:\.(\d{1,2}))?$/;
|
|
41
|
+
const INTERVAL_SYNONYMS = {
|
|
42
|
+
annual: "year",
|
|
43
|
+
annually: "year",
|
|
44
|
+
month: "month",
|
|
45
|
+
monthly: "month",
|
|
46
|
+
quarter: "quarter",
|
|
47
|
+
quarterly: "quarter",
|
|
48
|
+
week: "week",
|
|
49
|
+
weekly: "week",
|
|
50
|
+
year: "year",
|
|
51
|
+
yearly: "year"
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Monthly share of one charge, as a fraction so the division happens once.
|
|
55
|
+
* A week is 52/12 of a month's worth per month: 52 charges a year, spread
|
|
56
|
+
* over twelve months.
|
|
57
|
+
*/
|
|
58
|
+
const MONTHLY_FRACTION = {
|
|
59
|
+
month: {
|
|
60
|
+
denominator: 1,
|
|
61
|
+
numerator: 1
|
|
62
|
+
},
|
|
63
|
+
quarter: {
|
|
64
|
+
denominator: MONTHS_PER_QUARTER,
|
|
65
|
+
numerator: 1
|
|
66
|
+
},
|
|
67
|
+
week: {
|
|
68
|
+
denominator: MONTHS_PER_YEAR,
|
|
69
|
+
numerator: WEEKS_PER_YEAR
|
|
70
|
+
},
|
|
71
|
+
year: {
|
|
72
|
+
denominator: MONTHS_PER_YEAR,
|
|
73
|
+
numerator: 1
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The billing interval a row names. `undefined` when no interval column is
|
|
78
|
+
* configured or mapped; `null` when it holds something unrecognised.
|
|
79
|
+
*/
|
|
80
|
+
function readInterval(intervalField, fields, mappedFields) {
|
|
81
|
+
if (intervalField === void 0 || !mappedFields.has(intervalField)) return;
|
|
82
|
+
const raw = fields[intervalField]?.trim().toLowerCase();
|
|
83
|
+
if (!raw) return null;
|
|
84
|
+
return INTERVAL_SYNONYMS[raw] ?? null;
|
|
85
|
+
}
|
|
37
86
|
/**
|
|
38
87
|
* The value one deal should have, in cents, or null to leave it alone.
|
|
39
88
|
*
|
|
@@ -45,15 +94,25 @@ const SEAT_COUNT_REGEX = /^\d+$/;
|
|
|
45
94
|
*/
|
|
46
95
|
function computeDealValue(source, fields, mappedFields, stageType) {
|
|
47
96
|
if (source.zeroInStageTypes?.includes(stageType)) return 0;
|
|
97
|
+
if (source.kind === "mapped_amount") return computeMappedAmount(source, fields, mappedFields);
|
|
98
|
+
return computePerSeat(source, fields, mappedFields);
|
|
99
|
+
}
|
|
100
|
+
function computePerSeat(source, fields, mappedFields) {
|
|
48
101
|
if (!(mappedFields.has(source.seatField) && mappedFields.has(source.planField))) return null;
|
|
49
102
|
const planKey = fields[source.planField];
|
|
50
103
|
if (planKey == null || planKey === "") return null;
|
|
51
|
-
const unitPriceCents = source.plans[planKey];
|
|
52
|
-
if (unitPriceCents === void 0) return null;
|
|
53
104
|
const rawSeats = fields[source.seatField];
|
|
54
105
|
if (rawSeats == null || !SEAT_COUNT_REGEX.test(rawSeats)) return null;
|
|
55
106
|
const seats = Number(rawSeats);
|
|
56
107
|
if (!Number.isSafeInteger(seats)) return null;
|
|
108
|
+
const yearlyPrice = source.yearlyPlans?.[planKey];
|
|
109
|
+
if (yearlyPrice !== void 0 && readInterval(source.intervalField, fields, mappedFields) === "year") {
|
|
110
|
+
const yearly = (source.yearlyBaseFeeCents ?? (source.baseFeeCents ?? 0) * MONTHS_PER_YEAR) + seats * yearlyPrice;
|
|
111
|
+
if (!Number.isSafeInteger(yearly) || yearly < 0) return null;
|
|
112
|
+
return Math.round(yearly / MONTHS_PER_YEAR);
|
|
113
|
+
}
|
|
114
|
+
const unitPriceCents = source.plans[planKey];
|
|
115
|
+
if (unitPriceCents === void 0) return null;
|
|
57
116
|
const monthly = (source.baseFeeCents ?? 0) + seats * unitPriceCents;
|
|
58
117
|
if (!Number.isSafeInteger(monthly) || monthly < 0) return null;
|
|
59
118
|
return normalizePrice(monthly, source, fields, mappedFields);
|
|
@@ -62,13 +121,43 @@ function computeDealValue(source, fields, mappedFields, stageType) {
|
|
|
62
121
|
function normalizePrice(monthly, source, fields, mappedFields) {
|
|
63
122
|
if (source.priceBasis === "monthly") return monthly;
|
|
64
123
|
if (source.priceBasis === "billing_interval") {
|
|
65
|
-
const interval = source.intervalField
|
|
66
|
-
if (interval === "month"
|
|
67
|
-
if (interval === "year"
|
|
124
|
+
const interval = readInterval(source.intervalField, fields, mappedFields);
|
|
125
|
+
if (interval === "month") return monthly;
|
|
126
|
+
if (interval === "year") return Math.round(monthly / MONTHS_PER_YEAR);
|
|
68
127
|
return null;
|
|
69
128
|
}
|
|
70
129
|
return source.intervalField !== void 0 && mappedFields.has(source.intervalField) && fields[source.intervalField] === "year" ? Math.round(monthly / MONTHS_PER_YEAR) : monthly;
|
|
71
130
|
}
|
|
131
|
+
/** A host amount in cents, or null when it is not one. */
|
|
132
|
+
function parseAmount(raw, unit) {
|
|
133
|
+
const text = raw?.trim();
|
|
134
|
+
if (!text) return null;
|
|
135
|
+
if (unit === "cents") return WHOLE_NUMBER_REGEX.test(text) ? Number(text) : null;
|
|
136
|
+
const match = DECIMAL_AMOUNT_REGEX.exec(text);
|
|
137
|
+
if (!match) return null;
|
|
138
|
+
const [, whole, fraction = ""] = match;
|
|
139
|
+
return Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
|
|
140
|
+
}
|
|
141
|
+
function computeMappedAmount(source, fields, mappedFields) {
|
|
142
|
+
if (!mappedFields.has(source.amountField)) return null;
|
|
143
|
+
const amount = parseAmount(fields[source.amountField], source.amountUnit);
|
|
144
|
+
if (amount === null || !Number.isSafeInteger(amount)) return null;
|
|
145
|
+
const interval = source.intervalField === void 0 ? "month" : readInterval(source.intervalField, fields, mappedFields);
|
|
146
|
+
if (!interval) return null;
|
|
147
|
+
let count = 1;
|
|
148
|
+
if (source.intervalCountField !== void 0) {
|
|
149
|
+
if (!mappedFields.has(source.intervalCountField)) return null;
|
|
150
|
+
const rawCount = fields[source.intervalCountField]?.trim();
|
|
151
|
+
if (rawCount) {
|
|
152
|
+
if (!WHOLE_NUMBER_REGEX.test(rawCount) || Number(rawCount) < 1) return null;
|
|
153
|
+
count = Number(rawCount);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const { denominator, numerator } = MONTHLY_FRACTION[interval];
|
|
157
|
+
const scaled = amount * numerator;
|
|
158
|
+
if (!Number.isSafeInteger(scaled)) return null;
|
|
159
|
+
return Math.round(scaled / (denominator * count));
|
|
160
|
+
}
|
|
72
161
|
// ../core/src/host-owned-fields.ts
|
|
73
162
|
/**
|
|
74
163
|
* Which fields a CRM record lets a user edit.
|
|
@@ -21,9 +21,52 @@ interface PerSeatValueSource {
|
|
|
21
21
|
priceBasis?: "monthly" | "billing_interval";
|
|
22
22
|
/** Mapped column holding the seat count. */
|
|
23
23
|
seatField: string;
|
|
24
|
+
/**
|
|
25
|
+
* Annual flat fee in cents, for rows billed yearly at a yearly price. When
|
|
26
|
+
* absent, an annual row with a yearly plan price uses twelve times
|
|
27
|
+
* `baseFeeCents`, which is a monthly fee.
|
|
28
|
+
*/
|
|
29
|
+
yearlyBaseFeeCents?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Annual list price per seat in cents, keyed like `plans`. A row billed
|
|
32
|
+
* yearly whose plan has one is valued at (annual fee + seats × this) ÷ 12.
|
|
33
|
+
* One `plans` map cannot be both a monthly and a yearly price, which is why
|
|
34
|
+
* an annual plan that is not simply twelve months needs its own number.
|
|
35
|
+
*/
|
|
36
|
+
yearlyPlans?: Record<string, number>;
|
|
24
37
|
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
25
38
|
zeroInStageTypes?: string[];
|
|
26
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Value read from an amount the host's billing system already knows.
|
|
42
|
+
*
|
|
43
|
+
* The recommended source whenever the host has it: negotiated prices,
|
|
44
|
+
* discounts and multi-item subscriptions are all already in the billed
|
|
45
|
+
* amount, so Clivly does not have to model a price book to get them right.
|
|
46
|
+
*/
|
|
47
|
+
interface MappedAmountValueSource {
|
|
48
|
+
/** Mapped column holding the amount charged each billing period. */
|
|
49
|
+
amountField: string;
|
|
50
|
+
/**
|
|
51
|
+
* How the amount is written: `cents` for minor units (Stripe's `amount`,
|
|
52
|
+
* `1250`), `units` for a decimal amount (`12.50`).
|
|
53
|
+
*/
|
|
54
|
+
amountUnit: "cents" | "units";
|
|
55
|
+
/**
|
|
56
|
+
* Mapped column holding how many intervals one charge covers (Stripe's
|
|
57
|
+
* `interval_count`: 3 with `month` is quarterly). Absent means 1.
|
|
58
|
+
*/
|
|
59
|
+
intervalCountField?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Mapped column holding the billing interval: month, quarter, year or week.
|
|
62
|
+
* Absent means every amount is already monthly.
|
|
63
|
+
*/
|
|
64
|
+
intervalField?: string;
|
|
65
|
+
kind: "mapped_amount";
|
|
66
|
+
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
67
|
+
zeroInStageTypes?: string[];
|
|
68
|
+
}
|
|
69
|
+
type DealValueSource = PerSeatValueSource | MappedAmountValueSource;
|
|
27
70
|
/**
|
|
28
71
|
* The value one deal should have, in cents, or null to leave it alone.
|
|
29
72
|
*
|
|
@@ -33,7 +76,7 @@ interface PerSeatValueSource {
|
|
|
33
76
|
* unmapped case is surfaced through the rule-health warning surface instead of
|
|
34
77
|
* being written into the data — the same fail-safe `matchesCondition` applies.
|
|
35
78
|
*/
|
|
36
|
-
declare function computeDealValue(source:
|
|
79
|
+
declare function computeDealValue(source: DealValueSource, fields: Record<string, string | null>, mappedFields: Set<string>, stageType: string): number | null;
|
|
37
80
|
/**
|
|
38
81
|
* Which fields a CRM record lets a user edit.
|
|
39
82
|
*
|
|
@@ -182,4 +225,4 @@ declare function matchesCondition(condition: Condition, fields: Record<string, s
|
|
|
182
225
|
* a half-written rule should do.
|
|
183
226
|
*/
|
|
184
227
|
declare function evaluateStage(rules: EvaluableRule[], fields: Record<string, string | null>, mappedFields: Set<string>): string | null;
|
|
185
|
-
export { matchesCondition as a, HostOwnedCompanyField as c, hostOwnedFieldMessage as d, isHostOwned as f,
|
|
228
|
+
export { PerSeatValueSource as _, matchesCondition as a, HostOwnedCompanyField as c, hostOwnedFieldMessage as d, isHostOwned as f, MappedAmountValueSource as g, DealValueSource as h, evaluateStage as i, HostOwnedContactField as l, rejectedContactFields as m, ConditionOp as n, slugify as o, rejectedCompanyFields as p, EvaluableRule as r, toObjectTypeSlug as s, Condition as t, SourcedRecord as u, computeDealValue as v };
|
|
@@ -21,9 +21,52 @@ interface PerSeatValueSource {
|
|
|
21
21
|
priceBasis?: "monthly" | "billing_interval";
|
|
22
22
|
/** Mapped column holding the seat count. */
|
|
23
23
|
seatField: string;
|
|
24
|
+
/**
|
|
25
|
+
* Annual flat fee in cents, for rows billed yearly at a yearly price. When
|
|
26
|
+
* absent, an annual row with a yearly plan price uses twelve times
|
|
27
|
+
* `baseFeeCents`, which is a monthly fee.
|
|
28
|
+
*/
|
|
29
|
+
yearlyBaseFeeCents?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Annual list price per seat in cents, keyed like `plans`. A row billed
|
|
32
|
+
* yearly whose plan has one is valued at (annual fee + seats × this) ÷ 12.
|
|
33
|
+
* One `plans` map cannot be both a monthly and a yearly price, which is why
|
|
34
|
+
* an annual plan that is not simply twelve months needs its own number.
|
|
35
|
+
*/
|
|
36
|
+
yearlyPlans?: Record<string, number>;
|
|
24
37
|
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
25
38
|
zeroInStageTypes?: string[];
|
|
26
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Value read from an amount the host's billing system already knows.
|
|
42
|
+
*
|
|
43
|
+
* The recommended source whenever the host has it: negotiated prices,
|
|
44
|
+
* discounts and multi-item subscriptions are all already in the billed
|
|
45
|
+
* amount, so Clivly does not have to model a price book to get them right.
|
|
46
|
+
*/
|
|
47
|
+
interface MappedAmountValueSource {
|
|
48
|
+
/** Mapped column holding the amount charged each billing period. */
|
|
49
|
+
amountField: string;
|
|
50
|
+
/**
|
|
51
|
+
* How the amount is written: `cents` for minor units (Stripe's `amount`,
|
|
52
|
+
* `1250`), `units` for a decimal amount (`12.50`).
|
|
53
|
+
*/
|
|
54
|
+
amountUnit: "cents" | "units";
|
|
55
|
+
/**
|
|
56
|
+
* Mapped column holding how many intervals one charge covers (Stripe's
|
|
57
|
+
* `interval_count`: 3 with `month` is quarterly). Absent means 1.
|
|
58
|
+
*/
|
|
59
|
+
intervalCountField?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Mapped column holding the billing interval: month, quarter, year or week.
|
|
62
|
+
* Absent means every amount is already monthly.
|
|
63
|
+
*/
|
|
64
|
+
intervalField?: string;
|
|
65
|
+
kind: "mapped_amount";
|
|
66
|
+
/** Stage types whose deals are worth nothing (usually `["lost"]`). */
|
|
67
|
+
zeroInStageTypes?: string[];
|
|
68
|
+
}
|
|
69
|
+
type DealValueSource = PerSeatValueSource | MappedAmountValueSource;
|
|
27
70
|
/**
|
|
28
71
|
* The value one deal should have, in cents, or null to leave it alone.
|
|
29
72
|
*
|
|
@@ -33,7 +76,7 @@ interface PerSeatValueSource {
|
|
|
33
76
|
* unmapped case is surfaced through the rule-health warning surface instead of
|
|
34
77
|
* being written into the data — the same fail-safe `matchesCondition` applies.
|
|
35
78
|
*/
|
|
36
|
-
declare function computeDealValue(source:
|
|
79
|
+
declare function computeDealValue(source: DealValueSource, fields: Record<string, string | null>, mappedFields: Set<string>, stageType: string): number | null;
|
|
37
80
|
/**
|
|
38
81
|
* Which fields a CRM record lets a user edit.
|
|
39
82
|
*
|
|
@@ -182,4 +225,4 @@ declare function matchesCondition(condition: Condition, fields: Record<string, s
|
|
|
182
225
|
* a half-written rule should do.
|
|
183
226
|
*/
|
|
184
227
|
declare function evaluateStage(rules: EvaluableRule[], fields: Record<string, string | null>, mappedFields: Set<string>): string | null;
|
|
185
|
-
export { matchesCondition as a, HostOwnedCompanyField as c, hostOwnedFieldMessage as d, isHostOwned as f,
|
|
228
|
+
export { PerSeatValueSource as _, matchesCondition as a, HostOwnedCompanyField as c, hostOwnedFieldMessage as d, isHostOwned as f, MappedAmountValueSource as g, DealValueSource as h, evaluateStage as i, HostOwnedContactField as l, rejectedContactFields as m, ConditionOp as n, slugify as o, rejectedCompanyFields as p, EvaluableRule as r, toObjectTypeSlug as s, Condition as t, SourcedRecord as u, computeDealValue as v };
|
|
@@ -32,8 +32,57 @@ const contactSegmentSchema = zod.z.array(zod.z.object({
|
|
|
32
32
|
})).max(20);
|
|
33
33
|
// ../core/src/deal-value.ts
|
|
34
34
|
const MONTHS_PER_YEAR = 12;
|
|
35
|
+
const MONTHS_PER_QUARTER = 3;
|
|
36
|
+
const WEEKS_PER_YEAR = 52;
|
|
35
37
|
/** Only two decimal-free seat counts make sense; anything else is bad data. */
|
|
36
38
|
const SEAT_COUNT_REGEX = /^\d+$/;
|
|
39
|
+
const WHOLE_NUMBER_REGEX = /^\d+$/;
|
|
40
|
+
const DECIMAL_AMOUNT_REGEX = /^(\d+)(?:\.(\d{1,2}))?$/;
|
|
41
|
+
const INTERVAL_SYNONYMS = {
|
|
42
|
+
annual: "year",
|
|
43
|
+
annually: "year",
|
|
44
|
+
month: "month",
|
|
45
|
+
monthly: "month",
|
|
46
|
+
quarter: "quarter",
|
|
47
|
+
quarterly: "quarter",
|
|
48
|
+
week: "week",
|
|
49
|
+
weekly: "week",
|
|
50
|
+
year: "year",
|
|
51
|
+
yearly: "year"
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Monthly share of one charge, as a fraction so the division happens once.
|
|
55
|
+
* A week is 52/12 of a month's worth per month: 52 charges a year, spread
|
|
56
|
+
* over twelve months.
|
|
57
|
+
*/
|
|
58
|
+
const MONTHLY_FRACTION = {
|
|
59
|
+
month: {
|
|
60
|
+
denominator: 1,
|
|
61
|
+
numerator: 1
|
|
62
|
+
},
|
|
63
|
+
quarter: {
|
|
64
|
+
denominator: MONTHS_PER_QUARTER,
|
|
65
|
+
numerator: 1
|
|
66
|
+
},
|
|
67
|
+
week: {
|
|
68
|
+
denominator: MONTHS_PER_YEAR,
|
|
69
|
+
numerator: WEEKS_PER_YEAR
|
|
70
|
+
},
|
|
71
|
+
year: {
|
|
72
|
+
denominator: MONTHS_PER_YEAR,
|
|
73
|
+
numerator: 1
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The billing interval a row names. `undefined` when no interval column is
|
|
78
|
+
* configured or mapped; `null` when it holds something unrecognised.
|
|
79
|
+
*/
|
|
80
|
+
function readInterval(intervalField, fields, mappedFields) {
|
|
81
|
+
if (intervalField === void 0 || !mappedFields.has(intervalField)) return;
|
|
82
|
+
const raw = fields[intervalField]?.trim().toLowerCase();
|
|
83
|
+
if (!raw) return null;
|
|
84
|
+
return INTERVAL_SYNONYMS[raw] ?? null;
|
|
85
|
+
}
|
|
37
86
|
/**
|
|
38
87
|
* The value one deal should have, in cents, or null to leave it alone.
|
|
39
88
|
*
|
|
@@ -45,15 +94,25 @@ const SEAT_COUNT_REGEX = /^\d+$/;
|
|
|
45
94
|
*/
|
|
46
95
|
function computeDealValue(source, fields, mappedFields, stageType) {
|
|
47
96
|
if (source.zeroInStageTypes?.includes(stageType)) return 0;
|
|
97
|
+
if (source.kind === "mapped_amount") return computeMappedAmount(source, fields, mappedFields);
|
|
98
|
+
return computePerSeat(source, fields, mappedFields);
|
|
99
|
+
}
|
|
100
|
+
function computePerSeat(source, fields, mappedFields) {
|
|
48
101
|
if (!(mappedFields.has(source.seatField) && mappedFields.has(source.planField))) return null;
|
|
49
102
|
const planKey = fields[source.planField];
|
|
50
103
|
if (planKey == null || planKey === "") return null;
|
|
51
|
-
const unitPriceCents = source.plans[planKey];
|
|
52
|
-
if (unitPriceCents === void 0) return null;
|
|
53
104
|
const rawSeats = fields[source.seatField];
|
|
54
105
|
if (rawSeats == null || !SEAT_COUNT_REGEX.test(rawSeats)) return null;
|
|
55
106
|
const seats = Number(rawSeats);
|
|
56
107
|
if (!Number.isSafeInteger(seats)) return null;
|
|
108
|
+
const yearlyPrice = source.yearlyPlans?.[planKey];
|
|
109
|
+
if (yearlyPrice !== void 0 && readInterval(source.intervalField, fields, mappedFields) === "year") {
|
|
110
|
+
const yearly = (source.yearlyBaseFeeCents ?? (source.baseFeeCents ?? 0) * MONTHS_PER_YEAR) + seats * yearlyPrice;
|
|
111
|
+
if (!Number.isSafeInteger(yearly) || yearly < 0) return null;
|
|
112
|
+
return Math.round(yearly / MONTHS_PER_YEAR);
|
|
113
|
+
}
|
|
114
|
+
const unitPriceCents = source.plans[planKey];
|
|
115
|
+
if (unitPriceCents === void 0) return null;
|
|
57
116
|
const monthly = (source.baseFeeCents ?? 0) + seats * unitPriceCents;
|
|
58
117
|
if (!Number.isSafeInteger(monthly) || monthly < 0) return null;
|
|
59
118
|
return normalizePrice(monthly, source, fields, mappedFields);
|
|
@@ -62,13 +121,43 @@ function computeDealValue(source, fields, mappedFields, stageType) {
|
|
|
62
121
|
function normalizePrice(monthly, source, fields, mappedFields) {
|
|
63
122
|
if (source.priceBasis === "monthly") return monthly;
|
|
64
123
|
if (source.priceBasis === "billing_interval") {
|
|
65
|
-
const interval = source.intervalField
|
|
66
|
-
if (interval === "month"
|
|
67
|
-
if (interval === "year"
|
|
124
|
+
const interval = readInterval(source.intervalField, fields, mappedFields);
|
|
125
|
+
if (interval === "month") return monthly;
|
|
126
|
+
if (interval === "year") return Math.round(monthly / MONTHS_PER_YEAR);
|
|
68
127
|
return null;
|
|
69
128
|
}
|
|
70
129
|
return source.intervalField !== void 0 && mappedFields.has(source.intervalField) && fields[source.intervalField] === "year" ? Math.round(monthly / MONTHS_PER_YEAR) : monthly;
|
|
71
130
|
}
|
|
131
|
+
/** A host amount in cents, or null when it is not one. */
|
|
132
|
+
function parseAmount(raw, unit) {
|
|
133
|
+
const text = raw?.trim();
|
|
134
|
+
if (!text) return null;
|
|
135
|
+
if (unit === "cents") return WHOLE_NUMBER_REGEX.test(text) ? Number(text) : null;
|
|
136
|
+
const match = DECIMAL_AMOUNT_REGEX.exec(text);
|
|
137
|
+
if (!match) return null;
|
|
138
|
+
const [, whole, fraction = ""] = match;
|
|
139
|
+
return Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
|
|
140
|
+
}
|
|
141
|
+
function computeMappedAmount(source, fields, mappedFields) {
|
|
142
|
+
if (!mappedFields.has(source.amountField)) return null;
|
|
143
|
+
const amount = parseAmount(fields[source.amountField], source.amountUnit);
|
|
144
|
+
if (amount === null || !Number.isSafeInteger(amount)) return null;
|
|
145
|
+
const interval = source.intervalField === void 0 ? "month" : readInterval(source.intervalField, fields, mappedFields);
|
|
146
|
+
if (!interval) return null;
|
|
147
|
+
let count = 1;
|
|
148
|
+
if (source.intervalCountField !== void 0) {
|
|
149
|
+
if (!mappedFields.has(source.intervalCountField)) return null;
|
|
150
|
+
const rawCount = fields[source.intervalCountField]?.trim();
|
|
151
|
+
if (rawCount) {
|
|
152
|
+
if (!WHOLE_NUMBER_REGEX.test(rawCount) || Number(rawCount) < 1) return null;
|
|
153
|
+
count = Number(rawCount);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const { denominator, numerator } = MONTHLY_FRACTION[interval];
|
|
157
|
+
const scaled = amount * numerator;
|
|
158
|
+
if (!Number.isSafeInteger(scaled)) return null;
|
|
159
|
+
return Math.round(scaled / (denominator * count));
|
|
160
|
+
}
|
|
72
161
|
// ../core/src/host-owned-fields.ts
|
|
73
162
|
/**
|
|
74
163
|
* Which fields a CRM record lets a user edit.
|
package/internal.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const require_projection = require("./projection-w4Z6vSL2.cjs");
|
|
|
3
3
|
const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
|
|
4
4
|
const require_mappings_config = require("./mappings-config-CC-vltWb.cjs");
|
|
5
5
|
const require_auth_adapter = require("./auth-adapter-CNVuxT9W.cjs");
|
|
6
|
-
const require_internal = require("./internal-
|
|
6
|
+
const require_internal = require("./internal-D88LTRlu.cjs");
|
|
7
7
|
const require_mapping_form = require("./mapping-form-Bs6JQurC.cjs");
|
|
8
8
|
const require_projection_sql = require("./projection-sql-BkrHR2ea.cjs");
|
|
9
9
|
const require_view_compiler = require("./view-compiler-NqiortOA.cjs");
|
package/internal.d.cts
CHANGED
|
@@ -6,6 +6,6 @@ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as
|
|
|
6
6
|
import { i as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-DNo_Cum_.cjs";
|
|
7
7
|
import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-BDD93Luw.cjs";
|
|
8
8
|
import { c as SyncAction, f as isRemovalAction, g as runSync, h as resolveActions, l as SyncResult, m as reconcile, n as MirrorRecord, o as ResolvedMembership, r as PersistAction, s as SourceRow, t as EntitySyncResult, u as SyncStore } from "./sync-engine-DCjTr2XQ.cjs";
|
|
9
|
-
import { a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as
|
|
9
|
+
import { _ as PerSeatValueSource, a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as MappedAmountValueSource, h as DealValueSource, i as evaluateStage, l as HostOwnedContactField, m as rejectedContactFields, n as ConditionOp, o as slugify, p as rejectedCompanyFields, r as EvaluableRule, s as toObjectTypeSlug, t as Condition, u as SourcedRecord, v as computeDealValue } from "./internal-D7qVRIFb.cjs";
|
|
10
10
|
import { C as StepProblem, S as StepId, _ as IntegrationFacts, a as validateProjection, b as IntegrationStep, c as compileProjectionFrom, d as compileProjectionPreview, f as compileProjectionSelect, g as ConnectionLiveness, h as joinFansOut, i as primaryKeyColumns, l as compileProjectionIdentity, m as fanOutJoins, n as coversUniqueKey, o as validateProjectionFilter, p as quoteIdent, r as hasRichMeta, s as PREVIEW_MAX_ROWS, t as columnMetaFor, u as compileProjectionJoins, v as IntegrationState, w as StepState, x as NextAction, y as IntegrationStatus } from "./index-DRRTE5IJ.cjs";
|
|
11
|
-
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
|
11
|
+
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DealValueSource, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MappedAmountValueSource, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
package/internal.d.mts
CHANGED
|
@@ -6,6 +6,6 @@ import { i as relationshipViaSignature, n as buildFilterFromDiscriminator, r as
|
|
|
6
6
|
import { i as mappingsToEntitiesConfig, t as EntityMappingRow } from "./mappings-config-wAe-p1rG.mjs";
|
|
7
7
|
import { a as compileEntityView, i as ExplainResult, n as CompiledView, o as compileEntityViews, r as DEFAULT_VIEW_PREFIX, s as explainEntitiesConfig, t as CompileOptions } from "./view-compiler-CSNhmCY2.mjs";
|
|
8
8
|
import { c as SyncAction, f as isRemovalAction, g as runSync, h as resolveActions, l as SyncResult, m as reconcile, n as MirrorRecord, o as ResolvedMembership, r as PersistAction, s as SourceRow, t as EntitySyncResult, u as SyncStore } from "./sync-engine-UNORma7f.mjs";
|
|
9
|
-
import { a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as
|
|
9
|
+
import { _ as PerSeatValueSource, a as matchesCondition, c as HostOwnedCompanyField, d as hostOwnedFieldMessage, f as isHostOwned, g as MappedAmountValueSource, h as DealValueSource, i as evaluateStage, l as HostOwnedContactField, m as rejectedContactFields, n as ConditionOp, o as slugify, p as rejectedCompanyFields, r as EvaluableRule, s as toObjectTypeSlug, t as Condition, u as SourcedRecord, v as computeDealValue } from "./internal-CdfVkh4O.mjs";
|
|
10
10
|
import { C as StepProblem, S as StepId, _ as IntegrationFacts, a as validateProjection, b as IntegrationStep, c as compileProjectionFrom, d as compileProjectionPreview, f as compileProjectionSelect, g as ConnectionLiveness, h as joinFansOut, i as primaryKeyColumns, l as compileProjectionIdentity, m as fanOutJoins, n as coversUniqueKey, o as validateProjectionFilter, p as quoteIdent, r as hasRichMeta, s as PREVIEW_MAX_ROWS, t as columnMetaFor, u as compileProjectionJoins, v as IntegrationState, w as StepState, x as NextAction, y as IntegrationStatus } from "./index-Bh7o2J7K.mjs";
|
|
11
|
-
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
|
11
|
+
export { type Activity, type ActivityType, BASE_REF, CANONICAL_FIELDS, type CRMAdapter, CRM_CONCEPTS, type ClivlyAuthAdapter, ClivlyConfigError, type ClivlyEntitiesConfig, type ClivlyEntityConfig, type ClivlyUser, type Company, type CompanyFilters, type CompileOptions, type CompiledView, type Condition, type ConditionOp, type ConfigValidationError, type ConfigValidationResult, type ConnectionLiveness, type Contact, type ContactFilters, type ContactSegment, type ContactSource, type ContactStatus, type CreateActivityInput, type CreateCompanyInput, type CreateContactInput, type CreateDealInput, type CreateTaskInput, type CrmConcept, type CrmMembership, type CrmRole, DEFAULT_VIEW_PREFIX, type Deal, type DealStage, type DealValueSource, type DiscoveredColumnMeta, type DiscoveredSchemaTable, type EntityMappingRow, type EntitySyncResult, type EvaluableRule, type ExplainResult, type FilterExpr, type FilterValue, type HostOwnedCompanyField, type HostOwnedContactField, type IntegrationFacts, type IntegrationState, type IntegrationStatus, type IntegrationStep, MATERIALIZING_CONCEPTS, type MappedAmountValueSource, type MaterializingConcept, type MembershipResolver, type MirrorRecord, type NextAction, type Note, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, type Page, type PageRequest, type PerSeatValueSource, type PersistAction, type PipelineConfig, type PipelineKind, type PipelineStageConfig, type ProjectionFieldBinding, type ProjectionIdentity, type ProjectionJoin, type ProjectionMapping, type ProjectionRef, REQUIRED_FIELDS, type RecordSource, type RelationshipCandidate, type RelationshipSpec, type RelationshipVia, type RelationshipsMap, type ResolvedMembership, type SourceRow, type SourcedRecord, type StageType, type StepId, type StepProblem, type StepState, type SyncAction, type SyncResult, type SyncStore, type Task, type TaskEntityType, type TaskFilters, type TaskPriority, type TaskStatus, type UpdateCompanyInput, type UpdateContactInput, type UpdateDealInput, type UpdateTaskInput, type ValueInterval, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, contactSegmentSchema, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, isRemovalAction, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, resolveActions, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
|
package/internal.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { i as projectionSchema, n as PROJECTION_KEY_PATTERN, r as identityRefs,
|
|
|
2
2
|
import { C as hasRichMeta, S as coversUniqueKey, _ as validateProjection, a as MATERIALIZING_CONCEPTS, b as joinFansOut, c as defineClivlyConfig, d as missingRequiredFields, f as projectionFields, g as validateEntitiesConfig, h as requiredFieldsFor, i as ClivlyConfigError, l as entitiesConfigSchema, m as relationshipsSchema, n as CRM_CONCEPTS, o as REQUIRED_FIELDS, p as relationshipSchema, t as CANONICAL_FIELDS, u as filterSchema, v as validateProjectionFilter, w as primaryKeyColumns, x as columnMetaFor, y as fanOutJoins } from "./entity-config-CI5CGfaN.mjs";
|
|
3
3
|
import { n as mappingsToEntitiesConfig } from "./mappings-config-Opw7ZM6Y.mjs";
|
|
4
4
|
import { t as authCustom } from "./auth-adapter-u91PByaw.mjs";
|
|
5
|
-
import { a as hostOwnedFieldMessage, c as rejectedContactFields, i as toObjectTypeSlug, l as computeDealValue, n as matchesCondition, o as isHostOwned, r as slugify, s as rejectedCompanyFields, t as evaluateStage, u as contactSegmentSchema } from "./internal-
|
|
5
|
+
import { a as hostOwnedFieldMessage, c as rejectedContactFields, i as toObjectTypeSlug, l as computeDealValue, n as matchesCondition, o as isHostOwned, r as slugify, s as rejectedCompanyFields, t as evaluateStage, u as contactSegmentSchema } from "./internal-BAw1MCMV.mjs";
|
|
6
6
|
import { n as buildRelationships, r as relationshipViaSignature, t as buildFilterFromDiscriminator } from "./mapping-form-C7kDMWzp.mjs";
|
|
7
7
|
import { a as compileProjectionPreview, i as compileProjectionJoins, n as compileProjectionFrom, o as compileProjectionSelect, r as compileProjectionIdentity, s as quoteIdent, t as PREVIEW_MAX_ROWS } from "./projection-sql-DQQdjw9I.mjs";
|
|
8
8
|
import { i as explainEntitiesConfig, n as compileEntityView, r as compileEntityViews, t as DEFAULT_VIEW_PREFIX } from "./view-compiler-CSHSqZl7.mjs";
|
|
@@ -58,6 +58,13 @@ interface ClivlySDKConfig {
|
|
|
58
58
|
apiKey: string;
|
|
59
59
|
/** Clivly API base URL. Defaults to https://api.clivly.com. */
|
|
60
60
|
apiUrl?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Where this app keeps the ID Clivly issued it, so Clivly can recognise the
|
|
63
|
+
* same app across workspaces. Build one with `drizzleAppIdStore(db)` from
|
|
64
|
+
* `clivly/drizzle`. Without it the app is simply not identified; nothing
|
|
65
|
+
* else changes.
|
|
66
|
+
*/
|
|
67
|
+
appIdStore?: AppIdStore;
|
|
61
68
|
/**
|
|
62
69
|
* The host table Clivly treats as the contact entity.
|
|
63
70
|
* @deprecated Prefer `entities` — the same mapping-derived shape
|
|
@@ -416,6 +423,15 @@ interface SyncSource {
|
|
|
416
423
|
[DRIZZLE_META]?: DrizzleSourceMeta;
|
|
417
424
|
}
|
|
418
425
|
type SyncMode = "delta" | "full";
|
|
426
|
+
/**
|
|
427
|
+
* Keeps the one ID Clivly issued this app (the `crm_clivly_app` row). `get`
|
|
428
|
+
* returns null until Clivly has issued one. Both may throw; a failure is
|
|
429
|
+
* retried on the next heartbeat and never breaks the heartbeat itself.
|
|
430
|
+
*/
|
|
431
|
+
interface AppIdStore {
|
|
432
|
+
get(): Promise<string | null> | string | null;
|
|
433
|
+
set(appId: string): Promise<void> | void;
|
|
434
|
+
}
|
|
419
435
|
interface CursorStore {
|
|
420
436
|
get(entity: string): Promise<SyncCursor | null> | SyncCursor | null;
|
|
421
437
|
set(entity: string, cursor: SyncCursor | null): Promise<void> | void;
|
|
@@ -714,4 +730,4 @@ interface NamespaceIntrospector {
|
|
|
714
730
|
/** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
|
|
715
731
|
sampleSelect(table: string): Promise<void>;
|
|
716
732
|
}
|
|
717
|
-
export { ExposurePolicy as S,
|
|
733
|
+
export { ExposurePolicy as C, SyncTriggerDescription as S, EnsureSchemaResult as _, ClivlyConnectReason as a, RemoteProjectionsDescription as b, ClivlyConsentResult as c, ClivlyUser as d, CreateChatSessionHandlerOptions as f, DoctorReport as g, DoctorCheck as h, ChatWidgetVisitor as i, ClivlySDK as l, DiscoveredTable as m, AppIdStore as n, ClivlyConnectResult as o, CursorStore as p, ChatSessionRequestBody as r, ClivlyConsentInput as s, NamespaceIntrospector as t, ClivlySDKConfig as u, EnsuredMappingResult as v, SyncSource as x, EnsuredObjectTypeResult as y };
|
|
@@ -58,6 +58,13 @@ interface ClivlySDKConfig {
|
|
|
58
58
|
apiKey: string;
|
|
59
59
|
/** Clivly API base URL. Defaults to https://api.clivly.com. */
|
|
60
60
|
apiUrl?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Where this app keeps the ID Clivly issued it, so Clivly can recognise the
|
|
63
|
+
* same app across workspaces. Build one with `drizzleAppIdStore(db)` from
|
|
64
|
+
* `clivly/drizzle`. Without it the app is simply not identified; nothing
|
|
65
|
+
* else changes.
|
|
66
|
+
*/
|
|
67
|
+
appIdStore?: AppIdStore;
|
|
61
68
|
/**
|
|
62
69
|
* The host table Clivly treats as the contact entity.
|
|
63
70
|
* @deprecated Prefer `entities` — the same mapping-derived shape
|
|
@@ -416,6 +423,15 @@ interface SyncSource {
|
|
|
416
423
|
[DRIZZLE_META]?: DrizzleSourceMeta;
|
|
417
424
|
}
|
|
418
425
|
type SyncMode = "delta" | "full";
|
|
426
|
+
/**
|
|
427
|
+
* Keeps the one ID Clivly issued this app (the `crm_clivly_app` row). `get`
|
|
428
|
+
* returns null until Clivly has issued one. Both may throw; a failure is
|
|
429
|
+
* retried on the next heartbeat and never breaks the heartbeat itself.
|
|
430
|
+
*/
|
|
431
|
+
interface AppIdStore {
|
|
432
|
+
get(): Promise<string | null> | string | null;
|
|
433
|
+
set(appId: string): Promise<void> | void;
|
|
434
|
+
}
|
|
419
435
|
interface CursorStore {
|
|
420
436
|
get(entity: string): Promise<SyncCursor | null> | SyncCursor | null;
|
|
421
437
|
set(entity: string, cursor: SyncCursor | null): Promise<void> | void;
|
|
@@ -714,4 +730,4 @@ interface NamespaceIntrospector {
|
|
|
714
730
|
/** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
|
|
715
731
|
sampleSelect(table: string): Promise<void>;
|
|
716
732
|
}
|
|
717
|
-
export { ExposurePolicy as S,
|
|
733
|
+
export { ExposurePolicy as C, SyncTriggerDescription as S, EnsureSchemaResult as _, ClivlyConnectReason as a, RemoteProjectionsDescription as b, ClivlyConsentResult as c, ClivlyUser as d, CreateChatSessionHandlerOptions as f, DoctorReport as g, DoctorCheck as h, ChatWidgetVisitor as i, ClivlySDK as l, DiscoveredTable as m, AppIdStore as n, ClivlyConnectResult as o, CursorStore as p, ChatSessionRequestBody as r, ClivlyConsentInput as s, NamespaceIntrospector as t, ClivlySDKConfig as u, EnsuredMappingResult as v, SyncSource as x, EnsuredObjectTypeResult as y };
|
package/package.json
CHANGED
|
@@ -2684,15 +2684,36 @@ function createClivlySDK(config) {
|
|
|
2684
2684
|
...counts
|
|
2685
2685
|
};
|
|
2686
2686
|
};
|
|
2687
|
-
|
|
2687
|
+
let appId;
|
|
2688
|
+
const readAppId = async () => {
|
|
2689
|
+
if (appId !== void 0 || !config.appIdStore) return appId ?? null;
|
|
2690
|
+
try {
|
|
2691
|
+
appId = await config.appIdStore.get() ?? null;
|
|
2692
|
+
} catch {
|
|
2693
|
+
return null;
|
|
2694
|
+
}
|
|
2695
|
+
return appId;
|
|
2696
|
+
};
|
|
2697
|
+
const keepIssuedAppId = async (response) => {
|
|
2698
|
+
if (!(config.appIdStore && response?.ok) || appId) return;
|
|
2699
|
+
try {
|
|
2700
|
+
const body = await response.clone().json();
|
|
2701
|
+
if (typeof body?.appId !== "string" || body.appId.length === 0) return;
|
|
2702
|
+
await config.appIdStore.set(body.appId);
|
|
2703
|
+
appId = body.appId;
|
|
2704
|
+
} catch {}
|
|
2705
|
+
};
|
|
2706
|
+
const sendHeartbeat = async () => {
|
|
2688
2707
|
const triggerUrl = describeSyncTrigger().resolved;
|
|
2689
|
-
|
|
2708
|
+
const reportedAppId = config.appIdStore ? await readAppId() : void 0;
|
|
2709
|
+
const response = await fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
|
|
2690
2710
|
method: "POST",
|
|
2691
2711
|
headers: {
|
|
2692
2712
|
"content-type": "application/json",
|
|
2693
2713
|
authorization: `Bearer ${config.apiKey}`
|
|
2694
2714
|
},
|
|
2695
2715
|
body: JSON.stringify({
|
|
2716
|
+
...reportedAppId === void 0 ? {} : { appId: reportedAppId },
|
|
2696
2717
|
...deploymentId ? { deploymentId } : {},
|
|
2697
2718
|
framework: config.framework,
|
|
2698
2719
|
orm: config.orm,
|
|
@@ -2711,6 +2732,8 @@ function createClivlySDK(config) {
|
|
|
2711
2732
|
...triggerUrl ? { syncTrigger: { url: triggerUrl } } : {}
|
|
2712
2733
|
})
|
|
2713
2734
|
});
|
|
2735
|
+
await keepIssuedAppId(response);
|
|
2736
|
+
return response;
|
|
2714
2737
|
};
|
|
2715
2738
|
const heartbeat = async () => {
|
|
2716
2739
|
return (await sendHeartbeat())?.ok ?? false;
|
|
@@ -2684,15 +2684,36 @@ function createClivlySDK(config) {
|
|
|
2684
2684
|
...counts
|
|
2685
2685
|
};
|
|
2686
2686
|
};
|
|
2687
|
-
|
|
2687
|
+
let appId;
|
|
2688
|
+
const readAppId = async () => {
|
|
2689
|
+
if (appId !== void 0 || !config.appIdStore) return appId ?? null;
|
|
2690
|
+
try {
|
|
2691
|
+
appId = await config.appIdStore.get() ?? null;
|
|
2692
|
+
} catch {
|
|
2693
|
+
return null;
|
|
2694
|
+
}
|
|
2695
|
+
return appId;
|
|
2696
|
+
};
|
|
2697
|
+
const keepIssuedAppId = async (response) => {
|
|
2698
|
+
if (!(config.appIdStore && response?.ok) || appId) return;
|
|
2699
|
+
try {
|
|
2700
|
+
const body = await response.clone().json();
|
|
2701
|
+
if (typeof body?.appId !== "string" || body.appId.length === 0) return;
|
|
2702
|
+
await config.appIdStore.set(body.appId);
|
|
2703
|
+
appId = body.appId;
|
|
2704
|
+
} catch {}
|
|
2705
|
+
};
|
|
2706
|
+
const sendHeartbeat = async () => {
|
|
2688
2707
|
const triggerUrl = describeSyncTrigger().resolved;
|
|
2689
|
-
|
|
2708
|
+
const reportedAppId = config.appIdStore ? await readAppId() : void 0;
|
|
2709
|
+
const response = await fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
|
|
2690
2710
|
method: "POST",
|
|
2691
2711
|
headers: {
|
|
2692
2712
|
"content-type": "application/json",
|
|
2693
2713
|
authorization: `Bearer ${config.apiKey}`
|
|
2694
2714
|
},
|
|
2695
2715
|
body: JSON.stringify({
|
|
2716
|
+
...reportedAppId === void 0 ? {} : { appId: reportedAppId },
|
|
2696
2717
|
...deploymentId ? { deploymentId } : {},
|
|
2697
2718
|
framework: config.framework,
|
|
2698
2719
|
orm: config.orm,
|
|
@@ -2711,6 +2732,8 @@ function createClivlySDK(config) {
|
|
|
2711
2732
|
...triggerUrl ? { syncTrigger: { url: triggerUrl } } : {}
|
|
2712
2733
|
})
|
|
2713
2734
|
});
|
|
2735
|
+
await keepIssuedAppId(response);
|
|
2736
|
+
return response;
|
|
2714
2737
|
};
|
|
2715
2738
|
const heartbeat = async () => {
|
|
2716
2739
|
return (await sendHeartbeat())?.ok ?? false;
|
package/sdk.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
|
|
3
|
-
const require_sdk = require("./sdk-
|
|
3
|
+
const require_sdk = require("./sdk-BOarpe5I.cjs");
|
|
4
4
|
exports.CURSOR_KEY_PREFIX = require_sdk.CURSOR_KEY_PREFIX;
|
|
5
5
|
exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
|
|
6
6
|
exports.ClivlyError = require_sdk.ClivlyError;
|
package/sdk.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe-CcL6Wj8E.cjs";
|
|
2
2
|
import { C as customObjectDeclarations, M as validateEntitiesConfig, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult, w as defineClivlyConfig } from "./entity-config-CXpGowQa.cjs";
|
|
3
3
|
export declare function isPlaceholderUrl(value: string): boolean;
|
|
4
4
|
export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser, resolveVisitorIp }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
|
|
@@ -60,4 +60,4 @@ export declare function kvCursorStore(kv: CursorKV, options?: {
|
|
|
60
60
|
* clearly-marked TODOs) and land with the Cloudflare infrastructure.
|
|
61
61
|
*/
|
|
62
62
|
export declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
|
|
63
|
-
export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
|
|
63
|
+
export { type AppIdStore, type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
|
package/sdk.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe-JuHriruA.mjs";
|
|
2
2
|
import { C as customObjectDeclarations, M as validateEntitiesConfig, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult, w as defineClivlyConfig } from "./entity-config-CXpGowQa.mjs";
|
|
3
3
|
export declare function isPlaceholderUrl(value: string): boolean;
|
|
4
4
|
export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser, resolveVisitorIp }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
|
|
@@ -60,4 +60,4 @@ export declare function kvCursorStore(kv: CursorKV, options?: {
|
|
|
60
60
|
* clearly-marked TODOs) and land with the Cloudflare infrastructure.
|
|
61
61
|
*/
|
|
62
62
|
export declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
|
|
63
|
-
export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
|
|
63
|
+
export { type AppIdStore, type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
|
package/sdk.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { c as defineClivlyConfig, g as validateEntitiesConfig, s as customObjectDeclarations } from "./entity-config-CI5CGfaN.mjs";
|
|
2
|
-
import { a as ClivlyAuthError, c as ClivlyRateLimitError, i as memoryCursorStore, l as createChatSessionHandler, n as createClivlySDK, o as ClivlyError, r as kvCursorStore, s as ClivlyNetworkError, t as CURSOR_KEY_PREFIX, u as isPlaceholderUrl } from "./sdk-
|
|
2
|
+
import { a as ClivlyAuthError, c as ClivlyRateLimitError, i as memoryCursorStore, l as createChatSessionHandler, n as createClivlySDK, o as ClivlyError, r as kvCursorStore, s as ClivlyNetworkError, t as CURSOR_KEY_PREFIX, u as isPlaceholderUrl } from "./sdk-BkMDOfCk.mjs";
|
|
3
3
|
export { CURSOR_KEY_PREFIX, ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, kvCursorStore, memoryCursorStore, validateEntitiesConfig };
|
package/vite.d.cts
CHANGED
package/vite.d.mts
CHANGED