gambling-bot-shared 0.1.48 → 0.1.51

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 CHANGED
@@ -10,17 +10,14 @@ https://www.krouskystepan.com/projects/discord-gambling-hub
10
10
  The project is split into three repositories:
11
11
 
12
12
  - **Admin Panel**
13
-
14
13
  - Web interface for managing data and configuration.
15
14
  - 🔗 https://github.com/krouskystepan/gambling-bot-admin
16
15
 
17
16
  - **Discord Bot**
18
-
19
17
  - Uses the shared data and logic to run the gambling system inside Discord.
20
18
  - 🔗 https://github.com/krouskystepan/gambling-bot-discord
21
19
 
22
20
  - **Shared Package (this repository)**
23
-
24
21
  - Common types, database models, and business logic shared between the admin panel and the bot.
25
22
  - 🔗 https://github.com/krouskystepan/gambling-bot-shared
26
23
 
@@ -34,3 +31,7 @@ https://discord.gg/Y2mMQN5QVE
34
31
 
35
32
  All architecture decisions, data flow, and detailed explanations are documented
36
33
  in the case study linked above.
34
+
35
+ ## Local development
36
+
37
+ See [LOCAL_DEVELOPMENT.md](./LOCAL_DEVELOPMENT.md) for the local linking workflow, debugging commands, and release process.
@@ -13,9 +13,8 @@ export type GlobalSettings = {
13
13
  disableVip: boolean;
14
14
  maintenanceMode: boolean;
15
15
  timezone: string;
16
- currencyCode: string;
17
16
  currencySymbol: string;
18
- /** prefix: symbol before amount ($ 1.5k). suffix: ISO code after amount (1.5k CZK). */
17
+ /** prefix: symbol before amount ($1.5k). suffix: symbol after amount (1.5kCZK). Spacing is part of currencySymbol. */
19
18
  currencyPlacement: CurrencyPlacement;
20
19
  };
21
20
  export declare const defaultGlobalSettings: GlobalSettings;
@@ -15,7 +15,6 @@ exports.defaultGlobalSettings = {
15
15
  disableVip: false,
16
16
  maintenanceMode: false,
17
17
  timezone: 'UTC',
18
- currencyCode: 'USD',
19
18
  currencySymbol: '$',
20
19
  currencyPlacement: 'prefix'
21
20
  };
