@se-studio/contentful-cms 1.0.81 → 1.0.82
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/CHANGELOG.md +6 -0
- package/HOSTED.md +121 -0
- package/INSTALL.md +22 -5
- package/README.md +2 -0
- package/dist/bin/cms-edit.js +8 -143
- package/dist/bin/cms-edit.js.map +1 -1
- package/dist/cli/program.d.ts +9 -0
- package/dist/cli/program.d.ts.map +1 -0
- package/dist/cli/program.js +159 -0
- package/dist/cli/program.js.map +1 -0
- package/dist/cli/runner.d.ts +15 -0
- package/dist/cli/runner.d.ts.map +1 -0
- package/dist/cli/runner.js +93 -0
- package/dist/cli/runner.js.map +1 -0
- package/dist/commands/add.js +2 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/asset.js +5 -5
- package/dist/commands/asset.js.map +1 -1
- package/dist/commands/backup.js +1 -1
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/create-from-json.js +1 -1
- package/dist/commands/create-from-json.js.map +1 -1
- package/dist/commands/create.js +4 -4
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/diff.js +2 -2
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/discard.js +4 -4
- package/dist/commands/discard.js.map +1 -1
- package/dist/commands/guide.d.ts +4 -0
- package/dist/commands/guide.d.ts.map +1 -0
- package/dist/commands/guide.js +18 -0
- package/dist/commands/guide.js.map +1 -0
- package/dist/commands/links.js +10 -10
- package/dist/commands/links.js.map +1 -1
- package/dist/commands/move.js +3 -3
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/nav.js +3 -3
- package/dist/commands/nav.js.map +1 -1
- package/dist/commands/open.js +1 -1
- package/dist/commands/open.js.map +1 -1
- package/dist/commands/peek.d.ts.map +1 -1
- package/dist/commands/peek.js +8 -2
- package/dist/commands/peek.js.map +1 -1
- package/dist/commands/preview.js +1 -1
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/read.js +2 -2
- package/dist/commands/read.js.map +1 -1
- package/dist/commands/remove.js +2 -2
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/revert.js +5 -5
- package/dist/commands/revert.js.map +1 -1
- package/dist/commands/rtf.js +11 -11
- package/dist/commands/rtf.js.map +1 -1
- package/dist/commands/run.js +8 -8
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/save.js +3 -3
- package/dist/commands/save.js.map +1 -1
- package/dist/commands/screenshot.js +2 -2
- package/dist/commands/screenshot.js.map +1 -1
- package/dist/commands/set.js +7 -7
- package/dist/commands/set.js.map +1 -1
- package/dist/commands/snapshot.js +1 -1
- package/dist/commands/snapshot.js.map +1 -1
- package/dist/commands/version.d.ts +4 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +17 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/config/hosted.d.ts +28 -0
- package/dist/config/hosted.d.ts.map +1 -0
- package/dist/config/hosted.js +94 -0
- package/dist/config/hosted.js.map +1 -0
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +5 -0
- package/dist/config/load.js.map +1 -1
- package/dist/hosted/index.d.ts +13 -0
- package/dist/hosted/index.d.ts.map +1 -0
- package/dist/hosted/index.js +12 -0
- package/dist/hosted/index.js.map +1 -0
- package/dist/mcp/guide.d.ts +20 -0
- package/dist/mcp/guide.d.ts.map +1 -0
- package/dist/mcp/guide.js +91 -0
- package/dist/mcp/guide.js.map +1 -0
- package/dist/mcp/http-handler.d.ts +13 -0
- package/dist/mcp/http-handler.d.ts.map +1 -0
- package/dist/mcp/http-handler.js +28 -0
- package/dist/mcp/http-handler.js.map +1 -0
- package/dist/mcp/prompts/onboarding.d.ts +4 -0
- package/dist/mcp/prompts/onboarding.d.ts.map +1 -0
- package/dist/mcp/prompts/onboarding.js +77 -0
- package/dist/mcp/prompts/onboarding.js.map +1 -0
- package/dist/mcp/resources/guide.d.ts +4 -0
- package/dist/mcp/resources/guide.d.ts.map +1 -0
- package/dist/mcp/resources/guide.js +16 -0
- package/dist/mcp/resources/guide.js.map +1 -0
- package/dist/mcp/server.d.ts +13 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +20 -92
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/cms-edit.d.ts +9 -0
- package/dist/mcp/tools/cms-edit.d.ts.map +1 -0
- package/dist/mcp/tools/cms-edit.js +57 -0
- package/dist/mcp/tools/cms-edit.js.map +1 -0
- package/dist/mcp/tools/help.d.ts +4 -0
- package/dist/mcp/tools/help.d.ts.map +1 -0
- package/dist/mcp/tools/help.js +22 -0
- package/dist/mcp/tools/help.js.map +1 -0
- package/dist/mcp/types.d.ts +2 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/runtime/context.d.ts +19 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.js +9 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/session/file-session-store.d.ts +10 -0
- package/dist/session/file-session-store.d.ts.map +1 -0
- package/dist/session/file-session-store.js +92 -0
- package/dist/session/file-session-store.js.map +1 -0
- package/dist/session/redis-session-store.d.ts +21 -0
- package/dist/session/redis-session-store.d.ts.map +1 -0
- package/dist/session/redis-session-store.js +121 -0
- package/dist/session/redis-session-store.js.map +1 -0
- package/dist/session/session-store.d.ts +19 -0
- package/dist/session/session-store.d.ts.map +1 -0
- package/dist/session/session-store.js +9 -0
- package/dist/session/session-store.js.map +1 -0
- package/dist/session/store.d.ts +5 -5
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +16 -74
- package/dist/session/store.js.map +1 -1
- package/dist/version.d.ts +9 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +19 -0
- package/dist/version.js.map +1 -0
- package/docs/FEATURE_REQUESTS_ARCHIVE.md +141 -0
- package/docs/FUNCTIONAL_SPEC.md +271 -0
- package/docs/mcp/hosted-guide.md +149 -0
- package/package.json +14 -6
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { getRuntimeContext } from '../runtime/context.js';
|
|
2
|
+
import { buildSessionKey } from './session-store.js';
|
|
3
|
+
const SESSION_TTL_SECONDS = 60 * 60 * 24 * 7; // 7 days
|
|
4
|
+
/** Parses session JSON from Redis — Upstash may return a deserialized object. */
|
|
5
|
+
export function parseSessionValue(raw) {
|
|
6
|
+
if (!raw)
|
|
7
|
+
return null;
|
|
8
|
+
if (typeof raw === 'string') {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(raw);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (typeof raw === 'object') {
|
|
17
|
+
return raw;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
export class RedisSessionStore {
|
|
22
|
+
redis;
|
|
23
|
+
keyPrefix;
|
|
24
|
+
constructor(redis, keyPrefix = 'cms-edit:session:') {
|
|
25
|
+
this.redis = redis;
|
|
26
|
+
this.keyPrefix = keyPrefix;
|
|
27
|
+
}
|
|
28
|
+
fullKey(sessionKey) {
|
|
29
|
+
return `${this.keyPrefix}${sessionKey}`;
|
|
30
|
+
}
|
|
31
|
+
activePointerKey(userId, sessionName) {
|
|
32
|
+
if (sessionName) {
|
|
33
|
+
return `${this.keyPrefix}${userId}:active:${sessionName}`;
|
|
34
|
+
}
|
|
35
|
+
return `${this.keyPrefix}${userId}:active`;
|
|
36
|
+
}
|
|
37
|
+
getUserId() {
|
|
38
|
+
const userId = getRuntimeContext()?.user?.userId;
|
|
39
|
+
if (!userId) {
|
|
40
|
+
throw new Error('Redis session store requires a Contentful user ID in runtime context.');
|
|
41
|
+
}
|
|
42
|
+
return userId;
|
|
43
|
+
}
|
|
44
|
+
async load(spaceId, rootEntryId, sessionName) {
|
|
45
|
+
const userId = this.getUserId();
|
|
46
|
+
if (spaceId && rootEntryId) {
|
|
47
|
+
const sessionKey = buildSessionKey(userId, spaceId, rootEntryId, sessionName);
|
|
48
|
+
return this.readSession(sessionKey);
|
|
49
|
+
}
|
|
50
|
+
const sessionKey = await this.resolveActiveSessionKey(userId, sessionName);
|
|
51
|
+
if (!sessionKey)
|
|
52
|
+
return null;
|
|
53
|
+
return this.readSession(sessionKey);
|
|
54
|
+
}
|
|
55
|
+
async save(state, sessionName) {
|
|
56
|
+
const userId = this.getUserId();
|
|
57
|
+
const sessionKey = buildSessionKey(userId, state.spaceId, state.rootEntryId, sessionName);
|
|
58
|
+
const ttl = { ex: SESSION_TTL_SECONDS };
|
|
59
|
+
await this.redis.set(this.fullKey(sessionKey), JSON.stringify(state), ttl);
|
|
60
|
+
await this.redis.set(this.activePointerKey(userId, sessionName), sessionKey, ttl);
|
|
61
|
+
}
|
|
62
|
+
async clear(spaceId, rootEntryId, sessionName) {
|
|
63
|
+
const userId = this.getUserId();
|
|
64
|
+
const sessionKey = buildSessionKey(userId, spaceId, rootEntryId, sessionName);
|
|
65
|
+
await this.redis.del(this.fullKey(sessionKey));
|
|
66
|
+
const pointerKey = this.activePointerKey(userId, sessionName);
|
|
67
|
+
const activeKey = await this.redis.get(pointerKey);
|
|
68
|
+
if (activeKey === sessionKey) {
|
|
69
|
+
await this.redis.del(pointerKey);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async clearAll() {
|
|
73
|
+
const userId = this.getUserId();
|
|
74
|
+
const keys = await this.redis.keys(`${this.keyPrefix}${userId}:*`);
|
|
75
|
+
await Promise.all(keys.map((key) => this.redis.del(key)));
|
|
76
|
+
}
|
|
77
|
+
async readSession(sessionKey) {
|
|
78
|
+
const raw = await this.redis.get(this.fullKey(sessionKey));
|
|
79
|
+
return parseSessionValue(raw);
|
|
80
|
+
}
|
|
81
|
+
async resolveActiveSessionKey(userId, sessionName) {
|
|
82
|
+
const pointerKey = this.activePointerKey(userId, sessionName);
|
|
83
|
+
const activeKey = await this.redis.get(pointerKey);
|
|
84
|
+
if (typeof activeKey === 'string' && activeKey.length > 0) {
|
|
85
|
+
return activeKey;
|
|
86
|
+
}
|
|
87
|
+
return this.findLatestSessionKeyFallback(userId, sessionName);
|
|
88
|
+
}
|
|
89
|
+
/** Legacy lookup for sessions saved before active pointers existed. */
|
|
90
|
+
async findLatestSessionKeyFallback(userId, sessionName) {
|
|
91
|
+
const keys = await this.redis.keys(`${this.keyPrefix}${userId}:*`);
|
|
92
|
+
const activeSuffix = sessionName ? `:active:${sessionName}` : ':active';
|
|
93
|
+
const suffix = sessionName ? `-${sessionName}` : undefined;
|
|
94
|
+
const candidates = keys.filter((key) => {
|
|
95
|
+
if (key.endsWith(activeSuffix))
|
|
96
|
+
return false;
|
|
97
|
+
if (suffix)
|
|
98
|
+
return key.endsWith(suffix);
|
|
99
|
+
return !key.includes(':active');
|
|
100
|
+
});
|
|
101
|
+
if (candidates.length === 0)
|
|
102
|
+
return null;
|
|
103
|
+
let latestKey = null;
|
|
104
|
+
let latestFetchedAt = '';
|
|
105
|
+
for (const fullKey of candidates) {
|
|
106
|
+
const raw = await this.redis.get(fullKey);
|
|
107
|
+
const state = parseSessionValue(raw);
|
|
108
|
+
if (!state)
|
|
109
|
+
continue;
|
|
110
|
+
const fetchedAt = state.fetchedAt ?? '';
|
|
111
|
+
if (!latestKey || fetchedAt > latestFetchedAt) {
|
|
112
|
+
latestKey = fullKey;
|
|
113
|
+
latestFetchedAt = fetchedAt;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!latestKey)
|
|
117
|
+
return null;
|
|
118
|
+
return latestKey.slice(this.keyPrefix.length);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=redis-session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-session-store.js","sourceRoot":"","sources":["../../src/session/redis-session-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAA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AC,GAAG,CAAC,CAAC;YACrC,IAAI,CAAC,KAAK;gBAAE,SAAS;YAErB,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;YACxC,IAAI,CAAC,SAAS,IAAI,SAAS,GAAG,eAAe,EAAE,CAAC;gBAC9C,SAAS,GAAG,OAAO,CAAC;gBACpB,eAAe,GAAG,SAAS,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC;QAC5B,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SessionState } from './state.js';
|
|
2
|
+
export interface SessionStore {
|
|
3
|
+
load(spaceId?: string, rootEntryId?: string, sessionName?: string): SessionState | null | Promise<SessionState | null>;
|
|
4
|
+
save(state: SessionState, sessionName?: string): void | Promise<void>;
|
|
5
|
+
clear(spaceId: string, rootEntryId: string, sessionName?: string): void | Promise<void>;
|
|
6
|
+
clearAll(): void | Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface RedisClient {
|
|
9
|
+
/** Upstash may return parsed JSON objects when automaticDeserialization is enabled. */
|
|
10
|
+
get(key: string): Promise<unknown>;
|
|
11
|
+
set(key: string, value: string, options?: {
|
|
12
|
+
ex?: number;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
del(key: string): Promise<void>;
|
|
15
|
+
keys(pattern: string): Promise<string[]>;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildSessionKey(userId: string | undefined, spaceId: string, rootEntryId: string, sessionName?: string): string;
|
|
18
|
+
export declare function buildSessionNameSuffix(sessionName: string): string;
|
|
19
|
+
//# sourceMappingURL=session-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/session/session-store.ts"],"names":[],"mappings":"AAAA,O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+1,9 @@
|
|
|
1
|
+
export function buildSessionKey(userId, spaceId, rootEntryId, sessionName) {
|
|
2
|
+
const suffix = sessionName ? `-${sessionName}` : '';
|
|
3
|
+
const base = `${spaceId}-${rootEntryId}${suffix}`;
|
|
4
|
+
return userId ? `${userId}:${base}` : base;
|
|
5
|
+
}
|
|
6
|
+
export function buildSessionNameSuffix(sessionName) {
|
|
7
|
+
return `-${sessionName}`;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/session/session-store.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,eAAe,CAC7B,MAA0B,EAC1B,OAAe,EACf,WAAmB,EACnB,WAAoB;IAEpB,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,GAAG,OAAO,IAAI,WAAW,GAAG,MAAM,EAAE,CAAC;IAClD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,WAAmB;IACxD,OAAO,IAAI,WAAW,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/session/store.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type { SessionState } from './state.js';
|
|
|
4
4
|
* Used by all commands to support named, isolated sessions (--session <name>).
|
|
5
5
|
*/
|
|
6
6
|
export declare function resolveSessionName(cliName?: string): string | undefined;
|
|
7
|
-
export declare function loadSession(spaceId?: string, rootEntryId?: string, sessionName?: string): SessionState | null
|
|
8
|
-
export declare function saveSession(state: SessionState, sessionName?: string): void
|
|
9
|
-
export declare function clearSession(spaceId: string, rootEntryId: string, sessionName?: string): void
|
|
10
|
-
export declare function clearAllSessions(): void
|
|
7
|
+
export declare function loadSession(spaceId?: string, rootEntryId?: string, sessionName?: string): Promise<SessionState | null>;
|
|
8
|
+
export declare function saveSession(state: SessionState, sessionName?: string): Promise<void>;
|
|
9
|
+
export declare function clearSession(spaceId: string, rootEntryId: string, sessionName?: string): Promise<void>;
|
|
10
|
+
export declare function clearAllSessions(): Promise<void>;
|
|
11
11
|
/**
|
|
12
12
|
* Loads the active session or throws a helpful error if none exists.
|
|
13
13
|
* Pass `sessionName` (or set CONTENTFUL_CMS_SESSION) to target a named session.
|
|
14
14
|
*/
|
|
15
|
-
export declare function requireSession(sessionName?: string, configPath?: string): SessionState
|
|
15
|
+
export declare function requireSession(sessionName?: string, configPath?: string): Promise<SessionState>;
|
|
16
16
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/session/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/session/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvE;AAUD,wBAAsB,WAAW,CAC/B,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAI9B;AAED,wBAAsB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1F;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,WAAW,CAAC,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,YAAY,CAAC,CA2BvB"}
|
package/dist/session/store.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as os from 'node:os';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
1
|
import { ConfigUnavailableError, loadConfig } from '../config/load.js';
|
|
5
|
-
|
|
2
|
+
import { getRuntimeContext } from '../runtime/context.js';
|
|
3
|
+
import { defaultFileSessionStore } from './file-session-store.js';
|
|
6
4
|
/**
|
|
7
5
|
* Returns the name of the active session from CLI options or the CONTENTFUL_CMS_SESSION env var.
|
|
8
6
|
* Used by all commands to support named, isolated sessions (--session <name>).
|
|
@@ -10,91 +8,35 @@ const SESSIONS_DIR = path.join(os.homedir(), '.contentful-cms', 'sessions');
|
|
|
10
8
|
export function resolveSessionName(cliName) {
|
|
11
9
|
return cliName ?? process.env['CONTENTFUL_CMS_SESSION'] ?? undefined;
|
|
12
10
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
return path.join(SESSIONS_DIR, `${spaceId}-${rootEntryId}${suffix}.json`);
|
|
11
|
+
function getActiveSessionStore() {
|
|
12
|
+
return getRuntimeContext()?.sessionStore ?? defaultFileSessionStore;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* session name suffix, if any. Used when only --session is given without spaceId/rootEntryId.
|
|
20
|
-
*/
|
|
21
|
-
function findNamedSessionPath(sessionName) {
|
|
22
|
-
if (!fs.existsSync(SESSIONS_DIR))
|
|
23
|
-
return null;
|
|
24
|
-
const suffix = `-${sessionName}.json`;
|
|
25
|
-
const files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith(suffix));
|
|
26
|
-
if (files.length === 0)
|
|
27
|
-
return null;
|
|
28
|
-
const sorted = files
|
|
29
|
-
.map((f) => ({ file: f, mtime: fs.statSync(path.join(SESSIONS_DIR, f)).mtime }))
|
|
30
|
-
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
|
31
|
-
const latest = sorted[0];
|
|
32
|
-
return latest ? path.join(SESSIONS_DIR, latest.file) : null;
|
|
14
|
+
async function resolveStoreResult(value) {
|
|
15
|
+
return await Promise.resolve(value);
|
|
33
16
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!fs.existsSync(SESSIONS_DIR))
|
|
37
|
-
return null;
|
|
38
|
-
const files = fs.readdirSync(SESSIONS_DIR).filter((f) => f.endsWith('.json'));
|
|
39
|
-
if (files.length === 0)
|
|
40
|
-
return null;
|
|
41
|
-
const sorted = files
|
|
42
|
-
.map((f) => ({ file: f, mtime: fs.statSync(path.join(SESSIONS_DIR, f)).mtime }))
|
|
43
|
-
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
|
44
|
-
const latest = sorted[0];
|
|
45
|
-
return latest ? path.join(SESSIONS_DIR, latest.file) : null;
|
|
17
|
+
export async function loadSession(spaceId, rootEntryId, sessionName) {
|
|
18
|
+
return resolveStoreResult(getActiveSessionStore().load(spaceId, rootEntryId, resolveSessionName(sessionName)));
|
|
46
19
|
}
|
|
47
|
-
export function
|
|
48
|
-
|
|
49
|
-
const sessionPath = spaceId && rootEntryId
|
|
50
|
-
? getSessionPath(spaceId, rootEntryId, resolvedName)
|
|
51
|
-
: resolvedName
|
|
52
|
-
? findNamedSessionPath(resolvedName)
|
|
53
|
-
: findLatestSessionPath();
|
|
54
|
-
if (!sessionPath || !fs.existsSync(sessionPath))
|
|
55
|
-
return null;
|
|
56
|
-
try {
|
|
57
|
-
return JSON.parse(fs.readFileSync(sessionPath, 'utf-8'));
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
20
|
+
export async function saveSession(state, sessionName) {
|
|
21
|
+
await resolveStoreResult(getActiveSessionStore().save(state, resolveSessionName(sessionName)));
|
|
62
22
|
}
|
|
63
|
-
export function
|
|
64
|
-
|
|
65
|
-
const resolvedName = resolveSessionName(sessionName);
|
|
66
|
-
const sessionPath = getSessionPath(state.spaceId, state.rootEntryId, resolvedName);
|
|
67
|
-
fs.writeFileSync(sessionPath, JSON.stringify(state, null, 2), 'utf-8');
|
|
23
|
+
export async function clearSession(spaceId, rootEntryId, sessionName) {
|
|
24
|
+
await resolveStoreResult(getActiveSessionStore().clear(spaceId, rootEntryId, resolveSessionName(sessionName)));
|
|
68
25
|
}
|
|
69
|
-
export function
|
|
70
|
-
|
|
71
|
-
const sessionPath = getSessionPath(spaceId, rootEntryId, resolvedName);
|
|
72
|
-
if (fs.existsSync(sessionPath)) {
|
|
73
|
-
fs.unlinkSync(sessionPath);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export function clearAllSessions() {
|
|
77
|
-
if (!fs.existsSync(SESSIONS_DIR))
|
|
78
|
-
return;
|
|
79
|
-
for (const file of fs.readdirSync(SESSIONS_DIR)) {
|
|
80
|
-
if (file.endsWith('.json')) {
|
|
81
|
-
fs.unlinkSync(path.join(SESSIONS_DIR, file));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
26
|
+
export async function clearAllSessions() {
|
|
27
|
+
await resolveStoreResult(getActiveSessionStore().clearAll());
|
|
84
28
|
}
|
|
85
29
|
/**
|
|
86
30
|
* Loads the active session or throws a helpful error if none exists.
|
|
87
31
|
* Pass `sessionName` (or set CONTENTFUL_CMS_SESSION) to target a named session.
|
|
88
32
|
*/
|
|
89
|
-
export function requireSession(sessionName, configPath) {
|
|
90
|
-
const session = loadSession(undefined, undefined, sessionName);
|
|
33
|
+
export async function requireSession(sessionName, configPath) {
|
|
34
|
+
const session = await loadSession(undefined, undefined, resolveSessionName(sessionName));
|
|
91
35
|
if (!session) {
|
|
92
36
|
const nameHint = resolveSessionName(sessionName);
|
|
93
37
|
const hint = nameHint ? ` (session: ${nameHint})` : '';
|
|
94
38
|
throw new Error(`No active session${hint}. Run 'cms-edit open <slug>' or 'cms-edit open <id> --id' first.`);
|
|
95
39
|
}
|
|
96
|
-
// Validate the session belongs to a space configured in this project.
|
|
97
|
-
// Silently skips when no config file is found or env vars are missing (e.g. CI / global use).
|
|
98
40
|
try {
|
|
99
41
|
const config = loadConfig(configPath);
|
|
100
42
|
const validSpaceKeys = Object.keys(config.spaces);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAIlE;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,OAAO,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,SAAS,CAAC;AACvE,CAAC;AAED,SAAS,qBAAqB;IAC5B,OAAO,iBAAiB,EAAE,EAAE,YAAY,IAAI,uBAAuB,CAAC;AACtE,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAI,KAAqB;IACxD,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,WAAoB,EACpB,WAAoB;IAEpB,OAAO,kBAAkB,CACvB,qBAAqB,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC,CACpF,CAAC;AACJ,CAAC;AAED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C;YAC5E,MAAM,IAAI,KAAK,CACb,+CAA+C,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;gBAC3E,yCAAyC,OAAO,CAAC,QAAQ,mCAAmC;gBAC5F,oDAAoD,CACvD,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,sBAAsB,EAAE,CAAC;YACxC,6CAA6C;QAC/C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CmsEditVersionInfo {
|
|
2
|
+
name: 'cms-edit';
|
|
3
|
+
version: string;
|
|
4
|
+
package: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const CMS_EDIT_PACKAGE_NAME: string;
|
|
7
|
+
export declare const CMS_EDIT_VERSION: string;
|
|
8
|
+
export declare function getVersionInfo(): CmsEditVersionInfo;
|
|
9
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAeD,eAAO,MAAM,qBAAqB,QAA0C,CAAC;AAC7E,eAAO,MAAM,gBAAgB,QAAyB,CAAC;AAEvD,wBAAgB,cAAc,IAAI,kBAAkB,CAMnD"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
function readPackageJson() {
|
|
5
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
6
|
+
const raw = readFileSync(path.join(packageRoot, 'package.json'), 'utf-8');
|
|
7
|
+
return JSON.parse(raw);
|
|
8
|
+
}
|
|
9
|
+
const pkg = readPackageJson();
|
|
10
|
+
export const CMS_EDIT_PACKAGE_NAME = pkg.name ?? '@se-studio/contentful-cms';
|
|
11
|
+
export const CMS_EDIT_VERSION = pkg.version ?? '0.0.0';
|
|
12
|
+
export function getVersionInfo() {
|
|
13
|
+
return {
|
|
14
|
+
name: 'cms-edit',
|
|
15
|
+
version: CMS_EDIT_VERSION,
|
|
16
|
+
package: CMS_EDIT_PACKAGE_NAME,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAazC,SAAS,eAAe;IACtB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACrF,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAgB,CAAC;AACxC,CAAC;AAED,MAAM,GAAG,GAAG,eAAe,EAAE,CAAC;AAE9B,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC,IAAI,IAAI,2BAA2B,CAAC;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC;AAEvD,MAAM,UAAU,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,gBAAgB;QACzB,OAAO,EAAE,qBAAqB;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# cms-edit: Feature Requests Archive — `rtf replace` Improvements
|
|
2
|
+
|
|
3
|
+
> **Archive notice (2026-03-26):** All items in this file have been implemented. FR-1 (`--protect-pattern`), FR-2 (`--find-plain`), FR-3 (`--ignore-marks`), and FR-4 (`--in-table-col`) are all available in `rtf replace`. Retained for historical context.
|
|
4
|
+
|
|
5
|
+
These requests were identified during real-world compliance automation work where `cms-edit rtf replace` was used to surgically insert Quidget codes into credit card affiliate articles. Each issue caused a failed or unsafe replacement and required a discard-and-redo.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## FR-1 — `rtf replace`: `--mode all` must skip content inside existing quidget spans
|
|
10
|
+
|
|
11
|
+
### Problem
|
|
12
|
+
|
|
13
|
+
Once a quidget code has been inserted into a text node (e.g. `{*credit_card_id*:*2061159*,*field*:*annual_fees*,*api*:*cc*,*case*:*uf*,*placeholder*:*$95*}`), a subsequent `--find '$95' --mode all` matches the `$95` character sequence inside the placeholder value of the already-inserted code. This nests a new quidget code inside the old one, producing:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
{*credit_card_id*:*2061159*,...,*placeholder*:*{*credit_card_id*:*2061159*,...,*placeholder*:*$95*}*}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The document is now corrupt and the quidget will not render correctly.
|
|
20
|
+
|
|
21
|
+
### Reproducing scenario
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Step 1 — insert a quidget code for one occurrence of $95
|
|
25
|
+
cms-edit rtf replace @c1 body \
|
|
26
|
+
--find 'justify the $95 annual fee' \
|
|
27
|
+
--replace-plain 'justify the {*credit_card_id*:*2061159*,*field*:*annual_fees*,*api*:*cc*,*case*:*uf*,*placeholder*:*$95*} annual fee' \
|
|
28
|
+
--mode exactlyOne
|
|
29
|
+
|
|
30
|
+
# Step 2 — now try to replace remaining $95 occurrences
|
|
31
|
+
cms-edit rtf replace @c1 body \
|
|
32
|
+
--find '$95' \
|
|
33
|
+
--replace-plain '{*credit_card_id*:*2061159*,*field*:*annual_fees*,*api*:*cc*,*case*:*uf*,*placeholder*:*$95*}' \
|
|
34
|
+
--mode all
|
|
35
|
+
# ❌ Step 2 also matches $95 inside the placeholder written in Step 1
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Proposed solution
|
|
39
|
+
|
|
40
|
+
When scanning text nodes for `--find` matches, treat any span matching `{*...*}` as opaque — skip over it entirely. The tool already understands quidget token syntax (it writes them via `--replace-plain`); it should also recognise them as protected spans during search, the same way a text editor's Find would not match inside a non-editable region.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## FR-2 — `rtf replace`: add `--find-plain` to search for literal asterisks
|
|
45
|
+
|
|
46
|
+
### Problem
|
|
47
|
+
|
|
48
|
+
`--replace-plain` exists so that quidget tokens containing `*` are written as literal characters rather than parsed as Markdown bold markers. There is no equivalent flag for `--find`. This makes it impossible to search for any string that contains `*`, including:
|
|
49
|
+
|
|
50
|
+
- Existing quidget codes (e.g. to verify or fix a previously inserted code)
|
|
51
|
+
- Any content that legitimately contains asterisks
|
|
52
|
+
|
|
53
|
+
As a practical consequence, when FR-1's corruption does occur, there is no surgical way to fix the corrupted node — it can only be corrected by discarding the entire session and starting over.
|
|
54
|
+
|
|
55
|
+
### Reproducing scenario
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Try to fix a corrupted quidget by searching for its text — fails silently
|
|
59
|
+
cms-edit rtf replace @c1 body \
|
|
60
|
+
--find 'placeholder*:*{*credit_card_id' \
|
|
61
|
+
--replace-plain 'placeholder*:*$95*}' \
|
|
62
|
+
--mode all
|
|
63
|
+
# ❌ Warning: No occurrence of --find in "body" on @c1; session unchanged for this field.
|
|
64
|
+
# (asterisks are parsed as Markdown bold markers, not literal characters)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Proposed solution
|
|
68
|
+
|
|
69
|
+
Add a `--find-plain` flag (mirroring `--replace-plain`) that treats the `--find` argument as a literal string with no Markdown interpretation. Combined with FR-1, this would allow both safe searching and recovery from corruption.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Desired behaviour with --find-plain
|
|
73
|
+
cms-edit rtf replace @c1 body \
|
|
74
|
+
--find-plain 'placeholder*:*{*credit_card_id*:*2061159*,...' \
|
|
75
|
+
--replace-plain 'placeholder*:*$95*}' \
|
|
76
|
+
--mode exactlyOne
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## FR-3 — `rtf replace`: `--ignore-marks` to match across inline formatting boundaries
|
|
82
|
+
|
|
83
|
+
### Problem
|
|
84
|
+
|
|
85
|
+
The `--find` search operates per text node. A paragraph stored as `**Annual fee: **$95` is two adjacent text nodes — one bold (`Annual fee: `) and one normal (`$95`) — so `--find "Annual fee: $95"` finds nothing. This affects every bold-label + plain-value pattern in credit card articles:
|
|
86
|
+
|
|
87
|
+
- `**Annual fee: **$95`
|
|
88
|
+
- `**Foreign transaction fees: **None`
|
|
89
|
+
- `**Current welcome bonus: **75,000 points…`
|
|
90
|
+
|
|
91
|
+
These are extremely common in affiliate content. Because the label cannot be used as context, the search string must be the bare value (`$95`), which is then often not unique across the document.
|
|
92
|
+
|
|
93
|
+
### Reproducing scenario
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Article body contains: **Annual fee: **$95
|
|
97
|
+
cms-edit rtf replace @c1 body \
|
|
98
|
+
--find 'Annual fee: $95' \
|
|
99
|
+
--replace-plain 'Annual fee: {*credit_card_id*:*2061159*,*field*:*annual_fees*,...*}' \
|
|
100
|
+
--mode exactlyOne
|
|
101
|
+
# ❌ Error: No occurrence of find string in document
|
|
102
|
+
# (because "Annual fee: " and "$95" are in different text nodes)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Proposed solution
|
|
106
|
+
|
|
107
|
+
Add an `--ignore-marks` flag that, for the purpose of matching only, concatenates the text content of adjacent sibling nodes within the same block (paragraph, list item, table cell). The replacement then applies to the matching text while preserving the original inline marks in the output.
|
|
108
|
+
|
|
109
|
+
**Alternative (lower effort):** If the full implementation is complex, at minimum document this limitation in the `rtf replace --help` output with a concrete example, so that LLMs using the tool do not waste retries on searches that can never succeed.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## FR-4 — `rtf replace`: table column targeting
|
|
114
|
+
|
|
115
|
+
### Problem
|
|
116
|
+
|
|
117
|
+
When a comparison table contains the same plain-text value in multiple columns — for example, both the primary card and a competitor showing `None` for foreign transaction fees — there is no way to target only the column belonging to the primary card. Any `--find "None"` replacement hits every matching cell in every column.
|
|
118
|
+
|
|
119
|
+
In the specific case that prompted this request: a Chase Sapphire Preferred vs. Chase Sapphire Reserve comparison table has `None` in both the CSP and CSR foreign-transaction-fee cells. Replacing all occurrences would incorrectly tag the CSR cell with the CSP card's quidget code.
|
|
120
|
+
|
|
121
|
+
### Proposed solution
|
|
122
|
+
|
|
123
|
+
**Option A (preferred):** A `--in-table-col N` flag (1-indexed) that restricts matches to cells in the Nth column of any table encountered in the field.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
cms-edit rtf replace @c1 body \
|
|
127
|
+
--find 'None' \
|
|
128
|
+
--replace-plain '{*credit_card_id*:*2061159*,*field*:*foreign_transaction_fee*,...*}' \
|
|
129
|
+
--in-table-col 2 \
|
|
130
|
+
--mode all
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Option B:** An `--after "text"` flag that requires the match to appear after a specific string in document order, scoped to the nearest enclosing table row.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Minor: `diff` output for rich text fields
|
|
138
|
+
|
|
139
|
+
The `diff` command currently shows a single-line before/after delta for an entire rich text body field, making it impossible to verify which text runs actually changed before saving.
|
|
140
|
+
|
|
141
|
+
**Requested:** Show a count of changed text runs (e.g. `7 text run(s) changed`) and/or show abbreviated before/after excerpts for each changed span. This would let an LLM confirm that exactly the expected number of replacements took effect without requiring a full re-read of the field.
|