@terminalfour/terminalfour-js 1.0.0 → 1.0.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.
@@ -239,10 +239,29 @@ export declare class ContentTypeResource {
239
239
  maxRepeats?: number;
240
240
  };
241
241
  }>;
242
+ /**
243
+ * Existing fields to modify, matched by `name`. Only the provided
244
+ * properties are changed; omitted ones are left as-is. Use this to change
245
+ * an element's length (`maxSize`), description, or its `required`/`shown`
246
+ * flags. Throws if a named field does not exist on the content type.
247
+ */
248
+ updateFields?: Array<{
249
+ name: string;
250
+ maxSize?: number;
251
+ description?: string;
252
+ required?: boolean;
253
+ shown?: boolean;
254
+ }>;
242
255
  /** Field names to remove from the content type */
243
256
  removeFields?: string[];
244
257
  }): Promise<ContentType>;
245
- /** Deletes a content type by ID. */
258
+ /**
259
+ * Deletes a content type by ID.
260
+ *
261
+ * System content types (`type === 30`) are managed by T4 and back core
262
+ * features; deleting one can break the instance, so this is blocked with a
263
+ * clear error. There is no override.
264
+ */
246
265
  delete(id: number): Promise<void>;
247
266
  /** Creates a new content type. */
248
267
  create(data: {
@@ -809,6 +809,22 @@ class ContentTypeResource {
809
809
  ct.sharedGroups = data.sharedGroups;
810
810
  if (data.primaryGroup !== undefined)
811
811
  ct.primaryGroup = data.primaryGroup;
812
+ if (data.updateFields) {
813
+ for (const change of data.updateFields) {
814
+ const field = ct.fields[change.name];
815
+ if (!field) {
816
+ throw new Error(`Cannot update field "${change.name}" because it does not exist on content type "${ct.name}".`);
817
+ }
818
+ if (change.maxSize !== undefined)
819
+ field.maxSize = change.maxSize;
820
+ if (change.description !== undefined)
821
+ field.description = change.description;
822
+ if (change.required !== undefined)
823
+ field.required = change.required;
824
+ if (change.shown !== undefined)
825
+ field.shown = change.shown;
826
+ }
827
+ }
812
828
  if (data.removeFields) {
813
829
  for (const fieldName of data.removeFields) {
814
830
  ct.removeField(fieldName);
@@ -822,8 +838,23 @@ class ContentTypeResource {
822
838
  await ct.save();
823
839
  return ct;
824
840
  }
825
- /** Deletes a content type by ID. */
841
+ /**
842
+ * Deletes a content type by ID.
843
+ *
844
+ * System content types (`type === 30`) are managed by T4 and back core
845
+ * features; deleting one can break the instance, so this is blocked with a
846
+ * clear error. There is no override.
847
+ */
826
848
  async delete(id) {
849
+ const raw = await this.httpClient.request({
850
+ method: 'GET',
851
+ path: `/contenttype/${id}`,
852
+ });
853
+ if (raw.type === SYSTEM_CONTENT_TYPE) {
854
+ const name = (0, utils_js_1.decodeHtmlEntities)(raw.alias || raw.name);
855
+ throw new Error(`Cannot delete content type "${name}" (${id}) because it is a system content type. ` +
856
+ 'Deleting system content types is not allowed.');
857
+ }
827
858
  await this.httpClient.request({
828
859
  method: 'DELETE',
829
860
  path: `/contenttype/${id}`,
@@ -239,10 +239,29 @@ export declare class ContentTypeResource {
239
239
  maxRepeats?: number;
240
240
  };
241
241
  }>;
242
+ /**
243
+ * Existing fields to modify, matched by `name`. Only the provided
244
+ * properties are changed; omitted ones are left as-is. Use this to change
245
+ * an element's length (`maxSize`), description, or its `required`/`shown`
246
+ * flags. Throws if a named field does not exist on the content type.
247
+ */
248
+ updateFields?: Array<{
249
+ name: string;
250
+ maxSize?: number;
251
+ description?: string;
252
+ required?: boolean;
253
+ shown?: boolean;
254
+ }>;
242
255
  /** Field names to remove from the content type */
243
256
  removeFields?: string[];
244
257
  }): Promise<ContentType>;
245
- /** Deletes a content type by ID. */
258
+ /**
259
+ * Deletes a content type by ID.
260
+ *
261
+ * System content types (`type === 30`) are managed by T4 and back core
262
+ * features; deleting one can break the instance, so this is blocked with a
263
+ * clear error. There is no override.
264
+ */
246
265
  delete(id: number): Promise<void>;
247
266
  /** Creates a new content type. */
248
267
  create(data: {
@@ -804,6 +804,22 @@ export class ContentTypeResource {
804
804
  ct.sharedGroups = data.sharedGroups;
805
805
  if (data.primaryGroup !== undefined)
806
806
  ct.primaryGroup = data.primaryGroup;
807
+ if (data.updateFields) {
808
+ for (const change of data.updateFields) {
809
+ const field = ct.fields[change.name];
810
+ if (!field) {
811
+ throw new Error(`Cannot update field "${change.name}" because it does not exist on content type "${ct.name}".`);
812
+ }
813
+ if (change.maxSize !== undefined)
814
+ field.maxSize = change.maxSize;
815
+ if (change.description !== undefined)
816
+ field.description = change.description;
817
+ if (change.required !== undefined)
818
+ field.required = change.required;
819
+ if (change.shown !== undefined)
820
+ field.shown = change.shown;
821
+ }
822
+ }
807
823
  if (data.removeFields) {
808
824
  for (const fieldName of data.removeFields) {
809
825
  ct.removeField(fieldName);
@@ -817,8 +833,23 @@ export class ContentTypeResource {
817
833
  await ct.save();
818
834
  return ct;
819
835
  }
820
- /** Deletes a content type by ID. */
836
+ /**
837
+ * Deletes a content type by ID.
838
+ *
839
+ * System content types (`type === 30`) are managed by T4 and back core
840
+ * features; deleting one can break the instance, so this is blocked with a
841
+ * clear error. There is no override.
842
+ */
821
843
  async delete(id) {
844
+ const raw = await this.httpClient.request({
845
+ method: 'GET',
846
+ path: `/contenttype/${id}`,
847
+ });
848
+ if (raw.type === SYSTEM_CONTENT_TYPE) {
849
+ const name = decodeHtmlEntities(raw.alias || raw.name);
850
+ throw new Error(`Cannot delete content type "${name}" (${id}) because it is a system content type. ` +
851
+ 'Deleting system content types is not allowed.');
852
+ }
822
853
  await this.httpClient.request({
823
854
  method: 'DELETE',
824
855
  path: `/contenttype/${id}`,
@@ -167,6 +167,21 @@ await t4.contentTypes.update(44, {
167
167
  });
168
168
  ```
169
169
 
170
+ Change properties of existing fields with `updateFields`. Fields are matched by `name`, and only the properties you supply are changed — anything you omit is left as-is. This is how you increase an element's length (`maxSize`):
171
+
172
+ ```typescript
173
+ await t4.contentTypes.update(44, {
174
+ updateFields: [
175
+ { name: 'Title', maxSize: 500 },
176
+ { name: 'Summary', description: 'Short teaser', required: true, shown: false },
177
+ ],
178
+ });
179
+ ```
180
+
181
+ `updateFields` can change `maxSize`, `description`, `required`, and `shown`. It throws if a named field does not exist on the content type, and (like the other field operations) nothing is sent to T4 when it throws. To change a field's *type* or *name*, remove it and add a new one instead.
182
+
183
+ `updateFields`, `removeFields`, and `addFields` can be combined in a single call; updates are applied first, then removals, then additions.
184
+
170
185
  ### Mutable item
171
186
 
172
187
  ```typescript
@@ -231,6 +246,8 @@ Delete a content type through the resource:
231
246
  await t4.contentTypes.delete(44);
232
247
  ```
233
248
 
249
+ System content types cannot be deleted — see [System content types](#system-content-types) below.
250
+
234
251
  ## System content types
235
252
 
236
253
  System content types are managed by T4 and back core features. Removing or renaming their elements can break the instance, so the SDK blocks both on `save()` (and through `update({ removeFields })`):
@@ -249,10 +266,22 @@ On a system content type you can still:
249
266
  - Change an element's `maxSize`
250
267
  - Change the content type's `description` and any element's `description`
251
268
 
252
- Two system content types are exempt, because removing and renaming their elements is safe: the **Section Metadata** content type and the **Extended User** content type. On those two, removal and renaming work exactly like a regular content type.
269
+ Two system content types are exempt from the element removal and renaming guard, because removing and renaming their elements is safe: the **Section Metadata** content type and the **Extended User** content type. On those two, removal and renaming work exactly like a regular content type.
253
270
 
254
271
  The check runs when you call `save()` or `update()`, not when you call `removeField()`. Because `removeField()` only stages the change in memory, nothing is sent to T4 when the guard blocks a save.
255
272
 
273
+ ### Deleting a system content type is always blocked
274
+
275
+ `delete()` refuses to delete **any** system content type, with no exceptions. Deleting a system content type outright (rather than editing its elements) can break instance-wide features, so there is no override:
276
+
277
+ ```typescript
278
+ await t4.contentTypes.delete(systemTypeId);
279
+ // Error: Cannot delete content type "..." (<id>) because it is a system
280
+ // content type. Deleting system content types is not allowed.
281
+ ```
282
+
283
+ `delete()` fetches the content type first to check its type; if it is a system content type, nothing is deleted.
284
+
256
285
  ## Manage content layouts
257
286
 
258
287
  Access layouts through `layouts` on a `ContentType`. Layout operations use names; layout IDs are not exposed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terminalfour/terminalfour-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "JavaScript / TypeScript SDK for the Terminalfour Web Services REST API",
5
5
  "keywords": [
6
6
  "terminalfour",
@@ -59,7 +59,7 @@
59
59
  "@types/node": "^25.5.2",
60
60
  "fast-check": "^4.1.1",
61
61
  "typescript": "^5.7.0",
62
- "vitest": "^3.2.1"
62
+ "vitest": "^5.0.0"
63
63
  },
64
64
  "license": "Elastic-2.0"
65
65
  }