@managesome/eposmatic-toolkit 0.4.84 → 0.4.85

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.
@@ -219,7 +219,10 @@ export const CUSTOMER_COLLECTION_NAME = 'customers';
219
219
  * be passed straight to `.hint()`.
220
220
  * - `_id`: unique primary key.
221
221
  * - `brand_id__phone_number`: per-brand customer lookups by phone number.
222
- * - `brand_id__email`: per-brand customer lookups by email (email/Google login).
222
+ * UNIQUE (partial on non-empty phone) — one customer per phone per brand.
223
+ * - `brand_id__email`: per-brand customer lookups by email (email login).
224
+ * UNIQUE (partial on non-empty email) — one customer per email per brand.
225
+ * See `CUSTOMER_COLLECTION_UNIQUE_INDEXES` for the exact index options.
223
226
  * - `brand_id__createdAt`: per-brand customer lookups newest first.
224
227
  * - `brand_id__total_spent`: per-brand customer lookups by total spent.
225
228
  * - `brand_id__total_orders`: per-brand customer lookups by total orders.
@@ -272,3 +275,37 @@ export const CUSTOMER_COLLECTION_INDEXES = {
272
275
  voucher_codes: 1,
273
276
  }, // per-brand customer lookups by voucher codes
274
277
  };
278
+ /**
279
+ * Unique indexes that protect the customer identity inside a brand:
280
+ * - one customer per phone number,
281
+ * - one customer per email.
282
+ *
283
+ * Both are PARTIAL on non-empty values. A plain unique index would allow only
284
+ * one customer per brand without an email/phone because MongoDB indexes `null`
285
+ * and missing fields like any other value; the `$gt: ''` filter keeps those
286
+ * documents out of the index entirely.
287
+ *
288
+ * Use these definitions whenever the indexes are created (services, migrations,
289
+ * maintenance scripts) instead of re-deriving the options, so every environment
290
+ * ends up with the same constraint. The legacy non-unique index on the same key
291
+ * pattern must be dropped first; MongoDB rejects a second index with the same
292
+ * keys and different options.
293
+ */
294
+ export const CUSTOMER_COLLECTION_UNIQUE_INDEXES = {
295
+ brand_id__phone_number: {
296
+ keys: CUSTOMER_COLLECTION_INDEXES.brand_id__phone_number,
297
+ options: {
298
+ name: 'brand_id__phone_number_unique',
299
+ unique: true,
300
+ partialFilterExpression: { phone_number: { $type: 'string', $gt: '' } },
301
+ },
302
+ },
303
+ brand_id__email: {
304
+ keys: CUSTOMER_COLLECTION_INDEXES.brand_id__email,
305
+ options: {
306
+ name: 'brand_id__email_unique',
307
+ unique: true,
308
+ partialFilterExpression: { email: { $type: 'string', $gt: '' } },
309
+ },
310
+ },
311
+ };
@@ -572,7 +572,10 @@ export declare const CUSTOMER_COLLECTION_NAME = "customers";
572
572
  * be passed straight to `.hint()`.
573
573
  * - `_id`: unique primary key.
574
574
  * - `brand_id__phone_number`: per-brand customer lookups by phone number.
575
- * - `brand_id__email`: per-brand customer lookups by email (email/Google login).
575
+ * UNIQUE (partial on non-empty phone) — one customer per phone per brand.
576
+ * - `brand_id__email`: per-brand customer lookups by email (email login).
577
+ * UNIQUE (partial on non-empty email) — one customer per email per brand.
578
+ * See `CUSTOMER_COLLECTION_UNIQUE_INDEXES` for the exact index options.
576
579
  * - `brand_id__createdAt`: per-brand customer lookups newest first.
577
580
  * - `brand_id__total_spent`: per-brand customer lookups by total spent.
578
581
  * - `brand_id__total_orders`: per-brand customer lookups by total orders.
@@ -627,3 +630,53 @@ export declare const CUSTOMER_COLLECTION_INDEXES: {
627
630
  voucher_codes: number;
628
631
  };
629
632
  };
