@se-studio/contentful-cms 1.0.91 → 1.1.0
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 +22 -0
- package/README.md +49 -2
- package/dist/cli/program.d.ts.map +1 -1
- package/dist/cli/program.js +10 -1
- package/dist/cli/program.js.map +1 -1
- package/dist/commands/asset.d.ts.map +1 -1
- package/dist/commands/asset.js +232 -56
- package/dist/commands/asset.js.map +1 -1
- package/dist/commands/create-from-json.d.ts.map +1 -1
- package/dist/commands/create-from-json.js +63 -69
- package/dist/commands/create-from-json.js.map +1 -1
- package/dist/commands/create-taxonomy-from-json.d.ts +4 -0
- package/dist/commands/create-taxonomy-from-json.d.ts.map +1 -0
- package/dist/commands/create-taxonomy-from-json.js +79 -0
- package/dist/commands/create-taxonomy-from-json.js.map +1 -0
- package/dist/commands/create-taxonomy.d.ts +29 -0
- package/dist/commands/create-taxonomy.d.ts.map +1 -0
- package/dist/commands/create-taxonomy.js +187 -0
- package/dist/commands/create-taxonomy.js.map +1 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +14 -36
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/ensure.d.ts +4 -0
- package/dist/commands/ensure.d.ts.map +1 -0
- package/dist/commands/ensure.js +95 -0
- package/dist/commands/ensure.js.map +1 -0
- package/dist/commands/help.js +1 -1
- package/dist/commands/help.js.map +1 -1
- package/dist/commands/index-dump.d.ts +13 -0
- package/dist/commands/index-dump.d.ts.map +1 -0
- package/dist/commands/index-dump.js +161 -0
- package/dist/commands/index-dump.js.map +1 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +101 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +91 -17
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/resolve-options.d.ts +13 -0
- package/dist/commands/resolve-options.d.ts.map +1 -0
- package/dist/commands/resolve-options.js +29 -0
- package/dist/commands/resolve-options.js.map +1 -0
- package/dist/commands/resolve.d.ts.map +1 -1
- package/dist/commands/resolve.js +70 -26
- package/dist/commands/resolve.js.map +1 -1
- package/dist/config/load.d.ts.map +1 -1
- package/dist/config/load.js +10 -0
- package/dist/config/load.js.map +1 -1
- package/dist/config/types.d.ts +14 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/contentful/asset-link-from-json.d.ts +17 -0
- package/dist/contentful/asset-link-from-json.d.ts.map +1 -0
- package/dist/contentful/asset-link-from-json.js +41 -0
- package/dist/contentful/asset-link-from-json.js.map +1 -0
- package/dist/contentful/assets.d.ts +19 -8
- package/dist/contentful/assets.d.ts.map +1 -1
- package/dist/contentful/assets.js +82 -31
- package/dist/contentful/assets.js.map +1 -1
- package/dist/contentful/cda-sync.d.ts +37 -0
- package/dist/contentful/cda-sync.d.ts.map +1 -0
- package/dist/contentful/cda-sync.js +115 -0
- package/dist/contentful/cda-sync.js.map +1 -0
- package/dist/contentful/delivery-token.d.ts +17 -0
- package/dist/contentful/delivery-token.d.ts.map +1 -0
- package/dist/contentful/delivery-token.js +103 -0
- package/dist/contentful/delivery-token.js.map +1 -0
- package/dist/contentful/entry-fields.d.ts +71 -0
- package/dist/contentful/entry-fields.d.ts.map +1 -0
- package/dist/contentful/entry-fields.js +334 -0
- package/dist/contentful/entry-fields.js.map +1 -0
- package/dist/contentful/fetch.d.ts +11 -1
- package/dist/contentful/fetch.d.ts.map +1 -1
- package/dist/contentful/fetch.js +30 -6
- package/dist/contentful/fetch.js.map +1 -1
- package/dist/contentful/field-value-from-json.d.ts +24 -0
- package/dist/contentful/field-value-from-json.d.ts.map +1 -0
- package/dist/contentful/field-value-from-json.js +205 -0
- package/dist/contentful/field-value-from-json.js.map +1 -0
- package/dist/contentful/list-entry-format.d.ts +18 -0
- package/dist/contentful/list-entry-format.d.ts.map +1 -0
- package/dist/contentful/list-entry-format.js +45 -0
- package/dist/contentful/list-entry-format.js.map +1 -0
- package/dist/contentful/media.d.ts +24 -0
- package/dist/contentful/media.d.ts.map +1 -0
- package/dist/contentful/media.js +70 -0
- package/dist/contentful/media.js.map +1 -0
- package/dist/contentful/regex.d.ts +14 -0
- package/dist/contentful/regex.d.ts.map +1 -0
- package/dist/contentful/regex.js +38 -0
- package/dist/contentful/regex.js.map +1 -0
- package/dist/contentful/resolve-content-type.d.ts +9 -0
- package/dist/contentful/resolve-content-type.d.ts.map +1 -0
- package/dist/contentful/resolve-content-type.js +38 -0
- package/dist/contentful/resolve-content-type.js.map +1 -0
- package/dist/contentful/upload-fetch.d.ts +11 -0
- package/dist/contentful/upload-fetch.d.ts.map +1 -0
- package/dist/contentful/upload-fetch.js +26 -0
- package/dist/contentful/upload-fetch.js.map +1 -0
- package/dist/contentful/upload-limits.d.ts +7 -0
- package/dist/contentful/upload-limits.d.ts.map +1 -0
- package/dist/contentful/upload-limits.js +13 -0
- package/dist/contentful/upload-limits.js.map +1 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.d.ts.map +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/generated/version.js.map +1 -1
- package/dist/index/db.d.ts +10 -0
- package/dist/index/db.d.ts.map +1 -0
- package/dist/index/db.js +29 -0
- package/dist/index/db.js.map +1 -0
- package/dist/index/mode.d.ts +7 -0
- package/dist/index/mode.d.ts.map +1 -0
- package/dist/index/mode.js +9 -0
- package/dist/index/mode.js.map +1 -0
- package/dist/index/paths.d.ts +6 -0
- package/dist/index/paths.d.ts.map +1 -0
- package/dist/index/paths.js +23 -0
- package/dist/index/paths.js.map +1 -0
- package/dist/index/query.d.ts +75 -0
- package/dist/index/query.d.ts.map +1 -0
- package/dist/index/query.js +214 -0
- package/dist/index/query.js.map +1 -0
- package/dist/index/require.d.ts +16 -0
- package/dist/index/require.d.ts.map +1 -0
- package/dist/index/require.js +28 -0
- package/dist/index/require.js.map +1 -0
- package/dist/index/schema.d.ts +3 -0
- package/dist/index/schema.d.ts.map +1 -0
- package/dist/index/schema.js +34 -0
- package/dist/index/schema.js.map +1 -0
- package/dist/index/sync.d.ts +29 -0
- package/dist/index/sync.d.ts.map +1 -0
- package/dist/index/sync.js +116 -0
- package/dist/index/sync.js.map +1 -0
- package/dist/output/terminal-table.d.ts +15 -0
- package/dist/output/terminal-table.d.ts.map +1 -0
- package/dist/output/terminal-table.js +60 -0
- package/dist/output/terminal-table.js.map +1 -0
- package/docs/FUNCTIONAL_SPEC.md +11 -0
- package/docs/MEDIA_INDEX_PLAN.md +238 -0
- package/docs/help/create-from-json.md +54 -2
- package/docs/help/fields-article.md +5 -0
- package/docs/help/fields-component.md +11 -1
- package/docs/help/fields-page.md +2 -0
- package/docs/help/fields-taxonomy.md +154 -0
- package/docs/help/index-sync.md +73 -0
- package/docs/help/index.md +16 -0
- package/docs/help/taxonomy-from-json.md +115 -0
- package/package.json +5 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolveIndexPreview } from './mode.js';
|
|
2
|
+
import { indexExists } from './paths.js';
|
|
3
|
+
import { getIndexSyncedAt } from './query.js';
|
|
4
|
+
import { INDEX_STALE_MS, isSyncedAtStale } from './sync.js';
|
|
5
|
+
export class MediaIndexRequiredError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'MediaIndexRequiredError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ensures the local media index exists before asset search / list / audit commands.
|
|
13
|
+
*/
|
|
14
|
+
export function requireMediaIndex(space, opts = {}) {
|
|
15
|
+
const preview = resolveIndexPreview(opts.preview);
|
|
16
|
+
if (!indexExists(space, preview)) {
|
|
17
|
+
const flag = preview ? '' : ' --published';
|
|
18
|
+
throw new MediaIndexRequiredError(`Media index not found for this space/environment. Run: cms-edit index sync${flag}`);
|
|
19
|
+
}
|
|
20
|
+
const syncedAt = getIndexSyncedAt(space, preview);
|
|
21
|
+
const stale = syncedAt ? isSyncedAtStale(syncedAt) : true;
|
|
22
|
+
if (stale && opts.warnIfStale) {
|
|
23
|
+
const hours = Math.round(INDEX_STALE_MS / (60 * 60 * 1000));
|
|
24
|
+
opts.warnIfStale(`Media index is older than ${String(hours)}h (synced ${syncedAt ?? 'unknown'}). Run cms-edit index sync for fresh data.`);
|
|
25
|
+
}
|
|
26
|
+
return { syncedAt, stale };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=require.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"require.js","sourceRoot":"","sources":["../../src/index/require.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAOD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,OAAuE,EAAE;IAEzE,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAElD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;QAC3C,MAAM,IAAI,uBAAuB,CAC/B,6EAA6E,IAAI,EAAE,CACpF,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE1D,IAAI,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,CACd,6BAA6B,MAAM,CAAC,KAAK,CAAC,aAAa,QAAQ,IAAI,SAAS,4CAA4C,CACzH,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const SCHEMA_VERSION = 1;
|
|
2
|
+
export declare const DDL = "\nCREATE TABLE IF NOT EXISTS meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS assets (\n id TEXT PRIMARY KEY,\n fileName TEXT NOT NULL,\n title TEXT NOT NULL,\n description TEXT,\n contentType TEXT NOT NULL,\n url TEXT NOT NULL,\n width INTEGER,\n height INTEGER,\n size INTEGER,\n updatedAt TEXT NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS media (\n id TEXT PRIMARY KEY,\n name TEXT NOT NULL,\n assetId TEXT NOT NULL,\n assetFileName TEXT NOT NULL,\n updatedAt TEXT NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_assets_fileName ON assets(fileName);\nCREATE INDEX IF NOT EXISTS idx_assets_title ON assets(title);\nCREATE INDEX IF NOT EXISTS idx_media_assetId ON media(assetId);\nCREATE INDEX IF NOT EXISTS idx_media_assetFileName ON media(assetFileName);\n";
|
|
3
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/index/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,eAAO,MAAM,GAAG,gzBA+Bf,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const SCHEMA_VERSION = 1;
|
|
2
|
+
export const DDL = `
|
|
3
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
4
|
+
key TEXT PRIMARY KEY,
|
|
5
|
+
value TEXT NOT NULL
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
CREATE TABLE IF NOT EXISTS assets (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
fileName TEXT NOT NULL,
|
|
11
|
+
title TEXT NOT NULL,
|
|
12
|
+
description TEXT,
|
|
13
|
+
contentType TEXT NOT NULL,
|
|
14
|
+
url TEXT NOT NULL,
|
|
15
|
+
width INTEGER,
|
|
16
|
+
height INTEGER,
|
|
17
|
+
size INTEGER,
|
|
18
|
+
updatedAt TEXT NOT NULL
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS media (
|
|
22
|
+
id TEXT PRIMARY KEY,
|
|
23
|
+
name TEXT NOT NULL,
|
|
24
|
+
assetId TEXT NOT NULL,
|
|
25
|
+
assetFileName TEXT NOT NULL,
|
|
26
|
+
updatedAt TEXT NOT NULL
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE INDEX IF NOT EXISTS idx_assets_fileName ON assets(fileName);
|
|
30
|
+
CREATE INDEX IF NOT EXISTS idx_assets_title ON assets(title);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_media_assetId ON media(assetId);
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_media_assetFileName ON media(assetFileName);
|
|
33
|
+
`;
|
|
34
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/index/schema.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,MAAM,CAAC,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BlB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SpaceConfig } from '../config/types.js';
|
|
2
|
+
import type { CdaAssetRecord, CdaSyncPayload } from '../contentful/cda-sync.js';
|
|
3
|
+
export interface SyncIndexOptions {
|
|
4
|
+
preview?: boolean;
|
|
5
|
+
accessToken: string;
|
|
6
|
+
apiKeyId?: string;
|
|
7
|
+
payload: CdaSyncPayload;
|
|
8
|
+
}
|
|
9
|
+
export interface SyncIndexResult {
|
|
10
|
+
dbPath: string;
|
|
11
|
+
assetCount: number;
|
|
12
|
+
mediaCount: number;
|
|
13
|
+
syncedAt: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function rebuildIndexFromPayload(space: SpaceConfig, options: SyncIndexOptions): SyncIndexResult;
|
|
16
|
+
/** Upsert a single asset row after CMA upload (optional dedup freshness). */
|
|
17
|
+
export declare function upsertAssetRow(space: SpaceConfig, asset: CdaAssetRecord, preview?: boolean): void;
|
|
18
|
+
export declare function readIndexStatus(space: SpaceConfig, preview?: boolean): {
|
|
19
|
+
exists: boolean;
|
|
20
|
+
dbPath: string;
|
|
21
|
+
syncedAt: string | null;
|
|
22
|
+
assetCount: number | null;
|
|
23
|
+
mediaCount: number | null;
|
|
24
|
+
apiKeyId: string | null;
|
|
25
|
+
stale: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare const INDEX_STALE_MS: number;
|
|
28
|
+
export declare function isSyncedAtStale(syncedAt: string, now?: number): boolean;
|
|
29
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/index/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAkB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAOhG,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AA0CD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,gBAAgB,GACxB,eAAe,CAmCjB;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,cAAc,EACrB,OAAO,GAAE,OAA+B,GACvC,IAAI,CA6BN;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;CAChB,CAiCA;AAED,eAAO,MAAM,cAAc,QAAsB,CAAC;AAElD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,OAAO,CAI3E"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { hashDeliveryToken } from '../contentful/delivery-token.js';
|
|
2
|
+
import { getMeta, openIndexDatabase, setMeta } from './db.js';
|
|
3
|
+
import { DEFAULT_INDEX_PREVIEW, resolveIndexPreview } from './mode.js';
|
|
4
|
+
import { ensureIndexDirectory, getIndexDbPath, indexExists } from './paths.js';
|
|
5
|
+
import { SCHEMA_VERSION } from './schema.js';
|
|
6
|
+
function clearTables(db) {
|
|
7
|
+
db.exec('DELETE FROM assets; DELETE FROM media;');
|
|
8
|
+
}
|
|
9
|
+
function insertAssets(db, assets) {
|
|
10
|
+
const stmt = db.prepare(`
|
|
11
|
+
INSERT INTO assets (id, fileName, title, description, contentType, url, width, height, size, updatedAt)
|
|
12
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
13
|
+
`);
|
|
14
|
+
for (const a of assets) {
|
|
15
|
+
stmt.run(a.id, a.fileName, a.title, a.description, a.contentType, a.url, a.width, a.height, a.size, a.updatedAt);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function insertMedia(db, media, fileNameByAssetId) {
|
|
19
|
+
const stmt = db.prepare(`
|
|
20
|
+
INSERT INTO media (id, name, assetId, assetFileName, updatedAt)
|
|
21
|
+
VALUES (?, ?, ?, ?, ?)
|
|
22
|
+
`);
|
|
23
|
+
for (const m of media) {
|
|
24
|
+
const assetFileName = fileNameByAssetId.get(m.assetId) ?? '';
|
|
25
|
+
stmt.run(m.id, m.name, m.assetId, assetFileName, m.updatedAt);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function rebuildIndexFromPayload(space, options) {
|
|
29
|
+
const preview = resolveIndexPreview(options.preview);
|
|
30
|
+
ensureIndexDirectory(space, preview);
|
|
31
|
+
const dbPath = getIndexDbPath(space, preview);
|
|
32
|
+
const db = openIndexDatabase(dbPath);
|
|
33
|
+
clearTables(db);
|
|
34
|
+
const fileNameByAssetId = new Map();
|
|
35
|
+
for (const a of options.payload.assets) {
|
|
36
|
+
fileNameByAssetId.set(a.id, a.fileName);
|
|
37
|
+
}
|
|
38
|
+
insertAssets(db, options.payload.assets);
|
|
39
|
+
insertMedia(db, options.payload.media, fileNameByAssetId);
|
|
40
|
+
const syncedAt = new Date().toISOString();
|
|
41
|
+
setMeta(db, 'syncedAt', syncedAt);
|
|
42
|
+
setMeta(db, 'assetCount', String(options.payload.assets.length));
|
|
43
|
+
setMeta(db, 'mediaCount', String(options.payload.media.length));
|
|
44
|
+
setMeta(db, 'cdaTokenHash', hashDeliveryToken(options.accessToken));
|
|
45
|
+
setMeta(db, 'schemaVersion', String(SCHEMA_VERSION));
|
|
46
|
+
setMeta(db, 'preview', preview ? '1' : '0');
|
|
47
|
+
if (options.apiKeyId) {
|
|
48
|
+
setMeta(db, 'apiKeyId', options.apiKeyId);
|
|
49
|
+
}
|
|
50
|
+
db.close();
|
|
51
|
+
return {
|
|
52
|
+
dbPath,
|
|
53
|
+
assetCount: options.payload.assets.length,
|
|
54
|
+
mediaCount: options.payload.media.length,
|
|
55
|
+
syncedAt,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Upsert a single asset row after CMA upload (optional dedup freshness). */
|
|
59
|
+
export function upsertAssetRow(space, asset, preview = DEFAULT_INDEX_PREVIEW) {
|
|
60
|
+
const dbPath = getIndexDbPath(space, preview);
|
|
61
|
+
const db = openIndexDatabase(dbPath);
|
|
62
|
+
db.prepare(`
|
|
63
|
+
INSERT INTO assets (id, fileName, title, description, contentType, url, width, height, size, updatedAt)
|
|
64
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
65
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
66
|
+
fileName = excluded.fileName,
|
|
67
|
+
title = excluded.title,
|
|
68
|
+
description = excluded.description,
|
|
69
|
+
contentType = excluded.contentType,
|
|
70
|
+
url = excluded.url,
|
|
71
|
+
width = excluded.width,
|
|
72
|
+
height = excluded.height,
|
|
73
|
+
size = excluded.size,
|
|
74
|
+
updatedAt = excluded.updatedAt
|
|
75
|
+
`).run(asset.id, asset.fileName, asset.title, asset.description, asset.contentType, asset.url, asset.width, asset.height, asset.size, asset.updatedAt);
|
|
76
|
+
db.close();
|
|
77
|
+
}
|
|
78
|
+
export function readIndexStatus(space, preview) {
|
|
79
|
+
const usePreview = resolveIndexPreview(preview);
|
|
80
|
+
const dbPath = getIndexDbPath(space, usePreview);
|
|
81
|
+
if (!indexExists(space, usePreview)) {
|
|
82
|
+
return {
|
|
83
|
+
exists: false,
|
|
84
|
+
dbPath,
|
|
85
|
+
syncedAt: null,
|
|
86
|
+
assetCount: null,
|
|
87
|
+
mediaCount: null,
|
|
88
|
+
apiKeyId: null,
|
|
89
|
+
stale: true,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const db = openIndexDatabase(dbPath);
|
|
93
|
+
const syncedAt = getMeta(db, 'syncedAt');
|
|
94
|
+
const assetCount = Number.parseInt(getMeta(db, 'assetCount') ?? '0', 10);
|
|
95
|
+
const mediaCount = Number.parseInt(getMeta(db, 'mediaCount') ?? '0', 10);
|
|
96
|
+
const apiKeyId = getMeta(db, 'apiKeyId');
|
|
97
|
+
db.close();
|
|
98
|
+
const stale = syncedAt ? isSyncedAtStale(syncedAt) : true;
|
|
99
|
+
return {
|
|
100
|
+
exists: true,
|
|
101
|
+
dbPath,
|
|
102
|
+
syncedAt,
|
|
103
|
+
assetCount,
|
|
104
|
+
mediaCount,
|
|
105
|
+
apiKeyId,
|
|
106
|
+
stale,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export const INDEX_STALE_MS = 24 * 60 * 60 * 1000;
|
|
110
|
+
export function isSyncedAtStale(syncedAt, now = Date.now()) {
|
|
111
|
+
const t = Date.parse(syncedAt);
|
|
112
|
+
if (Number.isNaN(t))
|
|
113
|
+
return true;
|
|
114
|
+
return now - t > INDEX_STALE_MS;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/index/sync.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,OAAO,EAA2B,iBAAiB,E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G,GAAG,CAAC,GAAG,cAAc,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noConsole: Console output is intentional in CLI */
|
|
2
|
+
export declare function terminalWidth(defaultWidth?: number): number;
|
|
3
|
+
export declare function truncateText(text: string, max: number): string;
|
|
4
|
+
export declare function printBanner(title: string): void;
|
|
5
|
+
export declare function printSection(label: string): void;
|
|
6
|
+
export declare function printKeyValue(key: string, value: string, keyWidth?: number): void;
|
|
7
|
+
export interface TableColumn {
|
|
8
|
+
header: string;
|
|
9
|
+
width: number;
|
|
10
|
+
align?: 'left' | 'right';
|
|
11
|
+
color?: (value: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare function printTable(columns: TableColumn[], rows: string[][]): void;
|
|
14
|
+
export declare function formatRange(start: number, end: number, total: number): string;
|
|
15
|
+
//# sourceMappingURL=terminal-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-table.d.ts","sourceRoot":"","sources":["../../src/output/terminal-table.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAIvF,wBAAgB,aAAa,CAAC,YAAY,SAAM,GAAG,MAAM,CAMxD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK9D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAK/C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAQhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,IAAI,CAE7E;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,CAkBzE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG7E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noConsole: Console output is intentional in CLI */
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
export function terminalWidth(defaultWidth = 100) {
|
|
4
|
+
const cols = process.stdout.columns;
|
|
5
|
+
if (typeof cols === 'number' && cols >= 40) {
|
|
6
|
+
return Math.min(cols, 120);
|
|
7
|
+
}
|
|
8
|
+
return defaultWidth;
|
|
9
|
+
}
|
|
10
|
+
export function truncateText(text, max) {
|
|
11
|
+
if (max <= 0)
|
|
12
|
+
return '';
|
|
13
|
+
if (text.length <= max)
|
|
14
|
+
return text;
|
|
15
|
+
if (max === 1)
|
|
16
|
+
return '…';
|
|
17
|
+
return `${text.slice(0, max - 1)}…`;
|
|
18
|
+
}
|
|
19
|
+
export function printBanner(title) {
|
|
20
|
+
const width = terminalWidth();
|
|
21
|
+
console.log('');
|
|
22
|
+
console.log(pc.bold(` ${title}`));
|
|
23
|
+
console.log(pc.dim(` ${'═'.repeat(Math.max(8, width - 2))}`));
|
|
24
|
+
}
|
|
25
|
+
export function printSection(label) {
|
|
26
|
+
const width = terminalWidth();
|
|
27
|
+
const padded = ` ${label} `;
|
|
28
|
+
const lineLen = Math.max(0, width - padded.length);
|
|
29
|
+
const left = Math.floor(lineLen / 2);
|
|
30
|
+
const right = lineLen - left;
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log(pc.dim(` ${'─'.repeat(left)}${padded}${'─'.repeat(right)}`));
|
|
33
|
+
}
|
|
34
|
+
export function printKeyValue(key, value, keyWidth = 12) {
|
|
35
|
+
console.log(` ${pc.dim(key.padEnd(keyWidth))} ${value}`);
|
|
36
|
+
}
|
|
37
|
+
export function printTable(columns, rows) {
|
|
38
|
+
const header = columns
|
|
39
|
+
.map((c) => pc.bold(truncateText(c.header, c.width).padEnd(c.width)))
|
|
40
|
+
.join(' ');
|
|
41
|
+
console.log(` ${header}`);
|
|
42
|
+
console.log(` ${columns.map((c) => pc.dim('─'.repeat(c.width))).join(' ')}`);
|
|
43
|
+
for (const row of rows) {
|
|
44
|
+
const line = columns
|
|
45
|
+
.map((c, i) => {
|
|
46
|
+
const raw = row[i] ?? '';
|
|
47
|
+
const text = truncateText(raw, c.width);
|
|
48
|
+
const padded = c.align === 'right' ? text.padStart(c.width) : text.padEnd(c.width);
|
|
49
|
+
return c.color ? c.color(padded) : padded;
|
|
50
|
+
})
|
|
51
|
+
.join(' ');
|
|
52
|
+
console.log(` ${line}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function formatRange(start, end, total) {
|
|
56
|
+
if (total === 0)
|
|
57
|
+
return '0 rows';
|
|
58
|
+
return `${String(start)}–${String(end)} of ${String(total)}`;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=terminal-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-table.js","sourceRoot":"","sources":["../../src/output/terminal-table.ts"],"names":[],"mappings":"AAAA,uFAAuF;AAEvF,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,UAAU,aAAa,CAAC,YAAY,GAAG,GAAG;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;QAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM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,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACnF,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5C,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,GAAW,EAAE,KAAa;IACnE,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACjC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC/D,CAAC"}
|
package/docs/FUNCTIONAL_SPEC.md
CHANGED
|
@@ -99,8 +99,14 @@ Each resolved entry is assigned a stable `@ref` label (`@c0` = the root, `@c1`,
|
|
|
99
99
|
| `read <id> --id [field]` | Print entry fields by ID without an open session |
|
|
100
100
|
| `search <query>` | Full-text search across entries; returns matching entries |
|
|
101
101
|
| `list --type <type>` | List all entries of a given content type |
|
|
102
|
+
| `index sync` | Rebuild local SQLite media index from Content Preview API (draft; default). Use `--published` for Delivery API only |
|
|
103
|
+
| `index status` | Show index path, sync time, and row counts |
|
|
104
|
+
| `index dump` | Pretty-print index contents (assets, media, type breakdown) for terminal inspection |
|
|
105
|
+
| `list --type media --asset-id <id>` | List Media entries linked to an asset (index) |
|
|
106
|
+
| `list --type media --asset-filename <name>` | List Media entries by exact asset fileName (index) |
|
|
102
107
|
| `sitemap` | List all pages with their slugs and publish status |
|
|
103
108
|
| `resolve <id>` | Resolve an entry or asset ID to its details |
|
|
109
|
+
| `resolve --type <type> --slug <slug>` | Resolve an entry by content type and slug (no session). Types: page, article, articleType, tagType, tag |
|
|
104
110
|
|
|
105
111
|
### 7.2 Session Management
|
|
106
112
|
|
|
@@ -139,6 +145,11 @@ Each resolved entry is assigned a stable `@ref` label (`@c0` = the root, `@c1`,
|
|
|
139
145
|
| `create template --label "X"` | Create a new template entry |
|
|
140
146
|
| `create media --asset-id <id> --name "X"` | Create a Media wrapper entry around an existing asset |
|
|
141
147
|
| `create from-json --file <path>` | Bulk-create a page or article with all its components from a declarative JSON file |
|
|
148
|
+
| `create taxonomy-from-json --file <path>` | Batch-create tagType, articleType, and tag entries from JSON |
|
|
149
|
+
| `create tag-type --slug <slug> --name "X"` | Create a tagType entry (draft) |
|
|
150
|
+
| `create article-type --slug <slug> --name "X"` | Create an articleType entry (draft) |
|
|
151
|
+
| `create tag --slug <slug> --name "X" --tag-type <slug>` | Create a tag entry (draft) |
|
|
152
|
+
| `ensure tag-type\|tag\|article-type …` | Idempotent taxonomy create (returns existing entry when slug matches) |
|
|
142
153
|
| `add <entry-type> --content-type <ct>` | Create a new child entry of a given content type, link it into the current open entry's content array, and assign it a @ref |
|
|
143
154
|
|
|
144
155
|
### 7.5 Entry Removal and Reordering
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# Media & asset search — local index plan
|
|
2
|
+
|
|
3
|
+
## Implementation status (2026-06)
|
|
4
|
+
|
|
5
|
+
**Implemented** in `@se-studio/contentful-cms`:
|
|
6
|
+
|
|
7
|
+
- `cms-edit index sync` / `index status` (Preview API draft default + `--published`)
|
|
8
|
+
- SQLite index at `~/.contentful-cms/index/<spaceId>/<environment>/media.db` via `node:sqlite`
|
|
9
|
+
- Delivery token resolution: `deliveryAccessToken` → `deliveryApiKeyName` → environment match → optional `autoCreateDeliveryApiKey`
|
|
10
|
+
- **Index required** (no CMA fallback) for: `asset search`, `asset audit`, `list --type media` with `--asset-id` / `--asset-filename*`, upload `--if-exists-by-filename`
|
|
11
|
+
- Bulk CMA asset pagination and N+1 `links_to_asset` scans removed from those paths
|
|
12
|
+
|
|
13
|
+
Help: [help/index-sync.md](./help/index-sync.md).
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Problem
|
|
18
|
+
|
|
19
|
+
Today, cms-edit discovers assets and Media entries via the **Contentful Management API (CMA)**:
|
|
20
|
+
|
|
21
|
+
| Operation | CMA approach | Pain |
|
|
22
|
+
|-----------|--------------|------|
|
|
23
|
+
| Exact `fileName` | `fields.file.fileName` filter | Fast |
|
|
24
|
+
| Regex `fileName` | Paginate assets (+ optional `[match]` prefix), filter client-side | Slow on large spaces |
|
|
25
|
+
| `list --type media --asset-filename*` | Find assets, then **N×** `links_to_asset` queries for Media | Very slow at scale |
|
|
26
|
+
| Title search | `fields.title[match]` | OK for small result sets |
|
|
27
|
+
|
|
28
|
+
CMA is rate-limited, optimized for writes, and regex scans can mean thousands of round trips. Publication-import and deduplication workflows need **fast repeated lookups** by `fileName`, title, MIME type, and “which Media wraps this asset?”.
|
|
29
|
+
|
|
30
|
+
## Goal
|
|
31
|
+
|
|
32
|
+
A **local, per-space index** built from the **Content Delivery API (CDA)** (read-only, cache-friendly) that powers:
|
|
33
|
+
|
|
34
|
+
- Sub-second filename / regex / title search over all assets
|
|
35
|
+
- Reverse lookup: asset ID → Media entry IDs
|
|
36
|
+
- Optional freshness via incremental sync or scheduled rebuild
|
|
37
|
+
|
|
38
|
+
CMA remains the source of truth for **creates/updates** (`asset upload`, `create media`, taxonomy).
|
|
39
|
+
|
|
40
|
+
## Non-goals (v1)
|
|
41
|
+
|
|
42
|
+
- Full-text search across entry bodies
|
|
43
|
+
- Replacing CMA for asset upload or processing
|
|
44
|
+
- Cross-space search
|
|
45
|
+
- Publishing or preview-mode mixing in one index (pick one: published CDA or preview CPA — see below)
|
|
46
|
+
|
|
47
|
+
## Proposed architecture
|
|
48
|
+
|
|
49
|
+
```mermaid
|
|
50
|
+
flowchart LR
|
|
51
|
+
subgraph sync [Index sync]
|
|
52
|
+
CMA_keys[CMA API keys]
|
|
53
|
+
CDA[Contentful CDA]
|
|
54
|
+
SyncCmd["cms-edit index sync"]
|
|
55
|
+
Store[(Local index)]
|
|
56
|
+
CMA_keys -->|"resolve accessToken"| SyncCmd
|
|
57
|
+
SyncCmd --> CDA
|
|
58
|
+
CDA --> Store
|
|
59
|
+
end
|
|
60
|
+
subgraph query [Search]
|
|
61
|
+
CLI[cms-edit asset search]
|
|
62
|
+
List[cms-edit list --type media]
|
|
63
|
+
CLI --> Store
|
|
64
|
+
List --> Store
|
|
65
|
+
end
|
|
66
|
+
subgraph write [Writes unchanged]
|
|
67
|
+
CMA[Contentful CMA]
|
|
68
|
+
Upload[asset upload]
|
|
69
|
+
Upload --> CMA
|
|
70
|
+
end
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Index store
|
|
74
|
+
|
|
75
|
+
**Location:** `~/.contentful-cms/index/<spaceId>/<environment>/` (or project-local `.contentful-cms/index/` when `--config` is set).
|
|
76
|
+
|
|
77
|
+
**Format (v1):** SQLite via `better-sqlite3` or embedded JSONL + in-memory Map for zero native deps. Prefer **SQLite** for regex scans and stable pagination on 10k+ assets.
|
|
78
|
+
|
|
79
|
+
**Tables (conceptual):**
|
|
80
|
+
|
|
81
|
+
| Table | Key fields | Purpose |
|
|
82
|
+
|-------|------------|---------|
|
|
83
|
+
| `assets` | `id`, `fileName`, `title`, `description`, `contentType`, `url`, `width`, `height`, `size`, `updatedAt` | Asset search |
|
|
84
|
+
| `media` | `id`, `name`, `assetId`, `updatedAt` | Media wrapper lookup |
|
|
85
|
+
| `meta` | `syncedAt`, `assetCount`, `mediaCount`, `cdaTokenHash` | Freshness |
|
|
86
|
+
|
|
87
|
+
Indexes: `assets.fileName`, `assets.title`; `media.assetId`.
|
|
88
|
+
|
|
89
|
+
### Sync command
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Full rebuild (paginate CDA assets + media entries)
|
|
93
|
+
cms-edit index sync
|
|
94
|
+
|
|
95
|
+
# Incremental (if sync token / updatedSince supported)
|
|
96
|
+
cms-edit index sync --since <iso>
|
|
97
|
+
|
|
98
|
+
# Status
|
|
99
|
+
cms-edit index status
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**CDA pagination:** Use `contentful` JS SDK or fetch `https://cdn.contentful.com/.../assets` and `.../entries?content_type=media` with `limit=1000`, following `skip` until complete.
|
|
103
|
+
|
|
104
|
+
**Preview vs published:** Default index = **Preview API** (draft content, matches CMA uploads). Optional `--published` uses Delivery API for published assets only (separate DB file suffix `-published`).
|
|
105
|
+
|
|
106
|
+
### Delivery token resolution (CMA → CDA)
|
|
107
|
+
|
|
108
|
+
The **management token is not a delivery token** — it cannot call `cdn.contentful.com`. For index sync we only need a **read-only** CDA (or CPA) access token. That token can be obtained without asking operators to copy a second secret, by using the **same CMA client** cms-edit already uses.
|
|
109
|
+
|
|
110
|
+
Contentful exposes delivery keys on the space via the [Management API — API keys](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/api-keys): list/create delivery keys; each key includes an `accessToken` for CDA. Creating a delivery key also creates a linked preview key (resolve separately for `--preview` sync).
|
|
111
|
+
|
|
112
|
+
**Resolution order** (first match wins):
|
|
113
|
+
|
|
114
|
+
| Priority | Source | Notes |
|
|
115
|
+
|----------|--------|--------|
|
|
116
|
+
| 1 | Explicit override | Space config `deliveryAccessToken` or `${CONTENTFUL_ACCESS_TOKEN}` / `${CONTENTFUL_DELIVERY_TOKEN}` — same vars as marketing apps |
|
|
117
|
+
| 2 | Named key via CMA | `deliveryApiKeyName` in `.contentful-cms.json` → `space.getApiKeys()` → match `name` |
|
|
118
|
+
| 3 | Environment match via CMA | Pick first delivery key whose `environments` includes the configured `environment` (default `master`) |
|
|
119
|
+
| 4 | Auto-create (optional) | If PAT has API-key manage rights and no key matches: create `cms-edit-index` delivery key scoped to that environment |
|
|
120
|
+
|
|
121
|
+
Implement as `resolveDeliveryAccessToken(space, { preview?: boolean })` in `src/contentful/delivery-token.ts` (or similar), called at the start of `index sync` only — not on every search (cache resolved token in `meta` as a hash + key id, not the raw token).
|
|
122
|
+
|
|
123
|
+
**SDK sketch (contentful-management, already a dependency):**
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
const client = createClient({ accessToken: space.managementToken }, { type: 'plain' });
|
|
127
|
+
const spaceApi = await client.getSpace(space.spaceId);
|
|
128
|
+
const { items: keys } = await spaceApi.getApiKeys();
|
|
129
|
+
const key = pickDeliveryKey(keys, { name: space.deliveryApiKeyName, environment: space.environment });
|
|
130
|
+
const deliveryToken = key.accessToken; // CDA
|
|
131
|
+
// preview: await spaceApi.getPreviewApiKey(key.preview_api_key.sys.id) → accessToken
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**What does not work:**
|
|
135
|
+
|
|
136
|
+
- Passing `managementToken` directly to the CDA client.
|
|
137
|
+
- Assuming any single PAT can read API keys (editor-only tokens may lack `ContentDelivery` / key read rights — fail with a clear error and point to explicit `deliveryAccessToken`).
|
|
138
|
+
|
|
139
|
+
**Caveats:**
|
|
140
|
+
|
|
141
|
+
| Topic | Guidance |
|
|
142
|
+
|-------|----------|
|
|
143
|
+
| Permissions | PAT needs rights to read (and optionally create) space API keys; document in setup wizard |
|
|
144
|
+
| Multiple keys | Never “first key in list” without environment/name filter |
|
|
145
|
+
| Propagation | New keys may 401 for a few seconds after create — retry with backoff |
|
|
146
|
+
| Secrets | Do not log `accessToken`; store only `cdaTokenHash` + `apiKeyId` in index `meta` |
|
|
147
|
+
| Preview index | Resolve linked preview key when `index sync --preview` |
|
|
148
|
+
|
|
149
|
+
**Config additions** (`.contentful-cms.json` per space, all optional):
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"deliveryAccessToken": "${CONTENTFUL_ACCESS_TOKEN}",
|
|
154
|
+
"deliveryApiKeyName": "Production",
|
|
155
|
+
"autoCreateDeliveryApiKey": false
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
If only `managementToken` is configured, `index sync` should still work when CMA can list a suitable delivery key — aligning with agent setups that already have cms-edit credentials.
|
|
160
|
+
|
|
161
|
+
### Query integration (implemented)
|
|
162
|
+
|
|
163
|
+
1. **`asset search`** — Requires index; queries SQLite (title `LIKE`, filename exact/regex, MIME filter).
|
|
164
|
+
2. **`list --type media --asset-filename*`** — Single index query (assets + joined media rows); no CMA.
|
|
165
|
+
3. **`--if-exists-by-filename`** — Index exact `fileName` lookup; optional post-upload row upsert.
|
|
166
|
+
|
|
167
|
+
Stale index: warn when `syncedAt` > 24h; no `--no-index` CMA fallback.
|
|
168
|
+
|
|
169
|
+
### Freshness
|
|
170
|
+
|
|
171
|
+
| Strategy | When |
|
|
172
|
+
|----------|------|
|
|
173
|
+
| Manual `index sync` | Before large import jobs |
|
|
174
|
+
| `index sync` in CI nightly | Keeps agents fast |
|
|
175
|
+
| Post-upload hook (optional) | After `asset upload`, upsert one row into index |
|
|
176
|
+
|
|
177
|
+
Webhook-driven incremental sync is out of scope for v1 but fits the same schema.
|
|
178
|
+
|
|
179
|
+
## Implementation phases
|
|
180
|
+
|
|
181
|
+
### Phase 1 — Foundation (MVP)
|
|
182
|
+
|
|
183
|
+
- [x] Add `contentful` delivery client dependency
|
|
184
|
+
- [x] `resolveDeliveryAccessToken()` — explicit config, then CMA `getApiKeys()` (+ optional `createApiKey`)
|
|
185
|
+
- [x] Config fields: `deliveryAccessToken`, `deliveryApiKeyName`, `autoCreateDeliveryApiKey`
|
|
186
|
+
- [x] `cms-edit index sync` full rebuild → SQLite (CDA pagination after token resolve)
|
|
187
|
+
- [x] `cms-edit index status`
|
|
188
|
+
- [x] Unit tests: delivery token, index queries
|
|
189
|
+
|
|
190
|
+
### Phase 2 — Wire search
|
|
191
|
+
|
|
192
|
+
- [x] `asset search --filename` / `--filename-match` uses index (required)
|
|
193
|
+
- [x] `findAssetByExactFilename` replaced by index lookup
|
|
194
|
+
- [x] README / help document index requirement
|
|
195
|
+
|
|
196
|
+
### Phase 3 — Media discovery
|
|
197
|
+
|
|
198
|
+
- [x] Index `media` entries with `assetId` and denormalized `assetFileName`
|
|
199
|
+
- [x] `list --type media --asset-id` / `--asset-filename*` without N+1 CMA
|
|
200
|
+
- [x] JSON output for indexed media list
|
|
201
|
+
|
|
202
|
+
### Phase 4 — Operator UX
|
|
203
|
+
|
|
204
|
+
- [x] Stale index warning + suggested `index sync`
|
|
205
|
+
- [ ] Optional `index sync` before bulk upload scripts (skill note — partial)
|
|
206
|
+
- [ ] MCP tool exposure if hosted MCP should search assets
|
|
207
|
+
|
|
208
|
+
## Dependencies & package boundaries
|
|
209
|
+
|
|
210
|
+
- Keep index code inside `packages/contentful-cms` (CLI owns agent workflows).
|
|
211
|
+
- **Do not** pull `@se-studio/contentful-rest-api` into cms-edit unless we need shared cache tags; a thin CDA client keeps the CLI package self-contained.
|
|
212
|
+
- SQLite: evaluate `node:sqlite` (Node 22+) vs `better-sqlite3` for install size in npx usage.
|
|
213
|
+
|
|
214
|
+
## Risks
|
|
215
|
+
|
|
216
|
+
| Risk | Mitigation |
|
|
217
|
+
|------|------------|
|
|
218
|
+
| Index stale vs CMA | Show `syncedAt` in search output; exact match confirm via CMA before skip-upload |
|
|
219
|
+
| Draft assets missing from CDA | Default index uses Preview API; use `--published` only when you need published-only discovery |
|
|
220
|
+
| Disk size | 10k assets ≈ few MB in SQLite |
|
|
221
|
+
| Token sprawl | Prefer CMA-resolve when only `managementToken` is set; optional explicit `deliveryAccessToken` for CI |
|
|
222
|
+
| CMA cannot read API keys | Clear error; require `deliveryAccessToken` in config |
|
|
223
|
+
| Leaked delivery token in logs | Never log; `meta.cdaTokenHash` only |
|
|
224
|
+
| New API key 401 | Retry CDA requests after create (Contentful propagation delay) |
|
|
225
|
+
|
|
226
|
+
## Success criteria
|
|
227
|
+
|
|
228
|
+
- Regex search over 5k assets completes in **< 2s** locally after sync
|
|
229
|
+
- `list --type media --asset-filename-match` does **not** scale with asset count via N+1 CMA calls
|
|
230
|
+
- No change to write paths; tests cover index-off fallback
|
|
231
|
+
|
|
232
|
+
## References
|
|
233
|
+
|
|
234
|
+
- Current CMA helpers: `src/contentful/assets.ts`, `src/contentful/media.ts`
|
|
235
|
+
- CMA client: `src/contentful/client.ts` (`managementToken` per space)
|
|
236
|
+
- Contentful: [API keys (CMA)](https://www.contentful.com/developers/docs/references/content-management-api/#/reference/api-keys), [Authentication](https://www.contentful.com/developers/docs/references/authentication/)
|
|
237
|
+
- App delivery env vars (override): `CONTENTFUL_ACCESS_TOKEN`, `CONTENTFUL_PREVIEW_ACCESS_TOKEN` in `contentful-rest-api`
|
|
238
|
+
- Issue context: #42 publication import (GITHUB_ISSUES_IMPLEMENTATION_STATUS.md)
|