@e-mc/cloud 0.0.1 → 0.0.3
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/index.js +18 -8
- package/package.json +4 -4
- package/atlas/index.js +0 -193
- package/aws/download/index.js +0 -44
- package/aws/index.js +0 -381
- package/aws/upload/index.js +0 -137
- package/aws-v3/download/index.js +0 -42
- package/aws-v3/index.js +0 -285
- package/aws-v3/upload/index.js +0 -157
- package/azure/download/index.js +0 -40
- package/azure/index.js +0 -236
- package/azure/upload/index.js +0 -124
- package/gcp/download/index.js +0 -86
- package/gcp/index.js +0 -801
- package/gcp/upload/index.js +0 -234
- package/ibm/download/index.js +0 -13
- package/ibm/index.js +0 -229
- package/ibm/upload/index.js +0 -13
- package/minio/download/index.js +0 -44
- package/minio/index.js +0 -182
- package/minio/upload/index.js +0 -135
- package/oci/download/index.js +0 -13
- package/oci/index.js +0 -183
- package/oci/upload/index.js +0 -13
package/gcp/index.js
DELETED
|
@@ -1,801 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProjectId = exports.createBucketRequest = exports.setPredefinedAcl = exports.setPublicRead = exports.executeBatchQuery = exports.executeQuery = exports.deleteObjectsV2 = exports.deleteObjects = exports.setBucketWebsite = exports.setBucketPolicy = exports.createBucketV2 = exports.createBucket = exports.createDatabaseClient = exports.createStorageClient = exports.validateDatabase = exports.validateStorage = exports.isFirebaseApp = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const util_1 = require("../util");
|
|
6
|
-
const types_1 = require("../../types");
|
|
7
|
-
const module_1 = require("../../module");
|
|
8
|
-
const index_1 = require("../index");
|
|
9
|
-
const FIREBASE_DB = {};
|
|
10
|
-
const FIREBASE_STORAGE = {};
|
|
11
|
-
const ADMIN_DB = {};
|
|
12
|
-
const ADMIN_STORAGE = {};
|
|
13
|
-
function getApp(credential, isDB) {
|
|
14
|
-
var _a, _b;
|
|
15
|
-
const { projectId, databaseURL, storageBucket, apiKey, authDomain } = credential;
|
|
16
|
-
if (apiKey && authDomain) {
|
|
17
|
-
const { getApps, initializeApp } = require('@firebase/app');
|
|
18
|
-
let app;
|
|
19
|
-
for (const item of getApps()) {
|
|
20
|
-
const options = item.options;
|
|
21
|
-
if (projectId === options.projectId && apiKey === options.apiKey && authDomain === options.authDomain && (!isDB || isDB && databaseURL === options.databaseURL)) {
|
|
22
|
-
app = item;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!app) {
|
|
27
|
-
const firebaseKey = (projectId || '') + '_' + apiKey + '_' + authDomain + (isDB ? '_' + databaseURL : '');
|
|
28
|
-
app = isDB ? FIREBASE_DB[firebaseKey] || (FIREBASE_DB[firebaseKey] = initializeApp({ ...credential, databaseURL }, firebaseKey)) : FIREBASE_STORAGE[firebaseKey] || (FIREBASE_STORAGE[firebaseKey] = initializeApp({ ...credential, storageBucket }, firebaseKey));
|
|
29
|
-
}
|
|
30
|
-
if (isDB) {
|
|
31
|
-
const { getDatabase, goOnline } = require('@firebase/database');
|
|
32
|
-
const db = getDatabase(app);
|
|
33
|
-
goOnline(db);
|
|
34
|
-
return db;
|
|
35
|
-
}
|
|
36
|
-
const { getStorage } = require('@firebase/storage');
|
|
37
|
-
return getStorage(app);
|
|
38
|
-
}
|
|
39
|
-
{
|
|
40
|
-
const { getApps, initializeApp, applicationDefault } = require('firebase-admin/app');
|
|
41
|
-
let app;
|
|
42
|
-
for (const item of getApps()) {
|
|
43
|
-
if (!isDB && storageBucket && item.name === storageBucket || isDB && databaseURL && item.name === databaseURL) {
|
|
44
|
-
app = item;
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!app) {
|
|
49
|
-
app = isDB ? ADMIN_DB[_a = databaseURL || '[DEFAULT]'] || (ADMIN_DB[_a] = initializeApp({ credential: applicationDefault(), databaseURL }, databaseURL)) : ADMIN_STORAGE[_b = storageBucket || '[DEFAULT]'] || (ADMIN_STORAGE[_b] = initializeApp({ credential: applicationDefault(), storageBucket }, storageBucket));
|
|
50
|
-
}
|
|
51
|
-
credential.admin = true;
|
|
52
|
-
if (isDB) {
|
|
53
|
-
const { getDatabase } = require('firebase-admin/database');
|
|
54
|
-
return getDatabase(app);
|
|
55
|
-
}
|
|
56
|
-
const { getStorage } = require('firebase-admin/storage');
|
|
57
|
-
return getStorage(app);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function hasBucket(client) {
|
|
61
|
-
const [exists] = await client.exists().catch(err => isErrorConflict(err) ? [true] : [false]);
|
|
62
|
-
return exists;
|
|
63
|
-
}
|
|
64
|
-
function updatePredefinedAcl(acl, values, metadata) {
|
|
65
|
-
const { generation, userProject } = metadata;
|
|
66
|
-
const items = [];
|
|
67
|
-
for (const target of acl.default ? [acl, acl.default] : [acl]) {
|
|
68
|
-
items.push(...values.map(async (value) => {
|
|
69
|
-
if (generation !== undefined) {
|
|
70
|
-
value.generation ?? (value.generation = +generation);
|
|
71
|
-
}
|
|
72
|
-
if (userProject) {
|
|
73
|
-
value.userProject || (value.userProject = userProject);
|
|
74
|
-
}
|
|
75
|
-
const entity = await target.get({ entity: value.entity }).catch(() => null);
|
|
76
|
-
if (entity) {
|
|
77
|
-
return (0, types_1.isString)(value.role) ? target.update(value) : target.delete(value);
|
|
78
|
-
}
|
|
79
|
-
if ((0, types_1.isString)(value.role)) {
|
|
80
|
-
return target.add(value);
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
return Promise.allSettled(items)
|
|
85
|
-
.then(result => {
|
|
86
|
-
const errors = [];
|
|
87
|
-
for (const item of result) {
|
|
88
|
-
if (item.status === 'rejected') {
|
|
89
|
-
errors.push(item.reason);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return errors;
|
|
93
|
-
})
|
|
94
|
-
.catch(err => [err]);
|
|
95
|
-
}
|
|
96
|
-
function setUniformBucketLevel(bucket, enabled) {
|
|
97
|
-
return bucket.setMetadata({ iamConfiguration: { uniformBucketLevelAccess: { enabled } } });
|
|
98
|
-
}
|
|
99
|
-
const getFirebasePackageName = (credential) => credential.apiKey && credential.authDomain ? 'firebase' : 'firebase-admin';
|
|
100
|
-
const hasKeyFile = (credential) => !!(credential.keyFile || credential.keyFilename || process.env.GOOGLE_APPLICATION_CREDENTIALS);
|
|
101
|
-
const isErrorConflict = (err) => (err instanceof Error) && err.code === 409;
|
|
102
|
-
function isFirebaseApp(credential, storage, admin) {
|
|
103
|
-
return !!(credential.apiKey && credential.authDomain && (storage || credential.databaseURL) || credential.product === 'firebase' && process.env.GOOGLE_APPLICATION_CREDENTIALS) && (!admin || !credential.admin);
|
|
104
|
-
}
|
|
105
|
-
exports.isFirebaseApp = isFirebaseApp;
|
|
106
|
-
function validateStorage(credential) {
|
|
107
|
-
return hasKeyFile(credential) || isFirebaseApp(credential, true);
|
|
108
|
-
}
|
|
109
|
-
exports.validateStorage = validateStorage;
|
|
110
|
-
function validateDatabase(credential, data) {
|
|
111
|
-
return hasKeyFile(credential) && !!(data.table || data.query || data.keys || data.product || data.database) || isFirebaseApp(credential);
|
|
112
|
-
}
|
|
113
|
-
exports.validateDatabase = validateDatabase;
|
|
114
|
-
function createStorageClient(credential, bucket) {
|
|
115
|
-
let packageName = '';
|
|
116
|
-
try {
|
|
117
|
-
if (isFirebaseApp(credential, true)) {
|
|
118
|
-
if (bucket) {
|
|
119
|
-
credential.storageBucket = bucket;
|
|
120
|
-
}
|
|
121
|
-
packageName = getFirebasePackageName(credential);
|
|
122
|
-
return getApp(credential, false);
|
|
123
|
-
}
|
|
124
|
-
credential.projectId || (credential.projectId = getProjectId(credential));
|
|
125
|
-
const { Storage } = require(packageName = '@google-cloud/storage');
|
|
126
|
-
return new Storage(credential);
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
this.checkPackage(err, packageName, { passThrough: true });
|
|
130
|
-
throw err;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.createStorageClient = createStorageClient;
|
|
134
|
-
function createDatabaseClient(credential, data) {
|
|
135
|
-
let packageName = '';
|
|
136
|
-
try {
|
|
137
|
-
const product = data?.product;
|
|
138
|
-
if (product === 'firebase' || isFirebaseApp(credential)) {
|
|
139
|
-
packageName = getFirebasePackageName(credential);
|
|
140
|
-
return getApp(credential, true);
|
|
141
|
-
}
|
|
142
|
-
credential.projectId || (credential.projectId = getProjectId(credential));
|
|
143
|
-
if (data) {
|
|
144
|
-
if (product === 'spanner' || !product && data.name && data.database) {
|
|
145
|
-
const { Spanner } = require(packageName = '@google-cloud/spanner');
|
|
146
|
-
return new Spanner(credential);
|
|
147
|
-
}
|
|
148
|
-
if (product === 'bigtable' || !product && data.name && data.table) {
|
|
149
|
-
const { Bigtable } = require(packageName = '@google-cloud/bigtable');
|
|
150
|
-
return new Bigtable(credential);
|
|
151
|
-
}
|
|
152
|
-
if (product === 'bigquery' || !product && data.query && !data.table) {
|
|
153
|
-
const { BigQuery } = require(packageName = '@google-cloud/bigquery');
|
|
154
|
-
return new BigQuery(credential);
|
|
155
|
-
}
|
|
156
|
-
if (product === 'datastore' || !product && data.keys) {
|
|
157
|
-
const { Datastore } = require(packageName = '@google-cloud/datastore');
|
|
158
|
-
return new Datastore(credential);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const { Firestore } = require(packageName = '@google-cloud/firestore');
|
|
162
|
-
return new Firestore(credential);
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
this.checkPackage(err, packageName, { passThrough: true });
|
|
166
|
-
throw err;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.createDatabaseClient = createDatabaseClient;
|
|
170
|
-
async function createBucket(credential, bucket, publicRead, service = 'gcp') {
|
|
171
|
-
return createBucketV2.call(this, credential, bucket, publicRead ? 'publicRead' : undefined, createBucketRequest(credential), service);
|
|
172
|
-
}
|
|
173
|
-
exports.createBucket = createBucket;
|
|
174
|
-
async function createBucketV2(credential, bucket, acl, options, service = 'gcp') {
|
|
175
|
-
if (isFirebaseApp(credential, true, true)) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
const storage = createStorageClient.call(this, credential, bucket);
|
|
179
|
-
if (await hasBucket(storage.bucket(bucket))) {
|
|
180
|
-
if (acl) {
|
|
181
|
-
await setBucketPolicy.call(this, credential, bucket, { acl }, service);
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
return storage.createBucket(bucket, options)
|
|
186
|
-
.then(async ([target]) => {
|
|
187
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket created" /* CMD_CLOUD.CREATE_BUCKET */, bucket], '', { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
188
|
-
if (acl) {
|
|
189
|
-
await setBucketPolicy.call(this, credential, bucket, { acl, bucket: target }, service);
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
})
|
|
193
|
-
.catch(async (err) => {
|
|
194
|
-
if (isErrorConflict(err)) {
|
|
195
|
-
return acl ? await setBucketPolicy.call(this, credential, bucket, { acl }, service) : true;
|
|
196
|
-
}
|
|
197
|
-
this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to create bucket" /* ERR_CLOUD.CREATE_BUCKET */, bucket], err, { ...index_1.default.LOG_CLOUD_FAIL });
|
|
198
|
-
return false;
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
exports.createBucketV2 = createBucketV2;
|
|
202
|
-
async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
203
|
-
if (isFirebaseApp(credential, true, true)) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
const client = createStorageClient.call(this, credential, bucket).bucket(bucket);
|
|
207
|
-
if (!await hasBucket(client)) {
|
|
208
|
-
this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Bucket does not exist" /* ERR_CLOUD.EXISTS_BUCKET */, bucket], (0, util_1.formatError)(service, "Bucket does not exist" /* ERR_CLOUD.EXISTS_BUCKET */), { ...index_1.default.LOG_CLOUD_FAIL, fatal: false });
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
const errors = [];
|
|
212
|
-
const acl = options.acl;
|
|
213
|
-
if (!Array.isArray(options.acl)) {
|
|
214
|
-
options.acl = undefined;
|
|
215
|
-
switch (acl) {
|
|
216
|
-
case 'private':
|
|
217
|
-
case 'projectPrivate':
|
|
218
|
-
await client.makePrivate(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
219
|
-
await setPredefinedAcl.call(this, client.acl, acl, client, '', options.bucket?.metadata);
|
|
220
|
-
break;
|
|
221
|
-
case 'authenticatedRead':
|
|
222
|
-
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
223
|
-
options = { ...options };
|
|
224
|
-
options.acl = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers', role: 'READER' }];
|
|
225
|
-
break;
|
|
226
|
-
case 'publicReadWrite':
|
|
227
|
-
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
228
|
-
options = { ...options };
|
|
229
|
-
options.acl = [{ entity: 'allUsers', role: 'WRITER' }];
|
|
230
|
-
break;
|
|
231
|
-
case 'publicRead':
|
|
232
|
-
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
233
|
-
break;
|
|
234
|
-
case 'bucketAccessUniform':
|
|
235
|
-
await setUniformBucketLevel(client, true).catch(err => errors.push(err));
|
|
236
|
-
break;
|
|
237
|
-
case 'bucketAccessACL':
|
|
238
|
-
await setUniformBucketLevel(client, false).catch(err => errors.push(err));
|
|
239
|
-
break;
|
|
240
|
-
default:
|
|
241
|
-
errors.push((0, types_1.errorValue)('Invalid ACL', module_1.default.asString(acl) || 'empty'));
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (options.acl && (options.acl = options.acl.filter(user => (0, types_1.isString)(user.entity))).length) {
|
|
246
|
-
errors.push(...await updatePredefinedAcl(client.acl, options.acl, options));
|
|
247
|
-
}
|
|
248
|
-
if (errors.length) {
|
|
249
|
-
this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to update bucket policy" /* ERR_CLOUD.POLICY_BUCKET */, bucket], errors[0], { ...index_1.default.LOG_CLOUD_FAIL, fatal: false });
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket ACL configured" /* CMD_CLOUD.ACL_BUCKET */, bucket], (0, types_1.isString)(acl) ? acl : '', { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
exports.setBucketPolicy = setBucketPolicy;
|
|
256
|
-
function setBucketWebsite(credential, bucket, options, service = 'gcp') {
|
|
257
|
-
if (isFirebaseApp(credential, true, true)) {
|
|
258
|
-
return Promise.resolve(false);
|
|
259
|
-
}
|
|
260
|
-
const website = {};
|
|
261
|
-
if ((0, types_1.isString)(options.indexPage)) {
|
|
262
|
-
website.mainPageSuffix = options.indexPage;
|
|
263
|
-
}
|
|
264
|
-
if ((0, types_1.isString)(options.errorPage)) {
|
|
265
|
-
website.notFoundPage = options.errorPage;
|
|
266
|
-
}
|
|
267
|
-
return createStorageClient.call(this, credential, bucket).bucket(bucket).setMetadata({ website })
|
|
268
|
-
.then(() => {
|
|
269
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* CMD_CLOUD.CONFIGURE_BUCKET */, bucket], website, { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
270
|
-
return true;
|
|
271
|
-
})
|
|
272
|
-
.catch(err => {
|
|
273
|
-
this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to configure bucket" /* ERR_CLOUD.CONFIGURE_BUCKET */, bucket], err, { ...index_1.default.LOG_CLOUD_FAIL, fatal: false });
|
|
274
|
-
return false;
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
exports.setBucketWebsite = setBucketWebsite;
|
|
278
|
-
function deleteObjects(credential, Bucket, service) {
|
|
279
|
-
return deleteObjectsV2.call(this, credential, Bucket, true, service);
|
|
280
|
-
}
|
|
281
|
-
exports.deleteObjects = deleteObjects;
|
|
282
|
-
async function deleteObjectsV2(credential, bucket, recursive = true, service = 'gcp') {
|
|
283
|
-
const storage = createStorageClient.call(this, credential, bucket);
|
|
284
|
-
const errors = [];
|
|
285
|
-
let promise;
|
|
286
|
-
if (isFirebaseApp(credential, true, true)) {
|
|
287
|
-
const { ref, listAll, deleteObject } = require('@firebase/storage');
|
|
288
|
-
const files = [];
|
|
289
|
-
await (async function recurse(prefix) {
|
|
290
|
-
try {
|
|
291
|
-
const { items, prefixes } = await listAll(ref(storage, prefix));
|
|
292
|
-
if (items.length) {
|
|
293
|
-
files.push(...items.map(value => value.fullPath));
|
|
294
|
-
}
|
|
295
|
-
if (recursive && prefixes.length) {
|
|
296
|
-
for (const { name } of prefixes) {
|
|
297
|
-
await recurse(module_1.default.joinPath(prefix, name));
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
catch (err) {
|
|
302
|
-
errors.push(err);
|
|
303
|
-
}
|
|
304
|
-
})('');
|
|
305
|
-
if (files.length) {
|
|
306
|
-
promise = Promise.allSettled(files.map(value => deleteObject(ref(storage, value))));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
const client = storage.bucket(bucket);
|
|
311
|
-
if (await hasBucket(client)) {
|
|
312
|
-
if (recursive) {
|
|
313
|
-
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Bucket emptied" /* CMD_CLOUD.EMPTY_BUCKET */ + ' (recursive)', bucket, { ...index_1.default.LOG_CLOUD_COMMAND }));
|
|
314
|
-
}
|
|
315
|
-
const tasks = [];
|
|
316
|
-
try {
|
|
317
|
-
const result = await client.getFiles();
|
|
318
|
-
for (const { name } of result[0]) {
|
|
319
|
-
if (name.indexOf('/') === -1) {
|
|
320
|
-
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Delete failed" /* ERR_CLOUD.DELETE_FAIL */, name], err, { ...index_1.default.LOG_CLOUD_FAIL, fatal: false })));
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
catch (err) {
|
|
325
|
-
errors.push(err);
|
|
326
|
-
}
|
|
327
|
-
if (tasks.length) {
|
|
328
|
-
promise = Promise.allSettled(tasks);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
const checkErrors = () => {
|
|
333
|
-
if (errors.length) {
|
|
334
|
-
this.formatFail(64 /* LOG_TYPE.CLOUD */, service, ["Unable to empty bucket" /* ERR_CLOUD.DELETE_BUCKET */ + (recursive ? ' (recursive)' : ''), errors.length + ' errors'], errors[0], { ...index_1.default.LOG_CLOUD_FAIL, fatal: false });
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
337
|
-
return false;
|
|
338
|
-
};
|
|
339
|
-
if (promise) {
|
|
340
|
-
return promise.then(result => {
|
|
341
|
-
errors.push(...result.filter(item => item.status === 'rejected').map((item) => item.reason));
|
|
342
|
-
if (!checkErrors()) {
|
|
343
|
-
const files = result.length + ' files';
|
|
344
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket emptied" /* CMD_CLOUD.EMPTY_BUCKET */ + ` (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
345
|
-
}
|
|
346
|
-
})
|
|
347
|
-
.catch(err => {
|
|
348
|
-
errors.push(err);
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
checkErrors();
|
|
352
|
-
}
|
|
353
|
-
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
354
|
-
async function executeQuery(credential, data, sessionKey) {
|
|
355
|
-
return (await executeBatchQuery.call(this, credential, [data], sessionKey))[0] || [];
|
|
356
|
-
}
|
|
357
|
-
exports.executeQuery = executeQuery;
|
|
358
|
-
async function executeBatchQuery(credential, batch, sessionKey) {
|
|
359
|
-
const length = batch.length;
|
|
360
|
-
const result = new Array(length);
|
|
361
|
-
const clients = [];
|
|
362
|
-
const caching = length > 0 && this.hasCache(batch[0].service, sessionKey);
|
|
363
|
-
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
364
|
-
const authItems = [];
|
|
365
|
-
const createClient = (data, type) => {
|
|
366
|
-
const client = clients[type];
|
|
367
|
-
if (client) {
|
|
368
|
-
return client;
|
|
369
|
-
}
|
|
370
|
-
const item = length === 1 ? credential : { ...credential };
|
|
371
|
-
authItems.push(item);
|
|
372
|
-
return (clients[type] = createDatabaseClient.call(this, item, data));
|
|
373
|
-
};
|
|
374
|
-
const closeClient = () => {
|
|
375
|
-
const fs = clients[3 /* DB.FIRESTORE */];
|
|
376
|
-
if (fs) {
|
|
377
|
-
fs.terminate();
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
const getFamily = (data, row, family) => {
|
|
381
|
-
const familyData = data[family];
|
|
382
|
-
for (const qualifier of Object.keys(familyData)) {
|
|
383
|
-
const items = familyData[qualifier];
|
|
384
|
-
row[qualifier] = items.length === 1 ? items[0].value : items.map(col => col.value);
|
|
385
|
-
}
|
|
386
|
-
return row;
|
|
387
|
-
};
|
|
388
|
-
const getRowData = (rowId, data) => {
|
|
389
|
-
const families = Object.keys(data);
|
|
390
|
-
const row = { '__id__': rowId };
|
|
391
|
-
if (families.length === 1) {
|
|
392
|
-
return getFamily(data, row, families[0]);
|
|
393
|
-
}
|
|
394
|
-
for (const family of families) {
|
|
395
|
-
row[family] = getFamily(data, {}, family);
|
|
396
|
-
}
|
|
397
|
-
return row;
|
|
398
|
-
};
|
|
399
|
-
for (let i = 0; i < length; ++i) {
|
|
400
|
-
const item = batch[i];
|
|
401
|
-
const { service, product, name, database, table, id, query, orderBy, keys, limit = 0, update, ignoreCache } = item;
|
|
402
|
-
const renewCache = ignoreCache === 0;
|
|
403
|
-
const cached = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache;
|
|
404
|
-
const getCache = (value) => {
|
|
405
|
-
if (ignoreCache === 1) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
cacheValue.renewCache = renewCache;
|
|
409
|
-
return this.getQueryResult(service, credential, value, cacheValue);
|
|
410
|
-
};
|
|
411
|
-
let rows, queryString = '';
|
|
412
|
-
if (product === 'bigtable' || !product && name && table && !database) {
|
|
413
|
-
const { columns, options = {} } = item;
|
|
414
|
-
if ((0, types_1.isObject)(query)) {
|
|
415
|
-
options.filter = query;
|
|
416
|
-
}
|
|
417
|
-
if (!id && limit > 0) {
|
|
418
|
-
(options.gaxOptions || (options.gaxOptions = {})).maxResults = limit;
|
|
419
|
-
}
|
|
420
|
-
if (cached && (rows = getCache(queryString = name + '_' + table + '_' + (id ? id + ((0, types_1.isArray)(columns) ? '_' + module_1.default.asString(columns, true) : '') : '') + module_1.default.asString(options, true)))) {
|
|
421
|
-
result[i] = rows;
|
|
422
|
-
continue;
|
|
423
|
-
}
|
|
424
|
-
const db = createClient(item, 4 /* DB.BIGTABLE */).instance(name).table(table);
|
|
425
|
-
if (id) {
|
|
426
|
-
const row = db.row(id);
|
|
427
|
-
if (Array.isArray(columns)) {
|
|
428
|
-
const [data] = await row.get(columns, options);
|
|
429
|
-
rows = [getRowData(id, data)];
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
const [response] = await row.get(options);
|
|
433
|
-
rows = [getRowData(response.id, response.data)];
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
rows = [];
|
|
438
|
-
await new Promise((resolve, reject) => {
|
|
439
|
-
db.createReadStream(options)
|
|
440
|
-
.on('data', row => rows.push(getRowData(row.id, row.data)))
|
|
441
|
-
.on('error', reject)
|
|
442
|
-
.on('end', resolve);
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
else if (product === 'spanner' || !product && name && database && (query || table)) {
|
|
447
|
-
const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
|
|
448
|
-
if (!(query || table && columns)) {
|
|
449
|
-
closeClient();
|
|
450
|
-
throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
|
|
451
|
-
}
|
|
452
|
-
if (!name || !database) {
|
|
453
|
-
closeClient();
|
|
454
|
-
throw (0, util_1.formatError)(item, !name ? "Missing instance name" /* ERR_DB.INSTANCE */ : "Missing database name" /* ERR_DB.NAME */);
|
|
455
|
-
}
|
|
456
|
-
const { updateType, options = {} } = item;
|
|
457
|
-
if (cached) {
|
|
458
|
-
queryString = name + '_' + database + '_' + (table ? table + module_1.default.asString(columns, true) : '') + module_1.default.asString(query, true) + limit;
|
|
459
|
-
if (!update && (rows = getCache(queryString))) {
|
|
460
|
-
result[i] = rows;
|
|
461
|
-
continue;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
const db = createClient(item, 5 /* DB.SPANNER */).instance(name).database(database, options.databasePool, options.databaseQuery);
|
|
465
|
-
if (table) {
|
|
466
|
-
if ((0, types_1.isPlainObject)(update)) {
|
|
467
|
-
await db.table(table)[updateType === 1 ? 'insert' : updateType === 2 ? 'replace' : 'update'](update, options.tableUpdate);
|
|
468
|
-
}
|
|
469
|
-
const request = (0, types_1.isPlainObject)(query) ? query : { columns };
|
|
470
|
-
request.json = true;
|
|
471
|
-
request.columns || (request.columns = item.columns);
|
|
472
|
-
request.keySet = { all: true };
|
|
473
|
-
if (limit > 0) {
|
|
474
|
-
request.limit = limit;
|
|
475
|
-
}
|
|
476
|
-
[rows] = await db.table(table).read(request, options.tableRead);
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
if ((0, types_1.isString)(update) || (0, types_1.isPlainObject)(update) && (0, types_1.isString)(update.sql)) {
|
|
480
|
-
await new Promise((resolve, reject) => {
|
|
481
|
-
db.runTransaction((err, transaction) => {
|
|
482
|
-
if (err || !transaction) {
|
|
483
|
-
reject(err || new Error("Unknown" /* ERR_MESSAGE.UNKNOWN */));
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
transaction.runUpdate(update)
|
|
487
|
-
.then(() => transaction.commit().then(() => resolve()).catch(error => reject(error)))
|
|
488
|
-
.catch(error => reject(error));
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
const request = (0, types_1.isPlainObject)(query) ? query : { sql: query };
|
|
494
|
-
request.json = true;
|
|
495
|
-
if (limit > 0) {
|
|
496
|
-
(request.gaxOptions || (request.gaxOptions = {})).maxResults = limit;
|
|
497
|
-
}
|
|
498
|
-
[rows] = await db.run(request);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
else if (product === 'firebase' || product === 'bigquery' || !product && !table && query) {
|
|
502
|
-
if (!(0, types_1.isString)(query)) {
|
|
503
|
-
closeClient();
|
|
504
|
-
throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
|
|
505
|
-
}
|
|
506
|
-
const firebaseApp = product === 'firebase' || isFirebaseApp(credential);
|
|
507
|
-
if (cached) {
|
|
508
|
-
queryString = query + (firebaseApp ? module_1.default.asString(orderBy, true) : module_1.default.asString(item.params, true) + module_1.default.asString(item.options, true) + limit);
|
|
509
|
-
if ((product === 'bigquery' || !update) && (rows = getCache(queryString))) {
|
|
510
|
-
result[i] = rows;
|
|
511
|
-
continue;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
if (firebaseApp) {
|
|
515
|
-
const { ref, get, child, query: queryDB, update: updateDB } = require('@firebase/database');
|
|
516
|
-
const constraints = [];
|
|
517
|
-
let limiter = 0;
|
|
518
|
-
if ((0, types_1.isArray)(orderBy)) {
|
|
519
|
-
const sort = require('@firebase/database');
|
|
520
|
-
for (const items of orderBy) {
|
|
521
|
-
if (!Array.isArray(items)) {
|
|
522
|
-
continue;
|
|
523
|
-
}
|
|
524
|
-
const method = items[0];
|
|
525
|
-
const args = items.slice(1);
|
|
526
|
-
switch (typeof method === 'string' && method.toLowerCase()) {
|
|
527
|
-
case 'orderbychild':
|
|
528
|
-
constraints.push(sort.orderByChild(args[0]));
|
|
529
|
-
break;
|
|
530
|
-
case 'orderbykey':
|
|
531
|
-
constraints.push(sort.orderByKey());
|
|
532
|
-
break;
|
|
533
|
-
case 'orderbyvalue':
|
|
534
|
-
constraints.push(sort.orderByValue());
|
|
535
|
-
break;
|
|
536
|
-
case 'limittofirst':
|
|
537
|
-
constraints.push(sort.limitToFirst(limiter = +args[0]));
|
|
538
|
-
break;
|
|
539
|
-
case 'limittolast':
|
|
540
|
-
constraints.push(sort.limitToLast(limiter = +args[0]));
|
|
541
|
-
break;
|
|
542
|
-
case 'startat':
|
|
543
|
-
constraints.push(sort.startAt(args[0], args[1]));
|
|
544
|
-
break;
|
|
545
|
-
case 'startafter':
|
|
546
|
-
constraints.push(sort.startAfter(args[0], args[1]));
|
|
547
|
-
break;
|
|
548
|
-
case 'endat':
|
|
549
|
-
constraints.push(sort.endAt(args[0], args[1]));
|
|
550
|
-
break;
|
|
551
|
-
case 'endbefore':
|
|
552
|
-
constraints.push(sort.endBefore(args[0], args[1]));
|
|
553
|
-
break;
|
|
554
|
-
case 'equalto':
|
|
555
|
-
constraints.push(sort.equalTo(args[0], args[1]));
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
const db = createClient(item, 0 /* DB.FIREBASE */);
|
|
561
|
-
if ((0, types_1.isPlainObject)(update)) {
|
|
562
|
-
await updateDB(ref(db, query), update);
|
|
563
|
-
}
|
|
564
|
-
const snapshot = await (constraints.length ? get(queryDB(ref(db, query), ...constraints)) : get(child(ref(db), query)));
|
|
565
|
-
if (snapshot.exists()) {
|
|
566
|
-
const val = snapshot.val();
|
|
567
|
-
const group = limiter === 1 && Object.keys(val);
|
|
568
|
-
rows = [group && (0, types_1.isObject)(val) && (0, types_1.isObject)(val[group[0]]) ? val[group[0]] : val];
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
else {
|
|
572
|
-
const { options = {} } = item;
|
|
573
|
-
options.query = query;
|
|
574
|
-
options.params || (options.params = item.params);
|
|
575
|
-
if (limit > 0) {
|
|
576
|
-
options.maxResults = limit;
|
|
577
|
-
}
|
|
578
|
-
const [job] = await createClient(item, 1 /* DB.BIGQUERY */).createQueryJob(options);
|
|
579
|
-
[rows] = await job.getQueryResults();
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
else if (product === 'datastore' || !product && keys) {
|
|
583
|
-
if (!keys) {
|
|
584
|
-
closeClient();
|
|
585
|
-
throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
|
|
586
|
-
}
|
|
587
|
-
if (cached && (rows = getCache(queryString = module_1.default.asString(keys, true) + module_1.default.asString(item.options, true) + limit))) {
|
|
588
|
-
result[i] = rows;
|
|
589
|
-
continue;
|
|
590
|
-
}
|
|
591
|
-
const db = createClient(item, 2 /* DB.DATASTORE */);
|
|
592
|
-
const items = !Array.isArray(keys) ? db.key(keys) : keys.map((key) => db.key(key));
|
|
593
|
-
rows = await db.get(items, item.options);
|
|
594
|
-
if (rows.length > limit) {
|
|
595
|
-
rows = rows.slice(0, limit);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
else if (product === 'firestore' || !product && table) {
|
|
599
|
-
if (!table) {
|
|
600
|
-
closeClient();
|
|
601
|
-
throw (0, util_1.formatError)(item, "Missing database table" /* ERR_DB.TABLE */);
|
|
602
|
-
}
|
|
603
|
-
if (cached) {
|
|
604
|
-
queryString = table + '_';
|
|
605
|
-
}
|
|
606
|
-
if (id) {
|
|
607
|
-
if (cached) {
|
|
608
|
-
queryString += id;
|
|
609
|
-
if (!update && (rows = getCache(queryString))) {
|
|
610
|
-
result[i] = rows;
|
|
611
|
-
continue;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
const db = createClient(item, 3 /* DB.FIRESTORE */).collection(table).doc(id);
|
|
615
|
-
if ((0, types_1.isPlainObject)(update)) {
|
|
616
|
-
await db.update(update, { exists: true });
|
|
617
|
-
}
|
|
618
|
-
const data = (await db.get()).data();
|
|
619
|
-
if (data) {
|
|
620
|
-
rows = [data];
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
else if (Array.isArray(query)) {
|
|
624
|
-
if (cached && (rows = getCache(queryString += module_1.default.asString(query, true) + module_1.default.asString(orderBy, true) + limit))) {
|
|
625
|
-
result[i] = rows;
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
let db = createClient(item, 3 /* DB.FIRESTORE */).collection(table);
|
|
629
|
-
for (const where of query) {
|
|
630
|
-
if (where.length === 3) {
|
|
631
|
-
db = db.where(where[0], where[1], where[2]);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
if (Array.isArray(orderBy)) {
|
|
635
|
-
for (const order of orderBy) {
|
|
636
|
-
if (Array.isArray(order) && typeof order[0] === 'string') {
|
|
637
|
-
db = db.orderBy(order[0], order[1] === 'desc' || order[1] === 'asc' ? order[1] : undefined);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
if (limit > 0) {
|
|
642
|
-
db = db.limit(limit);
|
|
643
|
-
}
|
|
644
|
-
rows = (await db.get()).docs.map(doc => doc.data());
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
closeClient();
|
|
648
|
-
throw (0, util_1.formatError)(item, "Missing database query" /* ERR_DB.QUERY */);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
else {
|
|
652
|
-
closeClient();
|
|
653
|
-
throw (0, util_1.formatError)(item, "Missing database product" /* ERR_DB.PRODUCT */);
|
|
654
|
-
}
|
|
655
|
-
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
656
|
-
}
|
|
657
|
-
closeClient();
|
|
658
|
-
return result;
|
|
659
|
-
}
|
|
660
|
-
exports.executeBatchQuery = executeBatchQuery;
|
|
661
|
-
function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
662
|
-
acl.add({ entity: 'allUsers', role: 'READER' })
|
|
663
|
-
.then(() => {
|
|
664
|
-
if (requested) {
|
|
665
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, "Grant public-read" /* CMD_CLOUD.PUBLIC_READ */, pathname, { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
666
|
-
}
|
|
667
|
-
})
|
|
668
|
-
.catch(err => {
|
|
669
|
-
if (requested) {
|
|
670
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Unable to grant public-read" /* ERR_CLOUD.PUBLIC_READ */, pathname], err, { ...index_1.default.LOG_CLOUD_WARN });
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
exports.setPublicRead = setPublicRead;
|
|
675
|
-
async function setPredefinedAcl(target, value, bucket, pathname = '', metadata = {}, requested = true, service = 'gcp') {
|
|
676
|
-
let revoke;
|
|
677
|
-
if (metadata === true) {
|
|
678
|
-
revoke = true;
|
|
679
|
-
metadata = {};
|
|
680
|
-
}
|
|
681
|
-
let items;
|
|
682
|
-
switch (value) {
|
|
683
|
-
case 'publicRead':
|
|
684
|
-
items = [{ entity: 'allUsers', role: revoke ? undefined : 'READER' }];
|
|
685
|
-
break;
|
|
686
|
-
case 'authenticatedRead':
|
|
687
|
-
items = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers', role: revoke ? undefined : 'READER' }];
|
|
688
|
-
break;
|
|
689
|
-
default: {
|
|
690
|
-
const owner = metadata.owner?.entity;
|
|
691
|
-
let acl = metadata.acl;
|
|
692
|
-
if ((0, types_1.isArray)(acl)) {
|
|
693
|
-
items = [];
|
|
694
|
-
}
|
|
695
|
-
else {
|
|
696
|
-
if (bucket) {
|
|
697
|
-
const [users] = await bucket.acl.get().catch(() => [[]]);
|
|
698
|
-
acl = Array.isArray(users) ? users : [users];
|
|
699
|
-
}
|
|
700
|
-
else {
|
|
701
|
-
acl = [];
|
|
702
|
-
}
|
|
703
|
-
items = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers' }];
|
|
704
|
-
}
|
|
705
|
-
switch (value) {
|
|
706
|
-
case 'private': {
|
|
707
|
-
const owners = new Set(acl.filter(item => item.role === 'OWNER').map(item => item.entity));
|
|
708
|
-
if (owner) {
|
|
709
|
-
owners.add(owner);
|
|
710
|
-
}
|
|
711
|
-
if (owners.size) {
|
|
712
|
-
for (const user of acl) {
|
|
713
|
-
const entity = user.entity;
|
|
714
|
-
if (!owners.has(entity)) {
|
|
715
|
-
items.push({ entity });
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
break;
|
|
720
|
-
}
|
|
721
|
-
case 'projectPrivate':
|
|
722
|
-
for (const user of acl) {
|
|
723
|
-
const entity = user.entity;
|
|
724
|
-
if (entity.startsWith('project-')) {
|
|
725
|
-
items.push({ ...user, role: entity.startsWith('project-editors-') || entity.startsWith('project-owners-') ? 'OWNER' : 'READER' });
|
|
726
|
-
}
|
|
727
|
-
else {
|
|
728
|
-
items.push({ ...user, role: undefined });
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
break;
|
|
732
|
-
case 'bucketOwnerRead':
|
|
733
|
-
if (bucket && owner) {
|
|
734
|
-
for (const user of acl) {
|
|
735
|
-
if (user.entity !== owner) {
|
|
736
|
-
items.push({ entity: user.entity, role: 'READER' });
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
case 'bucketOwnerFullControl':
|
|
741
|
-
if (bucket && owner) {
|
|
742
|
-
items.push({ entity: owner, role: 'OWNER' });
|
|
743
|
-
}
|
|
744
|
-
break;
|
|
745
|
-
default:
|
|
746
|
-
return Promise.resolve();
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return updatePredefinedAcl(target, items, metadata).then(errors => {
|
|
751
|
-
if (errors.length) {
|
|
752
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [`Unable to ${revoke ? 'revoke' : 'grant'} ` + value, bucket && pathname ? bucket.name + '/' + pathname : bucket ? bucket.name : pathname], errors[0], { ...index_1.default.LOG_CLOUD_WARN });
|
|
753
|
-
}
|
|
754
|
-
else if (requested && (bucket || pathname)) {
|
|
755
|
-
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...index_1.default.LOG_CLOUD_COMMAND });
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
exports.setPredefinedAcl = setPredefinedAcl;
|
|
760
|
-
function createBucketRequest(credential) {
|
|
761
|
-
const options = {};
|
|
762
|
-
for (const attr in credential) {
|
|
763
|
-
switch (attr) {
|
|
764
|
-
case 'archive':
|
|
765
|
-
case 'coldline':
|
|
766
|
-
case 'cors':
|
|
767
|
-
case 'customPlacementConfig':
|
|
768
|
-
case 'dra':
|
|
769
|
-
case 'location':
|
|
770
|
-
case 'multiRegional':
|
|
771
|
-
case 'nearline':
|
|
772
|
-
case 'regional':
|
|
773
|
-
case 'requesterPays':
|
|
774
|
-
case 'retentionPolicy':
|
|
775
|
-
case 'rpo':
|
|
776
|
-
case 'standard':
|
|
777
|
-
case 'storageClass':
|
|
778
|
-
case 'userProject':
|
|
779
|
-
case 'versioning':
|
|
780
|
-
options[attr] = credential[attr];
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
return options;
|
|
785
|
-
}
|
|
786
|
-
exports.createBucketRequest = createBucketRequest;
|
|
787
|
-
function getProjectId(credential) {
|
|
788
|
-
try {
|
|
789
|
-
let pathname = credential.keyFilename || credential.keyFile;
|
|
790
|
-
if (pathname && module_1.default.isPath(pathname = path.resolve(pathname)) || (pathname = process.env.GOOGLE_APPLICATION_CREDENTIALS) && module_1.default.isPath(pathname = path.resolve(pathname))) {
|
|
791
|
-
const projectId = require(pathname).project_id;
|
|
792
|
-
if ((0, types_1.isString)(projectId)) {
|
|
793
|
-
return projectId;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
catch {
|
|
798
|
-
}
|
|
799
|
-
return '';
|
|
800
|
-
}
|
|
801
|
-
exports.getProjectId = getProjectId;
|