tevrocsdk 0.1.29 → 0.1.31

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
@@ -1,13 +1,6 @@
1
1
  # Tevroc SDK
2
2
 
3
- JavaScript SDK for the `tevroc-api`
4
-
5
- Supports:
6
- - ESM (import)
7
- - UMD (browser `<script>`)
8
- - CDN usage (unpkg/jsdelivr)
9
-
10
- ---
3
+ Tevroc SDK helps you work with Tevroc apps and worker APIs from JavaScript or TypeScript projects. Use it for authentication, records, custom functions, AI integrations, payments, file handling, and more.
11
4
 
12
5
  ## Install
13
6
 
@@ -16,91 +9,97 @@ Supports:
16
9
  npm install tevrocsdk
17
10
  ```
18
11
 
19
- ### Browser (UMD / CDN)
20
- Option 1: Local file
21
- ``` html
22
- <script src="./tevroc-sdk.umd.js"></script>
23
- <script>
24
- const tevroc = Tevroc.createClient({
25
- baseUrl: "https://your-worker.example.workers.dev"
26
- });
27
- </script>
28
- ```
29
-
30
- Option 2: CDN (recommended)
12
+ ### Browser
31
13
  ```html
32
14
  <script src="https://unpkg.com/tevrocsdk@latest/tevroc-sdk.min.js"></script>
33
15
  <script>
34
16
  const tevroc = Tevroc.createClient({
35
- baseUrl: "https://api.tevrocsdk.example.com"
17
+ baseUrl: "https://your-worker.example.workers.dev"
36
18
  });
37
19
  </script>
38
20
  ```
39
21
 
40
-
41
22
  ## Create a client
42
23
 
24
+ Start by creating a client with your Tevroc worker URL and app details. This gives you a single object that you can use throughout your app for authentication, data access, integrations, and more.
25
+
43
26
  ```js
44
27
  import { createClient } from "tevrocsdk";
45
28
 
46
29
  const tevroc = createClient({
47
- baseUrl: "https://api.tevrocsdk.example.com",
30
+ baseUrl: "https://your-worker.example.workers.dev",
31
+ serviceUrl: "https://services.example.com",
48
32
  appId: "tevroc-portal",
49
33
  appName: "Tevroc Portal",
50
34
  });
51
35
  ```
52
36
 
53
- You can also pass an existing token:
37
+ You can also reuse an existing access token:
54
38
 
55
39
  ```js
56
40
  const tevroc = createClient({
57
- baseUrl: "https://api.tevrocsdk.example.com",
41
+ baseUrl: "https://your-worker.example.workers.dev",
58
42
  token: localStorage.getItem("tevroc_access_token"),
59
43
  appId: "tevroc-portal",
60
44
  appName: "Tevroc Portal",
61
45
  });
62
46
  ```
63
47
 
64
- ## Auth
48
+ ## Authentication
49
+
50
+ Use the authentication helpers to sign users in, keep their session active, and fetch profile information. These methods are useful for login pages, protected screens, and account management flows.
65
51
 
52
+ ### Log in and fetch your profile
66
53
  ```js
67
54
  const { token, user } = await tevroc.auth.login({
68
55
  email: "ada@example.com",
69
56
  password: "correct horse battery staple",
70
57
  });
71
58
 
72
- // The SDK stores the token on the client after login/register.
73
59
  const me = await tevroc.auth.me();
74
60
  ```
75
61
 
76
- ## Google login
62
+ ### Register, log out, and reset password
63
+ ```js
64
+ await tevroc.auth.register({
65
+ email: "ada@example.com",
66
+ password: "correct horse battery staple",
67
+ });
68
+
69
+ await tevroc.auth.logout();
70
+ await tevroc.auth.verifyOtp({ code: "123456" });
71
+ await tevroc.auth.changePassword({ oldPassword: "old", newPassword: "new" });
72
+ await tevroc.auth.resetPassword({ email: "ada@example.com" });
73
+ await tevroc.auth.loginUrl("/dashboard");
74
+ ```
77
75
 
76
+ ### Google sign-in
78
77
  ```js
79
- // Start Google auth flow in web or mobile.
80
78
  await tevroc.auth.googleLogin({
81
79
  appId: "tevroc-portal",
82
80
  appName: "Tevroc Portal",
83
- serviceUrl: "https://services.tevrocsdk.example.com",
81
+ serviceUrl: "https://services.example.com",
84
82
  });
85
83
 
86
- // Subscribe to login events from the SDK.
87
84
  tevroc.auth.onGoogleLogin((user, error) => {
88
85
  if (error) {
89
86
  console.error("Google login failed", error);
90
87
  return;
91
88
  }
92
89
 
93
- console.log("Google user profile:", user);
94
- // Optionally exchange the user object with your API after callback.
90
+ console.log("Google user", user);
91
+ });
92
+
93
+ await tevroc.auth.loginWithGoogle({
94
+ accessToken: googleAccessToken,
95
95
  });
