appwrite-cli 4.2.0 → 4.2.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.
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/install.ps1 +2 -2
- package/install.sh +1 -1
- package/lib/client.js +61 -74
- package/lib/commands/account.js +550 -196
- package/lib/commands/assistant.js +42 -7
- package/lib/commands/avatars.js +197 -81
- package/lib/commands/console.js +42 -3
- package/lib/commands/databases.js +981 -552
- package/lib/commands/functions.js +561 -291
- package/lib/commands/graphql.js +58 -11
- package/lib/commands/health.js +325 -68
- package/lib/commands/locale.js +154 -17
- package/lib/commands/migrations.js +328 -147
- package/lib/commands/project.js +128 -33
- package/lib/commands/projects.js +788 -411
- package/lib/commands/proxy.js +113 -28
- package/lib/commands/storage.js +422 -207
- package/lib/commands/teams.js +279 -103
- package/lib/commands/users.js +550 -262
- package/lib/commands/vcs.js +186 -53
- package/package.json +9 -9
- package/scoop/appwrite.json +3 -3
|
@@ -9,33 +9,68 @@ const { Command } = require('commander');
|
|
|
9
9
|
const { sdkForProject, sdkForConsole } = require('../sdks')
|
|
10
10
|
const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
|
|
11
11
|
const { localConfig, globalConfig } = require("../config");
|
|
12
|
+
const { File } = require('undici');
|
|
13
|
+
const { ReadableStream } = require('stream/web');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {fs.ReadStream} readStream
|
|
17
|
+
* @returns {ReadableStream}
|
|
18
|
+
*/
|
|
19
|
+
function convertReadStreamToReadableStream(readStream) {
|
|
20
|
+
return new ReadableStream({
|
|
21
|
+
start(controller) {
|
|
22
|
+
readStream.on("data", (chunk) => {
|
|
23
|
+
controller.enqueue(chunk);
|
|
24
|
+
});
|
|
25
|
+
readStream.on("end", () => {
|
|
26
|
+
controller.close();
|
|
27
|
+
});
|
|
28
|
+
readStream.on("error", (err) => {
|
|
29
|
+
controller.error(err);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
cancel() {
|
|
33
|
+
readStream.destroy();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
12
37
|
|
|
13
38
|
const assistant = new Command("assistant").description(commandDescriptions['assistant']).configureHelp({
|
|
14
39
|
helpWidth: process.stdout.columns || 80
|
|
15
40
|
})
|
|
16
41
|
|
|
17
|
-
|
|
18
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} AssistantChatRequestParams
|
|
44
|
+
* @property {string} prompt Prompt. A string containing questions asked to the AI assistant.
|
|
45
|
+
* @property {boolean} parseOutput
|
|
46
|
+
* @property {libClient | undefined} sdk
|
|
47
|
+
*/
|
|
19
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {AssistantChatRequestParams} params
|
|
51
|
+
*/
|
|
52
|
+
const assistantChat = async ({ prompt, parseOutput = true, sdk = undefined}) => {
|
|
20
53
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
54
|
+
|
|
21
55
|
let apiPath = '/console/assistant';
|
|
22
56
|
let payload = {};
|
|
23
|
-
|
|
24
|
-
/** Body Params */
|
|
25
|
-
|
|
26
57
|
if (typeof prompt !== 'undefined') {
|
|
27
58
|
payload['prompt'] = prompt;
|
|
28
59
|
}
|
|
29
60
|
|
|
61
|
+
|
|
30
62
|
let response = undefined;
|
|
63
|
+
|
|
31
64
|
response = await client.call('post', apiPath, {
|
|
32
65
|
'content-type': 'application/json',
|
|
33
66
|
}, payload);
|
|
67
|
+
|
|
34
68
|
|
|
35
69
|
if (parseOutput) {
|
|
36
70
|
parse(response)
|
|
37
71
|
success()
|
|
38
72
|
}
|
|
73
|
+
|
|
39
74
|
return response;
|
|
40
75
|
}
|
|
41
76
|
|
|
@@ -49,5 +84,5 @@ assistant
|
|
|
49
84
|
|
|
50
85
|
module.exports = {
|
|
51
86
|
assistant,
|
|
52
|
-
assistantChat
|
|
53
|
-
};
|
|
87
|
+
assistantChat
|
|
88
|
+
};
|
package/lib/commands/avatars.js
CHANGED
|
@@ -9,22 +9,55 @@ const { Command } = require('commander');
|
|
|
9
9
|
const { sdkForProject, sdkForConsole } = require('../sdks')
|
|
10
10
|
const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
|
|
11
11
|
const { localConfig, globalConfig } = require("../config");
|
|
12
|
+
const { File } = require('undici');
|
|
13
|
+
const { ReadableStream } = require('stream/web');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {fs.ReadStream} readStream
|
|
17
|
+
* @returns {ReadableStream}
|
|
18
|
+
*/
|
|
19
|
+
function convertReadStreamToReadableStream(readStream) {
|
|
20
|
+
return new ReadableStream({
|
|
21
|
+
start(controller) {
|
|
22
|
+
readStream.on("data", (chunk) => {
|
|
23
|
+
controller.enqueue(chunk);
|
|
24
|
+
});
|
|
25
|
+
readStream.on("end", () => {
|
|
26
|
+
controller.close();
|
|
27
|
+
});
|
|
28
|
+
readStream.on("error", (err) => {
|
|
29
|
+
controller.error(err);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
cancel() {
|
|
33
|
+
readStream.destroy();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
12
37
|
|
|
13
38
|
const avatars = new Command("avatars").description(commandDescriptions['avatars']).configureHelp({
|
|
14
39
|
helpWidth: process.stdout.columns || 80
|
|
15
40
|
})
|
|
16
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} AvatarsGetBrowserRequestParams
|
|
44
|
+
* @property {string} code Browser Code.
|
|
45
|
+
* @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100.
|
|
46
|
+
* @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100.
|
|
47
|
+
* @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100.
|
|
48
|
+
* @property {boolean} parseOutput
|
|
49
|
+
* @property {libClient | undefined} sdk
|
|
50
|
+
* @property {string} destination
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {AvatarsGetBrowserRequestParams} params
|
|
55
|
+
*/
|
|
17
56
|
const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => {
|
|
18
|
-
/* @param {string} code */
|
|
19
|
-
/* @param {number} width */
|
|
20
|
-
/* @param {number} height */
|
|
21
|
-
/* @param {number} quality */
|
|
22
|
-
|
|
23
57
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
58
|
+
|
|
24
59
|
let apiPath = '/avatars/browsers/{code}'.replace('{code}', code);
|
|
25
60
|
let payload = {};
|
|
26
|
-
|
|
27
|
-
/** Query Params */
|
|
28
61
|
if (typeof width !== 'undefined') {
|
|
29
62
|
payload['width'] = width;
|
|
30
63
|
}
|
|
@@ -34,34 +67,47 @@ const avatarsGetBrowser = async ({ code, width, height, quality, parseOutput = t
|
|
|
34
67
|
if (typeof quality !== 'undefined') {
|
|
35
68
|
payload['quality'] = quality;
|
|
36
69
|
}
|
|
70
|
+
|
|
37
71
|
payload['project'] = localConfig.getProject().projectId
|
|
38
72
|
payload['key'] = globalConfig.getKey();
|
|
39
73
|
const queryParams = new URLSearchParams(payload);
|
|
40
74
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
41
75
|
|
|
42
|
-
|
|
76
|
+
let response = undefined;
|
|
77
|
+
|
|
78
|
+
response = await client.call('get', apiPath, {
|
|
43
79
|
'content-type': 'application/json',
|
|
44
80
|
}, payload, 'arraybuffer');
|
|
45
81
|
|
|
46
82
|
fs.writeFileSync(destination, response);
|
|
47
|
-
|
|
48
|
-
if (parseOutput) {
|
|
49
|
-
|
|
83
|
+
|
|
84
|
+
if (parseOutput) {
|
|
85
|
+
parse(response)
|
|
50
86
|
success()
|
|
51
87
|
}
|
|
88
|
+
|
|
89
|
+
return response;
|
|
52
90
|
}
|
|
53
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @typedef {Object} AvatarsGetCreditCardRequestParams
|
|
94
|
+
* @property {string} code Credit Card Code. Possible values: amex, argencard, cabal, censosud, diners, discover, elo, hipercard, jcb, mastercard, naranja, targeta-shopping, union-china-pay, visa, mir, maestro.
|
|
95
|
+
* @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100.
|
|
96
|
+
* @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100.
|
|
97
|
+
* @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100.
|
|
98
|
+
* @property {boolean} parseOutput
|
|
99
|
+
* @property {libClient | undefined} sdk
|
|
100
|
+
* @property {string} destination
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {AvatarsGetCreditCardRequestParams} params
|
|
105
|
+
*/
|
|
54
106
|
const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => {
|
|
55
|
-
/* @param {string} code */
|
|
56
|
-
/* @param {number} width */
|
|
57
|
-
/* @param {number} height */
|
|
58
|
-
/* @param {number} quality */
|
|
59
|
-
|
|
60
107
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
108
|
+
|
|
61
109
|
let apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code);
|
|
62
110
|
let payload = {};
|
|
63
|
-
|
|
64
|
-
/** Query Params */
|
|
65
111
|
if (typeof width !== 'undefined') {
|
|
66
112
|
payload['width'] = width;
|
|
67
113
|
}
|
|
@@ -71,62 +117,88 @@ const avatarsGetCreditCard = async ({ code, width, height, quality, parseOutput
|
|
|
71
117
|
if (typeof quality !== 'undefined') {
|
|
72
118
|
payload['quality'] = quality;
|
|
73
119
|
}
|
|
120
|
+
|
|
74
121
|
payload['project'] = localConfig.getProject().projectId
|
|
75
122
|
payload['key'] = globalConfig.getKey();
|
|
76
123
|
const queryParams = new URLSearchParams(payload);
|
|
77
124
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
78
125
|
|
|
79
|
-
|
|
126
|
+
let response = undefined;
|
|
127
|
+
|
|
128
|
+
response = await client.call('get', apiPath, {
|
|
80
129
|
'content-type': 'application/json',
|
|
81
130
|
}, payload, 'arraybuffer');
|
|
82
131
|
|
|
83
132
|
fs.writeFileSync(destination, response);
|
|
84
|
-
|
|
85
|
-
if (parseOutput) {
|
|
86
|
-
|
|
133
|
+
|
|
134
|
+
if (parseOutput) {
|
|
135
|
+
parse(response)
|
|
87
136
|
success()
|
|
88
137
|
}
|
|
138
|
+
|
|
139
|
+
return response;
|
|
89
140
|
}
|
|
90
141
|
|
|
142
|
+
/**
|
|
143
|
+
* @typedef {Object} AvatarsGetFaviconRequestParams
|
|
144
|
+
* @property {string} url Website URL which you want to fetch the favicon from.
|
|
145
|
+
* @property {boolean} parseOutput
|
|
146
|
+
* @property {libClient | undefined} sdk
|
|
147
|
+
* @property {string} destination
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {AvatarsGetFaviconRequestParams} params
|
|
152
|
+
*/
|
|
91
153
|
const avatarsGetFavicon = async ({ url, parseOutput = true, sdk = undefined, destination}) => {
|
|
92
|
-
/* @param {string} url */
|
|
93
|
-
|
|
94
154
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
155
|
+
|
|
95
156
|
let apiPath = '/avatars/favicon';
|
|
96
157
|
let payload = {};
|
|
97
|
-
|
|
98
|
-
/** Query Params */
|
|
99
158
|
if (typeof url !== 'undefined') {
|
|
100
159
|
payload['url'] = url;
|
|
101
160
|
}
|
|
161
|
+
|
|
102
162
|
payload['project'] = localConfig.getProject().projectId
|
|
103
163
|
payload['key'] = globalConfig.getKey();
|
|
104
164
|
const queryParams = new URLSearchParams(payload);
|
|
105
165
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
106
166
|
|
|
107
|
-
|
|
167
|
+
let response = undefined;
|
|
168
|
+
|
|
169
|
+
response = await client.call('get', apiPath, {
|
|
108
170
|
'content-type': 'application/json',
|
|
109
171
|
}, payload, 'arraybuffer');
|
|
110
172
|
|
|
111
173
|
fs.writeFileSync(destination, response);
|
|
112
|
-
|
|
113
|
-
if (parseOutput) {
|
|
114
|
-
|
|
174
|
+
|
|
175
|
+
if (parseOutput) {
|
|
176
|
+
parse(response)
|
|
115
177
|
success()
|
|
116
178
|
}
|
|
179
|
+
|
|
180
|
+
return response;
|
|
117
181
|
}
|
|
118
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @typedef {Object} AvatarsGetFlagRequestParams
|
|
185
|
+
* @property {string} code Country Code. ISO Alpha-2 country code format.
|
|
186
|
+
* @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100.
|
|
187
|
+
* @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100.
|
|
188
|
+
* @property {number} quality Image quality. Pass an integer between 0 to 100. Defaults to 100.
|
|
189
|
+
* @property {boolean} parseOutput
|
|
190
|
+
* @property {libClient | undefined} sdk
|
|
191
|
+
* @property {string} destination
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {AvatarsGetFlagRequestParams} params
|
|
196
|
+
*/
|
|
119
197
|
const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true, sdk = undefined, destination}) => {
|
|
120
|
-
/* @param {string} code */
|
|
121
|
-
/* @param {number} width */
|
|
122
|
-
/* @param {number} height */
|
|
123
|
-
/* @param {number} quality */
|
|
124
|
-
|
|
125
198
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
199
|
+
|
|
126
200
|
let apiPath = '/avatars/flags/{code}'.replace('{code}', code);
|
|
127
201
|
let payload = {};
|
|
128
|
-
|
|
129
|
-
/** Query Params */
|
|
130
202
|
if (typeof width !== 'undefined') {
|
|
131
203
|
payload['width'] = width;
|
|
132
204
|
}
|
|
@@ -136,33 +208,46 @@ const avatarsGetFlag = async ({ code, width, height, quality, parseOutput = true
|
|
|
136
208
|
if (typeof quality !== 'undefined') {
|
|
137
209
|
payload['quality'] = quality;
|
|
138
210
|
}
|
|
211
|
+
|
|
139
212
|
payload['project'] = localConfig.getProject().projectId
|
|
140
213
|
payload['key'] = globalConfig.getKey();
|
|
141
214
|
const queryParams = new URLSearchParams(payload);
|
|
142
215
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
143
216
|
|
|
144
|
-
|
|
217
|
+
let response = undefined;
|
|
218
|
+
|
|
219
|
+
response = await client.call('get', apiPath, {
|
|
145
220
|
'content-type': 'application/json',
|
|
146
221
|
}, payload, 'arraybuffer');
|
|
147
222
|
|
|
148
223
|
fs.writeFileSync(destination, response);
|
|
149
|
-
|
|
150
|
-
if (parseOutput) {
|
|
151
|
-
|
|
224
|
+
|
|
225
|
+
if (parseOutput) {
|
|
226
|
+
parse(response)
|
|
152
227
|
success()
|
|
153
228
|
}
|
|
229
|
+
|
|
230
|
+
return response;
|
|
154
231
|
}
|
|
155
232
|
|
|
233
|
+
/**
|
|
234
|
+
* @typedef {Object} AvatarsGetImageRequestParams
|
|
235
|
+
* @property {string} url Image URL which you want to crop.
|
|
236
|
+
* @property {number} width Resize preview image width, Pass an integer between 0 to 2000. Defaults to 400.
|
|
237
|
+
* @property {number} height Resize preview image height, Pass an integer between 0 to 2000. Defaults to 400.
|
|
238
|
+
* @property {boolean} parseOutput
|
|
239
|
+
* @property {libClient | undefined} sdk
|
|
240
|
+
* @property {string} destination
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {AvatarsGetImageRequestParams} params
|
|
245
|
+
*/
|
|
156
246
|
const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = undefined, destination}) => {
|
|
157
|
-
/* @param {string} url */
|
|
158
|
-
/* @param {number} width */
|
|
159
|
-
/* @param {number} height */
|
|
160
|
-
|
|
161
247
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
248
|
+
|
|
162
249
|
let apiPath = '/avatars/image';
|
|
163
250
|
let payload = {};
|
|
164
|
-
|
|
165
|
-
/** Query Params */
|
|
166
251
|
if (typeof url !== 'undefined') {
|
|
167
252
|
payload['url'] = url;
|
|
168
253
|
}
|
|
@@ -172,34 +257,47 @@ const avatarsGetImage = async ({ url, width, height, parseOutput = true, sdk = u
|
|
|
172
257
|
if (typeof height !== 'undefined') {
|
|
173
258
|
payload['height'] = height;
|
|
174
259
|
}
|
|
260
|
+
|
|
175
261
|
payload['project'] = localConfig.getProject().projectId
|
|
176
262
|
payload['key'] = globalConfig.getKey();
|
|
177
263
|
const queryParams = new URLSearchParams(payload);
|
|
178
264
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
179
265
|
|
|
180
|
-
|
|
266
|
+
let response = undefined;
|
|
267
|
+
|
|
268
|
+
response = await client.call('get', apiPath, {
|
|
181
269
|
'content-type': 'application/json',
|
|
182
270
|
}, payload, 'arraybuffer');
|
|
183
271
|
|
|
184
272
|
fs.writeFileSync(destination, response);
|
|
185
|
-
|
|
186
|
-
if (parseOutput) {
|
|
187
|
-
|
|
273
|
+
|
|
274
|
+
if (parseOutput) {
|
|
275
|
+
parse(response)
|
|
188
276
|
success()
|
|
189
277
|
}
|
|
278
|
+
|
|
279
|
+
return response;
|
|
190
280
|
}
|
|
191
281
|
|
|
282
|
+
/**
|
|
283
|
+
* @typedef {Object} AvatarsGetInitialsRequestParams
|
|
284
|
+
* @property {string} name Full Name. When empty, current user name or email will be used. Max length: 128 chars.
|
|
285
|
+
* @property {number} width Image width. Pass an integer between 0 to 2000. Defaults to 100.
|
|
286
|
+
* @property {number} height Image height. Pass an integer between 0 to 2000. Defaults to 100.
|
|
287
|
+
* @property {string} background Changes background color. By default a random color will be picked and stay will persistent to the given name.
|
|
288
|
+
* @property {boolean} parseOutput
|
|
289
|
+
* @property {libClient | undefined} sdk
|
|
290
|
+
* @property {string} destination
|
|
291
|
+
*/
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* @param {AvatarsGetInitialsRequestParams} params
|
|
295
|
+
*/
|
|
192
296
|
const avatarsGetInitials = async ({ name, width, height, background, parseOutput = true, sdk = undefined, destination}) => {
|
|
193
|
-
/* @param {string} name */
|
|
194
|
-
/* @param {number} width */
|
|
195
|
-
/* @param {number} height */
|
|
196
|
-
/* @param {string} background */
|
|
197
|
-
|
|
198
297
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
298
|
+
|
|
199
299
|
let apiPath = '/avatars/initials';
|
|
200
300
|
let payload = {};
|
|
201
|
-
|
|
202
|
-
/** Query Params */
|
|
203
301
|
if (typeof name !== 'undefined') {
|
|
204
302
|
payload['name'] = name;
|
|
205
303
|
}
|
|
@@ -212,34 +310,47 @@ const avatarsGetInitials = async ({ name, width, height, background, parseOutput
|
|
|
212
310
|
if (typeof background !== 'undefined') {
|
|
213
311
|
payload['background'] = background;
|
|
214
312
|
}
|
|
313
|
+
|
|
215
314
|
payload['project'] = localConfig.getProject().projectId
|
|
216
315
|
payload['key'] = globalConfig.getKey();
|
|
217
316
|
const queryParams = new URLSearchParams(payload);
|
|
218
317
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
219
318
|
|
|
220
|
-
|
|
319
|
+
let response = undefined;
|
|
320
|
+
|
|
321
|
+
response = await client.call('get', apiPath, {
|
|
221
322
|
'content-type': 'application/json',
|
|
222
323
|
}, payload, 'arraybuffer');
|
|
223
324
|
|
|
224
325
|
fs.writeFileSync(destination, response);
|
|
225
|
-
|
|
226
|
-
if (parseOutput) {
|
|
227
|
-
|
|
326
|
+
|
|
327
|
+
if (parseOutput) {
|
|
328
|
+
parse(response)
|
|
228
329
|
success()
|
|
229
330
|
}
|
|
331
|
+
|
|
332
|
+
return response;
|
|
230
333
|
}
|
|
231
334
|
|
|
335
|
+
/**
|
|
336
|
+
* @typedef {Object} AvatarsGetQRRequestParams
|
|
337
|
+
* @property {string} text Plain text to be converted to QR code image.
|
|
338
|
+
* @property {number} size QR code size. Pass an integer between 1 to 1000. Defaults to 400.
|
|
339
|
+
* @property {number} margin Margin from edge. Pass an integer between 0 to 10. Defaults to 1.
|
|
340
|
+
* @property {boolean} download Return resulting image with 'Content-Disposition: attachment ' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.
|
|
341
|
+
* @property {boolean} parseOutput
|
|
342
|
+
* @property {libClient | undefined} sdk
|
|
343
|
+
* @property {string} destination
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @param {AvatarsGetQRRequestParams} params
|
|
348
|
+
*/
|
|
232
349
|
const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true, sdk = undefined, destination}) => {
|
|
233
|
-
/* @param {string} text */
|
|
234
|
-
/* @param {number} size */
|
|
235
|
-
/* @param {number} margin */
|
|
236
|
-
/* @param {boolean} download */
|
|
237
|
-
|
|
238
350
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
351
|
+
|
|
239
352
|
let apiPath = '/avatars/qr';
|
|
240
353
|
let payload = {};
|
|
241
|
-
|
|
242
|
-
/** Query Params */
|
|
243
354
|
if (typeof text !== 'undefined') {
|
|
244
355
|
payload['text'] = text;
|
|
245
356
|
}
|
|
@@ -252,21 +363,26 @@ const avatarsGetQR = async ({ text, size, margin, download, parseOutput = true,
|
|
|
252
363
|
if (typeof download !== 'undefined') {
|
|
253
364
|
payload['download'] = download;
|
|
254
365
|
}
|
|
366
|
+
|
|
255
367
|
payload['project'] = localConfig.getProject().projectId
|
|
256
368
|
payload['key'] = globalConfig.getKey();
|
|
257
369
|
const queryParams = new URLSearchParams(payload);
|
|
258
370
|
apiPath = `${globalConfig.getEndpoint()}${apiPath}?${queryParams.toString()}`;
|
|
259
371
|
|
|
260
|
-
|
|
372
|
+
let response = undefined;
|
|
373
|
+
|
|
374
|
+
response = await client.call('get', apiPath, {
|
|
261
375
|
'content-type': 'application/json',
|
|
262
376
|
}, payload, 'arraybuffer');
|
|
263
377
|
|
|
264
378
|
fs.writeFileSync(destination, response);
|
|
265
|
-
|
|
266
|
-
if (parseOutput) {
|
|
267
|
-
|
|
379
|
+
|
|
380
|
+
if (parseOutput) {
|
|
381
|
+
parse(response)
|
|
268
382
|
success()
|
|
269
383
|
}
|
|
384
|
+
|
|
385
|
+
return response;
|
|
270
386
|
}
|
|
271
387
|
|
|
272
388
|
|
|
@@ -339,11 +455,11 @@ avatars
|
|
|
339
455
|
|
|
340
456
|
module.exports = {
|
|
341
457
|
avatars,
|
|
342
|
-
avatarsGetBrowser,
|
|
343
|
-
avatarsGetCreditCard,
|
|
344
|
-
avatarsGetFavicon,
|
|
345
|
-
avatarsGetFlag,
|
|
346
|
-
avatarsGetImage,
|
|
347
|
-
avatarsGetInitials,
|
|
348
|
-
avatarsGetQR
|
|
349
|
-
};
|
|
458
|
+
avatarsGetBrowser,
|
|
459
|
+
avatarsGetCreditCard,
|
|
460
|
+
avatarsGetFavicon,
|
|
461
|
+
avatarsGetFlag,
|
|
462
|
+
avatarsGetImage,
|
|
463
|
+
avatarsGetInitials,
|
|
464
|
+
avatarsGetQR
|
|
465
|
+
};
|
package/lib/commands/console.js
CHANGED
|
@@ -9,25 +9,64 @@ const { Command } = require('commander');
|
|
|
9
9
|
const { sdkForProject, sdkForConsole } = require('../sdks')
|
|
10
10
|
const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
|
|
11
11
|
const { localConfig, globalConfig } = require("../config");
|
|
12
|
+
const { File } = require('undici');
|
|
13
|
+
const { ReadableStream } = require('stream/web');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {fs.ReadStream} readStream
|
|
17
|
+
* @returns {ReadableStream}
|
|
18
|
+
*/
|
|
19
|
+
function convertReadStreamToReadableStream(readStream) {
|
|
20
|
+
return new ReadableStream({
|
|
21
|
+
start(controller) {
|
|
22
|
+
readStream.on("data", (chunk) => {
|
|
23
|
+
controller.enqueue(chunk);
|
|
24
|
+
});
|
|
25
|
+
readStream.on("end", () => {
|
|
26
|
+
controller.close();
|
|
27
|
+
});
|
|
28
|
+
readStream.on("error", (err) => {
|
|
29
|
+
controller.error(err);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
cancel() {
|
|
33
|
+
readStream.destroy();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
12
37
|
|
|
13
38
|
const console = new Command("console").description(commandDescriptions['console']).configureHelp({
|
|
14
39
|
helpWidth: process.stdout.columns || 80
|
|
15
40
|
})
|
|
16
41
|
|
|
17
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {Object} ConsoleVariablesRequestParams
|
|
44
|
+
* @property {boolean} parseOutput
|
|
45
|
+
* @property {libClient | undefined} sdk
|
|
46
|
+
*/
|
|
18
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {ConsoleVariablesRequestParams} params
|
|
50
|
+
*/
|
|
51
|
+
const consoleVariables = async ({ parseOutput = true, sdk = undefined}) => {
|
|
19
52
|
let client = !sdk ? await sdkForProject() : sdk;
|
|
53
|
+
|
|
20
54
|
let apiPath = '/console/variables';
|
|
21
55
|
let payload = {};
|
|
56
|
+
|
|
57
|
+
|
|
22
58
|
let response = undefined;
|
|
59
|
+
|
|
23
60
|
response = await client.call('get', apiPath, {
|
|
24
61
|
'content-type': 'application/json',
|
|
25
62
|
}, payload);
|
|
63
|
+
|
|
26
64
|
|
|
27
65
|
if (parseOutput) {
|
|
28
66
|
parse(response)
|
|
29
67
|
success()
|
|
30
68
|
}
|
|
69
|
+
|
|
31
70
|
return response;
|
|
32
71
|
}
|
|
33
72
|
|
|
@@ -40,5 +79,5 @@ console
|
|
|
40
79
|
|
|
41
80
|
module.exports = {
|
|
42
81
|
console,
|
|
43
|
-
consoleVariables
|
|
44
|
-
};
|
|
82
|
+
consoleVariables
|
|
83
|
+
};
|