tevrocsdk 0.1.49 → 0.1.51
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 +334 -516
- package/package.json +1 -1
- package/tevroc-sdk.esm.js +368 -148
- package/tevroc-sdk.min.js +48 -48
- package/tevroc-sdk.umd.js +368 -148
package/README.md
CHANGED
|
@@ -1,516 +1,334 @@
|
|
|
1
|
-
# Tevroc SDK
|
|
2
|
-
|
|
3
|
-
Tevroc SDK
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
### npm / ESM
|
|
8
|
-
```bash
|
|
9
|
-
npm install tevrocsdk
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
### Browser
|
|
13
|
-
```html
|
|
14
|
-
<script src="https://unpkg.com/tevrocsdk@latest/tevroc-sdk.min.js"></script>
|
|
15
|
-
<script>
|
|
16
|
-
const tevroc = Tevroc.createClient({
|
|
17
|
-
baseUrl: "https://your-worker.example.workers.dev"
|
|
18
|
-
});
|
|
19
|
-
</script>
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
email: "ada@example.com",
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
await tevroc.integrations.Core.GenerateImage({
|
|
337
|
-
prompt: "A futuristic dashboard",
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
await tevroc.integrations.Core.SendEmail({
|
|
341
|
-
to: "ada@example.com",
|
|
342
|
-
subject: "Hello",
|
|
343
|
-
text: "From Tevroc",
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
await tevroc.integrations.Core.UploadFile(file, {
|
|
347
|
-
filename: "report.pdf",
|
|
348
|
-
contentType: "application/pdf",
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
await tevroc.integrations.Core.UploadPrivateFile(file, {
|
|
352
|
-
filename: "report.pdf",
|
|
353
|
-
contentType: "application/pdf",
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
await tevroc.integrations.Core.CreateFileSignedUrl({
|
|
357
|
-
key: "report.pdf",
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
await tevroc.integrations.Core.ExtractDataFromUploadedFile({
|
|
361
|
-
fileId: "123",
|
|
362
|
-
});
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
## Accept payments
|
|
366
|
-
|
|
367
|
-
If your app needs a checkout or payment flow, the payments helpers can start a Yoco-based payment experience and let you react to the resulting status updates.
|
|
368
|
-
|
|
369
|
-
```js
|
|
370
|
-
await tevroc.payments.create({
|
|
371
|
-
amountZAR: 50,
|
|
372
|
-
appId: "tevroc-portal",
|
|
373
|
-
mode: "web",
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
const unsubscribe = tevroc.payments.onstatus((status, error) => {
|
|
377
|
-
if (error) {
|
|
378
|
-
console.error("Payment listener error", error);
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
console.log("Payment status:", status);
|
|
383
|
-
});
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
## Work with files and local app data
|
|
387
|
-
|
|
388
|
-
Use the file helpers to build links for uploaded assets and the native helpers to store lightweight app data locally across web, mobile, and desktop environments.
|
|
389
|
-
|
|
390
|
-
```js
|
|
391
|
-
const fileUrl = tevroc.files.url("reports/summary.pdf");
|
|
392
|
-
const privateFileUrl = tevroc.files.privateUrl("reports/private.pdf");
|
|
393
|
-
|
|
394
|
-
await tevroc.files.get("reports/summary.pdf");
|
|
395
|
-
await tevroc.files.getPrivate("reports/private.pdf");
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
### Native store helpers
|
|
399
|
-
```js
|
|
400
|
-
const store = tevroc.native.store;
|
|
401
|
-
const ref = store.ref("settings");
|
|
402
|
-
await store.set(ref, { theme: "dark" });
|
|
403
|
-
await store.update(ref, { lastOpened: Date.now() });
|
|
404
|
-
await store.get(ref);
|
|
405
|
-
await store.remove(ref);
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
### Google Drive and project helpers
|
|
409
|
-
```js
|
|
410
|
-
await tevroc.native.files.saveJsonToDrive("project", { ok: true }, null, "user-1");
|
|
411
|
-
await tevroc.native.files.readJsonFromDrive("file_123", "user-1");
|
|
412
|
-
await tevroc.native.files.deleteFromDrive("file_123", "user-1");
|
|
413
|
-
|
|
414
|
-
await tevroc.native.projects.upsertUser({
|
|
415
|
-
uid: "u1",
|
|
416
|
-
email: "ada@example.com",
|
|
417
|
-
displayName: "Ada",
|
|
418
|
-
photoURL: "",
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
await tevroc.native.projects.saveProjectMeta("u1", "p1", { title: "Launch" });
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
## Create agent conversations
|
|
425
|
-
|
|
426
|
-
Agents are useful when you want to create multi-turn conversations with a support or assistant experience. You can start a conversation, add user messages, and list the thread history from the SDK.
|
|
427
|
-
|
|
428
|
-
```js
|
|
429
|
-
const conversation = await tevroc.agents.Support.createConversation({
|
|
430
|
-
title: "Onboarding",
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
## Offline & sync features
|
|
434
|
-
|
|
435
|
-
The SDK distribution includes built-in offline sync support when used in apps that integrate the native helpers (Capacitor/Tauri). Key features:
|
|
436
|
-
|
|
437
|
-
- Local storage of entities using platform-native SQLite when available (Capacitor/Tauri), with `localStorage` fallback.
|
|
438
|
-
- Queued operations: `create`, `update`, and `delete` are queued while offline and applied locally immediately so the UI remains responsive.
|
|
439
|
-
- Sync engine: periodic and event-driven flush of queued operations when the app regains connectivity or resumes; emits events and stores simple conflicts detected by timestamp comparison.
|
|
440
|
-
- Conflict APIs: `client.offline.listConflicts()` and `client.offline.resolveConflict(conflictId, resolution)` let apps inspect and resolve conflicts.
|
|
441
|
-
|
|
442
|
-
Example usage:
|
|
443
|
-
|
|
444
|
-
```js
|
|
445
|
-
const client = createClient({ baseUrl: 'https://api.example', appId: 'myapp' });
|
|
446
|
-
client.offline.startAutoSync();
|
|
447
|
-
|
|
448
|
-
client.offline.on('conflict', ({ conflictId }) => {
|
|
449
|
-
console.warn('Conflict detected:', conflictId);
|
|
450
|
-
});
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
Notes:
|
|
454
|
-
- The SDK attempts to use `@capacitor/network`, `@capacitor/app`, and `@capacitor-community/background-task` when available. If plugins are missing it falls back to foreground sync on resume/focus.
|
|
455
|
-
- For production mobile background sync, configure OS-level background permissions and install/verify background-task plugins.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
await tevroc.agents.Support.addMessage(conversation.data.id, {
|
|
459
|
-
role: "user",
|
|
460
|
-
content: "Help me configure my workspace",
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
const messages = await tevroc.agents.Support.listMessages(conversation.data.id);
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
## Connectors, logs, custom integrations, and SSO
|
|
467
|
-
|
|
468
|
-
These features help you connect external services, track app events, call custom integrations, and handle SSO flows. They are especially useful for admin dashboards, automation, and customer-facing experiences.
|
|
469
|
-
|
|
470
|
-
```js
|
|
471
|
-
await tevroc.connectors.list();
|
|
472
|
-
await tevroc.connectors.get("slack");
|
|
473
|
-
await tevroc.connectors.connect("slack", { config: { teamId: "T123" } });
|
|
474
|
-
await tevroc.connectors.disconnect("slack");
|
|
475
|
-
await tevroc.connectors.status("slack");
|
|
476
|
-
|
|
477
|
-
await tevroc.connectors.user.list();
|
|
478
|
-
await tevroc.connectors.user.refresh("abc123");
|
|
479
|
-
|
|
480
|
-
await tevroc.logs.list({ limit: 20 });
|
|
481
|
-
await tevroc.logs.create({
|
|
482
|
-
level: "info",
|
|
483
|
-
message: "User opened dashboard",
|
|
484
|
-
context: { source: "web" },
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
await tevroc.customIntegrations.example.echo({ ok: true });
|
|
488
|
-
await tevroc.sso.accessToken({ code: "provider-code" });
|
|
489
|
-
await tevroc.sso.callback({ code: "provider-code" });
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
## Make raw requests
|
|
493
|
-
|
|
494
|
-
Use `request` when you need to call a worker route that does not yet have a dedicated helper. This gives you a flexible fallback for custom endpoints while still using the same authenticated client.
|
|
495
|
-
|
|
496
|
-
```js
|
|
497
|
-
const health = await tevroc.request("/health", { auth: false });
|
|
498
|
-
```
|
|
499
|
-
|
|
500
|
-
## Handle errors
|
|
501
|
-
|
|
502
|
-
Tevroc SDK throws structured errors that make it easier to respond to failed requests. You can inspect the status code and details to guide the user experience or retry logic.
|
|
503
|
-
|
|
504
|
-
```js
|
|
505
|
-
import { TevrocError } from "tevrocsdk";
|
|
506
|
-
|
|
507
|
-
try {
|
|
508
|
-
await tevroc.auth.me();
|
|
509
|
-
} catch (error) {
|
|
510
|
-
if (error instanceof TevrocError && error.status === 401) {
|
|
511
|
-
// Ask the user to sign in again.
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
|
|
1
|
+
# Tevroc SDK
|
|
2
|
+
|
|
3
|
+
Tevroc SDK provides a unified JavaScript client for Tevroc worker APIs. It supports authentication, entity CRUD, integrations, file handling, payments, native persistence, offline sync, and runtime-aware behavior across browser, Capacitor, and Tauri environments.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
### npm / ESM
|
|
8
|
+
```bash
|
|
9
|
+
npm install tevrocsdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Browser
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://unpkg.com/tevrocsdk@latest/tevroc-sdk.min.js"></script>
|
|
15
|
+
<script>
|
|
16
|
+
const tevroc = Tevroc.createClient({
|
|
17
|
+
baseUrl: "https://your-worker.example.workers.dev"
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Create a client
|
|
23
|
+
|
|
24
|
+
Create a client to configure your runtime, application identity, and debug behavior.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { createClient } from "tevrocsdk";
|
|
28
|
+
|
|
29
|
+
const tevroc = createClient({
|
|
30
|
+
baseUrl: "https://your-worker.example.workers.dev",
|
|
31
|
+
serviceUrl: "https://services.example.com",
|
|
32
|
+
appId: "tevroc-portal",
|
|
33
|
+
appName: "Tevroc Portal",
|
|
34
|
+
debug: true,
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use the same client across auth, entities, files, integrations, payments, offline sync, and native helpers.
|
|
39
|
+
|
|
40
|
+
## Debug mode
|
|
41
|
+
|
|
42
|
+
Set `debug: true` to enable SDK diagnostics. When debug mode is active, the SDK logs request details, offline sync events, native helper activity, and retry behavior. In production, omit this flag to keep logs quiet.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const tevroc = createClient({
|
|
46
|
+
baseUrl: "https://your-worker.example.workers.dev",
|
|
47
|
+
debug: true,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Authentication
|
|
52
|
+
|
|
53
|
+
The SDK includes login, registration, logout, OTP verification, password reset, and social sign-in helpers.
|
|
54
|
+
|
|
55
|
+
### Sign in and profile
|
|
56
|
+
```js
|
|
57
|
+
const { token, user } = await tevroc.auth.login({
|
|
58
|
+
email: "ada@example.com",
|
|
59
|
+
password: "correct horse battery staple",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const me = await tevroc.auth.me();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Registration and account actions
|
|
66
|
+
```js
|
|
67
|
+
await tevroc.auth.register({
|
|
68
|
+
email: "ada@example.com",
|
|
69
|
+
password: "correct horse battery staple",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await tevroc.auth.logout();
|
|
73
|
+
await tevroc.auth.verifyOtp({ code: "123456" });
|
|
74
|
+
await tevroc.auth.changePassword({ oldPassword: "old", newPassword: "new" });
|
|
75
|
+
await tevroc.auth.resetPassword({ email: "ada@example.com" });
|
|
76
|
+
await tevroc.auth.loginUrl("/dashboard");
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Google sign-in
|
|
80
|
+
```js
|
|
81
|
+
await tevroc.auth.googleLogin({
|
|
82
|
+
appId: "tevroc-portal",
|
|
83
|
+
appName: "Tevroc Portal",
|
|
84
|
+
serviceUrl: "https://services.example.com",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
tevroc.auth.onGoogleLogin((user, error) => {
|
|
88
|
+
if (error) {
|
|
89
|
+
console.error("Google login failed", error);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.log("Google user", user);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await tevroc.auth.loginWithGoogle({
|
|
97
|
+
accessToken: googleAccessToken,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await tevroc.auth.loginWithProvider("google", "/dashboard");
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Entities
|
|
104
|
+
|
|
105
|
+
Entities are the main data layer for your app. Use them for create/read/update/delete workflows and list/query operations.
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
const created = await tevroc.entities.Project.create({
|
|
109
|
+
name: "Launch site",
|
|
110
|
+
status: "active",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const projects = await tevroc.entities.Project.list({ limit: 20 });
|
|
114
|
+
|
|
115
|
+
const filtered = await tevroc.entities.Project.query({
|
|
116
|
+
filter: { status: "active" },
|
|
117
|
+
limit: 10,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
await tevroc.entities.Project.update(created.data.id, { status: "done" });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Common entity methods:
|
|
124
|
+
|
|
125
|
+
- `list({ limit, offset })`
|
|
126
|
+
- `get(id)`
|
|
127
|
+
- `create(record)`
|
|
128
|
+
- `update(id, patch)`
|
|
129
|
+
- `delete(id)`
|
|
130
|
+
- `query({ filter, limit })`
|
|
131
|
+
- `filter(filter, sortOrOptions, limit)`
|
|
132
|
+
- `bulkCreate(records)`
|
|
133
|
+
- `bulkUpdate(records)`
|
|
134
|
+
- `bulkDelete(ids)`
|
|
135
|
+
- `import(records)`
|
|
136
|
+
|
|
137
|
+
## Custom functions
|
|
138
|
+
|
|
139
|
+
Call server-side functions by name to trigger custom business logic.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
await tevroc.functions.invoke("ping", { hello: "world" });
|
|
143
|
+
|
|
144
|
+
// Shorthand helper
|
|
145
|
+
await tevroc.functions.ping({ hello: "world" });
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Integrations
|
|
149
|
+
|
|
150
|
+
Use built-in integrations for AI, file uploads, email, signed URLs, and data extraction.
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
await tevroc.integrations.Core.InvokeLLM({
|
|
154
|
+
prompt: "Write a two-line launch checklist.",
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await tevroc.integrations.Core.GenerateImage({
|
|
158
|
+
prompt: "A futuristic dashboard",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await tevroc.integrations.Core.SendEmail({
|
|
162
|
+
to: "ada@example.com",
|
|
163
|
+
subject: "Hello",
|
|
164
|
+
text: "From Tevroc",
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
await tevroc.integrations.Core.UploadFile(file, {
|
|
168
|
+
filename: "report.pdf",
|
|
169
|
+
contentType: "application/pdf",
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
await tevroc.integrations.Core.UploadPrivateFile(file, {
|
|
173
|
+
filename: "report.pdf",
|
|
174
|
+
contentType: "application/pdf",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await tevroc.integrations.Core.CreateFileSignedUrl({
|
|
178
|
+
key: "report.pdf",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await tevroc.integrations.Core.ExtractDataFromUploadedFile({
|
|
182
|
+
fileId: "123",
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Payments
|
|
187
|
+
|
|
188
|
+
The payments helpers support Yoco-based checkout creation and status tracking.
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
await tevroc.payments.create({
|
|
192
|
+
amountZAR: 50,
|
|
193
|
+
appId: "tevroc-portal",
|
|
194
|
+
mode: "web",
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const unsubscribe = tevroc.payments.onstatus((status, error) => {
|
|
198
|
+
if (error) {
|
|
199
|
+
console.error("Payment listener error", error);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
console.log("Payment status:", status);
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Files and native app data
|
|
208
|
+
|
|
209
|
+
Use file helpers for public asset URLs and secure private downloads, and native storage helpers for app state across platforms.
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
const fileUrl = tevroc.files.url("reports/summary.pdf");
|
|
213
|
+
const privateFileUrl = tevroc.files.privateUrl("reports/private.pdf");
|
|
214
|
+
|
|
215
|
+
await tevroc.files.get("reports/summary.pdf");
|
|
216
|
+
await tevroc.files.getPrivate("reports/private.pdf");
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Native store helpers
|
|
220
|
+
```js
|
|
221
|
+
const store = tevroc.native.store;
|
|
222
|
+
const ref = store.ref("settings");
|
|
223
|
+
await store.set(ref, { theme: "dark" });
|
|
224
|
+
await store.update(ref, { lastOpened: Date.now() });
|
|
225
|
+
await store.get(ref);
|
|
226
|
+
await store.remove(ref);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Google Drive and project helpers
|
|
230
|
+
```js
|
|
231
|
+
await tevroc.native.files.saveJsonToDrive("project", { ok: true }, null, "user-1");
|
|
232
|
+
await tevroc.native.files.readJsonFromDrive("file_123", "user-1");
|
|
233
|
+
await tevroc.native.files.deleteFromDrive("file_123", "user-1");
|
|
234
|
+
|
|
235
|
+
await tevroc.native.projects.upsertUser({
|
|
236
|
+
uid: "u1",
|
|
237
|
+
email: "ada@example.com",
|
|
238
|
+
displayName: "Ada",
|
|
239
|
+
photoURL: "",
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Offline sync
|
|
244
|
+
|
|
245
|
+
Tevroc SDK uses native storage as the authoritative offline store for entities and queued file uploads when available. Write operations are persisted locally and replayed once connectivity returns. On mobile and desktop this uses SQLite-backed native storage; in browser-only environments it falls back to `localStorage`.
|
|
246
|
+
|
|
247
|
+
```js
|
|
248
|
+
const client = createClient({
|
|
249
|
+
baseUrl: "https://api.example",
|
|
250
|
+
appId: "myapp",
|
|
251
|
+
debug: true,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
client.offline.startAutoSync();
|
|
255
|
+
|
|
256
|
+
client.offline.on("conflict", ({ conflictId }) => {
|
|
257
|
+
console.warn("Conflict detected:", conflictId);
|
|
258
|
+
});
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Offline sync behavior:
|
|
262
|
+
|
|
263
|
+
- Local writes are queued and applied immediately to the native/local cache so the UI stays responsive.
|
|
264
|
+
- The SDK retries queued operations automatically on resume, focus, and reconnect events.
|
|
265
|
+
- Conflict data is surfaced through `client.offline.listConflicts()` and `client.offline.resolveConflict(conflictId, resolution)`.
|
|
266
|
+
- `debug: true` enables detailed request, sync, and persistence logging.
|
|
267
|
+
|
|
268
|
+
```mermaid
|
|
269
|
+
flowchart TD
|
|
270
|
+
UI[User action]
|
|
271
|
+
SDK[Tevroc SDK client]
|
|
272
|
+
Local[Native/local store]
|
|
273
|
+
Queue[Offline queue]
|
|
274
|
+
Network[Connectivity restored]
|
|
275
|
+
Server[Tevroc API]
|
|
276
|
+
|
|
277
|
+
UI --> SDK
|
|
278
|
+
SDK --> Local
|
|
279
|
+
SDK --> Queue
|
|
280
|
+
Queue --> Server
|
|
281
|
+
Server --> Local
|
|
282
|
+
Network --> Queue
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Architecture overview
|
|
286
|
+
|
|
287
|
+
The SDK is built around one unified client object. It exposes helpers for auth, entities, files, integrations, payments, native storage, and offline sync so your app can use the same model across browser, mobile, and desktop.
|
|
288
|
+
|
|
289
|
+
```mermaid
|
|
290
|
+
flowchart LR
|
|
291
|
+
Client[Tevroc SDK Client]
|
|
292
|
+
Auth[Auth API]
|
|
293
|
+
Entities[Entities API]
|
|
294
|
+
Integrations[Integrations API]
|
|
295
|
+
Files[Files API]
|
|
296
|
+
Payments[Payments API]
|
|
297
|
+
Native[Native helpers]
|
|
298
|
+
Offline[Offline sync]
|
|
299
|
+
Worker[Tevroc Worker / API]
|
|
300
|
+
Platform[Capacitor / Tauri / Browser]
|
|
301
|
+
|
|
302
|
+
Client --> Auth
|
|
303
|
+
Client --> Entities
|
|
304
|
+
Client --> Integrations
|
|
305
|
+
Client --> Files
|
|
306
|
+
Client --> Payments
|
|
307
|
+
Client --> Native
|
|
308
|
+
Client --> Offline
|
|
309
|
+
Auth --> Worker
|
|
310
|
+
Entities --> Worker
|
|
311
|
+
Integrations --> Worker
|
|
312
|
+
Files --> Worker
|
|
313
|
+
Payments --> Worker
|
|
314
|
+
Offline --> Worker
|
|
315
|
+
Native --> Platform
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Error handling
|
|
319
|
+
|
|
320
|
+
The SDK exports `TevrocError` for structured error handling.
|
|
321
|
+
|
|
322
|
+
```js
|
|
323
|
+
import { TevrocError } from "tevrocsdk";
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
await tevroc.auth.me();
|
|
327
|
+
} catch (error) {
|
|
328
|
+
if (error instanceof TevrocError && error.status === 401) {
|
|
329
|
+
// ask the user to sign in again
|
|
330
|
+
} else {
|
|
331
|
+
console.error("Unexpected Tevroc error", error);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
```
|