@truedat/core 6.3.0 → 6.3.2

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,143 @@
1
+ import { compile } from "path-to-regexp";
2
+ import { waitFor } from "@testing-library/react";
3
+ import { renderHook } from "@testing-library/react-hooks";
4
+ import { API_ACL_RESOURCE_ENTRIES, API_ACL_ENTRY } from "../../api";
5
+ import { apiJsonPost, apiJsonPatch, apiJsonDelete } from "../../services/api";
6
+ import {
7
+ useAclEntries,
8
+ useAclEntryCreate,
9
+ useAclEntryUpdate,
10
+ useAclEntryDelete,
11
+ } from "../useAclEntries";
12
+
13
+ jest.mock("@truedat/core/services/api", () => {
14
+ const originalModule = jest.requireActual("@truedat/core/services/api");
15
+
16
+ return {
17
+ __esModule: true,
18
+ ...originalModule,
19
+ apiJson: jest.fn(() => ({
20
+ data: {
21
+ _embedded: {
22
+ acl_entries: [
23
+ {
24
+ _links: {
25
+ self: {
26
+ href: "/api/acl_entries/1",
27
+ methods: ["GET", "DELETE", "POST"],
28
+ },
29
+ },
30
+ acl_entry_id: 1,
31
+ description: null,
32
+ principal: {
33
+ full_name: "Foo",
34
+ id: 11,
35
+ user_name: "foo@bar.com",
36
+ },
37
+ principal_type: "user",
38
+ role_id: 111,
39
+ role_name: "baz",
40
+ },
41
+ ],
42
+ },
43
+ },
44
+ })),
45
+ apiJsonPost: jest.fn(),
46
+ apiJsonPatch: jest.fn(),
47
+ apiJsonDelete: jest.fn(),
48
+ };
49
+ });
50
+
51
+ const id = 1;
52
+ const resource = {
53
+ type: "domain",
54
+ id,
55
+ };
56
+
57
+ const payload = {
58
+ acl_entry: {
59
+ role_name: "role2",
60
+ resource_type: resource.type,
61
+ principal_type: "user",
62
+ principal_id: 1,
63
+ description: "foo",
64
+ },
65
+ };
66
+
67
+ const acl_entry = {
68
+ acl_entry_id: id,
69
+ description: null,
70
+ principal: {
71
+ full_name: "Foo",
72
+ id: 11,
73
+ user_name: "foo@bar.com",
74
+ },
75
+ principal_type: "user",
76
+ role_id: 111,
77
+ role_name: "baz",
78
+ };
79
+
80
+ describe("hooks: useAclEntries", () => {
81
+ it("use acl entries return acl entries correctly", () => {
82
+ const {
83
+ result: {
84
+ current: { data },
85
+ },
86
+ } = renderHook(() => useAclEntries(resource));
87
+
88
+ waitFor(() =>
89
+ expect(data).toBe(
90
+ expect.objectContaining({
91
+ aclEntries: [acl_entry],
92
+ actions: { canCreate: true },
93
+ })
94
+ )
95
+ );
96
+ });
97
+
98
+ it("create acl entry trigger calls api json post with correct url and payload", () => {
99
+ const {
100
+ result: {
101
+ current: { trigger },
102
+ },
103
+ } = renderHook(() => useAclEntryCreate(resource));
104
+
105
+ trigger(payload);
106
+
107
+ const url = compile(API_ACL_RESOURCE_ENTRIES)(resource);
108
+ expect(apiJsonPost).toHaveBeenCalledWith(url, {
109
+ ...payload,
110
+ });
111
+ });
112
+
113
+ it("update acl entry trigger calls api json patch with correct url and payload", () => {
114
+ const {
115
+ result: {
116
+ current: { trigger },
117
+ },
118
+ } = renderHook(() => useAclEntryUpdate(resource.id));
119
+
120
+ trigger(payload);
121
+
122
+ const url = compile(API_ACL_ENTRY)({ id: resource.id });
123
+ expect(apiJsonPatch).toHaveBeenCalledWith(url, {
124
+ ...payload,
125
+ });
126
+ });
127
+
128
+ it("update acl entry trigger calls api json delete with correct url", () => {
129
+ const {
130
+ result: {
131
+ current: { trigger },
132
+ },
133
+ } = renderHook(() => useAclEntryDelete(resource.id));
134
+
135
+ trigger();
136
+
137
+ const url = compile(API_ACL_ENTRY)({ id: resource.id });
138
+ expect(apiJsonDelete).toHaveBeenCalledWith(
139
+ url,
140
+ expect.objectContaining({})
141
+ );
142
+ });
143
+ });
@@ -0,0 +1,44 @@
1
+ import { compile } from "path-to-regexp";
2
+ import _ from "lodash/fp";
3
+ import useSWR from "swr";
4
+ import useSWRMutation from "swr/mutation";
5
+ import { accentInsensitivePathOrder } from "../services/sort";
6
+ import { API_ACL_ENTRY, API_ACL_RESOURCE_ENTRIES } from "../api";
7
+ import {
8
+ apiJson,
9
+ apiJsonPatch,
10
+ apiJsonPost,
11
+ apiJsonDelete,
12
+ JSON_OPTS,
13
+ } from "../services/api";
14
+
15
+ export const useAclEntries = (resource) => {
16
+ const url = compile(API_ACL_RESOURCE_ENTRIES)(resource);
17
+ const { data, error, loading, mutate } = useSWR(url, apiJson);
18
+ const aclEntries = _.flow(
19
+ _.pathOr([], "_embedded.acl_entries"),
20
+ _.sortBy(accentInsensitivePathOrder("user_name"))
21
+ )(data?.data);
22
+ const actions = {
23
+ canCreate: _.flow(
24
+ _.pathOr([], "_links.self.methods"),
25
+ _.includes("POST")
26
+ )(data?.data),
27
+ };
28
+ return { data: { aclEntries, actions }, error, loading, mutate };
29
+ };
30
+
31
+ export const useAclEntryCreate = (resource) => {
32
+ const url = compile(API_ACL_RESOURCE_ENTRIES)(resource);
33
+ return useSWRMutation(url, (url, { arg }) => apiJsonPost(url, arg));
34
+ };
35
+
36
+ export const useAclEntryUpdate = (id) => {
37
+ const url = compile(API_ACL_ENTRY)({ id });
38
+ return useSWRMutation(url, (url, { arg }) => apiJsonPatch(url, arg));
39
+ };
40
+
41
+ export const useAclEntryDelete = (id) => {
42
+ const url = compile(API_ACL_ENTRY)({ id });
43
+ return useSWRMutation(url, (url) => apiJsonDelete(url, JSON_OPTS));
44
+ };
package/src/routes.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import _ from "lodash/fp";
2
2
  import { compile } from "path-to-regexp";
