@pi-r/gcp 0.2.9 → 0.2.11
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/README.md +1 -1
- package/client/index.js +8 -5
- package/package.json +4 -4
- package/types/index.d.ts +36 -0
- package/upload/index.js +2 -1
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/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -66,8 +66,9 @@ function updatePredefinedAcl(acl, values, metadata) {
|
|
|
66
66
|
const items = [];
|
|
67
67
|
for (const target of acl.default ? [acl, acl.default] : [acl]) {
|
|
68
68
|
items.push(...values.map(async (value) => {
|
|
69
|
+
var _a;
|
|
69
70
|
if (generation !== undefined) {
|
|
70
|
-
value.generation
|
|
71
|
+
(_a = value.generation) !== null && _a !== void 0 ? _a : (value.generation = +generation);
|
|
71
72
|
}
|
|
72
73
|
if (userProject) {
|
|
73
74
|
value.userProject || (value.userProject = userProject);
|
|
@@ -134,7 +135,7 @@ exports.createStorageClient = createStorageClient;
|
|
|
134
135
|
function createDatabaseClient(credential, data) {
|
|
135
136
|
let packageName = '';
|
|
136
137
|
try {
|
|
137
|
-
const product = data
|
|
138
|
+
const product = data === null || data === void 0 ? void 0 : data.product;
|
|
138
139
|
if (product === 'firebase' || isFirebaseApp(credential)) {
|
|
139
140
|
packageName = getFirebasePackageName(credential);
|
|
140
141
|
return getApp(credential, true);
|
|
@@ -200,6 +201,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
200
201
|
}
|
|
201
202
|
exports.createBucketV2 = createBucketV2;
|
|
202
203
|
async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
204
|
+
var _a;
|
|
203
205
|
if (isFirebaseApp(credential, true, true)) {
|
|
204
206
|
return false;
|
|
205
207
|
}
|
|
@@ -216,7 +218,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
216
218
|
case 'private':
|
|
217
219
|
case 'projectPrivate':
|
|
218
220
|
await client.makePrivate(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
219
|
-
await setPredefinedAcl.call(this, client.acl, acl, client, '', options.bucket
|
|
221
|
+
await setPredefinedAcl.call(this, client.acl, acl, client, '', (_a = options.bucket) === null || _a === void 0 ? void 0 : _a.metadata);
|
|
220
222
|
break;
|
|
221
223
|
case 'authenticatedRead':
|
|
222
224
|
await client.makePublic(options).catch(err => !isErrorConflict(err) && errors.push(err));
|
|
@@ -702,6 +704,7 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
|
702
704
|
}
|
|
703
705
|
exports.setPublicRead = setPublicRead;
|
|
704
706
|
async function setPredefinedAcl(target, value, bucket, pathname = '', metadata = {}, requested = true, service = 'gcp') {
|
|
707
|
+
var _a;
|
|
705
708
|
let revoke;
|
|
706
709
|
if (metadata === true) {
|
|
707
710
|
revoke = true;
|
|
@@ -716,7 +719,7 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
716
719
|
items = [{ entity: 'allUsers' }, { entity: 'allAuthenticatedUsers', role: revoke ? undefined : 'READER' }];
|
|
717
720
|
break;
|
|
718
721
|
default: {
|
|
719
|
-
const owner = metadata.owner
|
|
722
|
+
const owner = (_a = metadata.owner) === null || _a === void 0 ? void 0 : _a.entity;
|
|
720
723
|
let acl = metadata.acl;
|
|
721
724
|
if ((0, types_1.isArray)(acl)) {
|
|
722
725
|
items = [];
|
|
@@ -781,7 +784,7 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
781
784
|
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 });
|
|
782
785
|
}
|
|
783
786
|
else if (requested && (bucket || pathname)) {
|
|
784
|
-
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket
|
|
787
|
+
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket === null || bucket === void 0 ? void 0 : bucket.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
785
788
|
}
|
|
786
789
|
});
|
|
787
790
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
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.5.
|
|
24
|
-
"@e-mc/module": "^0.5.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
23
|
+
"@e-mc/cloud": "^0.5.6",
|
|
24
|
+
"@e-mc/module": "^0.5.6",
|
|
25
|
+
"@e-mc/types": "^0.5.6",
|
|
26
26
|
"@google-cloud/firestore": "^6.8.0",
|
|
27
27
|
"@google-cloud/storage": "^6.12.0"
|
|
28
28
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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";
|
package/upload/index.js
CHANGED
|
@@ -13,6 +13,7 @@ function upload(credential, service = 'gcp') {
|
|
|
13
13
|
const storage = client_1.createStorageClient.call(this, credential);
|
|
14
14
|
return async (data, callback) => {
|
|
15
15
|
var _a;
|
|
16
|
+
var _b;
|
|
16
17
|
const firebase = (0, client_1.isFirebaseApp)(credential, true, true);
|
|
17
18
|
const { bucket, localUri } = data;
|
|
18
19
|
const { pathname = '', fileGroup, contentType, metadata, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
|
|
@@ -42,7 +43,7 @@ function upload(credential, service = 'gcp') {
|
|
|
42
43
|
else {
|
|
43
44
|
if (!BUCKET_SESSION.has(bucket)) {
|
|
44
45
|
const bucketAcl = admin.publicRead ? 'publicRead' : admin.acl;
|
|
45
|
-
const response = BUCKET_RESPONSE[
|
|
46
|
+
const response = BUCKET_RESPONSE[_b = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_b] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, ((_a = admin.configBucket) === null || _a === void 0 ? void 0 : _a.create) || (0, client_1.createBucketRequest)(credential)));
|
|
46
47
|
if (!await response) {
|
|
47
48
|
uploadResponse(null);
|
|
48
49
|
return;
|