@freshpointcz/fresh-core 0.0.11 → 0.0.12

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.
@@ -0,0 +1,431 @@
1
+ import dayjs, { Dayjs } from 'dayjs';
2
+ import { Logger } from 'winston';
3
+ import { BaseEntity, ColumnOptions, Repository, DataSourceOptions } from 'typeorm';
4
+ import { Job } from 'node-schedule';
5
+ import * as eslint from 'eslint';
6
+ import * as typescript_eslint_dist_compatibility_types from 'typescript-eslint/dist/compatibility-types';
7
+
8
+ /**
9
+ * Static DateUtils class
10
+ */
11
+ declare class DateUtils {
12
+ /** Holidays 2025-2030 as YYYY-MM-DD strings */
13
+ static HOLIDAYS_STR: readonly string[];
14
+ /** Holidays 2025-2030 as UTC timestamps */
15
+ static HOLIDAYS: readonly number[];
16
+ static fromISOtoSQLtimestamp(ts?: string): string;
17
+ static toSQLtimestamp(ts: Dayjs): string;
18
+ static fromSQLtimestamp(mysqlDate: string): Dayjs;
19
+ static getSqlTimestampFromNowCzech(): string;
20
+ static fromISO(isoDate: string): Dayjs;
21
+ static getDate(ts: string): dayjs.Dayjs;
22
+ static getNow(): Dayjs;
23
+ static getNowCzech(): Dayjs;
24
+ static clone(ts: Dayjs): Dayjs;
25
+ static getLastSunday(weeksOffset?: number): Dayjs;
26
+ static dayInWeek(ts?: Dayjs): 1 | 2 | 3 | 4 | 5 | 6 | 7;
27
+ static isWorkdayDay(ts: Dayjs): boolean;
28
+ static getDiffInMinutesWithNow(inputTime: Dayjs): number;
29
+ static isInLastDays(numOfDays: number, timestampInput: string | Dayjs): boolean;
30
+ }
31
+
32
+ type Deferred<T> = {
33
+ promise: Promise<T>;
34
+ resolve: (value: T) => void;
35
+ reject: (err: any) => void;
36
+ };
37
+ /**
38
+ * Deferred promise is like "fake" which is used to manually resolve/reject later on with different promise
39
+ * With resolve and reject outside for easier change of promise
40
+ * is used as placeholder untill real promise is assigned
41
+ */
42
+ declare function createDeferred<T>(): Deferred<T>;
43
+
44
+ /**
45
+ * Experimental class to maintain just one promise for some process flow.
46
+ * Currently is in singleton design, so can be used only in one proces. (currently: all-product-availability-per-day)
47
+ */
48
+ declare class SinglePromiseWaiter<T = any> {
49
+ private static _instance;
50
+ static getInstance<T = any>(): SinglePromiseWaiter<any>;
51
+ private _promise;
52
+ get promise(): Promise<T> | null;
53
+ set promise(promise: Promise<T> | null);
54
+ get hasPromise(): boolean;
55
+ }
56
+
57
+ declare const logger: Logger;
58
+
59
+ declare function isValidCron(expr: string): boolean;
60
+
61
+ declare abstract class Singleton {
62
+ private static instances;
63
+ constructor();
64
+ protected abstract onInit(): void;
65
+ }
66
+
67
+ type Status = "ok" | "error" | "not-authorized" | "not-authenticated" | "internal-server-error" | "validation-error";
68
+
69
+ declare class StatusDto {
70
+ /**
71
+ * Call result status
72
+ */
73
+ status: Status;
74
+ /**
75
+ * UTC Timestamp
76
+ * @example "2021-12-01T13:23:39.305Z"
77
+ */
78
+ timestamp: string;
79
+ /**
80
+ * Details (optional)
81
+ */
82
+ details?: string;
83
+ constructor(status: Status, details?: string, timestamp?: string);
84
+ }
85
+
86
+ declare const AMOUNT_UNIT: {
87
+ readonly 1: {
88
+ readonly symbol: "g";
89
+ readonly translations: {
90
+ readonly en: "gram";
91
+ readonly cs: "gram";
92
+ };
93
+ };
94
+ readonly 2: {
95
+ readonly symbol: "kg";
96
+ readonly translations: {
97
+ readonly en: "kilogram";
98
+ readonly cs: "kilogram";
99
+ };
100
+ };
101
+ readonly 3: {
102
+ readonly symbol: "ml";
103
+ readonly translations: {
104
+ readonly en: "milliliter";
105
+ readonly cs: "mililitr";
106
+ };
107
+ };
108
+ readonly 4: {
109
+ readonly symbol: "l";
110
+ readonly translations: {
111
+ readonly en: "liter";
112
+ readonly cs: "litr";
113
+ };
114
+ };
115
+ };
116
+
117
+ /**
118
+ * Default Entity with needed columns for every basic entity `id`, `uuid`, `created_at`, `updated_at` and `deleted_at`;
119
+ */
120
+ declare abstract class FreshEntity extends BaseEntity {
121
+ id: number;
122
+ uuid: string;
123
+ created_at: Date;
124
+ updated_at: Date;
125
+ deleted_at: Date | null;
126
+ /** After manual construction `id` is irrelevant. Refer to `uuid` only, because that will be inserted into DB */
127
+ constructor();
128
+ }
129
+
130
+ /**
131
+ * Abstract class for hypertable entity
132
+ * @description
133
+ * @property `timestamp` is PrimaryKey of type 'timestamptz'
134
+ * @property `created_at` is timestamp of insert into DB
135
+ *
136
+ * @usage add into generated migration these snippets:
137
+ ** up: await queryRunner.query(`SELECT create_hypertable('my_hyper_table', 'timestamp', if_not_exists => TRUE);`);
138
+ ** down: await queryRunner.query(`SELECT drop_hypertable('my_hyper_table', if_exists => TRUE);`);
139
+ */
140
+ declare abstract class FreshHyperEntity extends BaseEntity {
141
+ timestamp: Date;
142
+ created_at: Date;
143
+ /** After manual construction `id` is irrelevant */
144
+ constructor(timestamp?: Date);
145
+ }
146
+
147
+ declare enum ActionCommandCode {
148
+ RESTART_PC = 1,
149
+ RESTART_APPLICATION = 2,
150
+ RESTART_ROUTER = 3,
151
+ RESTART_REMOTE_CONTROL = 4,
152
+ SYNCHRONIZE = 5,
153
+ DIAGNOSE_LOCKS = 6,
154
+ /** download config, save it locally and upload local config, if nothing found on server then just upload */
155
+ SYNCHRONIZE_CONFIG = 7
156
+ }
157
+
158
+ declare enum DepotPoolStatus {
159
+ NEW = 0,
160
+ PICKED = 1,
161
+ WRITTEN_OFF = 2,
162
+ ACTIVE = 3,
163
+ TERMINATED = 4
164
+ }
165
+
166
+ declare enum HttpStatus {
167
+ CONTINUE = 100,
168
+ SWITCHING_PROTOCOLS = 101,
169
+ PROCESSING = 102,
170
+ EARLY_HINTS = 103,
171
+ OK = 200,
172
+ CREATED = 201,
173
+ ACCEPTED = 202,
174
+ NON_AUTHORITATIVE_INFORMATION = 203,
175
+ NO_CONTENT = 204,
176
+ RESET_CONTENT = 205,
177
+ PARTIAL_CONTENT = 206,
178
+ MULTI_STATUS = 207,
179
+ ALREADY_REPORTED = 208,
180
+ IM_USED = 226,
181
+ MULTIPLE_CHOICES = 300,
182
+ MOVED_PERMANENTLY = 301,
183
+ FOUND = 302,
184
+ SEE_OTHER = 303,
185
+ NOT_MODIFIED = 304,
186
+ USE_PROXY = 305,
187
+ TEMPORARY_REDIRECT = 307,
188
+ PERMANENT_REDIRECT = 308,
189
+ BAD_REQUEST = 400,
190
+ UNAUTHORIZED = 401,
191
+ PAYMENT_REQUIRED = 402,
192
+ FORBIDDEN = 403,
193
+ NOT_FOUND = 404,
194
+ METHOD_NOT_ALLOWED = 405,
195
+ NOT_ACCEPTABLE = 406,
196
+ PROXY_AUTHENTICATION_REQUIRED = 407,
197
+ REQUEST_TIMEOUT = 408,
198
+ CONFLICT = 409,
199
+ GONE = 410,
200
+ LENGTH_REQUIRED = 411,
201
+ PRECONDITION_FAILED = 412,
202
+ PAYLOAD_TOO_LARGE = 413,
203
+ URI_TOO_LONG = 414,
204
+ UNSUPPORTED_MEDIA_TYPE = 415,
205
+ RANGE_NOT_SATISFIABLE = 416,
206
+ EXPECTATION_FAILED = 417,
207
+ IM_A_TEAPOT = 418,
208
+ MISDIRECTED_REQUEST = 421,
209
+ UNPROCESSABLE_ENTITY = 422,
210
+ LOCKED = 423,
211
+ FAILED_DEPENDENCY = 424,
212
+ TOO_EARLY = 425,
213
+ UPGRADE_REQUIRED = 426,
214
+ PRECONDITION_REQUIRED = 428,
215
+ TOO_MANY_REQUESTS = 429,
216
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
217
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
218
+ INTERNAL_SERVER_ERROR = 500,
219
+ NOT_IMPLEMENTED = 501,
220
+ BAD_GATEWAY = 502,
221
+ SERVICE_UNAVAILABLE = 503,
222
+ GATEWAY_TIMEOUT = 504,
223
+ HTTP_VERSION_NOT_SUPPORTED = 505,
224
+ VARIANT_ALSO_NEGOTIATES = 506,
225
+ INSUFFICIENT_STORAGE = 507,
226
+ LOOP_DETECTED = 508,
227
+ NOT_EXTENDED = 510,
228
+ NETWORK_AUTHENTICATION_REQUIRED = 511
229
+ }
230
+
231
+ declare enum LanguageCode {
232
+ CS = "cs",
233
+ EN = "en",
234
+ DE = "de",
235
+ PL = "pl",
236
+ SK = "sk"
237
+ }
238
+
239
+ declare enum PaymentMethod {
240
+ CODE = 0,
241
+ CARD = 1,
242
+ NONE = 2
243
+ }
244
+
245
+ declare enum TransactionType {
246
+ WRITEOFF = 0,
247
+ SALE = 1,
248
+ LOST = 2,
249
+ ADD = 3,
250
+ DELIVERY = 4,
251
+ DEPOT_WRITEOFF = 5,
252
+ DEPOT_ADD = 6,
253
+ RETURN = 7,
254
+ INVENTORY_SURPLUS = 8,
255
+ INVENTORY_MISSING = 9
256
+ }
257
+
258
+ declare abstract class FreshTranslationBase<T extends FreshEntity> extends BaseEntity {
259
+ id: number;
260
+ languageCode: LanguageCode;
261
+ /**
262
+ * @description relation column to parent Entity
263
+ * @override with your Entity specific relation using
264
+ *
265
+ ** `@ManyToOne(type => YourEntity, { onDelete: "CASCADE" })`
266
+ `baseEntity: YourEntity;`
267
+ *
268
+ * @usage
269
+ * In parent must be this definition
270
+ ** `@OneToMany(() => EntityTranslation, (t) => t.baseEntity, {
271
+ cascade: true,
272
+ })
273
+ translations!: EntityTranslation[];`
274
+ `translations: EntityTranslation[];`
275
+ */
276
+ abstract baseEntity: T;
277
+ constructor();
278
+ }
279
+
280
+ /**
281
+ * Extended typeorm `column` decorator for timestamp columns
282
+ *
283
+ * @description
284
+ * Is timestamp column with timezones and as default value passes current timestamp.
285
+ *
286
+ * * type: 'timestamptz'
287
+ * * nullable: false
288
+ * * default: () => 'CURRENT_TIMESTAMP'
289
+ */
290
+ declare function TimestampColumn(options?: ColumnOptions): PropertyDecorator;
291
+
292
+ declare abstract class FreshDao<T extends BaseEntity> {
293
+ protected abstract repo: Repository<T>;
294
+ }
295
+
296
+ declare class Category extends FreshEntity {
297
+ }
298
+
299
+ declare class Device extends FreshEntity {
300
+ }
301
+
302
+ declare class Manufacturer extends FreshEntity {
303
+ }
304
+
305
+ declare class Product extends FreshEntity {
306
+ }
307
+
308
+ declare class Subcategory extends FreshEntity {
309
+ }
310
+
311
+ type Maybe<T> = T | null;
312
+
313
+ declare abstract class DataHelper<T> {
314
+ private _data?;
315
+ private _dataPromise;
316
+ protected deviceIds: Promise<number[]>;
317
+ constructor(startDataRetrieve: boolean | undefined, deviceIds: Promise<number[]>);
318
+ protected get data(): Maybe<T> | undefined;
319
+ protected set data(value: Maybe<T>);
320
+ protected get dataPromise(): Maybe<Promise<Maybe<T>>>;
321
+ protected set dataPromise(value: Maybe<Promise<Maybe<T>>>);
322
+ getData(): Promise<Maybe<T>>;
323
+ abstract startDataRetrieval(): Promise<Maybe<T>>;
324
+ }
325
+
326
+ declare abstract class FreshJob<T = void> extends Singleton {
327
+ private _jobName;
328
+ private _cronExpression;
329
+ private _job;
330
+ /**
331
+ * @param cronExpression must be cron of just numbers ex.: `0 5 * * 4`
332
+ * By default timezone is added " Europe/Prague"
333
+ */
334
+ constructor(jobName: string, cronExpression: string, jobEnabled: boolean);
335
+ /** Just logging */
336
+ protected onInit(rescheduled?: boolean): void;
337
+ get jobName(): string;
338
+ protected set jobName(value: string);
339
+ get cronExpression(): string;
340
+ protected set cronExpression(value: string);
341
+ protected get job(): Job | null;
342
+ protected set job(value: Job | null);
343
+ abstract invoke(): T | Promise<T>;
344
+ }
345
+
346
+ declare class ApiError extends Error {
347
+ private _statusCode;
348
+ get statusCode(): number;
349
+ private _statusDto;
350
+ get statusDto(): any;
351
+ constructor(statusCode: number, status: Status, detail?: string);
352
+ }
353
+
354
+ declare const FRESH_ESLINT_CONFIG: {
355
+ files: string[];
356
+ ignores: string[];
357
+ languageOptions: {
358
+ parser: typescript_eslint_dist_compatibility_types.CompatibleParser;
359
+ ecmaVersion: string;
360
+ sourceType: string;
361
+ };
362
+ plugins: {
363
+ "@typescript-eslint": typescript_eslint_dist_compatibility_types.CompatiblePlugin;
364
+ prettier: eslint.ESLint.Plugin;
365
+ };
366
+ rules: {
367
+ "prefer-const": string;
368
+ yoda: string[];
369
+ "no-multiple-empty-lines": (string | {
370
+ max: number;
371
+ })[];
372
+ semi: string[];
373
+ curly: string[];
374
+ "object-curly-spacing": string[];
375
+ "no-dupe-else-if": string;
376
+ "no-duplicate-imports": string;
377
+ "no-cond-assign": string[];
378
+ "no-async-promise-executor": string;
379
+ "no-fallthrough": string;
380
+ eqeqeq: string[];
381
+ "prettier/prettier": (string | {
382
+ printWidth: number;
383
+ tabWidth: number;
384
+ useTabs: boolean;
385
+ semi: boolean;
386
+ singleQuote: boolean;
387
+ trailingComma: string;
388
+ bracketSpacing: boolean;
389
+ endOfLine: string;
390
+ })[];
391
+ "@typescript-eslint/naming-convention": (string | {
392
+ selector: string[];
393
+ format: string[];
394
+ leadingUnderscore: string;
395
+ modifiers?: undefined;
396
+ } | {
397
+ selector: string;
398
+ format: string[];
399
+ leadingUnderscore?: undefined;
400
+ modifiers?: undefined;
401
+ } | {
402
+ selector: string;
403
+ modifiers: string[];
404
+ format: string[];
405
+ leadingUnderscore?: undefined;
406
+ })[];
407
+ };
408
+ }[];
409
+
410
+ /**
411
+ * @usage
412
+ * configurate dotenv before dependency import
413
+ * @example
414
+ * `import { config } from 'dotenv';`
415
+ * `config();`
416
+ * `import { PgDataSourceOptions } from '@freshpointcz/fresh-package';`
417
+ */
418
+ declare const PG_DATA_SOURCE_OPTIONS: DataSourceOptions;
419
+
420
+ interface HealthCheckResult {
421
+ server: boolean;
422
+ db?: boolean | {
423
+ postgres?: boolean;
424
+ mariaDb?: boolean;
425
+ };
426
+ extras?: {
427
+ [extraServiceToCheck: string]: boolean;
428
+ };
429
+ }
430
+
431
+ export { AMOUNT_UNIT, ActionCommandCode, ApiError, Category, DataHelper, DateUtils, type Deferred, DepotPoolStatus, Device, FreshDao, FreshEntity, FreshHyperEntity, FreshJob, FreshTranslationBase, type HealthCheckResult, HttpStatus, LanguageCode, Manufacturer, type Maybe, PaymentMethod, PG_DATA_SOURCE_OPTIONS as PgDataSourceOptions, Product, SinglePromiseWaiter, Singleton, type Status, StatusDto, Subcategory, TimestampColumn, TransactionType, createDeferred, FRESH_ESLINT_CONFIG as freshEslintConfig, isValidCron, logger };