securenow 5.3.3 → 5.3.4

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 (3) hide show
  1. package/cli/apps.js +82 -13
  2. package/cli.js +1 -1
  3. package/package.json +1 -1
package/cli/apps.js CHANGED
@@ -4,32 +4,74 @@ const { api, requireAuth } = require('./client');
4
4
  const config = require('./config');
5
5
  const ui = require('./ui');
6
6
 
7
+ const FREE_TRIAL_URL = 'https://freetrial.securenow.ai:4318';
8
+
9
+ function instanceUrl(inst) {
10
+ if (!inst) return FREE_TRIAL_URL;
11
+ return `${inst.protocol || 'https'}://${inst.host}:4318`;
12
+ }
13
+
14
+ async function fetchInstanceMap() {
15
+ try {
16
+ const data = await api.get('/instances');
17
+ const instances = data.instances || [];
18
+ const map = {};
19
+ for (const inst of instances) {
20
+ map[inst._id] = inst;
21
+ }
22
+ return map;
23
+ } catch {
24
+ return {};
25
+ }
26
+ }
27
+
7
28
  async function list(args, flags) {
8
29
  requireAuth();
9
30
  const s = ui.spinner('Fetching applications');
10
31
 
11
32
  try {
12
- const data = await api.get('/applications');
13
- const apps = data.applications || [];
33
+ const [appData, instMap] = await Promise.all([
34
+ api.get('/applications'),
35
+ fetchInstanceMap(),
36
+ ]);
37
+ const apps = appData.applications || [];
14
38
  s.stop(`Found ${apps.length} application${apps.length !== 1 ? 's' : ''}`);
15
39
  console.log('');
16
40
 
17
41
  if (flags.json) {
18
- ui.json(apps);
42
+ const enriched = apps.map(app => ({
43
+ ...app,
44
+ instanceUrl: instanceUrl(app.instanceId ? instMap[app.instanceId] : null),
45
+ }));
46
+ ui.json(enriched);
19
47
  return;
20
48
  }
21
49
 
22
50
  const defaultApp = config.getDefaultApp();
23
- const rows = apps.map(app => [
24
- app.name + (app.key === defaultApp ? ui.c.cyan(' (default)') : ''),
25
- ui.c.dim(app.key),
26
- app.hosts?.length ? app.hosts.join(', ') : ui.c.dim(''),
27
- ui.timeAgo(app.createdAt),
28
- ]);
51
+ const rows = apps.map(app => {
52
+ const inst = app.instanceId ? instMap[app.instanceId] : null;
53
+ const url = instanceUrl(inst);
54
+ const instLabel = inst ? `${inst.name} ${ui.c.dim(url)}` : `${ui.c.green('Free Trial')} ${ui.c.dim(url)}`;
55
+ return [
56
+ app.name + (app.key === defaultApp ? ui.c.cyan(' (default)') : ''),
57
+ ui.c.dim(app.key),
58
+ instLabel,
59
+ ui.timeAgo(app.createdAt),
60
+ ];
61
+ });
29
62
 
30
- ui.table(['Name', 'Key', 'Hosts', 'Created'], rows);
63
+ ui.table(['Name', 'Key', 'Instance', 'Created'], rows);
31
64
  console.log('');
32
65
 
66
+ if (apps.length > 0) {
67
+ console.log(` ${ui.c.bold('Add to your .env:')}`);
68
+ const first = apps.find(a => a.key === defaultApp) || apps[0];
69
+ const firstInst = first.instanceId ? instMap[first.instanceId] : null;
70
+ console.log(` SECURENOW_APPID=${first.key}`);
71
+ console.log(` SECURENOW_INSTANCE=${instanceUrl(firstInst)}`);
72
+ console.log('');
73
+ }
74
+
33
75
  if (!defaultApp && apps.length > 0) {
34
76
  ui.info(`Tip: Set a default app with ${ui.c.bold('securenow config set defaultApp <key>')}`);
35
77
  console.log('');
@@ -63,17 +105,29 @@ async function create(args, flags) {
63
105
  body.instanceId = await pickInstance();
64
106
  }
65
107
 
108
+ const selectedInstanceId = body.instanceId;
109
+
66
110
  const s = ui.spinner(`Creating application "${name}"`);
67
111
  try {
68
112
  const result = await api.post('/applications', body);
69
113
  const app = result.application || result;
70
114
  s.stop(`Application created`);
71
115
 
116
+ let inst = null;
117
+ if (selectedInstanceId) {
118
+ try {
119
+ const instData = await api.get(`/instances/${selectedInstanceId}`);
120
+ inst = instData.instance || null;
121
+ } catch {}
122
+ }
123
+ const envUrl = instanceUrl(inst);
124
+
72
125
  console.log('');
73
126
  ui.keyValue([
74
127
  ['Name', app.name],
75
128
  ['Key', ui.c.green(ui.c.bold(app.key))],
76
129
  ['ID', ui.c.dim(app._id)],
130
+ ['Instance', inst ? `${inst.name} ${ui.c.dim(`(${envUrl})`)}` : `${ui.c.green('Free Trial')} ${ui.c.dim(`(${envUrl})`)}`],
77
131
  ['Hosts', app.hosts?.length ? app.hosts.join(', ') : ui.c.dim('none')],
78
132
  ]);
79
133
 
@@ -81,12 +135,13 @@ async function create(args, flags) {
81
135
  console.log(` ${ui.c.bold('Add to your .env.local:')}`);
82
136
  console.log('');
83
137
  console.log(` SECURENOW_APPID=${app.key}`);
138
+ console.log(` SECURENOW_INSTANCE=${envUrl}`);
84
139
  console.log('');
85
140
  ui.info(`Set as default: ${ui.c.bold(`securenow config set defaultApp ${app.key}`)}`);
86
141
  console.log('');
87
142
 
88
143
  if (flags.json) {
89
- ui.json(app);
144
+ ui.json({ ...app, instanceUrl: envUrl });
90
145
  }
91
146
  } catch (err) {
92
147
  s.fail('Failed to create application');
@@ -162,10 +217,19 @@ async function info(args, flags) {
162
217
  try {
163
218
  const data = await api.get(`/applications/${id}`);
164
219
  const app = data.application || data;
220
+
221
+ let inst = null;
222
+ if (app.instanceId) {
223
+ try {
224
+ const instData = await api.get(`/instances/${app.instanceId}`);
225
+ inst = instData.instance || null;
226
+ } catch {}
227
+ }
228
+ const envUrl = instanceUrl(inst);
165
229
  s.stop('Application details loaded');
166
230
 
167
231
  if (flags.json) {
168
- ui.json(app);
232
+ ui.json({ ...app, instanceUrl: envUrl });
169
233
  return;
170
234
  }
171
235
 
@@ -175,11 +239,16 @@ async function info(args, flags) {
175
239
  ui.keyValue([
176
240
  ['Key', ui.c.bold(app.key)],
177
241
  ['ID', ui.c.dim(app._id)],
242
+ ['Instance', inst ? `${inst.name} ${ui.c.dim(`(${envUrl})`)}` : `${ui.c.green('Free Trial')} ${ui.c.dim(`(${envUrl})`)}`],
178
243
  ['Hosts', app.hosts?.length ? app.hosts.join(', ') : ui.c.dim('none')],
179
- ['Instance', app.instanceId || ui.c.dim('default')],
180
244
  ['Created', app.createdAt ? new Date(app.createdAt).toLocaleString() : '—'],
181
245
  ['Updated', app.updatedAt ? new Date(app.updatedAt).toLocaleString() : '—'],
182
246
  ]);
247
+
248
+ console.log('');
249
+ console.log(` ${ui.c.bold('Environment variables:')}`);
250
+ console.log(` SECURENOW_APPID=${app.key}`);
251
+ console.log(` SECURENOW_INSTANCE=${envUrl}`);
183
252
  console.log('');
184
253
  } catch (err) {
185
254
  s.fail('Failed to fetch application');
package/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
4
  const ui = require('./cli/ui');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securenow",
3
- "version": "5.3.3",
3
+ "version": "5.3.4",
4
4
  "description": "OpenTelemetry instrumentation for Node.js and Next.js - Send traces and logs to any OTLP-compatible backend",
5
5
  "type": "commonjs",
6
6
  "main": "register.js",