sst 3.0.1-24 → 3.0.1-25
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/auth/session.d.ts +2 -10
- package/dist/auth/session.js +10 -3
- package/dist/resource.js +12 -11
- package/package.json +1 -1
package/dist/auth/session.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { JWTPayload } from "jose";
|
|
2
1
|
export type SessionBuilder = ReturnType<typeof createSessionBuilder>;
|
|
3
2
|
export declare function createSessionBuilder<SessionTypes extends Record<string, any> = {}>(): {
|
|
4
|
-
|
|
3
|
+
verify(token: string): Promise<{ [type in keyof SessionTypes]: {
|
|
5
4
|
type: type;
|
|
6
5
|
properties: SessionTypes[type];
|
|
7
6
|
}; }[keyof SessionTypes] | {
|
|
8
7
|
type: "public";
|
|
9
8
|
properties: {};
|
|
10
|
-
}
|
|
11
|
-
verify(token: string): { [type in keyof SessionTypes]: {
|
|
12
|
-
type: type;
|
|
13
|
-
properties: SessionTypes[type];
|
|
14
|
-
}; }[keyof SessionTypes] | {
|
|
15
|
-
type: "public";
|
|
16
|
-
properties: {};
|
|
17
|
-
};
|
|
9
|
+
}>;
|
|
18
10
|
$type: SessionTypes;
|
|
19
11
|
$typeValues: { [type in keyof SessionTypes]: {
|
|
20
12
|
type: type;
|
package/dist/auth/session.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { importSPKI, jwtVerify } from "jose";
|
|
2
|
+
import { Resource } from "../resource.js";
|
|
1
3
|
export function createSessionBuilder() {
|
|
4
|
+
const auth = Object.values(Resource).find((value) => value.auth === true && value.publicKey);
|
|
5
|
+
if (!auth) {
|
|
6
|
+
throw new Error("No auth resource found");
|
|
7
|
+
}
|
|
8
|
+
const publicKey = auth.publicKey;
|
|
2
9
|
return {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return
|
|
10
|
+
async verify(token) {
|
|
11
|
+
const result = await jwtVerify(token, await importSPKI(publicKey, "RS512"));
|
|
12
|
+
return result.payload;
|
|
6
13
|
},
|
|
7
14
|
$type: {},
|
|
8
15
|
$typeValues: {},
|
package/dist/resource.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const raw = {
|
|
2
|
+
// @ts-expect-error,
|
|
3
|
+
...globalThis.$SST_LINKS,
|
|
4
|
+
};
|
|
5
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
6
|
+
if (key.startsWith("SST_RESOURCE_") && value) {
|
|
7
|
+
raw[key.slice("SST_RESOURCE_".length)] = JSON.parse(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const Resource = new Proxy(raw, {
|
|
3
11
|
get(target, prop) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (env[envName]) {
|
|
7
|
-
return JSON.parse(env[envName]);
|
|
8
|
-
}
|
|
9
|
-
// @ts-expect-error
|
|
10
|
-
if (prop in (globalThis.$SST_LINKS || {})) {
|
|
11
|
-
// @ts-expect-error
|
|
12
|
-
return globalThis.$SST_LINKS[prop];
|
|
12
|
+
if (prop in target) {
|
|
13
|
+
return target[prop];
|
|
13
14
|
}
|
|
14
15
|
throw new Error(`"${prop}" is not linked`);
|
|
15
16
|
},
|