@pi-r/gcp 0.5.3 → 0.5.4
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 +1 -1
- package/client/index.js +7 -5
- package/package.json +4 -4
- package/upload/index.js +4 -3
- package/types/index.d.ts +0 -36
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/client/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function updatePredefinedAcl(acl, values, metadata = {}) {
|
|
|
70
70
|
let defaultObjectAcl;
|
|
71
71
|
({ projectNumber, defaultObjectAcl } = metadata);
|
|
72
72
|
if (projectNumber === undefined && (0, types_1.isArray)(defaultObjectAcl)) {
|
|
73
|
-
const target = defaultObjectAcl.find(item => item.projectTeam
|
|
73
|
+
const target = defaultObjectAcl.find(item => { var _a; return (_a = item.projectTeam) === null || _a === void 0 ? void 0 : _a.projectNumber; });
|
|
74
74
|
if (target !== undefined) {
|
|
75
75
|
projectNumber = target.projectTeam.projectNumber;
|
|
76
76
|
}
|
|
@@ -210,6 +210,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
210
210
|
}
|
|
211
211
|
exports.createBucketV2 = createBucketV2;
|
|
212
212
|
async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
213
|
+
var _a;
|
|
213
214
|
if (isFirebaseApp(credential, true, true)) {
|
|
214
215
|
return false;
|
|
215
216
|
}
|
|
@@ -226,7 +227,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
226
227
|
case 'private':
|
|
227
228
|
case 'projectPrivate':
|
|
228
229
|
await client.makePrivate(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
229
|
-
await setPredefinedAcl.call(this, client.acl, acl, client, '', options.bucket
|
|
230
|
+
await setPredefinedAcl.call(this, client.acl, acl, client, '', (_a = options.bucket) === null || _a === void 0 ? void 0 : _a.metadata).catch(err => errors.push(err));
|
|
230
231
|
break;
|
|
231
232
|
case 'authenticatedRead':
|
|
232
233
|
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
@@ -384,7 +385,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
384
385
|
};
|
|
385
386
|
const closeClient = () => {
|
|
386
387
|
const fs = clients[3];
|
|
387
|
-
fs
|
|
388
|
+
fs === null || fs === void 0 ? void 0 : fs.terminate();
|
|
388
389
|
};
|
|
389
390
|
const getFamily = (data, row, family) => {
|
|
390
391
|
const familyData = data[family];
|
|
@@ -712,6 +713,7 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
|
712
713
|
}
|
|
713
714
|
exports.setPublicRead = setPublicRead;
|
|
714
715
|
async function setPredefinedAcl(target, value, bucket, pathname = '', metadata = {}, requested = true, service = 'gcp') {
|
|
716
|
+
var _a;
|
|
715
717
|
let revoke;
|
|
716
718
|
if (metadata === true) {
|
|
717
719
|
revoke = true;
|
|
@@ -726,7 +728,7 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
726
728
|
items = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers', role: revoke ? undefined : 'READER' }];
|
|
727
729
|
break;
|
|
728
730
|
default: {
|
|
729
|
-
const owner = metadata.owner
|
|
731
|
+
const owner = (_a = metadata.owner) === null || _a === void 0 ? void 0 : _a.entity;
|
|
730
732
|
let acl = metadata.acl;
|
|
731
733
|
if ((0, types_1.isArray)(acl)) {
|
|
732
734
|
items = [];
|
|
@@ -784,7 +786,7 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
784
786
|
this.formatMessage(64, service, [`Unable to ${revoke ? 'revoke' : 'grant'} ` + value, bucket && pathname ? bucket.name + '/' + pathname : bucket ? bucket.name : pathname], errors[0], { ...Cloud.LOG_CLOUD_WARN });
|
|
785
787
|
}
|
|
786
788
|
else if (requested && (bucket || pathname)) {
|
|
787
|
-
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket
|
|
789
|
+
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket === null || bucket === void 0 ? void 0 : bucket.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
788
790
|
}
|
|
789
791
|
});
|
|
790
792
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.7.
|
|
24
|
-
"@e-mc/module": "^0.7.
|
|
25
|
-
"@e-mc/types": "^0.7.
|
|
23
|
+
"@e-mc/cloud": "^0.7.5",
|
|
24
|
+
"@e-mc/module": "^0.7.5",
|
|
25
|
+
"@e-mc/types": "^0.7.5",
|
|
26
26
|
"@google-cloud/firestore": "^7.6.0",
|
|
27
27
|
"@google-cloud/storage": "^7.9.0"
|
|
28
28
|
}
|
package/upload/index.js
CHANGED
|
@@ -44,7 +44,7 @@ function upload(credential, service = 'gcp') {
|
|
|
44
44
|
const configBucket = admin.configBucket;
|
|
45
45
|
if (!BUCKET_SESSION.has(bucket)) {
|
|
46
46
|
const bucketAcl = admin.publicRead ? 'publicRead' : admin.acl;
|
|
47
|
-
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, configBucket
|
|
47
|
+
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, (configBucket === null || configBucket === void 0 ? void 0 : configBucket.create) || (0, client_1.createBucketRequest)(credential)));
|
|
48
48
|
if (!await response) {
|
|
49
49
|
uploadResponse(null);
|
|
50
50
|
return;
|
|
@@ -52,11 +52,12 @@ function upload(credential, service = 'gcp') {
|
|
|
52
52
|
BUCKET_SESSION.add(bucket);
|
|
53
53
|
}
|
|
54
54
|
bucketClient = storage.bucket(bucket);
|
|
55
|
-
const retentionPolicy = configBucket
|
|
55
|
+
const retentionPolicy = configBucket === null || configBucket === void 0 ? void 0 : configBucket.retentionPolicy;
|
|
56
56
|
if (typeof retentionPolicy === 'number') {
|
|
57
57
|
bucketClient.setRetentionPeriod(retentionPolicy)
|
|
58
58
|
.then(([response]) => {
|
|
59
|
-
|
|
59
|
+
var _a;
|
|
60
|
+
this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], (_a = response.retentionPolicy) === null || _a === void 0 ? void 0 : _a.effectiveTime, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
60
61
|
})
|
|
61
62
|
.catch(err => addLog(err));
|
|
62
63
|
}
|
package/types/index.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { CloudDatabase, CloudStorage } from '@e-mc/types/lib/cloud';
|
|
2
|
-
|
|
3
|
-
import type { StorageOptions } from '@google-cloud/storage';
|
|
4
|
-
import type { PathType } from '@google-cloud/datastore';
|
|
5
|
-
import type { entity } from '@google-cloud/datastore/build/src/entity';
|
|
6
|
-
import type { FirebaseOptions as IFirebaseOptions } from '@firebase/app';
|
|
7
|
-
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
import type { GoogleAuthOptions } from 'google-auth-library';
|
|
10
|
-
|
|
11
|
-
export type GCPStorage = CloudStorage<GCPStorageCredential, "gcp | gcloud">;
|
|
12
|
-
|
|
13
|
-
export interface GCPStorageCredential extends StorageOptions, IFirebaseOptions {}
|
|
14
|
-
|
|
15
|
-
export interface GCPDatabaseQuery<T = PlainObject> extends Omit<CloudDatabase<unknown, T, unknown, unknown[] | StandardMap, GCPDatabaseCredential>, "id"> {
|
|
16
|
-
source: "cloud";
|
|
17
|
-
service: "gcp" | "gcloud";
|
|
18
|
-
product?: "firestore" | "firebase" | "bigquery" | "bigtable" | "datastore" | "spanner";
|
|
19
|
-
database?: string;
|
|
20
|
-
id?: ArrayOf<string>;
|
|
21
|
-
updateType?: 0 | 1 | 2 | 3;
|
|
22
|
-
columns?: string[];
|
|
23
|
-
keys?: ArrayOf<DatastoreKey>;
|
|
24
|
-
kind?: ArrayOf<string>;
|
|
25
|
-
orderBy?: unknown[][];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type GCPDatabaseCredential = GoogleAuthOptions;
|
|
29
|
-
|
|
30
|
-
export interface FirebaseOptions extends IFirebaseOptions {
|
|
31
|
-
product?: "firebase";
|
|
32
|
-
admin?: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type DatastoreKey = string | PathType[] | entity.KeyOptions;
|
|
36
|
-
export type BucketAcl = "authenticatedRead" | "private" | "projectPrivate" | "publicRead" | "publicReadWrite" | "bucketAccessUniform" | "bucketAccessACL";
|