@sequencemedia/drive 0.0.112 → 0.0.113
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 +3 -3
- package/src/common/authorize.d.mts +1 -1
- package/src/common/authorize.mjs +5 -5
- package/src/common/getKeyFile.d.mts +3 -3
- package/src/common/getKeyFile.mjs +3 -3
- package/src/common/hasKeyFile.d.mts +3 -3
- package/src/common/hasKeyFile.mjs +3 -3
- package/src/common/hasKeyFileJson.d.mts +2 -2
- package/src/common/hasKeyFileJson.mjs +2 -2
- package/src/common/hasKeyFilePath.d.mts +2 -2
- package/src/common/hasKeyFilePath.mjs +2 -2
- package/src/create/index.d.mts +1 -1
- package/src/create/index.mjs +16 -16
- package/src/delete/index.d.mts +1 -1
- package/src/delete/index.mjs +9 -9
- package/src/get/index.d.mts +1 -1
- package/src/get/index.mjs +12 -12
- package/src/get-list/index.d.mts +1 -1
- package/src/get-list/index.mjs +10 -10
- package/src/installed/index.mjs +17 -17
- package/src/upload/index.mjs +6 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/drive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.113",
|
|
4
4
|
"main": "./src/index.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./src/index.d.mts",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"nconf": "^0.13.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@sequencemedia/eslint-config-standard": "^0.2.
|
|
25
|
-
"@sequencemedia/eslint-config-typescript": "^0.1.
|
|
24
|
+
"@sequencemedia/eslint-config-standard": "^0.2.57",
|
|
25
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.89",
|
|
26
26
|
"@types/debug": "^4.1.12",
|
|
27
27
|
"@types/nconf": "^0.10.7",
|
|
28
28
|
"@types/node": "^22.15.17",
|
|
@@ -5,6 +5,6 @@ export function getClientEmail (keyFile: KeyFileType): string | null
|
|
|
5
5
|
export function getPrivateKey (keyFile: KeyFileType): string | null
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Authorise using a Service Account (and return a JWT client)
|
|
9
9
|
*/
|
|
10
10
|
export default function authorize (keyFile: KeyFileType, scopes?: string[]): Promise<JWT>
|
package/src/common/authorize.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').JWT} JWT
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -19,11 +19,11 @@ export function getPrivateKey ({
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Authorise using a Service Account (and return a JWT client)
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* @param {Record<PropertyKey, string | undefined>} keyFile
|
|
25
|
+
* @param {string[]} scopes
|
|
26
|
+
* @returns {JWT}
|
|
27
27
|
*/
|
|
28
28
|
export default async function authorize (keyFile, scopes = []) {
|
|
29
29
|
if (!keyFile) throw new Error('A key file is required')
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
} from '#common/config'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* @param {string | undefined | null} keyFileJson
|
|
8
|
+
* @param {string | undefined | null} keyFilePath
|
|
9
|
+
* @returns {Promise<KeyFileType>}
|
|
10
10
|
*/
|
|
11
11
|
export default function getKeyFile (keyFileJson: string | undefined | null, keyFilePath: string | undefined | null): Promise<KeyFileType>
|
|
12
12
|
|
|
@@ -16,9 +16,9 @@ export {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* @param {string | undefined | null} keyFileJson
|
|
20
|
+
* @param {string | undefined | null} keyFilePath
|
|
21
|
+
* @returns {Promise<Record<PropertyKey, string | undefined>>}
|
|
22
22
|
*/
|
|
23
23
|
export default async function getKeyFile (keyFileJson, keyFilePath) {
|
|
24
24
|
if (hasKeyFileJson(keyFileJson)) {
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
} from '#common/config'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* @param {string | undefined | null} keyFileJson
|
|
8
|
+
* @param {string | undefined | null} keyFilePath
|
|
9
|
+
* @returns {Promise<boolean>}
|
|
10
10
|
*/
|
|
11
11
|
export default function hasKeyFile (keyFileJson: string | undefined | null, keyFilePath: string | undefined | null): Promise<boolean>
|
|
12
12
|
|
|
@@ -12,9 +12,9 @@ export {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* @param {string | undefined | null} keyFileJson
|
|
16
|
+
* @param {string | undefined | null} keyFilePath
|
|
17
|
+
* @returns {Promise<boolean>}
|
|
18
18
|
*/
|
|
19
19
|
export default async function hasKeyFile (keyFileJson, keyFilePath) {
|
|
20
20
|
try {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @param {string | undefined | null} keyFilePath
|
|
3
|
+
* @returns {Promise<boolean>}
|
|
4
4
|
*/
|
|
5
5
|
export default function hasKeyFilePath (keyFilePath: string | undefined | null): Promise<boolean>
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
} from 'node:fs/promises'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* @param {string | undefined | null} keyFilePath
|
|
8
|
+
* @returns {Promise<boolean>}
|
|
9
9
|
*/
|
|
10
10
|
export default async function hasKeyFilePath (keyFilePath = null) {
|
|
11
11
|
try {
|
package/src/create/index.d.mts
CHANGED
package/src/create/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} AuthClient
|
|
3
|
+
* @typedef {import('googleapis').drive_v3 } DriveV3
|
|
4
|
+
* @typedef {DriveV3.Schema$File} File
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import debug from 'debug'
|
|
@@ -36,13 +36,13 @@ const error = debug('@sequencemedia/drive/create:error')
|
|
|
36
36
|
log('`@sequencemedia/drive` is awake')
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Create a JSON file in Google Drive
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* @param {string} driveId Drive identifier
|
|
42
|
+
* @param {string} fileName JSON file identifier
|
|
43
|
+
* @param {string} fileData JSON file contents
|
|
44
|
+
* @param {AuthClient} authClient An authorised OAuth2 client
|
|
45
|
+
* @returns {File}
|
|
46
46
|
*/
|
|
47
47
|
async function createJsonFile (driveId, fileName, fileData, authClient) {
|
|
48
48
|
try {
|
|
@@ -78,14 +78,14 @@ async function createJsonFile (driveId, fileName, fileData, authClient) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Create a JSON file in Google Drive
|
|
82
82
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
83
|
+
* @param {string} driveId Drive identifier
|
|
84
|
+
* @param {string} fileName JSON file name
|
|
85
|
+
* @param {Buffer} fileData JSON file data
|
|
86
|
+
* @param {Record<PropertyKey, string | undefined>} keyFile Authorisation
|
|
87
|
+
* @param {string[]} scopes Authorisation scopes
|
|
88
|
+
* @returns {File}
|
|
89
89
|
*/
|
|
90
90
|
export default async function createInDrive (driveId, fileName, fileData, keyFile, scopes = SCOPES) {
|
|
91
91
|
return (
|
package/src/delete/index.d.mts
CHANGED
package/src/delete/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} AuthClient
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import debug from 'debug'
|
|
@@ -30,11 +30,11 @@ const error = debug('@sequencemedia/drive/delete:error')
|
|
|
30
30
|
log('`@sequencemedia/drive` is awake')
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Delete a JSON file from Google Drive
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* @param {string} fileId JSON file identifier
|
|
36
|
+
* @param {AuthClient} authClient An authorised OAuth2 client
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
38
|
*/
|
|
39
39
|
async function deleteJsonFile (fileId, authClient) {
|
|
40
40
|
try {
|
|
@@ -56,11 +56,11 @@ async function deleteJsonFile (fileId, authClient) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Delete a JSON file from Google Drive
|
|
60
60
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
61
|
+
* @param {string} fileId JSON file identifier
|
|
62
|
+
* @param {Record<PropertyKey, string | undefined>} keyFile An authorised OAuth2 client
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
64
|
*/
|
|
65
65
|
export default async function deleteFromDrive (fileId, keyFile, scopes = SCOPES) {
|
|
66
66
|
return (
|
package/src/get/index.d.mts
CHANGED
package/src/get/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} AuthClient
|
|
3
|
+
* @typedef {import('googleapis').drive_v3 } DriveV3
|
|
4
|
+
* @typedef {DriveV3.Schema$File} File
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import debug from 'debug'
|
|
@@ -32,11 +32,11 @@ const error = debug('@sequencemedia/drive/get:error')
|
|
|
32
32
|
log('`@sequencemedia/drive` is awake')
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Get a JSON file from Google Drive
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* @param {string} fileId JSON file identifier
|
|
38
|
+
* @param {AuthClient} authClient An authorised OAuth2 client
|
|
39
|
+
* @returns {File}
|
|
40
40
|
*/
|
|
41
41
|
async function getJsonFile (fileId, authClient) {
|
|
42
42
|
try {
|
|
@@ -61,12 +61,12 @@ async function getJsonFile (fileId, authClient) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Get a JSON file from Google Drive
|
|
65
65
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
66
|
+
* @param {string} fileId JSON file identifier
|
|
67
|
+
* @param {Record<PropertyKey, string | undefined>} keyFile Authorisation
|
|
68
|
+
* @param {string[]} scopes Authorisation scopes
|
|
69
|
+
* @returns {Promise<File>}
|
|
70
70
|
*/
|
|
71
71
|
export default async function getFromDrive (fileId, keyFile, scopes = SCOPES) {
|
|
72
72
|
return (
|
package/src/get-list/index.d.mts
CHANGED
package/src/get-list/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} AuthClient
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import debug from 'debug'
|
|
@@ -30,11 +30,11 @@ const error = debug('@sequencemedia/drive/list:error')
|
|
|
30
30
|
log('`@sequencemedia/drive` is awake')
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Get a list of the JSON files from Google Drive
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* @param {string} driveId Drive identifier
|
|
36
|
+
* @param {AuthClient} authClient An authorised OAuth2 client
|
|
37
|
+
* @returns {Promise<{id: string, name: string}[]>}
|
|
38
38
|
*/
|
|
39
39
|
async function getJsonFileList (driveId, authClient) {
|
|
40
40
|
try {
|
|
@@ -65,12 +65,12 @@ async function getJsonFileList (driveId, authClient) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* Get a list of the JSON files from Google Drive
|
|
69
69
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
70
|
+
* @param {string} driveId Drive identifier
|
|
71
|
+
* @param {Record<PropertyKey, string | undefined>} keyFile Authorisation
|
|
72
|
+
* @param {string[]} scopes Authorisation scopes
|
|
73
|
+
* @returns {Promise<Array<{id: string, name: string}>>}
|
|
74
74
|
*/
|
|
75
75
|
export default async function getListFromDrive (driveId, keyFile, scopes = SCOPES) {
|
|
76
76
|
return (
|
package/src/installed/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} OAuth2Client
|
|
3
|
+
* @typedef {import('google-auth-library').JWTInput} UserRefreshClient
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -31,9 +31,9 @@ const SCOPES = [
|
|
|
31
31
|
const USER_REFRESH_CLIENT_PATH = './user-refresh-client.json'
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Deserialises `UserRefreshClient` from a file
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* @return {Promise<UserRefreshClient | null>}
|
|
37
37
|
*/
|
|
38
38
|
async function getUserRefreshClient () {
|
|
39
39
|
try {
|
|
@@ -47,10 +47,10 @@ async function getUserRefreshClient () {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Serializes `UserRefreshClient` to a file
|
|
51
51
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
52
|
+
* @param {UserRefreshClient} userRefreshClient
|
|
53
|
+
* @return {Promise<void>}
|
|
54
54
|
*/
|
|
55
55
|
async function setUserRefreshClient (userRefreshClient) {
|
|
56
56
|
const fileData = JSON.stringify(userRefreshClient)
|
|
@@ -58,10 +58,10 @@ async function setUserRefreshClient (userRefreshClient) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Transforms `UserRefreshClient` to `OAuth2Client`
|
|
62
62
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
63
|
+
* @param {UserRefreshClient} userRefreshClient
|
|
64
|
+
* @returns {OAuth2Client}
|
|
65
65
|
*/
|
|
66
66
|
function toAuthClient (userRefreshClient) {
|
|
67
67
|
return (
|
|
@@ -70,10 +70,10 @@ function toAuthClient (userRefreshClient) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* Transforms `OAuth2Client` to `UserRefreshClient`
|
|
74
74
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
75
|
+
* @param {OAuth2Client} authClient
|
|
76
|
+
* @return {Promise<UserRefreshClient>}
|
|
77
77
|
*/
|
|
78
78
|
async function toUserRefreshClient (credentials, authClient) {
|
|
79
79
|
const {
|
|
@@ -96,9 +96,9 @@ async function toUserRefreshClient (credentials, authClient) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
*
|
|
99
|
+
* Load or request or authorization to call APIs.
|
|
100
100
|
*
|
|
101
|
-
*
|
|
101
|
+
* @return {OAuth2Client}
|
|
102
102
|
*/
|
|
103
103
|
async function authorize () {
|
|
104
104
|
const userRefreshClient = await getUserRefreshClient()
|
|
@@ -119,9 +119,9 @@ async function authorize () {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
*
|
|
122
|
+
* Lists the names and IDs of up to 10 files.
|
|
123
123
|
*
|
|
124
|
-
*
|
|
124
|
+
* @param {OAuth2Client} authClient An authorized OAuth2 client.
|
|
125
125
|
*/
|
|
126
126
|
async function listFiles (authClient) {
|
|
127
127
|
try {
|
package/src/upload/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @typedef {import('google-auth-library').OAuth2Client} OAuth2Client
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -19,7 +19,7 @@ const SCOPES = [
|
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Authorize with service account and get jwt client
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
async function authorize () {
|
|
@@ -41,11 +41,11 @@ async function authorize () {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Create a JSON file in Google Drive
|
|
45
45
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* @param {string} id JSON file identifier
|
|
47
|
+
* @param {string} body JSON file contents
|
|
48
|
+
* @param {OAuth2Client} authClient An authorized OAuth2 client.
|
|
49
49
|
*/
|
|
50
50
|
async function createJsonFile (id, body, authClient) {
|
|
51
51
|
try {
|