@fonderie/customers 4.0.0 → 5.1.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/README.md +2 -2
- package/brain/signatures.md +1 -0
- package/dist/index.cjs +29 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ elsewhere in your app.
|
|
|
24
24
|
You've shipped this plumbing before — auth, teams, billing, messaging —
|
|
25
25
|
and the next project will ask for it again. Fonderie packages it once:
|
|
26
26
|
plain TypeScript modules for
|
|
27
|
-
[`@fonderie/core`](https://github.com/
|
|
27
|
+
[`@fonderie/core`](https://github.com/fonderiejs/sdk/tree/main/packages/core),
|
|
28
28
|
PostgreSQL-backed, self-hosted, MIT. No external control plane, no
|
|
29
29
|
per-seat anything. Register the modules you need; skip the ones you don't.
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ individuals and businesses with their emails, phones, addresses, notes,
|
|
|
33
33
|
and tags.
|
|
34
34
|
|
|
35
35
|
Browse the whole set at
|
|
36
|
-
[
|
|
36
|
+
[fonderiejs/sdk](https://github.com/fonderiejs/sdk) · follow
|
|
37
37
|
[@fonderiejs](https://x.com/fonderiejs)
|
|
38
38
|
|
|
39
39
|
## License
|
package/brain/signatures.md
CHANGED
|
@@ -123,6 +123,7 @@ new CustomerEmailModel(store: IStoreAdapter): CustomerEmailModel
|
|
|
123
123
|
new CustomerModel(store: IStoreAdapter): CustomerModel
|
|
124
124
|
.resolveReferralCode(workspaceId: string, code: string): Promise<string | null>
|
|
125
125
|
.list(opts: ListCustomersOpts): Promise<ICustomer[]>
|
|
126
|
+
.count(opts: Omit<ListCustomersOpts, "limit" | "offset">): Promise<number>
|
|
126
127
|
.findById(id: string, workspaceId: string): Promise<ICustomer | null>
|
|
127
128
|
.findDetail(id: string, workspaceId: string, depth: 2): Promise<ICustomerDetailD2 | null>
|
|
128
129
|
.create(opts: CreateCustomerOpts): Promise<ICustomer>
|
package/dist/index.cjs
CHANGED
|
@@ -293,6 +293,28 @@ var CustomerModel = class {
|
|
|
293
293
|
params
|
|
294
294
|
);
|
|
295
295
|
}
|
|
296
|
+
async count(opts) {
|
|
297
|
+
const conditions = ["workspace_id = $1"];
|
|
298
|
+
const params = [opts.workspaceId];
|
|
299
|
+
if (opts.blacklisted !== void 0) {
|
|
300
|
+
params.push(opts.blacklisted);
|
|
301
|
+
conditions.push(`is_blacklisted = $${params.length}`);
|
|
302
|
+
}
|
|
303
|
+
if (opts.search) {
|
|
304
|
+
params.push(`%${opts.search}%`);
|
|
305
|
+
const idx = params.length;
|
|
306
|
+
conditions.push(
|
|
307
|
+
`(first_name ILIKE $${idx} OR last_name ILIKE $${idx} OR company_name ILIKE $${idx} OR reference_code ILIKE $${idx})`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
const [row] = await this.store.query(
|
|
311
|
+
`SELECT COUNT(*) AS count
|
|
312
|
+
FROM fonderie_customers
|
|
313
|
+
WHERE ${conditions.join(" AND ")}`,
|
|
314
|
+
params
|
|
315
|
+
);
|
|
316
|
+
return Number(row?.count ?? 0);
|
|
317
|
+
}
|
|
296
318
|
async findById(id, workspaceId) {
|
|
297
319
|
const [row] = await this.store.query(
|
|
298
320
|
`SELECT ${SELECT_CUSTOMER}
|
|
@@ -1345,9 +1367,14 @@ function customerController(store, config = {}, bus) {
|
|
|
1345
1367
|
if (archived !== null && archived !== void 0) {
|
|
1346
1368
|
listOpts.blacklisted = archived === "true" || archived === "1";
|
|
1347
1369
|
}
|
|
1348
|
-
const
|
|
1370
|
+
const { limit: _limit, offset: _offset, ...countOpts } = listOpts;
|
|
1371
|
+
const [list, total] = await Promise.all([
|
|
1372
|
+
customers.list(listOpts),
|
|
1373
|
+
customers.count(countOpts)
|
|
1374
|
+
]);
|
|
1349
1375
|
return (0, import_core2.setApiResponse)(import_core2.HTTP.OK, "CUSTOMERS_FETCHED", "Customers retrieved successfully.", {
|
|
1350
|
-
customers: list.map(toCustomerDTO)
|
|
1376
|
+
customers: list.map(toCustomerDTO),
|
|
1377
|
+
total
|
|
1351
1378
|
});
|
|
1352
1379
|
},
|
|
1353
1380
|
async get(ctx) {
|