@@ -51,7 +51,7 @@ export {
5151
5252export { ParamOptions , Expression } ;
5353
54- type SecretOrExpr = Param < any > | SecretParam | JsonSecretParam ;
54+ type SecretOrExpr = Param < any > | SecretParam | JsonSecretParam < any > ;
5555export const declaredParams : SecretOrExpr [ ] = [ ] ;
5656
5757/**
@@ -129,27 +129,38 @@ export function defineSecret(name: string): SecretParam {
129129 * This is useful for managing groups of related configuration values, such as all settings
130130 * for a third-party API, as a single unit.
131131 *
132- * The secret value must be valid JSON. At runtime, the value will be automatically parsed
133- * and returned as a JavaScript object. If the value is not valid JSON, an error will be thrown.
132+ * The secret value must be a valid JSON string . At runtime, the value will be automatically parsed
133+ * and returned as a JavaScript object. If the value is not set or is not valid JSON, an error will be thrown.
134134 *
135135 * @param name The name of the environment variable to use to load the parameter.
136136 * @returns A parameter whose `.value()` method returns the parsed JSON object.
137137 *
138138 * @example
139139 * ```typescript
140+ * // Without type parameter
140141 * const stripeConfig = defineJsonSecret("STRIPE_CONFIG");
142+ * const { apiKey, webhookSecret, clientId } = stripeConfig.value();
143+ *
144+ * // With type parameter for type safety
145+ * interface StripeConfig {
146+ * apiKey: string;
147+ * webhookSecret: string;
148+ * clientId: string;
149+ * }
150+ * const stripeConfig = defineJsonSecret<StripeConfig>("STRIPE_CONFIG");
151+ * const { apiKey } = stripeConfig.value(); // apiKey is typed as string
141152 *
142153 * exports.myApi = onRequest(
143154 * { secrets: [stripeConfig] },
144155 * (req, res) => {
145- * const { apiKey, webhookSecret, clientId } = stripeConfig.value();
156+ * const config = stripeConfig.value();
146157 * // ... use the configuration values
147158 * }
148159 * );
149160 * ```
150161 */
151- export function defineJsonSecret ( name : string ) : JsonSecretParam {
152- const param = new JsonSecretParam ( name ) ;
162+ export function defineJsonSecret < T = any > ( name : string ) : JsonSecretParam < T > {
163+ const param = new JsonSecretParam < T > ( name ) ;
153164 registerParam ( param ) ;
154165 return param ;
155166}
0 commit comments