@tenonhq/dovetail-core 0.0.131 → 0.0.132
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/dist/FileUtils.js +7 -0
- package/dist/MultiScopeWatcher.js +7 -5
- package/dist/config.js +17 -4
- package/dist/deleteRecordCommand.js +5 -2
- package/dist/fingerprint.js +169 -0
- package/dist/reconcileCommand.js +9 -0
- package/dist/snClient.js +26 -3
- package/dist/tests/deleteRecordLocalCleanup.test.js +95 -0
- package/dist/tests/fileContextSkipReason.test.js +19 -0
- package/dist/tests/fingerprint.test.js +144 -0
- package/dist/tests/reconcileFingerprintCreate.test.js +79 -0
- package/dist/tests/resolveScopeFromPath.test.js +83 -0
- package/dist/tests/snClient.fingerprint.test.js +83 -0
- package/package.json +3 -3
- package/release-manifest.json +284 -202
package/dist/FileUtils.js
CHANGED
|
@@ -44,6 +44,7 @@ const fs_1 = __importStar(require("fs"));
|
|
|
44
44
|
const path_1 = __importDefault(require("path"));
|
|
45
45
|
const ConfigManager = __importStar(require("./config"));
|
|
46
46
|
const FileLogger_1 = require("./FileLogger");
|
|
47
|
+
const fingerprint_1 = require("./fingerprint");
|
|
47
48
|
const SNFileExists = (parentDirPath) => async (file) => {
|
|
48
49
|
try {
|
|
49
50
|
const files = await fs_1.promises.readdir(parentDirPath);
|
|
@@ -204,6 +205,12 @@ const getTargetFieldFromPath = (filePath, table, ext) => {
|
|
|
204
205
|
: path_1.default.basename(filePath, ext);
|
|
205
206
|
};
|
|
206
207
|
const getFileContextWithSkipReason = (filePath) => {
|
|
208
|
+
// A `.sha256` file holds a digest, not the field's content (fingerprint.ts).
|
|
209
|
+
// Refuse it before any manifest lookup, so push and build can never send a
|
|
210
|
+
// digest over the real value.
|
|
211
|
+
if ((0, fingerprint_1.isFingerprintFilePath)(filePath)) {
|
|
212
|
+
return { skipReason: "fingerprint only, read-only" };
|
|
213
|
+
}
|
|
207
214
|
const ext = getFileExtension(filePath);
|
|
208
215
|
const [tableName, recordName] = path_1.default
|
|
209
216
|
.dirname(filePath)
|
|
@@ -458,7 +458,7 @@ class MultiScopeWatcherManager {
|
|
|
458
458
|
// Ensure an update set exists for this scope
|
|
459
459
|
await this.ensureUpdateSetForScope(scopeWatcher.scope);
|
|
460
460
|
// Load the manifest for this specific scope
|
|
461
|
-
await this.loadScopeManifest(scopeWatcher.scope
|
|
461
|
+
await this.loadScopeManifest(scopeWatcher.scope);
|
|
462
462
|
// Process the files — track skip reasons for summary
|
|
463
463
|
const fileContexts = [];
|
|
464
464
|
const skippedFiles = [];
|
|
@@ -509,11 +509,13 @@ class MultiScopeWatcherManager {
|
|
|
509
509
|
Logger_1.logger.error(`[${scopeWatcher.scope}] Error processing queue: ${error}`);
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
|
-
async loadScopeManifest(scopeName
|
|
512
|
+
async loadScopeManifest(scopeName) {
|
|
513
513
|
try {
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
|
|
514
|
+
// Manifests live at the project root (next to dove.config.js). Derive it
|
|
515
|
+
// from the config, not from sourceDirectory: going "up two levels" only
|
|
516
|
+
// holds for src/<scope> and lands in src/ for a nested folder such as
|
|
517
|
+
// src/UIComponents/<scope>.
|
|
518
|
+
const projectRoot = ConfigManager.getRootDir();
|
|
517
519
|
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
518
520
|
// First try to load scope-specific manifest file (prefer dove.*, fall back to sinc.*).
|
|
519
521
|
const doveScopeManifestPath = path.join(projectRoot, `dove.manifest.${scopeName}.json`);
|
package/dist/config.js
CHANGED
|
@@ -496,18 +496,31 @@ function resolveManifestForScope(man, scope) {
|
|
|
496
496
|
}
|
|
497
497
|
return undefined;
|
|
498
498
|
}
|
|
499
|
+
// A path sits under a scope's folder only at a separator boundary. A plain
|
|
500
|
+
// string prefix lets "src/UIComponents/x_cadso_ui_form" claim a file in a
|
|
501
|
+
// sibling "src/UIComponents/x_cadso_ui_form_x/". When folders nest
|
|
502
|
+
// ("src/UIComponents" as a scope and "src/UIComponents/x_..." as another), the
|
|
503
|
+
// deepest match wins, whatever order the scopes are declared in.
|
|
499
504
|
function resolveScopeFromPath(filePath) {
|
|
505
|
+
if (typeof filePath !== "string" || filePath === "")
|
|
506
|
+
return undefined;
|
|
500
507
|
var cfg = getConfig();
|
|
501
508
|
if (!cfg.scopes)
|
|
502
509
|
return undefined;
|
|
510
|
+
var resolvedFile = path_1.default.resolve(filePath);
|
|
503
511
|
var scopeNames = Object.keys(cfg.scopes);
|
|
512
|
+
var best = undefined;
|
|
513
|
+
var bestLength = -1;
|
|
504
514
|
for (var i = 0; i < scopeNames.length; i++) {
|
|
505
|
-
var scopeSourcePath = getSourcePathForScope(scopeNames[i]);
|
|
506
|
-
|
|
507
|
-
|
|
515
|
+
var scopeSourcePath = path_1.default.resolve(getSourcePathForScope(scopeNames[i]));
|
|
516
|
+
var isUnder = resolvedFile === scopeSourcePath ||
|
|
517
|
+
resolvedFile.indexOf(scopeSourcePath + path_1.default.sep) === 0;
|
|
518
|
+
if (isUnder && scopeSourcePath.length > bestLength) {
|
|
519
|
+
best = scopeNames[i];
|
|
520
|
+
bestLength = scopeSourcePath.length;
|
|
508
521
|
}
|
|
509
522
|
}
|
|
510
|
-
return
|
|
523
|
+
return best;
|
|
511
524
|
}
|
|
512
525
|
// Exported for tests only.
|
|
513
526
|
async function loadConfigPath(pth) {
|
|
@@ -226,8 +226,11 @@ async function deleteRecordCommand(args) {
|
|
|
226
226
|
if (!typedArgs.keepLocal) {
|
|
227
227
|
Logger_1.logger.info("Cleaning up local files...");
|
|
228
228
|
try {
|
|
229
|
-
// Remove local record directory
|
|
230
|
-
|
|
229
|
+
// Remove local record directory. The scope's own folder, not the
|
|
230
|
+
// top-level sourceDirectory: records live at <scope dir>/<table>/<name>
|
|
231
|
+
// (src/Core/..., src/UIComponents/<scope>/...), so joining the top-level
|
|
232
|
+
// path never found them and the cleanup was a silent no-op.
|
|
233
|
+
var sourcePath = ConfigManager.getSourcePathForScope(scope);
|
|
231
234
|
var recordDir = path_1.default.join(sourcePath, table, name || recordName);
|
|
232
235
|
if (fs_1.default.existsSync(recordDir)) {
|
|
233
236
|
fs_1.default.rmSync(recordDir, { recursive: true, force: true });
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Fingerprint mode: mirror a field as a SHA-256 digest instead of its content.
|
|
3
|
+
//
|
|
4
|
+
// Built for compiled UI component bundles (sys_ux_lib_source_script.script):
|
|
5
|
+
// minified JS, often several MB, that no reviewer reads line by line. What a
|
|
6
|
+
// mirror needs from it is "is the bundle on this instance the same as on that
|
|
7
|
+
// one", and a digest answers that without MB-sized diffs.
|
|
8
|
+
//
|
|
9
|
+
// Configured per table in dove.config.js:
|
|
10
|
+
//
|
|
11
|
+
// tableOptions: { sys_ux_lib_source_script: { fingerprint: ["script"] } }
|
|
12
|
+
//
|
|
13
|
+
// Applied to every getManifest and bulkDownload response in snClient, so each
|
|
14
|
+
// writer (download, refresh, missing-file fill, single-record pull) and every
|
|
15
|
+
// manifest consumer sees the same thing without knowing about it:
|
|
16
|
+
// - the manifest lists the field as `<field>.sha256`, so the missing-file
|
|
17
|
+
// check finds it on disk and the next refresh does not re-download it;
|
|
18
|
+
// - the field file's content becomes "sha256:<hex>\nbytes:<n>\n";
|
|
19
|
+
// - the field's value in metaData.json becomes "sha256:<hex>".
|
|
20
|
+
// Push refuses a `.sha256` file (FileUtils.getFileContextWithSkipReason), so a
|
|
21
|
+
// digest can never be written back over a bundle.
|
|
22
|
+
//
|
|
23
|
+
// Client-side only: `fingerprint` is stripped from tableOptions before they are
|
|
24
|
+
// sent to the instance. The server echoes the requested file type back, so a
|
|
25
|
+
// bulkDownload asked for `script` as type "sha256" still returns the raw
|
|
26
|
+
// content, which is hashed here.
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.isFingerprintFilePath = exports.applyFingerprints = exports.stripClientOnlyTableOptions = exports.fingerprintFieldsFor = exports.isFingerprintContent = exports.formatFingerprint = exports.FINGERPRINT_FILE_TYPE = void 0;
|
|
32
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
33
|
+
exports.FINGERPRINT_FILE_TYPE = "sha256";
|
|
34
|
+
const DIGEST_PREFIX = "sha256:";
|
|
35
|
+
const FINGERPRINT_CONTENT_RE = /^sha256:[0-9a-f]{64}\nbytes:\d+\n$/;
|
|
36
|
+
const METADATA_DIGEST_RE = /^sha256:[0-9a-f]{64}$/;
|
|
37
|
+
const isPlainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
38
|
+
const digestOf = (content) => DIGEST_PREFIX + crypto_1.default.createHash("sha256").update(content, "utf8").digest("hex");
|
|
39
|
+
// The on-disk content of a fingerprint file. The byte length rides along so a
|
|
40
|
+
// diff between two instances reads as "bundle grew by N bytes", not just "changed".
|
|
41
|
+
const formatFingerprint = (content) => digestOf(content) + "\nbytes:" + Buffer.byteLength(content, "utf8") + "\n";
|
|
42
|
+
exports.formatFingerprint = formatFingerprint;
|
|
43
|
+
const isFingerprintContent = (content) => typeof content === "string" && FINGERPRINT_CONTENT_RE.test(content);
|
|
44
|
+
exports.isFingerprintContent = isFingerprintContent;
|
|
45
|
+
// Fields configured for fingerprinting on one table. Anything malformed in the
|
|
46
|
+
// config (not an array, non-string or empty entries) is dropped rather than
|
|
47
|
+
// trusted, so a typo fingerprints nothing instead of throwing mid-refresh.
|
|
48
|
+
const fingerprintFieldsFor = (tableOptions, tableName) => {
|
|
49
|
+
if (!isPlainObject(tableOptions))
|
|
50
|
+
return [];
|
|
51
|
+
const opts = tableOptions[tableName];
|
|
52
|
+
if (!isPlainObject(opts))
|
|
53
|
+
return [];
|
|
54
|
+
const raw = opts.fingerprint;
|
|
55
|
+
if (!Array.isArray(raw))
|
|
56
|
+
return [];
|
|
57
|
+
const fields = [];
|
|
58
|
+
for (let i = 0; i < raw.length; i++) {
|
|
59
|
+
const f = raw[i];
|
|
60
|
+
if (typeof f === "string" && f.trim() !== "" && fields.indexOf(f) === -1) {
|
|
61
|
+
fields.push(f);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return fields;
|
|
65
|
+
};
|
|
66
|
+
exports.fingerprintFieldsFor = fingerprintFieldsFor;
|
|
67
|
+
// A copy of tableOptions without the client-only `fingerprint` key, for the
|
|
68
|
+
// request body. The input is never mutated: the caller keeps using it to apply
|
|
69
|
+
// the fingerprints to the response.
|
|
70
|
+
const stripClientOnlyTableOptions = (tableOptions) => {
|
|
71
|
+
const out = {};
|
|
72
|
+
if (!isPlainObject(tableOptions))
|
|
73
|
+
return out;
|
|
74
|
+
const tables = Object.keys(tableOptions);
|
|
75
|
+
for (let i = 0; i < tables.length; i++) {
|
|
76
|
+
const opts = tableOptions[tables[i]];
|
|
77
|
+
// A non-object entry is not a valid table option; never forward it.
|
|
78
|
+
if (!isPlainObject(opts))
|
|
79
|
+
continue;
|
|
80
|
+
const copy = Object.assign({}, opts);
|
|
81
|
+
delete copy.fingerprint;
|
|
82
|
+
out[tables[i]] = copy;
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
};
|
|
86
|
+
exports.stripClientOnlyTableOptions = stripClientOnlyTableOptions;
|
|
87
|
+
// Replace each fingerprinted field's value in a metaData.json body with its
|
|
88
|
+
// digest. Leaves the content untouched when it is not a JSON object, or when a
|
|
89
|
+
// field is absent or not a { value: string } pair.
|
|
90
|
+
const fingerprintMetadataContent = (content, fields) => {
|
|
91
|
+
let metadata;
|
|
92
|
+
try {
|
|
93
|
+
metadata = JSON.parse(content);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return content;
|
|
97
|
+
}
|
|
98
|
+
if (!isPlainObject(metadata))
|
|
99
|
+
return content;
|
|
100
|
+
let changed = false;
|
|
101
|
+
for (let i = 0; i < fields.length; i++) {
|
|
102
|
+
const pair = metadata[fields[i]];
|
|
103
|
+
if (!isPlainObject(pair))
|
|
104
|
+
continue;
|
|
105
|
+
const value = pair.value;
|
|
106
|
+
if (typeof value === "string" && !METADATA_DIGEST_RE.test(value)) {
|
|
107
|
+
pair.value = digestOf(value);
|
|
108
|
+
changed = true;
|
|
109
|
+
}
|
|
110
|
+
if ("display_value" in pair) {
|
|
111
|
+
// display_value repeats the content (or a rendering of it); keeping it
|
|
112
|
+
// would put the bundle straight back into the mirror.
|
|
113
|
+
delete pair.display_value;
|
|
114
|
+
changed = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return changed ? JSON.stringify(metadata, null, 2) : content;
|
|
118
|
+
};
|
|
119
|
+
const fingerprintFile = (file, fields) => {
|
|
120
|
+
if (!isPlainObject(file) || typeof file.name !== "string")
|
|
121
|
+
return;
|
|
122
|
+
if (file.name === "metaData" && file.type === "json") {
|
|
123
|
+
if (typeof file.content === "string" && file.content !== "") {
|
|
124
|
+
file.content = fingerprintMetadataContent(file.content, fields);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (fields.indexOf(file.name) === -1)
|
|
129
|
+
return;
|
|
130
|
+
file.type = exports.FINGERPRINT_FILE_TYPE;
|
|
131
|
+
// Absent content = a structure-only manifest entry; only the type changes.
|
|
132
|
+
// Already-fingerprinted content is left alone so applying twice is a no-op.
|
|
133
|
+
if (typeof file.content === "string" && !(0, exports.isFingerprintContent)(file.content)) {
|
|
134
|
+
file.content = (0, exports.formatFingerprint)(file.content);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
// Apply fingerprinting in place to a table map from getManifest (`.tables`) or
|
|
138
|
+
// bulkDownload (the whole result). Returns the same object for chaining.
|
|
139
|
+
// Idempotent, and a no-op for any table without fingerprint config.
|
|
140
|
+
const applyFingerprints = (tables, tableOptions) => {
|
|
141
|
+
if (!isPlainObject(tables))
|
|
142
|
+
return tables;
|
|
143
|
+
const tableNames = Object.keys(tables);
|
|
144
|
+
for (let t = 0; t < tableNames.length; t++) {
|
|
145
|
+
const fields = (0, exports.fingerprintFieldsFor)(tableOptions, tableNames[t]);
|
|
146
|
+
if (fields.length === 0)
|
|
147
|
+
continue;
|
|
148
|
+
const table = tables[tableNames[t]];
|
|
149
|
+
if (!isPlainObject(table) || !isPlainObject(table.records))
|
|
150
|
+
continue;
|
|
151
|
+
const records = table.records;
|
|
152
|
+
const recKeys = Object.keys(records);
|
|
153
|
+
for (let r = 0; r < recKeys.length; r++) {
|
|
154
|
+
const rec = records[recKeys[r]];
|
|
155
|
+
if (!isPlainObject(rec) || !Array.isArray(rec.files))
|
|
156
|
+
continue;
|
|
157
|
+
const files = rec.files;
|
|
158
|
+
for (let f = 0; f < files.length; f++) {
|
|
159
|
+
fingerprintFile(files[f], fields);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return tables;
|
|
164
|
+
};
|
|
165
|
+
exports.applyFingerprints = applyFingerprints;
|
|
166
|
+
// True for a `<field>.sha256` path. Push uses it to refuse a digest outright,
|
|
167
|
+
// before any manifest lookup, so a fingerprint can never overwrite a bundle.
|
|
168
|
+
const isFingerprintFilePath = (filePath) => typeof filePath === "string" && filePath.slice(-(exports.FINGERPRINT_FILE_TYPE.length + 1)) === "." + exports.FINGERPRINT_FILE_TYPE;
|
|
169
|
+
exports.isFingerprintFilePath = isFingerprintFilePath;
|
package/dist/reconcileCommand.js
CHANGED
|
@@ -72,6 +72,7 @@ const projectFiles_1 = require("./projectFiles");
|
|
|
72
72
|
const recordSource_1 = require("./reconcile/recordSource");
|
|
73
73
|
const recordDiff_1 = require("./reconcile/recordDiff");
|
|
74
74
|
const fields_1 = require("./reconcile/fields");
|
|
75
|
+
const fingerprint_1 = require("./fingerprint");
|
|
75
76
|
const baseline_1 = require("./reconcile/baseline");
|
|
76
77
|
const report_1 = require("./reconcile/report");
|
|
77
78
|
const applyPlan_1 = require("./reconcile/applyPlan");
|
|
@@ -321,6 +322,14 @@ async function buildCreateFields(scope, change) {
|
|
|
321
322
|
}
|
|
322
323
|
const name = entry.slice(0, dot);
|
|
323
324
|
const type = entry.slice(dot + 1);
|
|
325
|
+
// A fingerprinted field lives in git as a digest only (fingerprint.ts), and
|
|
326
|
+
// its metaData value is the digest too, so the record cannot be rebuilt
|
|
327
|
+
// from the branch. Refuse the create rather than send a digest as content;
|
|
328
|
+
// such records ship from their own source (e.g. a UI component deploy).
|
|
329
|
+
if (type === fingerprint_1.FINGERPRINT_FILE_TYPE) {
|
|
330
|
+
throw new Error(change.table + "/" + change.name + ": field '" + name +
|
|
331
|
+
"' is mirrored as a fingerprint only, so the record cannot be created from the branch");
|
|
332
|
+
}
|
|
324
333
|
if (!(0, fields_1.isComparableField)({ name, type })) {
|
|
325
334
|
continue;
|
|
326
335
|
}
|
package/dist/snClient.js
CHANGED
|
@@ -17,6 +17,7 @@ const tough_cookie_1 = require("tough-cookie");
|
|
|
17
17
|
const genericUtils_1 = require("./genericUtils");
|
|
18
18
|
const Logger_1 = require("./Logger");
|
|
19
19
|
const FileLogger_1 = require("./FileLogger");
|
|
20
|
+
const fingerprint_1 = require("./fingerprint");
|
|
20
21
|
const authFailure_1 = require("./authFailure");
|
|
21
22
|
// Benchmark sink. Null when --benchmark is off; zero overhead in that case.
|
|
22
23
|
let _benchmarkSink = null;
|
|
@@ -609,7 +610,19 @@ const snClient = (baseURL, username, password, apiKey) => {
|
|
|
609
610
|
const endpoint = `api/cadso/dovetail_sync/bulkDownload`;
|
|
610
611
|
const tableCount = Object.keys(missingFiles).length;
|
|
611
612
|
FileLogger_1.fileLogger.debug("Bulk downloading files for " + tableCount + " tables");
|
|
612
|
-
|
|
613
|
+
// `fingerprint` is client-only: stripped from the request, applied to the
|
|
614
|
+
// response (see fingerprint.ts).
|
|
615
|
+
return client
|
|
616
|
+
.post(endpoint, {
|
|
617
|
+
missingFiles,
|
|
618
|
+
tableOptions: (0, fingerprint_1.stripClientOnlyTableOptions)(tableOptions),
|
|
619
|
+
})
|
|
620
|
+
.then(function (resp) {
|
|
621
|
+
if (resp && resp.data && resp.data.result) {
|
|
622
|
+
(0, fingerprint_1.applyFingerprints)(resp.data.result, tableOptions);
|
|
623
|
+
}
|
|
624
|
+
return resp;
|
|
625
|
+
});
|
|
613
626
|
};
|
|
614
627
|
const getManifest = (scope, config, withFiles = false) => {
|
|
615
628
|
const endpoint = `api/cadso/dovetail_sync/getManifest/${scope}`;
|
|
@@ -618,12 +631,22 @@ const snClient = (baseURL, username, password, apiKey) => {
|
|
|
618
631
|
var cleanIncludes = _stripUnderscoreKeys(includes);
|
|
619
632
|
var cleanExcludes = _stripUnderscoreKeys(excludes);
|
|
620
633
|
FileLogger_1.fileLogger.debug("Fetching manifest for scope " + scope + (withFiles ? " (with file contents)" : " (structure only)"));
|
|
621
|
-
return client
|
|
634
|
+
return client
|
|
635
|
+
.post(endpoint, {
|
|
622
636
|
includes: cleanIncludes,
|
|
623
637
|
excludes: cleanExcludes,
|
|
624
|
-
tableOptions,
|
|
638
|
+
tableOptions: (0, fingerprint_1.stripClientOnlyTableOptions)(tableOptions),
|
|
625
639
|
withFiles,
|
|
626
640
|
getContents: withFiles, // ServiceNow expects getContents, not withFiles
|
|
641
|
+
})
|
|
642
|
+
.then(function (resp) {
|
|
643
|
+
// Fingerprinted fields come back as `<field>.sha256` entries (and with
|
|
644
|
+
// hashed content when withFiles is set), so the manifest, the
|
|
645
|
+
// missing-file check and every writer agree on the on-disk name.
|
|
646
|
+
if (resp && resp.data && resp.data.result && resp.data.result.tables) {
|
|
647
|
+
(0, fingerprint_1.applyFingerprints)(resp.data.result.tables, tableOptions);
|
|
648
|
+
}
|
|
649
|
+
return resp;
|
|
627
650
|
});
|
|
628
651
|
};
|
|
629
652
|
const changeUpdateSet = (params) => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// After the instance delete, `dove delete` removes the record's local folder.
|
|
3
|
+
// It used to join the TOP-LEVEL sourceDirectory (src/<table>/<name>), but
|
|
4
|
+
// records live under their scope's folder (src/Core/..., or nested as
|
|
5
|
+
// src/UIComponents/<scope>/...), so the cleanup silently found nothing. It now
|
|
6
|
+
// uses the scope's own folder.
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
jest.mock("../Logger", function () {
|
|
12
|
+
return {
|
|
13
|
+
logger: {
|
|
14
|
+
info: jest.fn(),
|
|
15
|
+
debug: jest.fn(),
|
|
16
|
+
warn: jest.fn(),
|
|
17
|
+
error: jest.fn(),
|
|
18
|
+
success: jest.fn(),
|
|
19
|
+
getLogLevel: function () { return "info"; },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
jest.mock("../FileLogger", function () {
|
|
24
|
+
return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
|
|
25
|
+
});
|
|
26
|
+
jest.mock("../commands", function () {
|
|
27
|
+
return { setLogLevel: jest.fn() };
|
|
28
|
+
});
|
|
29
|
+
var mockRoot = "";
|
|
30
|
+
jest.mock("../config", function () {
|
|
31
|
+
var p = jest.requireActual("path");
|
|
32
|
+
return {
|
|
33
|
+
getSourcePath: function () { return p.join(mockRoot, "src"); },
|
|
34
|
+
getSourcePathForScope: function (scope) {
|
|
35
|
+
return p.join(mockRoot, "src", "UIComponents", scope);
|
|
36
|
+
},
|
|
37
|
+
loadScopeManifest: jest.fn().mockResolvedValue(undefined),
|
|
38
|
+
getManifest: function () { return undefined; },
|
|
39
|
+
getConfig: function () { return { scopes: {} }; },
|
|
40
|
+
isMultiScopeManifest: function () { return false; },
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
jest.mock("../FileUtils", function () {
|
|
44
|
+
return { writeScopeManifest: jest.fn().mockResolvedValue(undefined) };
|
|
45
|
+
});
|
|
46
|
+
var mockDelete = jest.fn();
|
|
47
|
+
jest.mock("../snClient", function () {
|
|
48
|
+
return {
|
|
49
|
+
defaultClient: function () {
|
|
50
|
+
return { deleteRecord: mockDelete };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
const fs_1 = __importDefault(require("fs"));
|
|
55
|
+
const os_1 = __importDefault(require("os"));
|
|
56
|
+
const path_1 = __importDefault(require("path"));
|
|
57
|
+
const deleteRecordCommand_1 = require("../deleteRecordCommand");
|
|
58
|
+
describe("deleteRecordCommand local cleanup", function () {
|
|
59
|
+
beforeEach(function () {
|
|
60
|
+
mockRoot = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-delete-"));
|
|
61
|
+
mockDelete.mockReset();
|
|
62
|
+
mockDelete.mockResolvedValue({ data: { result: { name: "Panel" } } });
|
|
63
|
+
});
|
|
64
|
+
afterEach(function () {
|
|
65
|
+
fs_1.default.rmSync(mockRoot, { recursive: true, force: true });
|
|
66
|
+
});
|
|
67
|
+
it("removes the record folder under the scope's own folder", async function () {
|
|
68
|
+
var recordDir = path_1.default.join(mockRoot, "src", "UIComponents", "x_cadso_ui_panel", "sys_ux_lib_component", "Panel");
|
|
69
|
+
fs_1.default.mkdirSync(recordDir, { recursive: true });
|
|
70
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), "{}");
|
|
71
|
+
await (0, deleteRecordCommand_1.deleteRecordCommand)({
|
|
72
|
+
table: "sys_ux_lib_component",
|
|
73
|
+
name: "Panel",
|
|
74
|
+
scope: "x_cadso_ui_panel",
|
|
75
|
+
sysid: "abc",
|
|
76
|
+
ci: true,
|
|
77
|
+
logLevel: "info",
|
|
78
|
+
});
|
|
79
|
+
expect(mockDelete).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(fs_1.default.existsSync(recordDir)).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
it("leaves a same-named folder under the top-level source path alone", async function () {
|
|
83
|
+
var wrongDir = path_1.default.join(mockRoot, "src", "sys_ux_lib_component", "Panel");
|
|
84
|
+
fs_1.default.mkdirSync(wrongDir, { recursive: true });
|
|
85
|
+
await (0, deleteRecordCommand_1.deleteRecordCommand)({
|
|
86
|
+
table: "sys_ux_lib_component",
|
|
87
|
+
name: "Panel",
|
|
88
|
+
scope: "x_cadso_ui_panel",
|
|
89
|
+
sysid: "abc",
|
|
90
|
+
ci: true,
|
|
91
|
+
logLevel: "info",
|
|
92
|
+
});
|
|
93
|
+
expect(fs_1.default.existsSync(wrongDir)).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -107,6 +107,25 @@ describe("getFileContextWithSkipReason", function () {
|
|
|
107
107
|
expect(result.context.name).toBe("TestRecord");
|
|
108
108
|
expect(result.context.scope).toBe("x_test");
|
|
109
109
|
});
|
|
110
|
+
it("refuses a .sha256 fingerprint file even when its field is in the manifest", function () {
|
|
111
|
+
mockManifest = {
|
|
112
|
+
scope: "x_cadso_ui_form",
|
|
113
|
+
tables: {
|
|
114
|
+
sys_ux_lib_source_script: {
|
|
115
|
+
records: {
|
|
116
|
+
Bundle: {
|
|
117
|
+
sys_id: "f9cd",
|
|
118
|
+
files: [{ name: "script", type: "sha256" }],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
mockIsMultiScope = false;
|
|
125
|
+
var result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/UIComponents/x_cadso_ui_form/sys_ux_lib_source_script/Bundle/script.sha256");
|
|
126
|
+
expect(result.context).toBeUndefined();
|
|
127
|
+
expect(result.skipReason).toBe("fingerprint only, read-only");
|
|
128
|
+
});
|
|
110
129
|
it("throws when no manifest is loaded", function () {
|
|
111
130
|
mockManifest = null;
|
|
112
131
|
expect(function () {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Fingerprint mode (fingerprint.ts): a configured field is mirrored as a
|
|
3
|
+
// SHA-256 digest instead of its content. Covers the digest format, config
|
|
4
|
+
// validation, request stripping, response rewriting (manifest structure,
|
|
5
|
+
// bulkDownload content, metaData.json), idempotency and the push-side path test.
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const fingerprint_1 = require("../fingerprint");
|
|
12
|
+
const BUNDLE = "!function(){console.log(\"bundle ü\")}();";
|
|
13
|
+
const HEX = crypto_1.default.createHash("sha256").update(BUNDLE, "utf8").digest("hex");
|
|
14
|
+
const OPTIONS = {
|
|
15
|
+
sys_ux_lib_source_script: { fingerprint: ["script"] },
|
|
16
|
+
sys_choice: { nameTemplate: "{name}.{element}.{value}" },
|
|
17
|
+
};
|
|
18
|
+
function metaContent(extra) {
|
|
19
|
+
return JSON.stringify(Object.assign({ _table: "sys_ux_lib_source_script", name: { value: "@tenon/ui-form" } }, extra), null, 2);
|
|
20
|
+
}
|
|
21
|
+
function bulkResult(files) {
|
|
22
|
+
return {
|
|
23
|
+
sys_ux_lib_source_script: {
|
|
24
|
+
records: {
|
|
25
|
+
"@tenon/ui-form": { name: "@tenon/ui-form", sys_id: "f9cd", files: files },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
describe("formatFingerprint", function () {
|
|
31
|
+
it("writes the digest and the UTF-8 byte length", function () {
|
|
32
|
+
expect((0, fingerprint_1.formatFingerprint)(BUNDLE)).toBe("sha256:" + HEX + "\nbytes:" + Buffer.byteLength(BUNDLE, "utf8") + "\n");
|
|
33
|
+
});
|
|
34
|
+
it("is recognized by isFingerprintContent", function () {
|
|
35
|
+
expect((0, fingerprint_1.isFingerprintContent)((0, fingerprint_1.formatFingerprint)(BUNDLE))).toBe(true);
|
|
36
|
+
expect((0, fingerprint_1.isFingerprintContent)(BUNDLE)).toBe(false);
|
|
37
|
+
expect((0, fingerprint_1.isFingerprintContent)(undefined)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("fingerprintFieldsFor", function () {
|
|
41
|
+
it("returns the configured fields", function () {
|
|
42
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_ux_lib_source_script")).toEqual(["script"]);
|
|
43
|
+
});
|
|
44
|
+
it("returns nothing for an unconfigured table or missing options", function () {
|
|
45
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_choice")).toEqual([]);
|
|
46
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_script")).toEqual([]);
|
|
47
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(undefined, "sys_ux_lib_source_script")).toEqual([]);
|
|
48
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(null, "sys_ux_lib_source_script")).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
it("drops malformed entries instead of throwing", function () {
|
|
51
|
+
var bad = {
|
|
52
|
+
t1: { fingerprint: "script" },
|
|
53
|
+
t2: { fingerprint: ["", " ", 5, "script", "script"] },
|
|
54
|
+
};
|
|
55
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(bad, "t1")).toEqual([]);
|
|
56
|
+
expect((0, fingerprint_1.fingerprintFieldsFor)(bad, "t2")).toEqual(["script"]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe("stripClientOnlyTableOptions", function () {
|
|
60
|
+
it("removes fingerprint and keeps every other option", function () {
|
|
61
|
+
var out = (0, fingerprint_1.stripClientOnlyTableOptions)(OPTIONS);
|
|
62
|
+
expect(out.sys_ux_lib_source_script).toEqual({});
|
|
63
|
+
expect(out.sys_choice).toEqual({ nameTemplate: "{name}.{element}.{value}" });
|
|
64
|
+
});
|
|
65
|
+
it("never mutates the caller's options", function () {
|
|
66
|
+
(0, fingerprint_1.stripClientOnlyTableOptions)(OPTIONS);
|
|
67
|
+
expect(OPTIONS.sys_ux_lib_source_script.fingerprint).toEqual(["script"]);
|
|
68
|
+
});
|
|
69
|
+
it("returns an empty map for missing options", function () {
|
|
70
|
+
expect((0, fingerprint_1.stripClientOnlyTableOptions)(undefined)).toEqual({});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("applyFingerprints", function () {
|
|
74
|
+
it("renames a structure-only manifest entry to .sha256 without content", function () {
|
|
75
|
+
var tables = bulkResult([{ name: "script", type: "js" }]);
|
|
76
|
+
(0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
|
|
77
|
+
var file = tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0];
|
|
78
|
+
expect(file).toEqual({ name: "script", type: "sha256" });
|
|
79
|
+
});
|
|
80
|
+
it("hashes downloaded content, whatever type the server echoed", function () {
|
|
81
|
+
var tables = bulkResult([
|
|
82
|
+
{ name: "script", type: "js", content: BUNDLE },
|
|
83
|
+
{ name: "script_b", type: "sha256", content: BUNDLE },
|
|
84
|
+
]);
|
|
85
|
+
(0, fingerprint_1.applyFingerprints)(tables, { sys_ux_lib_source_script: { fingerprint: ["script", "script_b"] } });
|
|
86
|
+
var files = tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files;
|
|
87
|
+
expect(files[0]).toEqual({ name: "script", type: "sha256", content: (0, fingerprint_1.formatFingerprint)(BUNDLE) });
|
|
88
|
+
expect(files[1].content).toBe((0, fingerprint_1.formatFingerprint)(BUNDLE));
|
|
89
|
+
});
|
|
90
|
+
it("replaces the field's metaData.json value with the digest and drops display_value", function () {
|
|
91
|
+
var tables = bulkResult([
|
|
92
|
+
{
|
|
93
|
+
name: "metaData",
|
|
94
|
+
type: "json",
|
|
95
|
+
content: metaContent({ script: { value: BUNDLE, display_value: BUNDLE } }),
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
(0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
|
|
99
|
+
var meta = JSON.parse(tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0].content);
|
|
100
|
+
expect(meta.script).toEqual({ value: "sha256:" + HEX });
|
|
101
|
+
expect(meta.name).toEqual({ value: "@tenon/ui-form" });
|
|
102
|
+
expect(JSON.stringify(meta)).not.toContain("bundle");
|
|
103
|
+
});
|
|
104
|
+
it("is idempotent", function () {
|
|
105
|
+
var tables = bulkResult([
|
|
106
|
+
{ name: "script", type: "js", content: BUNDLE },
|
|
107
|
+
{ name: "metaData", type: "json", content: metaContent({ script: { value: BUNDLE } }) },
|
|
108
|
+
]);
|
|
109
|
+
(0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
|
|
110
|
+
var once = JSON.stringify(tables);
|
|
111
|
+
(0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
|
|
112
|
+
expect(JSON.stringify(tables)).toBe(once);
|
|
113
|
+
});
|
|
114
|
+
it("leaves tables without fingerprint config untouched", function () {
|
|
115
|
+
var tables = {
|
|
116
|
+
sys_script_include: {
|
|
117
|
+
records: {
|
|
118
|
+
Foo: { name: "Foo", sys_id: "1", files: [{ name: "script", type: "js", content: "x" }] },
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
var before = JSON.stringify(tables);
|
|
123
|
+
(0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
|
|
124
|
+
expect(JSON.stringify(tables)).toBe(before);
|
|
125
|
+
});
|
|
126
|
+
it("tolerates malformed responses", function () {
|
|
127
|
+
expect((0, fingerprint_1.applyFingerprints)(null, OPTIONS)).toBeNull();
|
|
128
|
+
expect((0, fingerprint_1.applyFingerprints)("nope", OPTIONS)).toBe("nope");
|
|
129
|
+
var odd = {
|
|
130
|
+
sys_ux_lib_source_script: { records: { a: null, b: { files: "x" }, c: { files: [null, 7] } } },
|
|
131
|
+
};
|
|
132
|
+
expect(function () { (0, fingerprint_1.applyFingerprints)(odd, OPTIONS); }).not.toThrow();
|
|
133
|
+
var badMeta = bulkResult([{ name: "metaData", type: "json", content: "not json" }]);
|
|
134
|
+
(0, fingerprint_1.applyFingerprints)(badMeta, OPTIONS);
|
|
135
|
+
expect(badMeta.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0].content).toBe("not json");
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe("isFingerprintFilePath", function () {
|
|
139
|
+
it("matches only a .sha256 extension", function () {
|
|
140
|
+
expect((0, fingerprint_1.isFingerprintFilePath)("/r/src/UIComponents/x/sys_ux_lib_source_script/a/script.sha256")).toBe(true);
|
|
141
|
+
expect((0, fingerprint_1.isFingerprintFilePath)("/r/src/Core/sys_script_include/a/script.js")).toBe(false);
|
|
142
|
+
expect((0, fingerprint_1.isFingerprintFilePath)("/r/a/sha256")).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
});
|