zibri 1.7.0 → 2.0.0
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/dist/index.d.mts +1763 -226
- package/dist/index.d.ts +1763 -226
- package/dist/index.js +8495 -5628
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9992 -7158
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -23
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,36 @@ import { Readable } from 'stream';
|
|
|
10
10
|
import { Transporter } from 'nodemailer';
|
|
11
11
|
import SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
12
12
|
import { Counter, Gauge, Histogram } from 'prom-client';
|
|
13
|
+
import { ImageDefinition, TDocumentDefinitions, Content, Column } from 'pdfmake/interfaces';
|
|
14
|
+
import BigNumberJs from 'bignumber.js';
|
|
15
|
+
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
|
16
|
+
import { BehaviorSubject } from 'rxjs';
|
|
17
|
+
import { Worker } from 'node:worker_threads';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Metadata for an Entity.
|
|
21
|
+
*/
|
|
22
|
+
type EntityMetadata = {
|
|
23
|
+
/**
|
|
24
|
+
* The name of the table in the db.
|
|
25
|
+
*/
|
|
26
|
+
tableName: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Marks an entity.
|
|
30
|
+
* @param tableName - The name of the table to generate for the entity.
|
|
31
|
+
*/
|
|
32
|
+
declare function Entity(tableName?: string): ClassDecorator;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The base entity that all db entities need to extend from.
|
|
36
|
+
*/
|
|
37
|
+
declare class BaseEntity {
|
|
38
|
+
/**
|
|
39
|
+
* The uuid (universal unique identifier) of the entity.
|
|
40
|
+
*/
|
|
41
|
+
id: string;
|
|
42
|
+
}
|
|
13
43
|
|
|
14
44
|
/**
|
|
15
45
|
* Metadata shared by all properties.
|
|
@@ -38,6 +68,13 @@ type WithDefaultMetadata<T extends string | number | boolean | Date> = {
|
|
|
38
68
|
default: T | (<X extends Object>(createData: X) => T | Promise<T>) | undefined;
|
|
39
69
|
};
|
|
40
70
|
|
|
71
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc['length']]>;
|
|
72
|
+
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
73
|
+
/**
|
|
74
|
+
* A number from 0 to 100.
|
|
75
|
+
*/
|
|
76
|
+
type Percentage = IntRange<0, 101>;
|
|
77
|
+
|
|
41
78
|
type Newable<T> = new (...args: any[]) => T;
|
|
42
79
|
|
|
43
80
|
type DeepPartial<T> = T | (T extends (infer U)[] ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
|
@@ -153,16 +190,6 @@ type ObjectPropertyMetadata = BasePropertyMetadata & {
|
|
|
153
190
|
*/
|
|
154
191
|
type ObjectPropertyMetadataInput = Partial<OmitStrict<ObjectPropertyMetadata, 'type'>> & Pick<ObjectPropertyMetadata, 'cls'>;
|
|
155
192
|
|
|
156
|
-
/**
|
|
157
|
-
* A base entity that all db entities need to implement.
|
|
158
|
-
*/
|
|
159
|
-
type BaseEntity = {
|
|
160
|
-
/**
|
|
161
|
-
* The id of the entity.
|
|
162
|
-
*/
|
|
163
|
-
id: string;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
193
|
/**
|
|
167
194
|
* Metadata for boolean properties.
|
|
168
195
|
*/
|
|
@@ -238,7 +265,7 @@ declare enum HttpStatus {
|
|
|
238
265
|
UNAUTHORIZED = 401,
|
|
239
266
|
PAYMENT_REQUIRED = 402,
|
|
240
267
|
FORBIDDEN = 403,
|
|
241
|
-
|
|
268
|
+
NOT_FOUND = 404,
|
|
242
269
|
METHOD_NOT_ALLOWED = 405,
|
|
243
270
|
NOT_ACCEPTABLE = 406,
|
|
244
271
|
CONFLICT = 409,
|
|
@@ -261,6 +288,7 @@ declare enum HttpStatus {
|
|
|
261
288
|
*/
|
|
262
289
|
declare enum MimeType {
|
|
263
290
|
JSON = "application/json",
|
|
291
|
+
XML = "application/xml",
|
|
264
292
|
HTML = "text/html",
|
|
265
293
|
FORM_DATA = "multipart/form-data",
|
|
266
294
|
OCTET_STREAM = "application/octet-stream",
|
|
@@ -368,6 +396,7 @@ declare const mimeTypeToExtension: {
|
|
|
368
396
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx";
|
|
369
397
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx";
|
|
370
398
|
"text/plain": ".txt";
|
|
399
|
+
"application/xml": ".xml";
|
|
371
400
|
};
|
|
372
401
|
/**
|
|
373
402
|
* Resolves the mime type of the file at the given path.
|
|
@@ -693,19 +722,11 @@ declare namespace Property {
|
|
|
693
722
|
declare function createArrayItemPropertyMetadata(data: ArrayPropertyItemMetadataInput, fullPropertyKey: string): ArrayPropertyItemMetadata;
|
|
694
723
|
|
|
695
724
|
/**
|
|
696
|
-
*
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* The name of the table in the db.
|
|
701
|
-
*/
|
|
702
|
-
tableName: string;
|
|
703
|
-
};
|
|
704
|
-
/**
|
|
705
|
-
* Marks an entity.
|
|
706
|
-
* @param tableName - The name of the table to generate for the entity.
|
|
725
|
+
* Defines a omit class based on the provided class.
|
|
726
|
+
* @param Base - The base class that should be made into a omit class.
|
|
727
|
+
* @param keys - The keys that should be omitted.
|
|
707
728
|
*/
|
|
708
|
-
declare function
|
|
729
|
+
declare function OmitClass<T, K extends keyof T>(Base: Newable<T>, keys: readonly K[]): Newable<Omit<T, K>>;
|
|
709
730
|
|
|
710
731
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
711
732
|
type IntersectionInstances<T extends Newable<unknown>[]> = UnionToIntersection<InstanceType<T[number]>>;
|
|
@@ -713,27 +734,20 @@ type IntersectionInstances<T extends Newable<unknown>[]> = UnionToIntersection<I
|
|
|
713
734
|
* Defines an combined class based on the provided classes.
|
|
714
735
|
* @param bases - The base classes that should be made into a single combined class.
|
|
715
736
|
*/
|
|
716
|
-
declare function
|
|
737
|
+
declare function IntersectionClass<Bases extends Newable<unknown>[]>(...bases: Bases): Newable<IntersectionInstances<Bases>>;
|
|
717
738
|
|
|
718
739
|
/**
|
|
719
740
|
* Defines a partial class based on the provided class.
|
|
720
741
|
* @param Base - The base class that should be made into a partial.
|
|
721
742
|
*/
|
|
722
|
-
declare function
|
|
743
|
+
declare function PartialClass<T>(Base: Newable<T>): Newable<Partial<T>>;
|
|
723
744
|
|
|
724
745
|
/**
|
|
725
746
|
* Defines a pick class based on the provided class.
|
|
726
747
|
* @param Base - The base class that should be made into a pick class.
|
|
727
748
|
* @param keys - The keys that should be picked from the base class.
|
|
728
749
|
*/
|
|
729
|
-
declare function
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* Defines a omit class based on the provided class.
|
|
733
|
-
* @param Base - The base class that should be made into a omit class.
|
|
734
|
-
* @param keys - The keys that should be omitted.
|
|
735
|
-
*/
|
|
736
|
-
declare function OmitType<T, K extends keyof T>(Base: Newable<T>, keys: readonly K[]): Newable<Omit<T, K>>;
|
|
750
|
+
declare function PickClass<T, K extends keyof T>(Base: Newable<T>, keys: readonly K[]): Newable<Pick<T, K>>;
|
|
737
751
|
|
|
738
752
|
/**
|
|
739
753
|
* Definition for a route used eg. By controllers.
|
|
@@ -870,6 +884,36 @@ type ArrayParamMetadataInput = Partial<OmitStrict<ArrayParamMetadata, 'type' | '
|
|
|
870
884
|
items: ArrayParamItemMetadataInput;
|
|
871
885
|
};
|
|
872
886
|
|
|
887
|
+
/**
|
|
888
|
+
* Interface for a CRUD (create, read, update, delete) controller.
|
|
889
|
+
*/
|
|
890
|
+
interface CrudControllerInterface<T extends BaseEntity, CreateData extends DeepPartial<T> = DeepPartial<T>, UpdateData extends DeepPartial<T> = DeepPartial<T>> {
|
|
891
|
+
/**
|
|
892
|
+
* Creates a new entity with the given data.
|
|
893
|
+
*/
|
|
894
|
+
create: (data: CreateData) => Promise<T>;
|
|
895
|
+
/**
|
|
896
|
+
* Gets paginated data from the given page.
|
|
897
|
+
*/
|
|
898
|
+
findAll: (page: number, limit: number) => Promise<PaginationResult<T>>;
|
|
899
|
+
/**
|
|
900
|
+
* Finds an entity with the given id.
|
|
901
|
+
*/
|
|
902
|
+
findById: (id: T['id']) => Promise<T>;
|
|
903
|
+
/**
|
|
904
|
+
* Updates the entity with the given id by the given data.
|
|
905
|
+
*/
|
|
906
|
+
updateById: (id: T['id'], data: UpdateData) => Promise<T>;
|
|
907
|
+
/**
|
|
908
|
+
* Deletes the entity with the given id.
|
|
909
|
+
*/
|
|
910
|
+
deleteById: (id: T['id']) => Promise<void>;
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Defines a CRUD controller for the specified entity.
|
|
914
|
+
*/
|
|
915
|
+
declare function CrudController<T extends BaseEntity, CreateData extends DeepPartial<T> = DeepPartial<T>, UpdateData extends DeepPartial<T> = DeepPartial<T>>(entityClass: Newable<T>, createDataClass: Newable<CreateData>, updateDataClass: Newable<UpdateData>): Newable<CrudControllerInterface<T, CreateData, UpdateData>>;
|
|
916
|
+
|
|
873
917
|
/**
|
|
874
918
|
* Metadata of path parameters.
|
|
875
919
|
*/
|
|
@@ -1142,6 +1186,8 @@ declare class Router implements RouterInterface {
|
|
|
1142
1186
|
private readonly validationService;
|
|
1143
1187
|
private readonly authService;
|
|
1144
1188
|
private readonly allowedOrphans;
|
|
1189
|
+
private readonly allBaseRoutes;
|
|
1190
|
+
private readonly allFinalRoutes;
|
|
1145
1191
|
readonly manuallyRegisteredRoutes: RouteConfiguration<BodyMetadata, Record<string, PathParamMetadata>, Record<string, QueryParamMetadata>, Record<string, HeaderParamMetadata>>[];
|
|
1146
1192
|
constructor();
|
|
1147
1193
|
init(app: ZibriApplication): Promise<void>;
|
|
@@ -1468,6 +1514,17 @@ type BaseUser<Role extends string> = BaseEntity & {
|
|
|
1468
1514
|
*/
|
|
1469
1515
|
roles: Role[];
|
|
1470
1516
|
};
|
|
1517
|
+
/**
|
|
1518
|
+
* Defines a base user entity class with the specified roles.
|
|
1519
|
+
* @param roleValue - The enum that is used for defining the roles of the user.
|
|
1520
|
+
*/
|
|
1521
|
+
declare function BaseUserEntity<Role extends string>(roleValue: AnyEnum<Role>): Newable<BaseUser<Role>>;
|
|
1522
|
+
/**
|
|
1523
|
+
* Checks whether or not the given value is a base user.
|
|
1524
|
+
* @param value - The value to check.
|
|
1525
|
+
* @returns True if the value has "id", "createdAt", "updatedAt", "email" and "roles" keys, false otherwise.
|
|
1526
|
+
*/
|
|
1527
|
+
declare function isBaseUser(value: unknown): value is BaseUser<string>;
|
|
1471
1528
|
|
|
1472
1529
|
/**
|
|
1473
1530
|
* A generic auth strategy array.
|
|
@@ -1585,8 +1642,7 @@ type SkipBelongsToMetadata = SkipAuthMetadata;
|
|
|
1585
1642
|
/**
|
|
1586
1643
|
* A short lived token used to confirm a password reset.
|
|
1587
1644
|
*/
|
|
1588
|
-
declare class PasswordResetToken
|
|
1589
|
-
id: string;
|
|
1645
|
+
declare class PasswordResetToken extends BaseEntity {
|
|
1590
1646
|
/**
|
|
1591
1647
|
* The expiration date of the password reset token.
|
|
1592
1648
|
*/
|
|
@@ -1902,8 +1958,7 @@ declare class LoggedError {
|
|
|
1902
1958
|
/**
|
|
1903
1959
|
* The data saved for a log entry.
|
|
1904
1960
|
*/
|
|
1905
|
-
declare class Log
|
|
1906
|
-
id: string;
|
|
1961
|
+
declare class Log extends BaseEntity {
|
|
1907
1962
|
/**
|
|
1908
1963
|
* The log level.
|
|
1909
1964
|
*/
|
|
@@ -1965,8 +2020,7 @@ declare enum EmailStatus {
|
|
|
1965
2020
|
/**
|
|
1966
2021
|
* Definition of a Email.
|
|
1967
2022
|
*/
|
|
1968
|
-
declare class Email
|
|
1969
|
-
id: string;
|
|
2023
|
+
declare class Email extends BaseEntity {
|
|
1970
2024
|
/**
|
|
1971
2025
|
* The createdAt date. Is set to now by default.
|
|
1972
2026
|
*/
|
|
@@ -2017,7 +2071,7 @@ declare class Email implements BaseEntity {
|
|
|
2017
2071
|
priority: EmailPriority;
|
|
2018
2072
|
}
|
|
2019
2073
|
|
|
2020
|
-
declare const CreateEmailData_base: Newable<Omit<Email, "
|
|
2074
|
+
declare const CreateEmailData_base: Newable<Omit<Email, "createdAt" | "id">>;
|
|
2021
2075
|
/**
|
|
2022
2076
|
* Data for creating a new email in the db.
|
|
2023
2077
|
*/
|
|
@@ -2114,7 +2168,6 @@ declare class DataSourceService implements DataSourceServiceInterface {
|
|
|
2114
2168
|
private readonly allowedOrphans;
|
|
2115
2169
|
constructor();
|
|
2116
2170
|
init(): Promise<void>;
|
|
2117
|
-
private checkForOrphanedEntities;
|
|
2118
2171
|
}
|
|
2119
2172
|
|
|
2120
2173
|
/**
|
|
@@ -2500,8 +2553,7 @@ declare class Repository<T extends BaseEntity, CreateData extends DeepPartial<T>
|
|
|
2500
2553
|
/**
|
|
2501
2554
|
* The migration entity that is stored in the db.
|
|
2502
2555
|
*/
|
|
2503
|
-
declare class MigrationEntity
|
|
2504
|
-
id: string;
|
|
2556
|
+
declare class MigrationEntity extends BaseEntity {
|
|
2505
2557
|
/**
|
|
2506
2558
|
* The name of the migration.
|
|
2507
2559
|
*/
|
|
@@ -2582,7 +2634,7 @@ declare abstract class Migration {
|
|
|
2582
2634
|
protected getEntityMetadata<T extends BaseEntity>(target: EntityTarget<T>, transaction: Transaction): EntityMetadata$1;
|
|
2583
2635
|
}
|
|
2584
2636
|
|
|
2585
|
-
type ToColumnMappableTypes = ExcludeStrict<PropertyMetadata, RelationMetadata<BaseEntity
|
|
2637
|
+
type ToColumnMappableTypes = ExcludeStrict<PropertyMetadata, RelationMetadata<BaseEntity>>['type'];
|
|
2586
2638
|
/**
|
|
2587
2639
|
* A base data source definition.
|
|
2588
2640
|
* Configured for postgres by default.
|
|
@@ -2634,12 +2686,10 @@ declare abstract class BaseDataSource {
|
|
|
2634
2686
|
/**
|
|
2635
2687
|
* Transforms the given property metadata to typeorm column options.
|
|
2636
2688
|
* @param metadata - The property metadata to transform.
|
|
2637
|
-
* @param cls - The entity class.
|
|
2638
|
-
* @param key - The key of the property on the entity class.
|
|
2639
2689
|
* @returns Typeorm column options.
|
|
2640
2690
|
* @throws When the metadata is incorrect.
|
|
2641
2691
|
*/
|
|
2642
|
-
protected propertyToColumnOptions(metadata: ExcludeStrict<PropertyMetadata, RelationMetadata<BaseEntity
|
|
2692
|
+
protected propertyToColumnOptions(metadata: ExcludeStrict<PropertyMetadata, RelationMetadata<BaseEntity>>): EntitySchemaColumnOptions;
|
|
2643
2693
|
/**
|
|
2644
2694
|
* Gets a repository to access the table of the provided entity class.
|
|
2645
2695
|
* @param cls - The entity class to get the repository for.
|
|
@@ -2782,8 +2832,7 @@ declare class EmailService implements EmailServiceInterface {
|
|
|
2782
2832
|
/**
|
|
2783
2833
|
* A mailing list like a newsletter that people can easily subscribe and unsubscribe to.
|
|
2784
2834
|
*/
|
|
2785
|
-
declare class MailingList
|
|
2786
|
-
id: string;
|
|
2835
|
+
declare class MailingList extends BaseEntity {
|
|
2787
2836
|
/**
|
|
2788
2837
|
* The name of the mailing list.
|
|
2789
2838
|
*/
|
|
@@ -2797,8 +2846,7 @@ declare class MailingList implements BaseEntity {
|
|
|
2797
2846
|
/**
|
|
2798
2847
|
* Defines a subscriber to a single or multiple mailing lists.
|
|
2799
2848
|
*/
|
|
2800
|
-
declare class MailingListSubscriber
|
|
2801
|
-
id: string;
|
|
2849
|
+
declare class MailingListSubscriber extends BaseEntity {
|
|
2802
2850
|
/**
|
|
2803
2851
|
* The optional name of the subscriber.
|
|
2804
2852
|
*/
|
|
@@ -2816,8 +2864,7 @@ declare class MailingListSubscriber implements BaseEntity {
|
|
|
2816
2864
|
/**
|
|
2817
2865
|
* A short lived token used to confirm a mailing list subscription.
|
|
2818
2866
|
*/
|
|
2819
|
-
declare class MailingListSubscriptionConfirmationToken
|
|
2820
|
-
id: string;
|
|
2867
|
+
declare class MailingListSubscriptionConfirmationToken extends BaseEntity {
|
|
2821
2868
|
/**
|
|
2822
2869
|
* The expiration date of the confirmation token.
|
|
2823
2870
|
*/
|
|
@@ -3128,7 +3175,7 @@ declare class AssetService implements AssetServiceInterface {
|
|
|
3128
3175
|
readonly pageTemplatePath: string;
|
|
3129
3176
|
readonly emailTemplatePath: string;
|
|
3130
3177
|
readonly assetsRoute: Route;
|
|
3131
|
-
constructor();
|
|
3178
|
+
constructor(logger: LoggerInterface);
|
|
3132
3179
|
attachTo(app: ZibriApplication): Promise<void>;
|
|
3133
3180
|
private buildFileTree;
|
|
3134
3181
|
private mapToTree;
|
|
@@ -3157,7 +3204,6 @@ declare class MailingListService implements MailingListServiceInterface {
|
|
|
3157
3204
|
protected get confirmationTokenRepository(): Repository<MailingListSubscriptionConfirmationToken, MailingListSubscriptionConfirmationTokenCreateData>;
|
|
3158
3205
|
constructor();
|
|
3159
3206
|
attachTo(): void;
|
|
3160
|
-
private validate;
|
|
3161
3207
|
queueEmailForList<T extends BaseMailingListEmailTemplateData>(listId: string, data: MailingListQueueEmailData<T>): Promise<void>;
|
|
3162
3208
|
requestSubscribeToList<T extends BaseMailingListEmailTemplateData>(listId: string, subscriber: MailingListSubscriberCreateData, emailData: MailingListQueueEmailData<T>): Promise<void>;
|
|
3163
3209
|
confirmSubscribeToList(confirmationTokenValue: string): Promise<void>;
|
|
@@ -3215,7 +3261,7 @@ declare class LoggerTransport<T extends BaseLoggerTransportConfig> {
|
|
|
3215
3261
|
*/
|
|
3216
3262
|
static create<X extends BaseLoggerTransportConfig>(config: X, send: LoggerTransportSend<X>): LoggerTransport<X>;
|
|
3217
3263
|
/**
|
|
3218
|
-
* Creates a new logger transport that prints the log to the
|
|
3264
|
+
* Creates a new logger transport that prints the log to the terminal.
|
|
3219
3265
|
* @param level - The log level at which the transport should be active.
|
|
3220
3266
|
* @returns The newly created transport.
|
|
3221
3267
|
*/
|
|
@@ -3274,7 +3320,7 @@ interface LoggerInterface {
|
|
|
3274
3320
|
declare class Logger implements LoggerInterface {
|
|
3275
3321
|
readonly transports: LoggerTransport<BaseLoggerTransportConfig>[];
|
|
3276
3322
|
protected readonly cleanupAfterMs: Record<LogLevel, number>;
|
|
3277
|
-
constructor();
|
|
3323
|
+
constructor(transports: LoggerTransport<BaseLoggerTransportConfig>[], cleanupAfterMs: Record<LogLevel, number>);
|
|
3278
3324
|
attachTo(app: ZibriApplication): void;
|
|
3279
3325
|
debug(message: string, context?: LogContextInput): Promise<void>;
|
|
3280
3326
|
info(message: string, context?: LogContextInput): Promise<void>;
|
|
@@ -3384,8 +3430,7 @@ declare class JwtConfirmPasswordResetData {
|
|
|
3384
3430
|
/**
|
|
3385
3431
|
* The credentials used by the jwt auth strategy.
|
|
3386
3432
|
*/
|
|
3387
|
-
declare class JwtCredentials implements Pick<BaseUser<string>, 'id' | 'email'> {
|
|
3388
|
-
id: string;
|
|
3433
|
+
declare class JwtCredentials extends BaseEntity implements Pick<BaseUser<string>, 'id' | 'email'> {
|
|
3389
3434
|
/**
|
|
3390
3435
|
* The id of the user that this credentials belong to.
|
|
3391
3436
|
*/
|
|
@@ -3399,7 +3444,7 @@ declare class JwtCredentials implements Pick<BaseUser<string>, 'id' | 'email'> {
|
|
|
3399
3444
|
*/
|
|
3400
3445
|
password: string;
|
|
3401
3446
|
}
|
|
3402
|
-
declare const JwtCredentialsDto_base: Newable<Omit<JwtCredentials, "
|
|
3447
|
+
declare const JwtCredentialsDto_base: Newable<Omit<JwtCredentials, "userId" | "id">>;
|
|
3403
3448
|
/**
|
|
3404
3449
|
* The actual credentials sent over http.
|
|
3405
3450
|
*/
|
|
@@ -3460,7 +3505,6 @@ declare class JwtAuthStrategy<RoleType extends string, UserType extends BaseUser
|
|
|
3460
3505
|
private get credentialsRepository();
|
|
3461
3506
|
constructor();
|
|
3462
3507
|
init(): void;
|
|
3463
|
-
private checkForEntities;
|
|
3464
3508
|
login(credentials: JwtCredentialsDto): Promise<JwtAuthData<RoleType>>;
|
|
3465
3509
|
logout(data: JwtRefreshLoginData): Promise<void>;
|
|
3466
3510
|
private createRefreshToken;
|
|
@@ -3531,8 +3575,7 @@ type JwtRefreshTokenPayload<Role extends string, T extends BaseUser<Role>> = {
|
|
|
3531
3575
|
/**
|
|
3532
3576
|
* The jwt refresh token that gets stored in the database.
|
|
3533
3577
|
*/
|
|
3534
|
-
declare class JwtRefreshToken
|
|
3535
|
-
id: string;
|
|
3578
|
+
declare class JwtRefreshToken extends BaseEntity {
|
|
3536
3579
|
/**
|
|
3537
3580
|
* The id of the user that this token belongs to.
|
|
3538
3581
|
*/
|
|
@@ -3618,9 +3661,8 @@ declare class JwtVerifyPasswordResetTokenResponse {
|
|
|
3618
3661
|
declare class JwtAuthController implements AuthControllerInterface<JwtCredentialsDto, JwtAuthData<string>, JwtRefreshLoginData, JwtRequestPasswordResetInput, JwtConfirmPasswordResetData> {
|
|
3619
3662
|
private readonly authService;
|
|
3620
3663
|
private readonly userService;
|
|
3621
|
-
private readonly refreshTokenRepository;
|
|
3622
3664
|
private readonly passwordResetTokenRepository;
|
|
3623
|
-
constructor(authService: AuthServiceInterface, userService: UserServiceInterface,
|
|
3665
|
+
constructor(authService: AuthServiceInterface, userService: UserServiceInterface, passwordResetTokenRepository: Repository<PasswordResetToken>);
|
|
3624
3666
|
login(credentials: JwtCredentialsDto): Promise<JwtAuthData<string>>;
|
|
3625
3667
|
refreshLogin(data: JwtRefreshLoginData): Promise<JwtAuthData<string>>;
|
|
3626
3668
|
requestPasswordReset(data: JwtRequestPasswordResetInput): Promise<void>;
|
|
@@ -3661,8 +3703,7 @@ declare abstract class HashUtilities {
|
|
|
3661
3703
|
/**
|
|
3662
3704
|
* The cron job entity that is stored in the db.
|
|
3663
3705
|
*/
|
|
3664
|
-
declare class CronJobEntity
|
|
3665
|
-
id: string;
|
|
3706
|
+
declare class CronJobEntity extends BaseEntity {
|
|
3666
3707
|
/**
|
|
3667
3708
|
* The name of the cron job.
|
|
3668
3709
|
*/
|
|
@@ -3932,11 +3973,17 @@ declare const ZIBRI_DI_TOKENS: {
|
|
|
3932
3973
|
readonly USER_SERVICE: "zi.user_service";
|
|
3933
3974
|
readonly CRON_SERVICE: "zi.cron_service";
|
|
3934
3975
|
readonly FILE_UPLOAD_TEMP_FOLDER: "zi.file_upload_temp_folder";
|
|
3976
|
+
readonly LOCALIZE_OPTIONS_INPUT: "zi.localize_options_input";
|
|
3977
|
+
readonly LOCALIZE_OPTIONS: "zi.localize_options";
|
|
3935
3978
|
readonly FORMAT_DATE: "zi.format_date";
|
|
3979
|
+
readonly FORMAT_PRICE: "zi.format_price";
|
|
3980
|
+
readonly FORMAT_PERCENT: "zi.format_percent";
|
|
3936
3981
|
readonly EMAIL_SERVICE: "zi.email_service";
|
|
3937
3982
|
readonly EMAIL_CONFIG: "zi.email_config";
|
|
3938
3983
|
readonly MAILING_LIST_SERVICE: "zi.mailing_list_service";
|
|
3939
3984
|
readonly CURRENT_REQUEST: "zi.current_request";
|
|
3985
|
+
readonly MULTITHREADING_SERVICE: "zi.multithreading_service";
|
|
3986
|
+
readonly MULTITHREADING_OPTIONS: "zi.multithreading_options";
|
|
3940
3987
|
};
|
|
3941
3988
|
|
|
3942
3989
|
/**
|
|
@@ -4177,201 +4224,1290 @@ declare class HtmlResponse {
|
|
|
4177
4224
|
}
|
|
4178
4225
|
|
|
4179
4226
|
/**
|
|
4180
|
-
*
|
|
4227
|
+
* A bundle of providers, controllers, cronJobs, bodyParsers and authStrategies.
|
|
4181
4228
|
*/
|
|
4182
|
-
|
|
4183
|
-
/**
|
|
4184
|
-
* The name of the app.
|
|
4185
|
-
*/
|
|
4186
|
-
name: string;
|
|
4187
|
-
/**
|
|
4188
|
-
* The base url of the app.
|
|
4189
|
-
* Eg. Http://localhost:3000.
|
|
4190
|
-
*/
|
|
4191
|
-
baseUrl: string;
|
|
4229
|
+
declare abstract class ZibriPlugin {
|
|
4192
4230
|
/**
|
|
4193
|
-
* The
|
|
4194
|
-
*
|
|
4195
|
-
* Is also used by migrations by default.
|
|
4231
|
+
* The DI providers to register/override.
|
|
4196
4232
|
*/
|
|
4197
|
-
|
|
4233
|
+
providers: DiProvider<unknown>[];
|
|
4198
4234
|
/**
|
|
4199
4235
|
* The controllers to register in the app.
|
|
4200
4236
|
*/
|
|
4201
4237
|
controllers: Newable<unknown>[];
|
|
4202
4238
|
/**
|
|
4203
|
-
* The
|
|
4204
|
-
*/
|
|
4205
|
-
dataSources?: Newable<BaseDataSource>[];
|
|
4206
|
-
/**
|
|
4207
|
-
* The DI providers to register/override.
|
|
4239
|
+
* The cron jobs to register in the app.
|
|
4208
4240
|
*/
|
|
4209
|
-
|
|
4241
|
+
cronJobs: Newable<CronJob>[];
|
|
4210
4242
|
/**
|
|
4211
4243
|
* The body parsers to register.
|
|
4212
4244
|
*
|
|
4213
4245
|
* If nothing is provided, the Zibri default parsers will be used.
|
|
4214
4246
|
*/
|
|
4215
|
-
bodyParsers
|
|
4247
|
+
bodyParsers: Newable<BodyParserInterface>[];
|
|
4216
4248
|
/**
|
|
4217
4249
|
* The auth strategies to register.
|
|
4218
4250
|
*
|
|
4219
4251
|
* If nothing is provided, the Zibri default jwt auth strategy will be used.
|
|
4220
4252
|
*/
|
|
4221
|
-
authStrategies
|
|
4253
|
+
authStrategies: AuthStrategies;
|
|
4222
4254
|
/**
|
|
4223
|
-
*
|
|
4255
|
+
* Validates that the plugin can work correctly. This should check that all entities exist,
|
|
4256
|
+
* all required providers exist etc.
|
|
4257
|
+
*
|
|
4258
|
+
* It's called after the initialization of the app, so that data sources etc. Should all be available.
|
|
4224
4259
|
*/
|
|
4225
|
-
|
|
4226
|
-
}
|
|
4260
|
+
abstract validate(app: ZibriApplication): void | Promise<void>;
|
|
4261
|
+
}
|
|
4227
4262
|
|
|
4228
|
-
type FullZibriApplicationOptions = Required<ZibriApplicationOptions>;
|
|
4229
4263
|
/**
|
|
4230
|
-
*
|
|
4264
|
+
* Plugin that includes everything for handling invoices.
|
|
4231
4265
|
*/
|
|
4232
|
-
declare class
|
|
4233
|
-
private readonly
|
|
4266
|
+
declare class ZibriInvoicingPlugin extends ZibriPlugin {
|
|
4267
|
+
private readonly defaultDiProviders;
|
|
4268
|
+
providers: DiProvider<unknown>[];
|
|
4269
|
+
private getProviders;
|
|
4270
|
+
validate(): void;
|
|
4271
|
+
}
|
|
4272
|
+
|
|
4273
|
+
/**
|
|
4274
|
+
* Contains base information about a company.
|
|
4275
|
+
*/
|
|
4276
|
+
type CompanyInfo = {
|
|
4234
4277
|
/**
|
|
4235
|
-
* The
|
|
4278
|
+
* The name of the company.
|
|
4236
4279
|
*/
|
|
4237
|
-
|
|
4238
|
-
private _router;
|
|
4280
|
+
readonly name: string;
|
|
4239
4281
|
/**
|
|
4240
|
-
* The
|
|
4282
|
+
* The full name of the company, including the company addendum.
|
|
4241
4283
|
*/
|
|
4242
|
-
|
|
4243
|
-
private logger;
|
|
4244
|
-
private metricsService;
|
|
4245
|
-
private assetService;
|
|
4246
|
-
private openApiService;
|
|
4247
|
-
private parser;
|
|
4248
|
-
private dataSourceService;
|
|
4249
|
-
private authService;
|
|
4250
|
-
private cronService;
|
|
4251
|
-
private emailService;
|
|
4252
|
-
private mailingListService?;
|
|
4284
|
+
readonly fullName: string;
|
|
4253
4285
|
/**
|
|
4254
|
-
* The
|
|
4286
|
+
* The email of the company.
|
|
4255
4287
|
*/
|
|
4256
|
-
readonly
|
|
4257
|
-
constructor(providedOptions: ZibriApplicationOptions);
|
|
4258
|
-
use(handler: RequestHandler): express.Express;
|
|
4259
|
-
use(...handlers: RequestHandler[]): void;
|
|
4260
|
-
use(path: Route, ...handlers: RequestHandler[]): void;
|
|
4261
|
-
use(path: Route, handlers: RequestHandler[]): void;
|
|
4288
|
+
readonly email: string;
|
|
4262
4289
|
/**
|
|
4263
|
-
*
|
|
4264
|
-
* @param H - The global handlebars instance, needed to provide some helpers used in templating.
|
|
4290
|
+
* The phone number of the company.
|
|
4265
4291
|
*/
|
|
4266
|
-
|
|
4292
|
+
readonly phone: string;
|
|
4267
4293
|
/**
|
|
4268
|
-
*
|
|
4269
|
-
* @param port - The port to start on.
|
|
4270
|
-
* @throws When the app has already been started.
|
|
4294
|
+
* The tax number.
|
|
4271
4295
|
*/
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4296
|
+
readonly taxNumber?: string;
|
|
4297
|
+
/**
|
|
4298
|
+
* The vat number.
|
|
4299
|
+
*/
|
|
4300
|
+
readonly vatNumber?: string;
|
|
4301
|
+
/**
|
|
4302
|
+
* The ceo of the company to display in the footer.
|
|
4303
|
+
* Can be omitted.
|
|
4304
|
+
*/
|
|
4305
|
+
readonly ceo?: string;
|
|
4306
|
+
/**
|
|
4307
|
+
* The IBAN of the company.
|
|
4308
|
+
* Can be omitted.
|
|
4309
|
+
*/
|
|
4310
|
+
readonly iban?: string;
|
|
4311
|
+
/**
|
|
4312
|
+
* The BIC/SWIFT of the company.
|
|
4313
|
+
* Can be omitted.
|
|
4314
|
+
*/
|
|
4315
|
+
readonly bic?: string;
|
|
4316
|
+
/**
|
|
4317
|
+
* The address of the company.
|
|
4318
|
+
*/
|
|
4319
|
+
readonly address: {
|
|
4320
|
+
/**
|
|
4321
|
+
* The street of the address.
|
|
4322
|
+
*/
|
|
4323
|
+
readonly street: string;
|
|
4324
|
+
/**
|
|
4325
|
+
* The number of the address.
|
|
4326
|
+
*/
|
|
4327
|
+
readonly number: string;
|
|
4328
|
+
/**
|
|
4329
|
+
* The 5 digit postcode of the address.
|
|
4330
|
+
*/
|
|
4331
|
+
readonly postcode: string;
|
|
4332
|
+
/**
|
|
4333
|
+
* The city of the address.
|
|
4334
|
+
*/
|
|
4335
|
+
readonly city: string;
|
|
4336
|
+
/**
|
|
4337
|
+
* The ISO 3166-1 country id.
|
|
4338
|
+
*/
|
|
4339
|
+
readonly countryId: string;
|
|
4340
|
+
};
|
|
4341
|
+
};
|
|
4288
4342
|
|
|
4289
4343
|
/**
|
|
4290
|
-
*
|
|
4344
|
+
* Complete definition of a PDF document.
|
|
4291
4345
|
*/
|
|
4292
|
-
|
|
4346
|
+
type PdfDocumentDefinition = TDocumentDefinitions & {
|
|
4293
4347
|
/**
|
|
4294
|
-
*
|
|
4348
|
+
* Attachments of the pdf file.
|
|
4295
4349
|
*/
|
|
4296
|
-
|
|
4350
|
+
attachments: PdfAttachmentDefinition[];
|
|
4351
|
+
};
|
|
4352
|
+
/**
|
|
4353
|
+
* Definition for an attachment of a pdf file.
|
|
4354
|
+
*/
|
|
4355
|
+
type PdfAttachmentDefinition = {
|
|
4297
4356
|
/**
|
|
4298
|
-
* The
|
|
4357
|
+
* The file content of the attachment. A string value is interpreted as a file path.
|
|
4299
4358
|
*/
|
|
4300
|
-
|
|
4359
|
+
src: string | ArrayBuffer | Buffer<ArrayBufferLike>;
|
|
4301
4360
|
/**
|
|
4302
|
-
*
|
|
4361
|
+
* Metadata about the attachment.
|
|
4303
4362
|
*/
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
}
|
|
4363
|
+
options: PDFKit.Mixins.PDFAttachmentOptions & Required<Pick<PDFKit.Mixins.PDFAttachmentOptions, 'name'>>;
|
|
4364
|
+
};
|
|
4307
4365
|
/**
|
|
4308
|
-
*
|
|
4309
|
-
* @param value - The value to check.
|
|
4310
|
-
* @returns True when value is an instance of HttpError, false otherwise.
|
|
4366
|
+
* Definition of an image to be embedded into the document.
|
|
4311
4367
|
*/
|
|
4312
|
-
|
|
4313
|
-
|
|
4368
|
+
type PdfImageDefinition = ImageDefinition;
|
|
4314
4369
|
/**
|
|
4315
|
-
*
|
|
4370
|
+
* Common type for all available pdf content elements.
|
|
4316
4371
|
*/
|
|
4317
|
-
|
|
4318
|
-
constructor(message: string | string[], options?: ErrorOptions);
|
|
4319
|
-
}
|
|
4320
|
-
|
|
4372
|
+
type PdfContentDefinition = Content;
|
|
4321
4373
|
/**
|
|
4322
|
-
*
|
|
4323
|
-
*
|
|
4324
|
-
* In contrast to the UnmatchedRouteError, this should be thrown when the endpoint actually exists (eg. /items/:id), but the resource was not found.
|
|
4325
|
-
* Eg. Because the id of the item is incorrect.
|
|
4374
|
+
* Definition of a pdf column.
|
|
4326
4375
|
*/
|
|
4327
|
-
|
|
4328
|
-
constructor(message: string | string[], options?: ErrorOptions);
|
|
4329
|
-
}
|
|
4330
|
-
|
|
4376
|
+
type PdfColumnDefinition = Column;
|
|
4331
4377
|
/**
|
|
4332
|
-
*
|
|
4333
|
-
*
|
|
4334
|
-
* In contrast to NotFoundError, this should only be thrown the route itself does not exist at all.
|
|
4335
|
-
* Eg. /does-not-exist and not when the route itself (eg. Items/:id) exists, but it could not find a value for eg. /items/42.
|
|
4378
|
+
* Definition of a pdf table cell.
|
|
4336
4379
|
*/
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4380
|
+
type PdfTableCellDefinition = Content;
|
|
4381
|
+
/**
|
|
4382
|
+
* A created pdf document.
|
|
4383
|
+
*/
|
|
4384
|
+
type PdfDocument = PDFKit.PDFDocument;
|
|
4340
4385
|
|
|
4341
4386
|
/**
|
|
4342
|
-
*
|
|
4387
|
+
* Represents a wrapper around XML nodes to implement easy to use and chainable document builder methods.
|
|
4343
4388
|
*/
|
|
4344
|
-
|
|
4345
|
-
constructor(message: string | string[], options?: ErrorOptions);
|
|
4346
|
-
}
|
|
4389
|
+
type XML = XMLBuilder;
|
|
4347
4390
|
|
|
4348
4391
|
/**
|
|
4349
|
-
*
|
|
4392
|
+
* Options used throughout the plugin.
|
|
4350
4393
|
*/
|
|
4351
|
-
type
|
|
4394
|
+
type InvoicingOptions = {
|
|
4352
4395
|
/**
|
|
4353
|
-
* The
|
|
4396
|
+
* The font size that should be used for the footer.
|
|
4397
|
+
* @default 10
|
|
4354
4398
|
*/
|
|
4355
|
-
|
|
4399
|
+
readonly footerFontSize: number;
|
|
4356
4400
|
/**
|
|
4357
|
-
*
|
|
4401
|
+
* Globally defined images which can be referenced by name inside the document definition.
|
|
4402
|
+
* @default undefined
|
|
4358
4403
|
*/
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4404
|
+
readonly images: Record<string, PdfImageDefinition> | undefined;
|
|
4405
|
+
/**
|
|
4406
|
+
* Available options:
|
|
4407
|
+
*
|
|
4408
|
+
* - A reference by name to an image defined in PdfMakeDocumentDefinition.images
|
|
4409
|
+
* - A data URL
|
|
4410
|
+
* - A remote URL via http:// or https://.
|
|
4411
|
+
*
|
|
4412
|
+
* Supported image formats: JPEG, PNG.
|
|
4413
|
+
* @default undefined
|
|
4414
|
+
*/
|
|
4415
|
+
readonly logo: string | undefined;
|
|
4416
|
+
/**
|
|
4417
|
+
* The label for the phone number on the invoice.
|
|
4418
|
+
* @default 'Phone'
|
|
4419
|
+
*/
|
|
4420
|
+
readonly phoneLabel: string;
|
|
4421
|
+
/**
|
|
4422
|
+
* The label for the email on the invoice.
|
|
4423
|
+
* @default 'E-Mail'
|
|
4424
|
+
*/
|
|
4425
|
+
readonly emailLabel: string;
|
|
4426
|
+
/**
|
|
4427
|
+
* The headline of the invoice.
|
|
4428
|
+
* @default 'Invoice'
|
|
4429
|
+
*/
|
|
4430
|
+
readonly headline: string;
|
|
4431
|
+
/**
|
|
4432
|
+
* The font size of the headline.
|
|
4433
|
+
* @default 20
|
|
4434
|
+
*/
|
|
4435
|
+
readonly headlineFontSize: number;
|
|
4436
|
+
/**
|
|
4437
|
+
* The label for the invoice number on the invoice.
|
|
4438
|
+
* @default 'Invoice No.'
|
|
4439
|
+
*/
|
|
4440
|
+
readonly invoiceNumberLabel: string;
|
|
4441
|
+
/**
|
|
4442
|
+
* The notice below the invoice number.
|
|
4443
|
+
* @default 'Please specify when making payments and invoicing!'
|
|
4444
|
+
*/
|
|
4445
|
+
readonly invoiceNumberNotice: string;
|
|
4446
|
+
/**
|
|
4447
|
+
* The label for the date on the invoice.
|
|
4448
|
+
* @default 'Date'
|
|
4449
|
+
*/
|
|
4450
|
+
readonly dateLabel: string;
|
|
4451
|
+
/**
|
|
4452
|
+
* The label for the date of performance on the invoice.
|
|
4453
|
+
* @default 'Date of performance'
|
|
4454
|
+
*/
|
|
4455
|
+
readonly performanceDateLabel: string;
|
|
4456
|
+
/**
|
|
4457
|
+
* Whether or not a performance date should be displayed on the invoice.
|
|
4458
|
+
* @default false
|
|
4459
|
+
*/
|
|
4460
|
+
readonly showPerformanceDate: boolean;
|
|
4461
|
+
/**
|
|
4462
|
+
* Whether or not a due date should be displayed on the invoice.
|
|
4463
|
+
* @default true
|
|
4464
|
+
*/
|
|
4465
|
+
readonly showDueDate: boolean;
|
|
4466
|
+
/**
|
|
4467
|
+
* The label for the due date on the invoice.
|
|
4468
|
+
* @default 'Due date'
|
|
4469
|
+
*/
|
|
4470
|
+
readonly dueDateLabel: string;
|
|
4471
|
+
/**
|
|
4472
|
+
* The font size that should be used inside the tables.
|
|
4473
|
+
* @default 12
|
|
4474
|
+
*/
|
|
4475
|
+
readonly tableFontSize: number;
|
|
4476
|
+
/**
|
|
4477
|
+
* The label for item name on the invoice.
|
|
4478
|
+
* @default 'Name'
|
|
4479
|
+
*/
|
|
4480
|
+
readonly itemNameLabel: string;
|
|
4481
|
+
/**
|
|
4482
|
+
* The label for the total when no taxes exist on the invoice.
|
|
4483
|
+
* @default 'Total'
|
|
4484
|
+
*/
|
|
4485
|
+
readonly totalLabel: string;
|
|
4486
|
+
/**
|
|
4487
|
+
* The label for the total before tax value on the invoice.
|
|
4488
|
+
* @default 'Total (excl. tax)'
|
|
4489
|
+
*/
|
|
4490
|
+
readonly totalBeforeTaxLabel: string;
|
|
4491
|
+
/**
|
|
4492
|
+
* The label for the total after tax value on the invoice.
|
|
4493
|
+
* @default 'Total (incl. tax)'
|
|
4494
|
+
*/
|
|
4495
|
+
readonly totalAfterTaxLabel: string;
|
|
4496
|
+
/**
|
|
4497
|
+
* The label for tax value on the invoice.
|
|
4498
|
+
* @default 'VAT'
|
|
4499
|
+
*/
|
|
4500
|
+
readonly taxLabel: string;
|
|
4501
|
+
/**
|
|
4502
|
+
* The label for tax number on the invoice.
|
|
4503
|
+
* @default 'Tax number:'
|
|
4504
|
+
*/
|
|
4505
|
+
readonly taxNumberLabel: string;
|
|
4506
|
+
/**
|
|
4507
|
+
* The label for the ceo on the invoice.
|
|
4508
|
+
* @default 'CEO:'
|
|
4509
|
+
*/
|
|
4510
|
+
readonly ceoLabel: string;
|
|
4511
|
+
/**
|
|
4512
|
+
* The label for item amount on the invoice.
|
|
4513
|
+
* @default 'Amount'
|
|
4514
|
+
*/
|
|
4515
|
+
readonly itemAmountLabel: string;
|
|
4516
|
+
/**
|
|
4517
|
+
* The label for single price of an item on the invoice.
|
|
4518
|
+
* @default 'Price'
|
|
4519
|
+
*/
|
|
4520
|
+
readonly itemSinglePriceLabel: string;
|
|
4521
|
+
/**
|
|
4522
|
+
* The label for total price of an item on the invoice.
|
|
4523
|
+
* @default 'Total'
|
|
4524
|
+
*/
|
|
4525
|
+
readonly itemTotalPriceLabel: string;
|
|
4526
|
+
/**
|
|
4527
|
+
* The tax office to display in the footer.
|
|
4528
|
+
* Can be omitted.
|
|
4529
|
+
*/
|
|
4530
|
+
readonly taxOffice: string | undefined;
|
|
4531
|
+
/**
|
|
4532
|
+
* The label for the bank details in the footer.
|
|
4533
|
+
* @default 'Bank details:'
|
|
4534
|
+
*/
|
|
4535
|
+
readonly bankDetailsLabel: string;
|
|
4536
|
+
/**
|
|
4537
|
+
* The label for the iban to display in the footer.
|
|
4538
|
+
* @default 'IBAN:'
|
|
4539
|
+
*/
|
|
4540
|
+
readonly ibanLabel: string;
|
|
4541
|
+
/**
|
|
4542
|
+
* The label for the bic to display in the footer.
|
|
4543
|
+
* @default 'BIC/SWIFT:'
|
|
4544
|
+
*/
|
|
4545
|
+
readonly bicLabel: string;
|
|
4546
|
+
/**
|
|
4547
|
+
* The bank name to display in the footer.
|
|
4548
|
+
* Can be omitted.
|
|
4549
|
+
*/
|
|
4550
|
+
readonly bankName: string | undefined;
|
|
4551
|
+
/**
|
|
4552
|
+
* The information about the company sending out the invoice.
|
|
4553
|
+
*/
|
|
4554
|
+
readonly companyInfo: CompanyInfo;
|
|
4555
|
+
/**
|
|
4556
|
+
* The number of digits used to generate the consecutive number.
|
|
4557
|
+
* @default 4
|
|
4558
|
+
*/
|
|
4559
|
+
readonly numberOfDigits: number;
|
|
4560
|
+
/**
|
|
4561
|
+
* The separator for the parts of the invoice number.
|
|
4562
|
+
* @default '-'
|
|
4563
|
+
*/
|
|
4564
|
+
readonly separator: string;
|
|
4565
|
+
/**
|
|
4566
|
+
* How many characters of the company name should be used in the invoice number.
|
|
4567
|
+
* @default 6
|
|
4568
|
+
*/
|
|
4569
|
+
readonly numberCompanyAbbreviationCharacters: number;
|
|
4570
|
+
/**
|
|
4571
|
+
* How many characters of the private customer first and last name should be used in the invoice number.
|
|
4572
|
+
* @default 3
|
|
4573
|
+
*/
|
|
4574
|
+
readonly numberPrivateCustomerAbbreviationCharacters: number;
|
|
4575
|
+
};
|
|
4576
|
+
|
|
4577
|
+
/**
|
|
4578
|
+
* The invoice address, which can be either a private or a company address.
|
|
4579
|
+
*/
|
|
4580
|
+
declare class InvoiceAddress {
|
|
4581
|
+
/**
|
|
4582
|
+
* The form of address of the customer.
|
|
4583
|
+
*/
|
|
4584
|
+
formOfAddress: string;
|
|
4585
|
+
/**
|
|
4586
|
+
* The first name of the customer.
|
|
4587
|
+
*/
|
|
4588
|
+
firstName: string;
|
|
4589
|
+
/**
|
|
4590
|
+
* The last name of the customer.
|
|
4591
|
+
*/
|
|
4592
|
+
lastName: string;
|
|
4593
|
+
/**
|
|
4594
|
+
* The email of the customer.
|
|
4595
|
+
* This does NOT have to be the same email where the invoice is sent.
|
|
4596
|
+
* It is required for factur-x or x-rechnung compliant invoices.
|
|
4597
|
+
*/
|
|
4598
|
+
email?: string;
|
|
4599
|
+
/**
|
|
4600
|
+
* The street of the address.
|
|
4601
|
+
*/
|
|
4602
|
+
street: string;
|
|
4603
|
+
/**
|
|
4604
|
+
* The number of the address.
|
|
4605
|
+
*/
|
|
4606
|
+
number: string;
|
|
4607
|
+
/**
|
|
4608
|
+
* The postcode of the address.
|
|
4609
|
+
*/
|
|
4610
|
+
postcode: string;
|
|
4611
|
+
/**
|
|
4612
|
+
* The city of the address.
|
|
4613
|
+
*/
|
|
4614
|
+
city: string;
|
|
4615
|
+
/**
|
|
4616
|
+
* The country id of the address.
|
|
4617
|
+
* Eg. 'US'.
|
|
4618
|
+
*/
|
|
4619
|
+
countryId: string;
|
|
4620
|
+
/**
|
|
4621
|
+
* Whether or not the address is of a company.
|
|
4622
|
+
*/
|
|
4623
|
+
company: boolean;
|
|
4624
|
+
/**
|
|
4625
|
+
* The name of the company.
|
|
4626
|
+
*/
|
|
4627
|
+
companyName?: string;
|
|
4628
|
+
}
|
|
4629
|
+
|
|
4630
|
+
/**
|
|
4631
|
+
* Information about the unit of the amount value.
|
|
4632
|
+
* Consists of a display name like "Hours" and a code like "HUR".
|
|
4633
|
+
*/
|
|
4634
|
+
declare class AmountUnit {
|
|
4635
|
+
/**
|
|
4636
|
+
* The display name for invoices.
|
|
4637
|
+
*/
|
|
4638
|
+
displayName: string;
|
|
4639
|
+
/**
|
|
4640
|
+
* The common code for the unit, based on rec20
|
|
4641
|
+
* https://unece.org/trade/uncefact/cl-recommendations.
|
|
4642
|
+
* Used for x-rechnung.
|
|
4643
|
+
*/
|
|
4644
|
+
code: string;
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4647
|
+
/**
|
|
4648
|
+
* Contains the information about how many invoices have been created in a specific year.
|
|
4649
|
+
*/
|
|
4650
|
+
declare class NumberInvoices extends BaseEntity {
|
|
4651
|
+
/**
|
|
4652
|
+
* The id of the recipient of the invoice.
|
|
4653
|
+
*/
|
|
4654
|
+
recipientId: string;
|
|
4655
|
+
/**
|
|
4656
|
+
* The amount of invoices of that year.
|
|
4657
|
+
*/
|
|
4658
|
+
number: number;
|
|
4659
|
+
/**
|
|
4660
|
+
* The year for which this entity hold the amount of invoices.
|
|
4661
|
+
*/
|
|
4662
|
+
year: number;
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
/**
|
|
4666
|
+
* S = standard rate
|
|
4667
|
+
* Z = zero rated
|
|
4668
|
+
* E = tax-exempt
|
|
4669
|
+
* AE = VAT reverse charge
|
|
4670
|
+
* K = VAT exempt for EEA intra-community supply of goods and services
|
|
4671
|
+
* G = Free export item, tax not charged
|
|
4672
|
+
* O = Services outside scope of tax
|
|
4673
|
+
* L = Canary Islands general indirect tax
|
|
4674
|
+
* M = Tax for production, services and importation in Ceuta and Melilla.
|
|
4675
|
+
*/
|
|
4676
|
+
type VatCategoryCode = 'S' | 'Z' | 'E' | 'AE' | 'K' | 'G' | 'O' | 'L' | 'M';
|
|
4677
|
+
/**
|
|
4678
|
+
* Contains tax information.
|
|
4679
|
+
* Consists of the tax rate in percent and a Category Code used for x-rechnung.
|
|
4680
|
+
*/
|
|
4681
|
+
declare class Vat {
|
|
4682
|
+
/**
|
|
4683
|
+
* The tax rate in percent.
|
|
4684
|
+
*/
|
|
4685
|
+
rate: number;
|
|
4686
|
+
/**
|
|
4687
|
+
* The category code used for x-rechnung.
|
|
4688
|
+
*/
|
|
4689
|
+
categoryCode: VatCategoryCode | string & {};
|
|
4690
|
+
/**
|
|
4691
|
+
* A description for why this is tax exempt.
|
|
4692
|
+
* Is required when categoryCode is set to 'E'.
|
|
4693
|
+
*/
|
|
4694
|
+
exemptionReason?: string;
|
|
4695
|
+
}
|
|
4696
|
+
|
|
4697
|
+
/**
|
|
4698
|
+
* Contains information about a single item of an invoice.
|
|
4699
|
+
*/
|
|
4700
|
+
declare class InvoiceItem {
|
|
4701
|
+
/**
|
|
4702
|
+
* The name of the item.
|
|
4703
|
+
*/
|
|
4704
|
+
name: string;
|
|
4705
|
+
/**
|
|
4706
|
+
* The amount of the item.
|
|
4707
|
+
*/
|
|
4708
|
+
amount: number;
|
|
4709
|
+
/**
|
|
4710
|
+
* The unit, eg. Pieces or meter.
|
|
4711
|
+
* Is either a free string or an object containing a display name and a code.
|
|
4712
|
+
* (This is required for factur-x/x-rechnung conformance).
|
|
4713
|
+
*/
|
|
4714
|
+
amountUnit: AmountUnit;
|
|
4715
|
+
/**
|
|
4716
|
+
* The tax on the item.
|
|
4717
|
+
* Is either a percentage number (eg. 20 means 20%) or an object containing a percentage number and a code.
|
|
4718
|
+
* (This is required for factur-x/x-rechnung conformance).
|
|
4719
|
+
*/
|
|
4720
|
+
vat: Vat;
|
|
4721
|
+
/**
|
|
4722
|
+
* The price of the item.
|
|
4723
|
+
*/
|
|
4724
|
+
price: number;
|
|
4725
|
+
}
|
|
4726
|
+
|
|
4727
|
+
/**
|
|
4728
|
+
* Codes for the different currencies of the world.
|
|
4729
|
+
* Is loosely typed to support custom string values.
|
|
4730
|
+
*/
|
|
4731
|
+
type CurrencyCode = 'USD' | 'EUR' | string & {};
|
|
4732
|
+
|
|
4733
|
+
/**
|
|
4734
|
+
* Codes for the different languages of the world.
|
|
4735
|
+
* Is loosely typed to support custom string values.
|
|
4736
|
+
*/
|
|
4737
|
+
type LanguageCode = 'de' | 'en' | string & {};
|
|
4738
|
+
|
|
4739
|
+
/**
|
|
4740
|
+
* The options for handling localization, eg. In date or currency formatting.
|
|
4741
|
+
*/
|
|
4742
|
+
type LocalizeOptions = {
|
|
4743
|
+
/**
|
|
4744
|
+
* The language code to use by default.
|
|
4745
|
+
*/
|
|
4746
|
+
readonly language: LanguageCode;
|
|
4747
|
+
/**
|
|
4748
|
+
* The currency code to use by default.
|
|
4749
|
+
*/
|
|
4750
|
+
readonly currency: CurrencyCode;
|
|
4751
|
+
};
|
|
4752
|
+
/**
|
|
4753
|
+
* Input for modifying the localize options.
|
|
4754
|
+
*/
|
|
4755
|
+
type LocalizeOptionsInput = Partial<LocalizeOptions>;
|
|
4756
|
+
|
|
4757
|
+
/**
|
|
4758
|
+
* Function for formatting dates.
|
|
4759
|
+
*/
|
|
4760
|
+
type FormatDateFn = (date: Date, includeTime?: boolean, language?: LanguageCode) => string;
|
|
4761
|
+
|
|
4762
|
+
/**
|
|
4763
|
+
* Function for formatting percentages.
|
|
4764
|
+
*/
|
|
4765
|
+
type FormatPercentFn = (percentage: number) => string;
|
|
4766
|
+
|
|
4767
|
+
/**
|
|
4768
|
+
* Numbers with increased precision. (No rounding errors).
|
|
4769
|
+
*/
|
|
4770
|
+
type BigNumber = BigNumberJs;
|
|
4771
|
+
/**
|
|
4772
|
+
* Provides functionality around calculating with high precision.
|
|
4773
|
+
*/
|
|
4774
|
+
declare abstract class BigNumberUtilities {
|
|
4775
|
+
/**
|
|
4776
|
+
* Creates a BigNumber from the provided input.
|
|
4777
|
+
* @param value - The number value to create from.
|
|
4778
|
+
* @returns A new BigNumber.
|
|
4779
|
+
*/
|
|
4780
|
+
static new(value: number): BigNumber;
|
|
4781
|
+
/**
|
|
4782
|
+
* Precisely multiplies the given values.
|
|
4783
|
+
* @param value1 - The first number to multiply.
|
|
4784
|
+
* @param value2 - The second number to multiply.
|
|
4785
|
+
* @returns The precise result as BigNumber.
|
|
4786
|
+
*/
|
|
4787
|
+
static multiply(value1: number | BigNumber, value2: number | BigNumber): BigNumber;
|
|
4788
|
+
/**
|
|
4789
|
+
* Precisely divides the first value by the second value.
|
|
4790
|
+
* @param dividend - The value that will be divided.
|
|
4791
|
+
* @param divisor - The value that divides the first value.
|
|
4792
|
+
* @returns The precise result as BigNumber.
|
|
4793
|
+
*/
|
|
4794
|
+
static divide(dividend: number | BigNumber, divisor: number | BigNumber): BigNumber;
|
|
4795
|
+
/**
|
|
4796
|
+
* Precisely adds the given values.
|
|
4797
|
+
* @param value1 - The first number for the addition.
|
|
4798
|
+
* @param value2 - The second number for the addition.
|
|
4799
|
+
* @returns The precise result as BigNumber.
|
|
4800
|
+
*/
|
|
4801
|
+
static add(value1: number | BigNumber, value2: number | BigNumber): BigNumber;
|
|
4802
|
+
}
|
|
4803
|
+
|
|
4804
|
+
/**
|
|
4805
|
+
* Options for chunking.
|
|
4806
|
+
*/
|
|
4807
|
+
type ChunkingOptions = {
|
|
4808
|
+
/**
|
|
4809
|
+
* The size of a single chunk.
|
|
4810
|
+
*/
|
|
4811
|
+
chunkSize: number;
|
|
4812
|
+
};
|
|
4813
|
+
/**
|
|
4814
|
+
* Like Promise.all, but chunked.
|
|
4815
|
+
* @param promises - The promises to resolve.
|
|
4816
|
+
* @param options - Options for chunking, like the size of chunks etc.
|
|
4817
|
+
* @returns The resolved promises after all chunks have been resolved.
|
|
4818
|
+
*/
|
|
4819
|
+
declare function chunkedPromiseAll<T>(promises: Promise<T>[], options?: ChunkingOptions): Promise<T[]>;
|
|
4820
|
+
|
|
4821
|
+
/**
|
|
4822
|
+
* Compares the given versions and check if the first one is bigger, equal or smaller than the second one.
|
|
4823
|
+
* @param v1 - The first version.
|
|
4824
|
+
* @param v2 - The second version to compare against.
|
|
4825
|
+
* @returns 'bigger', 'equal' or 'smaller'.
|
|
4826
|
+
*/
|
|
4827
|
+
declare function compareVersion(v1: Version, v2: Version): 'bigger' | 'equal' | 'smaller';
|
|
4828
|
+
|
|
4829
|
+
/**
|
|
4830
|
+
* Checks whether the given value is a valid SemVer Version.
|
|
4831
|
+
* @param value - The value to check.
|
|
4832
|
+
*/
|
|
4833
|
+
declare function isVersion(value: string): value is Version;
|
|
4834
|
+
|
|
4835
|
+
declare abstract class Ms {
|
|
4836
|
+
/**
|
|
4837
|
+
* The amount of ms in a second.
|
|
4838
|
+
*/
|
|
4839
|
+
static SECOND: 1000;
|
|
4840
|
+
/**
|
|
4841
|
+
* The amount of ms in a minute.
|
|
4842
|
+
*/
|
|
4843
|
+
static MINUTE: 60000;
|
|
4844
|
+
/**
|
|
4845
|
+
* The amount of ms in an hour.
|
|
4846
|
+
*/
|
|
4847
|
+
static HOUR: 3600000;
|
|
4848
|
+
/**
|
|
4849
|
+
* The amount of ms in a day.
|
|
4850
|
+
*/
|
|
4851
|
+
static DAY: 86400000;
|
|
4852
|
+
/**
|
|
4853
|
+
* The amount of ms in a week.
|
|
4854
|
+
*/
|
|
4855
|
+
static WEEK: 604800000;
|
|
4856
|
+
}
|
|
4857
|
+
|
|
4858
|
+
/**
|
|
4859
|
+
* Validates that the given entities are registered in a data source somewhere.
|
|
4860
|
+
* @param context - The name of the class where this function was called. Is needed to provide information about who expects the entities to exist.
|
|
4861
|
+
* @param entities - The entities that should be validated to be registered.
|
|
4862
|
+
* @throws When one of the entities is not registered in a data source.
|
|
4863
|
+
*/
|
|
4864
|
+
declare function validateEntitiesRegistered(context: string, ...entities: Newable<BaseEntity>[]): void;
|
|
4865
|
+
|
|
4866
|
+
/**
|
|
4867
|
+
* Utilities for dealing with uuid.
|
|
4868
|
+
*/
|
|
4869
|
+
declare abstract class UUIDUtilities {
|
|
4870
|
+
/**
|
|
4871
|
+
* Generate a new uuid.
|
|
4872
|
+
* @returns A v4 uuid string.
|
|
4873
|
+
*/
|
|
4874
|
+
static generate(): string;
|
|
4875
|
+
}
|
|
4876
|
+
|
|
4877
|
+
/**
|
|
4878
|
+
* Function for formatting prices.
|
|
4879
|
+
*/
|
|
4880
|
+
type FormatPriceFn = (price: number | BigNumber, currency?: CurrencyCode, language?: LanguageCode) => string;
|
|
4881
|
+
|
|
4882
|
+
/**
|
|
4883
|
+
* Contains information about an invoice.
|
|
4884
|
+
*/
|
|
4885
|
+
declare class Invoice extends BaseEntity {
|
|
4886
|
+
/**
|
|
4887
|
+
* The unique invoice number for this invoice.
|
|
4888
|
+
*/
|
|
4889
|
+
number: string;
|
|
4890
|
+
/**
|
|
4891
|
+
* The actual content of the invoice.
|
|
4892
|
+
*/
|
|
4893
|
+
items: InvoiceItem[];
|
|
4894
|
+
/**
|
|
4895
|
+
* The date at which the invoice was created.
|
|
4896
|
+
* Defaults to now.
|
|
4897
|
+
*/
|
|
4898
|
+
date: Date;
|
|
4899
|
+
/**
|
|
4900
|
+
* The date at which the invoice items were/will be done.
|
|
4901
|
+
*/
|
|
4902
|
+
performanceDate: Date;
|
|
4903
|
+
/**
|
|
4904
|
+
* The date at which the invoice has to be paid.
|
|
4905
|
+
*/
|
|
4906
|
+
dueDate: Date;
|
|
4907
|
+
/**
|
|
4908
|
+
* The address data to which the invoice gets sent.
|
|
4909
|
+
* Contains information about the customer and the actual address.
|
|
4910
|
+
*/
|
|
4911
|
+
customerAddressData: InvoiceAddress;
|
|
4912
|
+
/**
|
|
4913
|
+
* The text that is displayed before the invoice items.
|
|
4914
|
+
* Is an array of strings that represent paragraphs.
|
|
4915
|
+
*/
|
|
4916
|
+
textBeforeItems: string[];
|
|
4917
|
+
/**
|
|
4918
|
+
* The text that is displayed after the invoice items.
|
|
4919
|
+
* Is an array of strings that represent paragraphs.
|
|
4920
|
+
*/
|
|
4921
|
+
textAfterItems: string[];
|
|
4922
|
+
/**
|
|
4923
|
+
* The currency code of the invoice.
|
|
4924
|
+
*/
|
|
4925
|
+
currency: CurrencyCode;
|
|
4926
|
+
}
|
|
4927
|
+
|
|
4928
|
+
/**
|
|
4929
|
+
* Input for creating invoicing options.
|
|
4930
|
+
*/
|
|
4931
|
+
type InvoicingOptionsInput = Partial<InvoicingOptions> & Pick<InvoicingOptions, 'companyInfo'>;
|
|
4932
|
+
|
|
4933
|
+
/**
|
|
4934
|
+
* Handles generating unique and consecutive numbers for invoices.
|
|
4935
|
+
*/
|
|
4936
|
+
interface InvoiceNumberServiceInterface<AddressData extends InvoiceAddress> {
|
|
4937
|
+
/**
|
|
4938
|
+
* Generates a new invoice number.
|
|
4939
|
+
* @param recipientId - The id of the recipient of the invoice.
|
|
4940
|
+
* @param invoiceAddress - The address data of the recipient of the invoice.
|
|
4941
|
+
* @param transaction - An optional transaction from outside to make sure any changes only apply when the transaction is committed.
|
|
4942
|
+
* @param nameAbbreviation - An optional name abbreviation if you don't want to generate one.
|
|
4943
|
+
* @returns A promise of the new invoice number.
|
|
4944
|
+
*/
|
|
4945
|
+
generateInvoiceNumber: (recipientId: string, invoiceAddress: AddressData, transaction?: Transaction, nameAbbreviation?: string) => string | Promise<string>;
|
|
4946
|
+
/**
|
|
4947
|
+
* Generates a temporary invoice number with the prefix "TEMP".
|
|
4948
|
+
* This does not increase the number of invoices which can be helpful if you create an invoice that might not be sent out.
|
|
4949
|
+
* @param recipientId - The id of the recipient of the invoice.
|
|
4950
|
+
* @param invoiceAddress - The address data of the customer.
|
|
4951
|
+
* @param nameAbbreviation - An optional name abbreviation if you don't want to generate one.
|
|
4952
|
+
* @returns A promise of the new temporary invoice number.
|
|
4953
|
+
*/
|
|
4954
|
+
generateTemporaryInvoiceNumber: (recipientId: string, invoiceAddress: InvoiceAddress, nameAbbreviation?: string) => string | Promise<string>;
|
|
4955
|
+
}
|
|
4956
|
+
|
|
4957
|
+
/**
|
|
4958
|
+
* Default implementation of the invoice number service.
|
|
4959
|
+
*/
|
|
4960
|
+
declare class InvoiceNumberService implements InvoiceNumberServiceInterface<InvoiceAddress> {
|
|
4961
|
+
private readonly invoiceRepository;
|
|
4962
|
+
private readonly numberInvoicesRepository;
|
|
4963
|
+
protected readonly options: InvoicingOptions;
|
|
4964
|
+
constructor(invoiceRepository: Repository<Invoice>, numberInvoicesRepository: Repository<NumberInvoices, OmitStrict<NumberInvoices, 'id'>, OmitStrict<NumberInvoices, 'id'>>, options: InvoicingOptions);
|
|
4965
|
+
generateInvoiceNumber(recipientId: string, invoiceAddress: InvoiceAddress, transaction: Transaction | undefined, nameAbbreviation?: string): Promise<string>;
|
|
4966
|
+
generateTemporaryInvoiceNumber(recipientId: string, invoiceAddress: InvoiceAddress, nameAbbreviation?: string): Promise<string>;
|
|
4967
|
+
/**
|
|
4968
|
+
* Gets the temporary consecutive number of the invoices in this year and for the provided recipientId.
|
|
4969
|
+
* Prefixes it with zeroes until the result has the same length as this.options.numberOfDigits.
|
|
4970
|
+
* @param recipientId - The id of the recipient of the invoice.
|
|
4971
|
+
* @returns The number of invoices over a year filled up with zeroes to match this.options.numberOfDigits.
|
|
4972
|
+
*/
|
|
4973
|
+
protected getTemporaryConsecutiveNumber(recipientId: string): Promise<string>;
|
|
4974
|
+
/**
|
|
4975
|
+
* Gets the consecutive number of the invoices in this year.
|
|
4976
|
+
* Prefixes it with zeroes until the result has the same length as this.options.numberOfDigits.
|
|
4977
|
+
* @param recipientId - The id of the recipient of the invoice.
|
|
4978
|
+
* @param transaction - An optional transaction from outside to make sure any changes only apply when the transaction is committed.
|
|
4979
|
+
* @returns The number of invoices over a year filled up with zeroes to match this.options.numberOfDigits.
|
|
4980
|
+
*/
|
|
4981
|
+
protected getConsecutiveNumber(recipientId: string, transaction: Transaction | undefined): Promise<string>;
|
|
4982
|
+
/**
|
|
4983
|
+
* Gets the customer name abbreviation.
|
|
4984
|
+
* @param invoiceAddress - The address data to get the name abbreviation from.
|
|
4985
|
+
* @returns The first char of first and last name for private customers
|
|
4986
|
+
* and the first two chars of the company name for company customers.
|
|
4987
|
+
*/
|
|
4988
|
+
protected getCustomerNameAbbreviation(invoiceAddress: InvoiceAddress): string;
|
|
4989
|
+
private getPrivateCustomerAbbreviation;
|
|
4990
|
+
private getCompanyNameAbbreviation;
|
|
4991
|
+
/**
|
|
4992
|
+
* Validates the given invoice number.
|
|
4993
|
+
* @param invoiceNumber - The invoice number to validate.
|
|
4994
|
+
*/
|
|
4995
|
+
protected validateInvoiceNumber(invoiceNumber: string): Promise<void>;
|
|
4996
|
+
}
|
|
4997
|
+
|
|
4998
|
+
/**
|
|
4999
|
+
* Defines the different conformance types.
|
|
5000
|
+
* Is loosely typed so that a custom string can be provided.
|
|
5001
|
+
*/
|
|
5002
|
+
type InvoiceConformance = 'x-rechnung' | 'peppol' | string & {};
|
|
5003
|
+
/**
|
|
5004
|
+
* Interface for a service that handles updating an invoice pdf in a way that it conforms to a certain standard like X-Rechnung.
|
|
5005
|
+
*/
|
|
5006
|
+
interface InvoiceConformanceServiceInterface<Invoice extends Invoice> {
|
|
5007
|
+
/**
|
|
5008
|
+
* The name of the conformance that is handled by this service.
|
|
5009
|
+
*/
|
|
5010
|
+
readonly name: InvoiceConformance;
|
|
5011
|
+
/**
|
|
5012
|
+
* Updates the given pdf document definition.
|
|
5013
|
+
*/
|
|
5014
|
+
updateDocumentDefinition: (invoice: Invoice, definition: PdfDocumentDefinition) => void | Promise<void>;
|
|
5015
|
+
/**
|
|
5016
|
+
* Updates the given finished pdf document.
|
|
5017
|
+
*/
|
|
5018
|
+
updateDocument: (doc: PdfDocument) => void | Promise<void>;
|
|
5019
|
+
}
|
|
5020
|
+
|
|
5021
|
+
/**
|
|
5022
|
+
* Handles calculating anything regarding invoices.
|
|
5023
|
+
*/
|
|
5024
|
+
interface InvoiceCalcServiceInterface<Invoice extends Invoice> {
|
|
5025
|
+
/**
|
|
5026
|
+
* Gets the total price of an item before tax.
|
|
5027
|
+
* @param item - The invoice item to get the price from.
|
|
5028
|
+
* @returns The amount of the item times its price.
|
|
5029
|
+
*/
|
|
5030
|
+
getItemTotalPriceBeforeTax: (item: InvoiceItem) => BigNumber | Promise<BigNumber>;
|
|
5031
|
+
/**
|
|
5032
|
+
* Gets the total price of an item after tax.
|
|
5033
|
+
* @param item - The invoice item to get the price from.
|
|
5034
|
+
* @returns The total price before tax times 1 + tax/100.
|
|
5035
|
+
*/
|
|
5036
|
+
getItemTotalPriceAfterTax: (item: InvoiceItem) => BigNumber | Promise<BigNumber>;
|
|
5037
|
+
/**
|
|
5038
|
+
* Gets the total tax for the given item.
|
|
5039
|
+
* @param item - The item to get the total tax from.
|
|
5040
|
+
* @returns The total price before tax times tax/100.
|
|
5041
|
+
*/
|
|
5042
|
+
getItemTotalTax: (item: InvoiceItem) => BigNumber | Promise<BigNumber>;
|
|
5043
|
+
/**
|
|
5044
|
+
* Gets the total price of an invoice before tax.
|
|
5045
|
+
* @param invoice - The invoice to get the price from.
|
|
5046
|
+
* @returns The addition of the total price before tax of all items in the invoice. If this would be negative this returns 0.
|
|
5047
|
+
*/
|
|
5048
|
+
getTotalBeforeTax: (invoice: Invoice) => BigNumber | Promise<BigNumber>;
|
|
5049
|
+
/**
|
|
5050
|
+
* Gets the total price of an invoice after tax.
|
|
5051
|
+
* @param invoice - The invoice to get the price from.
|
|
5052
|
+
* @returns The addition of the total price before tax and the total tax of the invoice.
|
|
5053
|
+
*/
|
|
5054
|
+
getTotalAfterTax: (invoice: Invoice) => BigNumber | Promise<BigNumber>;
|
|
5055
|
+
/**
|
|
5056
|
+
* Gets the total tax of the invoice.
|
|
5057
|
+
* @param invoice - The invoice to get the total tax from.
|
|
5058
|
+
* @returns The addition of the tax of all items of the invoice.
|
|
5059
|
+
*/
|
|
5060
|
+
getTotalTax: (invoice: Invoice) => BigNumber | Promise<BigNumber>;
|
|
5061
|
+
/**
|
|
5062
|
+
* Gets the total tax for a specific tax group (eg. 19%).
|
|
5063
|
+
* @param invoice - The invoice to get the total tax from.
|
|
5064
|
+
* @param group - The tax group for which the total tax should be calculated.
|
|
5065
|
+
* @param groupOnlyByRate - Whether or not VAT groups are only determined by rate and not by category code.
|
|
5066
|
+
* @returns The addition of the tax of all items that are in the provided tax group.
|
|
5067
|
+
*/
|
|
5068
|
+
getTotalTaxForTaxGroup: (invoice: Invoice, group: Vat, groupOnlyByRate: boolean) => BigNumber | Promise<BigNumber>;
|
|
5069
|
+
/**
|
|
5070
|
+
* Gets the total price of an invoice before tax.
|
|
5071
|
+
* @param invoice - The invoice to get the price from.
|
|
5072
|
+
* @param group - The tax group to get the total before from.
|
|
5073
|
+
* @param groupOnlyByRate - Whether or not VAT groups are only determined by rate and not by category code.
|
|
5074
|
+
* @returns The addition of the total price before tax of all items in the invoice. If this would be negative this returns 0.
|
|
5075
|
+
*/
|
|
5076
|
+
getTotalBeforeTaxForTaxGroup: (invoice: Invoice, group: Vat, groupOnlyByRate: boolean) => BigNumber | Promise<BigNumber>;
|
|
5077
|
+
}
|
|
5078
|
+
|
|
5079
|
+
/**
|
|
5080
|
+
* The different possible document context ids.
|
|
5081
|
+
*/
|
|
5082
|
+
type EN16931DocumentContextId = 'urn:cen.eu:en16931:2017#compliant#urn:xrechnung:3.0' | 'urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0';
|
|
5083
|
+
/**
|
|
5084
|
+
* Base service shared by all the specific standards that conform to EN16931.
|
|
5085
|
+
*/
|
|
5086
|
+
declare abstract class EN16931ConformanceService implements InvoiceConformanceServiceInterface<Invoice> {
|
|
5087
|
+
protected readonly options: InvoicingOptions;
|
|
5088
|
+
private readonly invoiceCalcService;
|
|
5089
|
+
abstract readonly name: InvoiceConformance;
|
|
5090
|
+
abstract readonly documentContextId: EN16931DocumentContextId;
|
|
5091
|
+
constructor(options: InvoicingOptions, invoiceCalcService: InvoiceCalcServiceInterface<Invoice>);
|
|
5092
|
+
updateDocumentDefinition(invoice: Invoice, definition: PdfDocumentDefinition): Promise<void>;
|
|
5093
|
+
updateDocument(doc: PdfDocument): void;
|
|
5094
|
+
generateXml(invoice: Invoice): Promise<XML>;
|
|
5095
|
+
private createCrossIndustryInvoiceXml;
|
|
5096
|
+
private buildBuyerParty;
|
|
5097
|
+
private buildSellerParty;
|
|
5098
|
+
private buildTradeLineItems;
|
|
5099
|
+
private getCustomerName;
|
|
5100
|
+
private dateTo102;
|
|
5101
|
+
/**
|
|
5102
|
+
* Gets all relevant tax groups for the xml file.
|
|
5103
|
+
* @param invoice - The invoice to get the tax groups for.
|
|
5104
|
+
* @returns The tax groups for the xml.
|
|
5105
|
+
*/
|
|
5106
|
+
protected getTaxGroups(invoice: Invoice): Vat[];
|
|
5107
|
+
}
|
|
5108
|
+
|
|
5109
|
+
/**
|
|
5110
|
+
* Handles conforming to the X-Rechnung standard.
|
|
5111
|
+
*/
|
|
5112
|
+
declare class XRechnungConformanceService extends EN16931ConformanceService {
|
|
5113
|
+
readonly name: InvoiceConformance;
|
|
5114
|
+
readonly documentContextId: EN16931DocumentContextId;
|
|
5115
|
+
}
|
|
5116
|
+
|
|
5117
|
+
/**
|
|
5118
|
+
* Handles conforming to the peppol standard.
|
|
5119
|
+
*/
|
|
5120
|
+
declare class PeppolConformanceService extends EN16931ConformanceService {
|
|
5121
|
+
readonly name: InvoiceConformance;
|
|
5122
|
+
readonly documentContextId: EN16931DocumentContextId;
|
|
5123
|
+
}
|
|
5124
|
+
|
|
5125
|
+
/**
|
|
5126
|
+
* Handles generating pdf invoice files.
|
|
5127
|
+
*/
|
|
5128
|
+
interface InvoicePdfServiceInterface<Invoice extends Invoice> {
|
|
5129
|
+
/**
|
|
5130
|
+
* Creates a pdf for the provided invoice.
|
|
5131
|
+
* @param invoice - The invoice to create the pdf for.
|
|
5132
|
+
*/
|
|
5133
|
+
generateInvoicePdf: (invoice: Invoice, conformance: InvoiceConformance, ...args: any[]) => PdfDocument | Promise<PdfDocument>;
|
|
5134
|
+
}
|
|
5135
|
+
|
|
5136
|
+
/**
|
|
5137
|
+
* Default implementation of the invoice pdf service.
|
|
5138
|
+
*/
|
|
5139
|
+
declare class InvoicePdfService implements InvoicePdfServiceInterface<Invoice> {
|
|
5140
|
+
protected readonly options: InvoicingOptions;
|
|
5141
|
+
private readonly invoiceCalcService;
|
|
5142
|
+
private readonly invoiceConformanceServices;
|
|
5143
|
+
private readonly formatDate;
|
|
5144
|
+
private readonly formatPrice;
|
|
5145
|
+
private readonly formatPercent;
|
|
5146
|
+
/**
|
|
5147
|
+
* The definition of the header of the pdf.
|
|
5148
|
+
*/
|
|
5149
|
+
protected readonly header: PdfContentDefinition;
|
|
5150
|
+
/**
|
|
5151
|
+
* The definition of the footer of the pdf.
|
|
5152
|
+
*/
|
|
5153
|
+
protected readonly footer: PdfContentDefinition;
|
|
5154
|
+
/**
|
|
5155
|
+
* The definition of the column in the letterhead that displays the information about the company that is sending out the invoice.
|
|
5156
|
+
*/
|
|
5157
|
+
protected readonly companyLetterheadColumn: PdfColumnDefinition;
|
|
5158
|
+
constructor(options: InvoicingOptions, invoiceCalcService: InvoiceCalcServiceInterface<Invoice>, invoiceConformanceServices: InvoiceConformanceServiceInterface<Invoice>[], formatDate: FormatDateFn, formatPrice: FormatPriceFn, formatPercent: FormatPercentFn);
|
|
5159
|
+
generateInvoicePdf(invoice: Invoice, conformance?: InvoiceConformance): Promise<PdfDocument>;
|
|
5160
|
+
/**
|
|
5161
|
+
* Generates a pdf document definition for the given invoice.
|
|
5162
|
+
* @param invoice - The invoice to generate the document definition for.
|
|
5163
|
+
* @param conformance - The legal conformance that the invoice should conform to.
|
|
5164
|
+
* @returns The invoice document definition.
|
|
5165
|
+
*/
|
|
5166
|
+
protected generateInvoiceDocumentDefinition(invoice: Invoice, conformance: InvoiceConformance | undefined): Promise<PdfDocumentDefinition>;
|
|
5167
|
+
/**
|
|
5168
|
+
* Gets the conformance service for the given name.
|
|
5169
|
+
* @param conformance - The name of the conformance to get the service for.
|
|
5170
|
+
* @returns The found conformance service.
|
|
5171
|
+
* @throws When no conformance service has been found.
|
|
5172
|
+
*/
|
|
5173
|
+
protected getConformanceService(conformance: InvoiceConformance): InvoiceConformanceServiceInterface<Invoice>;
|
|
5174
|
+
/**
|
|
5175
|
+
* Gets the table that displays the total price of all items.
|
|
5176
|
+
* @param invoice - The invoice to get the table from.
|
|
5177
|
+
* @param taxGroups - The different tax groups that need to be taken into consideration.
|
|
5178
|
+
* @returns The total price of all items and the tax groups.
|
|
5179
|
+
*/
|
|
5180
|
+
protected getTotalTable(invoice: Invoice, taxGroups: Vat[]): Promise<PdfContentDefinition>;
|
|
5181
|
+
/**
|
|
5182
|
+
* Gets the body of the total table.
|
|
5183
|
+
* @param invoice - The invoice to build the body from.
|
|
5184
|
+
* @param taxGroups - The different tax groups that need to be taken into consideration.
|
|
5185
|
+
* @returns The body of the total table.
|
|
5186
|
+
*/
|
|
5187
|
+
protected getTotalBody(invoice: Invoice, taxGroups: Vat[]): Promise<PdfTableCellDefinition[][]>;
|
|
5188
|
+
/**
|
|
5189
|
+
* Gets the table that displays all invoice items.
|
|
5190
|
+
* @param invoice - The invoice to build the table from.
|
|
5191
|
+
* @param taxGroups - The different tax groups that need to be taken into consideration.
|
|
5192
|
+
* @returns The table with all invoice items.
|
|
5193
|
+
*/
|
|
5194
|
+
protected getInvoiceItemsTable(invoice: Invoice, taxGroups: Vat[]): Promise<PdfContentDefinition>;
|
|
5195
|
+
/**
|
|
5196
|
+
* Gets the body of the invoice items table.
|
|
5197
|
+
* @param invoice - The invoice to build the body from.
|
|
5198
|
+
* @param taxGroups - The different tax groups that need to be taken into consideration.
|
|
5199
|
+
* @returns The body of the invoice items table.
|
|
5200
|
+
*/
|
|
5201
|
+
protected getInvoiceItemsBody(invoice: Invoice, taxGroups: Vat[]): Promise<PdfTableCellDefinition[][]>;
|
|
5202
|
+
/**
|
|
5203
|
+
* Gets the headers for the invoice items table. If the only tax group is 0, the tax column is removed.
|
|
5204
|
+
* @param taxGroups - The different tax groups that need to be taken into consideration.
|
|
5205
|
+
* @returns The headers of the invoice items table.
|
|
5206
|
+
*/
|
|
5207
|
+
protected getInvoiceItemsHeaders(taxGroups: Vat[]): PdfTableCellDefinition[];
|
|
5208
|
+
/**
|
|
5209
|
+
* Gets the text that should be displayed before the actual invoice items start.
|
|
5210
|
+
* @param paragraphs - The paragraphs to get the text from.
|
|
5211
|
+
* @returns The text that should be displayed before the actual invoice items.
|
|
5212
|
+
*/
|
|
5213
|
+
protected getContentFromParagraphs(paragraphs: string[]): PdfContentDefinition[];
|
|
5214
|
+
/**
|
|
5215
|
+
* Gets the invoice number and the dates.
|
|
5216
|
+
* @param invoice - The invoice to build the content from.
|
|
5217
|
+
* @returns The content containing the invoice number and the date, performance date and due date.
|
|
5218
|
+
*/
|
|
5219
|
+
protected getNumberAndDates(invoice: Invoice): PdfContentDefinition;
|
|
5220
|
+
/**
|
|
5221
|
+
* Gets the letterhead.
|
|
5222
|
+
* @param invoice - The invoice to get the letterhead from.
|
|
5223
|
+
* @returns The letterhead of the customer and the company.
|
|
5224
|
+
*/
|
|
5225
|
+
protected getLetterhead(invoice: Invoice): PdfContentDefinition;
|
|
5226
|
+
/**
|
|
5227
|
+
* Gets the letterhead of the customer.
|
|
5228
|
+
* @param invoice - The invoice to get the customer letterhead from.
|
|
5229
|
+
* @returns The letterhead of the customer, containing the name and address.
|
|
5230
|
+
*/
|
|
5231
|
+
protected getCustomerLetterheadColumn(invoice: Invoice): PdfColumnDefinition;
|
|
5232
|
+
private getCustomerName;
|
|
5233
|
+
/**
|
|
5234
|
+
* Gets the font size for the provided company address line.
|
|
5235
|
+
* Checks if the address line is too big and makes the font smaller accordingly.
|
|
5236
|
+
* @param companyAddressLine - The company address line of the invoice.
|
|
5237
|
+
* @returns The font size to use for the letter head.
|
|
5238
|
+
*/
|
|
5239
|
+
protected getFontSizeForLetterhead(companyAddressLine: string): number;
|
|
5240
|
+
/**
|
|
5241
|
+
* Gets the letterhead of the company.
|
|
5242
|
+
* @returns The letterhead of the company, containing full name, address and contact information.
|
|
5243
|
+
*/
|
|
5244
|
+
protected getCompanyLetterheadColumn(): PdfColumnDefinition;
|
|
5245
|
+
/**
|
|
5246
|
+
* Gets all relevant tax groups for the pdf file.
|
|
5247
|
+
* @param invoice - The invoice to get the tax groups for.
|
|
5248
|
+
* @returns The tax groups for the pdf.
|
|
5249
|
+
*/
|
|
5250
|
+
protected getTaxGroups(invoice: Invoice): Vat[];
|
|
5251
|
+
/**
|
|
5252
|
+
* Gets the Content of the header.
|
|
5253
|
+
* @returns A row with the logo or an empty array if no logo has been specified.
|
|
5254
|
+
*/
|
|
5255
|
+
protected getHeader(): PdfContentDefinition;
|
|
5256
|
+
/**
|
|
5257
|
+
* Gets the Content of the footer.
|
|
5258
|
+
* @returns Multiple rows containing information about the company and payment data.
|
|
5259
|
+
*/
|
|
5260
|
+
protected getFooter(): PdfContentDefinition;
|
|
5261
|
+
/**
|
|
5262
|
+
* Gets the first column of the footer.
|
|
5263
|
+
* @returns The column definition.
|
|
5264
|
+
*/
|
|
5265
|
+
protected getFirstFooterColumn(): PdfColumnDefinition;
|
|
5266
|
+
/**
|
|
5267
|
+
* Gets the second column of the footer.
|
|
5268
|
+
* @returns The column definition.
|
|
5269
|
+
*/
|
|
5270
|
+
protected getSecondFooterColumn(): PdfColumnDefinition;
|
|
5271
|
+
}
|
|
5272
|
+
|
|
5273
|
+
/**
|
|
5274
|
+
* Default implementation of the invoice calculation service.
|
|
5275
|
+
*/
|
|
5276
|
+
declare class InvoiceCalcService implements InvoiceCalcServiceInterface<Invoice> {
|
|
5277
|
+
getItemTotalPriceBeforeTax(item: InvoiceItem): BigNumber;
|
|
5278
|
+
getItemTotalPriceAfterTax(item: InvoiceItem): BigNumber;
|
|
5279
|
+
getItemTotalTax(item: InvoiceItem): BigNumber;
|
|
5280
|
+
getTotalBeforeTax<Invoice extends Invoice>(invoice: Invoice): BigNumber;
|
|
5281
|
+
getTotalAfterTax<Invoice extends Invoice>(invoice: Invoice): BigNumber;
|
|
5282
|
+
getTotalTax<Invoice extends Invoice>(invoice: Invoice): BigNumber;
|
|
5283
|
+
getTotalTaxForTaxGroup<Invoice extends Invoice>(invoice: Invoice, group: Vat, groupOnlyByRate: boolean): BigNumber;
|
|
5284
|
+
getTotalBeforeTaxForTaxGroup<Invoice extends Invoice>(invoice: Invoice, group: Vat, groupOnlyByRate: boolean): BigNumber;
|
|
5285
|
+
private getItemsForTaxGroup;
|
|
5286
|
+
}
|
|
5287
|
+
|
|
5288
|
+
/**
|
|
5289
|
+
* The dependency injection tokens used by the ZibriInvoicingPlugin.
|
|
5290
|
+
*/
|
|
5291
|
+
declare const ZIBRI_INVOICING_DI_TOKENS: {
|
|
5292
|
+
readonly INVOICE_NUMBER_SERVICE: "zi.invoicing.invoice_number_service";
|
|
5293
|
+
readonly OPTIONS_INPUT: "zi.invoicing.options_input";
|
|
5294
|
+
readonly OPTIONS: "zi.invoicing.options";
|
|
5295
|
+
readonly INVOICE_CALC_SERVICE: "zi.invoicing.invoice_calc_service";
|
|
5296
|
+
readonly INVOICE_PDF_SERVICE: "zi.invoicing.invoice_pdf_service";
|
|
5297
|
+
readonly INVOICE_CONFORMANCE_SERVICES: "zi.invoicing.invoice_conformance_services";
|
|
5298
|
+
};
|
|
5299
|
+
type ZibriInvoicingPluginDiProvider<T> = OmitStrict<DiProvider<T>, 'token'>;
|
|
5300
|
+
type ZibriInvoicingPluginDiProviders = {
|
|
5301
|
+
[ZIBRI_INVOICING_DI_TOKENS.INVOICE_NUMBER_SERVICE]: ZibriInvoicingPluginDiProvider<InvoiceNumberServiceInterface<any>>;
|
|
5302
|
+
[ZIBRI_INVOICING_DI_TOKENS.OPTIONS]: ZibriInvoicingPluginDiProvider<InvoicingOptions>;
|
|
5303
|
+
[ZIBRI_INVOICING_DI_TOKENS.OPTIONS_INPUT]: ZibriInvoicingPluginDiProvider<InvoicingOptionsInput>;
|
|
5304
|
+
[ZIBRI_INVOICING_DI_TOKENS.INVOICE_PDF_SERVICE]: ZibriInvoicingPluginDiProvider<InvoicePdfServiceInterface<any>>;
|
|
5305
|
+
[ZIBRI_INVOICING_DI_TOKENS.INVOICE_CALC_SERVICE]: ZibriInvoicingPluginDiProvider<InvoiceCalcServiceInterface<any>>;
|
|
5306
|
+
[ZIBRI_INVOICING_DI_TOKENS.INVOICE_CONFORMANCE_SERVICES]: ZibriInvoicingPluginDiProvider<InvoiceConformanceServiceInterface<any>[]>;
|
|
5307
|
+
};
|
|
5308
|
+
|
|
5309
|
+
/**
|
|
5310
|
+
* All options for a Zibri application.
|
|
5311
|
+
*/
|
|
5312
|
+
type ZibriApplicationOptions = {
|
|
5313
|
+
/**
|
|
5314
|
+
* The name of the app.
|
|
5315
|
+
*/
|
|
5316
|
+
name: string;
|
|
5317
|
+
/**
|
|
5318
|
+
* The base url of the app.
|
|
5319
|
+
* Eg. Http://localhost:3000.
|
|
5320
|
+
*/
|
|
5321
|
+
baseUrl: string;
|
|
5322
|
+
/**
|
|
5323
|
+
* The SemVer version of the app.
|
|
5324
|
+
*
|
|
5325
|
+
* Is also used by migrations by default.
|
|
5326
|
+
*/
|
|
5327
|
+
version: Version;
|
|
5328
|
+
/**
|
|
5329
|
+
* The controllers to register in the app.
|
|
5330
|
+
*/
|
|
5331
|
+
controllers: Newable<unknown>[];
|
|
5332
|
+
/**
|
|
5333
|
+
* The data sources to register in the app.
|
|
5334
|
+
*/
|
|
5335
|
+
dataSources?: Newable<BaseDataSource>[];
|
|
5336
|
+
/**
|
|
5337
|
+
* The DI providers to register/override.
|
|
5338
|
+
*/
|
|
5339
|
+
providers?: DiProvider<unknown>[];
|
|
5340
|
+
/**
|
|
5341
|
+
* The body parsers to register.
|
|
5342
|
+
*
|
|
5343
|
+
* If nothing is provided, the Zibri default parsers will be used.
|
|
5344
|
+
*/
|
|
5345
|
+
bodyParsers?: Newable<BodyParserInterface>[];
|
|
5346
|
+
/**
|
|
5347
|
+
* The auth strategies to register.
|
|
5348
|
+
*
|
|
5349
|
+
* If nothing is provided, the Zibri default jwt auth strategy will be used.
|
|
5350
|
+
*/
|
|
5351
|
+
authStrategies?: AuthStrategies;
|
|
5352
|
+
/**
|
|
5353
|
+
* The cron jobs to register in the app.
|
|
5354
|
+
*/
|
|
5355
|
+
cronJobs?: Newable<CronJob>[];
|
|
5356
|
+
/**
|
|
5357
|
+
* The plugins to be used.
|
|
5358
|
+
*/
|
|
5359
|
+
plugins?: Newable<ZibriPlugin>[];
|
|
5360
|
+
};
|
|
5361
|
+
|
|
5362
|
+
type FullZibriApplicationOptions = Required<OmitStrict<ZibriApplicationOptions, 'plugins'>>;
|
|
5363
|
+
/**
|
|
5364
|
+
* A Zibri application.
|
|
5365
|
+
*/
|
|
5366
|
+
declare class ZibriApplication {
|
|
5367
|
+
private readonly providedOptions;
|
|
5368
|
+
/**
|
|
5369
|
+
* The internal express app.
|
|
5370
|
+
*/
|
|
5371
|
+
private readonly express;
|
|
5372
|
+
private _router;
|
|
5373
|
+
/**
|
|
5374
|
+
* The router used by the application.
|
|
5375
|
+
*/
|
|
5376
|
+
get router(): RouterInterface;
|
|
5377
|
+
private logger;
|
|
5378
|
+
private metricsService;
|
|
5379
|
+
private assetService;
|
|
5380
|
+
private openApiService;
|
|
5381
|
+
private parser;
|
|
5382
|
+
private dataSourceService;
|
|
5383
|
+
private authService;
|
|
5384
|
+
private cronService;
|
|
5385
|
+
private multithreadingService;
|
|
5386
|
+
private emailService;
|
|
5387
|
+
private mailingListService?;
|
|
5388
|
+
/**
|
|
5389
|
+
* The options of which the application was build.
|
|
5390
|
+
*/
|
|
5391
|
+
readonly options: FullZibriApplicationOptions;
|
|
5392
|
+
constructor(providedOptions: ZibriApplicationOptions);
|
|
5393
|
+
use(handler: RequestHandler): express.Express;
|
|
5394
|
+
use(...handlers: RequestHandler[]): void;
|
|
5395
|
+
use(path: Route, ...handlers: RequestHandler[]): void;
|
|
5396
|
+
use(path: Route, handlers: RequestHandler[]): void;
|
|
5397
|
+
/**
|
|
5398
|
+
* Initializes the app.
|
|
5399
|
+
* @param H - The global handlebars instance, needed to provide some helpers used in templating.
|
|
5400
|
+
*/
|
|
5401
|
+
init(H: typeof Handlebars): Promise<void>;
|
|
5402
|
+
/**
|
|
5403
|
+
* Starts on the given port.
|
|
5404
|
+
* @param port - The port to start on.
|
|
5405
|
+
* @throws When the app has already been started.
|
|
5406
|
+
*/
|
|
5407
|
+
start(port: number): Promise<void>;
|
|
5408
|
+
private createFullOptions;
|
|
5409
|
+
}
|
|
5410
|
+
|
|
5411
|
+
/**
|
|
5412
|
+
* A global error handler function.
|
|
5413
|
+
*/
|
|
5414
|
+
type GlobalErrorHandler = (err: unknown, req: HttpRequest, res: HttpResponse, next: NextFunction) => void | Promise<void>;
|
|
5415
|
+
|
|
5416
|
+
/**
|
|
5417
|
+
* The default error handler implementation of Zibri.
|
|
5418
|
+
* @param error - The error that was caught.
|
|
5419
|
+
* @param req - The http request.
|
|
5420
|
+
* @param res - The http response.
|
|
5421
|
+
* @param next - The express next function.
|
|
5422
|
+
*/
|
|
5423
|
+
declare const errorHandler: GlobalErrorHandler;
|
|
5424
|
+
|
|
5425
|
+
/**
|
|
5426
|
+
* A base http error.
|
|
5427
|
+
*/
|
|
5428
|
+
declare abstract class HttpError extends Error {
|
|
5429
|
+
/**
|
|
5430
|
+
* The status of the error.
|
|
5431
|
+
*/
|
|
5432
|
+
status: HttpStatus;
|
|
5433
|
+
/**
|
|
5434
|
+
* The title of the error.
|
|
5435
|
+
*/
|
|
5436
|
+
title: string;
|
|
5437
|
+
/**
|
|
5438
|
+
* A paragraphs error with the error message.
|
|
5439
|
+
*/
|
|
5440
|
+
paragraphs: string[];
|
|
5441
|
+
constructor(message: string | string[], status: HttpStatus, title: string, options?: ErrorOptions);
|
|
5442
|
+
}
|
|
5443
|
+
/**
|
|
5444
|
+
* Check whether or not the given value is a http error.
|
|
5445
|
+
* @param value - The value to check.
|
|
5446
|
+
* @returns True when value is an instance of HttpError, false otherwise.
|
|
5447
|
+
*/
|
|
5448
|
+
declare function isHttpError(value: unknown): value is HttpError;
|
|
5449
|
+
|
|
5450
|
+
/**
|
|
5451
|
+
* An error to throw when something unexpected happened inside the server.
|
|
5452
|
+
*/
|
|
5453
|
+
declare class InternalServerError extends HttpError {
|
|
5454
|
+
constructor(message: string | string[], options?: ErrorOptions);
|
|
5455
|
+
}
|
|
5456
|
+
|
|
5457
|
+
/**
|
|
5458
|
+
* An error to throw when the requested resource could not be found.
|
|
5459
|
+
*
|
|
5460
|
+
* In contrast to the UnmatchedRouteError, this should be thrown when the endpoint actually exists (eg. /items/:id), but the resource was not found.
|
|
5461
|
+
* Eg. Because the id of the item is incorrect.
|
|
5462
|
+
*/
|
|
5463
|
+
declare class NotFoundError extends HttpError {
|
|
5464
|
+
constructor(message: string | string[], options?: ErrorOptions);
|
|
5465
|
+
}
|
|
5466
|
+
|
|
5467
|
+
/**
|
|
5468
|
+
* An error to throw when a route requested by a user does not exist at all.
|
|
5469
|
+
*
|
|
5470
|
+
* In contrast to NotFoundError, this should only be thrown the route itself does not exist at all.
|
|
5471
|
+
* Eg. /does-not-exist and not when the route itself (eg. Items/:id) exists, but it could not find a value for eg. /items/42.
|
|
5472
|
+
*/
|
|
5473
|
+
declare class UnmatchedRouteError extends NotFoundError {
|
|
5474
|
+
constructor(originalUrl: string, options?: ErrorOptions);
|
|
5475
|
+
}
|
|
5476
|
+
|
|
5477
|
+
/**
|
|
5478
|
+
* An error to throw when the user send some invalid data to the server.
|
|
5479
|
+
*/
|
|
5480
|
+
declare class BadRequestError extends HttpError {
|
|
5481
|
+
constructor(message: string | string[], options?: ErrorOptions);
|
|
5482
|
+
}
|
|
5483
|
+
|
|
5484
|
+
/**
|
|
5485
|
+
* A validation problem, consisting of the key where the problem is located and a description of the problem.
|
|
5486
|
+
*/
|
|
5487
|
+
type ValidationProblem = {
|
|
5488
|
+
/**
|
|
5489
|
+
* The key where the problem is located.
|
|
5490
|
+
*/
|
|
5491
|
+
key: string;
|
|
5492
|
+
/**
|
|
5493
|
+
* The validation problem message.
|
|
5494
|
+
*/
|
|
5495
|
+
message: string;
|
|
5496
|
+
};
|
|
5497
|
+
/**
|
|
5498
|
+
* The validation problem that the property is required and no value has been provided.
|
|
5499
|
+
*/
|
|
5500
|
+
declare class IsRequiredValidationProblem implements ValidationProblem {
|
|
5501
|
+
readonly key: string;
|
|
5502
|
+
readonly message: string;
|
|
5503
|
+
constructor(key: string);
|
|
5504
|
+
}
|
|
5505
|
+
/**
|
|
5506
|
+
* The validation problem that the provided value has an incorrect type.
|
|
5507
|
+
*/
|
|
5508
|
+
declare class TypeMismatchValidationProblem implements ValidationProblem {
|
|
5509
|
+
readonly key: string;
|
|
5510
|
+
readonly message: string;
|
|
4375
5511
|
constructor(key: string, type: string);
|
|
4376
5512
|
}
|
|
4377
5513
|
/**
|
|
@@ -4464,6 +5600,20 @@ declare class TooManyRequestsError extends HttpError {
|
|
|
4464
5600
|
constructor(message: string | string[], options?: ErrorOptions);
|
|
4465
5601
|
}
|
|
4466
5602
|
|
|
5603
|
+
/**
|
|
5604
|
+
* An error to throw when the user send some invalid data to the server.
|
|
5605
|
+
*/
|
|
5606
|
+
declare class ConflictError extends HttpError {
|
|
5607
|
+
constructor(message: string | string[], options?: ErrorOptions);
|
|
5608
|
+
}
|
|
5609
|
+
|
|
5610
|
+
/**
|
|
5611
|
+
* An error to throw when there are entities that are not registered in a data source.
|
|
5612
|
+
*/
|
|
5613
|
+
declare class MissingEntitiesError extends Error {
|
|
5614
|
+
constructor(context: string, orphanedEntities: Newable<BaseEntity>[]);
|
|
5615
|
+
}
|
|
5616
|
+
|
|
4467
5617
|
/**
|
|
4468
5618
|
* The possible state that the app can be in.
|
|
4469
5619
|
*/
|
|
@@ -4750,8 +5900,7 @@ declare enum ChangeSetType {
|
|
|
4750
5900
|
/**
|
|
4751
5901
|
* Defines a single value change of an change set.
|
|
4752
5902
|
*/
|
|
4753
|
-
declare class Change<T = unknown>
|
|
4754
|
-
id: string;
|
|
5903
|
+
declare class Change<T = unknown> extends BaseEntity {
|
|
4755
5904
|
/**
|
|
4756
5905
|
* The key of the value that has been changed.
|
|
4757
5906
|
*/
|
|
@@ -4765,7 +5914,7 @@ declare class Change<T = unknown> implements BaseEntity {
|
|
|
4765
5914
|
*/
|
|
4766
5915
|
newValue?: T;
|
|
4767
5916
|
/**
|
|
4768
|
-
* The
|
|
5917
|
+
* The change set that this change belongs to.
|
|
4769
5918
|
*/
|
|
4770
5919
|
changeSet: ChangeSet;
|
|
4771
5920
|
}
|
|
@@ -4782,8 +5931,7 @@ type NewChange = OmitStrict<Change, 'id' | 'changeSet'>;
|
|
|
4782
5931
|
* A single change set.
|
|
4783
5932
|
* Gets automatically created for configured entities whenever they are changed.
|
|
4784
5933
|
*/
|
|
4785
|
-
declare class ChangeSet
|
|
4786
|
-
id: string;
|
|
5934
|
+
declare class ChangeSet extends BaseEntity {
|
|
4787
5935
|
/**
|
|
4788
5936
|
* Whether this change set was initialized on creating, updating or deleting the entity.
|
|
4789
5937
|
*/
|
|
@@ -5156,39 +6304,428 @@ declare class SoftDeleteRepository<T extends SoftDeleteEntity, CreateData extend
|
|
|
5156
6304
|
}
|
|
5157
6305
|
|
|
5158
6306
|
/**
|
|
5159
|
-
*
|
|
5160
|
-
* @param v1 - The first version.
|
|
5161
|
-
* @param v2 - The second version to compare against.
|
|
5162
|
-
* @returns 'bigger', 'equal' or 'smaller'.
|
|
6307
|
+
* Options for handling multithreading.
|
|
5163
6308
|
*/
|
|
5164
|
-
|
|
6309
|
+
type MultithreadingOptions = {
|
|
6310
|
+
/**
|
|
6311
|
+
* The number of threads that can be used.
|
|
6312
|
+
* Please notice that there is also **maxPriorityThreads** for the number of threads that should be reserved for priority jobs.
|
|
6313
|
+
* Both these values added up need to be smaller than your current machines available threads.
|
|
6314
|
+
* @default os.availableParallelism() - Number(process.env.UV_THREADPOOL_SIZE ?? '4') - 1 (the -1 is reserved for a priority thread)
|
|
6315
|
+
*/
|
|
6316
|
+
maxThreads: number;
|
|
6317
|
+
/**
|
|
6318
|
+
* The number of threads that can be used by priority jobs.
|
|
6319
|
+
* Please notice that there is also **maxThreads** for the number of threads that can be used by normal and priority jobs.
|
|
6320
|
+
* Both these values added up need to be smaller than your current machines available threads.
|
|
6321
|
+
* @default 1
|
|
6322
|
+
*/
|
|
6323
|
+
maxPriorityThreads: number;
|
|
6324
|
+
/**
|
|
6325
|
+
* The default timeout for a thread job.
|
|
6326
|
+
* @default 1 hour.
|
|
6327
|
+
*/
|
|
6328
|
+
defaultTimeoutMs: number;
|
|
6329
|
+
/**
|
|
6330
|
+
* The default timeout for a priority thread job.
|
|
6331
|
+
* @default 5 minutes.
|
|
6332
|
+
*/
|
|
6333
|
+
defaultTimeoutPriorityMs: number;
|
|
6334
|
+
};
|
|
5165
6335
|
|
|
5166
6336
|
/**
|
|
5167
|
-
*
|
|
5168
|
-
* @param value - The value to check.
|
|
6337
|
+
* The status that a thread job can have.
|
|
5169
6338
|
*/
|
|
5170
|
-
declare
|
|
6339
|
+
declare enum ThreadJobStatus {
|
|
6340
|
+
IN_QUEUE = "IN_QUEUE",
|
|
6341
|
+
IN_PROGRESS = "IN_PROGRESS",
|
|
6342
|
+
COMPLETED = "COMPLETED",
|
|
6343
|
+
FAILED = "FAILED",
|
|
6344
|
+
CANCELLED = "CANCELLED"
|
|
6345
|
+
}
|
|
5171
6346
|
|
|
5172
6347
|
/**
|
|
5173
|
-
*
|
|
6348
|
+
* The internal thread job message types.
|
|
6349
|
+
*/
|
|
6350
|
+
type ThreadJobMessage<T = unknown> = StatusMessage | ProgressMessage | CompletionMessage<T> | InitializationMessage | ErrorMessage;
|
|
6351
|
+
/**
|
|
6352
|
+
* The message that is sent once on initialization.
|
|
6353
|
+
*/
|
|
6354
|
+
type InitializationMessage = {
|
|
6355
|
+
/**
|
|
6356
|
+
* The type of the message.
|
|
6357
|
+
*/
|
|
6358
|
+
type: 'initialization';
|
|
6359
|
+
};
|
|
6360
|
+
/**
|
|
6361
|
+
* A message to change the status of the thread job.
|
|
6362
|
+
*/
|
|
6363
|
+
type StatusMessage = {
|
|
6364
|
+
/**
|
|
6365
|
+
* The type of the message.
|
|
6366
|
+
*/
|
|
6367
|
+
type: 'status';
|
|
6368
|
+
/**
|
|
6369
|
+
* The status that should be set.
|
|
6370
|
+
*/
|
|
6371
|
+
status: ThreadJobStatus;
|
|
6372
|
+
};
|
|
6373
|
+
/**
|
|
6374
|
+
* A message to indicate that the thread job has failed.
|
|
6375
|
+
*/
|
|
6376
|
+
type ErrorMessage<ErrorType extends Error = Error> = {
|
|
6377
|
+
/**
|
|
6378
|
+
* The type of the message.
|
|
6379
|
+
*/
|
|
6380
|
+
type: 'error';
|
|
6381
|
+
/**
|
|
6382
|
+
* The error that the thread job failed with.
|
|
6383
|
+
*/
|
|
6384
|
+
error: ErrorType;
|
|
6385
|
+
};
|
|
6386
|
+
/**
|
|
6387
|
+
* A message to update the progress of the job.
|
|
6388
|
+
*/
|
|
6389
|
+
type ProgressMessage = {
|
|
6390
|
+
/**
|
|
6391
|
+
* The type of the message.
|
|
6392
|
+
*/
|
|
6393
|
+
type: 'progress';
|
|
6394
|
+
/**
|
|
6395
|
+
* The progress as a percentage number.
|
|
6396
|
+
* Cannot be set to 100 as the CompletionMessage should be used for that.
|
|
6397
|
+
*/
|
|
6398
|
+
progress: Percentage;
|
|
6399
|
+
};
|
|
6400
|
+
/**
|
|
6401
|
+
* A message to indicate that the thread job was completed successfully.
|
|
6402
|
+
*/
|
|
6403
|
+
type CompletionMessage<T> = {
|
|
6404
|
+
/**
|
|
6405
|
+
* The type of the message.
|
|
6406
|
+
*/
|
|
6407
|
+
type: 'completion';
|
|
6408
|
+
/**
|
|
6409
|
+
* The result of the thread job.
|
|
6410
|
+
*/
|
|
6411
|
+
result: T;
|
|
6412
|
+
};
|
|
6413
|
+
|
|
6414
|
+
/**
|
|
6415
|
+
* The base data for a thread job worker.
|
|
6416
|
+
*/
|
|
6417
|
+
type BaseThreadJobWorkerData = {
|
|
6418
|
+
/**
|
|
6419
|
+
* The path to the worker file.
|
|
6420
|
+
* **This can either be a ts or a js file**.
|
|
6421
|
+
*/
|
|
6422
|
+
filePath: string;
|
|
6423
|
+
};
|
|
6424
|
+
/**
|
|
6425
|
+
* The data to run a function in the thread worker.
|
|
6426
|
+
*
|
|
6427
|
+
* **IMPORTANT**: This uses "eval" in the thread worker, so make sure that the data passed is not malicious.
|
|
5174
6428
|
*/
|
|
5175
|
-
type
|
|
6429
|
+
type BaseFunctionThreadJobWorkerData<I> = BaseThreadJobWorkerData & {
|
|
6430
|
+
/**
|
|
6431
|
+
* A stringified function to call in the worker.
|
|
6432
|
+
*/
|
|
6433
|
+
func: string;
|
|
6434
|
+
/**
|
|
6435
|
+
* The input parameter of the function.
|
|
6436
|
+
*/
|
|
6437
|
+
input: I;
|
|
6438
|
+
};
|
|
5176
6439
|
|
|
5177
6440
|
/**
|
|
5178
|
-
*
|
|
6441
|
+
* The function values of the thread job data.
|
|
6442
|
+
* This is separated because this cannot be persisted in a database.
|
|
5179
6443
|
*/
|
|
5180
|
-
type
|
|
6444
|
+
type ThreadJobDataFunctions = {
|
|
5181
6445
|
/**
|
|
5182
|
-
*
|
|
6446
|
+
* What should happen when a message is received from the thread job.
|
|
5183
6447
|
*/
|
|
5184
|
-
|
|
6448
|
+
onMessage?: (message: unknown) => void;
|
|
6449
|
+
/**
|
|
6450
|
+
* What should happen when the thread job completes.
|
|
6451
|
+
*/
|
|
6452
|
+
onComplete?: () => void;
|
|
6453
|
+
/**
|
|
6454
|
+
* What should happen when the thread job was cancelled.
|
|
6455
|
+
*/
|
|
6456
|
+
onCancel?: () => void;
|
|
6457
|
+
/**
|
|
6458
|
+
* What should happen when an error occurs inside the thread job.
|
|
6459
|
+
*/
|
|
6460
|
+
onError?: (error: Error) => void;
|
|
5185
6461
|
};
|
|
5186
6462
|
/**
|
|
5187
|
-
*
|
|
5188
|
-
* @param promises - The promises to resolve.
|
|
5189
|
-
* @param options - Options for chunking, like the size of chunks etc.
|
|
5190
|
-
* @returns The resolved promises after all chunks have been resolved.
|
|
6463
|
+
* Data that is needed to start a thread job.
|
|
5191
6464
|
*/
|
|
5192
|
-
|
|
6465
|
+
type ThreadJobData<T extends BaseThreadJobWorkerData> = ThreadJobDataFunctions & {
|
|
6466
|
+
/**
|
|
6467
|
+
* Data that should be passed to the worker.
|
|
6468
|
+
*/
|
|
6469
|
+
workerData: T;
|
|
6470
|
+
/**
|
|
6471
|
+
* Wether or not the job should use priority workers.
|
|
6472
|
+
* @default false
|
|
6473
|
+
*/
|
|
6474
|
+
priority?: boolean;
|
|
6475
|
+
/**
|
|
6476
|
+
* The timeout after which the job should exit with an error.
|
|
6477
|
+
* @default one hour in ms.
|
|
6478
|
+
*/
|
|
6479
|
+
timeout?: number;
|
|
6480
|
+
};
|
|
6481
|
+
|
|
6482
|
+
/**
|
|
6483
|
+
* The type of a function that can be run on a separate thread.
|
|
6484
|
+
*/
|
|
6485
|
+
type ThreadJobFunction<InputType, ResultType> = ((data: InputType) => ResultType) | ((data: InputType) => Promise<ResultType>);
|
|
6486
|
+
|
|
6487
|
+
/**
|
|
6488
|
+
* Definition for a service that handles multithreading.
|
|
6489
|
+
*/
|
|
6490
|
+
interface MultithreadingServiceInterface {
|
|
6491
|
+
/**
|
|
6492
|
+
* Initializes the service.
|
|
6493
|
+
*/
|
|
6494
|
+
init: () => void | Promise<void>;
|
|
6495
|
+
/**
|
|
6496
|
+
* Creates and queues a thread job with the given data.
|
|
6497
|
+
* @param threadJobData - The data to create the thread job from.
|
|
6498
|
+
* @returns The id of the created thread job in the database and queue.
|
|
6499
|
+
*
|
|
6500
|
+
* **This differs from the threadId, which is created by the os and set when the thread actually starts.**.
|
|
6501
|
+
*/
|
|
6502
|
+
queueThreadJob: <WorkerData extends BaseThreadJobWorkerData>(threadJobData: ThreadJobData<WorkerData>) => Promise<string> | string;
|
|
6503
|
+
/**
|
|
6504
|
+
* Queues a thread job for the given data and waits for its completion.
|
|
6505
|
+
* @param threadJobData - The data of the job to queue.
|
|
6506
|
+
* @returns The thread job.
|
|
6507
|
+
*/
|
|
6508
|
+
runThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(threadJobData: ThreadJobData<WorkerData>) => Promise<ThreadJobEntity<WorkerData, ResultType>> | ThreadJobEntity<WorkerData, ResultType>;
|
|
6509
|
+
/**
|
|
6510
|
+
* Runs the given function on a separate thread. This will not persist the state in the database.
|
|
6511
|
+
*
|
|
6512
|
+
***IMPORTANT**: This uses "eval" in the thread worker, so make sure that the data passed is not malicious.
|
|
6513
|
+
* @param func - The function that should be run in a separate thread.
|
|
6514
|
+
* @param input - The input value of the function.
|
|
6515
|
+
* @param timeout - A custom timeout for the task. Defaults to 5 minutes or an hour, depending on the priority.
|
|
6516
|
+
* @param priority - Whether or not the function should make use of priority workers or not. Defaults to **true**.
|
|
6517
|
+
* @returns The result value of the function passed.
|
|
6518
|
+
* @throws When either the function itself throws an error or something didn't work during parsing/evaluation.
|
|
6519
|
+
*/
|
|
6520
|
+
run: <InputType, ResultType>(func: ThreadJobFunction<InputType, ResultType>, input: InputType, timeout?: number, priority?: boolean) => Promise<ResultType> | ResultType;
|
|
6521
|
+
/**
|
|
6522
|
+
* Requeues a thread job that was already completed.
|
|
6523
|
+
* @param jobId - The id of the job to requeue.
|
|
6524
|
+
* @param data - Additional data for the job.
|
|
6525
|
+
*/
|
|
6526
|
+
requeueThreadJob: (jobId: string, data?: ThreadJobDataFunctions) => Promise<void> | void;
|
|
6527
|
+
/**
|
|
6528
|
+
* Reruns a thread job that was already completed.
|
|
6529
|
+
* @param jobId - The id of the job to rerun.
|
|
6530
|
+
* @param data - Additional data for the job.
|
|
6531
|
+
* @returns The thread job.
|
|
6532
|
+
*/
|
|
6533
|
+
rerunThreadJob: <WorkerData extends BaseThreadJobWorkerData, ResultType>(jobId: string, data?: ThreadJobDataFunctions) => Promise<ThreadJobEntity<WorkerData, ResultType>> | ThreadJobEntity<WorkerData, ResultType>;
|
|
6534
|
+
/**
|
|
6535
|
+
* Waits for the thread job with the given id to complete.
|
|
6536
|
+
* @param jobId - The id of the thread job to wait for.
|
|
6537
|
+
* @returns The thread job.
|
|
6538
|
+
*/
|
|
6539
|
+
waitForThreadJob: <ResultType, WorkerData extends BaseThreadJobWorkerData = BaseThreadJobWorkerData>(jobId: string) => Promise<ThreadJobEntity<WorkerData, ResultType>> | ThreadJobEntity<WorkerData, ResultType>;
|
|
6540
|
+
/**
|
|
6541
|
+
* Terminates all the workers.
|
|
6542
|
+
*/
|
|
6543
|
+
shutdown: () => Promise<void> | void;
|
|
6544
|
+
}
|
|
6545
|
+
|
|
6546
|
+
/**
|
|
6547
|
+
* A service that handles multithreading.
|
|
6548
|
+
*/
|
|
6549
|
+
declare class MultithreadingService implements MultithreadingServiceInterface {
|
|
6550
|
+
private readonly options;
|
|
6551
|
+
private readonly threadJobEntityRepository;
|
|
6552
|
+
private readonly assetService;
|
|
6553
|
+
private readonly logger;
|
|
6554
|
+
/**
|
|
6555
|
+
* All thread jobs.
|
|
6556
|
+
*/
|
|
6557
|
+
private queue;
|
|
6558
|
+
/**
|
|
6559
|
+
* The workers that are currently running.
|
|
6560
|
+
*/
|
|
6561
|
+
private workers;
|
|
6562
|
+
/**
|
|
6563
|
+
* The workers that are currently idle.
|
|
6564
|
+
*/
|
|
6565
|
+
private idleWorkers;
|
|
6566
|
+
private readonly threadJobWorkerFilePath;
|
|
6567
|
+
constructor(options: MultithreadingOptions, threadJobEntityRepository: Repository<ThreadJobEntity<BaseThreadJobWorkerData, unknown>>, assetService: AssetServiceInterface, logger: LoggerInterface);
|
|
6568
|
+
init(): Promise<void>;
|
|
6569
|
+
private initWorker;
|
|
6570
|
+
private validateInputs;
|
|
6571
|
+
queueThreadJob<WorkerData extends BaseThreadJobWorkerData, ResultType>(threadJobData: ThreadJobData<WorkerData>): Promise<string>;
|
|
6572
|
+
runThreadJob<WorkerData extends BaseThreadJobWorkerData, ResultType>(threadJobData: ThreadJobData<WorkerData>): Promise<ThreadJobEntity<WorkerData, ResultType>>;
|
|
6573
|
+
run<InputType, ResultType>(func: ThreadJobFunction<InputType, ResultType>, input: InputType, timeout?: number, priority?: boolean): Promise<ResultType>;
|
|
6574
|
+
requeueThreadJob(jobId: string, data?: ThreadJobDataFunctions): Promise<void>;
|
|
6575
|
+
rerunThreadJob<WorkerData extends BaseThreadJobWorkerData, ResultType>(jobId: string, data?: ThreadJobDataFunctions): Promise<ThreadJobEntity<WorkerData, ResultType>>;
|
|
6576
|
+
waitForThreadJob<ResultType, WorkerData extends BaseThreadJobWorkerData = BaseThreadJobWorkerData>(jobId: string): Promise<ThreadJobEntity<WorkerData, ResultType>>;
|
|
6577
|
+
shutdown(): Promise<void>;
|
|
6578
|
+
private getDefaultTimeout;
|
|
6579
|
+
private startJobs;
|
|
6580
|
+
private startJob;
|
|
6581
|
+
private handleWorkerMessage;
|
|
6582
|
+
private handleJobCompletion;
|
|
6583
|
+
private handleInitializationMessage;
|
|
6584
|
+
private freeWorker;
|
|
6585
|
+
private getJobByThreadId;
|
|
6586
|
+
private getWorkerByThreadId;
|
|
6587
|
+
/**
|
|
6588
|
+
* This should only happen on shutdown.
|
|
6589
|
+
* To see where an error from the thread job is actually handled take a look at "handleWorkerMessage".
|
|
6590
|
+
* @param exitCode - The code that the worker exited with.
|
|
6591
|
+
* @param threadId - The thread id of the worker.
|
|
6592
|
+
*/
|
|
6593
|
+
private handleWorkerExit;
|
|
6594
|
+
/**
|
|
6595
|
+
* This should actually never happen, as the whole worker crashes and not just the current task.
|
|
6596
|
+
* That's why the provided "onError"-method from the threadJob data is not called.
|
|
6597
|
+
* To see where an error from the thread job is actually handled take a look at "handleWorkerMessage".
|
|
6598
|
+
* @param error - The error that crashed the worker.
|
|
6599
|
+
* @param threadId - The threadId of the worker that crashed.
|
|
6600
|
+
*/
|
|
6601
|
+
private handleWorkerError;
|
|
6602
|
+
private updateThreadJobById;
|
|
6603
|
+
private isThreadJobMessage;
|
|
6604
|
+
}
|
|
6605
|
+
|
|
6606
|
+
/**
|
|
6607
|
+
* A thread job.
|
|
6608
|
+
*/
|
|
6609
|
+
declare class ThreadJob<WorkerData extends BaseThreadJobWorkerData, ResultType> implements ThreadJobData<WorkerData> {
|
|
6610
|
+
/**
|
|
6611
|
+
* Timestamp of when the job was queued in milliseconds.
|
|
6612
|
+
*/
|
|
6613
|
+
readonly queuedAtMs: number;
|
|
6614
|
+
/**
|
|
6615
|
+
* The type of the job. (whether it's a real job with db persistence or just a simple function call).
|
|
6616
|
+
*/
|
|
6617
|
+
readonly type: 'job' | 'function';
|
|
6618
|
+
/**
|
|
6619
|
+
* Timestamp of when the job was started in milliseconds.
|
|
6620
|
+
*/
|
|
6621
|
+
startedAtMs?: number;
|
|
6622
|
+
/**
|
|
6623
|
+
* Timestamp of when the job was stopped in milliseconds.
|
|
6624
|
+
*/
|
|
6625
|
+
stoppedAtMs?: number;
|
|
6626
|
+
/**
|
|
6627
|
+
* A unique identifier of the job.
|
|
6628
|
+
* **This differs from the threadId, which is created by the os and set when the thread actually starts.**.
|
|
6629
|
+
*/
|
|
6630
|
+
readonly id: string;
|
|
6631
|
+
/**
|
|
6632
|
+
* The status of the job.
|
|
6633
|
+
*/
|
|
6634
|
+
status: ThreadJobStatus;
|
|
6635
|
+
/**
|
|
6636
|
+
* The id of the thread that the job is running in.
|
|
6637
|
+
* Set by the os.
|
|
6638
|
+
*/
|
|
6639
|
+
threadId?: number;
|
|
6640
|
+
/**
|
|
6641
|
+
* The progress of the job in a percentage.
|
|
6642
|
+
*/
|
|
6643
|
+
progress: Percentage;
|
|
6644
|
+
/**
|
|
6645
|
+
* The error that the job failed with.
|
|
6646
|
+
*/
|
|
6647
|
+
error?: Error;
|
|
6648
|
+
/**
|
|
6649
|
+
* The result that the job finished with.
|
|
6650
|
+
*/
|
|
6651
|
+
result?: ResultType;
|
|
6652
|
+
/**
|
|
6653
|
+
* A subject that contains whether or not the job was completed.
|
|
6654
|
+
*/
|
|
6655
|
+
readonly completedSubject: BehaviorSubject<boolean>;
|
|
6656
|
+
timeout: number;
|
|
6657
|
+
priority: boolean;
|
|
6658
|
+
readonly workerData: WorkerData;
|
|
6659
|
+
onMessage?: (message: unknown) => void;
|
|
6660
|
+
onComplete?: () => void;
|
|
6661
|
+
onError?: (error: Error) => void;
|
|
6662
|
+
onCancel?: () => void;
|
|
6663
|
+
constructor(entity: ThreadJobEntity<WorkerData, ResultType>, type: 'job' | 'function', functions?: ThreadJobDataFunctions);
|
|
6664
|
+
}
|
|
6665
|
+
|
|
6666
|
+
/**
|
|
6667
|
+
* A worker for handling thread job.
|
|
6668
|
+
* Consists of the actual worker, whether or not it is a priority worker. And the information of whether the worker is still initializing.
|
|
6669
|
+
*/
|
|
6670
|
+
declare class ThreadJobWorker {
|
|
6671
|
+
/**
|
|
6672
|
+
* A persisted thread id.
|
|
6673
|
+
* This is needed because the internal worker sets its threadId to -1 when it crashes
|
|
6674
|
+
* => There is no way to check which thread job was affected by the crash.
|
|
6675
|
+
*/
|
|
6676
|
+
readonly threadId: number;
|
|
6677
|
+
/**
|
|
6678
|
+
* The actual worker.
|
|
6679
|
+
*/
|
|
6680
|
+
readonly worker: Worker;
|
|
6681
|
+
/**
|
|
6682
|
+
* Whether or not this is a priority worker.
|
|
6683
|
+
*/
|
|
6684
|
+
readonly priority: boolean;
|
|
6685
|
+
/**
|
|
6686
|
+
* The timeout object after which this thread should be terminated.
|
|
6687
|
+
*/
|
|
6688
|
+
timeout?: NodeJS.Timeout;
|
|
6689
|
+
/**
|
|
6690
|
+
* Subject that contains whether or not the worker is still initializing.
|
|
6691
|
+
*/
|
|
6692
|
+
readonly isInitializingSubject: BehaviorSubject<boolean>;
|
|
6693
|
+
constructor(worker: Worker, priority: boolean, threadId: number);
|
|
6694
|
+
}
|
|
6695
|
+
|
|
6696
|
+
/**
|
|
6697
|
+
* Reports the given progress to the thread job service.
|
|
6698
|
+
* @param progress - The progress to report.
|
|
6699
|
+
*/
|
|
6700
|
+
declare function reportProgress(progress: Percentage): void;
|
|
6701
|
+
/**
|
|
6702
|
+
* Reports the completion of a thread job.
|
|
6703
|
+
* @param result - The result of the job.
|
|
6704
|
+
*/
|
|
6705
|
+
declare function reportCompletion<T>(result?: T): void;
|
|
6706
|
+
/**
|
|
6707
|
+
* Reports an error inside a thread job.
|
|
6708
|
+
* @param error - The error to report.
|
|
6709
|
+
*/
|
|
6710
|
+
declare function reportError(error: Error): void;
|
|
6711
|
+
|
|
6712
|
+
declare const omitValues: (keyof ThreadJob<BaseThreadJobWorkerData, unknown>)[];
|
|
6713
|
+
type OmitValues = typeof omitValues[number];
|
|
6714
|
+
/**
|
|
6715
|
+
* Contains information about an invoice.
|
|
6716
|
+
*/
|
|
6717
|
+
declare class ThreadJobEntity<WorkerData extends BaseThreadJobWorkerData, ResultType> extends BaseEntity implements OmitStrict<ThreadJob<WorkerData, ResultType>, OmitValues> {
|
|
6718
|
+
queuedAtMs: number;
|
|
6719
|
+
startedAtMs?: number;
|
|
6720
|
+
stoppedAtMs?: number;
|
|
6721
|
+
status: ThreadJobStatus;
|
|
6722
|
+
threadId?: number;
|
|
6723
|
+
progress: Percentage;
|
|
6724
|
+
priority: boolean;
|
|
6725
|
+
timeout: number;
|
|
6726
|
+
error?: Error;
|
|
6727
|
+
workerData: WorkerData;
|
|
6728
|
+
result?: ResultType;
|
|
6729
|
+
}
|
|
5193
6730
|
|
|
5194
|
-
export { type AppData, AppState, type ArrayParamItemMetadata, type ArrayParamItemMetadataInput, type ArrayParamMetadata, type ArrayParamMetadataInput, type ArrayPropertyItemMetadata, type ArrayPropertyItemMetadataInput, type ArrayPropertyMetadata, type ArrayPropertyMetadataInput, type ArrayWhereFilter, AssetService, type AssetServiceInterface, Auth, type AuthControllerInterface, AuthService, type AuthServiceInterface, type AuthStrategies, type AuthStrategyInterface, BadRequestError, BaseDataSource, type BaseEmailTemplateData, type BaseEmailTemplateDataInput, type
|
|
6731
|
+
export { AmountUnit, type AppData, AppState, type ArrayParamItemMetadata, type ArrayParamItemMetadataInput, type ArrayParamMetadata, type ArrayParamMetadataInput, type ArrayPropertyItemMetadata, type ArrayPropertyItemMetadataInput, type ArrayPropertyMetadata, type ArrayPropertyMetadataInput, type ArrayWhereFilter, AssetService, type AssetServiceInterface, Auth, type AuthControllerInterface, AuthService, type AuthServiceInterface, type AuthStrategies, type AuthStrategyInterface, BadRequestError, BaseDataSource, type BaseEmailTemplateData, type BaseEmailTemplateDataInput, BaseEntity, type BaseFunctionThreadJobWorkerData, type BaseLoggerTransportConfig, type BaseMailingListEmailTemplateData, type BasePageTemplateData, type BasePageTemplateDataInput, type BaseRepositoryOptions, type BaseThreadJobWorkerData, type BaseUser, BaseUserEntity, type BelongsToMetadata, type BelongsToOnePropertyMetadataInput, type BigNumber, BigNumberUtilities, Body, type BodyMetadata, type BodyMetadataInput, BodyParser, type BodyParserInterface, type BooleanParamMetadata, type BooleanParamMetadataInput, type BooleanPropertyMetadata, type BooleanPropertyMetadataInput, type BooleanWhereFilter, CLEANUP_AT_FILE_NAME, Change, ChangeSet, type ChangeSetEntity, ChangeSetRepository, ChangeSetType, type ChunkingOptions, type ColumnType, type CompanyInfo, ConflictError, Controller, type ControllerRouteConfiguration, type CounterInterface, type CounterMetricName, type CreateAllOptions, type CreateChangeData, type CreateChangeSetData, type CreateCronJobEntityData, CreateEmailData, type CreateOptions, type CronConfig, CronJob, CronJobEntity, CronService, type CronServiceInterface, type CronUpdateData, CrudController, type CrudControllerInterface, type CurrencyCode, CurrentUser, type CurrentUserMetadata, DataSource, type DataSourceOptions, DataSourceService, type DataSourceServiceInterface, type DateParamMetadata, type DateParamMetadataInput, type DatePropertyMetadata, type DatePropertyMetadataInput, type DateWhereFilter, Delete, type DeleteAllOptions, type DeleteByIdOptions, type DiProvider, type DiToken, EN16931ConformanceService, type EN16931DocumentContextId, Email, EmailAttachment, type EmailConfig, type EmailConfigInput, EmailPriority, EmailService, type EmailServiceInterface, EmailStatus, type EncodedJwtAccessToken, Entity, type EntityMetadata, type ErrorOpenApiResponse, File, type FileExtension, type FileMimeType, type FileOpenApiResponse, type FilePropertyMetadata, type FilePropertyMetadataInput, FileResponse, type FileSize, type FindAllOptions, type FindAllPaginatedOptions, type FindByIdOptions, type FindOneOptions, FormData, type FormDataBodyMetadata, FormDataBodyParser, type FormDataValue, type FormatDateFn, type FormatPercentFn, type FormatPriceFn, type GaugeInterface, type GaugeMetricName, Get, type GlobalErrorHandler, GlobalRegistry, HandlebarUtilities, type HasOnePropertyMetadataInput, type HasRoleMetadata, HashUtilities, type Header, type HeaderParamMetadata, type HeaderParamMetadataInput, type HistogramInterface, type HistogramMetricName, type HtmlOpenApiResponse, HtmlResponse, HttpError, HttpMethod, type HttpRequest, type HttpResponse, HttpStatus, type InitialCronConfig, Inject, InjectRepository, Injectable, InternalServerError, IntersectionClass, Invoice, InvoiceAddress, InvoiceCalcService, type InvoiceCalcServiceInterface, type InvoiceConformance, type InvoiceConformanceServiceInterface, InvoiceItem, InvoiceNumberService, type InvoiceNumberServiceInterface, InvoicePdfService, type InvoicePdfServiceInterface, type InvoicingOptions, type InvoicingOptionsInput, type IsLoggedInMetadata, type IsNotLoggedInMetadata, IsRequiredValidationProblem, type JsonBodyMetadata, JsonBodyParser, type JsonOpenApiResponse, Jwt, type JwtAccessTokenPayload, JwtAuthController, JwtAuthData, JwtAuthStrategy, JwtConfirmPasswordResetData, JwtCredentials, JwtCredentialsCreateData, JwtCredentialsDto, JwtRefreshToken, JwtRefreshTokenCreateDto, type JwtRefreshTokenPayload, type JwtRequestPasswordResetData, JwtUtilities, KnownHeader, type LanguageCode, type LocalizeOptions, type LocalizeOptionsInput, Log, LogLevel, LoggedError, Logger, type LoggerInterface, LoggerTransport, type LoggerTransportSend, type LooseFileMimeType, MailingList, type MailingListQueueEmailData, MailingListService, type MailingListServiceInterface, MailingListSubscriber, MailingListSubscriberCreateData, MailingListSubscriptionConfirmationToken, MailingListSubscriptionConfirmationTokenCreateData, type ManyToManyPropertyMetadata, type ManyToManyPropertyMetadataInput, type ManyToOnePropertyMetadata, type ManyToOnePropertyMetadataInput, MaxFileSizeValidationProblem, Metric, MetricType, type MetricsServiceInterface, type MetricsSnapshot, Migration, MigrationEntity, MimeType, MimeTypeMismatchValidationProblem, MissingEntitiesError, Ms, type MulterFile, type MultithreadingOptions, MultithreadingService, type MultithreadingServiceInterface, NO_USER_REPOSITORIES_PROVIDED_ERROR_MESSAGE, type NewChange, type Newable, NotFoundError, NumberInvoices, type NumberParamMetadata, type NumberParamMetadataInput, type NumberPropertyMetadata, type NumberPropertyMetadataInput, type NumberWhereFilter, type ObjectParamMetadata, type ObjectParamMetadataInput, type ObjectPropertyMetadata, type ObjectPropertyMetadataInput, type ObjectWhereFilter, OmitClass, type OneToManyPropertyMetadata, type OneToManyPropertyMetadataInput, type OneToOnePropertyMetadata, type OneToOnePropertyMetadataInput, type OpenApiDefinition, type OpenApiOperation, type OpenApiParameter, type OpenApiPaths, type OpenApiRequestBodyObject, type OpenApiResponse, type OpenApiRouteConfiguration, type OpenApiSchemaObject, type OpenApiSecurityRequirementObject, type OpenApiSecuritySchemeObject, OpenApiService, type OpenApiServiceInterface, type PaginationResult, Param, Parser, type ParserInterface, PartialClass, PasswordResetToken, PasswordResetTokenCreateData, Patch, type PathParamMetadata, type PathParamMetadataInput, type PathTree, PeppolConformanceService, PickClass, Post, PrometheusMetricsService, Property, type PropertyMetadata, type PropertyMetadataInput, type QueryParamMetadata, type QueryParamMetadataInput, QueueEmailData, RateLimiter, Relation, type RelationMetadata, type RelationMetadataInput, RelationsNotAllowedValidationProblem, Repository, type ResetChangeSetResult, Response, type Route, type RouteConfiguration, type RouteConfigurationInput, type RouteHandler, Router, type RouterInterface, type SkipAuthMetadata, type SkipBelongsToMetadata, type SkipHasRoleMetadata, type SkipIsLoggedInMetadata, type SkipIsNotLoggedInMetadata, type SoftDeleteAllOptions, type SoftDeleteByIdOptions, type SoftDeleteEntity, type SoftDeleteFindAllOptions, type SoftDeleteFindAllPaginatedOptions, type SoftDeleteFindByIdOptions, type SoftDeleteFindOneOptions, SoftDeleteRepository, type SoftDeleteUpdateAllOptions, type SoftDeleteUpdateByIdOptions, type SoftDeleteWhere, type SoftDeleteWhereFilter, type StringFormat, type StringParamMetadata, type StringParamMetadataInput, type StringPropertyMetadata, type StringPropertyMetadataInput, type StringWhereFilter, ThreadJob, type ThreadJobData, type ThreadJobDataFunctions, ThreadJobEntity, type ThreadJobFunction, type ThreadJobMessage, ThreadJobStatus, ThreadJobWorker, TooManyRequestsError, type Transaction, type TreeNode, TypeMismatchValidationProblem, UUIDUtilities, UnauthorizedError, type UnknownPropertyMetadata, type UnknownPropertyMetadataInput, UnmatchedRouteError, type UpdateAllOptions, type UpdateByIdOptions, UpdateMailingListPreferences, UserRepo, type UserRepositories, type UserRepositoryInterface, UserService, type UserServiceInterface, ValidationError, type ValidationProblem, ValidationService, type ValidationServiceInterface, Vat, type VatCategoryCode, type Version, type Where, type WhereFilter, type WhereFilterProperty, XRechnungConformanceService, ZIBRI_DI_TOKENS, ZIBRI_INVOICING_DI_TOKENS, ZibriApplication, type ZibriApplicationOptions, ZibriInvoicingPlugin, type ZibriInvoicingPluginDiProvider, type ZibriInvoicingPluginDiProviders, ZibriPlugin, chunkedPromiseAll, compareVersion, createArrayItemPropertyMetadata, errorHandler, errorToLoggedError, fileSizeToBytes, generateHandlebarType, generateHandlebarTypeFiles, getCurrentRequest, inject, isBaseUser, isChangeSetEntityNewable, isHttpError, isMimeType, isSoftDeleteEntityNewable, isVersion, renderEmailTemplate, renderPageTemplate, renderTemplate, renderTemplateString, reportCompletion, reportError, reportProgress, repositoryTokenFor, resolveFileExtension, resolveMimeType, runWithRequest, validateEntitiesRegistered };
|