@xcitedbs/client 0.1.0
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 +53 -0
- package/dist/client.d.ts +211 -0
- package/dist/client.js +894 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +9 -0
- package/dist/types.d.ts +421 -0
- package/dist/types.js +12 -0
- package/dist/websocket.d.ts +27 -0
- package/dist/websocket.js +93 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @xcitedbs/client
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript client for the **XCiteDB BaaS** HTTP API and WebSocket notifications.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
From npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @xcitedbs/client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
From this repo:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd sdks/javascript && npm install && npm run build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Link or `npm pack` / publish as needed.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { XCiteDBClient } from '@xcitedbs/client';
|
|
25
|
+
|
|
26
|
+
const client = new XCiteDBClient({
|
|
27
|
+
baseUrl: 'http://localhost:8080',
|
|
28
|
+
apiKey: process.env.XCITEDB_API_KEY,
|
|
29
|
+
context: { branch: 'main', date: '03/27/2026' },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await client.health();
|
|
33
|
+
const docs = await client.queryByIdentifier('/test1', 'FirstMatch');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### WebSocket
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
client.subscribe(
|
|
40
|
+
{ pattern: '/us/bills/*', event_type: '*' },
|
|
41
|
+
(ev) => console.log(ev)
|
|
42
|
+
);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With JWT in browsers, tokens are passed as `access_token` query parameter on the WebSocket URL. API keys can use `api_key` query parameter.
|
|
46
|
+
|
|
47
|
+
## Build
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm run build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Outputs `dist/` (CommonJS + `.d.ts`).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { AccessCheckResult, AppAuthConfig, AppEmailConfig, AppEmailTemplates, AppUser, AppUserTokenPair, EmailTestResponse, ForgotPasswordResponse, SendVerificationResponse, BranchInfo, CommitRecord, DatabaseContext, DiffRef, DiffResult, Flags, ListIdentifierChildrenResult, ListIdentifiersResult, LockInfo, LogEntry, MergeResult, PolicySubjectInput, PolicyUpdateResponse, RealtimeEvent, SecurityConfig, SecurityPolicy, StoredTriggerResponse, TriggerDefinition, StoredPolicyResponse, SubscriptionOptions, TagRecord, TextSearchQuery, TextSearchResult, OAuthProvidersResponse, OwnedTenantInfo, PlatformRegistrationConfig, PlatformWorkspacesResponse, TokenPair, UserInfo, ApiKeyInfo, WriteDocumentOptions, XCiteDBClientOptions, XCiteQuery } from './types';
|
|
2
|
+
import { WebSocketSubscription } from './websocket';
|
|
3
|
+
export declare class XCiteDBClient {
|
|
4
|
+
private baseUrl;
|
|
5
|
+
private apiKey?;
|
|
6
|
+
private accessToken?;
|
|
7
|
+
private refreshToken?;
|
|
8
|
+
private appUserAccessToken?;
|
|
9
|
+
private appUserRefreshToken?;
|
|
10
|
+
private defaultContext;
|
|
11
|
+
private platformConsole;
|
|
12
|
+
/** When set with {@link platformConsole}, sent as `X-Project-Id` on API requests. */
|
|
13
|
+
private projectId?;
|
|
14
|
+
private onSessionTokensUpdated?;
|
|
15
|
+
private onAppUserTokensUpdated?;
|
|
16
|
+
private onSessionInvalid?;
|
|
17
|
+
constructor(options: XCiteDBClientOptions);
|
|
18
|
+
/** True if this client would send API key or Bearer credentials on a normal request. */
|
|
19
|
+
private sentAuthCredentials;
|
|
20
|
+
/** 401 on these paths is an expected auth flow outcome, not a dead session. */
|
|
21
|
+
private isSessionInvalidExcludedPath;
|
|
22
|
+
private notifySessionInvalidIfNeeded;
|
|
23
|
+
/** Use platform console JWT routes (`/api/v1/platform/auth/*`) for this client instance. */
|
|
24
|
+
setPlatformConsole(enabled: boolean): void;
|
|
25
|
+
get isPlatformConsole(): boolean;
|
|
26
|
+
/** Sets active project for platform console mode (`X-Project-Id`). */
|
|
27
|
+
setProjectId(projectId: string): void;
|
|
28
|
+
setContext(ctx: DatabaseContext): void;
|
|
29
|
+
setTokens(access: string, refresh?: string): void;
|
|
30
|
+
/** End-user (app) tokens. With developer `accessToken`/`apiKey`, sent as `X-App-User-Token`. */
|
|
31
|
+
setAppUserTokens(access: string, refresh?: string): void;
|
|
32
|
+
clearAppUserTokens(): void;
|
|
33
|
+
private contextHeaders;
|
|
34
|
+
/** Include `tenant_id` for public app-auth routes when using only app-user tokens (no developer key/JWT). */
|
|
35
|
+
private mergeAppTenant;
|
|
36
|
+
private authHeaders;
|
|
37
|
+
private request;
|
|
38
|
+
/** Developer Bearer refresh first, then app-user refresh (no API key refresh). */
|
|
39
|
+
private tryRefreshSessionAfter401;
|
|
40
|
+
private refreshAppUserNoRetry;
|
|
41
|
+
health(): Promise<{
|
|
42
|
+
status: string;
|
|
43
|
+
timestamp?: number;
|
|
44
|
+
}>;
|
|
45
|
+
version(): Promise<{
|
|
46
|
+
version: string;
|
|
47
|
+
server: string;
|
|
48
|
+
api_version: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Platform console sign-in. The first argument is the account **email** (e.g. `admin@localhost`).
|
|
52
|
+
* Legacy `/api/v1/auth/login` has been removed.
|
|
53
|
+
*/
|
|
54
|
+
login(email: string, password: string): Promise<TokenPair>;
|
|
55
|
+
/** Platform console sign-in (`email` + `password`). Project context is `X-Project-Id`, not the JWT. */
|
|
56
|
+
platformLogin(email: string, password: string): Promise<TokenPair>;
|
|
57
|
+
refresh(): Promise<TokenPair>;
|
|
58
|
+
logout(): Promise<void>;
|
|
59
|
+
me(): Promise<UserInfo>;
|
|
60
|
+
platformRegistrationConfig(): Promise<PlatformRegistrationConfig>;
|
|
61
|
+
platformRegister(body: {
|
|
62
|
+
email: string;
|
|
63
|
+
password: string;
|
|
64
|
+
display_name?: string;
|
|
65
|
+
invite_code?: string;
|
|
66
|
+
org_action?: 'create' | 'join';
|
|
67
|
+
org_name?: string;
|
|
68
|
+
org_id?: string;
|
|
69
|
+
attributes?: Record<string, unknown>;
|
|
70
|
+
}): Promise<unknown>;
|
|
71
|
+
platformWorkspaces(): Promise<PlatformWorkspacesResponse>;
|
|
72
|
+
listMyTenants(): Promise<OwnedTenantInfo[]>;
|
|
73
|
+
/** Alias for {@link listMyTenants} (organization/project terminology). */
|
|
74
|
+
listMyProjects(): Promise<OwnedTenantInfo[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Switch active tenant/project for API calls. Platform console: updates `X-Project-Id` only (no token exchange).
|
|
77
|
+
* Legacy `/api/v1/auth/switch-tenant` has been removed; non-platform callers should set context instead.
|
|
78
|
+
*/
|
|
79
|
+
switchTenant(tenantId: string): Promise<void>;
|
|
80
|
+
/** Alias for {@link switchTenant}. */
|
|
81
|
+
switchProject(projectId: string): Promise<void>;
|
|
82
|
+
listApiKeys(): Promise<ApiKeyInfo[]>;
|
|
83
|
+
createApiKey(name: string, expiresAt?: number, keyType?: 'secret' | 'public'): Promise<unknown>;
|
|
84
|
+
changePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
85
|
+
revokeApiKey(keyId: string): Promise<void>;
|
|
86
|
+
registerAppUser(email: string, password: string, displayName?: string, groups?: string[], attributes?: Record<string, unknown>): Promise<AppUser>;
|
|
87
|
+
getOAuthProviders(): Promise<OAuthProvidersResponse>;
|
|
88
|
+
/** Relative path + query for browser navigation to start OAuth (append to API base URL). */
|
|
89
|
+
oauthAuthorizePath(provider: string): string;
|
|
90
|
+
/** Exchange one-time session code from OAuth browser redirect (public + tenant_id). */
|
|
91
|
+
exchangeOAuthCode(code: string): Promise<AppUserTokenPair>;
|
|
92
|
+
loginAppUser(email: string, password: string): Promise<AppUserTokenPair>;
|
|
93
|
+
refreshAppUser(): Promise<AppUserTokenPair>;
|
|
94
|
+
logoutAppUser(): Promise<void>;
|
|
95
|
+
appUserMe(): Promise<AppUser>;
|
|
96
|
+
updateAppUserProfile(displayName?: string, attributes?: Record<string, unknown>): Promise<AppUser>;
|
|
97
|
+
exchangeCustomToken(token: string): Promise<AppUserTokenPair>;
|
|
98
|
+
/** Change app-user password (requires valid app-user access token). */
|
|
99
|
+
changeAppUserPassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
100
|
+
/** Request a password-reset token (developer-authenticated). Token omitted when delivery is smtp/webhook success. */
|
|
101
|
+
forgotAppUserPassword(email: string): Promise<ForgotPasswordResponse>;
|
|
102
|
+
/** Complete password reset with token from `forgotAppUserPassword` (public; set `context.tenant_id` if no developer auth). */
|
|
103
|
+
resetAppUserPassword(token: string, newPassword: string): Promise<void>;
|
|
104
|
+
/** Issue email verification token (developer-authenticated). Token omitted when delivery is smtp/webhook success. */
|
|
105
|
+
sendAppUserVerification(userId: string): Promise<SendVerificationResponse>;
|
|
106
|
+
getAppAuthConfig(): Promise<AppAuthConfig>;
|
|
107
|
+
getEmailConfig(): Promise<AppEmailConfig>;
|
|
108
|
+
updateEmailConfig(config: AppEmailConfig): Promise<AppEmailConfig>;
|
|
109
|
+
getEmailTemplates(): Promise<AppEmailTemplates>;
|
|
110
|
+
updateEmailTemplates(templates: AppEmailTemplates): Promise<AppEmailTemplates>;
|
|
111
|
+
sendTestEmail(to: string): Promise<EmailTestResponse>;
|
|
112
|
+
/** Verify email with token (public; set `context.tenant_id` if no developer auth). */
|
|
113
|
+
verifyAppUserEmail(token: string): Promise<void>;
|
|
114
|
+
listAppUsers(): Promise<AppUser[]>;
|
|
115
|
+
getAppUser(userId: string): Promise<AppUser>;
|
|
116
|
+
createAppUser(email: string, password: string, displayName?: string, groups?: string[], attributes?: Record<string, unknown>): Promise<AppUser>;
|
|
117
|
+
deleteAppUser(userId: string): Promise<void>;
|
|
118
|
+
updateAppUserGroups(userId: string, groups: string[]): Promise<void>;
|
|
119
|
+
updateAppUserStatus(userId: string, status: 'active' | 'disabled' | 'pending_verification'): Promise<void>;
|
|
120
|
+
createPolicy(policyId: string, policy: SecurityPolicy): Promise<StoredPolicyResponse>;
|
|
121
|
+
listPolicies(): Promise<Record<string, SecurityPolicy>>;
|
|
122
|
+
getPolicy(policyId: string): Promise<StoredPolicyResponse>;
|
|
123
|
+
updatePolicy(policyId: string, policy: SecurityPolicy): Promise<PolicyUpdateResponse>;
|
|
124
|
+
deletePolicy(policyId: string): Promise<void>;
|
|
125
|
+
upsertTrigger(triggerId: string, trigger: TriggerDefinition): Promise<StoredTriggerResponse>;
|
|
126
|
+
listTriggers(): Promise<Record<string, TriggerDefinition>>;
|
|
127
|
+
getTrigger(name: string): Promise<StoredTriggerResponse>;
|
|
128
|
+
deleteTrigger(name: string): Promise<void>;
|
|
129
|
+
checkAccess(subject: PolicySubjectInput, identifier: string, action: string, metaPath?: string, branch?: string): Promise<AccessCheckResult>;
|
|
130
|
+
getSecurityConfig(): Promise<SecurityConfig>;
|
|
131
|
+
updateSecurityConfig(config: Partial<SecurityConfig>): Promise<void>;
|
|
132
|
+
createBranch(name: string, fromBranch?: string, fromDate?: string): Promise<void>;
|
|
133
|
+
deleteBranch(name: string): Promise<void>;
|
|
134
|
+
deleteRevision(branch: string, date: string): Promise<void>;
|
|
135
|
+
listBranches(): Promise<BranchInfo[]>;
|
|
136
|
+
getBranch(name: string): Promise<BranchInfo>;
|
|
137
|
+
createCommit(message: string, author?: string): Promise<CommitRecord>;
|
|
138
|
+
listCommits(options?: {
|
|
139
|
+
branch?: string;
|
|
140
|
+
limit?: number;
|
|
141
|
+
offset?: number;
|
|
142
|
+
}): Promise<{
|
|
143
|
+
commits: CommitRecord[];
|
|
144
|
+
total: number;
|
|
145
|
+
branch: string;
|
|
146
|
+
}>;
|
|
147
|
+
getCommit(commitId: string): Promise<CommitRecord>;
|
|
148
|
+
rollbackToCommit(commitId: string, _confirm?: boolean): Promise<{
|
|
149
|
+
rolled_back_commits: string[];
|
|
150
|
+
current_tip: string;
|
|
151
|
+
}>;
|
|
152
|
+
cherryPick(commitId: string, message?: string, author?: string): Promise<CommitRecord>;
|
|
153
|
+
createTag(name: string, commitId: string, message?: string, author?: string): Promise<TagRecord>;
|
|
154
|
+
listTags(options?: {
|
|
155
|
+
limit?: number;
|
|
156
|
+
offset?: number;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
tags: TagRecord[];
|
|
159
|
+
total: number;
|
|
160
|
+
}>;
|
|
161
|
+
getTag(name: string): Promise<TagRecord>;
|
|
162
|
+
deleteTag(name: string): Promise<void>;
|
|
163
|
+
diff(from: DiffRef, to: DiffRef, includeContent?: boolean): Promise<DiffResult>;
|
|
164
|
+
mergeBranch(targetBranch: string, sourceBranch: string, options?: {
|
|
165
|
+
message?: string;
|
|
166
|
+
autoResolve?: 'none' | 'source' | 'target';
|
|
167
|
+
}): Promise<MergeResult>;
|
|
168
|
+
/** Send raw XML body (`Content-Type: application/xml`). For JSON wrapper + options use `writeDocumentJson`. */
|
|
169
|
+
writeXML(xml: string, _options?: WriteDocumentOptions): Promise<void>;
|
|
170
|
+
writeDocumentJson(xml: string, options?: WriteDocumentOptions): Promise<void>;
|
|
171
|
+
queryByIdentifier(identifier: string, flags?: Flags, filter?: string, pathFilter?: string): Promise<string[]>;
|
|
172
|
+
queryDocuments(query: XCiteQuery, flags?: Flags, filter?: string, pathFilter?: string): Promise<string[]>;
|
|
173
|
+
deleteDocument(identifier: string): Promise<void>;
|
|
174
|
+
addIdentifier(identifier: string): Promise<boolean>;
|
|
175
|
+
addAlias(original: string, alias: string): Promise<boolean>;
|
|
176
|
+
queryChangeDate(identifier: string): Promise<string>;
|
|
177
|
+
getXcitepath(identifier: string): Promise<string>;
|
|
178
|
+
changedIdentifiers(branch: string, fromDate?: string, toDate?: string): Promise<string[]>;
|
|
179
|
+
listIdentifiers(query: XCiteQuery): Promise<ListIdentifiersResult>;
|
|
180
|
+
listIdentifierChildren(parentPath?: string): Promise<ListIdentifierChildrenResult>;
|
|
181
|
+
queryLog(query: XCiteQuery, fromDate: string, toDate: string): Promise<LogEntry[]>;
|
|
182
|
+
addMeta(identifier: string, value: unknown, path?: string, opts?: {
|
|
183
|
+
mode?: 'set' | 'append';
|
|
184
|
+
}): Promise<boolean>;
|
|
185
|
+
addMetaByQuery(query: XCiteQuery, value: unknown, path?: string, firstMatch?: boolean, opts?: {
|
|
186
|
+
mode?: 'set' | 'append';
|
|
187
|
+
}): Promise<boolean>;
|
|
188
|
+
appendMeta(identifier: string, value: unknown, path?: string): Promise<boolean>;
|
|
189
|
+
appendMetaByQuery(query: XCiteQuery, value: unknown, path?: string, firstMatch?: boolean): Promise<boolean>;
|
|
190
|
+
queryMeta(identifier: string, path?: string): Promise<unknown>;
|
|
191
|
+
queryMetaByQuery(query: XCiteQuery, path?: string): Promise<unknown>;
|
|
192
|
+
clearMeta(query: XCiteQuery): Promise<boolean>;
|
|
193
|
+
acquireLock(identifier: string, expires?: number): Promise<LockInfo>;
|
|
194
|
+
releaseLock(identifier: string, lockId: string): Promise<boolean>;
|
|
195
|
+
findLocks(identifier: string): Promise<LockInfo[]>;
|
|
196
|
+
unquery(query: XCiteQuery, unquery: unknown): Promise<unknown>;
|
|
197
|
+
search(q: TextSearchQuery): Promise<TextSearchResult>;
|
|
198
|
+
reindex(): Promise<{
|
|
199
|
+
status: string;
|
|
200
|
+
message: string;
|
|
201
|
+
}>;
|
|
202
|
+
writeJsonDocument(identifier: string, data: unknown): Promise<void>;
|
|
203
|
+
readJsonDocument(identifier: string): Promise<unknown>;
|
|
204
|
+
deleteJsonDocument(identifier: string): Promise<void>;
|
|
205
|
+
listJsonDocuments(match?: string, limit?: number, offset?: number): Promise<ListIdentifiersResult>;
|
|
206
|
+
/**
|
|
207
|
+
* WebSocket `/api/v1/ws` — optional initial subscription pattern.
|
|
208
|
+
* Uses `access_token` or `api_key` query params when headers are not available (browser).
|
|
209
|
+
*/
|
|
210
|
+
subscribe(options: SubscriptionOptions, callback: (event: RealtimeEvent) => void, onError?: (err: Error) => void): WebSocketSubscription;
|
|
211
|
+
}
|