-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(config): use znv to parse and validate env variable
- Loading branch information
Showing
10 changed files
with
66 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
export default { | ||
botDomain: process.env.BOT_DOMAIN as string, | ||
port: (process.env.PORT || 3000) as number, | ||
botToken: process.env.BOT_TOKEN as string, | ||
nodeEnv: process.env.NODE_ENV as string, | ||
adminId: process.env.ADMIN_ID as string, | ||
scraperAPIKey: process.env.SCRAPER_API_KEY as string, | ||
databaseUrl: process.env.DATABASE_URL as string, | ||
databaseAuthToken: process.env.DATABASE_AUTH_TOKEN as string, | ||
xenditSecret: process.env.XENDIT_SECRET as string, | ||
midtransServerKey: process.env.MIDTRANS_SERVER_KEY as string, | ||
midtransClientKey: process.env.MIDTRANS_CLIENT_KEY as string, | ||
message: { | ||
start: `Selamat datang di bot *KBBI* | ||
import { parseEnv, port, z } from 'znv' | ||
|
||
Dengan bot ini kalian dapat mencari pengertian dari suatu kata dalam KBBI. Kalian hanya perlu mengirim sebuah kata kepada bot ini, maka bot ini akan mengirim definisi dari kata Tersebut. | ||
export const { | ||
BOT_DOMAIN, | ||
PORT, | ||
BOT_TOKEN, | ||
NODE_ENV, | ||
ADMIN_ID, | ||
DATABASE_URL, | ||
DATABASE_AUTH_TOKEN, | ||
MIDTRANS_SERVER_KEY, | ||
MIDTRANS_CLIENT_KEY, | ||
} = parseEnv(process.env, { | ||
BOT_DOMAIN: z.string().url().optional(), | ||
PORT: port().default(3000), | ||
BOT_TOKEN: z.string().min(1), | ||
NODE_ENV: z.enum(['production', 'development']).default('development'), | ||
ADMIN_ID: z.number().int().positive(), | ||
DATABASE_URL: z.string().min(1), | ||
DATABASE_AUTH_TOKEN: z.string().optional(), | ||
MIDTRANS_SERVER_KEY: z.string().min(1), | ||
MIDTRANS_CLIENT_KEY: z.string().min(1), | ||
}) | ||
|
||
Data dari bot ini diambil dari situs resmi KBBI melalui metode _Web Scraping_ dengan *Node.js*, *Telegraf*, dan *Cheerio*. | ||
export const message = { | ||
start: `Selamat datang di bot *KBBI* | ||
Untuk pertanyaan lebih lanjut, silakan hubungi @tfkhdyt.`, | ||
help: 'Untuk menggunakan bot ini, kalian hanya perlu mengirimkan kata yang ingin kalian cari kepada bot ini.\nUntuk pertanyaan lebih lanjut, silakan hubungi @tfkhdyt.', | ||
}, | ||
Dengan bot ini kalian dapat mencari pengertian dari suatu kata dalam KBBI. Kalian hanya perlu mengirim sebuah kata kepada bot ini, maka bot ini akan mengirim definisi dari kata Tersebut. | ||
Data dari bot ini diambil dari situs resmi KBBI melalui metode _Web Scraping_ dengan *Node.js*, *Telegraf*, dan *Cheerio*. | ||
Untuk pertanyaan lebih lanjut, silakan hubungi @tfkhdyt.`, | ||
help: 'Untuk menggunakan bot ini, kalian hanya perlu mengirimkan kata yang ingin kalian cari kepada bot ini.\nUntuk pertanyaan lebih lanjut, silakan hubungi @tfkhdyt.', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { MidtransClient } from 'midtrans-node-client' | ||
|
||
import config from '../config/config.js' | ||
import { | ||
MIDTRANS_CLIENT_KEY, | ||
MIDTRANS_SERVER_KEY, | ||
NODE_ENV, | ||
} from '../config/config.js' | ||
|
||
export const snap = new MidtransClient.Snap({ | ||
isProduction: config.nodeEnv === 'production', | ||
serverKey: config.midtransServerKey, | ||
clientKey: config.midtransClientKey, | ||
isProduction: NODE_ENV === 'production', | ||
serverKey: MIDTRANS_SERVER_KEY, | ||
clientKey: MIDTRANS_CLIENT_KEY, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Telegraf } from 'telegraf' | ||
|
||
import config from '../config/config.js' | ||
import { BOT_TOKEN } from '../config/config.js' | ||
import { MyContext } from '../types/context.js' | ||
|
||
export const bot = new Telegraf<MyContext>(config.botToken) | ||
export const bot = new Telegraf<MyContext>(BOT_TOKEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Invoice } from 'xendit-node' | ||
// import { Invoice } from 'xendit-node' | ||
|
||
import config from '../config/config.js' | ||
// import config from '../config/config.js' | ||
|
||
export const xenditClient = new Invoice({ | ||
secretKey: config.xenditSecret, | ||
}) | ||
// export const xenditClient = new Invoice({ | ||
// secretKey: config.xenditSecret, | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters