@activepieces/piece-google-drive 0.3.0 → 0.4.0

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/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@activepieces/piece-google-drive",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "dependencies": {
5
5
  "@sinclair/typebox": "^0.26.3",
6
6
  "axios": "1.2.4",
7
7
  "form-data": "^4.0.0",
8
+ "mime-types": "^2.1.35",
8
9
  "nanoid": "^3.3.4",
9
10
  "@activepieces/pieces-common": "0.1.0",
10
11
  "@activepieces/pieces-framework": "0.4.0",
package/src/index.js CHANGED
@@ -4,6 +4,7 @@ exports.googleDrive = exports.googleDriveAuth = void 0;
4
4
  const pieces_framework_1 = require("@activepieces/pieces-framework");
5
5
  const create_new_folder_1 = require("./lib/action/create-new-folder");
6
6
  const create_new_text_file_1 = require("./lib/action/create-new-text-file");
7
+ const upload_file_1 = require("./lib/action/upload-file");
7
8
  exports.googleDriveAuth = pieces_framework_1.PieceAuth.OAuth2({
8
9
  description: "",
9
10
  displayName: 'Authentication',
@@ -15,9 +16,9 @@ exports.googleDriveAuth = pieces_framework_1.PieceAuth.OAuth2({
15
16
  exports.googleDrive = (0, pieces_framework_1.createPiece)({
16
17
  minimumSupportedRelease: '0.5.0',
17
18
  logoUrl: 'https://cdn.activepieces.com/pieces/google-drive.png',
18
- actions: [create_new_folder_1.googleDriveCreateNewFolder, create_new_text_file_1.googleDriveCreateNewTextFile],
19
+ actions: [create_new_folder_1.googleDriveCreateNewFolder, create_new_text_file_1.googleDriveCreateNewTextFile, upload_file_1.googleDriveUploadFile],
19
20
  displayName: "Google Drive",
20
- authors: ['kanarelo'],
21
+ authors: ['kanarelo', 'BastienMe'],
21
22
  triggers: [],
22
23
  auth: exports.googleDriveAuth,
23
24
  });
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/google-drive/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AACxE,sEAA4E;AAC5E,4EAAiF;AAEpE,QAAA,eAAe,GAAG,4BAAS,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,gBAAgB;IAC7B,OAAO,EAAE,2CAA2C;IACpD,QAAQ,EAAE,qCAAqC;IAC/C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,CAAC,uCAAuC,CAAC;CACnD,CAAC,CAAA;AAEW,QAAA,WAAW,GAAG,IAAA,8BAAW,EAAC;IAClC,uBAAuB,EAAE,OAAO;IACjC,OAAO,EAAE,sDAAsD;IAClE,OAAO,EAAE,CAAC,8CAA0B,EAAE,mDAA4B,CAAC;IACnE,WAAW,EAAE,cAAc;IAC3B,OAAO,EAAE,CAAC,UAAU,CAAC;IACrB,QAAQ,EAAE,EAAE;IACT,IAAI,EAAE,uBAAe;CACxB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/pieces/google-drive/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AACxE,sEAA4E;AAC5E,4EAAiF;AACjF,0DAAiE;AAEpD,QAAA,eAAe,GAAG,4BAAS,CAAC,MAAM,CAAC;IAC5C,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,gBAAgB;IAC7B,OAAO,EAAE,2CAA2C;IACpD,QAAQ,EAAE,qCAAqC;IAC/C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE,CAAC,uCAAuC,CAAC;CACnD,CAAC,CAAA;AAEW,QAAA,WAAW,GAAG,IAAA,8BAAW,EAAC;IACtC,uBAAuB,EAAE,OAAO;IAC7B,OAAO,EAAE,sDAAsD;IAClE,OAAO,EAAE,CAAC,8CAA0B,EAAE,mDAA4B,EAAE,mCAAqB,CAAC;IAC1F,WAAW,EAAE,cAAc;IAC3B,OAAO,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;IAClC,QAAQ,EAAE,EAAE;IACT,IAAI,EAAE,uBAAe;CACxB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const googleDriveUploadFile: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").OAuth2Property<true, import("@activepieces/pieces-framework").OAuth2Props>, {
2
+ fileName: import("@activepieces/pieces-framework").ShortTextProperty<true>;
3
+ file: import("@activepieces/pieces-framework").FileProperty<true>;
4
+ parentFolder: import("@activepieces/pieces-framework").DropdownProperty<string, false>;
5
+ }>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleDriveUploadFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const pieces_common_1 = require("@activepieces/pieces-common");
7
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
8
+ const __1 = require("../../");
9
+ const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
10
+ exports.googleDriveUploadFile = (0, pieces_framework_1.createAction)({
11
+ auth: __1.googleDriveAuth,
12
+ name: 'upload_gdrive_file',
13
+ description: 'Upload a file in your Google Drive',
14
+ displayName: 'Upload file',
15
+ props: {
16
+ fileName: pieces_framework_1.Property.ShortText({
17
+ displayName: 'File name',
18
+ description: 'The name of the file',
19
+ required: true,
20
+ }),
21
+ file: pieces_framework_1.Property.File({
22
+ displayName: "File",
23
+ description: "The file URL or base64 to upload",
24
+ required: true,
25
+ }),
26
+ parentFolder: pieces_framework_1.Property.Dropdown({
27
+ displayName: "Parent Folder",
28
+ required: false,
29
+ refreshers: [],
30
+ options: ({ auth }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
31
+ if (!auth) {
32
+ return {
33
+ disabled: true,
34
+ options: [],
35
+ placeholder: 'Please authenticate first'
36
+ };
37
+ }
38
+ const authProp = auth;
39
+ const folders = (yield pieces_common_1.httpClient.sendRequest({
40
+ method: pieces_common_1.HttpMethod.GET,
41
+ url: `https://www.googleapis.com/drive/v3/files`,
42
+ queryParams: {
43
+ q: "mimeType='application/vnd.google-apps.folder'"
44
+ },
45
+ authentication: {
46
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
47
+ token: authProp['access_token'],
48
+ }
49
+ })).body.files;
50
+ return {
51
+ disabled: false,
52
+ options: folders.map((sheet) => {
53
+ return {
54
+ label: sheet.name,
55
+ value: sheet.id
56
+ };
57
+ })
58
+ };
59
+ })
60
+ }),
61
+ },
62
+ sampleData: {
63
+ "kind": "drive#file",
64
+ "id": "1VjCR4-747AvKH7KeQ6GclFpCnu_41ZDX",
65
+ "name": "text.txt",
66
+ "mimeType": "plain/text"
67
+ },
68
+ run(context) {
69
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
70
+ const fileData = context.propsValue.file;
71
+ const mimeType = mime_types_1.default.lookup(fileData.extension ? fileData.extension : '');
72
+ const meta = Object.assign({ 'mimeType': mimeType, 'name': context.propsValue.fileName }, (context.propsValue.parentFolder ? { 'parents': [context.propsValue.parentFolder] } : {}));
73
+ const metaBuffer = Buffer.from(JSON.stringify(meta), 'utf-8');
74
+ const fileBuffer = Buffer.from(fileData.base64, 'base64');
75
+ const form = new form_data_1.default();
76
+ form.append("Metadata", metaBuffer, { contentType: 'application/json' });
77
+ form.append("Media", fileBuffer);
78
+ const result = yield pieces_common_1.httpClient.sendRequest({
79
+ method: pieces_common_1.HttpMethod.POST,
80
+ url: `https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart`,
81
+ body: form,
82
+ headers: Object.assign({}, form.getHeaders()),
83
+ authentication: {
84
+ type: pieces_common_1.AuthenticationType.BEARER_TOKEN,
85
+ token: context.auth.access_token,
86
+ }
87
+ });
88
+ console.debug("File upload response", result);
89
+ return result.body;
90
+ });
91
+ }
92
+ });
93
+ //# sourceMappingURL=upload-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/google-drive/src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