@voyantjs/crm 0.6.7 → 0.6.8
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/schema-accounts.d.ts +145 -0
- package/dist/schema-accounts.d.ts.map +1 -1
- package/dist/schema-accounts.js +32 -4
- package/dist/schema-activities.d.ts.map +1 -1
- package/dist/schema-activities.js +9 -0
- package/dist/schema-sales.d.ts.map +1 -1
- package/dist/schema-sales.js +15 -0
- package/dist/service/accounts-shared.d.ts +2 -0
- package/dist/service/accounts-shared.d.ts.map +1 -1
- package/dist/service/accounts-shared.js +120 -40
- package/package.json +5 -5
|
@@ -628,6 +628,149 @@ export declare const people: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
628
628
|
};
|
|
629
629
|
dialect: "pg";
|
|
630
630
|
}>;
|
|
631
|
+
export declare const personDirectoryProjections: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
632
|
+
name: "person_directory_projections";
|
|
633
|
+
schema: undefined;
|
|
634
|
+
columns: {
|
|
635
|
+
personId: import("drizzle-orm/pg-core").PgColumn<{
|
|
636
|
+
name: string;
|
|
637
|
+
tableName: "person_directory_projections";
|
|
638
|
+
dataType: "string";
|
|
639
|
+
columnType: "PgText";
|
|
640
|
+
data: string;
|
|
641
|
+
driverParam: string;
|
|
642
|
+
notNull: true;
|
|
643
|
+
hasDefault: false;
|
|
644
|
+
isPrimaryKey: false;
|
|
645
|
+
isAutoincrement: false;
|
|
646
|
+
hasRuntimeDefault: false;
|
|
647
|
+
enumValues: [string, ...string[]];
|
|
648
|
+
baseColumn: never;
|
|
649
|
+
identity: undefined;
|
|
650
|
+
generated: undefined;
|
|
651
|
+
}, {}, {}>;
|
|
652
|
+
email: import("drizzle-orm/pg-core").PgColumn<{
|
|
653
|
+
name: "email";
|
|
654
|
+
tableName: "person_directory_projections";
|
|
655
|
+
dataType: "string";
|
|
656
|
+
columnType: "PgText";
|
|
657
|
+
data: string;
|
|
658
|
+
driverParam: string;
|
|
659
|
+
notNull: false;
|
|
660
|
+
hasDefault: false;
|
|
661
|
+
isPrimaryKey: false;
|
|
662
|
+
isAutoincrement: false;
|
|
663
|
+
hasRuntimeDefault: false;
|
|
664
|
+
enumValues: [string, ...string[]];
|
|
665
|
+
baseColumn: never;
|
|
666
|
+
identity: undefined;
|
|
667
|
+
generated: undefined;
|
|
668
|
+
}, {}, {}>;
|
|
669
|
+
phone: import("drizzle-orm/pg-core").PgColumn<{
|
|
670
|
+
name: "phone";
|
|
671
|
+
tableName: "person_directory_projections";
|
|
672
|
+
dataType: "string";
|
|
673
|
+
columnType: "PgText";
|
|
674
|
+
data: string;
|
|
675
|
+
driverParam: string;
|
|
676
|
+
notNull: false;
|
|
677
|
+
hasDefault: false;
|
|
678
|
+
isPrimaryKey: false;
|
|
679
|
+
isAutoincrement: false;
|
|
680
|
+
hasRuntimeDefault: false;
|
|
681
|
+
enumValues: [string, ...string[]];
|
|
682
|
+
baseColumn: never;
|
|
683
|
+
identity: undefined;
|
|
684
|
+
generated: undefined;
|
|
685
|
+
}, {}, {}>;
|
|
686
|
+
website: import("drizzle-orm/pg-core").PgColumn<{
|
|
687
|
+
name: "website";
|
|
688
|
+
tableName: "person_directory_projections";
|
|
689
|
+
dataType: "string";
|
|
690
|
+
columnType: "PgText";
|
|
691
|
+
data: string;
|
|
692
|
+
driverParam: string;
|
|
693
|
+
notNull: false;
|
|
694
|
+
hasDefault: false;
|
|
695
|
+
isPrimaryKey: false;
|
|
696
|
+
isAutoincrement: false;
|
|
697
|
+
hasRuntimeDefault: false;
|
|
698
|
+
enumValues: [string, ...string[]];
|
|
699
|
+
baseColumn: never;
|
|
700
|
+
identity: undefined;
|
|
701
|
+
generated: undefined;
|
|
702
|
+
}, {}, {}>;
|
|
703
|
+
address: import("drizzle-orm/pg-core").PgColumn<{
|
|
704
|
+
name: "address";
|
|
705
|
+
tableName: "person_directory_projections";
|
|
706
|
+
dataType: "string";
|
|
707
|
+
columnType: "PgText";
|
|
708
|
+
data: string;
|
|
709
|
+
driverParam: string;
|
|
710
|
+
notNull: false;
|
|
711
|
+
hasDefault: false;
|
|
712
|
+
isPrimaryKey: false;
|
|
713
|
+
isAutoincrement: false;
|
|
714
|
+
hasRuntimeDefault: false;
|
|
715
|
+
enumValues: [string, ...string[]];
|
|
716
|
+
baseColumn: never;
|
|
717
|
+
identity: undefined;
|
|
718
|
+
generated: undefined;
|
|
719
|
+
}, {}, {}>;
|
|
720
|
+
city: import("drizzle-orm/pg-core").PgColumn<{
|
|
721
|
+
name: "city";
|
|
722
|
+
tableName: "person_directory_projections";
|
|
723
|
+
dataType: "string";
|
|
724
|
+
columnType: "PgText";
|
|
725
|
+
data: string;
|
|
726
|
+
driverParam: string;
|
|
727
|
+
notNull: false;
|
|
728
|
+
hasDefault: false;
|
|
729
|
+
isPrimaryKey: false;
|
|
730
|
+
isAutoincrement: false;
|
|
731
|
+
hasRuntimeDefault: false;
|
|
732
|
+
enumValues: [string, ...string[]];
|
|
733
|
+
baseColumn: never;
|
|
734
|
+
identity: undefined;
|
|
735
|
+
generated: undefined;
|
|
736
|
+
}, {}, {}>;
|
|
737
|
+
country: import("drizzle-orm/pg-core").PgColumn<{
|
|
738
|
+
name: "country";
|
|
739
|
+
tableName: "person_directory_projections";
|
|
740
|
+
dataType: "string";
|
|
741
|
+
columnType: "PgText";
|
|
742
|
+
data: string;
|
|
743
|
+
driverParam: string;
|
|
744
|
+
notNull: false;
|
|
745
|
+
hasDefault: false;
|
|
746
|
+
isPrimaryKey: false;
|
|
747
|
+
isAutoincrement: false;
|
|
748
|
+
hasRuntimeDefault: false;
|
|
749
|
+
enumValues: [string, ...string[]];
|
|
750
|
+
baseColumn: never;
|
|
751
|
+
identity: undefined;
|
|
752
|
+
generated: undefined;
|
|
753
|
+
}, {}, {}>;
|
|
754
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
755
|
+
name: "updated_at";
|
|
756
|
+
tableName: "person_directory_projections";
|
|
757
|
+
dataType: "date";
|
|
758
|
+
columnType: "PgTimestamp";
|
|
759
|
+
data: Date;
|
|
760
|
+
driverParam: string;
|
|
761
|
+
notNull: true;
|
|
762
|
+
hasDefault: true;
|
|
763
|
+
isPrimaryKey: false;
|
|
764
|
+
isAutoincrement: false;
|
|
765
|
+
hasRuntimeDefault: false;
|
|
766
|
+
enumValues: undefined;
|
|
767
|
+
baseColumn: never;
|
|
768
|
+
identity: undefined;
|
|
769
|
+
generated: undefined;
|
|
770
|
+
}, {}, {}>;
|
|
771
|
+
};
|
|
772
|
+
dialect: "pg";
|
|
773
|
+
}>;
|
|
631
774
|
export declare const personNotes: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
632
775
|
name: "person_notes";
|
|
633
776
|
schema: undefined;
|
|
@@ -1172,4 +1315,6 @@ export type Organization = typeof organizations.$inferSelect;
|
|
|
1172
1315
|
export type NewOrganization = typeof organizations.$inferInsert;
|
|
1173
1316
|
export type Person = typeof people.$inferSelect;
|
|
1174
1317
|
export type NewPerson = typeof people.$inferInsert;
|
|
1318
|
+
export type PersonDirectoryProjection = typeof personDirectoryProjections.$inferSelect;
|
|
1319
|
+
export type NewPersonDirectoryProjection = typeof personDirectoryProjections.$inferInsert;
|
|
1175
1320
|
//# sourceMappingURL=schema-accounts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-accounts.d.ts","sourceRoot":"","sources":["../src/schema-accounts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-accounts.d.ts","sourceRoot":"","sources":["../src/schema-accounts.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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MAAM,CAAC,YAAY,CAAA;AAClD,MAAM,MAAM,yBAAyB,GAAG,OAAO,0BAA0B,CAAC,YAAY,CAAA;AACtF,MAAM,MAAM,4BAA4B,GAAG,OAAO,0BAA0B,CAAC,YAAY,CAAA"}
|
package/dist/schema-accounts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
|
|
2
|
-
import { date, index, integer, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
+
import { date, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
3
3
|
import { communicationChannelEnum, communicationDirectionEnum, recordStatusEnum, relationTypeEnum, } from "./schema-shared";
|
|
4
4
|
export const organizations = pgTable("organizations", {
|
|
5
5
|
id: typeId("organizations"),
|
|
@@ -24,6 +24,9 @@ export const organizations = pgTable("organizations", {
|
|
|
24
24
|
index("idx_organizations_name").on(table.name),
|
|
25
25
|
index("idx_organizations_owner").on(table.ownerId),
|
|
26
26
|
index("idx_organizations_status").on(table.status),
|
|
27
|
+
index("idx_organizations_owner_updated").on(table.ownerId, table.updatedAt),
|
|
28
|
+
index("idx_organizations_relation_updated").on(table.relation, table.updatedAt),
|
|
29
|
+
index("idx_organizations_status_updated").on(table.status, table.updatedAt),
|
|
27
30
|
]);
|
|
28
31
|
export const people = pgTable("people", {
|
|
29
32
|
id: typeId("people"),
|
|
@@ -51,7 +54,23 @@ export const people = pgTable("people", {
|
|
|
51
54
|
index("idx_people_owner").on(table.ownerId),
|
|
52
55
|
index("idx_people_status").on(table.status),
|
|
53
56
|
index("idx_people_name").on(table.firstName, table.lastName),
|
|
57
|
+
index("idx_people_org_updated").on(table.organizationId, table.updatedAt),
|
|
58
|
+
index("idx_people_owner_updated").on(table.ownerId, table.updatedAt),
|
|
59
|
+
index("idx_people_relation_updated").on(table.relation, table.updatedAt),
|
|
60
|
+
index("idx_people_status_updated").on(table.status, table.updatedAt),
|
|
54
61
|
]);
|
|
62
|
+
export const personDirectoryProjections = pgTable("person_directory_projections", {
|
|
63
|
+
personId: typeIdRef("person_id")
|
|
64
|
+
.notNull()
|
|
65
|
+
.references(() => people.id, { onDelete: "cascade" }),
|
|
66
|
+
email: text("email"),
|
|
67
|
+
phone: text("phone"),
|
|
68
|
+
website: text("website"),
|
|
69
|
+
address: text("address"),
|
|
70
|
+
city: text("city"),
|
|
71
|
+
country: text("country"),
|
|
72
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
73
|
+
}, (table) => [uniqueIndex("uq_person_directory_projections_person").on(table.personId)]);
|
|
55
74
|
export const personNotes = pgTable("person_notes", {
|
|
56
75
|
id: typeId("person_notes"),
|
|
57
76
|
personId: typeIdRef("person_id")
|
|
@@ -60,7 +79,10 @@ export const personNotes = pgTable("person_notes", {
|
|
|
60
79
|
authorId: text("author_id").notNull(),
|
|
61
80
|
content: text("content").notNull(),
|
|
62
81
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
63
|
-
}, (table) => [
|
|
82
|
+
}, (table) => [
|
|
83
|
+
index("idx_person_notes_person").on(table.personId),
|
|
84
|
+
index("idx_person_notes_person_created").on(table.personId, table.createdAt),
|
|
85
|
+
]);
|
|
64
86
|
export const organizationNotes = pgTable("organization_notes", {
|
|
65
87
|
id: typeId("organization_notes"),
|
|
66
88
|
organizationId: typeIdRef("organization_id")
|
|
@@ -69,7 +91,10 @@ export const organizationNotes = pgTable("organization_notes", {
|
|
|
69
91
|
authorId: text("author_id").notNull(),
|
|
70
92
|
content: text("content").notNull(),
|
|
71
93
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
72
|
-
}, (table) => [
|
|
94
|
+
}, (table) => [
|
|
95
|
+
index("idx_organization_notes_org").on(table.organizationId),
|
|
96
|
+
index("idx_organization_notes_org_created").on(table.organizationId, table.createdAt),
|
|
97
|
+
]);
|
|
73
98
|
export const communicationLog = pgTable("communication_log", {
|
|
74
99
|
id: typeId("communication_log"),
|
|
75
100
|
personId: typeIdRef("person_id")
|
|
@@ -86,6 +111,9 @@ export const communicationLog = pgTable("communication_log", {
|
|
|
86
111
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
87
112
|
}, (table) => [
|
|
88
113
|
index("idx_communication_log_person").on(table.personId),
|
|
114
|
+
index("idx_communication_log_person_created").on(table.personId, table.createdAt),
|
|
115
|
+
index("idx_communication_log_person_channel_created").on(table.personId, table.channel, table.createdAt),
|
|
116
|
+
index("idx_communication_log_person_direction_created").on(table.personId, table.direction, table.createdAt),
|
|
89
117
|
index("idx_communication_log_org").on(table.organizationId),
|
|
90
118
|
index("idx_communication_log_channel").on(table.channel),
|
|
91
119
|
]);
|
|
@@ -96,7 +124,7 @@ export const segments = pgTable("segments", {
|
|
|
96
124
|
conditions: jsonb("conditions").$type(),
|
|
97
125
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
98
126
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
99
|
-
});
|
|
127
|
+
}, (table) => [index("idx_segments_created").on(table.createdAt)]);
|
|
100
128
|
export const segmentMembers = pgTable("segment_members", {
|
|
101
129
|
id: typeId("segment_members"),
|
|
102
130
|
segmentId: typeIdRef("segment_id")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-activities.d.ts","sourceRoot":"","sources":["../src/schema-activities.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema-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;;;;;;;;;;;EAkC7B,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,UAAU,CAAC,YAAY,CAAA;AACrD,MAAM,MAAM,WAAW,GAAG,OAAO,UAAU,CAAC,YAAY,CAAA;AACxD,MAAM,MAAM,YAAY,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC5D,MAAM,MAAM,eAAe,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC/D,MAAM,MAAM,mBAAmB,GAAG,OAAO,oBAAoB,CAAC,YAAY,CAAA;AAC1E,MAAM,MAAM,sBAAsB,GAAG,OAAO,oBAAoB,CAAC,YAAY,CAAA;AAC7E,MAAM,MAAM,qBAAqB,GAAG,OAAO,sBAAsB,CAAC,YAAY,CAAA;AAC9E,MAAM,MAAM,wBAAwB,GAAG,OAAO,sBAAsB,CAAC,YAAY,CAAA;AACjF,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAA;AACpE,MAAM,MAAM,mBAAmB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAA"}
|
|
@@ -18,6 +18,9 @@ export const activities = pgTable("activities", {
|
|
|
18
18
|
index("idx_activities_owner").on(table.ownerId),
|
|
19
19
|
index("idx_activities_status").on(table.status),
|
|
20
20
|
index("idx_activities_type").on(table.type),
|
|
21
|
+
index("idx_activities_owner_updated").on(table.ownerId, table.updatedAt),
|
|
22
|
+
index("idx_activities_status_updated").on(table.status, table.updatedAt),
|
|
23
|
+
index("idx_activities_type_updated").on(table.type, table.updatedAt),
|
|
21
24
|
]);
|
|
22
25
|
export const activityLinks = pgTable("activity_links", {
|
|
23
26
|
id: typeId("activity_links"),
|
|
@@ -30,6 +33,7 @@ export const activityLinks = pgTable("activity_links", {
|
|
|
30
33
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
31
34
|
}, (table) => [
|
|
32
35
|
index("idx_activity_links_activity").on(table.activityId),
|
|
36
|
+
index("idx_activity_links_activity_role").on(table.activityId, table.role, table.createdAt),
|
|
33
37
|
index("idx_activity_links_entity").on(table.entityType, table.entityId),
|
|
34
38
|
]);
|
|
35
39
|
export const activityParticipants = pgTable("activity_participants", {
|
|
@@ -44,6 +48,7 @@ export const activityParticipants = pgTable("activity_participants", {
|
|
|
44
48
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
45
49
|
}, (table) => [
|
|
46
50
|
index("idx_activity_participants_activity").on(table.activityId),
|
|
51
|
+
index("idx_activity_participants_activity_primary").on(table.activityId, table.isPrimary, table.createdAt),
|
|
47
52
|
uniqueIndex("uidx_activity_participants_unique").on(table.activityId, table.personId),
|
|
48
53
|
]);
|
|
49
54
|
export const customFieldDefinitions = pgTable("custom_field_definitions", {
|
|
@@ -59,6 +64,7 @@ export const customFieldDefinitions = pgTable("custom_field_definitions", {
|
|
|
59
64
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
60
65
|
}, (table) => [
|
|
61
66
|
index("idx_custom_field_definitions_entity").on(table.entityType),
|
|
67
|
+
index("idx_custom_field_definitions_entity_label").on(table.entityType, table.label),
|
|
62
68
|
uniqueIndex("uidx_custom_field_definitions_key").on(table.entityType, table.key),
|
|
63
69
|
]);
|
|
64
70
|
export const customFieldValues = pgTable("custom_field_values", {
|
|
@@ -79,5 +85,8 @@ export const customFieldValues = pgTable("custom_field_values", {
|
|
|
79
85
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
80
86
|
}, (table) => [
|
|
81
87
|
index("idx_custom_field_values_entity").on(table.entityType, table.entityId),
|
|
88
|
+
index("idx_custom_field_values_entity_type_updated").on(table.entityType, table.updatedAt),
|
|
89
|
+
index("idx_custom_field_values_entity_updated").on(table.entityType, table.entityId, table.updatedAt),
|
|
90
|
+
index("idx_custom_field_values_definition_updated").on(table.definitionId, table.updatedAt),
|
|
82
91
|
uniqueIndex("uidx_custom_field_values_unique").on(table.definitionId, table.entityType, table.entityId),
|
|
83
92
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-sales.d.ts","sourceRoot":"","sources":["../src/schema-sales.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"schema-sales.d.ts","sourceRoot":"","sources":["../src/schema-sales.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBrB,CAAA;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBlB,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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A;AAC9C,MAAM,MAAM,QAAQ,GAAG,OAAO,MAAM,CAAC,YAAY,CAAA;AACjD,MAAM,MAAM,WAAW,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC3D,MAAM,MAAM,cAAc,GAAG,OAAO,aAAa,CAAC,YAAY,CAAA;AAC9D,MAAM,MAAM,sBAAsB,GAAG,OAAO,uBAAuB,CAAC,YAAY,CAAA;AAChF,MAAM,MAAM,yBAAyB,GAAG,OAAO,uBAAuB,CAAC,YAAY,CAAA;AACnF,MAAM,MAAM,kBAAkB,GAAG,OAAO,mBAAmB,CAAC,YAAY,CAAA;AACxE,MAAM,MAAM,qBAAqB,GAAG,OAAO,mBAAmB,CAAC,YAAY,CAAA;AAC3E,MAAM,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,YAAY,CAAA;AAC9C,MAAM,MAAM,QAAQ,GAAG,OAAO,MAAM,CAAC,YAAY,CAAA;AACjD,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,YAAY,CAAA;AACtD,MAAM,MAAM,YAAY,GAAG,OAAO,UAAU,CAAC,YAAY,CAAA"}
|
package/dist/schema-sales.js
CHANGED
|
@@ -12,6 +12,8 @@ export const pipelines = pgTable("pipelines", {
|
|
|
12
12
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13
13
|
}, (table) => [
|
|
14
14
|
index("idx_pipelines_entity").on(table.entityType),
|
|
15
|
+
index("idx_pipelines_sort").on(table.sortOrder, table.createdAt),
|
|
16
|
+
index("idx_pipelines_entity_sort").on(table.entityType, table.sortOrder, table.createdAt),
|
|
15
17
|
uniqueIndex("uidx_pipelines_entity_name").on(table.entityType, table.name),
|
|
16
18
|
]);
|
|
17
19
|
export const stages = pgTable("stages", {
|
|
@@ -29,6 +31,8 @@ export const stages = pgTable("stages", {
|
|
|
29
31
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
30
32
|
}, (table) => [
|
|
31
33
|
index("idx_stages_pipeline").on(table.pipelineId),
|
|
34
|
+
index("idx_stages_sort").on(table.sortOrder, table.createdAt),
|
|
35
|
+
index("idx_stages_pipeline_sort").on(table.pipelineId, table.sortOrder, table.createdAt),
|
|
32
36
|
uniqueIndex("uidx_stages_pipeline_name").on(table.pipelineId, table.name),
|
|
33
37
|
]);
|
|
34
38
|
export const opportunities = pgTable("opportunities", {
|
|
@@ -64,6 +68,12 @@ export const opportunities = pgTable("opportunities", {
|
|
|
64
68
|
index("idx_opportunities_stage").on(table.stageId),
|
|
65
69
|
index("idx_opportunities_owner").on(table.ownerId),
|
|
66
70
|
index("idx_opportunities_status").on(table.status),
|
|
71
|
+
index("idx_opportunities_person_updated").on(table.personId, table.updatedAt),
|
|
72
|
+
index("idx_opportunities_org_updated").on(table.organizationId, table.updatedAt),
|
|
73
|
+
index("idx_opportunities_pipeline_updated").on(table.pipelineId, table.updatedAt),
|
|
74
|
+
index("idx_opportunities_stage_updated").on(table.stageId, table.updatedAt),
|
|
75
|
+
index("idx_opportunities_owner_updated").on(table.ownerId, table.updatedAt),
|
|
76
|
+
index("idx_opportunities_status_updated").on(table.status, table.updatedAt),
|
|
67
77
|
]);
|
|
68
78
|
export const opportunityParticipants = pgTable("opportunity_participants", {
|
|
69
79
|
id: typeId("opportunity_participants"),
|
|
@@ -78,6 +88,7 @@ export const opportunityParticipants = pgTable("opportunity_participants", {
|
|
|
78
88
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
79
89
|
}, (table) => [
|
|
80
90
|
index("idx_opportunity_participants_opportunity").on(table.opportunityId),
|
|
91
|
+
index("idx_opportunity_participants_opportunity_primary").on(table.opportunityId, table.isPrimary, table.createdAt),
|
|
81
92
|
index("idx_opportunity_participants_person").on(table.personId),
|
|
82
93
|
uniqueIndex("uidx_opportunity_participants_unique").on(table.opportunityId, table.personId),
|
|
83
94
|
]);
|
|
@@ -99,6 +110,7 @@ export const opportunityProducts = pgTable("opportunity_products", {
|
|
|
99
110
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
100
111
|
}, (table) => [
|
|
101
112
|
index("idx_opportunity_products_opportunity").on(table.opportunityId),
|
|
113
|
+
index("idx_opportunity_products_opportunity_created").on(table.opportunityId, table.createdAt),
|
|
102
114
|
index("idx_opportunity_products_product").on(table.productId),
|
|
103
115
|
index("idx_opportunity_products_supplier_service").on(table.supplierServiceId),
|
|
104
116
|
]);
|
|
@@ -120,6 +132,8 @@ export const quotes = pgTable("quotes", {
|
|
|
120
132
|
}, (table) => [
|
|
121
133
|
index("idx_quotes_opportunity").on(table.opportunityId),
|
|
122
134
|
index("idx_quotes_status").on(table.status),
|
|
135
|
+
index("idx_quotes_opportunity_updated").on(table.opportunityId, table.updatedAt),
|
|
136
|
+
index("idx_quotes_status_updated").on(table.status, table.updatedAt),
|
|
123
137
|
]);
|
|
124
138
|
export const quoteLines = pgTable("quote_lines", {
|
|
125
139
|
id: typeId("quote_lines"),
|
|
@@ -137,6 +151,7 @@ export const quoteLines = pgTable("quote_lines", {
|
|
|
137
151
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
138
152
|
}, (table) => [
|
|
139
153
|
index("idx_quote_lines_quote").on(table.quoteId),
|
|
154
|
+
index("idx_quote_lines_quote_created").on(table.quoteId, table.createdAt),
|
|
140
155
|
index("idx_quote_lines_product").on(table.productId),
|
|
141
156
|
index("idx_quote_lines_supplier_service").on(table.supplierServiceId),
|
|
142
157
|
]);
|
|
@@ -45,6 +45,8 @@ export declare function personBaseFields(data: CreatePersonInput | UpdatePersonI
|
|
|
45
45
|
birthday: string | null | undefined;
|
|
46
46
|
notes: string | null | undefined;
|
|
47
47
|
};
|
|
48
|
+
export declare function rebuildPersonDirectoryProjection(db: PostgresJsDatabase, personId: string): Promise<void>;
|
|
49
|
+
export declare function rebuildPersonDirectoryProjections(db: PostgresJsDatabase, personIds: string[]): Promise<void>;
|
|
48
50
|
export declare function syncPersonIdentity(db: PostgresJsDatabase, personId: string, data: PersonIdentityInput): Promise<void>;
|
|
49
51
|
export declare function deletePersonIdentity(db: PostgresJsDatabase, personId: string): Promise<void>;
|
|
50
52
|
export declare function hydratePeople<T extends {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accounts-shared.d.ts","sourceRoot":"","sources":["../../src/service/accounts-shared.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAQzB,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA;AAC/E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAC9E,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAC9E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA;AACnE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAClE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAClE,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO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,EAAE,QAAQ,EAAE,MAAM,iBAE9F;AAED,wBAAsB,iCAAiC,CACrD,EAAE,EAAE,kBAAkB,EACtB,SAAS,EAAE,MAAM,EAAE,iBAYpB;AAsDD,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,kBAAkB,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,mBAAmB,iBAuF1B;AAED,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,iBAUlF;AAED,wBAAsB,aAAa,CAAC,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAC1D,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,CAAC,EAAE,GACR,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAiB1C"}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { identityAddresses, identityContactPoints } from "@voyantjs/identity/schema";
|
|
2
2
|
import { identityService } from "@voyantjs/identity/service";
|
|
3
3
|
import { and, eq, inArray } from "drizzle-orm";
|
|
4
|
+
import { personDirectoryProjections } from "../schema.js";
|
|
4
5
|
import { formatAddress, isManagedBySource, normalizeContactValue, toNullableTrimmed, } from "./helpers.js";
|
|
5
6
|
export const organizationEntityType = "organization";
|
|
6
7
|
export const personEntityType = "person";
|
|
7
8
|
export const personBaseIdentitySource = "crm.person.base";
|
|
9
|
+
function emptyPersonHydratedFields() {
|
|
10
|
+
return {
|
|
11
|
+
email: null,
|
|
12
|
+
phone: null,
|
|
13
|
+
website: null,
|
|
14
|
+
address: null,
|
|
15
|
+
city: null,
|
|
16
|
+
country: null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
8
19
|
export function personBaseFields(data) {
|
|
9
20
|
return {
|
|
10
21
|
organizationId: data.organizationId,
|
|
@@ -23,6 +34,110 @@ export function personBaseFields(data) {
|
|
|
23
34
|
notes: data.notes,
|
|
24
35
|
};
|
|
25
36
|
}
|
|
37
|
+
async function buildPersonDirectoryProjectionRows(db, personIds) {
|
|
38
|
+
if (personIds.length === 0) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
const ids = [...new Set(personIds)];
|
|
42
|
+
const [contactPoints, addresses] = await Promise.all([
|
|
43
|
+
db
|
|
44
|
+
.select()
|
|
45
|
+
.from(identityContactPoints)
|
|
46
|
+
.where(and(eq(identityContactPoints.entityType, personEntityType), inArray(identityContactPoints.entityId, ids))),
|
|
47
|
+
db
|
|
48
|
+
.select()
|
|
49
|
+
.from(identityAddresses)
|
|
50
|
+
.where(and(eq(identityAddresses.entityType, personEntityType), inArray(identityAddresses.entityId, ids))),
|
|
51
|
+
]);
|
|
52
|
+
const contactPointMap = new Map();
|
|
53
|
+
const addressMap = new Map();
|
|
54
|
+
for (const point of contactPoints) {
|
|
55
|
+
const bucket = contactPointMap.get(point.entityId) ?? [];
|
|
56
|
+
bucket.push(point);
|
|
57
|
+
contactPointMap.set(point.entityId, bucket);
|
|
58
|
+
}
|
|
59
|
+
for (const address of addresses) {
|
|
60
|
+
const bucket = addressMap.get(address.entityId) ?? [];
|
|
61
|
+
bucket.push(address);
|
|
62
|
+
addressMap.set(address.entityId, bucket);
|
|
63
|
+
}
|
|
64
|
+
return ids.map((personId) => {
|
|
65
|
+
const entityContactPoints = contactPointMap.get(personId) ?? [];
|
|
66
|
+
const entityAddresses = addressMap.get(personId) ?? [];
|
|
67
|
+
const findPrimaryContactPoint = (kind) => entityContactPoints.find((point) => point.kind === kind && point.isPrimary)?.value ??
|
|
68
|
+
entityContactPoints.find((point) => point.kind === kind)?.value ??
|
|
69
|
+
null;
|
|
70
|
+
const primaryAddress = entityAddresses.find((address) => address.isPrimary) ?? entityAddresses[0] ?? null;
|
|
71
|
+
return {
|
|
72
|
+
personId,
|
|
73
|
+
email: findPrimaryContactPoint("email"),
|
|
74
|
+
phone: findPrimaryContactPoint("phone"),
|
|
75
|
+
website: findPrimaryContactPoint("website"),
|
|
76
|
+
address: primaryAddress ? formatAddress(primaryAddress) : null,
|
|
77
|
+
city: primaryAddress?.city ?? null,
|
|
78
|
+
country: primaryAddress?.country ?? null,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export async function rebuildPersonDirectoryProjection(db, personId) {
|
|
83
|
+
return rebuildPersonDirectoryProjections(db, [personId]);
|
|
84
|
+
}
|
|
85
|
+
export async function rebuildPersonDirectoryProjections(db, personIds) {
|
|
86
|
+
const ids = [...new Set(personIds)];
|
|
87
|
+
if (ids.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const rows = await buildPersonDirectoryProjectionRows(db, ids);
|
|
91
|
+
await db
|
|
92
|
+
.delete(personDirectoryProjections)
|
|
93
|
+
.where(inArray(personDirectoryProjections.personId, ids));
|
|
94
|
+
await db.insert(personDirectoryProjections).values(rows);
|
|
95
|
+
}
|
|
96
|
+
async function ensurePersonDirectoryProjectionMap(db, personIds) {
|
|
97
|
+
const ids = [...new Set(personIds)];
|
|
98
|
+
if (ids.length === 0) {
|
|
99
|
+
return new Map();
|
|
100
|
+
}
|
|
101
|
+
const existing = await db
|
|
102
|
+
.select()
|
|
103
|
+
.from(personDirectoryProjections)
|
|
104
|
+
.where(inArray(personDirectoryProjections.personId, ids));
|
|
105
|
+
const map = new Map();
|
|
106
|
+
for (const projection of existing) {
|
|
107
|
+
map.set(projection.personId, {
|
|
108
|
+
email: projection.email,
|
|
109
|
+
phone: projection.phone,
|
|
110
|
+
website: projection.website,
|
|
111
|
+
address: projection.address,
|
|
112
|
+
city: projection.city,
|
|
113
|
+
country: projection.country,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const missingIds = ids.filter((id) => !map.has(id));
|
|
117
|
+
if (missingIds.length > 0) {
|
|
118
|
+
await rebuildPersonDirectoryProjections(db, missingIds);
|
|
119
|
+
const rebuilt = await db
|
|
120
|
+
.select()
|
|
121
|
+
.from(personDirectoryProjections)
|
|
122
|
+
.where(inArray(personDirectoryProjections.personId, missingIds));
|
|
123
|
+
for (const projection of rebuilt) {
|
|
124
|
+
map.set(projection.personId, {
|
|
125
|
+
email: projection.email,
|
|
126
|
+
phone: projection.phone,
|
|
127
|
+
website: projection.website,
|
|
128
|
+
address: projection.address,
|
|
129
|
+
city: projection.city,
|
|
130
|
+
country: projection.country,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const id of ids) {
|
|
135
|
+
if (!map.has(id)) {
|
|
136
|
+
map.set(id, emptyPersonHydratedFields());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return map;
|
|
140
|
+
}
|
|
26
141
|
export async function syncPersonIdentity(db, personId, data) {
|
|
27
142
|
const existingContactPoints = await identityService.listContactPointsForEntity(db, personEntityType, personId);
|
|
28
143
|
const existingAddresses = await identityService.listAddressesForEntity(db, personEntityType, personId);
|
|
@@ -67,6 +182,7 @@ export async function syncPersonIdentity(db, personId, data) {
|
|
|
67
182
|
if (managedAddress) {
|
|
68
183
|
await identityService.deleteAddress(db, managedAddress.id);
|
|
69
184
|
}
|
|
185
|
+
await rebuildPersonDirectoryProjection(db, personId);
|
|
70
186
|
return;
|
|
71
187
|
}
|
|
72
188
|
const addressPayload = {
|
|
@@ -86,6 +202,7 @@ export async function syncPersonIdentity(db, personId, data) {
|
|
|
86
202
|
else {
|
|
87
203
|
await identityService.createAddress(db, addressPayload);
|
|
88
204
|
}
|
|
205
|
+
await rebuildPersonDirectoryProjection(db, personId);
|
|
89
206
|
}
|
|
90
207
|
export async function deletePersonIdentity(db, personId) {
|
|
91
208
|
const [contactPoints, addresses] = await Promise.all([
|
|
@@ -101,52 +218,15 @@ export async function hydratePeople(db, rows) {
|
|
|
101
218
|
if (rows.length === 0) {
|
|
102
219
|
return rows.map((row) => ({
|
|
103
220
|
...row,
|
|
104
|
-
|
|
105
|
-
phone: null,
|
|
106
|
-
website: null,
|
|
107
|
-
address: null,
|
|
108
|
-
city: null,
|
|
109
|
-
country: null,
|
|
221
|
+
...emptyPersonHydratedFields(),
|
|
110
222
|
}));
|
|
111
223
|
}
|
|
112
224
|
const ids = rows.map((row) => row.id);
|
|
113
|
-
const
|
|
114
|
-
db
|
|
115
|
-
.select()
|
|
116
|
-
.from(identityContactPoints)
|
|
117
|
-
.where(and(eq(identityContactPoints.entityType, personEntityType), inArray(identityContactPoints.entityId, ids))),
|
|
118
|
-
db
|
|
119
|
-
.select()
|
|
120
|
-
.from(identityAddresses)
|
|
121
|
-
.where(and(eq(identityAddresses.entityType, personEntityType), inArray(identityAddresses.entityId, ids))),
|
|
122
|
-
]);
|
|
123
|
-
const contactPointMap = new Map();
|
|
124
|
-
const addressMap = new Map();
|
|
125
|
-
for (const point of contactPoints) {
|
|
126
|
-
const bucket = contactPointMap.get(point.entityId) ?? [];
|
|
127
|
-
bucket.push(point);
|
|
128
|
-
contactPointMap.set(point.entityId, bucket);
|
|
129
|
-
}
|
|
130
|
-
for (const address of addresses) {
|
|
131
|
-
const bucket = addressMap.get(address.entityId) ?? [];
|
|
132
|
-
bucket.push(address);
|
|
133
|
-
addressMap.set(address.entityId, bucket);
|
|
134
|
-
}
|
|
225
|
+
const projectionMap = await ensurePersonDirectoryProjectionMap(db, ids);
|
|
135
226
|
return rows.map((row) => {
|
|
136
|
-
const entityContactPoints = contactPointMap.get(row.id) ?? [];
|
|
137
|
-
const entityAddresses = addressMap.get(row.id) ?? [];
|
|
138
|
-
const findPrimaryContactPoint = (kind) => entityContactPoints.find((point) => point.kind === kind && point.isPrimary) ??
|
|
139
|
-
entityContactPoints.find((point) => point.kind === kind) ??
|
|
140
|
-
null;
|
|
141
|
-
const primaryAddress = entityAddresses.find((address) => address.isPrimary) ?? entityAddresses[0] ?? null;
|
|
142
227
|
return {
|
|
143
228
|
...row,
|
|
144
|
-
|
|
145
|
-
phone: findPrimaryContactPoint("phone")?.value ?? null,
|
|
146
|
-
website: findPrimaryContactPoint("website")?.value ?? null,
|
|
147
|
-
address: primaryAddress ? formatAddress(primaryAddress) : null,
|
|
148
|
-
city: primaryAddress?.city ?? null,
|
|
149
|
-
country: primaryAddress?.country ?? null,
|
|
229
|
+
...(projectionMap.get(row.id) ?? emptyPersonHydratedFields()),
|
|
150
230
|
};
|
|
151
231
|
});
|
|
152
232
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/crm",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"license": "FSL-1.1-Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"drizzle-orm": "^0.45.2",
|
|
30
30
|
"hono": "^4.12.10",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@voyantjs/core": "0.6.
|
|
33
|
-
"@voyantjs/db": "0.6.
|
|
34
|
-
"@voyantjs/hono": "0.6.
|
|
35
|
-
"@voyantjs/identity": "0.6.
|
|
32
|
+
"@voyantjs/core": "0.6.8",
|
|
33
|
+
"@voyantjs/db": "0.6.8",
|
|
34
|
+
"@voyantjs/hono": "0.6.8",
|
|
35
|
+
"@voyantjs/identity": "0.6.8"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^6.0.2",
|