@insforge/sdk 1.3.0-ssr.2 → 1.3.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/README.md +18 -0
- package/dist/{client-B8ykVESe.d.mts → client-CQfw9UsO.d.mts} +7 -1
- package/dist/{client-B8ykVESe.d.ts → client-CQfw9UsO.d.ts} +7 -1
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +88 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -57
- package/dist/index.mjs.map +1 -1
- package/dist/ssr.d.mts +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +89 -64
- package/dist/ssr.js.map +1 -1
- package/dist/ssr.mjs +79 -64
- package/dist/ssr.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2177,7 +2177,6 @@ var Functions = class _Functions {
|
|
|
2177
2177
|
};
|
|
2178
2178
|
|
|
2179
2179
|
// src/modules/realtime.ts
|
|
2180
|
-
import { io } from "socket.io-client";
|
|
2181
2180
|
var CONNECT_TIMEOUT = 1e4;
|
|
2182
2181
|
var Realtime = class {
|
|
2183
2182
|
constructor(baseUrl, tokenManager, anonKey) {
|
|
@@ -2212,61 +2211,69 @@ var Realtime = class {
|
|
|
2212
2211
|
if (this.connectPromise) {
|
|
2213
2212
|
return this.connectPromise;
|
|
2214
2213
|
}
|
|
2215
|
-
this.connectPromise =
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
this.socket.
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2214
|
+
this.connectPromise = (async () => {
|
|
2215
|
+
try {
|
|
2216
|
+
const { io } = await import("socket.io-client");
|
|
2217
|
+
await new Promise((resolve, reject) => {
|
|
2218
|
+
const token = this.tokenManager.getAccessToken() ?? this.anonKey;
|
|
2219
|
+
this.socket = io(this.baseUrl, {
|
|
2220
|
+
transports: ["websocket"],
|
|
2221
|
+
auth: token ? { token } : void 0
|
|
2222
|
+
});
|
|
2223
|
+
let initialConnection = true;
|
|
2224
|
+
let timeoutId = null;
|
|
2225
|
+
const cleanup = () => {
|
|
2226
|
+
if (timeoutId) {
|
|
2227
|
+
clearTimeout(timeoutId);
|
|
2228
|
+
timeoutId = null;
|
|
2229
|
+
}
|
|
2230
|
+
};
|
|
2231
|
+
timeoutId = setTimeout(() => {
|
|
2232
|
+
if (initialConnection) {
|
|
2233
|
+
initialConnection = false;
|
|
2234
|
+
this.connectPromise = null;
|
|
2235
|
+
this.socket?.disconnect();
|
|
2236
|
+
this.socket = null;
|
|
2237
|
+
reject(new Error(`Connection timeout after ${CONNECT_TIMEOUT}ms`));
|
|
2238
|
+
}
|
|
2239
|
+
}, CONNECT_TIMEOUT);
|
|
2240
|
+
this.socket.on("connect", () => {
|
|
2241
|
+
cleanup();
|
|
2242
|
+
for (const channel of this.subscribedChannels) {
|
|
2243
|
+
this.socket.emit("realtime:subscribe", { channel });
|
|
2244
|
+
}
|
|
2245
|
+
this.notifyListeners("connect");
|
|
2246
|
+
if (initialConnection) {
|
|
2247
|
+
initialConnection = false;
|
|
2248
|
+
this.connectPromise = null;
|
|
2249
|
+
resolve();
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2252
|
+
this.socket.on("connect_error", (error) => {
|
|
2253
|
+
cleanup();
|
|
2254
|
+
this.notifyListeners("connect_error", error);
|
|
2255
|
+
if (initialConnection) {
|
|
2256
|
+
initialConnection = false;
|
|
2257
|
+
this.connectPromise = null;
|
|
2258
|
+
reject(error);
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
this.socket.on("disconnect", (reason) => {
|
|
2262
|
+
this.notifyListeners("disconnect", reason);
|
|
2263
|
+
});
|
|
2264
|
+
this.socket.on("realtime:error", (error) => {
|
|
2265
|
+
this.notifyListeners("error", error);
|
|
2266
|
+
});
|
|
2267
|
+
this.socket.onAny((event, message) => {
|
|
2268
|
+
if (event === "realtime:error") return;
|
|
2269
|
+
this.notifyListeners(event, message);
|
|
2270
|
+
});
|
|
2271
|
+
});
|
|
2272
|
+
} catch (error) {
|
|
2273
|
+
this.connectPromise = null;
|
|
2274
|
+
throw error;
|
|
2275
|
+
}
|
|
2276
|
+
})();
|
|
2270
2277
|
return this.connectPromise;
|
|
2271
2278
|
}
|
|
2272
2279
|
/**
|
|
@@ -2590,9 +2597,21 @@ var InsForgeClient = class {
|
|
|
2590
2597
|
};
|
|
2591
2598
|
|
|
2592
2599
|
// src/index.ts
|
|
2593
|
-
function createClient(config) {
|
|
2600
|
+
function createClient(config = {}) {
|
|
2594
2601
|
return new InsForgeClient(config);
|
|
2595
2602
|
}
|
|
2603
|
+
function createAdminClient(config) {
|
|
2604
|
+
const { apiKey: rawApiKey, ...clientConfig } = config ?? {};
|
|
2605
|
+
const apiKey = rawApiKey?.trim();
|
|
2606
|
+
if (!apiKey) {
|
|
2607
|
+
throw new Error("Missing apiKey. Pass apiKey to createAdminClient().");
|
|
2608
|
+
}
|
|
2609
|
+
return new InsForgeClient({
|
|
2610
|
+
...clientConfig,
|
|
2611
|
+
edgeFunctionToken: apiKey,
|
|
2612
|
+
isServerMode: true
|
|
2613
|
+
});
|
|
2614
|
+
}
|
|
2596
2615
|
var index_default = InsForgeClient;
|
|
2597
2616
|
export {
|
|
2598
2617
|
AI,
|
|
@@ -2609,6 +2628,7 @@ export {
|
|
|
2609
2628
|
Storage,
|
|
2610
2629
|
StorageBucket,
|
|
2611
2630
|
TokenManager,
|
|
2631
|
+
createAdminClient,
|
|
2612
2632
|
createClient,
|
|
2613
2633
|
index_default as default
|
|
2614
2634
|
};
|