@react-router/architect 0.0.0-experimental-f7761f1cd → 0.0.0-experimental-63fd291ad
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 +59 -0
- package/dist/index.d.ts +32 -42
- package/dist/index.js +235 -161
- package/dist/index.mjs +218 -0
- package/package.json +29 -21
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext, ServerBuild } from 'react-router';
|
|
2
|
+
import { ArcTable } from '@architect/functions/types/tables';
|
|
3
|
+
import { APIGatewayProxyEventV2, APIGatewayProxyHandlerV2 } from 'aws-lambda';
|
|
4
|
+
|
|
5
|
+
interface ArcTableSessionStorageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The Cookie used to store the session id on the client, or options used
|
|
8
|
+
* to automatically create one.
|
|
9
|
+
*/
|
|
10
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
11
|
+
/**
|
|
12
|
+
* The table used to store sessions, or its name as it appears in your
|
|
13
|
+
* project's app.arc file.
|
|
14
|
+
*/
|
|
15
|
+
table: ArcTable<SessionData> | string;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the DynamoDB attribute used to store the session ID.
|
|
18
|
+
* This should be the table's partition key.
|
|
19
|
+
*/
|
|
20
|
+
idx: string;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the DynamoDB attribute used to store the expiration time.
|
|
23
|
+
* If absent, then no TTL will be stored and session records will not expire.
|
|
24
|
+
*/
|
|
25
|
+
ttl?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Session storage using a DynamoDB table managed by Architect.
|
|
29
|
+
*
|
|
30
|
+
* Add the following lines to your project's `app.arc` file:
|
|
31
|
+
*
|
|
32
|
+
* @tables
|
|
33
|
+
* arc-sessions
|
|
34
|
+
* _idx *String
|
|
35
|
+
* _ttl TTL
|
|
36
|
+
*/
|
|
37
|
+
declare function createArcTableSessionStorage<Data = SessionData, FlashData = Data>({ cookie, ...props }: ArcTableSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
38
|
+
|
|
39
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* A function that returns the value to use as `context` in route `loader` and
|
|
42
|
+
* `action` functions.
|
|
43
|
+
*
|
|
44
|
+
* You can think of this as an escape hatch that allows you to pass
|
|
45
|
+
* environment/platform-specific values through to your loader/action.
|
|
46
|
+
*/
|
|
47
|
+
type GetLoadContextFunction = (event: APIGatewayProxyEventV2) => UNSAFE_MiddlewareEnabled extends true ? MaybePromise<RouterContextProvider> : MaybePromise<AppLoadContext>;
|
|
48
|
+
type RequestHandler = APIGatewayProxyHandlerV2;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a request handler for Architect that serves the response using
|
|
51
|
+
* React Router.
|
|
52
|
+
*/
|
|
53
|
+
declare function createRequestHandler({ build, getLoadContext, mode, }: {
|
|
54
|
+
build: ServerBuild;
|
|
55
|
+
getLoadContext?: GetLoadContextFunction;
|
|
56
|
+
mode?: string;
|
|
57
|
+
}): RequestHandler;
|
|
58
|
+
|
|
59
|
+
export { type GetLoadContextFunction, type RequestHandler, createArcTableSessionStorage, createRequestHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
+
import { SessionData, SessionIdStorageStrategy, SessionStorage, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext, ServerBuild } from 'react-router';
|
|
2
|
+
import { ArcTable } from '@architect/functions/types/tables';
|
|
3
|
+
import { APIGatewayProxyEventV2, APIGatewayProxyHandlerV2 } from 'aws-lambda';
|
|
1
4
|
|
|
2
|
-
import { RouterContextProvider, ServerBuild, SessionData, SessionIdStorageStrategy, SessionStorage } from "react-router";
|
|
3
|
-
import { ArcTable } from "@architect/functions/types/tables";
|
|
4
|
-
import { APIGatewayProxyEventV2, APIGatewayProxyHandlerV2 } from "aws-lambda";
|
|
5
|
-
|
|
6
|
-
//#region sessions/arcTableSessionStorage.d.ts
|
|
7
5
|
interface ArcTableSessionStorageOptions {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The Cookie used to store the session id on the client, or options used
|
|
8
|
+
* to automatically create one.
|
|
9
|
+
*/
|
|
10
|
+
cookie?: SessionIdStorageStrategy["cookie"];
|
|
11
|
+
/**
|
|
12
|
+
* The table used to store sessions, or its name as it appears in your
|
|
13
|
+
* project's app.arc file.
|
|
14
|
+
*/
|
|
15
|
+
table: ArcTable<SessionData> | string;
|
|
16
|
+
/**
|
|
17
|
+
* The name of the DynamoDB attribute used to store the session ID.
|
|
18
|
+
* This should be the table's partition key.
|
|
19
|
+
*/
|
|
20
|
+
idx: string;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the DynamoDB attribute used to store the expiration time.
|
|
23
|
+
* If absent, then no TTL will be stored and session records will not expire.
|
|
24
|
+
*/
|
|
25
|
+
ttl?: string;
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
28
|
* Session storage using a DynamoDB table managed by Architect.
|
|
@@ -36,12 +34,8 @@ interface ArcTableSessionStorageOptions {
|
|
|
36
34
|
* _idx *String
|
|
37
35
|
* _ttl TTL
|
|
38
36
|
*/
|
|
39
|
-
declare function createArcTableSessionStorage<Data = SessionData, FlashData = Data>({
|
|
40
|
-
|
|
41
|
-
...props
|
|
42
|
-
}: ArcTableSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region server.d.ts
|
|
37
|
+
declare function createArcTableSessionStorage<Data = SessionData, FlashData = Data>({ cookie, ...props }: ArcTableSessionStorageOptions): SessionStorage<Data, FlashData>;
|
|
38
|
+
|
|
45
39
|
type MaybePromise<T> = T | Promise<T>;
|
|
46
40
|
/**
|
|
47
41
|
* A function that returns the value to use as `context` in route `loader` and
|
|
@@ -50,20 +44,16 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
50
44
|
* You can think of this as an escape hatch that allows you to pass
|
|
51
45
|
* environment/platform-specific values through to your loader/action.
|
|
52
46
|
*/
|
|
53
|
-
type GetLoadContextFunction = (event: APIGatewayProxyEventV2) => MaybePromise<RouterContextProvider>;
|
|
47
|
+
type GetLoadContextFunction = (event: APIGatewayProxyEventV2) => UNSAFE_MiddlewareEnabled extends true ? MaybePromise<RouterContextProvider> : MaybePromise<AppLoadContext>;
|
|
54
48
|
type RequestHandler = APIGatewayProxyHandlerV2;
|
|
55
49
|
/**
|
|
56
50
|
* Returns a request handler for Architect that serves the response using
|
|
57
51
|
* React Router.
|
|
58
52
|
*/
|
|
59
|
-
declare function createRequestHandler({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}: {
|
|
64
|
-
build: ServerBuild;
|
|
65
|
-
getLoadContext?: GetLoadContextFunction;
|
|
66
|
-
mode?: string;
|
|
53
|
+
declare function createRequestHandler({ build, getLoadContext, mode, }: {
|
|
54
|
+
build: ServerBuild;
|
|
55
|
+
getLoadContext?: GetLoadContextFunction;
|
|
56
|
+
mode?: string;
|
|
67
57
|
}): RequestHandler;
|
|
68
|
-
|
|
69
|
-
export { type GetLoadContextFunction, type RequestHandler, createArcTableSessionStorage, createRequestHandler };
|
|
58
|
+
|
|
59
|
+
export { type GetLoadContextFunction, type RequestHandler, createArcTableSessionStorage, createRequestHandler };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/architect v0.0.0-experimental-
|
|
2
|
+
* @react-router/architect v0.0.0-experimental-63fd291ad
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,174 +8,248 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
11
|
+
"use strict";
|
|
12
|
+
var __create = Object.create;
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
17
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(from))
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
+
}
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
|
|
40
|
+
// index.ts
|
|
41
|
+
var index_exports = {};
|
|
42
|
+
__export(index_exports, {
|
|
43
|
+
createArcTableSessionStorage: () => createArcTableSessionStorage,
|
|
44
|
+
createRequestHandler: () => createRequestHandler
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
|
|
48
|
+
// sessions/arcTableSessionStorage.ts
|
|
49
|
+
var import_react_router = require("react-router");
|
|
50
|
+
var import_functions = __toESM(require("@architect/functions"));
|
|
51
|
+
function createArcTableSessionStorage({
|
|
52
|
+
cookie,
|
|
53
|
+
...props
|
|
54
|
+
}) {
|
|
55
|
+
async function getTable() {
|
|
56
|
+
if (typeof props.table === "string") {
|
|
57
|
+
let tables = await import_functions.default.tables();
|
|
58
|
+
return tables[props.table];
|
|
59
|
+
} else {
|
|
60
|
+
return props.table;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (0, import_react_router.createSessionStorage)({
|
|
64
|
+
cookie,
|
|
65
|
+
async createData(data, expires) {
|
|
66
|
+
let table = await getTable();
|
|
67
|
+
while (true) {
|
|
68
|
+
let randomBytes = crypto.getRandomValues(new Uint8Array(8));
|
|
69
|
+
let id = [...randomBytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
70
|
+
if (await table.get({ [props.idx]: id })) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let params = {
|
|
74
|
+
[props.idx]: id,
|
|
75
|
+
...data
|
|
76
|
+
};
|
|
77
|
+
if (props.ttl) {
|
|
78
|
+
params[props.ttl] = expires ? Math.round(expires.getTime() / 1e3) : void 0;
|
|
79
|
+
}
|
|
80
|
+
await table.put(params);
|
|
81
|
+
return id;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
async readData(id) {
|
|
85
|
+
let table = await getTable();
|
|
86
|
+
let data = await table.get({ [props.idx]: id });
|
|
87
|
+
if (data) {
|
|
88
|
+
delete data[props.idx];
|
|
89
|
+
if (props.ttl) delete data[props.ttl];
|
|
90
|
+
}
|
|
91
|
+
return data;
|
|
92
|
+
},
|
|
93
|
+
async updateData(id, data, expires) {
|
|
94
|
+
let table = await getTable();
|
|
95
|
+
let params = {
|
|
96
|
+
[props.idx]: id,
|
|
97
|
+
...data
|
|
98
|
+
};
|
|
99
|
+
if (props.ttl) {
|
|
100
|
+
params[props.ttl] = expires ? Math.round(expires.getTime() / 1e3) : void 0;
|
|
101
|
+
}
|
|
102
|
+
await table.put(params);
|
|
103
|
+
},
|
|
104
|
+
async deleteData(id) {
|
|
105
|
+
let table = await getTable();
|
|
106
|
+
await table.delete({ [props.idx]: id });
|
|
107
|
+
}
|
|
108
|
+
});
|
|
67
109
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
|
|
111
|
+
// server.ts
|
|
112
|
+
var import_react_router2 = require("react-router");
|
|
113
|
+
var import_node = require("@react-router/node");
|
|
114
|
+
|
|
115
|
+
// binaryTypes.ts
|
|
116
|
+
var binaryTypes = [
|
|
117
|
+
"application/octet-stream",
|
|
118
|
+
// Docs
|
|
119
|
+
"application/epub+zip",
|
|
120
|
+
"application/msword",
|
|
121
|
+
"application/pdf",
|
|
122
|
+
"application/rtf",
|
|
123
|
+
"application/vnd.amazon.ebook",
|
|
124
|
+
"application/vnd.ms-excel",
|
|
125
|
+
"application/vnd.ms-powerpoint",
|
|
126
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
127
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
128
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
129
|
+
// Fonts
|
|
130
|
+
"font/otf",
|
|
131
|
+
"font/woff",
|
|
132
|
+
"font/woff2",
|
|
133
|
+
// Images
|
|
134
|
+
"image/avif",
|
|
135
|
+
"image/bmp",
|
|
136
|
+
"image/gif",
|
|
137
|
+
"image/jpeg",
|
|
138
|
+
"image/png",
|
|
139
|
+
"image/tiff",
|
|
140
|
+
"image/vnd.microsoft.icon",
|
|
141
|
+
"image/webp",
|
|
142
|
+
// Audio
|
|
143
|
+
"audio/3gpp",
|
|
144
|
+
"audio/aac",
|
|
145
|
+
"audio/basic",
|
|
146
|
+
"audio/mpeg",
|
|
147
|
+
"audio/ogg",
|
|
148
|
+
"audio/wav",
|
|
149
|
+
"audio/webm",
|
|
150
|
+
"audio/x-aiff",
|
|
151
|
+
"audio/x-midi",
|
|
152
|
+
"audio/x-wav",
|
|
153
|
+
// Video
|
|
154
|
+
"video/3gpp",
|
|
155
|
+
"video/mp2t",
|
|
156
|
+
"video/mpeg",
|
|
157
|
+
"video/ogg",
|
|
158
|
+
"video/quicktime",
|
|
159
|
+
"video/webm",
|
|
160
|
+
"video/x-msvideo",
|
|
161
|
+
// Archives
|
|
162
|
+
"application/java-archive",
|
|
163
|
+
"application/vnd.apple.installer+xml",
|
|
164
|
+
"application/x-7z-compressed",
|
|
165
|
+
"application/x-apple-diskimage",
|
|
166
|
+
"application/x-bzip",
|
|
167
|
+
"application/x-bzip2",
|
|
168
|
+
"application/x-gzip",
|
|
169
|
+
"application/x-java-archive",
|
|
170
|
+
"application/x-rar-compressed",
|
|
171
|
+
"application/x-tar",
|
|
172
|
+
"application/x-zip",
|
|
173
|
+
"application/zip"
|
|
126
174
|
];
|
|
127
175
|
function isBinaryType(contentType) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
176
|
+
if (!contentType) return false;
|
|
177
|
+
let [test] = contentType.split(";");
|
|
178
|
+
return binaryTypes.includes(test);
|
|
131
179
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
180
|
+
|
|
181
|
+
// server.ts
|
|
182
|
+
function createRequestHandler({
|
|
183
|
+
build,
|
|
184
|
+
getLoadContext,
|
|
185
|
+
mode = process.env.NODE_ENV
|
|
186
|
+
}) {
|
|
187
|
+
let handleRequest = (0, import_react_router2.createRequestHandler)(build, mode);
|
|
188
|
+
return async (event) => {
|
|
189
|
+
let request = createReactRouterRequest(event);
|
|
190
|
+
let loadContext = await getLoadContext?.(event);
|
|
191
|
+
let response = await handleRequest(request, loadContext);
|
|
192
|
+
return sendReactRouterResponse(response);
|
|
193
|
+
};
|
|
143
194
|
}
|
|
144
195
|
function createReactRouterRequest(event) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
196
|
+
let host = event.headers["x-forwarded-host"] || event.headers.host;
|
|
197
|
+
let search = event.rawQueryString.length ? `?${event.rawQueryString}` : "";
|
|
198
|
+
let scheme = process.env.ARC_SANDBOX ? "http" : "https";
|
|
199
|
+
let url = new URL(`${scheme}://${host}${event.rawPath}${search}`);
|
|
200
|
+
let isFormData = event.headers["content-type"]?.includes(
|
|
201
|
+
"multipart/form-data"
|
|
202
|
+
);
|
|
203
|
+
let controller = new AbortController();
|
|
204
|
+
return new Request(url.href, {
|
|
205
|
+
method: event.requestContext.http.method,
|
|
206
|
+
headers: createReactRouterHeaders(event.headers, event.cookies),
|
|
207
|
+
signal: controller.signal,
|
|
208
|
+
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body
|
|
209
|
+
});
|
|
157
210
|
}
|
|
158
211
|
function createReactRouterHeaders(requestHeaders, requestCookies) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
212
|
+
let headers = new Headers();
|
|
213
|
+
for (let [header, value] of Object.entries(requestHeaders)) {
|
|
214
|
+
if (value) {
|
|
215
|
+
headers.append(header, value);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (requestCookies) {
|
|
219
|
+
headers.append("Cookie", requestCookies.join("; "));
|
|
220
|
+
}
|
|
221
|
+
return headers;
|
|
163
222
|
}
|
|
164
223
|
async function sendReactRouterResponse(nodeResponse) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
224
|
+
let cookies = [];
|
|
225
|
+
for (let [key, value] of nodeResponse.headers.entries()) {
|
|
226
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
227
|
+
cookies.push(value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (cookies.length) {
|
|
231
|
+
nodeResponse.headers.delete("Set-Cookie");
|
|
232
|
+
}
|
|
233
|
+
let contentType = nodeResponse.headers.get("Content-Type");
|
|
234
|
+
let isBase64Encoded = isBinaryType(contentType);
|
|
235
|
+
let body;
|
|
236
|
+
if (nodeResponse.body) {
|
|
237
|
+
if (isBase64Encoded) {
|
|
238
|
+
body = await (0, import_node.readableStreamToString)(nodeResponse.body, "base64");
|
|
239
|
+
} else {
|
|
240
|
+
body = await nodeResponse.text();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
statusCode: nodeResponse.status,
|
|
245
|
+
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
246
|
+
cookies,
|
|
247
|
+
body,
|
|
248
|
+
isBase64Encoded
|
|
249
|
+
};
|
|
179
250
|
}
|
|
180
|
-
|
|
181
|
-
|
|
251
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
+
0 && (module.exports = {
|
|
253
|
+
createArcTableSessionStorage,
|
|
254
|
+
createRequestHandler
|
|
255
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/architect v0.0.0-experimental-63fd291ad
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// sessions/arcTableSessionStorage.ts
|
|
13
|
+
import { createSessionStorage } from "react-router";
|
|
14
|
+
import arc from "@architect/functions";
|
|
15
|
+
function createArcTableSessionStorage({
|
|
16
|
+
cookie,
|
|
17
|
+
...props
|
|
18
|
+
}) {
|
|
19
|
+
async function getTable() {
|
|
20
|
+
if (typeof props.table === "string") {
|
|
21
|
+
let tables = await arc.tables();
|
|
22
|
+
return tables[props.table];
|
|
23
|
+
} else {
|
|
24
|
+
return props.table;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return createSessionStorage({
|
|
28
|
+
cookie,
|
|
29
|
+
async createData(data, expires) {
|
|
30
|
+
let table = await getTable();
|
|
31
|
+
while (true) {
|
|
32
|
+
let randomBytes = crypto.getRandomValues(new Uint8Array(8));
|
|
33
|
+
let id = [...randomBytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
34
|
+
if (await table.get({ [props.idx]: id })) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let params = {
|
|
38
|
+
[props.idx]: id,
|
|
39
|
+
...data
|
|
40
|
+
};
|
|
41
|
+
if (props.ttl) {
|
|
42
|
+
params[props.ttl] = expires ? Math.round(expires.getTime() / 1e3) : void 0;
|
|
43
|
+
}
|
|
44
|
+
await table.put(params);
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
async readData(id) {
|
|
49
|
+
let table = await getTable();
|
|
50
|
+
let data = await table.get({ [props.idx]: id });
|
|
51
|
+
if (data) {
|
|
52
|
+
delete data[props.idx];
|
|
53
|
+
if (props.ttl) delete data[props.ttl];
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
},
|
|
57
|
+
async updateData(id, data, expires) {
|
|
58
|
+
let table = await getTable();
|
|
59
|
+
let params = {
|
|
60
|
+
[props.idx]: id,
|
|
61
|
+
...data
|
|
62
|
+
};
|
|
63
|
+
if (props.ttl) {
|
|
64
|
+
params[props.ttl] = expires ? Math.round(expires.getTime() / 1e3) : void 0;
|
|
65
|
+
}
|
|
66
|
+
await table.put(params);
|
|
67
|
+
},
|
|
68
|
+
async deleteData(id) {
|
|
69
|
+
let table = await getTable();
|
|
70
|
+
await table.delete({ [props.idx]: id });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// server.ts
|
|
76
|
+
import { createRequestHandler as createReactRouterRequestHandler } from "react-router";
|
|
77
|
+
import { readableStreamToString } from "@react-router/node";
|
|
78
|
+
|
|
79
|
+
// binaryTypes.ts
|
|
80
|
+
var binaryTypes = [
|
|
81
|
+
"application/octet-stream",
|
|
82
|
+
// Docs
|
|
83
|
+
"application/epub+zip",
|
|
84
|
+
"application/msword",
|
|
85
|
+
"application/pdf",
|
|
86
|
+
"application/rtf",
|
|
87
|
+
"application/vnd.amazon.ebook",
|
|
88
|
+
"application/vnd.ms-excel",
|
|
89
|
+
"application/vnd.ms-powerpoint",
|
|
90
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
91
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
92
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
93
|
+
// Fonts
|
|
94
|
+
"font/otf",
|
|
95
|
+
"font/woff",
|
|
96
|
+
"font/woff2",
|
|
97
|
+
// Images
|
|
98
|
+
"image/avif",
|
|
99
|
+
"image/bmp",
|
|
100
|
+
"image/gif",
|
|
101
|
+
"image/jpeg",
|
|
102
|
+
"image/png",
|
|
103
|
+
"image/tiff",
|
|
104
|
+
"image/vnd.microsoft.icon",
|
|
105
|
+
"image/webp",
|
|
106
|
+
// Audio
|
|
107
|
+
"audio/3gpp",
|
|
108
|
+
"audio/aac",
|
|
109
|
+
"audio/basic",
|
|
110
|
+
"audio/mpeg",
|
|
111
|
+
"audio/ogg",
|
|
112
|
+
"audio/wav",
|
|
113
|
+
"audio/webm",
|
|
114
|
+
"audio/x-aiff",
|
|
115
|
+
"audio/x-midi",
|
|
116
|
+
"audio/x-wav",
|
|
117
|
+
// Video
|
|
118
|
+
"video/3gpp",
|
|
119
|
+
"video/mp2t",
|
|
120
|
+
"video/mpeg",
|
|
121
|
+
"video/ogg",
|
|
122
|
+
"video/quicktime",
|
|
123
|
+
"video/webm",
|
|
124
|
+
"video/x-msvideo",
|
|
125
|
+
// Archives
|
|
126
|
+
"application/java-archive",
|
|
127
|
+
"application/vnd.apple.installer+xml",
|
|
128
|
+
"application/x-7z-compressed",
|
|
129
|
+
"application/x-apple-diskimage",
|
|
130
|
+
"application/x-bzip",
|
|
131
|
+
"application/x-bzip2",
|
|
132
|
+
"application/x-gzip",
|
|
133
|
+
"application/x-java-archive",
|
|
134
|
+
"application/x-rar-compressed",
|
|
135
|
+
"application/x-tar",
|
|
136
|
+
"application/x-zip",
|
|
137
|
+
"application/zip"
|
|
138
|
+
];
|
|
139
|
+
function isBinaryType(contentType) {
|
|
140
|
+
if (!contentType) return false;
|
|
141
|
+
let [test] = contentType.split(";");
|
|
142
|
+
return binaryTypes.includes(test);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// server.ts
|
|
146
|
+
function createRequestHandler({
|
|
147
|
+
build,
|
|
148
|
+
getLoadContext,
|
|
149
|
+
mode = process.env.NODE_ENV
|
|
150
|
+
}) {
|
|
151
|
+
let handleRequest = createReactRouterRequestHandler(build, mode);
|
|
152
|
+
return async (event) => {
|
|
153
|
+
let request = createReactRouterRequest(event);
|
|
154
|
+
let loadContext = await getLoadContext?.(event);
|
|
155
|
+
let response = await handleRequest(request, loadContext);
|
|
156
|
+
return sendReactRouterResponse(response);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function createReactRouterRequest(event) {
|
|
160
|
+
let host = event.headers["x-forwarded-host"] || event.headers.host;
|
|
161
|
+
let search = event.rawQueryString.length ? `?${event.rawQueryString}` : "";
|
|
162
|
+
let scheme = process.env.ARC_SANDBOX ? "http" : "https";
|
|
163
|
+
let url = new URL(`${scheme}://${host}${event.rawPath}${search}`);
|
|
164
|
+
let isFormData = event.headers["content-type"]?.includes(
|
|
165
|
+
"multipart/form-data"
|
|
166
|
+
);
|
|
167
|
+
let controller = new AbortController();
|
|
168
|
+
return new Request(url.href, {
|
|
169
|
+
method: event.requestContext.http.method,
|
|
170
|
+
headers: createReactRouterHeaders(event.headers, event.cookies),
|
|
171
|
+
signal: controller.signal,
|
|
172
|
+
body: event.body && event.isBase64Encoded ? isFormData ? Buffer.from(event.body, "base64") : Buffer.from(event.body, "base64").toString() : event.body
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function createReactRouterHeaders(requestHeaders, requestCookies) {
|
|
176
|
+
let headers = new Headers();
|
|
177
|
+
for (let [header, value] of Object.entries(requestHeaders)) {
|
|
178
|
+
if (value) {
|
|
179
|
+
headers.append(header, value);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (requestCookies) {
|
|
183
|
+
headers.append("Cookie", requestCookies.join("; "));
|
|
184
|
+
}
|
|
185
|
+
return headers;
|
|
186
|
+
}
|
|
187
|
+
async function sendReactRouterResponse(nodeResponse) {
|
|
188
|
+
let cookies = [];
|
|
189
|
+
for (let [key, value] of nodeResponse.headers.entries()) {
|
|
190
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
191
|
+
cookies.push(value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (cookies.length) {
|
|
195
|
+
nodeResponse.headers.delete("Set-Cookie");
|
|
196
|
+
}
|
|
197
|
+
let contentType = nodeResponse.headers.get("Content-Type");
|
|
198
|
+
let isBase64Encoded = isBinaryType(contentType);
|
|
199
|
+
let body;
|
|
200
|
+
if (nodeResponse.body) {
|
|
201
|
+
if (isBase64Encoded) {
|
|
202
|
+
body = await readableStreamToString(nodeResponse.body, "base64");
|
|
203
|
+
} else {
|
|
204
|
+
body = await nodeResponse.text();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
statusCode: nodeResponse.status,
|
|
209
|
+
headers: Object.fromEntries(nodeResponse.headers.entries()),
|
|
210
|
+
cookies,
|
|
211
|
+
body,
|
|
212
|
+
isBase64Encoded
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
export {
|
|
216
|
+
createArcTableSessionStorage,
|
|
217
|
+
createRequestHandler
|
|
218
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/architect",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.0-experimental-f7761f1cd",
|
|
3
|
+
"version": "0.0.0-experimental-63fd291ad",
|
|
5
4
|
"description": "Architect server request handler for React Router",
|
|
6
5
|
"bugs": {
|
|
7
6
|
"url": "https://github.com/remix-run/react-router/issues"
|
|
@@ -16,15 +15,25 @@
|
|
|
16
15
|
"typings": "dist/index.d.ts",
|
|
17
16
|
"exports": {
|
|
18
17
|
".": {
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
"node": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"module-sync": "./dist/index.mjs",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"default": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"default": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
22
31
|
},
|
|
23
32
|
"./package.json": "./package.json"
|
|
24
33
|
},
|
|
25
34
|
"wireit": {
|
|
26
35
|
"build": {
|
|
27
|
-
"command": "
|
|
36
|
+
"command": "tsup",
|
|
28
37
|
"files": [
|
|
29
38
|
"../../pnpm-workspace.yaml",
|
|
30
39
|
"sessions/**",
|
|
@@ -38,26 +47,25 @@
|
|
|
38
47
|
}
|
|
39
48
|
},
|
|
40
49
|
"dependencies": {
|
|
41
|
-
"@architect/functions": "^
|
|
42
|
-
"@types/aws-lambda": "^8.10.
|
|
50
|
+
"@architect/functions": "^7.0.0",
|
|
51
|
+
"@types/aws-lambda": "^8.10.82"
|
|
43
52
|
},
|
|
44
53
|
"devDependencies": {
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/
|
|
47
|
-
"@types/node": "^22.19.19",
|
|
54
|
+
"@types/lambda-tester": "^3.6.1",
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
48
56
|
"lambda-tester": "^4.0.1",
|
|
49
|
-
"react": "^19.2.
|
|
50
|
-
"react-dom": "^19.2.
|
|
51
|
-
"
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"wireit": "0.14.
|
|
54
|
-
"@react-router/node": "0.0.0-experimental-
|
|
55
|
-
"react-router": "0.0.0-experimental-
|
|
57
|
+
"react": "^19.2.3",
|
|
58
|
+
"react-dom": "^19.2.3",
|
|
59
|
+
"tsup": "^8.3.0",
|
|
60
|
+
"typescript": "^5.4.5",
|
|
61
|
+
"wireit": "0.14.9",
|
|
62
|
+
"@react-router/node": "0.0.0-experimental-63fd291ad",
|
|
63
|
+
"react-router": "0.0.0-experimental-63fd291ad"
|
|
56
64
|
},
|
|
57
65
|
"peerDependencies": {
|
|
58
66
|
"typescript": "^5.1.0 || ^6.0.0",
|
|
59
|
-
"
|
|
60
|
-
"react-router": "^0.0.0-experimental-
|
|
67
|
+
"react-router": "^0.0.0-experimental-63fd291ad",
|
|
68
|
+
"@react-router/node": "^0.0.0-experimental-63fd291ad"
|
|
61
69
|
},
|
|
62
70
|
"peerDependenciesMeta": {
|
|
63
71
|
"typescript": {
|
|
@@ -65,7 +73,7 @@
|
|
|
65
73
|
}
|
|
66
74
|
},
|
|
67
75
|
"engines": {
|
|
68
|
-
"node": ">=
|
|
76
|
+
"node": ">=20.0.0"
|
|
69
77
|
},
|
|
70
78
|
"files": [
|
|
71
79
|
"dist/",
|