sst 3.0.18 → 3.0.20

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.
@@ -8,3 +8,4 @@ export * from "./oauth.js";
8
8
  export * from "./spotify.js";
9
9
  export * from "./code.js";
10
10
  export * from "./apple.js";
11
+ export type { Adapter } from "./adapter.js";
@@ -1,4 +1,4 @@
1
- export type { Adapter } from "./adapter/adapter.js";
1
+ export * from "./adapter/index.js";
2
2
  export * from "./session.js";
3
3
  export * from "./handler.js";
4
4
  export { Issuer } from "openid-client";
@@ -1,3 +1,4 @@
1
+ export * from "./adapter/index.js";
1
2
  export * from "./session.js";
2
3
  export * from "./handler.js";
3
4
  export { Issuer } from "openid-client";
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,57 @@
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 = {}));
@@ -0,0 +1,3 @@
1
+ import { AwsClient } from "aws4fetch";
2
+ export declare const client: AwsClient;
3
+ export type AwsOptions = Exclude<Parameters<AwsClient["fetch"]>[1], null | undefined>["aws"];
@@ -0,0 +1,7 @@
1
+ import { AwsClient } from "aws4fetch";
2
+ export const client = new AwsClient({
3
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
4
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
5
+ sessionToken: process.env.AWS_SESSION_TOKEN,
6
+ region: process.env.AWS_REGION,
7
+ });
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1,76 @@
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 = {}));
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,57 @@
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 = {}));
@@ -0,0 +1,19 @@
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 {};
@@ -0,0 +1,6 @@
1
+ const Publishers = {
2
+ "sst.aws.Bus": (properties, payload) => { },
3
+ };
4
+ export function publish(destination, payload) {
5
+ return Publishers[destination.type](destination, payload);
6
+ }
@@ -0,0 +1,75 @@
1
+ import { ZodSchema, z } from "zod";
2
+ export declare namespace event {
3
+ export type Definition = {
4
+ type: string;
5
+ $input: any;
6
+ $output: any;
7
+ $metadata: any;
8
+ $payload: any;
9
+ create: (...args: any[]) => Promise<any>;
10
+ };
11
+ export function builder<MetadataFunction extends (type: string, properties: any) => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
12
+ metadata?: MetadataSchema;
13
+ metadataFn?: MetadataFunction;
14
+ validator: Validator;
15
+ }): {
16
+ <Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
17
+ create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<{
18
+ type: Type;
19
+ properties: inferParser<Schema>["out"];
20
+ metadata: ReturnType<MetadataFunction>;
21
+ }> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
22
+ type: Type;
23
+ properties: inferParser<Schema>["out"];
24
+ metadata: ReturnType<MetadataFunction>;
25
+ }>;
26
+ type: Type;
27
+ $input: inferParser<Schema>["in"];
28
+ $output: inferParser<Schema>["out"];
29
+ $payload: {
30
+ type: Type;
31
+ properties: inferParser<Schema>["out"];
32
+ metadata: ReturnType<MetadataFunction>;
33
+ };
34
+ $metadata: ReturnType<MetadataFunction>;
35
+ };
36
+ coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
37
+ type: K;
38
+ }>["$payload"]; }[Events["type"]];
39
+ };
40
+ export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
41
+ type ParserZodEsque<TInput, TParsedInput> = {
42
+ _input: TInput;
43
+ _output: TParsedInput;
44
+ };
45
+ type ParserValibotEsque<TInput, TParsedInput> = {
46
+ _types?: {
47
+ input: TInput;
48
+ output: TParsedInput;
49
+ };
50
+ };
51
+ type ParserMyZodEsque<TInput> = {
52
+ parse: (input: any) => TInput;
53
+ };
54
+ type ParserSuperstructEsque<TInput> = {
55
+ create: (input: unknown) => TInput;
56
+ };
57
+ type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
58
+ type ParserYupEsque<TInput> = {
59
+ validateSync: (input: unknown) => TInput;
60
+ };
61
+ type ParserScaleEsque<TInput> = {
62
+ assert(value: unknown): asserts value is TInput;
63
+ };
64
+ export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
65
+ export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
66
+ export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
67
+ export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
68
+ in: $TIn;
69
+ out: $TOut;
70
+ } : TParser extends ParserWithoutInput<infer $InOut> ? {
71
+ in: $InOut;
72
+ out: $InOut;
73
+ } : never;
74
+ export {};
75
+ }
@@ -0,0 +1,43 @@
1
+ export var event;
2
+ (function (event) {
3
+ function builder(input) {
4
+ const validator = input.validator;
5
+ const metadataValidator = input.metadata ? validator(input.metadata) : null;
6
+ const fn = function event(type, schema) {
7
+ const validate = validator(schema);
8
+ async function create(properties, metadata) {
9
+ if (metadataValidator) {
10
+ metadata = metadataValidator(metadata);
11
+ }
12
+ if (input.metadataFn) {
13
+ metadata = input.metadataFn(type, properties);
14
+ }
15
+ properties = validate(properties);
16
+ return {
17
+ type,
18
+ properties,
19
+ metadata,
20
+ };
21
+ }
22
+ return {
23
+ create: create,
24
+ type,
25
+ $input: {},
26
+ $output: {},
27
+ $payload: {},
28
+ $metadata: {},
29
+ };
30
+ };
31
+ fn.coerce = (_events, raw) => {
32
+ return raw;
33
+ };
34
+ return fn;
35
+ }
36
+ event.builder = builder;
37
+ function ZodValidator(schema) {
38
+ return (input) => {
39
+ return schema.parse(input);
40
+ };
41
+ }
42
+ event.ZodValidator = ZodValidator;
43
+ })(event || (event = {}));
@@ -1,74 +1,75 @@
1
- import { ZodObject, ZodSchema, z } from "zod";
2
- type Event = {
3
- type: string;
4
- $output: any;
5
- $metadata: any;
6
- $payload: any;
7
- };
8
- export declare function EventClient<MetadataFunction extends () => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
9
- metadata?: MetadataSchema;
10
- metadataFn?: MetadataFunction;
11
- validator: Validator;
12
- }): {
13
- <Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
14
- create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => {
15
- type: Type;
16
- properties: inferParser<Schema>["out"];
17
- metadata: ReturnType<MetadataFunction>;
18
- } : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
19
- type: Type;
20
- properties: inferParser<Schema>["out"];
21
- metadata: ReturnType<MetadataFunction>;
22
- }>;
23
- type: Type;
24
- $input: inferParser<Schema>["in"];
25
- $output: inferParser<Schema>["out"];
26
- $payload: {
1
+ import { ZodSchema, z } from "zod";
2
+ export declare namespace event {
3
+ export type Definition = {
4
+ type: string;
5
+ $input: any;
6
+ $output: any;
7
+ $metadata: any;
8
+ $payload: any;
9
+ create: (...args: any[]) => Promise<any>;
10
+ };
11
+ export function builder<MetadataFunction extends (type: string, properties: any) => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
12
+ metadata?: MetadataSchema;
13
+ metadataFn?: MetadataFunction;
14
+ validator: Validator;
15
+ }): {
16
+ <Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
17
+ create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<{
18
+ type: Type;
19
+ properties: inferParser<Schema>["out"];
20
+ metadata: ReturnType<MetadataFunction>;
21
+ }> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
22
+ type: Type;
23
+ properties: inferParser<Schema>["out"];
24
+ metadata: ReturnType<MetadataFunction>;
25
+ }>;
27
26
  type: Type;
