@doany-ai/sdk 0.1.0 → 0.2.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/dist/client.d.ts +28 -28
- package/dist/client.js +36 -36
- package/dist/client.types.d.ts +11 -11
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/modules/agents.types.d.ts +12 -12
- package/dist/modules/ai-gateway.types.d.ts +12 -12
- package/dist/modules/analytics.d.ts +1 -1
- package/dist/modules/analytics.js +1 -1
- package/dist/modules/analytics.types.d.ts +4 -4
- package/dist/modules/app-logs.d.ts +1 -1
- package/dist/modules/app-logs.js +1 -1
- package/dist/modules/app-logs.types.d.ts +3 -3
- package/dist/modules/auth.d.ts +1 -1
- package/dist/modules/auth.js +4 -4
- package/dist/modules/auth.types.d.ts +32 -32
- package/dist/modules/connectors.d.ts +1 -1
- package/dist/modules/connectors.js +1 -1
- package/dist/modules/connectors.types.d.ts +18 -18
- package/dist/modules/custom-integrations.d.ts +1 -1
- package/dist/modules/custom-integrations.js +1 -1
- package/dist/modules/custom-integrations.types.d.ts +5 -5
- package/dist/modules/entities.d.ts +1 -1
- package/dist/modules/entities.js +4 -4
- package/dist/modules/entities.types.d.ts +36 -36
- package/dist/modules/functions.d.ts +1 -1
- package/dist/modules/functions.js +1 -1
- package/dist/modules/functions.types.d.ts +8 -8
- package/dist/modules/integrations.d.ts +1 -1
- package/dist/modules/integrations.js +1 -1
- package/dist/modules/integrations.types.d.ts +27 -27
- package/dist/modules/sso.d.ts +1 -1
- package/dist/modules/sso.js +1 -1
- package/dist/modules/sso.types.d.ts +7 -7
- package/dist/modules/users.d.ts +1 -1
- package/dist/modules/users.js +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/utils/auth-utils.d.ts +7 -7
- package/dist/utils/auth-utils.js +10 -10
- package/dist/utils/auth-utils.types.d.ts +7 -7
- package/dist/utils/axios-client.d.ts +10 -10
- package/dist/utils/axios-client.js +14 -14
- package/dist/utils/axios-client.types.d.ts +4 -4
- package/dist/utils/sharedInstance.js +6 -6
- package/dist/utils/socket-utils.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type {
|
|
1
|
+
import type { DoanyClient, CreateClientConfig, CreateClientOptions } from "./client.types.js";
|
|
2
|
+
export type { DoanyClient, CreateClientConfig, CreateClientOptions };
|
|
3
3
|
/**
|
|
4
|
-
* Creates a
|
|
4
|
+
* Creates a Doany client.
|
|
5
5
|
*
|
|
6
|
-
* This is the main entry point for the
|
|
6
|
+
* This is the main entry point for the Doany SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
7
7
|
*
|
|
8
8
|
* How you get a client depends on your context:
|
|
9
|
-
* - **Inside a
|
|
10
|
-
* - **External app using
|
|
9
|
+
* - **Inside a Doany app:** The client is automatically created and configured for you. Import it from `@/api/doanyClient`.
|
|
10
|
+
* - **External app using Doany as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
11
11
|
*
|
|
12
12
|
* The client supports three authentication modes:
|
|
13
|
-
* - **Anonymous**: Access modules without authentication using `
|
|
14
|
-
* - **User authentication**: Access modules with user-level permissions using `
|
|
15
|
-
* - **Service role authentication**: Access modules with elevated permissions using `
|
|
13
|
+
* - **Anonymous**: Access modules without authentication using `doany.moduleName`. Operations are scoped to public data and permissions.
|
|
14
|
+
* - **User authentication**: Access modules with user-level permissions using `doany.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `doany.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
15
|
+
* - **Service role authentication**: Access modules with elevated permissions using `doany.asServiceRole.moduleName`. Operations bypass entity access rules and field-level security, giving full read and write access to all of the app's data. Only available in Doany-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
16
16
|
*
|
|
17
17
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
18
18
|
* - **Anonymous**: Can only read public data.
|
|
@@ -22,50 +22,50 @@ export type { Base44Client, CreateClientConfig, CreateClientOptions };
|
|
|
22
22
|
* Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
|
|
23
23
|
*
|
|
24
24
|
* @param config - Configuration object for the client.
|
|
25
|
-
* @returns A configured
|
|
25
|
+
* @returns A configured Doany client instance with access to all SDK modules.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
28
|
* ```typescript
|
|
29
29
|
* // Create a client for your app
|
|
30
|
-
* import { createClient } from '@
|
|
30
|
+
* import { createClient } from '@doany/sdk';
|
|
31
31
|
*
|
|
32
|
-
* const
|
|
32
|
+
* const doany = createClient({
|
|
33
33
|
* appId: 'my-app-id'
|
|
34
34
|
* });
|
|
35
35
|
*
|
|
36
36
|
* // Use the client to access your data
|
|
37
|
-
* const products = await
|
|
37
|
+
* const products = await doany.entities.Products.list();
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export declare function createClient(config: CreateClientConfig):
|
|
40
|
+
export declare function createClient(config: CreateClientConfig): DoanyClient;
|
|
41
41
|
/**
|
|
42
|
-
* Creates a
|
|
42
|
+
* Creates a Doany client from an HTTP request.
|
|
43
43
|
*
|
|
44
|
-
* This function is designed for use in
|
|
44
|
+
* This function is designed for use in Doany-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
45
45
|
*
|
|
46
|
-
* When used in a
|
|
46
|
+
* When used in a Doany-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Doany injects when forwarding requests. The returned client includes service role access using `doany.asServiceRole`, which bypasses entity access rules and field-level security.
|
|
47
47
|
*
|
|
48
|
-
* To learn more about the
|
|
48
|
+
* To learn more about the Doany client, see {@linkcode createClient | createClient()}.
|
|
49
49
|
*
|
|
50
|
-
* @param request - The incoming HTTP request object containing
|
|
51
|
-
* @returns A configured
|
|
50
|
+
* @param request - The incoming HTTP request object containing Doany authentication headers.
|
|
51
|
+
* @returns A configured Doany client instance with authentication from the incoming request.
|
|
52
52
|
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```typescript
|
|
55
55
|
* // User authentication in backend function
|
|
56
|
-
* import { createClientFromRequest } from 'npm:@
|
|
56
|
+
* import { createClientFromRequest } from 'npm:@doany/sdk';
|
|
57
57
|
*
|
|
58
58
|
* Deno.serve(async (req) => {
|
|
59
59
|
* try {
|
|
60
|
-
* const
|
|
61
|
-
* const user = await
|
|
60
|
+
* const doany = createClientFromRequest(req);
|
|
61
|
+
* const user = await doany.auth.me();
|
|
62
62
|
*
|
|
63
63
|
* if (!user) {
|
|
64
64
|
* return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
65
65
|
* }
|
|
66
66
|
*
|
|
67
67
|
* // Access user's data
|
|
68
|
-
* const userOrders = await
|
|
68
|
+
* const userOrders = await doany.entities.Orders.filter({ userId: user.id });
|
|
69
69
|
* return Response.json({ orders: userOrders });
|
|
70
70
|
* } catch (error) {
|
|
71
71
|
* return Response.json({ error: error.message }, { status: 500 });
|
|
@@ -76,14 +76,14 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
76
76
|
* @example
|
|
77
77
|
* ```typescript
|
|
78
78
|
* // Service role authentication in backend function
|
|
79
|
-
* import { createClientFromRequest } from 'npm:@
|
|
79
|
+
* import { createClientFromRequest } from 'npm:@doany/sdk';
|
|
80
80
|
*
|
|
81
81
|
* Deno.serve(async (req) => {
|
|
82
82
|
* try {
|
|
83
|
-
* const
|
|
83
|
+
* const doany = createClientFromRequest(req);
|
|
84
84
|
*
|
|
85
85
|
* // Read across all users, bypassing the Orders entity's access rules
|
|
86
|
-
* const recentOrders = await
|
|
86
|
+
* const recentOrders = await doany.asServiceRole.entities.Orders.list('-created_at', 50);
|
|
87
87
|
*
|
|
88
88
|
* return Response.json({ orders: recentOrders });
|
|
89
89
|
* } catch (error) {
|
|
@@ -93,4 +93,4 @@ export declare function createClient(config: CreateClientConfig): Base44Client;
|
|
|
93
93
|
* ```
|
|
94
94
|
*
|
|
95
95
|
*/
|
|
96
|
-
export declare function createClientFromRequest(request: Request):
|
|
96
|
+
export declare function createClientFromRequest(request: Request): DoanyClient;
|
package/dist/client.js
CHANGED
|
@@ -13,18 +13,18 @@ import { createUsersModule } from "./modules/users.js";
|
|
|
13
13
|
import { RoomsSocket } from "./utils/socket-utils.js";
|
|
14
14
|
import { createAnalyticsModule } from "./modules/analytics.js";
|
|
15
15
|
/**
|
|
16
|
-
* Creates a
|
|
16
|
+
* Creates a Doany client.
|
|
17
17
|
*
|
|
18
|
-
* This is the main entry point for the
|
|
18
|
+
* This is the main entry point for the Doany SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
|
|
19
19
|
*
|
|
20
20
|
* How you get a client depends on your context:
|
|
21
|
-
* - **Inside a
|
|
22
|
-
* - **External app using
|
|
21
|
+
* - **Inside a Doany app:** The client is automatically created and configured for you. Import it from `@/api/doanyClient`.
|
|
22
|
+
* - **External app using Doany as a backend:** Call `createClient()` directly in your code to create and configure the client.
|
|
23
23
|
*
|
|
24
24
|
* The client supports three authentication modes:
|
|
25
|
-
* - **Anonymous**: Access modules without authentication using `
|
|
26
|
-
* - **User authentication**: Access modules with user-level permissions using `
|
|
27
|
-
* - **Service role authentication**: Access modules with elevated permissions using `
|
|
25
|
+
* - **Anonymous**: Access modules without authentication using `doany.moduleName`. Operations are scoped to public data and permissions.
|
|
26
|
+
* - **User authentication**: Access modules with user-level permissions using `doany.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `doany.auth.loginViaEmailPassword()` or other auth methods to get a token.
|
|
27
|
+
* - **Service role authentication**: Access modules with elevated permissions using `doany.asServiceRole.moduleName`. Operations bypass entity access rules and field-level security, giving full read and write access to all of the app's data. Only available in Doany-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
28
28
|
*
|
|
29
29
|
* For example, when using the {@linkcode EntitiesModule | entities} module:
|
|
30
30
|
* - **Anonymous**: Can only read public data.
|
|
@@ -34,19 +34,19 @@ import { createAnalyticsModule } from "./modules/analytics.js";
|
|
|
34
34
|
* Most modules are available in all three modes, but with different permission levels. However, some modules are only available in specific authentication modes.
|
|
35
35
|
*
|
|
36
36
|
* @param config - Configuration object for the client.
|
|
37
|
-
* @returns A configured
|
|
37
|
+
* @returns A configured Doany client instance with access to all SDK modules.
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```typescript
|
|
41
41
|
* // Create a client for your app
|
|
42
|
-
* import { createClient } from '@
|
|
42
|
+
* import { createClient } from '@doany/sdk';
|
|
43
43
|
*
|
|
44
|
-
* const
|
|
44
|
+
* const doany = createClient({
|
|
45
45
|
* appId: 'my-app-id'
|
|
46
46
|
* });
|
|
47
47
|
*
|
|
48
48
|
* // Use the client to access your data
|
|
49
|
-
* const products = await
|
|
49
|
+
* const products = await doany.entities.Products.list();
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
export function createClient(config) {
|
|
@@ -77,7 +77,7 @@ export function createClient(config) {
|
|
|
77
77
|
const functionHeaders = functionsVersion
|
|
78
78
|
? {
|
|
79
79
|
...headers,
|
|
80
|
-
"
|
|
80
|
+
"Doany-Functions-Version": functionsVersion,
|
|
81
81
|
}
|
|
82
82
|
: headers;
|
|
83
83
|
const axiosClient = createAxiosClient({
|
|
@@ -229,11 +229,11 @@ export function createClient(config) {
|
|
|
229
229
|
* @example
|
|
230
230
|
* ```typescript
|
|
231
231
|
* // Update token after login
|
|
232
|
-
* const { access_token } = await
|
|
232
|
+
* const { access_token } = await doany.auth.loginViaEmailPassword(
|
|
233
233
|
* 'user@example.com',
|
|
234
234
|
* 'password'
|
|
235
235
|
* );
|
|
236
|
-
*
|
|
236
|
+
* doany.setToken(access_token);
|
|
237
237
|
* ```
|
|
238
238
|
*/
|
|
239
239
|
setToken(newToken) {
|
|
@@ -266,13 +266,13 @@ export function createClient(config) {
|
|
|
266
266
|
*
|
|
267
267
|
* @example
|
|
268
268
|
* ```typescript
|
|
269
|
-
* const
|
|
269
|
+
* const doany = createClient({
|
|
270
270
|
* appId: 'my-app-id',
|
|
271
271
|
* serviceToken: 'service-role-token'
|
|
272
272
|
* });
|
|
273
273
|
*
|
|
274
274
|
* // Read every user record, bypassing the User entity's access rules
|
|
275
|
-
* const allUsers = await
|
|
275
|
+
* const allUsers = await doany.asServiceRole.entities.User.list();
|
|
276
276
|
* ```
|
|
277
277
|
*/
|
|
278
278
|
get asServiceRole() {
|
|
@@ -285,33 +285,33 @@ export function createClient(config) {
|
|
|
285
285
|
return client;
|
|
286
286
|
}
|
|
287
287
|
/**
|
|
288
|
-
* Creates a
|
|
288
|
+
* Creates a Doany client from an HTTP request.
|
|
289
289
|
*
|
|
290
|
-
* This function is designed for use in
|
|
290
|
+
* This function is designed for use in Doany-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
|
|
291
291
|
*
|
|
292
|
-
* When used in a
|
|
292
|
+
* When used in a Doany-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Doany injects when forwarding requests. The returned client includes service role access using `doany.asServiceRole`, which bypasses entity access rules and field-level security.
|
|
293
293
|
*
|
|
294
|
-
* To learn more about the
|
|
294
|
+
* To learn more about the Doany client, see {@linkcode createClient | createClient()}.
|
|
295
295
|
*
|
|
296
|
-
* @param request - The incoming HTTP request object containing
|
|
297
|
-
* @returns A configured
|
|
296
|
+
* @param request - The incoming HTTP request object containing Doany authentication headers.
|
|
297
|
+
* @returns A configured Doany client instance with authentication from the incoming request.
|
|
298
298
|
*
|
|
299
299
|
* @example
|
|
300
300
|
* ```typescript
|
|
301
301
|
* // User authentication in backend function
|
|
302
|
-
* import { createClientFromRequest } from 'npm:@
|
|
302
|
+
* import { createClientFromRequest } from 'npm:@doany/sdk';
|
|
303
303
|
*
|
|
304
304
|
* Deno.serve(async (req) => {
|
|
305
305
|
* try {
|
|
306
|
-
* const
|
|
307
|
-
* const user = await
|
|
306
|
+
* const doany = createClientFromRequest(req);
|
|
307
|
+
* const user = await doany.auth.me();
|
|
308
308
|
*
|
|
309
309
|
* if (!user) {
|
|
310
310
|
* return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
311
311
|
* }
|
|
312
312
|
*
|
|
313
313
|
* // Access user's data
|
|
314
|
-
* const userOrders = await
|
|
314
|
+
* const userOrders = await doany.entities.Orders.filter({ userId: user.id });
|
|
315
315
|
* return Response.json({ orders: userOrders });
|
|
316
316
|
* } catch (error) {
|
|
317
317
|
* return Response.json({ error: error.message }, { status: 500 });
|
|
@@ -322,14 +322,14 @@ export function createClient(config) {
|
|
|
322
322
|
* @example
|
|
323
323
|
* ```typescript
|
|
324
324
|
* // Service role authentication in backend function
|
|
325
|
-
* import { createClientFromRequest } from 'npm:@
|
|
325
|
+
* import { createClientFromRequest } from 'npm:@doany/sdk';
|
|
326
326
|
*
|
|
327
327
|
* Deno.serve(async (req) => {
|
|
328
328
|
* try {
|
|
329
|
-
* const
|
|
329
|
+
* const doany = createClientFromRequest(req);
|
|
330
330
|
*
|
|
331
331
|
* // Read across all users, bypassing the Orders entity's access rules
|
|
332
|
-
* const recentOrders = await
|
|
332
|
+
* const recentOrders = await doany.asServiceRole.entities.Orders.list('-created_at', 50);
|
|
333
333
|
*
|
|
334
334
|
* return Response.json({ orders: recentOrders });
|
|
335
335
|
* } catch (error) {
|
|
@@ -341,14 +341,14 @@ export function createClient(config) {
|
|
|
341
341
|
*/
|
|
342
342
|
export function createClientFromRequest(request) {
|
|
343
343
|
const authHeader = request.headers.get("Authorization");
|
|
344
|
-
const serviceRoleAuthHeader = request.headers.get("
|
|
345
|
-
const appId = request.headers.get("
|
|
346
|
-
const serverUrlHeader = request.headers.get("
|
|
347
|
-
const functionsVersion = request.headers.get("
|
|
348
|
-
const stateHeader = request.headers.get("
|
|
344
|
+
const serviceRoleAuthHeader = request.headers.get("Doany-Service-Authorization");
|
|
345
|
+
const appId = request.headers.get("Doany-App-Id");
|
|
346
|
+
const serverUrlHeader = request.headers.get("Doany-Api-Url");
|
|
347
|
+
const functionsVersion = request.headers.get("Doany-Functions-Version");
|
|
348
|
+
const stateHeader = request.headers.get("Doany-State");
|
|
349
349
|
const dataEnvHeader = request.headers.get("X-Data-Env");
|
|
350
350
|
if (!appId) {
|
|
351
|
-
throw new Error("
|
|
351
|
+
throw new Error("Doany-App-Id header is required, but is was not found on the request");
|
|
352
352
|
}
|
|
353
353
|
// Validate authorization header formats
|
|
354
354
|
let serviceRoleToken;
|
|
@@ -372,7 +372,7 @@ export function createClientFromRequest(request) {
|
|
|
372
372
|
// Prepare additional headers to propagate
|
|
373
373
|
const additionalHeaders = {};
|
|
374
374
|
if (stateHeader) {
|
|
375
|
-
additionalHeaders["
|
|
375
|
+
additionalHeaders["Doany-State"] = stateHeader;
|
|
376
376
|
}
|
|
377
377
|
// Propagate the data environment so entity operations from the function stay
|
|
378
378
|
// in the same environment (e.g. test data) as the triggering request. This
|
package/dist/client.types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { AiGatewayModule } from "./modules/ai-gateway.types.js";
|
|
|
9
9
|
import type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
10
10
|
import type { AnalyticsModule } from "./modules/analytics.types.js";
|
|
11
11
|
/**
|
|
12
|
-
* Options for creating a
|
|
12
|
+
* Options for creating a Doany client.
|
|
13
13
|
*/
|
|
14
14
|
export interface CreateClientOptions {
|
|
15
15
|
/**
|
|
@@ -18,17 +18,17 @@ export interface CreateClientOptions {
|
|
|
18
18
|
onError?: (error: Error) => void;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Configuration for creating a
|
|
21
|
+
* Configuration for creating a Doany client.
|
|
22
22
|
*/
|
|
23
23
|
export interface CreateClientConfig {
|
|
24
24
|
/**
|
|
25
|
-
* The
|
|
25
|
+
* The Doany server URL.
|
|
26
26
|
*
|
|
27
|
-
* You don't need to set this for production use. The SDK defaults to `https://
|
|
27
|
+
* You don't need to set this for production use. The SDK defaults to `https://api.doany.ai`.
|
|
28
28
|
*
|
|
29
29
|
* Set this when using a local development server to point SDK requests at your local machine instead of the hosted backend.
|
|
30
30
|
*
|
|
31
|
-
* @defaultValue `"https://
|
|
31
|
+
* @defaultValue `"https://api.doany.ai"`
|
|
32
32
|
*/
|
|
33
33
|
serverUrl?: string;
|
|
34
34
|
/**
|
|
@@ -37,7 +37,7 @@ export interface CreateClientConfig {
|
|
|
37
37
|
*/
|
|
38
38
|
appBaseUrl?: string;
|
|
39
39
|
/**
|
|
40
|
-
* The
|
|
40
|
+
* The Doany app ID.
|
|
41
41
|
*
|
|
42
42
|
* You can find the `appId` in the browser URL when you're in the app editor.
|
|
43
43
|
* It's the string between `/apps/` and `/editor/`.
|
|
@@ -46,11 +46,11 @@ export interface CreateClientConfig {
|
|
|
46
46
|
/**
|
|
47
47
|
* User authentication token. Used to authenticate as a specific user.
|
|
48
48
|
*
|
|
49
|
-
* Inside
|
|
49
|
+
* Inside Doany apps, the token is managed automatically. For external apps, use auth methods like {@linkcode AuthModule.loginViaEmailPassword | loginViaEmailPassword()} which set the token automatically.
|
|
50
50
|
*/
|
|
51
51
|
token?: string;
|
|
52
52
|
/**
|
|
53
|
-
* Service role authentication token. Provides elevated permissions that bypass entity access rules and field-level security. Only available in
|
|
53
|
+
* Service role authentication token. Provides elevated permissions that bypass entity access rules and field-level security. Only available in Doany-hosted backend functions. Automatically added to clients created using {@linkcode createClientFromRequest | createClientFromRequest()}.
|
|
54
54
|
* @internal
|
|
55
55
|
*/
|
|
56
56
|
serviceToken?: string;
|
|
@@ -75,14 +75,14 @@ export interface CreateClientConfig {
|
|
|
75
75
|
options?: CreateClientOptions;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* The
|
|
78
|
+
* The Doany client instance.
|
|
79
79
|
*
|
|
80
80
|
* Provides access to all SDK modules for interacting with the app.
|
|
81
81
|
*/
|
|
82
|
-
export interface
|
|
82
|
+
export interface DoanyClient {
|
|
83
83
|
/** {@link AgentsModule | Agents module} for managing AI agent conversations. */
|
|
84
84
|
agents: AgentsModule;
|
|
85
|
-
/** {@link AiGatewayModule | AI Gateway module} for connecting to the
|
|
85
|
+
/** {@link AiGatewayModule | AI Gateway module} for connecting to the Doany AI Gateway with your own SDK. */
|
|
86
86
|
aiGateway: AiGatewayModule;
|
|
87
87
|
/** {@link AnalyticsModule | Analytics module} for tracking custom events in your app. */
|
|
88
88
|
analytics: AnalyticsModule;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createClient, createClientFromRequest, type
|
|
2
|
-
import {
|
|
1
|
+
import { createClient, createClientFromRequest, type DoanyClient, type CreateClientConfig, type CreateClientOptions } from "./client.js";
|
|
2
|
+
import { DoanyError, type DoanyErrorJSON } from "./utils/axios-client.js";
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from "./utils/auth-utils.js";
|
|
4
|
-
export { createClient, createClientFromRequest,
|
|
5
|
-
export type {
|
|
4
|
+
export { createClient, createClientFromRequest, DoanyError, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
|
+
export type { DoanyClient, CreateClientConfig, CreateClientOptions, DoanyErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
7
|
export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityFilterOperators, EntityFilterQuery, EntityFilterValue, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient, createClientFromRequest, } from "./client.js";
|
|
2
|
-
import {
|
|
2
|
+
import { DoanyError } from "./utils/axios-client.js";
|
|
3
3
|
import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, } from "./utils/auth-utils.js";
|
|
4
|
-
export { createClient, createClientFromRequest,
|
|
4
|
+
export { createClient, createClientFromRequest, DoanyError, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export * from "./types.js";
|
|
@@ -13,7 +13,7 @@ export interface AgentNameRegistry {
|
|
|
13
13
|
* ```typescript
|
|
14
14
|
* // Using generated agent name types
|
|
15
15
|
* // With generated types, you get autocomplete on agent names
|
|
16
|
-
* const conversation = await
|
|
16
|
+
* const conversation = await doany.agents.createConversation({ agent_name: 'SupportBot' });
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export type AgentName = keyof AgentNameRegistry extends never ? string : keyof AgentNameRegistry;
|
|
@@ -193,8 +193,8 @@ export interface AgentsModuleConfig {
|
|
|
193
193
|
*
|
|
194
194
|
* This module is available to use with a client in all authentication modes:
|
|
195
195
|
*
|
|
196
|
-
* - **Anonymous or User authentication** (`
|
|
197
|
-
* - **Service role authentication** (`
|
|
196
|
+
* - **Anonymous or User authentication** (`doany.agents`): Access is scoped to the current user's permissions. Users must be authenticated to create and access conversations.
|
|
197
|
+
* - **Service role authentication** (`doany.asServiceRole.agents`): Operations are invoked with the service role for backend code that needs elevated permissions.
|
|
198
198
|
*
|
|
199
199
|
* ## Generated Types
|
|
200
200
|
*
|
|
@@ -211,7 +211,7 @@ export interface AgentsModule {
|
|
|
211
211
|
* @example
|
|
212
212
|
* ```typescript
|
|
213
213
|
* // Get all conversations
|
|
214
|
-
* const conversations = await
|
|
214
|
+
* const conversations = await doany.agents.getConversations();
|
|
215
215
|
* console.log(`Total conversations: ${conversations.length}`);
|
|
216
216
|
* ```
|
|
217
217
|
*
|
|
@@ -233,7 +233,7 @@ export interface AgentsModule {
|
|
|
233
233
|
* @example
|
|
234
234
|
* ```typescript
|
|
235
235
|
* // Get a specific conversation by ID
|
|
236
|
-
* const conversation = await
|
|
236
|
+
* const conversation = await doany.agents.getConversation('conv-123');
|
|
237
237
|
* if (conversation) {
|
|
238
238
|
* console.log(`Conversation has ${conversation.messages.length} messages`);
|
|
239
239
|
* }
|
|
@@ -254,7 +254,7 @@ export interface AgentsModule {
|
|
|
254
254
|
* @example
|
|
255
255
|
* ```typescript
|
|
256
256
|
* // List recent conversations with pagination
|
|
257
|
-
* const recentConversations = await
|
|
257
|
+
* const recentConversations = await doany.agents.listConversations({
|
|
258
258
|
* limit: 10,
|
|
259
259
|
* sort: '-created_date'
|
|
260
260
|
* });
|
|
@@ -263,7 +263,7 @@ export interface AgentsModule {
|
|
|
263
263
|
* @example
|
|
264
264
|
* ```typescript
|
|
265
265
|
* // Filter by agent and metadata
|
|
266
|
-
* const supportConversations = await
|
|
266
|
+
* const supportConversations = await doany.agents.listConversations({
|
|
267
267
|
* q: {
|
|
268
268
|
* agent_name: 'support-agent',
|
|
269
269
|
* 'metadata.priority': 'high'
|
|
@@ -286,7 +286,7 @@ export interface AgentsModule {
|
|
|
286
286
|
* @example
|
|
287
287
|
* ```typescript
|
|
288
288
|
* // Create a new conversation with metadata
|
|
289
|
-
* const conversation = await
|
|
289
|
+
* const conversation = await doany.agents.createConversation({
|
|
290
290
|
* agent_name: 'support-agent',
|
|
291
291
|
* metadata: {
|
|
292
292
|
* order_id: 'ORD-789',
|
|
@@ -311,7 +311,7 @@ export interface AgentsModule {
|
|
|
311
311
|
* @example
|
|
312
312
|
* ```typescript
|
|
313
313
|
* // Send a message to the agent
|
|
314
|
-
* const message = await
|
|
314
|
+
* const message = await doany.agents.addMessage(conversation, {
|
|
315
315
|
* role: 'user',
|
|
316
316
|
* content: 'Hello, I need help with my order #12345'
|
|
317
317
|
* });
|
|
@@ -343,7 +343,7 @@ export interface AgentsModule {
|
|
|
343
343
|
* @example
|
|
344
344
|
* ```typescript
|
|
345
345
|
* // Subscribe to realtime updates
|
|
346
|
-
* const unsubscribe =
|
|
346
|
+
* const unsubscribe = doany.agents.subscribeToConversation(
|
|
347
347
|
* 'conv-123',
|
|
348
348
|
* (updatedConversation) => {
|
|
349
349
|
* const latestMessage = updatedConversation.messages[updatedConversation.messages.length - 1];
|
|
@@ -368,7 +368,7 @@ export interface AgentsModule {
|
|
|
368
368
|
* @example
|
|
369
369
|
* ```typescript
|
|
370
370
|
* // Get WhatsApp connection URL
|
|
371
|
-
* const whatsappUrl =
|
|
371
|
+
* const whatsappUrl = doany.agents.getWhatsAppConnectURL('support-agent');
|
|
372
372
|
* console.log(`Connect through WhatsApp: ${whatsappUrl}`);
|
|
373
373
|
* // User can open this URL to start a WhatsApp conversation
|
|
374
374
|
* ```
|
|
@@ -388,7 +388,7 @@ export interface AgentsModule {
|
|
|
388
388
|
* @example
|
|
389
389
|
* ```typescript
|
|
390
390
|
* // Get Telegram connection URL
|
|
391
|
-
* const telegramUrl =
|
|
391
|
+
* const telegramUrl = doany.agents.getTelegramConnectURL('support-agent');
|
|
392
392
|
* console.log(`Connect through Telegram: ${telegramUrl}`);
|
|
393
393
|
* // User can open this URL to start a Telegram conversation
|
|
394
394
|
* ```
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A connection to the
|
|
2
|
+
* A connection to the Doany AI Gateway.
|
|
3
3
|
*
|
|
4
4
|
* Contains the base URL and bearer token to use with any OpenAI-compatible
|
|
5
|
-
* client pointed at the
|
|
5
|
+
* client pointed at the Doany AI Gateway.
|
|
6
6
|
*/
|
|
7
7
|
export interface AiGatewayConnection {
|
|
8
8
|
/** Base URL of the gateway's OpenAI-compatible endpoint. */
|
|
@@ -23,24 +23,24 @@ export interface AiGatewayModuleConfig {
|
|
|
23
23
|
appId: string;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* AI Gateway module for calling
|
|
26
|
+
* AI Gateway module for calling Doany's managed AI models from your own code.
|
|
27
27
|
*
|
|
28
28
|
* The gateway exposes an OpenAI-compatible Chat Completions endpoint, so any
|
|
29
29
|
* OpenAI-compatible SDK works against it:
|
|
30
30
|
* - Build custom AI agents or call models directly from your backend code
|
|
31
31
|
* - Uses your app's models, billing, and credit quota, no API key to manage
|
|
32
32
|
*
|
|
33
|
-
* Available in user authentication mode (`
|
|
34
|
-
* service-role token via `
|
|
33
|
+
* Available in user authentication mode (`doany.aiGateway`) and with the
|
|
34
|
+
* service-role token via `doany.asServiceRole.aiGateway`.
|
|
35
35
|
*/
|
|
36
36
|
export interface AiGatewayModule {
|
|
37
37
|
/**
|
|
38
|
-
* Gets the connection details for the
|
|
38
|
+
* Gets the connection details for the Doany AI Gateway.
|
|
39
39
|
*
|
|
40
40
|
* Returns the `baseURL` and `token` to pass to any OpenAI-compatible client.
|
|
41
41
|
*
|
|
42
42
|
* The `token` is the current caller's bearer token: the app user's token for
|
|
43
|
-
* `
|
|
43
|
+
* `doany.aiGateway`, or the service-role token for `doany.asServiceRole.aiGateway`.
|
|
44
44
|
* When the caller is unauthenticated, `token` is an empty string.
|
|
45
45
|
*
|
|
46
46
|
* @returns The gateway {@linkcode AiGatewayConnection | connection} (`baseURL` and `token`).
|
|
@@ -51,10 +51,10 @@ export interface AiGatewayModule {
|
|
|
51
51
|
* import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
52
52
|
* import { z } from "zod";
|
|
53
53
|
*
|
|
54
|
-
* const request = await
|
|
55
|
-
* const { baseURL, token } =
|
|
54
|
+
* const request = await doany.entities.ReturnRequest.get(returnId);
|
|
55
|
+
* const { baseURL, token } = doany.aiGateway.connection();
|
|
56
56
|
* // Point any OpenAI-compatible client at `baseURL` with `apiKey: token`.
|
|
57
|
-
* const models = createOpenAICompatible({ name: "
|
|
57
|
+
* const models = createOpenAICompatible({ name: "doany", baseURL, apiKey: token });
|
|
58
58
|
*
|
|
59
59
|
* const agent = new ToolLoopAgent({
|
|
60
60
|
* model: models("automatic"),
|
|
@@ -68,14 +68,14 @@ export interface AiGatewayModule {
|
|
|
68
68
|
* execute: ({ status }) => {
|
|
69
69
|
* const query = { customer_email: request.customer_email };
|
|
70
70
|
* if (status) query.status = status;
|
|
71
|
-
* return
|
|
71
|
+
* return doany.entities.Order.filter(query, "-created_date", 50);
|
|
72
72
|
* },
|
|
73
73
|
* }),
|
|
74
74
|
* submitVerdict: tool({
|
|
75
75
|
* description: "Record the final verdict",
|
|
76
76
|
* inputSchema: z.object({ decision: z.enum(["approved", "flagged"]), reason: z.string() }),
|
|
77
77
|
* execute: ({ decision, reason }) =>
|
|
78
|
-
*
|
|
78
|
+
* doany.entities.ReturnRequest.update(returnId, { status: decision, review_note: reason }),
|
|
79
79
|
* }),
|
|
80
80
|
* },
|
|
81
81
|
* stopWhen: [stepCountIs(8), hasToolCall("submitVerdict")],
|
|
@@ -5,7 +5,7 @@ export declare const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
|
5
5
|
export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
6
6
|
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
7
7
|
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
8
|
-
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "
|
|
8
|
+
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "doany_analytics_session_id";
|
|
9
9
|
export interface AnalyticsModuleArgs {
|
|
10
10
|
axiosClient: AxiosInstance;
|
|
11
11
|
serverUrl: string;
|
|
@@ -4,7 +4,7 @@ export const USER_HEARTBEAT_EVENT_NAME = "__user_heartbeat_event__";
|
|
|
4
4
|
export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
5
5
|
export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
6
6
|
export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
7
|
-
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "
|
|
7
|
+
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "doany_analytics_session_id";
|
|
8
8
|
const defaultConfiguration = {
|
|
9
9
|
// default to enabled //
|
|
10
10
|
enabled: true,
|
|
@@ -23,7 +23,7 @@ export type TrackEventParams = {
|
|
|
23
23
|
*
|
|
24
24
|
* @example
|
|
25
25
|
* ```typescript
|
|
26
|
-
*
|
|
26
|
+
* doany.analytics.track({
|
|
27
27
|
* eventName: 'add_to_cart',
|
|
28
28
|
* properties: {
|
|
29
29
|
* product_id: 'prod_123',
|
|
@@ -83,7 +83,7 @@ export type AnalyticsModuleOptions = {
|
|
|
83
83
|
*
|
|
84
84
|
* ## Authentication Modes
|
|
85
85
|
*
|
|
86
|
-
* This module is only available in user authentication mode (`
|
|
86
|
+
* This module is only available in user authentication mode (`doany.analytics`).
|
|
87
87
|
*/
|
|
88
88
|
export interface AnalyticsModule {
|
|
89
89
|
/**
|
|
@@ -98,7 +98,7 @@ export interface AnalyticsModule {
|
|
|
98
98
|
* @example Track a button click
|
|
99
99
|
* ```typescript
|
|
100
100
|
* // Track a button click
|
|
101
|
-
*
|
|
101
|
+
* doany.analytics.track({
|
|
102
102
|
* eventName: 'signup_button_click'
|
|
103
103
|
* });
|
|
104
104
|
* ```
|
|
@@ -106,7 +106,7 @@ export interface AnalyticsModule {
|
|
|
106
106
|
* @example Track with properties
|
|
107
107
|
* ```typescript
|
|
108
108
|
* // Track with properties
|
|
109
|
-
*
|
|
109
|
+
* doany.analytics.track({
|
|
110
110
|
* eventName: 'add_to_cart',
|
|
111
111
|
* properties: {
|
|
112
112
|
* product_id: 'prod_123',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { AppLogsModule } from "./app-logs.types";
|
|
3
3
|
/**
|
|
4
|
-
* Creates the app logs module for the
|
|
4
|
+
* Creates the app logs module for the Doany SDK.
|
|
5
5
|
*
|
|
6
6
|
* @param axios - Axios instance
|
|
7
7
|
* @param appId - Application ID
|
package/dist/modules/app-logs.js
CHANGED