@norbix.ai/cli 0.1.0 → 0.2.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/README.md +125 -13
- package/dist/base.js +92 -23
- package/dist/commands/api.js +15 -81
- package/dist/commands/configure.js +68 -0
- package/dist/commands/env/use.js +36 -7
- package/dist/commands/files/delete.js +1 -1
- package/dist/commands/files/download.js +1 -1
- package/dist/commands/files/info.js +1 -1
- package/dist/commands/files/list.js +1 -1
- package/dist/commands/files/publish.js +38 -0
- package/dist/commands/files/sign.js +1 -1
- package/dist/commands/files/unpublish.js +34 -0
- package/dist/commands/files/upload.js +1 -1
- package/dist/commands/hub.js +24 -0
- package/dist/commands/login.js +82 -36
- package/dist/commands/logout.js +11 -13
- package/dist/commands/profiles.js +25 -0
- package/dist/commands/push/archive.js +4 -1
- package/dist/commands/push/clone.js +4 -1
- package/dist/commands/push/delete.js +4 -1
- package/dist/commands/push/device/register.js +35 -0
- package/dist/commands/push/integration/default.js +19 -0
- package/dist/commands/push/integration/delete.js +28 -0
- package/dist/commands/push/integration/disable.js +19 -0
- package/dist/commands/push/integration/enable.js +19 -0
- package/dist/commands/push/integration/test.js +30 -0
- package/dist/commands/push/integration.js +16 -0
- package/dist/commands/push/integrations.js +20 -0
- package/dist/commands/push/preview.js +19 -0
- package/dist/commands/push/settings.js +16 -0
- package/dist/commands/push/unarchive.js +4 -1
- package/dist/commands/raw.js +86 -0
- package/dist/commands/whoami.js +25 -8
- package/dist/help.js +18 -0
- package/dist/lib/device-login.js +76 -0
- package/dist/lib/dispatch.js +151 -0
- package/dist/lib/namespace-command.js +148 -0
- package/dist/lib/profiles.js +138 -0
- package/dist/lib/publicFiles.js +63 -0
- package/oclif.manifest.json +3166 -725
- package/package.json +24 -12
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { NorbixError } from '@norbix.ai/ts';
|
|
2
|
+
const ROUTES = {
|
|
3
|
+
makeFilePrivate: 'files/item/private',
|
|
4
|
+
makeFilePublic: 'files/item/public',
|
|
5
|
+
makeFolderPrivate: 'files/folder/private',
|
|
6
|
+
makeFolderPublic: 'files/folder/public',
|
|
7
|
+
};
|
|
8
|
+
/** The Hub version the SDK talks by default. Kept in one place. */
|
|
9
|
+
const HUB_VERSION = 'v2';
|
|
10
|
+
export async function callPublicFiles(ctx, operation, body) {
|
|
11
|
+
const token = ctx.bearerToken ?? ctx.apiKey;
|
|
12
|
+
const headers = new Headers({
|
|
13
|
+
Accept: 'application/json',
|
|
14
|
+
'Content-Type': 'application/json',
|
|
15
|
+
});
|
|
16
|
+
if (token)
|
|
17
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
18
|
+
if (ctx.projectId)
|
|
19
|
+
headers.set('X-CM-ProjectId', ctx.projectId);
|
|
20
|
+
if (ctx.accountId)
|
|
21
|
+
headers.set('X-CM-AccountId', ctx.accountId);
|
|
22
|
+
if (ctx.env && ctx.env !== 'PROD')
|
|
23
|
+
headers.set('norbix-env', ctx.env);
|
|
24
|
+
if (ctx.region)
|
|
25
|
+
headers.set('nb-region', ctx.region);
|
|
26
|
+
const base = ctx.hubUrl.endsWith('/') ? ctx.hubUrl.slice(0, -1) : ctx.hubUrl;
|
|
27
|
+
const url = `${base}/${HUB_VERSION}/${ROUTES[operation]}`;
|
|
28
|
+
const response = await fetch(url, { body: JSON.stringify(body), headers, method: 'POST' });
|
|
29
|
+
const text = await response.text();
|
|
30
|
+
let payload = {};
|
|
31
|
+
if (text) {
|
|
32
|
+
try {
|
|
33
|
+
payload = JSON.parse(text);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
payload = {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new NorbixError({
|
|
41
|
+
code: payload.status,
|
|
42
|
+
message: payload.message ?? text ?? 'Request failed',
|
|
43
|
+
status: response.status,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return payload;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The address anyone can open. The gateway builds the same one and puts it on
|
|
50
|
+
* the file's `publicUrl`; this is what to print right after publishing, when
|
|
51
|
+
* the caller has only just been handed the id.
|
|
52
|
+
*
|
|
53
|
+
* `remote` is the path that was published. For a file the link ends with its
|
|
54
|
+
* name; for a folder it ends with a slash, and a file inside it is reached by
|
|
55
|
+
* appending the path inside the folder.
|
|
56
|
+
*/
|
|
57
|
+
export function publicUrlFor(apiUrl, publicId, remote, isFolder) {
|
|
58
|
+
const base = apiUrl.endsWith('/') ? apiUrl.slice(0, -1) : apiUrl;
|
|
59
|
+
if (isFolder)
|
|
60
|
+
return `${base}/v3/files/public/${publicId}/`;
|
|
61
|
+
const name = remote.split('/').filter(Boolean).pop() ?? remote;
|
|
62
|
+
return `${base}/v3/files/public/${publicId}/${name.split('/').map(encodeURIComponent).join('/')}`;
|
|
63
|
+
}
|