apaas-oapi-client 1.0.0 → 1.0.1
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.
|
@@ -47,7 +47,8 @@ export declare const OPTION_COLOR_RULES: {
|
|
|
47
47
|
readonly colorPath: "type.settings.options[].color";
|
|
48
48
|
readonly colorInput: "SDK accepts metadata color names and normalizes them to OpenAPI color codes before writing.";
|
|
49
49
|
readonly colorCodeByName: Record<"blue" | "cyan" | "green" | "yellow" | "orange" | "red" | "magenta" | "purple" | "blueMagenta" | "grey", string>;
|
|
50
|
-
readonly sourcePath: "type.settings.
|
|
50
|
+
readonly sourcePath: "type.settings.option_type";
|
|
51
|
+
readonly customSourceValue: "local";
|
|
51
52
|
readonly globalOptionPath: "type.settings.global_option_api_name";
|
|
52
53
|
};
|
|
53
54
|
};
|
package/dist/index.js
CHANGED
|
@@ -828,7 +828,8 @@ const OPTION_COLOR_RULES = {
|
|
|
828
828
|
colorPath: 'type.settings.options[].color',
|
|
829
829
|
colorInput: 'SDK accepts metadata color names and normalizes them to OpenAPI color codes before writing.',
|
|
830
830
|
colorCodeByName: OPTION_COLOR_CODE_BY_NAME,
|
|
831
|
-
sourcePath: 'type.settings.
|
|
831
|
+
sourcePath: 'type.settings.option_type',
|
|
832
|
+
customSourceValue: 'local',
|
|
832
833
|
globalOptionPath: 'type.settings.global_option_api_name'
|
|
833
834
|
}
|
|
834
835
|
};
|
|
@@ -894,7 +895,7 @@ const FIELD_SCHEMA_RULES = [
|
|
|
894
895
|
settingsExample: {
|
|
895
896
|
required: false,
|
|
896
897
|
multiple: false,
|
|
897
|
-
|
|
898
|
+
option_type: 'local',
|
|
898
899
|
global_option_api_name: '',
|
|
899
900
|
options: [
|
|
900
901
|
{
|
|
@@ -913,7 +914,7 @@ const FIELD_SCHEMA_RULES = [
|
|
|
913
914
|
}
|
|
914
915
|
]
|
|
915
916
|
},
|
|
916
|
-
notes: `Do not send create type as \`option\`. Metadata returns optionList/optionSource/globalOptionAPIName; create/update expects options
|
|
917
|
+
notes: `Do not send create type as \`option\`. Metadata returns optionList/optionSource/globalOptionAPIName; create/update expects options and UI-editable custom options require option_type=local. The SDK also accepts legacy option_source=custom or option_type=custom and sends option_type=local. The SDK accepts metadata color names and sends OpenAPI color codes (${Object.entries(OPTION_COLOR_CODE_BY_NAME).map(([name, code]) => `${name}=${code}`).join(', ')}).`
|
|
917
918
|
},
|
|
918
919
|
{
|
|
919
920
|
metadataType: 'boolean',
|
|
@@ -1118,13 +1119,18 @@ function normalizeSchemaFieldForWrite(field) {
|
|
|
1118
1119
|
if (((_b = field.type) === null || _b === void 0 ? void 0 : _b.name) !== 'enum' || !Array.isArray(settings === null || settings === void 0 ? void 0 : settings.options)) {
|
|
1119
1120
|
return { ...field };
|
|
1120
1121
|
}
|
|
1122
|
+
const normalizedSettings = { ...settings };
|
|
1123
|
+
if (normalizedSettings.option_type === 'custom' || normalizedSettings.option_source === 'custom') {
|
|
1124
|
+
normalizedSettings.option_type = 'local';
|
|
1125
|
+
delete normalizedSettings.option_source;
|
|
1126
|
+
}
|
|
1121
1127
|
return {
|
|
1122
1128
|
...field,
|
|
1123
1129
|
type: {
|
|
1124
1130
|
...field.type,
|
|
1125
1131
|
settings: {
|
|
1126
|
-
...
|
|
1127
|
-
options:
|
|
1132
|
+
...normalizedSettings,
|
|
1133
|
+
options: normalizedSettings.options.map((option) => {
|
|
1128
1134
|
if (!option || typeof option !== 'object' || !('color' in option)) {
|
|
1129
1135
|
return option;
|
|
1130
1136
|
}
|
package/package.json
CHANGED
|
@@ -94,7 +94,7 @@ blue, cyan, green, yellow, orange, red, magenta, purple, blueMagenta, grey, blue
|
|
|
94
94
|
type: {
|
|
95
95
|
name: "enum",
|
|
96
96
|
settings: {
|
|
97
|
-
|
|
97
|
+
option_type: "local",
|
|
98
98
|
global_option_api_name: "",
|
|
99
99
|
options: [
|
|
100
100
|
{ api_name: "option_x", color: "blue", active: true, label: { zh_cn: "1", en_us: "1" } }
|
|
@@ -104,6 +104,8 @@ blue, cyan, green, yellow, orange, red, magenta, purple, blueMagenta, grey, blue
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
For UI-editable custom options, use `option_type: "local"`. The SDK accepts legacy `option_source: "custom"` or `option_type: "custom"` and normalizes them to `option_type: "local"` before writing.
|
|
108
|
+
|
|
107
109
|
OpenAPI write payloads require color short codes, while metadata returns color names. The SDK normalizes these names before writing, so SDK callers can keep using `blue`, `cyan`, etc.
|
|
108
110
|
|
|
109
111
|
| Metadata color | OpenAPI write code |
|
|
@@ -76,13 +76,15 @@ Live metadata for option fields returns camelCase keys:
|
|
|
76
76
|
- Option source: `type.settings.optionSource`
|
|
77
77
|
- Global option API name: `type.settings.globalOptionAPIName`
|
|
78
78
|
|
|
79
|
-
Create/update schema payloads use
|
|
79
|
+
Create/update schema payloads use write keys:
|
|
80
80
|
|
|
81
81
|
- Type name: `enum`
|
|
82
82
|
- Options path: `type.settings.options`
|
|
83
|
-
-
|
|
83
|
+
- Custom option source: `type.settings.option_type = "local"`
|
|
84
84
|
- Global option API name: `type.settings.global_option_api_name`
|
|
85
85
|
|
|
86
|
+
For UI-editable custom options, send `option_type: "local"`. The SDK also accepts legacy `option_source: "custom"` or `option_type: "custom"` and normalizes them to `option_type: "local"` before writing.
|
|
87
|
+
|
|
86
88
|
OpenAPI write payloads require color short codes, while metadata returns color names. The SDK normalizes these metadata names before writing:
|
|
87
89
|
|
|
88
90
|
| Metadata color | OpenAPI write code |
|
|
@@ -157,7 +157,8 @@ export const OPTION_COLOR_RULES = {
|
|
|
157
157
|
colorPath: 'type.settings.options[].color',
|
|
158
158
|
colorInput: 'SDK accepts metadata color names and normalizes them to OpenAPI color codes before writing.',
|
|
159
159
|
colorCodeByName: OPTION_COLOR_CODE_BY_NAME,
|
|
160
|
-
sourcePath: 'type.settings.
|
|
160
|
+
sourcePath: 'type.settings.option_type',
|
|
161
|
+
customSourceValue: 'local',
|
|
161
162
|
globalOptionPath: 'type.settings.global_option_api_name'
|
|
162
163
|
}
|
|
163
164
|
} as const;
|
|
@@ -224,7 +225,7 @@ export const FIELD_SCHEMA_RULES: FieldCreateRule[] = [
|
|
|
224
225
|
settingsExample: {
|
|
225
226
|
required: false,
|
|
226
227
|
multiple: false,
|
|
227
|
-
|
|
228
|
+
option_type: 'local',
|
|
228
229
|
global_option_api_name: '',
|
|
229
230
|
options: [
|
|
230
231
|
{
|
|
@@ -243,7 +244,7 @@ export const FIELD_SCHEMA_RULES: FieldCreateRule[] = [
|
|
|
243
244
|
}
|
|
244
245
|
]
|
|
245
246
|
},
|
|
246
|
-
notes: `Do not send create type as \`option\`. Metadata returns optionList/optionSource/globalOptionAPIName; create/update expects options
|
|
247
|
+
notes: `Do not send create type as \`option\`. Metadata returns optionList/optionSource/globalOptionAPIName; create/update expects options and UI-editable custom options require option_type=local. The SDK also accepts legacy option_source=custom or option_type=custom and sends option_type=local. The SDK accepts metadata color names and sends OpenAPI color codes (${Object.entries(OPTION_COLOR_CODE_BY_NAME).map(([name, code]) => `${name}=${code}`).join(', ')}).`
|
|
247
248
|
},
|
|
248
249
|
{
|
|
249
250
|
metadataType: 'boolean',
|
package/src/schema-utils.ts
CHANGED
|
@@ -205,13 +205,19 @@ function normalizeSchemaFieldForWrite<T extends { type?: any }>(field: T): T {
|
|
|
205
205
|
return { ...field };
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
const normalizedSettings = { ...settings };
|
|
209
|
+
if (normalizedSettings.option_type === 'custom' || normalizedSettings.option_source === 'custom') {
|
|
210
|
+
normalizedSettings.option_type = 'local';
|
|
211
|
+
delete normalizedSettings.option_source;
|
|
212
|
+
}
|
|
213
|
+
|
|
208
214
|
return {
|
|
209
215
|
...field,
|
|
210
216
|
type: {
|
|
211
217
|
...field.type,
|
|
212
218
|
settings: {
|
|
213
|
-
...
|
|
214
|
-
options:
|
|
219
|
+
...normalizedSettings,
|
|
220
|
+
options: normalizedSettings.options.map((option: any) => {
|
|
215
221
|
if (!option || typeof option !== 'object' || !('color' in option)) {
|
|
216
222
|
return option;
|
|
217
223
|
}
|