@rebasepro/client 0.0.1-canary.f81da60 → 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/auth.d.ts +6 -1
- package/dist/functions.d.ts +49 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.es.js +30 -13
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +30 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
- package/src/auth.ts +20 -8
- package/src/functions.ts +80 -0
- package/src/index.ts +6 -0
- package/src/websocket.ts +7 -3
package/dist/index.umd.js
CHANGED
|
@@ -383,21 +383,18 @@
|
|
|
383
383
|
refreshToken: session.refreshToken
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
async function signInWithGoogle(
|
|
386
|
+
async function signInWithGoogle(tokenOrPayload) {
|
|
387
387
|
const fetchFn = getFetch();
|
|
388
|
+
const body = typeof tokenOrPayload === "string" ? { idToken: tokenOrPayload } : tokenOrPayload;
|
|
388
389
|
const res = await fetchFn(authUrl("/google"), {
|
|
389
390
|
method: "POST",
|
|
390
391
|
headers: { "Content-Type": "application/json" },
|
|
391
|
-
body: JSON.stringify(
|
|
392
|
+
body: JSON.stringify(body)
|
|
392
393
|
});
|
|
393
|
-
const
|
|
394
|
-
if (!res.ok) throwApiError(res.status,
|
|
395
|
-
const session = handleAuthResponse(
|
|
396
|
-
return {
|
|
397
|
-
user: session.user,
|
|
398
|
-
accessToken: session.accessToken,
|
|
399
|
-
refreshToken: session.refreshToken
|
|
400
|
-
};
|
|
394
|
+
const responseBody = await res.json().catch(() => ({}));
|
|
395
|
+
if (!res.ok) throwApiError(res.status, responseBody, res.statusText);
|
|
396
|
+
const session = handleAuthResponse(responseBody, "SIGNED_IN");
|
|
397
|
+
return { user: session.user, accessToken: session.accessToken, refreshToken: session.refreshToken };
|
|
401
398
|
}
|
|
402
399
|
async function signInWithLinkedin(code, redirectUri) {
|
|
403
400
|
const fetchFn = getFetch();
|
|
@@ -1151,6 +1148,23 @@
|
|
|
1151
1148
|
}
|
|
1152
1149
|
return client;
|
|
1153
1150
|
}
|
|
1151
|
+
function createFunctionsClient(transport) {
|
|
1152
|
+
return {
|
|
1153
|
+
async invoke(name, payload, options) {
|
|
1154
|
+
const method = options?.method ?? "POST";
|
|
1155
|
+
const subPath = options?.path ? `/${options.path.replace(/^\//, "")}` : "";
|
|
1156
|
+
const routePath = `/functions/${encodeURIComponent(name)}${subPath}`;
|
|
1157
|
+
const init = { method };
|
|
1158
|
+
if (payload !== void 0 && method !== "GET") {
|
|
1159
|
+
init.body = JSON.stringify(payload);
|
|
1160
|
+
}
|
|
1161
|
+
if (options?.headers) {
|
|
1162
|
+
init.headers = options.headers;
|
|
1163
|
+
}
|
|
1164
|
+
return transport.request(routePath, init);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1154
1168
|
function rehydrateEntity(entity) {
|
|
1155
1169
|
return entity;
|
|
1156
1170
|
}
|
|
@@ -1262,11 +1276,11 @@
|
|
|
1262
1276
|
if (!this.ws) return;
|
|
1263
1277
|
if (token) {
|
|
1264
1278
|
this.authenticate(token).catch((e) => {
|
|
1265
|
-
if (this.ws) console.
|
|
1279
|
+
if (this.ws) console.debug("WebSocket auto-auth skipped:", e?.message || e);
|
|
1266
1280
|
});
|
|
1267
1281
|
}
|
|
1268
1282
|
}).catch((e) => {
|
|
1269
|
-
if (this.ws) console.
|
|
1283
|
+
if (this.ws) console.debug("WebSocket auto-auth skipped:", e?.message || e);
|
|
1270
1284
|
});
|
|
1271
1285
|
}
|
|
1272
1286
|
}
|
|
@@ -1305,7 +1319,7 @@
|
|
|
1305
1319
|
console.debug("WebSocket auto-authenticated");
|
|
1306
1320
|
}
|
|
1307
1321
|
} catch (error) {
|
|
1308
|
-
console.
|
|
1322
|
+
console.debug("WebSocket connected without auth:", error?.message || error);
|
|
1309
1323
|
}
|
|
1310
1324
|
}
|
|
1311
1325
|
this.emit(wasReconnect ? "reconnect" : "connect");
|
|
@@ -2190,6 +2204,7 @@
|
|
|
2190
2204
|
const admin = createAdmin(transport, options.admin);
|
|
2191
2205
|
const cron = createCron(transport, options.cron);
|
|
2192
2206
|
const storage = createStorage(transport);
|
|
2207
|
+
const functions = createFunctionsClient(transport);
|
|
2193
2208
|
const resolvedWsUrl = options.websocketUrl ?? deriveWebSocketUrl(options.baseUrl);
|
|
2194
2209
|
let ws;
|
|
2195
2210
|
if (resolvedWsUrl) {
|
|
@@ -2246,6 +2261,7 @@
|
|
|
2246
2261
|
auth,
|
|
2247
2262
|
admin,
|
|
2248
2263
|
cron,
|
|
2264
|
+
functions,
|
|
2249
2265
|
storage,
|
|
2250
2266
|
ws,
|
|
2251
2267
|
setToken: transport.setToken,
|
|
@@ -2275,6 +2291,7 @@
|
|
|
2275
2291
|
exports2.createAuth = createAuth;
|
|
2276
2292
|
exports2.createCollectionClient = createCollectionClient;
|
|
2277
2293
|
exports2.createCron = createCron;
|
|
2294
|
+
exports2.createFunctionsClient = createFunctionsClient;
|
|
2278
2295
|
exports2.createMemoryStorage = createMemoryStorage;
|
|
2279
2296
|
exports2.createRebaseClient = createRebaseClient;
|
|
2280
2297
|
exports2.createStorage = createStorage;
|