@ethora/sdk-backend 25.1.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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Configuration and secrets management for Ethora SDK
3
+ *
4
+ * @format
5
+ */
6
+ /**
7
+ * Secrets configuration interface
8
+ */
9
+ export interface Secrets {
10
+ /** Base URL for the Ethora chat API */
11
+ chatApiUrl: string;
12
+ /** Application ID for the Ethora chat service */
13
+ chatAppId: string;
14
+ /** Secret key for JWT token generation */
15
+ chatAppSecret: string;
16
+ /** Chatbot JID (optional) */
17
+ chatBotJid?: string;
18
+ }
19
+ /**
20
+ * Default timeout configuration
21
+ */
22
+ export interface TimeoutConfig {
23
+ /** Total request timeout in milliseconds */
24
+ total: number;
25
+ /** Connection timeout in milliseconds */
26
+ connect: number;
27
+ }
28
+ /**
29
+ * Default timeout values
30
+ */
31
+ export declare const DEFAULT_TIMEOUT: TimeoutConfig;
32
+ /**
33
+ * JID domain for Ethora chat rooms
34
+ */
35
+ export declare const ETHORA_JID_DOMAIN = "@conference.xmpp.ethoradev.com";
36
+ /**
37
+ * Gets secrets configuration
38
+ *
39
+ * In a real implementation, this would read from environment variables,
40
+ * a secrets manager, or a configuration file.
41
+ *
42
+ * @returns Secrets configuration object
43
+ * @throws Error if required secrets are not configured
44
+ */
45
+ export declare function getSecretsSync(): Secrets;
46
+ /**
47
+ * Gets or creates a singleton instance of secrets
48
+ *
49
+ * @returns Secrets configuration object
50
+ */
51
+ export declare function getSecrets(): Secrets;
52
+ //# sourceMappingURL=secrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/config/secrets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,aAG7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,mCAAmC,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAoBxC;AAOD;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAKpC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration and secrets management for Ethora SDK
4
+ *
5
+ * @format
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ETHORA_JID_DOMAIN = exports.DEFAULT_TIMEOUT = void 0;
9
+ exports.getSecretsSync = getSecretsSync;
10
+ exports.getSecrets = getSecrets;
11
+ /**
12
+ * Default timeout values
13
+ */
14
+ exports.DEFAULT_TIMEOUT = {
15
+ total: 30000, // 30 seconds
16
+ connect: 5000, // 5 seconds
17
+ };
18
+ /**
19
+ * JID domain for Ethora chat rooms
20
+ */
21
+ exports.ETHORA_JID_DOMAIN = "@conference.xmpp.ethoradev.com";
22
+ /**
23
+ * Gets secrets configuration
24
+ *
25
+ * In a real implementation, this would read from environment variables,
26
+ * a secrets manager, or a configuration file.
27
+ *
28
+ * @returns Secrets configuration object
29
+ * @throws Error if required secrets are not configured
30
+ */
31
+ function getSecretsSync() {
32
+ const chatApiUrl = process.env.ETHORA_CHAT_API_URL;
33
+ const chatAppId = process.env.ETHORA_CHAT_APP_ID;
34
+ const chatAppSecret = process.env.ETHORA_CHAT_APP_SECRET;
35
+ if (!chatApiUrl || !chatAppId || !chatAppSecret) {
36
+ throw new Error("Missing required Ethora configuration. Please set the following environment variables:\n" +
37
+ "- ETHORA_CHAT_API_URL\n" +
38
+ "- ETHORA_CHAT_APP_ID\n" +
39
+ "- ETHORA_CHAT_APP_SECRET");
40
+ }
41
+ return {
42
+ chatApiUrl,
43
+ chatAppId,
44
+ chatAppSecret,
45
+ chatBotJid: process.env.ETHORA_CHAT_BOT_JID,
46
+ };
47
+ }
48
+ /**
49
+ * Singleton instance of secrets
50
+ */
51
+ let secretsInstance = null;
52
+ /**
53
+ * Gets or creates a singleton instance of secrets
54
+ *
55
+ * @returns Secrets configuration object
56
+ */
57
+ function getSecrets() {
58
+ if (!secretsInstance) {
59
+ secretsInstance = getSecretsSync();
60
+ }
61
+ return secretsInstance;
62
+ }
63
+ //# sourceMappingURL=secrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/config/secrets.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAgDH,wCAoBC;AAYD,gCAKC;AA3DD;;GAEG;AACU,QAAA,eAAe,GAAkB;IAC5C,KAAK,EAAE,KAAK,EAAE,aAAa;IAC3B,OAAO,EAAE,IAAI,EAAE,YAAY;CAC5B,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,gCAAgC,CAAC;AAElE;;;;;;;;GAQG;AACH,SAAgB,cAAc;IAC5B,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IACnD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IACjD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;IAEzD,IAAI,CAAC,UAAU,IAAI,CAAC,SAAS,IAAI,CAAC,aAAa,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,0FAA0F;YACxF,yBAAyB;YACzB,wBAAwB;YACxB,0BAA0B,CAC7B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,UAAU;QACV,SAAS;QACT,aAAa;QACb,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;KAC5C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,IAAI,eAAe,GAAmB,IAAI,CAAC;AAE3C;;;;GAIG;AACH,SAAgB,UAAU;IACxB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,eAAe,GAAG,cAAc,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Ethora SDK - Main entry point
3
+ *
4
+ * This SDK provides a TypeScript/Node.js implementation for integrating
5
+ * with the Ethora chat service backend API.
6
+ *
7
+ * @format
8
+ */
9
+ export * from "./types";
10
+ export * from "./config/secrets";
11
+ export * from "./utils/logger";
12
+ export * from "./utils/jwt";
13
+ export { EthoraSDKService, getEthoraSDKService, } from "./repositories/EthoraSDKService";
14
+ export type { ChatRepository } from "./types";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,SAAS,CAAC;AAGxB,cAAc,kBAAkB,CAAC;AAGjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAG5B,OAAO,EACL,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * Ethora SDK - Main entry point
4
+ *
5
+ * This SDK provides a TypeScript/Node.js implementation for integrating
6
+ * with the Ethora chat service backend API.
7
+ *
8
+ * @format
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.getEthoraSDKService = exports.EthoraSDKService = void 0;
26
+ // Export types
27
+ __exportStar(require("./types"), exports);
28
+ // Export configuration
29
+ __exportStar(require("./config/secrets"), exports);
30
+ // Export utilities
31
+ __exportStar(require("./utils/logger"), exports);
32
+ __exportStar(require("./utils/jwt"), exports);
33
+ // Export repositories
34
+ var EthoraSDKService_1 = require("./repositories/EthoraSDKService");
35
+ Object.defineProperty(exports, "EthoraSDKService", { enumerable: true, get: function () { return EthoraSDKService_1.EthoraSDKService; } });
36
+ Object.defineProperty(exports, "getEthoraSDKService", { enumerable: true, get: function () { return EthoraSDKService_1.getEthoraSDKService; } });
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;AAEH,eAAe;AACf,0CAAwB;AAExB,uBAAuB;AACvB,mDAAiC;AAEjC,mBAAmB;AACnB,iDAA+B;AAC/B,8CAA4B;AAE5B,sBAAsB;AACtB,oEAGyC;AAFvC,oHAAA,gBAAgB,OAAA;AAChB,uHAAA,mBAAmB,OAAA"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Concrete implementation of the ChatRepository using the Ethora API
3
+ *
4
+ * This class handles chat operations in the Ethora chat service. It manages
5
+ * JWT authentication tokens for server-to-server communication and uses
6
+ * HTTP clients to make asynchronous API calls.
7
+ *
8
+ * @format
9
+ */
10
+ import type { UUID, ChatRepository, ApiResponse, UpdateUserData, GetUsersQueryParams } from "../types";
11
+ /**
12
+ * EthoraSDKService - Concrete implementation of ChatRepository
13
+ */
14
+ export declare class EthoraSDKService implements ChatRepository {
15
+ private readonly baseEthoraUrl;
16
+ private readonly secrets;
17
+ private readonly httpClient;
18
+ constructor();
19
+ /**
20
+ * Generates a fully-qualified chat room JID from a workspace ID
21
+ *
22
+ * The JID is constructed in the format `<appId>_<workspace_id>@conference.xmpp.ethoradev.com`.
23
+ * This method uses a static JID domain to provide a unique identifier for a chat room.
24
+ *
25
+ * @param workspaceId - The unique identifier of the workspace
26
+ * @param full - Whether to include the full JID domain
27
+ * @returns The fully-qualified JID string for the chat room
28
+ */
29
+ createChatName(workspaceId: UUID, full?: boolean): string;
30
+ /**
31
+ * Creates a client-side JWT token for a specific user ID
32
+ *
33
+ * This method generates a JWT token for a user that can be used for client-side
34
+ * authentication with the chat service. The token payload includes the
35
+ * user's ID and the app ID.
36
+ *
37
+ * @param userId - The unique identifier of the user
38
+ * @returns The encoded JWT token for client-side authentication
39
+ */
40
+ createChatUserJwtToken(userId: UUID): string;
41
+ /**
42
+ * Creates the necessary headers for an API call with a JWT token
43
+ *
44
+ * @returns The headers dictionary containing the `x-custom-token` field
45
+ */
46
+ private getHeaders;
47
+ /**
48
+ * Makes an HTTP request with error handling
49
+ *
50
+ * @param config - Axios request configuration
51
+ * @returns The API response
52
+ */
53
+ private makeRequest;
54
+ /**
55
+ * Creates a user in the chat service
56
+ *
57
+ * Uses the batch API endpoint to create a single user. The API expects:
58
+ * - bypassEmailConfirmation: true
59
+ * - usersList: array with user objects containing email, firstName, lastName, password, uuid
60
+ *
61
+ * @param userId - The unique identifier of the user (used as uuid)
62
+ * @param userData - Additional user data (optional) - can include email, firstName, lastName, password, etc.
63
+ * @returns The API response
64
+ */
65
+ createUser(userId: UUID, userData?: Record<string, unknown>): Promise<ApiResponse>;
66
+ /**
67
+ * Creates a chat room for a workspace
68
+ *
69
+ * @param workspaceId - The unique identifier of the workspace
70
+ * @param roomData - Additional room data (optional)
71
+ * @returns The API response
72
+ */
73
+ createChatRoom(workspaceId: UUID, roomData?: Record<string, unknown>): Promise<ApiResponse>;
74
+ /**
75
+ * Grants a user access to a chat room
76
+ *
77
+ * Uses plain userIds without prefixing (matching how users are created)
78
+ *
79
+ * @param workspaceId - The unique identifier of the workspace
80
+ * @param userId - The unique identifier of the user (or array of user IDs)
81
+ * @returns The API response
82
+ */
83
+ grantUserAccessToChatRoom(workspaceId: UUID, userId: UUID | UUID[]): Promise<ApiResponse>;
84
+ /**
85
+ * Grants chatbot access to a chat room
86
+ *
87
+ * @param workspaceId - The unique identifier of the workspace
88
+ * @returns The API response
89
+ */
90
+ grantChatbotAccessToChatRoom(workspaceId: UUID): Promise<ApiResponse>;
91
+ /**
92
+ * Deletes users from the chat service
93
+ *
94
+ * @param userIds - Array of user IDs to delete
95
+ * @returns The API response
96
+ */
97
+ deleteUsers(userIds: UUID[]): Promise<ApiResponse>;
98
+ /**
99
+ * Deletes a chat room from the chat service by its workspace ID
100
+ *
101
+ * This method sends a DELETE request to the Ethora API using the workspace ID
102
+ * to construct the chat name. It gracefully handles the case where the chat room
103
+ * is already non-existent (422 Not Found).
104
+ *
105
+ * @param workspaceId - The unique identifier of the workspace associated with the chat room
106
+ * @returns The JSON response from the chat service upon successful deletion or a success status if not found
107
+ */
108
+ deleteChatRoom(workspaceId: UUID): Promise<ApiResponse>;
109
+ /**
110
+ * Updates multiple users in the chat service
111
+ *
112
+ * This method sends a PATCH request to update multiple users at once.
113
+ * The endpoint accepts an array of user objects with userId and optional
114
+ * fields. Only provided fields will be updated.
115
+ *
116
+ * Limits: 1-100 users per request
117
+ * Response contains results array with status for each user:
118
+ * - updated: user was successfully updated (includes updated user data)
119
+ * - not-found: user was not found
120
+ * - skipped: user update was skipped
121
+ *
122
+ * @param users - Array of user data to update (1-100 users)
123
+ * @returns The API response with results array containing status for each user
124
+ */
125
+ updateUsers(users: UpdateUserData[]): Promise<ApiResponse>;
126
+ /**
127
+ * Gets users from the chat service
128
+ *
129
+ * This method supports multiple query modes:
130
+ * - No parameters: returns all users of the app
131
+ * - chatName parameter: returns all users of the chat
132
+ * - For group chats: use appId_uuId format
133
+ * - For 1-on-1 chats: use xmppUsernameA-xmppUsernameB format
134
+ * - xmppUsername parameter: returns a specific user by XMPP username
135
+ *
136
+ * @param params - Query parameters for filtering users (optional)
137
+ * @returns The API response
138
+ */
139
+ getUsers(params?: GetUsersQueryParams): Promise<ApiResponse>;
140
+ }
141
+ export declare function getEthoraSDKService(): EthoraSDKService;
142
+ //# sourceMappingURL=EthoraSDKService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthoraSDKService.d.ts","sourceRoot":"","sources":["../../src/repositories/EthoraSDKService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,WAAW,EAIX,cAAc,EAEd,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAWlB;;GAEG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;;IAgB3C;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,GAAE,OAAc,GAAG,MAAM;IAa/D;;;;;;;;;OASG;IACH,sBAAsB,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM;IAK5C;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAOlB;;;;;OAKG;YACW,WAAW;IA4BzB;;;;;;;;;;OAUG;IACG,UAAU,CACd,MAAM,EAAE,IAAI,EACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC;IA0EvB;;;;;;OAMG;IACG,cAAc,CAClB,WAAW,EAAE,IAAI,EACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC;IAwBvB;;;;;;;;OAQG;IACG,yBAAyB,CAC7B,WAAW,EAAE,IAAI,EACjB,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,GACpB,OAAO,CAAC,WAAW,CAAC;IA8CvB;;;;;OAKG;IACG,4BAA4B,CAAC,WAAW,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IAoB3E;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAkCxD;;;;;;;;;OASG;IACG,cAAc,CAAC,WAAW,EAAE,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;IAgD7D;;;;;;;;;;;;;;;OAeG;IACG,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAkChE;;;;;;;;;;;;OAYG;IACG,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;CA6BnE;AAaD,wBAAgB,mBAAmB,IAAI,gBAAgB,CAMtD"}