dgc-core 2.0.1 → 2.0.3

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.
@@ -2,6 +2,6 @@ export declare enum UserCollectorType {
2
2
  'Non-member' = -1,
3
3
  Free = 2,
4
4
  Rookie = 1,
5
- Collector = 0,
6
- Elite = 3
5
+ Collector = 3,
6
+ Elite = 0
7
7
  }
@@ -6,6 +6,6 @@ var UserCollectorType;
6
6
  UserCollectorType[UserCollectorType["Non-member"] = -1] = "Non-member";
7
7
  UserCollectorType[UserCollectorType["Free"] = 2] = "Free";
8
8
  UserCollectorType[UserCollectorType["Rookie"] = 1] = "Rookie";
9
- UserCollectorType[UserCollectorType["Collector"] = 0] = "Collector";
10
- UserCollectorType[UserCollectorType["Elite"] = 3] = "Elite";
9
+ UserCollectorType[UserCollectorType["Collector"] = 3] = "Collector";
10
+ UserCollectorType[UserCollectorType["Elite"] = 0] = "Elite";
11
11
  })(UserCollectorType || (exports.UserCollectorType = UserCollectorType = {}));
@@ -177,14 +177,14 @@ function submitEntry(g, account, raw) {
177
177
  new Date(g.startsAt) > now ||
178
178
  new Date(g.closesAt) <= now)
179
179
  throw new http_error_1.HttpError('This giveaway is not accepting entries', 409);
180
- const country = input.country || account.country;
180
+ const country = input.country;
181
181
  if (g.countries.length && (!country || !g.countries.includes(country)))
182
182
  throw new http_error_1.HttpError('This country is not eligible', 422);
183
183
  const at = now.toISOString();