633
+ /**
634
+ * Unique indexes that protect the customer identity inside a brand:
635
+ * - one customer per phone number,
636
+ * - one customer per email.
637
+ *
638
+ * Both are PARTIAL on non-empty values. A plain unique index would allow only
639
+ * one customer per brand without an email/phone because MongoDB indexes `null`
640
+ * and missing fields like any other value; the `$gt: ''` filter keeps those
641
+ * documents out of the index entirely.
642
+ *
643
+ * Use these definitions whenever the indexes are created (services, migrations,
644
+ * maintenance scripts) instead of re-deriving the options, so every environment
645
+ * ends up with the same constraint. The legacy non-unique index on the same key
646
+ * pattern must be dropped first; MongoDB rejects a second index with the same
647
+ * keys and different options.
648
+ */
649
+ export declare const CUSTOMER_COLLECTION_UNIQUE_INDEXES: {
650
+ brand_id__phone_number: {
651
+ keys: {
652
+ brand_id: number;
653
+ phone_number: number;
654
+ };
655
+ options: {
656
+ name: string;
657
+ unique: boolean;
658
+ partialFilterExpression: {
659
+ phone_number: {
660
+ $type: string;
661
+ $gt: string;
662
+ };
663
+ };
664
+ };
665
+ };
666
+ brand_id__email: {
667
+ keys: {
668
+ brand_id: number;
669
+ email: number;
670
+ };
671
+ options: {
672
+ name: string;
673
+ unique: boolean;
674
+ partialFilterExpression: {
675
+ email: {
676
+ $type: string;
677
+ $gt: string;
678
+ };
679
+ };
680
+ };
681
+ };
682
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CUSTOMER_COLLECTION_INDEXES = exports.CUSTOMER_COLLECTION_NAME = exports.CustomersSchema = void 0;
3
+ exports.CUSTOMER_COLLECTION_UNIQUE_INDEXES = exports.CUSTOMER_COLLECTION_INDEXES = exports.CUSTOMER_COLLECTION_NAME = exports.CustomersSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const constants_1 = require("../../constants");
6
6
  const common_models_1 = require("./common-models");
@@ -222,7 +222,10 @@ exports.CUSTOMER_COLLECTION_NAME = 'customers';
222
222
  * be passed straight to `.hint()`.
223
223
  * - `_id`: unique primary key.
224
224
  * - `brand_id__phone_number`: per-brand customer lookups by phone number.
225
- * - `brand_id__email`: per-brand customer lookups by email (email/Google login).
225
+ * UNIQUE (partial on non-empty phone) — one customer per phone per brand.
226
+ * - `brand_id__email`: per-brand customer lookups by email (email login).
227
+ * UNIQUE (partial on non-empty email) — one customer per email per brand.
228
+ * See `CUSTOMER_COLLECTION_UNIQUE_INDEXES` for the exact index options.
226
229
  * - `brand_id__createdAt`: per-brand customer lookups newest first.
227
230
  * - `brand_id__total_spent`: per-brand customer lookups by total spent.
228
231
  * - `brand_id__total_orders`: per-brand customer lookups by total orders.
@@ -275,3 +278,37 @@ exports.CUSTOMER_COLLECTION_INDEXES = {
275
278
  voucher_codes: 1,
276
279
  }, // per-brand customer lookups by voucher codes
277
280
  };
281
+ /**
282
+ * Unique indexes that protect the customer identity inside a brand:
283
+ * - one customer per phone number,
284
+ * - one customer per email.
285
+ *
286
+ * Both are PARTIAL on non-empty values. A plain unique index would allow only
287
+ * one customer per brand without an email/phone because MongoDB indexes `null`
288
+ * and missing fields like any other value; the `$gt: ''` filter keeps those
289
+ * documents out of the index entirely.
290
+ *
291
+ * Use these definitions whenever the indexes are created (services, migrations,
292
+ * maintenance scripts) instead of re-deriving the options, so every environment
293
+ * ends up with the same constraint. The legacy non-unique index on the same key
294
+ * pattern must be dropped first; MongoDB rejects a second index with the same
295
+ * keys and different options.
296
+ */
297
+ exports.CUSTOMER_COLLECTION_UNIQUE_INDEXES = {
298
+ brand_id__phone_number: {
299
+ keys: exports.CUSTOMER_COLLECTION_INDEXES.brand_id__phone_number,
300
+ options: {
301
+ name: 'brand_id__phone_number_unique',
302
+ unique: true,
303
+ partialFilterExpression: { phone_number: { $type: 'string', $gt: '' } },
304
+ },
305
+ },
306
+ brand_id__email: {
307
+ keys: exports.CUSTOMER_COLLECTION_INDEXES.brand_id__email,
308
+ options: {
309
+ name: 'brand_id__email_unique',
310
+ unique: true,
311
+ partialFilterExpression: { email: { $type: 'string', $gt: '' } },
312
+ },
313
+ },
314
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.84",
3
+ "version": "0.4.85",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",