@odla-ai/crm 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1264,6 +1264,22 @@ interface IntegrationProvision {
1264
1264
  human: string[];
1265
1265
  cli: string[];
1266
1266
  doctor: string[];
1267
+ smoke?: string[];
1268
+ }
1269
+ /** Natural-key config row the CLI creates only when no CRM config exists. */
1270
+ interface CrmIntegrationSeed {
1271
+ id: string;
1272
+ ns: string;
1273
+ key: {
1274
+ attr: string;
1275
+ value: string;
1276
+ };
1277
+ attrs: Record<string, unknown>;
1278
+ }
1279
+ /** Unauthenticated route check run by `odla-ai smoke`. */
1280
+ interface CrmIntegrationProbe {
1281
+ path: string;
1282
+ expectedStatus: number;
1267
1283
  }
1268
1284
  /** The CRM's descriptor shape: the shared base plus the schema + deny-all
1269
1285
  * rules provisioning installs (the chat-style extension). */
@@ -1275,16 +1291,38 @@ interface CrmIntegrationDescriptor {
1275
1291
  secrets: IntegrationSecret[];
1276
1292
  schema: SerializedSchema;
1277
1293
  rules: CrmRules;
1294
+ seeds?: CrmIntegrationSeed[];
1295
+ probes?: CrmIntegrationProbe[];
1278
1296
  provision: IntegrationProvision;
1279
1297
  }
1298
+ /** Initial owner-editable CRM settings seeded during first provisioning. */
1299
+ interface CrmIntegrationOptions {
1300
+ /** Worker mount path; defaults to `/api/crm`. */
1301
+ basePath?: string;
1302
+ notificationEmail?: string;
1303
+ replyTo?: string;
1304
+ debugEmail?: string;
1305
+ settings?: Record<string, unknown>;
1306
+ /** Seed timestamp override for reproducible builds/tests. */
1307
+ now?: number;
1308
+ }
1280
1309
  /**
1281
- * The concrete descriptor for @odla-ai/crm — consumed by the odla CLI,
1282
- * `odla doctor`, and the docs. Data only: it describes what installing the
1310
+ * The static documentation descriptor for @odla-ai/crm. Data only: it
1311
+ * describes what installing the
1283
1312
  * CRM means (push {@link CRM_SCHEMA}, install deny-all {@link CRM_RULES},
1284
1313
  * seed the `crm_config` row, mount `createCrmRoutes` in the app worker); it
1285
- * performs none of it. Billing secrets arrive with the @odla-ai/stripe
1286
- * adapter (M2) — the M1 surface needs no vault entries.
1314
+ * performs none of it. Use {@link createCrmIntegration} in `odla.config.mjs`
1315
+ * to add the config seed and live route probe the CLI can execute. Billing is
1316
+ * an optional injected provider seam and the core CRM needs no vault entries.
1287
1317
  */
1288
1318
  declare const crmIntegration: CrmIntegrationDescriptor;
1319
+ /**
1320
+ * Build the project-specific, CLI-consumable CRM integration descriptor.
1321
+ * The returned schema/rules merge structurally with app-authored db config;
1322
+ * the config singleton is seeded only when absent, preserving later owner
1323
+ * edits, and `smoke` verifies the mounted records route rejects anonymous
1324
+ * access. Mounting `createCrmRoutes` remains app-owned source work.
1325
+ */
1326
+ declare function createCrmIntegration(crm: Crm, options?: CrmIntegrationOptions): CrmIntegrationDescriptor;
1289
1327
 
