@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.
Files changed (41) hide show
  1. package/README.md +125 -13
  2. package/dist/base.js +92 -23
  3. package/dist/commands/api.js +15 -81
  4. package/dist/commands/configure.js +68 -0
  5. package/dist/commands/env/use.js +36 -7
  6. package/dist/commands/files/delete.js +1 -1
  7. package/dist/commands/files/download.js +1 -1
  8. package/dist/commands/files/info.js +1 -1
  9. package/dist/commands/files/list.js +1 -1
  10. package/dist/commands/files/publish.js +38 -0
  11. package/dist/commands/files/sign.js +1 -1
  12. package/dist/commands/files/unpublish.js +34 -0
  13. package/dist/commands/files/upload.js +1 -1
  14. package/dist/commands/hub.js +24 -0
  15. package/dist/commands/login.js +82 -36
  16. package/dist/commands/logout.js +11 -13
  17. package/dist/commands/profiles.js +25 -0
  18. package/dist/commands/push/archive.js +4 -1
  19. package/dist/commands/push/clone.js +4 -1
  20. package/dist/commands/push/delete.js +4 -1
  21. package/dist/commands/push/device/register.js +35 -0
  22. package/dist/commands/push/integration/default.js +19 -0
  23. package/dist/commands/push/integration/delete.js +28 -0
  24. package/dist/commands/push/integration/disable.js +19 -0
  25. package/dist/commands/push/integration/enable.js +19 -0
  26. package/dist/commands/push/integration/test.js +30 -0
  27. package/dist/commands/push/integration.js +16 -0
  28. package/dist/commands/push/integrations.js +20 -0
  29. package/dist/commands/push/preview.js +19 -0
  30. package/dist/commands/push/settings.js +16 -0
  31. package/dist/commands/push/unarchive.js +4 -1
  32. package/dist/commands/raw.js +86 -0
  33. package/dist/commands/whoami.js +25 -8
  34. package/dist/help.js +18 -0
  35. package/dist/lib/device-login.js +76 -0
  36. package/dist/lib/dispatch.js +151 -0
  37. package/dist/lib/namespace-command.js +148 -0
  38. package/dist/lib/profiles.js +138 -0
  39. package/dist/lib/publicFiles.js +63 -0
  40. package/oclif.manifest.json +3166 -725
  41. 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
+ }