nucleus-core-ts 0.9.792 → 0.9.793
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/fe/components/IntegrationsPage/components/MappingsTab.js +36 -2
- package/dist/fe/components/IntegrationsPage/components/formSupport.d.ts +11 -6
- package/dist/fe/components/IntegrationsPage/components/formSupport.js +37 -1
- package/dist/fe/components/IntegrationsPage/components/formSupport.test.js +98 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useEffect, useEffectEvent, useState } from 'react';
|
|
4
4
|
import { useIntegrationsStore } from '../store';
|
|
5
5
|
import { integrationsPageTheme } from '../theme';
|
|
6
|
+
import { fieldsOfStoredSample } from './formSupport';
|
|
6
7
|
import { MappingEditor } from './MappingEditor';
|
|
7
8
|
import { MappingList } from './MappingList';
|
|
8
9
|
import { blankMappingDraft, toMappingDraft } from './mappingDraft';
|
|
@@ -42,6 +43,32 @@ export function MappingsTab({ actions }) {
|
|
|
42
43
|
useEffect(()=>{
|
|
43
44
|
loadTargets();
|
|
44
45
|
}, []);
|
|
46
|
+
/**
|
|
47
|
+
* The connection's endpoints, when nothing has fetched them yet.
|
|
48
|
+
*
|
|
49
|
+
* `store.endpoints` is filled by the Endpoints tab, so opening a connection
|
|
50
|
+
* and going straight to Mappings met "No endpoints on this connection yet"
|
|
51
|
+
* and a disabled New mapping — about a connection with three of them. The
|
|
52
|
+
* only way through was to visit the other tab first, which nothing said.
|
|
53
|
+
*
|
|
54
|
+
* One page is enough to offer a source and to name one; the Endpoints tab
|
|
55
|
+
* remains the place that pages through them all.
|
|
56
|
+
*/ const loadEndpointsIfMissing = useEffectEvent(()=>{
|
|
57
|
+
if (sourceId === '' || store.endpoints.length > 0) return;
|
|
58
|
+
actions.listEndpoints(sourceId, {
|
|
59
|
+
page: 1,
|
|
60
|
+
limit: 50
|
|
61
|
+
}).then((result)=>{
|
|
62
|
+
store.setEndpoints(result.items, result.meta?.totalItems ?? result.items.length);
|
|
63
|
+
}).catch((error)=>{
|
|
64
|
+
store.setError(messageOf(error));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
useEffect(()=>{
|
|
68
|
+
loadEndpointsIfMissing();
|
|
69
|
+
}, [
|
|
70
|
+
sourceId
|
|
71
|
+
]);
|
|
45
72
|
const startNew = ()=>{
|
|
46
73
|
setSelected(null);
|
|
47
74
|
setCreating(true);
|
|
@@ -88,8 +115,15 @@ export function MappingsTab({ actions }) {
|
|
|
88
115
|
};
|
|
89
116
|
const draft = creating ? blankMappingDraft(newMappingEndpointId) : selected ? toMappingDraft(selected) : null;
|
|
90
117
|
// A sample describes ONE endpoint. Offering its field names against a mapping
|
|
91
|
-
// that reads from a different one would suggest columns that never arrive
|
|
92
|
-
|
|
118
|
+
// that reads from a different one would suggest columns that never arrive —
|
|
119
|
+
// so both the in-session sample and the stored one are matched to the
|
|
120
|
+
// mapping's OWN endpoint, never to whatever happens to be selected elsewhere.
|
|
121
|
+
//
|
|
122
|
+
// The stored sample is the fallback rather than an afterthought: it is why the
|
|
123
|
+
// sample is persisted at all. Reading only the in-session one meant a
|
|
124
|
+
// connection revisited tomorrow claimed it had never been sampled.
|
|
125
|
+
const draftEndpoint = draft ? store.endpoints.find((e)=>e.id === draft.endpointId) : undefined;
|
|
126
|
+
const sourceFields = draft && store.selectedEndpointId === draft.endpointId && store.sample?.fields?.length ? store.sample.fields : fieldsOfStoredSample(draftEndpoint?.sampleResponse);
|
|
93
127
|
return /*#__PURE__*/ _jsxs("section", {
|
|
94
128
|
className: "flex flex-col gap-4",
|
|
95
129
|
children: [
|
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { IntegrationEndpoint } from '../types';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The field names an endpoint's STORED sample reports.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* A sample is persisted on the endpoint precisely so the field list survives a
|
|
9
|
+
* reload, but the mapping editor was reading only the sample taken in this
|
|
10
|
+
* browser session. Come back to a connection tomorrow and it said "sample the
|
|
11
|
+
* endpoint first" about an endpoint it had already sampled and saved — so the
|
|
12
|
+
* source names had to be typed from memory, which is the one thing the sample
|
|
13
|
+
* exists to prevent.
|
|
14
|
+
*
|
|
15
|
+
* Mirrors the engine's `flattenKeys` rather than calling it: that lives in the
|
|
16
|
+
* server bundle, which this kit cannot import.
|
|
13
17
|
*/
|
|
18
|
+
export declare function fieldsOfStoredSample(sample: IntegrationEndpoint['sampleResponse']): string[];
|
|
14
19
|
export declare function endpointLabel(endpoint: IntegrationEndpoint): string;
|
|
15
20
|
/**
|
|
16
21
|
* The ids a control should point `aria-describedby` at.
|
|
@@ -8,7 +8,43 @@
|
|
|
8
8
|
* three identical options and no way to tell which one supplied the value.
|
|
9
9
|
* The name is what distinguishes them; the path is what distinguishes them when
|
|
10
10
|
* nobody typed a name, since it is the one field that cannot be blank.
|
|
11
|
-
*/
|
|
11
|
+
*/ /** Same caps as the engine's `flattenKeys`: this feeds a dropdown, not an analysis. */ const MAX_FIELDS_LISTED = 200;
|
|
12
|
+
const MAX_FIELD_DEPTH = 4;
|
|
13
|
+
function walkKeys(value, prefix, out, depth) {
|
|
14
|
+
if (out.length > MAX_FIELDS_LISTED || depth > MAX_FIELD_DEPTH) return out;
|
|
15
|
+
if (value == null || typeof value !== 'object') return out;
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
if (prefix) out.push(prefix);
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
for (const [key, child] of Object.entries(value)){
|
|
21
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
22
|
+
if (child != null && typeof child === 'object' && !Array.isArray(child)) {
|
|
23
|
+
walkKeys(child, path, out, depth + 1);
|
|
24
|
+
} else {
|
|
25
|
+
out.push(path);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The field names an endpoint's STORED sample reports.
|
|
32
|
+
*
|
|
33
|
+
* A sample is persisted on the endpoint precisely so the field list survives a
|
|
34
|
+
* reload, but the mapping editor was reading only the sample taken in this
|
|
35
|
+
* browser session. Come back to a connection tomorrow and it said "sample the
|
|
36
|
+
* endpoint first" about an endpoint it had already sampled and saved — so the
|
|
37
|
+
* source names had to be typed from memory, which is the one thing the sample
|
|
38
|
+
* exists to prevent.
|
|
39
|
+
*
|
|
40
|
+
* Mirrors the engine's `flattenKeys` rather than calling it: that lives in the
|
|
41
|
+
* server bundle, which this kit cannot import.
|
|
42
|
+
*/ export function fieldsOfStoredSample(sample) {
|
|
43
|
+
const first = sample?.records?.[0];
|
|
44
|
+
if (!first || typeof first !== 'object') return [];
|
|
45
|
+
return walkKeys(first, '', [], 0);
|
|
46
|
+
}
|
|
47
|
+
export function endpointLabel(endpoint) {
|
|
12
48
|
const name = endpoint.name?.trim();
|
|
13
49
|
if (name) return name;
|
|
14
50
|
const path = endpoint.path?.trim();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
import { describedBy, endpointLabel, errorText } from './formSupport';
|
|
2
|
+
import { describedBy, endpointLabel, errorText, fieldsOfStoredSample } from './formSupport';
|
|
3
3
|
const endpoint = (over)=>({
|
|
4
4
|
id: 'e1',
|
|
5
5
|
sourceId: 's1',
|
|
@@ -38,6 +38,103 @@ const endpoint = (over)=>({
|
|
|
38
38
|
}))).toBe('corporate-portal');
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
+
/**
|
|
42
|
+
* The sample is persisted on the endpoint so the field list survives a reload.
|
|
43
|
+
* The mapping editor was reading only the sample taken in the current browser
|
|
44
|
+
* session, so a connection revisited later said "sample the endpoint first"
|
|
45
|
+
* about an endpoint it had already sampled and stored.
|
|
46
|
+
*/ describe('fieldsOfStoredSample', ()=>{
|
|
47
|
+
test('reads the field names off the stored first record', ()=>{
|
|
48
|
+
const fields = fieldsOfStoredSample({
|
|
49
|
+
records: [
|
|
50
|
+
{
|
|
51
|
+
companyCode: 'TAT',
|
|
52
|
+
companyName: 'TATMETAL ÇELİK SAN. VE TİC.A.Ş.',
|
|
53
|
+
organizationCode: '010',
|
|
54
|
+
organizationName: 'YÖNETİM KURULU',
|
|
55
|
+
parentOrganizationCode: '*'
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
expect(fields).toEqual([
|
|
60
|
+
'companyCode',
|
|
61
|
+
'companyName',
|
|
62
|
+
'organizationCode',
|
|
63
|
+
'organizationName',
|
|
64
|
+
'parentOrganizationCode'
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
test('nested objects become dot-paths, the way the engine reports them', ()=>{
|
|
68
|
+
const fields = fieldsOfStoredSample({
|
|
69
|
+
records: [
|
|
70
|
+
{
|
|
71
|
+
a: 1,
|
|
72
|
+
b: {
|
|
73
|
+
c: 2,
|
|
74
|
+
d: {
|
|
75
|
+
e: 3
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
expect(fields).toEqual([
|
|
82
|
+
'a',
|
|
83
|
+
'b.c',
|
|
84
|
+
'b.d.e'
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
test('an array is a leaf — its contents are a shape, not a field name', ()=>{
|
|
88
|
+
const fields = fieldsOfStoredSample({
|
|
89
|
+
records: [
|
|
90
|
+
{
|
|
91
|
+
organizationName: 'GENEL MÜDÜRLÜK',
|
|
92
|
+
subOrganization: [
|
|
93
|
+
{
|
|
94
|
+
x: 1
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
expect(fields).toEqual([
|
|
101
|
+
'organizationName',
|
|
102
|
+
'subOrganization'
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
test('nothing stored yields nothing, rather than throwing', ()=>{
|
|
106
|
+
expect(fieldsOfStoredSample(null)).toEqual([]);
|
|
107
|
+
expect(fieldsOfStoredSample(undefined)).toEqual([]);
|
|
108
|
+
expect(fieldsOfStoredSample({
|
|
109
|
+
records: []
|
|
110
|
+
})).toEqual([]);
|
|
111
|
+
expect(fieldsOfStoredSample({
|
|
112
|
+
records: [
|
|
113
|
+
'not an object'
|
|
114
|
+
]
|
|
115
|
+
})).toEqual([]);
|
|
116
|
+
});
|
|
117
|
+
test('depth is capped, so a deep document cannot flood the picker', ()=>{
|
|
118
|
+
const deep = {
|
|
119
|
+
l1: {
|
|
120
|
+
l2: {
|
|
121
|
+
l3: {
|
|
122
|
+
l4: {
|
|
123
|
+
l5: {
|
|
124
|
+
l6: 'too far'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
expect(fieldsOfStoredSample({
|
|
132
|
+
records: [
|
|
133
|
+
deep
|
|
134
|
+
]
|
|
135
|
+
})).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
41
138
|
describe('describedBy', ()=>{
|
|
42
139
|
test('names only the ids that were rendered', ()=>{
|
|
43
140
|
expect(describedBy('f', true, true)).toBe('f-hint f-error');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.793",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|