-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
classes.ts
1207 lines (1105 loc) · 31.8 KB
/
classes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable @typescript-eslint/no-empty-function, @typescript-eslint/no-useless-constructor, max-classes-per-file */
import 'reflect-metadata';
import { ClassConstructor, Expose, Type } from 'class-transformer';
import {
IsEmail,
IsUrl,
IsString,
IsBoolean,
IsOptional,
ValidateNested,
IsEnum,
IsInt,
Min,
Matches,
IsObject,
ArrayNotEmpty,
IsArray,
Max,
IsNotEmpty,
IsNumber,
} from 'class-validator';
import { ServerOptions } from 'https';
import { ListenOptions } from 'net';
import cronParser from 'cron-parser';
import path from 'path';
export const CONFIG_DIR = process.env.CONFIG_DIR || 'config';
export enum NotificationType {
EMAIL = 'email',
TELEGRAM = 'telegram',
DISCORD = 'discord',
PUSHOVER = 'pushover',
APPRISE = 'apprise',
LOCAL = 'local',
GOTIFY = 'gotify',
SLACK = 'slack',
HOMEASSISTANT = 'homeassistant',
BARK = 'bark',
NTFY = 'ntfy',
WEBHOOK = 'webhook',
}
/**
* @ignore
*/
export abstract class NotifierConfig {
@IsEnum(NotificationType)
type: NotificationType;
constructor(type: NotificationType) {
this.type = type;
}
}
/**
* For local development only. This just opens the notified URL in your default browser.
*/
export class LocalConfig extends NotifierConfig {
/**
* @ignore
*/
constructor() {
super(NotificationType.LOCAL);
}
}
/**
* Sends a notification to many services via [Apprise API](https://github.com/caronc/apprise-api).
* Supports 70+ different [notification services](https://github.com/caronc/apprise/wiki#notification-services).
*/
export class AppriseConfig extends NotifierConfig {
/**
* The base URL of your Apprise instance
* @example http://localhost:8000
* @env APPRISE_API
*/
@IsUrl({
require_tld: false,
})
apiUrl: string;
/**
* One or more URLs identifying where the notification should be sent to.
* If this field isn't specified then it automatically assumes the settings.APPRISE_STATELESS_URLS in your Apprise instance.
* More details: https://github.com/caronc/apprise-api#stateless-solution
* @example mailto://user:pass@gmail.com
* @env APPRISE_URLS
*/
@IsString()
@IsOptional()
urls?: string;
/**
* @ignore
*/
constructor() {
super(NotificationType.APPRISE);
}
}
/**
* Sends a message to a server text channel using a webhook
*/
export class DiscordConfig extends NotifierConfig {
/**
* Discord channel webhook URL.
* Guide: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
* @example https://discord.com/api/webhooks/123456789123456789/A-abcdefghijklmn-abcdefghijklmnopqrst12345678-abcdefghijklmnop123456
* @env DISCORD_WEBHOOK
*/
@IsUrl()
webhookUrl: string;
/**
* A list of Discord user IDs to ping when posting the message. The IDs must be strings wrapped in quotes.
* How to get a user ID: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-
* @example ["914360712086843432", "914360712086843433"]
* @env DISCORD_MENTIONED_USERS (comma separated)
*/
@IsOptional()
@IsArray()
@IsString({ each: true })
mentionedUsers: string[];
/**
* A list of Discord role IDs to ping when posting the message. The IDs must be strings wrapped in quotes.
* To get a role ID: enable developer mode > right click a role > "Copy ID"
* @example ["734548250895319070", "734548250895319071"]
* @env DISCORD_MENTIONED_ROLES (comma separated)
*/
@IsOptional()
@IsArray()
@IsString({ each: true })
mentionedRoles: string[];
/**
* @ignore
*/
constructor() {
super(NotificationType.DISCORD);
}
}
/**
* Sends a pushover message
*/
export class PushoverConfig extends NotifierConfig {
/**
* Guide: https://pushover.net/apps/build
* @example a172fyyl9gw99p2xi16tq8hnib48p2
* @env PUSHOVER_TOKEN
*/
@IsString()
token: string;
/**
* @example uvgidym7l5ggpwu2r8i1oy6diaapll
* @env PUSHOVER_USER_ID
*/
@IsString()
userKey: string;
/**
* @ignore
*/
constructor() {
super(NotificationType.PUSHOVER);
}
}
/**
* Sends a message to a group chat using a bot you must set up yourself
*/
export class TelegramConfig extends NotifierConfig {
/**
* Telegram bot token obtained here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
* @example 644739147:AAGMPo-Jz3mKRnHRTnrPEDi7jUF1vqNOD5k
* @env TELEGRAM_TOKEN
*/
@IsString()
@Matches(/\d+:[a-zA-Z0-9_-]{35}/)
token: string;
/**
* Unique identifier for the target chat or username of the target channel
* @example -987654321
* @example @channelusername
* @env TELEGRAM_CHAT_ID
*/
@IsString()
@IsNotEmpty()
chatId: string;
/**
* Custom TELEGRAM server URL
* @default https://api.telegram.org
* @env TELEGRAM_API_URL
*/
@IsUrl({ require_tld: false })
@IsOptional()
apiUrl = 'https://api.telegram.org';
/**
* @ignore
*/
constructor() {
super(NotificationType.TELEGRAM);
}
}
/**
* Sends a message to a self-hosted [Gotify](https://gotify.net/) server
*/
export class GotifyConfig extends NotifierConfig {
/**
* The Gotify server host URL
* @example http://gotify.net
* @env GOTIFY_API_URL
*/
@IsUrl({
require_tld: false,
})
apiUrl: string;
/**
* On the Gotify web UI, Apps > Create Application > reveal the token
* @example SnL-wAvmfo_QT
* @env GOTIFY_TOKEN
*/
@IsNotEmpty()
@IsString()
token: string;
/**
* The priority level sent with the message.
* @example 7
* @default 5
* @env GOTIFY_PRIORITY
*/
@IsInt()
@Min(0)
@Max(10)
@IsOptional()
priority = 5;
/**
* @ignore
*/
constructor() {
super(NotificationType.GOTIFY);
}
}
/**
* Sends a [slack](https://slack.com/) message using webhook
*/
export class SlackConfig extends NotifierConfig {
/**
* slack channel webhook URL.
* Guide: https://api.slack.com/messaging/webhooks
* @example https://hooks.slack.com/services/T22CE80ABCD/CE3AWABCDEFG/F8jdewBb4fmDDx6fV0abcdefg
* @env SLACK_WEBHOOK
*/
@IsUrl()
webhookUrl: string;
/**
* @ignore
*/
constructor() {
super(NotificationType.SLACK);
}
}
/**
* Sends a ntfy message using webhook
*/
export class NtfyConfig extends NotifierConfig {
/**
* ntfy channel webhook URL.
* Guide: https://docs.ntfy.sh/publish/
* @example https://ntfy.sh/mytopic
* @env NTFY_WEBHOOK
*/
@IsUrl()
webhookUrl: string;
/**
* ntfy channel priority.
* Guide: https://docs.ntfy.sh/publish/
* @example urgent
* @env NTFY_PRIORITY
*/
@IsString()
priority: string;
/**
* ntfy channel token.
* Guide: https://docs.ntfy.sh/config/#access-tokens
* @example tk_yourtoken
* @env NTFY_TOKEN
*/
@IsString()
token: string;
/**
* @ignore
*/
constructor() {
super(NotificationType.NTFY);
}
}
export class EmailAuthConfig {
/**
* The SMTP username (if necessary)
* @example hello@gmail.com
* @env SMTP_USERNAME
*/
@IsString()
user: string;
/**
* The SMTP password (if necessary)
* @example abc123
* @env SMTP_PASSWORD
*/
@IsString()
pass: string;
/**
* @ignore
*/
constructor() {}
}
/**
* Configuration for sending notifications via email.
*
* [Example Gmail settings](https://www.siteground.com/kb/google_free_smtp_server).
*
* If you have 2FA setup for your Google account, you'll need to create an [app password](https://support.google.com/mail/answer/185833)
*/
export class EmailConfig extends NotifierConfig {
/**
* The outgoing SMTP host name
* @example smtp.gmail.com
* @env SMTP_HOST
*/
@IsUrl({ require_tld: false })
smtpHost: string;
/**
* The outgoing SMTP port (SSL or TLS, see secure)
* @example 587
* @env SMTP_PORT
*/
@IsInt()
@Min(0)
@Max(65535)
smtpPort: number;
/**
* The sender of the email you will recieve (can be your email address)
* @example hello@gmail.com
* @env EMAIL_SENDER_ADDRESS
*/
@IsEmail()
emailSenderAddress: string;
/**
* The name of the email sender
* @example Epic Games Free Games
* @env EMAIL_SENDER_NAME
*/
@IsString()
emailSenderName: string;
/**
* The recipient of the email (can be your email address)
* @example hello@gmail.com
* @env EMAIL_RECIPIENT_ADDRESS
*/
@IsEmail()
emailRecipientAddress: string;
/**
* true for SSL (port 465), false for TLS or unsecure
* @example true
* @default false
* @env SMTP_SECURE
*/
@IsBoolean()
secure = false;
/**
* Auth settings for SMTP
*/
@IsOptional()
@ValidateNested()
@Type(() => EmailAuthConfig)
auth?: EmailAuthConfig;
/**
* @ignore
*/
constructor() {
super(NotificationType.EMAIL);
}
}
/**
* Sends a homeassistant notification
*/
export class HomeassistantConfig extends NotifierConfig {
/**
* @example https://homeassistant.example.com
* @env HOMEASSISTANT_INSTANCE
*/
@IsString()
instance: string;
/**
* @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
* @env HOMEASSISTANT_LONG_LIVED_ACCESS_TOKEN
*/
@IsString()
token: string;
/**
* @example mobile_app_smartphone_name
* @env HOMEASSISTANT_NOTIFYSERVICE
*/
@IsString()
notifyservice: string;
/**
* A key-value pair object to additionally pass into the service's `data` object
* @example { "parse_mode": "html" }
* @env HOMEASSISTANT_CUSTOM_DATA (stringified JSON)
*/
@IsObject()
@IsOptional()
customData: Record<string, boolean | number | string> | undefined;
/**
* @ignore
*/
constructor() {
super(NotificationType.HOMEASSISTANT);
}
}
/**
* Send a notification to the Bark iOS app
* https://github.com/Finb/Bark
*/
export class BarkConfig extends NotifierConfig {
/**
* Bark key
* @env BARK_KEY
*/
@IsString()
key: string;
/**
* Bark title
* @default epicgames-freegames-node
* @env BARK_TITLE
*/
@IsString()
@IsOptional()
title = 'epicgames-freegames-node';
/**
* Bark group
* @default epicgames-freegames-node
* @env BARK_GROUP
*/
@IsString()
@IsOptional()
group = 'epicgames-freegames-node';
/**
* Custom Bark server URL
* @default https://api.day.app
* @env BARK_API_URL
*/
@IsUrl({ require_tld: false })
@IsOptional()
apiUrl = 'https://api.day.app';
/**
* @ignore
*/
constructor() {
super(NotificationType.BARK);
}
}
/**
* Sends a POST request with the notification contents in the body to a [webhook](https://en.wikipedia.org/wiki/Webhook) URL
*/
export class WebhookConfig extends NotifierConfig {
/**
* Webhook URL
* @env WEBHOOK_URL
*/
@IsUrl({ require_tld: false })
url: string;
/**
* A key-value pair object to pass into the POST request headers
* @example { Authorization: "Bearer ABCD" }
* @env WEBHOOK_HEADERS (stringified JSON)
*/
@IsObject()
@IsOptional()
headers: Record<string, string> | undefined;
/**
* @ignore
*/
constructor() {
super(NotificationType.WEBHOOK);
}
}
export type AnyNotifierConfig =
| EmailConfig
| DiscordConfig
| LocalConfig
| TelegramConfig
| AppriseConfig
| PushoverConfig
| GotifyConfig
| SlackConfig
| HomeassistantConfig
| BarkConfig
| NtfyConfig
| WebhookConfig;
const notifierSubtypes: {
value: ClassConstructor<NotifierConfig>;
name: string;
}[] = [
{ value: EmailConfig, name: NotificationType.EMAIL },
{ value: DiscordConfig, name: NotificationType.DISCORD },
{ value: PushoverConfig, name: NotificationType.PUSHOVER },
{ value: LocalConfig, name: NotificationType.LOCAL },
{ value: TelegramConfig, name: NotificationType.TELEGRAM },
{ value: AppriseConfig, name: NotificationType.APPRISE },
{ value: GotifyConfig, name: NotificationType.GOTIFY },
{ value: SlackConfig, name: NotificationType.SLACK },
{ value: HomeassistantConfig, name: NotificationType.HOMEASSISTANT },
{ value: BarkConfig, name: NotificationType.BARK },
{ value: NtfyConfig, name: NotificationType.NTFY },
{ value: WebhookConfig, name: NotificationType.WEBHOOK },
];
export class WebPortalConfig {
/**
* The URL base that will be returned when a device token login is required
* @example https://epic.example.com
* @default http://localhost:3000
* @env BASE_URL
*/
@IsOptional()
@IsUrl({
require_tld: false,
})
baseUrl?: string;
/**
* Node Net.listen options: https://nodejs.org/api/net.html#net_server_listen_options_callback
* @default { port: 3000 }
* @env SERVER_PORT (for `{port: SERVER_PORT}` only)
*/
@IsOptional()
@IsObject()
listenOpts?: ListenOptions;
/**
* Node HTTPS.createServer options: https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
*/
@IsOptional()
@IsObject()
serverOpts?: ServerOptions;
/**
* If true, provide a remotely accessible web address via [localtunnel](https://localtunnel.me) without the need to port forward or reverse proxy
* @example true
* @default false
* @env LOCAL_TUNNEL
*/
@IsOptional()
@IsBoolean()
localtunnel? = process.env.LOCAL_TUNNEL?.toLowerCase() === 'true' || false;
/**
* @ignore
*/
constructor() {}
}
export class AccountConfig {
/**
* Epic Games login email
* @example example@gmail.com
* @env EMAIL
*/
@IsEmail()
email: string;
/**
* Notification options for just this account. This overrides any global notification configs.
*
* You may configure multiple notifiers, and they will all be triggered simultaneously.
*/
@IsOptional()
@ValidateNested()
@IsArray()
@Type(() => NotifierConfig, {
discriminator: {
property: 'type',
subTypes: notifierSubtypes,
},
})
notifiers?: AnyNotifierConfig[];
/**
* @ignore
*/
constructor() {}
}
export enum SearchStrategy {
/**
* Redeem only the games defined as a weekly free game at https://www.epicgames.com/store/free-games
*
* This uses a different set of APIs from the other search strategies, so it may work in case finding games breaks.
*
* Generally is less stable than `promotion` due to a more complex lookup method.
*/
WEEKLY = 'weekly',
/**
* Search the entire Epic Games site for any game with a 100% discount.
* This includes the `weekly` games, plus any uncommon non-weekly temporarily free games.
* Occasionally excludes the weekly promotion if it's a bundle.
*/
PROMOTION = 'promotion',
/**
* Combines the results from `weekly` and `promotion`.
* Continues if at least one of the APIs works.
*/
ALL = 'all',
}
export enum LogLevel {
SILENT = 'silent',
ERROR = 'error',
WARN = 'warn',
INFO = 'info',
DEBUG = 'debug',
TRACE = 'trace',
}
/**
* @example ```jsonc
* {
* "runOnStartup": true,
* "cronSchedule": "0 0,6,12,18 * * *",
* "logLevel": "info",
* "webPortalConfig": {
* "baseUrl": "https://epic.example.com",
* },
* "accounts": [
* {
* "email": "example@gmail.com",
* },
* ],
* "notifiers": [
* // You may configure as many of any notifier as needed
* // Here are some examples of each type
* {
* "type": "email",
* "smtpHost": "smtp.gmail.com",
* "smtpPort": 587,
* "emailSenderAddress": "hello@gmail.com",
* "emailSenderName": "Epic Games Free Games",
* "emailRecipientAddress": "hello@gmail.com",
* "secure": false,
* "auth": {
* "user": "hello@gmail.com",
* "pass": "abc123",
* },
* },
* {
* "type": "discord",
* "webhookUrl": "https://discord.com/api/webhooks/123456789123456789/A-abcdefghijklmn-abcdefghijklmnopqrst12345678-abcdefghijklmnop123456",
* },
* {
* "type": "telegram",
* "token": "644739147:AAGMPo-Jz3mKRnHRTnrPEDi7jUF1vqNOD5k",
* "chatId": "-987654321",
* },
* {
* "type": "apprise",
* "apiUrl": "http://192.168.1.2:8000",
* "urls": "mailto://user:pass@gmail.com",
* },
* ],
* }
* ```
*/
export class AppConfig {
/**
* Cron string of when to run the process.
* **It is recommended to run every 6 hours, otherwise the refresh tokens will expire after 8 hours and a new login will be prompted every run.**
* If you want the check to occur immediately after the new free game is released, you can offset the cron schedule. For example in a timezone where the free games release at 11:00am: `0 5,11,17,23 * * *`
* @example 0 5,11,17,23 * * *
* @default 0 0,6,12,18 * * * (every six hours)
* @env CRON_SCHEDULE
*/
@IsOptional()
@IsString()
cronSchedule = process.env.CRON_SCHEDULE || '0 0,6,12,18 * * *';
@Expose({ toClassOnly: true })
getMsUntilNextRun() {
const cronExpression = cronParser.parseExpression(this.cronSchedule);
return cronExpression.next().getTime() - new Date().getTime();
}
/**
* A list of excluded game titles to skip during processing.
* @example ['Gigabash Demo', 'Another Blacklisted Game']
* @env BLACKLISTED_GAMES (comma separated)
*/
@IsOptional()
@IsArray()
@IsString({ each: true })
blacklistedGames: string[] = [];
/**
* The search criteria for finding free games. Either the weekly promotion, and free promotion, or all free products.
* @example weekly
* @default all
* @env SEARCH_STRATEGY
*/
@IsOptional()
@IsEnum(SearchStrategy)
searchStrategy = process.env.SEARCH_STRATEGY || SearchStrategy.ALL;
/**
* If true, the process will run on startup in addition to the scheduled time.
* @example true
* @default false
* @env RUN_ON_STARTUP
*/
@IsOptional()
@IsBoolean()
runOnStartup = process.env.RUN_ON_STARTUP?.toLowerCase() === 'true' || false;
/**
* If true, don't schedule runs. Use with RUN_ON_STARTUP to run once and shutdown.
* @example true
* @default false
* @env RUN_ONCE
*/
@IsOptional()
@IsBoolean()
runOnce = process.env.RUN_ONCE?.toLowerCase() === 'true' || false;
/**
* TZ name from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
* @example America/Chicago
* @default UTC
* @env TZ
*/
@IsOptional()
@IsString()
timezone = process.env.TZ || 'UTC';
/**
* The delay interval between runs of each account in seconds. (Only effective when multiple accounts are configured)
* @example 30
* @default 60
* @env INTERVAL_TIME
*/
@IsOptional()
@IsInt()
@Min(0)
intervalTime = process.env.INTERVAL_TIME ? parseInt(process.env.INTERVAL_TIME, 10) : 60;
/**
* How many accounts can be processed at the same time
* @example 1
* @default 3
* @env ACCOUNT_CONCURRENCY
*/
@IsOptional()
@IsInt()
@Min(1)
accountConcurrency = process.env.ACCOUNT_CONCURRENCY
? parseInt(process.env.ACCOUNT_CONCURRENCY, 10)
: 3;
/**
* Log level in lower case. Can be [silent, error, warn, info, debug, trace]
* @example debug
* @default info
* @env LOG_LEVEL
*/
@IsOptional()
@IsEnum(LogLevel)
logLevel = process.env.LOG_LEVEL || LogLevel.INFO;
/**
* Web server configurations for the remote web portal
*/
@IsOptional()
@ValidateNested()
@Type(() => WebPortalConfig)
webPortalConfig?: WebPortalConfig;
/**
* A list of accounts to work with
*/
@IsArray()
@ValidateNested({ each: true })
@ArrayNotEmpty()
@Type(() => AccountConfig)
accounts: AccountConfig[];
/**
* Global default notification configuration.
*
* You may configure multiple notifiers, and they will all be triggered simultaneously.
*/
@IsOptional()
@ValidateNested()
@IsArray()
@Type(() => NotifierConfig, {
discriminator: {
property: 'type',
subTypes: notifierSubtypes,
},
})
notifiers?: AnyNotifierConfig[];
/**
* When true, the process will send test notifications with a test redirect to example.com for all configured accounts.
* **Be sure to disable this after a successful test.**
* This test will block normal operation until the test link is accessed by one account. The test page can only be used once.
* @example true
* @default false
* @env TEST_NOTIFIERS
*/
@IsOptional()
@IsBoolean()
testNotifiers = process.env.TEST_NOTIFIERS?.toLowerCase() === 'true' || false;
/**
* Skip the call to api.github.com that checks for the latest version on launch
* @example true
* @default false
* @env SKIP_VERSION_CHECK
*/
@IsOptional()
@IsBoolean()
skipVersionCheck = process.env.SKIP_VERSION_CHECK?.toLowerCase() === 'true' || false;
/**
* In seconds, how long before a [stuck Chromium process](https://github.com/claabs/epicgames-freegames-node/issues/164) times out and gets restarted
* @example 30
* @default 15
* @env BROWSER_LAUNCH_TIMEOUT
*/
@IsOptional()
@IsInt()
@Min(1)
browserLaunchTimeout = process.env.BROWSER_LAUNCH_TIMEOUT
? parseInt(process.env.BROWSER_LAUNCH_TIMEOUT, 10)
: 15;
/**
* How many times to attempt retry attempts to launch a browser after it [times out](https://github.com/claabs/epicgames-freegames-node/issues/164)
* @example 2
* @default 5
* @env BROWSER_LAUNCH_RETRY_ATTEMPTS
*/
@IsOptional()
@IsInt()
@Min(0)
browserLaunchRetryAttempts = process.env.BROWSER_LAUNCH_RETRY_ATTEMPTS
? parseInt(process.env.BROWSER_LAUNCH_RETRY_ATTEMPTS, 10)
: 5;
/**
* How long in milliseconds the browser navigation will wait before timing out.
* 0 disables timeout (not recommended).
* See: https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagesetdefaulttimeouttimeout
* @example 120000
* @default 30000
* @env BROWSER_NAVIGATION_TIMEOUT
*/
@IsOptional()
@IsInt()
@Min(0)
browserNavigationTimeout = process.env.BROWSER_NAVIGATION_TIMEOUT
? parseInt(process.env.BROWSER_NAVIGATION_TIMEOUT, 10)
: 30000;
/**
* The 2 character country code associated with your account.
* Used when determining if a game is blacklisted for your account.
* Commonly blacklisted countries: "MO","HK","RU","BY","CN"
* @example RU
* @default blacklisting is not checked
* @env COUNTRY_CODE
*/
@IsOptional()
@IsString()
countryCode = process.env.COUNTRY_CODE;
/**
* The Epic Games application client ID used for device code authorization to check your account's ownership of a game
* List of available clients [here](https://github.com/Jaren8r/EpicClients).
* @example b070f20729f84693b5d621c904fc5bc2 (Diesel - Dauntless)
* @example e645e4b96298419cbffbfa353ebf8b82 (wexAndroidGameClient)
* @default 98f7e42c2e3a4f86a74eb43fbb41ed39 (fortniteNewSwitchGameClient client ID)
* @env DEVICE_AUTH_CLIENT_ID
*/
@IsOptional()
@IsString()
deviceAuthClientId = process.env.DEVICE_AUTH_CLIENT_ID || '98f7e42c2e3a4f86a74eb43fbb41ed39';
/**
* The Epic Games application secret used for device code authorization to check your account's ownership of a game.
* List of available clients [here](https://github.com/Jaren8r/EpicClients).
* @example HG@XE&TGCxEJsgT#&_p2]=aRo#~>=>+c6PhR)zXP (Diesel - Dauntless)
* @example d03089fd-628a-448a-ac39-0e8c5b022a11 (wexAndroidGameClient)
* @default 0a2449a2-001a-451e-afec-3e812901c4d7 (fortniteNewSwitchGameClient client secret)
* @env DEVICE_AUTH_SECRET
*/
@IsOptional()
@IsString()
deviceAuthSecret = process.env.DEVICE_AUTH_SECRET || '0a2449a2-001a-451e-afec-3e812901c4d7';
/**
* After redirecting to a device authorization verification URL, how often the Epic Games API is polled for a successful login.
* @example 20
* @default 10
* @env DEVICE_AUTH_POLL_RATE_SECONDS
*/
@Min(1) // TODO: breaking change, set to 10
@IsNumber()
@IsOptional()
deviceAuthPollRateSeconds = process.env.DEVICE_AUTH_POLL_RATE_SECONDS
? parseInt(process.env.DEVICE_AUTH_POLL_RATE_SECONDS, 10)
: 10;
/**
* The full path where the browser automation error screenshots will be output
* @example /errors
* @default ${CONFIG_DIR}/errors
* @env ERRORS_DIR
*/
@IsOptional()
@IsString()
errorsDir = process.env.ERRORS_DIR || path.join(CONFIG_DIR, 'errors');
/**
* @hidden
*/
constructor() {
// Use environment variables to fill one account if present
const { EMAIL } = process.env;
if (EMAIL) {
const account = new AccountConfig();
account.email = EMAIL;
this.accounts = [account];
}
// Use environment variables to fill email notification config if present
const {
SMTP_HOST,
SMTP_PORT,
EMAIL_SENDER_ADDRESS,
EMAIL_SENDER_NAME,
EMAIL_RECIPIENT_ADDRESS,
SMTP_SECURE,
SMTP_USERNAME,
SMTP_PASSWORD,
} = process.env;
if (
SMTP_HOST &&
SMTP_PORT &&
EMAIL_SENDER_ADDRESS &&