@@ -112,7 +112,6 @@ exports.GuildConfigurationSchema = new mongoose_1.Schema({
112
112
  disableVip: { type: Boolean, default: false },
113
113
  maintenanceMode: { type: Boolean, default: false },
114
114
  timezone: { type: String, default: constants_1.defaultGlobalSettings.timezone },
115
- currencyCode: { type: String, default: constants_1.defaultGlobalSettings.currencyCode },
116
115
  currencySymbol: {
117
116
  type: String,
118
117
  default: constants_1.defaultGlobalSettings.currencySymbol
@@ -148,7 +148,6 @@ export declare const globalSettingsFormSchema: z.ZodObject<{
148
148
  "Australia/Melbourne": "Australia/Melbourne";
149
149
  "Pacific/Auckland": "Pacific/Auckland";
150
150
  }>;
151
- currencyCode: z.ZodString;
152
151
  currencySymbol: z.ZodString;
153
152
  currencyPlacement: z.ZodEnum<{
154
153
  prefix: "prefix";
@@ -143,12 +143,12 @@ exports.globalSettingsFormSchema = zod_1.default.object({
143
143
  disableVip: zod_1.default.boolean(),
144
144
  maintenanceMode: zod_1.default.boolean(),
145
145
  timezone: zod_1.default.enum(commonTimezones_1.COMMON_TIMEZONES),
146
- currencyCode: zod_1.default
146
+ currencySymbol: zod_1.default
147
147
  .string()
148
- .trim()
149
- .toUpperCase()
150
- .regex(/^[A-Z]{3}$/, 'Use a 3-letter ISO 4217 code (e.g. USD, CZK).'),
151
- currencySymbol: zod_1.default.string().trim().min(1).max(8),
148
+ .max(8)
149
+ .refine((value) => value.trim().length > 0, {
150
+ message: 'Currency symbol is required'
151
+ }),
152
152
  currencyPlacement: zod_1.default.enum(['prefix', 'suffix'])
153
153
  });
154
154
  exports.bonusFormSchema = zod_1.default.object({
@@ -2,9 +2,9 @@ import type { GlobalSettings } from '../constants/defaultGlobalSettings';
2
2
  export declare const formatNumberToReadableString: (number: number) => string;
3
3
  export declare const parseReadableStringToNumber: (readableString: string) => number;
4
4
  export declare const formatNumberWithSpaces: (num: number) => string;
5
- /** Compact amount with guild currency (prefix: symbol, suffix: ISO code). */
5
+ /** Compact amount with guild currency (prefix or suffix symbol). */
6
6
  export declare const formatMoney: (amount: number, globalSettings?: Partial<GlobalSettings> | null) => string;
7
- /** Full-precision amount with guild currency (prefix: symbol, suffix: ISO code). */
7
+ /** Full-precision amount with guild currency (prefix or suffix symbol). */
8
8
  export declare const formatMoneyExact: (amount: number, globalSettings?: Partial<GlobalSettings> | null) => string;
9
9
  export declare const formatNumberToPercentage: (num: number) => string;
10
10
  export declare const getReadableName: (key: string, map: {
@@ -5,10 +5,11 @@ const globalSettings_1 = require("./globalSettings");
5
5
  const formatAmountWithCurrency = (amount, formattedAbsAmount, globalSettings) => {
6
6
  const negative = amount < 0;
7
7
  const sign = negative ? '-' : '';
8
+ const symbol = (0, globalSettings_1.getCurrencySymbol)(globalSettings);
8
9
  if ((0, globalSettings_1.getCurrencyPlacement)(globalSettings) === 'suffix') {
9
- return `${sign}${formattedAbsAmount} ${(0, globalSettings_1.getCurrencyCode)(globalSettings)}`;
10
+ return `${sign}${formattedAbsAmount}${symbol}`;
10
11
  }
11
- return `${sign}${(0, globalSettings_1.getCurrencySymbol)(globalSettings)} ${formattedAbsAmount}`;
12
+ return `${sign}${symbol}${formattedAbsAmount}`;
12
13
  };
13
14
  const formatNumberToReadableString = (number) => {
14
15
  const absNumber = Math.abs(number);
@@ -52,10 +53,10 @@ const formatNumberWithSpaces = (num) => {
52
53
  return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
53
54
  };
54
55
  exports.formatNumberWithSpaces = formatNumberWithSpaces;
55
- /** Compact amount with guild currency (prefix: symbol, suffix: ISO code). */
56
+ /** Compact amount with guild currency (prefix or suffix symbol). */
56
57
  const formatMoney = (amount, globalSettings) => formatAmountWithCurrency(amount, (0, exports.formatNumberToReadableString)(Math.abs(amount)), globalSettings);
57
58
  exports.formatMoney = formatMoney;
58
- /** Full-precision amount with guild currency (prefix: symbol, suffix: ISO code). */
59
+ /** Full-precision amount with guild currency (prefix or suffix symbol). */
59
60
  const formatMoneyExact = (amount, globalSettings) => formatAmountWithCurrency(amount, (0, exports.formatNumberWithSpaces)(Math.abs(amount)), globalSettings);
60
61
  exports.formatMoneyExact = formatMoneyExact;
61
62
  const formatNumberToPercentage = (num) => {
@@ -4,4 +4,3 @@ export type GlobalFeature = 'registration' | 'deposit' | 'withdraw' | 'casinoGam
4
4
  export declare function isGlobalFeatureDisabled(config: TGuildConfiguration | null | undefined, feature: GlobalFeature): boolean;
5
5
  export declare const getCurrencyPlacement: (globalSettings?: Partial<GlobalSettings> | null) => CurrencyPlacement;
6
6
  export declare const getCurrencySymbol: (globalSettings?: Partial<GlobalSettings> | null) => string;
7
- export declare const getCurrencyCode: (globalSettings?: Partial<GlobalSettings> | null) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCurrencyCode = exports.getCurrencySymbol = exports.getCurrencyPlacement = void 0;
3
+ exports.getCurrencySymbol = exports.getCurrencyPlacement = void 0;
4
4
  exports.isGlobalFeatureDisabled = isGlobalFeatureDisabled;
5
5
  const defaultGlobalSettings_1 = require("../constants/defaultGlobalSettings");
6
6
  function isGlobalFeatureDisabled(config, feature) {
@@ -40,12 +40,11 @@ function isGlobalFeatureDisabled(config, feature) {
40
40
  }
41
41
  const getCurrencyPlacement = (globalSettings) => globalSettings?.currencyPlacement === 'suffix' ? 'suffix' : 'prefix';
42
42
  exports.getCurrencyPlacement = getCurrencyPlacement;
43
- const getCurrencySymbol = (globalSettings) => globalSettings?.currencySymbol?.trim() || '$';
44
- exports.getCurrencySymbol = getCurrencySymbol;
45
- const getCurrencyCode = (globalSettings) => {
46
- const raw = typeof globalSettings?.currencyCode === 'string'
47
- ? globalSettings.currencyCode.trim().toUpperCase()
48
- : '';
49
- return /^[A-Z]{3}$/.test(raw) ? raw : defaultGlobalSettings_1.defaultGlobalSettings.currencyCode;
43
+ const getCurrencySymbol = (globalSettings) => {
44
+ const symbol = globalSettings?.currencySymbol;
45
+ if (symbol == null || symbol.trim().length === 0) {
46
+ return defaultGlobalSettings_1.defaultGlobalSettings.currencySymbol;
47
+ }
48
+ return symbol;
50
49
  };
51
- exports.getCurrencyCode = getCurrencyCode;
50
+ exports.getCurrencySymbol = getCurrencySymbol;
@@ -11,14 +11,11 @@ const coerceBool = (value, fallback) => {
11
11
  return false;
12
12
  return fallback;
13
13
  };
14
- const trimCurrencyCode = (value) => {
15
- const raw = typeof value === 'string' ? value.trim().toUpperCase() : '';
16
- const code = raw.slice(0, 3);
17
- return /^[A-Z]{3}$/.test(code) ? code : constants_1.defaultGlobalSettings.currencyCode;
18
- };
19
- const trimCurrencySymbol = (value) => {
20
- const raw = typeof value === 'string' ? value.trim() : '';
21
- return raw.length > 0 ? raw.slice(0, 8) : constants_1.defaultGlobalSettings.currencySymbol;
14
+ const normalizeCurrencySymbol = (value) => {
15
+ if (typeof value !== 'string' || value.trim().length === 0) {
16
+ return constants_1.defaultGlobalSettings.currencySymbol;
17
+ }
18
+ return value.slice(0, 8);
22
19
  };
23
20
  const normalizeCurrencyPlacement = (value) => value === 'suffix' ? 'suffix' : 'prefix';
24
21
  const normalizeTimezone = (value) => {
@@ -43,8 +40,7 @@ const normalizeGlobalSettings = (settings) => ({
43
40
  disableVip: coerceBool(settings?.disableVip, constants_1.defaultGlobalSettings.disableVip),
44
41
  maintenanceMode: coerceBool(settings?.maintenanceMode, constants_1.defaultGlobalSettings.maintenanceMode),
45
42
  timezone: normalizeTimezone(settings?.timezone),
46
- currencyCode: trimCurrencyCode(settings?.currencyCode),
47
- currencySymbol: trimCurrencySymbol(settings?.currencySymbol),
43
+ currencySymbol: normalizeCurrencySymbol(settings?.currencySymbol),
48
44
  currencyPlacement: normalizeCurrencyPlacement(settings?.currencyPlacement)
49
45
  });
50
46
  exports.normalizeGlobalSettings = normalizeGlobalSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gambling-bot-shared",
3
- "version": "0.1.48",
3
+ "version": "0.1.51",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
@@ -24,9 +24,15 @@
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsc -p tsconfig.json",
27
+ "dev": "tsc -p tsconfig.json --watch",
27
28
  "prepublishOnly": "pnpm build",
28
- "publish-and-bump-projects": "bash scripts/publish-to-npm.sh",
29
- "release": "npm version patch && npm publish"
29
+ "prepare": "bash scripts/setup-git-hooks.sh",
30
+ "link-local": "bash scripts/link-local.sh",
31
+ "unlink-local": "bash scripts/unlink-local.sh",
32
+ "link-status": "bash scripts/shared-link-status.sh",
33
+ "release": "bash scripts/release.sh",
34
+ "publish-and-bump-projects": "bash scripts/release.sh --no-bump",
35
+ "publish-to-npm": "bash scripts/publish-to-npm.sh"
30
36
  },
31
37
  "peerDependencies": {
32
38
  "mongoose": "^9.0.0"