@stevenkellner/team-conduct-api 1.0.36 → 2.0.1
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/lib/src/firebase/FirebaseConfiguration.d.ts +45 -1
- package/lib/src/firebase/FirebaseConfiguration.js +44 -0
- package/lib/src/firebase/Firestore.d.ts +196 -0
- package/lib/src/firebase/Firestore.js +235 -0
- package/lib/src/{FirestoreScheme.d.ts → firebase/FirestoreScheme.d.ts} +15 -1
- package/lib/src/firebase/Messaging.d.ts +64 -0
- package/lib/src/firebase/checkAuthentication.d.ts +37 -0
- package/lib/src/{checkAuthentication.js → firebase/checkAuthentication.js} +26 -1
- package/lib/src/firebase/index.d.ts +4 -0
- package/lib/src/firebase/index.js +4 -0
- package/lib/src/firebase/pushNotification.d.ts +39 -0
- package/lib/src/firebase/pushNotification.js +88 -0
- package/lib/src/functions/fine/add.d.ts +10 -13
- package/lib/src/functions/fine/add.js +3 -30
- package/lib/src/functions/fine/delete.d.ts +10 -13
- package/lib/src/functions/fine/delete.js +3 -27
- package/lib/src/functions/fine/update.d.ts +10 -13
- package/lib/src/functions/fine/update.js +3 -28
- package/lib/src/functions/fineTemplate/add.d.ts +6 -9
- package/lib/src/functions/fineTemplate/add.js +3 -12
- package/lib/src/functions/fineTemplate/delete.d.ts +6 -9
- package/lib/src/functions/fineTemplate/delete.js +3 -12
- package/lib/src/functions/fineTemplate/update.d.ts +6 -9
- package/lib/src/functions/fineTemplate/update.js +3 -12
- package/lib/src/functions/invitation/getInvitation.d.ts +40 -43
- package/lib/src/functions/invitation/getInvitation.js +57 -88
- package/lib/src/functions/invitation/invite.d.ts +1 -2
- package/lib/src/functions/invitation/invite.js +3 -18
- package/lib/src/functions/invitation/register.d.ts +6 -11
- package/lib/src/functions/invitation/register.js +3 -39
- package/lib/src/functions/invitation/withdraw.d.ts +1 -2
- package/lib/src/functions/invitation/withdraw.js +3 -13
- package/lib/src/functions/notification/register.d.ts +7 -10
- package/lib/src/functions/notification/register.js +3 -15
- package/lib/src/functions/notification/subscribe.d.ts +8 -11
- package/lib/src/functions/notification/subscribe.js +3 -14
- package/lib/src/functions/paypalMe/edit.d.ts +6 -9
- package/lib/src/functions/paypalMe/edit.js +3 -14
- package/lib/src/functions/person/add.d.ts +7 -10
- package/lib/src/functions/person/add.js +3 -12
- package/lib/src/functions/person/delete.d.ts +6 -9
- package/lib/src/functions/person/delete.js +3 -14
- package/lib/src/functions/person/update.d.ts +7 -10
- package/lib/src/functions/person/update.js +3 -13
- package/lib/src/functions/team/new.d.ts +9 -12
- package/lib/src/functions/team/new.js +3 -22
- package/lib/src/functions/user/kickout.d.ts +6 -9
- package/lib/src/functions/user/kickout.js +3 -25
- package/lib/src/functions/user/login.d.ts +1 -2
- package/lib/src/functions/user/login.js +3 -13
- package/lib/src/functions/user/roleEdit.d.ts +8 -11
- package/lib/src/functions/user/roleEdit.js +3 -18
- package/lib/src/index.d.ts +0 -5
- package/lib/src/index.js +0 -5
- package/lib/src/locales/de.d.ts +10 -67
- package/lib/src/locales/de.js +8 -0
- package/lib/src/locales/en.d.ts +10 -0
- package/lib/src/locales/en.js +19 -2
- package/lib/src/types/Configuration.d.ts +33 -15
- package/lib/src/types/Configuration.js +24 -12
- package/lib/src/types/Currency.d.ts +20 -0
- package/lib/src/types/Currency.js +19 -0
- package/lib/src/types/Fine.d.ts +41 -0
- package/lib/src/types/Fine.js +32 -0
- package/lib/src/types/FineAmount.d.ts +160 -9
- package/lib/src/types/FineAmount.js +128 -7
- package/lib/src/types/FineTemplate.d.ts +41 -0
- package/lib/src/types/FineTemplate.js +32 -0
- package/lib/src/types/FineTemplateRepetition.d.ts +72 -10
- package/lib/src/types/FineTemplateRepetition.js +66 -12
- package/lib/src/types/Invitation.d.ts +48 -0
- package/lib/src/types/Invitation.js +39 -0
- package/lib/src/types/Locale.d.ts +16 -0
- package/lib/src/types/Locale.js +16 -0
- package/lib/src/types/Localization.d.ts +74 -74
- package/lib/src/types/Localization.js +80 -41
- package/lib/src/types/MoneyAmount.d.ts +67 -1
- package/lib/src/types/MoneyAmount.js +62 -0
- package/lib/src/types/NotificationProperties.d.ts +70 -9
- package/lib/src/types/NotificationProperties.js +49 -5
- package/lib/src/types/PayedState.d.ts +25 -9
- package/lib/src/types/PayedState.js +17 -27
- package/lib/src/types/Person.d.ts +45 -0
- package/lib/src/types/Person.js +36 -0
- package/lib/src/types/PersonPrivateProperties.d.ts +28 -0
- package/lib/src/types/PersonPrivateProperties.js +25 -0
- package/lib/src/types/PersonSignInProperties.d.ts +30 -0
- package/lib/src/types/PersonSignInProperties.js +27 -0
- package/lib/src/types/Pluralization.d.ts +46 -0
- package/lib/src/types/Pluralization.js +46 -0
- package/lib/src/types/Team.d.ts +38 -0
- package/lib/src/types/Team.js +29 -0
- package/lib/src/types/User.d.ts +68 -3
- package/lib/src/types/User.js +59 -5
- package/lib/src/types/UserRole.d.ts +26 -4
- package/lib/src/types/UserRole.js +25 -9
- package/lib/src/types/index.d.ts +2 -0
- package/lib/src/types/index.js +2 -0
- package/lib/test/firebase/FirebaseConfiguration.test.js +155 -0
- package/lib/test/firebase/Firestore.test.js +46 -0
- package/lib/test/firebase/checkAuthentication.test.d.ts +1 -0
- package/lib/test/firebase/checkAuthentication.test.js +305 -0
- package/lib/test/firebase/firebase-utils.d.ts +32 -0
- package/lib/test/firebase/firebase-utils.js +131 -0
- package/lib/test/firebase/pushNotification.test.d.ts +1 -0
- package/lib/test/firebase/pushNotification.test.js +300 -0
- package/lib/test/locales/localization.de.test.d.ts +1 -0
- package/lib/test/locales/localization.de.test.js +144 -0
- package/lib/test/locales/localization.en.test.d.ts +1 -0
- package/lib/test/locales/localization.en.test.js +144 -0
- package/lib/test/types/Configuration.test.d.ts +1 -0
- package/lib/test/types/Configuration.test.js +84 -0
- package/lib/test/types/Currency.test.d.ts +1 -0
- package/lib/test/types/Currency.test.js +41 -0
- package/lib/test/types/Fine.test.d.ts +1 -0
- package/lib/test/types/Fine.test.js +265 -0
- package/lib/test/types/FineAmount.test.d.ts +1 -0
- package/lib/test/types/FineAmount.test.js +445 -0
- package/lib/test/types/FineTemplate.test.d.ts +1 -0
- package/lib/test/types/FineTemplate.test.js +271 -0
- package/lib/test/types/FineTemplateRepetition.test.d.ts +1 -0
- package/lib/test/types/FineTemplateRepetition.test.js +361 -0
- package/lib/test/types/Invitation.test.d.ts +1 -0
- package/lib/test/types/Invitation.test.js +269 -0
- package/lib/test/types/Locale.test.d.ts +1 -0
- package/lib/test/types/Locale.test.js +46 -0
- package/lib/test/types/Localization.test.d.ts +1 -0
- package/lib/test/types/Localization.test.js +241 -0
- package/lib/test/types/MoneyAmount.test.d.ts +1 -0
- package/lib/test/types/MoneyAmount.test.js +276 -0
- package/lib/test/types/NotificationProperties.test.d.ts +1 -0
- package/lib/test/types/NotificationProperties.test.js +258 -0
- package/lib/test/types/PayedState.test.d.ts +1 -0
- package/lib/test/types/PayedState.test.js +105 -0
- package/lib/test/types/Person.test.d.ts +1 -0
- package/lib/test/types/Person.test.js +266 -0
- package/lib/test/types/PersonPrivateProperties.test.d.ts +1 -0
- package/lib/test/types/PersonPrivateProperties.test.js +155 -0
- package/lib/test/types/PersonSignInProperties.test.d.ts +1 -0
- package/lib/test/types/PersonSignInProperties.test.js +208 -0
- package/lib/test/types/Pluralization.test.d.ts +1 -0
- package/lib/test/types/Pluralization.test.js +206 -0
- package/lib/test/types/Team.test.d.ts +1 -0
- package/lib/test/types/Team.test.js +145 -0
- package/lib/test/types/User.test.d.ts +1 -0
- package/lib/test/types/User.test.js +232 -0
- package/lib/test/types/UserRole.test.d.ts +1 -0
- package/lib/test/types/UserRole.test.js +140 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/src/firebase/FirebaseConfiguration.ts +49 -1
- package/src/firebase/Firestore.ts +248 -0
- package/src/{FirestoreScheme.ts → firebase/FirestoreScheme.ts} +15 -1
- package/src/firebase/Messaging.ts +64 -0
- package/src/{checkAuthentication.ts → firebase/checkAuthentication.ts} +39 -1
- package/src/firebase/index.ts +5 -0
- package/src/firebase/pushNotification.ts +90 -0
- package/src/functions/fine/add.ts +10 -48
- package/src/functions/fine/delete.ts +9 -43
- package/src/functions/fine/update.ts +10 -44
- package/src/functions/fineTemplate/add.ts +7 -23
- package/src/functions/fineTemplate/delete.ts +7 -23
- package/src/functions/fineTemplate/update.ts +7 -24
- package/src/functions/index.ts +0 -1
- package/src/functions/invitation/getInvitation.ts +81 -118
- package/src/functions/invitation/invite.ts +2 -25
- package/src/functions/invitation/register.ts +9 -60
- package/src/functions/invitation/withdraw.ts +2 -16
- package/src/functions/notification/register.ts +7 -26
- package/src/functions/notification/subscribe.ts +8 -26
- package/src/functions/paypalMe/edit.ts +7 -25
- package/src/functions/person/add.ts +8 -24
- package/src/functions/person/delete.ts +6 -25
- package/src/functions/person/update.ts +8 -25
- package/src/functions/team/new.ts +12 -42
- package/src/functions/user/kickout.ts +8 -41
- package/src/functions/user/login.ts +2 -16
- package/src/functions/user/roleEdit.ts +8 -32
- package/src/index.ts +0 -5
- package/src/locales/de.ts +10 -1
- package/src/locales/en.ts +21 -2
- package/src/types/Configuration.ts +33 -23
- package/src/types/Currency.ts +24 -0
- package/src/types/Fine.ts +41 -0
- package/src/types/FineAmount.ts +162 -11
- package/src/types/FineTemplate.ts +41 -0
- package/src/types/FineTemplateRepetition.ts +75 -17
- package/src/types/Invitation.ts +48 -0
- package/src/types/Locale.ts +20 -0
- package/src/types/Localization.ts +96 -41
- package/src/types/MoneyAmount.ts +67 -1
- package/src/types/NotificationProperties.ts +67 -9
- package/src/types/PayedState.ts +25 -30
- package/src/types/Person.ts +45 -0
- package/src/types/PersonPrivateProperties.ts +28 -1
- package/src/types/PersonSignInProperties.ts +30 -0
- package/src/types/Pluralization.ts +46 -0
- package/src/types/Team.ts +38 -0
- package/src/types/User.ts +70 -4
- package/src/types/UserRole.ts +32 -16
- package/src/types/index.ts +2 -0
- package/lib/src/Firestore.d.ts +0 -24
- package/lib/src/Firestore.js +0 -62
- package/lib/src/checkAuthentication.d.ts +0 -6
- package/lib/src/firebaseFunctionsContext.d.ts +0 -39
- package/lib/src/firebaseFunctionsContext.js +0 -43
- package/lib/src/pushNotification.d.ts +0 -3
- package/lib/src/pushNotification.js +0 -35
- package/lib/test/localization-utils.d.ts +0 -1
- package/lib/test/localization-utils.js +0 -24
- package/lib/test/localization.de.test.js +0 -151
- package/lib/test/localization.en.test.js +0 -145
- package/src/Firestore.ts +0 -75
- package/src/firebaseFunctionsContext.ts +0 -48
- package/src/pushNotification.ts +0 -37
- /package/lib/src/{FirestoreScheme.js → firebase/FirestoreScheme.js} +0 -0
- /package/lib/test/{localization.de.test.d.ts → firebase/FirebaseConfiguration.test.d.ts} +0 -0
- /package/lib/test/{localization.en.test.d.ts → firebase/Firestore.test.d.ts} +0 -0
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { localizationEN } from '../locales/en';
|
|
1
2
|
import { Pluralization } from './Pluralization';
|
|
3
|
+
import { Locale } from './Locale';
|
|
4
|
+
/**
|
|
5
|
+
* Type representing the structure of a localization dictionary.
|
|
6
|
+
* Derived from the English localization as the base template.
|
|
7
|
+
*/
|
|
8
|
+
export type LocalizationDict = typeof localizationEN;
|
|
9
|
+
/**
|
|
10
|
+
* Record of all available localizations keyed by locale.
|
|
11
|
+
* Each localization must match the structure of LocalizationDict.
|
|
12
|
+
*/
|
|
2
13
|
export declare const localizations: {
|
|
3
14
|
en: {
|
|
4
15
|
notification: {
|
|
@@ -133,91 +144,80 @@ export declare const localizations: {
|
|
|
133
144
|
};
|
|
134
145
|
};
|
|
135
146
|
};
|
|
147
|
+
/**
|
|
148
|
+
* Recursive type definition for localization values.
|
|
149
|
+
* Can be nested objects, strings with template variables, or Pluralization instances.
|
|
150
|
+
*/
|
|
136
151
|
export type SubLocalizationType = {
|
|
137
152
|
[Key in string]: SubLocalizationType;
|
|
138
153
|
} | string | Pluralization;
|
|
154
|
+
/**
|
|
155
|
+
* Mapped type that transforms SubLocalizationType into corresponding localization classes.
|
|
156
|
+
* - Objects become nested SubLocalization structures
|
|
157
|
+
* - Strings become ValueLocalization instances
|
|
158
|
+
* - Pluralization instances become PluralLocalization instances
|
|
159
|
+
*/
|
|
139
160
|
export type SubLocalization<T extends SubLocalizationType> = T extends {
|
|
140
161
|
[Key in string]: SubLocalizationType;
|
|
141
162
|
} ? {
|
|
142
163
|
[Key in keyof T]: SubLocalization<T[Key]>;
|
|
143
164
|
} : T extends string ? ValueLocalization : T extends Pluralization ? PluralLocalization : never;
|
|
165
|
+
/**
|
|
166
|
+
* Main localization class that provides access to localized strings.
|
|
167
|
+
* Transforms raw localization data into type-safe localization objects.
|
|
168
|
+
*/
|
|
169
|
+
export declare class Localization {
|
|
170
|
+
/**
|
|
171
|
+
* Returns the localization structure for the specified locale.
|
|
172
|
+
* Transforms the raw localization data into ValueLocalization and PluralLocalization instances.
|
|
173
|
+
* @param locale - The locale to retrieve localizations for
|
|
174
|
+
* @returns The complete localization structure with type-safe access
|
|
175
|
+
*/
|
|
176
|
+
static shared(locale: Locale): SubLocalization<LocalizationDict>;
|
|
177
|
+
/**
|
|
178
|
+
* Recursively maps raw localization data to localization class instances.
|
|
179
|
+
* @param localization - The raw localization value to transform
|
|
180
|
+
* @returns The transformed localization with proper class instances
|
|
181
|
+
*/
|
|
182
|
+
private static mapSubLocalization;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Handles localization strings with template variable substitution.
|
|
186
|
+
* Supports {{variableName}} syntax for runtime value replacement.
|
|
187
|
+
*/
|
|
144
188
|
export declare class ValueLocalization {
|
|
145
|
-
private readonly
|
|
146
|
-
|
|
189
|
+
private readonly rawValue;
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new ValueLocalization instance.
|
|
192
|
+
* @param rawValue - The template string with {{variable}} placeholders
|
|
193
|
+
*/
|
|
194
|
+
constructor(rawValue: string);
|
|
195
|
+
/**
|
|
196
|
+
* Returns the localized string with variables substituted.
|
|
197
|
+
* Template variables in the format {{key}} are replaced with provided argument values.
|
|
198
|
+
* @param args - Record of variable names to their replacement values
|
|
199
|
+
* @returns The localized string with all variables replaced
|
|
200
|
+
* @throws Error if a required template variable is not provided in args
|
|
201
|
+
*/
|
|
147
202
|
value(args?: Record<string, string>): string;
|
|
148
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Handles pluralized localization strings that vary based on count.
|
|
206
|
+
* Combines Pluralization logic with template variable substitution.
|
|
207
|
+
*/
|
|
149
208
|
export declare class PluralLocalization {
|
|
150
|
-
private readonly
|
|
151
|
-
|
|
209
|
+
private readonly pluralization;
|
|
210
|
+
/**
|
|
211
|
+
* Creates a new PluralLocalization instance.
|
|
212
|
+
* @param pluralization - The Pluralization instance containing plural forms
|
|
213
|
+
*/
|
|
214
|
+
constructor(pluralization: Pluralization);
|
|
215
|
+
/**
|
|
216
|
+
* Returns the appropriate pluralized string for the given count with variables substituted.
|
|
217
|
+
* Automatically includes 'count' in the template variables.
|
|
218
|
+
* @param count - The count to determine which plural form to use
|
|
219
|
+
* @param args - Additional template variables to substitute (count is added automatically)
|
|
220
|
+
* @returns The localized plural string with all variables replaced
|
|
221
|
+
*/
|
|
152
222
|
value(count: number, args?: Record<string, string>): string;
|
|
153
223
|
}
|
|
154
|
-
export declare class Localization {
|
|
155
|
-
static locale: keyof typeof localizations;
|
|
156
|
-
static readonly shared: {
|
|
157
|
-
notification: {
|
|
158
|
-
fine: {
|
|
159
|
-
new: {
|
|
160
|
-
title: ValueLocalization;
|
|
161
|
-
body: ValueLocalization;
|
|
162
|
-
};
|
|
163
|
-
reminder: {
|
|
164
|
-
title: ValueLocalization;
|
|
165
|
-
body: ValueLocalization;
|
|
166
|
-
};
|
|
167
|
-
stateChange: {
|
|
168
|
-
title: ValueLocalization;
|
|
169
|
-
bodyPayed: ValueLocalization;
|
|
170
|
-
bodyUnpayed: ValueLocalization;
|
|
171
|
-
bodyDeleted: ValueLocalization;
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
fineAmount: {
|
|
176
|
-
item: {
|
|
177
|
-
type: {
|
|
178
|
-
crateOfBeer: {
|
|
179
|
-
name: ValueLocalization;
|
|
180
|
-
withCount: PluralLocalization;
|
|
181
|
-
withoutCount: PluralLocalization;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
fineTemplateRepetition: {
|
|
187
|
-
item: {
|
|
188
|
-
minute: {
|
|
189
|
-
name: ValueLocalization;
|
|
190
|
-
withCount: PluralLocalization;
|
|
191
|
-
withoutCount: PluralLocalization;
|
|
192
|
-
};
|
|
193
|
-
day: {
|
|
194
|
-
name: ValueLocalization;
|
|
195
|
-
withCount: PluralLocalization;
|
|
196
|
-
withoutCount: PluralLocalization;
|
|
197
|
-
};
|
|
198
|
-
item: {
|
|
199
|
-
name: ValueLocalization;
|
|
200
|
-
withCount: PluralLocalization;
|
|
201
|
-
withoutCount: PluralLocalization;
|
|
202
|
-
};
|
|
203
|
-
count: {
|
|
204
|
-
name: ValueLocalization;
|
|
205
|
-
withCount: PluralLocalization;
|
|
206
|
-
withoutCount: PluralLocalization;
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
payedState: {
|
|
211
|
-
payed: ValueLocalization;
|
|
212
|
-
notPayed: ValueLocalization;
|
|
213
|
-
};
|
|
214
|
-
userRole: {
|
|
215
|
-
personManager: ValueLocalization;
|
|
216
|
-
fineTemplateManager: ValueLocalization;
|
|
217
|
-
fineManager: ValueLocalization;
|
|
218
|
-
fineCanAdd: ValueLocalization;
|
|
219
|
-
teamManager: ValueLocalization;
|
|
220
|
-
};
|
|
221
|
-
};
|
|
222
|
-
private static getSubLocalization;
|
|
223
|
-
}
|
|
@@ -1,21 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PluralLocalization = exports.ValueLocalization = exports.Localization = exports.localizations = void 0;
|
|
4
4
|
const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
|
|
5
5
|
const en_1 = require("../locales/en");
|
|
6
6
|
const de_1 = require("../locales/de");
|
|
7
7
|
const Pluralization_1 = require("./Pluralization");
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to ensure a record satisfies the localization structure
|
|
10
|
+
* while preserving its concrete type.
|
|
11
|
+
*/
|
|
12
|
+
const satisfiesLocalizationRecord = (value) => value;
|
|
13
|
+
/**
|
|
14
|
+
* Record of all available localizations keyed by locale.
|
|
15
|
+
* Each localization must match the structure of LocalizationDict.
|
|
16
|
+
*/
|
|
17
|
+
exports.localizations = satisfiesLocalizationRecord({
|
|
9
18
|
en: en_1.localizationEN,
|
|
10
19
|
de: de_1.localizationDE
|
|
11
|
-
};
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Main localization class that provides access to localized strings.
|
|
23
|
+
* Transforms raw localization data into type-safe localization objects.
|
|
24
|
+
*/
|
|
25
|
+
class Localization {
|
|
26
|
+
/**
|
|
27
|
+
* Returns the localization structure for the specified locale.
|
|
28
|
+
* Transforms the raw localization data into ValueLocalization and PluralLocalization instances.
|
|
29
|
+
* @param locale - The locale to retrieve localizations for
|
|
30
|
+
* @returns The complete localization structure with type-safe access
|
|
31
|
+
*/
|
|
32
|
+
static shared(locale) {
|
|
33
|
+
return Localization.mapSubLocalization(exports.localizations[locale]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Recursively maps raw localization data to localization class instances.
|
|
37
|
+
* @param localization - The raw localization value to transform
|
|
38
|
+
* @returns The transformed localization with proper class instances
|
|
39
|
+
*/
|
|
40
|
+
static mapSubLocalization(localization) {
|
|
41
|
+
if (typeof localization === 'object' && !(localization instanceof Pluralization_1.Pluralization))
|
|
42
|
+
return (0, typescript_common_functionality_1.mapRecord)(localization, subLocalization => Localization.mapSubLocalization(subLocalization));
|
|
43
|
+
if (typeof localization === 'string')
|
|
44
|
+
return new ValueLocalization(localization);
|
|
45
|
+
if (localization instanceof Pluralization_1.Pluralization)
|
|
46
|
+
return new PluralLocalization(localization);
|
|
47
|
+
throw new Error('Invalid localization structure');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Localization = Localization;
|
|
51
|
+
/**
|
|
52
|
+
* Handles localization strings with template variable substitution.
|
|
53
|
+
* Supports {{variableName}} syntax for runtime value replacement.
|
|
54
|
+
*/
|
|
12
55
|
class ValueLocalization {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
56
|
+
rawValue;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new ValueLocalization instance.
|
|
59
|
+
* @param rawValue - The template string with {{variable}} placeholders
|
|
60
|
+
*/
|
|
61
|
+
constructor(rawValue) {
|
|
62
|
+
this.rawValue = rawValue;
|
|
16
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the localized string with variables substituted.
|
|
66
|
+
* Template variables in the format {{key}} are replaced with provided argument values.
|
|
67
|
+
* @param args - Record of variable names to their replacement values
|
|
68
|
+
* @returns The localized string with all variables replaced
|
|
69
|
+
* @throws Error if a required template variable is not provided in args
|
|
70
|
+
*/
|
|
17
71
|
value(args = {}) {
|
|
18
|
-
let rawValue = this.
|
|
72
|
+
let rawValue = this.rawValue;
|
|
19
73
|
const regex = /\{\{(?<key>.*?)\}\}/;
|
|
20
74
|
while (true) {
|
|
21
75
|
const match = regex.exec(rawValue);
|
|
@@ -30,13 +84,28 @@ class ValueLocalization {
|
|
|
30
84
|
}
|
|
31
85
|
}
|
|
32
86
|
exports.ValueLocalization = ValueLocalization;
|
|
87
|
+
/**
|
|
88
|
+
* Handles pluralized localization strings that vary based on count.
|
|
89
|
+
* Combines Pluralization logic with template variable substitution.
|
|
90
|
+
*/
|
|
33
91
|
class PluralLocalization {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
92
|
+
pluralization;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new PluralLocalization instance.
|
|
95
|
+
* @param pluralization - The Pluralization instance containing plural forms
|
|
96
|
+
*/
|
|
97
|
+
constructor(pluralization) {
|
|
98
|
+
this.pluralization = pluralization;
|
|
37
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the appropriate pluralized string for the given count with variables substituted.
|
|
102
|
+
* Automatically includes 'count' in the template variables.
|
|
103
|
+
* @param count - The count to determine which plural form to use
|
|
104
|
+
* @param args - Additional template variables to substitute (count is added automatically)
|
|
105
|
+
* @returns The localized plural string with all variables replaced
|
|
106
|
+
*/
|
|
38
107
|
value(count, args = {}) {
|
|
39
|
-
const valueLocalization = new ValueLocalization(
|
|
108
|
+
const valueLocalization = new ValueLocalization(this.pluralization.get(count));
|
|
40
109
|
return valueLocalization.value({
|
|
41
110
|
count: `${count}`,
|
|
42
111
|
...args
|
|
@@ -44,33 +113,3 @@ class PluralLocalization {
|
|
|
44
113
|
}
|
|
45
114
|
}
|
|
46
115
|
exports.PluralLocalization = PluralLocalization;
|
|
47
|
-
function swap1stAnd2ndLevel(record) {
|
|
48
|
-
const swapped = {};
|
|
49
|
-
for (const key1 of (0, typescript_common_functionality_1.keys)(record)) {
|
|
50
|
-
for (const key2 of (0, typescript_common_functionality_1.keys)(record[key1])) {
|
|
51
|
-
if (!(key2 in swapped))
|
|
52
|
-
swapped[key2] = {};
|
|
53
|
-
swapped[key2][key1] = record[key1][key2];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return swapped;
|
|
57
|
-
}
|
|
58
|
-
class Localization {
|
|
59
|
-
static locale = 'en';
|
|
60
|
-
static shared = Localization.getSubLocalization(exports.localizations);
|
|
61
|
-
static getSubLocalization(_localizations) {
|
|
62
|
-
const _localizationValue = (0, typescript_common_functionality_1.values)(_localizations);
|
|
63
|
-
if (_localizationValue.length === 0)
|
|
64
|
-
return {};
|
|
65
|
-
if (typeof _localizationValue[0] === 'object' && !(_localizationValue[0] instanceof Pluralization_1.Pluralization)) {
|
|
66
|
-
const swapped = swap1stAnd2ndLevel(_localizations);
|
|
67
|
-
return (0, typescript_common_functionality_1.mapRecord)(swapped, subLocalization => Localization.getSubLocalization(subLocalization));
|
|
68
|
-
}
|
|
69
|
-
if (typeof _localizationValue[0] === 'string')
|
|
70
|
-
return new ValueLocalization(_localizations);
|
|
71
|
-
if (_localizationValue[0] instanceof Pluralization_1.Pluralization)
|
|
72
|
-
return new PluralLocalization(_localizations);
|
|
73
|
-
throw new Error('Invalid localization structure');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.Localization = Localization;
|
|
@@ -1,20 +1,86 @@
|
|
|
1
1
|
import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
2
|
import { Configuration } from './Configuration';
|
|
3
|
+
import { Currency } from './Currency';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a monetary amount with integer value and subunit components.
|
|
6
|
+
*
|
|
7
|
+
* Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
|
|
8
|
+
* This prevents floating-point precision issues in financial calculations.
|
|
9
|
+
*/
|
|
3
10
|
export declare class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
|
|
4
11
|
value: number;
|
|
5
12
|
subunitValue: number;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new MoneyAmount instance.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The main value (e.g., dollars, euros)
|
|
17
|
+
* @param subunitValue - The subunit value (e.g., cents), should be 0-99
|
|
18
|
+
*/
|
|
6
19
|
constructor(value: number, subunitValue: number);
|
|
20
|
+
/**
|
|
21
|
+
* Returns a MoneyAmount representing zero.
|
|
22
|
+
*/
|
|
7
23
|
static get zero(): MoneyAmount;
|
|
24
|
+
/**
|
|
25
|
+
* Adds another MoneyAmount to this one and returns the result.
|
|
26
|
+
*
|
|
27
|
+
* Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
|
|
28
|
+
*
|
|
29
|
+
* @param amount - The MoneyAmount to add
|
|
30
|
+
* @returns A new MoneyAmount representing the sum
|
|
31
|
+
*/
|
|
8
32
|
added(amount: MoneyAmount): MoneyAmount;
|
|
33
|
+
/**
|
|
34
|
+
* Multiplies this MoneyAmount by a factor and returns the result.
|
|
35
|
+
*
|
|
36
|
+
* Properly handles subunit calculations and overflow.
|
|
37
|
+
*
|
|
38
|
+
* @param factor - The multiplication factor
|
|
39
|
+
* @returns A new MoneyAmount representing the product
|
|
40
|
+
*/
|
|
9
41
|
multiplied(factor: number): MoneyAmount;
|
|
10
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Returns a localized formatted string representation of the amount.
|
|
44
|
+
*
|
|
45
|
+
* Uses Intl.NumberFormat for proper currency formatting based on locale.
|
|
46
|
+
*
|
|
47
|
+
* @param currency - The currency code (e.g., 'USD', 'EUR')
|
|
48
|
+
* @param configuration - Configuration containing locale information
|
|
49
|
+
* @returns Formatted currency string (e.g., "$12.50", "12,50 €")
|
|
50
|
+
*/
|
|
51
|
+
formatted(currency: Currency, configuration: Configuration): string;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the complete monetary value as a decimal number.
|
|
54
|
+
*
|
|
55
|
+
* @returns The total value (e.g., 12.50 for 12 dollars and 50 cents)
|
|
56
|
+
*/
|
|
11
57
|
get completeValue(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the flattened representation as a decimal number.
|
|
60
|
+
*/
|
|
12
61
|
get flatten(): MoneyAmount.Flatten;
|
|
13
62
|
}
|
|
14
63
|
export declare namespace MoneyAmount {
|
|
64
|
+
/**
|
|
65
|
+
* Flattened representation of MoneyAmount as a decimal number.
|
|
66
|
+
*/
|
|
15
67
|
type Flatten = number;
|
|
68
|
+
/**
|
|
69
|
+
* Type builder for MoneyAmount serialization/deserialization.
|
|
70
|
+
*/
|
|
16
71
|
class TypeBuilder implements ITypeBuilder<Flatten, MoneyAmount> {
|
|
72
|
+
/**
|
|
73
|
+
* Builds a MoneyAmount instance from a flattened decimal value.
|
|
74
|
+
*
|
|
75
|
+
* Separates the decimal into integer and subunit parts.
|
|
76
|
+
*
|
|
77
|
+
* @param value - Decimal value (e.g., 12.50)
|
|
78
|
+
* @returns MoneyAmount instance
|
|
79
|
+
*/
|
|
17
80
|
build(value: Flatten): MoneyAmount;
|
|
18
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Singleton instance of TypeBuilder for MoneyAmount.
|
|
84
|
+
*/
|
|
19
85
|
const builder: TypeBuilder;
|
|
20
86
|
}
|
|
@@ -1,26 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MoneyAmount = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a monetary amount with integer value and subunit components.
|
|
6
|
+
*
|
|
7
|
+
* Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
|
|
8
|
+
* This prevents floating-point precision issues in financial calculations.
|
|
9
|
+
*/
|
|
4
10
|
class MoneyAmount {
|
|
5
11
|
value;
|
|
6
12
|
subunitValue;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new MoneyAmount instance.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The main value (e.g., dollars, euros)
|
|
17
|
+
* @param subunitValue - The subunit value (e.g., cents), should be 0-99
|
|
18
|
+
*/
|
|
7
19
|
constructor(value, subunitValue) {
|
|
8
20
|
this.value = value;
|
|
9
21
|
this.subunitValue = subunitValue;
|
|
10
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns a MoneyAmount representing zero.
|
|
25
|
+
*/
|
|
11
26
|
static get zero() {
|
|
12
27
|
return new MoneyAmount(0, 0);
|
|
13
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Adds another MoneyAmount to this one and returns the result.
|
|
31
|
+
*
|
|
32
|
+
* Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
|
|
33
|
+
*
|
|
34
|
+
* @param amount - The MoneyAmount to add
|
|
35
|
+
* @returns A new MoneyAmount representing the sum
|
|
36
|
+
*/
|
|
14
37
|
added(amount) {
|
|
15
38
|
const subunitValue = this.subunitValue + amount.subunitValue;
|
|
16
39
|
const value = this.value + amount.value + Math.floor(subunitValue / 100);
|
|
17
40
|
return new MoneyAmount(value, subunitValue % 100);
|
|
18
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Multiplies this MoneyAmount by a factor and returns the result.
|
|
44
|
+
*
|
|
45
|
+
* Properly handles subunit calculations and overflow.
|
|
46
|
+
*
|
|
47
|
+
* @param factor - The multiplication factor
|
|
48
|
+
* @returns A new MoneyAmount representing the product
|
|
49
|
+
*/
|
|
19
50
|
multiplied(factor) {
|
|
20
51
|
const subunitValue = this.subunitValue * factor;
|
|
21
52
|
const value = this.value * factor + Math.floor(subunitValue / 100);
|
|
22
53
|
return new MoneyAmount(value, subunitValue % 100);
|
|
23
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns a localized formatted string representation of the amount.
|
|
57
|
+
*
|
|
58
|
+
* Uses Intl.NumberFormat for proper currency formatting based on locale.
|
|
59
|
+
*
|
|
60
|
+
* @param currency - The currency code (e.g., 'USD', 'EUR')
|
|
61
|
+
* @param configuration - Configuration containing locale information
|
|
62
|
+
* @returns Formatted currency string (e.g., "$12.50", "12,50 €")
|
|
63
|
+
*/
|
|
24
64
|
formatted(currency, configuration) {
|
|
25
65
|
const numberFormat = Intl.NumberFormat(configuration.locale, {
|
|
26
66
|
style: 'currency',
|
|
@@ -28,20 +68,42 @@ class MoneyAmount {
|
|
|
28
68
|
});
|
|
29
69
|
return numberFormat.format(this.value + this.subunitValue / 100);
|
|
30
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns the complete monetary value as a decimal number.
|
|
73
|
+
*
|
|
74
|
+
* @returns The total value (e.g., 12.50 for 12 dollars and 50 cents)
|
|
75
|
+
*/
|
|
31
76
|
get completeValue() {
|
|
32
77
|
return this.value + this.subunitValue / 100;
|
|
33
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns the flattened representation as a decimal number.
|
|
81
|
+
*/
|
|
34
82
|
get flatten() {
|
|
35
83
|
return this.value + this.subunitValue / 100;
|
|
36
84
|
}
|
|
37
85
|
}
|
|
38
86
|
exports.MoneyAmount = MoneyAmount;
|
|
39
87
|
(function (MoneyAmount) {
|
|
88
|
+
/**
|
|
89
|
+
* Type builder for MoneyAmount serialization/deserialization.
|
|
90
|
+
*/
|
|
40
91
|
class TypeBuilder {
|
|
92
|
+
/**
|
|
93
|
+
* Builds a MoneyAmount instance from a flattened decimal value.
|
|
94
|
+
*
|
|
95
|
+
* Separates the decimal into integer and subunit parts.
|
|
96
|
+
*
|
|
97
|
+
* @param value - Decimal value (e.g., 12.50)
|
|
98
|
+
* @returns MoneyAmount instance
|
|
99
|
+
*/
|
|
41
100
|
build(value) {
|
|
42
101
|
return new MoneyAmount(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
|
|
43
102
|
}
|
|
44
103
|
}
|
|
45
104
|
MoneyAmount.TypeBuilder = TypeBuilder;
|
|
105
|
+
/**
|
|
106
|
+
* Singleton instance of TypeBuilder for MoneyAmount.
|
|
107
|
+
*/
|
|
46
108
|
MoneyAmount.builder = new MoneyAmount.TypeBuilder();
|
|
47
109
|
})(MoneyAmount || (exports.MoneyAmount = MoneyAmount = {}));
|
|
@@ -1,28 +1,89 @@
|
|
|
1
1
|
import { Dictionary, Flattable, ITypeBuilder, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
|
|
2
|
+
/**
|
|
3
|
+
* Represents notification properties for a user including device tokens and subscription preferences.
|
|
4
|
+
*
|
|
5
|
+
* Manages push notification device tokens (identified by hashed token IDs for security)
|
|
6
|
+
* and user preferences for which types of notifications they want to receive.
|
|
7
|
+
*/
|
|
2
8
|
export declare class NotificationProperties implements Flattable<NotificationProperties.Flatten> {
|
|
3
9
|
tokens: Dictionary<NotificationProperties.TokenId, string>;
|
|
4
10
|
subscriptions: NotificationProperties.Subscription[];
|
|
11
|
+
/**
|
|
12
|
+
* Creates new notification properties.
|
|
13
|
+
* @param tokens - Dictionary mapping token IDs to device tokens for push notifications (defaults to empty)
|
|
14
|
+
* @param subscriptions - Array of notification types the user is subscribed to (defaults to empty)
|
|
15
|
+
*/
|
|
5
16
|
constructor(tokens?: Dictionary<NotificationProperties.TokenId, string>, subscriptions?: NotificationProperties.Subscription[]);
|
|
17
|
+
/**
|
|
18
|
+
* Gets the flattened representation of these notification properties for serialization.
|
|
19
|
+
*/
|
|
6
20
|
get flatten(): NotificationProperties.Flatten;
|
|
7
21
|
}
|
|
8
22
|
export declare namespace NotificationProperties {
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Tagged type for notification token identifiers.
|
|
25
|
+
* Token IDs are derived from hashing the actual device tokens for security.
|
|
26
|
+
*/
|
|
27
|
+
export type TokenId = Tagged<string, 'notificationToken'>;
|
|
28
|
+
export namespace TokenId {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a token ID from a device token by hashing it with SHA-512.
|
|
31
|
+
* Only the first 16 characters of the hash are used as the identifier.
|
|
32
|
+
* @param token - The device push notification token
|
|
33
|
+
* @returns A hashed token ID for secure storage and lookup
|
|
34
|
+
*/
|
|
11
35
|
function create(token: string): TokenId;
|
|
36
|
+
/**
|
|
37
|
+
* Flattened representation of a token ID (plain string).
|
|
38
|
+
*/
|
|
12
39
|
type Flatten = string;
|
|
40
|
+
/**
|
|
41
|
+
* Builder for constructing TokenId instances from strings.
|
|
42
|
+
*/
|
|
13
43
|
const builder: Tagged.TypeBuilder<string, "notificationToken">;
|
|
14
44
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Available notification subscription types.
|
|
47
|
+
*/
|
|
48
|
+
const subscriptions: readonly ["new-fine", "fine-reminder", "fine-state-change"];
|
|
49
|
+
/**
|
|
50
|
+
* Type representing the available notification subscription options.
|
|
51
|
+
* - new-fine: Notifications when a new fine is created
|
|
52
|
+
* - fine-reminder: Reminder notifications for unpaid fines
|
|
53
|
+
* - fine-state-change: Notifications when a fine's status changes
|
|
54
|
+
*/
|
|
55
|
+
export type Subscription = typeof subscriptions[number];
|
|
56
|
+
export namespace Subscription {
|
|
57
|
+
/**
|
|
58
|
+
* Readonly array of all available subscription types.
|
|
59
|
+
*/
|
|
60
|
+
const all: readonly Subscription[];
|
|
61
|
+
/**
|
|
62
|
+
* Builder for constructing Subscription values from strings.
|
|
63
|
+
*/
|
|
64
|
+
const builder: ValueTypeBuilder<"new-fine" | "fine-reminder" | "fine-state-change">;
|
|
19
65
|
}
|
|
20
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Flattened representation of notification properties for serialization.
|
|
68
|
+
*/
|
|
69
|
+
export type Flatten = {
|
|
21
70
|
tokens: Dictionary.Flatten<string>;
|
|
22
71
|
subscriptions: Subscription[];
|
|
23
72
|
};
|
|
24
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Builder for constructing NotificationProperties from flattened data.
|
|
75
|
+
*/
|
|
76
|
+
export class TypeBuilder implements ITypeBuilder<Flatten, NotificationProperties> {
|
|
77
|
+
/**
|
|
78
|
+
* Builds a NotificationProperties instance from flattened data.
|
|
79
|
+
* @param value - The flattened notification properties data
|
|
80
|
+
* @returns A new NotificationProperties instance
|
|
81
|
+
*/
|
|
25
82
|
build(value: Flatten): NotificationProperties;
|
|
26
83
|
}
|
|
27
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Singleton builder instance for NotificationProperties.
|
|
86
|
+
*/
|
|
87
|
+
export const builder: TypeBuilder;
|
|
88
|
+
export {};
|
|
28
89
|
}
|