@decoupla/sdk 0.1.1 → 0.1.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.
- package/dist/cli/index.cjs +104 -2
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +104 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +104 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -8280,6 +8280,8 @@ function buildCreateFieldRequest(modelId, fieldName, fieldDef) {
|
|
|
8280
8280
|
control,
|
|
8281
8281
|
required: fieldDef.required ?? false,
|
|
8282
8282
|
description: (_b = fieldDef.settings) == null ? void 0 : _b.description,
|
|
8283
|
+
is_label: fieldDef.isLabel ?? false,
|
|
8284
|
+
options: fieldDef.options,
|
|
8283
8285
|
meta: Object.keys(meta).length > 0 ? meta : void 0
|
|
8284
8286
|
};
|
|
8285
8287
|
}
|
|
@@ -8297,6 +8299,12 @@ function buildUpdateFieldRequest(fieldId, changes) {
|
|
|
8297
8299
|
if (changes.description !== void 0) {
|
|
8298
8300
|
request.description = changes.description;
|
|
8299
8301
|
}
|
|
8302
|
+
if (changes.isLabel !== void 0) {
|
|
8303
|
+
request.is_label = !!changes.isLabel;
|
|
8304
|
+
}
|
|
8305
|
+
if (changes.options !== void 0) {
|
|
8306
|
+
request.options = changes.options;
|
|
8307
|
+
}
|
|
8300
8308
|
if (changes.references !== void 0) {
|
|
8301
8309
|
request.meta = { ...changes.meta || {}, reference_types: changes.references };
|
|
8302
8310
|
} else if (changes.meta !== void 0) {
|
|
@@ -9155,7 +9163,7 @@ var normalizeEntryMetadata = (entry) => ({
|
|
|
9155
9163
|
updatedAt: entry.updated_at
|
|
9156
9164
|
});
|
|
9157
9165
|
var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam) => {
|
|
9158
|
-
var _a;
|
|
9166
|
+
var _a, _b, _c;
|
|
9159
9167
|
const { apiToken, workspace } = options;
|
|
9160
9168
|
const opts = typeof optionsParam === "boolean" ? { published: optionsParam } : optionsParam || {};
|
|
9161
9169
|
const published = opts.published ?? true;
|
|
@@ -9164,6 +9172,100 @@ var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam)
|
|
|
9164
9172
|
throw new Error(validation.error || "Invalid field values");
|
|
9165
9173
|
}
|
|
9166
9174
|
const normalizedFieldValues = normalizeFieldValues(fieldValues);
|
|
9175
|
+
try {
|
|
9176
|
+
const fieldDefs = ((_a = contentTypeDef.__definition) == null ? void 0 : _a.fields) || {};
|
|
9177
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
9178
|
+
for (const defKey of Object.keys(fieldDefs)) {
|
|
9179
|
+
keyMap.set(defKey, defKey);
|
|
9180
|
+
try {
|
|
9181
|
+
keyMap.set(camelToSnake(defKey), defKey);
|
|
9182
|
+
} catch (e) {
|
|
9183
|
+
}
|
|
9184
|
+
try {
|
|
9185
|
+
keyMap.set(snakeToCamel(camelToSnake(defKey)), defKey);
|
|
9186
|
+
} catch (e) {
|
|
9187
|
+
}
|
|
9188
|
+
}
|
|
9189
|
+
for (const [k, v] of Object.entries(normalizedFieldValues)) {
|
|
9190
|
+
const defKey = keyMap.get(k) || void 0;
|
|
9191
|
+
if (!defKey)
|
|
9192
|
+
continue;
|
|
9193
|
+
const fdef = fieldDefs[defKey];
|
|
9194
|
+
if (!fdef)
|
|
9195
|
+
continue;
|
|
9196
|
+
if (fdef.type === "date") {
|
|
9197
|
+
const toDateOnly = (val) => {
|
|
9198
|
+
if (val instanceof Date) {
|
|
9199
|
+
const y = val.getFullYear();
|
|
9200
|
+
const m = String(val.getMonth() + 1).padStart(2, "0");
|
|
9201
|
+
const d = String(val.getDate()).padStart(2, "0");
|
|
9202
|
+
return `${y}-${m}-${d}`;
|
|
9203
|
+
}
|
|
9204
|
+
if (typeof val === "string") {
|
|
9205
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(val))
|
|
9206
|
+
return val;
|
|
9207
|
+
const parsed = new Date(val);
|
|
9208
|
+
if (!isNaN(parsed.getTime())) {
|
|
9209
|
+
const y = parsed.getFullYear();
|
|
9210
|
+
const m = String(parsed.getMonth() + 1).padStart(2, "0");
|
|
9211
|
+
const d = String(parsed.getDate()).padStart(2, "0");
|
|
9212
|
+
return `${y}-${m}-${d}`;
|
|
9213
|
+
}
|
|
9214
|
+
}
|
|
9215
|
+
return val;
|
|
9216
|
+
};
|
|
9217
|
+
normalizedFieldValues[k] = toDateOnly(v);
|
|
9218
|
+
}
|
|
9219
|
+
}
|
|
9220
|
+
} catch (e) {
|
|
9221
|
+
}
|
|
9222
|
+
try {
|
|
9223
|
+
const fieldDefs = ((_b = contentTypeDef.__definition) == null ? void 0 : _b.fields) || {};
|
|
9224
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
9225
|
+
for (const defKey of Object.keys(fieldDefs)) {
|
|
9226
|
+
keyMap.set(defKey, defKey);
|
|
9227
|
+
try {
|
|
9228
|
+
keyMap.set(camelToSnake(defKey), defKey);
|
|
9229
|
+
} catch (e) {
|
|
9230
|
+
}
|
|
9231
|
+
try {
|
|
9232
|
+
keyMap.set(snakeToCamel(camelToSnake(defKey)), defKey);
|
|
9233
|
+
} catch (e) {
|
|
9234
|
+
}
|
|
9235
|
+
}
|
|
9236
|
+
for (const [k, v] of Object.entries(normalizedFieldValues)) {
|
|
9237
|
+
const defKey = keyMap.get(k) || keyMap.get(k) || void 0;
|
|
9238
|
+
if (!defKey)
|
|
9239
|
+
continue;
|
|
9240
|
+
const fdef = fieldDefs[defKey];
|
|
9241
|
+
if (!fdef)
|
|
9242
|
+
continue;
|
|
9243
|
+
if (fdef.type === "date") {
|
|
9244
|
+
const toDateOnly = (val) => {
|
|
9245
|
+
if (val instanceof Date) {
|
|
9246
|
+
const y = val.getFullYear();
|
|
9247
|
+
const m = String(val.getMonth() + 1).padStart(2, "0");
|
|
9248
|
+
const d = String(val.getDate()).padStart(2, "0");
|
|
9249
|
+
return `${y}-${m}-${d}`;
|
|
9250
|
+
}
|
|
9251
|
+
if (typeof val === "string") {
|
|
9252
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(val))
|
|
9253
|
+
return val;
|
|
9254
|
+
const parsed = new Date(val);
|
|
9255
|
+
if (!isNaN(parsed.getTime())) {
|
|
9256
|
+
const y = parsed.getFullYear();
|
|
9257
|
+
const m = String(parsed.getMonth() + 1).padStart(2, "0");
|
|
9258
|
+
const d = String(parsed.getDate()).padStart(2, "0");
|
|
9259
|
+
return `${y}-${m}-${d}`;
|
|
9260
|
+
}
|
|
9261
|
+
}
|
|
9262
|
+
return val;
|
|
9263
|
+
};
|
|
9264
|
+
normalizedFieldValues[k] = toDateOnly(v);
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
9267
|
+
} catch (e) {
|
|
9268
|
+
}
|
|
9167
9269
|
const normalizePreload = (p) => {
|
|
9168
9270
|
if (!Array.isArray(p))
|
|
9169
9271
|
return p;
|
|
@@ -9222,7 +9324,7 @@ var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam)
|
|
|
9222
9324
|
throw new Error(`Failed to create entry: ${errorMessages}`);
|
|
9223
9325
|
}
|
|
9224
9326
|
const createResponse = respData;
|
|
9225
|
-
const entry = (
|
|
9327
|
+
const entry = (_c = createResponse.data) == null ? void 0 : _c.entry;
|
|
9226
9328
|
if (!entry) {
|
|
9227
9329
|
throw new Error(
|
|
9228
9330
|
`Failed to create entry: Content type "${contentTypeDef.__definition.name}" returned null. This typically means the content type has no fields defined. Please add at least one field to the content type before creating entries.`
|