@levrbet/shared 0.4.19 → 0.4.20

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.
@@ -1,5 +1,18 @@
1
- import { User } from "@prisma/client";
1
+ import type { User } from "@prisma/client";
2
+ /**
3
+ * Input for creating/saving a full user profile (settings page, profile modal).
4
+ * All fields except objectId/timestamps are settable.
5
+ */
2
6
  export interface SaveUserProfile extends Omit<User, "objectId" | "createdAt" | "updatedAt" | "email"> {
3
7
  imageData?: string;
4
8
  email?: string;
5
9
  }
10
+ /**
11
+ * Minimal input for ensuring a user profile exists (idempotent create-or-return).
12
+ * The backend fills in all defaults server-side.
13
+ */
14
+ export interface EnsureUserProfileInput {
15
+ walletAddress: string;
16
+ referrerCode?: string | null;
17
+ timeZone?: string;
18
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./express.utils";
2
2
  export * from "./tracing";
3
3
  export * from "./game_progress";
4
+ export * from "./referral.utils";
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./express.utils"), exports);
18
18
  __exportStar(require("./tracing"), exports);
19
19
  __exportStar(require("./game_progress"), exports);
20
+ __exportStar(require("./referral.utils"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,4CAAyB;AACzB,kDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,4CAAyB;AACzB,kDAA+B;AAC/B,mDAAgC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generates a deterministic referral code from a wallet address.
3
+ *
4
+ * The same wallet address + attempt number always produces the same code.
5
+ * Use `attempt` > 0 only to resolve collisions — each attempt derives a
6
+ * different 8-character base-36 code from a different segment of the
7
+ * SHA-256 hash.
8
+ *
9
+ * @param walletAddress - Ethereum wallet address (any casing)
10
+ * @param attempt - Collision-resolution attempt (0 = first try)
11
+ * @returns 8-character uppercase alphanumeric referral code
12
+ */
13
+ export declare function generateReferralCode(walletAddress: string, attempt?: number): string;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateReferralCode = generateReferralCode;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const BASE36_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
9
+ const CODE_LENGTH = 8;
10
+ /**
11
+ * Generates a deterministic referral code from a wallet address.
12
+ *
13
+ * The same wallet address + attempt number always produces the same code.
14
+ * Use `attempt` > 0 only to resolve collisions — each attempt derives a
15
+ * different 8-character base-36 code from a different segment of the
16
+ * SHA-256 hash.
17
+ *
18
+ * @param walletAddress - Ethereum wallet address (any casing)
19
+ * @param attempt - Collision-resolution attempt (0 = first try)
20
+ * @returns 8-character uppercase alphanumeric referral code
21
+ */
22
+ function generateReferralCode(walletAddress, attempt = 0) {
23
+ const hash = node_crypto_1.default
24
+ .createHash("sha256")
25
+ .update(walletAddress.toLowerCase())
26
+ .digest("hex");
27
+ const hashOffset = attempt * 8;
28
+ const hashSegment = hash.slice(hashOffset, hashOffset + 16) || hash.slice(0, 16);
29
+ let num = BigInt(`0x${hashSegment}`);
30
+ let code = "";
31
+ for (let i = 0; i < CODE_LENGTH; i++) {
32
+ code = BASE36_CHARS[Number(num % BigInt(36))] + code;
33
+ num = num / BigInt(36);
34
+ }
35
+ return code;
36
+ }
37
+ //# sourceMappingURL=referral.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referral.utils.js","sourceRoot":"","sources":["../../../src/server/utils/referral.utils.ts"],"names":[],"mappings":";;;;;AAiBA,oDAsBC;AAvCD,8DAAiC;AAEjC,MAAM,YAAY,GAAG,sCAAsC,CAAC;AAC5D,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;;GAWG;AACH,SAAgB,oBAAoB,CACnC,aAAqB,EACrB,OAAO,GAAG,CAAC;IAEX,MAAM,IAAI,GAAG,qBAAM;SACjB,UAAU,CAAC,QAAQ,CAAC;SACpB,MAAM,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;SACnC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEhB,MAAM,UAAU,GAAG,OAAO,GAAG,CAAC,CAAC;IAC/B,MAAM,WAAW,GAChB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE9D,IAAI,GAAG,GAAG,MAAM,CAAC,KAAK,WAAW,EAAE,CAAC,CAAC;IACrC,IAAI,IAAI,GAAG,EAAE,CAAC;IAEd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QACrD,GAAG,GAAG,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levrbet/shared",
3
- "version": "0.4.19",
3
+ "version": "0.4.20",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -307,13 +307,13 @@ enum UserOddsPreference {
307
307
  model User {
308
308
  objectId String @id @default(auto()) @map("_id") @db.ObjectId
309
309
  walletAddress String @unique
310
- userName String @unique
311
- email String @unique
312
- referralCode String @unique
310
+ userName String? @unique
311
+ email String?
312
+ referralCode String? @unique
313
313
  referrerCode String?
314
- timeZone String
314
+ timeZone String @default("UTC")
315
315
  preferredTimeZone String?
316
- userOddsPreference UserOddsPreference
316
+ userOddsPreference UserOddsPreference @default(American)
317
317
  profileImageUrl String?
318
318
  profileImageKey String?
319
319
  language String @default("en")