@tenonhq/dovetail-core 0.0.133 → 0.0.135

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,133 @@
1
+ "use strict";
2
+ // getManifest and getMissingFiles (bulkDownload) are the two reads every
3
+ // refresh/download/pull path uses, so layout elements are added there once.
4
+ // Checks that `layoutElements` never reaches the instance, that a filter such as
5
+ // `query: "sys_userISEMPTY"` still does, that the child rows are read through the
6
+ // Table API, and that nothing changes for a mirror that does not set the option.
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ jest.mock("../Logger", function () {
9
+ return {
10
+ logger: {
11
+ info: jest.fn(),
12
+ debug: jest.fn(),
13
+ warn: jest.fn(),
14
+ error: jest.fn(),
15
+ getLogLevel: function () { return "debug"; },
16
+ },
17
+ };
18
+ });
19
+ jest.mock("../FileLogger", function () {
20
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
21
+ });
22
+ const snClient_1 = require("../snClient");
23
+ const SHARED = "1".repeat(32);
24
+ const PERSONAL = "2".repeat(32);
25
+ function okResponse(result) {
26
+ return { status: 200, data: { result: result }, headers: {}, statusText: "OK", config: {} };
27
+ }
28
+ function makeClient(post, get) {
29
+ const c = (0, snClient_1.snClient)("https://x.service-now.com/", "u", "p");
30
+ c.client.post = post;
31
+ c.client.get = get;
32
+ return c;
33
+ }
34
+ const LAYOUT_OPTIONS = {
35
+ sys_ui_list: { layoutElements: true, query: "sys_userISEMPTY", nameTemplate: "{name}.{view}" },
36
+ };
37
+ describe("snClient layout elements hook", function () {
38
+ it("getManifest strips layoutElements, forwards the personal-layout filter, and lists the columns file", async function () {
39
+ // The instance applies `query`, so only the shared layout comes back.
40
+ const post = jest.fn().mockResolvedValue(okResponse({
41
+ scope: "x_cadso_work",
42
+ tables: {
43
+ sys_ui_list: {
44
+ records: {
45
+ "x_cadso_work_task.Default view": {
46
+ name: "x_cadso_work_task.Default view",
47
+ sys_id: SHARED,
48
+ files: [{ name: "name", type: "txt" }],
49
+ },
50
+ },
51
+ },
52
+ },
53
+ }));
54
+ const get = jest.fn();
55
+ const c = makeClient(post, get);
56
+ const config = { includes: {}, excludes: {}, tableOptions: LAYOUT_OPTIONS };
57
+ const resp = await c.getManifest("x_cadso_work", config);
58
+ const body = post.mock.calls[0][1];
59
+ expect(body.tableOptions).toEqual({ sys_ui_list: { query: "sys_userISEMPTY", nameTemplate: "{name}.{view}" } });
60
+ expect(JSON.stringify(body)).not.toContain("layoutElements");
61
+ expect(resp.data.result.tables.sys_ui_list.records["x_cadso_work_task.Default view"].files).toEqual([
62
+ { name: "name", type: "txt" },
63
+ { name: "columns", type: "txt" },
64
+ ]);
65
+ // Structure only: no child rows are read yet.
66
+ expect(get).not.toHaveBeenCalled();
67
+ // The caller's config is not mutated.
68
+ expect(LAYOUT_OPTIONS.sys_ui_list.layoutElements).toBe(true);
69
+ });
70
+ it("getMissingFiles asks the instance for real fields only and fills the columns from the Table API", async function () {
71
+ const post = jest.fn().mockResolvedValue(okResponse({
72
+ sys_ui_list: {
73
+ records: {
74
+ "x_cadso_work_task.Default view": {
75
+ name: "x_cadso_work_task.Default view",
76
+ sys_id: SHARED,
77
+ files: [
78
+ { name: "name", type: "txt", content: "x_cadso_work_task" },
79
+ { name: "metaData", type: "json", content: "{}" },
80
+ ],
81
+ },
82
+ },
83
+ },
84
+ }));
85
+ const get = jest.fn().mockResolvedValue(okResponse([
86
+ { sys_id: "9".repeat(32), list_id: SHARED, element: "short_description", position: "1" },
87
+ { sys_id: "8".repeat(32), list_id: SHARED, element: "number", position: "0" },
88
+ ]));
89
+ const c = makeClient(post, get);
90
+ const resp = await c.getMissingFiles({ sys_ui_list: { [SHARED]: [{ name: "name", type: "txt" }, { name: "columns", type: "txt" }] } }, LAYOUT_OPTIONS);
91
+ const body = post.mock.calls[0][1];
92
+ expect(body.missingFiles).toEqual({ sys_ui_list: { [SHARED]: [{ name: "name", type: "txt" }] } });
93
+ expect(JSON.stringify(body.tableOptions)).not.toContain("layoutElements");
94
+ expect(get).toHaveBeenCalledTimes(1);
95
+ const url = get.mock.calls[0][0];
96
+ const params = get.mock.calls[0][1].params;
97
+ expect(url).toBe("api/now/table/sys_ui_list_element");
98
+ expect(params.sysparm_query).toBe("list_idIN" + SHARED + "^ORDERBYsys_id");
99
+ expect(params.sysparm_exclude_reference_link).toBe("true");
100
+ // A long IN list makes the instance refuse to build its pagination Link
101
+ // header ("Pagination not supported", HTTP 400); paging is done by offset here.
102
+ expect(params.sysparm_suppress_pagination_header).toBe("true");
103
+ expect(params.sysparm_limit).toBe("1000");
104
+ expect(params.sysparm_offset).toBe("0");
105
+ const files = resp.data.result.sys_ui_list.records["x_cadso_work_task.Default view"].files;
106
+ expect(files[files.length - 1]).toEqual({ name: "columns", type: "txt", content: "number\nshort_description\n" });
107
+ });
108
+ it("never reads or writes a personal layout the instance left out", async function () {
109
+ const post = jest.fn().mockResolvedValue(okResponse({ sys_ui_list: { records: {} } }));
110
+ const get = jest.fn().mockResolvedValue(okResponse([]));
111
+ const c = makeClient(post, get);
112
+ await c.getMissingFiles({ sys_ui_list: { [SHARED]: [{ name: "columns", type: "txt" }] } }, LAYOUT_OPTIONS);
113
+ const query = get.mock.calls[0][1].params.sysparm_query;
114
+ expect(query).not.toContain(PERSONAL);
115
+ });
116
+ it("changes nothing for a mirror that does not set layoutElements", async function () {
117
+ const result = {
118
+ scope: "x_cadso_work",
119
+ tables: {
120
+ sys_ui_list: {
121
+ records: { a: { name: "a", sys_id: SHARED, files: [{ name: "name", type: "txt" }] } },
122
+ },
123
+ },
124
+ };
125
+ const post = jest.fn().mockResolvedValue(okResponse(JSON.parse(JSON.stringify(result))));
126
+ const get = jest.fn();
127
+ const c = makeClient(post, get);
128
+ const config = { includes: {}, excludes: {}, tableOptions: { sys_ui_list: { query: "sys_userISEMPTY" } } };
129
+ const resp = await c.getManifest("x_cadso_work", config);
130
+ expect(resp.data.result).toEqual(result);
131
+ expect(get).not.toHaveBeenCalled();
132
+ });
133
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/dovetail-core",
3
- "version": "0.0.133",
3
+ "version": "0.0.135",
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.24",
25
+ "@tenonhq/dovetail-types": "~0.0.25",
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.17",
42
+ "@tenonhq/dovetail-schema": "~0.0.18",
43
43
  "axios": "^1.20.0",
44
44
  "axios-cookiejar-support": "^4.0.7",
45
45
  "axios-rate-limit": "^1.3.0",