-
Notifications
You must be signed in to change notification settings - Fork 394
[Draft] Add generated client files to fcm #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maceonthompson
wants to merge
9
commits into
master
Choose a base branch
from
maceo-fcm-gapic-client
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
29271ef
Add protos types for GAPIC client
maceonthompson ae3a480
Add GAPIC generated client code
maceonthompson d45746d
Modify tsconfig to properly compile with GAPIC changes
maceonthompson 87840dc
Disable linting for autogenerated files
maceonthompson 313ded1
Fix style error in tsconfig
maceonthompson 0ab0d72
Refactor file structure of generated files/directories
maceonthompson c4be955
Ignore generated files in linter
maceonthompson 1ffae15
Update Gulpfile to copy files required for generated client to proper…
maceonthompson 3900ea9
Fcm GAPIC type conversion (#1354)
maceonthompson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
559 changes: 559 additions & 0 deletions
559
src/messaging/protos/google/firebase/fcm/v1/fcm_service.proto
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ** This file is automatically generated by gapic-generator-typescript. ** | ||
// ** https://github.com/googleapis/gapic-generator-typescript ** | ||
// ** All changes to this file may be overwritten. ** | ||
|
||
import * as v1 from './v1'; | ||
const FcmServiceClient = v1.FcmServiceClient; | ||
type FcmServiceClient = v1.FcmServiceClient; | ||
export {v1, FcmServiceClient}; | ||
export default {v1, FcmServiceClient}; | ||
hiranya911 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import * as protos from '../protos/protos'; | ||
export {protos} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,362 @@ | ||
/* eslint-disable */ | ||
maceonthompson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ** This file is automatically generated by gapic-generator-typescript. ** | ||
// ** https://github.com/googleapis/gapic-generator-typescript ** | ||
// ** All changes to this file may be overwritten. ** | ||
|
||
/* global window */ | ||
import * as gax from 'google-gax'; | ||
import {Callback, CallOptions, Descriptors, ClientOptions} from 'google-gax'; | ||
|
||
import * as protos from '../../protos/protos'; | ||
import jsonProtos = require('../../protos/protos.json'); | ||
/** | ||
* Client JSON configuration object, loaded from | ||
* `src/v1/fcm_service_client_config.json`. | ||
* This file defines retry strategy and timeouts for all API methods in this library. | ||
*/ | ||
import * as gapicConfig from './fcm_service_client_config.json'; | ||
|
||
const version = require('../../../package.json').version; | ||
|
||
/** | ||
* Firebase Cloud Messaging service (FCM) to target cross-platform messaging. | ||
* @class | ||
* @memberof v1 | ||
*/ | ||
export class FcmServiceClient { | ||
private _terminated = false; | ||
private _opts: ClientOptions; | ||
private _gaxModule: typeof gax | typeof gax.fallback; | ||
private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; | ||
private _protos: {}; | ||
private _defaults: {[method: string]: gax.CallSettings}; | ||
auth: gax.GoogleAuth; | ||
descriptors: Descriptors = { | ||
page: {}, | ||
stream: {}, | ||
longrunning: {}, | ||
batching: {}, | ||
}; | ||
innerApiCalls: {[name: string]: Function}; | ||
fcmServiceStub?: Promise<{[name: string]: Function}>; | ||
|
||
/** | ||
* Construct an instance of FcmServiceClient. | ||
* | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
* @param {string} [options.credentials.client_email] | ||
* @param {string} [options.credentials.private_key] | ||
* @param {string} [options.email] - Account email address. Required when | ||
* using a .pem or .p12 keyFilename. | ||
* @param {string} [options.keyFilename] - Full path to the a .json, .pem, or | ||
* .p12 key downloaded from the Google Developers Console. If you provide | ||
* a path to a JSON file, the projectId option below is not necessary. | ||
* NOTE: .pem and .p12 require you to specify options.email as well. | ||
* @param {number} [options.port] - The port on which to connect to | ||
* the remote host. | ||
* @param {string} [options.projectId] - The project ID from the Google | ||
* Developer's Console, e.g. 'grape-spaceship-123'. We will also check | ||
* the environment variable GCLOUD_PROJECT for your project ID. If your | ||
* app is running in an environment which supports | ||
* {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, | ||
* your project ID will be detected automatically. | ||
* @param {string} [options.apiEndpoint] - The domain name of the | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override. | ||
* Follows the structure of {@link gapicConfig}. | ||
* @param {boolean} [options.fallback] - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
constructor(opts?: ClientOptions) { | ||
// Ensure that options include all the required fields. | ||
const staticMembers = this.constructor as typeof FcmServiceClient; | ||
const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; | ||
const port = opts?.port || staticMembers.port; | ||
const clientConfig = opts?.clientConfig ?? {}; | ||
const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); | ||
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); | ||
|
||
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. | ||
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { | ||
opts['scopes'] = staticMembers.scopes; | ||
} | ||
|
||
// Choose either gRPC or proto-over-HTTP implementation of google-gax. | ||
this._gaxModule = opts.fallback ? gax.fallback : gax; | ||
|
||
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client. | ||
this._gaxGrpc = new this._gaxModule.GrpcClient(opts); | ||
|
||
// Save options to use in initialize() method. | ||
this._opts = opts; | ||
|
||
// Save the auth object to the client, for use by other methods. | ||
this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); | ||
|
||
// Set the default scopes in auth client if needed. | ||
if (servicePath === staticMembers.servicePath) { | ||
this.auth.defaultScopes = staticMembers.scopes; | ||
} | ||
|
||
// Determine the client header string. | ||
const clientHeader = [ | ||
`gax/${this._gaxModule.version}`, | ||
`gapic/${version}`, | ||
]; | ||
if (typeof process !== 'undefined' && 'versions' in process) { | ||
clientHeader.push(`gl-node/${process.versions.node}`); | ||
} else { | ||
clientHeader.push(`gl-web/${this._gaxModule.version}`); | ||
} | ||
if (!opts.fallback) { | ||
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); | ||
} else if (opts.fallback === 'rest' ) { | ||
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); | ||
} | ||
if (opts.libName && opts.libVersion) { | ||
clientHeader.push(`${opts.libName}/${opts.libVersion}`); | ||
} | ||
// Load the applicable protos. | ||
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); | ||
|
||
// Put together the default options sent with requests. | ||
this._defaults = this._gaxGrpc.constructSettings( | ||
'google.firebase.fcm.v1.FcmService', gapicConfig as gax.ClientConfig, | ||
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); | ||
|
||
// Set up a dictionary of "inner API calls"; the core implementation | ||
// of calling the API is handled in `google-gax`, with this code | ||
// merely providing the destination and request information. | ||
this.innerApiCalls = {}; | ||
} | ||
|
||
/** | ||
* Initialize the client. | ||
* Performs asynchronous operations (such as authentication) and prepares the client. | ||
* This function will be called automatically when any class method is called for the | ||
* first time, but if you need to initialize it before calling an actual method, | ||
* feel free to call initialize() directly. | ||
* | ||
* You can await on this method if you want to make sure the client is initialized. | ||
* | ||
* @returns {Promise} A promise that resolves to an authenticated service stub. | ||
*/ | ||
initialize() { | ||
// If the client stub promise is already initialized, return immediately. | ||
if (this.fcmServiceStub) { | ||
return this.fcmServiceStub; | ||
} | ||
|
||
// Put together the "service stub" for | ||
// google.firebase.fcm.v1.FcmService. | ||
this.fcmServiceStub = this._gaxGrpc.createStub( | ||
this._opts.fallback ? | ||
(this._protos as protobuf.Root).lookupService('google.firebase.fcm.v1.FcmService') : | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(this._protos as any).google.firebase.fcm.v1.FcmService, | ||
this._opts) as Promise<{[method: string]: Function}>; | ||
|
||
// Iterate over each of the methods that the service provides | ||
// and create an API call method for each. | ||
const fcmServiceStubMethods = | ||
['sendMessage']; | ||
for (const methodName of fcmServiceStubMethods) { | ||
const callPromise = this.fcmServiceStub.then( | ||
stub => (...args: Array<{}>) => { | ||
if (this._terminated) { | ||
return Promise.reject('The client has already been closed.'); | ||
} | ||
const func = stub[methodName]; | ||
return func.apply(stub, args); | ||
}, | ||
(err: Error|null|undefined) => () => { | ||
throw err; | ||
}); | ||
|
||
const descriptor = | ||
undefined; | ||
const apiCall = this._gaxModule.createApiCall( | ||
callPromise, | ||
this._defaults[methodName], | ||
descriptor | ||
); | ||
|
||
this.innerApiCalls[methodName] = apiCall; | ||
} | ||
|
||
return this.fcmServiceStub; | ||
} | ||
|
||
/** | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
static get servicePath() { | ||
return 'fcm.googleapis.com'; | ||
} | ||
|
||
/** | ||
* The DNS address for this API service - same as servicePath(), | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
static get apiEndpoint() { | ||
return 'fcm.googleapis.com'; | ||
} | ||
|
||
/** | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
static get port() { | ||
return 443; | ||
} | ||
|
||
/** | ||
* The scopes needed to make gRPC calls for every method defined | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
static get scopes() { | ||
return [ | ||
'https://www.googleapis.com/auth/cloud-platform' | ||
]; | ||
} | ||
|
||
getProjectId(): Promise<string>; | ||
getProjectId(callback: Callback<string, undefined, undefined>): void; | ||
/** | ||
* Return the project ID used by this class. | ||
* @returns {Promise} A promise that resolves to string containing the project ID. | ||
*/ | ||
getProjectId(callback?: Callback<string, undefined, undefined>): | ||
Promise<string>|void { | ||
if (callback) { | ||
this.auth.getProjectId(callback); | ||
return; | ||
} | ||
return this.auth.getProjectId(); | ||
} | ||
|
||
// ------------------- | ||
// -- Service calls -- | ||
// ------------------- | ||
sendMessage( | ||
request: protos.google.firebase.fcm.v1.ISendMessageRequest, | ||
options?: CallOptions): | ||
Promise<[ | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|undefined, {}|undefined | ||
]>; | ||
sendMessage( | ||
request: protos.google.firebase.fcm.v1.ISendMessageRequest, | ||
options: CallOptions, | ||
callback: Callback< | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|null|undefined, | ||
{}|null|undefined>): void; | ||
sendMessage( | ||
request: protos.google.firebase.fcm.v1.ISendMessageRequest, | ||
callback: Callback< | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|null|undefined, | ||
{}|null|undefined>): void; | ||
/** | ||
* Send a message to specified target (a registration token, topic | ||
* or condition). | ||
* | ||
* @param {Object} request | ||
* The request object that will be sent. | ||
* @param {string} request.parent | ||
* Required. It contains the Firebase project id (i.e. the unique identifier | ||
* for your Firebase project), in the format of `projects/{project_id}`. | ||
* For legacy support, the numeric project number with no padding is also | ||
* supported in the format of `projects/{project_number}`. | ||
* @param {boolean} request.validateOnly | ||
* Flag for testing the request without actually delivering the message. | ||
* @param {google.firebase.fcm.v1.Message} request.message | ||
* Required. Message to send. | ||
* @param {object} [options] | ||
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. | ||
* @returns {Promise} - The promise which resolves to an array. | ||
* The first element of the array is an object representing [Message]{@link google.firebase.fcm.v1.Message}. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.sendMessage(request); | ||
*/ | ||
sendMessage( | ||
request: protos.google.firebase.fcm.v1.ISendMessageRequest, | ||
optionsOrCallback?: CallOptions|Callback< | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|null|undefined, | ||
{}|null|undefined>, | ||
callback?: Callback< | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|null|undefined, | ||
{}|null|undefined>): | ||
Promise<[ | ||
protos.google.firebase.fcm.v1.IMessage, | ||
protos.google.firebase.fcm.v1.ISendMessageRequest|undefined, {}|undefined | ||
]>|void { | ||
request = request || {}; | ||
let options: CallOptions; | ||
if (typeof optionsOrCallback === 'function' && callback === undefined) { | ||
callback = optionsOrCallback; | ||
options = {}; | ||
} | ||
else { | ||
options = optionsOrCallback as CallOptions; | ||
} | ||
options = options || {}; | ||
options.otherArgs = options.otherArgs || {}; | ||
options.otherArgs.headers = options.otherArgs.headers || {}; | ||
options.otherArgs.headers[ | ||
'x-goog-request-params' | ||
] = gax.routingHeader.fromParams({ | ||
'parent': request.parent || '', | ||
}); | ||
this.initialize(); | ||
return this.innerApiCalls.sendMessage(request, options, callback); | ||
} | ||
|
||
|
||
/** | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
close(): Promise<void> { | ||
this.initialize(); | ||
if (!this._terminated) { | ||
return this.fcmServiceStub!.then(stub => { | ||
this._terminated = true; | ||
stub.close(); | ||
}); | ||
} | ||
return Promise.resolve(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.