28
- properties: inferParser<Schema>["out"];
29
- metadata: ReturnType<MetadataFunction>;
27
+ $input: inferParser<Schema>["in"];
28
+ $output: inferParser<Schema>["out"];
29
+ $payload: {
30
+ type: Type;
31
+ properties: inferParser<Schema>["out"];
32
+ metadata: ReturnType<MetadataFunction>;
33
+ };
34
+ $metadata: ReturnType<MetadataFunction>;
30
35
  };
31
- $metadata: ReturnType<MetadataFunction>;
36
+ coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
37
+ type: K;
38
+ }>["$payload"]; }[Events["type"]];
39
+ };
40
+ export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
41
+ type ParserZodEsque<TInput, TParsedInput> = {
42
+ _input: TInput;
43
+ _output: TParsedInput;
44
+ };
45
+ type ParserValibotEsque<TInput, TParsedInput> = {
46
+ _types?: {
47
+ input: TInput;
48
+ output: TParsedInput;
49
+ };
50
+ };
51
+ type ParserMyZodEsque<TInput> = {
52
+ parse: (input: any) => TInput;
53
+ };
54
+ type ParserSuperstructEsque<TInput> = {
55
+ create: (input: unknown) => TInput;
56
+ };
57
+ type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
58
+ type ParserYupEsque<TInput> = {
59
+ validateSync: (input: unknown) => TInput;
32
60
  };
