firebase-admin 10.1.0 → 11.0.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/README.md +1 -1
- package/lib/app/core.d.ts +1 -1
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +1 -1
- package/lib/app/credential-factory.js +8 -8
- package/lib/app/credential-internal.d.ts +3 -1
- package/lib/app/credential-internal.js +103 -95
- package/lib/app/credential.d.ts +1 -1
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +1 -1
- package/lib/app/firebase-app.js +76 -91
- package/lib/app/firebase-namespace.d.ts +1 -1
- package/lib/app/firebase-namespace.js +209 -279
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +4 -4
- package/lib/app/lifecycle.d.ts +1 -1
- package/lib/app/lifecycle.js +37 -43
- package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
- package/lib/app-check/app-check-api-client-internal.js +54 -73
- package/lib/app-check/app-check-api.d.ts +1 -1
- package/lib/app-check/app-check-api.js +1 -1
- package/lib/app-check/app-check-namespace.d.ts +1 -1
- package/lib/app-check/app-check-namespace.js +1 -1
- package/lib/app-check/app-check.d.ts +1 -1
- package/lib/app-check/app-check.js +17 -19
- package/lib/app-check/index.d.ts +1 -1
- package/lib/app-check/index.js +7 -7
- package/lib/app-check/token-generator.d.ts +1 -1
- package/lib/app-check/token-generator.js +47 -52
- package/lib/app-check/token-verifier.d.ts +1 -1
- package/lib/app-check/token-verifier.js +46 -50
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +10 -11
- package/lib/auth/auth-api-request.d.ts +1 -1
- package/lib/auth/auth-api-request.js +355 -382
- package/lib/auth/auth-config.d.ts +1 -1
- package/lib/auth/auth-config.js +95 -106
- package/lib/auth/auth-namespace.d.ts +1 -1
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +1 -1
- package/lib/auth/auth.js +20 -40
- package/lib/auth/base-auth.d.ts +26 -1
- package/lib/auth/base-auth.js +162 -142
- package/lib/auth/identifier.d.ts +1 -1
- package/lib/auth/identifier.js +2 -2
- package/lib/auth/index.d.ts +1 -1
- package/lib/auth/index.js +7 -7
- package/lib/auth/tenant-manager.d.ts +1 -1
- package/lib/auth/tenant-manager.js +49 -71
- package/lib/auth/tenant.d.ts +1 -1
- package/lib/auth/tenant.js +44 -55
- package/lib/auth/token-generator.d.ts +1 -1
- package/lib/auth/token-generator.js +49 -53
- package/lib/auth/token-verifier.d.ts +1 -1
- package/lib/auth/token-verifier.js +83 -91
- package/lib/auth/user-import-builder.d.ts +1 -1
- package/lib/auth/user-import-builder.js +70 -73
- package/lib/auth/user-record.d.ts +1 -1
- package/lib/auth/user-record.js +61 -84
- package/lib/credential/index.d.ts +1 -1
- package/lib/credential/index.js +2 -2
- package/lib/database/database-namespace.d.ts +1 -1
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +1 -1
- package/lib/database/database.js +92 -108
- package/lib/database/index.d.ts +1 -1
- package/lib/database/index.js +10 -10
- package/lib/default-namespace.d.ts +1 -1
- package/lib/default-namespace.js +2 -2
- package/lib/esm/eventarc/index.js +5 -0
- package/lib/esm/functions/index.js +5 -0
- package/lib/eventarc/cloudevent.d.ts +84 -0
- package/lib/eventarc/cloudevent.js +19 -0
- package/lib/eventarc/eventarc-client-internal.d.ts +18 -0
- package/lib/eventarc/eventarc-client-internal.js +139 -0
- package/lib/eventarc/eventarc-utils.d.ts +31 -0
- package/lib/eventarc/eventarc-utils.js +125 -0
- package/lib/eventarc/eventarc.d.ts +107 -0
- package/lib/eventarc/eventarc.js +125 -0
- package/lib/eventarc/index.d.ts +53 -0
- package/lib/eventarc/index.js +64 -0
- package/lib/firebase-namespace-api.d.ts +1 -1
- package/lib/firebase-namespace-api.js +8 -3
- package/lib/firestore/firestore-internal.d.ts +1 -1
- package/lib/firestore/firestore-internal.js +28 -37
- package/lib/firestore/firestore-namespace.d.ts +9 -1
- package/lib/firestore/firestore-namespace.js +2 -2
- package/lib/firestore/index.d.ts +2 -2
- package/lib/firestore/index.js +7 -7
- package/lib/functions/functions-api-client-internal.d.ts +32 -0
- package/lib/functions/functions-api-client-internal.js +257 -0
- package/lib/functions/functions-api.d.ts +67 -0
- package/lib/functions/functions-api.js +19 -0
- package/lib/functions/functions.d.ts +63 -0
- package/lib/functions/functions.js +97 -0
- package/lib/functions/index.d.ts +53 -0
- package/lib/functions/index.js +64 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -4
- package/lib/installations/index.d.ts +1 -1
- package/lib/installations/index.js +6 -6
- package/lib/installations/installations-namespace.d.ts +1 -1
- package/lib/installations/installations-namespace.js +1 -1
- package/lib/installations/installations-request-handler.d.ts +1 -1
- package/lib/installations/installations-request-handler.js +33 -36
- package/lib/installations/installations.d.ts +1 -1
- package/lib/installations/installations.js +17 -22
- package/lib/instance-id/index.d.ts +1 -1
- package/lib/instance-id/index.js +6 -6
- package/lib/instance-id/instance-id-namespace.d.ts +1 -1
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +1 -1
- package/lib/instance-id/instance-id.js +21 -26
- package/lib/machine-learning/index.d.ts +1 -1
- package/lib/machine-learning/index.js +7 -7
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +110 -124
- package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
- package/lib/machine-learning/machine-learning-namespace.js +1 -1
- package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
- package/lib/machine-learning/machine-learning-utils.js +9 -24
- package/lib/machine-learning/machine-learning.d.ts +1 -1
- package/lib/machine-learning/machine-learning.js +146 -207
- package/lib/messaging/batch-request-internal.d.ts +1 -1
- package/lib/messaging/batch-request-internal.js +33 -35
- package/lib/messaging/index.d.ts +1 -1
- package/lib/messaging/index.js +7 -7
- package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
- package/lib/messaging/messaging-api-request-internal.js +38 -40
- package/lib/messaging/messaging-api.d.ts +1 -1
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +1 -1
- package/lib/messaging/messaging-errors-internal.js +12 -13
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +51 -51
- package/lib/messaging/messaging-namespace.d.ts +1 -1
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +1 -1
- package/lib/messaging/messaging.js +184 -208
- package/lib/project-management/android-app.d.ts +1 -1
- package/lib/project-management/android-app.js +41 -43
- package/lib/project-management/app-metadata.d.ts +1 -1
- package/lib/project-management/app-metadata.js +1 -1
- package/lib/project-management/index.d.ts +1 -1
- package/lib/project-management/index.js +7 -7
- package/lib/project-management/ios-app.d.ts +1 -1
- package/lib/project-management/ios-app.js +25 -26
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
- package/lib/project-management/project-management-api-request-internal.js +84 -89
- package/lib/project-management/project-management-namespace.d.ts +1 -1
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +1 -1
- package/lib/project-management/project-management.js +80 -87
- package/lib/remote-config/index.d.ts +1 -1
- package/lib/remote-config/index.js +7 -7
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +116 -154
- package/lib/remote-config/remote-config-api.d.ts +1 -1
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +1 -1
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +1 -1
- package/lib/remote-config/remote-config.js +51 -59
- package/lib/security-rules/index.d.ts +1 -1
- package/lib/security-rules/index.js +7 -7
- package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +95 -107
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +6 -21
- package/lib/security-rules/security-rules-namespace.d.ts +1 -1
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +1 -1
- package/lib/security-rules/security-rules.js +82 -91
- package/lib/storage/index.d.ts +1 -1
- package/lib/storage/index.js +7 -7
- package/lib/storage/storage-namespace.d.ts +1 -1
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +25 -30
- package/lib/utils/api-request.d.ts +3 -1
- package/lib/utils/api-request.js +278 -356
- package/lib/utils/crypto-signer.d.ts +1 -1
- package/lib/utils/crypto-signer.js +58 -93
- package/lib/utils/deep-copy.d.ts +1 -1
- package/lib/utils/deep-copy.js +3 -3
- package/lib/utils/error.d.ts +5 -1
- package/lib/utils/error.js +613 -677
- package/lib/utils/index.d.ts +43 -1
- package/lib/utils/index.js +99 -34
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/jwt.js +97 -123
- package/lib/utils/validator.d.ts +1 -1
- package/lib/utils/validator.js +13 -13
- package/package.json +43 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getMachineLearning = void 0;
|
|
19
|
+
exports.getMachineLearning = exports.Model = exports.MachineLearning = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Firebase Machine Learning.
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const app_1 = require("../app");
|
|
26
|
+
const machine_learning_1 = require("./machine-learning");
|
|
27
27
|
var machine_learning_2 = require("./machine-learning");
|
|
28
28
|
Object.defineProperty(exports, "MachineLearning", { enumerable: true, get: function () { return machine_learning_2.MachineLearning; } });
|
|
29
29
|
Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return machine_learning_2.Model; } });
|
|
@@ -55,9 +55,9 @@ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { r
|
|
|
55
55
|
*/
|
|
56
56
|
function getMachineLearning(app) {
|
|
57
57
|
if (typeof app === 'undefined') {
|
|
58
|
-
app = app_1.getApp();
|
|
58
|
+
app = (0, app_1.getApp)();
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
return firebaseApp.getOrInitService('machineLearning',
|
|
60
|
+
const firebaseApp = app;
|
|
61
|
+
return firebaseApp.getOrInitService('machineLearning', (app) => new machine_learning_1.MachineLearning(app));
|
|
62
62
|
}
|
|
63
63
|
exports.getMachineLearning = getMachineLearning;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -17,22 +17,21 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.MachineLearningApiClient = exports.isGcsTfliteModelOptions = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'X-Firebase-Client':
|
|
20
|
+
const api_request_1 = require("../utils/api-request");
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
|
+
const utils = require("../utils/index");
|
|
23
|
+
const validator = require("../utils/validator");
|
|
24
|
+
const machine_learning_utils_1 = require("./machine-learning-utils");
|
|
25
|
+
const ML_V1BETA2_API = 'https://firebaseml.googleapis.com/v1beta2';
|
|
26
|
+
const FIREBASE_VERSION_HEADER = {
|
|
27
|
+
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`,
|
|
28
28
|
};
|
|
29
29
|
// Operation polling defaults
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const POLL_DEFAULT_MAX_TIME_MILLISECONDS = 120000; // Maximum overall 2 minutes
|
|
31
|
+
const POLL_BASE_WAIT_TIME_MILLISECONDS = 3000; // Start with 3 second delay
|
|
32
|
+
const POLL_MAX_WAIT_TIME_MILLISECONDS = 30000; // Maximum 30 second delay
|
|
33
33
|
function isGcsTfliteModelOptions(options) {
|
|
34
|
-
|
|
35
|
-
var gcsUri = (_b = (_a = options) === null || _a === void 0 ? void 0 : _a.tfliteModel) === null || _b === void 0 ? void 0 : _b.gcsTfliteUri;
|
|
34
|
+
const gcsUri = options?.tfliteModel?.gcsTfliteUri;
|
|
36
35
|
return typeof gcsUri !== 'undefined';
|
|
37
36
|
}
|
|
38
37
|
exports.isGcsTfliteModelOptions = isGcsTfliteModelOptions;
|
|
@@ -41,8 +40,8 @@ exports.isGcsTfliteModelOptions = isGcsTfliteModelOptions;
|
|
|
41
40
|
*
|
|
42
41
|
* @internal
|
|
43
42
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
class MachineLearningApiClient {
|
|
44
|
+
constructor(app) {
|
|
46
45
|
this.app = app;
|
|
47
46
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
48
47
|
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'First argument passed to admin.machineLearning() must be a valid '
|
|
@@ -50,156 +49,147 @@ var MachineLearningApiClient = /** @class */ (function () {
|
|
|
50
49
|
}
|
|
51
50
|
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
var _this = this;
|
|
52
|
+
createModel(model) {
|
|
55
53
|
if (!validator.isNonNullObject(model) ||
|
|
56
54
|
!validator.isNonEmptyString(model.displayName)) {
|
|
57
|
-
|
|
55
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid model content.');
|
|
58
56
|
return Promise.reject(err);
|
|
59
57
|
}
|
|
60
58
|
return this.getProjectUrl()
|
|
61
|
-
.then(
|
|
62
|
-
|
|
59
|
+
.then((url) => {
|
|
60
|
+
const request = {
|
|
63
61
|
method: 'POST',
|
|
64
|
-
url: url
|
|
62
|
+
url: `${url}/models`,
|
|
65
63
|
data: model,
|
|
66
64
|
};
|
|
67
|
-
return
|
|
65
|
+
return this.sendRequest(request);
|
|
68
66
|
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var _this = this;
|
|
67
|
+
}
|
|
68
|
+
updateModel(modelId, model, updateMask) {
|
|
72
69
|
if (!validator.isNonEmptyString(modelId) ||
|
|
73
70
|
!validator.isNonNullObject(model) ||
|
|
74
71
|
!validator.isNonEmptyArray(updateMask)) {
|
|
75
|
-
|
|
72
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid model or mask content.');
|
|
76
73
|
return Promise.reject(err);
|
|
77
74
|
}
|
|
78
75
|
return this.getProjectUrl()
|
|
79
|
-
.then(
|
|
80
|
-
|
|
76
|
+
.then((url) => {
|
|
77
|
+
const request = {
|
|
81
78
|
method: 'PATCH',
|
|
82
|
-
url: url
|
|
79
|
+
url: `${url}/models/${modelId}?updateMask=${updateMask.join()}`,
|
|
83
80
|
data: model,
|
|
84
81
|
};
|
|
85
|
-
return
|
|
82
|
+
return this.sendRequest(request);
|
|
86
83
|
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
var _this = this;
|
|
84
|
+
}
|
|
85
|
+
getModel(modelId) {
|
|
90
86
|
return Promise.resolve()
|
|
91
|
-
.then(
|
|
92
|
-
return
|
|
87
|
+
.then(() => {
|
|
88
|
+
return this.getModelName(modelId);
|
|
93
89
|
})
|
|
94
|
-
.then(
|
|
95
|
-
return
|
|
90
|
+
.then((modelName) => {
|
|
91
|
+
return this.getResourceWithShortName(modelName);
|
|
96
92
|
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var _this = this;
|
|
93
|
+
}
|
|
94
|
+
getOperation(operationName) {
|
|
100
95
|
return Promise.resolve()
|
|
101
|
-
.then(
|
|
102
|
-
return
|
|
96
|
+
.then(() => {
|
|
97
|
+
return this.getResourceWithFullName(operationName);
|
|
103
98
|
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
var _this = this;
|
|
107
|
-
if (options === void 0) { options = {}; }
|
|
99
|
+
}
|
|
100
|
+
listModels(options = {}) {
|
|
108
101
|
if (!validator.isNonNullObject(options)) {
|
|
109
|
-
|
|
102
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid ListModelsOptions');
|
|
110
103
|
return Promise.reject(err);
|
|
111
104
|
}
|
|
112
105
|
if (typeof options.filter !== 'undefined' && !validator.isNonEmptyString(options.filter)) {
|
|
113
|
-
|
|
106
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid list filter.');
|
|
114
107
|
return Promise.reject(err);
|
|
115
108
|
}
|
|
116
109
|
if (typeof options.pageSize !== 'undefined') {
|
|
117
110
|
if (!validator.isNumber(options.pageSize)) {
|
|
118
|
-
|
|
111
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Invalid page size.');
|
|
119
112
|
return Promise.reject(err);
|
|
120
113
|
}
|
|
121
114
|
if (options.pageSize < 1 || options.pageSize > 100) {
|
|
122
|
-
|
|
115
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Page size must be between 1 and 100.');
|
|
123
116
|
return Promise.reject(err);
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
if (typeof options.pageToken !== 'undefined' && !validator.isNonEmptyString(options.pageToken)) {
|
|
127
|
-
|
|
120
|
+
const err = new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Next page token must be a non-empty string.');
|
|
128
121
|
return Promise.reject(err);
|
|
129
122
|
}
|
|
130
123
|
return this.getProjectUrl()
|
|
131
|
-
.then(
|
|
132
|
-
|
|
124
|
+
.then((url) => {
|
|
125
|
+
const request = {
|
|
133
126
|
method: 'GET',
|
|
134
|
-
url: url
|
|
127
|
+
url: `${url}/models`,
|
|
135
128
|
data: options,
|
|
136
129
|
};
|
|
137
|
-
return
|
|
130
|
+
return this.sendRequest(request);
|
|
138
131
|
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
var _this = this;
|
|
132
|
+
}
|
|
133
|
+
deleteModel(modelId) {
|
|
142
134
|
return this.getProjectUrl()
|
|
143
|
-
.then(
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
.then((url) => {
|
|
136
|
+
const modelName = this.getModelName(modelId);
|
|
137
|
+
const request = {
|
|
146
138
|
method: 'DELETE',
|
|
147
|
-
url: url
|
|
139
|
+
url: `${url}/${modelName}`,
|
|
148
140
|
};
|
|
149
|
-
return
|
|
141
|
+
return this.sendRequest(request);
|
|
150
142
|
});
|
|
151
|
-
}
|
|
143
|
+
}
|
|
152
144
|
/**
|
|
153
145
|
* Handles a Long Running Operation coming back from the server.
|
|
154
146
|
*
|
|
155
147
|
* @param op - The operation to handle
|
|
156
148
|
* @param options - The options for polling
|
|
157
149
|
*/
|
|
158
|
-
|
|
150
|
+
handleOperation(op, options) {
|
|
159
151
|
if (op.done) {
|
|
160
152
|
if (op.response) {
|
|
161
153
|
return Promise.resolve(op.response);
|
|
162
154
|
}
|
|
163
155
|
else if (op.error) {
|
|
164
|
-
|
|
156
|
+
const err = machine_learning_utils_1.FirebaseMachineLearningError.fromOperationError(op.error.code, op.error.message);
|
|
165
157
|
return Promise.reject(err);
|
|
166
158
|
}
|
|
167
159
|
// Done operations must have either a response or an error.
|
|
168
160
|
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-server-response', 'Invalid operation response.');
|
|
169
161
|
}
|
|
170
162
|
// Operation is not done
|
|
171
|
-
if (options
|
|
163
|
+
if (options?.wait) {
|
|
172
164
|
return this.pollOperationWithExponentialBackoff(op.name, options);
|
|
173
165
|
}
|
|
174
|
-
|
|
175
|
-
|
|
166
|
+
const metadata = op.metadata || {};
|
|
167
|
+
const metadataType = metadata['@type'] || '';
|
|
176
168
|
if (!metadataType.includes('ModelOperationMetadata')) {
|
|
177
|
-
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-server-response',
|
|
169
|
+
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-server-response', `Unknown Metadata type: ${JSON.stringify(metadata)}`);
|
|
178
170
|
}
|
|
179
171
|
return this.getModel(extractModelId(metadata.name));
|
|
180
|
-
}
|
|
172
|
+
}
|
|
181
173
|
// baseWaitMillis and maxWaitMillis should only ever be modified by unit tests to run faster.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return _this.getOperation(opName)
|
|
191
|
-
.then(function (responseData) {
|
|
174
|
+
pollOperationWithExponentialBackoff(opName, options) {
|
|
175
|
+
const maxTimeMilliseconds = options?.maxTimeMillis ?? POLL_DEFAULT_MAX_TIME_MILLISECONDS;
|
|
176
|
+
const baseWaitMillis = options?.baseWaitMillis ?? POLL_BASE_WAIT_TIME_MILLISECONDS;
|
|
177
|
+
const maxWaitMillis = options?.maxWaitMillis ?? POLL_MAX_WAIT_TIME_MILLISECONDS;
|
|
178
|
+
const poller = new api_request_1.ExponentialBackoffPoller(baseWaitMillis, maxWaitMillis, maxTimeMilliseconds);
|
|
179
|
+
return poller.poll(() => {
|
|
180
|
+
return this.getOperation(opName)
|
|
181
|
+
.then((responseData) => {
|
|
192
182
|
if (!responseData.done) {
|
|
193
183
|
return null;
|
|
194
184
|
}
|
|
195
185
|
if (responseData.error) {
|
|
196
|
-
|
|
186
|
+
const err = machine_learning_utils_1.FirebaseMachineLearningError.fromOperationError(responseData.error.code, responseData.error.message);
|
|
197
187
|
throw err;
|
|
198
188
|
}
|
|
199
189
|
return responseData.response;
|
|
200
190
|
});
|
|
201
191
|
});
|
|
202
|
-
}
|
|
192
|
+
}
|
|
203
193
|
/**
|
|
204
194
|
* Gets the specified resource from the ML API. Resource names must be the short names without project
|
|
205
195
|
* ID prefix (e.g. `models/123456789`).
|
|
@@ -207,92 +197,88 @@ var MachineLearningApiClient = /** @class */ (function () {
|
|
|
207
197
|
* @param {string} name Short name of the resource to get. e.g. 'models/12345'
|
|
208
198
|
* @returns {Promise<T>} A promise that fulfills with the resource.
|
|
209
199
|
*/
|
|
210
|
-
|
|
211
|
-
var _this = this;
|
|
200
|
+
getResourceWithShortName(name) {
|
|
212
201
|
return this.getProjectUrl()
|
|
213
|
-
.then(
|
|
214
|
-
|
|
202
|
+
.then((url) => {
|
|
203
|
+
const request = {
|
|
215
204
|
method: 'GET',
|
|
216
|
-
url: url
|
|
205
|
+
url: `${url}/${name}`,
|
|
217
206
|
};
|
|
218
|
-
return
|
|
207
|
+
return this.sendRequest(request);
|
|
219
208
|
});
|
|
220
|
-
}
|
|
209
|
+
}
|
|
221
210
|
/**
|
|
222
211
|
* Gets the specified resource from the ML API. Resource names must be the full names including project
|
|
223
212
|
* number prefix.
|
|
224
213
|
* @param fullName - Full resource name of the resource to get. e.g. projects/123465/operations/987654
|
|
225
214
|
* @returns {Promise<T>} A promise that fulfulls with the resource.
|
|
226
215
|
*/
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
getResourceWithFullName(fullName) {
|
|
217
|
+
const request = {
|
|
229
218
|
method: 'GET',
|
|
230
|
-
url: ML_V1BETA2_API
|
|
219
|
+
url: `${ML_V1BETA2_API}/${fullName}`
|
|
231
220
|
};
|
|
232
221
|
return this.sendRequest(request);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
var _this = this;
|
|
222
|
+
}
|
|
223
|
+
sendRequest(request) {
|
|
236
224
|
request.headers = FIREBASE_VERSION_HEADER;
|
|
237
225
|
return this.httpClient.send(request)
|
|
238
|
-
.then(
|
|
226
|
+
.then((resp) => {
|
|
239
227
|
return resp.data;
|
|
240
228
|
})
|
|
241
|
-
.catch(
|
|
242
|
-
throw
|
|
229
|
+
.catch((err) => {
|
|
230
|
+
throw this.toFirebaseError(err);
|
|
243
231
|
});
|
|
244
|
-
}
|
|
245
|
-
|
|
232
|
+
}
|
|
233
|
+
toFirebaseError(err) {
|
|
246
234
|
if (err instanceof error_1.PrefixedFirebaseError) {
|
|
247
235
|
return err;
|
|
248
236
|
}
|
|
249
|
-
|
|
237
|
+
const response = err.response;
|
|
250
238
|
if (!response.isJson()) {
|
|
251
|
-
return new machine_learning_utils_1.FirebaseMachineLearningError('unknown-error',
|
|
239
|
+
return new machine_learning_utils_1.FirebaseMachineLearningError('unknown-error', `Unexpected response with status: ${response.status} and body: ${response.text}`);
|
|
252
240
|
}
|
|
253
|
-
|
|
254
|
-
|
|
241
|
+
const error = response.data.error || {};
|
|
242
|
+
let code = 'unknown-error';
|
|
255
243
|
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
|
256
244
|
code = ERROR_CODE_MAPPING[error.status];
|
|
257
245
|
}
|
|
258
|
-
|
|
246
|
+
const message = error.message || `Unknown server error: ${response.text}`;
|
|
259
247
|
return new machine_learning_utils_1.FirebaseMachineLearningError(code, message);
|
|
260
|
-
}
|
|
261
|
-
|
|
248
|
+
}
|
|
249
|
+
getProjectUrl() {
|
|
262
250
|
return this.getProjectIdPrefix()
|
|
263
|
-
.then(
|
|
264
|
-
return ML_V1BETA2_API
|
|
251
|
+
.then((projectIdPrefix) => {
|
|
252
|
+
return `${ML_V1BETA2_API}/${projectIdPrefix}`;
|
|
265
253
|
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
var _this = this;
|
|
254
|
+
}
|
|
255
|
+
getProjectIdPrefix() {
|
|
269
256
|
if (this.projectIdPrefix) {
|
|
270
257
|
return Promise.resolve(this.projectIdPrefix);
|
|
271
258
|
}
|
|
272
259
|
return utils.findProjectId(this.app)
|
|
273
|
-
.then(
|
|
260
|
+
.then((projectId) => {
|
|
274
261
|
if (!validator.isNonEmptyString(projectId)) {
|
|
275
262
|
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
|
276
263
|
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
|
277
264
|
+ 'environment variable.');
|
|
278
265
|
}
|
|
279
|
-
|
|
280
|
-
return
|
|
266
|
+
this.projectIdPrefix = `projects/${projectId}`;
|
|
267
|
+
return this.projectIdPrefix;
|
|
281
268
|
});
|
|
282
|
-
}
|
|
283
|
-
|
|
269
|
+
}
|
|
270
|
+
getModelName(modelId) {
|
|
284
271
|
if (!validator.isNonEmptyString(modelId)) {
|
|
285
272
|
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Model ID must be a non-empty string.');
|
|
286
273
|
}
|
|
287
274
|
if (modelId.indexOf('/') !== -1) {
|
|
288
275
|
throw new machine_learning_utils_1.FirebaseMachineLearningError('invalid-argument', 'Model ID must not contain any "/" characters.');
|
|
289
276
|
}
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
}());
|
|
277
|
+
return `models/${modelId}`;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
294
280
|
exports.MachineLearningApiClient = MachineLearningApiClient;
|
|
295
|
-
|
|
281
|
+
const ERROR_CODE_MAPPING = {
|
|
296
282
|
INVALID_ARGUMENT: 'invalid-argument',
|
|
297
283
|
NOT_FOUND: 'not-found',
|
|
298
284
|
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -15,28 +15,11 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
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
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
19
|
exports.FirebaseMachineLearningError = void 0;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function FirebaseMachineLearningError(code, message) {
|
|
37
|
-
return _super.call(this, 'machine-learning', code, message) || this;
|
|
38
|
-
}
|
|
39
|
-
FirebaseMachineLearningError.fromOperationError = function (code, message) {
|
|
20
|
+
const error_1 = require("../utils/error");
|
|
21
|
+
class FirebaseMachineLearningError extends error_1.PrefixedFirebaseError {
|
|
22
|
+
static fromOperationError(code, message) {
|
|
40
23
|
switch (code) {
|
|
41
24
|
case 1: return new FirebaseMachineLearningError('cancelled', message);
|
|
42
25
|
case 2: return new FirebaseMachineLearningError('unknown-error', message);
|
|
@@ -56,7 +39,9 @@ var FirebaseMachineLearningError = /** @class */ (function (_super) {
|
|
|
56
39
|
default:
|
|
57
40
|
return new FirebaseMachineLearningError('unknown-error', message);
|
|
58
41
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
}
|
|
43
|
+
constructor(code, message) {
|
|
44
|
+
super('machine-learning', code, message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
62
47
|
exports.FirebaseMachineLearningError = FirebaseMachineLearningError;
|