@activepieces/piece-google-drive 0.0.0-pre1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # pieces-google-drive
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running lint
6
+
7
+ Run `nx lint pieces-google-drive` to execute the lint via [ESLint](https://eslint.org/).
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@activepieces/piece-google-drive",
3
+ "version": "0.0.0-pre1",
4
+ "dependencies": {
5
+ "@sinclair/typebox": "0.24.51",
6
+ "axios": "1.2.4",
7
+ "cron-validator": "1.3.1",
8
+ "form-data": "4.0.0",
9
+ "nanoid": "3.3.4"
10
+ },
11
+ "peerDependencies": {
12
+ "@activepieces/framework": "0.0.1",
13
+ "@activepieces/shared": "0.0.1",
14
+ "tslib": "2.4.1"
15
+ },
16
+ "main": "./src/index.js",
17
+ "types": "./src/index.d.ts"
18
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const googleDrive: import("@activepieces/framework").Piece;
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleDrive = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const package_json_1 = tslib_1.__importDefault(require("../package.json"));
6
+ const framework_1 = require("@activepieces/framework");
7
+ const create_new_folder_1 = require("./lib/action/create-new-folder");
8
+ const create_new_text_file_1 = require("./lib/action/create-new-text-file");
9
+ exports.googleDrive = (0, framework_1.createPiece)({
10
+ name: 'google_drive',
11
+ logoUrl: 'https://cdn.activepieces.com/pieces/google_drive.png',
12
+ actions: [create_new_folder_1.googleDriveCreateNewFolder, create_new_text_file_1.googleDriveCreateNewTextFile],
13
+ displayName: "Google Drive",
14
+ authors: ['kanarelo'],
15
+ triggers: [],
16
+ version: package_json_1.default.version,
17
+ });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/google-drive/src/index.ts"],"names":[],"mappings":";;;;AAAA,2EAA0C;AAC1C,uDAAsD;AACtD,sEAA4E;AAC5E,4EAAiF;AAEpE,QAAA,WAAW,GAAG,IAAA,uBAAW,EAAC;IACtC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,sDAAsD;IAC/D,OAAO,EAAE,CAAC,8CAA0B,EAAE,mDAA4B,CAAC;IACnE,WAAW,EAAE,cAAc;IAC3B,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB,QAAQ,EAAE,EAAE;IACX,OAAO,EAAE,sBAAW,CAAC,OAAO;CAC7B,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const googleDriveCreateNewFolder: import("@activepieces/framework").Action;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleDriveCreateNewFolder = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const framework_1 = require("@activepieces/framework");
6
+ exports.googleDriveCreateNewFolder = (0, framework_1.createAction)({
7
+ name: 'create_new_gdrive_folder',
8
+ description: 'Create a new empty folder in your Google Drive',
9
+ displayName: 'Create new folder',
10
+ props: {
11
+ authentication: framework_1.Property.OAuth2({
12
+ description: "",
13
+ displayName: 'Authentication',
14
+ authUrl: "https://accounts.google.com/o/oauth2/auth",
15
+ tokenUrl: "https://oauth2.googleapis.com/token",
16
+ required: true,
17
+ scope: ["https://www.googleapis.com/auth/drive"]
18
+ }),
19
+ folderName: framework_1.Property.ShortText({
20
+ displayName: 'Folder name',
21
+ description: 'The name of the new folder',
22
+ required: true,
23
+ }),
24
+ parentFolder: framework_1.Property.Dropdown({
25
+ displayName: "Parent Folder",
26
+ required: false,
27
+ refreshers: ['authentication'],
28
+ options: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
29
+ if (!propsValue['authentication']) {
30
+ return {
31
+ disabled: true,
32
+ options: [],
33
+ placeholder: 'Please authenticate first'
34
+ };
35
+ }
36
+ const authProp = propsValue['authentication'];
37
+ const folders = (yield framework_1.httpClient.sendRequest({
38
+ method: framework_1.HttpMethod.GET,
39
+ url: `https://www.googleapis.com/drive/v3/files`,
40
+ queryParams: {
41
+ q: "mimeType='application/vnd.google-apps.folder'"
42
+ },
43
+ authentication: {
44
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
45
+ token: authProp['access_token'],
46
+ }
47
+ })).body.files;
48
+ return {
49
+ disabled: false,
50
+ options: folders.map((sheet) => {
51
+ return {
52
+ label: sheet.name,
53
+ value: sheet.id
54
+ };
55
+ })
56
+ };
57
+ })
58
+ }),
59
+ },
60
+ sampleData: {
61
+ "kind": "drive#file",
62
+ "id": "1zBGDdjasE4A63269CXhqOvAe3odTsplF",
63
+ "name": "New Folder",
64
+ "mimeType": "application/vnd.google-apps.folder"
65
+ },
66
+ run(context) {
67
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
68
+ const body = Object.assign({ 'mimeType': "application/vnd.google-apps.folder", 'name': context.propsValue.folderName }, (context.propsValue.parentFolder ? { 'parents': [context.propsValue.parentFolder] } : {}));
69
+ const request = {
70
+ method: framework_1.HttpMethod.POST,
71
+ url: `https://www.googleapis.com/drive/v3/files`,
72
+ body: body,
73
+ authentication: {
74
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
75
+ token: context.propsValue['authentication']['access_token'],
76
+ }
77
+ };
78
+ const result = yield framework_1.httpClient.sendRequest(request);
79
+ console.debug("Folder creation response", result);
80
+ if (result.status == 200) {
81
+ return result.body;
82
+ }
83
+ else {
84
+ return result;
85
+ }
86
+ });
87
+ }
88
+ });
89
+ //# sourceMappingURL=create-new-folder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-new-folder.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/google-drive/src/lib/action/create-new-folder.ts"],"names":[],"mappings":";;;;AAAA,uDAA+I;A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;CACF,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const googleDriveCreateNewTextFile: import("@activepieces/framework").Action;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleDriveCreateNewTextFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const framework_1 = require("@activepieces/framework");
6
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
7
+ exports.googleDriveCreateNewTextFile = (0, framework_1.createAction)({
8
+ name: 'create_new_gdrive_file',
9
+ description: 'Create a new text file in your Google Drive from text',
10
+ displayName: 'Create new file',
11
+ props: {
12
+ authentication: framework_1.Property.OAuth2({
13
+ description: "",
14
+ displayName: 'Authentication',
15
+ authUrl: "https://accounts.google.com/o/oauth2/auth",
16
+ tokenUrl: "https://oauth2.googleapis.com/token",
17
+ required: true,
18
+ scope: ["https://www.googleapis.com/auth/drive"]
19
+ }),
20
+ fileName: framework_1.Property.ShortText({
21
+ displayName: 'File name',
22
+ description: 'The name of the new text file',
23
+ required: true,
24
+ }),
25
+ text: framework_1.Property.LongText({
26
+ displayName: 'Text',
27
+ description: 'The text content to add to file',
28
+ required: true,
29
+ }),
30
+ parentFolder: framework_1.Property.Dropdown({
31
+ displayName: "Parent Folder",
32
+ required: false,
33
+ refreshers: ['authentication'],
34
+ options: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
35
+ if (!propsValue['authentication']) {
36
+ return {
37
+ disabled: true,
38
+ options: [],
39
+ placeholder: 'Please authenticate first'
40
+ };
41
+ }
42
+ const authProp = propsValue['authentication'];
43
+ const folders = (yield framework_1.httpClient.sendRequest({
44
+ method: framework_1.HttpMethod.GET,
45
+ url: `https://www.googleapis.com/drive/v3/files`,
46
+ queryParams: {
47
+ q: "mimeType='application/vnd.google-apps.folder'"
48
+ },
49
+ authentication: {
50
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
51
+ token: authProp['access_token'],
52
+ }
53
+ })).body.files;
54
+ return {
55
+ disabled: false,
56
+ options: folders.map((sheet) => {
57
+ return {
58
+ label: sheet.name,
59
+ value: sheet.id
60
+ };
61
+ })
62
+ };
63
+ })
64
+ }),
65
+ },
66
+ sampleData: {
67
+ "kind": "drive#file",
68
+ "id": "1VjCR4-747AvKH7KeQ6GclFpCnu_41ZDX",
69
+ "name": "text.txt",
70
+ "mimeType": "plain/text"
71
+ },
72
+ run(context) {
73
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
74
+ const meta = Object.assign({ 'mimeType': "plain/text", 'name': context.propsValue.fileName }, (context.propsValue.parentFolder ? { 'parents': [context.propsValue.parentFolder] } : {}));
75
+ const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
76
+ const textBuffer = Buffer.from(context.propsValue.text, 'utf-8');
77
+ const form = new form_data_1.default();
78
+ form.append("Metadata", metaBuffer, { contentType: 'application/json' });
79
+ form.append("Media", textBuffer, { contentType: 'plain/text' });
80
+ const result = yield framework_1.httpClient.sendRequest({
81
+ method: framework_1.HttpMethod.POST,
82
+ url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart`,
83
+ body: form,
84
+ headers: Object.assign({}, form.getHeaders()),
85
+ authentication: {
86
+ type: framework_1.AuthenticationType.BEARER_TOKEN,
87
+ token: context.propsValue['authentication']['access_token'],
88
+ }
89
+ });
90
+ console.debug("File creation response", result);
91
+ return result.body;
92
+ });
93
+ }
94
+ });
95
+ //# sourceMappingURL=create-new-text-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-new-text-file.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/google-drive/src/lib/action/create-new-text-file.ts"],"names":[],"mappings":";;;;AAAA,uDAAkI;AAClI,kEAAiC;AAEpB,QAAA,4BAA4B,GAAG,IAAA,wBAAY,EAAC;IACvD,IAAI,EAAE,wBAAwB;IAC9B,WAAW,EAAE,uDAAuD;IACpE,WAAW,EAAE,iBAAiB;IAC9B,KAAK,EAAE;QACL,cAAc,EAAE,oBA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