@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.
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ // A fingerprinted field is in the branch as a digest only (fingerprint.ts), and
3
+ // its metaData.json value is the digest too. `dove reconcile --apply` must not
4
+ // create such a record from the branch: it would write the digest over the
5
+ // field's real content. The create is refused per record and nothing is posted.
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
+ jest.mock("../Logger", function () {
11
+ return {
12
+ logger: {
13
+ info: jest.fn(),
14
+ debug: jest.fn(),
15
+ warn: jest.fn(),
16
+ error: jest.fn(),
17
+ success: jest.fn(),
18
+ getLogLevel: function () { return "debug"; },
19
+ },
20
+ };
21
+ });
22
+ jest.mock("../FileLogger", function () {
23
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
24
+ });
25
+ var mockSourcePath = "";
26
+ jest.mock("../config", function () {
27
+ return {
28
+ getSourcePathForScope: function () {
29
+ return mockSourcePath;
30
+ },
31
+ };
32
+ });
33
+ var mockPost = jest.fn();
34
+ jest.mock("../snClient", function () {
35
+ var actual = jest.requireActual("../snClient");
36
+ var client = actual.snClient("https://x.service-now.com/", "u", "p");
37
+ client.client.post = mockPost;
38
+ return Object.assign({}, actual, {
39
+ defaultClient: function () {
40
+ return client;
41
+ },
42
+ });
43
+ });
44
+ const fs_1 = __importDefault(require("fs"));
45
+ const os_1 = __importDefault(require("os"));
46
+ const path_1 = __importDefault(require("path"));
47
+ const reconcileCommand_1 = require("../reconcileCommand");
48
+ const fingerprint_1 = require("../fingerprint");
49
+ describe("reconcile applyCreates with a fingerprinted record", function () {
50
+ var tmp = "";
51
+ beforeEach(function () {
52
+ mockPost.mockReset();
53
+ tmp = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-fp-create-"));
54
+ mockSourcePath = tmp;
55
+ var recordDir = path_1.default.join(tmp, "sys_ux_lib_source_script", "Bundle");
56
+ fs_1.default.mkdirSync(recordDir, { recursive: true });
57
+ fs_1.default.writeFileSync(path_1.default.join(recordDir, "script.sha256"), (0, fingerprint_1.formatFingerprint)("!function(){}();"));
58
+ fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), JSON.stringify({ name: { value: "@tenon/ui-form" }, script: { value: "sha256:" + "0".repeat(64) } }));
59
+ });
60
+ afterEach(function () {
61
+ fs_1.default.rmSync(tmp, { recursive: true, force: true });
62
+ });
63
+ it("refuses the create with a named reason and never posts", async function () {
64
+ var change = {
65
+ kind: "create",
66
+ table: "sys_ux_lib_source_script",
67
+ scope: "x_cadso_ui_form",
68
+ sys_id: "f9cd",
69
+ name: "Bundle",
70
+ fieldDeltas: [],
71
+ };
72
+ var outcomes = await (0, reconcileCommand_1.applyCreates)("x_cadso_ui_form", [change], "us1");
73
+ expect(outcomes).toHaveLength(1);
74
+ expect(outcomes[0].ok).toBe(false);
75
+ expect(outcomes[0].error).toMatch(/fingerprint only/);
76
+ expect(outcomes[0].error).toMatch(/sys_ux_lib_source_script\/Bundle/);
77
+ expect(mockPost).not.toHaveBeenCalled();
78
+ });
79
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // resolveScopeFromPath (config.ts) maps a file to the scope whose folder holds
3
+ // it; push relies on it (FileUtils.getFileContextWithSkipReason). With scopes in
4
+ // nested folders (src/UIComponents/<scope>) a plain string prefix is wrong: a
5
+ // folder claims a sibling whose name starts the same. Matching is now on a
6
+ // separator boundary, and the deepest folder wins regardless of declaration order.
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 "debug"; },
20
+ setLogLevel: jest.fn(),
21
+ },
22
+ };
23
+ });
24
+ jest.mock("../FileLogger", function () {
25
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
26
+ });
27
+ const fs_1 = __importDefault(require("fs"));
28
+ const os_1 = __importDefault(require("os"));
29
+ const path_1 = __importDefault(require("path"));
30
+ const config_1 = require("../config");
31
+ const CONFIG = [
32
+ "module.exports = {",
33
+ " sourceDirectory: 'src',",
34
+ " buildDirectory: 'build',",
35
+ " includes: { _tables: ['sys_script_include'] },",
36
+ " excludes: { _tables: [] },",
37
+ " tableOptions: {},",
38
+ " scopes: {",
39
+ // Declared parent-first on purpose: the old first-match loop returned it for
40
+ // every file below it.
41
+ " x_parent: { sourceDirectory: 'src/UIComponents' },",
42
+ " x_cadso_ui_form: { sourceDirectory: 'src/UIComponents/x_cadso_ui_form' },",
43
+ " x_cadso_ui_form_x: { sourceDirectory: 'src/UIComponents/x_cadso_ui_form_x' },",
44
+ " x_cadso_core: { sourceDirectory: 'src/Core' },",
45
+ " },",
46
+ "};",
47
+ "",
48
+ ].join("\n");
49
+ describe("resolveScopeFromPath", function () {
50
+ var tmp = "";
51
+ var cwd = process.cwd();
52
+ beforeAll(async function () {
53
+ tmp = fs_1.default.realpathSync(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-scope-path-")));
54
+ fs_1.default.writeFileSync(path_1.default.join(tmp, "dove.config.js"), CONFIG);
55
+ process.chdir(tmp);
56
+ await (0, config_1.loadConfigs)();
57
+ });
58
+ afterAll(function () {
59
+ process.chdir(cwd);
60
+ fs_1.default.rmSync(tmp, { recursive: true, force: true });
61
+ });
62
+ function file(rel) {
63
+ return path_1.default.join(tmp, rel);
64
+ }
65
+ it("resolves each scope's folder from the config", function () {
66
+ expect((0, config_1.getSourcePathForScope)("x_cadso_ui_form")).toBe(file("src/UIComponents/x_cadso_ui_form"));
67
+ });
68
+ it("does not let a folder claim a sibling that shares its prefix", function () {
69
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form_x/sys_ux_lib_component/a/metaData.json"))).toBe("x_cadso_ui_form_x");
70
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form/sys_ux_lib_component/a/metaData.json"))).toBe("x_cadso_ui_form");
71
+ });
72
+ it("picks the deepest folder when scope folders nest", function () {
73
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form/t/r/script.js"))).toBe("x_cadso_ui_form");
74
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/other/t/r/script.js"))).toBe("x_parent");
75
+ });
76
+ it("still resolves a flat scope folder", function () {
77
+ expect((0, config_1.resolveScopeFromPath)(file("src/Core/sys_script_include/APIUtils/script.js"))).toBe("x_cadso_core");
78
+ });
79
+ it("returns undefined outside every scope folder or for bad input", function () {
80
+ expect((0, config_1.resolveScopeFromPath)(file("src/CoreX/sys_script_include/a/script.js"))).toBeUndefined();
81
+ expect((0, config_1.resolveScopeFromPath)("")).toBeUndefined();
82
+ });
83
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // getManifest and getMissingFiles (bulkDownload) are the two reads every
3
+ // refresh/download/pull path uses, so fingerprinting is applied there once.
4
+ // Checks that `fingerprint` never reaches the instance and that the response
5
+ // comes back rewritten.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ jest.mock("../Logger", function () {
8
+ return {
9
+ logger: {
10
+ info: jest.fn(),
11
+ debug: jest.fn(),
12
+ warn: jest.fn(),
13
+ error: jest.fn(),
14
+ getLogLevel: function () { return "debug"; },
15
+ },
16
+ };
17
+ });
18
+ jest.mock("../FileLogger", function () {
19
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
20
+ });
21
+ const snClient_1 = require("../snClient");
22
+ const fingerprint_1 = require("../fingerprint");
23
+ const BUNDLE = "!function(){}();";
24
+ function okResponse(result) {
25
+ return { status: 200, data: { result: result }, headers: {}, statusText: "OK", config: {} };
26
+ }
27
+ function makeClient(post) {
28
+ var c = (0, snClient_1.snClient)("https://x.service-now.com/", "u", "p");
29
+ c.client.post = post;
30
+ return c;
31
+ }
32
+ const TABLE_OPTIONS = {
33
+ sys_ux_lib_source_script: { fingerprint: ["script"], query: "active=true" },
34
+ };
35
+ describe("snClient fingerprint hook", function () {
36
+ it("getManifest strips fingerprint from the request and renames the field in the manifest", async function () {
37
+ var post = jest.fn().mockResolvedValue(okResponse({
38
+ scope: "x_cadso_ui_form",
39
+ tables: {
40
+ sys_ux_lib_source_script: {
41
+ records: { a: { name: "a", sys_id: "1", files: [{ name: "script", type: "js" }] } },
42
+ },
43
+ },
44
+ }));
45
+ var c = makeClient(post);
46
+ var config = { includes: {}, excludes: {}, tableOptions: TABLE_OPTIONS };
47
+ var resp = await c.getManifest("x_cadso_ui_form", config);
48
+ var body = post.mock.calls[0][1];
49
+ expect(body.tableOptions).toEqual({ sys_ux_lib_source_script: { query: "active=true" } });
50
+ expect(JSON.stringify(body)).not.toContain("fingerprint");
51
+ expect(resp.data.result.tables.sys_ux_lib_source_script.records.a.files[0]).toEqual({
52
+ name: "script",
53
+ type: "sha256",
54
+ });
55
+ // The caller's config is not mutated.
56
+ expect(TABLE_OPTIONS.sys_ux_lib_source_script.fingerprint).toEqual(["script"]);
57
+ });
58
+ it("getMissingFiles strips fingerprint from the request and hashes the downloaded content", async function () {
59
+ var post = jest.fn().mockResolvedValue(okResponse({
60
+ sys_ux_lib_source_script: {
61
+ records: {
62
+ a: { name: "a", sys_id: "1", files: [{ name: "script", type: "sha256", content: BUNDLE }] },
63
+ },
64
+ },
65
+ }));
66
+ var c = makeClient(post);
67
+ var resp = await c.getMissingFiles({ sys_ux_lib_source_script: { "1": [{ name: "script", type: "sha256" }] } }, TABLE_OPTIONS);
68
+ var body = post.mock.calls[0][1];
69
+ expect(JSON.stringify(body.tableOptions)).not.toContain("fingerprint");
70
+ expect(resp.data.result.sys_ux_lib_source_script.records.a.files[0].content).toBe((0, fingerprint_1.formatFingerprint)(BUNDLE));
71
+ });
72
+ it("passes responses through untouched when nothing is fingerprinted", async function () {
73
+ var result = {
74
+ sys_script_include: {
75
+ records: { a: { name: "a", sys_id: "1", files: [{ name: "script", type: "js", content: "x" }] } },
76
+ },
77
+ };
78
+ var post = jest.fn().mockResolvedValue(okResponse(result));
79
+ var c = makeClient(post);
80
+ var resp = await c.getMissingFiles({ sys_script_include: { "1": [{ name: "script", type: "js" }] } }, {});
81
+ expect(resp.data.result).toEqual(result);
82
+ });
83
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/dovetail-core",
3
- "version": "0.0.131",
3
+ "version": "0.0.132",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "node": ">=22"
23
23
  },
24
24
  "devDependencies": {
25
- "@tenonhq/dovetail-types": "~0.0.22",
25
+ "@tenonhq/dovetail-types": "~0.0.24",
26
26
  "@types/dotenv": "^6.1.1",
27
27
  "@types/inquirer": "^8.2.10",
28
28
  "@types/jest": "^29.5.5",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@tenonhq/dovetail-clickup": "~0.0.15",
42
- "@tenonhq/dovetail-schema": "~0.0.16",
42
+ "@tenonhq/dovetail-schema": "~0.0.17",
43
43
  "axios": "^1.20.0",
44
44
  "axios-cookiejar-support": "^4.0.7",
45
45
  "axios-rate-limit": "^1.3.0",