1290
- export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_NS, CRM_RULES, CRM_SCHEMA, CRM_SLOTS, type CompiledList, type ConfigPatch, type ConsentEvent, type ConsentOutcome, type ConsentState, type Crm, type CrmActivity, type CrmActor, type CrmAggregateResult, type CrmAggregateSpec, type CrmAttrs, CrmClient, type CrmClientOptions, type CrmConfig, type CrmConfigRow, type CrmContactChannel, type CrmDb, type CrmDeps, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmResult, type CrmRouteOpts, type CrmRow, type CrmRule, type CrmRules, type CrmScalar, type CrmSlot, type CrmSort, type CrmTag, type CrmView, DEFAULT_LIMIT, EMAIL_STATUSES, type EmailStatus, type FieldDef, type FieldFilter, type FieldType, MAX_LIMIT, type PipelineDef, type PreparedWrite, RANK_EPSILON, RANK_STEP, type RelationDef, SORTABLE_COLUMNS, type SendEmailOpts, type SendEmailResult, type SerializedAttr, type SerializedEntity, type SerializedLink, type SerializedLinkEnd, type SerializedSchema, type StageDef, type StoredTemplate, type SubscriptionSnapshot, TASK_STATUSES, type TaskStatus, type TemplateSpec, type TypeDef, type TypeFacets, type TypeSummary, type ViewFilters, type ViewSpec, addActivity, addLink, addTag, applyConsent, applyConsentEvent, canEmail, canTransition, channelKey, compileList, createCrmRoutes, createRecord, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, getConfig, getRecord, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView };
1328
+ export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_NS, CRM_RULES, CRM_SCHEMA, CRM_SLOTS, type CompiledList, type ConfigPatch, type ConsentEvent, type ConsentOutcome, type ConsentState, type Crm, type CrmActivity, type CrmActor, type CrmAggregateResult, type CrmAggregateSpec, type CrmAttrs, CrmClient, type CrmClientOptions, type CrmConfig, type CrmConfigRow, type CrmContactChannel, type CrmDb, type CrmDeps, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmResult, type CrmRouteOpts, type CrmRow, type CrmRule, type CrmRules, type CrmScalar, type CrmSlot, type CrmSort, type CrmTag, type CrmView, DEFAULT_LIMIT, EMAIL_STATUSES, type EmailStatus, type FieldDef, type FieldFilter, type FieldType, MAX_LIMIT, type PipelineDef, type PreparedWrite, RANK_EPSILON, RANK_STEP, type RelationDef, SORTABLE_COLUMNS, type SendEmailOpts, type SendEmailResult, type SerializedAttr, type SerializedEntity, type SerializedLink, type SerializedLinkEnd, type SerializedSchema, type StageDef, type StoredTemplate, type SubscriptionSnapshot, TASK_STATUSES, type TaskStatus, type TemplateSpec, type TypeDef, type TypeFacets, type TypeSummary, type ViewFilters, type ViewSpec, addActivity, addLink, addTag, applyConsent, applyConsentEvent, canEmail, canTransition, channelKey, compileList, createCrmIntegration, createCrmRoutes, createRecord, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, getConfig, getRecord, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView };
package/dist/index.d.ts CHANGED
@@ -1264,6 +1264,22 @@ interface IntegrationProvision {
1264
1264
  human: string[];
1265
1265
  cli: string[];
1266
1266
  doctor: string[];
1267
+ smoke?: string[];
1268
+ }
1269
+ /** Natural-key config row the CLI creates only when no CRM config exists. */
1270
+ interface CrmIntegrationSeed {
1271
+ id: string;
1272
+ ns: string;
1273
+ key: {
1274
+ attr: string;
1275
+ value: string;
1276
+ };
1277
+ attrs: Record<string, unknown>;
1278
+ }
1279
+ /** Unauthenticated route check run by `odla-ai smoke`. */
1280
+ interface CrmIntegrationProbe {
1281
+ path: string;
1282
+ expectedStatus: number;
1267
1283
  }
1268
1284
  /** The CRM's descriptor shape: the shared base plus the schema + deny-all
1269
1285
  * rules provisioning installs (the chat-style extension). */
@@ -1275,16 +1291,38 @@ interface CrmIntegrationDescriptor {
1275
1291
  secrets: IntegrationSecret[];
1276
1292
  schema: SerializedSchema;
1277
1293
  rules: CrmRules;
1294
+ seeds?: CrmIntegrationSeed[];
1295
+ probes?: CrmIntegrationProbe[];
1278
1296
  provision: IntegrationProvision;
1279
1297
  }
