@doany-ai/sdk 0.1.0 → 0.2.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/dist/client.d.ts +28 -28
- package/dist/client.js +45 -37
- 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/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export * from "./modules/types.js";
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* // Filter conversations by agent name
|
|
17
|
-
* const conversations = await
|
|
17
|
+
* const conversations = await doany.agents.listConversations({
|
|
18
18
|
* q: { agent_name: 'support-bot' }
|
|
19
19
|
* });
|
|
20
20
|
* ```
|
|
@@ -22,7 +22,7 @@ export * from "./modules/types.js";
|
|
|
22
22
|
* @example
|
|
23
23
|
* ```typescript
|
|
24
24
|
* // Filter conversations with sorting
|
|
25
|
-
* const conversations = await
|
|
25
|
+
* const conversations = await doany.agents.listConversations({
|
|
26
26
|
* q: { status: 'active' },
|
|
27
27
|
* sort: '-created_at' // Sort by created_at descending
|
|
28
28
|
* });
|
|
@@ -31,7 +31,7 @@ export * from "./modules/types.js";
|
|
|
31
31
|
* @example
|
|
32
32
|
* ```typescript
|
|
33
33
|
* // Filter conversations with pagination
|
|
34
|
-
* const conversations = await
|
|
34
|
+
* const conversations = await doany.agents.listConversations({
|
|
35
35
|
* q: { agent_name: 'support-bot' },
|
|
36
36
|
* limit: 20, // Get 20 results
|
|
37
37
|
* skip: 40 // Skip first 40 (page 3)
|
|
@@ -41,7 +41,7 @@ export * from "./modules/types.js";
|
|
|
41
41
|
* @example
|
|
42
42
|
* ```typescript
|
|
43
43
|
* // Filter conversations with field selection
|
|
44
|
-
* const conversations = await
|
|
44
|
+
* const conversations = await doany.agents.listConversations({
|
|
45
45
|
* q: { status: 'active' },
|
|
46
46
|
* fields: ['id', 'agent_name', 'created_at']
|
|
47
47
|
* });
|
|
@@ -50,7 +50,7 @@ export * from "./modules/types.js";
|
|
|
50
50
|
* @example
|
|
51
51
|
* ```typescript
|
|
52
52
|
* // Filter conversations with multiple filters
|
|
53
|
-
* const conversations = await
|
|
53
|
+
* const conversations = await doany.agents.listConversations({
|
|
54
54
|
* q: {
|
|
55
55
|
* agent_name: 'support-bot',
|
|
56
56
|
* 'metadata.priority': 'high',
|
|
@@ -2,7 +2,7 @@ import { GetAccessTokenOptions, SaveAccessTokenOptions, RemoveAccessTokenOptions
|
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves an access token from URL parameters or local storage.
|
|
4
4
|
*
|
|
5
|
-
* Low-level utility for manually retrieving tokens. In most cases, the
|
|
5
|
+
* Low-level utility for manually retrieving tokens. In most cases, the Doany client handles
|
|
6
6
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
7
7
|
*
|
|
8
8
|
* @internal
|
|
@@ -39,7 +39,7 @@ export declare function getAccessToken(options?: GetAccessTokenOptions): string
|
|
|
39
39
|
/**
|
|
40
40
|
* Saves an access token to local storage.
|
|
41
41
|
*
|
|
42
|
-
* Low-level utility for manually saving tokens. In most cases, the
|
|
42
|
+
* Low-level utility for manually saving tokens. In most cases, the Doany client handles token management automatically. This function is useful for custom authentication flows or managing custom tokens. Requires a browser environment and can't be used in the backend.
|
|
43
43
|
*
|
|
44
44
|
* @internal
|
|
45
45
|
*
|
|
@@ -50,7 +50,7 @@ export declare function getAccessToken(options?: GetAccessTokenOptions): string
|
|
|
50
50
|
* @example
|
|
51
51
|
* ```typescript
|
|
52
52
|
* // Save access token after login
|
|
53
|
-
* const response = await
|
|
53
|
+
* const response = await doany.auth.loginViaEmailPassword(email, password);
|
|
54
54
|
* const success = saveAccessToken(response.access_token, {});
|
|
55
55
|
*
|
|
56
56
|
* if (success) {
|
|
@@ -70,7 +70,7 @@ export declare function saveAccessToken(token: string, options: SaveAccessTokenO
|
|
|
70
70
|
/**
|
|
71
71
|
* Removes the access token from local storage.
|
|
72
72
|
*
|
|
73
|
-
* Low-level utility for manually removing tokens from the browser's local storage. In most cases, the
|
|
73
|
+
* Low-level utility for manually removing tokens from the browser's local storage. In most cases, the Doany client handles token management automatically. For standard logout flows, use {@linkcode AuthModule.logout | doany.auth.logout()} instead, which handles token removal and redirects automatically. This function is useful for custom authentication flows or when you need to manually remove tokens. Requires a browser environment and can't be used in the backend.
|
|
74
74
|
*
|
|
75
75
|
* @internal
|
|
76
76
|
*
|
|
@@ -88,14 +88,14 @@ export declare function saveAccessToken(token: string, options: SaveAccessTokenO
|
|
|
88
88
|
* @example
|
|
89
89
|
* ```typescript
|
|
90
90
|
* // Standard logout flow with token removal and redirect
|
|
91
|
-
*
|
|
91
|
+
* doany.auth.logout('/login');
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
94
|
export declare function removeAccessToken(options: RemoveAccessTokenOptions): boolean;
|
|
95
95
|
/**
|
|
96
96
|
* Constructs the absolute URL for the login page with a redirect parameter.
|
|
97
97
|
*
|
|
98
|
-
* Low-level utility for building login URLs. For standard login redirects, use {@linkcode AuthModule.redirectToLogin |
|
|
98
|
+
* Low-level utility for building login URLs. For standard login redirects, use {@linkcode AuthModule.redirectToLogin | doany.auth.redirectToLogin()} instead, which handles this automatically. This function is useful when you need to construct login URLs without a client instance or for custom authentication flows.
|
|
99
99
|
*
|
|
100
100
|
* @internal
|
|
101
101
|
*
|
|
@@ -107,7 +107,7 @@ export declare function removeAccessToken(options: RemoveAccessTokenOptions): bo
|
|
|
107
107
|
* ```typescript
|
|
108
108
|
* // Redirect to login page
|
|
109
109
|
* const loginUrl = getLoginUrl('/dashboard', {
|
|
110
|
-
* serverUrl: 'https://
|
|
110
|
+
* serverUrl: 'https://api.doany.ai',
|
|
111
111
|
* appId: 'my-app-123'
|
|
112
112
|
* });
|
|
113
113
|
* window.location.href = loginUrl;
|
package/dist/utils/auth-utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Retrieves an access token from URL parameters or local storage.
|
|
3
3
|
*
|
|
4
|
-
* Low-level utility for manually retrieving tokens. In most cases, the
|
|
4
|
+
* Low-level utility for manually retrieving tokens. In most cases, the Doany client handles
|
|
5
5
|
* token management automatically. This function is useful for custom authentication flows or when you need direct access to stored tokens. Requires a browser environment and can't be used in the backend.
|
|
6
6
|
*
|
|
7
7
|
* @internal
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export function getAccessToken(options = {}) {
|
|
38
|
-
const { storageKey = "
|
|
38
|
+
const { storageKey = "doany_access_token", paramName = "access_token", saveToStorage = true, removeFromUrl = true, } = options;
|
|
39
39
|
let token = null;
|
|
40
40
|
// Try to get token from URL parameters
|
|
41
41
|
if (typeof window !== "undefined" && window.location) {
|
|
@@ -76,7 +76,7 @@ export function getAccessToken(options = {}) {
|
|
|
76
76
|
/**
|
|
77
77
|
* Saves an access token to local storage.
|
|
78
78
|
*
|
|
79
|
-
* Low-level utility for manually saving tokens. In most cases, the
|
|
79
|
+
* Low-level utility for manually saving tokens. In most cases, the Doany client handles token management automatically. This function is useful for custom authentication flows or managing custom tokens. Requires a browser environment and can't be used in the backend.
|
|
80
80
|
*
|
|
81
81
|
* @internal
|
|
82
82
|
*
|
|
@@ -87,7 +87,7 @@ export function getAccessToken(options = {}) {
|
|
|
87
87
|
* @example
|
|
88
88
|
* ```typescript
|
|
89
89
|
* // Save access token after login
|
|
90
|
-
* const response = await
|
|
90
|
+
* const response = await doany.auth.loginViaEmailPassword(email, password);
|
|
91
91
|
* const success = saveAccessToken(response.access_token, {});
|
|
92
92
|
*
|
|
93
93
|
* if (success) {
|
|
@@ -104,7 +104,7 @@ export function getAccessToken(options = {}) {
|
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
106
|
export function saveAccessToken(token, options) {
|
|
107
|
-
const { storageKey = "
|
|
107
|
+
const { storageKey = "doany_access_token" } = options;
|
|
108
108
|
if (typeof window === "undefined" || !window.localStorage || !token) {
|
|
109
109
|
return false;
|
|
110
110
|
}
|
|
@@ -122,7 +122,7 @@ export function saveAccessToken(token, options) {
|
|
|
122
122
|
/**
|
|
123
123
|
* Removes the access token from local storage.
|
|
124
124
|
*
|
|
125
|
-
* Low-level utility for manually removing tokens from the browser's local storage. In most cases, the
|
|
125
|
+
* Low-level utility for manually removing tokens from the browser's local storage. In most cases, the Doany client handles token management automatically. For standard logout flows, use {@linkcode AuthModule.logout | doany.auth.logout()} instead, which handles token removal and redirects automatically. This function is useful for custom authentication flows or when you need to manually remove tokens. Requires a browser environment and can't be used in the backend.
|
|
126
126
|
*
|
|
127
127
|
* @internal
|
|
128
128
|
*
|
|
@@ -140,11 +140,11 @@ export function saveAccessToken(token, options) {
|
|
|
140
140
|
* @example
|
|
141
141
|
* ```typescript
|
|
142
142
|
* // Standard logout flow with token removal and redirect
|
|
143
|
-
*
|
|
143
|
+
* doany.auth.logout('/login');
|
|
144
144
|
* ```
|
|
145
145
|
*/
|
|
146
146
|
export function removeAccessToken(options) {
|
|
147
|
-
const { storageKey = "
|
|
147
|
+
const { storageKey = "doany_access_token" } = options;
|
|
148
148
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
@@ -160,7 +160,7 @@ export function removeAccessToken(options) {
|
|
|
160
160
|
/**
|
|
161
161
|
* Constructs the absolute URL for the login page with a redirect parameter.
|
|
162
162
|
*
|
|
163
|
-
* Low-level utility for building login URLs. For standard login redirects, use {@linkcode AuthModule.redirectToLogin |
|
|
163
|
+
* Low-level utility for building login URLs. For standard login redirects, use {@linkcode AuthModule.redirectToLogin | doany.auth.redirectToLogin()} instead, which handles this automatically. This function is useful when you need to construct login URLs without a client instance or for custom authentication flows.
|
|
164
164
|
*
|
|
165
165
|
* @internal
|
|
166
166
|
*
|
|
@@ -172,7 +172,7 @@ export function removeAccessToken(options) {
|
|
|
172
172
|
* ```typescript
|
|
173
173
|
* // Redirect to login page
|
|
174
174
|
* const loginUrl = getLoginUrl('/dashboard', {
|
|
175
|
-
* serverUrl: 'https://
|
|
175
|
+
* serverUrl: 'https://api.doany.ai',
|
|
176
176
|
* appId: 'my-app-123'
|
|
177
177
|
* });
|
|
178
178
|
* window.location.href = loginUrl;
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
export interface GetAccessTokenOptions {
|
|
28
28
|
/**
|
|
29
29
|
* The key to use when storing or retrieving the token in local storage.
|
|
30
|
-
* @default '
|
|
30
|
+
* @default 'doany_access_token'
|
|
31
31
|
*/
|
|
32
32
|
storageKey?: string;
|
|
33
33
|
/**
|
|
@@ -63,7 +63,7 @@ export interface GetAccessTokenOptions {
|
|
|
63
63
|
export interface SaveAccessTokenOptions {
|
|
64
64
|
/**
|
|
65
65
|
* The key to use when storing the token in local storage.
|
|
66
|
-
* @default '
|
|
66
|
+
* @default 'doany_access_token'
|
|
67
67
|
*/
|
|
68
68
|
storageKey?: string;
|
|
69
69
|
}
|
|
@@ -84,7 +84,7 @@ export interface SaveAccessTokenOptions {
|
|
|
84
84
|
export interface RemoveAccessTokenOptions {
|
|
85
85
|
/**
|
|
86
86
|
* The key to use when removing the token from local storage.
|
|
87
|
-
* @default '
|
|
87
|
+
* @default 'doany_access_token'
|
|
88
88
|
*/
|
|
89
89
|
storageKey?: string;
|
|
90
90
|
}
|
|
@@ -96,14 +96,14 @@ export interface RemoveAccessTokenOptions {
|
|
|
96
96
|
* @example
|
|
97
97
|
* ```typescript
|
|
98
98
|
* const loginUrl = getLoginUrl('/dashboard', {
|
|
99
|
-
* serverUrl: 'https://
|
|
99
|
+
* serverUrl: 'https://api.doany.ai',
|
|
100
100
|
* appId: 'my-app-123'
|
|
101
101
|
* });
|
|
102
|
-
* // Returns: 'https://
|
|
102
|
+
* // Returns: 'https://api.doany.ai/login?from_url=%2Fdashboard&app_id=my-app-123'
|
|
103
103
|
*
|
|
104
104
|
* // Custom login path
|
|
105
105
|
* const loginUrl = getLoginUrl('/dashboard', {
|
|
106
|
-
* serverUrl: 'https://
|
|
106
|
+
* serverUrl: 'https://api.doany.ai',
|
|
107
107
|
* appId: 'my-app-123',
|
|
108
108
|
* loginPath: '/auth/login'
|
|
109
109
|
* });
|
|
@@ -111,7 +111,7 @@ export interface RemoveAccessTokenOptions {
|
|
|
111
111
|
*/
|
|
112
112
|
export interface GetLoginUrlOptions {
|
|
113
113
|
/**
|
|
114
|
-
* The base server URL (e.g., 'https://
|
|
114
|
+
* The base server URL (e.g., 'https://api.doany.ai').
|
|
115
115
|
*/
|
|
116
116
|
serverUrl: string;
|
|
117
117
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DoanyErrorJSON } from "./axios-client.types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Custom error class for
|
|
3
|
+
* Custom error class for Doany SDK errors.
|
|
4
4
|
*
|
|
5
5
|
* This error is thrown when API requests fail. It extends the standard `Error` class and includes additional information about the HTTP status, error code, and response data from the server.
|
|
6
6
|
*
|
|
@@ -9,7 +9,7 @@ import type { Base44ErrorJSON } from "./axios-client.types.js";
|
|
|
9
9
|
* try {
|
|
10
10
|
* await client.entities.Todo.get('invalid-id');
|
|
11
11
|
* } catch (error) {
|
|
12
|
-
* if (error instanceof
|
|
12
|
+
* if (error instanceof DoanyError) {
|
|
13
13
|
* console.error('Status:', error.status); // 404
|
|
14
14
|
* console.error('Message:', error.message); // "Not found"
|
|
15
15
|
* console.error('Code:', error.code); // "NOT_FOUND"
|
|
@@ -19,7 +19,7 @@ import type { Base44ErrorJSON } from "./axios-client.types.js";
|
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
export declare class
|
|
22
|
+
export declare class DoanyError extends Error {
|
|
23
23
|
/**
|
|
24
24
|
* HTTP status code of the error.
|
|
25
25
|
*/
|
|
@@ -37,7 +37,7 @@ export declare class Base44Error extends Error {
|
|
|
37
37
|
*/
|
|
38
38
|
originalError: unknown;
|
|
39
39
|
/**
|
|
40
|
-
* Creates a new
|
|
40
|
+
* Creates a new DoanyError instance.
|
|
41
41
|
*
|
|
42
42
|
* @param message - Human-readable error message
|
|
43
43
|
* @param status - HTTP status code
|
|
@@ -60,11 +60,11 @@ export declare class Base44Error extends Error {
|
|
|
60
60
|
* try {
|
|
61
61
|
* await client.entities.Todo.get('invalid-id');
|
|
62
62
|
* } catch (error) {
|
|
63
|
-
* if (error instanceof
|
|
63
|
+
* if (error instanceof DoanyError) {
|
|
64
64
|
* const json = error.toJSON();
|
|
65
65
|
* console.log(json);
|
|
66
66
|
* // {
|
|
67
|
-
* // name: "
|
|
67
|
+
* // name: "DoanyError",
|
|
68
68
|
* // message: "Not found",
|
|
69
69
|
* // status: 404,
|
|
70
70
|
* // code: "NOT_FOUND",
|
|
@@ -74,7 +74,7 @@ export declare class Base44Error extends Error {
|
|
|
74
74
|
* }
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
toJSON():
|
|
77
|
+
toJSON(): DoanyErrorJSON;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Creates an axios client with default configuration and interceptors.
|
|
@@ -83,7 +83,7 @@ export declare class Base44Error extends Error {
|
|
|
83
83
|
* - Default headers
|
|
84
84
|
* - Authentication token injection
|
|
85
85
|
* - Response data unwrapping
|
|
86
|
-
* - Error transformation to
|
|
86
|
+
* - Error transformation to DoanyError
|
|
87
87
|
* - iframe messaging support
|
|
88
88
|
*
|
|
89
89
|
* @param options - Client configuration options
|
|
@@ -97,4 +97,4 @@ export declare function createAxiosClient({ baseURL, headers, token, interceptRe
|
|
|
97
97
|
interceptResponses?: boolean;
|
|
98
98
|
onError?: (error: Error) => void;
|
|
99
99
|
}): import("axios").AxiosInstance;
|
|
100
|
-
export type {
|
|
100
|
+
export type { DoanyErrorJSON } from "./axios-client.types.js";
|
|
@@ -3,7 +3,7 @@ import { isInIFrame } from "./common.js";
|
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
4
|
import { getAnalyticsSessionId } from "../modules/analytics.js";
|
|
5
5
|
/**
|
|
6
|
-
* Custom error class for
|
|
6
|
+
* Custom error class for Doany SDK errors.
|
|
7
7
|
*
|
|
8
8
|
* This error is thrown when API requests fail. It extends the standard `Error` class and includes additional information about the HTTP status, error code, and response data from the server.
|
|
9
9
|
*
|
|
@@ -12,7 +12,7 @@ import { getAnalyticsSessionId } from "../modules/analytics.js";
|
|
|
12
12
|
* try {
|
|
13
13
|
* await client.entities.Todo.get('invalid-id');
|
|
14
14
|
* } catch (error) {
|
|
15
|
-
* if (error instanceof
|
|
15
|
+
* if (error instanceof DoanyError) {
|
|
16
16
|
* console.error('Status:', error.status); // 404
|
|
17
17
|
* console.error('Message:', error.message); // "Not found"
|
|
18
18
|
* console.error('Code:', error.code); // "NOT_FOUND"
|
|
@@ -22,9 +22,9 @@ import { getAnalyticsSessionId } from "../modules/analytics.js";
|
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
export class
|
|
25
|
+
export class DoanyError extends Error {
|
|
26
26
|
/**
|
|
27
|
-
* Creates a new
|
|
27
|
+
* Creates a new DoanyError instance.
|
|
28
28
|
*
|
|
29
29
|
* @param message - Human-readable error message
|
|
30
30
|
* @param status - HTTP status code
|
|
@@ -35,7 +35,7 @@ export class Base44Error extends Error {
|
|
|
35
35
|
*/
|
|
36
36
|
constructor(message, status, code, data, originalError) {
|
|
37
37
|
super(message);
|
|
38
|
-
this.name = "
|
|
38
|
+
this.name = "DoanyError";
|
|
39
39
|
this.status = status;
|
|
40
40
|
this.code = code;
|
|
41
41
|
this.data = data;
|
|
@@ -54,11 +54,11 @@ export class Base44Error extends Error {
|
|
|
54
54
|
* try {
|
|
55
55
|
* await client.entities.Todo.get('invalid-id');
|
|
56
56
|
* } catch (error) {
|
|
57
|
-
* if (error instanceof
|
|
57
|
+
* if (error instanceof DoanyError) {
|
|
58
58
|
* const json = error.toJSON();
|
|
59
59
|
* console.log(json);
|
|
60
60
|
* // {
|
|
61
|
-
* // name: "
|
|
61
|
+
* // name: "DoanyError",
|
|
62
62
|
* // message: "Not found",
|
|
63
63
|
* // status: 404,
|
|
64
64
|
* // code: "NOT_FOUND",
|
|
@@ -86,7 +86,7 @@ export class Base44Error extends Error {
|
|
|
86
86
|
* @internal
|
|
87
87
|
*/
|
|
88
88
|
function safeErrorLog(prefix, error) {
|
|
89
|
-
if (error instanceof
|
|
89
|
+
if (error instanceof DoanyError) {
|
|
90
90
|
console.error(`${prefix} ${error.status}: ${error.message}`);
|
|
91
91
|
if (error.data) {
|
|
92
92
|
try {
|
|
@@ -108,7 +108,7 @@ function safeErrorLog(prefix, error) {
|
|
|
108
108
|
* - Default headers
|
|
109
109
|
* - Authentication token injection
|
|
110
110
|
* - Response data unwrapping
|
|
111
|
-
* - Error transformation to
|
|
111
|
+
* - Error transformation to DoanyError
|
|
112
112
|
* - iframe messaging support
|
|
113
113
|
*
|
|
114
114
|
* @param options - Client configuration options
|
|
@@ -138,7 +138,7 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
|
|
|
138
138
|
// backend can support anonymous agent access (conversation grouping + ownership).
|
|
139
139
|
// Authenticated requests are identified by their Authorization header instead.
|
|
140
140
|
if (!config.headers.get("Authorization")) {
|
|
141
|
-
config.headers.set("X-
|
|
141
|
+
config.headers.set("X-Doany-Anonymous-Id", getAnalyticsSessionId());
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
const requestId = uuidv4();
|
|
@@ -189,13 +189,13 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
|
|
|
189
189
|
const message = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) ||
|
|
190
190
|
((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.detail) ||
|
|
191
191
|
error.message;
|
|
192
|
-
const
|
|
192
|
+
const doanyError = new DoanyError(message, (_e = error.response) === null || _e === void 0 ? void 0 : _e.status, (_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.code, (_h = error.response) === null || _h === void 0 ? void 0 : _h.data, error);
|
|
193
193
|
// Log errors in development
|
|
194
194
|
if (process.env.NODE_ENV !== "production") {
|
|
195
|
-
safeErrorLog("[
|
|
195
|
+
safeErrorLog("[Doany SDK Error]", doanyError);
|
|
196
196
|
}
|
|
197
|
-
onError === null || onError === void 0 ? void 0 : onError(
|
|
198
|
-
return Promise.reject(
|
|
197
|
+
onError === null || onError === void 0 ? void 0 : onError(doanyError);
|
|
198
|
+
return Promise.reject(doanyError);
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
return client;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON representation of a
|
|
2
|
+
* JSON representation of a DoanyError.
|
|
3
3
|
*
|
|
4
|
-
* This is the structure returned by {@linkcode
|
|
4
|
+
* This is the structure returned by {@linkcode DoanyError.toJSON | DoanyError.toJSON()}.
|
|
5
5
|
* Useful for logging or sending error information to external services.
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface DoanyErrorJSON {
|
|
8
8
|
/**
|
|
9
|
-
* The error name, always "
|
|
9
|
+
* The error name, always "DoanyError".
|
|
10
10
|
*/
|
|
11
11
|
name: string;
|
|
12
12
|
/**
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const windowObj = typeof window !== "undefined"
|
|
2
2
|
? window
|
|
3
|
-
: {
|
|
3
|
+
: { doanySharedInstances: {} };
|
|
4
4
|
// Singleton (shared between sdk instances)//
|
|
5
5
|
export function getSharedInstance(name, factory) {
|
|
6
|
-
if (!windowObj.
|
|
7
|
-
windowObj.
|
|
6
|
+
if (!windowObj.doanySharedInstances) {
|
|
7
|
+
windowObj.doanySharedInstances = {};
|
|
8
8
|
}
|
|
9
|
-
if (!windowObj.
|
|
10
|
-
windowObj.
|
|
9
|
+
if (!windowObj.doanySharedInstances[name]) {
|
|
10
|
+
windowObj.doanySharedInstances[name] = {
|
|
11
11
|
instance: factory(),
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
return windowObj.
|
|
14
|
+
return windowObj.doanySharedInstances[name].instance;
|
|
15
15
|
}
|
|
@@ -6,7 +6,7 @@ function initializeSocket(config, handlers) {
|
|
|
6
6
|
var _a;
|
|
7
7
|
// On unauthenticated clients, send a stable anonymous visitor id on the
|
|
8
8
|
// handshake so the backend can verify room access for anonymous agent
|
|
9
|
-
// conversations (mirrors the X-
|
|
9
|
+
// conversations (mirrors the X-Doany-Anonymous-Id HTTP header). Authenticated
|
|
10
10
|
// clients are identified by their token instead.
|
|
11
11
|
const resolvedToken = (_a = config.token) !== null && _a !== void 0 ? _a : getAccessToken();
|
|
12
12
|
const query = {
|