@qmuse/appwrite-runtime-sdk 1.0.1 → 1.0.3-dev.1
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 +15 -0
- package/dist/index.d.ts +1 -1
- package/dist/runtime/AppwriteSessionCoordinator.d.ts +29 -0
- package/dist/runtime/AppwriteSessionCoordinator.js +647 -0
- package/dist/runtime/MutationAuditReporter.d.ts +18 -0
- package/dist/runtime/MutationAuditReporter.js +110 -0
- package/dist/runtime/QmuseAppwriteRuntime.d.ts +22 -0
- package/dist/runtime/QmuseAppwriteRuntime.js +321 -0
- package/dist/runtime/rowData.d.ts +3 -0
- package/dist/runtime/rowData.js +60 -0
- package/dist/runtime/utils.d.ts +11 -0
- package/dist/runtime/utils.js +68 -0
- package/dist/runtime.d.ts +2 -31
- package/dist/runtime.js +2 -937
- package/dist/types.d.ts +32 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,21 @@ export const createQmuseRow = runtime.createRow;
|
|
|
29
29
|
export const updateQmuseRow = runtime.updateRow;
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
`createQmuseAppwriteRuntime()` 返回的实例应在 `src/services/appwrite.ts` 中作为模块级单例复用。实例创建后会立即异步初始化;`initAppwrite()` 返回同一个共享 Promise,`getAppwriteClients()` 和所有 CRUD 也会等待该初始化。SDK 会在内部观察每个公开方法返回的 Promise,因此忽略后台初始化或数据调用不会产生影响应用运行的全局 `unhandledrejection`;显式等待仍会收到同一个 Promise 的原始错误,初始化失败后下一次调用可以重试。
|
|
33
|
+
|
|
34
|
+
工厂创建阶段不因缺少 `fetch` 或 Runtime 配置异常同步抛错;这类问题会进入共享初始化 Promise。异步审计链路中的 Runtime 读取、URL 构造和请求错误也不会改变 CRUD 结果。
|
|
35
|
+
|
|
36
|
+
`getCurrentAppwriteUser()` 同样是异步方法,使用时需要 `await`;它会先等待共享初始化,不会在调用阶段同步抛错。
|
|
37
|
+
|
|
38
|
+
### 内部结构
|
|
39
|
+
|
|
40
|
+
- `src/runtime.ts`:稳定的工厂入口。
|
|
41
|
+
- `src/runtime/QmuseAppwriteRuntime.ts`:公开 API 装配与 TablesDB CRUD 编排。
|
|
42
|
+
- `src/runtime/AppwriteSessionCoordinator.ts`:Runtime 配置、Session 状态机和 401 刷新。
|
|
43
|
+
- `src/runtime/MutationAuditReporter.ts`:非阻塞 mutation 安全审计。
|
|
44
|
+
- `src/runtime/rowData.ts`:业务字段过滤与审计数据脱敏。
|
|
45
|
+
- `src/runtime/utils.ts`:HTTP 错误、fetch 延迟解析和 Promise rejection 观察。
|
|
46
|
+
|
|
32
47
|
不要在页面、hook 或业务服务中直接创建 Appwrite SDK 实例,或绕过 `createRow` / `updateRow` 写入审计字段。
|
|
33
48
|
|
|
34
49
|
新增、更新和删除会由 SDK 内置地异步上报最小审计事件;上报不阻塞 CRUD,也不向业务代码暴露 hook、开关或 API Key。SDK 不上传业务 data、custom-token 或 Session。项目内置的 Appwrite 事件云函数仍负责成功 mutation 的可靠服务端审计与重试;浏览器侧上报只用于补充安全信号。
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { createQmuseAppwriteRuntime } from './runtime';
|
|
2
|
-
export type { AppwriteAccountLike, AppwriteClientLike, AppwriteError, AppwriteRuntimeConfig, AppwriteSession, AppwriteTablesDBLike, AppwriteUser, BusinessRowData, QmuseAppwriteClients, QmuseAppwriteRuntimeOptions, QmuseEnvironment, QmuseRuntimeContext, } from './types';
|
|
2
|
+
export type { AppwriteAccountLike, AppwriteClientLike, AppwriteError, AppwriteRuntimeConfig, AppwriteSession, AppwriteTablesDBLike, AppwriteUser, BusinessRowData, CreateRowInput, DeleteRowInput, GetRowInput, ListRowsInput, QmuseAppwriteClients, QmuseAppwriteRuntimeApi, QmuseAppwriteRuntimeOptions, QmuseEnvironment, QmuseRuntimeContext, UpdateRowInput, } from './types';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AppwriteUser, QmuseAppwriteRuntimeOptions } from '../types';
|
|
2
|
+
export declare class AppwriteSessionCoordinator {
|
|
3
|
+
private readonly options;
|
|
4
|
+
private readonly request;
|
|
5
|
+
private readonly state;
|
|
6
|
+
private initPromise;
|
|
7
|
+
private sessionSyncPromise;
|
|
8
|
+
private refreshPromise;
|
|
9
|
+
constructor(options: QmuseAppwriteRuntimeOptions, request: typeof globalThis.fetch);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
getDatabaseId(): Promise<string>;
|
|
12
|
+
getCurrentUser(): Promise<AppwriteUser>;
|
|
13
|
+
requireCurrentUser(): AppwriteUser;
|
|
14
|
+
refreshSession(): Promise<void>;
|
|
15
|
+
withSessionRetry<T>(operation: () => Promise<T>): Promise<T>;
|
|
16
|
+
private getMuseRuntime;
|
|
17
|
+
private requireRuntimeConfig;
|
|
18
|
+
private clearCurrentSession;
|
|
19
|
+
private loadRuntimeConfig;
|
|
20
|
+
private cacheCurrentSession;
|
|
21
|
+
private tryCacheCurrentSession;
|
|
22
|
+
private deleteCurrentSession;
|
|
23
|
+
private ensureAnonymousSession;
|
|
24
|
+
private requestCustomToken;
|
|
25
|
+
private ensureAuthenticatedSession;
|
|
26
|
+
private coordinateSession;
|
|
27
|
+
private synchronizeSession;
|
|
28
|
+
private initialize;
|
|
29
|
+
}
|