@reshotdev/screenshot 0.0.1-beta.15 → 0.0.1-beta.16
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/package.json +1 -1
- package/src/commands/auth.js +17 -2
- package/src/commands/pull.js +30 -7
package/package.json
CHANGED
package/src/commands/auth.js
CHANGED
|
@@ -150,11 +150,12 @@ async function waitForCompletion(
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
async function verifyApiKey(apiBaseUrl, apiKey, httpClient = axios) {
|
|
153
|
-
await httpClient.get(`${apiBaseUrl}/auth/cli/verify`, {
|
|
153
|
+
const response = await httpClient.get(`${apiBaseUrl}/auth/cli/verify`, {
|
|
154
154
|
headers: {
|
|
155
155
|
Authorization: `Bearer ${apiKey}`,
|
|
156
156
|
},
|
|
157
157
|
});
|
|
158
|
+
return response?.data || null;
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
async function authCommand(options = {}) {
|
|
@@ -172,19 +173,33 @@ async function authCommand(options = {}) {
|
|
|
172
173
|
const timeoutMs = Number(options.timeoutMs || DEFAULT_AUTH_TIMEOUT_MS);
|
|
173
174
|
if (envApiKey && envProjectId) {
|
|
174
175
|
const platformUrl = process.env.RESHOT_PLATFORM_URL || "https://reshot.dev";
|
|
176
|
+
// Best-effort resolve the project name so settings + the setup report
|
|
177
|
+
// don't record `projectName: null` on this non-interactive path.
|
|
178
|
+
let projectName = null;
|
|
179
|
+
try {
|
|
180
|
+
const apiBaseUrl = options.apiBaseUrl || getApiBaseUrl();
|
|
181
|
+
const verified = await verifyApiKeyFn(apiBaseUrl, envApiKey, httpClient);
|
|
182
|
+
projectName = verified?.project?.name || null;
|
|
183
|
+
} catch {
|
|
184
|
+
// Verification is best-effort here; keep going without the name.
|
|
185
|
+
}
|
|
175
186
|
writeSettingsFn({
|
|
176
187
|
projectId: envProjectId,
|
|
188
|
+
projectName,
|
|
177
189
|
apiKey: envApiKey,
|
|
178
190
|
platformUrl,
|
|
179
191
|
linkedAt: new Date().toISOString(),
|
|
180
192
|
cliVersion: pkg.version,
|
|
181
193
|
});
|
|
182
194
|
console.log(chalk.green("✔ Authenticated via environment variables"));
|
|
183
|
-
console.log(
|
|
195
|
+
console.log(
|
|
196
|
+
chalk.gray(` Project: ${projectName || envProjectId}`),
|
|
197
|
+
);
|
|
184
198
|
console.log(chalk.gray(` Platform: ${platformUrl}`));
|
|
185
199
|
return {
|
|
186
200
|
mode: "cloud-connected",
|
|
187
201
|
projectId: envProjectId,
|
|
202
|
+
projectName,
|
|
188
203
|
platformUrl,
|
|
189
204
|
};
|
|
190
205
|
}
|
package/src/commands/pull.js
CHANGED
|
@@ -109,6 +109,23 @@ function normalizeAssetMap(assets) {
|
|
|
109
109
|
return { assets: normalized, repairs };
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Pick a real {group, visualKey, context} from a normalized asset map so the
|
|
114
|
+
* printed usage example is copy-pasteable for THIS project (prefers the
|
|
115
|
+
* "default" context). Returns null if the map is empty.
|
|
116
|
+
*/
|
|
117
|
+
function deriveUsageSample(assets) {
|
|
118
|
+
for (const group of Object.keys(assets || {})) {
|
|
119
|
+
for (const visualKey of Object.keys(assets[group] || {})) {
|
|
120
|
+
const contexts = Object.keys(assets[group][visualKey] || {});
|
|
121
|
+
if (contexts.length === 0) continue;
|
|
122
|
+
const context = contexts.includes("default") ? "default" : contexts[0];
|
|
123
|
+
return { group, visualKey, context };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
112
129
|
function validateHostedAssetUrl(urlString) {
|
|
113
130
|
if (!urlString || typeof urlString !== "string") {
|
|
114
131
|
return;
|
|
@@ -456,6 +473,13 @@ async function pullCommand(options = {}) {
|
|
|
456
473
|
console.log(chalk.green(`✓ Generated ${contentType} file: ${outputPath}`));
|
|
457
474
|
console.log(chalk.gray(` ${assetCount} visuals exported\n`));
|
|
458
475
|
|
|
476
|
+
// Derive a REAL key path from the pulled map so the printed usage example
|
|
477
|
+
// is copy-pasteable (was hardcoded to a non-existent `dashboard.mainView`).
|
|
478
|
+
const sample = deriveUsageSample(normalizedAssets);
|
|
479
|
+
const sGroup = sample?.group ?? "dashboard";
|
|
480
|
+
const sVisual = sample?.visualKey ?? "mainView";
|
|
481
|
+
const sCtx = sample?.context ?? "default";
|
|
482
|
+
|
|
459
483
|
// Show format-specific usage instructions
|
|
460
484
|
if (format === "ts") {
|
|
461
485
|
console.log(chalk.blue("━━━ TypeScript Usage ━━━\n"));
|
|
@@ -463,10 +487,9 @@ async function pullCommand(options = {}) {
|
|
|
463
487
|
console.log(chalk.cyan(' import { ReshotVisuals } from "./visuals";\n'));
|
|
464
488
|
console.log(chalk.white("Use with full autocomplete support:\n"));
|
|
465
489
|
console.log(chalk.cyan(" // Single context (flattened)"));
|
|
466
|
-
console.log(chalk.cyan(
|
|
490
|
+
console.log(chalk.cyan(` <img src={ReshotVisuals.${sGroup}.${sVisual}} />\n`));
|
|
467
491
|
console.log(chalk.cyan(" // Multiple contexts (dark mode, locales)"));
|
|
468
|
-
console.log(chalk.cyan(
|
|
469
|
-
console.log(chalk.cyan(" <img src={ReshotVisuals.dashboard.mainView.dark} />\n"));
|
|
492
|
+
console.log(chalk.cyan(` <img src={ReshotVisuals.${sGroup}.${sVisual}.${sCtx}} />\n`));
|
|
470
493
|
if (!full) {
|
|
471
494
|
console.log(chalk.gray(" Tip: Use --full flag to include width, height, and alt text\n"));
|
|
472
495
|
}
|
|
@@ -476,10 +499,10 @@ async function pullCommand(options = {}) {
|
|
|
476
499
|
console.log(chalk.cyan(' import assets from "./reshot-assets.json";\n'));
|
|
477
500
|
console.log(chalk.white("Access assets with dot notation:\n"));
|
|
478
501
|
console.log(chalk.cyan(" <img"));
|
|
479
|
-
console.log(chalk.cyan(
|
|
480
|
-
console.log(chalk.cyan(
|
|
481
|
-
console.log(chalk.cyan(
|
|
482
|
-
console.log(chalk.cyan(
|
|
502
|
+
console.log(chalk.cyan(` src={assets.assets.${sGroup}.${sVisual}.${sCtx}.src}`));
|
|
503
|
+
console.log(chalk.cyan(` width={assets.assets.${sGroup}.${sVisual}.${sCtx}.width}`));
|
|
504
|
+
console.log(chalk.cyan(` height={assets.assets.${sGroup}.${sVisual}.${sCtx}.height}`));
|
|
505
|
+
console.log(chalk.cyan(` alt={assets.assets.${sGroup}.${sVisual}.${sCtx}.alt}`));
|
|
483
506
|
console.log(chalk.cyan(" />\n"));
|
|
484
507
|
} else if (format === "csv") {
|
|
485
508
|
console.log(chalk.blue("━━━ CSV Usage ━━━\n"));
|