3
3
 
4
+ export const AI_SANDBOX = "/aiSandbox";
4
5
  export const CALLBACK = "/callback";
5
6
  export const BUCKETS_VIEW = "/buckets/:propertyPath";
6
7
  export const BUCKET_VIEW = "/bucketStructures";
@@ -148,6 +149,7 @@ export const PROFILE_EXECUTION =
148
149
  "/profileGroups/:group_id/profileExecutions/:id";
149
150
  export const PROFILE_GROUP = "/profileGroups/:id";
150
151
  export const PROMPTS = "/prompts";
152
+ export const PROVIDERS = "/providers";
151
153
  export const QUALITY_CONTROLS = "/qualityControls";
152
154
  export const QUALITY_CONTROLS_DEPRECATED = "/qualityControls/deprecated";
153
155
  export const QUALITY_CONTROLS_DRAFTS = "/qualityControls/drafts";
@@ -213,15 +215,17 @@ export const STRUCTURE_STRUCTURE_LINKS_NEW =
213
215
  "/structures/:id/structureLinks/new";
214
216
  export const STRUCTURE_LINKS = "/structures/:id/links";
215
217
  export const STRUCTURE_LINKS_NEW = "/structures/:id/links/new";
218
+ export const STRUCTURE_MEMBERS = "/structures/:id/members";
219
+ export const STRUCTURE_MEMBERS_NEW = "/structures/:id/members/new";
216
220
  export const STRUCTURE_METADATA = "/structures/:id/metadata";
217
221
  export const STRUCTURE_NOTES = "/structures/:id/notes";
218
222
  export const STRUCTURE_NOTES_EDIT = "/structures/:id/notes/edit";
219
223
  export const STRUCTURE_PARENTS = "/structures/:id/parents";
220
224
  export const STRUCTURE_PROFILE = "/structures/:id/profile";
221
225
  export const STRUCTURE_RULES = "/structures/:id/rules";
226
+ export const STRUCTURE_TAG_EDIT = "/structureTags/:id/edit";
222
227
  export const STRUCTURE_TAGS = "/structureTags";
223
228
  export const STRUCTURE_TAGS_NEW = "/structureTags/new";
224
- export const STRUCTURE_TAG_EDIT = "/structureTags/:id/edit";
225
229
  export const STRUCTURE_TYPES = "/structureTypes";
226
230
  export const STRUCTURE_TYPES_EDIT = "/structureTypes/:id/edit";
227
231
  export const STRUCTURE_VERSION = "/structures/:id/versions/:version";
@@ -251,6 +255,7 @@ export const USER_EDIT = "/users/:id/edit";
251
255
  export const USER_EDIT_PASSWORD = "/users/:id/password";
252
256
 
253
257
  const routes = {
258
+ AI_SANDBOX,
254
259
  CALLBACK,
255
260
  BUCKETS_VIEW,
256
261
  BUCKET_VIEW,
@@ -365,6 +370,7 @@ const routes = {
365
370
  PROFILE_EXECUTION,
366
371
  PROFILE_GROUP,
367
372
  PROMPTS,
373
+ PROVIDERS,
368
374
  QUALITY_CONTROLS,
369
375
  QUALITY_CONTROLS_DEPRECATED,
370
376
  QUALITY_CONTROLS_DRAFTS,
@@ -425,9 +431,11 @@ const routes = {
425
431
  STRUCTURE_STRUCTURE_LINKS_NEW,
426
432
  STRUCTURE_LINKS,
427
433
  STRUCTURE_LINKS_NEW,
434
+ STRUCTURE_MEMBERS_NEW,
435
+ STRUCTURE_MEMBERS,
428
436
  STRUCTURE_METADATA,
429
- STRUCTURE_NOTES,
430
437
  STRUCTURE_NOTES_EDIT,
438
+ STRUCTURE_NOTES,
431
439
  STRUCTURE_PARENTS,
432
440
  STRUCTURE_PROFILE,
433
441
  STRUCTURE_RULES,