@mhbdev/unicms 0.1.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 +117 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +30 -0
- package/dist/client.js.map +1 -0
- package/dist/contracts/v1.d.ts +13507 -0
- package/dist/contracts/v1.d.ts.map +1 -0
- package/dist/contracts/v1.js +354 -0
- package/dist/contracts/v1.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +15 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +129 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/methods/getPageBySlug.d.ts +6 -0
- package/dist/methods/getPageBySlug.d.ts.map +1 -0
- package/dist/methods/getPageBySlug.js +12 -0
- package/dist/methods/getPageBySlug.js.map +1 -0
- package/dist/methods/getPostBySlug.d.ts +6 -0
- package/dist/methods/getPostBySlug.d.ts.map +1 -0
- package/dist/methods/getPostBySlug.js +12 -0
- package/dist/methods/getPostBySlug.js.map +1 -0
- package/dist/methods/getSiteSettings.d.ts +4 -0
- package/dist/methods/getSiteSettings.d.ts.map +1 -0
- package/dist/methods/getSiteSettings.js +9 -0
- package/dist/methods/getSiteSettings.js.map +1 -0
- package/dist/methods/listCategories.d.ts +4 -0
- package/dist/methods/listCategories.d.ts.map +1 -0
- package/dist/methods/listCategories.js +9 -0
- package/dist/methods/listCategories.js.map +1 -0
- package/dist/methods/listFaqs.d.ts +6 -0
- package/dist/methods/listFaqs.d.ts.map +1 -0
- package/dist/methods/listFaqs.js +12 -0
- package/dist/methods/listFaqs.js.map +1 -0
- package/dist/methods/listPosts.d.ts +4 -0
- package/dist/methods/listPosts.d.ts.map +1 -0
- package/dist/methods/listPosts.js +16 -0
- package/dist/methods/listPosts.js.map +1 -0
- package/dist/methods/listTags.d.ts +4 -0
- package/dist/methods/listTags.d.ts.map +1 -0
- package/dist/methods/listTags.js +9 -0
- package/dist/methods/listTags.js.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# @mhbdev/unicms
|
|
2
|
+
|
|
3
|
+
Typed SDK for the UniCMS public API (`/api/public/v1/*`).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @mhbdev/unicms
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Create client
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createUniCmsClient } from '@mhbdev/unicms'
|
|
15
|
+
|
|
16
|
+
const cms = createUniCmsClient({
|
|
17
|
+
baseUrl: 'https://cms.example.com',
|
|
18
|
+
tenant: { slug: 'acme' },
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Use domain-based tenant scope instead:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const cms = createUniCmsClient({
|
|
26
|
+
baseUrl: 'https://cms.example.com',
|
|
27
|
+
tenant: { domain: 'acme.example.com' },
|
|
28
|
+
})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Optional auth headers (private tenants)
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const cms = createUniCmsClient({
|
|
35
|
+
baseUrl: 'https://cms.example.com',
|
|
36
|
+
tenant: { slug: 'acme' },
|
|
37
|
+
headers: async () => ({
|
|
38
|
+
Authorization: `Bearer ${await getToken()}`,
|
|
39
|
+
}),
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
await cms.getSiteSettings()
|
|
47
|
+
await cms.getPageBySlug('home')
|
|
48
|
+
await cms.getPageBySlug('pricing', { includeRawContent: true })
|
|
49
|
+
|
|
50
|
+
await cms.listPosts({ page: 1, limit: 10, q: 'cms', categorySlug: 'news', tagSlug: 'payload' })
|
|
51
|
+
await cms.getPostBySlug('hello-world')
|
|
52
|
+
await cms.getPostBySlug('hello-world', { includeRawContent: true })
|
|
53
|
+
|
|
54
|
+
await cms.listFaqs()
|
|
55
|
+
await cms.listFaqs({ includeRawContent: true })
|
|
56
|
+
|
|
57
|
+
await cms.listCategories()
|
|
58
|
+
await cms.listTags()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Error handling
|
|
62
|
+
|
|
63
|
+
SDK methods throw `UniCmsError`:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { UniCmsError } from '@mhbdev/unicms'
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await cms.getPageBySlug('missing-page')
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (error instanceof UniCmsError) {
|
|
72
|
+
console.error(error.code, error.status, error.message, error.details)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Error codes:
|
|
78
|
+
- `BAD_REQUEST`
|
|
79
|
+
- `UNAUTHORIZED`
|
|
80
|
+
- `FORBIDDEN`
|
|
81
|
+
- `NOT_FOUND`
|
|
82
|
+
- `VALIDATION_ERROR`
|
|
83
|
+
- `NETWORK_ERROR`
|
|
84
|
+
- `PARSE_ERROR`
|
|
85
|
+
- `UNKNOWN`
|
|
86
|
+
|
|
87
|
+
## Pagination
|
|
88
|
+
|
|
89
|
+
`listPosts` returns:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
type Paginated<T> = {
|
|
93
|
+
docs: T[]
|
|
94
|
+
pagination: {
|
|
95
|
+
page: number
|
|
96
|
+
limit: number
|
|
97
|
+
totalDocs: number
|
|
98
|
+
totalPages: number
|
|
99
|
+
hasNextPage: boolean
|
|
100
|
+
hasPrevPage: boolean
|
|
101
|
+
nextPage: number | null
|
|
102
|
+
prevPage: number | null
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Defaults: `page=1`, `limit=10`, max `limit=50`.
|
|
108
|
+
|
|
109
|
+
## Compatibility
|
|
110
|
+
|
|
111
|
+
- SDK targets UniCMS public API v1.
|
|
112
|
+
- Endpoints are expected at `/api/public/v1/*`.
|
|
113
|
+
- v1 returns published content only.
|
|
114
|
+
|
|
115
|
+
## Release notes
|
|
116
|
+
|
|
117
|
+
- `0.1.x`: Initial v1 contract-first release.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAYnE,eAAO,MAAM,kBAAkB,GAAI,SAAS,mBAAmB,KAAG,YAcjE,CAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHttpClient } from './http.js';
|
|
2
|
+
import { getPageBySlug } from './methods/getPageBySlug.js';
|
|
3
|
+
import { getPostBySlug } from './methods/getPostBySlug.js';
|
|
4
|
+
import { getSiteSettings } from './methods/getSiteSettings.js';
|
|
5
|
+
import { listCategories } from './methods/listCategories.js';
|
|
6
|
+
import { listFaqs } from './methods/listFaqs.js';
|
|
7
|
+
import { listPosts } from './methods/listPosts.js';
|
|
8
|
+
import { listTags } from './methods/listTags.js';
|
|
9
|
+
const assertTenantScope = (options) => {
|
|
10
|
+
if ('slug' in options.tenant && !options.tenant.slug.trim()) {
|
|
11
|
+
throw new Error('tenant.slug must be a non-empty string');
|
|
12
|
+
}
|
|
13
|
+
if ('domain' in options.tenant && !options.tenant.domain.trim()) {
|
|
14
|
+
throw new Error('tenant.domain must be a non-empty string');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const createUniCmsClient = (options) => {
|
|
18
|
+
assertTenantScope(options);
|
|
19
|
+
const http = createHttpClient(options);
|
|
20
|
+
return {
|
|
21
|
+
getSiteSettings: () => getSiteSettings(http),
|
|
22
|
+
getPageBySlug: (slug, opts) => getPageBySlug(http, slug, opts),
|
|
23
|
+
listPosts: (params) => listPosts(http, params),
|
|
24
|
+
getPostBySlug: (slug, opts) => getPostBySlug(http, slug, opts),
|
|
25
|
+
listFaqs: (opts) => listFaqs(http, opts),
|
|
26
|
+
listCategories: () => listCategories(http),
|
|
27
|
+
listTags: () => listTags(http),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGhD,MAAM,iBAAiB,GAAG,CAAC,OAA4B,EAAE,EAAE;IACzD,IAAI,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QAC5D,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;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