184
184
  return {
185
185
  giveawayId: g._id,
186
186
  userId: account.userId,
187
- fullName: [account.firstName, account.lastName].filter(Boolean).join(' ').trim() || account.email,
187
+ name: account.name,
188
188
  email: account.email,
189
189
  username: account.username,
190
190
  country,
@@ -53,12 +53,12 @@ export declare class GiveawayRepository {
53
53
  _id: string;
54
54
  email: string;
55
55
  _collectorType: UserCollectorType | null;
56
+ name: string;
56
57
  giveawayId: import("../types").GiveawayObjectId;
57
58
  enteredAt: string;
58
59
  username?: string | undefined;
59
60
  rulesSnapshot: string;
60
61
  userId: string;
61
- fullName: string;
62
62
  address?: import("../types").GiveawayDeliveryAddress | undefined;
63
63
  country?: string | undefined;
64
64
  rulesAcceptedAt: string;
@@ -22,6 +22,11 @@ function serialize(record) {
22
22
  return { ...record, _id: record._id.toHexString() };
23
23
  }
24
24
  const statuses = Object.values(giveaway_2.GiveawayStatus);
25
+ /** Normalize historical entry names at read boundaries without rewriting stored records. */
26
+ function normalizeEntry(record) {
27
+ const { fullName, ...fields } = record;
28
+ return { ...fields, name: record.name ?? fullName ?? '' };
29
+ }
25
30
  function pagination(params) {
26
31
  const integer = (key, fallback, max) => {
27
32
  const value = Number(params.get(key));
@@ -411,6 +416,7 @@ class GiveawayRepository {
411
416
  const q = search(params);
412
417
  if (q)
413
418
  filter.$or = [
419
+ 'name',
414
420
  'fullName',
415
421
  '_id',
416
422
  'username',
@@ -470,7 +476,7 @@ class GiveawayRepository {
470
476
  .aggregate([...pipeline, { $facet: { data, total: [{ $count: 'count' }] } }])
471
477
  .next();
472
478
  return {
473
- data: result?.data || [],
479
+ data: (result?.data || []).map(normalizeEntry),
474
480
  total: result?.total[0]?.count || 0,
475
481
  page,
476
482
  limit
@@ -542,6 +548,7 @@ class GiveawayRepository {
542
548
  return {
543
549
  data: data.map(w => ({
544
550
  ...w,
551
+ entry: normalizeEntry(w.entry),
545
552
  giveaway: { ...w.giveaway, status: (0, domain_1.effectiveStatus)(w.giveaway) }
546
553
  })),
547
554
  total,
@@ -716,7 +723,7 @@ class GiveawayRepository {
716
723
  })
717
724
  .limit(1000)
718
725
  .toArray();
719
- const entries = rows;
726
+ const entries = rows.map(normalizeEntry);
720
727
  const existing = await this.winners.findOne({ giveawayId: id, replacedAt: null }, { projection: { _id: 1 } });
721
728
  (0, domain_1.confirmWinners)(g, entries, !!existing, 'preview', input);
722
729
  return { entries, giveaway: { ...g, status: (0, domain_1.effectiveStatus)(g) } };
@@ -851,7 +858,7 @@ class GiveawayRepository {
851
858
  const updated = { ...g, selection, revision: g.revision + 1 };
852
859
  await this.updateGiveaway(updated, g.revision, session);
853
860
  await this.audit(actor, 'Winner selected: ' + input.method, id, entry._id + (selection.reason ? ': ' + selection.reason : ''), session);
854
- return { giveaway: updated, entry };
861
+ return { giveaway: updated, entry: normalizeEntry(entry) };
855
862
  });
856
863
  }
857
864
  async resetSelection(actor, id, revision, reason) {
@@ -1250,7 +1257,7 @@ class GiveawayRepository {
1250
1257
  ...marketingLookup
1251
1258
  ];
1252
1259
  if (marketingOnly)
1253
- pipeline.push({ $match: { marketingAllowed: true } }, { $project: { fullName: 1, email: 1 } });
1260
+ pipeline.push({ $match: { marketingAllowed: true } }, { $project: { name: 1, fullName: 1, email: 1 } });
1254
1261
  const cursor = this.entries.aggregate(pipeline, {
1255
1262
  batchSize: 100
1256
1263
  });
@@ -1276,11 +1283,12 @@ class GiveawayRepository {
1276
1283
  'Rules accepted'
1277
1284
  ]
1278
1285
  ]);
1279
- for await (const e of cursor) {
1286
+ for await (const record of cursor) {
1287
+ const e = normalizeEntry(record);
1280
1288
  const row = marketingOnly
1281
- ? [e.fullName, e.email]
1289
+ ? [e.name, e.email]
1282
1290
  : [
1283
- e.fullName,
1291
+ e.name,
1284
1292
  e.email,
1285
1293
  e.address?.line1 || '',
1286
1294
  e.address?.line2 || '',
@@ -70,7 +70,7 @@ export type GiveawayEntry = {
70
70
  _id: GiveawayEntryId;
71
71
  giveawayId: GiveawayObjectId;
72
72
  userId: string;
73
- fullName: string;
73
+ name: string;
74
74
  email: string;
75
75
  /** Historical entry addresses are retained; new entries collect delivery only at claim. */
76
76
  address?: GiveawayDeliveryAddress;
@@ -180,10 +180,9 @@ export type GiveawayOverviewData = {
180
180
  liveGiveaways: GiveawaySummary[];
181
181
  needsSelection: Giveaway[];
182
182
  };
183
- export type GiveawayUserProfile = Pick<FbUser, 'email' | 'firstName' | 'lastName' | '_collectorType'> & {
183
+ export type GiveawayUserProfile = Pick<FbUser, 'email' | 'name' | '_collectorType'> & {
184
184
  userId: string;
185
185
  username?: string;
186
- country?: string;
187
186
  };
188
187
  export type GiveawayPhysicalClaim = {
189
188
  fullName: string;
@@ -8,6 +8,8 @@ export type FbUser = {
8
8
  count: number;
9
9
  };
10
10
  email: string;
11
+ /** Full name stored on the Firebase account. */
12
+ name: string;
11
13
  fcmTokens: Record<string, boolean>;
12
14
  firstName: string;
13
15
  fundAmount: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgc-core",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Shared DGC contracts, business rules and server utilities",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",