talizen 0.0.5 → 0.0.7
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/dist/cms/index.d.ts +10 -41
- package/dist/cms/index.js +17 -36
- package/dist/core/index.d.ts +1 -44
- package/dist/core/index.js +9 -8
- package/dist/form/index.d.ts +5 -38
- package/dist/form/index.js +4 -23
- package/package.json +2 -2
package/dist/cms/index.d.ts
CHANGED
|
@@ -1,49 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TalizenRequestOptions } from "../core/index.js";
|
|
2
2
|
export interface BaseCmsItem {
|
|
3
3
|
readonly __cmsKey: string;
|
|
4
4
|
slug: string;
|
|
5
|
-
id:
|
|
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
|
-
export interface CmsApp<TSchema extends ContentSchema = ContentSchema> {
|
|
14
|
-
id: DBId;
|
|
15
|
-
project_id: DBId;
|
|
16
|
-
key: string;
|
|
17
|
-
user_id: number;
|
|
18
|
-
name: string;
|
|
19
|
-
desc: string;
|
|
20
|
-
schema: TSchema;
|
|
21
|
-
created_at: string;
|
|
22
|
-
updated_at: string;
|
|
23
|
-
visibility?: "private" | "public" | (string & {});
|
|
24
|
-
}
|
|
25
|
-
export type ContentStatus = "online" | "offline" | (string & {});
|
|
26
|
-
export interface CmsContent<TBody extends Record<string, unknown> = Record<string, unknown>> {
|
|
27
|
-
id: DBId;
|
|
28
|
-
slug: string;
|
|
29
|
-
content_app_id: DBId;
|
|
30
|
-
user_id: number;
|
|
31
|
-
schema: ContentSchema;
|
|
32
|
-
tags?: string[];
|
|
33
|
-
status?: ContentStatus;
|
|
34
|
-
body: {
|
|
35
|
-
[K in keyof TBody]?: ContentBodyField<TBody[K]>;
|
|
36
|
-
};
|
|
37
|
-
draft_body?: {
|
|
38
|
-
[K in keyof TBody]?: ContentBodyField<TBody[K]>;
|
|
39
|
-
};
|
|
40
|
-
created_at: string;
|
|
41
|
-
updated_at: string;
|
|
42
|
-
}
|
|
43
8
|
export interface GetContentListFilterCondition {
|
|
44
9
|
fieldId?: string;
|
|
45
10
|
operator?: string;
|
|
46
|
-
value?:
|
|
11
|
+
value?: any;
|
|
47
12
|
}
|
|
48
13
|
export interface GetContentListFilter {
|
|
49
14
|
match?: "any" | "all";
|
|
@@ -72,6 +37,10 @@ export interface ContentWithPrevNext<T extends BaseCmsItem> {
|
|
|
72
37
|
next?: T;
|
|
73
38
|
prev?: T;
|
|
74
39
|
}
|
|
75
|
-
export
|
|
76
|
-
|
|
77
|
-
|
|
40
|
+
export interface ListResponse<T> {
|
|
41
|
+
list?: T[];
|
|
42
|
+
total?: number;
|
|
43
|
+
}
|
|
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/dist/cms/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { requestJson
|
|
2
|
-
export async function
|
|
3
|
-
const projectId = requireProjectId(options);
|
|
1
|
+
import { requestJson } from "../core/index.js";
|
|
2
|
+
export async function listContents(key, params = {}, options) {
|
|
4
3
|
const response = await requestJson(`/cms/${key}/content_list`, {
|
|
5
4
|
method: "POST",
|
|
6
5
|
body: JSON.stringify({
|
|
@@ -12,10 +11,9 @@ export async function ListContent(key, params = {}, options) {
|
|
|
12
11
|
filter: params.filter,
|
|
13
12
|
}),
|
|
14
13
|
}, options);
|
|
15
|
-
return response
|
|
14
|
+
return response;
|
|
16
15
|
}
|
|
17
|
-
export async function
|
|
18
|
-
const projectId = requireProjectId(options);
|
|
16
|
+
export async function getContent(key, slug, params, options) {
|
|
19
17
|
const url = new URL(`/cms/${key}/content`, "https://talizen.local");
|
|
20
18
|
url.searchParams.set("slug", slug);
|
|
21
19
|
if (params?.builtinRef != null) {
|
|
@@ -23,34 +21,17 @@ export async function GetContent(key, slug, params, options) {
|
|
|
23
21
|
}
|
|
24
22
|
return requestJson(url.pathname + url.search, undefined, options);
|
|
25
23
|
}
|
|
26
|
-
export async function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
if (params.orderBy) {
|
|
40
|
-
url.searchParams.set("order_by", params.orderBy);
|
|
41
|
-
}
|
|
42
|
-
if (params.builtinRef != null) {
|
|
43
|
-
url.searchParams.set("builtin_ref", String(params.builtinRef));
|
|
44
|
-
}
|
|
45
|
-
if (params.filter) {
|
|
46
|
-
url.searchParams.set("filter", JSON.stringify(params.filter));
|
|
47
|
-
}
|
|
48
|
-
return requestJson(url.pathname + url.search, undefined, options);
|
|
49
|
-
}
|
|
50
|
-
function requireProjectId(options) {
|
|
51
|
-
const projectId = resolveTalizenConfig(options).projectId;
|
|
52
|
-
if (projectId) {
|
|
53
|
-
return projectId;
|
|
54
|
-
}
|
|
55
|
-
throw new Error("Talizen projectId is required. Pass options.projectId or call setTalizenConfig({ projectId }).");
|
|
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);
|
|
56
37
|
}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export type DBId = string;
|
|
2
|
-
export type Variable = unknown;
|
|
3
1
|
export type Datatype = "array" | "string" | "int" | "float" | "bool" | "date" | "datetime" | "time" | "file" | "image" | "video" | "audio" | "text" | "cms";
|
|
4
2
|
export interface TV<T = unknown> {
|
|
5
3
|
type: Datatype | string;
|
|
@@ -13,48 +11,8 @@ export interface ImgItem {
|
|
|
13
11
|
width?: number;
|
|
14
12
|
}
|
|
15
13
|
export type Image = ImgItem[] | ImgItem;
|
|
16
|
-
export type Link = string;
|
|
17
|
-
export type LinkType = "custom" | "system" | (string & {});
|
|
18
|
-
export interface LinkProps {
|
|
19
|
-
value?: string;
|
|
20
|
-
link?: string;
|
|
21
|
-
type?: LinkType;
|
|
22
|
-
linkType?: LinkType;
|
|
23
|
-
section?: string;
|
|
24
|
-
slug?: Variable;
|
|
25
|
-
}
|
|
26
|
-
export interface ContentBodyField<T = unknown> {
|
|
27
|
-
value?: T;
|
|
28
|
-
value_raw?: unknown;
|
|
29
|
-
type: Datatype | string;
|
|
30
|
-
type_ref?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface SchemaControl {
|
|
33
|
-
path: string;
|
|
34
|
-
type: Datatype | string;
|
|
35
|
-
controls?: SchemaControl[];
|
|
36
|
-
}
|
|
37
|
-
export type ContentFieldOptionM = Record<string, TV>;
|
|
38
|
-
export interface ContentSchemaField {
|
|
39
|
-
key: string;
|
|
40
|
-
name: string;
|
|
41
|
-
desc?: string;
|
|
42
|
-
name_locales?: Record<string, string>;
|
|
43
|
-
datatype?: Datatype | string;
|
|
44
|
-
help_locales?: Record<string, string>;
|
|
45
|
-
enable_search?: boolean;
|
|
46
|
-
extension?: unknown;
|
|
47
|
-
options?: ContentFieldOptionM[];
|
|
48
|
-
controls?: SchemaControl[];
|
|
49
|
-
cms_id?: string;
|
|
50
|
-
cms_label_field?: string;
|
|
51
|
-
}
|
|
52
|
-
export interface ContentSchema {
|
|
53
|
-
fields?: ContentSchemaField[];
|
|
54
|
-
}
|
|
55
14
|
export interface TalizenClientConfig {
|
|
56
15
|
baseUrl?: string;
|
|
57
|
-
projectId?: string;
|
|
58
16
|
headers?: HeadersInit;
|
|
59
17
|
fetch?: typeof fetch;
|
|
60
18
|
}
|
|
@@ -63,6 +21,5 @@ export interface TalizenRequestOptions extends TalizenClientConfig {
|
|
|
63
21
|
}
|
|
64
22
|
export declare function setTalizenConfig(config: TalizenClientConfig): void;
|
|
65
23
|
export declare function getTalizenConfig(): TalizenClientConfig;
|
|
66
|
-
export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "
|
|
67
|
-
export declare function buildTalizenUrl(path: string, config?: TalizenRequestOptions): string;
|
|
24
|
+
export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "fetch">> & TalizenRequestOptions;
|
|
68
25
|
export declare function requestJson<T>(path: string, init?: RequestInit, config?: TalizenRequestOptions): Promise<T>;
|
package/dist/core/index.js
CHANGED
|
@@ -16,18 +16,22 @@ export function resolveTalizenConfig(config) {
|
|
|
16
16
|
...config,
|
|
17
17
|
};
|
|
18
18
|
const baseUrl = merged.baseUrl ?? getDefaultBaseUrl();
|
|
19
|
-
const projectId = merged.projectId ?? "";
|
|
20
19
|
const fetchImpl = merged.fetch ?? getDefaultFetch();
|
|
21
20
|
return {
|
|
22
21
|
...merged,
|
|
23
22
|
baseUrl,
|
|
24
|
-
projectId,
|
|
25
23
|
fetch: fetchImpl,
|
|
26
24
|
};
|
|
27
25
|
}
|
|
28
|
-
|
|
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) {
|
|
29
32
|
const resolved = resolveTalizenConfig(config);
|
|
30
|
-
|
|
33
|
+
// new URL is not used because baseUrl may not include protocols and domain names, e.g. /api
|
|
34
|
+
return joinUrl(resolved.baseUrl, path);
|
|
31
35
|
}
|
|
32
36
|
export async function requestJson(path, init, config) {
|
|
33
37
|
const resolved = resolveTalizenConfig(config);
|
|
@@ -55,9 +59,6 @@ export async function requestJson(path, init, config) {
|
|
|
55
59
|
}
|
|
56
60
|
return JSON.parse(text);
|
|
57
61
|
}
|
|
58
|
-
function ensureBaseUrl(baseUrl) {
|
|
59
|
-
return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
60
|
-
}
|
|
61
62
|
function getDefaultBaseUrl() {
|
|
62
63
|
if (typeof window !== "undefined" && window.location?.origin) {
|
|
63
64
|
return window.location.origin;
|
|
@@ -66,7 +67,7 @@ function getDefaultBaseUrl() {
|
|
|
66
67
|
}
|
|
67
68
|
function getDefaultFetch() {
|
|
68
69
|
if (typeof fetch === "function") {
|
|
69
|
-
return fetch;
|
|
70
|
+
return (input, init) => fetch(input, init);
|
|
70
71
|
}
|
|
71
72
|
throw new Error("Talizen fetch implementation is required in the current runtime.");
|
|
72
73
|
}
|
package/dist/form/index.d.ts
CHANGED
|
@@ -1,39 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export interface
|
|
1
|
+
import { type TalizenRequestOptions } from "../core/index.js";
|
|
2
|
+
export interface FormRecord {
|
|
3
|
+
readonly __formKey?: string;
|
|
4
|
+
[key: string]: unknown;
|
|
3
5
|
}
|
|
4
|
-
export
|
|
5
|
-
id: DBId;
|
|
6
|
-
project_id: DBId;
|
|
7
|
-
key: string;
|
|
8
|
-
user_id: number;
|
|
9
|
-
name: string;
|
|
10
|
-
desc: string;
|
|
11
|
-
schema: TSchema;
|
|
12
|
-
setting: FormSetting;
|
|
13
|
-
created_at: string;
|
|
14
|
-
updated_at: string;
|
|
15
|
-
}
|
|
16
|
-
export type FormLogBody<TBody extends Record<string, unknown>> = {
|
|
17
|
-
[K in keyof TBody]?: ContentBodyField<TBody[K]>;
|
|
18
|
-
};
|
|
19
|
-
export interface FormLog<TBody extends Record<string, unknown> = Record<string, unknown>> {
|
|
20
|
-
id: DBId;
|
|
21
|
-
form_id: DBId;
|
|
22
|
-
uid: string;
|
|
23
|
-
ua: string;
|
|
24
|
-
ip: string;
|
|
25
|
-
form_url: string;
|
|
26
|
-
body: FormLogBody<TBody>;
|
|
27
|
-
created_at: string;
|
|
28
|
-
updated_at: string;
|
|
29
|
-
}
|
|
30
|
-
export interface SubmitFormParams<TBody extends Record<string, unknown> = Record<string, unknown>> {
|
|
31
|
-
token: string;
|
|
32
|
-
data: TBody;
|
|
33
|
-
ip?: string;
|
|
34
|
-
uid?: string;
|
|
35
|
-
ua?: string;
|
|
36
|
-
fromUrl?: string;
|
|
37
|
-
}
|
|
38
|
-
export declare function GetForm(formId: DBId, options?: TalizenRequestOptions): Promise<FormApp>;
|
|
39
|
-
export declare function SubmitForm<TBody extends Record<string, unknown> = Record<string, unknown>>(params: SubmitFormParams<TBody>, options?: TalizenRequestOptions): Promise<"ok">;
|
|
6
|
+
export declare function submitForm<T extends FormRecord>(keyOrToken: T["__formKey"] | string, payload: T, options?: TalizenRequestOptions): Promise<"ok">;
|
package/dist/form/index.js
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import { requestJson
|
|
2
|
-
export async function
|
|
3
|
-
|
|
4
|
-
return requestJson(`/api/r/project/${projectId}/form/${formId}`, undefined, options);
|
|
5
|
-
}
|
|
6
|
-
export async function SubmitForm(params, options) {
|
|
7
|
-
const projectId = requireProjectId(options);
|
|
8
|
-
return requestJson(`/api/r/project/${projectId}/form`, {
|
|
1
|
+
import { requestJson } from "../core/index.js";
|
|
2
|
+
export async function submitForm(keyOrToken, payload, options) {
|
|
3
|
+
return requestJson(`/form/${keyOrToken}/submit`, {
|
|
9
4
|
method: "POST",
|
|
10
|
-
body: JSON.stringify(
|
|
11
|
-
token: params.token,
|
|
12
|
-
data: params.data,
|
|
13
|
-
ip: params.ip,
|
|
14
|
-
uid: params.uid,
|
|
15
|
-
ua: params.ua,
|
|
16
|
-
from_url: params.fromUrl,
|
|
17
|
-
}),
|
|
5
|
+
body: JSON.stringify(payload),
|
|
18
6
|
}, options);
|
|
19
7
|
}
|
|
20
|
-
function requireProjectId(options) {
|
|
21
|
-
const projectId = resolveTalizenConfig(options).projectId;
|
|
22
|
-
if (projectId) {
|
|
23
|
-
return projectId;
|
|
24
|
-
}
|
|
25
|
-
throw new Error("Talizen projectId is required. Pass options.projectId or call setTalizenConfig({ projectId }).");
|
|
26
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "talizen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Talizen frontend SDK types for cms, form and core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,4 +35,4 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"typescript": "^5.9.2"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|