talizen 0.2.6 → 0.2.8
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 +34 -15
- package/auth.d.ts +30 -1
- package/auth.js +20 -0
- package/func-runtime.d.ts +37 -3
- package/func-runtime.js +1 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,13 +112,30 @@ When a `File` object appears in the payload, `submitForm()` will:
|
|
|
112
112
|
### Login users
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
|
-
import {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
import {
|
|
116
|
+
currentUser,
|
|
117
|
+
listAuthProviders,
|
|
118
|
+
login,
|
|
119
|
+
loginWithOAuth,
|
|
120
|
+
logout,
|
|
121
|
+
register,
|
|
122
|
+
} from "talizen/auth";
|
|
123
|
+
|
|
124
|
+
await register({
|
|
125
|
+
account: "alice",
|
|
126
|
+
password: "secret",
|
|
127
|
+
name: "Alice",
|
|
128
|
+
email: "hi@talizen.com",
|
|
129
|
+
});
|
|
130
|
+
await login({ account: "alice", password: "secret" });
|
|
119
131
|
|
|
120
132
|
const user = await currentUser();
|
|
121
133
|
await logout();
|
|
134
|
+
|
|
135
|
+
const providers = await listAuthProviders();
|
|
136
|
+
console.log(providers.map((provider) => provider.key));
|
|
137
|
+
|
|
138
|
+
await loginWithOAuth("github", { redirectUrl: "/account" });
|
|
122
139
|
```
|
|
123
140
|
|
|
124
141
|
### Invoke a custom function
|
|
@@ -126,38 +143,40 @@ await logout();
|
|
|
126
143
|
```ts
|
|
127
144
|
import { invoke } from "talizen/func";
|
|
128
145
|
|
|
129
|
-
const result = await invoke<{
|
|
146
|
+
const result = await invoke<{ ok: boolean; id: string }>("booking.create", {
|
|
130
147
|
email: "hi@talizen.com",
|
|
131
|
-
|
|
148
|
+
date: "2026-07-04",
|
|
149
|
+
time: "10:00",
|
|
132
150
|
});
|
|
133
151
|
```
|
|
134
152
|
|
|
135
153
|
`invoke("<fileKey>.<method>", input)` calls the method exported by the script file. If `.method` is omitted, Talizen calls `main`:
|
|
136
154
|
|
|
137
155
|
```ts
|
|
138
|
-
await invoke("
|
|
156
|
+
await invoke("booking", { email: "hi@talizen.com" });
|
|
139
157
|
```
|
|
140
158
|
|
|
141
159
|
### Write function runtime code
|
|
142
160
|
|
|
143
|
-
Func code can use TypeScript and import
|
|
161
|
+
Func code can use TypeScript and import Func authoring types from `talizen/func-runtime`.
|
|
162
|
+
Runtime capabilities are passed through `ctx`:
|
|
144
163
|
|
|
145
164
|
```ts
|
|
146
|
-
import {
|
|
165
|
+
import type { TalizenFuncContext } from "talizen/func-runtime";
|
|
147
166
|
|
|
148
|
-
export function create(input: { title: string }) {
|
|
149
|
-
const user = auth.requireUser();
|
|
150
|
-
const row = db.insert("book", {
|
|
167
|
+
export function create(input: { title: string }, ctx: TalizenFuncContext) {
|
|
168
|
+
const user = ctx.auth.requireUser();
|
|
169
|
+
const row = ctx.db.insert("book", {
|
|
151
170
|
title: input.title,
|
|
152
171
|
user_id: user.id,
|
|
153
172
|
status: "draft",
|
|
154
173
|
});
|
|
155
|
-
cache.set(`book:${row.id}`, row, 60);
|
|
174
|
+
ctx.cache.set(`book:${row.id}`, row, 60);
|
|
156
175
|
return { ok: true, id: row.id };
|
|
157
176
|
}
|
|
158
177
|
```
|
|
159
178
|
|
|
160
|
-
`db`, `cache`, and
|
|
179
|
+
`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.
|
|
161
180
|
|
|
162
181
|
## Package Layout
|
|
163
182
|
|
|
@@ -166,7 +185,7 @@ export function create(input: { title: string }) {
|
|
|
166
185
|
- `talizen/cms`: CMS content types and content query APIs.
|
|
167
186
|
- `talizen/form`: form submission helpers and related types.
|
|
168
187
|
- `talizen/func`: custom function invocation helpers such as `invoke`.
|
|
169
|
-
- `talizen/func-runtime`: Func-runtime-only `
|
|
188
|
+
- `talizen/func-runtime`: Func-runtime-only `ctx` capability types.
|
|
170
189
|
|
|
171
190
|
## Publish
|
|
172
191
|
|
package/auth.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { type TalizenRequestOptions } from "./core.js";
|
|
2
2
|
export interface AuthUser {
|
|
3
3
|
id: string;
|
|
4
|
+
/**
|
|
5
|
+
* Login identifier for this project user.
|
|
6
|
+
* This does not need to be an email address or phone number.
|
|
7
|
+
*/
|
|
8
|
+
account?: string;
|
|
9
|
+
/** Optional contact email/profile field, not the primary login identifier. */
|
|
4
10
|
email?: string;
|
|
11
|
+
/** Optional contact phone/profile field, not the primary login identifier. */
|
|
5
12
|
phone?: string;
|
|
6
13
|
name?: string;
|
|
7
14
|
avatar?: string;
|
|
@@ -13,15 +20,34 @@ export interface AuthUser {
|
|
|
13
20
|
updated_at?: string;
|
|
14
21
|
}
|
|
15
22
|
export interface AuthPasswordInput {
|
|
16
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Login identifier for register/login.
|
|
25
|
+
* Do not substitute email or phone unless the user intentionally uses that
|
|
26
|
+
* value as their account.
|
|
27
|
+
*/
|
|
28
|
+
account: string;
|
|
17
29
|
password: string;
|
|
18
30
|
}
|
|
19
31
|
export interface AuthRegisterInput extends AuthPasswordInput {
|
|
32
|
+
email?: string;
|
|
20
33
|
phone?: string;
|
|
21
34
|
name?: string;
|
|
22
35
|
avatar?: string;
|
|
23
36
|
profile?: unknown;
|
|
24
37
|
}
|
|
38
|
+
export interface AuthProvider {
|
|
39
|
+
key: string;
|
|
40
|
+
name: string;
|
|
41
|
+
scopes?: string;
|
|
42
|
+
status?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AuthProviderListResponse {
|
|
45
|
+
total?: number;
|
|
46
|
+
list?: AuthProvider[];
|
|
47
|
+
}
|
|
48
|
+
export interface AuthOAuthLoginURLOptions extends TalizenRequestOptions {
|
|
49
|
+
redirectUrl?: string;
|
|
50
|
+
}
|
|
25
51
|
export declare class TalizenAuthError extends Error {
|
|
26
52
|
constructor(message: string);
|
|
27
53
|
}
|
|
@@ -30,3 +56,6 @@ export declare function login(input: AuthPasswordInput, options?: TalizenRequest
|
|
|
30
56
|
export declare function logout(options?: TalizenRequestOptions): Promise<void>;
|
|
31
57
|
export declare function currentUser(options?: TalizenRequestOptions): Promise<AuthUser | null>;
|
|
32
58
|
export declare function requireUser(options?: TalizenRequestOptions): Promise<AuthUser>;
|
|
59
|
+
export declare function listAuthProviders(options?: TalizenRequestOptions): Promise<AuthProvider[]>;
|
|
60
|
+
export declare function getOAuthLoginUrl(provider: string, options?: AuthOAuthLoginURLOptions): Promise<string>;
|
|
61
|
+
export declare function loginWithOAuth(provider: string, options?: AuthOAuthLoginURLOptions): Promise<void>;
|
package/auth.js
CHANGED
|
@@ -33,3 +33,23 @@ export async function requireUser(options) {
|
|
|
33
33
|
}
|
|
34
34
|
return user;
|
|
35
35
|
}
|
|
36
|
+
export async function listAuthProviders(options) {
|
|
37
|
+
const response = await requestJson("/auth/provider_list", { method: "GET" }, options);
|
|
38
|
+
return response.list ?? [];
|
|
39
|
+
}
|
|
40
|
+
export async function getOAuthLoginUrl(provider, options) {
|
|
41
|
+
const url = new URL("/auth/oauth/login_url", "https://talizen.local");
|
|
42
|
+
url.searchParams.set("provider", provider);
|
|
43
|
+
if (options?.redirectUrl) {
|
|
44
|
+
url.searchParams.set("redirect_url", options.redirectUrl);
|
|
45
|
+
}
|
|
46
|
+
const response = await requestJson(url.pathname + url.search, { method: "GET" }, options);
|
|
47
|
+
return response.url;
|
|
48
|
+
}
|
|
49
|
+
export async function loginWithOAuth(provider, options) {
|
|
50
|
+
const target = await getOAuthLoginUrl(provider, options);
|
|
51
|
+
if (typeof window === "undefined" || !window.location) {
|
|
52
|
+
throw new TalizenAuthError("OAuth login requires a browser window.");
|
|
53
|
+
}
|
|
54
|
+
window.location.href = target;
|
|
55
|
+
}
|
package/func-runtime.d.ts
CHANGED
|
@@ -60,6 +60,40 @@ export interface FuncCacheRuntime {
|
|
|
60
60
|
ok?: boolean;
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
export interface FuncReadonlyStringMap {
|
|
64
|
+
get(name: string): string | null;
|
|
65
|
+
}
|
|
66
|
+
export interface FuncRequestRuntime {
|
|
67
|
+
host: string;
|
|
68
|
+
ip: string;
|
|
69
|
+
method: string;
|
|
70
|
+
path: string;
|
|
71
|
+
headers: FuncReadonlyStringMap;
|
|
72
|
+
cookies: FuncReadonlyStringMap;
|
|
73
|
+
}
|
|
74
|
+
export interface FuncCookieSetOptions {
|
|
75
|
+
path?: string;
|
|
76
|
+
domain?: string;
|
|
77
|
+
maxAge?: number;
|
|
78
|
+
secure?: boolean;
|
|
79
|
+
httpOnly?: boolean;
|
|
80
|
+
sameSite?: "lax" | "strict" | "none";
|
|
81
|
+
}
|
|
82
|
+
export interface FuncCookieRuntime {
|
|
83
|
+
get(name: string): string | null;
|
|
84
|
+
set(name: string, value: string, options?: FuncCookieSetOptions): {
|
|
85
|
+
ok?: boolean;
|
|
86
|
+
};
|
|
87
|
+
delete(name: string, options?: Pick<FuncCookieSetOptions, "path" | "domain">): {
|
|
88
|
+
ok?: boolean;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export interface TalizenFuncContext {
|
|
92
|
+
trace_id: string;
|
|
93
|
+
extra?: Record<string, unknown>;
|
|
94
|
+
request: FuncRequestRuntime;
|
|
95
|
+
db: FuncDbRuntime;
|
|
96
|
+
auth: FuncAuthRuntime;
|
|
97
|
+
cache: FuncCacheRuntime;
|
|
98
|
+
cookies: FuncCookieRuntime;
|
|
99
|
+
}
|
package/func-runtime.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
throw new Error("talizen/func-runtime is only available inside Talizen Func runtime.");
|
|
3
|
-
}
|
|
4
|
-
export const db = {
|
|
5
|
-
get: unavailable,
|
|
6
|
-
query: unavailable,
|
|
7
|
-
insert: unavailable,
|
|
8
|
-
update: unavailable,
|
|
9
|
-
delete: unavailable,
|
|
10
|
-
};
|
|
11
|
-
export const auth = {
|
|
12
|
-
currentUser: unavailable,
|
|
13
|
-
requireUser: unavailable,
|
|
14
|
-
};
|
|
15
|
-
export const cache = {
|
|
16
|
-
get: unavailable,
|
|
17
|
-
set: unavailable,
|
|
18
|
-
del: unavailable,
|
|
19
|
-
incr: unavailable,
|
|
20
|
-
expire: unavailable,
|
|
21
|
-
};
|
|
1
|
+
export {};
|