Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Apr 7, 2022
1 parent c517dbc commit fb0a393
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/eventarc/eventarc-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import * as validator from '../utils/validator';
import { FirebaseEventarcError, toCloudEventProtoFormat } from './eventarc-utils';
import { Eventarc, Channel } from './eventarc';
import { App } from '../app';
import { Channel } from './eventarc';
import {
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient
} from '../utils/api-request';
Expand All @@ -43,21 +44,21 @@ export class EventarcApiClient {
private projectId?: string;
private readonly resolvedChannelName: Promise<string>;

constructor(private readonly eventarc: Eventarc, private readonly channel: Channel) {
if (!validator.isNonNullObject(eventarc.app) || !('options' in eventarc.app)) {
constructor(private readonly app: App, private readonly channel: Channel) {
if (!validator.isNonNullObject(app) || !('options' in app)) {
throw new FirebaseEventarcError(
'invalid-argument',
'First argument passed to admin.appCheck() must be a valid Firebase app instance.');
'First argument passed to Channel() must be a valid Eventarc service instance.');
}
this.httpClient = new AuthorizedHttpClient(eventarc.app as FirebaseApp);
this.httpClient = new AuthorizedHttpClient(app as FirebaseApp);
this.resolvedChannelName = this.resolveChannelName(channel.name);
}

private getProjectId(): Promise<string> {
if (this.projectId) {
return Promise.resolve(this.projectId);
}
return utils.findProjectId(this.eventarc.app)
return utils.findProjectId(this.app)
.then((projectId) => {
if (!validator.isNonEmptyString(projectId)) {
throw new FirebaseEventarcError(
Expand Down Expand Up @@ -153,4 +154,4 @@ export class EventarcApiClient {
const projectId = await this.getProjectId();
return `projects/${projectId}/locations/${location}/channels/${channelId}`;
}
}
}
2 changes: 1 addition & 1 deletion src/eventarc/eventarc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class Channel {
this.nameInternal = name;
this.eventarcInternal = eventarc;
this.allowedEventTypes = allowedEventTypes;
this.client = new EventarcApiClient(eventarc, this);
this.client = new EventarcApiClient(eventarc.app, this);
}

/**
Expand Down

0 comments on commit fb0a393

Please sign in to comment.