1298
+ /** Initial owner-editable CRM settings seeded during first provisioning. */
1299
+ interface CrmIntegrationOptions {
1300
+ /** Worker mount path; defaults to `/api/crm`. */
1301
+ basePath?: string;
1302
+ notificationEmail?: string;
1303
+ replyTo?: string;
1304
+ debugEmail?: string;
1305
+ settings?: Record<string, unknown>;
1306
+ /** Seed timestamp override for reproducible builds/tests. */
1307
+ now?: number;
1308
+ }
1280
1309
  /**
1281
- * The concrete descriptor for @odla-ai/crm — consumed by the odla CLI,
1282
- * `odla doctor`, and the docs. Data only: it describes what installing the
1310
+ * The static documentation descriptor for @odla-ai/crm. Data only: it
1311
+ * describes what installing the
1283
1312
  * CRM means (push {@link CRM_SCHEMA}, install deny-all {@link CRM_RULES},
1284
1313
  * seed the `crm_config` row, mount `createCrmRoutes` in the app worker); it
1285
- * performs none of it. Billing secrets arrive with the @odla-ai/stripe
1286
- * adapter (M2) — the M1 surface needs no vault entries.
1314
+ * performs none of it. Use {@link createCrmIntegration} in `odla.config.mjs`
1315
+ * to add the config seed and live route probe the CLI can execute. Billing is
1316
+ * an optional injected provider seam and the core CRM needs no vault entries.
1287
1317
  */
1288
1318
  declare const crmIntegration: CrmIntegrationDescriptor;
1319
+ /**
1320
+ * Build the project-specific, CLI-consumable CRM integration descriptor.
1321
+ * The returned schema/rules merge structurally with app-authored db config;
1322
+ * the config singleton is seeded only when absent, preserving later owner
1323
+ * edits, and `smoke` verifies the mounted records route rejects anonymous
1324
+ * access. Mounting `createCrmRoutes` remains app-owned source work.
1325
+ */
1326
+ declare function createCrmIntegration(crm: Crm, options?: CrmIntegrationOptions): CrmIntegrationDescriptor;
1289
1327
 
1290
- export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_NS, CRM_RULES, CRM_SCHEMA, CRM_SLOTS, type CompiledList, type ConfigPatch, type ConsentEvent, type ConsentOutcome, type ConsentState, type Crm, type CrmActivity, type CrmActor, type CrmAggregateResult, type CrmAggregateSpec, type CrmAttrs, CrmClient, type CrmClientOptions, type CrmConfig, type CrmConfigRow, type CrmContactChannel, type CrmDb, type CrmDeps, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmResult, type CrmRouteOpts, type CrmRow, type CrmRule, type CrmRules, type CrmScalar, type CrmSlot, type CrmSort, type CrmTag, type CrmView, DEFAULT_LIMIT, EMAIL_STATUSES, type EmailStatus, type FieldDef, type FieldFilter, type FieldType, MAX_LIMIT, type PipelineDef, type PreparedWrite, RANK_EPSILON, RANK_STEP, type RelationDef, SORTABLE_COLUMNS, type SendEmailOpts, type SendEmailResult, type SerializedAttr, type SerializedEntity, type SerializedLink, type SerializedLinkEnd, type SerializedSchema, type StageDef, type StoredTemplate, type SubscriptionSnapshot, TASK_STATUSES, type TaskStatus, type TemplateSpec, type TypeDef, type TypeFacets, type TypeSummary, type ViewFilters, type ViewSpec, addActivity, addLink, addTag, applyConsent, applyConsentEvent, canEmail, canTransition, channelKey, compileList, createCrmRoutes, createRecord, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, getConfig, getRecord, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView };
1328
+ export { ACTIVITY_KINDS, type ActivityKind, type AttrType, type BillingEvent, type BillingProvider, CONFIG_KEY, CONSENT_STATES, CRM_NS, CRM_RULES, CRM_SCHEMA, CRM_SLOTS, type CompiledList, type ConfigPatch, type ConsentEvent, type ConsentOutcome, type ConsentState, type Crm, type CrmActivity, type CrmActor, type CrmAggregateResult, type CrmAggregateSpec, type CrmAttrs, CrmClient, type CrmClientOptions, type CrmConfig, type CrmConfigRow, type CrmContactChannel, type CrmDb, type CrmDeps, type CrmEmailLogRow, type CrmEmailSender, type CrmEntityRef, CrmInputError, type CrmIntegrationDescriptor, type CrmIntegrationOptions, type CrmIntegrationProbe, type CrmIntegrationSeed, type CrmLink, type CrmListParams, type CrmLookup, CrmNotFoundError, type CrmOp, type CrmQuery, type CrmRecord, type CrmResult, type CrmRouteOpts, type CrmRow, type CrmRule, type CrmRules, type CrmScalar, type CrmSlot, type CrmSort, type CrmTag, type CrmView, DEFAULT_LIMIT, EMAIL_STATUSES, type EmailStatus, type FieldDef, type FieldFilter, type FieldType, MAX_LIMIT, type PipelineDef, type PreparedWrite, RANK_EPSILON, RANK_STEP, type RelationDef, SORTABLE_COLUMNS, type SendEmailOpts, type SendEmailResult, type SerializedAttr, type SerializedEntity, type SerializedLink, type SerializedLinkEnd, type SerializedSchema, type StageDef, type StoredTemplate, type SubscriptionSnapshot, TASK_STATUSES, type TaskStatus, type TemplateSpec, type TypeDef, type TypeFacets, type TypeSummary, type ViewFilters, type ViewSpec, addActivity, addLink, addTag, applyConsent, applyConsentEvent, canEmail, canTransition, channelKey, compileList, createCrmIntegration, createCrmRoutes, createRecord, crmIntegration, crmRules, defaultTemplates, defineCrm, deleteView, emailChannelOps, foldEmailStatus, getConfig, getRecord, initialStage, linkIdentity, lintTemplate, listActivities, listChannels, listEmailLog, listLinks, listRecords, listTags, listTasks, listViews, mustGetRecord, needsRebalance, normalizeTag, prepare, rankBetween, rebalancePlan, rebalanceRanks, recordCanEmail, removeLink, removeTag, renderTemplate, resolveDeps, resolveSortColumn, rowToRecord, saveConfig, saveView, searchTextFor, sendTemplatedEmail, setArchived, setRank, setStage, stageIndexOf, templateVars, typeSummary, updateRecord, updateTask, updateView };
package/dist/index.js CHANGED
@@ -260,6 +260,25 @@ function canTransition(def, record, to) {
260
260
  return null;
261
261
  }
