@tridion-sites/models 0.1.3 → 1.0.0

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/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # Tridion Sites models for Extensions
2
+
3
+ This NPM package provides a set of domain models specifically designed for frontend development of Tridion Sites. These models encapsulate domain-specific logic and provide a convenient abstraction for interacting with the backend data.
4
+
5
+ ## Note
6
+
7
+ Due to reliance on various functionality provided at runtime by Tridion Sites, this package is not suitable for standalone usage and can only be utilized as a part of an extension.
8
+
9
+ ## Features
10
+
11
+ - Class-based definitions allow for easy item type checks
12
+ - Quality of life utilities provided as class instance methods
13
+ - Handling of TCM / ECL URI formats
14
+ - Easy conversion from and to `@tridion-sites/open-api-client` objects
15
+
16
+ ## Installation
17
+
18
+ To install `@tridion-sites/models`, you can use npm or yarn:
19
+
20
+ ```bash
21
+ $ npm install @tridion-sites/models
22
+ # or
23
+ $ yarn add @tridion-sites/models
24
+ ```
25
+
26
+ ## Mapping to and from the backend data
27
+
28
+ ### Converting from a `@tridion-sites/open-api-client` response to a model
29
+
30
+ Primary utility methods for conversion of the backend DTOs to models are:
31
+
32
+ - `tryMapToModel<TModel>(backendDto)` - maps provided dto to a model, returns `undefined` on failure.
33
+ <b>Important</b>: generic argument is provided to simplify usage of the utility. It doesn't check that the provided type actually corresponds with the realtime type after the conversion.
34
+ - `mapToModel<TModel>(backendDto)` - convenience method that throws an error instead of returning `undefined` if conversion has failed.
35
+ - `mapToModels<TModel>(backendDto[])` - maps an array of backend DTOs to models, returning only successfully mapped objects.
36
+
37
+ ```typescript
38
+ import type { ActivityInstance, ItemUri } from '@tridion-sites/models';
39
+ import { mapToModel } from '@tridion-sites/models';
40
+ import { ItemsService } from '@tridion-sites/open-api-client';
41
+
42
+ const getActivityById = async (activityId: ItemUri) => {
43
+ const activity = await ItemsService.getItem(activityId.asString);
44
+ return mapToModel<ActivityInstance>(activity);
45
+ };
46
+ ```
47
+
48
+ ### Converting from a model to a `@tridion-sites/open-api-client` DTO
49
+
50
+ Every model contains `.getInternalModel()` method that allows to get the underlying backend DTO.
51
+
52
+ ```typescript
53
+ import { IdentifiableObject } from '@tridion-sites/models';
54
+ import { ItemsService } from '@tridion-sites/open-api-client';
55
+
56
+ const updateItem = async (item: IdentifiableObject) => {
57
+ const backendDto = item.getInternalModel();
58
+ await ItemsService.update(backendDto.Id, backendDto);
59
+ };
60
+ ```
61
+
62
+ ## Item URI handling
63
+
64
+ There are 2 primary methods for parsing string URIs:
65
+
66
+ - `tryParseItemUri` - parses a string into an ItemUri object. Returns `undefined` if the conversion has failed
67
+ - `parseItemUri` - convenience method that throws an error instead of returning `undefined` if conversion has failed.
68
+
69
+ ## API Documentation
70
+
71
+ Documentation for all available models, their methods and model utilities can be found at
72
+ http://developers.rws.com/tridion-sites-extensions-api-docs/models.html
package/dist/index.d.ts CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * This NPM package provides a set of domain models specifically designed for frontend development of Tridion Sites.
3
+ * These models encapsulate domain-specific logic and provide a convenient abstraction for interacting with the backend data.
4
+ *
5
+ * @remarks
6
+ * Due to reliance on various functionality provided at runtime by Tridion Sites,
7
+ * this package is not suitable for standalone usage and can only be utilized as a part of an extension.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+
1
12
  import type { AccessControlEntry as AccessControlEntry_2 } from '@tridion-sites/open-api-client';
2
13
  import type { AccessControlList as AccessControlList_2 } from '@tridion-sites/open-api-client';
3
14
  import type { AccessToken as AccessToken_2 } from '@tridion-sites/open-api-client';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tridion-sites/models",
3
- "version": "0.1.3",
3
+ "version": "1.0.0",
4
4
  "description": "Tridion Sites models",
5
5
  "author": "RWS",
6
6
  "homepage": "https://www.rws.com",
@@ -9,13 +9,6 @@
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/index.js",
11
11
  "typings": "dist/index.d.ts",
12
- "repository": {
13
- "type": "git",
14
- "url": "https://stash.sdl.com/scm/tdx/tridion-sites.git"
15
- },
16
- "bugs": {
17
- "url": "https://jira.sdl.com/projects/DXUI/issues/"
18
- },
19
12
  "files": [
20
13
  "dist/**/*"
21
14
  ],
@@ -31,7 +24,7 @@
31
24
  "test:ci": "jest --verbose --reporters='default' --reporters='jest-junit'"
32
25
  },
33
26
  "dependencies": {
34
- "@tridion-sites/open-api-client": "1.0.5",
27
+ "@tridion-sites/open-api-client": "2.0.0",
35
28
  "immer": "9.0.16"
36
29
  },
37
30
  "devDependencies": {
package/CHANGELOG.md DELETED
@@ -1,60 +0,0 @@
1
- # @tridion-sites/models
2
-
3
- ## 0.1.3
4
-
5
- ### Patch Changes
6
-
7
- - be9284a536: rename a property
8
-
9
- ## 0.1.2
10
-
11
- ### Patch Changes
12
-
13
- - b803ef7b33: Fake models now have special creation functions
14
- - 9b78d6d626: upgrade dependencies
15
- - 31bdf04adf: fixed VersionedItem isNew behavior
16
-
17
- ## 0.1.1
18
-
19
- ### Patch Changes
20
-
21
- - 226cc4cce1: Additional info for Taxonomies model is added
22
- - 1845a12377: use the latest typescript version
23
- - Updated dependencies [1845a12377]
24
- - @tridion-sites/open-api-client@1.0.5
25
-
26
- ## 0.1.0
27
-
28
- ### Minor Changes
29
-
30
- - Set of small improvements and fixes to the extensions framework
31
-
32
- ## 0.0.5
33
-
34
- ### Patch Changes
35
-
36
- - update packages
37
-
38
- ## 0.0.4
39
-
40
- ### Patch Changes
41
-
42
- - include node_modules into the build
43
-
44
- ## 0.0.3
45
-
46
- ### Patch Changes
47
-
48
- - include node_modules into the build
49
-
50
- ## 0.0.2
51
-
52
- ### Patch Changes
53
-
54
- - release new package version for extensions, extensions-cli, models, open-api-client
55
- - c616d80f3c: fixed circular dependencies in @tridion-sites/models
56
- - 117e9e5f76: Models package became public
57
- - Updated dependencies
58
- - Updated dependencies [0738aa9ac3]
59
- - Updated dependencies [ff20566f80]
60
- - @tridion-sites/open-api-client@1.0.4