talizen 0.2.8 → 0.2.10

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
@@ -119,6 +119,7 @@ import {
119
119
  loginWithOAuth,
120
120
  logout,
121
121
  register,
122
+ updateProfile,
122
123
  } from "talizen/auth";
123
124
 
124
125
  await register({
@@ -130,6 +131,9 @@ await register({
130
131
  await login({ account: "alice", password: "secret" });
131
132
 
132
133
  const user = await currentUser();
134
+ await updateProfile({
135
+ address: "No. 1 Example Road",
136
+ });
133
137
  await logout();
134
138
 
135
139
  const providers = await listAuthProviders();
@@ -156,6 +160,24 @@ const result = await invoke<{ ok: boolean; id: string }>("booking.create", {
156
160
  await invoke("booking", { email: "hi@talizen.com" });
157
161
  ```
158
162
 
163
+ ### Server-side page context
164
+
165
+ In `getServerSideProps`, use the injected server context for request metadata
166
+ and cookies. Do not import `talizen/auth` or `talizen/func`, and do not read
167
+ auth state or call Func from server-side page code:
168
+
169
+ ```ts
170
+ import type { TalizenServerSideContext } from "talizen/server-runtime";
171
+
172
+ export async function getServerSideProps(ctx: TalizenServerSideContext) {
173
+ return { props: { path: ctx.request.path } };
174
+ }
175
+ ```
176
+
177
+ Server-side context supports `ctx.request` and `ctx.cookies`. It intentionally
178
+ does not expose `ctx.auth`, `ctx.db`, `ctx.cache`, or `ctx.func`; put login UI,
179
+ private business data access, and writes in browser-side SDK/Func/API flows.
180
+
159
181
  ### Write function runtime code
160
182
 
161
183
  Func code can use TypeScript and import Func authoring types from `talizen/func-runtime`.
@@ -176,6 +198,22 @@ export function create(input: { title: string }, ctx: TalizenFuncContext) {
176
198
  }
177
199
  ```
178
200
 
201
+ `ctx.db.query(table, query)` returns `{ total, list }`, where `total` is the
202
+ matched record count before pagination and `list` is the current page:
203
+
204
+ ```ts
205
+ import type { TalizenFuncContext } from "talizen/func-runtime";
206
+
207
+ export function list(input: { offset?: number }, ctx: TalizenFuncContext) {
208
+ const result = ctx.db.query<{ title: string; status: string }>("book", {
209
+ where: { status: "published" },
210
+ limit: 20,
211
+ offset: input.offset || 0,
212
+ });
213
+ return { total: result.total, books: result.list };
214
+ }
215
+ ```
216
+
179
217
  `ctx.db`, `ctx.cache`, `ctx.auth`, `ctx.request`, and `ctx.cookies` are injected by the Talizen Func runtime. `talizen/func-runtime` is a type-only authoring module; do not import runtime values from it.
180
218
 
181
219
  ## Package Layout
@@ -186,6 +224,7 @@ export function create(input: { title: string }, ctx: TalizenFuncContext) {
186
224
  - `talizen/form`: form submission helpers and related types.
187
225
  - `talizen/func`: custom function invocation helpers such as `invoke`.
188
226
  - `talizen/func-runtime`: Func-runtime-only `ctx` capability types.
227
+ - `talizen/server-runtime`: getServerSideProps-only `ctx` capability types.
189
228
 
190
229
  ## Publish
191
230
 
package/auth.d.ts CHANGED
@@ -13,12 +13,13 @@ export interface AuthUser {
13
13
  name?: string;
14
14
  avatar?: string;
15
15
  status?: string;
16
- profile?: unknown;
16
+ profile?: AuthProfile;
17
17
  email_verified_at?: string | null;
18
18
  last_login_at?: string | null;
19
19
  created_at?: string;
20
20
  updated_at?: string;
21
21
  }
22
+ export type AuthProfile = Record<string, unknown>;
22
23
  export interface AuthPasswordInput {
23
24
  /**
24
25
  * Login identifier for register/login.
@@ -33,7 +34,7 @@ export interface AuthRegisterInput extends AuthPasswordInput {
33
34
  phone?: string;
34
35
  name?: string;
35
36
  avatar?: string;
36
- profile?: unknown;
37
+ profile?: AuthProfile;
37
38
  }
38
39
  export interface AuthProvider {
39
40
  key: string;
@@ -55,6 +56,7 @@ export declare function register(input: AuthRegisterInput, options?: TalizenRequ
55
56
  export declare function login(input: AuthPasswordInput, options?: TalizenRequestOptions): Promise<AuthUser>;
56
57
  export declare function logout(options?: TalizenRequestOptions): Promise<void>;
57
58
  export declare function currentUser(options?: TalizenRequestOptions): Promise<AuthUser | null>;
59
+ export declare function updateProfile(profile: AuthProfile, options?: TalizenRequestOptions): Promise<AuthUser>;
58
60
  export declare function requireUser(options?: TalizenRequestOptions): Promise<AuthUser>;
59
61
  export declare function listAuthProviders(options?: TalizenRequestOptions): Promise<AuthProvider[]>;
60
62
  export declare function getOAuthLoginUrl(provider: string, options?: AuthOAuthLoginURLOptions): Promise<string>;
package/auth.js CHANGED
@@ -26,6 +26,12 @@ export async function logout(options) {
26
26
  export async function currentUser(options) {
27
27
  return requestJson("/auth/me", { method: "GET" }, options);
28
28
  }
29
+ export async function updateProfile(profile, options) {
30
+ return requestJson("/auth/me/profile", {
31
+ method: "PUT",
32
+ body: JSON.stringify({ profile }),
33
+ }, options);
34
+ }
29
35
  export async function requireUser(options) {
30
36
  const user = await currentUser(options);
31
37
  if (!user) {
package/func-runtime.d.ts CHANGED
@@ -22,9 +22,13 @@ export interface DbQuery {
22
22
  export type DbRecord<T extends Record<string, unknown> = Record<string, unknown>> = T & {
23
23
  id: string;
24
24
  };
25
+ export interface DbQueryResult<T extends Record<string, unknown> = Record<string, unknown>> {
26
+ total: number;
27
+ list: Array<DbRecord<T>>;
28
+ }
25
29
  export interface FuncDbRuntime {
26
30
  get<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string): DbRecord<T> | null;
27
- query<T extends Record<string, unknown> = Record<string, unknown>>(table: string, query?: DbQuery): Array<DbRecord<T>>;
31
+ query<T extends Record<string, unknown> = Record<string, unknown>>(table: string, query?: DbQuery): DbQueryResult<T>;
28
32
  insert<T extends Record<string, unknown> = Record<string, unknown>>(table: string, data: T): DbRecord<T>;
29
33
  update<T extends Record<string, unknown> = Record<string, unknown>>(table: string, id: string, data: Partial<T>): {
30
34
  ok?: boolean;
package/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from "./cms.js";
4
4
  export * from "./captcha-ui.js";
5
5
  export * from "./form.js";
6
6
  export * from "./i18n.js";
7
+ export * from "./server-runtime.js";
7
8
  type OneOrMany<T> = T | Array<T>;
8
9
  export interface MetadataTitle {
9
10
  default?: string;
package/index.js CHANGED
@@ -4,3 +4,4 @@ export * from "./cms.js";
4
4
  export * from "./captcha-ui.js";
5
5
  export * from "./form.js";
6
6
  export * from "./i18n.js";
7
+ export * from "./server-runtime.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Talizen frontend SDK types for cms, form and core.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -44,6 +44,10 @@
44
44
  "types": "./func-runtime.d.ts",
45
45
  "import": "./func-runtime.js"
46
46
  },
47
+ "./server-runtime": {
48
+ "types": "./server-runtime.d.ts",
49
+ "import": "./server-runtime.js"
50
+ },
47
51
  "./i18n": {
48
52
  "types": "./i18n.d.ts",
49
53
  "import": "./i18n.js"
@@ -0,0 +1,40 @@
1
+ export interface ServerReadonlyStringMap {
2
+ get(name: string): string | null;
3
+ }
4
+ export interface TalizenServerRequestRuntime {
5
+ host: string;
6
+ ip: string;
7
+ method: string;
8
+ path: string;
9
+ url: string;
10
+ headers: ServerReadonlyStringMap;
11
+ cookies: ServerReadonlyStringMap;
12
+ }
13
+ export interface ServerCookieSetOptions {
14
+ path?: string;
15
+ domain?: string;
16
+ maxAge?: number;
17
+ secure?: boolean;
18
+ httpOnly?: boolean;
19
+ sameSite?: "lax" | "strict" | "none";
20
+ }
21
+ export interface TalizenServerCookieRuntime {
22
+ get(name: string): string | null;
23
+ set(name: string, value: string, options?: ServerCookieSetOptions): {
24
+ ok?: boolean;
25
+ };
26
+ delete(name: string, options?: Pick<ServerCookieSetOptions, "path" | "domain">): {
27
+ ok?: boolean;
28
+ };
29
+ }
30
+ export interface TalizenServerSideContext {
31
+ query: Record<string, string | string[]>;
32
+ searchParams: Record<string, string | string[]>;
33
+ params: Record<string, string>;
34
+ locale?: string;
35
+ locales?: string[];
36
+ defaultLocale?: string;
37
+ request: TalizenServerRequestRuntime;
38
+ req: TalizenServerRequestRuntime;
39
+ cookies: TalizenServerCookieRuntime;
40
+ }
@@ -0,0 +1 @@
1
+ export {};