@fonderie/customers 1.0.0 → 1.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/brain/outcomes.md +189 -0
- package/brain/signatures.md +244 -0
- package/dist/index.cjs +103 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +109 -1
- package/dist/index.d.ts +109 -1
- package/dist/index.js +109 -40
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +3 -0
- package/package.json +13 -9
- package/dist/migrations/sql/001_customers.sql +0 -111
- package/dist/migrations/sql/002_customers_sex.sql +0 -2
- package/dist/migrations/sql/003_customer_sequences.sql +0 -6
- package/dist/migrations/sql/004_customer_sequences_per_workspace.sql +0 -1
- package/dist/migrations/sql/005_drop_job_title.sql +0 -1
- package/dist/migrations/sql/006_unique_email_phone.sql +0 -23
- package/dist/migrations/sql/007_rename_archived_to_blacklisted.sql +0 -13
- package/dist/migrations/sql/008_blacklist_reason.sql +0 -2
- package/dist/migrations/sql/009_customer_relationships.sql +0 -25
- package/dist/migrations/sql/010_customer_labels.sql +0 -75
- package/dist/migrations/sql/011_label_fk_set_null.sql +0 -17
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,7 @@ export { AddressLabel, CustomerType, EmailLabel, PhoneLabel } from './types.cjs'
|
|
|
3
3
|
import { IStoreAdapter } from '@fonderie/store';
|
|
4
4
|
import { IFonderieModule, IFonderieApp } from '@fonderie/core';
|
|
5
5
|
import { EventBus } from '@fonderie/events';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
|
|
7
8
|
declare const EVENT_KEYS: {
|
|
8
9
|
readonly customerCreated: "fonderie.customer.created";
|
|
@@ -234,4 +235,111 @@ declare class CustomersModule implements IFonderieModule {
|
|
|
234
235
|
install(app: IFonderieApp): void;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
declare const createCustomerSchema: z.ZodObject<{
|
|
239
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
240
|
+
individual: "individual";
|
|
241
|
+
business: "business";
|
|
242
|
+
}>>;
|
|
243
|
+
sex: z.ZodOptional<z.ZodEnum<{
|
|
244
|
+
UNKNOWN: "UNKNOWN";
|
|
245
|
+
MALE: "MALE";
|
|
246
|
+
FEMALE: "FEMALE";
|
|
247
|
+
}>>;
|
|
248
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
249
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
250
|
+
companyName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
251
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodURL>>>;
|
|
252
|
+
locale: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
253
|
+
referenceCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
254
|
+
}, z.core.$strip>;
|
|
255
|
+
declare const updateCustomerSchema: z.ZodObject<{
|
|
256
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
257
|
+
individual: "individual";
|
|
258
|
+
business: "business";
|
|
259
|
+
}>>;
|
|
260
|
+
sex: z.ZodOptional<z.ZodEnum<{
|
|
261
|
+
UNKNOWN: "UNKNOWN";
|
|
262
|
+
MALE: "MALE";
|
|
263
|
+
FEMALE: "FEMALE";
|
|
264
|
+
}>>;
|
|
265
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
266
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
267
|
+
companyName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
268
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodURL>>>;
|
|
269
|
+
locale: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
270
|
+
referenceCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
declare const blacklistSchema: z.ZodObject<{
|
|
273
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
274
|
+
}, z.core.$strip>;
|
|
275
|
+
declare const addEmailSchema: z.ZodObject<{
|
|
276
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
277
|
+
label: z.ZodOptional<z.ZodString>;
|
|
278
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
+
}, z.core.$strip>;
|
|
280
|
+
declare const updateEmailSchema: z.ZodObject<{
|
|
281
|
+
email: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodEmail>>;
|
|
282
|
+
label: z.ZodOptional<z.ZodString>;
|
|
283
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
284
|
+
}, z.core.$strip>;
|
|
285
|
+
declare const addPhoneSchema: z.ZodObject<{
|
|
286
|
+
phone: z.ZodString;
|
|
287
|
+
label: z.ZodOptional<z.ZodString>;
|
|
288
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
declare const updatePhoneSchema: z.ZodObject<{
|
|
291
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
292
|
+
label: z.ZodOptional<z.ZodString>;
|
|
293
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
294
|
+
}, z.core.$strip>;
|
|
295
|
+
declare const addAddressSchema: z.ZodObject<{
|
|
296
|
+
label: z.ZodOptional<z.ZodString>;
|
|
297
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
298
|
+
line1: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
299
|
+
line2: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
300
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
301
|
+
zipPostalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
302
|
+
countryIso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
303
|
+
subdivision1Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
304
|
+
subdivision2Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
305
|
+
}, z.core.$strip>;
|
|
306
|
+
declare const updateAddressSchema: z.ZodObject<{
|
|
307
|
+
label: z.ZodOptional<z.ZodString>;
|
|
308
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
309
|
+
line1: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
310
|
+
line2: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
311
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
312
|
+
zipPostalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
313
|
+
countryIso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
314
|
+
subdivision1Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
315
|
+
subdivision2Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
316
|
+
}, z.core.$strip>;
|
|
317
|
+
declare const noteSchema: z.ZodObject<{
|
|
318
|
+
body: z.ZodString;
|
|
319
|
+
}, z.core.$strip>;
|
|
320
|
+
declare const addTagSchema: z.ZodObject<{
|
|
321
|
+
tag: z.ZodString;
|
|
322
|
+
}, z.core.$strip>;
|
|
323
|
+
declare const addRelationshipSchema: z.ZodObject<{
|
|
324
|
+
relatedId: z.ZodString;
|
|
325
|
+
relationship: z.ZodOptional<z.ZodString>;
|
|
326
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
327
|
+
}, z.core.$strip>;
|
|
328
|
+
|
|
329
|
+
declare const schemas_addAddressSchema: typeof addAddressSchema;
|
|
330
|
+
declare const schemas_addEmailSchema: typeof addEmailSchema;
|
|
331
|
+
declare const schemas_addPhoneSchema: typeof addPhoneSchema;
|
|
332
|
+
declare const schemas_addRelationshipSchema: typeof addRelationshipSchema;
|
|
333
|
+
declare const schemas_addTagSchema: typeof addTagSchema;
|
|
334
|
+
declare const schemas_blacklistSchema: typeof blacklistSchema;
|
|
335
|
+
declare const schemas_createCustomerSchema: typeof createCustomerSchema;
|
|
336
|
+
declare const schemas_noteSchema: typeof noteSchema;
|
|
337
|
+
declare const schemas_updateAddressSchema: typeof updateAddressSchema;
|
|
338
|
+
declare const schemas_updateCustomerSchema: typeof updateCustomerSchema;
|
|
339
|
+
declare const schemas_updateEmailSchema: typeof updateEmailSchema;
|
|
340
|
+
declare const schemas_updatePhoneSchema: typeof updatePhoneSchema;
|
|
341
|
+
declare namespace schemas {
|
|
342
|
+
export { schemas_addAddressSchema as addAddressSchema, schemas_addEmailSchema as addEmailSchema, schemas_addPhoneSchema as addPhoneSchema, schemas_addRelationshipSchema as addRelationshipSchema, schemas_addTagSchema as addTagSchema, schemas_blacklistSchema as blacklistSchema, schemas_createCustomerSchema as createCustomerSchema, schemas_noteSchema as noteSchema, schemas_updateAddressSchema as updateAddressSchema, schemas_updateCustomerSchema as updateCustomerSchema, schemas_updateEmailSchema as updateEmailSchema, schemas_updatePhoneSchema as updatePhoneSchema };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
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, schemas, toAddressDTO, toCustomerAddressDTO, toCustomerDTO, toCustomerDetailDTO, toCustomerEmailDTO, toCustomerNoteDTO, toCustomerPhoneDTO, toCustomerTagDTO };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { AddressLabel, CustomerType, EmailLabel, PhoneLabel } from './types.js';
|
|
|
3
3
|
import { IStoreAdapter } from '@fonderie/store';
|
|
4
4
|
import { IFonderieModule, IFonderieApp } from '@fonderie/core';
|
|
5
5
|
import { EventBus } from '@fonderie/events';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
|
|
7
8
|
declare const EVENT_KEYS: {
|
|
8
9
|
readonly customerCreated: "fonderie.customer.created";
|
|
@@ -234,4 +235,111 @@ declare class CustomersModule implements IFonderieModule {
|
|
|
234
235
|
install(app: IFonderieApp): void;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
declare const createCustomerSchema: z.ZodObject<{
|
|
239
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
240
|
+
individual: "individual";
|
|
241
|
+
business: "business";
|
|
242
|
+
}>>;
|
|
243
|
+
sex: z.ZodOptional<z.ZodEnum<{
|
|
244
|
+
UNKNOWN: "UNKNOWN";
|
|
245
|
+
MALE: "MALE";
|
|
246
|
+
FEMALE: "FEMALE";
|
|
247
|
+
}>>;
|
|
248
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
249
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
250
|
+
companyName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
251
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodURL>>>;
|
|
252
|
+
locale: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
253
|
+
referenceCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
254
|
+
}, z.core.$strip>;
|
|
255
|
+
declare const updateCustomerSchema: z.ZodObject<{
|
|
256
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
257
|
+
individual: "individual";
|
|
258
|
+
business: "business";
|
|
259
|
+
}>>;
|
|
260
|
+
sex: z.ZodOptional<z.ZodEnum<{
|
|
261
|
+
UNKNOWN: "UNKNOWN";
|
|
262
|
+
MALE: "MALE";
|
|
263
|
+
FEMALE: "FEMALE";
|
|
264
|
+
}>>;
|
|
265
|
+
firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
266
|
+
lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
267
|
+
companyName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
268
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodURL>>>;
|
|
269
|
+
locale: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
270
|
+
referenceCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
declare const blacklistSchema: z.ZodObject<{
|
|
273
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
274
|
+
}, z.core.$strip>;
|
|
275
|
+
declare const addEmailSchema: z.ZodObject<{
|
|
276
|
+
email: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
277
|
+
label: z.ZodOptional<z.ZodString>;
|
|
278
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
+
}, z.core.$strip>;
|
|
280
|
+
declare const updateEmailSchema: z.ZodObject<{
|
|
281
|
+
email: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodEmail>>;
|
|
282
|
+
label: z.ZodOptional<z.ZodString>;
|
|
283
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
284
|
+
}, z.core.$strip>;
|
|
285
|
+
declare const addPhoneSchema: z.ZodObject<{
|
|
286
|
+
phone: z.ZodString;
|
|
287
|
+
label: z.ZodOptional<z.ZodString>;
|
|
288
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
declare const updatePhoneSchema: z.ZodObject<{
|
|
291
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
292
|
+
label: z.ZodOptional<z.ZodString>;
|
|
293
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
294
|
+
}, z.core.$strip>;
|
|
295
|
+
declare const addAddressSchema: z.ZodObject<{
|
|
296
|
+
label: z.ZodOptional<z.ZodString>;
|
|
297
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
298
|
+
line1: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
299
|
+
line2: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
300
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
301
|
+
zipPostalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
302
|
+
countryIso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
303
|
+
subdivision1Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
304
|
+
subdivision2Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
305
|
+
}, z.core.$strip>;
|
|
306
|
+
declare const updateAddressSchema: z.ZodObject<{
|
|
307
|
+
label: z.ZodOptional<z.ZodString>;
|
|
308
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
309
|
+
line1: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
310
|
+
line2: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
311
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
312
|
+
zipPostalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
313
|
+
countryIso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
314
|
+
subdivision1Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
315
|
+
subdivision2Iso: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
316
|
+
}, z.core.$strip>;
|
|
317
|
+
declare const noteSchema: z.ZodObject<{
|
|
318
|
+
body: z.ZodString;
|
|
319
|
+
}, z.core.$strip>;
|
|
320
|
+
declare const addTagSchema: z.ZodObject<{
|
|
321
|
+
tag: z.ZodString;
|
|
322
|
+
}, z.core.$strip>;
|
|
323
|
+
declare const addRelationshipSchema: z.ZodObject<{
|
|
324
|
+
relatedId: z.ZodString;
|
|
325
|
+
relationship: z.ZodOptional<z.ZodString>;
|
|
326
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
327
|
+
}, z.core.$strip>;
|
|
328
|
+
|
|
329
|
+
declare const schemas_addAddressSchema: typeof addAddressSchema;
|
|
330
|
+
declare const schemas_addEmailSchema: typeof addEmailSchema;
|
|
331
|
+
declare const schemas_addPhoneSchema: typeof addPhoneSchema;
|
|
332
|
+
declare const schemas_addRelationshipSchema: typeof addRelationshipSchema;
|
|
333
|
+
declare const schemas_addTagSchema: typeof addTagSchema;
|
|
334
|
+
declare const schemas_blacklistSchema: typeof blacklistSchema;
|
|
335
|
+
declare const schemas_createCustomerSchema: typeof createCustomerSchema;
|
|
336
|
+
declare const schemas_noteSchema: typeof noteSchema;
|
|
337
|
+
declare const schemas_updateAddressSchema: typeof updateAddressSchema;
|
|
338
|
+
declare const schemas_updateCustomerSchema: typeof updateCustomerSchema;
|
|
339
|
+
declare const schemas_updateEmailSchema: typeof updateEmailSchema;
|
|
340
|
+
declare const schemas_updatePhoneSchema: typeof updatePhoneSchema;
|
|
341
|
+
declare namespace schemas {
|
|
342
|
+
export { schemas_addAddressSchema as addAddressSchema, schemas_addEmailSchema as addEmailSchema, schemas_addPhoneSchema as addPhoneSchema, schemas_addRelationshipSchema as addRelationshipSchema, schemas_addTagSchema as addTagSchema, schemas_blacklistSchema as blacklistSchema, schemas_createCustomerSchema as createCustomerSchema, schemas_noteSchema as noteSchema, schemas_updateAddressSchema as updateAddressSchema, schemas_updateCustomerSchema as updateCustomerSchema, schemas_updateEmailSchema as updateEmailSchema, schemas_updatePhoneSchema as updatePhoneSchema };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
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, schemas, toAddressDTO, toCustomerAddressDTO, toCustomerDTO, toCustomerDetailDTO, toCustomerEmailDTO, toCustomerNoteDTO, toCustomerPhoneDTO, toCustomerTagDTO };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
1
7
|
// src/config.ts
|
|
2
8
|
var EVENT_KEYS = {
|
|
3
9
|
customerCreated: "fonderie.customer.created",
|
|
@@ -48,13 +54,13 @@ function toCustomerShallowDTO(c) {
|
|
|
48
54
|
};
|
|
49
55
|
}
|
|
50
56
|
function toCustomerRelationshipExpandedDTO(r) {
|
|
51
|
-
const { id: customerId, ...
|
|
57
|
+
const { id: customerId, ...customerFields2 } = toCustomerShallowDTO(r.customer);
|
|
52
58
|
return {
|
|
53
59
|
id: stringOrEmpty(r.id),
|
|
54
60
|
customerId,
|
|
55
61
|
relationship: stringOrEmpty(r.relationship),
|
|
56
62
|
isPrimary: booleanOrFalse(r.isPrimary),
|
|
57
|
-
...
|
|
63
|
+
...customerFields2
|
|
58
64
|
};
|
|
59
65
|
}
|
|
60
66
|
function toCustomerDetailDTO(c) {
|
|
@@ -69,13 +75,13 @@ function toCustomerDetailDTO(c) {
|
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
function toCustomerRelationshipExpandedD2DTO(r) {
|
|
72
|
-
const { id: customerId, ...
|
|
78
|
+
const { id: customerId, ...customerFields2 } = toCustomerShallowDTO(r.customer);
|
|
73
79
|
return {
|
|
74
80
|
id: stringOrEmpty(r.id),
|
|
75
81
|
customerId,
|
|
76
82
|
relationship: stringOrEmpty(r.relationship),
|
|
77
83
|
isPrimary: booleanOrFalse(r.isPrimary),
|
|
78
|
-
...
|
|
84
|
+
...customerFields2,
|
|
79
85
|
relationships: arrayOrEmpty(r.customer.relationships).map(toCustomerRelationshipExpandedDTO)
|
|
80
86
|
};
|
|
81
87
|
}
|
|
@@ -1154,7 +1160,68 @@ var CustomerTagModel = class {
|
|
|
1154
1160
|
};
|
|
1155
1161
|
|
|
1156
1162
|
// src/routes.ts
|
|
1157
|
-
import { requireAuth } from "@fonderie/core/middlewares";
|
|
1163
|
+
import { requireAuth, validate } from "@fonderie/core/middlewares";
|
|
1164
|
+
|
|
1165
|
+
// src/schemas.ts
|
|
1166
|
+
var schemas_exports = {};
|
|
1167
|
+
__export(schemas_exports, {
|
|
1168
|
+
addAddressSchema: () => addAddressSchema,
|
|
1169
|
+
addEmailSchema: () => addEmailSchema,
|
|
1170
|
+
addPhoneSchema: () => addPhoneSchema,
|
|
1171
|
+
addRelationshipSchema: () => addRelationshipSchema,
|
|
1172
|
+
addTagSchema: () => addTagSchema,
|
|
1173
|
+
blacklistSchema: () => blacklistSchema,
|
|
1174
|
+
createCustomerSchema: () => createCustomerSchema,
|
|
1175
|
+
noteSchema: () => noteSchema,
|
|
1176
|
+
updateAddressSchema: () => updateAddressSchema,
|
|
1177
|
+
updateCustomerSchema: () => updateCustomerSchema,
|
|
1178
|
+
updateEmailSchema: () => updateEmailSchema,
|
|
1179
|
+
updatePhoneSchema: () => updatePhoneSchema
|
|
1180
|
+
});
|
|
1181
|
+
import { z } from "zod";
|
|
1182
|
+
var label = z.string().max(100).optional();
|
|
1183
|
+
var isPrimary = z.boolean().optional();
|
|
1184
|
+
var email = z.string().trim().pipe(z.email());
|
|
1185
|
+
var phone = z.string().refine((v) => /^\+?[1-9]\d{6,14}$/.test(v.replace(/[\s\-()]/g, "")), "Invalid phone number");
|
|
1186
|
+
var customerFields = {
|
|
1187
|
+
type: z.enum(["individual", "business"]).optional(),
|
|
1188
|
+
sex: z.enum(["UNKNOWN", "MALE", "FEMALE"]).optional(),
|
|
1189
|
+
firstName: z.string().max(100).nullable().optional(),
|
|
1190
|
+
lastName: z.string().max(100).nullable().optional(),
|
|
1191
|
+
companyName: z.string().max(200).nullable().optional(),
|
|
1192
|
+
avatarUrl: z.string().trim().pipe(z.url()).nullable().optional(),
|
|
1193
|
+
locale: z.string().max(35).nullable().optional(),
|
|
1194
|
+
referenceCode: z.string().max(100).nullable().optional()
|
|
1195
|
+
};
|
|
1196
|
+
var createCustomerSchema = z.object(customerFields);
|
|
1197
|
+
var updateCustomerSchema = z.object(customerFields).refine((o) => Object.values(o).some((v) => v !== void 0), "Provide at least one field");
|
|
1198
|
+
var blacklistSchema = z.object({ reason: z.string().max(1e3).optional() });
|
|
1199
|
+
var addEmailSchema = z.object({ email, label, isPrimary });
|
|
1200
|
+
var updateEmailSchema = z.object({ email: email.optional(), label, isPrimary }).refine((o) => Object.values(o).some((v) => v !== void 0), "Provide at least one field");
|
|
1201
|
+
var addPhoneSchema = z.object({ phone, label, isPrimary });
|
|
1202
|
+
var updatePhoneSchema = z.object({ phone: phone.optional(), label, isPrimary }).refine((o) => Object.values(o).some((v) => v !== void 0), "Provide at least one field");
|
|
1203
|
+
var addressFields = {
|
|
1204
|
+
label,
|
|
1205
|
+
isPrimary,
|
|
1206
|
+
line1: z.string().max(200).nullable().optional(),
|
|
1207
|
+
line2: z.string().max(200).nullable().optional(),
|
|
1208
|
+
unit: z.string().max(50).nullable().optional(),
|
|
1209
|
+
zipPostalCode: z.string().max(20).nullable().optional(),
|
|
1210
|
+
countryIso: z.string().max(3).nullable().optional(),
|
|
1211
|
+
subdivision1Iso: z.string().max(10).nullable().optional(),
|
|
1212
|
+
subdivision2Iso: z.string().max(10).nullable().optional()
|
|
1213
|
+
};
|
|
1214
|
+
var addAddressSchema = z.object(addressFields);
|
|
1215
|
+
var updateAddressSchema = z.object(addressFields).refine((o) => Object.values(o).some((v) => v !== void 0), "Provide at least one field");
|
|
1216
|
+
var noteSchema = z.object({ body: z.string().trim().min(1, "body is required").max(1e4) });
|
|
1217
|
+
var addTagSchema = z.object({ tag: z.string().trim().min(1, "tag is required").max(100) });
|
|
1218
|
+
var addRelationshipSchema = z.object({
|
|
1219
|
+
relatedId: z.string().min(1, "relatedId is required"),
|
|
1220
|
+
relationship: z.string().max(100).optional(),
|
|
1221
|
+
isPrimary
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
// src/routes.ts
|
|
1158
1225
|
import { withWorkspace } from "@fonderie/workspaces";
|
|
1159
1226
|
|
|
1160
1227
|
// src/controllers/customer.controller.ts
|
|
@@ -1271,7 +1338,8 @@ function customerController(store, config = {}, bus) {
|
|
|
1271
1338
|
companyName: typeof companyName === "string" ? companyName : null,
|
|
1272
1339
|
avatarUrl: typeof avatarUrl === "string" ? avatarUrl : null,
|
|
1273
1340
|
locale: typeof locale === "string" ? locale : "en-US",
|
|
1274
|
-
|
|
1341
|
+
// exactOptionalPropertyTypes: omit the key entirely when absent
|
|
1342
|
+
...typeof referenceCode === "string" ? { referenceCode: referenceCode.toUpperCase() } : {},
|
|
1275
1343
|
referenceCodePrefix: prefix,
|
|
1276
1344
|
createdBy: ctx.user?.id ?? null
|
|
1277
1345
|
});
|
|
@@ -1620,20 +1688,20 @@ function customerEmailController(store) {
|
|
|
1620
1688
|
return r.error;
|
|
1621
1689
|
}
|
|
1622
1690
|
const body = ctx.meta["body"];
|
|
1623
|
-
const
|
|
1624
|
-
if (typeof
|
|
1691
|
+
const email2 = body?.["email"];
|
|
1692
|
+
if (typeof email2 !== "string" || email2.trim().length === 0) {
|
|
1625
1693
|
return setApiResponse3(HTTP3.UNPROCESSABLE, "INVALID_PARAMETER", "email is required");
|
|
1626
1694
|
}
|
|
1627
1695
|
const rawLabel = typeof body?.["label"] === "string" ? body["label"] : "work";
|
|
1628
|
-
const
|
|
1696
|
+
const isPrimary2 = body?.["isPrimary"] === true;
|
|
1629
1697
|
const { id: labelId } = await labels.findOrCreate("email", rawLabel);
|
|
1630
1698
|
let created;
|
|
1631
1699
|
try {
|
|
1632
1700
|
created = await emails.add({
|
|
1633
1701
|
customerId: r.customer.id,
|
|
1634
|
-
email:
|
|
1702
|
+
email: email2.trim(),
|
|
1635
1703
|
labelId,
|
|
1636
|
-
isPrimary
|
|
1704
|
+
isPrimary: isPrimary2
|
|
1637
1705
|
});
|
|
1638
1706
|
} catch (err) {
|
|
1639
1707
|
if (err instanceof Error && err.message.includes("idx_fce_unique_email")) {
|
|
@@ -1829,20 +1897,20 @@ function customerPhoneController(store) {
|
|
|
1829
1897
|
return r.error;
|
|
1830
1898
|
}
|
|
1831
1899
|
const body = ctx.meta["body"];
|
|
1832
|
-
const
|
|
1833
|
-
if (typeof
|
|
1900
|
+
const phone2 = body?.["phone"];
|
|
1901
|
+
if (typeof phone2 !== "string" || phone2.trim().length === 0) {
|
|
1834
1902
|
return setApiResponse5(HTTP5.UNPROCESSABLE, "INVALID_PARAMETER", "phone is required");
|
|
1835
1903
|
}
|
|
1836
1904
|
const rawLabel = typeof body?.["label"] === "string" ? body["label"] : "mobile";
|
|
1837
|
-
const
|
|
1905
|
+
const isPrimary2 = body?.["isPrimary"] === true;
|
|
1838
1906
|
const { id: labelId } = await labels.findOrCreate("phone", rawLabel);
|
|
1839
1907
|
let created;
|
|
1840
1908
|
try {
|
|
1841
1909
|
created = await phones.add({
|
|
1842
1910
|
customerId: r.customer.id,
|
|
1843
|
-
phone:
|
|
1911
|
+
phone: phone2.trim(),
|
|
1844
1912
|
labelId,
|
|
1845
|
-
isPrimary
|
|
1913
|
+
isPrimary: isPrimary2
|
|
1846
1914
|
});
|
|
1847
1915
|
} catch (err) {
|
|
1848
1916
|
if (err instanceof Error && err.message.includes("idx_fcp_unique_phone")) {
|
|
@@ -2084,55 +2152,55 @@ function customerRelationshipController(store) {
|
|
|
2084
2152
|
function buildCustomerRoutes(store, config, bus) {
|
|
2085
2153
|
const wsCtx = withWorkspace(store);
|
|
2086
2154
|
const customer = customerController(store, config, bus);
|
|
2087
|
-
const
|
|
2088
|
-
const
|
|
2155
|
+
const email2 = customerEmailController(store);
|
|
2156
|
+
const phone2 = customerPhoneController(store);
|
|
2089
2157
|
const address = customerAddressController(store);
|
|
2090
2158
|
const note = customerNoteController(store);
|
|
2091
2159
|
const tag = customerTagController(store);
|
|
2092
2160
|
const relationship = customerRelationshipController(store);
|
|
2093
|
-
const
|
|
2161
|
+
const label2 = customerLabelController(store);
|
|
2094
2162
|
return [
|
|
2095
2163
|
// ── Labels ───────────────────────────────────────────────────────
|
|
2096
|
-
["GET", "/customers/labels", requireAuth, wsCtx,
|
|
2097
|
-
["DELETE", "/customers/labels/:labelId", requireAuth, wsCtx,
|
|
2164
|
+
["GET", "/customers/labels", requireAuth, wsCtx, label2.list],
|
|
2165
|
+
["DELETE", "/customers/labels/:labelId", requireAuth, wsCtx, label2.remove],
|
|
2098
2166
|
// ── Core customer CRUD ───────────────────────────────────────────
|
|
2099
2167
|
["GET", "/customers", requireAuth, wsCtx, customer.list],
|
|
2100
|
-
["POST", "/customers", requireAuth, wsCtx, customer.create],
|
|
2168
|
+
["POST", "/customers", requireAuth, wsCtx, validate(createCustomerSchema), customer.create],
|
|
2101
2169
|
["GET", "/customers/:customerId", requireAuth, wsCtx, customer.get],
|
|
2102
|
-
["PUT", "/customers/:customerId", requireAuth, wsCtx, customer.update],
|
|
2170
|
+
["PUT", "/customers/:customerId", requireAuth, wsCtx, validate(updateCustomerSchema), customer.update],
|
|
2103
2171
|
["DELETE", "/customers/:customerId", requireAuth, wsCtx, customer.delete],
|
|
2104
|
-
["POST", "/customers/:customerId/blacklist", requireAuth, wsCtx, customer.blacklist],
|
|
2172
|
+
["POST", "/customers/:customerId/blacklist", requireAuth, wsCtx, validate(blacklistSchema), customer.blacklist],
|
|
2105
2173
|
["POST", "/customers/:customerId/unblacklist", requireAuth, wsCtx, customer.unblacklist],
|
|
2106
2174
|
// ── Emails ───────────────────────────────────────────────────────
|
|
2107
|
-
["GET", "/customers/:customerId/emails", requireAuth, wsCtx,
|
|
2108
|
-
["POST", "/customers/:customerId/emails", requireAuth, wsCtx,
|
|
2109
|
-
["PATCH", "/customers/:customerId/emails/:emailId", requireAuth, wsCtx,
|
|
2110
|
-
["PUT", "/customers/:customerId/emails/:emailId/primary", requireAuth, wsCtx,
|
|
2111
|
-
["DELETE", "/customers/:customerId/emails/:emailId", requireAuth, wsCtx,
|
|
2175
|
+
["GET", "/customers/:customerId/emails", requireAuth, wsCtx, email2.list],
|
|
2176
|
+
["POST", "/customers/:customerId/emails", requireAuth, wsCtx, validate(addEmailSchema), email2.add],
|
|
2177
|
+
["PATCH", "/customers/:customerId/emails/:emailId", requireAuth, wsCtx, validate(updateEmailSchema), email2.update],
|
|
2178
|
+
["PUT", "/customers/:customerId/emails/:emailId/primary", requireAuth, wsCtx, email2.setPrimary],
|
|
2179
|
+
["DELETE", "/customers/:customerId/emails/:emailId", requireAuth, wsCtx, email2.remove],
|
|
2112
2180
|
// ── Phones ───────────────────────────────────────────────────────
|
|
2113
|
-
["GET", "/customers/:customerId/phones", requireAuth, wsCtx,
|
|
2114
|
-
["POST", "/customers/:customerId/phones", requireAuth, wsCtx,
|
|
2115
|
-
["PATCH", "/customers/:customerId/phones/:phoneId", requireAuth, wsCtx,
|
|
2116
|
-
["PUT", "/customers/:customerId/phones/:phoneId/primary", requireAuth, wsCtx,
|
|
2117
|
-
["DELETE", "/customers/:customerId/phones/:phoneId", requireAuth, wsCtx,
|
|
2181
|
+
["GET", "/customers/:customerId/phones", requireAuth, wsCtx, phone2.list],
|
|
2182
|
+
["POST", "/customers/:customerId/phones", requireAuth, wsCtx, validate(addPhoneSchema), phone2.add],
|
|
2183
|
+
["PATCH", "/customers/:customerId/phones/:phoneId", requireAuth, wsCtx, validate(updatePhoneSchema), phone2.update],
|
|
2184
|
+
["PUT", "/customers/:customerId/phones/:phoneId/primary", requireAuth, wsCtx, phone2.setPrimary],
|
|
2185
|
+
["DELETE", "/customers/:customerId/phones/:phoneId", requireAuth, wsCtx, phone2.remove],
|
|
2118
2186
|
// ── Addresses ────────────────────────────────────────────────────
|
|
2119
2187
|
["GET", "/customers/:customerId/addresses", requireAuth, wsCtx, address.list],
|
|
2120
|
-
["POST", "/customers/:customerId/addresses", requireAuth, wsCtx, address.add],
|
|
2121
|
-
["PATCH", "/customers/:customerId/addresses/:addrId", requireAuth, wsCtx, address.update],
|
|
2188
|
+
["POST", "/customers/:customerId/addresses", requireAuth, wsCtx, validate(addAddressSchema), address.add],
|
|
2189
|
+
["PATCH", "/customers/:customerId/addresses/:addrId", requireAuth, wsCtx, validate(updateAddressSchema), address.update],
|
|
2122
2190
|
["PUT", "/customers/:customerId/addresses/:addrId/primary", requireAuth, wsCtx, address.setPrimary],
|
|
2123
2191
|
["DELETE", "/customers/:customerId/addresses/:addrId", requireAuth, wsCtx, address.remove],
|
|
2124
2192
|
// ── Notes ────────────────────────────────────────────────────────
|
|
2125
2193
|
["GET", "/customers/:customerId/notes", requireAuth, wsCtx, note.list],
|
|
2126
|
-
["POST", "/customers/:customerId/notes", requireAuth, wsCtx, note.create],
|
|
2127
|
-
["PUT", "/customers/:customerId/notes/:noteId", requireAuth, wsCtx, note.update],
|
|
2194
|
+
["POST", "/customers/:customerId/notes", requireAuth, wsCtx, validate(noteSchema), note.create],
|
|
2195
|
+
["PUT", "/customers/:customerId/notes/:noteId", requireAuth, wsCtx, validate(noteSchema), note.update],
|
|
2128
2196
|
["DELETE", "/customers/:customerId/notes/:noteId", requireAuth, wsCtx, note.delete],
|
|
2129
2197
|
// ── Tags ─────────────────────────────────────────────────────────
|
|
2130
2198
|
["GET", "/customers/:customerId/tags", requireAuth, wsCtx, tag.list],
|
|
2131
|
-
["POST", "/customers/:customerId/tags", requireAuth, wsCtx, tag.add],
|
|
2199
|
+
["POST", "/customers/:customerId/tags", requireAuth, wsCtx, validate(addTagSchema), tag.add],
|
|
2132
2200
|
["DELETE", "/customers/:customerId/tags/:tag", requireAuth, wsCtx, tag.remove],
|
|
2133
2201
|
// ── Relationships ────────────────────────────────────────────────────
|
|
2134
2202
|
["GET", "/customers/:customerId/relationships", requireAuth, wsCtx, relationship.list],
|
|
2135
|
-
["POST", "/customers/:customerId/relationships", requireAuth, wsCtx, relationship.add],
|
|
2203
|
+
["POST", "/customers/:customerId/relationships", requireAuth, wsCtx, validate(addRelationshipSchema), relationship.add],
|
|
2136
2204
|
["PUT", "/customers/:customerId/relationships/:relatedId/primary", requireAuth, wsCtx, relationship.setPrimary],
|
|
2137
2205
|
["DELETE", "/customers/:customerId/relationships/:relatedId", requireAuth, wsCtx, relationship.remove]
|
|
2138
2206
|
];
|
|
@@ -2166,6 +2234,7 @@ export {
|
|
|
2166
2234
|
CustomerTagModel,
|
|
2167
2235
|
CustomersModule,
|
|
2168
2236
|
EVENT_KEYS,
|
|
2237
|
+
schemas_exports as schemas,
|
|
2169
2238
|
toAddressDTO,
|
|
2170
2239
|
toCustomerAddressDTO,
|
|
2171
2240
|
toCustomerDTO,
|