houdini 1.2.10 → 1.2.12
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/cmd-cjs/index.js +1539 -16157
- package/build/cmd-esm/index.js +1541 -16159
- package/build/codegen/transforms/collectDefinitions.d.ts +1 -1
- package/build/codegen/utils/flattenSelections.d.ts +1 -1
- package/build/codegen-cjs/index.js +301 -14970
- package/build/codegen-esm/index.js +305 -14974
- package/build/lib/config.d.ts +4 -0
- package/build/lib/index.d.ts +1 -1
- package/build/lib/types.d.ts +2 -2
- package/build/lib-cjs/index.js +1600 -15892
- package/build/lib-esm/index.js +1596 -15894
- package/build/{lib/router → router}/conventions.d.ts +2 -1
- package/build/{lib/router → router}/index.d.ts +2 -0
- package/build/router/manifest.d.ts +12 -0
- package/build/router/server.d.ts +4 -0
- package/build/{lib/router → router}/types.d.ts +3 -2
- package/build/router-cjs/index.js +57736 -0
- package/build/router-cjs/package.json +1 -0
- package/build/router-esm/index.js +57726 -0
- package/build/router-esm/package.json +1 -0
- package/build/runtime/client/documentStore.d.ts +1 -0
- package/build/runtime/client/index.d.ts +14 -2
- package/build/runtime/lib/config.d.ts +19 -0
- package/build/runtime/lib/types.d.ts +39 -0
- package/build/runtime/router/cookies.d.ts +41 -0
- package/build/runtime/router/jwt.d.ts +117 -0
- package/build/runtime/router/server.d.ts +25 -0
- package/build/runtime-cjs/client/documentStore.d.ts +1 -0
- package/build/runtime-cjs/client/documentStore.js +42 -2
- package/build/runtime-cjs/client/index.d.ts +14 -2
- package/build/runtime-cjs/client/index.js +8 -2
- package/build/runtime-cjs/lib/config.d.ts +19 -0
- package/build/runtime-cjs/lib/config.js +10 -0
- package/build/runtime-cjs/lib/types.d.ts +39 -0
- package/build/runtime-cjs/router/cookies.d.ts +41 -0
- package/build/runtime-cjs/router/cookies.js +168 -0
- package/build/runtime-cjs/router/jwt.d.ts +117 -0
- package/build/runtime-cjs/router/jwt.js +181 -0
- package/build/runtime-cjs/router/server.d.ts +25 -0
- package/build/runtime-cjs/router/server.js +78 -0
- package/build/runtime-esm/client/documentStore.d.ts +1 -0
- package/build/runtime-esm/client/documentStore.js +42 -2
- package/build/runtime-esm/client/index.d.ts +14 -2
- package/build/runtime-esm/client/index.js +8 -2
- package/build/runtime-esm/lib/config.d.ts +19 -0
- package/build/runtime-esm/lib/config.js +8 -0
- package/build/runtime-esm/lib/types.d.ts +39 -0
- package/build/runtime-esm/router/cookies.d.ts +41 -0
- package/build/runtime-esm/router/cookies.js +143 -0
- package/build/runtime-esm/router/jwt.d.ts +117 -0
- package/build/runtime-esm/router/jwt.js +155 -0
- package/build/runtime-esm/router/server.d.ts +25 -0
- package/build/runtime-esm/router/server.js +53 -0
- package/build/test-cjs/index.js +324 -14973
- package/build/test-esm/index.js +328 -14977
- package/build/vite-cjs/index.js +1826 -16184
- package/build/vite-esm/index.js +1828 -16186
- package/package.json +10 -1
- package/build/lib/router/manifest.d.ts +0 -45
|
@@ -0,0 +1,168 @@
|
|
|
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 cookies_exports = {};
|
|
20
|
+
__export(cookies_exports, {
|
|
21
|
+
parse: () => parse,
|
|
22
|
+
serialize: () => serialize
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cookies_exports);
|
|
25
|
+
/*!
|
|
26
|
+
* cookie
|
|
27
|
+
* Copyright(c) 2012-2014 Roman Shtylman
|
|
28
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
29
|
+
* MIT Licensed
|
|
30
|
+
*/
|
|
31
|
+
let __toString = Object.prototype.toString;
|
|
32
|
+
let fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
33
|
+
function parse(str, options) {
|
|
34
|
+
if (typeof str !== "string") {
|
|
35
|
+
throw new TypeError("argument str must be a string");
|
|
36
|
+
}
|
|
37
|
+
let obj = {};
|
|
38
|
+
let opt = options || {};
|
|
39
|
+
let dec = opt.decode || decode;
|
|
40
|
+
let index = 0;
|
|
41
|
+
while (index < str.length) {
|
|
42
|
+
let eqIdx = str.indexOf("=", index);
|
|
43
|
+
if (eqIdx === -1) {
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
let endIdx = str.indexOf(";", index);
|
|
47
|
+
if (endIdx === -1) {
|
|
48
|
+
endIdx = str.length;
|
|
49
|
+
} else if (endIdx < eqIdx) {
|
|
50
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let key = str.slice(index, eqIdx).trim();
|
|
54
|
+
if (void 0 === obj[key]) {
|
|
55
|
+
let val = str.slice(eqIdx + 1, endIdx).trim();
|
|
56
|
+
if (val.charCodeAt(0) === 34) {
|
|
57
|
+
val = val.slice(1, -1);
|
|
58
|
+
}
|
|
59
|
+
obj[key] = tryDecode(val, dec);
|
|
60
|
+
}
|
|
61
|
+
index = endIdx + 1;
|
|
62
|
+
}
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
function serialize(name, val, options) {
|
|
66
|
+
let opt = options || {};
|
|
67
|
+
let enc = opt.encode || encode;
|
|
68
|
+
if (typeof enc !== "function") {
|
|
69
|
+
throw new TypeError("option encode is invalid");
|
|
70
|
+
}
|
|
71
|
+
if (!fieldContentRegExp.test(name)) {
|
|
72
|
+
throw new TypeError("argument name is invalid");
|
|
73
|
+
}
|
|
74
|
+
let value = enc(val);
|
|
75
|
+
if (value && !fieldContentRegExp.test(value)) {
|
|
76
|
+
throw new TypeError("argument val is invalid");
|
|
77
|
+
}
|
|
78
|
+
let str = name + "=" + value;
|
|
79
|
+
if (opt.maxAge !== null) {
|
|
80
|
+
let maxAge = opt.maxAge - 0;
|
|
81
|
+
if (Number.isNaN(maxAge) || !isFinite(maxAge)) {
|
|
82
|
+
throw new TypeError("option maxAge is invalid");
|
|
83
|
+
}
|
|
84
|
+
str += "; Max-Age=" + Math.floor(maxAge);
|
|
85
|
+
}
|
|
86
|
+
if (opt.domain) {
|
|
87
|
+
if (!fieldContentRegExp.test(opt.domain)) {
|
|
88
|
+
throw new TypeError("option domain is invalid");
|
|
89
|
+
}
|
|
90
|
+
str += "; Domain=" + opt.domain;
|
|
91
|
+
}
|
|
92
|
+
if (opt.path) {
|
|
93
|
+
if (!fieldContentRegExp.test(opt.path)) {
|
|
94
|
+
throw new TypeError("option path is invalid");
|
|
95
|
+
}
|
|
96
|
+
str += "; Path=" + opt.path;
|
|
97
|
+
}
|
|
98
|
+
if (opt.expires) {
|
|
99
|
+
let expires = opt.expires;
|
|
100
|
+
if (!isDate(expires) || Number.isNaN(expires.valueOf())) {
|
|
101
|
+
throw new TypeError("option expires is invalid");
|
|
102
|
+
}
|
|
103
|
+
str += "; Expires=" + expires.toUTCString();
|
|
104
|
+
}
|
|
105
|
+
if (opt.httpOnly) {
|
|
106
|
+
str += "; HttpOnly";
|
|
107
|
+
}
|
|
108
|
+
if (opt.secure) {
|
|
109
|
+
str += "; Secure";
|
|
110
|
+
}
|
|
111
|
+
if (opt.priority) {
|
|
112
|
+
let priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority;
|
|
113
|
+
switch (priority) {
|
|
114
|
+
case "low":
|
|
115
|
+
str += "; Priority=Low";
|
|
116
|
+
break;
|
|
117
|
+
case "medium":
|
|
118
|
+
str += "; Priority=Medium";
|
|
119
|
+
break;
|
|
120
|
+
case "high":
|
|
121
|
+
str += "; Priority=High";
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
throw new TypeError("option priority is invalid");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (opt.sameSite) {
|
|
128
|
+
let sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
129
|
+
switch (sameSite) {
|
|
130
|
+
case true:
|
|
131
|
+
str += "; SameSite=Strict";
|
|
132
|
+
break;
|
|
133
|
+
case "lax":
|
|
134
|
+
str += "; SameSite=Lax";
|
|
135
|
+
break;
|
|
136
|
+
case "strict":
|
|
137
|
+
str += "; SameSite=Strict";
|
|
138
|
+
break;
|
|
139
|
+
case "none":
|
|
140
|
+
str += "; SameSite=None";
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
throw new TypeError("option sameSite is invalid");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return str;
|
|
147
|
+
}
|
|
148
|
+
function decode(str) {
|
|
149
|
+
return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str;
|
|
150
|
+
}
|
|
151
|
+
function encode(val) {
|
|
152
|
+
return encodeURIComponent(val);
|
|
153
|
+
}
|
|
154
|
+
function isDate(val) {
|
|
155
|
+
return __toString.call(val) === "[object Date]" || val instanceof Date;
|
|
156
|
+
}
|
|
157
|
+
function tryDecode(str, decode2) {
|
|
158
|
+
try {
|
|
159
|
+
return decode2(str);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
return str;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
165
|
+
0 && (module.exports = {
|
|
166
|
+
parse,
|
|
167
|
+
serialize
|
|
168
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
type SubtleCryptoImportKeyAlgorithm = any;
|
|
2
|
+
/**
|
|
3
|
+
* @typedef JwtAlgorithm
|
|
4
|
+
* @type {'ES256'|'ES384'|'ES512'|'HS256'|'HS384'|'HS512'|'RS256'|'RS384'|'RS512'}
|
|
5
|
+
*/
|
|
6
|
+
export type JwtAlgorithm = 'ES256' | 'ES384' | 'ES512' | 'HS256' | 'HS384' | 'HS512' | 'RS256' | 'RS384' | 'RS512';
|
|
7
|
+
/**
|
|
8
|
+
* @typedef JwtAlgorithms
|
|
9
|
+
*/
|
|
10
|
+
export interface JwtAlgorithms {
|
|
11
|
+
[key: string]: SubtleCryptoImportKeyAlgorithm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @typedef JwtHeader
|
|
15
|
+
* @prop {string} [typ] Type
|
|
16
|
+
*/
|
|
17
|
+
export interface JwtHeader {
|
|
18
|
+
/**
|
|
19
|
+
* Type (default: `"JWT"`)
|
|
20
|
+
*
|
|
21
|
+
* @default "JWT"
|
|
22
|
+
*/
|
|
23
|
+
typ?: string;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @typedef JwtPayload
|
|
28
|
+
* @prop {string} [iss] Issuer
|
|
29
|
+
* @prop {string} [sub] Subject
|
|
30
|
+
* @prop {string | string[]} [aud] Audience
|
|
31
|
+
* @prop {string} [exp] Expiration Time
|
|
32
|
+
* @prop {string} [nbf] Not Before
|
|
33
|
+
* @prop {string} [iat] Issued At
|
|
34
|
+
* @prop {string} [jti] JWT ID
|
|
35
|
+
*/
|
|
36
|
+
export interface JwtPayload {
|
|
37
|
+
/** Issuer */
|
|
38
|
+
iss?: string;
|
|
39
|
+
/** Subject */
|
|
40
|
+
sub?: string;
|
|
41
|
+
/** Audience */
|
|
42
|
+
aud?: string | string[];
|
|
43
|
+
/** Expiration Time */
|
|
44
|
+
exp?: number;
|
|
45
|
+
/** Not Before */
|
|
46
|
+
nbf?: number;
|
|
47
|
+
/** Issued At */
|
|
48
|
+
iat?: number;
|
|
49
|
+
/** JWT ID */
|
|
50
|
+
jti?: string;
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @typedef JwtOptions
|
|
55
|
+
* @prop {JwtAlgorithm | string} algorithm
|
|
56
|
+
*/
|
|
57
|
+
export interface JwtOptions {
|
|
58
|
+
algorithm?: JwtAlgorithm | string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @typedef JwtSignOptions
|
|
62
|
+
* @extends JwtOptions
|
|
63
|
+
* @prop {JwtHeader} [header]
|
|
64
|
+
*/
|
|
65
|
+
export interface JwtSignOptions extends JwtOptions {
|
|
66
|
+
header?: JwtHeader;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @typedef JwtVerifyOptions
|
|
70
|
+
* @extends JwtOptions
|
|
71
|
+
* @prop {boolean} [throwError=false] If `true` throw error if checks fail. (default: `false`)
|
|
72
|
+
*/
|
|
73
|
+
export interface JwtVerifyOptions extends JwtOptions {
|
|
74
|
+
/**
|
|
75
|
+
* If `true` throw error if checks fail. (default: `false`)
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
throwError?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @typedef JwtData
|
|
83
|
+
* @prop {JwtHeader} header
|
|
84
|
+
* @prop {JwtPayload} payload
|
|
85
|
+
*/
|
|
86
|
+
export interface JwtData {
|
|
87
|
+
header: JwtHeader;
|
|
88
|
+
payload: JwtPayload;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Signs a payload and returns the token
|
|
92
|
+
*
|
|
93
|
+
* @param {JwtPayload} payload The payload object. To use `nbf` (Not Before) and/or `exp` (Expiration Time) add `nbf` and/or `exp` to the payload.
|
|
94
|
+
* @param {string | JsonWebKey} secret A string which is used to sign the payload.
|
|
95
|
+
* @param {JwtSignOptions | JwtAlgorithm | string} [options={ algorithm: 'HS256', header: { typ: 'JWT' } }] The options object or the algorithm.
|
|
96
|
+
* @throws {Error} If there's a validation issue.
|
|
97
|
+
* @returns {Promise<string>} Returns token as a `string`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function encode(payload: JwtPayload, secret: string | JsonWebKey, options?: JwtSignOptions | JwtAlgorithm): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Verifies the integrity of the token and returns a boolean value.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} token The token string generated by `jwt.sign()`.
|
|
104
|
+
* @param {string | JsonWebKey} secret The string which was used to sign the payload.
|
|
105
|
+
* @param {JWTVerifyOptions | JWTAlgorithm} options The options object or the algorithm.
|
|
106
|
+
* @throws {Error | string} Throws an error `string` if the token is invalid or an `Error-Object` if there's a validation issue.
|
|
107
|
+
* @returns {Promise<boolean>} Returns `true` if signature, `nbf` (if set) and `exp` (if set) are valid, otherwise returns `false`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function verify(token: string, secret: string | JsonWebKey, options?: JwtVerifyOptions | JwtAlgorithm): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the payload **without** verifying the integrity of the token. Please use `jwt.verify()` first to keep your application secure!
|
|
112
|
+
*
|
|
113
|
+
* @param {string} token The token string generated by `jwt.sign()`.
|
|
114
|
+
* @returns {JwtData} Returns an `object` containing `header` and `payload`.
|
|
115
|
+
*/
|
|
116
|
+
export declare function decode(token: string): JwtData;
|
|
117
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
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 jwt_exports = {};
|
|
20
|
+
__export(jwt_exports, {
|
|
21
|
+
decode: () => decode,
|
|
22
|
+
encode: () => encode,
|
|
23
|
+
verify: () => verify
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(jwt_exports);
|
|
26
|
+
function base64UrlParse(s) {
|
|
27
|
+
return new Uint8Array(
|
|
28
|
+
Array.prototype.map.call(
|
|
29
|
+
atob(s.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "")),
|
|
30
|
+
(c) => c.charCodeAt(0)
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function base64UrlStringify(a) {
|
|
35
|
+
return btoa(String.fromCharCode.apply(0, a)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
36
|
+
}
|
|
37
|
+
const algorithms = {
|
|
38
|
+
ES256: { name: "ECDSA", namedCurve: "P-256", hash: { name: "SHA-256" } },
|
|
39
|
+
ES384: { name: "ECDSA", namedCurve: "P-384", hash: { name: "SHA-384" } },
|
|
40
|
+
ES512: { name: "ECDSA", namedCurve: "P-521", hash: { name: "SHA-512" } },
|
|
41
|
+
HS256: { name: "HMAC", hash: { name: "SHA-256" } },
|
|
42
|
+
HS384: { name: "HMAC", hash: { name: "SHA-384" } },
|
|
43
|
+
HS512: { name: "HMAC", hash: { name: "SHA-512" } },
|
|
44
|
+
RS256: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } },
|
|
45
|
+
RS384: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-384" } },
|
|
46
|
+
RS512: { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-512" } }
|
|
47
|
+
};
|
|
48
|
+
function _utf8ToUint8Array(str) {
|
|
49
|
+
return base64UrlParse(btoa(unescape(encodeURIComponent(str))));
|
|
50
|
+
}
|
|
51
|
+
function _str2ab(str) {
|
|
52
|
+
str = atob(str);
|
|
53
|
+
const buf = new ArrayBuffer(str.length);
|
|
54
|
+
const bufView = new Uint8Array(buf);
|
|
55
|
+
for (let i = 0, strLen = str.length; i < strLen; i++) {
|
|
56
|
+
bufView[i] = str.charCodeAt(i);
|
|
57
|
+
}
|
|
58
|
+
return buf;
|
|
59
|
+
}
|
|
60
|
+
function _decodePayload(raw) {
|
|
61
|
+
switch (raw.length % 4) {
|
|
62
|
+
case 0:
|
|
63
|
+
break;
|
|
64
|
+
case 2:
|
|
65
|
+
raw += "==";
|
|
66
|
+
break;
|
|
67
|
+
case 3:
|
|
68
|
+
raw += "=";
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
throw new Error("Illegal base64url string!");
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(decodeURIComponent(escape(atob(raw))));
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function encode(payload, secret, options = { algorithm: "HS256", header: { typ: "JWT" } }) {
|
|
80
|
+
if (typeof options === "string")
|
|
81
|
+
options = { algorithm: options, header: { typ: "JWT" } };
|
|
82
|
+
options = { algorithm: "HS256", header: { typ: "JWT" }, ...options };
|
|
83
|
+
if (payload === null || typeof payload !== "object")
|
|
84
|
+
throw new Error("payload must be an object");
|
|
85
|
+
if (typeof secret !== "string" && typeof secret !== "object")
|
|
86
|
+
throw new Error("secret must be a string or a JWK object");
|
|
87
|
+
if (typeof options.algorithm !== "string")
|
|
88
|
+
throw new Error("options.algorithm must be a string");
|
|
89
|
+
const algorithm = algorithms[options.algorithm];
|
|
90
|
+
if (!algorithm)
|
|
91
|
+
throw new Error("algorithm not found");
|
|
92
|
+
if (!payload.iat)
|
|
93
|
+
payload.iat = Math.floor(Date.now() / 1e3);
|
|
94
|
+
const payloadAsJSON = JSON.stringify(payload);
|
|
95
|
+
const partialToken = `${base64UrlStringify(
|
|
96
|
+
_utf8ToUint8Array(JSON.stringify({ ...options.header, alg: options.algorithm }))
|
|
97
|
+
)}.${base64UrlStringify(_utf8ToUint8Array(payloadAsJSON))}`;
|
|
98
|
+
let keyFormat = "raw";
|
|
99
|
+
let keyData;
|
|
100
|
+
if (typeof secret === "object") {
|
|
101
|
+
keyFormat = "jwk";
|
|
102
|
+
keyData = secret;
|
|
103
|
+
} else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
|
|
104
|
+
keyFormat = "pkcs8";
|
|
105
|
+
keyData = _str2ab(
|
|
106
|
+
secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
|
|
107
|
+
);
|
|
108
|
+
} else
|
|
109
|
+
keyData = _utf8ToUint8Array(secret);
|
|
110
|
+
const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["sign"]);
|
|
111
|
+
const signature = await crypto.subtle.sign(algorithm, key, _utf8ToUint8Array(partialToken));
|
|
112
|
+
return `${partialToken}.${base64UrlStringify(new Uint8Array(signature))}`;
|
|
113
|
+
}
|
|
114
|
+
async function verify(token, secret, options = { algorithm: "HS256", throwError: false }) {
|
|
115
|
+
if (typeof options === "string")
|
|
116
|
+
options = { algorithm: options, throwError: false };
|
|
117
|
+
options = { algorithm: "HS256", throwError: false, ...options };
|
|
118
|
+
if (typeof token !== "string")
|
|
119
|
+
throw new Error("token must be a string");
|
|
120
|
+
if (typeof secret !== "string" && typeof secret !== "object")
|
|
121
|
+
throw new Error("secret must be a string or a JWK object");
|
|
122
|
+
if (typeof options.algorithm !== "string")
|
|
123
|
+
throw new Error("options.algorithm must be a string");
|
|
124
|
+
const tokenParts = token.split(".");
|
|
125
|
+
if (tokenParts.length !== 3)
|
|
126
|
+
throw new Error("token must consist of 3 parts");
|
|
127
|
+
const algorithm = algorithms[options.algorithm];
|
|
128
|
+
if (!algorithm)
|
|
129
|
+
throw new Error("algorithm not found");
|
|
130
|
+
const { payload } = decode(token);
|
|
131
|
+
if (!payload) {
|
|
132
|
+
if (options.throwError)
|
|
133
|
+
throw "PARSE_ERROR";
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (payload.nbf && payload.nbf > Math.floor(Date.now() / 1e3)) {
|
|
137
|
+
if (options.throwError)
|
|
138
|
+
throw "NOT_YET_VALID";
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (payload.exp && payload.exp <= Math.floor(Date.now() / 1e3)) {
|
|
142
|
+
if (options.throwError)
|
|
143
|
+
throw "EXPIRED";
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
let keyFormat = "raw";
|
|
147
|
+
let keyData;
|
|
148
|
+
if (typeof secret === "object") {
|
|
149
|
+
keyFormat = "jwk";
|
|
150
|
+
keyData = secret;
|
|
151
|
+
} else if (typeof secret === "string" && secret.startsWith("-----BEGIN")) {
|
|
152
|
+
keyFormat = "spki";
|
|
153
|
+
keyData = _str2ab(
|
|
154
|
+
secret.replace(/-----BEGIN.*?-----/g, "").replace(/-----END.*?-----/g, "").replace(/\s/g, "")
|
|
155
|
+
);
|
|
156
|
+
} else
|
|
157
|
+
keyData = _utf8ToUint8Array(secret);
|
|
158
|
+
const key = await crypto.subtle.importKey(keyFormat, keyData, algorithm, false, ["verify"]);
|
|
159
|
+
return await crypto.subtle.verify(
|
|
160
|
+
algorithm,
|
|
161
|
+
key,
|
|
162
|
+
base64UrlParse(tokenParts[2]),
|
|
163
|
+
_utf8ToUint8Array(`${tokenParts[0]}.${tokenParts[1]}`)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
function decode(token) {
|
|
167
|
+
return {
|
|
168
|
+
header: _decodePayload(
|
|
169
|
+
token.split(".")[0].replace(/-/g, "+").replace(/_/g, "/")
|
|
170
|
+
),
|
|
171
|
+
payload: _decodePayload(
|
|
172
|
+
token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")
|
|
173
|
+
)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
decode,
|
|
179
|
+
encode,
|
|
180
|
+
verify
|
|
181
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConfigFile } from '../lib';
|
|
2
|
+
type ServerHandlerArgs = {
|
|
3
|
+
url: string;
|
|
4
|
+
config: ConfigFile;
|
|
5
|
+
session_keys: string[];
|
|
6
|
+
set_header: (key: string, value: string | number | string[]) => void;
|
|
7
|
+
get_header: (key: string) => string | number | string[] | undefined;
|
|
8
|
+
redirect: (code: number, url: string) => void;
|
|
9
|
+
next: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function handle_request(args: ServerHandlerArgs): Promise<void>;
|
|
12
|
+
export type Server = {
|
|
13
|
+
use(fn: ServerMiddleware): void;
|
|
14
|
+
};
|
|
15
|
+
export type ServerMiddleware = (req: IncomingRequest, res: ServerResponse, next: () => void) => void;
|
|
16
|
+
export type IncomingRequest = {
|
|
17
|
+
url?: string;
|
|
18
|
+
headers: Headers;
|
|
19
|
+
};
|
|
20
|
+
export type ServerResponse = {
|
|
21
|
+
redirect(url: string, status?: number): void;
|
|
22
|
+
set_header(name: string, value: string): void;
|
|
23
|
+
};
|
|
24
|
+
export declare function get_session(req: Headers, secrets: string[]): Promise<App.Session>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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 server_exports = {};
|
|
20
|
+
__export(server_exports, {
|
|
21
|
+
get_session: () => get_session,
|
|
22
|
+
handle_request: () => handle_request
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(server_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
|
+
args.next();
|
|
33
|
+
}
|
|
34
|
+
async function redirect_auth(args) {
|
|
35
|
+
const { searchParams } = new URL(args.url, `http://${args.get_header("host")}`);
|
|
36
|
+
const { redirectTo, ...session } = Object.fromEntries(searchParams.entries());
|
|
37
|
+
await set_session(args, session);
|
|
38
|
+
if (redirectTo) {
|
|
39
|
+
return args.redirect(302, redirectTo);
|
|
40
|
+
}
|
|
41
|
+
args.next();
|
|
42
|
+
}
|
|
43
|
+
const session_cookie_name = "__houdini__";
|
|
44
|
+
async function set_session(req, value) {
|
|
45
|
+
const today = new Date();
|
|
46
|
+
const expires = new Date(today.getTime() + 7 * 24 * 60 * 60 * 1e3);
|
|
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;
|
|
65
|
+
}
|
|
66
|
+
const parsed = (0, import_jwt.decode)(cookie);
|
|
67
|
+
if (!parsed) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
return parsed.payload;
|
|
71
|
+
}
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
get_session,
|
|
77
|
+
handle_request
|
|
78
|
+
});
|
|
@@ -25,6 +25,7 @@ export declare class DocumentStore<_Data extends GraphQLObject, _Input extends G
|
|
|
25
25
|
});
|
|
26
26
|
send({ metadata, session, fetch, variables, policy, stuff, cacheParams, setup, silenceEcho, }?: SendParams): Promise<QueryResult<_Data, _Input>>;
|
|
27
27
|
cleanup(): Promise<void>;
|
|
28
|
+
getFetch(getSession: () => App.Session | null | undefined): (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>;
|
|
28
29
|
}
|
|
29
30
|
declare function marshalVariables<_Data extends GraphQLObject, _Input extends GraphQLVariables>(ctx: ClientPluginContext): Record<string, any>;
|
|
30
31
|
export type ClientPlugin = () => ClientHooks | null | (ClientHooks | ClientPlugin | null)[];
|
|
@@ -68,7 +68,7 @@ class DocumentStore extends Writable {
|
|
|
68
68
|
async send({
|
|
69
69
|
metadata,
|
|
70
70
|
session,
|
|
71
|
-
fetch
|
|
71
|
+
fetch,
|
|
72
72
|
variables,
|
|
73
73
|
policy,
|
|
74
74
|
stuff,
|
|
@@ -85,7 +85,7 @@ class DocumentStore extends Writable {
|
|
|
85
85
|
variables: null,
|
|
86
86
|
metadata,
|
|
87
87
|
session,
|
|
88
|
-
fetch,
|
|
88
|
+
fetch: fetch ?? this.getFetch(() => session),
|
|
89
89
|
stuff: {
|
|
90
90
|
inputs: {
|
|
91
91
|
changed: false,
|
|
@@ -127,6 +127,46 @@ class DocumentStore extends Writable {
|
|
|
127
127
|
plugin.cleanup?.(this.#lastContext);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
getFetch(getSession) {
|
|
131
|
+
return async (input, init) => {
|
|
132
|
+
let url = "";
|
|
133
|
+
let queries = [];
|
|
134
|
+
if (typeof input === "string") {
|
|
135
|
+
url = input.startsWith("http") ? new URL(input).pathname : input;
|
|
136
|
+
}
|
|
137
|
+
if (input instanceof URL) {
|
|
138
|
+
url = input.pathname;
|
|
139
|
+
} else if (input instanceof Request) {
|
|
140
|
+
url = new URL(input.url).pathname;
|
|
141
|
+
}
|
|
142
|
+
if (input instanceof Request) {
|
|
143
|
+
const body = await input.json();
|
|
144
|
+
if (!Array.isArray(body)) {
|
|
145
|
+
queries = [body];
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
const body = JSON.parse(init?.body);
|
|
149
|
+
if (!Array.isArray(body)) {
|
|
150
|
+
queries = [body];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!url || queries.length === 0) {
|
|
154
|
+
return await globalThis.fetch(input, init);
|
|
155
|
+
}
|
|
156
|
+
if (this.#client?.proxies[url]) {
|
|
157
|
+
const result = await Promise.all(
|
|
158
|
+
queries.map(
|
|
159
|
+
(q) => this.#client?.proxies[url]({
|
|
160
|
+
...q,
|
|
161
|
+
session: getSession()
|
|
162
|
+
})
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
return new Response(JSON.stringify(result.length === 1 ? result[0] : result));
|
|
166
|
+
}
|
|
167
|
+
return await globalThis.fetch(input, init);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
130
170
|
#step(direction, ctx, value) {
|
|
131
171
|
const hook = direction === "error" ? "catch" : steps[direction][ctx.currentStep];
|
|
132
172
|
let valid = (i) => i <= this.#plugins.length;
|
|
@@ -7,7 +7,7 @@ import type { FetchParamFn, ThrowOnErrorOperations, ThrowOnErrorParams } from '.
|
|
|
7
7
|
export { DocumentStore, type ClientPlugin, type SendParams } from './documentStore';
|
|
8
8
|
export { fetch, mutation, query, subscription } from './plugins';
|
|
9
9
|
export type HoudiniClientConstructorArgs = {
|
|
10
|
-
url
|
|
10
|
+
url?: string;
|
|
11
11
|
fetchParams?: FetchParamFn;
|
|
12
12
|
plugins?: NestedList<ClientPlugin>;
|
|
13
13
|
pipeline?: NestedList<ClientPlugin>;
|
|
@@ -25,7 +25,19 @@ export declare class HoudiniClient {
|
|
|
25
25
|
url: string;
|
|
26
26
|
readonly plugins: ClientPlugin[];
|
|
27
27
|
readonly throwOnError_operations: ThrowOnErrorOperations[];
|
|
28
|
-
|
|
28
|
+
proxies: Record<string, (operation: {
|
|
29
|
+
query: string;
|
|
30
|
+
variables: any;
|
|
31
|
+
operationName: string;
|
|
32
|
+
session: App.Session | null | undefined;
|
|
33
|
+
}) => Promise<any>>;
|
|
34
|
+
constructor({ url, fetchParams, plugins, pipeline, throwOnError, }?: HoudiniClientConstructorArgs);
|
|
29
35
|
observe<_Data extends GraphQLObject, _Input extends GraphQLVariables>({ enableCache, fetching, ...rest }: ObserveParams<_Data, DocumentArtifact, _Input>): DocumentStore<_Data, _Input>;
|
|
36
|
+
registerProxy(url: string, handler: (operation: {
|
|
37
|
+
query: string;
|
|
38
|
+
variables: any;
|
|
39
|
+
operationName: string;
|
|
40
|
+
session: App.Session | null | undefined;
|
|
41
|
+
}) => Promise<any>): void;
|
|
30
42
|
}
|
|
31
43
|
export declare function createPluginHooks(plugins: ClientPlugin[]): ClientHooks[];
|