@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.
@@ -8299,6 +8299,8 @@ function buildCreateFieldRequest(modelId, fieldName, fieldDef) {
8299
8299
  control,
8300
8300
  required: fieldDef.required ?? false,
8301
8301
  description: (_b = fieldDef.settings) == null ? void 0 : _b.description,
8302
+ is_label: fieldDef.isLabel ?? false,
8303
+ options: fieldDef.options,
8302
8304
  meta: Object.keys(meta).length > 0 ? meta : void 0
8303
8305
  };
8304
8306
  }
@@ -8316,6 +8318,12 @@ function buildUpdateFieldRequest(fieldId, changes) {
8316
8318
  if (changes.description !== void 0) {
8317
8319
  request.description = changes.description;
8318
8320
  }
8321
+ if (changes.isLabel !== void 0) {
8322
+ request.is_label = !!changes.isLabel;
8323
+ }
8324
+ if (changes.options !== void 0) {
8325
+ request.options = changes.options;
8326
+ }
8319
8327
  if (changes.references !== void 0) {
8320
8328
  request.meta = { ...changes.meta || {}, reference_types: changes.references };
8321
8329
  } else if (changes.meta !== void 0) {
@@ -9174,7 +9182,7 @@ var normalizeEntryMetadata = (entry) => ({
9174
9182
  updatedAt: entry.updated_at
9175
9183
  });
9176
9184
  var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam) => {
9177
- var _a;
9185
+ var _a, _b, _c;
9178
9186
  const { apiToken, workspace } = options;
9179
9187
  const opts = typeof optionsParam === "boolean" ? { published: optionsParam } : optionsParam || {};
9180
9188
  const published = opts.published ?? true;
@@ -9183,6 +9191,100 @@ var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam)
9183
9191
  throw new Error(validation.error || "Invalid field values");
9184
9192
  }
9185
9193
  const normalizedFieldValues = normalizeFieldValues(fieldValues);
9194
+ try {
9195
+ const fieldDefs = ((_a = contentTypeDef.__definition) == null ? void 0 : _a.fields) || {};
9196
+ const keyMap = /* @__PURE__ */ new Map();
9197
+ for (const defKey of Object.keys(fieldDefs)) {
9198
+ keyMap.set(defKey, defKey);
9199
+ try {
9200
+ keyMap.set(camelToSnake(defKey), defKey);
9201
+ } catch (e) {
9202
+ }
9203
+ try {
9204
+ keyMap.set(snakeToCamel(camelToSnake(defKey)), defKey);
9205
+ } catch (e) {
9206
+ }
9207
+ }
9208
+ for (const [k, v] of Object.entries(normalizedFieldValues)) {
9209
+ const defKey = keyMap.get(k) || void 0;
9210
+ if (!defKey)
9211
+ continue;
9212
+ const fdef = fieldDefs[defKey];
9213
+ if (!fdef)
9214
+ continue;
9215
+ if (fdef.type === "date") {
9216
+ const toDateOnly = (val) => {
9217
+ if (val instanceof Date) {
9218
+ const y = val.getFullYear();
9219
+ const m = String(val.getMonth() + 1).padStart(2, "0");
9220
+ const d = String(val.getDate()).padStart(2, "0");
9221
+ return `${y}-${m}-${d}`;
9222
+ }
9223
+ if (typeof val === "string") {
9224
+ if (/^\d{4}-\d{2}-\d{2}$/.test(val))
9225
+ return val;
9226
+ const parsed = new Date(val);
9227
+ if (!isNaN(parsed.getTime())) {
9228
+ const y = parsed.getFullYear();
9229
+ const m = String(parsed.getMonth() + 1).padStart(2, "0");
9230
+ const d = String(parsed.getDate()).padStart(2, "0");
9231
+ return `${y}-${m}-${d}`;
9232
+ }
9233
+ }
9234
+ return val;
9235
+ };
9236
+ normalizedFieldValues[k] = toDateOnly(v);
9237
+ }
9238
+ }
9239
+ } catch (e) {
9240
+ }
9241
+ try {
9242
+ const fieldDefs = ((_b = contentTypeDef.__definition) == null ? void 0 : _b.fields) || {};
9243
+ const keyMap = /* @__PURE__ */ new Map();
9244
+ for (const defKey of Object.keys(fieldDefs)) {
9245
+ keyMap.set(defKey, defKey);
9246
+ try {
9247
+ keyMap.set(camelToSnake(defKey), defKey);
9248
+ } catch (e) {
9249
+ }
9250
+ try {
9251
+ keyMap.set(snakeToCamel(camelToSnake(defKey)), defKey);
9252
+ } catch (e) {
9253
+ }
9254
+ }
9255
+ for (const [k, v] of Object.entries(normalizedFieldValues)) {
9256
+ const defKey = keyMap.get(k) || keyMap.get(k) || void 0;
9257
+ if (!defKey)
9258
+ continue;
9259
+ const fdef = fieldDefs[defKey];
9260
+ if (!fdef)
9261
+ continue;
9262
+ if (fdef.type === "date") {
9263
+ const toDateOnly = (val) => {
9264
+ if (val instanceof Date) {
9265
+ const y = val.getFullYear();
9266
+ const m = String(val.getMonth() + 1).padStart(2, "0");
9267
+ const d = String(val.getDate()).padStart(2, "0");
9268
+ return `${y}-${m}-${d}`;
9269
+ }
9270
+ if (typeof val === "string") {
9271
+ if (/^\d{4}-\d{2}-\d{2}$/.test(val))
9272
+ return val;
9273
+ const parsed = new Date(val);
9274
+ if (!isNaN(parsed.getTime())) {
9275
+ const y = parsed.getFullYear();
9276
+ const m = String(parsed.getMonth() + 1).padStart(2, "0");
9277
+ const d = String(parsed.getDate()).padStart(2, "0");
9278
+ return `${y}-${m}-${d}`;
9279
+ }
9280
+ }
9281
+ return val;
9282
+ };
9283
+ normalizedFieldValues[k] = toDateOnly(v);
9284
+ }
9285
+ }
9286
+ } catch (e) {
9287
+ }
9186
9288
  const normalizePreload = (p) => {
9187
9289
  if (!Array.isArray(p))
9188
9290
  return p;
@@ -9241,7 +9343,7 @@ var createEntry = (options) => async (contentTypeDef, fieldValues, optionsParam)
9241
9343
  throw new Error(`Failed to create entry: ${errorMessages}`);
9242
9344
  }
9243
9345
  const createResponse = respData;
9244
- const entry = (_a = createResponse.data) == null ? void 0 : _a.entry;
9346
+ const entry = (_c = createResponse.data) == null ? void 0 : _c.entry;
9245
9347
  if (!entry) {
9246
9348
  throw new Error(
9247
9349
  `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.`