previewer-agency 0.2.1 → 0.2.2

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 (2) hide show
  1. package/bin/previewer.mjs +29 -19
  2. package/package.json +1 -1
package/bin/previewer.mjs CHANGED
@@ -31,19 +31,29 @@ const fail = (message, hint) => {
31
31
  process.exit(1);
32
32
  };
33
33
 
34
+ // How this person runs us, so help and hints show a command that works when typed: through npx
35
+ // (no global install, so `previewer` itself isn't on their PATH) it's `npx previewer-agency`.
36
+ const RAN_VIA_NPX = process.env.npm_command === 'exec' || /[\\/]_npx[\\/]/.test(process.argv[1] || '');
37
+ const CMD = RAN_VIA_NPX ? 'npx previewer-agency' : 'previewer';
38
+
39
+ const COMMAND_HELP = [
40
+ ['login', 'Sign in (opens the browser to approve)'],
41
+ ['push [folder]', 'Upload a folder: ZIPs, banner folders, images, videos, backups'],
42
+ ['status', "Approvals and views of this folder's campaign"],
43
+ ['open', "Open the campaign's preview link"],
44
+ ['link', 'Choose which campaign this folder publishes to'],
45
+ ['campaigns', 'List campaigns'],
46
+ ['whoami', "Show who you're signed in as"],
47
+ ['logout', "Sign out (revokes this computer's token)"],
48
+ ['mcp', 'Run as an MCP server, for AI agents (Claude Code, Cursor, …)'],
49
+ ];
50
+ const commandWidth = Math.max(...COMMAND_HELP.map(([command]) => `${CMD} ${command}`.length)) + 3;
51
+
34
52
  const HELP = `${bold('previewer')} ${dim(VERSION)} — upload banners to Previewer and check on them
35
53
 
36
54
  ${bold('Usage')}
37
- previewer login Sign in (opens the browser to approve)
38
- previewer push [folder] Upload a folder: ZIPs, banner folders, images, videos, backups
39
- previewer status Approvals and views of this folder's campaign
40
- previewer open Open the campaign's preview link
41
- previewer link Choose which campaign this folder publishes to
42
- previewer campaigns List campaigns
43
- previewer whoami Show who you're signed in as
44
- previewer logout Sign out (revokes this computer's token)
45
- previewer mcp Run as an MCP server, for AI agents (Claude Code, Cursor, …)
46
-
55
+ ${COMMAND_HELP.map(([command, text]) => ` ${`${CMD} ${command}`.padEnd(commandWidth)}${text}`).join('\n')}
56
+ ${RAN_VIA_NPX ? `\n ${dim('Tip: npm install -g previewer-agency, then type just "previewer".')}\n` : ''}
47
57
  ${bold('Options')}
48
58
  --client <name|id> Client to publish to (push, link, campaigns)
49
59
  --campaign <name|id> Campaign to publish to (push, link, status, open)
@@ -55,12 +65,12 @@ ${bold('Options')}
55
65
 
56
66
  ${bold('In CI')}
57
67
  Set PREVIEWER_TOKEN (create one under API in the Previewer admin), then:
58
- previewer push dist --campaign 42
68
+ npx -y previewer-agency push dist --campaign 42
59
69
 
60
70
  ${bold('Folders')}
61
71
  *.zip and folders with an index.html are HTML5 banners. An image with the same name as a banner
62
72
  (300x250.zip + 300x250.jpg), or in a backups/ folder, is its backup image. Other images and videos
63
- are creatives. The first push saves the campaign to ${PROJECT_FILE}; after that, just run push.`;
73
+ are creatives. The first push saves the campaign to ${PROJECT_FILE}; after that, just run ${CMD} push.`;
64
74
 
65
75
  // --- small helpers -------------------------------------------------------------------------------
66
76
 
@@ -141,7 +151,7 @@ const matchName = (items, wanted, key = 'name') => {
141
151
 
142
152
  const clientFor = async (options, project) => {
143
153
  const auth = await resolveAuth({ site: options.site, project });
144
- if (!auth.token) fail(`Not signed in to ${auth.site}.`, 'Run: previewer login');
154
+ if (!auth.token) fail(`Not signed in to ${auth.site}.`, `Run: ${CMD} login`);
145
155
  return { client: new PreviewerClient({ baseUrl: auth.site, token: auth.token, userAgent: `previewer-cli/${VERSION}` }), auth };
146
156
  };
147
157
 
@@ -151,9 +161,9 @@ const explain = (error) => {
151
161
  error.code === 'auth'
152
162
  ? process.env.PREVIEWER_TOKEN
153
163
  ? 'Check PREVIEWER_TOKEN.'
154
- : 'Run: previewer login'
164
+ : `Run: ${CMD} login`
155
165
  : error.code === 'forbidden'
156
- ? 'Your token can\'t do this. Ask an owner, or sign in again with previewer login.'
166
+ ? `Your token can't do this. Ask an owner, or sign in again with ${CMD} login.`
157
167
  : error.code === 'not_found'
158
168
  ? 'Check the id, or that your token can reach it.'
159
169
  : undefined;
@@ -186,7 +196,7 @@ async function login(options) {
186
196
  if (status === 'denied') fail('The login was denied.');
187
197
  if (status === 'expired') break;
188
198
  }
189
- fail('The login expired before it was approved.', 'Run previewer login again.');
199
+ fail('The login expired before it was approved.', `Run ${CMD} login again.`);
190
200
  }
191
201
 
192
202
  async function logout(options) {
@@ -273,7 +283,7 @@ const pickCampaign = async (api, options, { allowCreate }) => {
273
283
  const rememberCampaign = async (site, campaign, project) => {
274
284
  if (project?.campaignId === campaign.id && project?.site === site) return;
275
285
  const file = await saveProject(process.cwd(), { site, campaignId: campaign.id, clientId: campaign.client.id, client: campaign.client.name, campaign: campaign.name });
276
- say(dim(`Saved to ${path.relative(process.cwd(), file) || file}: next time just run previewer push.`));
286
+ say(dim(`Saved to ${path.relative(process.cwd(), file) || file}: next time just run ${CMD} push.`));
277
287
  };
278
288
 
279
289
  async function link(options) {
@@ -409,14 +419,14 @@ const main = async () => {
409
419
  },
410
420
  });
411
421
  } catch (error) {
412
- fail(error.message, 'Run previewer help.');
422
+ fail(error.message, `Run ${CMD} help.`);
413
423
  }
414
424
  const { values, positionals } = parsed;
415
425
  if (values.version) return say(VERSION);
416
426
  const [command, ...rest] = positionals;
417
427
  if (!command || values.help || command === 'help') return say(HELP);
418
428
  const run = COMMANDS[command];
419
- if (!run) fail(`Unknown command "${command}".`, 'Run previewer help.');
429
+ if (!run) fail(`Unknown command "${command}".`, `Run ${CMD} help.`);
420
430
  try {
421
431
  await run(values, ...rest);
422
432
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "previewer-agency",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Upload HTML5 banners, images and videos to Previewer from any folder, CI job or AI agent (MCP), and check approvals.",
5
5
  "type": "module",
6
6
  "bin": {