@skopon-cool/form-sdk 0.4.4 → 0.4.5

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.4",
6
+ "version": "0.4.5",
7
7
  "description": "Skopon form rendering SDK (A2UI + form_definition) with submit helpers",
8
8
  "type": "module",
9
9
  "sideEffects": [
@@ -61,3 +61,62 @@ describe('mapFormDefinitionFromDto jsonSchema', () => {
61
61
  expect(def?.jsonSchema).toEqual(schema)
62
62
  })
63
63
  })
64
+
65
+ describe('normalizeCaseFilter flowUniqueIds', () => {
66
+ it('keeps array flowUniqueIds', () => {
67
+ const def = normalizeFormDefinition({
68
+ title: '',
69
+ description: '',
70
+ blocks: [
71
+ {
72
+ id: 'b1',
73
+ type: 'case_multiselect',
74
+ name: 'cases',
75
+ caseFilter: { flowUniqueIds: ['flow-a', 'flow-b'], pageSize: 20 },
76
+ },
77
+ ],
78
+ jsonSchema: {},
79
+ })
80
+ expect(def.blocks[0]?.caseFilter?.flowUniqueIds).toEqual(['flow-a', 'flow-b'])
81
+ })
82
+
83
+ it('parses JSON-string flowUniqueIds from n8n-style payloads', () => {
84
+ const def = normalizeFormDefinition({
85
+ title: '',
86
+ description: '',
87
+ blocks: [
88
+ {
89
+ id: 'b1',
90
+ type: 'case_multiselect',
91
+ name: 'cases',
92
+ caseFilter: {
93
+ flowUniqueIds: JSON.stringify(['flow-a', 'flow-b']) as unknown as string[],
94
+ pageSize: 20,
95
+ },
96
+ },
97
+ ],
98
+ jsonSchema: {},
99
+ })
100
+ expect(def.blocks[0]?.caseFilter?.flowUniqueIds).toEqual(['flow-a', 'flow-b'])
101
+ })
102
+
103
+ it('falls back to empty array when flowUniqueIds string is not a JSON array', () => {
104
+ const def = normalizeFormDefinition({
105
+ title: '',
106
+ description: '',
107
+ blocks: [
108
+ {
109
+ id: 'b1',
110
+ type: 'case_multiselect',
111
+ name: 'cases',
112
+ caseFilter: {
113
+ flowUniqueIds: 'not-json' as unknown as string[],
114
+ pageSize: 20,
115
+ },
116
+ },
117
+ ],
118
+ jsonSchema: {},
119
+ })
120
+ expect(def.blocks[0]?.caseFilter?.flowUniqueIds).toEqual([])
121
+ })
122
+ })
@@ -54,6 +54,20 @@ function normalizeDefaultValue(
54
54
  return String(raw)
55
55
  }
56
56
 
57
+ /** n8n 等可能把 flowUniqueIds 发成 JSON 数组字符串;解析失败则 []。 */
58
+ function normalizeFlowUniqueIds(raw: unknown): string[] {
59
+ if (Array.isArray(raw)) return raw.map(String).filter(Boolean)
60
+ if (typeof raw === 'string' && raw.trim()) {
61
+ try {
62
+ const parsed: unknown = JSON.parse(raw)
63
+ if (Array.isArray(parsed)) return parsed.map(String).filter(Boolean)
64
+ } catch {
65
+ /* ignore */
66
+ }
67
+ }
68
+ return []
69
+ }
70
+
57
71
  function normalizeCaseFilter(raw: FormCaseFilter | undefined): FormCaseFilter {
58
72
  const pageSizeRaw = typeof raw?.pageSize === 'number' ? raw.pageSize : Number(raw?.pageSize)
59
73
  const pageSize =
@@ -76,9 +90,7 @@ function normalizeCaseFilter(raw: FormCaseFilter | undefined): FormCaseFilter {
76
90
  typeof raw?.category === 'string' && raw.category.trim()
77
91
  ? raw.category.trim()
78
92
  : undefined
79
- const flowUniqueIds = Array.isArray(raw?.flowUniqueIds)
80
- ? raw.flowUniqueIds.map(String).filter(Boolean)
81
- : []
93
+ const flowUniqueIds = normalizeFlowUniqueIds(raw?.flowUniqueIds)
82
94
  return { agentKind, agentUniqueId, flowType, category, flowUniqueIds, pageSize }
83
95
  }
84
96
 
@@ -235,6 +235,43 @@ describe('intersectPayloadBlocksWithForm', () => {
235
235
  expect(result.matchedBlocks[0]?.defaultValue).toBe('hello')
236
236
  })
237
237
 
238
+ it('keeps form caseFilter when ask omits caseFilter key', () => {
239
+ const form: FormSchema = {
240
+ title: 'Form',
241
+ description: '',
242
+ blocks: [
243
+ {
244
+ id: '1',
245
+ type: 'case_multiselect',
246
+ name: 'field_aaa56f6c',
247
+ caseMinCount: 1,
248
+ caseMaxCount: 1,
249
+ caseFilter: { agentKind: 'business', flowUniqueIds: [], pageSize: 20 },
250
+ },
251
+ ],
252
+ jsonSchema: {},
253
+ }
254
+ const payloadDef = parsePayloadBlocksJson({
255
+ title: 'Ask',
256
+ blocks: [
257
+ {
258
+ id: 'p1',
259
+ type: 'case_multiselect',
260
+ name: 'field_aaa56f6c',
261
+ caseEnableRefresh: true,
262
+ },
263
+ ],
264
+ })!
265
+ const result = intersectPayloadBlocksWithForm(payloadDef, form)
266
+ expect(result.matchedBlocks[0]?.caseFilter).toMatchObject({
267
+ agentKind: 'business',
268
+ flowUniqueIds: [],
269
+ pageSize: 20,
270
+ })
271
+ expect(result.matchedBlocks[0]?.caseMinCount).toBe(1)
272
+ expect(result.matchedBlocks[0]?.caseMaxCount).toBe(1)
273
+ })
274
+
238
275
  it('overlays ask caseFilter over form caseFilter', () => {
239
276
  const form: FormSchema = {
240
277
  title: 'Form',