firebase-functions 6.2.0 → 6.3.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/lib/common/providers/https.d.ts +6 -6
- package/lib/common/providers/https.js +2 -2
- package/lib/runtime/manifest.d.ts +3 -1
- package/lib/v2/providers/alerts/alerts.d.ts +1 -1
- package/lib/v2/providers/alerts/appDistribution.d.ts +1 -1
- package/lib/v2/providers/alerts/crashlytics.d.ts +1 -1
- package/lib/v2/providers/eventarc.d.ts +1 -1
- package/lib/v2/providers/https.d.ts +26 -3
- package/lib/v2/providers/https.js +32 -1
- package/lib/v2/providers/identity.d.ts +1 -1
- package/lib/v2/providers/pubsub.d.ts +1 -1
- package/lib/v2/providers/storage.d.ts +1 -1
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/package.json +2 -1
|
@@ -69,7 +69,7 @@ export interface CallableRequest<T = any> {
|
|
|
69
69
|
*/
|
|
70
70
|
data: T;
|
|
71
71
|
/**
|
|
72
|
-
* The result of decoding and verifying a Firebase
|
|
72
|
+
* The result of decoding and verifying a Firebase App Check token.
|
|
73
73
|
*/
|
|
74
74
|
app?: AppCheckData;
|
|
75
75
|
/**
|
|
@@ -87,14 +87,14 @@ export interface CallableRequest<T = any> {
|
|
|
87
87
|
/**
|
|
88
88
|
* Whether this is a streaming request.
|
|
89
89
|
* Code can be optimized by not trying to generate a stream of chunks to
|
|
90
|
-
* call response.sendChunk
|
|
91
|
-
* It is always safe, however, to call response.sendChunk as this will
|
|
92
|
-
* noop if acceptsStreaming is false.
|
|
90
|
+
* call `response.sendChunk` if `request.acceptsStreaming` is false.
|
|
91
|
+
* It is always safe, however, to call `response.sendChunk` as this will
|
|
92
|
+
* noop if `acceptsStreaming` is false.
|
|
93
93
|
*/
|
|
94
94
|
acceptsStreaming: boolean;
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* CallableProxyResponse allows streaming response chunks and listening to signals
|
|
97
|
+
* `CallableProxyResponse` allows streaming response chunks and listening to signals
|
|
98
98
|
* triggered in events such as a disconnect.
|
|
99
99
|
*/
|
|
100
100
|
export interface CallableResponse<T = unknown> {
|
|
@@ -106,7 +106,7 @@ export interface CallableResponse<T = unknown> {
|
|
|
106
106
|
*/
|
|
107
107
|
sendChunk: (chunk: T) => Promise<boolean>;
|
|
108
108
|
/**
|
|
109
|
-
* An AbortSignal that is triggered when the client disconnects or the
|
|
109
|
+
* An `AbortSignal` that is triggered when the client disconnects or the
|
|
110
110
|
* request is terminated prematurely.
|
|
111
111
|
*/
|
|
112
112
|
signal: AbortSignal;
|
|
@@ -396,7 +396,7 @@ function onCallHandler(options, handler, version) {
|
|
|
396
396
|
}
|
|
397
397
|
exports.onCallHandler = onCallHandler;
|
|
398
398
|
function encodeSSE(data) {
|
|
399
|
-
return `data: ${JSON.stringify(data)}\n`;
|
|
399
|
+
return `data: ${JSON.stringify(data)}\n\n`;
|
|
400
400
|
}
|
|
401
401
|
/** @internal */
|
|
402
402
|
function wrapOnCallHandler(options, handler, version) {
|
|
@@ -416,7 +416,7 @@ function wrapOnCallHandler(options, handler, version) {
|
|
|
416
416
|
if (!abortController.signal.aborted) {
|
|
417
417
|
heartbeatInterval = setTimeout(() => {
|
|
418
418
|
if (!abortController.signal.aborted) {
|
|
419
|
-
res.write(": ping\n");
|
|
419
|
+
res.write(": ping\n\n");
|
|
420
420
|
scheduleHeartbeat();
|
|
421
421
|
}
|
|
422
422
|
}, heartbeatSeconds * 1000);
|
|
@@ -42,7 +42,9 @@ export interface ManifestEndpoint {
|
|
|
42
42
|
httpsTrigger?: {
|
|
43
43
|
invoker?: string[];
|
|
44
44
|
};
|
|
45
|
-
callableTrigger?:
|
|
45
|
+
callableTrigger?: {
|
|
46
|
+
genkitAction?: string;
|
|
47
|
+
};
|
|
46
48
|
eventTrigger?: {
|
|
47
49
|
eventFilters: Record<string, string | Expression<string>>;
|
|
48
50
|
eventFilterPathPatterns?: Record<string, string | Expression<string>>;
|
|
@@ -60,7 +60,7 @@ export interface FirebaseAlertOptions extends options.EventHandlerOptions {
|
|
|
60
60
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
61
61
|
* function depends on the type of function: Event handling functions have a
|
|
62
62
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
63
|
-
* maximum timeout of
|
|
63
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
64
64
|
* timeout of 1,800s (30 minutes)
|
|
65
65
|
*/
|
|
66
66
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -83,7 +83,7 @@ export interface AppDistributionOptions extends options.EventHandlerOptions {
|
|
|
83
83
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
84
84
|
* function depends on the type of function: Event handling functions have a
|
|
85
85
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
86
|
-
* maximum timeout of
|
|
86
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
87
87
|
* timeout of 1,800s (30 minutes)
|
|
88
88
|
*/
|
|
89
89
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -149,7 +149,7 @@ export interface CrashlyticsOptions extends options.EventHandlerOptions {
|
|
|
149
149
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
150
150
|
* function depends on the type of function: Event handling functions have a
|
|
151
151
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
152
|
-
* maximum timeout of
|
|
152
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
153
153
|
* timeout of 1,800s (30 minutes)
|
|
154
154
|
*/
|
|
155
155
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -48,7 +48,7 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
|
|
|
48
48
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
49
49
|
* function depends on the type of function: Event handling functions have a
|
|
50
50
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
51
|
-
* maximum timeout of
|
|
51
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
52
52
|
* timeout of 1,800s (30 minutes)
|
|
53
53
|
*/
|
|
54
54
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -6,7 +6,7 @@ import { GlobalOptions, SupportedRegion } from "../options";
|
|
|
6
6
|
import { Expression } from "../../params";
|
|
7
7
|
import { SecretParam } from "../../params/types";
|
|
8
8
|
import * as options from "../options";
|
|
9
|
-
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
|
|
9
|
+
export { Request, CallableRequest, CallableResponse, FunctionsErrorCode, HttpsError };
|
|
10
10
|
/**
|
|
11
11
|
* Options that can be set on an onRequest HTTPS function.
|
|
12
12
|
*/
|
|
@@ -35,7 +35,7 @@ export interface HttpsOptions extends Omit<GlobalOptions, "region" | "enforceApp
|
|
|
35
35
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
36
36
|
* function depends on the type of function: Event handling functions have a
|
|
37
37
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
38
|
-
* maximum timeout of
|
|
38
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
39
39
|
* timeout of 1,800s (30 minutes)
|
|
40
40
|
*/
|
|
41
41
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -178,7 +178,7 @@ export interface CallableFunction<T, Return, Stream = unknown> extends HttpsFunc
|
|
|
178
178
|
*/
|
|
179
179
|
run(request: CallableRequest<T>): Return;
|
|
180
180
|
stream(request: CallableRequest<T>, response: CallableResponse<Stream>): {
|
|
181
|
-
stream:
|
|
181
|
+
stream: AsyncIterable<Stream>;
|
|
182
182
|
output: Return;
|
|
183
183
|
};
|
|
184
184
|
}
|
|
@@ -208,3 +208,26 @@ export declare function onCall<T = any, Return = any | Promise<any>, Stream = un
|
|
|
208
208
|
* @returns A function that you can export and deploy.
|
|
209
209
|
*/
|
|
210
210
|
export declare function onCall<T = any, Return = any | Promise<any>, Stream = unknown>(handler: (request: CallableRequest<T>, response?: CallableResponse<Stream>) => Return): CallableFunction<T, Return extends Promise<unknown> ? Return : Promise<Return>>;
|
|
211
|
+
interface ZodType<T = any> {
|
|
212
|
+
__output: T;
|
|
213
|
+
}
|
|
214
|
+
interface GenkitRunOptions {
|
|
215
|
+
context?: any;
|
|
216
|
+
}
|
|
217
|
+
type GenkitAction<I extends ZodType = ZodType<any>, O extends ZodType = ZodType<any>, S extends ZodType = ZodType<any>> = {
|
|
218
|
+
run(input: I["__output"], options: GenkitRunOptions): Promise<{
|
|
219
|
+
result: O["__output"];
|
|
220
|
+
}>;
|
|
221
|
+
stream(input: I["__output"], options: GenkitRunOptions): {
|
|
222
|
+
stream: AsyncIterable<S["__output"]>;
|
|
223
|
+
output: Promise<O["__output"]>;
|
|
224
|
+
};
|
|
225
|
+
__action: {
|
|
226
|
+
name: string;
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
type ActionInput<F extends GenkitAction> = F extends GenkitAction<infer I extends ZodType, any, any> ? I["__output"] : never;
|
|
230
|
+
type ActionOutput<F extends GenkitAction> = F extends GenkitAction<any, infer O extends ZodType, any> ? O["__output"] : never;
|
|
231
|
+
type ActionStream<F extends GenkitAction> = F extends GenkitAction<any, any, infer S extends ZodType> ? S["__output"] : never;
|
|
232
|
+
export declare function onCallGenkit<A extends GenkitAction>(action: A): CallableFunction<ActionInput<A>, Promise<ActionOutput<A>>, ActionStream<A>>;
|
|
233
|
+
export declare function onCallGenkit<A extends GenkitAction>(opts: CallableOptions<ActionInput<A>>, flow: A): CallableFunction<ActionInput<A>, Promise<ActionOutput<A>>, ActionStream<A>>;
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.onCall = exports.onRequest = exports.hasClaim = exports.isSignedIn = exports.HttpsError = void 0;
|
|
24
|
+
exports.onCallGenkit = exports.onCall = exports.onRequest = exports.hasClaim = exports.isSignedIn = exports.HttpsError = void 0;
|
|
25
25
|
/**
|
|
26
26
|
* Cloud functions to handle HTTPS request or callable RPCs.
|
|
27
27
|
* @packageDocumentation
|
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function (
|
|
|
35
35
|
const manifest_1 = require("../../runtime/manifest");
|
|
36
36
|
const options = require("../options");
|
|
37
37
|
const onInit_1 = require("../../common/onInit");
|
|
38
|
+
const logger = require("../../logger");
|
|
38
39
|
/**
|
|
39
40
|
* An auth policy that requires a user to be signed in.
|
|
40
41
|
*/
|
|
@@ -209,3 +210,33 @@ function onCall(optsOrHandler, handler) {
|
|
|
209
210
|
return func;
|
|
210
211
|
}
|
|
211
212
|
exports.onCall = onCall;
|
|
213
|
+
function onCallGenkit(optsOrAction, action) {
|
|
214
|
+
var _a;
|
|
215
|
+
let opts;
|
|
216
|
+
if (arguments.length === 2) {
|
|
217
|
+
opts = optsOrAction;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
opts = {};
|
|
221
|
+
action = optsOrAction;
|
|
222
|
+
}
|
|
223
|
+
if (!((_a = opts.secrets) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
224
|
+
logger.debug(`Genkit function for ${action.__action.name} is not bound to any secret. This may mean that you are not storing API keys as a secret or that you are not binding your secret to this function. See https://firebase.google.com/docs/functions/config-env?gen=2nd#secret_parameters for more information.`);
|
|
225
|
+
}
|
|
226
|
+
const cloudFunction = onCall(opts, async (req, res) => {
|
|
227
|
+
const context = {};
|
|
228
|
+
(0, encoding_1.copyIfPresent)(context, req, "auth", "app", "instanceIdToken");
|
|
229
|
+
if (!req.acceptsStreaming) {
|
|
230
|
+
const { result } = await action.run(req.data, { context });
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
const { stream, output } = action.stream(req.data, { context });
|
|
234
|
+
for await (const chunk of stream) {
|
|
235
|
+
await res.sendChunk(chunk);
|
|
236
|
+
}
|
|
237
|
+
return output;
|
|
238
|
+
});
|
|
239
|
+
cloudFunction.__endpoint.callableTrigger.genkitAction = action.__action.name;
|
|
240
|
+
return cloudFunction;
|
|
241
|
+
}
|
|
242
|
+
exports.onCallGenkit = onCallGenkit;
|
|
@@ -46,7 +46,7 @@ export interface BlockingOptions {
|
|
|
46
46
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
47
47
|
* function depends on the type of function: Event handling functions have a
|
|
48
48
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
49
|
-
* maximum timeout of
|
|
49
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
50
50
|
* timeout of 1,800s (30 minutes)
|
|
51
51
|
*/
|
|
52
52
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -104,7 +104,7 @@ export interface PubSubOptions extends options.EventHandlerOptions {
|
|
|
104
104
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
105
105
|
* function depends on the type of function: Event handling functions have a
|
|
106
106
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
107
|
-
* maximum timeout of
|
|
107
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
108
108
|
* timeout of 1,800s (30 minutes)
|
|
109
109
|
*/
|
|
110
110
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -180,7 +180,7 @@ export interface StorageOptions extends options.EventHandlerOptions {
|
|
|
180
180
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
181
181
|
* function depends on the type of function: Event handling functions have a
|
|
182
182
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
183
|
-
* maximum timeout of
|
|
183
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
184
184
|
* timeout of 1,800s (30 minutes)
|
|
185
185
|
*/
|
|
186
186
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
@@ -39,7 +39,7 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
|
|
|
39
39
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
40
40
|
* function depends on the type of function: Event handling functions have a
|
|
41
41
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
42
|
-
* maximum timeout of
|
|
42
|
+
* maximum timeout of 3,600s (1 hour). Task queue functions have a maximum
|
|
43
43
|
* timeout of 1,800s (30 minutes)
|
|
44
44
|
*/
|
|
45
45
|
timeoutSeconds?: number | Expression<number> | ResetValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -300,6 +300,7 @@
|
|
|
300
300
|
"eslint-plugin-jsdoc": "^39.2.9",
|
|
301
301
|
"eslint-plugin-prettier": "^4.0.0",
|
|
302
302
|
"firebase-admin": "^13.0.0",
|
|
303
|
+
"genkit": "^1.0.0-rc.4",
|
|
303
304
|
"js-yaml": "^3.13.1",
|
|
304
305
|
"jsdom": "^16.2.1",
|
|
305
306
|
"jsonwebtoken": "^9.0.0",
|