@firebase-function-kits/firestore-bigquery-export 0.0.2-rc.14 → 0.0.2-rc.16
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/CHANGELOG.md +3 -1
- package/README.md +106 -16
- package/lib/default-options.d.ts +18 -0
- package/lib/default-options.d.ts.map +1 -0
- package/lib/default-options.js +36 -0
- package/lib/default-options.js.map +1 -0
- package/lib/events.d.ts +5 -0
- package/lib/events.d.ts.map +1 -1
- package/lib/events.js +10 -3
- package/lib/events.js.map +1 -1
- package/lib/global-options.d.ts +9 -0
- package/lib/global-options.d.ts.map +1 -0
- package/lib/global-options.js +78 -0
- package/lib/global-options.js.map +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -15
- package/lib/index.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +15 -1
- package/src/default-options.ts +35 -0
- package/src/events.ts +10 -2
- package/src/global-options.ts +48 -0
- package/src/index.ts +13 -15
- package/tests/default-options.test.ts +181 -0
- package/tests/events.test.ts +38 -0
- package/tests/index.test.ts +3 -3
- package/tests/required-apis.test.ts +102 -15
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
- feat: add the `./default-options` entry, which exports `defaultOptions` (`cpu: "gcf_gen1"`, `concurrency: 1`, `maxInstances: 100`). Spread it into your codebase's single `setGlobalOptions` call, before your own keys: `setGlobalOptions({ ...defaultOptions, region })`. The functions no longer declare `cpu` or `concurrency` themselves, so your global options can now override them; before, the per-function values always won. A hand-written entry that does not spread `defaultOptions` deploys at the 2nd gen defaults (1 vCPU at 256MiB, concurrency `80`) instead of the extension's 0.1666 vCPU. The trigger takes its instance cap from `defaultOptions` (100, the platform default the extension's 2nd gen trigger ran at) or your override. In an ES module entry, `export ... from` loads the kit before any `setGlobalOptions` statement in the same file runs, so call `setGlobalOptions` in its own module and import it first. Deploy discovery logs a warning when the kit loads with no global `cpu` set. `fsexportbigquery` keeps `ingressSettings: "ALLOW_INTERNAL_ONLY"`, the task-queue functions keep `timeoutSeconds: 540`, and `syncBigQuery` keeps `maxInstances: 500`, which a global `maxInstances` does not change.
|
|
2
|
+
- fix: `eventarcpublishing.googleapis.com` and `roles/eventarc.publisher` are declared only when `EVENTARC_CHANNEL` is set in `.env`. A default install never publishes an event, yet every deploy prompted to enable the Eventarc Publishing API and declining aborted the deploy with `Must enable required APIs to deploy.` The extension declared only `bigquery.googleapis.com` and gained Eventarc publishing when the user opted into events at install; the kit now does the same. Detecting the channel needs firebase-tools 15.28.0 or later, which loads `.env` during deploy discovery; an older CLI skips the declarations even with `EVENTARC_CHANNEL` set, and every publish then fails with `PERMISSION_DENIED`, logged as a warning while the export continues. A blank `EVENTARC_CHANNEL` now disables events the same as an unset one.
|
|
1
3
|
- fix: cap `syncBigQuery` at `maxInstances: 500`, its declared `maxConcurrentDispatches`. At concurrency `1`, the default 100 instances would take only 100 of the 500 dispatches Cloud Tasks may have in flight, so the cap keeps capacity level with the dispatch limit. A dispatch above the instance ceiling waits up to about 10 seconds for a free instance, then gets a Cloud Run 429 that Cloud Tasks counts as a failed attempt and retries on the queue's schedule (5 attempts, 60s minimum backoff), slowing the queue while 429s continue. The handler never ran for such a dispatch, so a task that exhausts its attempts that way writes no `BACKUP_COLLECTION` row. At 0.1666 vCPU the cap needs about 84 vCPU of regional Cloud Run CPU quota, within the captured defaults (500 in most regions, 343 in `europe-west10` and `europe-west12`); the README describes the deploy failure a smaller quota produces and how to recover.
|
|
2
4
|
- fix: set `timeoutSeconds: 540` on `syncBigQuery`, `initBigQuerySync` and `setupBigQuerySync`, the extension's 1st gen task-function timeout, instead of the 2nd gen default of 60s. `fsexportbigquery` keeps 60s, which the deployed trigger ran at.
|
|
3
5
|
- fix: set every function's `cpu` to `"gcf_gen1"` (0.1666 vCPU), the extension's allocation, instead of the 1 vCPU that the 2nd gen default resolves to at 256MiB.
|
|
4
6
|
- fix: set every function's concurrency to `1`, and `fsexportbigquery` ingress to `ALLOW_INTERNAL_ONLY`, matching the extension. Previously, the kit inherited the 2nd gen defaults of concurrency `80` and ingress `ALLOW_ALL`. The task-queue functions `syncBigQuery`, `initBigQuerySync` and `setupBigQuerySync` declare no `ingressSettings`, so they inherit the default `ALLOW_ALL`, or whatever `setGlobalOptions({ ingressSettings })` sets; the deployed extension's task-queue functions ran with open ingress, and the `initBigQuerySync` HTTP POST needs it. At concurrency `1` a function serves as many requests at once as it has instances: the Cloud Run default of 100, unless your codebase sets `setGlobalOptions({ maxInstances })`.
|
|
5
|
-
- fix: an Eventarc publish failure no longer fails the function. A channel that was deleted or is unreachable answers `PERMISSION_DENIED`, and the publish was awaited before the work the function exists to do, so the document change was never exported. The publish failure is now logged as a warning and the invocation continues. Deploys also
|
|
7
|
+
- fix: an Eventarc publish failure no longer fails the function. A channel that was deleted or is unreachable answers `PERMISSION_DENIED`, and the publish was awaited before the work the function exists to do, so the document change was never exported. The publish failure is now logged as a warning and the invocation continues. Deploys also declared `eventarcpublishing.googleapis.com` unconditionally; the entry above makes that conditional on `EVENTARC_CHANNEL`.
|
|
6
8
|
|
|
7
9
|
- docs: the no-region fallback needs an explicit empty `DATABASE_REGION=` line in `.env`. Omitting the key entirely fails a non-interactive deploy, because the CLI resolves parameters before it reads their defaults. Corrects the note on the `DATABASE_REGION` placement fix below; no behavior change.
|
|
8
10
|
- fix: `USE_NEW_SNAPSHOT_QUERY_SYNTAX` and `EXCLUDE_OLD_DATA` take the extension's `yes` / `no` values again, so a config exported from the extension works unchanged. `WILDCARD_IDS` is unchanged: the extension already used `true` / `false` there.
|
package/README.md
CHANGED
|
@@ -31,20 +31,36 @@ conflicts with that automatic setup.
|
|
|
31
31
|
| `roles/datastore.user` | write failed-row records back to Firestore (only if you configure a backup collection) |
|
|
32
32
|
| `roles/eventarc.eventReceiver` | receive Gen2 Firestore trigger events |
|
|
33
33
|
| `roles/run.invoker` | allow Eventarc to invoke the Gen2 Cloud Run service, and Cloud Tasks to dispatch to the three task-queue functions, which have no function-level invoker binding |
|
|
34
|
-
| `roles/eventarc.publisher` | publish the kit's custom Eventarc events (the Extensions platform granted this implicitly) |
|
|
35
34
|
| `roles/cloudtasks.enqueuer` | enqueue failed writes onto the kit's own `syncBigQuery` task queue |
|
|
35
|
+
| `firestore.googleapis.com` | receive document change events from Cloud Firestore |
|
|
36
36
|
| `bigquery.googleapis.com` | mirror Firestore collection changes in BigQuery |
|
|
37
37
|
|
|
38
|
+
Only when `EVENTARC_CHANNEL` is set in `.env` (see Events), the deploy also
|
|
39
|
+
declares `roles/eventarc.publisher` and `eventarcpublishing.googleapis.com`,
|
|
40
|
+
which the Extensions platform granted implicitly to installs that opted into
|
|
41
|
+
events. A default install declares neither, so nothing prompts you to enable
|
|
42
|
+
the Eventarc Publishing API.
|
|
43
|
+
|
|
38
44
|
If the dataset lives in a different project (`BIGQUERY_PROJECT_ID`), grant the
|
|
39
45
|
managed runtime service account the `bigquery.*` roles on that project. For a
|
|
40
46
|
CMEK dataset, also grant the BigQuery service account access to your KMS key.
|
|
41
47
|
|
|
42
48
|
## Usage
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
Spread the kit's `defaultOptions` into your codebase's single
|
|
51
|
+
`setGlobalOptions` call, then export the four functions from your functions
|
|
52
|
+
codebase entry. `setGlobalOptions` must run before the kit module loads,
|
|
53
|
+
because the kit reads the global options when it defines its functions. A
|
|
54
|
+
TypeScript entry compiled to CommonJS runs its statements in order, so this
|
|
55
|
+
works:
|
|
45
56
|
|
|
46
57
|
```ts
|
|
47
58
|
// functions/src/index.ts
|
|
59
|
+
import { setGlobalOptions } from "firebase-functions";
|
|
60
|
+
import { defaultOptions } from "@firebase-function-kits/firestore-bigquery-export/default-options";
|
|
61
|
+
|
|
62
|
+
setGlobalOptions({ ...defaultOptions });
|
|
63
|
+
|
|
48
64
|
export {
|
|
49
65
|
fsexportbigquery,
|
|
50
66
|
syncBigQuery,
|
|
@@ -53,6 +69,29 @@ export {
|
|
|
53
69
|
} from "@firebase-function-kits/firestore-bigquery-export";
|
|
54
70
|
```
|
|
55
71
|
|
|
72
|
+
In an ES module entry (`"type": "module"`, or TypeScript emitting ES modules),
|
|
73
|
+
Node loads every `import` and `export ... from` before any statement in the
|
|
74
|
+
file runs, so the kit loads before `setGlobalOptions` and your functions
|
|
75
|
+
deploy at 1 vCPU and concurrency `80`. Call `setGlobalOptions` in its
|
|
76
|
+
own module and import that module first:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
// functions/options.js
|
|
80
|
+
import { setGlobalOptions } from "firebase-functions";
|
|
81
|
+
import { defaultOptions } from "@firebase-function-kits/firestore-bigquery-export/default-options";
|
|
82
|
+
|
|
83
|
+
setGlobalOptions({ ...defaultOptions });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
// functions/index.js
|
|
88
|
+
import "./options.js";
|
|
89
|
+
export * from "@firebase-function-kits/firestore-bigquery-export";
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
If the global options set no `cpu` when the kit loads, deploy logs a warning
|
|
93
|
+
that `defaultOptions` was not applied.
|
|
94
|
+
|
|
56
95
|
and configure them with a `.env` (or `.env.<projectId>`):
|
|
57
96
|
|
|
58
97
|
```sh
|
|
@@ -173,7 +212,19 @@ the instances cannot collide.
|
|
|
173
212
|
When `EVENTARC_CHANNEL` is configured, the functions publish lifecycle events:
|
|
174
213
|
`onStart` and `onError` from the write path, and `onSuccess` from the
|
|
175
214
|
`syncBigQuery` task when a buffered write lands (matching the extension, which
|
|
176
|
-
only emitted `onSuccess` from its queue handler).
|
|
215
|
+
only emitted `onSuccess` from its queue handler). A blank value is the same as
|
|
216
|
+
an unset one: no channel is opened and nothing is published.
|
|
217
|
+
|
|
218
|
+
Setting `EVENTARC_CHANNEL` also makes the deploy declare
|
|
219
|
+
`eventarcpublishing.googleapis.com` and `roles/eventarc.publisher`: the CLI
|
|
220
|
+
grants the role and prompts to enable the API, and declining that prompt
|
|
221
|
+
aborts the deploy. That needs firebase-tools 15.28.0 or later, which loads
|
|
222
|
+
`.env` during deploy discovery; on an older CLI the declarations are skipped
|
|
223
|
+
and every publish fails with `PERMISSION_DENIED`, logged as a warning while
|
|
224
|
+
the export itself continues. The API and role summary printed by
|
|
225
|
+
`firebase functions:kits:install` and `firebase ext:migrate` runs discovery
|
|
226
|
+
without your `.env`, so it does not list either even when `ext:migrate` has
|
|
227
|
+
just written `EVENTARC_CHANNEL`; the deploy declares them regardless.
|
|
177
228
|
|
|
178
229
|
Each event is published twice, exactly as the extension published it: once
|
|
179
230
|
under `firebase.extensions.firestore-bigquery-export.v1.*` and once under
|
|
@@ -566,12 +617,46 @@ documents missed during a migration.
|
|
|
566
617
|
|
|
567
618
|
### Concurrency, CPU and timeouts match the extension
|
|
568
619
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
invocation at a time
|
|
574
|
-
|
|
620
|
+
The kit exports `defaultOptions` from
|
|
621
|
+
`@firebase-function-kits/firestore-bigquery-export/default-options`:
|
|
622
|
+
`cpu: "gcf_gen1"`, `concurrency: 1` and `maxInstances: 100`. The extension
|
|
623
|
+
deployed every function at 0.1666 vCPU with an instance handling one
|
|
624
|
+
invocation at a time. `maxInstances: 100` matches the extension's Firestore
|
|
625
|
+
trigger, a 2nd gen function that ran at the platform default of 100
|
|
626
|
+
instances; the extension's task-queue functions were 1st gen functions with no
|
|
627
|
+
declared cap. The 2nd gen defaults would be concurrency `80` and 1 vCPU at
|
|
628
|
+
256MiB. The module has no side effects, so you can import it before
|
|
629
|
+
`setGlobalOptions` runs.
|
|
630
|
+
|
|
631
|
+
Firebase Functions applies options in this order, field by field:
|
|
632
|
+
|
|
633
|
+
1. The object you pass to `setGlobalOptions`. Spread `defaultOptions` first
|
|
634
|
+
and put your own keys after it, so your keys win:
|
|
635
|
+
`setGlobalOptions({ ...defaultOptions, region: "europe-west1", maxInstances: 20 })`.
|
|
636
|
+
A key you set to `undefined` also wins: `maxInstances: undefined` removes
|
|
637
|
+
the default cap instead of keeping it.
|
|
638
|
+
2. The options each function declares, which override the globals. The kit
|
|
639
|
+
declares only `ingressSettings` on `fsexportbigquery`, `timeoutSeconds` and
|
|
640
|
+
`retryConfig` on the task-queue functions, `maxInstances` and `rateLimits`
|
|
641
|
+
on `syncBigQuery`, and `region` from `DATABASE_REGION`.
|
|
642
|
+
|
|
643
|
+
A codebase calls `setGlobalOptions` once; a second call replaces the first
|
|
644
|
+
instead of merging with it. For that reason the kit does not call it. If you
|
|
645
|
+
write your own entry file and do not spread `defaultOptions`, or your ES
|
|
646
|
+
module entry loads the kit before `setGlobalOptions` runs (see
|
|
647
|
+
[Usage](#usage)), every function falls back to the 2nd gen defaults: 1 vCPU at
|
|
648
|
+
256MiB, concurrency `80` and no instance cap from the kit. You lose CPU parity
|
|
649
|
+
with the extension.
|
|
650
|
+
|
|
651
|
+
`concurrency` above `1` needs `cpu` of `1` or more. To raise concurrency,
|
|
652
|
+
override both keys:
|
|
653
|
+
`setGlobalOptions({ ...defaultOptions, cpu: 1, concurrency: 80 })`.
|
|
654
|
+
|
|
655
|
+
`fsexportbigquery` sets `ingressSettings: "ALLOW_INTERNAL_ONLY"`, so only
|
|
656
|
+
internal traffic reaches the Firestore trigger, as with the extension. This
|
|
657
|
+
option is not in `defaultOptions`: as a global it would also apply to the
|
|
658
|
+
task-queue functions and stop Cloud Tasks from invoking them. The task-queue
|
|
659
|
+
functions `syncBigQuery`, `initBigQuerySync` and
|
|
575
660
|
`setupBigQuerySync` set `timeoutSeconds: 540`, the extension's 1st gen task
|
|
576
661
|
timeout; `fsexportbigquery` keeps the 60 second default, which the deployed
|
|
577
662
|
trigger ran at.
|
|
@@ -584,20 +669,21 @@ functions ran with open ingress, and the `curl` into `initBigQuerySync` under
|
|
|
584
669
|
globally makes that request fail.
|
|
585
670
|
|
|
586
671
|
At concurrency `1`, a function serves as many requests at once as it has
|
|
587
|
-
instances. `fsexportbigquery`, `initBigQuerySync` and `setupBigQuerySync`
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
672
|
+
instances. `fsexportbigquery`, `initBigQuerySync` and `setupBigQuerySync` take
|
|
673
|
+
the `maxInstances: 100` from `defaultOptions` unless you override it after the
|
|
674
|
+
spread; the two lifecycle tasks receive one task per deploy, so the cap does
|
|
675
|
+
not matter for them. The trigger therefore handles 100
|
|
591
676
|
events at once, the same as the deployed extension trigger (100 instances,
|
|
592
677
|
concurrency `1`, no retry policy). An event above that ceiling waits up to
|
|
593
678
|
about 10 seconds for a free instance and is then refused before the handler
|
|
594
679
|
runs: no error log, no `onError` event, no enqueue and no backup row. Whether
|
|
595
680
|
Eventarc redelivers a refused push under the trigger's
|
|
596
|
-
`RETRY_POLICY_DO_NOT_RETRY` is not verified.
|
|
597
|
-
`
|
|
681
|
+
`RETRY_POLICY_DO_NOT_RETRY` is not verified. Set a higher `maxInstances` after
|
|
682
|
+
the `defaultOptions` spread to lift the ceiling.
|
|
598
683
|
|
|
599
684
|
`syncBigQuery` sets `maxInstances: 500` to match its `maxConcurrentDispatches`
|
|
600
|
-
limit
|
|
685
|
+
limit. A global `maxInstances`, from `defaultOptions` or from your own keys,
|
|
686
|
+
does not change it, because the per-function value wins: Cloud Tasks may
|
|
601
687
|
dispatch 500 tasks at once, and 100 instances would take only 100 of them. A
|
|
602
688
|
dispatch above the instance ceiling waits for a free instance for up to about
|
|
603
689
|
10 seconds, then gets a Cloud Run 429. Cloud Tasks counts that as a failed
|
|
@@ -636,6 +722,10 @@ services in the region.
|
|
|
636
722
|
yourself, plus the config types and helpers (`ExportConfig`,
|
|
637
723
|
`resolveExportConfig`, `toTrackerConfig`, `SerializedDocumentChange`) for
|
|
638
724
|
building their injected `HandlerContext`. Safe to import anywhere.
|
|
725
|
+
- **Default options entry** (`./default-options`): `defaultOptions`, the
|
|
726
|
+
global options to spread into your `setGlobalOptions` call (see
|
|
727
|
+
[Concurrency, CPU and timeouts](#concurrency-cpu-and-timeouts-match-the-extension)).
|
|
728
|
+
Safe to import anywhere.
|
|
639
729
|
|
|
640
730
|
The change-tracker engine is an internal dependency and is not exported.
|
|
641
731
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global options that reproduce the extension's runtime shape: one request per
|
|
3
|
+
* 0.1666 vCPU instance, up to 100 instances. Spread into your codebase's single
|
|
4
|
+
* `setGlobalOptions` call, before your own keys so they override these:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* setGlobalOptions({ ...defaultOptions, region: "europe-west1" });
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Importing this module has no side effects, so it is safe to import before
|
|
11
|
+
* `setGlobalOptions` runs.
|
|
12
|
+
*/
|
|
13
|
+
export declare const defaultOptions: {
|
|
14
|
+
readonly cpu: "gcf_gen1";
|
|
15
|
+
readonly concurrency: 1;
|
|
16
|
+
readonly maxInstances: 100;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=default-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-options.d.ts","sourceRoot":"","sources":["../src/default-options.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc;;;;CAIO,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.defaultOptions = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* Global options that reproduce the extension's runtime shape: one request per
|
|
21
|
+
* 0.1666 vCPU instance, up to 100 instances. Spread into your codebase's single
|
|
22
|
+
* `setGlobalOptions` call, before your own keys so they override these:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* setGlobalOptions({ ...defaultOptions, region: "europe-west1" });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Importing this module has no side effects, so it is safe to import before
|
|
29
|
+
* `setGlobalOptions` runs.
|
|
30
|
+
*/
|
|
31
|
+
exports.defaultOptions = {
|
|
32
|
+
cpu: "gcf_gen1",
|
|
33
|
+
concurrency: 1,
|
|
34
|
+
maxInstances: 100,
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=default-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-options.js","sourceRoot":"","sources":["../src/default-options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH;;;;;;;;;;;GAWG;AACU,QAAA,cAAc,GAAG;IAC5B,GAAG,EAAE,UAAU;IACf,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,GAAG;CACe,CAAC"}
|
package/lib/events.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
3
|
+
* variable is unset or blank, which disables event publishing.
|
|
4
|
+
*/
|
|
5
|
+
export declare const configuredEventChannel: () => string | undefined;
|
|
1
6
|
/**
|
|
2
7
|
* Sets up the Eventarc channel.
|
|
3
8
|
*
|
package/lib/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAoCA;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAoCA;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAAO,MAAM,GAAG,SACA,CAAC;AAEpD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAO7B,CAAC;AAkBF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAU,MAAM,MAAM,GAAG,MAAM,kBAY3D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,KAAK,KAAK,EAAE,UAAU,MAAM,kBAalE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAU,oBAGtC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,kBAaA,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAU,MAAM,MAAM,GAAG,MAAM,kBAYhE,CAAC"}
|
package/lib/events.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.recordCompletionEvent = exports.recordSuccessEvent = exports.recordErrorEvent = exports.recordStartEvent = exports.setupEventChannel = void 0;
|
|
36
|
+
exports.recordCompletionEvent = exports.recordSuccessEvent = exports.recordErrorEvent = exports.recordStartEvent = exports.setupEventChannel = exports.configuredEventChannel = void 0;
|
|
37
37
|
/*
|
|
38
38
|
* Copyright 2019 Google LLC
|
|
39
39
|
*
|
|
@@ -66,6 +66,12 @@ const getEventTypes = (eventName) => [
|
|
|
66
66
|
`firebase.extensions.firestore-bigquery-export.v1.${eventName}`, // NEW Event Type following the updated convention
|
|
67
67
|
];
|
|
68
68
|
let eventChannel;
|
|
69
|
+
/**
|
|
70
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
71
|
+
* variable is unset or blank, which disables event publishing.
|
|
72
|
+
*/
|
|
73
|
+
const configuredEventChannel = () => process.env.EVENTARC_CHANNEL?.trim() || undefined;
|
|
74
|
+
exports.configuredEventChannel = configuredEventChannel;
|
|
69
75
|
/**
|
|
70
76
|
* Sets up the Eventarc channel.
|
|
71
77
|
*
|
|
@@ -76,8 +82,9 @@ let eventChannel;
|
|
|
76
82
|
* @function setupEventChannel
|
|
77
83
|
*/
|
|
78
84
|
const setupEventChannel = () => {
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
const channel = (0, exports.configuredEventChannel)();
|
|
86
|
+
eventChannel = channel
|
|
87
|
+
? getEventarc().channel(channel, {
|
|
81
88
|
allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
|
|
82
89
|
})
|
|
83
90
|
: undefined;
|
package/lib/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,kEAAoD;AACpD,2DAA4C;AAE5C,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC;IAC3C,4CAA4C,SAAS,EAAE,EAAE,4CAA4C;IACrG,oDAAoD,SAAS,EAAE,EAAE,kDAAkD;CACpH,CAAC;AAEF,IAAI,YAA0C,CAAC;AAE/C;;;;;;;;GAQG;AACI,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACtB,OAAO,CAAC;QACN,IAAI;QACJ,IAAI;KACL,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,qBAAqB,yBAYhC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Warning logged when deploy discovery loads the kit before `defaultOptions` reached `setGlobalOptions`. */
|
|
2
|
+
export declare const DEFAULT_OPTIONS_MISSING_WARNING: string;
|
|
3
|
+
/**
|
|
4
|
+
* Logs {@link DEFAULT_OPTIONS_MISSING_WARNING} during deploy discovery when the
|
|
5
|
+
* codebase's global options set no `cpu`, which means `defaultOptions` was not
|
|
6
|
+
* applied before the kit's functions were defined.
|
|
7
|
+
*/
|
|
8
|
+
export declare function warnIfDefaultOptionsMissing(): void;
|
|
9
|
+
//# sourceMappingURL=global-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-options.d.ts","sourceRoot":"","sources":["../src/global-options.ts"],"names":[],"mappings":"AAyBA,6GAA6G;AAC7G,eAAO,MAAM,+BAA+B,QAMwF,CAAC;AAErI;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,IAAI,CAQlD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.DEFAULT_OPTIONS_MISSING_WARNING = void 0;
|
|
52
|
+
exports.warnIfDefaultOptionsMissing = warnIfDefaultOptionsMissing;
|
|
53
|
+
const logger_1 = require("firebase-functions/logger");
|
|
54
|
+
const functionsOptions = __importStar(require("firebase-functions/options"));
|
|
55
|
+
/** `getGlobalOptions` ships at runtime but is marked internal, so it is absent from the typings. */
|
|
56
|
+
const { getGlobalOptions } = functionsOptions;
|
|
57
|
+
/** Warning logged when deploy discovery loads the kit before `defaultOptions` reached `setGlobalOptions`. */
|
|
58
|
+
exports.DEFAULT_OPTIONS_MISSING_WARNING = "firestore-bigquery-export: no global cpu was set when the kit loaded, so its functions " +
|
|
59
|
+
"deploy at the 2nd gen defaults (1 vCPU, concurrency 80) instead of the extension's 0.1666 vCPU. " +
|
|
60
|
+
"Spread defaultOptions from @firebase-function-kits/firestore-bigquery-export/default-options " +
|
|
61
|
+
"into setGlobalOptions before the kit is imported. In an ES module entry, call setGlobalOptions " +
|
|
62
|
+
"in its own module and import that module first. See " +
|
|
63
|
+
"https://github.com/firebase/extensions/tree/kits/kits/firestore-bigquery-export#concurrency-cpu-and-timeouts-match-the-extension";
|
|
64
|
+
/**
|
|
65
|
+
* Logs {@link DEFAULT_OPTIONS_MISSING_WARNING} during deploy discovery when the
|
|
66
|
+
* codebase's global options set no `cpu`, which means `defaultOptions` was not
|
|
67
|
+
* applied before the kit's functions were defined.
|
|
68
|
+
*/
|
|
69
|
+
function warnIfDefaultOptionsMissing() {
|
|
70
|
+
// The Firebase CLI sets FUNCTIONS_CONTROL_API only in the discovery process.
|
|
71
|
+
if (process.env.FUNCTIONS_CONTROL_API !== "true" || !getGlobalOptions) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (getGlobalOptions().cpu === undefined) {
|
|
75
|
+
(0, logger_1.warn)(exports.DEFAULT_OPTIONS_MISSING_WARNING);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=global-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-options.js","sourceRoot":"","sources":["../src/global-options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,kEAQC;AA/BD,sDAAiD;AACjD,6EAA+D;AAG/D,oGAAoG;AACpG,MAAM,EAAE,gBAAgB,EAAE,GAAG,gBAE5B,CAAC;AAEF,6GAA6G;AAChG,QAAA,+BAA+B,GAC1C,yFAAyF;IACzF,kGAAkG;IAClG,+FAA+F;IAC/F,iGAAiG;IACjG,sDAAsD;IACtD,kIAAkI,CAAC;AAErI;;;;GAIG;AACH,SAAgB,2BAA2B;IACzC,6EAA6E;IAC7E,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtE,OAAO;IACT,CAAC;IACD,IAAI,gBAAgB,EAAE,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACzC,IAAA,aAAI,EAAC,uCAA+B,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmDA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmDA,OAAO,EAEL,KAAK,wBAAwB,EAG9B,MAAM,YAAY,CAAC;AAUpB,cAAc,OAAO,CAAC;AAgItB;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,wOAO5B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,gFAiBxB,CAAC;AAWF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,2DAG5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2DAG7B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -75,11 +75,13 @@ const config_1 = require("./config");
|
|
|
75
75
|
const events = __importStar(require("./events"));
|
|
76
76
|
const export_config_1 = require("./export-config");
|
|
77
77
|
const handlers_1 = require("./handlers");
|
|
78
|
+
const global_options_1 = require("./global-options");
|
|
78
79
|
const init_1 = require("./init");
|
|
79
80
|
const logs = __importStar(require("./logs"));
|
|
80
81
|
const region_1 = require("./region");
|
|
81
82
|
const tasks_2 = require("./tasks");
|
|
82
83
|
(0, config_1.assertRequiredParams)();
|
|
84
|
+
(0, global_options_1.warnIfDefaultOptionsMissing)();
|
|
83
85
|
// Re-export the side-effect-free library surface (handlers and config types).
|
|
84
86
|
__exportStar(require("./lib"), exports);
|
|
85
87
|
const INIT_BIGQUERY_SYNC_FUNCTION = "initBigQuerySync";
|
|
@@ -100,11 +102,6 @@ const REQUIRED_ROLES = [
|
|
|
100
102
|
// Gen2 Firestore triggers need Eventarc receive and run.invoker on the function SA.
|
|
101
103
|
"roles/eventarc.eventReceiver",
|
|
102
104
|
"roles/run.invoker",
|
|
103
|
-
// The Extensions platform granted publish rights on the extension's Eventarc
|
|
104
|
-
// channel implicitly from `events:` in extension.yaml. Kits get no implicit
|
|
105
|
-
// grant, so without this the `channel.publish()` calls in ./events fail with
|
|
106
|
-
// PERMISSION_DENIED and no custom event is ever delivered.
|
|
107
|
-
"roles/eventarc.publisher",
|
|
108
105
|
// The trigger enqueues failed writes onto its own syncBigQuery task queue.
|
|
109
106
|
"roles/cloudtasks.enqueuer",
|
|
110
107
|
];
|
|
@@ -117,10 +114,6 @@ const REQUIRED_APIS = [
|
|
|
117
114
|
api: "bigquery.googleapis.com",
|
|
118
115
|
reason: "Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
119
116
|
},
|
|
120
|
-
{
|
|
121
|
-
api: "eventarcpublishing.googleapis.com",
|
|
122
|
-
reason: "Publishes the extension's custom events to its Eventarc channel.",
|
|
123
|
-
},
|
|
124
117
|
];
|
|
125
118
|
for (const role of REQUIRED_ROLES) {
|
|
126
119
|
(0, v2_1.requiresRole)(role);
|
|
@@ -128,6 +121,11 @@ for (const role of REQUIRED_ROLES) {
|
|
|
128
121
|
for (const { api, reason } of REQUIRED_APIS) {
|
|
129
122
|
(0, v2_1.requiresAPI)(api, reason);
|
|
130
123
|
}
|
|
124
|
+
// Declining a `requiresAPI` prompt aborts the deploy, and nothing publishes without a channel.
|
|
125
|
+
if (events.configuredEventChannel()) {
|
|
126
|
+
(0, v2_1.requiresRole)("roles/eventarc.publisher");
|
|
127
|
+
(0, v2_1.requiresAPI)("eventarcpublishing.googleapis.com", "Publishes the extension's custom events to its Eventarc channel.");
|
|
128
|
+
}
|
|
131
129
|
(0, lifecycle_1.afterFirstDeploy)({
|
|
132
130
|
task: { function: INIT_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
133
131
|
});
|
|
@@ -170,18 +168,14 @@ const functionRegion = (0, region_1.firestoreLocationToFunctionRegion)(process.e
|
|
|
170
168
|
const REGION_OPTION = functionRegion
|
|
171
169
|
? { region: functionRegion }
|
|
172
170
|
: {};
|
|
173
|
-
/**
|
|
171
|
+
/** Trigger ingress; as a global it would stop Cloud Tasks from invoking the task functions. */
|
|
174
172
|
const EVENT_FUNCTION_OPTIONS = {
|
|
175
173
|
...REGION_OPTION,
|
|
176
|
-
concurrency: 1,
|
|
177
|
-
cpu: "gcf_gen1",
|
|
178
174
|
ingressSettings: "ALLOW_INTERNAL_ONLY",
|
|
179
175
|
};
|
|
180
|
-
/** Options shared by the task-queue functions
|
|
176
|
+
/** Options shared by the task-queue functions: the extension's 1st gen task timeout. */
|
|
181
177
|
const TASK_FUNCTION_OPTIONS = {
|
|
182
178
|
...REGION_OPTION,
|
|
183
|
-
concurrency: 1,
|
|
184
|
-
cpu: "gcf_gen1",
|
|
185
179
|
timeoutSeconds: 540,
|
|
186
180
|
};
|
|
187
181
|
/** Options of the two lifecycle tasks, which share one retry config. */
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;;;;;;;GAWG;AAEH,6GAA6G;AAC7G,4CAA4D;AAC5D,4DAAiE;AACjE,sDAAiD;AACjD,oDAA4D;AAE5D,8CAAkE;AAClE,+DAGyC;AACzC,qCAIkB;AAClB,iDAAmC;AACnC,mDAIyB;AACzB,yCAKoB;AACpB,iCAAiD;AACjD,6CAA+B;AAC/B,qCAA6D;AAC7D,mCAA0C;AAE1C,IAAA,6BAAoB,GAAE,CAAC;AACvB,8EAA8E;AAC9E,wCAAsB;AAEtB,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AACvD,MAAM,4BAA4B,GAAG,mBAAmB,CAAC;AACzD,MAAM,sBAAsB,GAAG;IAC7B,WAAW,EAAE,EAAE;IACf,iBAAiB,EAAE,EAAE;CACb,CAAC;AACX,MAAM,iBAAiB,GAAG;IACxB,WAAW,EAAE,CAAC;IACd,iBAAiB,EAAE,EAAE;CACb,CAAC;AACX,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAC3C,MAAM,cAAc,GAAwB;IAC1C,2BAA2B;IAC3B,sBAAsB;IACtB,qBAAqB;IACrB,oFAAoF;IACpF,8BAA8B;IAC9B,mBAAmB;IACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;;;;;;;;;;GAWG;AAEH,6GAA6G;AAC7G,4CAA4D;AAC5D,4DAAiE;AACjE,sDAAiD;AACjD,oDAA4D;AAE5D,8CAAkE;AAClE,+DAGyC;AACzC,qCAIkB;AAClB,iDAAmC;AACnC,mDAIyB;AACzB,yCAKoB;AACpB,qDAA+D;AAC/D,iCAAiD;AACjD,6CAA+B;AAC/B,qCAA6D;AAC7D,mCAA0C;AA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CAAC,KAAK,EAAE,yCAAyC,EAAE,GAAG,CAAC,CAAC;QAClE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG,IAAA,wBAAgB,EAC9C,sBAAsB,EACtB,gCAAgC,CACjC,CAAC;AAEF;;;GAGG;AACU,QAAA,iBAAiB,GAAG,IAAA,wBAAgB,EAC/C,sBAAsB,EACtB,gCAAgC,CACjC,CAAC"}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
3
|
-
"version": "0.0.2-rc.
|
|
3
|
+
"version": "0.0.2-rc.16",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
9
|
-
"version": "0.0.2-rc.
|
|
9
|
+
"version": "0.0.2-rc.16",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@firebaseextensions/firestore-bigquery-change-tracker": "^2.2.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firebase-function-kits/firestore-bigquery-export",
|
|
3
|
-
"version": "0.0.2-rc.
|
|
3
|
+
"version": "0.0.2-rc.16",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/firebase/extensions.git",
|
|
@@ -18,6 +18,20 @@
|
|
|
18
18
|
"./lib": {
|
|
19
19
|
"types": "./lib/lib.d.ts",
|
|
20
20
|
"default": "./lib/lib.js"
|
|
21
|
+
},
|
|
22
|
+
"./default-options": {
|
|
23
|
+
"types": "./lib/default-options.d.ts",
|
|
24
|
+
"default": "./lib/default-options.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
"default-options": [
|
|
30
|
+
"lib/default-options.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"lib": [
|
|
33
|
+
"lib/lib.d.ts"
|
|
34
|
+
]
|
|
21
35
|
}
|
|
22
36
|
},
|
|
23
37
|
"engines": {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { GlobalOptions } from "firebase-functions/options";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Global options that reproduce the extension's runtime shape: one request per
|
|
21
|
+
* 0.1666 vCPU instance, up to 100 instances. Spread into your codebase's single
|
|
22
|
+
* `setGlobalOptions` call, before your own keys so they override these:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* setGlobalOptions({ ...defaultOptions, region: "europe-west1" });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Importing this module has no side effects, so it is safe to import before
|
|
29
|
+
* `setGlobalOptions` runs.
|
|
30
|
+
*/
|
|
31
|
+
export const defaultOptions = {
|
|
32
|
+
cpu: "gcf_gen1",
|
|
33
|
+
concurrency: 1,
|
|
34
|
+
maxInstances: 100,
|
|
35
|
+
} as const satisfies GlobalOptions;
|
package/src/events.ts
CHANGED
|
@@ -34,6 +34,13 @@ const getEventTypes = (eventName: string) => [
|
|
|
34
34
|
|
|
35
35
|
let eventChannel: eventArc.Channel | undefined;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* The Eventarc channel named by `EVENTARC_CHANNEL`, or `undefined` when the
|
|
39
|
+
* variable is unset or blank, which disables event publishing.
|
|
40
|
+
*/
|
|
41
|
+
export const configuredEventChannel = (): string | undefined =>
|
|
42
|
+
process.env.EVENTARC_CHANNEL?.trim() || undefined;
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Sets up the Eventarc channel.
|
|
39
46
|
*
|
|
@@ -44,8 +51,9 @@ let eventChannel: eventArc.Channel | undefined;
|
|
|
44
51
|
* @function setupEventChannel
|
|
45
52
|
*/
|
|
46
53
|
export const setupEventChannel = () => {
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
const channel = configuredEventChannel();
|
|
55
|
+
eventChannel = channel
|
|
56
|
+
? getEventarc().channel(channel, {
|
|
49
57
|
allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
|
|
50
58
|
})
|
|
51
59
|
: undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { warn } from "firebase-functions/logger";
|
|
18
|
+
import * as functionsOptions from "firebase-functions/options";
|
|
19
|
+
import type { GlobalOptions } from "firebase-functions/options";
|
|
20
|
+
|
|
21
|
+
/** `getGlobalOptions` ships at runtime but is marked internal, so it is absent from the typings. */
|
|
22
|
+
const { getGlobalOptions } = functionsOptions as typeof functionsOptions & {
|
|
23
|
+
getGlobalOptions?: () => GlobalOptions;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Warning logged when deploy discovery loads the kit before `defaultOptions` reached `setGlobalOptions`. */
|
|
27
|
+
export const DEFAULT_OPTIONS_MISSING_WARNING =
|
|
28
|
+
"firestore-bigquery-export: no global cpu was set when the kit loaded, so its functions " +
|
|
29
|
+
"deploy at the 2nd gen defaults (1 vCPU, concurrency 80) instead of the extension's 0.1666 vCPU. " +
|
|
30
|
+
"Spread defaultOptions from @firebase-function-kits/firestore-bigquery-export/default-options " +
|
|
31
|
+
"into setGlobalOptions before the kit is imported. In an ES module entry, call setGlobalOptions " +
|
|
32
|
+
"in its own module and import that module first. See " +
|
|
33
|
+
"https://github.com/firebase/extensions/tree/kits/kits/firestore-bigquery-export#concurrency-cpu-and-timeouts-match-the-extension";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Logs {@link DEFAULT_OPTIONS_MISSING_WARNING} during deploy discovery when the
|
|
37
|
+
* codebase's global options set no `cpu`, which means `defaultOptions` was not
|
|
38
|
+
* applied before the kit's functions were defined.
|
|
39
|
+
*/
|
|
40
|
+
export function warnIfDefaultOptionsMissing(): void {
|
|
41
|
+
// The Firebase CLI sets FUNCTIONS_CONTROL_API only in the discovery process.
|
|
42
|
+
if (process.env.FUNCTIONS_CONTROL_API !== "true" || !getGlobalOptions) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (getGlobalOptions().cpu === undefined) {
|
|
46
|
+
warn(DEFAULT_OPTIONS_MISSING_WARNING);
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -55,12 +55,14 @@ import {
|
|
|
55
55
|
handleDocumentWrite,
|
|
56
56
|
handleSyncBigQueryTask,
|
|
57
57
|
} from "./handlers";
|
|
58
|
+
import { warnIfDefaultOptionsMissing } from "./global-options";
|
|
58
59
|
import { createEnsureInitialized } from "./init";
|
|
59
60
|
import * as logs from "./logs";
|
|
60
61
|
import { firestoreLocationToFunctionRegion } from "./region";
|
|
61
62
|
import { enqueueSyncTask } from "./tasks";
|
|
62
63
|
|
|
63
64
|
assertRequiredParams();
|
|
65
|
+
warnIfDefaultOptionsMissing();
|
|
64
66
|
// Re-export the side-effect-free library surface (handlers and config types).
|
|
65
67
|
export * from "./lib";
|
|
66
68
|
|
|
@@ -82,11 +84,6 @@ const REQUIRED_ROLES: ReadonlyArray<Role> = [
|
|
|
82
84
|
// Gen2 Firestore triggers need Eventarc receive and run.invoker on the function SA.
|
|
83
85
|
"roles/eventarc.eventReceiver",
|
|
84
86
|
"roles/run.invoker",
|
|
85
|
-
// The Extensions platform granted publish rights on the extension's Eventarc
|
|
86
|
-
// channel implicitly from `events:` in extension.yaml. Kits get no implicit
|
|
87
|
-
// grant, so without this the `channel.publish()` calls in ./events fail with
|
|
88
|
-
// PERMISSION_DENIED and no custom event is ever delivered.
|
|
89
|
-
"roles/eventarc.publisher",
|
|
90
87
|
// The trigger enqueues failed writes onto its own syncBigQuery task queue.
|
|
91
88
|
"roles/cloudtasks.enqueuer",
|
|
92
89
|
];
|
|
@@ -99,10 +96,6 @@ const REQUIRED_APIS = [
|
|
|
99
96
|
api: "bigquery.googleapis.com",
|
|
100
97
|
reason: "Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
101
98
|
},
|
|
102
|
-
{
|
|
103
|
-
api: "eventarcpublishing.googleapis.com",
|
|
104
|
-
reason: "Publishes the extension's custom events to its Eventarc channel.",
|
|
105
|
-
},
|
|
106
99
|
] as const;
|
|
107
100
|
|
|
108
101
|
for (const role of REQUIRED_ROLES) {
|
|
@@ -113,6 +106,15 @@ for (const { api, reason } of REQUIRED_APIS) {
|
|
|
113
106
|
requiresAPI(api, reason);
|
|
114
107
|
}
|
|
115
108
|
|
|
109
|
+
// Declining a `requiresAPI` prompt aborts the deploy, and nothing publishes without a channel.
|
|
110
|
+
if (events.configuredEventChannel()) {
|
|
111
|
+
requiresRole("roles/eventarc.publisher");
|
|
112
|
+
requiresAPI(
|
|
113
|
+
"eventarcpublishing.googleapis.com",
|
|
114
|
+
"Publishes the extension's custom events to its Eventarc channel."
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
116
118
|
afterFirstDeploy({
|
|
117
119
|
task: { function: INIT_BIGQUERY_SYNC_FUNCTION, body: { data: {} } },
|
|
118
120
|
});
|
|
@@ -172,19 +174,15 @@ const REGION_OPTION = functionRegion
|
|
|
172
174
|
? ({ region: functionRegion } as const)
|
|
173
175
|
: {};
|
|
174
176
|
|
|
175
|
-
/**
|
|
177
|
+
/** Trigger ingress; as a global it would stop Cloud Tasks from invoking the task functions. */
|
|
176
178
|
const EVENT_FUNCTION_OPTIONS = {
|
|
177
179
|
...REGION_OPTION,
|
|
178
|
-
concurrency: 1,
|
|
179
|
-
cpu: "gcf_gen1",
|
|
180
180
|
ingressSettings: "ALLOW_INTERNAL_ONLY",
|
|
181
181
|
} as const;
|
|
182
182
|
|
|
183
|
-
/** Options shared by the task-queue functions
|
|
183
|
+
/** Options shared by the task-queue functions: the extension's 1st gen task timeout. */
|
|
184
184
|
const TASK_FUNCTION_OPTIONS = {
|
|
185
185
|
...REGION_OPTION,
|
|
186
|
-
concurrency: 1,
|
|
187
|
-
cpu: "gcf_gen1",
|
|
188
186
|
timeoutSeconds: 540,
|
|
189
187
|
} as const;
|
|
190
188
|
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { setGlobalOptions, type GlobalOptions } from "firebase-functions";
|
|
18
|
+
import { warn } from "firebase-functions/logger";
|
|
19
|
+
import * as v2Options from "firebase-functions/options";
|
|
20
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
21
|
+
|
|
22
|
+
// Each entry load registers the lifecycle hooks again, which the SDK allows only once per process.
|
|
23
|
+
vi.mock("firebase-functions/v2/lifecycle", () => ({
|
|
24
|
+
afterFirstDeploy: vi.fn(),
|
|
25
|
+
afterRedeploy: vi.fn(),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock("firebase-functions/logger", async (importOriginal) => ({
|
|
28
|
+
...(await importOriginal<typeof import("firebase-functions/logger")>()),
|
|
29
|
+
warn: vi.fn(),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const FUNCTION_NAMES = [
|
|
33
|
+
"fsexportbigquery",
|
|
34
|
+
"syncBigQuery",
|
|
35
|
+
"initBigQuerySync",
|
|
36
|
+
"setupBigQuerySync",
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
type FunctionName = (typeof FUNCTION_NAMES)[number];
|
|
40
|
+
type Endpoint = Record<string, unknown>;
|
|
41
|
+
|
|
42
|
+
/** `clearGlobalOptions` ships at runtime but is marked internal, so it is absent from the typings. */
|
|
43
|
+
const { clearGlobalOptions } = v2Options as unknown as {
|
|
44
|
+
clearGlobalOptions: () => void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
clearGlobalOptions();
|
|
49
|
+
vi.unstubAllEnvs();
|
|
50
|
+
vi.mocked(warn).mockClear();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** Loads the entry after the wrapper's `setGlobalOptions` call and returns each function's deploy endpoint. */
|
|
54
|
+
async function loadEndpoints(
|
|
55
|
+
globals?: GlobalOptions
|
|
56
|
+
): Promise<Record<FunctionName, Endpoint>> {
|
|
57
|
+
vi.resetModules();
|
|
58
|
+
vi.stubEnv("DATABASE_REGION", "");
|
|
59
|
+
if (globals) {
|
|
60
|
+
setGlobalOptions(globals);
|
|
61
|
+
}
|
|
62
|
+
const index: Record<string, unknown> = await import("../src/index");
|
|
63
|
+
const endpoints = {} as Record<FunctionName, Endpoint>;
|
|
64
|
+
for (const name of FUNCTION_NAMES) {
|
|
65
|
+
const fn = index[name] as { __endpoint: Endpoint };
|
|
66
|
+
expect(fn?.__endpoint, name).toBeDefined();
|
|
67
|
+
endpoints[name] = fn.__endpoint;
|
|
68
|
+
}
|
|
69
|
+
return endpoints;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Asserts the endpoint leaves `key` to the platform default: absent, or the SDK's reset marker. */
|
|
73
|
+
function expectPlatformDefault(
|
|
74
|
+
endpoint: Endpoint,
|
|
75
|
+
key: string,
|
|
76
|
+
label?: string
|
|
77
|
+
): void {
|
|
78
|
+
const value = endpoint[key];
|
|
79
|
+
if (value !== undefined) {
|
|
80
|
+
expect(value, label).toBeInstanceOf(v2Options.RESET_VALUE.constructor);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function loadDefaultOptions() {
|
|
85
|
+
vi.resetModules();
|
|
86
|
+
const { defaultOptions } = await import("../src/default-options");
|
|
87
|
+
return defaultOptions;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
describe("defaultOptions", () => {
|
|
91
|
+
test("holds the extension's runtime shape", async () => {
|
|
92
|
+
expect(await loadDefaultOptions()).toEqual({
|
|
93
|
+
cpu: "gcf_gen1",
|
|
94
|
+
concurrency: 1,
|
|
95
|
+
maxInstances: 100,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("imports without side effects when the entry would reject its params", async () => {
|
|
100
|
+
vi.stubEnv("DATASET_ID", "");
|
|
101
|
+
await expect(loadDefaultOptions()).resolves.toBeDefined();
|
|
102
|
+
vi.resetModules();
|
|
103
|
+
await expect(import("../src/index")).rejects.toThrow("DATASET_ID");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("as the globals, gives every function 0.1666 vCPU and concurrency 1", async () => {
|
|
107
|
+
const endpoints = await loadEndpoints(await loadDefaultOptions());
|
|
108
|
+
for (const name of FUNCTION_NAMES) {
|
|
109
|
+
expect(endpoints[name].cpu, name).toBe("gcf_gen1");
|
|
110
|
+
expect(endpoints[name].concurrency, name).toBe(1);
|
|
111
|
+
}
|
|
112
|
+
expect(endpoints.fsexportbigquery.maxInstances).toBe(100);
|
|
113
|
+
expect(endpoints.initBigQuerySync.maxInstances).toBe(100);
|
|
114
|
+
expect(endpoints.setupBigQuerySync.maxInstances).toBe(100);
|
|
115
|
+
expect(endpoints.syncBigQuery.maxInstances).toBe(500);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("keys after the spread override the defaults, except syncBigQuery's instance cap", async () => {
|
|
119
|
+
const endpoints = await loadEndpoints({
|
|
120
|
+
...(await loadDefaultOptions()),
|
|
121
|
+
maxInstances: 5,
|
|
122
|
+
cpu: 1,
|
|
123
|
+
});
|
|
124
|
+
expect(endpoints.fsexportbigquery.maxInstances).toBe(5);
|
|
125
|
+
expect(endpoints.fsexportbigquery.cpu).toBe(1);
|
|
126
|
+
expect(endpoints.syncBigQuery.maxInstances).toBe(500);
|
|
127
|
+
expect(endpoints.syncBigQuery.cpu).toBe(1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("per-function ingress and timeout survive the globals", async () => {
|
|
131
|
+
const endpoints = await loadEndpoints(await loadDefaultOptions());
|
|
132
|
+
expect(endpoints.fsexportbigquery.ingressSettings).toBe(
|
|
133
|
+
"ALLOW_INTERNAL_ONLY"
|
|
134
|
+
);
|
|
135
|
+
expectPlatformDefault(endpoints.fsexportbigquery, "timeoutSeconds");
|
|
136
|
+
for (const name of FUNCTION_NAMES.slice(1)) {
|
|
137
|
+
expectPlatformDefault(endpoints[name], "ingressSettings", name);
|
|
138
|
+
expect(endpoints[name].timeoutSeconds, name).toBe(540);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("without the globals, every function falls back to the platform cpu and concurrency", async () => {
|
|
143
|
+
const endpoints = await loadEndpoints();
|
|
144
|
+
for (const name of FUNCTION_NAMES) {
|
|
145
|
+
expectPlatformDefault(endpoints[name], "cpu", name);
|
|
146
|
+
expectPlatformDefault(endpoints[name], "concurrency", name);
|
|
147
|
+
}
|
|
148
|
+
expectPlatformDefault(endpoints.fsexportbigquery, "maxInstances");
|
|
149
|
+
expect(endpoints.syncBigQuery.maxInstances).toBe(500);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("a key set to undefined after the spread drops that default", async () => {
|
|
153
|
+
const endpoints = await loadEndpoints({
|
|
154
|
+
...(await loadDefaultOptions()),
|
|
155
|
+
maxInstances: undefined,
|
|
156
|
+
});
|
|
157
|
+
expectPlatformDefault(endpoints.fsexportbigquery, "maxInstances");
|
|
158
|
+
expect(endpoints.fsexportbigquery.cpu).toBe("gcf_gen1");
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("missing defaultOptions warning", () => {
|
|
163
|
+
test("warns during deploy discovery when no global cpu is set", async () => {
|
|
164
|
+
vi.stubEnv("FUNCTIONS_CONTROL_API", "true");
|
|
165
|
+
await loadEndpoints();
|
|
166
|
+
expect(warn).toHaveBeenCalledOnce();
|
|
167
|
+
expect(vi.mocked(warn).mock.calls[0][0]).toContain("defaultOptions");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("stays silent during deploy discovery when defaultOptions is applied", async () => {
|
|
171
|
+
vi.stubEnv("FUNCTIONS_CONTROL_API", "true");
|
|
172
|
+
await loadEndpoints(await loadDefaultOptions());
|
|
173
|
+
expect(warn).not.toHaveBeenCalled();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("stays silent outside deploy discovery", async () => {
|
|
177
|
+
vi.stubEnv("FUNCTIONS_CONTROL_API", undefined);
|
|
178
|
+
await loadEndpoints();
|
|
179
|
+
expect(warn).not.toHaveBeenCalled();
|
|
180
|
+
});
|
|
181
|
+
});
|
package/tests/events.test.ts
CHANGED
|
@@ -28,6 +28,7 @@ vi.mock("firebase-admin/eventarc", () => ({
|
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
import {
|
|
31
|
+
configuredEventChannel,
|
|
31
32
|
recordCompletionEvent,
|
|
32
33
|
recordErrorEvent,
|
|
33
34
|
recordStartEvent,
|
|
@@ -52,6 +53,28 @@ describe("no channel configured", () => {
|
|
|
52
53
|
await recordCompletionEvent({ a: 1 });
|
|
53
54
|
expect(publish).not.toHaveBeenCalled();
|
|
54
55
|
});
|
|
56
|
+
|
|
57
|
+
test.each([
|
|
58
|
+
["empty", ""],
|
|
59
|
+
["whitespace-only", " "],
|
|
60
|
+
])("a %s EVENTARC_CHANNEL opens no channel", async (_label, value) => {
|
|
61
|
+
process.env.EVENTARC_CHANNEL = value;
|
|
62
|
+
setupEventChannel();
|
|
63
|
+
|
|
64
|
+
await recordStartEvent({ a: 1 });
|
|
65
|
+
expect(channel).not.toHaveBeenCalled();
|
|
66
|
+
expect(publish).not.toHaveBeenCalled();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test.each([
|
|
70
|
+
["unset", undefined],
|
|
71
|
+
["empty", ""],
|
|
72
|
+
["whitespace-only", " "],
|
|
73
|
+
])("configuredEventChannel is undefined when %s", (_label, value) => {
|
|
74
|
+
if (value === undefined) delete process.env.EVENTARC_CHANNEL;
|
|
75
|
+
else process.env.EVENTARC_CHANNEL = value;
|
|
76
|
+
expect(configuredEventChannel()).toBeUndefined();
|
|
77
|
+
});
|
|
55
78
|
});
|
|
56
79
|
|
|
57
80
|
describe("channel configured", () => {
|
|
@@ -60,6 +83,21 @@ describe("channel configured", () => {
|
|
|
60
83
|
setupEventChannel();
|
|
61
84
|
});
|
|
62
85
|
|
|
86
|
+
test("configuredEventChannel returns the trimmed channel name", () => {
|
|
87
|
+
process.env.EVENTARC_CHANNEL = " projects/p/locations/l/channels/c ";
|
|
88
|
+
expect(configuredEventChannel()).toBe("projects/p/locations/l/channels/c");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("opens the channel on the trimmed name", () => {
|
|
92
|
+
process.env.EVENTARC_CHANNEL = " projects/p/locations/l/channels/c ";
|
|
93
|
+
setupEventChannel();
|
|
94
|
+
expect(channel).toHaveBeenCalledTimes(2);
|
|
95
|
+
expect(channel).toHaveBeenLastCalledWith(
|
|
96
|
+
"projects/p/locations/l/channels/c",
|
|
97
|
+
expect.anything()
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
63
101
|
test("publishes both the legacy and the current event type", async () => {
|
|
64
102
|
await recordStartEvent({ a: 1 });
|
|
65
103
|
expect(publish).toHaveBeenCalledTimes(2);
|
package/tests/index.test.ts
CHANGED
|
@@ -213,12 +213,12 @@ describe("exported function options", () => {
|
|
|
213
213
|
});
|
|
214
214
|
|
|
215
215
|
test.each(RUNTIME_OPTIONS_BY_FUNCTION)(
|
|
216
|
-
"%s
|
|
216
|
+
"%s declares ingress %s, maxInstances %s, timeout %s and leaves cpu and concurrency to the global options",
|
|
217
217
|
async (name, ingress, maxInstances, timeoutSeconds) => {
|
|
218
218
|
const deployed = await loadDeployedOptions();
|
|
219
219
|
const opts = deployed[name];
|
|
220
|
-
expect(opts
|
|
221
|
-
expect(opts
|
|
220
|
+
expect(opts).not.toHaveProperty("concurrency");
|
|
221
|
+
expect(opts).not.toHaveProperty("cpu");
|
|
222
222
|
expectOptional(opts, "ingressSettings", ingress);
|
|
223
223
|
expectOptional(opts, "maxInstances", maxInstances);
|
|
224
224
|
expectOptional(opts, "timeoutSeconds", timeoutSeconds);
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
18
18
|
|
|
19
|
-
const { requiresAPI } = vi.hoisted(() => ({
|
|
19
|
+
const { requiresAPI, requiresRole } = vi.hoisted(() => ({
|
|
20
|
+
requiresAPI: vi.fn(),
|
|
21
|
+
requiresRole: vi.fn(),
|
|
22
|
+
}));
|
|
20
23
|
|
|
21
24
|
vi.mock("firebase-functions/firestore", () => ({
|
|
22
25
|
onDocumentWritten: vi.fn(() => ({})),
|
|
@@ -26,18 +29,17 @@ vi.mock("firebase-functions/tasks", () => ({
|
|
|
26
29
|
}));
|
|
27
30
|
vi.mock("firebase-functions/v2", () => ({
|
|
28
31
|
requiresAPI,
|
|
29
|
-
requiresRole
|
|
32
|
+
requiresRole,
|
|
30
33
|
}));
|
|
31
34
|
vi.mock("firebase-functions/v2/lifecycle", () => ({
|
|
32
35
|
afterFirstDeploy: vi.fn(),
|
|
33
36
|
afterRedeploy: vi.fn(),
|
|
34
37
|
}));
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
+
const EVENTARC_API = "eventarcpublishing.googleapis.com";
|
|
40
|
+
const EVENTARC_PUBLISHER = "roles/eventarc.publisher";
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
const UNCONDITIONAL_APIS: ReadonlyArray<[api: string, reason: string]> = [
|
|
41
43
|
[
|
|
42
44
|
"firestore.googleapis.com",
|
|
43
45
|
"Receives document change events from Cloud Firestore.",
|
|
@@ -46,14 +48,99 @@ test.each([
|
|
|
46
48
|
"bigquery.googleapis.com",
|
|
47
49
|
"Mirrors data from your Cloud Firestore collection in BigQuery.",
|
|
48
50
|
],
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const UNCONDITIONAL_ROLES = [
|
|
54
|
+
"roles/bigquery.dataEditor",
|
|
55
|
+
"roles/datastore.user",
|
|
56
|
+
"roles/bigquery.user",
|
|
57
|
+
"roles/eventarc.eventReceiver",
|
|
58
|
+
"roles/run.invoker",
|
|
59
|
+
"roles/cloudtasks.enqueuer",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
vi.unstubAllEnvs();
|
|
64
|
+
vi.clearAllMocks();
|
|
55
65
|
});
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
/** Loads the entry afresh with `EVENTARC_CHANNEL` set to `channel`, or unset when omitted. */
|
|
68
|
+
async function loadWithChannel(channel?: string): Promise<void> {
|
|
69
|
+
vi.resetModules();
|
|
70
|
+
if (channel === undefined) {
|
|
71
|
+
vi.stubEnv("EVENTARC_CHANNEL", undefined);
|
|
72
|
+
} else {
|
|
73
|
+
vi.stubEnv("EVENTARC_CHANNEL", channel);
|
|
74
|
+
}
|
|
75
|
+
await import("../src/index");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function declaredApis(): string[] {
|
|
79
|
+
return requiresAPI.mock.calls.map(([api]) => api);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function declaredRoles(): string[] {
|
|
83
|
+
return requiresRole.mock.calls.map(([role]) => role);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe("without an Eventarc channel", () => {
|
|
87
|
+
test.each(UNCONDITIONAL_APIS)("declares %s", async (api, reason) => {
|
|
88
|
+
await loadWithChannel();
|
|
89
|
+
expect(requiresAPI).toHaveBeenCalledWith(api, reason);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("declares exactly the 2 APIs the export path needs", async () => {
|
|
93
|
+
await loadWithChannel();
|
|
94
|
+
expect(declaredApis()).toEqual(UNCONDITIONAL_APIS.map(([api]) => api));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("declares the roles the export path needs and no publisher role", async () => {
|
|
98
|
+
await loadWithChannel();
|
|
99
|
+
expect(declaredRoles()).toEqual(UNCONDITIONAL_ROLES);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// The extension declared one API and gained Eventarc publishing only when the
|
|
103
|
+
// user opted into events, so a default install must not gate the deploy on it.
|
|
104
|
+
test.each([
|
|
105
|
+
["unset", undefined],
|
|
106
|
+
["empty", ""],
|
|
107
|
+
["whitespace-only", " "],
|
|
108
|
+
])(
|
|
109
|
+
"leaves the Eventarc publishing API and role undeclared when EVENTARC_CHANNEL is %s",
|
|
110
|
+
async (_label, channel) => {
|
|
111
|
+
await loadWithChannel(channel);
|
|
112
|
+
expect(declaredApis()).not.toContain(EVENTARC_API);
|
|
113
|
+
expect(declaredRoles()).not.toContain(EVENTARC_PUBLISHER);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("with an Eventarc channel", () => {
|
|
119
|
+
const CHANNEL = "projects/p/locations/l/channels/firebase";
|
|
120
|
+
|
|
121
|
+
test("declares the Eventarc publishing API", async () => {
|
|
122
|
+
await loadWithChannel(CHANNEL);
|
|
123
|
+
expect(requiresAPI).toHaveBeenCalledWith(
|
|
124
|
+
EVENTARC_API,
|
|
125
|
+
"Publishes the extension's custom events to its Eventarc channel."
|
|
126
|
+
);
|
|
127
|
+
expect(declaredApis()).toEqual([
|
|
128
|
+
...UNCONDITIONAL_APIS.map(([api]) => api),
|
|
129
|
+
EVENTARC_API,
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("declares the publisher role alongside the unconditional roles", async () => {
|
|
134
|
+
await loadWithChannel(CHANNEL);
|
|
135
|
+
expect(declaredRoles()).toEqual([
|
|
136
|
+
...UNCONDITIONAL_ROLES,
|
|
137
|
+
EVENTARC_PUBLISHER,
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("a padded channel name still counts as configured", async () => {
|
|
142
|
+
await loadWithChannel(` ${CHANNEL} `);
|
|
143
|
+
expect(declaredApis()).toContain(EVENTARC_API);
|
|
144
|
+
expect(declaredRoles()).toContain(EVENTARC_PUBLISHER);
|
|
145
|
+
});
|
|
59
146
|
});
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/config.ts","./src/events.ts","./src/export-config.ts","./src/handlers.ts","./src/index.ts","./src/init.ts","./src/lib.ts","./src/logs.ts","./src/region.ts","./src/tasks.ts","./src/util.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["./src/config.ts","./src/default-options.ts","./src/events.ts","./src/export-config.ts","./src/global-options.ts","./src/handlers.ts","./src/index.ts","./src/init.ts","./src/lib.ts","./src/logs.ts","./src/region.ts","./src/tasks.ts","./src/util.ts"],"version":"5.9.3"}
|