Skip to content

Commit 118aec2

Browse files
committed
feat: trial apis & interval support
1 parent 55e7529 commit 118aec2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1083
-870
lines changed

Diff for: .eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
},
1616
"rules": {
1717
"global-require": 0,
18+
"lines-between-class-members": 0,
19+
"no-continue": 0,
20+
"no-plusplus": 0,
1821
"import/no-dynamic-require": 0,
1922
"camelcase": 0,
2023
"react/jsx-props-no-spreading": 0,

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ server/src/routes/api/v1/*
4444
!server/src/routes/api/v1/available.js
4545
!server/src/routes/api/v1/config.js
4646
!server/src/routes/api/v1/area.js
47+
!server/src/routes/api/v1/trial.js
4748

4849
# custom model
4950
server/src/models/Custom.js

Diff for: ReactMap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
/* eslint-disable import/no-extraneous-dependencies */
33
const { build } = require('vite')
44

5-
const { log, HELPERS } = require('@rm/logger')
5+
const { log, TAGS } = require('@rm/logger')
66
const { generate } = require('@rm/masterfile')
77

88
generate(true).then(() =>
99
build()
10-
.then(() => log.info(HELPERS.build, 'React Map Compiled'))
10+
.then(() => log.info(TAGS.build, 'React Map Compiled'))
1111
.then(() => require('./server/src/index')),
1212
)

Diff for: packages/config/lib/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (process.env.NODE_CONFIG_ENV) {
2222
}
2323
}
2424

25-
const { setLogLevel, HELPERS, log } = require('@rm/logger')
25+
const { setGlobalLogLevel, TAGS, log } = require('@rm/logger')
2626
const { applyMutations } = require('./mutations')
2727

