talizen 0.0.7 → 0.0.9
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 +55 -36
- package/{dist/cms/index.d.ts → cms.d.ts} +1 -1
- package/{dist/cms/index.js → cms.js} +1 -1
- package/{dist/core/index.d.ts → core.d.ts} +5 -0
- package/{dist/core/index.js → core.js} +5 -4
- package/{dist/form/index.d.ts → form.d.ts} +1 -1
- package/{dist/form/index.js → form.js} +1 -1
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +12 -22
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
package/README.md
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
# talizen
|
|
2
2
|
|
|
3
|
-
Talizen
|
|
3
|
+
Talizen's frontend SDK package. It provides a small runtime client and shared types for:
|
|
4
4
|
|
|
5
5
|
- `talizen/core`
|
|
6
6
|
- `talizen/cms`
|
|
7
7
|
- `talizen/form`
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The package is designed to hold the platform-level APIs that frontend projects use directly, while project-specific CMS and form schema types can still be generated separately per project.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Install
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm install talizen
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Configure the client
|
|
18
20
|
|
|
19
21
|
```ts
|
|
20
22
|
import { setTalizenConfig } from "talizen/core"
|
|
21
|
-
import { ListContent, type BaseCmsItem } from "talizen/cms"
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
setTalizenConfig({
|
|
25
|
+
baseUrl: "https://www.talizen.com",
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### List CMS content
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { listContents, type BaseCmsItem } from "talizen/cms"
|
|
33
|
+
|
|
34
|
+
interface Blog extends BaseCmsItem {
|
|
24
35
|
readonly __cmsKey: "blogs"
|
|
25
36
|
body: {
|
|
26
37
|
title?: string
|
|
@@ -28,53 +39,61 @@ interface Blogs extends BaseCmsItem {
|
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
baseUrl: "https://www.talizen.com",
|
|
33
|
-
projectId: "demo-project",
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const blogs = await ListContent<Blogs>("blogs", {
|
|
42
|
+
const result = await listContents<Blog>("blogs", {
|
|
37
43
|
limit: 10,
|
|
44
|
+
orderBy: "-created_at",
|
|
38
45
|
})
|
|
46
|
+
|
|
47
|
+
console.log(result.list)
|
|
48
|
+
console.log(result.total)
|
|
39
49
|
```
|
|
40
50
|
|
|
41
|
-
|
|
51
|
+
### Get a single CMS content item
|
|
42
52
|
|
|
43
53
|
```ts
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
import { getContent, type BaseCmsItem } from "talizen/cms"
|
|
55
|
+
|
|
56
|
+
interface Blog extends BaseCmsItem {
|
|
57
|
+
readonly __cmsKey: "blogs"
|
|
58
|
+
body: {
|
|
59
|
+
title?: string
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const blog = await getContent<Blog>("blogs", "hello-world")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Submit a form
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { submitForm } from "talizen/form"
|
|
70
|
+
|
|
71
|
+
await submitForm("contact-form", {
|
|
72
|
+
email: "hi@talizen.com",
|
|
73
|
+
message: "Hello from the website",
|
|
74
|
+
})
|
|
57
75
|
```
|
|
58
76
|
|
|
59
|
-
##
|
|
77
|
+
## Package Layout
|
|
60
78
|
|
|
61
|
-
- `talizen/core
|
|
62
|
-
- `talizen/cms
|
|
63
|
-
- `talizen/form
|
|
79
|
+
- `talizen/core`: shared runtime config, request helpers, and base data types.
|
|
80
|
+
- `talizen/cms`: CMS content types and content query APIs.
|
|
81
|
+
- `talizen/form`: form submission helpers and related types.
|
|
64
82
|
|
|
65
|
-
|
|
83
|
+
## Publish
|
|
66
84
|
|
|
67
|
-
|
|
85
|
+
Build and prepare the package contents:
|
|
68
86
|
|
|
69
87
|
```bash
|
|
70
88
|
npm install
|
|
71
89
|
npm run build
|
|
72
|
-
|
|
90
|
+
node scripts/prepare-publish.mjs
|
|
73
91
|
```
|
|
74
92
|
|
|
75
|
-
GitHub Actions
|
|
93
|
+
The GitHub Actions workflow in `.github/workflows/publish.yml` publishes on a tag push. Release a new version with:
|
|
76
94
|
|
|
77
95
|
```bash
|
|
78
|
-
git tag v0.
|
|
79
|
-
git push origin
|
|
96
|
+
git tag v0.0.8
|
|
97
|
+
git push origin main
|
|
98
|
+
git push origin v0.0.8
|
|
80
99
|
```
|
|
@@ -21,5 +21,10 @@ export interface TalizenRequestOptions extends TalizenClientConfig {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function setTalizenConfig(config: TalizenClientConfig): void;
|
|
23
23
|
export declare function getTalizenConfig(): TalizenClientConfig;
|
|
24
|
+
declare global {
|
|
25
|
+
interface Window {
|
|
26
|
+
TalizenConfig?: TalizenClientConfig | undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
24
29
|
export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "fetch">> & TalizenRequestOptions;
|
|
25
30
|
export declare function requestJson<T>(path: string, init?: RequestInit, config?: TalizenRequestOptions): Promise<T>;
|
|
@@ -11,7 +11,9 @@ export function getTalizenConfig() {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export function resolveTalizenConfig(config) {
|
|
14
|
+
const windowConfig = typeof window !== "undefined" ? window.TalizenConfig : {};
|
|
14
15
|
const merged = {
|
|
16
|
+
...windowConfig,
|
|
15
17
|
...globalTalizenConfig,
|
|
16
18
|
...config,
|
|
17
19
|
};
|
|
@@ -24,13 +26,12 @@ export function resolveTalizenConfig(config) {
|
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
function joinUrl(baseUrl, path) {
|
|
27
|
-
const base = baseUrl.endsWith(
|
|
28
|
-
const subPath = path.startsWith(
|
|
29
|
+
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
30
|
+
const subPath = path.startsWith("/") ? path.slice(1) : path;
|
|
29
31
|
return `${base}/${subPath}`;
|
|
30
32
|
}
|
|
31
33
|
function buildTalizenUrl(path, config) {
|
|
32
34
|
const resolved = resolveTalizenConfig(config);
|
|
33
|
-
// new URL is not used because baseUrl may not include protocols and domain names, e.g. /api
|
|
34
35
|
return joinUrl(resolved.baseUrl, path);
|
|
35
36
|
}
|
|
36
37
|
export async function requestJson(path, init, config) {
|
|
@@ -63,7 +64,7 @@ function getDefaultBaseUrl() {
|
|
|
63
64
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
64
65
|
return window.location.origin;
|
|
65
66
|
}
|
|
66
|
-
throw new Error("Talizen baseUrl is required.
|
|
67
|
+
throw new Error("Talizen baseUrl is required. set window.TalizenConfig = { baseUrl: 'https://example.com' } first.");
|
|
67
68
|
}
|
|
68
69
|
function getDefaultFetch() {
|
|
69
70
|
if (typeof fetch === "function") {
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,38 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "talizen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Talizen frontend SDK types for cms, form and core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist",
|
|
9
|
-
"README.md"
|
|
10
|
-
],
|
|
11
7
|
"sideEffects": false,
|
|
12
|
-
"
|
|
8
|
+
"main": "./index.js",
|
|
9
|
+
"types": "./index.d.ts",
|
|
13
10
|
"exports": {
|
|
14
11
|
".": {
|
|
15
|
-
"types": "./
|
|
16
|
-
"import": "./
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js"
|
|
17
14
|
},
|
|
18
15
|
"./core": {
|
|
19
|
-
"types": "./
|
|
20
|
-
"import": "./
|
|
16
|
+
"types": "./core.d.ts",
|
|
17
|
+
"import": "./core.js"
|
|
21
18
|
},
|
|
22
19
|
"./cms": {
|
|
23
|
-
"types": "./
|
|
24
|
-
"import": "./
|
|
20
|
+
"types": "./cms.d.ts",
|
|
21
|
+
"import": "./cms.js"
|
|
25
22
|
},
|
|
26
23
|
"./form": {
|
|
27
|
-
"types": "./
|
|
28
|
-
"import": "./
|
|
24
|
+
"types": "./form.d.ts",
|
|
25
|
+
"import": "./form.js"
|
|
29
26
|
}
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsc -p tsconfig.json",
|
|
33
|
-
"check": "tsc -p tsconfig.json --noEmit"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"typescript": "^5.9.2"
|
|
37
27
|
}
|
|
38
|
-
}
|
|
28
|
+
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED