@driveflux/env 0.0.2-develop.5 → 1.0.0-next.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/main.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/main.js DELETED
@@ -1,4 +0,0 @@
1
- import{a as A}from"./init-env.js";import{b as z}from"./augment-env.js";import{c as C,e as x}from"./chunk-wy1gj9e4.js";await A().catch((k)=>{console.error("Error initializing environment:",k),process.exit(1)});z();if(x.main==x.module){let k=process.argv.slice(2);if(!k.length)console.error("No arguments provided"),process.exit(1);let{spawn:B}=await import("node:child_process"),y=k.shift();if(!y)console.error("No binary to run provided"),process.exit(1);B(y,k,{stdio:"inherit",shell:!0,env:process.env})}
2
-
3
- //# debugId=E1235BA9A4FBE9DA64756E2164756E21
4
- //# sourceMappingURL=main.js.map
package/dist/main.js.map DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/main.ts"],
4
- "sourcesContent": [
5
- "import { augmentEnv } from './augment-env'\nimport { initEnv } from './init-env'\n\n// Init the env\nawait initEnv().catch((error: Error) => {\n console.error('Error initializing environment:', error)\n process.exit(1)\n})\n\n// Augment the env with the base configs\naugmentEnv()\n\nif (import.meta.main) {\n // When this file is called as the main, it is supposed to load the env\n // and set it in the shell calling the rest of the script from argv\n // as if it's just a pre-script to load env variables\n\n const args = process.argv.slice(2)\n if (!args.length) {\n console.error('No arguments provided')\n process.exit(1)\n }\n\n const { spawn } = await import('node:child_process')\n const binToRunRun = args.shift()\n if (!binToRunRun) {\n console.error('No binary to run provided')\n process.exit(1)\n }\n spawn(binToRunRun, args, {\n stdio: 'inherit',\n shell: true,\n env: process.env,\n })\n}\n"
6
- ],
7
- "mappings": "qIAIA,HAAM,JAAQ,EAAE,MAAM,CAAC,IAAiB,CACtC,QAAQ,MAAM,kCAAmC,CAAK,EACtD,QAAQ,KAAK,CAAC,EACf,EAGD,EAAW,EAEX,GAAI,iBAAkB,CAKpB,IAAM,EAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,GAAI,CAAC,EAAK,OACR,QAAQ,MAAM,uBAAuB,EACrC,QAAQ,KAAK,CAAC,EAGhB,IAAQ,SAAU,KAAa,8BACzB,EAAc,EAAK,MAAM,EAC/B,GAAI,CAAC,EACH,QAAQ,MAAM,2BAA2B,EACzC,QAAQ,KAAK,CAAC,EAEhB,EAAM,EAAa,EAAM,CACvB,MAAO,UACP,MAAO,GACP,IAAK,QAAQ,GACf,CAAC",
8
- "debugId": "E1235BA9A4FBE9DA64756E2164756E21",
9
- "names": []
10
- }
package/src/app-env.ts DELETED
@@ -1,21 +0,0 @@
1
- export const getAppEnv = () => {
2
- if (process.env.APP_ENV) {
3
- return process.env.APP_ENV
4
- }
5
-
6
- // If USE_ENV is set, use it
7
- if (process.env.USE_ENV) {
8
- return process.env.USE_ENV
9
- }
10
-
11
- // If NODE_ENV is set, use it
12
- if (process.env.NODE_ENV) {
13
- return process.env.NODE_ENV
14
- }
15
-
16
- // Default to development as a last resort
17
- return 'development'
18
- }
19
-
20
- const isAppEnv = (env: string) => getAppEnv() === env
21
- export const isProd = () => isAppEnv('production')
@@ -1,15 +0,0 @@
1
- import { getAppEnv } from './app-env'
2
- import { getNotionIds, getSlackIds } from './base-configs'
3
-
4
- export const augmentEnv = () => {
5
- const slackIds = getSlackIds(getAppEnv(), process.env)
6
- const notionIds = getNotionIds(getAppEnv())
7
-
8
- for (const [key, value] of Object.entries({ ...slackIds, ...notionIds })) {
9
- if (process.env[key]) {
10
- continue
11
- }
12
-
13
- process.env[key] = value
14
- }
15
- }
@@ -1,96 +0,0 @@
1
- type SlackIds = {
2
- -readonly [k in keyof typeof slackProductionChannels]: string
3
- }
4
- type NotionIds = {
5
- -readonly [k in keyof typeof notionProductionChannels]: string
6
- }
7
-
8
- const slackProductionChannels = {
9
- SLACK_DEFAULT_CHANNEL_ID: 'C0679V8KGSH',
10
- SLACK_RESERVATIONS_CHANNEL_ID: 'C01G8B12G67',
11
- SLACK_FBC_CHANNEL: 'C01L1AAKB3N',
12
- SLACK_BD_CHANNEL: 'CN21PGKK8',
13
- SLACK_MAIN_FLUX_CHANNEL: 'GHDPV1858',
14
- SLACK_INQUIRIES_CHANNEL_ID: 'C067CSK5J5Q',
15
- SLACK_INVOICE_FAILURES_CHANNEL_ID: 'C067CPUMB8T',
16
- SLACK_SST_CHANNEL_ID: 'C068NH60A78',
17
- SLACK_ERROR_CHANNEL_ID: 'C04N4Q7HA79',
18
- SLACK_ISSUES_CHANNEL_ID: 'C0680P99AE8',
19
- SLACK_COMING_SERVICES_CHANNEL_ID: 'C06SB20H2J1',
20
- SLACK_ESMS_CHANNEL_ID: 'C07RPEP2BMY',
21
- SLACK_EXCESS_MILEAGE_CHANNEL_ID: 'C0679URBY93',
22
- SLACK_ENGINEERING_REQUESTS_CHANNEL_ID: 'C01U8GTK3K9',
23
- } as const
24
-
25
- const getSlackIdsMap = (processEnv?: Record<string, string | undefined>) =>
26
- ({
27
- production: slackProductionChannels,
28
- staging: Object.keys(slackProductionChannels).reduce((acc, key) => {
29
- acc[key as keyof SlackIds] = 'C0661UNMBQU' // #platform-staging-notifications
30
- return acc
31
- }, {} as SlackIds),
32
- development: Object.keys(slackProductionChannels).reduce((acc, key) => {
33
- acc[key as keyof SlackIds] =
34
- processEnv?.SLACK_MY_CHANNEL_ID || 'C09GJ4FJVRS' // #platform-dev-notifications
35
- return acc
36
- }, {} as SlackIds),
37
- }) as const satisfies Record<string, SlackIds>
38
-
39
- export const getSlackIds = (
40
- appEnv?: string,
41
- processEnv?: Record<string, string | undefined>,
42
- ): SlackIds => {
43
- const slackIdsMap = getSlackIdsMap(processEnv)
44
- const envIds: SlackIds =
45
- appEnv && appEnv in slackIdsMap
46
- ? slackIdsMap[appEnv as keyof typeof slackIdsMap]
47
- : slackIdsMap.staging
48
-
49
- // Override the values from ENV if available
50
- for (const key of Object.keys(envIds)) {
51
- if (processEnv?.[key]) {
52
- envIds[key as keyof SlackIds] = processEnv[key] as string
53
- }
54
- }
55
-
56
- return envIds
57
- }
58
-
59
- const notionProductionChannels = {
60
- NOTION_REQUEST_DATABASE_ID: '32332c0e-4277-43fa-b10e-7d458234f9ea',
61
- NOTION_REVIEWS_DATABASE_ID: '8a8b0df9-567d-433f-8937-583db2766176', // Seems to be unused
62
- NOTION_FBC_DATABASE_ID: '76960d4b-2b43-4019-a77e-ac46a0b3d752', // Seems to be unused
63
- NOTION_FLUXSTERS_DATABASE_ID: '4ea6953a-61c2-4673-8950-c0d0e158de0a',
64
- NOTION_BD_DATABASE_ID: '172a9182-56c0-4358-b4f1-7e8fcfa44e46',
65
- NOTION_BRANDS_LANDING_PAGES_DATABASE_ID:
66
- 'e321d71a-0d29-42da-ab0b-dca2260b643e',
67
- NOTION_KNOWLEDGE_BASE_DATABASE_ID: '7a81653f-4351-4a17-aa1e-c3082c378441',
68
- NOTION_REFERRALS_DATABASE_ID: 'b5599d70-b414-4aa9-9ff2-d445c8f3f0fc',
69
- } as const satisfies Record<string, string>
70
-
71
- const NOTION_IDS_MAP = {
72
- production: notionProductionChannels,
73
- staging: {
74
- ...notionProductionChannels,
75
- NOTION_KNOWLEDGE_BASE_DATABASE_ID: 'f95b9986-c1c9-46ca-a742-d49f3f80d7dd',
76
- },
77
- } as const satisfies Record<string, NotionIds>
78
-
79
- export const getNotionIds = (
80
- appEnv?: string,
81
- processEnv?: Record<string, string>,
82
- ): NotionIds => {
83
- const envIds: NotionIds =
84
- appEnv && appEnv in NOTION_IDS_MAP
85
- ? NOTION_IDS_MAP[appEnv as keyof typeof NOTION_IDS_MAP]
86
- : NOTION_IDS_MAP.staging
87
-
88
- // Override the values from ENV if available
89
- for (const key of Object.keys(envIds)) {
90
- if (processEnv?.[key]) {
91
- envIds[key as keyof NotionIds] = processEnv[key] as string
92
- }
93
- }
94
-
95
- return envIds
96
- }
package/src/init-env.ts DELETED
@@ -1,72 +0,0 @@
1
- import dotenv from '@dotenvx/dotenvx'
2
-
3
- /**
4
- * Dealing with env variables can be complicated. So we need to simplify the process
5
- *
6
- * Bun automatically loads a .env (or .env.[NODE_ENV]) file which will be detected
7
- * here as system set env variables and dotenvx won't work properly with USE_ENV.
8
- *
9
- * The way to fix this behaviour is to know how to separate between env set from the shell
10
- * and env loaded by bun.
11
- *
12
- * 1. Check the env loaded by bun according to its logic (load using NODE_ENV)
13
- * 2. If USE_ENV !== NODE_ENV, load those variables
14
- * 3. For each env loaded automatically by bun, we override the process env with the values from the loaded env.$USE_ENv files
15
- */
16
- export const initEnv = async () => {
17
- if (!process.env.USE_ENV) {
18
- if (process.env.NODE_ENV && process.env.NODE_ENV !== 'development') {
19
- return
20
- }
21
-
22
- process.env.USE_ENV = process.env.NODE_ENV || 'development'
23
- }
24
-
25
- // By default bun will load the .env files, so for example, if NODE_ENV=production,
26
- // it will load the .env.production file even if we're in the staging env (USE_ENV=staging)
27
- // so we need to override that behaviour
28
- const nodeEnv = process.env.NODE_ENV || 'development'
29
-
30
- // For these, we won't need to load them into the env because bun did
31
- // however, we record them to override them in case USE_ENV is different from NODE_ENV
32
- const bunLoadedEnv: Record<string, string> = {}
33
- dotenv.config({
34
- convention: 'nextjs',
35
- ignore: ['MISSING_ENV_FILE'],
36
- path: [`.env.${nodeEnv}.local`, `.env.${nodeEnv}`, '.env.local', '.env'],
37
- processEnv: bunLoadedEnv,
38
- logLevel: 'error',
39
- })
40
-
41
- // If USE_ENV is different from NODE_ENV, we need to load the .env.${USE_ENV} file and override
42
- // bun's loaded env from the files
43
- if (process.env.USE_ENV !== process.env.NODE_ENV) {
44
- // Load the .env files initially
45
- const useEnvLoadedEnv: Record<string, string> = {}
46
- dotenv.config({
47
- convention: 'nextjs',
48
- ignore: ['MISSING_ENV_FILE'],
49
- override: true,
50
- path: [
51
- `.env.${process.env.USE_ENV}.local`,
52
- `.env.${process.env.USE_ENV}`,
53
- ],
54
- logLevel: 'info',
55
- processEnv: useEnvLoadedEnv,
56
- })
57
-
58
- for (const [key, value] of Object.entries(useEnvLoadedEnv)) {
59
- // No process env found, just set it
60
- if (!process.env[key]) {
61
- process.env[key] = value
62
- }
63
-
64
- if (bunLoadedEnv[key] !== value) {
65
- // Now we set the value in the process env to override bun's loaded env
66
- process.env[key] = value
67
- }
68
-
69
- // Here we do nothing because the env was set from the shell
70
- }
71
- }
72
- }
package/src/main.ts DELETED
@@ -1,35 +0,0 @@
1
- import { augmentEnv } from './augment-env'
2
- import { initEnv } from './init-env'
3
-
4
- // Init the env
5
- await initEnv().catch((error: Error) => {
6
- console.error('Error initializing environment:', error)
7
- process.exit(1)
8
- })
9
-
10
- // Augment the env with the base configs
11
- augmentEnv()
12
-
13
- if (import.meta.main) {
14
- // When this file is called as the main, it is supposed to load the env
15
- // and set it in the shell calling the rest of the script from argv
16
- // as if it's just a pre-script to load env variables
17
-
18
- const args = process.argv.slice(2)
19
- if (!args.length) {
20
- console.error('No arguments provided')
21
- process.exit(1)
22
- }
23
-
24
- const { spawn } = await import('node:child_process')
25
- const binToRunRun = args.shift()
26
- if (!binToRunRun) {
27
- console.error('No binary to run provided')
28
- process.exit(1)
29
- }
30
- spawn(binToRunRun, args, {
31
- stdio: 'inherit',
32
- shell: true,
33
- env: process.env,
34
- })
35
- }