@divyacon/piece-google-cloud-storage 0.0.0-stage → 0.1.1

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.
Files changed (93) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +50 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/clone-object.d.ts +9 -0
  7. package/dist/lib/actions/clone-object.d.ts.map +1 -0
  8. package/dist/lib/actions/clone-object.js +77 -0
  9. package/dist/lib/actions/clone-object.js.map +1 -0
  10. package/dist/lib/actions/create-bucket-acl.d.ts +7 -0
  11. package/dist/lib/actions/create-bucket-acl.d.ts.map +1 -0
  12. package/dist/lib/actions/create-bucket-acl.js +60 -0
  13. package/dist/lib/actions/create-bucket-acl.js.map +1 -0
  14. package/dist/lib/actions/create-bucket-default-object-acl.d.ts +7 -0
  15. package/dist/lib/actions/create-bucket-default-object-acl.d.ts.map +1 -0
  16. package/dist/lib/actions/create-bucket-default-object-acl.js +60 -0
  17. package/dist/lib/actions/create-bucket-default-object-acl.js.map +1 -0
  18. package/dist/lib/actions/create-bucket.d.ts +10 -0
  19. package/dist/lib/actions/create-bucket.d.ts.map +1 -0
  20. package/dist/lib/actions/create-bucket.js +80 -0
  21. package/dist/lib/actions/create-bucket.js.map +1 -0
  22. package/dist/lib/actions/create-object-acl.d.ts +9 -0
  23. package/dist/lib/actions/create-object-acl.d.ts.map +1 -0
  24. package/dist/lib/actions/create-object-acl.js +72 -0
  25. package/dist/lib/actions/create-object-acl.js.map +1 -0
  26. package/dist/lib/actions/delete-bucket-acl.d.ts +6 -0
  27. package/dist/lib/actions/delete-bucket-acl.d.ts.map +1 -0
  28. package/dist/lib/actions/delete-bucket-acl.js +56 -0
  29. package/dist/lib/actions/delete-bucket-acl.js.map +1 -0
  30. package/dist/lib/actions/delete-bucket-default-object-acl.d.ts +6 -0
  31. package/dist/lib/actions/delete-bucket-default-object-acl.d.ts.map +1 -0
  32. package/dist/lib/actions/delete-bucket-default-object-acl.js +56 -0
  33. package/dist/lib/actions/delete-bucket-default-object-acl.js.map +1 -0
  34. package/dist/lib/actions/delete-empty-bucket.d.ts +5 -0
  35. package/dist/lib/actions/delete-empty-bucket.d.ts.map +1 -0
  36. package/dist/lib/actions/delete-empty-bucket.js +50 -0
  37. package/dist/lib/actions/delete-empty-bucket.js.map +1 -0
  38. package/dist/lib/actions/delete-object-acl.d.ts +8 -0
  39. package/dist/lib/actions/delete-object-acl.d.ts.map +1 -0
  40. package/dist/lib/actions/delete-object-acl.js +71 -0
  41. package/dist/lib/actions/delete-object-acl.js.map +1 -0
  42. package/dist/lib/actions/delete-object.d.ts +7 -0
  43. package/dist/lib/actions/delete-object.d.ts.map +1 -0
  44. package/dist/lib/actions/delete-object.js +66 -0
  45. package/dist/lib/actions/delete-object.js.map +1 -0
  46. package/dist/lib/actions/search-buckets.d.ts +9 -0
  47. package/dist/lib/actions/search-buckets.d.ts.map +1 -0
  48. package/dist/lib/actions/search-buckets.js +96 -0
  49. package/dist/lib/actions/search-buckets.js.map +1 -0
  50. package/dist/lib/actions/search-objects.d.ts +12 -0
  51. package/dist/lib/actions/search-objects.d.ts.map +1 -0
  52. package/dist/lib/actions/search-objects.js +105 -0
  53. package/dist/lib/actions/search-objects.js.map +1 -0
  54. package/dist/lib/common/auth.d.ts +2 -0
  55. package/dist/lib/common/auth.d.ts.map +1 -0
  56. package/dist/lib/common/auth.js +20 -0
  57. package/dist/lib/common/auth.js.map +1 -0
  58. package/dist/lib/common/client.d.ts +9 -0
  59. package/dist/lib/common/client.d.ts.map +1 -0
  60. package/dist/lib/common/client.js +48 -0
  61. package/dist/lib/common/client.js.map +1 -0
  62. package/dist/lib/common/props.d.ts +12 -0
  63. package/dist/lib/common/props.d.ts.map +1 -0
  64. package/dist/lib/common/props.js +231 -0
  65. package/dist/lib/common/props.js.map +1 -0
  66. package/dist/lib/triggers/new-object-created.d.ts +19 -0
  67. package/dist/lib/triggers/new-object-created.d.ts.map +1 -0
  68. package/dist/lib/triggers/new-object-created.js +127 -0
  69. package/dist/lib/triggers/new-object-created.js.map +1 -0
  70. package/dist/lib/triggers/object-updated.d.ts +19 -0
  71. package/dist/lib/triggers/object-updated.d.ts.map +1 -0
  72. package/dist/lib/triggers/object-updated.js +127 -0
  73. package/dist/lib/triggers/object-updated.js.map +1 -0
  74. package/package.json +44 -4
  75. package/src/index.ts +46 -0
  76. package/src/lib/actions/clone-object.ts +75 -0
  77. package/src/lib/actions/create-bucket-acl.ts +58 -0
  78. package/src/lib/actions/create-bucket-default-object-acl.ts +58 -0
  79. package/src/lib/actions/create-bucket.ts +75 -0
  80. package/src/lib/actions/create-object-acl.ts +81 -0
  81. package/src/lib/actions/delete-bucket-acl.ts +52 -0
  82. package/src/lib/actions/delete-bucket-default-object-acl.ts +52 -0
  83. package/src/lib/actions/delete-empty-bucket.ts +42 -0
  84. package/src/lib/actions/delete-object-acl.ts +64 -0
  85. package/src/lib/actions/delete-object.ts +59 -0
  86. package/src/lib/actions/search-buckets.ts +92 -0
  87. package/src/lib/actions/search-objects.ts +101 -0
  88. package/src/lib/common/auth.ts +15 -0
  89. package/src/lib/common/client.ts +63 -0
  90. package/src/lib/common/props.ts +249 -0
  91. package/src/lib/triggers/new-object-created.ts +174 -0
  92. package/src/lib/triggers/object-updated.ts +174 -0
  93. package/README.md +0 -3
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectUpdated = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/google-cloud-storage/src/lib/triggers/object-updated.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const auth_1 = require("../common/auth");
9
+ const client_1 = require("../common/client");
10
+ const props_1 = require("../common/props");
11
+ const pieces_common_1 = require("@agnocon/pieces-common");
12
+ exports.objectUpdated = (0, pieces_framework_1.createTrigger)({
13
+ auth: auth_1.googleCloudStorageAuth,
14
+ name: 'object_updated',
15
+ displayName: 'Object Updated',
16
+ description: 'Triggers when an existing object is updated in a bucket',
17
+ aiMetadata: {
18
+ description: 'Fires when the metadata of an existing object in the configured bucket is updated, optionally limited to objects whose name starts with a given prefix. Represents a change to an existing file\'s metadata; delivered via a Cloud Pub/Sub push notification (OBJECT_METADATA_UPDATE event).',
19
+ },
20
+ props: {
21
+ projectId: props_1.projectIdProperty,
22
+ bucket: props_1.bucketDropdown,
23
+ prefix: pieces_framework_1.Property.ShortText({
24
+ displayName: 'Prefix Filter',
25
+ description: 'Only trigger for objects with this prefix',
26
+ required: false,
27
+ }),
28
+ },
29
+ type: pieces_framework_1.TriggerStrategy.WEBHOOK,
30
+ sampleData: {
31
+ kind: 'storage#object',
32
+ id: 'example-bucket/example-object/1234567890',
33
+ name: 'example-object.txt',
34
+ bucket: 'example-bucket',
35
+ generation: '1234567890',
36
+ contentType: 'text/plain',
37
+ timeCreated: '2023-01-01T00:00:00.000Z',
38
+ updated: '2023-01-01T01:00:00.000Z',
39
+ size: '2048',
40
+ },
41
+ onEnable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
42
+ const { projectId, bucket, prefix } = context.propsValue;
43
+ const auth = context.auth;
44
+ // Generate unique names for this trigger instance
45
+ const triggerId = `ap-gcs-update-${bucket}-${Date.now()}`;
46
+ const topicName = `projects/${projectId}/topics/${triggerId}`;
47
+ const subscriptionName = `projects/${projectId}/subscriptions/${triggerId}`;
48
+ try {
49
+ // 1. Create Pub/Sub topic
50
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.PUT, `/projects/${projectId}/topics/${triggerId}`, auth.access_token);
51
+ // 2. Create GCS notification configuration for metadata updates
52
+ const notificationConfig = {
53
+ topic: topicName,
54
+ payload_format: 'JSON_API_V1',
55
+ event_types: ['OBJECT_METADATA_UPDATE'],
56
+ };
57
+ if (prefix) {
58
+ notificationConfig.object_name_prefix = prefix;
59
+ }
60
+ const notificationResponse = yield client_1.gcsCommon.makeGCSRequest(pieces_common_1.HttpMethod.POST, `/b/${bucket}/notificationConfigs`, auth.access_token, notificationConfig);
61
+ // 3. Create Pub/Sub subscription with webhook push
62
+ const subscriptionConfig = {
63
+ topic: topicName,
64
+ pushConfig: {
65
+ pushEndpoint: context.webhookUrl,
66
+ },
67
+ ackDeadlineSeconds: 60,
68
+ };
69
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.PUT, `/projects/${projectId}/subscriptions/${triggerId}`, auth.access_token, subscriptionConfig);
70
+ // Store trigger data for cleanup
71
+ yield context.store.put('_trigger', {
72
+ topicName: triggerId,
73
+ subscriptionName: triggerId,
74
+ notificationId: notificationResponse.id,
75
+ });
76
+ }
77
+ catch (error) {
78
+ // Cleanup on failure
79
+ try {
80
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.DELETE, `/projects/${projectId}/subscriptions/${triggerId}`, auth.access_token);
81
+ }
82
+ catch (e) { /* ignore */ }
83
+ try {
84
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.DELETE, `/projects/${projectId}/topics/${triggerId}`, auth.access_token);
85
+ }
86
+ catch (e) { /* ignore */ }
87
+ throw new Error(`Failed to setup Pub/Sub notifications: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
88
+ }
89
+ }),
90
+ onDisable: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
91
+ const triggerData = yield context.store.get('_trigger');
92
+ if (!triggerData)
93
+ return;
94
+ const { projectId } = context.propsValue;
95
+ const { bucket } = context.propsValue;
96
+ const auth = context.auth;
97
+ // Clean up in reverse order
98
+ try {
99
+ // Delete subscription
100
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.DELETE, `/projects/${projectId}/subscriptions/${triggerData.subscriptionName}`, auth.access_token);
101
+ }
102
+ catch (e) { /* ignore */ }
103
+ try {
104
+ // Delete notification config
105
+ yield client_1.gcsCommon.makeGCSRequest(pieces_common_1.HttpMethod.DELETE, `/b/${bucket}/notificationConfigs/${triggerData.notificationId}`, auth.access_token);
106
+ }
107
+ catch (e) { /* ignore */ }
108
+ try {
109
+ // Delete topic
110
+ yield client_1.gcsCommon.makePubSubRequest(pieces_common_1.HttpMethod.DELETE, `/projects/${projectId}/topics/${triggerData.topicName}`, auth.access_token);
111
+ }
112
+ catch (e) { /* ignore */ }
113
+ }),
114
+ run: (context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
115
+ var _a;
116
+ const payload = context.payload.body;
117
+ if (!((_a = payload === null || payload === void 0 ? void 0 : payload.message) === null || _a === void 0 ? void 0 : _a.data)) {
118
+ return [];
119
+ }
120
+ // Decode Pub/Sub message
121
+ const messageData = JSON.parse(Buffer.from(payload.message.data, 'base64').toString());
122
+ // Extract GCS object from notification payload
123
+ const gcsObject = messageData;
124
+ return [gcsObject];
125
+ }),
126
+ });
127
+ //# sourceMappingURL=object-updated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-updated.js","sourceRoot":"","sources":["../../../src/lib/triggers/object-updated.ts"],"names":[],"mappings":";;;;AAAA,sHAAsH;AACtH,qEAAqE;AACrE,gEAAqF;AACrF,yCAAwD;AACxD,6CAA6C;AAC7C,2CAAoE;AACpE,0DAAoD;AAQvC,QAAA,aAAa,GAAG,IAAA,gCAAa,EAAC;IACzC,IAAI,EAAE,6BAAsB;IAC5B,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,yDAAyD;IACtE,UAAU,EAAE;QACV,WAAW,EAAE,8RAA8R;KAC5S;IACD,KAAK,EAAE;QACL,SAAS,EAAE,yBAAiB;QAC5B,MAAM,EAAE,sBAAc;QACtB,MAAM,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACzB,WAAW,EAAE,eAAe;YAC5B,WAAW,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,uBAAP,OAAO,CAAE,OAAO,0CAAE,IAAI,CAAA,EAAE,CAAC;YAC5B,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,yBAAyB;QACzB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CACvD,CAAC;QAEF,+CAA+C;QAC/C,MAAM,SAAS,GAAG,WAAW,CAAC;QAE9B,OAAO,CAAC,SAAS,CAAC,CAAC;IACrB,CAAC,CAAA;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@divyacon/piece-google-cloud-storage",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "DivyaCon google-cloud-storage connector",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "LICENSE.MIT-AP"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "vendor": "node ../scripts/vendor-ap.mjs piece-google-cloud-storage"
22
+ },
23
+ "dependencies": {
24
+ "@agnocon/core-utils": "0.2.0",
25
+ "@agnocon/piece-types": "0.3.1",
26
+ "@agnocon/pieces-common": "0.12.8",
27
+ "@agnocon/pieces-framework": "0.36.0",
28
+ "tslib": "2.6.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "20.17.6",
32
+ "typescript": "5.5.4"
33
+ },
34
+ "license": "MIT",
35
+ "agnocon": {
36
+ "originVersion": "0.1.7"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "tag": "latest"
41
+ },
42
+ "keywords": [
43
+ "agnocon",
44
+ "connector"
45
+ ]
46
+ }
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+
2
+ import { createPiece } from "@agnocon/pieces-framework";
3
+ import { PieceCategory } from '@agnocon/pieces-framework';
4
+ import { googleCloudStorageAuth } from "./lib/common/auth";
5
+ import { createBucket } from "./lib/actions/create-bucket";
6
+ import { deleteEmptyBucket } from "./lib/actions/delete-empty-bucket";
7
+ import { cloneObject } from "./lib/actions/clone-object";
8
+ import { deleteObject } from "./lib/actions/delete-object";
9
+ import { searchObjects } from "./lib/actions/search-objects";
10
+ import { searchBuckets } from "./lib/actions/search-buckets";
11
+ import { createObjectAcl } from "./lib/actions/create-object-acl";
12
+ import { deleteObjectAcl } from "./lib/actions/delete-object-acl";
13
+ import { createBucketAcl } from "./lib/actions/create-bucket-acl";
14
+ import { deleteBucketAcl } from "./lib/actions/delete-bucket-acl";
15
+ import { createBucketDefaultObjectAcl } from "./lib/actions/create-bucket-default-object-acl";
16
+ import { deleteBucketDefaultObjectAcl } from "./lib/actions/delete-bucket-default-object-acl";
17
+ import { newObjectCreated } from "./lib/triggers/new-object-created";
18
+ import { objectUpdated } from "./lib/triggers/object-updated";
19
+
20
+ export const googleCloudStorage = createPiece({
21
+ displayName: "Google Cloud Storage",
22
+ description: "Automate file storage operations with Google Cloud Storage. Upload, download, manage buckets, set permissions, and monitor changes with real-time triggers.",
23
+ auth: googleCloudStorageAuth,
24
+ minimumSupportedRelease: '0.36.1',
25
+ logoUrl: "https://cdn.activepieces.com/pieces/google-cloud-storage.png",
26
+ authors: ["sparkybug"],
27
+ categories: [PieceCategory.CONTENT_AND_FILES],
28
+ actions: [
29
+ createBucket,
30
+ deleteEmptyBucket,
31
+ cloneObject,
32
+ deleteObject,
33
+ searchObjects,
34
+ searchBuckets,
35
+ createObjectAcl,
36
+ deleteObjectAcl,
37
+ createBucketAcl,
38
+ deleteBucketAcl,
39
+ createBucketDefaultObjectAcl,
40
+ deleteBucketDefaultObjectAcl,
41
+ ],
42
+ triggers: [
43
+ newObjectCreated,
44
+ objectUpdated,
45
+ ],
46
+ });
@@ -0,0 +1,75 @@
1
+ import { createAction, Property, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
+ import { googleCloudStorageAuth } from '../common/auth';
3
+ import { gcsCommon } from '../common/client';
4
+ import { bucketDropdown, objectDropdown, projectIdProperty } from '../common/props';
5
+ import { HttpMethod } from '@agnocon/pieces-common';
6
+
7
+ export const cloneObject = createAction({
8
+ auth: googleCloudStorageAuth,
9
+ name: 'clone_object',
10
+ displayName: 'Clone Object',
11
+ description: 'Copy / clone an object (file) to a new location (same or different bucket), optionally overriding metadata. Perfect for duplicating files as backup or version.',
12
+ audience: 'both',
13
+ aiMetadata: { description: 'Copies an existing object to a destination bucket/name (same or different bucket), optionally overriding metadata such as contentType or cacheControl. Use to duplicate a file for backups or to move data between buckets. Not idempotent: it writes a new destination object on each call, creating a fresh generation. Requires the source bucket/object and a destination bucket and object name.', idempotent: false },
14
+ props: {
15
+ projectId: projectIdProperty,
16
+ sourceBucket: bucketDropdown,
17
+ sourceObject: objectDropdown('sourceBucket'),
18
+ destBucket: bucketDropdown,
19
+ destObject: Property.ShortText({
20
+ displayName: 'Destination Object Name',
21
+ description: 'Name for the copied object (must be valid object name)',
22
+ required: true,
23
+ }),
24
+ metadataOverrides: Property.Object({
25
+ displayName: 'Metadata Overrides',
26
+ description: 'Optional metadata and properties to override in the copied object (contentType, cacheControl, contentDisposition, etc.)',
27
+ required: false,
28
+ }),
29
+ },
30
+ async run(context) {
31
+ const { sourceBucket, sourceObject, destBucket, destObject, metadataOverrides } = context.propsValue;
32
+ const auth = context.auth as OAuth2PropertyValue;
33
+
34
+ const body = metadataOverrides || undefined;
35
+
36
+ try {
37
+ const response = await gcsCommon.makeRequest(
38
+ HttpMethod.POST,
39
+ `/b/${sourceBucket}/o/${encodeURIComponent(sourceObject as string)}/copyTo/b/${destBucket}/o/${encodeURIComponent(destObject as string)}`,
40
+ auth.access_token,
41
+ body
42
+ );
43
+
44
+ return {
45
+ success: true,
46
+ source: {
47
+ bucket: sourceBucket,
48
+ object: sourceObject,
49
+ },
50
+ destination: {
51
+ bucket: destBucket,
52
+ object: destObject,
53
+ },
54
+ object: response,
55
+ };
56
+ } catch (error: any) {
57
+ if (error.response?.status === 404) {
58
+ throw new Error(`Source object "${sourceObject}" not found in bucket "${sourceBucket}".`);
59
+ }
60
+ if (error.response?.status === 403) {
61
+ throw new Error('Access denied. Check permissions for source and destination buckets.');
62
+ }
63
+ if (error.response?.status === 412) {
64
+ throw new Error('Precondition failed. Source object may have been modified.');
65
+ }
66
+ if (error.response?.status === 409) {
67
+ throw new Error(`Destination object "${destObject}" already exists in bucket "${destBucket}".`);
68
+ }
69
+ if (error.response?.status === 400) {
70
+ throw new Error('Invalid request. Check object names and bucket configurations.');
71
+ }
72
+ throw new Error(`Failed to clone object: ${error.message || 'Unknown error'}`);
73
+ }
74
+ },
75
+ });
@@ -0,0 +1,58 @@
1
+ import { createAction, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
+ import { googleCloudStorageAuth } from '../common/auth';
3
+ import { gcsCommon } from '../common/client';
4
+ import { bucketDropdown, aclEntityProperty, bucketAclRoleProperty, projectIdProperty } from '../common/props';
5
+ import { HttpMethod } from '@agnocon/pieces-common';
6
+
7
+ export const createBucketAcl = createAction({
8
+ auth: googleCloudStorageAuth,
9
+ name: 'create_bucket_acl',
10
+ displayName: 'Create Bucket ACL',
11
+ description: 'Add an ACL entry at bucket level. Perfect for granting permission to manage the bucket.',
12
+ audience: 'both',
13
+ aiMetadata: { description: 'Grants an entity (user, group, domain, or special scope) a role on a bucket\'s own access-control list. Use to let someone read or manage the bucket itself. Not idempotent: adding an entry that already exists fails. Only works on buckets using fine-grained ACLs, not uniform bucket-level access; requires bucket, entity, and role.', idempotent: false },
14
+ props: {
15
+ projectId: projectIdProperty,
16
+ bucket: bucketDropdown,
17
+ entity: aclEntityProperty,
18
+ role: bucketAclRoleProperty,
19
+ },
20
+ async run(context) {
21
+ const { bucket, entity, role } = context.propsValue;
22
+ const auth = context.auth as OAuth2PropertyValue;
23
+
24
+ const aclEntry = {
25
+ entity,
26
+ role,
27
+ };
28
+
29
+ try {
30
+ const response = await gcsCommon.makeRequest(
31
+ HttpMethod.POST,
32
+ `/b/${bucket}/acl`,
33
+ auth.access_token,
34
+ aclEntry
35
+ );
36
+
37
+ return {
38
+ success: true,
39
+ bucket,
40
+ acl: response,
41
+ };
42
+ } catch (error: any) {
43
+ if (error.response?.status === 400) {
44
+ throw new Error('Bad request. This bucket may have uniform bucket-level access enabled, which doesn\'t support bucket ACLs. Use IAM policies instead.');
45
+ }
46
+ if (error.response?.status === 403) {
47
+ throw new Error('Access denied. You need storage.buckets.update permission to modify bucket ACLs.');
48
+ }
49
+ if (error.response?.status === 404) {
50
+ throw new Error(`Bucket "${bucket}" not found.`);
51
+ }
52
+ if (error.response?.status === 409) {
53
+ throw new Error(`ACL entry for entity "${entity}" already exists on bucket "${bucket}".`);
54
+ }
55
+ throw new Error(`Failed to create bucket ACL: ${error.message || 'Unknown error'}`);
56
+ }
57
+ },
58
+ });
@@ -0,0 +1,58 @@
1
+ import { createAction, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
+ import { googleCloudStorageAuth } from '../common/auth';
3
+ import { gcsCommon } from '../common/client';
4
+ import { bucketDropdown, aclEntityProperty, objectAclRoleProperty, projectIdProperty } from '../common/props';
5
+ import { HttpMethod } from '@agnocon/pieces-common';
6
+
7
+ export const createBucketDefaultObjectAcl = createAction({
8
+ auth: googleCloudStorageAuth,
9
+ name: 'create_bucket_default_object_acl',
10
+ displayName: 'Create Bucket Default Object ACL',
11
+ description: 'Set default ACLs for new objects added to a bucket. Perfect for automatically assigning permissions to new uploads.',
12
+ audience: 'both',
13
+ aiMetadata: { description: 'Adds an entry to a bucket\'s default object ACL, which is applied automatically to objects later uploaded without their own ACL. Use to pre-set permissions for future uploads. Not idempotent: adding an entry that already exists fails, and it does not affect existing objects. Only works on buckets using fine-grained ACLs, not uniform bucket-level access; requires bucket, entity, and role.', idempotent: false },
14
+ props: {
15
+ projectId: projectIdProperty,
16
+ bucket: bucketDropdown,
17
+ entity: aclEntityProperty,
18
+ role: objectAclRoleProperty,
19
+ },
20
+ async run(context) {
21
+ const { bucket, entity, role } = context.propsValue;
22
+ const auth = context.auth as OAuth2PropertyValue;
23
+
24
+ const aclEntry = {
25
+ entity,
26
+ role,
27
+ };
28
+
29
+ try {
30
+ const response = await gcsCommon.makeRequest(
31
+ HttpMethod.POST,
32
+ `/b/${bucket}/defaultObjectAcl`,
33
+ auth.access_token,
34
+ aclEntry
35
+ );
36
+
37
+ return {
38
+ success: true,
39
+ bucket,
40
+ acl: response,
41
+ };
42
+ } catch (error: any) {
43
+ if (error.response?.status === 400) {
44
+ throw new Error('Bad request. This bucket may have uniform bucket-level access enabled, which doesn\'t support default object ACLs. Use IAM policies instead.');
45
+ }
46
+ if (error.response?.status === 403) {
47
+ throw new Error('Access denied. You need storage.buckets.update permission to modify bucket default object ACLs.');
48
+ }
49
+ if (error.response?.status === 404) {
50
+ throw new Error(`Bucket "${bucket}" not found.`);
51
+ }
52
+ if (error.response?.status === 409) {
53
+ throw new Error(`Default object ACL entry for entity "${entity}" already exists on bucket "${bucket}".`);
54
+ }
55
+ throw new Error(`Failed to create bucket default object ACL: ${error.message || 'Unknown error'}`);
56
+ }
57
+ },
58
+ });
@@ -0,0 +1,75 @@
1
+ import { createAction, Property, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
+ import { googleCloudStorageAuth } from '../common/auth';
3
+ import { gcsCommon } from '../common/client';
4
+ import { projectIdProperty, bucketNameProperty, locationProperty, storageClassProperty } from '../common/props';
5
+ import { HttpMethod } from '@agnocon/pieces-common';
6
+
7
+ export const createBucket = createAction({
8
+ auth: googleCloudStorageAuth,
9
+ name: 'create_bucket',
10
+ displayName: 'Create Bucket',
11
+ description: 'Create a new bucket in a specified location/configuration. Perfect for automating storage provisioning for new projects.',
12
+ audience: 'both',
13
+ aiMetadata: { description: 'Creates a new Cloud Storage bucket in the given project, with optional location, storage class, versioning, uniform bucket-level access, and labels. Use to provision storage before uploading objects. Not idempotent: bucket names are globally unique, so re-running with the same name fails. Requires a project ID and a globally-unique bucket name.', idempotent: false },
14
+ props: {
15
+ projectId: projectIdProperty,
16
+ name: bucketNameProperty,
17
+ location: locationProperty,
18
+ storageClass: storageClassProperty,
19
+ versioning: Property.Checkbox({
20
+ displayName: 'Enable Versioning',
21
+ required: false,
22
+ }),
23
+ uniformBucketLevelAccess: Property.Checkbox({
24
+ displayName: 'Uniform Bucket Level Access',
25
+ required: false,
26
+ }),
27
+ labels: Property.Object({
28
+ displayName: 'Labels',
29
+ description: 'Key-value pairs for bucket labels',
30
+ required: false,
31
+ }),
32
+ },
33
+ async run(context) {
34
+ const { projectId, name, location, storageClass, versioning, uniformBucketLevelAccess, labels } = context.propsValue;
35
+ const auth = context.auth as OAuth2PropertyValue;
36
+
37
+ const bucketConfig: any = {
38
+ name,
39
+ location: location || 'US',
40
+ storageClass: storageClass || 'STANDARD',
41
+ };
42
+
43
+ if (versioning) {
44
+ bucketConfig.versioning = { enabled: true };
45
+ }
46
+
47
+ if (uniformBucketLevelAccess !== undefined) {
48
+ bucketConfig.iamConfiguration = {
49
+ uniformBucketLevelAccess: {
50
+ enabled: uniformBucketLevelAccess,
51
+ },
52
+ };
53
+ }
54
+
55
+ if (labels) {
56
+ bucketConfig.labels = labels;
57
+ }
58
+
59
+ try {
60
+ const response = await gcsCommon.makeRequest(HttpMethod.POST, `/b?project=${projectId}`, auth.access_token, bucketConfig);
61
+ return response;
62
+ } catch (error: any) {
63
+ if (error.response?.status === 409) {
64
+ throw new Error(`Bucket "${name}" already exists. Bucket names must be globally unique.`);
65
+ }
66
+ if (error.response?.status === 403) {
67
+ throw new Error('Access denied. Check your permissions for the selected project.');
68
+ }
69
+ if (error.response?.status === 400) {
70
+ throw new Error('Invalid bucket configuration. Check bucket name format and project settings.');
71
+ }
72
+ throw new Error(`Failed to create bucket: ${error.message || 'Unknown error'}`);
73
+ }
74
+ },
75
+ });
@@ -0,0 +1,81 @@
1
+ import {
2
+ createAction,
3
+ Property,
4
+ OAuth2PropertyValue,
5
+ } from '@agnocon/pieces-framework';
6
+ import { googleCloudStorageAuth } from '../common/auth';
7
+ import { gcsCommon } from '../common/client';
8
+ import {
9
+ bucketDropdown,
10
+ objectDropdown,
11
+ aclEntityProperty,
12
+ objectAclRoleProperty,
13
+ projectIdProperty,
14
+ } from '../common/props';
15
+ import { HttpMethod } from '@agnocon/pieces-common';
16
+
17
+ export const createObjectAcl = createAction({
18
+ auth: googleCloudStorageAuth,
19
+ name: 'create_object_acl',
20
+ displayName: 'Create Object ACL',
21
+ description: 'Add an ACL entry to an object (grant a permission). Perfect for granting read/write access to a user or group.',
22
+ audience: 'both',
23
+ aiMetadata: { description: 'Grants an entity (user, group, domain, or special scope) a role on a single object\'s access-control list, optionally targeting a specific generation. Use to give read or owner access to one file. Not idempotent: adding an entry that already exists fails. Only works on buckets using fine-grained ACLs, not uniform bucket-level access; requires bucket, object, entity, and role.', idempotent: false },
24
+ props: {
25
+ projectId: projectIdProperty,
26
+ bucket: bucketDropdown,
27
+ object: objectDropdown('bucket'),
28
+ entity: aclEntityProperty,
29
+ role: objectAclRoleProperty,
30
+ generation: Property.Number({
31
+ displayName: 'Generation',
32
+ description: 'Optional generation number for versioned objects',
33
+ required: false,
34
+ }),
35
+ },
36
+ async run(context) {
37
+ const { bucket, object, entity, role, generation } = context.propsValue;
38
+ const auth = context.auth as OAuth2PropertyValue;
39
+
40
+ const aclEntry = {
41
+ entity,
42
+ role,
43
+ };
44
+
45
+ let path = `/b/${bucket}/o/${encodeURIComponent(object as string)}/acl`;
46
+ if (generation) {
47
+ path += `?generation=${generation}`;
48
+ }
49
+
50
+ try {
51
+ const response = await gcsCommon.makeRequest(
52
+ HttpMethod.POST,
53
+ path,
54
+ auth.access_token,
55
+ aclEntry
56
+ );
57
+
58
+ return {
59
+ success: true,
60
+ bucket,
61
+ object,
62
+ generation: generation || 'latest',
63
+ acl: response,
64
+ };
65
+ } catch (error: any) {
66
+ if (error.response?.status === 400) {
67
+ throw new Error('Bad request. This bucket may have uniform bucket-level access enabled, which doesn\'t support object ACLs. Use IAM policies instead.');
68
+ }
69
+ if (error.response?.status === 403) {
70
+ throw new Error('Access denied. You need storage.objects.setIamPolicy permission or OWNER ACL permission on the object.');
71
+ }
72
+ if (error.response?.status === 404) {
73
+ throw new Error(`Object "${object}" not found in bucket "${bucket}".`);
74
+ }
75
+ if (error.response?.status === 409) {
76
+ throw new Error(`ACL entry for entity "${entity}" already exists on this object.`);
77
+ }
78
+ throw new Error(`Failed to create object ACL: ${error.message || 'Unknown error'}`);
79
+ }
80
+ },
81
+ });
@@ -0,0 +1,52 @@
1
+ import { createAction, OAuth2PropertyValue } from '@agnocon/pieces-framework';
2
+ import { googleCloudStorageAuth } from '../common/auth';
3
+ import { gcsCommon } from '../common/client';
4
+ import { bucketDropdown, aclEntityProperty, projectIdProperty } from '../common/props';
5
+ import { HttpMethod } from '@agnocon/pieces-common';
6
+
7
+ export const deleteBucketAcl = createAction({
8
+ auth: googleCloudStorageAuth,
9
+ name: 'delete_bucket_acl',
10
+ displayName: 'Delete Bucket ACL',
11
+ description: 'Remove an ACL entry from a bucket. Perfect for revoking access for a user or group.',
12
+ audience: 'both',
13
+ aiMetadata: { description: 'Removes an entity\'s entry from a bucket\'s own access-control list. Use to revoke a user or group\'s access to the bucket. Not idempotent: the first call removes the entry and a repeat fails because it no longer exists. Only works on buckets using fine-grained ACLs, not uniform bucket-level access; requires bucket and entity.', idempotent: false },
14
+ props: {
15
+ projectId: projectIdProperty,
16
+ bucket: bucketDropdown,
17
+ entity: aclEntityProperty,
18
+ },
19
+ async run(context) {
20
+ const { bucket, entity } = context.propsValue;
21
+ const auth = context.auth as OAuth2PropertyValue;
22
+
23
+ try {
24
+ await gcsCommon.makeRequest(
25
+ HttpMethod.DELETE,
26
+ `/b/${bucket}/acl/${encodeURIComponent(entity)}`,
27
+ auth.access_token
28
+ );
29
+
30
+ return {
31
+ success: true,
32
+ bucket,
33
+ entity,
34
+ message: `ACL entry for entity "${entity}" removed successfully from bucket "${bucket}"`,
35
+ };
36
+ } catch (error: any) {
37
+ if (error.response?.status === 400) {
38
+ throw new Error('Bad request. This bucket may have uniform bucket-level access enabled, which doesn\'t support bucket ACLs. Use IAM policies instead.');
39
+ }
40
+ if (error.response?.status === 403) {
41
+ throw new Error('Access denied. You need storage.buckets.update permission to modify bucket ACLs.');
42
+ }
43
+ if (error.response?.status === 404) {
44
+ if (error.response?.data?.error?.message?.includes('ACL')) {
45
+ throw new Error(`ACL entry for entity "${entity}" not found on bucket "${bucket}".`);
46
+ }
47
+ throw new Error(`Bucket "${bucket}" not found.`);
48
+ }
49
+ throw new Error(`Failed to delete bucket ACL: ${error.message || 'Unknown error'}`);
50
+ }
51
+ },
52
+ });