sst 2.11.2 → 2.11.5

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,3 +1,28 @@
1
1
  export interface EventBusResources {
2
2
  }
3
3
  export declare const EventBus: EventBusResources;
4
+ import { EventBridgeEvent } from "aws-lambda";
5
+ import { ZodAny, ZodObject, ZodRawShape, z } from "zod";
6
+ export declare function createEventBuilder<Bus extends keyof typeof EventBus, MetadataShape extends ZodRawShape | undefined, MetadataFunction extends () => any>(props: {
7
+ bus: Bus;
8
+ metadata?: MetadataShape;
9
+ metadataFn?: MetadataFunction;
10
+ }): <Type extends string, Shape extends ZodRawShape, Properties = z.objectOutputType<Shape, ZodAny, "strip">>(type: Type, properties: Shape) => {
11
+ publish: undefined extends MetadataShape ? (properties: Properties) => Promise<void> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>;
12
+ type: Type;
13
+ shape: {
14
+ metadata: Parameters<undefined extends MetadataShape ? (properties: Properties) => Promise<void> : (properties: Properties, metadata: z.infer<ZodObject<Exclude<MetadataShape, undefined>, "strip", ZodAny>>) => Promise<void>>[1];
15
+ properties: Properties;
16
+ metadataFn: ReturnType<MetadataFunction>;
17
+ };
18
+ };
19
+ export type inferEvent<T extends {
20
+ shape: ZodObject<any>;
21
+ }> = z.infer<T["shape"]>;
22
+ export declare function EventHandler<Event extends {
23
+ shape: {
24
+ properties: any;
25
+ metadata: any;
26
+ metadataFn: any;
27
+ };
28
+ }>(_events: Event, cb: (properties: Event["shape"]["properties"], metadata: undefined extends Event["shape"]["metadata"] ? Event["shape"]["metadataFn"] : Event["shape"]["metadata"]) => Promise<void>): (event: EventBridgeEvent<string, any>) => Promise<void>;
@@ -1,3 +1,53 @@
1
1
  import { createProxy } from "../util/index.js";
2
2
  export const EventBus =
3
3
  /* @__PURE__ */ createProxy("EventBus");
4
+ import { EventBridgeClient, PutEventsCommand, } from "@aws-sdk/client-eventbridge";
5
+ import { z } from "zod";
6
+ const client = new EventBridgeClient({});
7
+ export function createEventBuilder(props) {
8
+ return function createEvent(type, properties) {
9
+ const propertiesSchema = z.object(properties);
10
+ const metadataSchema = props.metadata
11
+ ? z.object(props.metadata)
12
+ : undefined;
13
+ const publish = async (properties, metadata) => {
14
+ console.log("publishing", type, properties);
15
+ await client.send(new PutEventsCommand({
16
+ Entries: [
17
+ {
18
+ // @ts-expect-error
19
+ EventBusName: EventBus[props.bus].eventBusName,
20
+ Source: "console",
21
+ Detail: JSON.stringify({
22
+ properties: propertiesSchema.parse(properties),
23
+ metadata: (() => {
24
+ if (metadataSchema) {
25
+ return metadataSchema.parse(metadata);
26
+ }
27
+ if (props.metadataFn) {
28
+ return props.metadataFn();
29
+ }
30
+ })(),
31
+ }),
32
+ DetailType: type,
33
+ },
34
+ ],
35
+ }));
36
+ };
37
+ return {
38
+ publish: publish,
39
+ type,
40
+ shape: {
41
+ metadata: {},
42
+ properties: {},
43
+ metadataFn: {},
44
+ },
45
+ };
46
+ };
47
+ }
48
+ export function EventHandler(_events, cb) {
49
+ return async (event) => {
50
+ console.log("received", event);
51
+ await cb(event.detail.properties, event.detail.metadata);
52
+ };
53
+ }
@@ -0,0 +1,23 @@
1
+ import { OauthBasicConfig } from "./oauth.js";
2
+ /**
3
+ * The Spotify Adapter follows the PKCE flow outlined here:
4
+ * https://developer.spotify.com/documentation/web-api/tutorials/code-pkce-flow
5
+ *
6
+ * List of scopes available:
7
+ * https://developer.spotify.com/documentation/web-api/concepts/scopes
8
+ */
9
+ export declare const SpotifyAdapter: (config: OauthBasicConfig) => () => Promise<{
10
+ type: "success";
11
+ properties: {
12
+ tokenset: import("openid-client").TokenSet;
13
+ client: import("openid-client").BaseClient;
14
+ };
15
+ } | {
16
+ type: "step";
17
+ properties: {
18
+ statusCode: number;
19
+ headers: {
20
+ location: string;
21
+ };
22
+ };
23
+ }>;
@@ -0,0 +1,22 @@
1
+ import { Issuer } from "openid-client";
2
+ import { OauthAdapter } from "./oauth.js";
3
+ const issuer = new Issuer({
4
+ issuer: "https://accounts.spotify.com",
5
+ authorization_endpoint: "https://accounts.spotify.com/authorize",
6
+ token_endpoint: "https://accounts.spotify.com/api/token",
7
+ });
8
+ /**
9
+ * The Spotify Adapter follows the PKCE flow outlined here:
10
+ * https://developer.spotify.com/documentation/web-api/tutorials/code-pkce-flow
11
+ *
12
+ * List of scopes available:
13
+ * https://developer.spotify.com/documentation/web-api/concepts/scopes
14
+ */
15
+ export const SpotifyAdapter =
16
+ /* @__PURE__ */
17
+ (config) => {
18
+ return OauthAdapter({
19
+ issuer,
20
+ ...config,
21
+ });
22
+ };
@@ -8,6 +8,7 @@ export * from "./adapter/github.js";
8
8
  export * from "./adapter/facebook.js";
9
9
  export * from "./adapter/microsoft.js";
10
10
  export * from "./adapter/oauth.js";
11
+ export * from "./adapter/spotify.js";
11
12
  export type { Adapter } from "./adapter/adapter.js";
12
13
  export * from "./session.js";
13
14
  export * from "./handler.js";
@@ -7,6 +7,7 @@ export * from "./adapter/github.js";
7
7
  export * from "./adapter/facebook.js";
8
8
  export * from "./adapter/microsoft.js";
9
9
  export * from "./adapter/oauth.js";
10
+ export * from "./adapter/spotify.js";
10
11
  export * from "./session.js";
11
12
  export * from "./handler.js";
12
13
  export { Issuer } from "openid-client";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "sst",
4
- "version": "2.11.2",
4
+ "version": "2.11.5",
5
5
  "bin": {
6
6
  "sst": "cli/sst.js"
7
7
  },
@@ -32,6 +32,7 @@
32
32
  "@aws-cdk/cloudformation-diff": "2.79.1",
33
33
  "@aws-cdk/cx-api": "2.79.1",
34
34
  "@aws-sdk/client-cloudformation": "^3.279.0",
35
+ "@aws-sdk/client-eventbridge": "^3.342.0",
35
36
  "@aws-sdk/client-iam": "^3.279.0",
36
37
  "@aws-sdk/client-iot": "^3.279.0",
37
38
  "@aws-sdk/client-iot-data-plane": "^3.279.0",
@@ -87,7 +88,8 @@
87
88
  "undici": "^5.12.0",
88
89
  "uuid": "^9.0.0",
89
90
  "ws": "^8.11.0",
90
- "yargs": "^17.6.2"
91
+ "yargs": "^17.6.2",
92
+ "zod": "^3.21.4"
91
93
  },
92
94
  "devDependencies": {
93
95
  "@aws-sdk/client-api-gateway": "^3.208.0",