@instantdb/core 0.22.90-experimental.drewh-ssr.20312174628.1 → 0.22.90-experimental.drewh-ssr.20347747146.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/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +4 -2
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/createRouteHandler.d.ts +0 -2
- package/dist/commonjs/createRouteHandler.d.ts.map +1 -1
- package/dist/commonjs/createRouteHandler.js +43 -34
- package/dist/commonjs/createRouteHandler.js.map +1 -1
- package/dist/commonjs/framework.d.ts.map +1 -1
- package/dist/commonjs/framework.js +1 -0
- package/dist/commonjs/framework.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +4 -2
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/createRouteHandler.d.ts +0 -2
- package/dist/esm/createRouteHandler.d.ts.map +1 -1
- package/dist/esm/createRouteHandler.js +43 -34
- package/dist/esm/createRouteHandler.js.map +1 -1
- package/dist/esm/framework.d.ts.map +1 -1
- package/dist/esm/framework.js +1 -0
- package/dist/esm/framework.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/standalone/index.js +93 -80
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +4 -2
- package/src/createRouteHandler.ts +38 -26
- package/src/framework.ts +1 -0
- package/src/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/core",
|
|
3
|
-
"version": "0.22.90-experimental.drewh-ssr.
|
|
3
|
+
"version": "0.22.90-experimental.drewh-ssr.20347747146.1",
|
|
4
4
|
"description": "Instant's core local abstraction",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mutative": "^1.0.10",
|
|
55
55
|
"uuid": "^11.1.0",
|
|
56
|
-
"@instantdb/version": "0.22.90-experimental.drewh-ssr.
|
|
56
|
+
"@instantdb/version": "0.22.90-experimental.drewh-ssr.20347747146.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest",
|
package/src/Reactor.js
CHANGED
|
@@ -2048,11 +2048,13 @@ export default class Reactor {
|
|
|
2048
2048
|
}
|
|
2049
2049
|
|
|
2050
2050
|
async syncUserToEndpoint(user) {
|
|
2051
|
-
if (this.config.
|
|
2051
|
+
if (this.config.firstPartyPath) {
|
|
2052
2052
|
try {
|
|
2053
|
-
fetch(this.config.
|
|
2053
|
+
fetch(this.config.firstPartyPath + '/', {
|
|
2054
2054
|
method: 'POST',
|
|
2055
2055
|
body: JSON.stringify({
|
|
2056
|
+
type: 'sync-user',
|
|
2057
|
+
appId: this.config.appId,
|
|
2056
2058
|
user: user,
|
|
2057
2059
|
}),
|
|
2058
2060
|
headers: {
|
|
@@ -1,44 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (body.user && body.user.refresh_token) {
|
|
8
|
-
return new Response('sync', {
|
|
1
|
+
import type { User } from './clientTypes.js';
|
|
2
|
+
|
|
3
|
+
export const createInstantRouteHandler = (config: { appId: string }) => {
|
|
4
|
+
function createUserSyncResponse(user: User | null) {
|
|
5
|
+
if (user && user.refresh_token) {
|
|
6
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
9
7
|
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
10
9
|
// 7 day expiry
|
|
11
|
-
'Set-Cookie': `
|
|
10
|
+
'Set-Cookie': `instant_user_${config.appId}=${JSON.stringify(user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,
|
|
12
11
|
},
|
|
13
12
|
});
|
|
14
13
|
} else {
|
|
15
|
-
return new Response(
|
|
14
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
16
15
|
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
17
|
// remove the cookie (some browsers)
|
|
18
|
-
'Set-Cookie': `
|
|
18
|
+
'Set-Cookie': `instant_user_${config.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function errorResponse(status: number, message: string) {
|
|
25
|
+
return new Response(JSON.stringify({ ok: false, error: message }), {
|
|
26
|
+
status,
|
|
27
|
+
headers: { 'Content-Type': 'application/json' },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
return {
|
|
25
|
-
GET: async (_req: Request) => {
|
|
26
|
-
return new Response('Method not allowed', {
|
|
27
|
-
status: 405,
|
|
28
|
-
statusText: 'Method Not Allowed',
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
32
|
POST: async (req: Request) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
let body: { type?: string; appId?: string; user?: User | null };
|
|
34
|
+
try {
|
|
35
|
+
body = await req.json();
|
|
36
|
+
} catch {
|
|
37
|
+
return errorResponse(400, 'Invalid JSON body');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!body.type) {
|
|
41
|
+
return errorResponse(400, 'Missing "type" field');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (body.appId !== config.appId) {
|
|
45
|
+
return errorResponse(403, 'App ID mismatch');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
switch (body.type) {
|
|
49
|
+
case 'sync-user':
|
|
50
|
+
return createUserSyncResponse(body.user ?? null);
|
|
51
|
+
default:
|
|
52
|
+
return errorResponse(400, `Unknown type: ${body.type}`);
|
|
38
53
|
}
|
|
39
|
-
return new Response('Route not found', {
|
|
40
|
-
status: 404,
|
|
41
|
-
});
|
|
42
54
|
},
|
|
43
55
|
};
|
|
44
56
|
};
|
package/src/framework.ts
CHANGED
package/src/index.ts
CHANGED