sst 3.0.20 → 3.0.22
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/index.d.ts +7 -1
- package/dist/auth/index.js +7 -1
- package/dist/src/auth/adapter/adapter.d.ts +24 -0
- package/dist/src/auth/adapter/adapter.js +4 -0
- package/dist/src/auth/adapter/apple.d.ts +5 -0
- package/dist/src/auth/adapter/apple.js +22 -0
- package/dist/src/auth/adapter/code.d.ts +8 -0
- package/dist/src/auth/adapter/code.js +47 -0
- package/dist/src/auth/adapter/facebook.d.ts +5 -0
- package/dist/src/auth/adapter/facebook.js +27 -0
- package/dist/src/auth/adapter/github.d.ts +12 -0
- package/dist/src/auth/adapter/github.js +23 -0
- package/dist/src/auth/adapter/google.d.ts +17 -0
- package/dist/src/auth/adapter/google.js +22 -0
- package/dist/src/auth/adapter/index.d.ts +11 -0
- package/dist/src/auth/adapter/index.js +10 -0
- package/dist/src/auth/adapter/link.d.ts +6 -0
- package/dist/src/auth/adapter/link.js +27 -0
- package/dist/src/auth/adapter/microsoft.d.ts +11 -0
- package/dist/src/auth/adapter/microsoft.js +16 -0
- package/dist/src/auth/adapter/oauth.d.ts +33 -0
- package/dist/src/auth/adapter/oauth.js +79 -0
- package/dist/src/auth/adapter/oidc.d.ts +19 -0
- package/dist/src/auth/adapter/oidc.js +45 -0
- package/dist/src/auth/adapter/spotify.d.ts +12 -0
- package/dist/src/auth/adapter/spotify.js +22 -0
- package/dist/src/auth/example/bun.d.ts +2 -0
- package/dist/src/auth/example/bun.js +46 -0
- package/dist/src/auth/handler.d.ts +58 -0
- package/dist/src/auth/handler.js +207 -0
- package/dist/src/auth/index.d.ts +10 -0
- package/dist/src/auth/index.js +10 -0
- package/dist/src/auth/session.d.ts +25 -0
- package/dist/src/auth/session.js +28 -0
- package/dist/src/aws/bus.d.ts +29 -0
- package/dist/src/aws/bus.js +67 -0
- package/dist/src/aws/client.d.ts +3 -0
- package/dist/src/aws/client.js +7 -0
- package/dist/src/aws/realtime.d.ts +61 -0
- package/dist/src/aws/realtime.js +76 -0
- package/dist/src/event/index.d.ts +74 -0
- package/dist/src/event/index.js +41 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/realtime/index.d.ts +25 -0
- package/dist/src/realtime/index.js +24 -0
- package/dist/src/resource.d.ts +9 -0
- package/dist/src/resource.js +50 -0
- package/dist/src/util/prettify.d.ts +3 -0
- package/dist/src/util/prettify.js +1 -0
- package/dist/src/vector/index.d.ts +193 -0
- package/dist/src/vector/index.js +62 -0
- package/dist/test/event.test.d.ts +1 -0
- package/dist/test/event.test.js +12 -0
- package/package.json +2 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export var event;
|
|
2
|
+
(function (event) {
|
|
3
|
+
function builder(input) {
|
|
4
|
+
const validator = input.validator || ZodValidator;
|
|
5
|
+
const fn = function event(type, schema) {
|
|
6
|
+
const validate = validator(schema);
|
|
7
|
+
async function create(properties, metadata) {
|
|
8
|
+
metadata = input.metadata
|
|
9
|
+
? typeof input.metadata === "function"
|
|
10
|
+
? input.metadata(type, properties)
|
|
11
|
+
: input.metadata(metadata)
|
|
12
|
+
: {};
|
|
13
|
+
properties = validate(properties);
|
|
14
|
+
return {
|
|
15
|
+
type,
|
|
16
|
+
properties,
|
|
17
|
+
metadata,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
create: create,
|
|
22
|
+
type,
|
|
23
|
+
$input: {},
|
|
24
|
+
$output: {},
|
|
25
|
+
$payload: {},
|
|
26
|
+
$metadata: {},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
fn.coerce = (_events, raw) => {
|
|
30
|
+
return raw;
|
|
31
|
+
};
|
|
32
|
+
return fn;
|
|
33
|
+
}
|
|
34
|
+
event.builder = builder;
|
|
35
|
+
function ZodValidator(schema) {
|
|
36
|
+
return (input) => {
|
|
37
|
+
return schema.parse(input);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
event.ZodValidator = ZodValidator;
|
|
41
|
+
})(event || (event = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { realtime } from "../aws/realtime.js";
|
|
2
|
+
export type RealtimeAuthResult = realtime.AuthResult;
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated import from `sst/aws/realtime` instead.
|
|
5
|
+
*
|
|
6
|
+
* Creates an authorization handler for the `Realtime` component, that validates
|
|
7
|
+
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* import { RealtimeAuthHandler, Resource } from "sst";
|
|
12
|
+
*
|
|
13
|
+
* export const handler = RealtimeAuthHandler(async (token) => {
|
|
14
|
+
* // Validate the token
|
|
15
|
+
* console.log(token);
|
|
16
|
+
*
|
|
17
|
+
* // Return the topics to subscribe and publish
|
|
18
|
+
* return {
|
|
19
|
+
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
20
|
+
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
21
|
+
* };
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const RealtimeAuthHandler: typeof realtime.authorizer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { realtime } from "../aws/realtime.js";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated import from `sst/aws/realtime` instead.
|
|
4
|
+
*
|
|
5
|
+
* Creates an authorization handler for the `Realtime` component, that validates
|
|
6
|
+
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* import { RealtimeAuthHandler, Resource } from "sst";
|
|
11
|
+
*
|
|
12
|
+
* export const handler = RealtimeAuthHandler(async (token) => {
|
|
13
|
+
* // Validate the token
|
|
14
|
+
* console.log(token);
|
|
15
|
+
*
|
|
16
|
+
* // Return the topics to subscribe and publish
|
|
17
|
+
* return {
|
|
18
|
+
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
19
|
+
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
20
|
+
* };
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const RealtimeAuthHandler = realtime.authorizer;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { env } from "node:process";
|
|
2
|
+
const raw = {
|
|
3
|
+
// @ts-expect-error,
|
|
4
|
+
...globalThis.$SST_LINKS,
|
|
5
|
+
};
|
|
6
|
+
for (const [key, value] of Object.entries(env)) {
|
|
7
|
+
if (key.startsWith("SST_RESOURCE_") && value) {
|
|
8
|
+
raw[key.slice("SST_RESOURCE_".length)] = JSON.parse(value);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export function fromCloudflareEnv(input) {
|
|
12
|
+
for (let [key, value] of Object.entries(input)) {
|
|
13
|
+
if (typeof value === "string") {
|
|
14
|
+
try {
|
|
15
|
+
value = JSON.parse(value);
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
}
|
|
19
|
+
raw[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function wrapCloudflareHandler(handler) {
|
|
23
|
+
if (typeof handler === "function" && handler.hasOwnProperty("prototype")) {
|
|
24
|
+
return class extends handler {
|
|
25
|
+
constructor(ctx, env) {
|
|
26
|
+
fromCloudflareEnv(env);
|
|
27
|
+
super(ctx, env);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function wrap(fn) {
|
|
32
|
+
return function (req, env, ...rest) {
|
|
33
|
+
fromCloudflareEnv(env);
|
|
34
|
+
return fn(req, env, ...rest);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const result = {};
|
|
38
|
+
for (const [key, value] of Object.entries(handler)) {
|
|
39
|
+
result[key] = wrap(value);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
export const Resource = new Proxy(raw, {
|
|
44
|
+
get(_target, prop) {
|
|
45
|
+
if (prop in raw) {
|
|
46
|
+
return raw[prop];
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`"${prop}" is not linked`);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Resource } from "../resource.js";
|
|
2
|
+
export interface PutEvent {
|
|
3
|
+
/**
|
|
4
|
+
* The vector to store in the database.
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* {
|
|
8
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
vector: number[];
|
|
13
|
+
/**
|
|
14
|
+
* Metadata for the event in JSON format.
|
|
15
|
+
* This metadata will be used to filter when quering and removing vectors.
|
|
16
|
+
* @example
|
|
17
|
+
* ```js
|
|
18
|
+
* {
|
|
19
|
+
* metadata: {
|
|
20
|
+
* type: "movie",
|
|
21
|
+
* id: "movie-123",
|
|
22
|
+
* name: "Spiderman",
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
metadata: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
export interface QueryEvent {
|
|
30
|
+
/**
|
|
31
|
+
* The vector used to query the database.
|
|
32
|
+
* @example
|
|
33
|
+
* ```js
|
|
34
|
+
* {
|
|
35
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
vector: number[];
|
|
40
|
+
/**
|
|
41
|
+
* The metadata used to filter the vectors.
|
|
42
|
+
* Only vectors that match the provided fields will be returned.
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* {
|
|
46
|
+
* include: {
|
|
47
|
+
* type: "movie",
|
|
48
|
+
* release: "2001",
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
* This will match the vector with metadata:
|
|
53
|
+
* ```js
|
|
54
|
+
* {
|
|
55
|
+
* type: "movie",
|
|
56
|
+
* name: "Spiderman",
|
|
57
|
+
* release: "2001",
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* But not the vector with metadata:
|
|
62
|
+
* ```js
|
|
63
|
+
* {
|
|
64
|
+
* type: "book",
|
|
65
|
+
* name: "Spiderman",
|
|
66
|
+
* release: "2001",
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
include: Record<string, any>;
|
|
71
|
+
/**
|
|
72
|
+
* Exclude vectors with metadata that match the provided fields.
|
|
73
|
+
* @example
|
|
74
|
+
* ```js
|
|
75
|
+
* {
|
|
76
|
+
* include: {
|
|
77
|
+
* type: "movie",
|
|
78
|
+
* release: "2001",
|
|
79
|
+
* },
|
|
80
|
+
* exclude: {
|
|
81
|
+
* name: "Spiderman",
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
* This will match the vector with metadata:
|
|
86
|
+
* ```js
|
|
87
|
+
* {
|
|
88
|
+
* type: "movie",
|
|
89
|
+
* name: "A Beautiful Mind",
|
|
90
|
+
* release: "2001",
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* But not the vector with metadata:
|
|
95
|
+
* ```js
|
|
96
|
+
* {
|
|
97
|
+
* type: "book",
|
|
98
|
+
* name: "Spiderman",
|
|
99
|
+
* release: "2001",
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
exclude?: Record<string, any>;
|
|
104
|
+
/**
|
|
105
|
+
* The threshold of similarity between the prompt and the queried vectors.
|
|
106
|
+
* Only vectors with a similarity score higher than the threshold will be returned.
|
|
107
|
+
* Expected value is between 0 and 1.
|
|
108
|
+
* - 0 means the prompt and the queried vectors are completely different.
|
|
109
|
+
* - 1 means the prompt and the queried vectors are identical.
|
|
110
|
+
* @default `0`
|
|
111
|
+
* @example
|
|
112
|
+
* ```js
|
|
113
|
+
* {
|
|
114
|
+
* threshold: 0.5,
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
threshold?: number;
|
|
119
|
+
/**
|
|
120
|
+
* The number of results to return.
|
|
121
|
+
* @default `10`
|
|
122
|
+
* @example
|
|
123
|
+
* ```js
|
|
124
|
+
* {
|
|
125
|
+
* count: 10,
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
count?: number;
|
|
130
|
+
}
|
|
131
|
+
export interface RemoveEvent {
|
|
132
|
+
/**
|
|
133
|
+
* The metadata used to filter the removal of vectors.
|
|
134
|
+
* Only vectors with metadata that match the provided fields will be removed.
|
|
135
|
+
* @example
|
|
136
|
+
* To remove vectors for movie with id "movie-123":
|
|
137
|
+
* ```js
|
|
138
|
+
* {
|
|
139
|
+
* include: {
|
|
140
|
+
* id: "movie-123",
|
|
141
|
+
* }
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
* To remove vectors for all movies:
|
|
145
|
+
* ```js
|
|
146
|
+
* {
|
|
147
|
+
* include: {
|
|
148
|
+
* type: "movie",
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
include: Record<string, any>;
|
|
154
|
+
}
|
|
155
|
+
export interface QueryResponse {
|
|
156
|
+
/**
|
|
157
|
+
* Metadata for the event in JSON format that was provided when storing the vector.
|
|
158
|
+
*/
|
|
159
|
+
metadata: Record<string, any>;
|
|
160
|
+
/**
|
|
161
|
+
* The similarity score between the prompt and the queried vector.
|
|
162
|
+
*/
|
|
163
|
+
score: number;
|
|
164
|
+
}
|
|
165
|
+
export interface VectorClientResponse {
|
|
166
|
+
put: (event: PutEvent) => Promise<void>;
|
|
167
|
+
query: (event: QueryEvent) => Promise<QueryResponse>;
|
|
168
|
+
remove: (event: RemoveEvent) => Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a client to interact with the Vector database.
|
|
172
|
+
* @example
|
|
173
|
+
* ```js
|
|
174
|
+
* import { VectorClient } from "sst";
|
|
175
|
+
* const client = VectorClient("MyVectorDB");
|
|
176
|
+
*
|
|
177
|
+
* // Store a vector into the db
|
|
178
|
+
* await client.put({
|
|
179
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
180
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* // Query vectors similar to the provided vector
|
|
184
|
+
* const result = await client.query({
|
|
185
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
186
|
+
* include: { type: "movie" },
|
|
187
|
+
* exclude: { genre: "thriller" },
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function VectorClient<T extends keyof {
|
|
192
|
+
[key in keyof Resource as "sst.aws.Vector" extends Resource[key]["type"] ? string extends key ? never : key : never]: Resource[key];
|
|
193
|
+
}>(name: T): VectorClientResponse;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LambdaClient, InvokeCommand, } from "@aws-sdk/client-lambda";
|
|
2
|
+
import { Resource } from "../resource.js";
|
|
3
|
+
const lambda = new LambdaClient();
|
|
4
|
+
/**
|
|
5
|
+
* Create a client to interact with the Vector database.
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* import { VectorClient } from "sst";
|
|
9
|
+
* const client = VectorClient("MyVectorDB");
|
|
10
|
+
*
|
|
11
|
+
* // Store a vector into the db
|
|
12
|
+
* await client.put({
|
|
13
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
14
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Query vectors similar to the provided vector
|
|
18
|
+
* const result = await client.query({
|
|
19
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
20
|
+
* include: { type: "movie" },
|
|
21
|
+
* exclude: { genre: "thriller" },
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function VectorClient(name) {
|
|
26
|
+
return {
|
|
27
|
+
put: async (event) => {
|
|
28
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
FunctionName: Resource[name].putFunction,
|
|
31
|
+
Payload: JSON.stringify(event),
|
|
32
|
+
}));
|
|
33
|
+
parsePayload(ret, "Failed to store into the vector db");
|
|
34
|
+
},
|
|
35
|
+
query: async (event) => {
|
|
36
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
FunctionName: Resource[name].queryFunction,
|
|
39
|
+
Payload: JSON.stringify(event),
|
|
40
|
+
}));
|
|
41
|
+
return parsePayload(ret, "Failed to query the vector db");
|
|
42
|
+
},
|
|
43
|
+
remove: async (event) => {
|
|
44
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
FunctionName: Resource[name].removeFunction,
|
|
47
|
+
Payload: JSON.stringify(event),
|
|
48
|
+
}));
|
|
49
|
+
parsePayload(ret, "Failed to remove from the vector db");
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function parsePayload(output, message) {
|
|
54
|
+
const payload = JSON.parse(Buffer.from(output.Payload).toString());
|
|
55
|
+
// Set cause to the payload so that it can be logged in CloudWatch
|
|
56
|
+
if (output.FunctionError) {
|
|
57
|
+
const e = new Error(message);
|
|
58
|
+
e.cause = payload;
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
return payload;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { event } from "../src/event/index.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const defineEvent = event.builder({
|
|
4
|
+
metadata(type, properties) {
|
|
5
|
+
return {
|
|
6
|
+
traceID: "123",
|
|
7
|
+
};
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
const MyEvent = defineEvent("MyEvent", z.object({
|
|
11
|
+
foo: z.string(),
|
|
12
|
+
}));
|
package/package.json
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"version": "3.0.
|
|
6
|
+
"version": "3.0.22",
|
|
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/adapter/index.js",
|
|
11
12
|
"./event": "./dist/event/index.js",
|
|
12
13
|
"./realtime": "./dist/realtime/index.js",
|
|
13
14
|
"./*": "./dist/*.js"
|