Skip to content

Commit

Permalink
feat: Add Task Queue API (#1674)
Browse files Browse the repository at this point in the history
* Add Task Queue Functions API
  • Loading branch information
lahirumaramba committed May 4, 2022
1 parent b4b5e03 commit 331777d
Show file tree
Hide file tree
Showing 17 changed files with 1,540 additions and 1 deletion.
4 changes: 4 additions & 0 deletions entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"typings": "./lib/firestore/index.d.ts",
"dist": "./lib/firestore/index.js"
},
"firebase-admin/functions": {
"typings": "./lib/functions/index.d.ts",
"dist": "./lib/functions/index.js"
},
"firebase-admin/installations": {
"typings": "./lib/installations/index.d.ts",
"dist": "./lib/installations/index.js"
Expand Down
56 changes: 56 additions & 0 deletions etc/firebase-admin.functions.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## API Report File for "firebase-admin.functions"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

/// <reference types="node" />

import { Agent } from 'http';

// @public
export interface AbsoluteDelivery {
// @alpha (undocumented)
scheduleDelaySeconds?: never;
scheduleTime?: Date;
}

// @public
export interface DelayDelivery {
scheduleDelaySeconds?: number;
// @alpha (undocumented)
scheduleTime?: never;
}

// @public
export type DeliverySchedule = DelayDelivery | AbsoluteDelivery;

// @public
export class Functions {
// Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts
//
// (undocumented)
readonly app: App;
taskQueue<Args = Record<string, any>>(functionName: string, extensionId?: string): TaskQueue<Args>;
}

// @public
export function getFunctions(app?: App): Functions;

// @public
export type TaskOptions = DeliverySchedule & TaskOptionsExperimental & {
dispatchDeadlineSeconds?: number;
};

// @public
export interface TaskOptionsExperimental {
// @beta
uri?: string;
}

// @public
export class TaskQueue<Args = Record<string, any>> {
enqueue(data: Args, opts?: TaskOptions): Promise<void>;
}

```
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
"firestore": [
"lib/firestore"
],
"functions": [
"lib/functions"
],
"installations": [
"lib/installations"
],
Expand Down Expand Up @@ -132,6 +135,10 @@
"require": "./lib/firestore/index.js",
"import": "./lib/esm/firestore/index.js"
},
"./functions": {
"require": "./lib/functions/index.js",
"import": "./lib/esm/functions/index.js"
},
"./installations": {
"require": "./lib/installations/index.js",
"import": "./lib/esm/installations/index.js"
Expand Down
21 changes: 21 additions & 0 deletions src/app/credential-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const GOOGLE_AUTH_TOKEN_PATH = '/o/oauth2/token';
const GOOGLE_METADATA_SERVICE_HOST = 'metadata.google.internal';
const GOOGLE_METADATA_SERVICE_TOKEN_PATH = '/computeMetadata/v1/instance/service-accounts/default/token';
const GOOGLE_METADATA_SERVICE_PROJECT_ID_PATH = '/computeMetadata/v1/project/project-id';
const GOOGLE_METADATA_SERVICE_ACCOUNT_ID_PATH = '/computeMetadata/v1/instance/service-accounts/default/email';

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

constructor(httpAgent?: Agent) {
this.httpAgent = httpAgent;
Expand Down Expand Up @@ -226,6 +228,25 @@ export class ComputeEngineCredential implements Credential {
});
}

public getServiceAccountEmail(): Promise<string> {
if (this.accountId) {
return Promise.resolve(this.accountId);
}

const request = this.buildRequest(GOOGLE_METADATA_SERVICE_ACCOUNT_ID_PATH);
return this.httpClient.send(request)
.then((resp) => {
this.accountId = resp.text!;
return this.accountId;
})
.catch((err) => {
const detail: string = (err instanceof HttpError) ? getDetailFromResponse(err.response) : err.message;
throw new FirebaseAppError(
AppErrorCodes.INVALID_CREDENTIAL,
`Failed to determine service account email: ${detail}`);
});
}

private buildRequest(urlPath: string): HttpRequestConfig {
return {
method: 'GET',
Expand Down

0 comments on commit 331777d

Please sign in to comment.