houdini 1.2.13 → 1.2.14
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/build/adapter/index.d.ts +3 -0
- package/build/adapter-cjs/index.js +33 -0
- package/build/adapter-cjs/package.json +1 -0
- package/build/adapter-esm/index.js +9 -0
- package/build/adapter-esm/package.json +1 -0
- package/build/cmd-cjs/index.js +19 -19
- package/build/cmd-esm/index.js +18 -18
- package/build/codegen-cjs/index.js +16 -17
- package/build/codegen-esm/index.js +16 -16
- package/build/lib/index.d.ts +2 -0
- package/build/lib/router/conventions.d.ts +2 -4
- package/build/lib/router/index.d.ts +1 -1
- package/build/lib/router/types.d.ts +1 -0
- package/build/lib-cjs/index.js +140 -24
- package/build/lib-esm/index.js +136 -23
- package/build/runtime/lib/types.d.ts +1 -1
- package/build/runtime/router/match.d.ts +38 -0
- package/build/runtime/router/server.d.ts +22 -25
- package/build/runtime/router/session.d.ts +22 -0
- package/build/runtime/router/types.d.ts +23 -0
- package/build/runtime-cjs/lib/types.d.ts +1 -1
- package/build/runtime-cjs/lib/types.js +2 -0
- package/build/runtime-cjs/router/match.d.ts +38 -0
- package/build/runtime-cjs/router/match.js +149 -0
- package/build/runtime-cjs/router/server.d.ts +22 -25
- package/build/runtime-cjs/router/server.js +71 -49
- package/build/runtime-cjs/router/session.d.ts +22 -0
- package/build/runtime-cjs/router/session.js +77 -0
- package/build/runtime-cjs/router/types.d.ts +23 -0
- package/build/runtime-cjs/router/types.js +16 -0
- package/build/runtime-esm/lib/types.d.ts +1 -1
- package/build/runtime-esm/lib/types.js +1 -0
- package/build/runtime-esm/router/match.d.ts +38 -0
- package/build/runtime-esm/router/match.js +122 -0
- package/build/runtime-esm/router/server.d.ts +22 -25
- package/build/runtime-esm/router/server.js +64 -47
- package/build/runtime-esm/router/session.d.ts +22 -0
- package/build/runtime-esm/router/session.js +52 -0
- package/build/runtime-esm/router/types.d.ts +23 -0
- package/build/runtime-esm/router/types.js +0 -0
- package/build/test-cjs/index.js +16 -17
- package/build/test-esm/index.js +16 -16
- package/build/vite-cjs/index.js +26 -34
- package/build/vite-esm/index.js +26 -33
- package/package.json +10 -1
|
@@ -15,6 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
var types_exports = {};
|
|
20
21
|
__export(types_exports, {
|
|
@@ -32,6 +33,7 @@ __export(types_exports, {
|
|
|
32
33
|
isPending: () => isPending
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(types_exports);
|
|
36
|
+
__reExport(types_exports, require("../router/types"), module.exports);
|
|
35
37
|
const CachePolicy = {
|
|
36
38
|
CacheOrNetwork: "CacheOrNetwork",
|
|
37
39
|
CacheOnly: "CacheOnly",
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
2
|
+
import type { RouterManifest, RouterPageManifest } from './types';
|
|
3
|
+
export type RouteParam = {
|
|
4
|
+
name: string;
|
|
5
|
+
matcher: string;
|
|
6
|
+
optional: boolean;
|
|
7
|
+
rest: boolean;
|
|
8
|
+
chained: boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface ParamMatcher {
|
|
11
|
+
(param: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function find_match<_ComponentType>(manifest: RouterManifest<_ComponentType>, current: string, allowNull: true): [RouterPageManifest<_ComponentType> | null, GraphQLVariables];
|
|
14
|
+
export declare function find_match<_ComponentType>(manifest: RouterManifest<_ComponentType>, current: string, allowNull?: false): [RouterPageManifest<_ComponentType>, GraphQLVariables];
|
|
15
|
+
/**
|
|
16
|
+
* Creates the regex pattern, extracts parameter names, and generates types for a route
|
|
17
|
+
*/
|
|
18
|
+
export declare function parse_page_pattern(id: string): {
|
|
19
|
+
pattern: RegExp;
|
|
20
|
+
params: RouteParam[];
|
|
21
|
+
page_id: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Splits a route id into its segments, removing segments that
|
|
25
|
+
* don't affect the path (i.e. groups). The root route is represented by `/`
|
|
26
|
+
* and will be returned as `['']`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function get_route_segments(route: string): string[];
|
|
29
|
+
export declare function exec(match: RegExpMatchArray, params: RouteParam[]): Record<string, string> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
34
|
+
|
|
35
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
38
|
+
*/
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var match_exports = {};
|
|
20
|
+
__export(match_exports, {
|
|
21
|
+
exec: () => exec,
|
|
22
|
+
find_match: () => find_match,
|
|
23
|
+
get_route_segments: () => get_route_segments,
|
|
24
|
+
parse_page_pattern: () => parse_page_pattern
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(match_exports);
|
|
27
|
+
const param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;
|
|
28
|
+
function find_match(manifest, current, allowNull = true) {
|
|
29
|
+
let match = null;
|
|
30
|
+
let matchVariables = null;
|
|
31
|
+
for (const page of Object.values(manifest.pages)) {
|
|
32
|
+
const urlMatch = current.match(page.pattern);
|
|
33
|
+
if (!urlMatch) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
match = page;
|
|
37
|
+
matchVariables = exec(urlMatch, page.params) || {};
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (!match && !allowNull) {
|
|
41
|
+
throw new Error("404");
|
|
42
|
+
}
|
|
43
|
+
return [match, matchVariables];
|
|
44
|
+
}
|
|
45
|
+
function parse_page_pattern(id) {
|
|
46
|
+
const params = [];
|
|
47
|
+
const pattern = id === "/" ? /^\/$/ : new RegExp(
|
|
48
|
+
`^${get_route_segments(id).map((segment) => {
|
|
49
|
+
const rest_match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
|
|
50
|
+
if (rest_match) {
|
|
51
|
+
params.push({
|
|
52
|
+
name: rest_match[1],
|
|
53
|
+
matcher: rest_match[2],
|
|
54
|
+
optional: false,
|
|
55
|
+
rest: true,
|
|
56
|
+
chained: true
|
|
57
|
+
});
|
|
58
|
+
return "(?:/(.*))?";
|
|
59
|
+
}
|
|
60
|
+
const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
|
|
61
|
+
if (optional_match) {
|
|
62
|
+
params.push({
|
|
63
|
+
name: optional_match[1],
|
|
64
|
+
matcher: optional_match[2],
|
|
65
|
+
optional: true,
|
|
66
|
+
rest: false,
|
|
67
|
+
chained: true
|
|
68
|
+
});
|
|
69
|
+
return "(?:/([^/]+))?";
|
|
70
|
+
}
|
|
71
|
+
if (!segment) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const parts = segment.split(/\[(.+?)\](?!\])/);
|
|
75
|
+
const result = parts.map((content, i) => {
|
|
76
|
+
if (i % 2) {
|
|
77
|
+
if (content.startsWith("x+")) {
|
|
78
|
+
return escape(
|
|
79
|
+
String.fromCharCode(parseInt(content.slice(2), 16))
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (content.startsWith("u+")) {
|
|
83
|
+
return escape(
|
|
84
|
+
String.fromCharCode(
|
|
85
|
+
...content.slice(2).split("-").map((code) => parseInt(code, 16))
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const match = param_pattern.exec(content);
|
|
90
|
+
if (!match) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const [, is_optional, is_rest, name, matcher] = match;
|
|
96
|
+
params.push({
|
|
97
|
+
name,
|
|
98
|
+
matcher,
|
|
99
|
+
optional: !!is_optional,
|
|
100
|
+
rest: !!is_rest,
|
|
101
|
+
chained: is_rest ? i === 1 && parts[0] === "" : false
|
|
102
|
+
});
|
|
103
|
+
return is_rest ? "(.*?)" : is_optional ? "([^/]*)?" : "([^/]+?)";
|
|
104
|
+
}
|
|
105
|
+
return escape(content);
|
|
106
|
+
}).join("");
|
|
107
|
+
return "/" + result;
|
|
108
|
+
}).join("")}/?$`
|
|
109
|
+
);
|
|
110
|
+
return { pattern, params, page_id: id };
|
|
111
|
+
}
|
|
112
|
+
function affects_path(segment) {
|
|
113
|
+
return !/^\([^)]+\)$/.test(segment);
|
|
114
|
+
}
|
|
115
|
+
function get_route_segments(route) {
|
|
116
|
+
return route.slice(1).split("/").filter(affects_path);
|
|
117
|
+
}
|
|
118
|
+
function exec(match, params) {
|
|
119
|
+
const result = {};
|
|
120
|
+
const values = match.slice(1);
|
|
121
|
+
let buffered = "";
|
|
122
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
123
|
+
const param = params[i];
|
|
124
|
+
let value = values[i];
|
|
125
|
+
if (param.chained && param.rest && buffered) {
|
|
126
|
+
value = value ? buffered + "/" + value : buffered;
|
|
127
|
+
}
|
|
128
|
+
buffered = "";
|
|
129
|
+
if (value === void 0) {
|
|
130
|
+
if (param.rest)
|
|
131
|
+
result[param.name] = "";
|
|
132
|
+
} else {
|
|
133
|
+
result[param.name] = value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (buffered)
|
|
137
|
+
return;
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
function escape(str) {
|
|
141
|
+
return str.normalize().replace(/[[\]]/g, "\\$&").replace(/%/g, "%25").replace(/\//g, "%2[Ff]").replace(/\?/g, "%3[Ff]").replace(/#/g, "%23").replace(/[.*+?^${}()|\\]/g, "\\$&");
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
exec,
|
|
146
|
+
find_match,
|
|
147
|
+
get_route_segments,
|
|
148
|
+
parse_page_pattern
|
|
149
|
+
});
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
export declare function get_session(req: Headers, secrets: string[]): Promise<App.Session>;
|
|
25
|
-
export {};
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { createServerAdapter as createAdapter } from '@whatwg-node/server';
|
|
3
|
+
import { type GraphQLSchema } from 'graphql';
|
|
4
|
+
import { createYoga } from 'graphql-yoga';
|
|
5
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
|
+
import type { RouterManifest, RouterPageManifest, YogaServerOptions } from './types';
|
|
7
|
+
export declare const serverAdapterFactory: <ComponentType>({ schema, yoga, production, manifest, on_render, pipe, assetPrefix, }: {
|
|
8
|
+
schema?: GraphQLSchema | null | undefined;
|
|
9
|
+
yoga?: import("graphql-yoga").YogaServerInstance<Record<string, any>, Record<string, any>> | null | undefined;
|
|
10
|
+
assetPrefix: string;
|
|
11
|
+
production?: boolean | undefined;
|
|
12
|
+
pipe?: ServerResponse<IncomingMessage> | undefined;
|
|
13
|
+
on_render: (args: {
|
|
14
|
+
url: string;
|
|
15
|
+
match: RouterPageManifest<ComponentType> | null;
|
|
16
|
+
manifest: RouterManifest<unknown>;
|
|
17
|
+
session: App.Session;
|
|
18
|
+
pipe?: ServerResponse<IncomingMessage> | undefined;
|
|
19
|
+
}) => Response | Promise<Response>;
|
|
20
|
+
manifest: RouterManifest<ComponentType> | null;
|
|
21
|
+
} & Omit<import("graphql-yoga").YogaServerOptions<Record<string, any>, Record<string, any>>, "schema">) => ReturnType<typeof createAdapter>;
|
|
22
|
+
export type ServerAdapterFactory = typeof serverAdapterFactory;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,64 +17,84 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
18
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
25
|
var server_exports = {};
|
|
20
26
|
__export(server_exports, {
|
|
21
|
-
|
|
22
|
-
handle_request: () => handle_request
|
|
27
|
+
serverAdapterFactory: () => serverAdapterFactory
|
|
23
28
|
});
|
|
24
29
|
module.exports = __toCommonJS(server_exports);
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
var import_server = require("@whatwg-node/server");
|
|
31
|
+
var import_graphql = require("graphql");
|
|
32
|
+
var import_graphql_yoga = require("graphql-yoga");
|
|
33
|
+
var import_client = __toESM(require("../../../src/+client"), 1);
|
|
34
|
+
var import_config = require("../lib/config");
|
|
35
|
+
var import_match = require("./match");
|
|
36
|
+
var import_session = require("./session");
|
|
37
|
+
const config_file = (0, import_config.getCurrentConfig)();
|
|
38
|
+
const session_keys = (0, import_config.localApiSessionKeys)(config_file);
|
|
39
|
+
const graphqlEndpoint = (0, import_config.localApiEndpoint)(config_file);
|
|
40
|
+
const serverAdapterFactory = ({
|
|
41
|
+
schema,
|
|
42
|
+
yoga,
|
|
43
|
+
production,
|
|
44
|
+
manifest,
|
|
45
|
+
on_render,
|
|
46
|
+
pipe,
|
|
47
|
+
assetPrefix
|
|
48
|
+
}) => {
|
|
49
|
+
if (schema && !yoga) {
|
|
50
|
+
yoga = (0, import_graphql_yoga.createYoga)({
|
|
51
|
+
schema,
|
|
52
|
+
landingPage: !production,
|
|
53
|
+
graphqlEndpoint
|
|
54
|
+
});
|
|
31
55
|
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await set_session(args, session);
|
|
38
|
-
if (redirectTo) {
|
|
39
|
-
return args.redirect(302, redirectTo);
|
|
56
|
+
if (schema) {
|
|
57
|
+
import_client.default.registerProxy(graphqlEndpoint, async ({ query, variables, session }) => {
|
|
58
|
+
const parsed = (0, import_graphql.parse)(query);
|
|
59
|
+
return await (0, import_graphql.execute)(schema, parsed, null, session, variables);
|
|
60
|
+
});
|
|
40
61
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const serialized = await (0, import_jwt.encode)(value, req.session_keys[0]);
|
|
48
|
-
req.set_header(
|
|
49
|
-
"Set-Cookie",
|
|
50
|
-
`${session_cookie_name}=${serialized}; Path=/; HttpOnly; Secure; SameSite=Lax; Expires=${expires.toUTCString()} `
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
async function get_session(req, secrets) {
|
|
54
|
-
const cookies = req.get("cookie");
|
|
55
|
-
if (!cookies) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
const cookie = (0, import_cookies.parse)(cookies)[session_cookie_name];
|
|
59
|
-
if (!cookie) {
|
|
60
|
-
return {};
|
|
61
|
-
}
|
|
62
|
-
for (const secret of secrets) {
|
|
63
|
-
if (!await (0, import_jwt.verify)(cookie, secret)) {
|
|
64
|
-
continue;
|
|
62
|
+
return (0, import_server.createServerAdapter)(async (request) => {
|
|
63
|
+
if (!manifest) {
|
|
64
|
+
return new Response(
|
|
65
|
+
"Adapter did not provide the project's manifest. Please open an issue on github.",
|
|
66
|
+
{ status: 500 }
|
|
67
|
+
);
|
|
65
68
|
}
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
69
|
+
const url = new URL(request.url).pathname;
|
|
70
|
+
if (yoga && url === (0, import_config.localApiEndpoint)(config_file)) {
|
|
71
|
+
return yoga(request);
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const authResponse = await (0, import_session.handle_request)({
|
|
74
|
+
url,
|
|
75
|
+
config: config_file,
|
|
76
|
+
session_keys,
|
|
77
|
+
headers: request.headers
|
|
78
|
+
});
|
|
79
|
+
if (authResponse) {
|
|
80
|
+
return authResponse;
|
|
81
|
+
}
|
|
82
|
+
const [match] = (0, import_match.find_match)(manifest, url);
|
|
83
|
+
const rendered = await on_render({
|
|
84
|
+
url,
|
|
85
|
+
match,
|
|
86
|
+
session: await (0, import_session.get_session)(request.headers, session_keys),
|
|
87
|
+
manifest,
|
|
88
|
+
pipe
|
|
89
|
+
});
|
|
90
|
+
if (rendered) {
|
|
91
|
+
console.log(url, rendered);
|
|
92
|
+
return rendered;
|
|
93
|
+
}
|
|
94
|
+
return new Response("404", { status: 404 });
|
|
95
|
+
});
|
|
96
|
+
};
|
|
74
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
98
|
0 && (module.exports = {
|
|
76
|
-
|
|
77
|
-
handle_request
|
|
99
|
+
serverAdapterFactory
|
|
78
100
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ConfigFile } from '../lib';
|
|
2
|
+
type ServerHandlerArgs = {
|
|
3
|
+
url: string;
|
|
4
|
+
config: ConfigFile;
|
|
5
|
+
session_keys: string[];
|
|
6
|
+
headers: Headers;
|
|
7
|
+
};
|
|
8
|
+
export declare function handle_request(args: ServerHandlerArgs): Promise<Response | undefined>;
|
|
9
|
+
export type Server = {
|
|
10
|
+
use(fn: ServerMiddleware): void;
|
|
11
|
+
};
|
|
12
|
+
export type ServerMiddleware = (req: IncomingRequest, res: ServerResponse, next: () => void) => void;
|
|
13
|
+
export type IncomingRequest = {
|
|
14
|
+
url?: string;
|
|
15
|
+
headers: Headers;
|
|
16
|
+
};
|
|
17
|
+
export type ServerResponse = {
|
|
18
|
+
redirect(url: string, status?: number): void;
|
|
19
|
+
set_header(name: string, value: string): void;
|
|
20
|
+
};
|
|
21
|
+
export declare function get_session(req: Headers, secrets: string[]): Promise<App.Session>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var session_exports = {};
|
|
20
|
+
__export(session_exports, {
|
|
21
|
+
get_session: () => get_session,
|
|
22
|
+
handle_request: () => handle_request
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(session_exports);
|
|
25
|
+
var import_cookies = require("./cookies");
|
|
26
|
+
var import_jwt = require("./jwt");
|
|
27
|
+
async function handle_request(args) {
|
|
28
|
+
const plugin_config = args.config.router ?? {};
|
|
29
|
+
if (plugin_config.auth && "redirect" in plugin_config.auth && args.url.startsWith(plugin_config.auth.redirect)) {
|
|
30
|
+
return await redirect_auth(args);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function redirect_auth(args) {
|
|
34
|
+
const { searchParams } = new URL(args.url, `http://${args.headers.get("host")}`);
|
|
35
|
+
const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
|
|
36
|
+
if (redirectTo) {
|
|
37
|
+
const response = Response.redirect(redirectTo, 302);
|
|
38
|
+
await set_session(args, response, session);
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const session_cookie_name = "__houdini__";
|
|
43
|
+
async function set_session(req, response, value) {
|
|
44
|
+
const today = new Date();
|
|
45
|
+
const expires = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1e3);
|
|
46
|
+
const serialized = await (0, import_jwt.encode)(value, req.session_keys[0]);
|
|
47
|
+
response.headers.set(
|
|
48
|
+
"Set-Cookie",
|
|
49
|
+
`${session_cookie_name}=${serialized}; Path=/; HttpOnly; Secure; SameSite=Lax; Expires=${expires.toUTCString()} `
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
async function get_session(req, secrets) {
|
|
53
|
+
const cookies = req.get("cookie");
|
|
54
|
+
if (!cookies) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
const cookie = (0, import_cookies.parse)(cookies)[session_cookie_name];
|
|
58
|
+
if (!cookie) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
for (const secret of secrets) {
|
|
62
|
+
if (!await (0, import_jwt.verify)(cookie, secret)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const parsed = (0, import_jwt.decode)(cookie);
|
|
66
|
+
if (!parsed) {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
return parsed.payload;
|
|
70
|
+
}
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
get_session,
|
|
76
|
+
handle_request
|
|
77
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { QueryArtifact } from '$houdini/runtime/lib/types';
|
|
2
|
+
import type { createYoga } from 'graphql-yoga';
|
|
3
|
+
import type { RouteParam } from './match';
|
|
4
|
+
export type YogaServer = ReturnType<typeof createYoga>;
|
|
5
|
+
export type YogaServerOptions = Parameters<typeof createYoga>[0];
|
|
6
|
+
export type RouterManifest<_ComponentType> = {
|
|
7
|
+
pages: Record<string, RouterPageManifest<_ComponentType>>;
|
|
8
|
+
};
|
|
9
|
+
export type { ServerAdapterFactory } from './server';
|
|
10
|
+
export type RouterPageManifest<_ComponentType> = {
|
|
11
|
+
id: string;
|
|
12
|
+
pattern: RegExp;
|
|
13
|
+
params: RouteParam[];
|
|
14
|
+
documents: Record<string, {
|
|
15
|
+
artifact: () => Promise<{
|
|
16
|
+
default: QueryArtifact;
|
|
17
|
+
}>;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
component: () => Promise<{
|
|
21
|
+
default: (props: any) => _ComponentType;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -11,6 +11,7 @@ export declare const PaginateMode: {
|
|
|
11
11
|
readonly SinglePage: "SinglePage";
|
|
12
12
|
};
|
|
13
13
|
export type PaginateModes = ValuesOf<typeof PaginateMode>;
|
|
14
|
+
export * from '../router/types';
|
|
14
15
|
declare global {
|
|
15
16
|
namespace App {
|
|
16
17
|
interface Session {
|
|
@@ -356,4 +357,3 @@ export type QueryManifest = {
|
|
|
356
357
|
/** The filepath of the unit */
|
|
357
358
|
path: string;
|
|
358
359
|
};
|
|
359
|
-
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GraphQLVariables } from '$houdini/runtime/lib/types';
|
|
2
|
+
import type { RouterManifest, RouterPageManifest } from './types';
|
|
3
|
+
export type RouteParam = {
|
|
4
|
+
name: string;
|
|
5
|
+
matcher: string;
|
|
6
|
+
optional: boolean;
|
|
7
|
+
rest: boolean;
|
|
8
|
+
chained: boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface ParamMatcher {
|
|
11
|
+
(param: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function find_match<_ComponentType>(manifest: RouterManifest<_ComponentType>, current: string, allowNull: true): [RouterPageManifest<_ComponentType> | null, GraphQLVariables];
|
|
14
|
+
export declare function find_match<_ComponentType>(manifest: RouterManifest<_ComponentType>, current: string, allowNull?: false): [RouterPageManifest<_ComponentType>, GraphQLVariables];
|
|
15
|
+
/**
|
|
16
|
+
* Creates the regex pattern, extracts parameter names, and generates types for a route
|
|
17
|
+
*/
|
|
18
|
+
export declare function parse_page_pattern(id: string): {
|
|
19
|
+
pattern: RegExp;
|
|
20
|
+
params: RouteParam[];
|
|
21
|
+
page_id: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Splits a route id into its segments, removing segments that
|
|
25
|
+
* don't affect the path (i.e. groups). The root route is represented by `/`
|
|
26
|
+
* and will be returned as `['']`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function get_route_segments(route: string): string[];
|
|
29
|
+
export declare function exec(match: RegExpMatchArray, params: RouteParam[]): Record<string, string> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
34
|
+
|
|
35
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
38
|
+
*/
|