11import express from "express" ;
2+ import fsPromise from "fs/promises"
3+
4+ const FISSION_CONFIGS_BASE_PATH = "/configs/fission-default/mailer-configs"
5+ const FISSION_SECRETS_BASE_PATH = "/secrets/fission-default/mailer-secrets"
26
37// Context type for Fission serverless functions
48// https://github.com/fission/environments/blob/c679ff68371ec779f87e855987157a52f05ea8dd/nodejs/server.js#L138-L142
@@ -9,4 +13,68 @@ export type FissionContext = {
913
1014// Callback type for Fission serverless functions
1115// https://github.com/fission/environments/blob/c679ff68371ec779f87e855987157a52f05ea8dd/nodejs/server.js#L144-L152
12- export type FissionCallback = ( status : number , body : any , headers ?: Record < string , string > ) => void
16+ export type FissionCallback = ( status : number , body : any , headers ?: Record < string , string > ) => void
17+
18+ // Cache for storing configuration values
19+ const configCache = new Map < string , string > ( ) ;
20+
21+ export async function fissionGetConfig ( name : string , useCache : boolean = true ) : Promise < string | null > {
22+ // Check environment variables first (highest priority, always fresh)
23+ if ( process . env [ name ] ) {
24+ return process . env [ name ] ! ;
25+ }
26+
27+ // Check cache if enabled
28+ if ( useCache && configCache . has ( name ) ) {
29+ return configCache . get ( name ) ! ;
30+ }
31+
32+ // Check if file exists
33+ try {
34+ await fsPromise . access ( `${ FISSION_CONFIGS_BASE_PATH } /${ name } ` ) ;
35+ } catch ( e ) {
36+ return null ;
37+ }
38+
39+ // Read and cache the file content
40+ const content = await fsPromise . readFile ( `${ FISSION_CONFIGS_BASE_PATH } /${ name } ` , 'utf8' ) ;
41+
42+ // Update cache
43+ if ( useCache ) {
44+ configCache . set ( name , content ) ;
45+ }
46+
47+ return content ;
48+ }
49+
50+ // Cache for storing secret values
51+ const secretCache = new Map < string , string > ( ) ;
52+
53+ export async function fissionGetSecret ( name : string , useCache : boolean = true ) : Promise < string | null > {
54+ // Check environment variables first (highest priority, always fresh)
55+ if ( process . env [ name ] ) {
56+ return process . env [ name ] ! ;
57+ }
58+
59+ // Check cache if enabled
60+ if ( useCache && secretCache . has ( name ) ) {
61+ return secretCache . get ( name ) ! ;
62+ }
63+
64+ // Check if file exists
65+ try {
66+ await fsPromise . access ( `${ FISSION_SECRETS_BASE_PATH } /${ name } ` ) ;
67+ } catch ( e ) {
68+ return null ;
69+ }
70+
71+ // Read and cache the secret content
72+ const content = await fsPromise . readFile ( `${ FISSION_SECRETS_BASE_PATH } /${ name } ` , 'utf8' ) ;
73+
74+ // Update cache
75+ if ( useCache ) {
76+ secretCache . set ( name , content ) ;
77+ }
78+
79+ return content ;
80+ }
0 commit comments