sst 2.24.14 → 2.24.15
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.
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from "aws-lambda";
|
|
2
2
|
import { Adapter } from "./adapter/adapter.js";
|
|
3
3
|
import { SignerOptions } from "fast-jwt";
|
|
4
|
-
import { SessionValue } from "./session.js";
|
|
5
|
-
|
|
6
|
-
session(input:
|
|
4
|
+
import { SessionBuilder, SessionValue } from "./session.js";
|
|
5
|
+
interface OnSuccessResponder<T> {
|
|
6
|
+
session(input: T & Partial<SignerOptions>): {
|
|
7
7
|
type: "session";
|
|
8
|
-
properties:
|
|
8
|
+
properties: T;
|
|
9
9
|
};
|
|
10
10
|
http(input: APIGatewayProxyStructuredResultV2): {
|
|
11
11
|
type: "http";
|
|
12
|
-
properties:
|
|
12
|
+
properties: typeof input;
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
properties: {
|
|
17
|
-
statusCode: number;
|
|
18
|
-
headers: {
|
|
19
|
-
Location: string;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare function AuthHandler<Providers extends Record<string, Adapter<any>>, Result = {
|
|
14
|
+
}
|
|
15
|
+
export declare function AuthHandler<Providers extends Record<string, Adapter<any>>, Sessions extends SessionBuilder, Result = {
|
|
25
16
|
[key in keyof Providers]: {
|
|
26
17
|
provider: key;
|
|
27
18
|
} & Extract<Awaited<ReturnType<Providers[key]>>, {
|
|
@@ -29,11 +20,11 @@ export declare function AuthHandler<Providers extends Record<string, Adapter<any
|
|
|
29
20
|
}>["properties"];
|
|
30
21
|
}[keyof Providers]>(input: {
|
|
31
22
|
providers: Providers;
|
|
23
|
+
sessions?: Sessions;
|
|
32
24
|
clients: () => Promise<Record<string, string>>;
|
|
33
25
|
onAuthorize?: (event: APIGatewayProxyEventV2) => Promise<void | keyof Providers>;
|
|
34
|
-
onSuccess: (input: Result, response:
|
|
26
|
+
onSuccess: (input: Result, response: OnSuccessResponder<SessionValue | Sessions["$type"]>) => Promise<ReturnType<OnSuccessResponder<SessionValue | Sessions["$type"]>[keyof OnSuccessResponder<any>]>>;
|
|
35
27
|
onIndex?: (event: APIGatewayProxyEventV2) => Promise<APIGatewayProxyStructuredResultV2>;
|
|
36
28
|
onError?: () => Promise<APIGatewayProxyStructuredResultV2>;
|
|
37
29
|
}): (event: APIGatewayProxyEventV2, context: import("aws-lambda").Context) => Promise<APIGatewayProxyStructuredResultV2>;
|
|
38
|
-
export type SessionCreateInput = SessionValue & Partial<SignerOptions>;
|
|
39
30
|
export {};
|
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
import { createSigner, createVerifier } from "fast-jwt";
|
|
2
2
|
import { ApiHandler, useCookie, useCookies, useFormValue, usePathParam, useQueryParam, useQueryParams, useResponse, } from "../../api/index.js";
|
|
3
3
|
import { Config } from "../../config/index.js";
|
|
4
|
-
const onSuccessResponse = {
|
|
5
|
-
session(input) {
|
|
6
|
-
return {
|
|
7
|
-
type: "session",
|
|
8
|
-
properties: input,
|
|
9
|
-
};
|
|
10
|
-
},
|
|
11
|
-
http(input) {
|
|
12
|
-
return {
|
|
13
|
-
type: "http",
|
|
14
|
-
properties: input,
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
provider(provider) {
|
|
18
|
-
return {
|
|
19
|
-
type: "http",
|
|
20
|
-
properties: {
|
|
21
|
-
statusCode: 302,
|
|
22
|
-
headers: {
|
|
23
|
-
Location: "/authorize?" +
|
|
24
|
-
new URLSearchParams({
|
|
25
|
-
provider,
|
|
26
|
-
}).toString(),
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
4
|
export function AuthHandler(input) {
|
|
33
5
|
return ApiHandler(async (evt) => {
|
|
34
6
|
const step = usePathParam("step");
|
|
@@ -184,7 +156,20 @@ export function AuthHandler(input) {
|
|
|
184
156
|
const onSuccess = await input.onSuccess({
|
|
185
157
|
provider,
|
|
186
158
|
...result.properties,
|
|
187
|
-
},
|
|
159
|
+
}, {
|
|
160
|
+
http(input) {
|
|
161
|
+
return {
|
|
162
|
+
type: "http",
|
|
163
|
+
properties: input,
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
session(input) {
|
|
167
|
+
return {
|
|
168
|
+
type: "session",
|
|
169
|
+
properties: input,
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
});
|
|
188
173
|
console.log("onSuccess", onSuccess);
|
|
189
174
|
if (onSuccess.type === "session") {
|
|
190
175
|
const { type, properties, ...rest } = onSuccess.properties;
|
|
@@ -43,4 +43,35 @@ export declare const Session: {
|
|
|
43
43
|
create: typeof create;
|
|
44
44
|
verify: typeof verify;
|
|
45
45
|
};
|
|
46
|
+
export type SessionBuilder = ReturnType<typeof createSessionBuilder>;
|
|
47
|
+
export declare function createSessionBuilder<SessionTypes extends Record<string, any> = {}>(): {
|
|
48
|
+
create<T extends ({ [type in keyof SessionTypes]: {
|
|
49
|
+
type: type;
|
|
50
|
+
properties: SessionTypes[type];
|
|
51
|
+
}; }[keyof SessionTypes] | {
|
|
52
|
+
type: "public";
|
|
53
|
+
properties: {};
|
|
54
|
+
})["type"]>(type: T, properties: SessionTypes[T], options?: Partial<SignerOptions>): string;
|
|
55
|
+
verify(token: string): { [type in keyof SessionTypes]: {
|
|
56
|
+
type: type;
|
|
57
|
+
properties: SessionTypes[type];
|
|
58
|
+
}; }[keyof SessionTypes] | {
|
|
59
|
+
type: "public";
|
|
60
|
+
properties: {};
|
|
61
|
+
};
|
|
62
|
+
use(): { [type in keyof SessionTypes]: {
|
|
63
|
+
type: type;
|
|
64
|
+
properties: SessionTypes[type];
|
|
65
|
+
}; }[keyof SessionTypes] | {
|
|
66
|
+
type: "public";
|
|
67
|
+
properties: {};
|
|
68
|
+
};
|
|
69
|
+
$type: { [type in keyof SessionTypes]: {
|
|
70
|
+
type: type;
|
|
71
|
+
properties: SessionTypes[type];
|
|
72
|
+
}; }[keyof SessionTypes] | {
|
|
73
|
+
type: "public";
|
|
74
|
+
properties: {};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
46
77
|
export {};
|
|
@@ -106,3 +106,42 @@ export const Session = {
|
|
|
106
106
|
create,
|
|
107
107
|
verify,
|
|
108
108
|
};
|
|
109
|
+
export function createSessionBuilder() {
|
|
110
|
+
return {
|
|
111
|
+
create(type, properties, options) {
|
|
112
|
+
// @ts-expect-error
|
|
113
|
+
const key = Config[process.env.AUTH_ID + "PrivateKey"];
|
|
114
|
+
const signer = createSigner({
|
|
115
|
+
...options,
|
|
116
|
+
key,
|
|
117
|
+
algorithm: "RS512",
|
|
118
|
+
});
|
|
119
|
+
const token = signer({
|
|
120
|
+
type: type,
|
|
121
|
+
properties: properties,
|
|
122
|
+
});
|
|
123
|
+
return token;
|
|
124
|
+
},
|
|
125
|
+
verify(token) {
|
|
126
|
+
if (token) {
|
|
127
|
+
try {
|
|
128
|
+
const jwt = createVerifier({
|
|
129
|
+
algorithms: ["RS512"],
|
|
130
|
+
key: getPublicKey(),
|
|
131
|
+
})(token);
|
|
132
|
+
return jwt;
|
|
133
|
+
}
|
|
134
|
+
catch (e) { }
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
type: "public",
|
|
138
|
+
properties: {},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
use() {
|
|
142
|
+
const ctx = SessionMemo();
|
|
143
|
+
return ctx;
|
|
144
|
+
},
|
|
145
|
+
$type: {},
|
|
146
|
+
};
|
|
147
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sideEffects": false,
|
|
3
3
|
"name": "sst",
|
|
4
|
-
"version": "2.24.
|
|
4
|
+
"version": "2.24.15",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sst": "cli/sst.js"
|
|
7
7
|
},
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"dotenv": "^16.0.3",
|
|
72
72
|
"esbuild": "0.18.13",
|
|
73
73
|
"express": "^4.18.2",
|
|
74
|
-
"fast-jwt": "^1.
|
|
74
|
+
"fast-jwt": "^3.1.1",
|
|
75
75
|
"get-port": "^6.1.2",
|
|
76
76
|
"glob": "^8.0.3",
|
|
77
77
|
"graphql": "*",
|
|
@@ -40,7 +40,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
40
|
));
|
|
41
41
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
42
|
|
|
43
|
-
// ../../node_modules/.pnpm/tslib@2.6.
|
|
43
|
+
// ../../node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.es6.mjs
|
|
44
44
|
var tslib_es6_exports = {};
|
|
45
45
|
__export(tslib_es6_exports, {
|
|
46
46
|
__addDisposableResource: () => __addDisposableResource,
|
|
@@ -460,7 +460,7 @@ function __classPrivateFieldIn(state, receiver) {
|
|
|
460
460
|
}
|
|
461
461
|
function __addDisposableResource(env, value, async) {
|
|
462
462
|
if (value !== null && value !== void 0) {
|
|
463
|
-
if (typeof value !== "object")
|
|
463
|
+
if (typeof value !== "object" && typeof value !== "function")
|
|
464
464
|
throw new TypeError("Object expected.");
|
|
465
465
|
var dispose;
|
|
466
466
|
if (async) {
|
|
@@ -507,7 +507,7 @@ function __disposeResources(env) {
|
|
|
507
507
|
}
|
|
508
508
|
var extendStatics, __assign, __createBinding, __setModuleDefault, _SuppressedError, tslib_es6_default;
|
|
509
509
|
var init_tslib_es6 = __esm({
|
|
510
|
-
"../../node_modules/.pnpm/tslib@2.6.
|
|
510
|
+
"../../node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.es6.mjs"() {
|
|
511
511
|
extendStatics = function(d, b) {
|
|
512
512
|
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
513
513
|
d2.__proto__ = b2;
|