Skip to content

Commit 331777d

Browse files
feat: Add Task Queue API (#1674)
* Add Task Queue Functions API
1 parent b4b5e03 commit 331777d

17 files changed

+1540
-1
lines changed

entrypoints.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"typings": "./lib/firestore/index.d.ts",
2525
"dist": "./lib/firestore/index.js"
2626
},
27+
"firebase-admin/functions": {
28+
"typings": "./lib/functions/index.d.ts",
29+
"dist": "./lib/functions/index.js"
30+
},
2731
"firebase-admin/installations": {
2832
"typings": "./lib/installations/index.d.ts",
2933
"dist": "./lib/installations/index.js"

etc/firebase-admin.functions.api.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## API Report File for "firebase-admin.functions"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
/// <reference types="node" />
8+
9+
import { Agent } from 'http';
10+
11+
// @public
12+
export interface AbsoluteDelivery {
13+
// @alpha (undocumented)
14+
scheduleDelaySeconds?: never;
15+
scheduleTime?: Date;
16+
}
17+
18+
// @public
19+
export interface DelayDelivery {
20+
scheduleDelaySeconds?: number;
21+
// @alpha (undocumented)
22+
scheduleTime?: never;
23+
}
24+
25+
// @public
26+
export type DeliverySchedule = DelayDelivery | AbsoluteDelivery;
27+
28+
// @public
29+
export class Functions {
30+
// Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts
31+
//
32+
// (undocumented)
33+
readonly app: App;
34+
taskQueue<Args = Record<string, any>>(functionName: string, extensionId?: string): TaskQueue<Args>;
35+
}
36+
37+
// @public
38+
export function getFunctions(app?: App): Functions;
39+
40+
// @public
41+
export type TaskOptions = DeliverySchedule & TaskOptionsExperimental & {
42+
dispatchDeadlineSeconds?: number;
43+
};
44+
45+
// @public
46+
export interface TaskOptionsExperimental {
47+
// @beta
48+
uri?: string;
49+
}
50+
51+
// @public
52+
export class TaskQueue<Args = Record<string, any>> {
53+
enqueue(data: Args, opts?: TaskOptions): Promise<void>;
54+
}
55+
56+
```

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
"firestore": [
8181
"lib/firestore"
8282
],
83+
"functions": [
84+
"lib/functions"
85+
],
8386
"installations": [
8487
"lib/installations"
8588
],
@@ -132,6 +135,10 @@
132135
"require": "./lib/firestore/index.js",
133136
"import": "./lib/esm/firestore/index.js"
134137
},
138+
"./functions": {
139+
"require": "./lib/functions/index.js",
140+
"import": "./lib/esm/functions/index.js"
141+
},
135142
"./installations": {
136143
"require": "./lib/installations/index.js",
137144
"import": "./lib/esm/installations/index.js"

src/app/credential-internal.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const GOOGLE_AUTH_TOKEN_PATH = '/o/oauth2/token';
3333
const GOOGLE_METADATA_SERVICE_HOST = 'metadata.google.internal';
3434
const GOOGLE_METADATA_SERVICE_TOKEN_PATH = '/computeMetadata/v1/instance/service-accounts/default/token';
3535
const GOOGLE_METADATA_SERVICE_PROJECT_ID_PATH = '/computeMetadata/v1/project/project-id';
36+
const GOOGLE_METADATA_SERVICE_ACCOUNT_ID_PATH = '/computeMetadata/v1/instance/service-accounts/default/email';
3637

3738
const configDir = (() => {
3839
// Windows has a dedicated low-rights location for apps at ~/Application Data
@@ -197,6 +198,7 @@ export class ComputeEngineCredential implements Credential {
197198
private readonly httpClient = new HttpClient();
198199
private readonly httpAgent?: Agent;
199200
private projectId?: string;
201+
private accountId?: string;
200202

201203
constructor(httpAgent?: Agent) {
202204
this.httpAgent = httpAgent;
@@ -226,6 +228,25 @@ export class ComputeEngineCredential implements Credential {
226228
});
227229
}
228230

231+
public getServiceAccountEmail(): Promise<string> {
232+
if (this.accountId) {
233+
return Promise.resolve(this.accountId);
234+
}
235+
236+
const request = this.buildRequest(GOOGLE_METADATA_SERVICE_ACCOUNT_ID_PATH);
237+
return this.httpClient.send(request)
238+
.then((resp) => {
239+
this.accountId = resp.text!;
240+
return this.accountId;
241+
})
242+
.catch((err) => {
243+
const detail: string = (err instanceof HttpError) ? getDetailFromResponse(err.response) : err.message;
244+
throw new FirebaseAppError(
245+
AppErrorCodes.INVALID_CREDENTIAL,
246+
`Failed to determine service account email: ${detail}`);
247+
});
248+
}
249+
229250
private buildRequest(urlPath: string): HttpRequestConfig {
230251
return {
231252
method: 'GET',

0 commit comments

Comments
 (0)