@norbix.ai/cli 0.1.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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +121 -0
  3. package/bin/run.js +4 -0
  4. package/dist/base.js +100 -0
  5. package/dist/commands/account/billing-portal.js +21 -0
  6. package/dist/commands/account/profile.js +12 -0
  7. package/dist/commands/account/projects.js +12 -0
  8. package/dist/commands/account/regions.js +12 -0
  9. package/dist/commands/account/status.js +12 -0
  10. package/dist/commands/account/team.js +12 -0
  11. package/dist/commands/account/usage.js +12 -0
  12. package/dist/commands/api.js +87 -0
  13. package/dist/commands/apikeys/list.js +12 -0
  14. package/dist/commands/apikeys/regenerate.js +25 -0
  15. package/dist/commands/config/get.js +20 -0
  16. package/dist/commands/config/list.js +18 -0
  17. package/dist/commands/config/set.js +25 -0
  18. package/dist/commands/config/unset.js +20 -0
  19. package/dist/commands/db/aggregate.js +42 -0
  20. package/dist/commands/db/aggregates.js +16 -0
  21. package/dist/commands/db/count.js +26 -0
  22. package/dist/commands/db/delete.js +45 -0
  23. package/dist/commands/db/distinct.js +25 -0
  24. package/dist/commands/db/find.js +33 -0
  25. package/dist/commands/db/get.js +20 -0
  26. package/dist/commands/db/insert-many.js +29 -0
  27. package/dist/commands/db/insert.js +26 -0
  28. package/dist/commands/db/replace.js +25 -0
  29. package/dist/commands/db/schema.js +16 -0
  30. package/dist/commands/db/schemas.js +20 -0
  31. package/dist/commands/db/taxonomies.js +20 -0
  32. package/dist/commands/db/taxonomy.js +16 -0
  33. package/dist/commands/db/update.js +44 -0
  34. package/dist/commands/email/archive.js +16 -0
  35. package/dist/commands/email/campaign.js +21 -0
  36. package/dist/commands/email/campaigns.js +20 -0
  37. package/dist/commands/email/clone.js +16 -0
  38. package/dist/commands/email/delete.js +25 -0
  39. package/dist/commands/email/stop.js +31 -0
  40. package/dist/commands/email/template.js +16 -0
  41. package/dist/commands/email/templates.js +18 -0
  42. package/dist/commands/email/unarchive.js +16 -0
  43. package/dist/commands/env/delete.js +28 -0
  44. package/dist/commands/env/list.js +12 -0
  45. package/dist/commands/env/use.js +17 -0
  46. package/dist/commands/files/delete.js +34 -0
  47. package/dist/commands/files/download.js +45 -0
  48. package/dist/commands/files/info.js +27 -0
  49. package/dist/commands/files/list.js +30 -0
  50. package/dist/commands/files/sign.js +29 -0
  51. package/dist/commands/files/upload.js +62 -0
  52. package/dist/commands/integrations.js +34 -0
  53. package/dist/commands/login.js +65 -0
  54. package/dist/commands/logout.js +27 -0
  55. package/dist/commands/logs/list.js +38 -0
  56. package/dist/commands/logs/settings.js +12 -0
  57. package/dist/commands/logs/trail.js +18 -0
  58. package/dist/commands/module.js +48 -0
  59. package/dist/commands/payments/disable.js +16 -0
  60. package/dist/commands/payments/enable.js +16 -0
  61. package/dist/commands/payments/integrations.js +12 -0
  62. package/dist/commands/payments/trigger.js +16 -0
  63. package/dist/commands/payments/triggers.js +12 -0
  64. package/dist/commands/push/archive.js +16 -0
  65. package/dist/commands/push/campaign.js +21 -0
  66. package/dist/commands/push/campaigns.js +20 -0
  67. package/dist/commands/push/clone.js +16 -0
  68. package/dist/commands/push/delete.js +25 -0
  69. package/dist/commands/push/stop.js +30 -0
  70. package/dist/commands/push/template.js +16 -0
  71. package/dist/commands/push/templates.js +18 -0
  72. package/dist/commands/push/unarchive.js +16 -0
  73. package/dist/commands/scheduler/delete.js +25 -0
  74. package/dist/commands/scheduler/disable.js +16 -0
  75. package/dist/commands/scheduler/enable.js +16 -0
  76. package/dist/commands/scheduler/get.js +16 -0
  77. package/dist/commands/scheduler/list.js +20 -0
  78. package/dist/commands/sms/archive.js +16 -0
  79. package/dist/commands/sms/campaign.js +21 -0
  80. package/dist/commands/sms/campaigns.js +20 -0
  81. package/dist/commands/sms/clone.js +16 -0
  82. package/dist/commands/sms/delete.js +25 -0
  83. package/dist/commands/sms/stop.js +30 -0
  84. package/dist/commands/sms/template.js +16 -0
  85. package/dist/commands/sms/templates.js +18 -0
  86. package/dist/commands/sms/unarchive.js +16 -0
  87. package/dist/commands/users/block.js +16 -0
  88. package/dist/commands/users/delete.js +25 -0
  89. package/dist/commands/users/get.js +16 -0
  90. package/dist/commands/users/invite.js +16 -0
  91. package/dist/commands/users/list.js +27 -0
  92. package/dist/commands/users/policies.js +12 -0
  93. package/dist/commands/users/roles.js +12 -0
  94. package/dist/commands/users/unblock.js +16 -0
  95. package/dist/commands/webhooks/disable.js +18 -0
  96. package/dist/commands/webhooks/enable.js +18 -0
  97. package/dist/commands/webhooks/remove.js +30 -0
  98. package/dist/commands/webhooks/secret.js +34 -0
  99. package/dist/commands/webhooks/show.js +12 -0
  100. package/dist/commands/whoami.js +43 -0
  101. package/dist/lib/files.js +35 -0
  102. package/dist/lib/json.js +21 -0
  103. package/dist/lib/store.js +39 -0
  104. package/oclif.manifest.json +8497 -0
  105. package/package.json +114 -0
