@odla-ai/crm 0.7.1 → 0.8.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/dist/ui/index.js CHANGED
@@ -76,6 +76,18 @@ function useCrmRecord(client, id) {
76
76
  }
77
77
 
78
78
  // src/constants.ts
79
+ var CRM_NS = {
80
+ record: "crm_record",
81
+ tag: "crm_tag",
82
+ link: "crm_link",
83
+ activity: "crm_activity",
84
+ channel: "crm_contact_channel",
85
+ emailLog: "crm_email_log",
86
+ view: "crm_view",
87
+ config: "crm_config",
88
+ origin: "crm_record_origin",
89
+ delivery: "crm_record_delivery"
90
+ };
79
91
  var CRM_SLOTS = ["s1", "s2", "s3", "s4", "n1", "n2", "n3", "d1", "d2"];
80
92
  var SORTABLE_COLUMNS = [
81
93
  "name",
@@ -116,7 +128,200 @@ var RESERVED_FIELDS = /* @__PURE__ */ new Set([
116
128
  ...CRM_SLOTS
117
129
  ]);
118
130
 
131
+ // src/schema.ts
132
+ var a = (type, o = {}) => ({
133
+ type,
134
+ unique: false,
135
+ indexed: false,
136
+ optional: false,
137
+ ...o
138
+ });
139
+ var uniq = (type) => a(type, { unique: true, indexed: true });
140
+ var idx = (type, optional = false) => a(type, { indexed: true, optional });
141
+ var opt = (type) => a(type, { optional: true });
142
+ var CRM_SCHEMA = {
143
+ entities: {
144
+ [CRM_NS.record]: {
145
+ attrs: {
146
+ // Entity ids are not attributes in odla-db, so `where: { id }` matches
147
+ // nothing unless the id is mirrored as a written attr — the getRecord /
148
+ // tag-filter / neighbor reads all filter by id. Mirror it as unique.
149
+ id: uniq("string"),
150
+ type: idx("string"),
151
+ name: idx("string"),
152
+ primaryEmail: idx("string", true),
153
+ stage: idx("string", true),
154
+ stageIndex: idx("number", true),
155
+ stageChangedAt: idx("date", true),
156
+ rank: idx("number", true),
157
+ score: idx("number", true),
158
+ ownerId: idx("string", true),
159
+ emailStatus: idx("string", true),
160
+ clerkUserId: a("string", { unique: true, indexed: true, optional: true }),
161
+ stripeCustomerId: idx("string", true),
162
+ subscriptionId: opt("string"),
163
+ billingStatus: idx("string", true),
164
+ renewalAt: idx("date", true),
165
+ mrr: opt("number"),
166
+ s1: idx("string", true),
167
+ s2: idx("string", true),
168
+ s3: idx("string", true),
169
+ s4: idx("string", true),
170
+ n1: idx("number", true),
171
+ n2: idx("number", true),
172
+ n3: idx("number", true),
173
+ d1: idx("date", true),
174
+ d2: idx("date", true),
175
+ fields: a("json"),
176
+ searchText: a("string"),
177
+ archived: idx("boolean"),
178
+ createdAt: idx("date"),
179
+ updatedAt: idx("date"),
180
+ archivedAt: opt("date")
181
+ }
182
+ },
183
+ [CRM_NS.tag]: {
184
+ attrs: {
185
+ key: uniq("string"),
186
+ // `${recordId}:${tag}`
187
+ recordId: idx("string"),
188
+ tag: idx("string"),
189
+ createdAt: idx("date")
190
+ }
191
+ },
192
+ [CRM_NS.link]: {
193
+ attrs: {
194
+ key: uniq("string"),
195
+ // `${fromId}:${relation}:${toId}`
196
+ fromId: idx("string"),
197
+ toId: idx("string"),
198
+ relation: idx("string"),
199
+ createdAt: idx("date")
200
+ }
201
+ },
202
+ [CRM_NS.activity]: {
203
+ attrs: {
204
+ id: uniq("string"),
205
+ // mirrored so updateTask can read one by id
206
+ recordId: idx("string"),
207
+ kind: idx("string"),
208
+ body: a("string"),
209
+ status: idx("string", true),
210
+ // tasks: open | waiting | done
211
+ dueAt: idx("date", true),
212
+ waitingOn: opt("string"),
213
+ assigneeId: idx("string", true),
214
+ authorId: idx("string"),
215
+ createdAt: idx("date"),
216
+ completedAt: opt("date"),
217
+ meta: opt("json")
218
+ }
219
+ },
220
+ [CRM_NS.channel]: {
221
+ attrs: {
222
+ key: uniq("string"),
223
+ // `${recordId}:${kind}:${value}`
224
+ recordId: idx("string"),
225
+ kind: a("string"),
226
+ // email | phone
227
+ value: idx("string"),
228
+ // emails lowercased
229
+ isPrimary: a("boolean"),
230
+ consent: idx("string"),
231
+ consentAt: idx("date"),
232
+ consentSource: opt("string"),
233
+ unsubscribeToken: uniq("string"),
234
+ createdAt: idx("date")
235
+ }
236
+ },
237
+ [CRM_NS.emailLog]: {
238
+ attrs: {
239
+ recordId: idx("string", true),
240
+ channelId: opt("string"),
241
+ to: a("string"),
242
+ templateId: idx("string"),
243
+ subject: a("string"),
244
+ transport: a("string"),
245
+ // sent | log-only
246
+ redirected: opt("boolean"),
247
+ dedupeKey: idx("string", true),
248
+ messageId: opt("string"),
249
+ error: opt("string"),
250
+ sentAt: idx("date")
251
+ }
252
+ },
253
+ [CRM_NS.view]: {
254
+ attrs: {
255
+ id: uniq("string"),
256
+ // mirrored so getView/updateView can read one by id
257
+ name: a("string"),
258
+ type: idx("string"),
259
+ ownerId: idx("string", true),
260
+ shared: idx("boolean"),
261
+ filters: a("json"),
262
+ sort: a("json"),
263
+ columns: a("json"),
264
+ createdAt: idx("date"),
265
+ updatedAt: idx("date")
266
+ }
267
+ },
268
+ [CRM_NS.config]: {
269
+ attrs: {
270
+ key: uniq("string"),
271
+ // CONFIG_KEY singleton
272
+ notificationEmail: opt("string"),
273
+ replyTo: opt("string"),
274
+ debugEmail: opt("string"),
275
+ emailTemplates: a("json"),
276
+ // Record<templateId, {subject, text, enabled}>
277
+ settings: a("json"),
278
+ updatedAt: idx("date")
279
+ }
280
+ },
281
+ [CRM_NS.origin]: {
282
+ attrs: {
283
+ // One upstream record maps to one local record. The structured source
284
+ // survives tag edits and supports more than one upstream site.
285
+ key: uniq("string"),
286
+ // `${sourceId}:${sourceRecordId}`
287
+ recordId: idx("string"),
288
+ sourceId: idx("string"),
289
+ sourceRecordId: idx("string"),
290
+ sourceUrl: opt("string"),
291
+ payloadVersion: idx("number"),
292
+ firstReceivedAt: idx("date"),
293
+ lastReceivedAt: idx("date")
294
+ }
295
+ },
296
+ [CRM_NS.delivery]: {
297
+ attrs: {
298
+ // The latest delivery state for one local record → target edge.
299
+ key: uniq("string"),
300
+ // `${recordId}:${targetId}`
301
+ recordId: idx("string"),
302
+ targetId: idx("string"),
303
+ remoteRecordId: idx("string", true),
304
+ status: idx("string"),
305
+ attempts: idx("number"),
306
+ payloadVersion: idx("number"),
307
+ lastAttemptAt: idx("date"),
308
+ deliveredAt: idx("date", true),
309
+ error: opt("string")
310
+ }
311
+ }
312
+ },
313
+ links: {}
314
+ };
315
+
119
316
  // src/time.ts
317
+ var DATE_FIELDS = new Map(
318
+ Object.entries(CRM_SCHEMA.entities).map(([ns, entity]) => [
319
+ ns,
320
+ new Set(
321
+ Object.entries(entity.attrs).filter(([, attr]) => attr.type === "date").map(([label]) => label)
322
+ )
323
+ ])
324
+ );
120
325
  function epochOf(value) {
121
326
  if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
122
327
  if (typeof value !== "string") return void 0;