guratan 0.2.1 → 0.3.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/dist/cli.d.ts CHANGED
@@ -1,12 +1,31 @@
1
1
  /// <reference types="node" />
2
2
  import { Writable } from 'stream';
3
3
  declare type Opts = {
4
+ stdout: Writable;
5
+ stderr: Writable;
6
+ };
7
+ declare type OptsSend = Opts & {
4
8
  parentId: string;
5
9
  destFileName: string;
6
10
  srcFileName: string;
11
+ destMimeType: string;
12
+ srcMimeType: string;
13
+ printId: boolean;
14
+ };
15
+ declare type OptsShare = Opts & {
16
+ fileId: string;
17
+ type: string;
18
+ role: string;
19
+ emailAddress: string;
20
+ domain: string;
21
+ allowFileDiscovery?: boolean;
22
+ view: string;
23
+ moveToNewOwnersRoot?: boolean;
24
+ transferOwnership?: boolean;
25
+ sendNotificationEmail?: boolean;
26
+ emailMessage: string;
7
27
  printId: boolean;
8
- stdout: Writable;
9
- stderr: Writable;
10
28
  };
11
- export declare const cli: ({ parentId, destFileName, srcFileName, printId, stdout, stderr }: Opts) => Promise<number>;
29
+ export declare const cliSend: ({ parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }: OptsSend) => Promise<number>;
30
+ export declare const cliShare: ({ fileId, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }: OptsShare) => Promise<number>;
12
31
  export {};
