@somewhere-cloud/cli 0.38.88 → 0.38.89

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.
@@ -0,0 +1,78 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { isRecord, unwrapPlatformData } from './platform-command.js';
4
+ const PREVIEW_RECORD = join('.somewhere', 'preview.json');
5
+ export function loadPreviewRecord(dir, projectId) {
6
+ const path = join(dir, PREVIEW_RECORD);
7
+ if (!existsSync(path))
8
+ return null;
9
+ try {
10
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
11
+ if (parsed.project_id !== projectId || typeof parsed.preview_session_id !== 'string'
12
+ || typeof parsed.preview_id !== 'string' || !isRecord(parsed.files))
13
+ return null;
14
+ return parsed;
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ export function savePreviewRecord(dir, record) {
21
+ mkdirSync(join(dir, '.somewhere'), { recursive: true });
22
+ writeFileSync(join(dir, PREVIEW_RECORD), JSON.stringify({ ...record, saved_at: new Date().toISOString() }) + '\n');
23
+ }
24
+ export function clearPreviewRecord(dir) {
25
+ rmSync(join(dir, PREVIEW_RECORD), { force: true });
26
+ }
27
+ /** The open previews and the live release, from a deploy_status answer. */
28
+ export function openPreviewsFromStatus(status) {
29
+ const data = unwrapPlatformData(status);
30
+ if (!isRecord(data))
31
+ return { activeReleaseId: null, previews: [] };
32
+ const rows = (Array.isArray(data.previews) && data.previews.length ? data.previews
33
+ : Array.isArray(data.preview_candidates) ? data.preview_candidates : []).filter(isRecord);
34
+ const str = (value) => (typeof value === 'string' && value ? value : null);
35
+ const previews = rows.flatMap((row) => {
36
+ const previewSessionId = str(row.preview_session_id) ?? str(row.draft_id);
37
+ const previewId = str(row.preview_id) ?? str(row.candidate_release_id);
38
+ if (!previewSessionId || !previewId)
39
+ return [];
40
+ return [{
41
+ previewSessionId,
42
+ previewId,
43
+ baseReleaseId: str(row.base_release_id),
44
+ createdAt: str(row.created_at),
45
+ lastUpdatedAt: str(row.last_updated_at),
46
+ expiresAt: str(row.expires_at),
47
+ }];
48
+ });
49
+ return { activeReleaseId: str(data.active_release_id), previews };
50
+ }
51
+ /** A preview opened from an older production version can never be promoted. */
52
+ export function previewIsStale(preview, activeReleaseId) {
53
+ return preview.baseReleaseId !== null && activeReleaseId !== null && preview.baseReleaseId !== activeReleaseId;
54
+ }
55
+ /** "3 min", "2 h 5 min", "1 d 4 h": short, for a table cell. */
56
+ export function formatDuration(ms) {
57
+ const minutes = Math.max(0, Math.round(ms / 60_000));
58
+ if (minutes < 60)
59
+ return `${minutes} min`;
60
+ const hours = Math.floor(minutes / 60);
61
+ if (hours < 24)
62
+ return minutes % 60 ? `${hours} h ${minutes % 60} min` : `${hours} h`;
63
+ const days = Math.floor(hours / 24);
64
+ return hours % 24 ? `${days} d ${hours % 24} h` : `${days} d`;
65
+ }
66
+ export function decideContinue(args) {
67
+ if (args.forceNew)
68
+ return { action: 'new', reason: 'asked' };
69
+ if (!args.recorded)
70
+ return { action: 'new', reason: 'none-recorded' };
71
+ const preview = args.open.find((item) => item.previewSessionId === args.recorded.preview_session_id);
72
+ if (!preview)
73
+ return { action: 'new', reason: 'not-open', recorded: args.recorded };
74
+ if (previewIsStale(preview, args.activeReleaseId))
75
+ return { action: 'new', reason: 'stale', recorded: args.recorded };
76
+ return { action: 'continue', preview };
77
+ }
78
+ //# sourceMappingURL=preview-record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-record.js","sourceRoot":"","sources":["../../src/lib/preview-record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AA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AAE,CAAC;IAC7D,IAAI,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,KAAK,IAAI,CAAC,QAAS,CAAC,kBAAkB,CAAC,CAAC;IACtG,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpF,IAAI,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;IACtH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC"}
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@somewhere-cloud/cli",
3
- "version": "0.38.88",
3
+ "version": "0.38.89",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@somewhere-cloud/cli",
9
- "version": "0.38.88",
9
+ "version": "0.38.89",
10
10
  "bundleDependencies": [
11
11
  "@modelcontextprotocol/sdk",
12
12
  "chokidar",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somewhere-cloud/cli",
3
- "version": "0.38.88",
3
+ "version": "0.38.89",
4
4
  "description": "CLI for somewhere.cloud — auth, projects, deploy, pull, promote, db, logs, env, MCP bridge.",
5
5
  "keywords": [
6
6
  "somewhere",
@@ -45,7 +45,7 @@
45
45
  "worker/src/utils/dev-health-class.ts": "fd430f31b9c8469f3d90e118fd8c75d1836ebcf705c1f9e93915ffa53a4cb066",
46
46
  "worker/src/utils/errors.ts": "fcc62f5ad26d31ac3487fcca125bd1dae152ca62d801cd38df3c36a8fe36a3c1",
47
47
  "worker/src/utils/event-log.ts": "0c36483fa84c42ce607d195f1ded527ab4383d58808a63353d3cadef81d93948",
48
- "worker/src/utils/feed-kinds.ts": "f5973cbe0337e54294f7d38fc93397adc2ad77110d431a101c5dc1214371e8a1",
48
+ "worker/src/utils/feed-kinds.ts": "91fbe5df2edf31a0b08d2450b64a07d659cf02a9ccdb74a008785260d14a971b",
49
49
  "worker/src/utils/journey-segment.ts": "b1d27c58bea03a791193d7120d88d232ea1c8374d6f25f72cd86b5b8c33c73a1",
50
50
  "worker/src/utils/json-exact-integers.ts": "e2eb8d3b2e17da363eb14fb46d876208579e2e92bfac173fb27527e6c4fb575e",
51
51
  "worker/src/utils/log-sanitize.ts": "21997963eb5de1fa3e5544394996270d9bd073a76d57e6cbb3f8d789cb5c3663",