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 CHANGED
@@ -1,26 +1,37 @@
1
1
  # talizen
2
2
 
3
- Talizen 前端 SDK 类型仓库,统一提供:
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
- 这个仓库的目标是把 Talizen 平台前端会直接使用的类型和最小运行时请求封装整理成一个可以独立发布到 GitHub npm 的包。
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
- interface Blogs extends BaseCmsItem {
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
- setTalizenConfig({
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 { SubmitForm } from "talizen/form"
45
-
46
- await SubmitForm(
47
- {
48
- token: "form-token",
49
- data: {
50
- email: "hi@talizen.com",
51
- },
52
- },
53
- {
54
- projectId: "demo-project",
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`:通用基础类型,来自后端 `internal/model`。
62
- - `talizen/cms`:CMS schema、content、筛选参数、获取内容 API。
63
- - `talizen/form`:Form schema、提交参数、日志类型、提交 API。
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
- 其中业务项目自己的 `types/cms.d.ts`、`types/form.d.ts` 依然建议由平台按项目 schema 动态生成;本仓库负责承载平台级公共类型和泛型 API。
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
- npm publish
90
+ node scripts/prepare-publish.mjs
73
91
  ```
74
92
 
75
- GitHub Actions 工作流在 `.github/workflows/publish.yml`,按 tag 发布 npm 包:
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.1.0
79
- git push origin v0.1.0
96
+ git tag v0.0.8
97
+ git push origin main
98
+ git push origin v0.0.8
80
99
  ```
@@ -1,4 +1,4 @@
1
- import { type TalizenRequestOptions } from "../core/index.js";
1
+ import { type TalizenRequestOptions } from "./core.js";
2
2
  export interface BaseCmsItem {
3
3
  readonly __cmsKey: string;
4
4
  slug: string;
@@ -1,4 +1,4 @@
1
- import { requestJson } from "../core/index.js";
1
+ import { requestJson } from "./core.js";
2
2
  export async function listContents(key, params = {}, options) {
3
3
  const response = await requestJson(`/cms/${key}/content_list`, {
4
4
  method: "POST",
@@ -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('/') ? baseUrl.slice(0, -1) : baseUrl;
28
- const subPath = path.startsWith('/') ? path.slice(1) : path;
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. Call setTalizenConfig({ baseUrl }) first.");
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") {
@@ -1,4 +1,4 @@
1
- import { type TalizenRequestOptions } from "../core/index.js";
1
+ import { type TalizenRequestOptions } from "./core.js";
2
2
  export interface FormRecord {
3
3
  readonly __formKey?: string;
4
4
  [key: string]: unknown;
@@ -1,4 +1,4 @@
1
- import { requestJson } from "../core/index.js";
1
+ import { requestJson } from "./core.js";
2
2
  export async function submitForm(keyOrToken, payload, options) {
3
3
  return requestJson(`/form/${keyOrToken}/submit`, {
4
4
  method: "POST",
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./core.js";
2
+ export * from "./cms.js";
3
+ export * from "./form.js";
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./core.js";
2
+ export * from "./cms.js";
3
+ export * from "./form.js";
package/package.json CHANGED
@@ -1,38 +1,28 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.0.7",
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
- "types": "./dist/index.d.ts",
8
+ "main": "./index.js",
9
+ "types": "./index.d.ts",
13
10
  "exports": {
14
11
  ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
12
+ "types": "./index.d.ts",
13
+ "import": "./index.js"
17
14
  },
18
15
  "./core": {
19
- "types": "./dist/core/index.d.ts",
20
- "import": "./dist/core/index.js"
16
+ "types": "./core.d.ts",
17
+ "import": "./core.js"
21
18
  },
22
19
  "./cms": {
23
- "types": "./dist/cms/index.d.ts",
24
- "import": "./dist/cms/index.js"
20
+ "types": "./cms.d.ts",
21
+ "import": "./cms.js"
25
22
  },
26
23
  "./form": {
27
- "types": "./dist/form/index.d.ts",
28
- "import": "./dist/form/index.js"
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
@@ -1,3 +0,0 @@
1
- export * from "./core/index.js";
2
- export * from "./cms/index.js";
3
- export * from "./form/index.js";
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from "./core/index.js";
2
- export * from "./cms/index.js";
3
- export * from "./form/index.js";