talizen 0.0.6 → 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.
@@ -5,11 +5,6 @@ export interface BaseCmsItem {
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 extends BaseCmsItem> {
40
+ export interface ListResponse<T> {
46
41
  list?: T[];
47
42
  total?: number;
48
43
  }
49
- export declare function ListContent<T extends BaseCmsItem>(key: T["__cmsKey"], params?: ListContentParams, options?: TalizenRequestOptions): Promise<ListResponse<T>>;
50
- export declare function GetContent<T extends BaseCmsItem>(key: T["__cmsKey"], slug: string, params?: GetContentParams, options?: TalizenRequestOptions): Promise<T>;
51
- export declare function GetContentWithPrevNext<T extends BaseCmsItem>(key: T["__cmsKey"], slug: string, params?: GetContentWithPrevNextParams, options?: TalizenRequestOptions): Promise<ContentWithPrevNext<T>>;
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,5 +1,5 @@
1
- import { requestJson, resolveTalizenConfig } from "../core/index.js";
2
- export async function ListContent(key, params = {}, options) {
1
+ import { requestJson } from "../core/index.js";
2
+ export async function listContents(key, params = {}, options) {
3
3
  const response = await requestJson(`/cms/${key}/content_list`, {
4
4
  method: "POST",
5
5
  body: JSON.stringify({
@@ -13,7 +13,7 @@ export async function ListContent(key, params = {}, options) {
13
13
  }, options);
14
14
  return response;
15
15
  }
16
- export async function GetContent(key, slug, params, options) {
16
+ export async function getContent(key, slug, params, options) {
17
17
  const url = new URL(`/cms/${key}/content`, "https://talizen.local");
18
18
  url.searchParams.set("slug", slug);
19
19
  if (params?.builtinRef != null) {
@@ -21,26 +21,17 @@ export async function GetContent(key, slug, params, options) {
21
21
  }
22
22
  return requestJson(url.pathname + url.search, undefined, options);
23
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);
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);
46
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,15 @@ export function resolveTalizenConfig(config) {
23
23
  fetch: fetchImpl,
24
24
  };
25
25
  }
26
- export function buildTalizenUrl(path, config) {
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 new URL(path.replace(/^\//, ""), ensureBaseUrl(resolved.baseUrl)).toString();
33
+ // new URL is not used because baseUrl may not include protocols and domain names, e.g. /api
34
+ return joinUrl(resolved.baseUrl, path);
29
35
  }
30
36
  export async function requestJson(path, init, config) {
31
37
  const resolved = resolveTalizenConfig(config);
@@ -53,9 +59,6 @@ export async function requestJson(path, init, config) {
53
59
  }
54
60
  return JSON.parse(text);
55
61
  }
56
- function ensureBaseUrl(baseUrl) {
57
- return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
58
- }
59
62
  function getDefaultBaseUrl() {
60
63
  if (typeof window !== "undefined" && window.location?.origin) {
61
64
  return window.location.origin;
@@ -1,6 +1,6 @@
1
1
  import { type TalizenRequestOptions } from "../core/index.js";
2
- export interface SubmitFormParams<TBody extends Record<string, unknown>> {
3
- token: string;
4
- data: TBody;
2
+ export interface FormRecord {
3
+ readonly __formKey?: string;
4
+ [key: string]: unknown;
5
5
  }
6
- 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">;
@@ -1,10 +1,7 @@
1
- import { requestJson, resolveTalizenConfig } from "../core/index.js";
2
- export async function SubmitForm(params, options) {
3
- return requestJson(`/form/submit`, {
1
+ import { requestJson } from "../core/index.js";
2
+ export async function submitForm(keyOrToken, payload, options) {
3
+ return requestJson(`/form/${keyOrToken}/submit`, {
4
4
  method: "POST",
5
- body: JSON.stringify({
6
- token: params.token,
7
- data: params.data,
8
- }),
5
+ body: JSON.stringify(payload),
9
6
  }, options);
10
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.0.6",
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",