@fonderie/customers 1.0.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.
@@ -0,0 +1,237 @@
1
+ import { CustomerSex, IAddress, ICustomerAddress, ICustomer, ICustomerDetail, ICustomerEmail, ICustomerNote, ICustomerPhone, ICustomerTag, ICustomerDetailD2 } from './types.js';
2
+ export { AddressLabel, CustomerType, EmailLabel, PhoneLabel } from './types.js';
3
+ import { IStoreAdapter } from '@fonderie/store';
4
+ import { IFonderieModule, IFonderieApp } from '@fonderie/core';
5
+ import { EventBus } from '@fonderie/events';
6
+
7
+ declare const EVENT_KEYS: {
8
+ readonly customerCreated: "fonderie.customer.created";
9
+ readonly customerUpdated: "fonderie.customer.updated";
10
+ readonly customerDeleted: "fonderie.customer.deleted";
11
+ readonly customerBlacklisted: "fonderie.customer.blacklisted";
12
+ readonly customerUnblacklisted: "fonderie.customer.unblacklisted";
13
+ };
14
+ type CustomersEventKey = (typeof EVENT_KEYS)[keyof typeof EVENT_KEYS];
15
+ type ICustomersConfig = {
16
+ /** Prefix used when auto-generating customer reference codes. Defaults to DEFAULT_REFERENCE_CODE_PREFIX. */
17
+ referenceCodePrefix?: string;
18
+ };
19
+
20
+ interface ICustomerDTO {
21
+ id: string;
22
+ type: string;
23
+ sex: CustomerSex;
24
+ firstName: string;
25
+ lastName: string;
26
+ companyName: string;
27
+ avatarUrl: string;
28
+ locale: string;
29
+ referenceCode: string;
30
+ blacklisted: {
31
+ status: boolean;
32
+ reason: string | null;
33
+ };
34
+ createdBy: string;
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ }
38
+ interface ICustomerShallowDTO extends ICustomerDTO {
39
+ emails: ICustomerEmailDTO[];
40
+ phones: ICustomerPhoneDTO[];
41
+ addresses: ICustomerAddressDTO[];
42
+ notes: ICustomerNoteDTO[];
43
+ tags: string[];
44
+ }
45
+ type ICustomerRelationshipExpandedDTO = Omit<ICustomerShallowDTO, 'id'> & {
46
+ id: string;
47
+ customerId: string;
48
+ relationship: string;
49
+ isPrimary: boolean;
50
+ };
51
+ interface ICustomerDetailDTO extends ICustomerDTO {
52
+ emails: ICustomerEmailDTO[];
53
+ phones: ICustomerPhoneDTO[];
54
+ addresses: ICustomerAddressDTO[];
55
+ notes: ICustomerNoteDTO[];
56
+ relationships: ICustomerRelationshipExpandedDTO[];
57
+ tags: string[];
58
+ }
59
+ interface ICustomerEmailDTO {
60
+ id: string;
61
+ email: string;
62
+ label: string;
63
+ isPrimary: boolean;
64
+ createdAt: string;
65
+ }
66
+ interface ICustomerPhoneDTO {
67
+ id: string;
68
+ phone: string;
69
+ label: string;
70
+ isPrimary: boolean;
71
+ createdAt: string;
72
+ }
73
+ interface IAddressDTO {
74
+ countryIso: string;
75
+ subdivision1Iso: string;
76
+ subdivision2Iso: string;
77
+ zipPostalCode: string;
78
+ unit: string;
79
+ line1: string;
80
+ line2: string;
81
+ }
82
+ interface ICustomerAddressDTO {
83
+ id: string;
84
+ label: string;
85
+ isPrimary: boolean;
86
+ address: IAddressDTO;
87
+ }
88
+ interface ICustomerNoteDTO {
89
+ id: string;
90
+ authorId: string;
91
+ body: string;
92
+ createdAt: string;
93
+ updatedAt: string;
94
+ }
95
+ interface ICustomerTagDTO {
96
+ tag: string;
97
+ }
98
+ declare function toCustomerDTO(c: ICustomer): ICustomerDTO;
99
+ declare function toCustomerDetailDTO(c: ICustomerDetail): ICustomerDetailDTO;
100
+ declare function toAddressDTO(a: IAddress): IAddressDTO;
101
+ declare function toCustomerEmailDTO(e: ICustomerEmail): ICustomerEmailDTO;
102
+ declare function toCustomerPhoneDTO(p: ICustomerPhone): ICustomerPhoneDTO;
103
+ declare function toCustomerAddressDTO(ca: ICustomerAddress): ICustomerAddressDTO;
104
+ declare function toCustomerNoteDTO(n: ICustomerNote): ICustomerNoteDTO;
105
+ declare function toCustomerTagDTO(t: ICustomerTag): ICustomerTagDTO;
106
+
107
+ interface ListCustomersOpts {
108
+ workspaceId: string;
109
+ search?: string | undefined;
110
+ blacklisted?: boolean | undefined;
111
+ limit?: number | undefined;
112
+ offset?: number | undefined;
113
+ }
114
+ interface CreateCustomerOpts {
115
+ workspaceId: string;
116
+ type?: string;
117
+ sex?: string;
118
+ firstName?: string | null;
119
+ lastName?: string | null;
120
+ companyName?: string | null;
121
+ avatarUrl?: string | null;
122
+ locale?: string;
123
+ /** Explicit code to assign. Omit to auto-generate ({prefix}-0001, …). */
124
+ referenceCode?: string;
125
+ /** Prefix used when auto-generating. Defaults to 'CLT'. */
126
+ referenceCodePrefix?: string;
127
+ createdBy?: string | null;
128
+ }
129
+ interface UpdateCustomerOpts {
130
+ type?: string;
131
+ sex?: string;
132
+ firstName?: string | null;
133
+ lastName?: string | null;
134
+ companyName?: string | null;
135
+ avatarUrl?: string | null;
136
+ locale?: string;
137
+ /** Explicit code to assign. Omit to keep existing or auto-generate if none. */
138
+ referenceCode?: string;
139
+ }
140
+ declare class CustomerModel {
141
+ private readonly store;
142
+ constructor(store: IStoreAdapter);
143
+ private allocateCode;
144
+ list(opts: ListCustomersOpts): Promise<ICustomer[]>;
145
+ findById(id: string, workspaceId: string): Promise<ICustomer | null>;
146
+ findDetail(id: string, workspaceId: string, depth: 2): Promise<ICustomerDetailD2 | null>;
147
+ findDetail(id: string, workspaceId: string, depth?: 1): Promise<ICustomerDetail | null>;
148
+ create(opts: CreateCustomerOpts): Promise<ICustomer>;
149
+ update(id: string, workspaceId: string, opts: UpdateCustomerOpts, referenceCodePrefix?: string): Promise<ICustomer | null>;
150
+ delete(id: string, workspaceId: string): Promise<void>;
151
+ blacklist(id: string, workspaceId: string, reason?: string | null): Promise<void>;
152
+ unblacklist(id: string, workspaceId: string): Promise<void>;
153
+ }
154
+
155
+ declare class CustomerAddressModel {
156
+ private readonly store;
157
+ constructor(store: IStoreAdapter);
158
+ list(customerId: string): Promise<ICustomerAddress[]>;
159
+ add(opts: {
160
+ customerId: string;
161
+ countryIso: string;
162
+ subdivision1Iso?: string | null;
163
+ subdivision2Iso?: string | null;
164
+ zipPostalCode: string;
165
+ unit?: string | null;
166
+ line1?: string | null;
167
+ line2?: string | null;
168
+ labelId: string;
169
+ isPrimary?: boolean;
170
+ }): Promise<ICustomerAddress>;
171
+ updateLabel(addrId: string, customerId: string, labelId: string): Promise<ICustomerAddress>;
172
+ setPrimary(addrId: string, customerId: string): Promise<void>;
173
+ remove(addrId: string, customerId: string): Promise<void>;
174
+ }
175
+
176
+ declare class CustomerEmailModel {
177
+ private readonly store;
178
+ constructor(store: IStoreAdapter);
179
+ list(customerId: string): Promise<ICustomerEmail[]>;
180
+ add(opts: {
181
+ customerId: string;
182
+ email: string;
183
+ labelId: string;
184
+ isPrimary?: boolean;
185
+ }): Promise<ICustomerEmail>;
186
+ updateLabel(emailId: string, customerId: string, labelId: string): Promise<ICustomerEmail>;
187
+ setPrimary(emailId: string, customerId: string): Promise<void>;
188
+ remove(emailId: string, customerId: string): Promise<void>;
189
+ }
190
+
191
+ declare class CustomerNoteModel {
192
+ private readonly store;
193
+ constructor(store: IStoreAdapter);
194
+ list(customerId: string): Promise<ICustomerNote[]>;
195
+ create(opts: {
196
+ customerId: string;
197
+ authorId?: string | null;
198
+ body: string;
199
+ }): Promise<ICustomerNote>;
200
+ update(noteId: string, customerId: string, body: string): Promise<ICustomerNote | null>;
201
+ delete(noteId: string, customerId: string): Promise<void>;
202
+ }
203
+
204
+ declare class CustomerPhoneModel {
205
+ private readonly store;
206
+ constructor(store: IStoreAdapter);
207
+ list(customerId: string): Promise<ICustomerPhone[]>;
208
+ add(opts: {
209
+ customerId: string;
210
+ phone: string;
211
+ labelId: string;
212
+ isPrimary?: boolean;
213
+ }): Promise<ICustomerPhone>;
214
+ updateLabel(phoneId: string, customerId: string, labelId: string): Promise<ICustomerPhone>;
215
+ setPrimary(phoneId: string, customerId: string): Promise<void>;
216
+ remove(phoneId: string, customerId: string): Promise<void>;
217
+ }
218
+
219
+ declare class CustomerTagModel {
220
+ private readonly store;
221
+ constructor(store: IStoreAdapter);
222
+ list(customerId: string): Promise<string[]>;
223
+ add(customerId: string, tag: string): Promise<void>;
224
+ remove(customerId: string, tag: string): Promise<void>;
225
+ }
226
+
227
+ declare class CustomersModule implements IFonderieModule {
228
+ private store;
229
+ private config;
230
+ private bus?;
231
+ readonly name = "@fonderie/customers";
232
+ readonly deps: string[];
233
+ constructor(store: IStoreAdapter, config?: ICustomersConfig, bus?: EventBus | undefined);
234
+ install(app: IFonderieApp): void;
235
+ }
236
+
237
+ export { CustomerAddressModel, CustomerEmailModel, CustomerModel, CustomerNoteModel, CustomerPhoneModel, CustomerTagModel, type CustomersEventKey, CustomersModule, EVENT_KEYS, IAddress, type IAddressDTO, ICustomer, ICustomerAddress, type ICustomerAddressDTO, type ICustomerDTO, ICustomerDetail, type ICustomerDetailDTO, ICustomerEmail, type ICustomerEmailDTO, ICustomerNote, type ICustomerNoteDTO, ICustomerPhone, type ICustomerPhoneDTO, ICustomerTag, type ICustomerTagDTO, type ICustomersConfig, toAddressDTO, toCustomerAddressDTO, toCustomerDTO, toCustomerDetailDTO, toCustomerEmailDTO, toCustomerNoteDTO, toCustomerPhoneDTO, toCustomerTagDTO };