sst 0.0.508 → 0.0.509
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/scripts/release.d.ts +2 -0
- package/dist/scripts/release.js +12 -0
- package/dist/src/auth/adapter/oauth.js +7 -4
- package/dist/src/auth/adapter/oidc.js +5 -2
- package/dist/src/auth/handler.d.ts +1 -2
- package/dist/src/aws/auth.d.ts +9 -0
- package/dist/src/aws/auth.js +12 -0
- package/dist/src/aws/bus.js +8 -6
- package/dist/src/aws/client.d.ts +1 -1
- package/dist/src/aws/client.js +35 -6
- package/dist/src/aws/realtime.d.ts +19 -2
- package/dist/src/event/index.d.ts +2 -4
- package/dist/src/event/index.js +1 -7
- package/dist/src/event/validator.d.ts +4 -0
- package/dist/src/event/validator.js +11 -0
- package/dist/src/resource.js +6 -2
- package/package.json +3 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { $ } from "bun";
|
|
3
|
+
const version = process.argv[2];
|
|
4
|
+
await $ `bun run build`;
|
|
5
|
+
const pkg = await Bun.file("package.json").json();
|
|
6
|
+
try {
|
|
7
|
+
await Bun.write("package.json", JSON.stringify({ ...pkg, version }, null, 2));
|
|
8
|
+
await $ `npm publish --access public --tag ion`;
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
await Bun.write("package.json", JSON.stringify(pkg, null, 2));
|
|
12
|
+
}
|
|
@@ -8,13 +8,16 @@ export const OauthAdapter =
|
|
|
8
8
|
(config) => {
|
|
9
9
|
return async function (routes, ctx) {
|
|
10
10
|
function getClient(c) {
|
|
11
|
-
const callback = c.req.url
|
|
11
|
+
const callback = new URL(c.req.url);
|
|
12
|
+
callback.pathname = callback.pathname.replace(/authorize.*$/, "callback");
|
|
13
|
+
callback.search = "";
|
|
14
|
+
callback.host = c.req.header("x-forwarded-host") || callback.host;
|
|
12
15
|
return [
|
|
13
16
|
callback,
|
|
14
17
|
new config.issuer.Client({
|
|
15
18
|
client_id: config.clientID,
|
|
16
19
|
client_secret: config.clientSecret,
|
|
17
|
-
redirect_uris: [callback],
|
|
20
|
+
redirect_uris: [callback.toString()],
|
|
18
21
|
response_types: ["code"],
|
|
19
22
|
}),
|
|
20
23
|
];
|
|
@@ -46,7 +49,7 @@ export const OauthAdapter =
|
|
|
46
49
|
const state = getCookie(c, "auth_state");
|
|
47
50
|
const tokenset = await client[config.issuer.metadata.userinfo_endpoint
|
|
48
51
|
? "callback"
|
|
49
|
-
: "oauthCallback"](callback, query, {
|
|
52
|
+
: "oauthCallback"](callback.toString(), query, {
|
|
50
53
|
code_verifier,
|
|
51
54
|
state,
|
|
52
55
|
});
|
|
@@ -66,7 +69,7 @@ export const OauthAdapter =
|
|
|
66
69
|
const state = getCookie(c, "auth_state");
|
|
67
70
|
const tokenset = await client[config.issuer.metadata.userinfo_endpoint
|
|
68
71
|
? "callback"
|
|
69
|
-
: "oauthCallback"](callback, Object.fromEntries(form), {
|
|
72
|
+
: "oauthCallback"](callback.toString(), Object.fromEntries(form), {
|
|
70
73
|
code_verifier,
|
|
71
74
|
state,
|
|
72
75
|
});
|
|
@@ -3,10 +3,13 @@ import { getCookie } from "hono/cookie";
|
|
|
3
3
|
export const OidcAdapter = /* @__PURE__ */ (config) => {
|
|
4
4
|
return async function (routes, ctx) {
|
|
5
5
|
routes.get("/authorize", async (c) => {
|
|
6
|
-
const callback = c.req.url
|
|
6
|
+
const callback = new URL(c.req.url);
|
|
7
|
+
callback.pathname = callback.pathname.replace(/authorize.*$/, "callback");
|
|
8
|
+
callback.search = "";
|
|
9
|
+
callback.host = c.req.header("x-forwarded-host") || callback.host;
|
|
7
10
|
const client = new config.issuer.Client({
|
|
8
11
|
client_id: config.clientID,
|
|
9
|
-
redirect_uris: [callback],
|
|
12
|
+
redirect_uris: [callback.toString()],
|
|
10
13
|
response_types: ["id_token"],
|
|
11
14
|
});
|
|
12
15
|
const nonce = generators.nonce();
|
|
@@ -3,7 +3,7 @@ import { Adapter } from "./adapter/adapter.js";
|
|
|
3
3
|
import { JWTPayload } from "jose";
|
|
4
4
|
import { SessionBuilder } from "./session.js";
|
|
5
5
|
import { Hono } from "hono/tiny";
|
|
6
|
-
interface OnSuccessResponder<T extends {
|
|
6
|
+
export interface OnSuccessResponder<T extends {
|
|
7
7
|
type: any;
|
|
8
8
|
properties: any;
|
|
9
9
|
}> {
|
|
@@ -55,4 +55,3 @@ export declare function AuthHandler<Providers extends Record<string, Adapter<any
|
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
}): Hono<import("hono").Env, import("hono/types").BlankSchema, "/">;
|
|
58
|
-
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Handler } from "aws-lambda";
|
|
2
|
+
import { Adapter } from "../auth/adapter/adapter.js";
|
|
3
|
+
import { AuthHandler } from "../auth/handler.js";
|
|
4
|
+
import { SessionBuilder, createSessionBuilder } from "../auth/session.js";
|
|
5
|
+
export declare namespace auth {
|
|
6
|
+
type Issuer = import("openid-client").Issuer;
|
|
7
|
+
function authorizer<Providers extends Record<string, Adapter<any>>, Sessions extends SessionBuilder>(...args: Parameters<typeof AuthHandler<Providers, Sessions>>): Handler<any, any>;
|
|
8
|
+
const sessions: typeof createSessionBuilder;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthHandler } from "../auth/handler.js";
|
|
2
|
+
import { createSessionBuilder } from "../auth/session.js";
|
|
3
|
+
import { handle, streamHandle } from "hono/aws-lambda";
|
|
4
|
+
export var auth;
|
|
5
|
+
(function (auth) {
|
|
6
|
+
function authorizer(...args) {
|
|
7
|
+
const hono = AuthHandler(...args);
|
|
8
|
+
return (process.env.SST_LIVE ? handle(hono) : streamHandle(hono));
|
|
9
|
+
}
|
|
10
|
+
auth.authorizer = authorizer;
|
|
11
|
+
auth.sessions = createSessionBuilder;
|
|
12
|
+
})(auth || (auth = {}));
|
package/dist/src/aws/bus.js
CHANGED
|
@@ -2,8 +2,9 @@ import { client } from "../aws/client.js";
|
|
|
2
2
|
import { Resource } from "../resource.js";
|
|
3
3
|
export var bus;
|
|
4
4
|
(function (bus) {
|
|
5
|
-
function url(options) {
|
|
6
|
-
|
|
5
|
+
function url(region, options) {
|
|
6
|
+
if (options?.region)
|
|
7
|
+
region = options.region;
|
|
7
8
|
return `https://events.${region}.amazonaws.com/`;
|
|
8
9
|
}
|
|
9
10
|
function subscriber(_events, cb) {
|
|
@@ -22,15 +23,16 @@ export var bus;
|
|
|
22
23
|
* */
|
|
23
24
|
bus.handler = subscriber;
|
|
24
25
|
async function publish(name, def, properties, options) {
|
|
25
|
-
const
|
|
26
|
+
const c = await client();
|
|
27
|
+
const u = url(c.region, options?.aws);
|
|
26
28
|
const evt = typeof def === "string"
|
|
27
29
|
? {
|
|
28
30
|
type: def,
|
|
29
31
|
properties,
|
|
30
32
|
metadata: options?.metadata || {},
|
|
31
33
|
}
|
|
32
|
-
: await def.create(properties);
|
|
33
|
-
const res = await
|
|
34
|
+
: await def.create(properties, options?.metadata);
|
|
35
|
+
const res = await c.fetch(u, {
|
|
34
36
|
method: "POST",
|
|
35
37
|
aws: options?.aws,
|
|
36
38
|
headers: {
|
|
@@ -44,7 +46,7 @@ export var bus;
|
|
|
44
46
|
DetailType: evt.type,
|
|
45
47
|
Detail: JSON.stringify({
|
|
46
48
|
metadata: evt.metadata,
|
|
47
|
-
|
|
49
|
+
properties: evt.properties,
|
|
48
50
|
}),
|
|
49
51
|
EventBusName: typeof name === "string" ? name : name.name,
|
|
50
52
|
},
|
package/dist/src/aws/client.d.ts
CHANGED
package/dist/src/aws/client.js
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import { AwsClient } from "aws4fetch";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
let cachedCredentials = null;
|
|
3
|
+
async function getCredentials(url) {
|
|
4
|
+
if (cachedCredentials) {
|
|
5
|
+
const currentTime = new Date();
|
|
6
|
+
const fiveMinutesFromNow = new Date(currentTime.getTime() + 5 * 60000);
|
|
7
|
+
const expirationTime = new Date(cachedCredentials.Expiration);
|
|
8
|
+
if (expirationTime > fiveMinutesFromNow) {
|
|
9
|
+
return cachedCredentials;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const credentials = (await fetch(url).then((res) => res.json()));
|
|
13
|
+
cachedCredentials = credentials;
|
|
14
|
+
return credentials;
|
|
15
|
+
}
|
|
16
|
+
export async function client() {
|
|
17
|
+
if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
|
|
18
|
+
return new AwsClient({
|
|
19
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
20
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
21
|
+
sessionToken: process.env.AWS_SESSION_TOKEN,
|
|
22
|
+
region: process.env.AWS_REGION,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
|
|
26
|
+
const credentials = await getCredentials("http://169.254.170.2" +
|
|
27
|
+
process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI);
|
|
28
|
+
return new AwsClient({
|
|
29
|
+
accessKeyId: credentials.AccessKeyId,
|
|
30
|
+
secretAccessKey: credentials.SecretAccessKey,
|
|
31
|
+
sessionToken: credentials.Token,
|
|
32
|
+
region: process.env.AWS_REGION,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
throw new Error("No AWS credentials found");
|
|
36
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context, IoTCustomAuthorizerEvent } from "aws-lambda";
|
|
2
2
|
export declare namespace realtime {
|
|
3
3
|
interface AuthResult {
|
|
4
4
|
/**
|
|
@@ -57,5 +57,22 @@ export declare namespace realtime {
|
|
|
57
57
|
* });
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
function authorizer(input: (token: string) => Promise<AuthResult>):
|
|
60
|
+
function authorizer(input: (token: string) => Promise<AuthResult>): (evt: IoTCustomAuthorizerEvent, context: Context) => Promise<{
|
|
61
|
+
isAuthenticated: boolean;
|
|
62
|
+
principalId: string;
|
|
63
|
+
disconnectAfterInSeconds: number;
|
|
64
|
+
refreshAfterInSeconds: number;
|
|
65
|
+
policyDocuments: {
|
|
66
|
+
Version: string;
|
|
67
|
+
Statement: ({
|
|
68
|
+
Action: string;
|
|
69
|
+
Effect: string;
|
|
70
|
+
Resource: string;
|
|
71
|
+
} | {
|
|
72
|
+
Action: string;
|
|
73
|
+
Effect: string;
|
|
74
|
+
Resource: string[];
|
|
75
|
+
})[];
|
|
76
|
+
}[];
|
|
77
|
+
}>;
|
|
61
78
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ZodSchema, z } from "zod";
|
|
2
1
|
export declare namespace event {
|
|
3
2
|
export type Definition = {
|
|
4
3
|
type: string;
|
|
@@ -8,8 +7,8 @@ export declare namespace event {
|
|
|
8
7
|
$payload: any;
|
|
9
8
|
create: (...args: any[]) => Promise<any>;
|
|
10
9
|
};
|
|
11
|
-
export function builder<Metadata extends ((type: string, properties: any) => any) | Parameters<Validator>[0], Validator extends (schema: any) => (input: any) => any
|
|
12
|
-
validator
|
|
10
|
+
export function builder<Metadata extends ((type: string, properties: any) => any) | Parameters<Validator>[0], Validator extends (schema: any) => (input: any) => any>(input: {
|
|
11
|
+
validator: Validator;
|
|
13
12
|
metadata?: Metadata;
|
|
14
13
|
}): {
|
|
15
14
|
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
@@ -36,7 +35,6 @@ export declare namespace event {
|
|
|
36
35
|
type: K;
|
|
37
36
|
}>["$payload"]; }[Events["type"]];
|
|
38
37
|
};
|
|
39
|
-
export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
40
38
|
type ParserZodEsque<TInput, TParsedInput> = {
|
|
41
39
|
_input: TInput;
|
|
42
40
|
_output: TParsedInput;
|
package/dist/src/event/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export var event;
|
|
2
2
|
(function (event) {
|
|
3
3
|
function builder(input) {
|
|
4
|
-
const validator = input.validator
|
|
4
|
+
const validator = input.validator;
|
|
5
5
|
const fn = function event(type, schema) {
|
|
6
6
|
const validate = validator(schema);
|
|
7
7
|
async function create(properties, metadata) {
|
|
@@ -32,10 +32,4 @@ export var event;
|
|
|
32
32
|
return fn;
|
|
33
33
|
}
|
|
34
34
|
event.builder = builder;
|
|
35
|
-
function ZodValidator(schema) {
|
|
36
|
-
return (input) => {
|
|
37
|
-
return schema.parse(input);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
event.ZodValidator = ZodValidator;
|
|
41
35
|
})(event || (event = {}));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ZodSchema, z } from "zod";
|
|
2
|
+
export declare function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
3
|
+
import { BaseSchema, Input } from "valibot";
|
|
4
|
+
export declare function ValibotValidator<T extends BaseSchema>(schema: T): (value: Input<T>) => import("valibot").Output<T>;
|
package/dist/src/resource.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { env } from "
|
|
1
|
+
import { env } from "process";
|
|
2
2
|
const raw = {
|
|
3
3
|
// @ts-expect-error,
|
|
4
4
|
...globalThis.$SST_LINKS,
|
|
@@ -45,6 +45,10 @@ export const Resource = new Proxy(raw, {
|
|
|
45
45
|
if (prop in raw) {
|
|
46
46
|
return raw[prop];
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
let msg = `"${prop}" is not linked`;
|
|
49
|
+
if (env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
50
|
+
msg += ` to ${env.AWS_LAMBDA_FUNCTION_NAME}`;
|
|
51
|
+
}
|
|
52
|
+
throw new Error(msg);
|
|
49
53
|
},
|
|
50
54
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.509",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@tsconfig/node20": "20.1.4",
|
|
22
|
+
"@types/bun": "^1.1.6",
|
|
22
23
|
"@types/node": "20.11.0",
|
|
23
24
|
"hono": "4.3.9",
|
|
24
25
|
"typescript": "5.3.3",
|
|
@@ -47,4 +48,4 @@
|
|
|
47
48
|
"jose": "5.2.3",
|
|
48
49
|
"openid-client": "5.6.4"
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
+
}
|