96
96
 
97
- // Alternative helper: loginWithProvider redirects after success.
98
97
  await tevroc.auth.loginWithProvider("google", "/dashboard");
99
98
  ```
100
99
 
101
- ## Entities
100
+ ## Work with entities
102
101
 
103
- Entities are dynamic, like the Base44 SDK.
102
+ Entities let you manage dynamic records in a simple, Base44-style way. They are ideal for CRUD screens such as projects, tasks, customers, or any custom business data.
104
103
 
105
104
  ```js
106
105
  const created = await tevroc.entities.Project.create({
@@ -118,7 +117,7 @@ const filtered = await tevroc.entities.Project.query({
118
117
  await tevroc.entities.Project.update(created.data.id, { status: "done" });
119
118
  ```
120
119
 
121
- Available methods:
120
+ Common entity methods:
122
121
 
123
122
  - `list({ limit, offset })`
124
123
  - `get(id)`
@@ -126,31 +125,72 @@ Available methods:
126
125
  - `update(id, patch)`
127
126
  - `delete(id)`
128
127
  - `query({ filter, limit })`
128
+ - `filter(filter, sortOrOptions, limit)`
129
129
  - `bulkCreate(records)`
130
130
  - `bulkUpdate(records)`
131
131
  - `bulkDelete(ids)`
132
132
  - `import(records)`
133
133
 
134
- ## Functions
134
+ ## Call custom functions
135
+
136
+ Use custom functions when you want to trigger server-side logic by name. This is useful for actions such as sending data to a worker route, running a calculation, or invoking a workflow.
135
137
 
136
138
  ```js
137
139
  await tevroc.functions.invoke("ping", { hello: "world" });
138
140
 
139
- // Shorthand:
141
+ // Shorthand for common functions
140
142
  await tevroc.functions.ping({ hello: "world" });
141
143
  ```
142
144
 
143
- ## Yoco payment
145
+ ## Use core integrations
146
+
147
+ Core integrations give you quick access to common AI and content features such as LLM prompts, image generation, email delivery, file uploads, and signed URLs. These helpers make it easy to add backend-powered features without writing custom plumbing.
148
+
149
+ ```js
150
+ await tevroc.integrations.Core.InvokeLLM({
151
+ prompt: "Write a two-line launch checklist.",
152
+ });
153
+
154
+ await tevroc.integrations.Core.GenerateImage({
155
+ prompt: "A futuristic dashboard",
156
+ });
157
+
158
+ await tevroc.integrations.Core.SendEmail({
159
+ to: "ada@example.com",
160
+ subject: "Hello",
161
+ text: "From Tevroc",
162
+ });
163
+
164
+ await tevroc.integrations.Core.UploadFile(file, {
165
+ filename: "report.pdf",
166
+ contentType: "application/pdf",
167
+ });
168
+
169
+ await tevroc.integrations.Core.UploadPrivateFile(file, {
170
+ filename: "report.pdf",
171
+ contentType: "application/pdf",
172
+ });
173
+
174
+ await tevroc.integrations.Core.CreateFileSignedUrl({
175
+ key: "report.pdf",
176
+ });
177
+
178
+ await tevroc.integrations.Core.ExtractDataFromUploadedFile({
179
+ fileId: "123",
180
+ });
181
+ ```
182
+
183
+ ## Accept payments
184
+
185
+ 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.
144
186
 
145
187
  ```js
146
- // Create a payment flow for the amount in ZAR.
147
188
  await tevroc.payments.create({
148
- amountZAR: 50.0,
189
+ amountZAR: 50,
149
190
  appId: "tevroc-portal",
150
191
  mode: "web",
151
192
  });
152
193
 
153
- // Listen for payment status updates.
154
194
  const unsubscribe = tevroc.payments.onstatus((status, error) => {
155
195
  if (error) {
156
196
  console.error("Payment listener error", error);
@@ -158,35 +198,50 @@ const unsubscribe = tevroc.payments.onstatus((status, error) => {
158
198
  }
159
199
 
160
200
  console.log("Payment status:", status);
161
-
162
- if (status === "success") {
163
- // Payment succeeded.
164
- } else if (status === "failed") {
165
- // Payment failed or was canceled.
166
- }
167
201
  });
168
202
  ```
169
203
 
170
- ## Core integrations
204
+ ## Work with files and local app data
205
+
206
+ 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.
171
207
 
172
208
  ```js
173
- await tevroc.integrations.Core.InvokeLLM({
174
- prompt: "Write a two-line launch checklist.",
175
- });
209
+ const fileUrl = tevroc.files.url("reports/summary.pdf");
210
+ const privateFileUrl = tevroc.files.privateUrl("reports/private.pdf");
176
211
 
177
- await tevroc.integrations.Core.SendEmail({
178
- to: "ada@example.com",
179
- subject: "Hello",
180
- text: "From Tevroc",
181
- });
212
+ await tevroc.files.get("reports/summary.pdf");
213
+ await tevroc.files.getPrivate("reports/private.pdf");
214
+ ```
182
215
 
183
- await tevroc.integrations.Core.UploadFile(file, {
184
- filename: "report.pdf",
185
- contentType: "application/pdf",
216
+ ### Native store helpers
217
+ ```js
218
+ const store = tevroc.native.store;
219
+ const ref = store.ref("settings");
220
+ await store.set(ref, { theme: "dark" });
221
+ await store.update(ref, { lastOpened: Date.now() });
222
+ await store.get(ref);
223
+ await store.remove(ref);
224
+ ```
225
+
226
+ ### Google Drive and project helpers
227
+ ```js
228
+ await tevroc.native.files.saveJsonToDrive("project", { ok: true }, null, "user-1");
229
+ await tevroc.native.files.readJsonFromDrive("file_123", "user-1");
230
+ await tevroc.native.files.deleteFromDrive("file_123", "user-1");
231
+
232
+ await tevroc.native.projects.upsertUser({
233
+ uid: "u1",
234
+ email: "ada@example.com",
235
+ displayName: "Ada",
236
+ photoURL: "",
186
237
  });
238
+
239
+ await tevroc.native.projects.saveProjectMeta("u1", "p1", { title: "Launch" });
187
240
  ```
188
241
 
189
- ## Agents
242
+ ## Create agent conversations
243
+
244
+ 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.
190
245
 
191
246
  ```js
192
247
  const conversation = await tevroc.agents.Support.createConversation({
@@ -201,13 +256,21 @@ await tevroc.agents.Support.addMessage(conversation.data.id, {
201
256
  const messages = await tevroc.agents.Support.listMessages(conversation.data.id);
202
257
  ```
203
258
 
204
- ## Connectors, logs, SSO, and custom integrations
259
+ ## Connectors, logs, custom integrations, and SSO
260
+
261
+ 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.
205
262
 
206
263
  ```js
207
264
  await tevroc.connectors.list();
265
+ await tevroc.connectors.get("slack");
208
266
  await tevroc.connectors.connect("slack", { config: { teamId: "T123" } });
267
+ await tevroc.connectors.disconnect("slack");
209
268
  await tevroc.connectors.status("slack");
210
269
 
270
+ await tevroc.connectors.user.list();
271
+ await tevroc.connectors.user.refresh("abc123");
272
+
273
+ await tevroc.logs.list({ limit: 20 });
211
274
  await tevroc.logs.create({
212
275
  level: "info",
213
276
  message: "User opened dashboard",
@@ -216,19 +279,20 @@ await tevroc.logs.create({
216
279
 
217
280
  await tevroc.customIntegrations.example.echo({ ok: true });
218
281
  await tevroc.sso.accessToken({ code: "provider-code" });
282
+ await tevroc.sso.callback({ code: "provider-code" });
219
283
  ```
220
284
 
221
- ## Raw requests
285
+ ## Make raw requests
222
286
 
223
- Use `request` for worker routes that do not have a convenience wrapper yet.
287
+ 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.
224
288
 
225
289
  ```js
226
290
  const health = await tevroc.request("/health", { auth: false });
227
291
  ```
228
292
 
229
- ## Error handling
293
+ ## Handle errors
230
294
 
231
- API errors throw `TevrocError` with `status`, `code`, and `details`.
295
+ 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.
232
296
 
233
297
  ```js
234
298
  import { TevrocError } from "tevrocsdk";
@@ -237,7 +301,7 @@ try {
237
301
  await tevroc.auth.me();
238
302
  } catch (error) {
239
303
  if (error instanceof TevrocError && error.status === 401) {
240
- // Ask the user to log in.
304
+ // Ask the user to sign in again.
241
305
  }
242
306
  }
243
307
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tevrocsdk",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "JavaScript SDK for the Tevroc API.",
5
5
  "main": "./tevroc-sdk.umd.js",
6
6
  "module": "./tevroc-sdk.esm.js",
@@ -13,7 +13,9 @@
13
13
  "tauri",
14
14
  "capacitor",
15
15
  "YOCO" ,
16
- "google Auth"
16
+ "google Auth",
17
+ "Google Drive",
18
+ "Firebase"
17
19
  ],
18
20
  "license": "MIT"
19
21
  }