firebase-admin 9.12.0
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/LICENSE +201 -0
- package/README.md +90 -0
- package/lib/app-check/app-check-api-client-internal.js +197 -0
- package/lib/app-check/app-check.js +79 -0
- package/lib/app-check/index.d.ts +160 -0
- package/lib/app-check/index.js +19 -0
- package/lib/app-check/token-generator.js +161 -0
- package/lib/app-check/token-verifier.js +152 -0
- package/lib/auth/action-code-settings-builder.js +118 -0
- package/lib/auth/auth-api-request.js +1856 -0
- package/lib/auth/auth-config.js +636 -0
- package/lib/auth/auth.js +836 -0
- package/lib/auth/identifier.js +40 -0
- package/lib/auth/index.d.ts +1927 -0
- package/lib/auth/index.js +18 -0
- package/lib/auth/tenant-manager.js +140 -0
- package/lib/auth/tenant.js +171 -0
- package/lib/auth/token-generator.js +200 -0
- package/lib/auth/token-verifier.js +259 -0
- package/lib/auth/user-import-builder.js +387 -0
- package/lib/auth/user-record.js +346 -0
- package/lib/credential/credential-internal.js +391 -0
- package/lib/credential/credential.js +44 -0
- package/lib/credential/index.d.ts +169 -0
- package/lib/credential/index.js +23 -0
- package/lib/database/database-internal.js +266 -0
- package/lib/database/index.d.ts +89 -0
- package/lib/database/index.js +31 -0
- package/lib/default-namespace.js +31 -0
- package/lib/firebase-app.js +349 -0
- package/lib/firebase-namespace-api.d.ts +243 -0
- package/lib/firebase-namespace-api.js +18 -0
- package/lib/firebase-namespace.d.ts +31 -0
- package/lib/firebase-namespace.js +417 -0
- package/lib/firestore/firestore-internal.js +105 -0
- package/lib/firestore/index.d.ts +50 -0
- package/lib/firestore/index.js +47 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +27 -0
- package/lib/installations/index.d.ts +81 -0
- package/lib/installations/index.js +18 -0
- package/lib/installations/installations-request-handler.js +117 -0
- package/lib/installations/installations.js +62 -0
- package/lib/instance-id/index.d.ts +83 -0
- package/lib/instance-id/index.js +18 -0
- package/lib/instance-id/instance-id.js +87 -0
- package/lib/machine-learning/index.d.ts +249 -0
- package/lib/machine-learning/index.js +18 -0
- package/lib/machine-learning/machine-learning-api-client.js +304 -0
- package/lib/machine-learning/machine-learning-utils.js +62 -0
- package/lib/machine-learning/machine-learning.js +364 -0
- package/lib/messaging/batch-request-internal.js +129 -0
- package/lib/messaging/index.d.ts +1174 -0
- package/lib/messaging/index.js +18 -0
- package/lib/messaging/messaging-api-request-internal.js +128 -0
- package/lib/messaging/messaging-errors-internal.js +106 -0
- package/lib/messaging/messaging-internal.js +484 -0
- package/lib/messaging/messaging.js +846 -0
- package/lib/project-management/android-app.js +176 -0
- package/lib/project-management/index.d.ts +363 -0
- package/lib/project-management/index.js +41 -0
- package/lib/project-management/ios-app.js +88 -0
- package/lib/project-management/project-management-api-request-internal.js +273 -0
- package/lib/project-management/project-management.js +254 -0
- package/lib/remote-config/index.d.ts +369 -0
- package/lib/remote-config/index.js +18 -0
- package/lib/remote-config/remote-config-api-client-internal.js +407 -0
- package/lib/remote-config/remote-config.js +304 -0
- package/lib/security-rules/index.d.ts +216 -0
- package/lib/security-rules/index.js +18 -0
- package/lib/security-rules/security-rules-api-client-internal.js +237 -0
- package/lib/security-rules/security-rules-internal.js +41 -0
- package/lib/security-rules/security-rules.js +310 -0
- package/lib/storage/index.d.ts +60 -0
- package/lib/storage/index.js +18 -0
- package/lib/storage/storage.js +123 -0
- package/lib/utils/api-request.js +845 -0
- package/lib/utils/crypto-signer.js +237 -0
- package/lib/utils/deep-copy.js +78 -0
- package/lib/utils/error.js +1063 -0
- package/lib/utils/index.js +217 -0
- package/lib/utils/jwt.js +355 -0
- package/lib/utils/validator.js +271 -0
- package/package.json +122 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2020 Google Inc.
|
|
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
|
+
* http://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
|
+
import { app } from '../firebase-namespace-api';
|
|
18
|
+
/**
|
|
19
|
+
* Gets the {@link machineLearning.MachineLearning `MachineLearning`} service for the
|
|
20
|
+
* default app or a given app.
|
|
21
|
+
*
|
|
22
|
+
* `admin.machineLearning()` can be called with no arguments to access the
|
|
23
|
+
* default app's {@link machineLearning.MachineLearning
|
|
24
|
+
* `MachineLearning`} service or as `admin.machineLearning(app)` to access
|
|
25
|
+
* the {@link machineLearning.MachineLearning `MachineLearning`}
|
|
26
|
+
* service associated with a specific app.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```javascript
|
|
30
|
+
* // Get the MachineLearning service for the default app
|
|
31
|
+
* var defaultMachineLearning = admin.machineLearning();
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```javascript
|
|
36
|
+
* // Get the MachineLearning service for a given app
|
|
37
|
+
* var otherMachineLearning = admin.machineLearning(otherApp);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param app Optional app whose `MachineLearning` service to
|
|
41
|
+
* return. If not provided, the default `MachineLearning` service
|
|
42
|
+
* will be returned.
|
|
43
|
+
*
|
|
44
|
+
* @return The default `MachineLearning` service if no app is provided or the
|
|
45
|
+
* `MachineLearning` service associated with the provided app.
|
|
46
|
+
*/
|
|
47
|
+
export declare function machineLearning(app?: app.App): machineLearning.MachineLearning;
|
|
48
|
+
export declare namespace machineLearning {
|
|
49
|
+
/**
|
|
50
|
+
* Firebase ML Model input objects
|
|
51
|
+
*/
|
|
52
|
+
interface ModelOptionsBase {
|
|
53
|
+
displayName?: string;
|
|
54
|
+
tags?: string[];
|
|
55
|
+
}
|
|
56
|
+
interface GcsTfliteModelOptions extends ModelOptionsBase {
|
|
57
|
+
tfliteModel: {
|
|
58
|
+
gcsTfliteUri: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
interface AutoMLTfliteModelOptions extends ModelOptionsBase {
|
|
62
|
+
tfliteModel: {
|
|
63
|
+
automlModel: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
type ModelOptions = ModelOptionsBase | GcsTfliteModelOptions | AutoMLTfliteModelOptions;
|
|
67
|
+
/**
|
|
68
|
+
* A TensorFlow Lite Model output object
|
|
69
|
+
*
|
|
70
|
+
* One of either the `gcsTfliteUri` or `automlModel` properties will be
|
|
71
|
+
* defined.
|
|
72
|
+
*/
|
|
73
|
+
interface TFLiteModel {
|
|
74
|
+
/** The size of the model. */
|
|
75
|
+
readonly sizeBytes: number;
|
|
76
|
+
/** The URI from which the model was originally provided to Firebase. */
|
|
77
|
+
readonly gcsTfliteUri?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The AutoML model reference from which the model was originally provided
|
|
80
|
+
* to Firebase.
|
|
81
|
+
*/
|
|
82
|
+
readonly automlModel?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A Firebase ML Model output object
|
|
86
|
+
*/
|
|
87
|
+
interface Model {
|
|
88
|
+
/** The ID of the model. */
|
|
89
|
+
readonly modelId: string;
|
|
90
|
+
/**
|
|
91
|
+
* The model's name. This is the name you use from your app to load the
|
|
92
|
+
* model.
|
|
93
|
+
*/
|
|
94
|
+
readonly displayName: string;
|
|
95
|
+
/**
|
|
96
|
+
* The model's tags, which can be used to group or filter models in list
|
|
97
|
+
* operations.
|
|
98
|
+
*/
|
|
99
|
+
readonly tags?: string[];
|
|
100
|
+
/** The timestamp of the model's creation. */
|
|
101
|
+
readonly createTime: string;
|
|
102
|
+
/** The timestamp of the model's most recent update. */
|
|
103
|
+
readonly updateTime: string;
|
|
104
|
+
/** Error message when model validation fails. */
|
|
105
|
+
readonly validationError?: string;
|
|
106
|
+
/** True if the model is published. */
|
|
107
|
+
readonly published: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* The ETag identifier of the current version of the model. This value
|
|
110
|
+
* changes whenever you update any of the model's properties.
|
|
111
|
+
*/
|
|
112
|
+
readonly etag: string;
|
|
113
|
+
/**
|
|
114
|
+
* The hash of the model's `tflite` file. This value changes only when
|
|
115
|
+
* you upload a new TensorFlow Lite model.
|
|
116
|
+
*/
|
|
117
|
+
readonly modelHash?: string;
|
|
118
|
+
/**
|
|
119
|
+
* True if the model is locked by a server-side operation. You can't make
|
|
120
|
+
* changes to a locked model. See {@link waitForUnlocked `waitForUnlocked()`}.
|
|
121
|
+
*/
|
|
122
|
+
readonly locked: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Wait for the model to be unlocked.
|
|
125
|
+
*
|
|
126
|
+
* @param {number} maxTimeMillis The maximum time in milliseconds to wait.
|
|
127
|
+
* If not specified, a default maximum of 2 minutes is used.
|
|
128
|
+
*
|
|
129
|
+
* @return {Promise<void>} A promise that resolves when the model is unlocked
|
|
130
|
+
* or the maximum wait time has passed.
|
|
131
|
+
*/
|
|
132
|
+
waitForUnlocked(maxTimeMillis?: number): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Return the model as a JSON object.
|
|
135
|
+
*/
|
|
136
|
+
toJSON(): {
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
};
|
|
139
|
+
/** Metadata about the model's TensorFlow Lite model file. */
|
|
140
|
+
readonly tfliteModel?: TFLiteModel;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Interface representing options for listing Models.
|
|
144
|
+
*/
|
|
145
|
+
interface ListModelsOptions {
|
|
146
|
+
/**
|
|
147
|
+
* An expression that specifies how to filter the results.
|
|
148
|
+
*
|
|
149
|
+
* Examples:
|
|
150
|
+
*
|
|
151
|
+
* ```
|
|
152
|
+
* display_name = your_model
|
|
153
|
+
* display_name : experimental_*
|
|
154
|
+
* tags: face_detector AND tags: experimental
|
|
155
|
+
* state.published = true
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* See https://firebase.google.com/docs/ml/manage-hosted-models#list_your_projects_models
|
|
159
|
+
*/
|
|
160
|
+
filter?: string;
|
|
161
|
+
/** The number of results to return in each page. */
|
|
162
|
+
pageSize?: number;
|
|
163
|
+
/** A token that specifies the result page to return. */
|
|
164
|
+
pageToken?: string;
|
|
165
|
+
}
|
|
166
|
+
/** Response object for a listModels operation. */
|
|
167
|
+
interface ListModelsResult {
|
|
168
|
+
/** A list of models in your project. */
|
|
169
|
+
readonly models: Model[];
|
|
170
|
+
/**
|
|
171
|
+
* A token you can use to retrieve the next page of results. If null, the
|
|
172
|
+
* current page is the final page.
|
|
173
|
+
*/
|
|
174
|
+
readonly pageToken?: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The Firebase `MachineLearning` service interface.
|
|
178
|
+
*
|
|
179
|
+
* Do not call this constructor directly. Instead, use
|
|
180
|
+
* [`admin.machineLearning()`](admin.machineLearning#machineLearning).
|
|
181
|
+
*/
|
|
182
|
+
interface MachineLearning {
|
|
183
|
+
/**
|
|
184
|
+
* The {@link app.App} associated with the current `MachineLearning`
|
|
185
|
+
* service instance.
|
|
186
|
+
*/
|
|
187
|
+
app: app.App;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a model in the current Firebase project.
|
|
190
|
+
*
|
|
191
|
+
* @param {ModelOptions} model The model to create.
|
|
192
|
+
*
|
|
193
|
+
* @return {Promise<Model>} A Promise fulfilled with the created model.
|
|
194
|
+
*/
|
|
195
|
+
createModel(model: ModelOptions): Promise<Model>;
|
|
196
|
+
/**
|
|
197
|
+
* Updates a model's metadata or model file.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} modelId The ID of the model to update.
|
|
200
|
+
* @param {ModelOptions} model The model fields to update.
|
|
201
|
+
*
|
|
202
|
+
* @return {Promise<Model>} A Promise fulfilled with the updated model.
|
|
203
|
+
*/
|
|
204
|
+
updateModel(modelId: string, model: ModelOptions): Promise<Model>;
|
|
205
|
+
/**
|
|
206
|
+
* Publishes a Firebase ML model.
|
|
207
|
+
*
|
|
208
|
+
* A published model can be downloaded to client apps.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} modelId The ID of the model to publish.
|
|
211
|
+
*
|
|
212
|
+
* @return {Promise<Model>} A Promise fulfilled with the published model.
|
|
213
|
+
*/
|
|
214
|
+
publishModel(modelId: string): Promise<Model>;
|
|
215
|
+
/**
|
|
216
|
+
* Unpublishes a Firebase ML model.
|
|
217
|
+
*
|
|
218
|
+
* @param {string} modelId The ID of the model to unpublish.
|
|
219
|
+
*
|
|
220
|
+
* @return {Promise<Model>} A Promise fulfilled with the unpublished model.
|
|
221
|
+
*/
|
|
222
|
+
unpublishModel(modelId: string): Promise<Model>;
|
|
223
|
+
/**
|
|
224
|
+
* Gets the model specified by the given ID.
|
|
225
|
+
*
|
|
226
|
+
* @param {string} modelId The ID of the model to get.
|
|
227
|
+
*
|
|
228
|
+
* @return {Promise<Model>} A Promise fulfilled with the model object.
|
|
229
|
+
*/
|
|
230
|
+
getModel(modelId: string): Promise<Model>;
|
|
231
|
+
/**
|
|
232
|
+
* Lists the current project's models.
|
|
233
|
+
*
|
|
234
|
+
* @param {ListModelsOptions} options The listing options.
|
|
235
|
+
*
|
|
236
|
+
* @return {Promise<ListModelsResult>} A promise that
|
|
237
|
+
* resolves with the current (filtered) list of models and the next page
|
|
238
|
+
* token. For the last page, an empty list of models and no page token
|
|
239
|
+
* are returned.
|
|
240
|
+
*/
|
|
241
|
+
listModels(options?: ListModelsOptions): Promise<ListModelsResult>;
|
|
242
|
+
/**
|
|
243
|
+
* Deletes a model from the current project.
|
|
244
|
+
*
|
|
245
|
+
* @param {string} modelId The ID of the model to delete.
|
|
246
|
+
*/
|
|
247
|
+
deleteModel(modelId: string): Promise<void>;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2020 Google Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2020 Google Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.MachineLearningApiClient = exports.isGcsTfliteModelOptions = void 0;
|
|
20
|
+
var api_request_1 = require("../utils/api-request");
|
|
21
|
+
var error_1 = require("../utils/error");
|
|
22
|
+
var machine_learning_utils_1 = require("./machine-learning-utils");
|
|
23
|
+
var utils = require("../utils/index");
|
|
24
|
+
var validator = require("../utils/validator");
|
|
25
|
+
var ML_V1BETA2_API = 'https://firebaseml.googleapis.com/v1beta2';
|
|
26
|
+
var FIREBASE_VERSION_HEADER = {
|
|
27
|
+
'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
|
|
28
|
+
};
|
|
29
|
+
// Operation polling defaults
|
|
30
|
+
var POLL_DEFAULT_MAX_TIME_MILLISECONDS = 120000; // Maximum overall 2 minutes
|
|
31
|
+
var POLL_BASE_WAIT_TIME_MILLISECONDS = 3000; // Start with 3 second delay
|
|
32
|
+
var POLL_MAX_WAIT_TIME_MILLISECONDS = 30000; // Maximum 30 second delay
|
|
33
|
+
function isGcsTfliteModelOptions(options) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
var gcsUri = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.tfliteModel) === null || _b === void 0 ? void 0 : _b.gcsTfliteUri;
|
|
36
|
+
return typeof gcsUri !== 'undefined';
|
|
37
|
+
}
|
|
38
|
+
exports.isGcsTfliteModelOptions = isGcsTfliteModelOptions;
|
|
39
|
+
/**
|
|
40
|
+
* Class that facilitates sending requests to the Firebase ML backend API.
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
var MachineLearningApiClient = /** @class */ (function () {
|
|
45
|
+
function MachineLearningApiClient(app) {
|
|
46
|
+
this.app = app;
|
|
47
|
+
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
48
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'First argument passed to admin.machineLearning() must be a valid '
|
|
49
|
+
+ 'Firebase app instance.');
|
|
50
|
+
}
|
|
51
|
+
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
52
|
+
}
|
|
53
|
+
MachineLearningApiClient.prototype.createModel = function (model) {
|
|
54
|
+
var _this = this;
|
|
55
|
+
if (!validator.isNonNullObject(model) ||
|
|
56
|
+
!validator.isNonEmptyString(model.displayName)) {
|
|
57
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid model content.');
|
|
58
|
+
return Promise.reject(err);
|
|
59
|
+
}
|
|
60
|
+
return this.getProjectUrl()
|
|
61
|
+
.then(function (url) {
|
|
62
|
+
var request = {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
url: url + "/models",
|
|
65
|
+
data: model,
|
|
66
|
+
};
|
|
67
|
+
return _this.sendRequest(request);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
MachineLearningApiClient.prototype.updateModel = function (modelId, model, updateMask) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
if (!validator.isNonEmptyString(modelId) ||
|
|
73
|
+
!validator.isNonNullObject(model) ||
|
|
74
|
+
!validator.isNonEmptyArray(updateMask)) {
|
|
75
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid model or mask content.');
|
|
76
|
+
return Promise.reject(err);
|
|
77
|
+
}
|
|
78
|
+
return this.getProjectUrl()
|
|
79
|
+
.then(function (url) {
|
|
80
|
+
var request = {
|
|
81
|
+
method: 'PATCH',
|
|
82
|
+
url: url + "/models/" + modelId + "?updateMask=" + updateMask.join(),
|
|
83
|
+
data: model,
|
|
84
|
+
};
|
|
85
|
+
return _this.sendRequest(request);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
MachineLearningApiClient.prototype.getModel = function (modelId) {
|
|
89
|
+
var _this = this;
|
|
90
|
+
return Promise.resolve()
|
|
91
|
+
.then(function () {
|
|
92
|
+
return _this.getModelName(modelId);
|
|
93
|
+
})
|
|
94
|
+
.then(function (modelName) {
|
|
95
|
+
return _this.getResourceWithShortName(modelName);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
MachineLearningApiClient.prototype.getOperation = function (operationName) {
|
|
99
|
+
var _this = this;
|
|
100
|
+
return Promise.resolve()
|
|
101
|
+
.then(function () {
|
|
102
|
+
return _this.getResourceWithFullName(operationName);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
MachineLearningApiClient.prototype.listModels = function (options) {
|
|
106
|
+
var _this = this;
|
|
107
|
+
if (options === void 0) { options = {}; }
|
|
108
|
+
if (!validator.isNonNullObject(options)) {
|
|
109
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid ListModelsOptions');
|
|
110
|
+
return Promise.reject(err);
|
|
111
|
+
}
|
|
112
|
+
if (typeof options.filter !== 'undefined' && !validator.isNonEmptyString(options.filter)) {
|
|
113
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid list filter.');
|
|
114
|
+
return Promise.reject(err);
|
|
115
|
+
}
|
|
116
|
+
if (typeof options.pageSize !== 'undefined') {
|
|
117
|
+
if (!validator.isNumber(options.pageSize)) {
|
|
118
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid page size.');
|
|
119
|
+
return Promise.reject(err);
|
|
120
|
+
}
|
|
121
|
+
if (options.pageSize < 1 || options.pageSize > 100) {
|
|
122
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Page size must be between 1 and 100.');
|
|
123
|
+
return Promise.reject(err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (typeof options.pageToken !== 'undefined' && !validator.isNonEmptyString(options.pageToken)) {
|
|
127
|
+
var err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Next page token must be a non-empty string.');
|
|
128
|
+
return Promise.reject(err);
|
|
129
|
+
}
|
|
130
|
+
return this.getProjectUrl()
|
|
131
|
+
.then(function (url) {
|
|
132
|
+
var request = {
|
|
133
|
+
method: 'GET',
|
|
134
|
+
url: url + "/models",
|
|
135
|
+
data: options,
|
|
136
|
+
};
|
|
137
|
+
return _this.sendRequest(request);
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
MachineLearningApiClient.prototype.deleteModel = function (modelId) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
return this.getProjectUrl()
|
|
143
|
+
.then(function (url) {
|
|
144
|
+
var modelName = _this.getModelName(modelId);
|
|
145
|
+
var request = {
|
|
146
|
+
method: 'DELETE',
|
|
147
|
+
url: url + "/" + modelName,
|
|
148
|
+
};
|
|
149
|
+
return _this.sendRequest(request);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Handles a Long Running Operation coming back from the server.
|
|
154
|
+
*
|
|
155
|
+
* @param op The operation to handle
|
|
156
|
+
* @param options The options for polling
|
|
157
|
+
*/
|
|
158
|
+
MachineLearningApiClient.prototype.handleOperation = function (op, options) {
|
|
159
|
+
if (op.done) {
|
|
160
|
+
if (op.response) {
|
|
161
|
+
return Promise.resolve(op.response);
|
|
162
|
+
}
|
|
163
|
+
else if (op.error) {
|
|
164
|
+
var err = machine_learning_utils_1.FirebaseMachineLearningError.fromOperationError(op.error.code, op.error.message);
|
|
165
|
+
return Promise.reject(err);
|
|
166
|
+
}
|
|
167
|
+
// Done operations must have either a response or an error.
|
|
168
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-server-response', 'Invalid operation response.');
|
|
169
|
+
}
|
|
170
|
+
// Operation is not done
|
|
171
|
+
if (options === null || options === void 0 ? void 0 : options.wait) {
|
|
172
|
+
return this.pollOperationWithExponentialBackoff(op.name, options);
|
|
173
|
+
}
|
|
174
|
+
var metadata = op.metadata || {};
|
|
175
|
+
var metadataType = metadata['@type'] || '';
|
|
176
|
+
if (!metadataType.includes('ModelOperationMetadata')) {
|
|
177
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-server-response', "Unknown Metadata type: " + JSON.stringify(metadata));
|
|
178
|
+
}
|
|
179
|
+
return this.getModel(extractModelId(metadata.name));
|
|
180
|
+
};
|
|
181
|
+
// baseWaitMillis and maxWaitMillis should only ever be modified by unit tests to run faster.
|
|
182
|
+
MachineLearningApiClient.prototype.pollOperationWithExponentialBackoff = function (opName, options) {
|
|
183
|
+
var _this = this;
|
|
184
|
+
var _a, _b, _c;
|
|
185
|
+
var maxTimeMilliseconds = (_a = options === null || options === void 0 ? void 0 : options.maxTimeMillis) !== null && _a !== void 0 ? _a : POLL_DEFAULT_MAX_TIME_MILLISECONDS;
|
|
186
|
+
var baseWaitMillis = (_b = options === null || options === void 0 ? void 0 : options.baseWaitMillis) !== null && _b !== void 0 ? _b : POLL_BASE_WAIT_TIME_MILLISECONDS;
|
|
187
|
+
var maxWaitMillis = (_c = options === null || options === void 0 ? void 0 : options.maxWaitMillis) !== null && _c !== void 0 ? _c : POLL_MAX_WAIT_TIME_MILLISECONDS;
|
|
188
|
+
var poller = new api_request_1.ExponentialBackoffPoller(baseWaitMillis, maxWaitMillis, maxTimeMilliseconds);
|
|
189
|
+
return poller.poll(function () {
|
|
190
|
+
return _this.getOperation(opName)
|
|
191
|
+
.then(function (responseData) {
|
|
192
|
+
if (!responseData.done) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
if (responseData.error) {
|
|
196
|
+
var err = machine_learning_utils_1.FirebaseMachineLearningError.fromOperationError(responseData.error.code, responseData.error.message);
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
return responseData.response;
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Gets the specified resource from the ML API. Resource names must be the short names without project
|
|
205
|
+
* ID prefix (e.g. `models/123456789`).
|
|
206
|
+
*
|
|
207
|
+
* @param {string} name Short name of the resource to get. e.g. 'models/12345'
|
|
208
|
+
* @returns {Promise<T>} A promise that fulfills with the resource.
|
|
209
|
+
*/
|
|
210
|
+
MachineLearningApiClient.prototype.getResourceWithShortName = function (name) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
return this.getProjectUrl()
|
|
213
|
+
.then(function (url) {
|
|
214
|
+
var request = {
|
|
215
|
+
method: 'GET',
|
|
216
|
+
url: url + "/" + name,
|
|
217
|
+
};
|
|
218
|
+
return _this.sendRequest(request);
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Gets the specified resource from the ML API. Resource names must be the full names including project
|
|
223
|
+
* number prefix.
|
|
224
|
+
* @param fullName Full resource name of the resource to get. e.g. projects/123465/operations/987654
|
|
225
|
+
* @returns {Promise<T>} A promise that fulfulls with the resource.
|
|
226
|
+
*/
|
|
227
|
+
MachineLearningApiClient.prototype.getResourceWithFullName = function (fullName) {
|
|
228
|
+
var request = {
|
|
229
|
+
method: 'GET',
|
|
230
|
+
url: ML_V1BETA2_API + "/" + fullName
|
|
231
|
+
};
|
|
232
|
+
return this.sendRequest(request);
|
|
233
|
+
};
|
|
234
|
+
MachineLearningApiClient.prototype.sendRequest = function (request) {
|
|
235
|
+
var _this = this;
|
|
236
|
+
request.headers = FIREBASE_VERSION_HEADER;
|
|
237
|
+
return this.httpClient.send(request)
|
|
238
|
+
.then(function (resp) {
|
|
239
|
+
return resp.data;
|
|
240
|
+
})
|
|
241
|
+
.catch(function (err) {
|
|
242
|
+
throw _this.toFirebaseError(err);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
MachineLearningApiClient.prototype.toFirebaseError = function (err) {
|
|
246
|
+
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
247
|
+
return err;
|
|
248
|
+
}
|
|
249
|
+
var response = err.response;
|
|
250
|
+
if (!response.isJson()) {
|
|
251
|
+
return new machine_learning_utils_1.FirebaseMachineLearningError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
|
|
252
|
+
}
|
|
253
|
+
var error = response.data.error || {};
|
|
254
|
+
var code = 'unknown-error';
|
|
255
|
+
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
|
256
|
+
code = ERROR_CODE_MAPPING[error.status];
|
|
257
|
+
}
|
|
258
|
+
var message = error.message || "Unknown server error: " + response.text;
|
|
259
|
+
return new machine_learning_utils_1.FirebaseMachineLearningError(code, message);
|
|
260
|
+
};
|
|
261
|
+
MachineLearningApiClient.prototype.getProjectUrl = function () {
|
|
262
|
+
return this.getProjectIdPrefix()
|
|
263
|
+
.then(function (projectIdPrefix) {
|
|
264
|
+
return ML_V1BETA2_API + "/" + projectIdPrefix;
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
MachineLearningApiClient.prototype.getProjectIdPrefix = function () {
|
|
268
|
+
var _this = this;
|
|
269
|
+
if (this.projectIdPrefix) {
|
|
270
|
+
return Promise.resolve(this.projectIdPrefix);
|
|
271
|
+
}
|
|
272
|
+
return utils.findProjectId(this.app)
|
|
273
|
+
.then(function (projectId) {
|
|
274
|
+
if (!validator.isNonEmptyString(projectId)) {
|
|
275
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
276
|
+
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
277
|
+
+ 'environment variable.');
|
|
278
|
+
}
|
|
279
|
+
_this.projectIdPrefix = "projects/" + projectId;
|
|
280
|
+
return _this.projectIdPrefix;
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
MachineLearningApiClient.prototype.getModelName = function (modelId) {
|
|
284
|
+
if (!validator.isNonEmptyString(modelId)) {
|
|
285
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Model ID must be a non-empty string.');
|
|
286
|
+
}
|
|
287
|
+
if (modelId.indexOf('/') !== -1) {
|
|
288
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Model ID must not contain any "/" characters.');
|
|
289
|
+
}
|
|
290
|
+
return "models/" + modelId;
|
|
291
|
+
};
|
|
292
|
+
return MachineLearningApiClient;
|
|
293
|
+
}());
|
|
294
|
+
exports.MachineLearningApiClient = MachineLearningApiClient;
|
|
295
|
+
var ERROR_CODE_MAPPING = {
|
|
296
|
+
INVALID_ARGUMENT: 'invalid-argument',
|
|
297
|
+
NOT_FOUND: 'not-found',
|
|
298
|
+
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
|
299
|
+
UNAUTHENTICATED: 'authentication-error',
|
|
300
|
+
UNKNOWN: 'unknown-error',
|
|
301
|
+
};
|
|
302
|
+
function extractModelId(resourceName) {
|
|
303
|
+
return resourceName.split('/').pop();
|
|
304
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* Copyright 2020 Google Inc.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
var __extends = (this && this.__extends) || (function () {
|
|
19
|
+
var extendStatics = function (d, b) {
|
|
20
|
+
extendStatics = Object.setPrototypeOf ||
|
|
21
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
23
|
+
return extendStatics(d, b);
|
|
24
|
+
};
|
|
25
|
+
return function (d, b) {
|
|
26
|
+
extendStatics(d, b);
|
|
27
|
+
function __() { this.constructor = d; }
|
|
28
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
29
|
+
};
|
|
30
|
+
})();
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.FirebaseMachineLearningError = void 0;
|
|
33
|
+
var error_1 = require("../utils/error");
|
|
34
|
+
var FirebaseMachineLearningError = /** @class */ (function (_super) {
|
|
35
|
+
__extends(FirebaseMachineLearningError, _super);
|
|
36
|
+
function FirebaseMachineLearningError(code, message) {
|
|
37
|
+
return _super.call(this, 'machine-learning', code, message) || this;
|
|
38
|
+
}
|
|
39
|
+
FirebaseMachineLearningError.fromOperationError = function (code, message) {
|
|
40
|
+
switch (code) {
|
|
41
|
+
case 1: return new FirebaseMachineLearningError('cancelled', message);
|
|
42
|
+
case 2: return new FirebaseMachineLearningError('unknown-error', message);
|
|
43
|
+
case 3: return new FirebaseMachineLearningError('invalid-argument', message);
|
|
44
|
+
case 4: return new FirebaseMachineLearningError('deadline-exceeded', message);
|
|
45
|
+
case 5: return new FirebaseMachineLearningError('not-found', message);
|
|
46
|
+
case 6: return new FirebaseMachineLearningError('already-exists', message);
|
|
47
|
+
case 7: return new FirebaseMachineLearningError('permission-denied', message);
|
|
48
|
+
case 8: return new FirebaseMachineLearningError('resource-exhausted', message);
|
|
49
|
+
case 9: return new FirebaseMachineLearningError('failed-precondition', message);
|
|
50
|
+
case 10: return new FirebaseMachineLearningError('aborted', message);
|
|
51
|
+
case 11: return new FirebaseMachineLearningError('out-of-range', message);
|
|
52
|
+
case 13: return new FirebaseMachineLearningError('internal-error', message);
|
|
53
|
+
case 14: return new FirebaseMachineLearningError('service-unavailable', message);
|
|
54
|
+
case 15: return new FirebaseMachineLearningError('data-loss', message);
|
|
55
|
+
case 16: return new FirebaseMachineLearningError('unauthenticated', message);
|
|
56
|
+
default:
|
|
57
|
+
return new FirebaseMachineLearningError('unknown-error', message);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return FirebaseMachineLearningError;
|
|
61
|
+
}(error_1.PrefixedFirebaseError));
|
|
62
|
+
exports.FirebaseMachineLearningError = FirebaseMachineLearningError;
|