talizen 0.0.4 → 0.0.6

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.
@@ -1,8 +1,8 @@
1
- import { type ContentBodyField, type ContentSchema, type DBId, type TalizenRequestOptions } from "../core/index.js";
1
+ import { type TalizenRequestOptions } from "../core/index.js";
2
2
  export interface BaseCmsItem {
3
3
  readonly __cmsKey: string;
4
4
  slug: string;
5
- id: DBId;
5
+ id: string;
6
6
  body: Record<string, unknown>;
7
7
  }
8
8
  export interface CmsListItem<T extends BaseCmsItem = BaseCmsItem> {
@@ -10,40 +10,10 @@ export interface CmsListItem<T extends BaseCmsItem = BaseCmsItem> {
10
10
  name: string;
11
11
  Item: T;
12
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
13
  export interface GetContentListFilterCondition {
44
14
  fieldId?: string;
45
15
  operator?: string;
46
- value?: unknown;
16
+ value?: any;
47
17
  }
48
18
  export interface GetContentListFilter {
49
19
  match?: "any" | "all";
@@ -72,6 +42,10 @@ export interface ContentWithPrevNext<T extends BaseCmsItem> {
72
42
  next?: T;
73
43
  prev?: T;
74
44
  }
75
- export declare function ListContent<T extends BaseCmsItem>(key: T["__cmsKey"], params?: ListContentParams, options?: TalizenRequestOptions): Promise<T[]>;
45
+ export interface ListResponse<T extends BaseCmsItem> {
46
+ list?: T[];
47
+ total?: number;
48
+ }
49
+ export declare function ListContent<T extends BaseCmsItem>(key: T["__cmsKey"], params?: ListContentParams, options?: TalizenRequestOptions): Promise<ListResponse<T>>;
76
50
  export declare function GetContent<T extends BaseCmsItem>(key: T["__cmsKey"], slug: string, params?: GetContentParams, options?: TalizenRequestOptions): Promise<T>;
77
51
  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,7 +1,6 @@
1
1
  import { requestJson, resolveTalizenConfig } from "../core/index.js";
2
2
  export async function ListContent(key, params = {}, options) {
3
- const projectId = requireProjectId(options);
4
- const response = await requestJson(`/api/r/project/${projectId}/cms_by_key/${key}/content_list`, {
3
+ const response = await requestJson(`/cms/${key}/content_list`, {
5
4
  method: "POST",
6
5
  body: JSON.stringify({
7
6
  limit: params.limit,
@@ -12,11 +11,10 @@ export async function ListContent(key, params = {}, options) {
12
11
  filter: params.filter,
13
12
  }),
14
13
  }, options);
15
- return response.list ?? [];
14
+ return response;
16
15
  }
17
16
  export async function GetContent(key, slug, params, options) {
18
- const projectId = requireProjectId(options);
19
- const url = new URL(`/api/r/project/${projectId}/cms_by_key/${key}/content`, "https://talizen.local");
17
+ const url = new URL(`/cms/${key}/content`, "https://talizen.local");
20
18
  url.searchParams.set("slug", slug);
21
19
  if (params?.builtinRef != null) {
22
20
  url.searchParams.set("builtin_ref", String(params.builtinRef));
@@ -24,8 +22,7 @@ export async function GetContent(key, slug, params, options) {
24
22
  return requestJson(url.pathname + url.search, undefined, options);
25
23
  }
26
24
  export async function GetContentWithPrevNext(key, slug, params = {}, options) {
27
- const projectId = requireProjectId(options);
28
- const url = new URL(`/api/r/project/${projectId}/cms_by_key/${key}/content_with_prev_next`, "https://talizen.local");
25
+ const url = new URL(`/cms/${key}/content_with_prev_next`, "https://talizen.local");
29
26
  url.searchParams.set("slug", slug);
30
27
  if (params.prev != null) {
31
28
  url.searchParams.set("prev", String(params.prev));
@@ -47,10 +44,3 @@ export async function GetContentWithPrevNext(key, slug, params = {}, options) {
47
44
  }
48
45
  return requestJson(url.pathname + url.search, undefined, options);
49
46
  }
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 }).");
56
- }
@@ -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,6 @@ 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" | "projectId" | "fetch">> & TalizenRequestOptions;
24
+ export declare function resolveTalizenConfig(config?: TalizenRequestOptions): Required<Pick<TalizenClientConfig, "baseUrl" | "fetch">> & TalizenRequestOptions;
67
25
  export declare function buildTalizenUrl(path: string, config?: TalizenRequestOptions): string;
68
26
  export declare function requestJson<T>(path: string, init?: RequestInit, config?: TalizenRequestOptions): Promise<T>;
@@ -16,12 +16,10 @@ 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
  }
@@ -66,7 +64,7 @@ function getDefaultBaseUrl() {
66
64
  }
67
65
  function getDefaultFetch() {
68
66
  if (typeof fetch === "function") {
69
- return fetch;
67
+ return (input, init) => fetch(input, init);
70
68
  }
71
69
  throw new Error("Talizen fetch implementation is required in the current runtime.");
72
70
  }
@@ -1,39 +1,6 @@
1
- import { type ContentBodyField, type ContentSchema, type DBId, type TalizenRequestOptions } from "../core/index.js";
2
- export interface FormSetting {
3
- }
4
- export interface FormApp<TSchema extends ContentSchema = ContentSchema> {
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>> {
1
+ import { type TalizenRequestOptions } from "../core/index.js";
2
+ export interface SubmitFormParams<TBody extends Record<string, unknown>> {
31
3
  token: string;
32
4
  data: TBody;
33
- ip?: string;
34
- uid?: string;
35
- ua?: string;
36
- fromUrl?: string;
37
5
  }
38
- export declare function GetForm(formId: DBId, options?: TalizenRequestOptions): Promise<FormApp>;
39
6
  export declare function SubmitForm<TBody extends Record<string, unknown> = Record<string, unknown>>(params: SubmitFormParams<TBody>, options?: TalizenRequestOptions): Promise<"ok">;
@@ -1,26 +1,10 @@
1
1
  import { requestJson, resolveTalizenConfig } from "../core/index.js";
2
- export async function GetForm(formId, options) {
3
- const projectId = requireProjectId(options);
4
- return requestJson(`/api/r/project/${projectId}/form/${formId}`, undefined, options);
5
- }
6
2
  export async function SubmitForm(params, options) {
7
- const projectId = requireProjectId(options);
8
- return requestJson(`/api/r/project/${projectId}/form`, {
3
+ return requestJson(`/form/submit`, {
9
4
  method: "POST",
10
5
  body: JSON.stringify({
11
6
  token: params.token,
12
7
  data: params.data,
13
- ip: params.ip,
14
- uid: params.uid,
15
- ua: params.ua,
16
- from_url: params.fromUrl,
17
8
  }),
18
9
  }, options);
19
10
  }
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.4",
3
+ "version": "0.0.6",
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
+ }