sst 3.0.22 → 3.0.24
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/test/event.test.js +1 -7
- package/package.json +1 -1
- package/dist/auth/adapter/adapter.d.ts +0 -24
- package/dist/auth/adapter/adapter.js +0 -4
- package/dist/auth/adapter/apple.d.ts +0 -5
- package/dist/auth/adapter/apple.js +0 -22
- package/dist/auth/adapter/code.d.ts +0 -8
- package/dist/auth/adapter/code.js +0 -47
- package/dist/auth/adapter/facebook.d.ts +0 -5
- package/dist/auth/adapter/facebook.js +0 -27
- package/dist/auth/adapter/github.d.ts +0 -12
- package/dist/auth/adapter/github.js +0 -23
- package/dist/auth/adapter/google.d.ts +0 -17
- package/dist/auth/adapter/google.js +0 -22
- package/dist/auth/adapter/index.d.ts +0 -11
- package/dist/auth/adapter/index.js +0 -10
- package/dist/auth/adapter/link.d.ts +0 -6
- package/dist/auth/adapter/link.js +0 -27
- package/dist/auth/adapter/microsoft.d.ts +0 -11
- package/dist/auth/adapter/microsoft.js +0 -16
- package/dist/auth/adapter/oauth.d.ts +0 -33
- package/dist/auth/adapter/oauth.js +0 -79
- package/dist/auth/adapter/oidc.d.ts +0 -19
- package/dist/auth/adapter/oidc.js +0 -45
- package/dist/auth/adapter/spotify.d.ts +0 -12
- package/dist/auth/adapter/spotify.js +0 -22
- package/dist/auth/example/bun.d.ts +0 -2
- package/dist/auth/example/bun.js +0 -46
- package/dist/auth/handler.d.ts +0 -58
- package/dist/auth/handler.js +0 -207
- package/dist/auth/index.d.ts +0 -10
- package/dist/auth/index.js +0 -10
- package/dist/auth/session.d.ts +0 -25
- package/dist/auth/session.js +0 -28
- package/dist/aws/bus.d.ts +0 -24
- package/dist/aws/bus.js +0 -57
- package/dist/aws/client.d.ts +0 -3
- package/dist/aws/client.js +0 -7
- package/dist/aws/realtime.d.ts +0 -61
- package/dist/aws/realtime.js +0 -76
- package/dist/event/bus.d.ts +0 -20
- package/dist/event/bus.js +0 -57
- package/dist/event/destination.d.ts +0 -19
- package/dist/event/destination.js +0 -6
- package/dist/event/event.d.ts +0 -75
- package/dist/event/event.js +0 -43
- package/dist/event/index.d.ts +0 -75
- package/dist/event/index.js +0 -43
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/realtime/index.d.ts +0 -25
- package/dist/realtime/index.js +0 -24
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -50
- package/dist/util/prettify.d.ts +0 -3
- package/dist/util/prettify.js +0 -1
- package/dist/vector/index.d.ts +0 -193
- package/dist/vector/index.js +0 -62
- package/dist/vector-client.d.ts +0 -186
- package/dist/vector-client.js +0 -41
package/dist/auth/handler.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { Adapter } from "./adapter/adapter.js";
|
|
3
|
-
import { JWTPayload } from "jose";
|
|
4
|
-
import { SessionBuilder } from "./session.js";
|
|
5
|
-
import { Hono } from "hono/tiny";
|
|
6
|
-
interface OnSuccessResponder<T extends {
|
|
7
|
-
type: any;
|
|
8
|
-
properties: any;
|
|
9
|
-
}> {
|
|
10
|
-
session(input: T & JWTPayload): Promise<Response>;
|
|
11
|
-
}
|
|
12
|
-
export declare class UnknownProviderError extends Error {
|
|
13
|
-
provider?: string | undefined;
|
|
14
|
-
constructor(provider?: string | undefined);
|
|
15
|
-
}
|
|
16
|
-
export declare class MissingParameterError extends Error {
|
|
17
|
-
parameter: string;
|
|
18
|
-
constructor(parameter: string);
|
|
19
|
-
}
|
|
20
|
-
export declare class UnknownStateError extends Error {
|
|
21
|
-
constructor();
|
|
22
|
-
}
|
|
23
|
-
export declare class UnauthorizedClientError extends Error {
|
|
24
|
-
client: string;
|
|
25
|
-
redirect_uri: string;
|
|
26
|
-
constructor(client: string, redirect_uri: string);
|
|
27
|
-
}
|
|
28
|
-
export declare class InvalidSessionError extends Error {
|
|
29
|
-
constructor();
|
|
30
|
-
}
|
|
31
|
-
export type Prettify<T> = {
|
|
32
|
-
[K in keyof T]: T[K];
|
|
33
|
-
} & {};
|
|
34
|
-
export declare const aws: <E extends import("hono").Env = import("hono").Env, S extends import("hono").Schema = {}, BasePath extends string = "/">(app: import("hono").Hono<E, S, BasePath>) => (event: import("hono/aws-lambda").LambdaEvent, lambdaContext?: import("hono/aws-lambda").LambdaContext | undefined) => Promise<import("hono/aws-lambda").APIGatewayProxyResult>;
|
|
35
|
-
export declare function AuthHandler<Providers extends Record<string, Adapter<any>>, Sessions extends SessionBuilder = SessionBuilder, Result = {
|
|
36
|
-
[key in keyof Providers]: Prettify<{
|
|
37
|
-
provider: key;
|
|
38
|
-
} & (Providers[key] extends Adapter<infer T> ? T : {})>;
|
|
39
|
-
}[keyof Providers]>(input: {
|
|
40
|
-
session?: Sessions;
|
|
41
|
-
providers: Providers;
|
|
42
|
-
callbacks: {
|
|
43
|
-
index?(req: Request): Promise<Response>;
|
|
44
|
-
error?(error: UnknownStateError, req: Request): Promise<Response | undefined>;
|
|
45
|
-
auth: {
|
|
46
|
-
error?(error: MissingParameterError | UnauthorizedClientError | UnknownProviderError, req: Request): Promise<Response>;
|
|
47
|
-
start?(event: Request): Promise<void>;
|
|
48
|
-
allowClient(clientID: string, redirect: string, req: Request): Promise<boolean>;
|
|
49
|
-
success(response: OnSuccessResponder<Sessions["$typeValues"]>, input: Result, req: Request): Promise<Response>;
|
|
50
|
-
};
|
|
51
|
-
connect?: {
|
|
52
|
-
error?(error: InvalidSessionError | UnknownProviderError, req: Request): Promise<Response | undefined>;
|
|
53
|
-
start?(session: Sessions["$typeValues"], req: Request): Promise<void>;
|
|
54
|
-
success?(session: Sessions["$typeValues"], input: {}): Promise<Response>;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
}): Hono<import("hono").Env, import("hono/types").BlankSchema, "/">;
|
|
58
|
-
export {};
|
package/dist/auth/handler.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { SignJWT, importPKCS8, importSPKI, jwtVerify } from "jose";
|
|
2
|
-
import { Hono } from "hono/tiny";
|
|
3
|
-
import { handle as awsHandle } from "hono/aws-lambda";
|
|
4
|
-
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
|
|
5
|
-
export class UnknownProviderError extends Error {
|
|
6
|
-
provider;
|
|
7
|
-
constructor(provider) {
|
|
8
|
-
super("Unknown provider: " + provider);
|
|
9
|
-
this.provider = provider;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export class MissingParameterError extends Error {
|
|
13
|
-
parameter;
|
|
14
|
-
constructor(parameter) {
|
|
15
|
-
super("Missing parameter: " + parameter);
|
|
16
|
-
this.parameter = parameter;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class UnknownStateError extends Error {
|
|
20
|
-
constructor() {
|
|
21
|
-
super("The browser was in an unknown state. This could be because certain cookies expired or the browser was switched in the middle of an authentication flow");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class UnauthorizedClientError extends Error {
|
|
25
|
-
client;
|
|
26
|
-
redirect_uri;
|
|
27
|
-
constructor(client, redirect_uri) {
|
|
28
|
-
super("Unauthorized client");
|
|
29
|
-
this.client = client;
|
|
30
|
-
this.redirect_uri = redirect_uri;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class InvalidSessionError extends Error {
|
|
34
|
-
constructor() {
|
|
35
|
-
super("Invalid session");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
import process from "node:process";
|
|
39
|
-
import { Resource } from "../resource.js";
|
|
40
|
-
export const aws = awsHandle;
|
|
41
|
-
export function AuthHandler(input) {
|
|
42
|
-
const app = new Hono();
|
|
43
|
-
if (!input.callbacks.auth.error) {
|
|
44
|
-
input.callbacks.auth.error = async (err) => {
|
|
45
|
-
return new Response(err.message, {
|
|
46
|
-
status: 400,
|
|
47
|
-
headers: {
|
|
48
|
-
"Content-Type": "text/plain",
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const options = {
|
|
54
|
-
signing: {
|
|
55
|
-
privateKey: () => importPKCS8(
|
|
56
|
-
// @ts-expect-error
|
|
57
|
-
process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RS512"),
|
|
58
|
-
publicKey: () => importSPKI(
|
|
59
|
-
// @ts-expect-error
|
|
60
|
-
process.env.AUTH_PUBLIC_KEY || Resource.AUTH_PUBLIC_KEY, "RS512"),
|
|
61
|
-
},
|
|
62
|
-
encryption: {
|
|
63
|
-
privateKey: () => importPKCS8(
|
|
64
|
-
// @ts-expect-error
|
|
65
|
-
process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RSA-OAEP-512"),
|
|
66
|
-
publicKey: () => importSPKI(
|
|
67
|
-
// @ts-expect-error
|
|
68
|
-
process.env.AUTH_PUBLIC_KEY || Resource.AUTH_PUBLIC_KEY, "RSA-OAEP-512"),
|
|
69
|
-
},
|
|
70
|
-
algorithm: "RS512",
|
|
71
|
-
async success(ctx, properties) {
|
|
72
|
-
const redirect_uri = getCookie(ctx, "redirect_uri");
|
|
73
|
-
const response_type = getCookie(ctx, "response_type");
|
|
74
|
-
if (!redirect_uri) {
|
|
75
|
-
return options.forward(ctx, await input.callbacks.auth.error(new UnknownStateError(), ctx.req.raw));
|
|
76
|
-
}
|
|
77
|
-
return await input.callbacks.auth.success({
|
|
78
|
-
async session(session) {
|
|
79
|
-
const token = await new SignJWT(session)
|
|
80
|
-
.setProtectedHeader({ alg: "RS512" })
|
|
81
|
-
.setExpirationTime("1yr")
|
|
82
|
-
.sign(await options.signing.privateKey());
|
|
83
|
-
deleteCookie(ctx, "provider");
|
|
84
|
-
deleteCookie(ctx, "response_type");
|
|
85
|
-
deleteCookie(ctx, "redirect_uri");
|
|
86
|
-
deleteCookie(ctx, "state");
|
|
87
|
-
const client_id = getCookie(ctx, "client_id");
|
|
88
|
-
const state = getCookie(ctx, "state");
|
|
89
|
-
if (response_type === "token") {
|
|
90
|
-
const location = new URL(redirect_uri);
|
|
91
|
-
location.hash = `access_token=${token}&state=${state || ""}`;
|
|
92
|
-
return ctx.redirect(location.toString(), 302);
|
|
93
|
-
}
|
|
94
|
-
if (response_type === "code") {
|
|
95
|
-
// This allows the code to be reused within a 30 second window
|
|
96
|
-
// The code should be single use but we're making this tradeoff to remain stateless
|
|
97
|
-
// In the future can store this in a dynamo table to ensure single use
|
|
98
|
-
const code = await new SignJWT({
|
|
99
|
-
client_id,
|
|
100
|
-
redirect_uri,
|
|
101
|
-
token,
|
|
102
|
-
})
|
|
103
|
-
.setProtectedHeader({ alg: "RS512" })
|
|
104
|
-
.setExpirationTime("30s")
|
|
105
|
-
.sign(await options.signing.privateKey());
|
|
106
|
-
const location = new URL(redirect_uri);
|
|
107
|
-
location.searchParams.set("code", code);
|
|
108
|
-
location.searchParams.set("state", state || "");
|
|
109
|
-
return ctx.redirect(location.toString(), 302);
|
|
110
|
-
}
|
|
111
|
-
ctx.status(400);
|
|
112
|
-
return ctx.text(`Unsupported response_type: ${response_type}`);
|
|
113
|
-
},
|
|
114
|
-
}, {
|
|
115
|
-
provider: ctx.get("provider"),
|
|
116
|
-
...properties,
|
|
117
|
-
}, ctx.req.raw);
|
|
118
|
-
},
|
|
119
|
-
forward(ctx, response) {
|
|
120
|
-
return ctx.newResponse(response.body, response.status, Object.fromEntries(response.headers.entries()));
|
|
121
|
-
},
|
|
122
|
-
cookie(c, key, value, maxAge) {
|
|
123
|
-
setCookie(c, key, value, {
|
|
124
|
-
maxAge,
|
|
125
|
-
httpOnly: true,
|
|
126
|
-
...(c.req.url.startsWith("https://")
|
|
127
|
-
? { secure: true, sameSite: "None" }
|
|
128
|
-
: {}),
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
app.post("/token", async (c) => {
|
|
133
|
-
console.log("token request");
|
|
134
|
-
const form = await c.req.formData();
|
|
135
|
-
if (form.get("grant_type") !== "authorization_code") {
|
|
136
|
-
c.status(400);
|
|
137
|
-
return c.text("Invalid grant_type");
|
|
138
|
-
}
|
|
139
|
-
const code = form.get("code");
|
|
140
|
-
if (!code) {
|
|
141
|
-
c.status(400);
|
|
142
|
-
return c.text("Missing code");
|
|
143
|
-
}
|
|
144
|
-
const { payload } = await jwtVerify(code, await options.signing.publicKey());
|
|
145
|
-
if (payload.redirect_uri !== form.get("redirect_uri")) {
|
|
146
|
-
c.status(400);
|
|
147
|
-
return c.text("redirect_uri mismatch");
|
|
148
|
-
}
|
|
149
|
-
if (payload.client_id !== form.get("client_id")) {
|
|
150
|
-
c.status(400);
|
|
151
|
-
return c.text("client_id mismatch");
|
|
152
|
-
}
|
|
153
|
-
return c.json({
|
|
154
|
-
access_token: payload.token,
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
app.use("/:provider/authorize", async (c, next) => {
|
|
158
|
-
const provider = c.req.param("provider");
|
|
159
|
-
console.log("authorize request for", provider);
|
|
160
|
-
const response_type = c.req.query("response_type") || getCookie(c, "response_type");
|
|
161
|
-
const redirect_uri = c.req.query("redirect_uri") || getCookie(c, "redirect_uri");
|
|
162
|
-
const state = c.req.query("state") || getCookie(c, "state");
|
|
163
|
-
const client_id = c.req.query("client_id") || getCookie(c, "client_id");
|
|
164
|
-
if (!provider) {
|
|
165
|
-
c.status(400);
|
|
166
|
-
return c.text("Missing provider");
|
|
167
|
-
}
|
|
168
|
-
if (!redirect_uri) {
|
|
169
|
-
c.status(400);
|
|
170
|
-
return c.text("Missing redirect_uri");
|
|
171
|
-
}
|
|
172
|
-
if (!response_type) {
|
|
173
|
-
c.status(400);
|
|
174
|
-
return c.text("Missing response_type");
|
|
175
|
-
}
|
|
176
|
-
if (!client_id) {
|
|
177
|
-
c.status(400);
|
|
178
|
-
return c.text("Missing client_id");
|
|
179
|
-
}
|
|
180
|
-
options.cookie(c, "provider", provider, 60 * 10);
|
|
181
|
-
options.cookie(c, "response_type", response_type, 60 * 10);
|
|
182
|
-
options.cookie(c, "redirect_uri", redirect_uri, 60 * 10);
|
|
183
|
-
options.cookie(c, "state", state || "", 60 * 10);
|
|
184
|
-
options.cookie(c, "client_id", client_id || "", 60 * 10);
|
|
185
|
-
if (input.callbacks.auth.start) {
|
|
186
|
-
await input.callbacks.auth.start(c.req.raw);
|
|
187
|
-
}
|
|
188
|
-
await next();
|
|
189
|
-
});
|
|
190
|
-
for (const [name, value] of Object.entries(input.providers)) {
|
|
191
|
-
const route = new Hono();
|
|
192
|
-
route.use(async (c, next) => {
|
|
193
|
-
c.set("provider", name);
|
|
194
|
-
await next();
|
|
195
|
-
});
|
|
196
|
-
value(route, {
|
|
197
|
-
name,
|
|
198
|
-
...options,
|
|
199
|
-
});
|
|
200
|
-
app.route(`/${name}`, route);
|
|
201
|
-
}
|
|
202
|
-
app.all("/*", async (c) => {
|
|
203
|
-
return c.notFound();
|
|
204
|
-
});
|
|
205
|
-
console.log(app.routes);
|
|
206
|
-
return app;
|
|
207
|
-
}
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./session.js";
|
|
2
|
-
export * from "./handler.js";
|
|
3
|
-
export { Issuer } from "openid-client";
|
|
4
|
-
import { AuthHandler } from "./handler.js";
|
|
5
|
-
import { createSessionBuilder } from "./session.js";
|
|
6
|
-
export declare namespace auth {
|
|
7
|
-
type Issuer = import("openid-client").Issuer;
|
|
8
|
-
const authorizer: typeof AuthHandler;
|
|
9
|
-
const sessions: typeof createSessionBuilder;
|
|
10
|
-
}
|
package/dist/auth/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./session.js";
|
|
2
|
-
export * from "./handler.js";
|
|
3
|
-
export { Issuer } from "openid-client";
|
|
4
|
-
import { AuthHandler } from "./handler.js";
|
|
5
|
-
import { createSessionBuilder } from "./session.js";
|
|
6
|
-
export var auth;
|
|
7
|
-
(function (auth) {
|
|
8
|
-
auth.authorizer = AuthHandler;
|
|
9
|
-
auth.sessions = createSessionBuilder;
|
|
10
|
-
})(auth || (auth = {}));
|
package/dist/auth/session.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export type SessionBuilder = ReturnType<typeof createSessionBuilder>;
|
|
2
|
-
export declare function createSessionBuilder<SessionTypes extends Record<string, any> = {}>(): {
|
|
3
|
-
verify(token: string): Promise<{ [type in keyof SessionTypes]: {
|
|
4
|
-
type: type;
|
|
5
|
-
properties: SessionTypes[type];
|
|
6
|
-
}; }[keyof SessionTypes] | {
|
|
7
|
-
type: "public";
|
|
8
|
-
properties: {};
|
|
9
|
-
}>;
|
|
10
|
-
create(session: { [type in keyof SessionTypes]: {
|
|
11
|
-
type: type;
|
|
12
|
-
properties: SessionTypes[type];
|
|
13
|
-
}; }[keyof SessionTypes] | {
|
|
14
|
-
type: "public";
|
|
15
|
-
properties: {};
|
|
16
|
-
}): Promise<string>;
|
|
17
|
-
$type: SessionTypes;
|
|
18
|
-
$typeValues: { [type in keyof SessionTypes]: {
|
|
19
|
-
type: type;
|
|
20
|
-
properties: SessionTypes[type];
|
|
21
|
-
}; }[keyof SessionTypes] | {
|
|
22
|
-
type: "public";
|
|
23
|
-
properties: {};
|
|
24
|
-
};
|
|
25
|
-
};
|
package/dist/auth/session.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { SignJWT, importPKCS8, importSPKI, jwtVerify } from "jose";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
export function createSessionBuilder() {
|
|
5
|
-
return {
|
|
6
|
-
async verify(token) {
|
|
7
|
-
const auth = Object.values(Resource).find((value) => value.publicKey);
|
|
8
|
-
if (!auth) {
|
|
9
|
-
throw new Error("No auth resource found. Make sure to link the auth resource to this function.");
|
|
10
|
-
}
|
|
11
|
-
const publicKey = auth.publicKey;
|
|
12
|
-
const result = await jwtVerify(token, await importSPKI(publicKey, "RS512"));
|
|
13
|
-
return result.payload;
|
|
14
|
-
},
|
|
15
|
-
async create(session) {
|
|
16
|
-
const privateKey = await importPKCS8(
|
|
17
|
-
// @ts-expect-error
|
|
18
|
-
process.env.AUTH_PRIVATE_KEY || Resource.AUTH_PRIVATE_KEY, "RS512");
|
|
19
|
-
const token = await new SignJWT(session)
|
|
20
|
-
.setProtectedHeader({ alg: "RS512" })
|
|
21
|
-
.setExpirationTime("1yr")
|
|
22
|
-
.sign(privateKey);
|
|
23
|
-
return token;
|
|
24
|
-
},
|
|
25
|
-
$type: {},
|
|
26
|
-
$typeValues: {},
|
|
27
|
-
};
|
|
28
|
-
}
|
package/dist/aws/bus.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { AwsOptions } from "../aws/client.js";
|
|
3
|
-
import { Resource } from "../resource.js";
|
|
4
|
-
import { event } from "../event/index.js";
|
|
5
|
-
import { EventBridgeEvent, EventBridgeHandler } from "aws-lambda";
|
|
6
|
-
export declare namespace bus {
|
|
7
|
-
type Name = Extract<typeof Resource, {
|
|
8
|
-
type: "sst.aws.Bus";
|
|
9
|
-
}>["name"];
|
|
10
|
-
function handle<Events extends event.Definition>(_events: Events | Events[], cb: (input: {
|
|
11
|
-
[K in Events["type"]]: Extract<Events, {
|
|
12
|
-
type: K;
|
|
13
|
-
}>["$payload"];
|
|
14
|
-
}[Events["type"]], raw: EventBridgeEvent<string, any>) => Promise<void>): EventBridgeHandler<string, any, void>;
|
|
15
|
-
function publish<Definition extends event.Definition>(name: string | {
|
|
16
|
-
name: string;
|
|
17
|
-
}, def: Definition, properties: Definition["$input"], options?: {
|
|
18
|
-
aws?: AwsOptions;
|
|
19
|
-
}): Promise<any>;
|
|
20
|
-
class PublishError extends Error {
|
|
21
|
-
readonly response: Response;
|
|
22
|
-
constructor(response: Response);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/dist/aws/bus.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { client } from "../aws/client.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
3
|
-
export var bus;
|
|
4
|
-
(function (bus) {
|
|
5
|
-
function url(options) {
|
|
6
|
-
const region = options?.region || client.region;
|
|
7
|
-
return `https://events.${region}.amazonaws.com/`;
|
|
8
|
-
}
|
|
9
|
-
function handle(_events, cb) {
|
|
10
|
-
return async function (event) {
|
|
11
|
-
const payload = {
|
|
12
|
-
type: event["detail-type"],
|
|
13
|
-
properties: event.detail.properties,
|
|
14
|
-
metadata: event.detail.metadata,
|
|
15
|
-
};
|
|
16
|
-
return cb(payload, event);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
bus.handle = handle;
|
|
20
|
-
async function publish(name, def, properties, options) {
|
|
21
|
-
const u = url(options?.aws);
|
|
22
|
-
const evt = await def.create(properties);
|
|
23
|
-
const res = await client.fetch(u, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
aws: options?.aws,
|
|
26
|
-
headers: {
|
|
27
|
-
"X-Amz-Target": "AWSEvents.PutEvents",
|
|
28
|
-
"Content-Type": "application/x-amz-json-1.1",
|
|
29
|
-
},
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
Entries: [
|
|
32
|
-
{
|
|
33
|
-
Source: [Resource.App.name, Resource.App.stage].join("."),
|
|
34
|
-
DetailType: evt.type,
|
|
35
|
-
Detail: JSON.stringify({
|
|
36
|
-
metadata: evt.metadata,
|
|
37
|
-
payload: evt.properties,
|
|
38
|
-
}),
|
|
39
|
-
EventBusName: typeof name === "string" ? name : name.name,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
if (!res.ok)
|
|
45
|
-
throw new PublishError(res);
|
|
46
|
-
return res.json();
|
|
47
|
-
}
|
|
48
|
-
bus.publish = publish;
|
|
49
|
-
class PublishError extends Error {
|
|
50
|
-
response;
|
|
51
|
-
constructor(response) {
|
|
52
|
-
super("Failed to publish event to bus");
|
|
53
|
-
this.response = response;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
bus.PublishError = PublishError;
|
|
57
|
-
})(bus || (bus = {}));
|
package/dist/aws/client.d.ts
DELETED
package/dist/aws/client.js
DELETED
package/dist/aws/realtime.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { IoTCustomAuthorizerHandler } from "aws-lambda";
|
|
2
|
-
export declare namespace realtime {
|
|
3
|
-
interface AuthResult {
|
|
4
|
-
/**
|
|
5
|
-
* The topics the client can subscribe to.
|
|
6
|
-
* @example
|
|
7
|
-
* For example, this subscribes to specific topics.
|
|
8
|
-
* ```js
|
|
9
|
-
* {
|
|
10
|
-
* subscribe: ["chat/room1", "chat/room2"]
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* And to subscribe to all topics under a specific prefix.
|
|
15
|
-
* ```js
|
|
16
|
-
* {
|
|
17
|
-
* subscribe: ["chat/*"]
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
subscribe?: string[];
|
|
22
|
-
/**
|
|
23
|
-
* The topics the client can publish to.
|
|
24
|
-
* @example
|
|
25
|
-
* For example, this publishes to specific topics.
|
|
26
|
-
* ```js
|
|
27
|
-
* {
|
|
28
|
-
* publish: ["chat/room1", "chat/room2"]
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
* And to publish to all topics under a specific prefix.
|
|
32
|
-
* ```js
|
|
33
|
-
* {
|
|
34
|
-
* publish: ["chat/*"]
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
publish?: string[];
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates an authorization handler for the `Realtime` component, that validates
|
|
42
|
-
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```js
|
|
46
|
-
* import { realtime } from "sst/aws/realtime";
|
|
47
|
-
*
|
|
48
|
-
* export const handler = realtime.authorizer(async (token) => {
|
|
49
|
-
* // Validate the token
|
|
50
|
-
* console.log(token);
|
|
51
|
-
*
|
|
52
|
-
* // Return the topics to subscribe and publish
|
|
53
|
-
* return {
|
|
54
|
-
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
55
|
-
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
56
|
-
* };
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
function authorizer(input: (token: string) => Promise<AuthResult>): IoTCustomAuthorizerHandler;
|
|
61
|
-
}
|
package/dist/aws/realtime.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
export var realtime;
|
|
2
|
-
(function (realtime) {
|
|
3
|
-
/**
|
|
4
|
-
* Creates an authorization handler for the `Realtime` component, that validates
|
|
5
|
-
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```js
|
|
9
|
-
* import { realtime } from "sst/aws/realtime";
|
|
10
|
-
*
|
|
11
|
-
* export const handler = realtime.authorizer(async (token) => {
|
|
12
|
-
* // Validate the token
|
|
13
|
-
* console.log(token);
|
|
14
|
-
*
|
|
15
|
-
* // Return the topics to subscribe and publish
|
|
16
|
-
* return {
|
|
17
|
-
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
18
|
-
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
19
|
-
* };
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
function authorizer(input) {
|
|
24
|
-
return async (evt, context) => {
|
|
25
|
-
const [, , , region, accountId] = context.invokedFunctionArn.split(":");
|
|
26
|
-
const token = Buffer.from(evt.protocolData.mqtt?.password ?? "", "base64").toString();
|
|
27
|
-
const ret = await input(token);
|
|
28
|
-
return {
|
|
29
|
-
isAuthenticated: true,
|
|
30
|
-
principalId: Date.now().toString(),
|
|
31
|
-
disconnectAfterInSeconds: 86400,
|
|
32
|
-
refreshAfterInSeconds: 300,
|
|
33
|
-
policyDocuments: [
|
|
34
|
-
{
|
|
35
|
-
Version: "2012-10-17",
|
|
36
|
-
Statement: [
|
|
37
|
-
{
|
|
38
|
-
Action: "iot:Connect",
|
|
39
|
-
Effect: "Allow",
|
|
40
|
-
Resource: "*",
|
|
41
|
-
},
|
|
42
|
-
...(ret.subscribe
|
|
43
|
-
? [
|
|
44
|
-
{
|
|
45
|
-
Action: "iot:Receive",
|
|
46
|
-
Effect: "Allow",
|
|
47
|
-
Resource: ret.subscribe.map((t) => `arn:aws:iot:${region}:${accountId}:topic/${t}`),
|
|
48
|
-
},
|
|
49
|
-
]
|
|
50
|
-
: []),
|
|
51
|
-
...(ret.subscribe
|
|
52
|
-
? [
|
|
53
|
-
{
|
|
54
|
-
Action: "iot:Subscribe",
|
|
55
|
-
Effect: "Allow",
|
|
56
|
-
Resource: ret.subscribe.map((t) => `arn:aws:iot:${region}:${accountId}:topicfilter/${t}`),
|
|
57
|
-
},
|
|
58
|
-
]
|
|
59
|
-
: []),
|
|
60
|
-
...(ret.publish
|
|
61
|
-
? [
|
|
62
|
-
{
|
|
63
|
-
Action: "iot:Publish",
|
|
64
|
-
Effect: "Allow",
|
|
65
|
-
Resource: ret.publish.map((t) => `arn:aws:iot:${region}:${accountId}:topic/${t}`),
|
|
66
|
-
},
|
|
67
|
-
]
|
|
68
|
-
: []),
|
|
69
|
-
],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
realtime.authorizer = authorizer;
|
|
76
|
-
})(realtime || (realtime = {}));
|
package/dist/event/bus.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { AwsOptions } from "../aws/client.js";
|
|
3
|
-
import { Resource } from "../resource.js";
|
|
4
|
-
import { EventDefinition } from "./event.js";
|
|
5
|
-
import { EventBridgeEvent, EventBridgeHandler } from "aws-lambda";
|
|
6
|
-
export declare namespace bus {
|
|
7
|
-
type Name = Extract<typeof Resource, {
|
|
8
|
-
type: "sst.aws.Bus";
|
|
9
|
-
}>["name"];
|
|
10
|
-
function handle<Events extends EventDefinition>(_events: Events | Events[], cb: (input: {
|
|
11
|
-
[K in Events["type"]]: Extract<Events, {
|
|
12
|
-
type: K;
|
|
13
|
-
}>["$payload"];
|
|
14
|
-
}[Events["type"]], raw: EventBridgeEvent<string, any>) => Promise<void>): EventBridgeHandler<string, any, void>;
|
|
15
|
-
function publish<N extends Name, Definition extends EventDefinition>(name: N, def: Definition, properties: Definition["$input"], options?: AwsOptions): Promise<unknown>;
|
|
16
|
-
class PublishError extends Error {
|
|
17
|
-
readonly response: Response;
|
|
18
|
-
constructor(response: Response);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/dist/event/bus.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { client } from "../aws/client.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
3
|
-
export var bus;
|
|
4
|
-
(function (bus) {
|
|
5
|
-
function url(options) {
|
|
6
|
-
const region = options?.region || client.region;
|
|
7
|
-
return `https://events.${region}.amazonaws.com/`;
|
|
8
|
-
}
|
|
9
|
-
function handle(_events, cb) {
|
|
10
|
-
return async function (event) {
|
|
11
|
-
const payload = {
|
|
12
|
-
type: event["detail-type"],
|
|
13
|
-
properties: event.detail.properties,
|
|
14
|
-
metadata: event.detail.metadata,
|
|
15
|
-
};
|
|
16
|
-
return cb(payload, event);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
bus.handle = handle;
|
|
20
|
-
async function publish(name, def, properties, options) {
|
|
21
|
-
const u = url(options);
|
|
22
|
-
const evt = await def.create(properties);
|
|
23
|
-
const res = await client.fetch(u, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
aws: options,
|
|
26
|
-
headers: {
|
|
27
|
-
"X-Amz-Target": "AWSEvents.PutEvents",
|
|
28
|
-
"Content-Type": "application/x-amz-json-1.1",
|
|
29
|
-
},
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
Entries: [
|
|
32
|
-
{
|
|
33
|
-
Source: [Resource.App.name, Resource.App.stage].join("."),
|
|
34
|
-
DetailType: evt.type,
|
|
35
|
-
Detail: JSON.stringify({
|
|
36
|
-
metadata: evt.metadata,
|
|
37
|
-
payload: evt.properties,
|
|
38
|
-
}),
|
|
39
|
-
EventBusName: name,
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
if (!res.ok)
|
|
45
|
-
throw new PublishError(res);
|
|
46
|
-
return res.json();
|
|
47
|
-
}
|
|
48
|
-
bus.publish = publish;
|
|
49
|
-
class PublishError extends Error {
|
|
50
|
-
response;
|
|
51
|
-
constructor(response) {
|
|
52
|
-
super("Failed to publish event to bus");
|
|
53
|
-
this.response = response;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
bus.PublishError = PublishError;
|
|
57
|
-
})(bus || (bus = {}));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Prettify } from "../util/prettify.js";
|
|
2
|
-
export interface Payload {
|
|
3
|
-
type: string;
|
|
4
|
-
properties: any;
|
|
5
|
-
metadata: any;
|
|
6
|
-
}
|
|
7
|
-
declare const Publishers: {
|
|
8
|
-
"sst.aws.Bus": (properties: {
|
|
9
|
-
name: string;
|
|
10
|
-
}, payload: Payload) => void;
|
|
11
|
-
};
|
|
12
|
-
type Publishers = typeof Publishers;
|
|
13
|
-
export type Destinations = {
|
|
14
|
-
[key in keyof Publishers]: Prettify<{
|
|
15
|
-
type: key;
|
|
16
|
-
} & Parameters<Publishers[key]>[0]>;
|
|
17
|
-
}[keyof Publishers];
|
|
18
|
-
export declare function publish(destination: Destinations, payload: Payload): void;
|
|
19
|
-
export {};
|