@@ -0,0 +1,43 @@
1
+ import { BaseCommand } from '../base.js';
2
+ import { redact } from '../lib/store.js';
3
+ export default class Whoami extends BaseCommand {
4
+ static description = 'Show the current CLI context and verify it against the server';
5
+ static examples = ['<%= config.bin %> whoami', '<%= config.bin %> whoami --json'];
6
+ async run() {
7
+ const { flags } = await this.parse(Whoami);
8
+ const ctx = this.resolveContext(flags);
9
+ const summary = {
10
+ projectId: ctx.projectId,
11
+ env: ctx.env ?? 'PROD',
12
+ region: ctx.region ?? '(project default)',
13
+ auth: ctx.bearerToken ? `login token (${ctx.stored.userName ?? ctx.stored.userId ?? 'user'})` : ctx.apiKey ? `api key ${redact(ctx.apiKey)}` : 'none',
14
+ configFile: this.config.configDir,
15
+ };
16
+ let verified = false;
17
+ let environments;
18
+ let verifyError;
19
+ if (ctx.projectId && (ctx.apiKey || ctx.bearerToken)) {
20
+ try {
21
+ const client = this.client(flags);
22
+ const res = await client.hub.environments.list();
23
+ const item = res.item;
24
+ environments = (item?.environments ?? []).map((e) => (typeof e === 'string' ? e : (e.name ?? String(e))));
25
+ verified = true;
26
+ }
27
+ catch (error) {
28
+ verifyError = error instanceof Error ? error.message : String(error);
29
+ }
30
+ }
31
+ this.print([
32
+ `Project: ${summary.projectId ?? '(not set)'}`,
33
+ `Env: ${summary.env}`,
34
+ `Region: ${summary.region}`,
35
+ `Auth: ${summary.auth}`,
36
+ `Config: ${summary.configFile}`,
37
+ verified
38
+ ? `Server: OK${environments?.length ? ` — environments: ${environments.join(', ')}` : ''}`
39
+ : `Server: not verified${verifyError ? ` (${verifyError})` : ''}`,
40
+ ].join('\n'));
41
+ return { ...summary, verified, environments, verifyError };
42
+ }
43
+ }
@@ -0,0 +1,35 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { extname } from 'node:path';
3
+ /** Shared flag: which files integration to talk to. */
4
+ export const integrationFlag = Flags.string({
5
+ char: 'i',
6
+ description: 'Files integration ID',
7
+ env: 'NORBIX_FILES_INTEGRATION_ID',
8
+ });
9
+ /** Resolve the files integration ID: flag > env (via oclif) > config file. */
10
+ export function resolveIntegration(flagValue, storedValue) {
11
+ return flagValue ?? storedValue;
12
+ }
13
+ const MIME_BY_EXT = {
14
+ '.css': 'text/css',
15
+ '.csv': 'text/csv',
16
+ '.gif': 'image/gif',
17
+ '.html': 'text/html',
18
+ '.jpeg': 'image/jpeg',
19
+ '.jpg': 'image/jpeg',
20
+ '.js': 'text/javascript',
21
+ '.json': 'application/json',
22
+ '.md': 'text/markdown',
23
+ '.mp3': 'audio/mpeg',
24
+ '.mp4': 'video/mp4',
25
+ '.pdf': 'application/pdf',
26
+ '.png': 'image/png',
27
+ '.svg': 'image/svg+xml',
28
+ '.txt': 'text/plain',
29
+ '.webp': 'image/webp',
30
+ '.xml': 'application/xml',
31
+ '.zip': 'application/zip',
32
+ };
33
+ export function guessContentType(fileName) {
34
+ return MIME_BY_EXT[extname(fileName).toLowerCase()] ?? 'application/octet-stream';
35
+ }
@@ -0,0 +1,21 @@
1
+ /** Helpers for JSON flags: accept inline JSON or `-` to read from stdin. */
2
+ export async function readJsonInput(value, flagName) {
3
+ const raw = value === '-' ? await readStdin() : value;
4
+ try {
5
+ // Parse + re-stringify: validates and normalizes the JSON the backend
6
+ // receives (all Norbix DTOs take filters/documents as JSON strings).
7
+ return JSON.stringify(JSON.parse(raw));
8
+ }
9
+ catch {
10
+ throw new Error(`--${flagName} is not valid JSON: ${truncate(raw)}`);
11
+ }
12
+ }
13
+ async function readStdin() {
14
+ const chunks = [];
15
+ for await (const chunk of process.stdin)
16
+ chunks.push(chunk);
17
+ return Buffer.concat(chunks).toString('utf8');
18
+ }
19
+ function truncate(text, max = 120) {
20
+ return text.length > max ? `${text.slice(0, max)}…` : text;
21
+ }
@@ -0,0 +1,39 @@
1
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ /** Keys a user may change via `norbix config set`. Tokens are managed by login/logout. */
4
+ export const SETTABLE_KEYS = [
5
+ 'projectId',
6
+ 'accountId',
7
+ 'region',
8
+ 'env',
9
+ 'apiUrl',
10
+ 'hubUrl',
11
+ 'apiKey',
12
+ 'filesIntegrationId',
13
+ ];
14
+ export function isSettableKey(key) {
15
+ return SETTABLE_KEYS.includes(key);
16
+ }
17
+ export function configFilePath(configDir) {
18
+ return join(configDir, 'config.json');
19
+ }
20
+ export function readStore(configDir) {
21
+ try {
22
+ return JSON.parse(readFileSync(configFilePath(configDir), 'utf8'));
23
+ }
24
+ catch {
25
+ return {};
26
+ }
27
+ }
28
+ export function writeStore(configDir, store) {
29
+ mkdirSync(configDir, { recursive: true });
30
+ // Drop undefined values so the file stays clean.
31
+ const clean = Object.fromEntries(Object.entries(store).filter(([, v]) => v !== undefined));
32
+ writeFileSync(configFilePath(configDir), JSON.stringify(clean, null, 2) + '\n', { mode: 0o600 });
33
+ }
34
+ /** Shorten a secret for display: "nbk_abc…xyz". Never print full secrets. */
35
+ export function redact(secret) {
36
+ if (!secret)
37
+ return undefined;
38
+ return secret.length <= 8 ? '********' : `${secret.slice(0, 3)}…${secret.slice(-3)}`;
39
+ }