2828
function purge() {
@@ -38,21 +38,23 @@ function purge() {
3838

3939
const config = require('config')
4040

41+
config.getSafe = function getSafe(key) {
42+
return this.get(key)
43+
}
44+
45+
setGlobalLogLevel(config.getSafe('devOptions.logLevel'))
46+
4147
config.reload = function reload() {
4248
try {
4349
purge()
44-
log.info(HELPERS.config, 'config purged, returning old reference')
50+
log.info(TAGS.config, 'config purged, returning old reference')
4551
return this
4652
} catch (e) {
47-
log.error(HELPERS.config, 'error reloading config', e)
53+
log.error(TAGS.config, 'error reloading config', e)
4854
return this
4955
}
5056
}
5157

52-
config.getSafe = function getSafe(key) {
53-
return require('config').get(key)
54-
}
55-
5658
config.getMapConfig = function getMapConfig(req) {
5759
const domain = /** @type {const} */ (
5860
`multiDomainsObj.${req.headers.host.replaceAll('.', '_')}`
@@ -70,10 +72,10 @@ config.getAreas = function getAreas(req, key) {
7072
}
7173

7274
config.setAreas = function setAreas(newAreas) {
75+
log.info(TAGS.config, 'updating areas')
7376
this.areas = newAreas
7477
}
7578

76-
setLogLevel(config.getSafe('devOptions.logLevel'))
7779
applyMutations(config)
7880

7981
module.exports = config

Diff for: packages/config/lib/mutations.js

+12-31
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
const fs = require('fs')
44
const { resolve } = require('path')
55

6-
const { log, HELPERS } = require('@rm/logger')
6+
const { log, TAGS } = require('@rm/logger')
77

88
const { validateJsons } = require('./validateJsons')
99

1010
/** @param {import('config').IConfig} config */
1111
const applyMutations = (config) => {
1212
if (process.env.NODE_CONFIG_ENV) {
13-
log.info(HELPERS.config, `Using config for ${process.env.NODE_CONFIG_ENV}`)
13+
log.info(TAGS.config, `Using config for ${process.env.NODE_CONFIG_ENV}`)
1414
}
1515
const nodeConfigDir = process.env.NODE_CONFIG_DIR || ''
1616

@@ -40,13 +40,13 @@ const applyMutations = (config) => {
4040

4141
if (refLength !== defaultLength) {
4242
log.warn(
43-
HELPERS.config,
43+
TAGS.config,
4444
'It looks like you have modified the `default.json` file, you should not do this! Make all of your config changes in your `local.json` file.',
4545
)
4646
}
4747
} catch (e) {
4848
log.error(
49-
HELPERS.config,
49+
TAGS.config,
5050
'Error trying to read either the default.json or .ref file',
5151
e,
5252
)
@@ -111,7 +111,7 @@ const applyMutations = (config) => {
111111
})
112112
} else {
113113
log.error(
114-
HELPERS.config,
114+
TAGS.config,
115115
'Missing scanner database config! \nCheck to make sure you have SCANNER_DB_HOST,SCANNER_DB_PORT, SCANNER_DB_NAME, SCANNER_DB_USERNAME, and SCANNER_DB_PASSWORD',
116116
)
117117
}
@@ -126,7 +126,7 @@ const applyMutations = (config) => {
126126
})
127127
} else {
128128
log.info(
129-
HELPERS.config,
129+
TAGS.config,
130130
'Missing ReactMap specific table, attempting to use the manual database instead.',
131131
)
132132
}
@@ -141,14 +141,14 @@ const applyMutations = (config) => {
141141
})
142142
} else if (!hasReactMapDb) {
143143
log.error(
144-
HELPERS.config,
144+
TAGS.config,
145145
'Neither a ReactMap database or Manual database was found, you will need one of these to proceed.',
146146
)
147147
}
148148
}
149149
if (fs.existsSync(resolve(nodeConfigDir, `config.json`))) {
150150
log.info(
151-
HELPERS.config,
151+
TAGS.config,
152152
'Config v1 (config.json) found, it is fine to leave it but make sure you are using and updating local.json instead.',
153153
)
154154
}
@@ -186,7 +186,7 @@ const applyMutations = (config) => {
186186
merged.misc.distanceUnit !== 'miles'
187187
) {
188188
log.warn(
189-
HELPERS.config,
189+
TAGS.config,
190190
`Invalid distanceUnit: ${merged.misc.distanceUnit}, only 'kilometers' OR 'miles' are allowed.`,
191191
)
192192
if (merged.misc.distance === 'km') {
@@ -224,7 +224,7 @@ const applyMutations = (config) => {
224224

225225
if (config.has('multiDomains')) {
226226
log.warn(
227-
HELPERS.config,
227+
TAGS.config,
228228
'`multiDomains` has been deprecated and will be removed in the next major release. Please switch to the new format that makes use of `NODE_CONFIG_ENV`',
229229
)
230230
// Create multiDomain Objects
@@ -262,20 +262,9 @@ const applyMutations = (config) => {
262262
const aliasObj = Object.fromEntries(
263263
config.authentication.aliases.map((alias) => [alias.name, alias.role]),
264264
)
265-
265+
/** @param {string} role */
266266
const replaceAliases = (role) => aliasObj[role] ?? role
267267

268-
const getJsDate = (dataObj = {}) =>
269-
new Date(
270-
dataObj.year,
271-
dataObj.month - 1,
272-
dataObj.day,
273-
dataObj.hour || 0,
274-
dataObj.minute || 0,
275-
dataObj.second || 0,
276-
dataObj.millisecond || 0,
277-
)
278-
279268
const replaceBothAliases = (incomingObj) => ({
280269
...incomingObj,
281270
discordRoles: Array.isArray(incomingObj.discordRoles)
@@ -314,14 +303,6 @@ const applyMutations = (config) => {
314303
: [],
315304
trialPeriod: {
316305
...strategy.trialPeriod,
317-
start: {
318-
...strategy?.trialPeriod?.start,
319-
js: getJsDate(strategy?.trialPeriod?.start),
320-
},
321-
end: {
322-
...strategy?.trialPeriod?.end,
323-
js: getJsDate(strategy?.trialPeriod?.end),
324-
},
325306
roles: Array.isArray(strategy?.trialPeriod?.roles)
326307
? strategy.trialPeriod.roles.map(replaceAliases)
327308
: [],
@@ -361,7 +342,7 @@ const applyMutations = (config) => {
361342
)
362343
)
363344
log.warn(
364-
HELPERS.config,
345+
TAGS.config,
365346
'No authentication strategies enabled, adding the following perms to alwaysEnabledPerms array:\n',
366347
enabled,
367348
)

Diff for: packages/config/lib/validateJsons.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const fs = require('fs')
33
const { resolve } = require('path')
44

5-
const { log, HELPERS } = require('@rm/logger')
5+
const { log, TAGS } = require('@rm/logger')
66

77
/**
88
*
@@ -23,7 +23,7 @@ function validateJsons(fileName, domain = process.env.NODE_CONFIG_ENV || '') {
2323
: {}
2424
if (Object.keys(generalJson).length && !domain) {
2525
log.info(
26-
HELPERS.config,
26+
TAGS.config,
2727
`${fileName}.json found, overwriting your config.map.${fileName} with the found data.`,
2828
)
2929
}
@@ -40,7 +40,7 @@ function validateJsons(fileName, domain = process.env.NODE_CONFIG_ENV || '') {
4040
) || {}
4141
if (Object.keys(domainJson).length) {
4242
log.info(
43-
HELPERS.config,
43+
TAGS.config,
4444
`${fileName}/${domain}.json found, overwriting your config.map.${fileName} for ${domain} with the found data.`,
4545
)
4646
}

Diff for: packages/locales/lib/create.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { default: fetch } = require('node-fetch')
33

44
const config = require('@rm/config')
5-
const { log, HELPERS } = require('@rm/logger')
5+
const { log, TAGS } = require('@rm/logger')
66

77
const {
88
fetchRemote,
@@ -19,7 +19,7 @@ async function create() {
1919
const endpoint = config.getSafe('api.pogoApiEndpoints.translations')
2020

2121
if (!endpoint) {
22-
log.error(HELPERS.locales, 'No translations endpoint')
22+
log.error(TAGS.locales, 'No translations endpoint')
2323
return
2424
}
2525
const localTranslations = readLocaleDirectory(true)
@@ -39,7 +39,7 @@ async function create() {
3939

4040
if (!availableRemote.has(fileName)) {
4141
log.warn(
42-
HELPERS.locales,
42+
TAGS.locales,
4343
'No remote translation found for',
4444
fileName,
4545
'using English',
@@ -59,7 +59,7 @@ async function create() {
5959
...humanLocales,
6060
}
6161

62-
log.info(HELPERS.locales, fileName, 'done.')
62+
log.info(TAGS.locales, fileName, 'done.')
6363
return [locale, finalTranslations]
6464
}),
6565
)
@@ -75,5 +75,5 @@ if (require.main === module) {
7575
.then((locales) =>
7676
writeAll(locales, true, __dirname, '../../../dist/locales'),
7777
)
78-
.then(() => log.info(HELPERS.locales, 'locales have finished'))
78+
.then(() => log.info(TAGS.locales, 'locales have finished'))
7979
}

Diff for: packages/locales/lib/generate.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require('dotenv').config()
77
const { OpenAI } = require('openai')
88
const { encode } = require('gpt-tokenizer')
99

10-
const { log, HELPERS } = require('@rm/logger')
10+
const { log, TAGS } = require('@rm/logger')
1111

1212
const { readAndParseJson, readLocaleDirectory, writeAll } = require('./utils')
1313

@@ -147,7 +147,7 @@ async function generate() {
147147
try {
148148
const chunks = splitJson(missingKeys)
149149
log.info(
150-
HELPERS.locales,
150+
TAGS.locales,
151151
locale,
152152
'making',
153153
chunks.length,
@@ -178,7 +178,7 @@ async function generate() {
178178
result.reduce((acc, x) => ({ ...acc, ...x }), generated),
179179
]
180180
} catch (error) {
181-
log.error(HELPERS.locales, error)
181+
log.error(TAGS.locales, error)
182182
}
183183
}),
184184
)
@@ -197,6 +197,6 @@ if (require.main === module) {
197197
generate()
198198
.then((locales) => writeAll(locales, false, __dirname, './generated'))
199199
.then(() =>
200-
log.info(HELPERS.locales, 'ai has finished checking for missing locales'),
200+
log.info(TAGS.locales, 'ai has finished checking for missing locales'),
201201
)
202202
}

Diff for: packages/locales/lib/missing.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { promises: fs } = require('fs')
33
const { resolve } = require('path')
44

5-
const { log, HELPERS } = require('@rm/logger')
5+
const { log, TAGS } = require('@rm/logger')
66
const { readAndParseJson, readLocaleDirectory } = require('./utils')
77

88
/**
@@ -43,7 +43,7 @@ async function missingAll() {
4343
),
4444
JSON.stringify(missingKeys, null, 2),
4545
)
46-
log.info(HELPERS.locales, fileName, 'file saved.')
46+
log.info(TAGS.locales, fileName, 'file saved.')
4747
}),
4848
)
4949
}

Diff for: packages/locales/lib/utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { promises: fs, readdirSync, readFileSync } = require('fs')
33
const { resolve } = require('path')
44
const { default: fetch } = require('node-fetch')
55

6-
const { log, HELPERS } = require('@rm/logger')
6+
const { log, TAGS } = require('@rm/logger')
77

88
const HUMAN_LOCALES = resolve(__dirname, './human')
99

@@ -35,7 +35,7 @@ async function fetchRemote(locale, endpoint) {
3535
}),
3636
)
3737
} catch (e) {
38-
log.error(HELPERS.locales, `[${locale}]`, e)
38+
log.error(TAGS.locales, `[${locale}]`, e)
3939
}
4040
}
4141

@@ -70,9 +70,9 @@ async function writeJson(translations, ...directories) {
7070
: JSON.stringify(translations, null, 2)
7171

7272
await fs.writeFile(resolved, file, 'utf8')
73-
log.info(HELPERS.locales, 'wrote file', `${resolved.split('/').pop()}`)
73+
log.info(TAGS.locales, 'wrote file', `${resolved.split('/').pop()}`)
7474
} catch (e) {
75-
log.error(HELPERS.locales, '[writeJson]', e)
75+
log.error(TAGS.locales, '[writeJson]', e)
7676
}
7777
}
7878

Diff for: packages/logger/lib/Logger.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export declare class Logger<Tags extends string[]> {
2+
log: import('loglevel').Logger
3+
#tags: Tags
4+
5+
constructor(...tags: Tags)
6+
7+
static #formatTags(tags: string[]): string
8+
static getTimestamp(): string
9+
10+
get loggerTag(): Tags extends [infer First, ...infer Rest]
11+
? Rest extends string[]
12+
? `${First & string}.${Rest[number]}`
13+
: `${First & string}`
14+
: ''
15+
}

0 commit comments

Comments
 (0)