@terminalfour/terminalfour-js 1.0.0-rc.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.
- package/LICENSE.md +106 -0
- package/README.md +169 -0
- package/dist/cjs/element-resolver.d.ts +115 -0
- package/dist/cjs/element-resolver.d.ts.map +1 -0
- package/dist/cjs/element-resolver.js +391 -0
- package/dist/cjs/element-resolver.js.map +1 -0
- package/dist/cjs/errors.d.ts +21 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +21 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/handlebars.d.ts +123 -0
- package/dist/cjs/handlebars.d.ts.map +1 -0
- package/dist/cjs/handlebars.js +306 -0
- package/dist/cjs/handlebars.js.map +1 -0
- package/dist/cjs/http-client.d.ts +21 -0
- package/dist/cjs/http-client.d.ts.map +1 -0
- package/dist/cjs/http-client.js +126 -0
- package/dist/cjs/http-client.js.map +1 -0
- package/dist/cjs/index.d.ts +37 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/media-category-ref.d.ts +78 -0
- package/dist/cjs/media-category-ref.d.ts.map +1 -0
- package/dist/cjs/media-category-ref.js +184 -0
- package/dist/cjs/media-category-ref.js.map +1 -0
- package/dist/cjs/media-library.d.ts +30 -0
- package/dist/cjs/media-library.d.ts.map +1 -0
- package/dist/cjs/media-library.js +77 -0
- package/dist/cjs/media-library.js.map +1 -0
- package/dist/cjs/models/content-item.d.ts +80 -0
- package/dist/cjs/models/content-item.d.ts.map +1 -0
- package/dist/cjs/models/content-item.js +682 -0
- package/dist/cjs/models/content-item.js.map +1 -0
- package/dist/cjs/models/media-category-item.d.ts +29 -0
- package/dist/cjs/models/media-category-item.d.ts.map +1 -0
- package/dist/cjs/models/media-category-item.js +33 -0
- package/dist/cjs/models/media-category-item.js.map +1 -0
- package/dist/cjs/models/media-item.d.ts +74 -0
- package/dist/cjs/models/media-item.d.ts.map +1 -0
- package/dist/cjs/models/media-item.js +188 -0
- package/dist/cjs/models/media-item.js.map +1 -0
- package/dist/cjs/models/section-item.d.ts +58 -0
- package/dist/cjs/models/section-item.d.ts.map +1 -0
- package/dist/cjs/models/section-item.js +166 -0
- package/dist/cjs/models/section-item.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/channel-resource.d.ts +112 -0
- package/dist/cjs/resources/channel-resource.d.ts.map +1 -0
- package/dist/cjs/resources/channel-resource.js +107 -0
- package/dist/cjs/resources/channel-resource.js.map +1 -0
- package/dist/cjs/resources/content-resource.d.ts +50 -0
- package/dist/cjs/resources/content-resource.d.ts.map +1 -0
- package/dist/cjs/resources/content-resource.js +286 -0
- package/dist/cjs/resources/content-resource.js.map +1 -0
- package/dist/cjs/resources/content-type-resource.d.ts +283 -0
- package/dist/cjs/resources/content-type-resource.d.ts.map +1 -0
- package/dist/cjs/resources/content-type-resource.js +970 -0
- package/dist/cjs/resources/content-type-resource.js.map +1 -0
- package/dist/cjs/resources/group-resource.d.ts +96 -0
- package/dist/cjs/resources/group-resource.d.ts.map +1 -0
- package/dist/cjs/resources/group-resource.js +213 -0
- package/dist/cjs/resources/group-resource.js.map +1 -0
- package/dist/cjs/resources/list-resource.d.ts +111 -0
- package/dist/cjs/resources/list-resource.d.ts.map +1 -0
- package/dist/cjs/resources/list-resource.js +179 -0
- package/dist/cjs/resources/list-resource.js.map +1 -0
- package/dist/cjs/resources/media-resource.d.ts +69 -0
- package/dist/cjs/resources/media-resource.d.ts.map +1 -0
- package/dist/cjs/resources/media-resource.js +210 -0
- package/dist/cjs/resources/media-resource.js.map +1 -0
- package/dist/cjs/resources/media-type-resource.d.ts +70 -0
- package/dist/cjs/resources/media-type-resource.d.ts.map +1 -0
- package/dist/cjs/resources/media-type-resource.js +195 -0
- package/dist/cjs/resources/media-type-resource.js.map +1 -0
- package/dist/cjs/resources/navigation-resource.d.ts +664 -0
- package/dist/cjs/resources/navigation-resource.d.ts.map +1 -0
- package/dist/cjs/resources/navigation-resource.js +2349 -0
- package/dist/cjs/resources/navigation-resource.js.map +1 -0
- package/dist/cjs/resources/page-layout-resource.d.ts +83 -0
- package/dist/cjs/resources/page-layout-resource.d.ts.map +1 -0
- package/dist/cjs/resources/page-layout-resource.js +214 -0
- package/dist/cjs/resources/page-layout-resource.js.map +1 -0
- package/dist/cjs/resources/user-resource.d.ts +126 -0
- package/dist/cjs/resources/user-resource.d.ts.map +1 -0
- package/dist/cjs/resources/user-resource.js +317 -0
- package/dist/cjs/resources/user-resource.js.map +1 -0
- package/dist/cjs/section-ref.d.ts +185 -0
- package/dist/cjs/section-ref.d.ts.map +1 -0
- package/dist/cjs/section-ref.js +813 -0
- package/dist/cjs/section-ref.js.map +1 -0
- package/dist/cjs/site-structure.d.ts +18 -0
- package/dist/cjs/site-structure.d.ts.map +1 -0
- package/dist/cjs/site-structure.js +57 -0
- package/dist/cjs/site-structure.js.map +1 -0
- package/dist/cjs/t4-client.d.ts +121 -0
- package/dist/cjs/t4-client.d.ts.map +1 -0
- package/dist/cjs/t4-client.js +190 -0
- package/dist/cjs/t4-client.js.map +1 -0
- package/dist/cjs/type-registry.d.ts +31 -0
- package/dist/cjs/type-registry.d.ts.map +1 -0
- package/dist/cjs/type-registry.js +76 -0
- package/dist/cjs/type-registry.js.map +1 -0
- package/dist/cjs/types.d.ts +211 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +147 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +408 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/element-resolver.d.ts +115 -0
- package/dist/esm/element-resolver.d.ts.map +1 -0
- package/dist/esm/element-resolver.js +387 -0
- package/dist/esm/element-resolver.js.map +1 -0
- package/dist/esm/errors.d.ts +21 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +17 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/handlebars.d.ts +123 -0
- package/dist/esm/handlebars.d.ts.map +1 -0
- package/dist/esm/handlebars.js +300 -0
- package/dist/esm/handlebars.js.map +1 -0
- package/dist/esm/http-client.d.ts +21 -0
- package/dist/esm/http-client.d.ts.map +1 -0
- package/dist/esm/http-client.js +122 -0
- package/dist/esm/http-client.js.map +1 -0
- package/dist/esm/index.d.ts +37 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/media-category-ref.d.ts +78 -0
- package/dist/esm/media-category-ref.d.ts.map +1 -0
- package/dist/esm/media-category-ref.js +180 -0
- package/dist/esm/media-category-ref.js.map +1 -0
- package/dist/esm/media-library.d.ts +30 -0
- package/dist/esm/media-library.d.ts.map +1 -0
- package/dist/esm/media-library.js +73 -0
- package/dist/esm/media-library.js.map +1 -0
- package/dist/esm/models/content-item.d.ts +80 -0
- package/dist/esm/models/content-item.d.ts.map +1 -0
- package/dist/esm/models/content-item.js +676 -0
- package/dist/esm/models/content-item.js.map +1 -0
- package/dist/esm/models/media-category-item.d.ts +29 -0
- package/dist/esm/models/media-category-item.d.ts.map +1 -0
- package/dist/esm/models/media-category-item.js +29 -0
- package/dist/esm/models/media-category-item.js.map +1 -0
- package/dist/esm/models/media-item.d.ts +74 -0
- package/dist/esm/models/media-item.d.ts.map +1 -0
- package/dist/esm/models/media-item.js +184 -0
- package/dist/esm/models/media-item.js.map +1 -0
- package/dist/esm/models/section-item.d.ts +58 -0
- package/dist/esm/models/section-item.d.ts.map +1 -0
- package/dist/esm/models/section-item.js +162 -0
- package/dist/esm/models/section-item.js.map +1 -0
- package/dist/esm/resources/channel-resource.d.ts +112 -0
- package/dist/esm/resources/channel-resource.d.ts.map +1 -0
- package/dist/esm/resources/channel-resource.js +102 -0
- package/dist/esm/resources/channel-resource.js.map +1 -0
- package/dist/esm/resources/content-resource.d.ts +50 -0
- package/dist/esm/resources/content-resource.d.ts.map +1 -0
- package/dist/esm/resources/content-resource.js +282 -0
- package/dist/esm/resources/content-resource.js.map +1 -0
- package/dist/esm/resources/content-type-resource.d.ts +283 -0
- package/dist/esm/resources/content-type-resource.d.ts.map +1 -0
- package/dist/esm/resources/content-type-resource.js +964 -0
- package/dist/esm/resources/content-type-resource.js.map +1 -0
- package/dist/esm/resources/group-resource.d.ts +96 -0
- package/dist/esm/resources/group-resource.d.ts.map +1 -0
- package/dist/esm/resources/group-resource.js +208 -0
- package/dist/esm/resources/group-resource.js.map +1 -0
- package/dist/esm/resources/list-resource.d.ts +111 -0
- package/dist/esm/resources/list-resource.d.ts.map +1 -0
- package/dist/esm/resources/list-resource.js +174 -0
- package/dist/esm/resources/list-resource.js.map +1 -0
- package/dist/esm/resources/media-resource.d.ts +69 -0
- package/dist/esm/resources/media-resource.d.ts.map +1 -0
- package/dist/esm/resources/media-resource.js +206 -0
- package/dist/esm/resources/media-resource.js.map +1 -0
- package/dist/esm/resources/media-type-resource.d.ts +70 -0
- package/dist/esm/resources/media-type-resource.d.ts.map +1 -0
- package/dist/esm/resources/media-type-resource.js +190 -0
- package/dist/esm/resources/media-type-resource.js.map +1 -0
- package/dist/esm/resources/navigation-resource.d.ts +664 -0
- package/dist/esm/resources/navigation-resource.d.ts.map +1 -0
- package/dist/esm/resources/navigation-resource.js +2344 -0
- package/dist/esm/resources/navigation-resource.js.map +1 -0
- package/dist/esm/resources/page-layout-resource.d.ts +83 -0
- package/dist/esm/resources/page-layout-resource.d.ts.map +1 -0
- package/dist/esm/resources/page-layout-resource.js +209 -0
- package/dist/esm/resources/page-layout-resource.js.map +1 -0
- package/dist/esm/resources/user-resource.d.ts +126 -0
- package/dist/esm/resources/user-resource.d.ts.map +1 -0
- package/dist/esm/resources/user-resource.js +312 -0
- package/dist/esm/resources/user-resource.js.map +1 -0
- package/dist/esm/section-ref.d.ts +185 -0
- package/dist/esm/section-ref.d.ts.map +1 -0
- package/dist/esm/section-ref.js +808 -0
- package/dist/esm/section-ref.js.map +1 -0
- package/dist/esm/site-structure.d.ts +18 -0
- package/dist/esm/site-structure.d.ts.map +1 -0
- package/dist/esm/site-structure.js +53 -0
- package/dist/esm/site-structure.js.map +1 -0
- package/dist/esm/t4-client.d.ts +121 -0
- package/dist/esm/t4-client.d.ts.map +1 -0
- package/dist/esm/t4-client.js +186 -0
- package/dist/esm/t4-client.js.map +1 -0
- package/dist/esm/type-registry.d.ts +31 -0
- package/dist/esm/type-registry.d.ts.map +1 -0
- package/dist/esm/type-registry.js +72 -0
- package/dist/esm/type-registry.js.map +1 -0
- package/dist/esm/types.d.ts +211 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +147 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +355 -0
- package/dist/esm/utils.js.map +1 -0
- package/docs/channels.md +62 -0
- package/docs/content-types.md +313 -0
- package/docs/content.md +199 -0
- package/docs/error-handling.md +86 -0
- package/docs/getting-started.md +146 -0
- package/docs/groups-and-users.md +167 -0
- package/docs/handlebars.md +145 -0
- package/docs/lists.md +98 -0
- package/docs/media-types.md +111 -0
- package/docs/media.md +169 -0
- package/docs/navigation/a-to-z.md +62 -0
- package/docs/navigation/breadcrumbs.md +67 -0
- package/docs/navigation/css-selector.md +53 -0
- package/docs/navigation/generate-file.md +48 -0
- package/docs/navigation/keyword-search.md +134 -0
- package/docs/navigation/language-switcher.md +37 -0
- package/docs/navigation/link-menu.md +105 -0
- package/docs/navigation/pagination.md +80 -0
- package/docs/navigation/previous-next-fulltext.md +43 -0
- package/docs/navigation/publish-to-one-file.md +93 -0
- package/docs/navigation/related-content.md +79 -0
- package/docs/navigation/related-section-branch.md +31 -0
- package/docs/navigation/return-to-index.md +35 -0
- package/docs/navigation/section-details.md +51 -0
- package/docs/navigation/section-iterator.md +33 -0
- package/docs/navigation/section-meta-info.md +39 -0
- package/docs/navigation/site-map.md +58 -0
- package/docs/navigation/top-content.md +80 -0
- package/docs/navigation/top-stories.md +47 -0
- package/docs/navigation.md +134 -0
- package/docs/page-layouts.md +71 -0
- package/docs/sections.md +224 -0
- package/docs/typescript.md +124 -0
- package/package.json +64 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
SPDX-License-Identifier: Elastic-2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Terminalfour Solutions Limited
|
|
4
|
+
|
|
5
|
+
The licensor for the purposes of the terms below is Terminalfour Solutions
|
|
6
|
+
Limited, a company incorporated in Ireland. The software is terminalfour-js.
|
|
7
|
+
|
|
8
|
+
The text below is the Elastic License 2.0, reproduced verbatim. It is a
|
|
9
|
+
source-available licence, not an OSI-approved open-source licence.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Elastic License 2.0
|
|
14
|
+
|
|
15
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
16
|
+
|
|
17
|
+
## Acceptance
|
|
18
|
+
|
|
19
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
20
|
+
|
|
21
|
+
## Copyright License
|
|
22
|
+
|
|
23
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
24
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
25
|
+
available, and prepare derivative works of the software, in each case subject
|
|
26
|
+
to the limitations and conditions below.
|
|
27
|
+
|
|
28
|
+
## Limitations
|
|
29
|
+
|
|
30
|
+
You may not provide the software to third parties as a hosted or managed
|
|
31
|
+
service, where the service provides users with access to any substantial set
|
|
32
|
+
of the features or functionality of the software.
|
|
33
|
+
|
|
34
|
+
You may not move, change, disable, or circumvent the license key
|
|
35
|
+
functionality in the software, and you may not remove or obscure any
|
|
36
|
+
functionality in the software that is protected by the license key.
|
|
37
|
+
|
|
38
|
+
You may not alter, remove, or obscure any licensing, copyright, or other
|
|
39
|
+
notices of the licensor in the software. Any use of the licensor's trademarks
|
|
40
|
+
is subject to applicable law.
|
|
41
|
+
|
|
42
|
+
## Patents
|
|
43
|
+
|
|
44
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
45
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
46
|
+
sale, import and have imported the software, in each case subject to the
|
|
47
|
+
limitations and conditions in this license. This license does not cover any
|
|
48
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
49
|
+
the software. If you or your company make any written claim that the software
|
|
50
|
+
infringes or contributes to infringement of any patent, your patent license
|
|
51
|
+
for the software granted under these terms ends immediately. If your company
|
|
52
|
+
makes such a claim, your patent license ends immediately for work on behalf of
|
|
53
|
+
your company.
|
|
54
|
+
|
|
55
|
+
## Notices
|
|
56
|
+
|
|
57
|
+
You must ensure that anyone who gets a copy of any part of the software from
|
|
58
|
+
you also gets a copy of these terms.
|
|
59
|
+
|
|
60
|
+
If you modify the software, you must include in any modified copies of the
|
|
61
|
+
software prominent notices stating that you have modified the software.
|
|
62
|
+
|
|
63
|
+
## No Other Rights
|
|
64
|
+
|
|
65
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
66
|
+
these terms.
|
|
67
|
+
|
|
68
|
+
## Termination
|
|
69
|
+
|
|
70
|
+
If you use the software in violation of these terms, such use is not
|
|
71
|
+
licensed, and your licenses will automatically terminate. If the licensor
|
|
72
|
+
provides you with a notice of your violation, and you cease all violation of
|
|
73
|
+
this license no later than 30 days after you receive that notice, your
|
|
74
|
+
licenses will be reinstated retroactively. However, if you violate these terms
|
|
75
|
+
after such reinstatement, any additional violation of these terms will cause
|
|
76
|
+
your licenses to terminate automatically and permanently.
|
|
77
|
+
|
|
78
|
+
## No Liability
|
|
79
|
+
|
|
80
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
81
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
82
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
83
|
+
legal claim.*
|
|
84
|
+
|
|
85
|
+
## Definitions
|
|
86
|
+
|
|
87
|
+
The **licensor** is the entity offering these terms, and the **software** is
|
|
88
|
+
the software the licensor makes available under these terms, including any
|
|
89
|
+
portion of it.
|
|
90
|
+
|
|
91
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
92
|
+
|
|
93
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
94
|
+
organization that you work for, plus all organizations that have control over,
|
|
95
|
+
are under the control of, or are under common control with that organization.
|
|
96
|
+
**control** means ownership of substantially all the assets of an entity, or
|
|
97
|
+
the power to direct its management and policies by vote, contract, or
|
|
98
|
+
otherwise. Control can be direct or indirect.
|
|
99
|
+
|
|
100
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
101
|
+
these terms.
|
|
102
|
+
|
|
103
|
+
**use** means anything you do with the software requiring one of your
|
|
104
|
+
licenses.
|
|
105
|
+
|
|
106
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# terminalfour-js
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for working with the [Terminalfour](https://www.terminalfour.com/) Platform REST API.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install terminalfour-js
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { T4Client } from 'terminalfour-js';
|
|
11
|
+
|
|
12
|
+
const t4 = new T4Client({
|
|
13
|
+
baseUrl: 'https://mysite.edu/terminalfour/rs',
|
|
14
|
+
apiToken: 'your-api-token',
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Why use terminalfour-js?
|
|
19
|
+
|
|
20
|
+
The Terminalfour REST API is powerful but verbose. Updating content can require more than five requests, negative random IDs, data merged from multiple endpoints, and element keys such as `"Title#2:1"`. terminalfour-js handles that API plumbing and lets you work with field names and typed values.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
await t4.section(482).content.create({
|
|
24
|
+
type: 44,
|
|
25
|
+
name: 'New Article',
|
|
26
|
+
fields: {
|
|
27
|
+
Title: 'Breaking News',
|
|
28
|
+
Category: 'Featured', // list value by name, not "listId:itemId"
|
|
29
|
+
'Hero Image': './photo.jpg', // uploads the file automatically
|
|
30
|
+
'Publish Date': new Date(), // accepts a Date object
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Retrieve an item, change its fields, and save it:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const article = await t4.section(482).content.get(9132);
|
|
39
|
+
article.fields['Title'] = 'Updated Headline';
|
|
40
|
+
article.status = 'approved';
|
|
41
|
+
await article.save();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Section operations start from a lightweight section reference:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const section = t4.section(482);
|
|
48
|
+
|
|
49
|
+
await section.content.list();
|
|
50
|
+
await section.subsections();
|
|
51
|
+
await section.publish({ branch: true });
|
|
52
|
+
await section.addSection({ name: 'Child', customFields: { Title: 'Hello' } });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
|
|
57
|
+
- **Node 18 or later:** The SDK uses the built-in `fetch`, `FormData`, and `Error.cause`.
|
|
58
|
+
- **Server-side execution:** Do not include the SDK or API token in front-end code.
|
|
59
|
+
- **ESM and CommonJS:** Use either `import` or `require`.
|
|
60
|
+
- **TypeScript declarations:** No `@types` package is needed.
|
|
61
|
+
- **Zero runtime dependencies.**
|
|
62
|
+
|
|
63
|
+
## Keep the API token server-side
|
|
64
|
+
|
|
65
|
+
Do not use this SDK in front-end code. The `apiToken` has all the privileges of its associated user, and browser bundles are publicly readable. The SDK throws if you construct a client in a browser.
|
|
66
|
+
|
|
67
|
+
Construct the client in server-side code and return only the data the browser needs. See [Getting Started](./docs/getting-started.md#keep-the-client-server-side) for an example and the full runtime check.
|
|
68
|
+
|
|
69
|
+
## Supported resources
|
|
70
|
+
|
|
71
|
+
| Resource | Operations |
|
|
72
|
+
|---|---|
|
|
73
|
+
| **Sections** | get, create, update, delete, purge, move, tree, subsections, channels, owner, metadata, page layouts, edit rights, content types, publish |
|
|
74
|
+
| **Content** | list, get, create, update, delete, purge, move, duplicate, approve, approveAll |
|
|
75
|
+
| **Content Types** | list, get, create, update, delete, add/remove fields, content layouts (CRUD) |
|
|
76
|
+
| **Lists** | list, get, create, update, delete, add/remove items |
|
|
77
|
+
| **Groups** | list, get, create, update, delete, add/remove members |
|
|
78
|
+
| **Users** | list, get, create, update, delete, auth methods, custom fields |
|
|
79
|
+
| **Page Layouts** | list, get, create, update, delete |
|
|
80
|
+
| **Channels** | list, get, publish |
|
|
81
|
+
| **Media** | get, create, update, delete, purge (auto-detects type, handles binary and text) |
|
|
82
|
+
| **Media Categories** | get, create, update, delete, purge, move, list items, subcategories |
|
|
83
|
+
| **Media Library** | full category tree |
|
|
84
|
+
| **Media Types** | list, get, create, update |
|
|
85
|
+
| **Navigation** | list, get, create, update, delete (all 19 core navigation objects) |
|
|
86
|
+
| **Handlebars** | helpers and partials: list, get, create, update, delete, purge |
|
|
87
|
+
| **Platform** | about, database, environment, licence |
|
|
88
|
+
|
|
89
|
+
The SDK supports every element type: plain text, HTML, dates, select boxes, checkboxes, radio buttons, multi-selects, cascading lists, files, images, media, section/content links, numbers, content owners, group selects, keyword selectors, and repeaters.
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
Start with [Getting Started](./docs/getting-started.md), then use the resource guides as references:
|
|
94
|
+
|
|
95
|
+
- [Sections](./docs/sections.md): CRUD, tree navigation, metadata, page layouts, edit rights, and publishing
|
|
96
|
+
- [Content](./docs/content.md): CRUD, move, duplicate, approve, and all element types
|
|
97
|
+
- [Content Types](./docs/content-types.md): types, fields, and content layouts
|
|
98
|
+
- [Lists](./docs/lists.md): list management and item changes
|
|
99
|
+
- [Groups & Users](./docs/groups-and-users.md): CRUD, authentication methods, and memberships
|
|
100
|
+
- [Page Layouts](./docs/page-layouts.md): CRUD with processor and syntax resolution
|
|
101
|
+
- [Media](./docs/media.md): items, categories, library trees, and uploads
|
|
102
|
+
- [Media Types](./docs/media-types.md): definitions, extensions, and layouts
|
|
103
|
+
- [Channels](./docs/channels.md): details and publishing
|
|
104
|
+
- [Navigation](./docs/navigation.md): all navigation object types, including A to Z, Breadcrumbs, and Site Map
|
|
105
|
+
- [Handlebars](./docs/handlebars.md): custom helpers and partials
|
|
106
|
+
- [Error Handling](./docs/error-handling.md): `T4ApiError`, debugging, and cache management
|
|
107
|
+
- [TypeScript Reference](./docs/typescript.md): exported types and interfaces
|
|
108
|
+
|
|
109
|
+
## More examples
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Bulk approve all pending content
|
|
113
|
+
const totalApprovedCount = await t4.section(482).content.approveAll();
|
|
114
|
+
|
|
115
|
+
// Duplicate a content item
|
|
116
|
+
const item = await t4.section(482).content.get(9132);
|
|
117
|
+
await item.duplicate(); // same section, auto-named "(1)"
|
|
118
|
+
await item.duplicate(500); // different section, original name
|
|
119
|
+
|
|
120
|
+
// Move a section
|
|
121
|
+
await t4.section(500).move(233);
|
|
122
|
+
|
|
123
|
+
// Create a content type with fields
|
|
124
|
+
await t4.contentTypes.create({
|
|
125
|
+
name: 'Blog Post',
|
|
126
|
+
elements: [
|
|
127
|
+
{ name: 'Title', type: 'Plain Text', required: true },
|
|
128
|
+
{ name: 'Body', type: 'HTML' },
|
|
129
|
+
{ name: 'Category', type: 'Select Box', listId: 71 },
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Upload media
|
|
134
|
+
const media = await t4.media.create({
|
|
135
|
+
file: './hero-image.jpg',
|
|
136
|
+
name: 'Hero Image',
|
|
137
|
+
category: 391,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Create a Handlebars custom helper
|
|
141
|
+
await t4.handlebars.helpers.create({
|
|
142
|
+
name: 'truncate',
|
|
143
|
+
code: `function(context, options) {
|
|
144
|
+
return context.substring(0, options.hash('len')) + '...';
|
|
145
|
+
}`,
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Contributing
|
|
150
|
+
|
|
151
|
+
Pull requests are welcome. Before opening one, read `CONTRIBUTING.md` and `CODE_OF_CONDUCT.md`.
|
|
152
|
+
|
|
153
|
+
The SDK has no runtime dependencies, and the tests use a mocked HTTP client. You do not need a T4 instance to contribute:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install
|
|
157
|
+
npm test
|
|
158
|
+
npm run build
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Every change to `src/` should have matching test coverage in `tests/`.
|
|
162
|
+
|
|
163
|
+
Contributions require a signed [CLA](./CLA.md). Report security issues privately per [SECURITY.md](./SECURITY.md) rather than as a public issue.
|
|
164
|
+
|
|
165
|
+
## Licence
|
|
166
|
+
|
|
167
|
+
[Elastic License 2.0](./LICENSE.md).
|
|
168
|
+
|
|
169
|
+
This project is **open code, not open source**. You can read, use, modify, and distribute the SDK. You cannot offer it to third parties as a hosted or managed service. The Elastic License 2.0 is a source-available licence, not an OSI-approved open-source licence.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { HttpClient } from './http-client.js';
|
|
2
|
+
import { TypeRegistry } from './type-registry.js';
|
|
3
|
+
/** A content type element from the template */
|
|
4
|
+
export interface TemplateElement {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
alias: string;
|
|
8
|
+
type: number;
|
|
9
|
+
sequence: number;
|
|
10
|
+
listId: number;
|
|
11
|
+
maxSize?: number;
|
|
12
|
+
contentTypeElementConfiguration?: {
|
|
13
|
+
contentTypeId: number;
|
|
14
|
+
contentTypeDTO?: {
|
|
15
|
+
id: number;
|
|
16
|
+
contentTypeElements: TemplateElement[];
|
|
17
|
+
};
|
|
18
|
+
minRepeats: number;
|
|
19
|
+
maxRepeats: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** List item from GET /list/{id}/{language} */
|
|
23
|
+
interface ListItem {
|
|
24
|
+
id: number;
|
|
25
|
+
name: string;
|
|
26
|
+
value: string;
|
|
27
|
+
listId: number;
|
|
28
|
+
sublist: number;
|
|
29
|
+
}
|
|
30
|
+
/** List response from GET /list/{id}/{language} */
|
|
31
|
+
interface ListResponse {
|
|
32
|
+
id: number;
|
|
33
|
+
items: ListItem[];
|
|
34
|
+
}
|
|
35
|
+
/** Keyword selector AND group */
|
|
36
|
+
interface KeywordAndGroup {
|
|
37
|
+
and: Array<string>;
|
|
38
|
+
}
|
|
39
|
+
/** Keyword selector input: array of OR items, where each item is a string or AND group */
|
|
40
|
+
export type KeywordSelectorInput = {
|
|
41
|
+
or: Array<string | KeywordAndGroup>;
|
|
42
|
+
};
|
|
43
|
+
/** Repeater item input from the developer */
|
|
44
|
+
export interface RepeaterInput {
|
|
45
|
+
name: string;
|
|
46
|
+
fields: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/** Section/Content Link input from the developer */
|
|
49
|
+
export interface SectionContentLinkInput {
|
|
50
|
+
sectionId: number;
|
|
51
|
+
contentId?: number;
|
|
52
|
+
linkText?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Context needed for resolving certain element types (e.g. SS links) */
|
|
55
|
+
export interface ResolveContext {
|
|
56
|
+
fromSectionId: number;
|
|
57
|
+
fromContentId: number;
|
|
58
|
+
}
|
|
59
|
+
/** Input for inline media upload within a Media element */
|
|
60
|
+
export interface MediaElementUpload {
|
|
61
|
+
file: string | Blob | {
|
|
62
|
+
file: string | Blob;
|
|
63
|
+
filename?: string;
|
|
64
|
+
};
|
|
65
|
+
name: string;
|
|
66
|
+
category: number;
|
|
67
|
+
description?: string;
|
|
68
|
+
}
|
|
69
|
+
/** Function that creates a media item and returns its ID */
|
|
70
|
+
export type MediaCreateFn = (data: MediaElementUpload) => Promise<number>;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves developer-friendly field values to T4 API element format.
|
|
73
|
+
* Handles list lookups, date conversion, repeater building, etc.
|
|
74
|
+
*/
|
|
75
|
+
export declare class ElementResolver {
|
|
76
|
+
private readonly httpClient;
|
|
77
|
+
private readonly typeRegistry;
|
|
78
|
+
private readonly mediaCreateFn;
|
|
79
|
+
private listCache;
|
|
80
|
+
constructor(httpClient: HttpClient, _defaultLanguage: string, typeRegistry: TypeRegistry, mediaCreateFn?: MediaCreateFn | null);
|
|
81
|
+
/**
|
|
82
|
+
* Resolves a single field value based on its element type.
|
|
83
|
+
* Uses the TypeRegistry to look up type names instead of hardcoded IDs.
|
|
84
|
+
*/
|
|
85
|
+
resolveValue(value: unknown, element: TemplateElement, language: string, allElements?: TemplateElement[], context?: ResolveContext): Promise<unknown>;
|
|
86
|
+
getList(listId: number, language: string): Promise<ListResponse>;
|
|
87
|
+
private resolveItemName;
|
|
88
|
+
private resolveDate;
|
|
89
|
+
/** Select Box, Radio Button — single list value: "listId:itemId" */
|
|
90
|
+
private resolveSingleList;
|
|
91
|
+
/** Checkbox, Multiple Select — "listId:id1,id2" */
|
|
92
|
+
private resolveCheckbox;
|
|
93
|
+
/** Multi-Select — "listId:id1;listId:id2" */
|
|
94
|
+
private resolveMultiSelect;
|
|
95
|
+
/** Cascading List — "listId1:itemId1, listId2:itemId2" */
|
|
96
|
+
private resolveCascadingList;
|
|
97
|
+
/** Group Select — comma-separated group IDs */
|
|
98
|
+
private resolveGroupSelect;
|
|
99
|
+
/** Keyword Selector — OR items comma-separated, AND groups with && */
|
|
100
|
+
private resolveKeywordSelector;
|
|
101
|
+
/** File/Image — upload file via POST /upload/ and return element value */
|
|
102
|
+
private resolveFileUpload;
|
|
103
|
+
/** Section/Content Link — create SS record and return T4 tag */
|
|
104
|
+
private resolveSectionContentLink;
|
|
105
|
+
/** Regex to match anchor tags that are SS link markers (have data-section-id attribute) */
|
|
106
|
+
private static readonly SSLINK_ANCHOR_REGEX;
|
|
107
|
+
/**
|
|
108
|
+
* Reverts friendly anchor elements in HTML back to T4 SS link tags.
|
|
109
|
+
* - Existing links (data-t4-sslink="39") → `<t4 type="sslink" sslink_id="39"/>`
|
|
110
|
+
* - New links (no data-t4-sslink or data-t4-sslink="new") → creates SS record via PUT /ssl, then inserts the tag
|
|
111
|
+
*/
|
|
112
|
+
private revertHtmlSsLinks;
|
|
113
|
+
}
|
|
114
|
+
export {};
|
|
115
|
+
//# sourceMappingURL=element-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-resolver.d.ts","sourceRoot":"","sources":["../../src/element-resolver.ts"],"names":[],"mappings":"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"}
|