33
- coerce<Events extends Event>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
34
- type: K;
35
- }>["$payload"]; }[Events["type"]];
36
- };
37
- export declare function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
38
- export type ParserZodEsque<TInput, TParsedInput> = {
39
- _input: TInput;
40
- _output: TParsedInput;
41
- };
42
- export type ParserValibotEsque<TInput, TParsedInput> = {
43
- _types?: {
44
- input: TInput;
45
- output: TParsedInput;
61
+ type ParserScaleEsque<TInput> = {
62
+ assert(value: unknown): asserts value is TInput;
46
63
  };
47
- };
48
- export type ParserMyZodEsque<TInput> = {
49
- parse: (input: any) => TInput;
50
- };
51
- export type ParserSuperstructEsque<TInput> = {
52
- create: (input: unknown) => TInput;
53
- };
54
- export type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
55
- export type ParserYupEsque<TInput> = {
56
- validateSync: (input: unknown) => TInput;
57
- };
58
- export type ParserScaleEsque<TInput> = {
59
- assert(value: unknown): asserts value is TInput;
60
- };
61
- export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
62
- export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
63
- export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
64
- export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
65
- in: $TIn;
66
- out: $TOut;
67
- } : TParser extends ParserWithoutInput<infer $InOut> ? {
68
- in: $InOut;
69
- out: $InOut;
70
- } : never;
71
- export type inferEvent<T extends {
72
- shape: ZodObject<any>;
73
- }> = z.infer<T["shape"]>;
74
- export {};
64
+ export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
65
+ export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
66
+ export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
67
+ export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
68
+ in: $TIn;
69
+ out: $TOut;
70
+ } : TParser extends ParserWithoutInput<infer $InOut> ? {
71
+ in: $InOut;
72
+ out: $InOut;
73
+ } : never;
74
+ export {};
75
+ }
@@ -1,38 +1,43 @@
1
- export function EventClient(input) {
2
- const validator = input.validator;
3
- const metadataValidator = input.metadata ? validator(input.metadata) : null;
4
- const fn = function event(type, schema) {
5
- const validate = validator(schema);
6
- async function create(properties, metadata) {
7
- if (metadataValidator) {
8
- metadata = metadataValidator(metadata);
1
+ export var event;
2
+ (function (event) {
3
+ function builder(input) {
4
+ const validator = input.validator;
5
+ const metadataValidator = input.metadata ? validator(input.metadata) : null;
6
+ const fn = function event(type, schema) {
7
+ const validate = validator(schema);
8
+ async function create(properties, metadata) {
9
+ if (metadataValidator) {
10
+ metadata = metadataValidator(metadata);
11
+ }
12
+ if (input.metadataFn) {
13
+ metadata = input.metadataFn(type, properties);
14
+ }
15
+ properties = validate(properties);
16
+ return {
17
+ type,
18
+ properties,
19
+ metadata,
20
+ };
9
21
  }
10
- if (input.metadataFn) {
11
- metadata = input.metadataFn();
12
- }
13
- properties = validate(properties);
14
22
  return {
23
+ create: create,
15
24
  type,
16
- properties,
17
- metadata,
25
+ $input: {},
26
+ $output: {},
27
+ $payload: {},
28
+ $metadata: {},
18
29
  };
19
- }
20
- return {
21
- create: create,
22
- type,
23
- $input: {},
24
- $output: {},
25
- $payload: {},
26
- $metadata: {},
27
30
  };
28
- };
29
- fn.coerce = (_events, raw) => {
30
- return raw;
31
- };
32
- return fn;
33
- }
34
- export function ZodValidator(schema) {
35
- return (input) => {
36
- return schema.parse(input);
37
- };
38
- }
31
+ fn.coerce = (_events, raw) => {
32
+ return raw;
33
+ };
34
+ return fn;
35
+ }
36
+ event.builder = builder;
37
+ function ZodValidator(schema) {
38
+ return (input) => {
39
+ return schema.parse(input);
40
+ };
41
+ }
42
+ event.ZodValidator = ZodValidator;
43
+ })(event || (event = {}));
@@ -1,42 +1,8 @@
1
- import type { IoTCustomAuthorizerHandler } from "aws-lambda";
2
- export interface RealtimeAuthResult {
3
- /**
4
- * The topics the client can subscribe to.
5
- * @example
6
- * For example, this subscribes to specific topics.
7
- * ```js
8
- * {
9
- * subscribe: ["chat/room1", "chat/room2"]
10
- * }
11
- * ```
12
- *
13
- * And to subscribe to all topics under a specific prefix.
14
- * ```js
15
- * {
16
- * subscribe: ["chat/*"]
17
- * }
18
- * ```
19
- */
20
- subscribe?: string[];
21
- /**
22
- * The topics the client can publish to.
23
- * @example
24
- * For example, this publishes to specific topics.
25
- * ```js
26
- * {
27
- * publish: ["chat/room1", "chat/room2"]
28
- * }
29
- * ```
30
- * And to publish to all topics under a specific prefix.
31
- * ```js
32
- * {
33
- * publish: ["chat/*"]
34
- * }
35
- * ```
36
- */
37
- publish?: string[];
38
- }
1
+ import { realtime } from "../aws/realtime.js";
2
+ export type RealtimeAuthResult = realtime.AuthResult;
39
3
  /**
4
+ * @deprecated import from `sst/aws/realtime` instead.
5
+ *
40
6
  * Creates an authorization handler for the `Realtime` component, that validates
41
7
  * the token and grants permissions for the topics the client can subscribe and publish to.
42
8
  *
@@ -56,4 +22,4 @@ export interface RealtimeAuthResult {
56
22
  * });
57
23
  * ```
58
24
  */
59
- export declare function RealtimeAuthHandler(input: (token: string) => Promise<RealtimeAuthResult>): IoTCustomAuthorizerHandler;
25
+ export declare const RealtimeAuthHandler: typeof realtime.authorizer;
@@ -1,4 +1,7 @@
1
+ import { realtime } from "../aws/realtime.js";
1
2
  /**
3
+ * @deprecated import from `sst/aws/realtime` instead.
4
+ *
2
5
  * Creates an authorization handler for the `Realtime` component, that validates
3
6
  * the token and grants permissions for the topics the client can subscribe and publish to.
4
7
  *
@@ -18,55 +21,4 @@
18
21
  * });
19
22
  * ```
20
23
  */
21
- export function RealtimeAuthHandler(input) {
22
- return async (evt, context) => {
23
- const [, , , region, accountId] = context.invokedFunctionArn.split(":");
24
- const token = Buffer.from(evt.protocolData.mqtt?.password ?? "", "base64").toString();
25
- const ret = await input(token);
26
- return {
27
- isAuthenticated: true,
28
- principalId: Date.now().toString(),
29
- disconnectAfterInSeconds: 86400,
30
- refreshAfterInSeconds: 300,
31
- policyDocuments: [
32
- {
33
- Version: "2012-10-17",
34
- Statement: [
35
- {
36
- Action: "iot:Connect",
37
- Effect: "Allow",
38
- Resource: "*",
39
- },
40
- ...(ret.subscribe
41
- ? [
42
- {
43
- Action: "iot:Receive",
44
- Effect: "Allow",
45
- Resource: ret.subscribe.map((t) => `arn:aws:iot:${region}:${accountId}:topic/${t}`),
46
- },
47
- ]
48
- : []),
49
- ...(ret.subscribe
50
- ? [
51
- {
52
- Action: "iot:Subscribe",
53
- Effect: "Allow",
54
- Resource: ret.subscribe.map((t) => `arn:aws:iot:${region}:${accountId}:topicfilter/${t}`),
55
- },
56
- ]
57
- : []),
58
- ...(ret.publish
59
- ? [
60
- {
61
- Action: "iot:Publish",
62
- Effect: "Allow",
63
- Resource: ret.publish.map((t) => `arn:aws:iot:${region}:${accountId}:topic/${t}`),
64
- },
65
- ]
66
- : []),
67
- ],
68
- },
69
- ],
70
- };
71
- };
72
- }
24
+ export const RealtimeAuthHandler = realtime.authorizer;
package/package.json CHANGED
@@ -3,19 +3,20 @@
3
3
  "name": "sst",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "version": "3.0.18",
6
+ "version": "3.0.20",
7
7
  "main": "./dist/index.js",
8
8
  "exports": {
9
9
  ".": "./dist/index.js",
10
10
  "./auth": "./dist/auth/index.js",
11
- "./auth/adapter": "./dist/auth/index.js",
11
+ "./event": "./dist/event/index.js",
12
+ "./realtime": "./dist/realtime/index.js",
12
13
  "./*": "./dist/*.js"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@tsconfig/node18": "^18.2.2",
16
17
  "@types/node": "^20.11.0",
17
- "typescript": "^5.3.3",
18
- "hono": "4.3.9"
18
+ "hono": "4.3.9",
19
+ "typescript": "^5.3.3"
19
20
  },
20
21
  "files": [
21
22
  "dist"
@@ -25,12 +26,13 @@
25
26
  },
26
27
  "dependencies": {
27
28
  "@aws-sdk/client-lambda": "3.478.0",
29
+ "aws4fetch": "^1.0.18",
28
30
  "jose": "5.2.3",
29
31
  "openid-client": "5.6.4"
30
32
  },
31
33
  "scripts": {
32
34
  "build": "tsc",
33
35
  "dev": "tsc -w",
34
- "release": "pnpm build && pnpm version patch && pnpm publish --no-git-checks --tag=ion --access=public"
36
+ "release": "bun run build && pnpm version patch && pnpm publish --no-git-checks --tag=ion --access=public"
35
37
  }
36
38
  }