mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
use api_wrapper
This commit is contained in:
parent
728f33b01a
commit
20a59e8f3a
@ -1,131 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
if (!(process.env[secret.secretName])) {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -1,131 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
if (!(process.env[secret.secretName])) {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -3,7 +3,7 @@ import path from "node:path"
|
|||||||
|
|
||||||
export default async (middlewares, middlewaresPath) => {
|
export default async (middlewares, middlewaresPath) => {
|
||||||
if (typeof middlewaresPath === "undefined") {
|
if (typeof middlewaresPath === "undefined") {
|
||||||
middlewaresPath = path.resolve(globalThis["__root"], "middlewares")
|
middlewaresPath = path.resolve(globalThis["__src"], "middlewares")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(middlewaresPath)) {
|
if (!fs.existsSync(middlewaresPath)) {
|
||||||
|
@ -1,131 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
if (!(process.env[secret.secretName])) {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -1,131 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
if (!(process.env[secret.secretName])) {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -3,7 +3,7 @@ import path from "node:path"
|
|||||||
|
|
||||||
export default async (middlewares, middlewaresPath) => {
|
export default async (middlewares, middlewaresPath) => {
|
||||||
if (typeof middlewaresPath === "undefined") {
|
if (typeof middlewaresPath === "undefined") {
|
||||||
middlewaresPath = path.resolve(globalThis["__root"], "middlewares")
|
middlewaresPath = path.resolve(globalThis["__src"], "middlewares")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(middlewaresPath)) {
|
if (!fs.existsSync(middlewaresPath)) {
|
||||||
|
@ -1,131 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
if (!(process.env[secret.secretName])) {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -1,130 +1,3 @@
|
|||||||
import { webcrypto as crypto } from "crypto"
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
|
||||||
import infisical from "infisical-node"
|
|
||||||
|
|
||||||
require("dotenv").config()
|
require(path.resolve(process.cwd(), "../../shared/lib/api_wrapper"))
|
||||||
|
|
||||||
global.isProduction = process.env.NODE_ENV === "production"
|
|
||||||
|
|
||||||
globalThis["__root"] = path.resolve(__dirname)
|
|
||||||
|
|
||||||
const customAliases = {
|
|
||||||
"root": globalThis["__root"],
|
|
||||||
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
|
||||||
"@services": path.resolve(__dirname, "services"),
|
|
||||||
"@lib": path.resolve(__dirname, "lib"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!global.isProduction) {
|
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
|
||||||
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.USE_LINKED_SHARED) {
|
|
||||||
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
|
||||||
}
|
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
|
||||||
|
|
||||||
// patches
|
|
||||||
const { Buffer } = require("buffer")
|
|
||||||
|
|
||||||
global.b64Decode = (data) => {
|
|
||||||
return Buffer.from(data, "base64").toString("utf-8")
|
|
||||||
}
|
|
||||||
global.b64Encode = (data) => {
|
|
||||||
return Buffer.from(data, "utf-8").toString("base64")
|
|
||||||
}
|
|
||||||
|
|
||||||
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
|
||||||
|
|
||||||
Array.prototype.updateFromObjectKeys = function (obj) {
|
|
||||||
this.forEach((value, index) => {
|
|
||||||
if (obj[value] !== undefined) {
|
|
||||||
this[index] = obj[value]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
global.toBoolean = (value) => {
|
|
||||||
if (typeof value === "boolean") {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof value === "string") {
|
|
||||||
return value.toLowerCase() === "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
import API from "./api"
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (process.env.INFISICAL_TOKEN) {
|
|
||||||
console.log(`🔑 Injecting env variables from INFISICAL...`)
|
|
||||||
|
|
||||||
const client = new infisical({
|
|
||||||
token: process.env.INFISICAL_TOKEN,
|
|
||||||
})
|
|
||||||
|
|
||||||
const secrets = await client.getAllSecrets()
|
|
||||||
|
|
||||||
// inject to process.env
|
|
||||||
secrets.forEach((secret) => {
|
|
||||||
process.env[secret.secretName] = secret.secretValue
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new API()
|
|
||||||
|
|
||||||
await instance.initialize()
|
|
||||||
|
|
||||||
// kill on process exit
|
|
||||||
process.on("exit", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on ctrl+c
|
|
||||||
process.on("SIGINT", () => {
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on uncaught exceptions
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// kill on unhandled rejections
|
|
||||||
process.on("unhandledRejection", (error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
|
|
||||||
if (typeof instance.server.close === "function") {
|
|
||||||
instance.server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
console.error(`🆘 [FATAL ERROR] >`, error)
|
|
||||||
})
|
|
@ -3,7 +3,7 @@ import path from "node:path"
|
|||||||
|
|
||||||
export default async (middlewares, middlewaresPath) => {
|
export default async (middlewares, middlewaresPath) => {
|
||||||
if (typeof middlewaresPath === "undefined") {
|
if (typeof middlewaresPath === "undefined") {
|
||||||
middlewaresPath = path.resolve(globalThis["__root"], "middlewares")
|
middlewaresPath = path.resolve(globalThis["__src"], "middlewares")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fs.existsSync(middlewaresPath)) {
|
if (!fs.existsSync(middlewaresPath)) {
|
||||||
|
121
shared/lib/api_wrapper/index.js
Normal file
121
shared/lib/api_wrapper/index.js
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
require("dotenv").config()
|
||||||
|
|
||||||
|
import { webcrypto as crypto } from "crypto"
|
||||||
|
import path from "path"
|
||||||
|
import { registerBaseAliases } from "linebridge/dist/server"
|
||||||
|
import infisical from "infisical-node"
|
||||||
|
|
||||||
|
global.isProduction = process.env.NODE_ENV === "production"
|
||||||
|
|
||||||
|
globalThis["__root"] = path.resolve(process.cwd())
|
||||||
|
globalThis["__src"] = path.resolve(globalThis["__root"], "src")
|
||||||
|
|
||||||
|
const customAliases = {
|
||||||
|
"root": globalThis["__root"],
|
||||||
|
"src": globalThis["__src"],
|
||||||
|
"@shared-classes": path.resolve(globalThis["__src"], "_shared/classes"),
|
||||||
|
"@services": path.resolve(globalThis["__src"], "services"),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!global.isProduction) {
|
||||||
|
customAliases["comty.js"] = path.resolve(globalThis["__src"], "../../comty.js/src")
|
||||||
|
customAliases["@shared-classes"] = path.resolve(globalThis["__src"], "shared-classes")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.USE_LINKED_SHARED) {
|
||||||
|
customAliases["@shared-classes"] = path.resolve(globalThis["__src"], "shared-classes")
|
||||||
|
}
|
||||||
|
|
||||||
|
registerBaseAliases(undefined, customAliases)
|
||||||
|
|
||||||
|
// patches
|
||||||
|
const { Buffer } = require("buffer")
|
||||||
|
|
||||||
|
global.b64Decode = (data) => {
|
||||||
|
return Buffer.from(data, "base64").toString("utf-8")
|
||||||
|
}
|
||||||
|
global.b64Encode = (data) => {
|
||||||
|
return Buffer.from(data, "utf-8").toString("base64")
|
||||||
|
}
|
||||||
|
|
||||||
|
global.nanoid = (t = 21) => crypto.getRandomValues(new Uint8Array(t)).reduce(((t, e) => t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e > 62 ? "-" : "_"), "");
|
||||||
|
|
||||||
|
Array.prototype.updateFromObjectKeys = function (obj) {
|
||||||
|
this.forEach((value, index) => {
|
||||||
|
if (obj[value] !== undefined) {
|
||||||
|
this[index] = obj[value]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
global.toBoolean = (value) => {
|
||||||
|
if (typeof value === "boolean") {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === "string") {
|
||||||
|
return value.toLowerCase() === "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function injectEnvFromInfisical() {
|
||||||
|
const envMode = global.isProduction ? "prod" : "dev"
|
||||||
|
|
||||||
|
console.log(`🔑 Injecting env variables from INFISICAL in [${envMode}] mode...`)
|
||||||
|
|
||||||
|
const client = new infisical({
|
||||||
|
token: process.env.INFISICAL_TOKEN,
|
||||||
|
})
|
||||||
|
|
||||||
|
const secrets = await client.getAllSecrets({
|
||||||
|
environment: global.isProduction ? "prod" : "dev",
|
||||||
|
attachToProcessEnv: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
// inject to process.env
|
||||||
|
secrets.forEach((secret) => {
|
||||||
|
if (!(process.env[secret.secretName])) {
|
||||||
|
process.env[secret.secretName] = secret.secretValue
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleExit(instance, code) {
|
||||||
|
if (instance.server) {
|
||||||
|
if (typeof instance.server.close === "function") {
|
||||||
|
instance.server.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main({
|
||||||
|
main_filePath,
|
||||||
|
force_infisical,
|
||||||
|
} = {}) {
|
||||||
|
const API = require(main_filePath ?? path.resolve(globalThis["__src"], "api.js")).default
|
||||||
|
|
||||||
|
if (force_infisical || process.env.INFISICAL_TOKEN) {
|
||||||
|
await injectEnvFromInfisical()
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = new API()
|
||||||
|
|
||||||
|
process.on("exit", () => handleExit(instance, 0))
|
||||||
|
process.on("SIGINT", () => handleExit(instance, 0))
|
||||||
|
process.on("uncaughtException", () => handleExit(instance, 1))
|
||||||
|
process.on("unhandledRejection", () => handleExit(instance, 1))
|
||||||
|
|
||||||
|
await instance.initialize()
|
||||||
|
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error(`🆘 [FATAL ERROR] >`, error)
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user