262
262
 
263
+ // src/template.ts
264
+ var TOKEN_RE = /\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}/g;
265
+ function renderTemplate(template, vars) {
266
+ return template.replace(TOKEN_RE, (_, name) => vars[name] ?? "");
267
+ }
268
+ function templateVars(template) {
269
+ const seen = /* @__PURE__ */ new Set();
270
+ for (const match of template.matchAll(TOKEN_RE)) seen.add(match[1]);
271
+ return [...seen];
272
+ }
273
+ function lintTemplate(template, knownVars) {
274
+ const used = templateVars(template);
275
+ const known = new Set(knownVars);
276
+ return {
277
+ unknown: used.filter((v) => !known.has(v)),
278
+ unused: knownVars.filter((v) => !used.includes(v))
279
+ };
280
+ }
281
+
263
282
  // src/validate.ts
264
283
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
265
284
  var STRINGISH = /* @__PURE__ */ new Set(["string", "email", "url", "enum"]);
@@ -434,6 +453,11 @@ function defineCrm(config) {
434
453
  if (tpl.class !== "transactional" && tpl.class !== "marketing")
435
454
  fail(at, `class must be transactional|marketing`);
436
455
  for (const v of tpl.vars) if (!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(v)) fail(at, `bad var "${v}"`);
456
+ if (tpl.defaults) {
457
+ const lint = lintTemplate(`${tpl.defaults.subject}
458
+ ${tpl.defaults.text}`, tpl.vars);
459
+ if (lint.unknown.length) fail(at, `defaults reference unknown vars: ${lint.unknown.join(", ")}`);
460
+ }
437
461
  }
438
462
  const type = (name) => {
439
463
  const def = config.types[name];
@@ -581,25 +605,6 @@ function canEmail(consent, cls) {
581
605
  return true;
582
606
  }
583
607
 
584
- // src/template.ts
585
- var TOKEN_RE = /\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}/g;
586
- function renderTemplate(template, vars) {
587
- return template.replace(TOKEN_RE, (_, name) => vars[name] ?? "");
588
- }
589
- function templateVars(template) {
590
- const seen = /* @__PURE__ */ new Set();
591
- for (const match of template.matchAll(TOKEN_RE)) seen.add(match[1]);
592
- return [...seen];
593
- }
594
- function lintTemplate(template, knownVars) {
595
- const used = templateVars(template);
596
- const known = new Set(knownVars);
597
- return {
598
- unknown: used.filter((v) => !known.has(v)),
599
- unused: knownVars.filter((v) => !used.includes(v))
600
- };
601
- }
602
-
603
608
  // src/channels.ts
604
609
  var channelKey = (recordId, kind, value) => `${recordId}:${kind}:${value}`;
605
610
  function foldEmailStatus(consent) {
@@ -1200,6 +1205,9 @@ async function saveConfig(deps, patch, opts = {}) {
1200
1205
  throw new CrmInputError(`template "${id}": text must be a string`);
1201
1206
  if (tpl.enabled !== void 0 && typeof tpl.enabled !== "boolean")
1202
1207
  throw new CrmInputError(`template "${id}": enabled must be a boolean`);
1208
+ const copy = [tpl.subject, tpl.text].filter((value) => typeof value === "string").join("\n");
1209
+ const unknown = lintTemplate(copy, declared[id].vars).unknown;
1210
+ if (unknown.length) throw new CrmInputError(`template "${id}": unknown vars ${unknown.join(", ")}`);
1203
1211
  }
1204
1212
  const existing = await getConfig(deps);
1205
1213
  const base = existing ?? {
@@ -2066,7 +2074,7 @@ var crmIntegration = {
2066
2074
  provision: {
2067
2075
  human: [
2068
2076
  "None for the core install \u2014 records/pipelines/email-consent need no external accounts.",
2069
- "When billing lands (@odla-ai/stripe): paste the printed webhook URL into the Stripe dashboard and vault the sk_/whsec_ secrets (Studio, write-only)."
2077
+ "If the app injects billing, configure that provider's webhook and vault secrets according to the app-owned adapter."
2070
2078
  ],
2071
2079
  cli: [
2072
2080
  "POST the merged CRM_SCHEMA to /app/:id/schema.",
@@ -2075,12 +2083,38 @@ var crmIntegration = {
2075
2083
  ],
2076
2084
  doctor: [
2077
2085
  "Every crm_* namespace has rules installed (deny-all: no rule = exposed to nothing, but assert explicitly).",
2078
- "The crm_config row exists and its emailTemplates parse against the code-declared registry.",
2079
- "lintTemplate reports no unknown {{vars}} in stored template copy.",
2086
+ "The guarded crm_config seed targets the declared-unique crm_config.key attribute.",
2087
+ "Code-declared template defaults have no unknown {{vars}}; owner-edited copies are checked when saved."
2088
+ ],
2089
+ smoke: [
2080
2090
  "A GET probe of <basePath>/records without credentials answers 401 (routes mounted, authorize enforced)."
2081
2091
  ]
2082
2092
  }
2083
2093
  };
2094
+ function createCrmIntegration(crm, options = {}) {
2095
+ const basePath = options.basePath ?? "/api/crm";
2096
+ if (!/^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]*$/.test(basePath) || basePath.endsWith("/")) {
2097
+ throw new Error("createCrmIntegration: basePath must be an absolute path without a trailing slash");
2098
+ }
2099
+ const attrs = {
2100
+ emailTemplates: defaultTemplates(crm),
2101
+ settings: options.settings ?? {},
2102
+ updatedAt: options.now ?? Date.now()
2103
+ };
2104
+ if (options.notificationEmail !== void 0) attrs.notificationEmail = options.notificationEmail;
2105
+ if (options.replyTo !== void 0) attrs.replyTo = options.replyTo;
2106
+ if (options.debugEmail !== void 0) attrs.debugEmail = options.debugEmail;
2107
+ return {
2108
+ ...crmIntegration,
2109
+ seeds: [{
2110
+ id: "config",
2111
+ ns: CRM_NS.config,
2112
+ key: { attr: "key", value: CONFIG_KEY },
2113
+ attrs
2114
+ }],
2115
+ probes: [{ path: `${basePath}/records`, expectedStatus: 401 }]
2116
+ };
2117
+ }
2084
2118
  export {
2085
2119
  ACTIVITY_KINDS,
2086
2120
  CONFIG_KEY,
@@ -2108,6 +2142,7 @@ export {
2108
2142
  canTransition,
2109
2143
  channelKey,
2110
2144
  compileList,
2145
+ createCrmIntegration,
2111
2146
  createCrmRoutes,
2112
2147
  createRecord,
2113
2148
  crmIntegration,