@noematicsllc/talk-sdk 0.0.2 → 0.1.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/index.d.mts +93 -1
- package/dist/index.d.ts +93 -1
- package/dist/index.js +23 -0
- package/dist/index.mjs +22 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2144,4 +2144,96 @@ declare class TalkClient {
|
|
|
2144
2144
|
get host(): string;
|
|
2145
2145
|
}
|
|
2146
2146
|
|
|
2147
|
-
|
|
2147
|
+
/**
|
|
2148
|
+
* Browser Utilities for Nextcloud Talk SDK
|
|
2149
|
+
*
|
|
2150
|
+
* Provides utilities for running the SDK in browser environments,
|
|
2151
|
+
* including CORS proxy support.
|
|
2152
|
+
*/
|
|
2153
|
+
/**
|
|
2154
|
+
* Options for creating a proxy fetch function
|
|
2155
|
+
*/
|
|
2156
|
+
interface ProxyFetchOptions {
|
|
2157
|
+
/**
|
|
2158
|
+
* The base path for the proxy endpoint.
|
|
2159
|
+
* Default: '/nextcloud-proxy'
|
|
2160
|
+
*
|
|
2161
|
+
* The proxy should accept URLs in the format:
|
|
2162
|
+
* {proxyPath}/{protocol}/{host}/{path}
|
|
2163
|
+
*
|
|
2164
|
+
* Example: /nextcloud-proxy/https/nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2165
|
+
*/
|
|
2166
|
+
proxyPath?: string;
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Creates a fetch function that routes requests through a CORS proxy.
|
|
2170
|
+
*
|
|
2171
|
+
* This is useful when running the SDK in a browser environment where
|
|
2172
|
+
* direct requests to the Nextcloud server are blocked by CORS policy.
|
|
2173
|
+
*
|
|
2174
|
+
* The proxy transforms URLs like:
|
|
2175
|
+
* https://nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2176
|
+
* into:
|
|
2177
|
+
* /nextcloud-proxy/https/nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2178
|
+
*
|
|
2179
|
+
* @param targetHost - The Nextcloud server URL (e.g., 'https://nextcloud.example.com')
|
|
2180
|
+
* @param options - Optional configuration
|
|
2181
|
+
* @returns A fetch function that proxies requests
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```typescript
|
|
2185
|
+
* import { TalkClient, createProxyFetch } from '@noematicsllc/talk-sdk';
|
|
2186
|
+
*
|
|
2187
|
+
* const client = new TalkClient({
|
|
2188
|
+
* host: 'https://nextcloud.example.com',
|
|
2189
|
+
* username: 'admin',
|
|
2190
|
+
* password: 'app-password',
|
|
2191
|
+
* fetch: createProxyFetch('https://nextcloud.example.com'),
|
|
2192
|
+
* });
|
|
2193
|
+
* ```
|
|
2194
|
+
*
|
|
2195
|
+
* @remarks
|
|
2196
|
+
* You'll need to set up a proxy server that handles the `/nextcloud-proxy` endpoint.
|
|
2197
|
+
* For Vite, you can use a plugin like this:
|
|
2198
|
+
*
|
|
2199
|
+
* ```typescript
|
|
2200
|
+
* // vite.config.ts
|
|
2201
|
+
* import { defineConfig } from 'vite';
|
|
2202
|
+
* import http from 'http';
|
|
2203
|
+
* import https from 'https';
|
|
2204
|
+
*
|
|
2205
|
+
* export default defineConfig({
|
|
2206
|
+
* plugins: [{
|
|
2207
|
+
* name: 'nextcloud-proxy',
|
|
2208
|
+
* configureServer(server) {
|
|
2209
|
+
* server.middlewares.use('/nextcloud-proxy', (req, res) => {
|
|
2210
|
+
* const match = req.url?.match(/^\/(https?)\/([\w.-]+(?::\d+)?)(\/.*)?$/);
|
|
2211
|
+
* if (!match) {
|
|
2212
|
+
* res.statusCode = 400;
|
|
2213
|
+
* res.end('Invalid proxy URL');
|
|
2214
|
+
* return;
|
|
2215
|
+
* }
|
|
2216
|
+
* const [, protocol, host, path = '/'] = match;
|
|
2217
|
+
* const httpModule = protocol === 'https' ? https : http;
|
|
2218
|
+
* const proxyReq = httpModule.request({
|
|
2219
|
+
* hostname: host.split(':')[0],
|
|
2220
|
+
* port: host.split(':')[1] || (protocol === 'https' ? 443 : 80),
|
|
2221
|
+
* path,
|
|
2222
|
+
* method: req.method,
|
|
2223
|
+
* headers: { ...req.headers, host },
|
|
2224
|
+
* }, (proxyRes) => {
|
|
2225
|
+
* res.statusCode = proxyRes.statusCode || 500;
|
|
2226
|
+
* Object.entries(proxyRes.headers).forEach(([k, v]) => v && res.setHeader(k, v));
|
|
2227
|
+
* proxyRes.pipe(res);
|
|
2228
|
+
* });
|
|
2229
|
+
* proxyReq.on('error', (e) => { res.statusCode = 502; res.end(e.message); });
|
|
2230
|
+
* req.pipe(proxyReq);
|
|
2231
|
+
* });
|
|
2232
|
+
* },
|
|
2233
|
+
* }],
|
|
2234
|
+
* });
|
|
2235
|
+
* ```
|
|
2236
|
+
*/
|
|
2237
|
+
declare function createProxyFetch(targetHost: string, options?: ProxyFetchOptions): typeof fetch;
|
|
2238
|
+
|
|
2239
|
+
export { ActorType, type AddParticipantOptions, type AddReactionOptions, BreakoutRoomMode, type CallNotificationSettings, CallResource, type ChatPollResult, ChatResource, ConversationType, type CreatePollOptions, type CreateRoomOptions, type DeletedMessageRef, HttpClient, type HttpClientConfig, HttpClientError, type HttpResponse, InCallFlag, type JoinCallOptions, type JoinRoomOptions, type LeaveCallOptions, type ListRoomsOptions, ListableScope, type LobbySettings, LobbyState, type MessageMetadata, type MessageReminder, MessageType, type NormalizedMessage, type NormalizedParticipant, type NormalizedRoom, NotificationLevel, type NotificationSettings, type OCSResponse, ParticipantResource, ParticipantType, Permission, type PermissionMethod, type PermissionMode, type PollMessagesOptions, PollResource, PollResultMode, type PollVote, type ProxyFetchOptions, type ReactionActor, ReactionResource, type ReactionsByEmoji, ReadOnlyState, type ReceiveMessagesOptions, RecordingStatus, type RequestOptions, type ResponseMeta, Room, RoomResource, type RoomResources, RoomsAccessor, SIPState, type ScheduleMessageOptions, type SendMessageOptions, type SessionConflict, type SessionState, type SetPermissionsOptions, type ShareObjectOptions, SharedObjectType, type SignalingSettings, type TalkCallPeer, type TalkChatMentionSuggestion, type TalkChatMessage, type TalkChatMessageWithParent, TalkClient, type TalkClientConfig, type TalkParticipant, type TalkPoll, type TalkRichObjectParameter, type TalkRoom, type UpdateCallFlagsOptions, type VotePollOptions, createProxyFetch, normalizeMessage, normalizeMessageWithParent, normalizeMessages, normalizeParticipant, normalizeParticipants, normalizeRoom, normalizeRooms };
|
package/dist/index.d.ts
CHANGED
|
@@ -2144,4 +2144,96 @@ declare class TalkClient {
|
|
|
2144
2144
|
get host(): string;
|
|
2145
2145
|
}
|
|
2146
2146
|
|
|
2147
|
-
|
|
2147
|
+
/**
|
|
2148
|
+
* Browser Utilities for Nextcloud Talk SDK
|
|
2149
|
+
*
|
|
2150
|
+
* Provides utilities for running the SDK in browser environments,
|
|
2151
|
+
* including CORS proxy support.
|
|
2152
|
+
*/
|
|
2153
|
+
/**
|
|
2154
|
+
* Options for creating a proxy fetch function
|
|
2155
|
+
*/
|
|
2156
|
+
interface ProxyFetchOptions {
|
|
2157
|
+
/**
|
|
2158
|
+
* The base path for the proxy endpoint.
|
|
2159
|
+
* Default: '/nextcloud-proxy'
|
|
2160
|
+
*
|
|
2161
|
+
* The proxy should accept URLs in the format:
|
|
2162
|
+
* {proxyPath}/{protocol}/{host}/{path}
|
|
2163
|
+
*
|
|
2164
|
+
* Example: /nextcloud-proxy/https/nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2165
|
+
*/
|
|
2166
|
+
proxyPath?: string;
|
|
2167
|
+
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Creates a fetch function that routes requests through a CORS proxy.
|
|
2170
|
+
*
|
|
2171
|
+
* This is useful when running the SDK in a browser environment where
|
|
2172
|
+
* direct requests to the Nextcloud server are blocked by CORS policy.
|
|
2173
|
+
*
|
|
2174
|
+
* The proxy transforms URLs like:
|
|
2175
|
+
* https://nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2176
|
+
* into:
|
|
2177
|
+
* /nextcloud-proxy/https/nextcloud.example.com/ocs/v2.php/apps/spreed/api/v4/room
|
|
2178
|
+
*
|
|
2179
|
+
* @param targetHost - The Nextcloud server URL (e.g., 'https://nextcloud.example.com')
|
|
2180
|
+
* @param options - Optional configuration
|
|
2181
|
+
* @returns A fetch function that proxies requests
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```typescript
|
|
2185
|
+
* import { TalkClient, createProxyFetch } from '@noematicsllc/talk-sdk';
|
|
2186
|
+
*
|
|
2187
|
+
* const client = new TalkClient({
|
|
2188
|
+
* host: 'https://nextcloud.example.com',
|
|
2189
|
+
* username: 'admin',
|
|
2190
|
+
* password: 'app-password',
|
|
2191
|
+
* fetch: createProxyFetch('https://nextcloud.example.com'),
|
|
2192
|
+
* });
|
|
2193
|
+
* ```
|
|
2194
|
+
*
|
|
2195
|
+
* @remarks
|
|
2196
|
+
* You'll need to set up a proxy server that handles the `/nextcloud-proxy` endpoint.
|
|
2197
|
+
* For Vite, you can use a plugin like this:
|
|
2198
|
+
*
|
|
2199
|
+
* ```typescript
|
|
2200
|
+
* // vite.config.ts
|
|
2201
|
+
* import { defineConfig } from 'vite';
|
|
2202
|
+
* import http from 'http';
|
|
2203
|
+
* import https from 'https';
|
|
2204
|
+
*
|
|
2205
|
+
* export default defineConfig({
|
|
2206
|
+
* plugins: [{
|
|
2207
|
+
* name: 'nextcloud-proxy',
|
|
2208
|
+
* configureServer(server) {
|
|
2209
|
+
* server.middlewares.use('/nextcloud-proxy', (req, res) => {
|
|
2210
|
+
* const match = req.url?.match(/^\/(https?)\/([\w.-]+(?::\d+)?)(\/.*)?$/);
|
|
2211
|
+
* if (!match) {
|
|
2212
|
+
* res.statusCode = 400;
|
|
2213
|
+
* res.end('Invalid proxy URL');
|
|
2214
|
+
* return;
|
|
2215
|
+
* }
|
|
2216
|
+
* const [, protocol, host, path = '/'] = match;
|
|
2217
|
+
* const httpModule = protocol === 'https' ? https : http;
|
|
2218
|
+
* const proxyReq = httpModule.request({
|
|
2219
|
+
* hostname: host.split(':')[0],
|
|
2220
|
+
* port: host.split(':')[1] || (protocol === 'https' ? 443 : 80),
|
|
2221
|
+
* path,
|
|
2222
|
+
* method: req.method,
|
|
2223
|
+
* headers: { ...req.headers, host },
|
|
2224
|
+
* }, (proxyRes) => {
|
|
2225
|
+
* res.statusCode = proxyRes.statusCode || 500;
|
|
2226
|
+
* Object.entries(proxyRes.headers).forEach(([k, v]) => v && res.setHeader(k, v));
|
|
2227
|
+
* proxyRes.pipe(res);
|
|
2228
|
+
* });
|
|
2229
|
+
* proxyReq.on('error', (e) => { res.statusCode = 502; res.end(e.message); });
|
|
2230
|
+
* req.pipe(proxyReq);
|
|
2231
|
+
* });
|
|
2232
|
+
* },
|
|
2233
|
+
* }],
|
|
2234
|
+
* });
|
|
2235
|
+
* ```
|
|
2236
|
+
*/
|
|
2237
|
+
declare function createProxyFetch(targetHost: string, options?: ProxyFetchOptions): typeof fetch;
|
|
2238
|
+
|
|
2239
|
+
export { ActorType, type AddParticipantOptions, type AddReactionOptions, BreakoutRoomMode, type CallNotificationSettings, CallResource, type ChatPollResult, ChatResource, ConversationType, type CreatePollOptions, type CreateRoomOptions, type DeletedMessageRef, HttpClient, type HttpClientConfig, HttpClientError, type HttpResponse, InCallFlag, type JoinCallOptions, type JoinRoomOptions, type LeaveCallOptions, type ListRoomsOptions, ListableScope, type LobbySettings, LobbyState, type MessageMetadata, type MessageReminder, MessageType, type NormalizedMessage, type NormalizedParticipant, type NormalizedRoom, NotificationLevel, type NotificationSettings, type OCSResponse, ParticipantResource, ParticipantType, Permission, type PermissionMethod, type PermissionMode, type PollMessagesOptions, PollResource, PollResultMode, type PollVote, type ProxyFetchOptions, type ReactionActor, ReactionResource, type ReactionsByEmoji, ReadOnlyState, type ReceiveMessagesOptions, RecordingStatus, type RequestOptions, type ResponseMeta, Room, RoomResource, type RoomResources, RoomsAccessor, SIPState, type ScheduleMessageOptions, type SendMessageOptions, type SessionConflict, type SessionState, type SetPermissionsOptions, type ShareObjectOptions, SharedObjectType, type SignalingSettings, type TalkCallPeer, type TalkChatMentionSuggestion, type TalkChatMessage, type TalkChatMessageWithParent, TalkClient, type TalkClientConfig, type TalkParticipant, type TalkPoll, type TalkRichObjectParameter, type TalkRoom, type UpdateCallFlagsOptions, type VotePollOptions, createProxyFetch, normalizeMessage, normalizeMessageWithParent, normalizeMessages, normalizeParticipant, normalizeParticipants, normalizeRoom, normalizeRooms };
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
SIPState: () => SIPState,
|
|
47
47
|
SharedObjectType: () => SharedObjectType,
|
|
48
48
|
TalkClient: () => TalkClient,
|
|
49
|
+
createProxyFetch: () => createProxyFetch,
|
|
49
50
|
normalizeMessage: () => normalizeMessage,
|
|
50
51
|
normalizeMessageWithParent: () => normalizeMessageWithParent,
|
|
51
52
|
normalizeMessages: () => normalizeMessages,
|
|
@@ -1826,6 +1827,27 @@ var TalkClient = class {
|
|
|
1826
1827
|
return this.http.host;
|
|
1827
1828
|
}
|
|
1828
1829
|
};
|
|
1830
|
+
|
|
1831
|
+
// src/browser.ts
|
|
1832
|
+
function createProxyFetch(targetHost, options = {}) {
|
|
1833
|
+
const { proxyPath = "/nextcloud-proxy" } = options;
|
|
1834
|
+
const url = new URL(targetHost);
|
|
1835
|
+
const protocol = url.protocol.replace(":", "");
|
|
1836
|
+
const host = url.host;
|
|
1837
|
+
return (input, init) => {
|
|
1838
|
+
let requestUrl;
|
|
1839
|
+
if (typeof input === "string") {
|
|
1840
|
+
requestUrl = input;
|
|
1841
|
+
} else if (input instanceof URL) {
|
|
1842
|
+
requestUrl = input.toString();
|
|
1843
|
+
} else {
|
|
1844
|
+
requestUrl = input.url;
|
|
1845
|
+
}
|
|
1846
|
+
const targetUrl = new URL(requestUrl);
|
|
1847
|
+
const proxiedPath = `${proxyPath}/${protocol}/${host}${targetUrl.pathname}${targetUrl.search}`;
|
|
1848
|
+
return fetch(proxiedPath, init);
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1829
1851
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1830
1852
|
0 && (module.exports = {
|
|
1831
1853
|
ActorType,
|
|
@@ -1854,6 +1876,7 @@ var TalkClient = class {
|
|
|
1854
1876
|
SIPState,
|
|
1855
1877
|
SharedObjectType,
|
|
1856
1878
|
TalkClient,
|
|
1879
|
+
createProxyFetch,
|
|
1857
1880
|
normalizeMessage,
|
|
1858
1881
|
normalizeMessageWithParent,
|
|
1859
1882
|
normalizeMessages,
|
package/dist/index.mjs
CHANGED
|
@@ -1768,6 +1768,27 @@ var TalkClient = class {
|
|
|
1768
1768
|
return this.http.host;
|
|
1769
1769
|
}
|
|
1770
1770
|
};
|
|
1771
|
+
|
|
1772
|
+
// src/browser.ts
|
|
1773
|
+
function createProxyFetch(targetHost, options = {}) {
|
|
1774
|
+
const { proxyPath = "/nextcloud-proxy" } = options;
|
|
1775
|
+
const url = new URL(targetHost);
|
|
1776
|
+
const protocol = url.protocol.replace(":", "");
|
|
1777
|
+
const host = url.host;
|
|
1778
|
+
return (input, init) => {
|
|
1779
|
+
let requestUrl;
|
|
1780
|
+
if (typeof input === "string") {
|
|
1781
|
+
requestUrl = input;
|
|
1782
|
+
} else if (input instanceof URL) {
|
|
1783
|
+
requestUrl = input.toString();
|
|
1784
|
+
} else {
|
|
1785
|
+
requestUrl = input.url;
|
|
1786
|
+
}
|
|
1787
|
+
const targetUrl = new URL(requestUrl);
|
|
1788
|
+
const proxiedPath = `${proxyPath}/${protocol}/${host}${targetUrl.pathname}${targetUrl.search}`;
|
|
1789
|
+
return fetch(proxiedPath, init);
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1771
1792
|
export {
|
|
1772
1793
|
ActorType,
|
|
1773
1794
|
BreakoutRoomMode,
|
|
@@ -1795,6 +1816,7 @@ export {
|
|
|
1795
1816
|
SIPState,
|
|
1796
1817
|
SharedObjectType,
|
|
1797
1818
|
TalkClient,
|
|
1819
|
+
createProxyFetch,
|
|
1798
1820
|
normalizeMessage,
|
|
1799
1821
|
normalizeMessageWithParent,
|
|
1800
1822
|
normalizeMessages,
|