talizen 0.0.6 → 0.0.8
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} +5 -10
- package/cms.js +37 -0
- package/{dist/core/index.d.ts → core.d.ts} +0 -1
- package/{dist/core/index.js → core.js} +7 -5
- package/form.d.ts +6 -0
- package/form.js +7 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +12 -22
- package/dist/cms/index.js +0 -46
- package/dist/form/index.d.ts +0 -6
- package/dist/form/index.js +0 -10
- 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
|
```
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { type TalizenRequestOptions } from "
|
|
1
|
+
import { type TalizenRequestOptions } from "./core.js";
|
|
2
2
|
export interface BaseCmsItem {
|
|
3
3
|
readonly __cmsKey: string;
|
|
4
4
|
slug: string;
|
|
5
5
|
id: string;
|
|
6
6
|
body: Record<string, unknown>;
|
|
7
7
|
}
|
|
8
|
-
export interface CmsListItem<T extends BaseCmsItem = BaseCmsItem> {
|
|
9
|
-
key: T["__cmsKey"];
|
|
10
|
-
name: string;
|
|
11
|
-
Item: T;
|
|
12
|
-
}
|
|
13
8
|
export interface GetContentListFilterCondition {
|
|
14
9
|
fieldId?: string;
|
|
15
10
|
operator?: string;
|
|
@@ -42,10 +37,10 @@ export interface ContentWithPrevNext<T extends BaseCmsItem> {
|
|
|
42
37
|
next?: T;
|
|
43
38
|
prev?: T;
|
|
44
39
|
}
|
|
45
|
-
export interface ListResponse<T
|
|
40
|
+
export interface ListResponse<T> {
|
|
46
41
|
list?: T[];
|
|
47
42
|
total?: number;
|
|
48
43
|
}
|
|
49
|
-
export declare function
|
|
50
|
-
export declare function
|
|
51
|
-
export declare function
|
|
44
|
+
export declare function listContents<T extends BaseCmsItem>(key: T["__cmsKey"], params?: ListContentParams, options?: TalizenRequestOptions): Promise<ListResponse<T>>;
|
|
45
|
+
export declare function getContent<T extends BaseCmsItem>(key: T["__cmsKey"], slug: string, params?: GetContentParams, options?: TalizenRequestOptions): Promise<T>;
|
|
46
|
+
export declare function getContentWithPrevNext<T extends BaseCmsItem>(key: T["__cmsKey"], slug: string, params?: GetContentWithPrevNextParams, options?: TalizenRequestOptions): Promise<ContentWithPrevNext<T>>;
|
package/cms.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { requestJson } from "./core.js";
|
|
2
|
+
export async function listContents(key, params = {}, options) {
|
|
3
|
+
const response = await requestJson(`/cms/${key}/content_list`, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
body: JSON.stringify({
|
|
6
|
+
limit: params.limit,
|
|
7
|
+
offset: params.offset,
|
|
8
|
+
search_key: params.searchKey,
|
|
9
|
+
order_by: params.orderBy,
|
|
10
|
+
builtin_ref: params.builtinRef,
|
|
11
|
+
filter: params.filter,
|
|
12
|
+
}),
|
|
13
|
+
}, options);
|
|
14
|
+
return response;
|
|
15
|
+
}
|
|
16
|
+
export async function getContent(key, slug, params, options) {
|
|
17
|
+
const url = new URL(`/cms/${key}/content`, "https://talizen.local");
|
|
18
|
+
url.searchParams.set("slug", slug);
|
|
19
|
+
if (params?.builtinRef != null) {
|
|
20
|
+
url.searchParams.set("builtin_ref", String(params.builtinRef));
|
|
21
|
+
}
|
|
22
|
+
return requestJson(url.pathname + url.search, undefined, options);
|
|
23
|
+
}
|
|
24
|
+
export async function getContentWithPrevNext(key, slug, params = {}, options) {
|
|
25
|
+
return requestJson(`/cms/${key}/content_with_prev_next`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
slug,
|
|
29
|
+
prev: params.prev,
|
|
30
|
+
next: params.next,
|
|
31
|
+
search_key: params.searchKey,
|
|
32
|
+
order_by: params.orderBy,
|
|
33
|
+
builtin_ref: params.builtinRef,
|
|
34
|
+
filter: params.filter,
|
|
35
|
+
}),
|
|
36
|
+
}, options);
|
|
37
|
+
}
|
|
@@ -22,5 +22,4 @@ export interface TalizenRequestOptions extends TalizenClientConfig {
|
|
|
22
22
|
export declare function setTalizenConfig(config: TalizenClientConfig): void;
|
|
23
23
|
export declare function getTalizenConfig(): TalizenClientConfig;
|
|
24
24
|
export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "fetch">> & TalizenRequestOptions;
|
|
25
|
-
export declare function buildTalizenUrl(path: string, config?: TalizenRequestOptions): string;
|
|
26
25
|
export declare function requestJson<T>(path: string, init?: RequestInit, config?: TalizenRequestOptions): Promise<T>;
|
|
@@ -23,9 +23,14 @@ export function resolveTalizenConfig(config) {
|
|
|
23
23
|
fetch: fetchImpl,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
function joinUrl(baseUrl, path) {
|
|
27
|
+
const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
28
|
+
const subPath = path.startsWith("/") ? path.slice(1) : path;
|
|
29
|
+
return `${base}/${subPath}`;
|
|
30
|
+
}
|
|
31
|
+
function buildTalizenUrl(path, config) {
|
|
27
32
|
const resolved = resolveTalizenConfig(config);
|
|
28
|
-
return
|
|
33
|
+
return joinUrl(resolved.baseUrl, path);
|
|
29
34
|
}
|
|
30
35
|
export async function requestJson(path, init, config) {
|
|
31
36
|
const resolved = resolveTalizenConfig(config);
|
|
@@ -53,9 +58,6 @@ export async function requestJson(path, init, config) {
|
|
|
53
58
|
}
|
|
54
59
|
return JSON.parse(text);
|
|
55
60
|
}
|
|
56
|
-
function ensureBaseUrl(baseUrl) {
|
|
57
|
-
return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
58
|
-
}
|
|
59
61
|
function getDefaultBaseUrl() {
|
|
60
62
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
61
63
|
return window.location.origin;
|
package/form.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TalizenRequestOptions } from "./core.js";
|
|
2
|
+
export interface FormRecord {
|
|
3
|
+
readonly __formKey?: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare function submitForm<T extends FormRecord>(keyOrToken: T["__formKey"] | string, payload: T, options?: TalizenRequestOptions): Promise<"ok">;
|
package/form.js
ADDED
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.8",
|
|
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/cms/index.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { requestJson, resolveTalizenConfig } from "../core/index.js";
|
|
2
|
-
export async function ListContent(key, params = {}, options) {
|
|
3
|
-
const response = await requestJson(`/cms/${key}/content_list`, {
|
|
4
|
-
method: "POST",
|
|
5
|
-
body: JSON.stringify({
|
|
6
|
-
limit: params.limit,
|
|
7
|
-
offset: params.offset,
|
|
8
|
-
search_key: params.searchKey,
|
|
9
|
-
order_by: params.orderBy,
|
|
10
|
-
builtin_ref: params.builtinRef,
|
|
11
|
-
filter: params.filter,
|
|
12
|
-
}),
|
|
13
|
-
}, options);
|
|
14
|
-
return response;
|
|
15
|
-
}
|
|
16
|
-
export async function GetContent(key, slug, params, options) {
|
|
17
|
-
const url = new URL(`/cms/${key}/content`, "https://talizen.local");
|
|
18
|
-
url.searchParams.set("slug", slug);
|
|
19
|
-
if (params?.builtinRef != null) {
|
|
20
|
-
url.searchParams.set("builtin_ref", String(params.builtinRef));
|
|
21
|
-
}
|
|
22
|
-
return requestJson(url.pathname + url.search, undefined, options);
|
|
23
|
-
}
|
|
24
|
-
export async function GetContentWithPrevNext(key, slug, params = {}, options) {
|
|
25
|
-
const url = new URL(`/cms/${key}/content_with_prev_next`, "https://talizen.local");
|
|
26
|
-
url.searchParams.set("slug", slug);
|
|
27
|
-
if (params.prev != null) {
|
|
28
|
-
url.searchParams.set("prev", String(params.prev));
|
|
29
|
-
}
|
|
30
|
-
if (params.next != null) {
|
|
31
|
-
url.searchParams.set("next", String(params.next));
|
|
32
|
-
}
|
|
33
|
-
if (params.searchKey) {
|
|
34
|
-
url.searchParams.set("search_key", params.searchKey);
|
|
35
|
-
}
|
|
36
|
-
if (params.orderBy) {
|
|
37
|
-
url.searchParams.set("order_by", params.orderBy);
|
|
38
|
-
}
|
|
39
|
-
if (params.builtinRef != null) {
|
|
40
|
-
url.searchParams.set("builtin_ref", String(params.builtinRef));
|
|
41
|
-
}
|
|
42
|
-
if (params.filter) {
|
|
43
|
-
url.searchParams.set("filter", JSON.stringify(params.filter));
|
|
44
|
-
}
|
|
45
|
-
return requestJson(url.pathname + url.search, undefined, options);
|
|
46
|
-
}
|
package/dist/form/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type TalizenRequestOptions } from "../core/index.js";
|
|
2
|
-
export interface SubmitFormParams<TBody extends Record<string, unknown>> {
|
|
3
|
-
token: string;
|
|
4
|
-
data: TBody;
|
|
5
|
-
}
|
|
6
|
-
export declare function SubmitForm<TBody extends Record<string, unknown> = Record<string, unknown>>(params: SubmitFormParams<TBody>, options?: TalizenRequestOptions): Promise<"ok">;
|
package/dist/form/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { requestJson, resolveTalizenConfig } from "../core/index.js";
|
|
2
|
-
export async function SubmitForm(params, options) {
|
|
3
|
-
return requestJson(`/form/submit`, {
|
|
4
|
-
method: "POST",
|
|
5
|
-
body: JSON.stringify({
|
|
6
|
-
token: params.token,
|
|
7
|
-
data: params.data,
|
|
8
|
-
}),
|
|
9
|
-
}, options);
|
|
10
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED