@viglet/shio-client 2026.2.1 → 2026.3.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/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # @viglet/shio-client
2
2
 
3
- Framework-agnostic TypeScript client for the **Shio CMS Content Delivery API (CDA)**.
3
+ [![npm](https://img.shields.io/npm/v/@viglet/shio-client?logo=npm)](https://www.npmjs.com/package/@viglet/shio-client)
4
+ [![License](https://img.shields.io/npm/l/@viglet/shio-client)](https://github.com/openviglet/shio/blob/HEAD/LICENSE)
5
+ [![Website](https://img.shields.io/badge/shio.viglet.org-0ea5e9?logo=googlechrome&logoColor=white)](https://shio.viglet.org/)
6
+
7
+ Framework-agnostic **TypeScript client** for the Content Delivery API (CDA) of
8
+ **[Viglet Shio](https://shio.viglet.org/)**, the open source **headless CMS built
9
+ for coding agents**.
4
10
 
5
11
  - **Zero runtime dependencies** — just `fetch`.
6
12
  - Runs in **Node, the browser, edge runtimes, Next.js server components, Astro, Vue, Svelte** and plain scripts.
7
13
  - Targets the stable, read-only CDA contract (`/api/v2/cda/**`) — no Java, no legacy console API.
8
- - This is the **base** SDK; `@viglet/shio-react-sdk` is one consumer of it.
14
+ - This is the **base** SDK; [`@viglet/shio-react-sdk`](https://www.npmjs.com/package/@viglet/shio-react-sdk) is one consumer of it.
15
+ - Pair it with [`@viglet/shio`](https://www.npmjs.com/package/@viglet/shio) — `shio types` generates a `.d.ts` from your live content model, so `post.attrs.*` autocompletes.
9
16
 
10
17
  ## Install
11
18
 
@@ -95,6 +102,20 @@ npm run typecheck # tsc --noEmit
95
102
  npm test # node:test, no network (injected fetch)
96
103
  ```
97
104
 
105
+ ## Related packages
106
+
107
+ | Package | For |
108
+ |---|---|
109
+ | [`@viglet/shio`](https://www.npmjs.com/package/@viglet/shio) | The Shio CLI — content as files, type generation, and the MCP bridge for [Claude Code](https://claude.com/claude-code) |
110
+ | [`@viglet/shio-react-sdk`](https://www.npmjs.com/package/@viglet/shio-react-sdk) | React hooks and render components built on this client |
111
+ | [`@viglet/shio-sections`](https://www.npmjs.com/package/@viglet/shio-sections) | The page-section vocabulary |
112
+ | [`@viglet/shio-model`](https://www.npmjs.com/package/@viglet/shio-model) | Author the content model as typed code |
113
+ | [`@viglet/shio-editor-cors`](https://www.npmjs.com/package/@viglet/shio-editor-cors) | Inline visual editing with the Universal Editor |
114
+ | [`@viglet/create-shio-app`](https://www.npmjs.com/package/@viglet/create-shio-app) | Next.js starter generator |
115
+
98
116
  ## License
99
117
 
100
- GPL-3.0
118
+ Apache-2.0 — [Viglet Shio](https://shio.viglet.org/) ·
119
+ [github.com/openviglet/shio](https://github.com/openviglet/shio) ·
120
+ [docs.viglet.org/shio](https://docs.viglet.org/shio/) ·
121
+ part of the [Viglet](https://www.viglet.org) open source family.
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ * Copyright (C) 2016-2026 the original author or authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0.
6
+ *
7
+ * shio-types — generate a TypeScript `.d.ts` from a Shio instance's post-types
8
+ * (SH11). Fetches `/api/v2/cda/post-type` and writes typed `Post` interfaces so
9
+ * page code gets autocomplete on `post.attrs.*`.
10
+ *
11
+ * npx shio-types --url http://localhost:2710 --token <CDA token> --out lib/shio-types.d.ts
12
+ *
13
+ * Env fallbacks: SHIO_URL, SHIO_CDA_TOKEN.
14
+ */
15
+ import { writeFile } from "node:fs/promises";
16
+ import { argv, env, exit, stdout } from "node:process";
17
+
18
+ import { ShioClient, generateShioTypes } from "../dist/shio-client.js";
19
+
20
+ const HELP = `shio-types — generate TypeScript types from Shio post-types
21
+
22
+ Usage:
23
+ shio-types [options]
24
+
25
+ Options:
26
+ --url <baseUrl> Shio base URL (env SHIO_URL, default http://localhost:2710)
27
+ --token <token> CDA token (env SHIO_CDA_TOKEN)
28
+ --out <file> Output .d.ts path (default shio-types.d.ts; "-" for stdout)
29
+ --import-from <mod> Module to import ShioPost from (default @viglet/shio-client)
30
+ -h, --help Show this help
31
+ `;
32
+
33
+ function parseArgs(args) {
34
+ const opts = {};
35
+ for (let i = 0; i < args.length; i++) {
36
+ const a = args[i];
37
+ switch (a) {
38
+ case "-h":
39
+ case "--help":
40
+ opts.help = true;
41
+ break;
42
+ case "--url":
43
+ opts.url = args[++i];
44
+ break;
45
+ case "--token":
46
+ opts.token = args[++i];
47
+ break;
48
+ case "--out":
49
+ opts.out = args[++i];
50
+ break;
51
+ case "--import-from":
52
+ opts.importFrom = args[++i];
53
+ break;
54
+ default:
55
+ fail(`Unknown argument: ${a}\n\n${HELP}`);
56
+ }
57
+ }
58
+ return opts;
59
+ }
60
+
61
+ function fail(message) {
62
+ process.stderr.write(`${message}\n`);
63
+ exit(1);
64
+ }
65
+
66
+ async function main() {
67
+ const opts = parseArgs(argv.slice(2));
68
+ if (opts.help) {
69
+ stdout.write(HELP);
70
+ return;
71
+ }
72
+
73
+ const baseUrl = opts.url ?? env.SHIO_URL ?? "http://localhost:2710";
74
+ const apiToken = opts.token ?? env.SHIO_CDA_TOKEN;
75
+ const out = opts.out ?? "shio-types.d.ts";
76
+
77
+ const client = new ShioClient({ baseUrl, apiToken });
78
+
79
+ let schemas;
80
+ try {
81
+ schemas = await client.getPostTypes();
82
+ } catch (err) {
83
+ fail(`shio-types: failed to fetch post-types from ${baseUrl}\n ${err?.message ?? err}`);
84
+ }
85
+
86
+ const source = generateShioTypes(schemas, {
87
+ importFrom: opts.importFrom,
88
+ });
89
+
90
+ if (out === "-") {
91
+ stdout.write(source);
92
+ return;
93
+ }
94
+
95
+ await writeFile(out, source, "utf8");
96
+ stdout.write(`shio-types: wrote ${schemas.length} post-type(s) to ${out}\n`);
97
+ }
98
+
99
+ main().catch((err) => fail(`shio-types: ${err?.stack ?? err}`));
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ShioClientConfig, ShioListing, ShioPageParams, ShioPath, ShioPost, ShioQueryParams, ShioRequestOptions, ShioSite } from "./types";
1
+ import type { ShioClientConfig, ShioListing, ShioPageParams, ShioPath, ShioPost, ShioPostTypeSchema, ShioQueryParams, ShioRequestOptions, ShioSite } from "./types";
2
2
  /**
3
3
  * Framework-agnostic client for the Shio Content Delivery API (CDA, SH1).
4
4
  *
@@ -33,6 +33,14 @@ export declare class ShioClient {
33
33
  * routing (e.g. Next.js `[...slug]`). Returns `null` if unresolved.
34
34
  */
35
35
  getPostByUrl(siteId: string, url: string, opts?: ShioRequestOptions): Promise<ShioPost | null>;
36
+ /**
37
+ * List every post-type's content-model schema — the input to
38
+ * {@link generateShioTypes}. The schema is global (not site-scoped), so a
39
+ * per-site token sees every post-type.
40
+ */
41
+ getPostTypes(opts?: ShioRequestOptions): Promise<ShioPostTypeSchema[]>;
42
+ /** Get one post-type's content-model schema by its API name, or `null` if unknown. */
43
+ getPostType(name: string, opts?: ShioRequestOptions): Promise<ShioPostTypeSchema | null>;
36
44
  /** Query published posts by site / folder / post type (always returns a listing). */
37
45
  query(params?: ShioQueryParams, opts?: ShioRequestOptions): Promise<ShioListing>;
38
46
  private send;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TypeScript code generation from Shio post-type schemas (SH11).
3
+ *
4
+ * Pure and dependency-free: it turns the {@link ShioPostTypeSchema}[] returned by
5
+ * {@link ShioClient.getPostTypes} into a `.d.ts` source string. The `shio-types`
6
+ * CLI ({@link file:../bin/shio-types.mjs}) wires the fetch + file write around it;
7
+ * keeping the transform pure makes it testable without a network or a filesystem.
8
+ */
9
+ import type { ShioPostTypeSchema } from "./types";
10
+ /** Options for {@link generateShioTypes}. */
11
+ export interface GenerateTypesOptions {
12
+ /**
13
+ * The module the generated `Post` interfaces import `ShioPost` from. Defaults
14
+ * to the published package name; set to a relative path when generating into
15
+ * the SDK's own source tree.
16
+ */
17
+ importFrom?: string;
18
+ /** Override the file banner comment (e.g. to pin a version). */
19
+ banner?: string;
20
+ }
21
+ /**
22
+ * Generate `.d.ts` source declaring one typed `Post` interface per post-type,
23
+ * plus a `ShioPostTypes` name→type map. Page code then gets autocomplete on
24
+ * `post.attrs.*`.
25
+ *
26
+ * @example
27
+ * const schemas = await client.getPostTypes();
28
+ * await writeFile("shio-types.d.ts", generateShioTypes(schemas));
29
+ */
30
+ export declare function generateShioTypes(schemas: ShioPostTypeSchema[], options?: GenerateTypesOptions): string;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { ShioClient, createShioClient } from "./client";
2
2
  export { ShioHttpError } from "./errors";
3
- export type { ShioClientConfig, ShioRequestOptions, ShioSite, ShioFolder, ShioPostSummary, ShioPost, ShioListing, ShioPath, ShioQueryParams, ShioPageParams, } from "./types";
3
+ export { generateShioTypes } from "./codegen";
4
+ export type { GenerateTypesOptions } from "./codegen";
5
+ export type { ShioClientConfig, ShioRequestOptions, ShioSite, ShioFolder, ShioPostSummary, ShioPost, ShioListing, ShioPath, ShioQueryParams, ShioPageParams, ShioFieldSchema, ShioPostTypeSchema, } from "./types";
@@ -1,113 +1,139 @@
1
- class o extends Error {
2
- constructor(e, t, i) {
3
- super(`Shio CDA ${e} for ${t}`), this.name = "ShioHttpError", this.status = e, this.url = t, this.body = i, Object.setPrototypeOf(this, o.prototype);
4
- }
1
+ //#region src/errors.ts
2
+ var e = class e extends Error {
3
+ constructor(t, n, r) {
4
+ super(`Shio CDA ${t} for ${n}`), this.name = "ShioHttpError", this.status = t, this.url = n, this.body = r, Object.setPrototypeOf(this, e.prototype);
5
+ }
6
+ }, t = "/api/v2/cda", n = class {
7
+ constructor(e) {
8
+ if (!e?.baseUrl) throw Error("ShioClient: `baseUrl` is required");
9
+ this.baseUrl = e.baseUrl.replace(/\/+$/, ""), this.headers = {
10
+ Accept: "application/json",
11
+ ...e.headers ?? {}
12
+ }, e.apiToken && (this.headers.Key = e.apiToken);
13
+ let t = e.fetch ?? globalThis.fetch;
14
+ if (typeof t != "function") throw Error("ShioClient: no global `fetch` available — pass `fetch` in the config");
15
+ this.fetchFn = t.bind(globalThis), this.credentials = e.credentials;
16
+ }
17
+ getSites(e) {
18
+ return this.request("/site", e);
19
+ }
20
+ getSite(e, t) {
21
+ return this.requestOrNull(`/site/${i(e)}`, t);
22
+ }
23
+ listChildren(e, t, n) {
24
+ let r = a({
25
+ page: t?.page,
26
+ size: t?.size
27
+ });
28
+ return this.requestOrNull(`/object/${i(e)}/list${r}`, n);
29
+ }
30
+ getPath(e, t) {
31
+ return this.requestOrNull(`/object/${i(e)}/path`, t);
32
+ }
33
+ getPost(e, t) {
34
+ return this.requestOrNull(`/post/${i(e)}`, t);
35
+ }
36
+ getPostByUrl(e, t, n) {
37
+ let r = a({
38
+ siteId: e,
39
+ url: t
40
+ });
41
+ return this.requestOrNull(`/post/by-url${r}`, n);
42
+ }
43
+ getPostTypes(e) {
44
+ return this.request("/post-type", e);
45
+ }
46
+ getPostType(e, t) {
47
+ return this.requestOrNull(`/post-type/${i(e)}`, t);
48
+ }
49
+ query(e, t) {
50
+ let n = a({
51
+ siteId: e?.siteId,
52
+ folderId: e?.folderId,
53
+ postType: e?.postType,
54
+ page: e?.page,
55
+ size: e?.size
56
+ });
57
+ return this.request(`/query${n}`, t);
58
+ }
59
+ async send(e, n) {
60
+ return this.fetchFn(`${this.baseUrl}${t}${e}`, {
61
+ method: "GET",
62
+ headers: this.headers,
63
+ signal: n?.signal,
64
+ ...this.credentials ? { credentials: this.credentials } : {}
65
+ });
66
+ }
67
+ async request(t, n) {
68
+ let r = await this.send(t, n);
69
+ if (!r.ok) throw new e(r.status, t, await o(r));
70
+ return await r.json();
71
+ }
72
+ async requestOrNull(t, n) {
73
+ let r = await this.send(t, n);
74
+ if (r.status === 404) return null;
75
+ if (!r.ok) throw new e(r.status, t, await o(r));
76
+ return await r.json();
77
+ }
78
+ };
79
+ function r(e) {
80
+ return new n(e);
5
81
  }
6
- const u = "/api/v2/cda";
7
- class c {
8
- constructor(e) {
9
- if (!(e != null && e.baseUrl))
10
- throw new Error("ShioClient: `baseUrl` is required");
11
- this.baseUrl = e.baseUrl.replace(/\/+$/, ""), this.headers = { Accept: "application/json", ...e.headers ?? {} }, e.apiToken && (this.headers.Key = e.apiToken);
12
- const t = e.fetch ?? globalThis.fetch;
13
- if (typeof t != "function")
14
- throw new Error(
15
- "ShioClient: no global `fetch` available — pass `fetch` in the config"
16
- );
17
- this.fetchFn = t.bind(globalThis), this.credentials = e.credentials;
18
- }
19
- // --- Sites ---
20
- /** List all published sites. */
21
- getSites(e) {
22
- return this.request("/site", e);
23
- }
24
- /** Get one site (with its root folder id), or `null` if not found. */
25
- getSite(e, t) {
26
- return this.requestOrNull(`/site/${n(e)}`, t);
27
- }
28
- // --- Navigation ---
29
- /** List a folder's children (subfolders + published posts), or `null` if the folder is unknown. */
30
- listChildren(e, t, i) {
31
- const r = h({ page: t == null ? void 0 : t.page, size: t == null ? void 0 : t.size });
32
- return this.requestOrNull(
33
- `/object/${n(e)}/list${r}`,
34
- i
35
- );
36
- }
37
- /** Get the breadcrumb path for a folder or post, or `null` if unknown. */
38
- getPath(e, t) {
39
- return this.requestOrNull(`/object/${n(e)}/path`, t);
40
- }
41
- // --- Posts ---
42
- /** Get a published post by id (attributes expanded), or `null` if not found / not published. */
43
- getPost(e, t) {
44
- return this.requestOrNull(`/post/${n(e)}`, t);
45
- }
46
- /**
47
- * Resolve a published post by site + friendly URL — the call behind catch-all
48
- * routing (e.g. Next.js `[...slug]`). Returns `null` if unresolved.
49
- */
50
- getPostByUrl(e, t, i) {
51
- const r = h({ siteId: e, url: t });
52
- return this.requestOrNull(`/post/by-url${r}`, i);
53
- }
54
- /** Query published posts by site / folder / post type (always returns a listing). */
55
- query(e, t) {
56
- const i = h({
57
- siteId: e == null ? void 0 : e.siteId,
58
- folderId: e == null ? void 0 : e.folderId,
59
- postType: e == null ? void 0 : e.postType,
60
- page: e == null ? void 0 : e.page,
61
- size: e == null ? void 0 : e.size
62
- });
63
- return this.request(`/query${i}`, t);
64
- }
65
- // --- internals ---
66
- async send(e, t) {
67
- return this.fetchFn(`${this.baseUrl}${u}${e}`, {
68
- method: "GET",
69
- headers: this.headers,
70
- signal: t == null ? void 0 : t.signal,
71
- ...this.credentials ? { credentials: this.credentials } : {}
72
- });
73
- }
74
- async request(e, t) {
75
- const i = await this.send(e, t);
76
- if (!i.ok)
77
- throw new o(i.status, e, await l(i));
78
- return await i.json();
79
- }
80
- async requestOrNull(e, t) {
81
- const i = await this.send(e, t);
82
- if (i.status === 404)
83
- return null;
84
- if (!i.ok)
85
- throw new o(i.status, e, await l(i));
86
- return await i.json();
87
- }
82
+ function i(e) {
83
+ return encodeURIComponent(e);
88
84
  }
89
- function d(s) {
90
- return new c(s);
85
+ function a(e) {
86
+ let t = new URLSearchParams();
87
+ for (let [n, r] of Object.entries(e)) r != null && r !== "" && t.append(n, String(r));
88
+ let n = t.toString();
89
+ return n ? `?${n}` : "";
91
90
  }
92
- function n(s) {
93
- return encodeURIComponent(s);
91
+ async function o(e) {
92
+ try {
93
+ return await e.text();
94
+ } catch {
95
+ return;
96
+ }
94
97
  }
95
- function h(s) {
96
- const e = new URLSearchParams();
97
- for (const [i, r] of Object.entries(s))
98
- r != null && r !== "" && e.append(i, String(r));
99
- const t = e.toString();
100
- return t ? `?${t}` : "";
98
+ //#endregion
99
+ //#region src/codegen.ts
100
+ var s = "@viglet/shio-client", c = "// AUTO-GENERATED by @viglet/shio-client (shio-types). DO NOT EDIT BY HAND.\n// Re-run `shio-types` after changing a post-type.";
101
+ function l(e, t = {}) {
102
+ let n = t.importFrom ?? s, r = t.banner ?? c, i = [...e].sort((e, t) => e.name.localeCompare(t.name)), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set();
103
+ for (let e of i) {
104
+ let t = m(e.name) || "PostType", n = t, r = 2;
105
+ for (; o.has(n);) n = `${t}${r++}`;
106
+ o.add(n), a.set(e.name, n);
107
+ }
108
+ let l = [];
109
+ for (let e of i) {
110
+ let t = a.get(e.name), n = f(e.title ?? e.description, 0);
111
+ l.push(`${n}export interface ${t}Attrs {\n${u(e.fields, 1)}}\n\n/** A \`${e.name}\` post with typed attributes. */\nexport type ${t}Post = ShioPost & {\n postType: ${JSON.stringify(e.name)};\n attrs: ${t}Attrs;\n};`);
112
+ }
113
+ let d = `/** Maps each post-type's API name to its typed post interface. */
114
+ export interface ShioPostTypes {\n${i.map((e) => ` ${p(e.name)}: ${a.get(e.name)}Post;`).join("\n") || ""}\n}\n\n/** Union of all known post-type API names. */
115
+ export type ShioPostTypeName = keyof ShioPostTypes;`;
116
+ return `${r}\n\nimport type { ShioPost } from ${JSON.stringify(n)};\n\n` + (l.length ? `${l.join("\n\n")}\n\n` : "") + `${d}\n`;
101
117
  }
102
- async function l(s) {
103
- try {
104
- return await s.text();
105
- } catch {
106
- return;
107
- }
118
+ function u(e, t) {
119
+ let n = " ".repeat(t);
120
+ return [...e].sort((e, t) => e.ordinal - t.ordinal).map((e) => {
121
+ let r = f(e.label ?? e.description, t), i = e.required ? "" : "?";
122
+ return `${r}${n}${p(e.name)}${i}: ${d(e, t)};\n`;
123
+ }).join("");
108
124
  }
109
- export {
110
- c as ShioClient,
111
- o as ShioHttpError,
112
- d as createShioClient
113
- };
125
+ function d(e, t) {
126
+ return e.fields && e.fields.length > 0 ? `Array<{\n${u(e.fields, t + 1)}${" ".repeat(t)}}>` : e.multiple ? "string[]" : "string";
127
+ }
128
+ function f(e, t) {
129
+ return !e || !e.trim() ? "" : `${" ".repeat(t)}/** ${e.trim().replace(/\*\//g, "*\\/")} */\n`;
130
+ }
131
+ function p(e) {
132
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e) ? e : JSON.stringify(e);
133
+ }
134
+ function m(e) {
135
+ let t = (e ?? "").split(/[^A-Za-z0-9]+/).filter(Boolean).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join("");
136
+ return /^[0-9]/.test(t) && (t = `T${t}`), t;
137
+ }
138
+ //#endregion
139
+ export { n as ShioClient, e as ShioHttpError, r as createShioClient, l as generateShioTypes };
@@ -1 +1,6 @@
1
- (function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.ShioClient={}))})(this,(function(s){"use strict";class n extends Error{constructor(e,t,i){super(`Shio CDA ${e} for ${t}`),this.name="ShioHttpError",this.status=e,this.url=t,this.body=i,Object.setPrototypeOf(this,n.prototype)}}const d="/api/v2/cda";class u{constructor(e){if(!(e!=null&&e.baseUrl))throw new Error("ShioClient: `baseUrl` is required");this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.headers={Accept:"application/json",...e.headers??{}},e.apiToken&&(this.headers.Key=e.apiToken);const t=e.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("ShioClient: no global `fetch` available — pass `fetch` in the config");this.fetchFn=t.bind(globalThis),this.credentials=e.credentials}getSites(e){return this.request("/site",e)}getSite(e,t){return this.requestOrNull(`/site/${l(e)}`,t)}listChildren(e,t,i){const o=h({page:t==null?void 0:t.page,size:t==null?void 0:t.size});return this.requestOrNull(`/object/${l(e)}/list${o}`,i)}getPath(e,t){return this.requestOrNull(`/object/${l(e)}/path`,t)}getPost(e,t){return this.requestOrNull(`/post/${l(e)}`,t)}getPostByUrl(e,t,i){const o=h({siteId:e,url:t});return this.requestOrNull(`/post/by-url${o}`,i)}query(e,t){const i=h({siteId:e==null?void 0:e.siteId,folderId:e==null?void 0:e.folderId,postType:e==null?void 0:e.postType,page:e==null?void 0:e.page,size:e==null?void 0:e.size});return this.request(`/query${i}`,t)}async send(e,t){return this.fetchFn(`${this.baseUrl}${d}${e}`,{method:"GET",headers:this.headers,signal:t==null?void 0:t.signal,...this.credentials?{credentials:this.credentials}:{}})}async request(e,t){const i=await this.send(e,t);if(!i.ok)throw new n(i.status,e,await c(i));return await i.json()}async requestOrNull(e,t){const i=await this.send(e,t);if(i.status===404)return null;if(!i.ok)throw new n(i.status,e,await c(i));return await i.json()}}function f(r){return new u(r)}function l(r){return encodeURIComponent(r)}function h(r){const e=new URLSearchParams;for(const[i,o]of Object.entries(r))o!=null&&o!==""&&e.append(i,String(o));const t=e.toString();return t?`?${t}`:""}async function c(r){try{return await r.text()}catch{return}}s.ShioClient=u,s.ShioHttpError=n,s.createShioClient=f,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ShioClient={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class e extends Error{constructor(t,n,r){super(`Shio CDA ${t} for ${n}`),this.name=`ShioHttpError`,this.status=t,this.url=n,this.body=r,Object.setPrototypeOf(this,e.prototype)}},n=`/api/v2/cda`,r=class{constructor(e){if(!e?.baseUrl)throw Error("ShioClient: `baseUrl` is required");this.baseUrl=e.baseUrl.replace(/\/+$/,``),this.headers={Accept:`application/json`,...e.headers??{}},e.apiToken&&(this.headers.Key=e.apiToken);let t=e.fetch??globalThis.fetch;if(typeof t!=`function`)throw Error("ShioClient: no global `fetch` available — pass `fetch` in the config");this.fetchFn=t.bind(globalThis),this.credentials=e.credentials}getSites(e){return this.request(`/site`,e)}getSite(e,t){return this.requestOrNull(`/site/${a(e)}`,t)}listChildren(e,t,n){let r=o({page:t?.page,size:t?.size});return this.requestOrNull(`/object/${a(e)}/list${r}`,n)}getPath(e,t){return this.requestOrNull(`/object/${a(e)}/path`,t)}getPost(e,t){return this.requestOrNull(`/post/${a(e)}`,t)}getPostByUrl(e,t,n){let r=o({siteId:e,url:t});return this.requestOrNull(`/post/by-url${r}`,n)}getPostTypes(e){return this.request(`/post-type`,e)}getPostType(e,t){return this.requestOrNull(`/post-type/${a(e)}`,t)}query(e,t){let n=o({siteId:e?.siteId,folderId:e?.folderId,postType:e?.postType,page:e?.page,size:e?.size});return this.request(`/query${n}`,t)}async send(e,t){return this.fetchFn(`${this.baseUrl}${n}${e}`,{method:`GET`,headers:this.headers,signal:t?.signal,...this.credentials?{credentials:this.credentials}:{}})}async request(e,n){let r=await this.send(e,n);if(!r.ok)throw new t(r.status,e,await s(r));return await r.json()}async requestOrNull(e,n){let r=await this.send(e,n);if(r.status===404)return null;if(!r.ok)throw new t(r.status,e,await s(r));return await r.json()}};function i(e){return new r(e)}function a(e){return encodeURIComponent(e)}function o(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!=null&&r!==``&&t.append(n,String(r));let n=t.toString();return n?`?${n}`:``}async function s(e){try{return await e.text()}catch{return}}var c=`@viglet/shio-client`,l="// AUTO-GENERATED by @viglet/shio-client (shio-types). DO NOT EDIT BY HAND.\n// Re-run `shio-types` after changing a post-type.";function u(e,t={}){let n=t.importFrom??c,r=t.banner??l,i=[...e].sort((e,t)=>e.name.localeCompare(t.name)),a=new Map,o=new Set;for(let e of i){let t=h(e.name)||`PostType`,n=t,r=2;for(;o.has(n);)n=`${t}${r++}`;o.add(n),a.set(e.name,n)}let s=[];for(let e of i){let t=a.get(e.name),n=p(e.title??e.description,0);s.push(`${n}export interface ${t}Attrs {\n${d(e.fields,1)}}\n\n/** A \`${e.name}\` post with typed attributes. */\nexport type ${t}Post = ShioPost & {\n postType: ${JSON.stringify(e.name)};\n attrs: ${t}Attrs;\n};`)}let u=`/** Maps each post-type's API name to its typed post interface. */
2
+ export interface ShioPostTypes {\n${i.map(e=>` ${m(e.name)}: ${a.get(e.name)}Post;`).join(`
3
+ `)||``}\n}\n\n/** Union of all known post-type API names. */
4
+ export type ShioPostTypeName = keyof ShioPostTypes;`;return`${r}\n\nimport type { ShioPost } from ${JSON.stringify(n)};\n\n`+(s.length?`${s.join(`
5
+
6
+ `)}\n\n`:``)+`${u}\n`}function d(e,t){let n=` `.repeat(t);return[...e].sort((e,t)=>e.ordinal-t.ordinal).map(e=>{let r=p(e.label??e.description,t),i=e.required?``:`?`;return`${r}${n}${m(e.name)}${i}: ${f(e,t)};\n`}).join(``)}function f(e,t){return e.fields&&e.fields.length>0?`Array<{\n${d(e.fields,t+1)}${` `.repeat(t)}}>`:e.multiple?`string[]`:`string`}function p(e,t){return!e||!e.trim()?``:`${` `.repeat(t)}/** ${e.trim().replace(/\*\//g,`*\\/`)} */\n`}function m(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)?e:JSON.stringify(e)}function h(e){let t=(e??``).split(/[^A-Za-z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return/^[0-9]/.test(t)&&(t=`T${t}`),t}e.ShioClient=r,e.ShioHttpError=t,e.createShioClient=i,e.generateShioTypes=u});
package/dist/types.d.ts CHANGED
@@ -3,6 +3,14 @@
3
3
  * `/api/v2/cda/**`). Field names track the backend DTO records
4
4
  * (`com.viglet.shio.api.cda.dto`) one-for-one — they are a frozen public
5
5
  * contract; do not rename.
6
+ *
7
+ * **Optional, not nullable (SH127).** A field the CMS has no value for is *absent*
8
+ * from the JSON rather than present as `null`, so it is declared `field?: T` here.
9
+ * These two halves shipped together and had to: the backend omits the null because
10
+ * `"url": null` costs bytes and tokens to say nothing, and this file declares it
11
+ * optional because a consumer written against `string | null` would otherwise start
12
+ * receiving `undefined` from a comparison it believed was exhaustive. Narrow with a
13
+ * falsy check (`if (post.title)`) rather than `=== null`.
6
14
  */
7
15
  /** Configuration for {@link ShioClient}. */
8
16
  export interface ShioClientConfig {
@@ -35,9 +43,9 @@ export interface ShioRequestOptions {
35
43
  export interface ShioSite {
36
44
  id: string;
37
45
  name: string;
38
- description: string | null;
39
- url: string | null;
40
- rootFolderId: string | null;
46
+ description?: string;
47
+ url?: string;
48
+ rootFolderId?: string;
41
49
  }
42
50
  /** A folder (listing item / breadcrumb node). */
43
51
  export interface ShioFolder {
@@ -48,32 +56,42 @@ export interface ShioFolder {
48
56
  /** A post listing item — no heavy attribute payload. */
49
57
  export interface ShioPostSummary {
50
58
  id: string;
51
- title: string | null;
52
- summary: string | null;
53
- furl: string | null;
54
- postType: string | null;
55
- date: string | null;
56
- modifiedDate: string | null;
59
+ title?: string;
60
+ summary?: string;
61
+ furl?: string;
62
+ postType?: string;
63
+ /** BCP-47 locale of this row (SH52), absent on single-language content. */
64
+ locale?: string;
65
+ date?: string;
66
+ modifiedDate?: string;
57
67
  }
58
68
  /** A full post with its post-type attributes expanded into {@link attrs}. */
59
69
  export interface ShioPost {
60
70
  id: string;
61
- title: string | null;
62
- summary: string | null;
63
- furl: string | null;
64
- postType: string | null;
65
- siteId: string | null;
66
- folderId: string | null;
71
+ title?: string;
72
+ summary?: string;
73
+ furl?: string;
74
+ postType?: string;
75
+ siteId?: string;
76
+ folderId?: string;
67
77
  published: boolean;
68
- date: string | null;
69
- modifiedDate: string | null;
70
- publicationDate: string | null;
78
+ date?: string;
79
+ modifiedDate?: string;
80
+ publicationDate?: string;
81
+ /** BCP-47 locale of this post (SH52), absent on single-language content. */
82
+ locale?: string;
83
+ /**
84
+ * Every locale this post is translated into, including {@link locale} — the
85
+ * list a language switcher renders from (SH52). Always present; `[]` on a
86
+ * post with no translation group.
87
+ */
88
+ availableLocales: string[];
71
89
  /** Post-type attributes as a JSON object, keyed by attribute name. */
72
90
  attrs: Record<string, unknown>;
73
91
  }
74
92
  /** Folder children: subfolders plus a paged slice of published posts. */
75
93
  export interface ShioListing {
76
- folderId: string | null;
94
+ folderId?: string;
77
95
  folders: ShioFolder[];
78
96
  posts: ShioPostSummary[];
79
97
  page: number;
@@ -82,10 +100,46 @@ export interface ShioListing {
82
100
  }
83
101
  /** Breadcrumb path for a folder or post. */
84
102
  export interface ShioPath {
85
- site: ShioSite | null;
103
+ site?: ShioSite;
86
104
  /** Ordered root → ... → current. */
87
105
  breadcrumb: ShioFolder[];
88
- currentFolder: ShioFolder | null;
106
+ currentFolder?: ShioFolder;
107
+ }
108
+ /**
109
+ * One field of a post-type's content model (SH11). Recursive: a Relator field
110
+ * carries its item sub-fields in {@link fields}. Mirrors the backend
111
+ * `ShCdaSchemaField` record one-for-one.
112
+ */
113
+ export interface ShioFieldSchema {
114
+ name: string;
115
+ label?: string;
116
+ description?: string;
117
+ /** The Shio widget name (e.g. `"Text"`, `"Relator"`), or `null`. */
118
+ widget?: string;
119
+ required: boolean;
120
+ /**
121
+ * The delivered value is an array — a `Check Box` / `Multi Select` value, or a
122
+ * Relator's item list (in which case {@link fields} is non-empty).
123
+ */
124
+ multiple: boolean;
125
+ isTitle: boolean;
126
+ isSummary: boolean;
127
+ ordinal: number;
128
+ /** Sub-fields, for a Relator; empty for scalar fields. */
129
+ fields: ShioFieldSchema[];
130
+ }
131
+ /**
132
+ * A post-type's content model (SH11): its API {@link name} plus the ordered
133
+ * fields a post of this type exposes under {@link ShioPost.attrs}. Mirrors the
134
+ * backend `ShCdaPostTypeSchema` record. Feed an array of these to
135
+ * {@link generateShioTypes} to emit `.d.ts` declarations.
136
+ */
137
+ export interface ShioPostTypeSchema {
138
+ name: string;
139
+ title?: string;
140
+ namePlural?: string;
141
+ description?: string;
142
+ fields: ShioFieldSchema[];
89
143
  }
90
144
  /** Parameters for {@link ShioClient.query}. */
91
145
  export interface ShioQueryParams {
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@viglet/shio-client",
3
- "version": "2026.2.1",
3
+ "version": "2026.3.2",
4
4
  "description": "Framework-agnostic TypeScript client for the Shio CMS Content Delivery API (CDA). Zero runtime dependencies — works in Node, the browser, edge runtimes, Next.js server components, Astro, Vue, Svelte and plain scripts.",
5
+ "homepage": "https://shio.viglet.org/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/openviglet/shio.git",
9
+ "directory": "shio-client"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/openviglet/shio/issues"
13
+ },
5
14
  "type": "module",
6
15
  "main": "dist/shio-client.umd.cjs",
7
16
  "module": "dist/shio-client.js",
@@ -11,27 +20,47 @@
11
20
  "types": "./dist/index.d.ts",
12
21
  "import": "./dist/shio-client.js",
13
22
  "require": "./dist/shio-client.umd.cjs"
14
- }
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "bin": {
27
+ "shio-types": "bin/shio-types.mjs"
15
28
  },
16
29
  "files": [
17
- "dist"
30
+ "dist",
31
+ "bin"
18
32
  ],
19
33
  "sideEffects": false,
20
34
  "devDependencies": {
21
35
  "typescript": "^5.8.3",
22
- "vite": "^6.3.1"
36
+ "vite": "^8.2.0"
23
37
  },
24
38
  "keywords": [
25
39
  "shio",
40
+ "viglet",
26
41
  "cms",
27
- "headless",
42
+ "headless-cms",
43
+ "content-management-system",
44
+ "agent",
45
+ "ai",
46
+ "mcp",
47
+ "model-context-protocol",
48
+ "claude-code",
28
49
  "cda",
29
50
  "content-delivery",
30
51
  "typescript",
31
- "sdk"
52
+ "sdk",
53
+ "api-client",
54
+ "nextjs",
55
+ "astro",
56
+ "edge",
57
+ "headless"
32
58
  ],
33
- "author": "Viglet Team",
34
- "license": "GPL-3.0",
59
+ "author": {
60
+ "name": "Viglet Team",
61
+ "url": "https://www.viglet.org"
62
+ },
63
+ "license": "Apache-2.0",
35
64
  "scripts": {
36
65
  "dev": "vite build --watch",
37
66
  "build": "vite build && tsc --emitDeclarationOnly",