@kubohiroya/turbowarp-http-server 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/LICENSE +373 -0
- package/README.ja.md +346 -0
- package/README.md +874 -0
- package/dist/auth/digest-file.d.ts +17 -0
- package/dist/auth/digest-file.js +90 -0
- package/dist/auth/digest-file.js.map +1 -0
- package/dist/auth/digest.d.ts +23 -0
- package/dist/auth/digest.js +139 -0
- package/dist/auth/digest.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +156 -0
- package/dist/cli.js.map +1 -0
- package/dist/community.d.ts +81 -0
- package/dist/community.js +689 -0
- package/dist/community.js.map +1 -0
- package/dist/digest-cli.d.ts +1 -0
- package/dist/digest-cli.js +159 -0
- package/dist/digest-cli.js.map +1 -0
- package/dist/extension-manifest.json +441 -0
- package/dist/protocol.d.ts +59 -0
- package/dist/protocol.js +71 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server.d.ts +89 -0
- package/dist/server.js +650 -0
- package/dist/server.js.map +1 -0
- package/dist/turbowarp-http-server.js +1110 -0
- package/docs/deployment-targets.ja.md +274 -0
- package/docs/turbowarp-http-server.architecture.html +15149 -0
- package/docs/turbowarp-http-server.architecture.json +1014 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.1440x900.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.dark.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.2048x1320.light.png +0 -0
- package/docs/turbowarp-http-server.architecture.visual-check.html +32 -0
- package/docs/turbowarp-http-server.architecture.visual-check.json +547 -0
- package/examples/01-hello-form/README.ja.md +46 -0
- package/examples/01-hello-form/server.mjs +59 -0
- package/examples/02-visitor-counter/README.ja.md +39 -0
- package/examples/02-visitor-counter/server.mjs +44 -0
- package/examples/03-message-board/README.ja.md +47 -0
- package/examples/03-message-board/server.mjs +72 -0
- package/examples/04-image-upload/README.ja.md +46 -0
- package/examples/04-image-upload/server.mjs +149 -0
- package/examples/05-live-camera/README.ja.md +47 -0
- package/examples/05-live-camera/server.mjs +147 -0
- package/examples/06-scratch-like-community/README.ja.md +82 -0
- package/examples/06-scratch-like-community/server.mjs +17 -0
- package/examples/README.ja.md +20 -0
- package/package.json +75 -0
- package/schemas/extension-manifest.schema.json +49 -0
- package/src/auth/digest-file.ts +115 -0
- package/src/auth/digest.ts +170 -0
- package/src/block-definitions.json +417 -0
- package/src/cli.ts +172 -0
- package/src/community.ts +815 -0
- package/src/config.ts +12 -0
- package/src/digest-cli.ts +178 -0
- package/src/extension-manifest.ts +149 -0
- package/src/extension.ts +713 -0
- package/src/globals.d.ts +30 -0
- package/src/index.ts +8 -0
- package/src/protocol.ts +132 -0
- package/src/server.ts +880 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const HTTP_BRIDGE_PROTOCOL: "turbowarp-http-server";
|
|
2
|
+
export declare const HTTP_BRIDGE_PROTOCOL_VERSION: 1;
|
|
3
|
+
export interface BridgeTextBody {
|
|
4
|
+
kind: 'text';
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BridgeEmptyBody {
|
|
8
|
+
kind: 'empty';
|
|
9
|
+
}
|
|
10
|
+
export interface BridgeUnsupportedBody {
|
|
11
|
+
kind: 'unsupported';
|
|
12
|
+
reason: string;
|
|
13
|
+
}
|
|
14
|
+
export type BridgeBody = BridgeTextBody | BridgeEmptyBody | BridgeUnsupportedBody;
|
|
15
|
+
export interface BridgeAuthContext {
|
|
16
|
+
type: string;
|
|
17
|
+
username?: string;
|
|
18
|
+
provider?: string;
|
|
19
|
+
profile?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface BridgeRequestMessage {
|
|
22
|
+
type: 'request';
|
|
23
|
+
protocol: typeof HTTP_BRIDGE_PROTOCOL;
|
|
24
|
+
version: typeof HTTP_BRIDGE_PROTOCOL_VERSION;
|
|
25
|
+
id: string;
|
|
26
|
+
method: string;
|
|
27
|
+
url: string;
|
|
28
|
+
path: string;
|
|
29
|
+
route: string;
|
|
30
|
+
pathParams: Record<string, string>;
|
|
31
|
+
query: Record<string, string[]>;
|
|
32
|
+
headers: Record<string, string[]>;
|
|
33
|
+
body: BridgeBody;
|
|
34
|
+
clientAddress: string;
|
|
35
|
+
auth?: BridgeAuthContext;
|
|
36
|
+
}
|
|
37
|
+
export interface BridgeResponseMessage {
|
|
38
|
+
type: 'response';
|
|
39
|
+
id: string;
|
|
40
|
+
status: number;
|
|
41
|
+
headers: Record<string, string[]>;
|
|
42
|
+
body: BridgeBody;
|
|
43
|
+
}
|
|
44
|
+
export interface BridgeErrorMessage {
|
|
45
|
+
type: 'error';
|
|
46
|
+
id?: string;
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
export type BridgeClientMessage = BridgeResponseMessage | BridgeErrorMessage;
|
|
50
|
+
export declare function normalizeHeaderName(name: string): string;
|
|
51
|
+
export declare function isValidHttpStatus(status: number): boolean;
|
|
52
|
+
export declare function isBodyForbidden(method: string, status: number): boolean;
|
|
53
|
+
export declare function isForbiddenResponseHeader(name: string): boolean;
|
|
54
|
+
export declare function validateHeaderName(name: string): boolean;
|
|
55
|
+
export declare function validateHeaderValue(value: string): boolean;
|
|
56
|
+
export declare function firstValue(values: readonly string[] | undefined): string;
|
|
57
|
+
export declare function parseBridgeClientMessage(value: string): BridgeClientMessage | null;
|
|
58
|
+
export declare function requireHeaderRecord(value: unknown): Record<string, string[]>;
|
|
59
|
+
export declare function requireBridgeBody(value: unknown): BridgeBody;
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const HTTP_BRIDGE_PROTOCOL = 'turbowarp-http-server';
|
|
2
|
+
export const HTTP_BRIDGE_PROTOCOL_VERSION = 1;
|
|
3
|
+
export function normalizeHeaderName(name) {
|
|
4
|
+
return name.trim().toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
export function isValidHttpStatus(status) {
|
|
7
|
+
return Number.isInteger(status) && status >= 100 && status <= 599;
|
|
8
|
+
}
|
|
9
|
+
export function isBodyForbidden(method, status) {
|
|
10
|
+
return method.toUpperCase() === 'HEAD' || status === 204 || status === 205 || status === 304;
|
|
11
|
+
}
|
|
12
|
+
export function isForbiddenResponseHeader(name) {
|
|
13
|
+
return ['connection', 'content-length', 'transfer-encoding', 'upgrade'].includes(normalizeHeaderName(name));
|
|
14
|
+
}
|
|
15
|
+
export function validateHeaderName(name) {
|
|
16
|
+
return /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(name);
|
|
17
|
+
}
|
|
18
|
+
export function validateHeaderValue(value) {
|
|
19
|
+
return !/[\r\n]/.test(value);
|
|
20
|
+
}
|
|
21
|
+
export function firstValue(values) {
|
|
22
|
+
return values?.[0] ?? '';
|
|
23
|
+
}
|
|
24
|
+
export function parseBridgeClientMessage(value) {
|
|
25
|
+
try {
|
|
26
|
+
const parsed = JSON.parse(value);
|
|
27
|
+
if (parsed.type === 'response' && typeof parsed.id === 'string') {
|
|
28
|
+
return {
|
|
29
|
+
type: 'response',
|
|
30
|
+
id: parsed.id,
|
|
31
|
+
status: typeof parsed.status === 'number' ? parsed.status : 200,
|
|
32
|
+
headers: requireHeaderRecord(parsed.headers),
|
|
33
|
+
body: requireBridgeBody(parsed.body)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (parsed.type === 'error') {
|
|
37
|
+
const error = {
|
|
38
|
+
type: 'error',
|
|
39
|
+
message: typeof parsed.message === 'string' ? parsed.message : 'Bridge error.'
|
|
40
|
+
};
|
|
41
|
+
if (typeof parsed.id === 'string')
|
|
42
|
+
error.id = parsed.id;
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
export function requireHeaderRecord(value) {
|
|
52
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
53
|
+
return {};
|
|
54
|
+
const result = {};
|
|
55
|
+
for (const [name, rawValues] of Object.entries(value)) {
|
|
56
|
+
const values = Array.isArray(rawValues) ? rawValues : [rawValues];
|
|
57
|
+
result[name] = values.map((item) => String(item));
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
export function requireBridgeBody(value) {
|
|
62
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
63
|
+
return { kind: 'empty' };
|
|
64
|
+
const record = value;
|
|
65
|
+
if (record.kind === 'text')
|
|
66
|
+
return { kind: 'text', text: String(record.text ?? '') };
|
|
67
|
+
if (record.kind === 'unsupported')
|
|
68
|
+
return { kind: 'unsupported', reason: String(record.reason ?? '') };
|
|
69
|
+
return { kind: 'empty' };
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAgC,CAAC;AACrE,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAU,CAAC;AA0DvD,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,MAAc;IAC5D,OAAO,MAAM,CAAC,WAAW,EAAE,KAAK,MAAM,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AAC/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E,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,EAAC,CAAC;IACnF,IAAI,MAAM,CAAC,IAAI,KAAK,aAAa;QAAE,OAAO,EAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAC,CAAC;IACrG,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;AACzB,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ServerOptions as HttpsServerOptions } from 'node:https';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import type { DigestAuthOptions } from './auth/digest.js';
|
|
4
|
+
import type { CommunityServerOptions } from './community.js';
|
|
5
|
+
import type { BridgeRequestMessage } from './protocol.js';
|
|
6
|
+
export interface ServerOptions {
|
|
7
|
+
hostname: string;
|
|
8
|
+
port: number;
|
|
9
|
+
resources?: ResourceCapability;
|
|
10
|
+
maxResourceBodyBytes?: number;
|
|
11
|
+
maxRequestBodyBytes?: number;
|
|
12
|
+
logger?: ResourceLogger;
|
|
13
|
+
authorizeResource?: ResourceAuthorizer;
|
|
14
|
+
digestAuth?: DigestAuthOptions;
|
|
15
|
+
tls?: HttpsServerOptions;
|
|
16
|
+
requestTimeoutMs?: number;
|
|
17
|
+
routes?: readonly string[];
|
|
18
|
+
community?: false | CommunityServerOptions;
|
|
19
|
+
}
|
|
20
|
+
export interface RunningServer {
|
|
21
|
+
hostname: string;
|
|
22
|
+
port: number;
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export interface ResourceSnapshot {
|
|
26
|
+
name: string;
|
|
27
|
+
mimeType: string;
|
|
28
|
+
bytes: Uint8Array;
|
|
29
|
+
byteLength?: number;
|
|
30
|
+
etag?: string;
|
|
31
|
+
replacementId?: string;
|
|
32
|
+
lastModified?: Date;
|
|
33
|
+
cacheControl?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ResourceMetadata {
|
|
36
|
+
name: string;
|
|
37
|
+
mimeType: string;
|
|
38
|
+
byteLength?: number;
|
|
39
|
+
etag?: string;
|
|
40
|
+
replacementId?: string;
|
|
41
|
+
lastModified?: Date;
|
|
42
|
+
cacheControl?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ResourceWriteRequest {
|
|
45
|
+
routeName: string;
|
|
46
|
+
resourceName: string;
|
|
47
|
+
mimeType: string;
|
|
48
|
+
bytes: Uint8Array;
|
|
49
|
+
}
|
|
50
|
+
export interface ResourceWriteResult {
|
|
51
|
+
created: boolean;
|
|
52
|
+
snapshot?: ResourceSnapshot;
|
|
53
|
+
}
|
|
54
|
+
export interface ResourceCapability {
|
|
55
|
+
isNamespacePublished?(routeName: string): boolean | Promise<boolean>;
|
|
56
|
+
getResource(routeName: string, resourceName: string): ResourceSnapshot | null | Promise<ResourceSnapshot | null>;
|
|
57
|
+
listResources?(routeName: string): readonly ResourceMetadata[] | Promise<readonly ResourceMetadata[]>;
|
|
58
|
+
putResource?(request: ResourceWriteRequest): ResourceWriteResult | Promise<ResourceWriteResult>;
|
|
59
|
+
deleteResource?(routeName: string, resourceName: string): boolean | Promise<boolean>;
|
|
60
|
+
isSupportedResourceType?(mimeType: string): boolean | Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
export interface ResourceLogEvent {
|
|
63
|
+
event: 'resource.get' | 'resource.head' | 'resource.put' | 'resource.delete' | 'resource.list';
|
|
64
|
+
routeName: string;
|
|
65
|
+
resourceName?: string;
|
|
66
|
+
mimeType?: string;
|
|
67
|
+
byteLength?: number;
|
|
68
|
+
status: number;
|
|
69
|
+
}
|
|
70
|
+
export interface ResourceLogger {
|
|
71
|
+
info(event: ResourceLogEvent): void;
|
|
72
|
+
}
|
|
73
|
+
export type ResourceAuthorizer = (request: Request, operation: 'get' | 'head' | 'put' | 'delete' | 'list', routeName: string, resourceName?: string) => boolean | Promise<boolean>;
|
|
74
|
+
export interface ServerAppOptions {
|
|
75
|
+
resources?: ResourceCapability;
|
|
76
|
+
maxResourceBodyBytes?: number;
|
|
77
|
+
maxRequestBodyBytes?: number;
|
|
78
|
+
logger?: ResourceLogger;
|
|
79
|
+
authorizeResource?: ResourceAuthorizer;
|
|
80
|
+
digestAuth?: DigestAuthOptions;
|
|
81
|
+
bridge?: HttpRequestBridge;
|
|
82
|
+
routes?: readonly string[];
|
|
83
|
+
community?: false | CommunityServerOptions;
|
|
84
|
+
}
|
|
85
|
+
export interface HttpRequestBridge {
|
|
86
|
+
forward(message: BridgeRequestMessage, method: string): Promise<Response>;
|
|
87
|
+
}
|
|
88
|
+
export declare function createApp(options?: ServerAppOptions): Hono;
|
|
89
|
+
export declare function startServer(options: ServerOptions): RunningServer;
|