package/dist/cli.js CHANGED
@@ -1,7 +1,41 @@
1
- import { driveClient, sendFile } from './tsend.js';
2
- export const cli = async ({ parentId, destFileName, srcFileName, printId, stdout, stderr }) => {
1
+ import { driveClient } from './tdrive.js';
2
+ import { sendFile } from './tsend.js';
3
+ import { createPermisson } from './tshare.js';
4
+ export const cliSend = async ({ parentId, destFileName, srcFileName, destMimeType, srcMimeType, printId, stdout, stderr }) => {
3
5
  try {
4
- const id = await sendFile(driveClient(), parentId, destFileName, srcFileName);
6
+ const id = await sendFile(driveClient(), {
7
+ parentId,
8
+ destFileName,
9
+ srcFileName,
10
+ destMimeType,
11
+ srcMimeType
12
+ });
13
+ if (printId) {
14
+ stdout.write(id);
15
+ }
16
+ }
17
+ catch (err) {
18
+ stderr.write(err.toString());
19
+ stderr.write('\n');
20
+ return 1;
21
+ }
22
+ return 0;
23
+ };
24
+ export const cliShare = async ({ fileId, type, role, emailAddress, domain, allowFileDiscovery, view, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage, printId, stdout, stderr }) => {
25
+ try {
26
+ const id = await createPermisson(driveClient(), {
27
+ fileId,
28
+ type,
29
+ role,
30
+ emailAddress,
31
+ domain,
32
+ allowFileDiscovery,
33
+ view,
34
+ moveToNewOwnersRoot,
35
+ transferOwnership,
36
+ sendNotificationEmail,
37
+ emailMessage
38
+ });
5
39
  if (printId) {
6
40
  stdout.write(id);
7
41
  }
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
+ export { driveClient } from './tdrive.js';
1
2
  export { sendFile } from './tsend.js';
3
+ export { createPermisson } from './tshare.js';
package/dist/index.js CHANGED
@@ -1 +1,3 @@
1
+ export { driveClient } from './tdrive.js';
1
2
  export { sendFile } from './tsend.js';
3
+ export { createPermisson } from './tshare.js';
package/dist/main.js CHANGED
@@ -1,24 +1,110 @@
1
1
  #!/usr/bin/env node
2
2
  import yargs from 'yargs';
3
3
  import { hideBin } from 'yargs/helpers';
4
- import { cli } from './cli.js';
4
+ import { cliSend, cliShare } from './cli.js';
5
5
  const envVarsPrefix = process.env['GURATAN_ENV_VARS_PREFIX'] || 'GURATAN';
6
6
  const argv = await yargs(hideBin(process.argv))
7
7
  .scriptName('guratan')
8
8
  .env(envVarsPrefix)
9
- .command('$0 send [OPTIONS]', 'send file to folder in Google Drive', (yargs) => {
9
+ .command('send [OPTIONS]', 'send file to folder in Google Drive', (yargs) => {
10
10
  return yargs.options({
11
11
  'parent-id': {
12
12
  type: 'string',
13
- description: 'id of folder in Google Deive'
13
+ required: true,
14
+ description: 'The IDs of the parent folders which contain the file.'
14
15
  },
15
16
  'dest-file-name': {
16
17
  type: 'string',
17
- description: 'file name in Google Drive'
18
+ required: true,
19
+ description: 'The name of the file in remote'
18
20
  },
19
21
  'src-file-name': {
20
22
  type: 'string',
21
- description: 'file name in local filesystem'
23
+ required: true,
24
+ description: 'The name(path) of the file in local filesystem'
25
+ },
26
+ 'dest-mime-type': {
27
+ type: 'string',
28
+ required: false,
29
+ default: '',
30
+ description: 'The MIME type of the file.'
31
+ },
32
+ 'src-mime-type': {
33
+ type: 'string',
34
+ required: false,
35
+ default: '',
36
+ description: 'Media mime-type'
37
+ },
38
+ 'print-id': {
39
+ type: 'boolean',
40
+ required: false,
41
+ default: false,
42
+ description: 'Print the id of the file that is sended into remote'
43
+ }
44
+ });
45
+ })
46
+ .command('share [OPTIONS]', 'share file in Google Drive', (yargs) => {
47
+ return yargs.options({
48
+ 'file-id': {
49
+ type: 'string',
50
+ default: 'reader',
51
+ required: false,
52
+ description: 'The ID of the file or shared drive.'
53
+ },
54
+ type: {
55
+ choices: ['user', 'group', 'domain', 'anyone'],
56
+ required: false,
57
+ default: 'user',
58
+ description: 'The type of the grantee.'
59
+ },
60
+ role: {
61
+ choices: [
62
+ 'owner',
63
+ 'organizer',
64
+ 'fileOrganizer',
65
+ 'writer',
66
+ 'commenter',
67
+ 'reader'
68
+ ],
69
+ required: false,
70
+ default: 'reader',
71
+ description: 'The role granted by this permission'
72
+ },
73
+ 'email-address': {
74
+ type: 'string',
75
+ default: '',
76
+ description: 'The email address of the user or group to which this permission refers.'
77
+ },
78
+ domain: {
79
+ type: 'string',
80
+ default: '',
81
+ description: 'The domain to which this permission refers. '
82
+ },
83
+ 'move-to-new-owners-root': {
84
+ type: 'boolean',
85
+ description: 'This parameter will only take effect if the item is not in a shared drive and the request is attempting to transfer the ownership of the item.'
86
+ },
87
+ 'allow-file-discovery': {
88
+ type: 'boolean',
89
+ description: 'Whether the permission allows the file to be discovered through search.'
90
+ },
91
+ view: {
92
+ type: 'string',
93
+ default: '',
94
+ description: 'Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type domain or anyone.'
95
+ },
96
+ 'transfer-ownership': {
97
+ type: 'boolean',
98
+ description: 'Whether to transfer ownership to the specified user and downgrade the current owner to a writer.'
99
+ },
100
+ 'send-notification-email': {
101
+ type: 'boolean',
102
+ description: 'Whether to send a notification email when sharing to users or groups.'
103
+ },
104
+ 'email-message': {
105
+ type: 'string',
106
+ default: '',
107
+ description: 'A plain text custom message to include in the notification email.'
22
108
  },
23
109
  'print-id': {
24
110
  type: 'boolean',
@@ -28,13 +114,43 @@ const argv = await yargs(hideBin(process.argv))
28
114
  }
29
115
  });
30
116
  })
117
+ .demandCommand()
31
118
  .demand(0)
119
+ .strictOptions(true)
32
120
  .help().argv;
33
- process.exit(await cli({
34
- parentId: argv['parent-id'] || '',
35
- destFileName: argv['dest-file-name'] || '',
36
- srcFileName: argv['src-file-name'] || '',
37
- printId: argv['print-id'] || false,
38
- stdout: process.stdout,
39
- stderr: process.stderr
40
- }));
121
+ switch (`${argv._[0]}`) {
122
+ case 'send':
123
+ process.exit(await cliSend({
124
+ parentId: argv['parent-id'] || '',
125
+ destFileName: argv['dest-file-name'] || '',
126
+ srcFileName: argv['src-file-name'] || '',
127
+ destMimeType: argv['dest-mime-type'] || '',
128
+ srcMimeType: argv['src-mime-type'] || '',
129
+ printId: argv['print-id'] || false,
130
+ stdout: process.stdout,
131
+ stderr: process.stderr
132
+ }));
133
+ break;
134
+ case 'share':
135
+ process.exit(await cliShare({
136
+ fileId: argv['file-id'],
137
+ type: argv['type'],
138
+ role: argv['role'],
139
+ emailAddress: argv['email-address'],
140
+ domain: argv['domain'],
141
+ view: argv['view'],
142
+ allowFileDiscovery: argv['allow-file-discovery'],
143
+ moveToNewOwnersRoot: argv['move-to-new-owners-root'],
144
+ transferOwnership: argv['transfer-ownership'],
145
+ sendNotificationEmail: argv['send-notification-email'],
146
+ printId: argv['print-id'] || false,
147
+ emailMessage: argv['email-message'],
148
+ stdout: process.stdout,
149
+ stderr: process.stderr
150
+ }));
151
+ break;
152
+ default:
153
+ console.log(argv);
154
+ process.stderr.write(`unknown command: ${argv._[0]}\n`);
155
+ process.exit(1);
156
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Validate value that is used in query parameter.
3
+ * return false if value has included "'">
4
+ * @param s - value string.
5
+ * @returns result of validation.
6
+ */
7
+ export declare function validateQueryValue(s: string): boolean;
8
+ /**
9
+ * Make instacen of drive that is authenticated.
10
+ * @returns instance of drive.
11
+ */
12
+ export declare function driveClient(): import("@googleapis/drive").drive_v3.Drive;
package/dist/tdrive.js ADDED
@@ -0,0 +1,25 @@
1
+ import { GoogleAuth } from 'google-auth-library';
2
+ import { drive as gdrive } from '@googleapis/drive';
3
+ /**
4
+ * Validate value that is used in query parameter.
5
+ * return false if value has included "'">
6
+ * @param s - value string.
7
+ * @returns result of validation.
8
+ */
9
+ export function validateQueryValue(s) {
10
+ if (s.indexOf("'") >= 0) {
11
+ return false;
12
+ }
13
+ return true;
14
+ }
15
+ /**
16
+ * Make instacen of drive that is authenticated.
17
+ * @returns instance of drive.
18
+ */
19
+ export function driveClient() {
20
+ const SCOPES = ['https://www.googleapis.com/auth/drive.file'];
21
+ const auth = new GoogleAuth({
22
+ scopes: SCOPES
23
+ });
24
+ return gdrive({ version: 'v3', auth });
25
+ }
package/dist/tsend.d.ts CHANGED
@@ -9,17 +9,30 @@ export declare class UpdateFileError extends Error {
9
9
  constructor(message: string);
10
10
  }
11
11
  /**
12
- * Validate value that is used in query parameter.
13
- * return false if value has included "'">
14
- * @param s - value string.
15
- * @returns result of validation.
12
+ * Options for sendFile().
16
13
  */
17
- export declare function validateQueryValue(s: string): boolean;
18
- /**
19
- * Make instacen of drive that is authenticated.
20
- * @returns instance of drive.
21
- */
22
- export declare function driveClient(): drive_v3.Drive;
14
+ export declare type SendFileOpts = {
15
+ /**
16
+ * @type The IDs of the parent folders which contain the file.
17
+ */
18
+ parentId: string;
19
+ /**
20
+ * @type The name of the file in remote
21
+ */
22
+ destFileName: string;
23
+ /**
24
+ @type The name(path) of the file in local filesystem
25
+ */
26
+ srcFileName: string;
27
+ /**
28
+ * @type The MIME type of the file.
29
+ */
30
+ destMimeType: string;
31
+ /**
32
+ * @type Media mime-type.
33
+ */
34
+ srcMimeType: string;
35
+ };
23
36
  /**
24
37
  * Get file id in spesiced parent.
25
38
  * @param drive - drive instance.
@@ -31,18 +44,23 @@ export declare function getFileId(drive: drive_v3.Drive, parentId: string, fileN
31
44
  /**
32
45
  * Create file using by source file into Google Drive.
33
46
  * @param drive - drive instance.
34
- * @param parentId - id of folder in Google Deive.
35
- * @param destFileName - file name in Google Drive.
36
- * @param srcFileName - file name in local filesystem.
37
- * @returns id of file in Google Drive
47
+ * @param opts - options.
48
+ * @returns Print the id of the file that is sended into remote
38
49
  */
39
- export declare function uploadFile(drive: drive_v3.Drive, parentId: string, destFileName: string, srcFileName: string): Promise<string>;
50
+ export declare function uploadFile(drive: drive_v3.Drive, opts: Pick<SendFileOpts, 'parentId' | 'destFileName' | 'srcFileName' | 'destMimeType' | 'srcMimeType'>): Promise<string>;
40
51
  /**
41
52
  * Update file using by source file into Google Drive.
42
53
  * @param drive - drive instance.
43
- * @param fileId - id of file in Google Deive.
44
- * @param srcFileName - file name in local filesystem.
54
+ * @param opts - options.
55
+ * @returns id of file in Google Drive
56
+ */
57
+ export declare function updateFile(drive: drive_v3.Drive, opts: {
58
+ fileId: string;
59
+ } & Pick<SendFileOpts, 'srcFileName' | 'destMimeType' | 'srcMimeType'>): Promise<string>;
60
+ /**
61
+ * Send file using by source file into Google Drive.
62
+ * @param drive - drive instance.
63
+ * @param opts - options.
45
64
  * @returns id of file in Google Drive
46
65
  */
47
- export declare function updateFile(drive: drive_v3.Drive, fileId: string, srcFileName: string): Promise<string>;
48
- export declare function sendFile(drive: drive_v3.Drive, parentId: string, destFileName: string, srcFileName: string): Promise<string>;
66
+ export declare function sendFile(drive: drive_v3.Drive, opts: SendFileOpts): Promise<string>;
package/dist/tsend.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import * as fs from 'fs';
3
- import { drive as gdrive } from '@googleapis/drive';
4
- import { GoogleAuth } from 'google-auth-library';
3
+ import { validateQueryValue } from './tdrive.js';
5
4
  export class GetFileIdError extends Error {
6
5
  constructor(message) {
7
6
  //https://stackoverflow.com/questions/41102060/typescript-extending-error-class
@@ -23,29 +22,6 @@ export class UpdateFileError extends Error {
23
22
  Object.setPrototypeOf(this, UpdateFileError.prototype);
24
23
  }
25
24
  }
26
- /**
27
- * Validate value that is used in query parameter.
28
- * return false if value has included "'">
29
- * @param s - value string.
30
- * @returns result of validation.
31
- */
32
- export function validateQueryValue(s) {
33
- if (s.indexOf("'") >= 0) {
34
- return false;
35
- }
36
- return true;
37
- }
38
- /**
39
- * Make instacen of drive that is authenticated.
40
- * @returns instance of drive.
41
- */
42
- export function driveClient() {
43
- const SCOPES = ['https://www.googleapis.com/auth/drive.file'];
44
- const auth = new GoogleAuth({
45
- scopes: SCOPES
46
- });
47
- return gdrive({ version: 'v3', auth });
48
- }
49
25
  /**
50
26
  * Get file id in spesiced parent.
51
27
  * @param drive - drive instance.
@@ -81,24 +57,29 @@ export async function getFileId(drive, parentId, fileName) {
81
57
  /**
82
58
  * Create file using by source file into Google Drive.
83
59
  * @param drive - drive instance.
84
- * @param parentId - id of folder in Google Deive.
85
- * @param destFileName - file name in Google Drive.
86
- * @param srcFileName - file name in local filesystem.
87
- * @returns id of file in Google Drive
60
+ * @param opts - options.
61
+ * @returns Print the id of the file that is sended into remote
88
62
  */
89
- export async function uploadFile(drive, parentId, destFileName, srcFileName) {
63
+ export async function uploadFile(drive, opts) {
90
64
  try {
91
- const res = await drive.files.create({
65
+ const { parentId, destFileName, srcFileName, destMimeType, srcMimeType } = opts;
66
+ const params = {
92
67
  requestBody: {
93
68
  name: path.basename(destFileName),
94
69
  parents: [parentId]
95
70
  },
96
71
  media: {
97
- // mimeType: 'image/jpeg',
98
72
  body: fs.createReadStream(srcFileName)
99
73
  },
100
74
  fields: 'id'
101
- });
75
+ };
76
+ if (destMimeType) {
77
+ params.requestBody.mimeType = destMimeType;
78
+ }
79
+ if (srcMimeType) {
80
+ params.media.mimeType = srcMimeType;
81
+ }
82
+ const res = await drive.files.create(params);
102
83
  return res.data.id || '';
103
84
  }
104
85
  catch (err) {
@@ -108,43 +89,50 @@ export async function uploadFile(drive, parentId, destFileName, srcFileName) {
108
89
  /**
109
90
  * Update file using by source file into Google Drive.
110
91
  * @param drive - drive instance.
111
- * @param fileId - id of file in Google Deive.
112
- * @param srcFileName - file name in local filesystem.
92
+ * @param opts - options.
113
93
  * @returns id of file in Google Drive
114
94
  */
115
- export async function updateFile(drive, fileId, srcFileName) {
95
+ export async function updateFile(drive, opts) {
116
96
  try {
117
- const res = await drive.files.update({
97
+ const { fileId, srcFileName, destMimeType, srcMimeType } = opts;
98
+ const params = {
118
99
  fileId,
119
100
  requestBody: {},
120
101
  media: {
121
- // mimeType: 'image/jpeg',
122
102
  body: fs.createReadStream(srcFileName)
123
103
  },
124
104
  fields: 'id'
125
- });
105
+ };
106
+ if (destMimeType) {
107
+ params.requestBody.mimeType = destMimeType;
108
+ }
109
+ if (srcMimeType) {
110
+ params.media.mimeType = srcMimeType;
111
+ }
112
+ const res = await drive.files.update(params);
126
113
  return res.data.id || '';
127
114
  }
128
115
  catch (err) {
129
116
  throw new UpdateFileError(JSON.stringify(err.errors));
130
117
  }
131
118
  }
132
- export async function sendFile(drive, parentId, destFileName, srcFileName) {
119
+ /**
120
+ * Send file using by source file into Google Drive.
121
+ * @param drive - drive instance.
122
+ * @param opts - options.
123
+ * @returns id of file in Google Drive
124
+ */
125
+ export async function sendFile(drive, opts) {
126
+ const { parentId, destFileName, srcFileName, destMimeType, srcMimeType } = opts;
133
127
  const fileId = await getFileId(drive, parentId, destFileName);
134
128
  if (fileId === '') {
135
- return uploadFile(drive, parentId, destFileName, srcFileName);
129
+ return uploadFile(drive, {
130
+ parentId,
131
+ destFileName,
132
+ srcFileName,
133
+ destMimeType,
134
+ srcMimeType
135
+ });
136
136
  }
137
- return updateFile(drive, fileId, srcFileName);
137
+ return updateFile(drive, { fileId, srcFileName, destMimeType, srcMimeType });
138
138
  }
139
- // try {
140
- // const parentId = process.env['PARENT_ID'] || ''
141
- // const destFileName = process.env['DEST_FILE_NAME'] || ''
142
- // const srcFileName = process.env['SRC_FILE_NAME'] || ''
143
- // const drive = driveClient()
144
- // const id = await getFileId(drive, parentId, destFileName)
145
- // console.log(id)
146
- // console.log(await updateFile(drive, id, srcFileName))
147
- // } catch (err) {
148
- // console.error('--err--')
149
- // console.error(err)
150
- // }
@@ -0,0 +1,63 @@
1
+ import { drive_v3 } from '@googleapis/drive';
2
+ export declare class CreatePermissonError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare class UpdatePermissonError extends Error {
6
+ constructor(message: string);
7
+ }
8
+ /**
9
+ * Options for createPermisson().
10
+ */
11
+ export declare type CreatePermissonOpts = {
12
+ /**
13
+ * @type The ID of the file or shared drive.
14
+ */
15
+ fileId: string;
16
+ /**
17
+ * @type The type of the grantee.
18
+ */
19
+ type: string;
20
+ /**
21
+ * The role granted by this permission
22
+ */
23
+ role: string;
24
+ /**
25
+ * @type The email address of the user or group to which this permission refers.
26
+ */
27
+ emailAddress: string;
28
+ /**
29
+ * @type The domain to which this permission refers.
30
+ */
31
+ domain: string;
32
+ /**
33
+ * @type Whether the permission allows the file to be discovered through search.
34
+ */
35
+ allowFileDiscovery?: boolean;
36
+ /**
37
+ * @type Indicates the view for this permission. Only populated for permissions that belong to a view. published is the only supported value.
38
+ */
39
+ view: string;
40
+ /**
41
+ * @type This parameter will only take effect if the item is not in a shared drive and the request is attempting to transfer the ownership of the item.
42
+ */
43
+ moveToNewOwnersRoot?: boolean;
44
+ /**
45
+ * @type Whether to transfer ownership to the specified user and downgrade the current owner to a writer.
46
+ */
47
+ transferOwnership?: boolean;
48
+ /**
49
+ * @type Whether the permission allows the file to be discovered through search. This is only applicable for permissions of type domain or anyone.
50
+ */
51
+ sendNotificationEmail?: boolean;
52
+ /**
53
+ * @type A plain text custom message to include in the notification email.
54
+ */
55
+ emailMessage: string;
56
+ };
57
+ /**
58
+ * Create permission
59
+ * @param drive - drive instance.
60
+ * @param opts
61
+ * @returns id of file in Google Drive
62
+ */
63
+ export declare function createPermisson(drive: drive_v3.Drive, opts: CreatePermissonOpts): Promise<string>;
package/dist/tshare.js ADDED
@@ -0,0 +1,84 @@
1
+ export class CreatePermissonError extends Error {
2
+ constructor(message) {
3
+ //https://stackoverflow.com/questions/41102060/typescript-extending-error-class
4
+ super(message);
5
+ Object.setPrototypeOf(this, CreatePermissonError.prototype);
6
+ }
7
+ }
8
+ export class UpdatePermissonError extends Error {
9
+ constructor(message) {
10
+ //https://stackoverflow.com/questions/41102060/typescript-extending-error-class
11
+ super(message);
12
+ Object.setPrototypeOf(this, UpdatePermissonError.prototype);
13
+ }
14
+ }
15
+ /**
16
+ * Create permission
17
+ * @param drive - drive instance.
18
+ * @param opts
19
+ * @returns id of file in Google Drive
20
+ */
21
+ export async function createPermisson(drive, opts) {
22
+ let created = false;
23
+ try {
24
+ const { fileId, type, role, emailAddress, domain, view, allowFileDiscovery, moveToNewOwnersRoot, transferOwnership, sendNotificationEmail, emailMessage } = opts;
25
+ const createParams = {
26
+ requestBody: {
27
+ type,
28
+ role
29
+ },
30
+ fileId,
31
+ fields: 'id'
32
+ };
33
+ if (emailAddress) {
34
+ createParams.requestBody.emailAddress = emailAddress;
35
+ }
36
+ if (domain) {
37
+ createParams.requestBody.domain = domain;
38
+ }
39
+ if (view) {
40
+ createParams.requestBody.view = view;
41
+ }
42
+ if (allowFileDiscovery !== undefined) {
43
+ createParams.requestBody.allowFileDiscovery = allowFileDiscovery;
44
+ }
45
+ if (moveToNewOwnersRoot !== undefined) {
46
+ createParams.moveToNewOwnersRoot = moveToNewOwnersRoot;
47
+ }
48
+ if (transferOwnership !== undefined) {
49
+ createParams.transferOwnership = transferOwnership;
50
+ }
51
+ if (sendNotificationEmail !== undefined) {
52
+ createParams.sendNotificationEmail = sendNotificationEmail;
53
+ }
54
+ if (sendNotificationEmail && emailMessage) {
55
+ createParams.emailMessage = emailMessage;
56
+ }
57
+ const resCreate = await drive.permissions.create(createParams);
58
+ created = true;
59
+ const id = resCreate.data.id || '';
60
+ if (id === '') {
61
+ throw new CreatePermissonError('drive.permissions.create() return blank id ');
62
+ }
63
+ if (!transferOwnership) {
64
+ const resUpdate = await drive.permissions.update({
65
+ permissionId: id,
66
+ requestBody: {
67
+ role
68
+ },
69
+ fileId,
70
+ fields: 'id'
71
+ });
72
+ }
73
+ return id;
74
+ }
75
+ catch (err) {
76
+ if (err.errors) {
77
+ if (!created) {
78
+ throw new CreatePermissonError(JSON.stringify(err.errors));
79
+ }
80
+ throw new UpdatePermissonError(JSON.stringify(err.errors));
81
+ }
82
+ throw err;
83
+ }
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guratan",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Tiny send tool for Google Drive",
5
5
  "author": "hankei6km <hankei6km@gmail.com> (https://github.com/hankei6km)",
6
6
  "license": "MIT",