sst 3.0.37 → 3.0.38
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/bin/sst.mjs +28 -0
- package/dist/aws/realtime.d.ts +16 -10
- package/dist/aws/realtime.js +12 -6
- package/dist/resource.js +8 -1
- package/dist/vector/index.d.ts +81 -36
- package/dist/vector/index.js +9 -3
- package/package.json +23 -12
- package/dist/src/auth/adapter/adapter.d.ts +0 -24
- package/dist/src/auth/adapter/adapter.js +0 -4
- package/dist/src/auth/adapter/apple.d.ts +0 -5
- package/dist/src/auth/adapter/apple.js +0 -22
- package/dist/src/auth/adapter/code.d.ts +0 -8
- package/dist/src/auth/adapter/code.js +0 -47
- package/dist/src/auth/adapter/facebook.d.ts +0 -5
- package/dist/src/auth/adapter/facebook.js +0 -27
- package/dist/src/auth/adapter/github.d.ts +0 -12
- package/dist/src/auth/adapter/github.js +0 -23
- package/dist/src/auth/adapter/google.d.ts +0 -17
- package/dist/src/auth/adapter/google.js +0 -22
- package/dist/src/auth/adapter/index.d.ts +0 -11
- package/dist/src/auth/adapter/index.js +0 -10
- package/dist/src/auth/adapter/link.d.ts +0 -6
- package/dist/src/auth/adapter/link.js +0 -27
- package/dist/src/auth/adapter/microsoft.d.ts +0 -11
- package/dist/src/auth/adapter/microsoft.js +0 -16
- package/dist/src/auth/adapter/oauth.d.ts +0 -33
- package/dist/src/auth/adapter/oauth.js +0 -79
- package/dist/src/auth/adapter/oidc.d.ts +0 -19
- package/dist/src/auth/adapter/oidc.js +0 -45
- package/dist/src/auth/adapter/spotify.d.ts +0 -12
- package/dist/src/auth/adapter/spotify.js +0 -22
- package/dist/src/auth/example/bun.d.ts +0 -2
- package/dist/src/auth/example/bun.js +0 -46
- package/dist/src/auth/handler.d.ts +0 -58
- package/dist/src/auth/handler.js +0 -207
- package/dist/src/auth/index.d.ts +0 -10
- package/dist/src/auth/index.js +0 -10
- package/dist/src/auth/session.d.ts +0 -25
- package/dist/src/auth/session.js +0 -28
- package/dist/src/aws/bus.d.ts +0 -29
- package/dist/src/aws/bus.js +0 -67
- package/dist/src/aws/client.d.ts +0 -3
- package/dist/src/aws/client.js +0 -7
- package/dist/src/aws/realtime.d.ts +0 -61
- package/dist/src/aws/realtime.js +0 -76
- package/dist/src/event/index.d.ts +0 -74
- package/dist/src/event/index.js +0 -41
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.js +0 -3
- package/dist/src/realtime/index.d.ts +0 -25
- package/dist/src/realtime/index.js +0 -24
- package/dist/src/resource.d.ts +0 -9
- package/dist/src/resource.js +0 -50
- package/dist/src/util/prettify.d.ts +0 -3
- package/dist/src/util/prettify.js +0 -1
- package/dist/src/vector/index.d.ts +0 -193
- package/dist/src/vector/index.js +0 -62
- package/dist/test/event.test.d.ts +0 -1
- package/dist/test/event.test.js +0 -6
package/bin/sst.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { execFileSync } from "child_process"
|
|
7
|
+
const name = `sst-${process.platform}-${process.arch}`;
|
|
8
|
+
const binary = process.platform === "win32" ? "sst.exe" : "sst";
|
|
9
|
+
|
|
10
|
+
let resolved;
|
|
11
|
+
try {
|
|
12
|
+
resolved = require.resolve(path.join(name, "bin", binary));
|
|
13
|
+
} catch (ex) {
|
|
14
|
+
console.error(
|
|
15
|
+
`It seems that your package manager failed to install the right version of the SST CLI for your platform. You can try manually installing the "${name}" package.`,
|
|
16
|
+
);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
execFileSync(resolved, process.argv.slice(2),
|
|
22
|
+
{
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
})
|
|
25
|
+
} catch (ex) {
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
package/dist/aws/realtime.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import { Context, IoTCustomAuthorizerEvent } from "aws-lambda";
|
|
2
|
+
/**
|
|
3
|
+
* The `realtime` client SDK is available through the following.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```js title="src/authorizer.ts"
|
|
7
|
+
* import { realtime } from "sst/aws/realtime";
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
2
10
|
export declare namespace realtime {
|
|
3
11
|
interface AuthResult {
|
|
4
12
|
/**
|
|
5
13
|
* The topics the client can subscribe to.
|
|
6
14
|
* @example
|
|
7
|
-
* For example, this subscribes to specific topics.
|
|
15
|
+
* For example, this subscribes to two specific topics.
|
|
8
16
|
* ```js
|
|
9
17
|
* {
|
|
10
18
|
* subscribe: ["chat/room1", "chat/room2"]
|
|
11
19
|
* }
|
|
12
20
|
* ```
|
|
13
21
|
*
|
|
14
|
-
* And to subscribe to all topics under a
|
|
22
|
+
* And to subscribe to all topics under a given prefix.
|
|
15
23
|
* ```js
|
|
16
24
|
* {
|
|
17
25
|
* subscribe: ["chat/*"]
|
|
@@ -22,13 +30,13 @@ export declare namespace realtime {
|
|
|
22
30
|
/**
|
|
23
31
|
* The topics the client can publish to.
|
|
24
32
|
* @example
|
|
25
|
-
* For example, this publishes to specific topics.
|
|
33
|
+
* For example, this publishes to two specific topics.
|
|
26
34
|
* ```js
|
|
27
35
|
* {
|
|
28
36
|
* publish: ["chat/room1", "chat/room2"]
|
|
29
37
|
* }
|
|
30
38
|
* ```
|
|
31
|
-
* And to publish to all topics under a
|
|
39
|
+
* And to publish to all topics under a given prefix.
|
|
32
40
|
* ```js
|
|
33
41
|
* {
|
|
34
42
|
* publish: ["chat/*"]
|
|
@@ -38,21 +46,19 @@ export declare namespace realtime {
|
|
|
38
46
|
publish?: string[];
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
|
-
* Creates an authorization handler for the `Realtime` component
|
|
49
|
+
* Creates an authorization handler for the `Realtime` component. It validates
|
|
42
50
|
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
43
51
|
*
|
|
44
52
|
* @example
|
|
45
|
-
* ```js
|
|
46
|
-
* import { realtime } from "sst/aws/realtime";
|
|
47
|
-
*
|
|
53
|
+
* ```js title="src/authorizer.ts" "realtime.authorizer"
|
|
48
54
|
* export const handler = realtime.authorizer(async (token) => {
|
|
49
55
|
* // Validate the token
|
|
50
56
|
* console.log(token);
|
|
51
57
|
*
|
|
52
58
|
* // Return the topics to subscribe and publish
|
|
53
59
|
* return {
|
|
54
|
-
* subscribe: [
|
|
55
|
-
* publish: [
|
|
60
|
+
* subscribe: ["*"],
|
|
61
|
+
* publish: ["*"],
|
|
56
62
|
* };
|
|
57
63
|
* });
|
|
58
64
|
* ```
|
package/dist/aws/realtime.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `realtime` client SDK is available through the following.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```js title="src/authorizer.ts"
|
|
6
|
+
* import { realtime } from "sst/aws/realtime";
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
1
9
|
export var realtime;
|
|
2
10
|
(function (realtime) {
|
|
3
11
|
/**
|
|
4
|
-
* Creates an authorization handler for the `Realtime` component
|
|
12
|
+
* Creates an authorization handler for the `Realtime` component. It validates
|
|
5
13
|
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
6
14
|
*
|
|
7
15
|
* @example
|
|
8
|
-
* ```js
|
|
9
|
-
* import { realtime } from "sst/aws/realtime";
|
|
10
|
-
*
|
|
16
|
+
* ```js title="src/authorizer.ts" "realtime.authorizer"
|
|
11
17
|
* export const handler = realtime.authorizer(async (token) => {
|
|
12
18
|
* // Validate the token
|
|
13
19
|
* console.log(token);
|
|
14
20
|
*
|
|
15
21
|
* // Return the topics to subscribe and publish
|
|
16
22
|
* return {
|
|
17
|
-
* subscribe: [
|
|
18
|
-
* publish: [
|
|
23
|
+
* subscribe: ["*"],
|
|
24
|
+
* publish: ["*"],
|
|
19
25
|
* };
|
|
20
26
|
* });
|
|
21
27
|
* ```
|
package/dist/resource.js
CHANGED
|
@@ -45,6 +45,13 @@ export const Resource = new Proxy(raw, {
|
|
|
45
45
|
if (prop in raw) {
|
|
46
46
|
return raw[prop];
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
if (!env.SST_RESOURCE_App) {
|
|
49
|
+
throw new Error("It does not look like SST links are active. If this is in local development and you are not starting this process through the multiplexer, wrap your command with `sst dev -- <command>`");
|
|
50
|
+
}
|
|
51
|
+
let msg = `"${prop}" is not linked in your sst.config.ts`;
|
|
52
|
+
if (env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
53
|
+
msg += ` to ${env.AWS_LAMBDA_FUNCTION_NAME}`;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(msg);
|
|
49
56
|
},
|
|
50
57
|
});
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -5,21 +5,21 @@ export interface PutEvent {
|
|
|
5
5
|
* @example
|
|
6
6
|
* ```js
|
|
7
7
|
* {
|
|
8
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9]
|
|
8
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9]
|
|
9
9
|
* }
|
|
10
10
|
* ```
|
|
11
11
|
*/
|
|
12
12
|
vector: number[];
|
|
13
13
|
/**
|
|
14
|
-
* Metadata for the event
|
|
15
|
-
* This
|
|
14
|
+
* Metadata for the event as JSON.
|
|
15
|
+
* This will be used to filter when querying and removing vectors.
|
|
16
16
|
* @example
|
|
17
17
|
* ```js
|
|
18
18
|
* {
|
|
19
19
|
* metadata: {
|
|
20
20
|
* type: "movie",
|
|
21
21
|
* id: "movie-123",
|
|
22
|
-
* name: "Spiderman"
|
|
22
|
+
* name: "Spiderman"
|
|
23
23
|
* }
|
|
24
24
|
* }
|
|
25
25
|
* ```
|
|
@@ -32,7 +32,7 @@ export interface QueryEvent {
|
|
|
32
32
|
* @example
|
|
33
33
|
* ```js
|
|
34
34
|
* {
|
|
35
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9]
|
|
35
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9]
|
|
36
36
|
* }
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
@@ -41,29 +41,30 @@ export interface QueryEvent {
|
|
|
41
41
|
* The metadata used to filter the vectors.
|
|
42
42
|
* Only vectors that match the provided fields will be returned.
|
|
43
43
|
* @example
|
|
44
|
+
* Given this filter.
|
|
44
45
|
* ```js
|
|
45
46
|
* {
|
|
46
47
|
* include: {
|
|
47
48
|
* type: "movie",
|
|
48
|
-
* release: "2001"
|
|
49
|
+
* release: "2001"
|
|
49
50
|
* }
|
|
50
51
|
* }
|
|
51
52
|
* ```
|
|
52
|
-
*
|
|
53
|
+
* It will match a vector with the metadata:
|
|
53
54
|
* ```js
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
55
|
+
* {
|
|
56
|
+
* type: "movie",
|
|
57
|
+
* name: "Spiderman",
|
|
58
|
+
* release: "2001"
|
|
59
|
+
* }
|
|
59
60
|
* ```
|
|
60
61
|
*
|
|
61
|
-
* But not
|
|
62
|
+
* But not a vector with this metadata:
|
|
62
63
|
* ```js
|
|
63
64
|
* {
|
|
64
65
|
* type: "book",
|
|
65
66
|
* name: "Spiderman",
|
|
66
|
-
* release: "2001"
|
|
67
|
+
* release: "2001"
|
|
67
68
|
* }
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
@@ -71,32 +72,33 @@ export interface QueryEvent {
|
|
|
71
72
|
/**
|
|
72
73
|
* Exclude vectors with metadata that match the provided fields.
|
|
73
74
|
* @example
|
|
75
|
+
* Given this filter.
|
|
74
76
|
* ```js
|
|
75
77
|
* {
|
|
76
78
|
* include: {
|
|
77
79
|
* type: "movie",
|
|
78
|
-
* release: "2001"
|
|
80
|
+
* release: "2001"
|
|
79
81
|
* },
|
|
80
82
|
* exclude: {
|
|
81
|
-
* name: "Spiderman"
|
|
83
|
+
* name: "Spiderman"
|
|
82
84
|
* }
|
|
83
85
|
* }
|
|
84
86
|
* ```
|
|
85
|
-
* This will match
|
|
87
|
+
* This will match a vector with metadata:
|
|
86
88
|
* ```js
|
|
87
89
|
* {
|
|
88
90
|
* type: "movie",
|
|
89
91
|
* name: "A Beautiful Mind",
|
|
90
|
-
* release: "2001"
|
|
92
|
+
* release: "2001"
|
|
91
93
|
* }
|
|
92
94
|
* ```
|
|
93
95
|
*
|
|
94
|
-
* But not
|
|
96
|
+
* But not a vector with the metadata:
|
|
95
97
|
* ```js
|
|
96
98
|
* {
|
|
97
99
|
* type: "book",
|
|
98
100
|
* name: "Spiderman",
|
|
99
|
-
* release: "2001"
|
|
101
|
+
* release: "2001"
|
|
100
102
|
* }
|
|
101
103
|
* ```
|
|
102
104
|
*/
|
|
@@ -104,14 +106,16 @@ export interface QueryEvent {
|
|
|
104
106
|
/**
|
|
105
107
|
* The threshold of similarity between the prompt and the queried vectors.
|
|
106
108
|
* Only vectors with a similarity score higher than the threshold will be returned.
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* -
|
|
109
|
+
*
|
|
110
|
+
* This will return values is between 0 and 1.
|
|
111
|
+
* - `0` means the prompt and the queried vectors are completely different.
|
|
112
|
+
* - `1` means the prompt and the queried vectors are identical.
|
|
113
|
+
*
|
|
110
114
|
* @default `0`
|
|
111
115
|
* @example
|
|
112
116
|
* ```js
|
|
113
117
|
* {
|
|
114
|
-
* threshold: 0.5
|
|
118
|
+
* threshold: 0.5
|
|
115
119
|
* }
|
|
116
120
|
* ```
|
|
117
121
|
*/
|
|
@@ -122,7 +126,7 @@ export interface QueryEvent {
|
|
|
122
126
|
* @example
|
|
123
127
|
* ```js
|
|
124
128
|
* {
|
|
125
|
-
* count: 10
|
|
129
|
+
* count: 10
|
|
126
130
|
* }
|
|
127
131
|
* ```
|
|
128
132
|
*/
|
|
@@ -133,7 +137,7 @@ export interface RemoveEvent {
|
|
|
133
137
|
* The metadata used to filter the removal of vectors.
|
|
134
138
|
* Only vectors with metadata that match the provided fields will be removed.
|
|
135
139
|
* @example
|
|
136
|
-
* To remove vectors for movie with id
|
|
140
|
+
* To remove vectors for movie with id `movie-123`:
|
|
137
141
|
* ```js
|
|
138
142
|
* {
|
|
139
143
|
* include: {
|
|
@@ -141,7 +145,7 @@ export interface RemoveEvent {
|
|
|
141
145
|
* }
|
|
142
146
|
* }
|
|
143
147
|
* ```
|
|
144
|
-
* To remove vectors for all
|
|
148
|
+
* To remove vectors for all _movies_:
|
|
145
149
|
* ```js
|
|
146
150
|
* {
|
|
147
151
|
* include: {
|
|
@@ -154,33 +158,74 @@ export interface RemoveEvent {
|
|
|
154
158
|
}
|
|
155
159
|
export interface QueryResponse {
|
|
156
160
|
/**
|
|
157
|
-
*
|
|
158
|
-
*/
|
|
159
|
-
metadata: Record<string, any>;
|
|
160
|
-
/**
|
|
161
|
-
* The similarity score between the prompt and the queried vector.
|
|
161
|
+
* List of results matching the query.
|
|
162
162
|
*/
|
|
163
|
-
|
|
163
|
+
results: {
|
|
164
|
+
/**
|
|
165
|
+
* Metadata for the event that was provided when storing the vector.
|
|
166
|
+
*/
|
|
167
|
+
metadata: Record<string, any>;
|
|
168
|
+
/**
|
|
169
|
+
* The similarity score between the prompt and the queried vector.
|
|
170
|
+
*/
|
|
171
|
+
score: number;
|
|
172
|
+
}[];
|
|
164
173
|
}
|
|
165
174
|
export interface VectorClientResponse {
|
|
175
|
+
/**
|
|
176
|
+
* Store a vector into the database.
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts title="src/lambda.ts"
|
|
179
|
+
* await client.put({
|
|
180
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
181
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
166
185
|
put: (event: PutEvent) => Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Query vectors that are similar to the given vector
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts title="src/lambda.ts"
|
|
190
|
+
* const result = await client.query({
|
|
191
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
192
|
+
* include: { type: "movie" },
|
|
193
|
+
* exclude: { genre: "thriller" },
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
167
197
|
query: (event: QueryEvent) => Promise<QueryResponse>;
|
|
198
|
+
/**
|
|
199
|
+
* Remove vectors from the database.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts title="src/lambda.ts"
|
|
202
|
+
* await client.remove({
|
|
203
|
+
* include: { type: "movie" },
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
168
207
|
remove: (event: RemoveEvent) => Promise<void>;
|
|
169
208
|
}
|
|
170
209
|
/**
|
|
171
210
|
* Create a client to interact with the Vector database.
|
|
172
211
|
* @example
|
|
173
|
-
* ```
|
|
212
|
+
* ```ts title="src/lambda.ts"
|
|
174
213
|
* import { VectorClient } from "sst";
|
|
175
214
|
* const client = VectorClient("MyVectorDB");
|
|
215
|
+
* ```
|
|
176
216
|
*
|
|
177
|
-
*
|
|
217
|
+
* Store a vector into the db
|
|
218
|
+
*
|
|
219
|
+
* ```ts title="src/lambda.ts"
|
|
178
220
|
* await client.put({
|
|
179
221
|
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
180
222
|
* metadata: { type: "movie", genre: "comedy" },
|
|
181
223
|
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* Query vectors that are similar to the given vector
|
|
182
227
|
*
|
|
183
|
-
*
|
|
228
|
+
* ```ts title="src/lambda.ts"
|
|
184
229
|
* const result = await client.query({
|
|
185
230
|
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
186
231
|
* include: { type: "movie" },
|
package/dist/vector/index.js
CHANGED
|
@@ -4,17 +4,23 @@ const lambda = new LambdaClient();
|
|
|
4
4
|
/**
|
|
5
5
|
* Create a client to interact with the Vector database.
|
|
6
6
|
* @example
|
|
7
|
-
* ```
|
|
7
|
+
* ```ts title="src/lambda.ts"
|
|
8
8
|
* import { VectorClient } from "sst";
|
|
9
9
|
* const client = VectorClient("MyVectorDB");
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Store a vector into the db
|
|
10
13
|
*
|
|
11
|
-
*
|
|
14
|
+
* ```ts title="src/lambda.ts"
|
|
12
15
|
* await client.put({
|
|
13
16
|
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
14
17
|
* metadata: { type: "movie", genre: "comedy" },
|
|
15
18
|
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Query vectors that are similar to the given vector
|
|
16
22
|
*
|
|
17
|
-
*
|
|
23
|
+
* ```ts title="src/lambda.ts"
|
|
18
24
|
* const result = await client.query({
|
|
19
25
|
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
20
26
|
* include: { type: "movie" },
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
-
"version": "3.0.
|
|
6
|
+
"version": "3.0.38",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": "./dist/index.js",
|
|
@@ -13,17 +13,27 @@
|
|
|
13
13
|
"./realtime": "./dist/realtime/index.js",
|
|
14
14
|
"./*": "./dist/*.js"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc -w",
|
|
19
|
+
"release": "./scripts/release.ts"
|
|
20
|
+
},
|
|
16
21
|
"devDependencies": {
|
|
17
|
-
"@tsconfig/
|
|
18
|
-
"@types/
|
|
22
|
+
"@tsconfig/node20": "20.1.4",
|
|
23
|
+
"@types/bun": "^1.1.6",
|
|
24
|
+
"@types/node": "20.11.0",
|
|
19
25
|
"hono": "4.3.9",
|
|
20
|
-
"typescript": "
|
|
26
|
+
"typescript": "5.3.3",
|
|
21
27
|
"valibot": "0.30.0",
|
|
22
|
-
"zod": "
|
|
28
|
+
"zod": "3.23.8"
|
|
23
29
|
},
|
|
24
30
|
"files": [
|
|
25
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"bin"
|
|
26
33
|
],
|
|
34
|
+
"bin": {
|
|
35
|
+
"sst": "./bin/sst.mjs"
|
|
36
|
+
},
|
|
27
37
|
"peerDependencies": {
|
|
28
38
|
"hono": "4.x",
|
|
29
39
|
"valibot": "0.30.x"
|
|
@@ -36,16 +46,17 @@
|
|
|
36
46
|
"optional": true
|
|
37
47
|
}
|
|
38
48
|
},
|
|
49
|
+
"optionalDependencies": {
|
|
50
|
+
"sst-linux-x64": "3.0.38",
|
|
51
|
+
"sst-linux-x86": "3.0.38",
|
|
52
|
+
"sst-linux-arm64": "3.0.38",
|
|
53
|
+
"sst-darwin-x64": "3.0.38",
|
|
54
|
+
"sst-darwin-arm64": "3.0.38"
|
|
55
|
+
},
|
|
39
56
|
"dependencies": {
|
|
40
57
|
"@aws-sdk/client-lambda": "3.478.0",
|
|
41
|
-
"@tsconfig/node20": "^20.1.4",
|
|
42
58
|
"aws4fetch": "^1.0.18",
|
|
43
59
|
"jose": "5.2.3",
|
|
44
60
|
"openid-client": "5.6.4"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "tsc",
|
|
48
|
-
"dev": "tsc -w",
|
|
49
|
-
"release": "bun run build && pnpm version patch && pnpm publish --no-git-checks --tag=ion --access=public"
|
|
50
61
|
}
|
|
51
62
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type { Context, Hono } from "hono";
|
|
3
|
-
import { KeyLike } from "jose";
|
|
4
|
-
export type Adapter<Properties = any> = (route: AdapterRoute, options: AdapterOptions<Properties>) => void;
|
|
5
|
-
export type AdapterRoute = Hono;
|
|
6
|
-
export interface AdapterOptions<Properties> {
|
|
7
|
-
name: string;
|
|
8
|
-
algorithm: string;
|
|
9
|
-
encryption: {
|
|
10
|
-
publicKey: () => Promise<KeyLike>;
|
|
11
|
-
privateKey: () => Promise<KeyLike>;
|
|
12
|
-
};
|
|
13
|
-
signing: {
|
|
14
|
-
publicKey: () => Promise<KeyLike>;
|
|
15
|
-
privateKey: () => Promise<KeyLike>;
|
|
16
|
-
};
|
|
17
|
-
success: (ctx: Context, properties: Properties) => Promise<Response>;
|
|
18
|
-
forward: (ctx: Context, response: Response) => Response;
|
|
19
|
-
cookie: (ctx: Context, key: string, value: string, maxAge: number) => void;
|
|
20
|
-
}
|
|
21
|
-
export declare class AdapterError extends Error {
|
|
22
|
-
}
|
|
23
|
-
export declare class AdapterUnknownError extends AdapterError {
|
|
24
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
export declare const AppleAdapter: (config: OauthBasicConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
3
|
-
tokenset: import("openid-client").TokenSet;
|
|
4
|
-
client: import("openid-client").BaseClient;
|
|
5
|
-
}>) => Promise<void>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
// This adapter support the OAuth flow with the response_mode "form_post" for now.
|
|
4
|
-
// More details about the flow:
|
|
5
|
-
// https://developer.apple.com/documentation/devicemanagement/user_enrollment/onboarding_users_with_account_sign-in/implementing_the_oauth2_authentication_user-enrollment_flow
|
|
6
|
-
//
|
|
7
|
-
// Also note that Apple's discover uri does not work for the OAuth flow, as the
|
|
8
|
-
// userinfo_endpoint are not included in the response.
|
|
9
|
-
// await Issuer.discover("https://appleid.apple.com/.well-known/openid-configuration/");
|
|
10
|
-
const issuer = await Issuer.discover("https://appleid.apple.com/.well-known/openid-configuration");
|
|
11
|
-
export const AppleAdapter =
|
|
12
|
-
/* @__PURE__ */
|
|
13
|
-
(config) => {
|
|
14
|
-
return OauthAdapter({
|
|
15
|
-
issuer,
|
|
16
|
-
...config,
|
|
17
|
-
params: {
|
|
18
|
-
...config.params,
|
|
19
|
-
response_mode: "form_post",
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
export declare function CodeAdapter(config: {
|
|
3
|
-
length?: number;
|
|
4
|
-
onCodeRequest: (code: string, claims: Record<string, any>, req: Request) => Promise<Response>;
|
|
5
|
-
onCodeInvalid: (code: string, claims: Record<string, any>, req: Request) => Promise<Response>;
|
|
6
|
-
}): (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
7
|
-
claims: Record<string, string>;
|
|
8
|
-
}>) => void;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { deleteCookie, getCookie } from "hono/cookie";
|
|
2
|
-
import { UnknownStateError } from "../index.js";
|
|
3
|
-
import { CompactEncrypt, compactDecrypt } from "jose";
|
|
4
|
-
export function CodeAdapter(config) {
|
|
5
|
-
const length = config.length || 6;
|
|
6
|
-
function generate() {
|
|
7
|
-
const buffer = crypto.getRandomValues(new Uint8Array(length));
|
|
8
|
-
const otp = Array.from(buffer)
|
|
9
|
-
.map((byte) => byte % 10)
|
|
10
|
-
.join("");
|
|
11
|
-
return otp;
|
|
12
|
-
}
|
|
13
|
-
return function (routes, ctx) {
|
|
14
|
-
routes.get("/authorize", async (c) => {
|
|
15
|
-
const code = generate();
|
|
16
|
-
const claims = c.req.query();
|
|
17
|
-
delete claims["client_id"];
|
|
18
|
-
delete claims["redirect_uri"];
|
|
19
|
-
delete claims["response_type"];
|
|
20
|
-
delete claims["provider"];
|
|
21
|
-
const authorization = await new CompactEncrypt(new TextEncoder().encode(JSON.stringify({
|
|
22
|
-
claims,
|
|
23
|
-
code,
|
|
24
|
-
})))
|
|
25
|
-
.setProtectedHeader({ alg: "RSA-OAEP-512", enc: "A256GCM" })
|
|
26
|
-
.encrypt(await ctx.encryption.publicKey());
|
|
27
|
-
ctx.cookie(c, "authorization", authorization, 60 * 10);
|
|
28
|
-
return ctx.forward(c, await config.onCodeRequest(code, claims, c.req.raw));
|
|
29
|
-
});
|
|
30
|
-
routes.get("/callback", async (c) => {
|
|
31
|
-
const authorization = getCookie(c, "authorization");
|
|
32
|
-
if (!authorization)
|
|
33
|
-
throw new UnknownStateError();
|
|
34
|
-
const { code, claims } = JSON.parse(new TextDecoder().decode(await compactDecrypt(authorization, await ctx.encryption.privateKey()).then((value) => value.plaintext)));
|
|
35
|
-
if (!code || !claims) {
|
|
36
|
-
return ctx.forward(c, await config.onCodeInvalid(code, claims, c.req.raw));
|
|
37
|
-
}
|
|
38
|
-
const compare = c.req.query("code");
|
|
39
|
-
console.log("comparing", code, "to", compare);
|
|
40
|
-
if (code !== compare) {
|
|
41
|
-
return ctx.forward(c, await config.onCodeInvalid(code, claims, c.req.raw));
|
|
42
|
-
}
|
|
43
|
-
deleteCookie(c, "authorization");
|
|
44
|
-
return ctx.forward(c, await ctx.success(c, { claims }));
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
export declare const FacebookAdapter: (config: OauthBasicConfig) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
3
|
-
tokenset: import("openid-client").TokenSet;
|
|
4
|
-
client: import("openid-client").BaseClient;
|
|
5
|
-
}>) => Promise<void>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Issuer } from "openid-client";
|
|
2
|
-
import { OauthAdapter } from "./oauth.js";
|
|
3
|
-
// Facebook's OIDC flow returns "id_token" as uri hash in redirect uri. Hashes
|
|
4
|
-
// are not passed to Lambda event object. It is likely that Facebook only wants
|
|
5
|
-
// to support redirecting to a frontend uri.
|
|
6
|
-
//
|
|
7
|
-
// We are only going to support the OAuth flow for now. More details about the flow:
|
|
8
|
-
// https://developers.facebook.com/docs/facebook-login/guides/advanced/oidc-token
|
|
9
|
-
//
|
|
10
|
-
// Also note that Facebook's discover uri does not work for the OAuth flow, as the
|
|
11
|
-
// token_endpoint and userinfo_endpoint are not included in the response.
|
|
12
|
-
// await Issuer.discover("https://www.facebook.com/.well-known/openid-configuration/");
|
|
13
|
-
const issuer = new Issuer({
|
|
14
|
-
issuer: "https://www.facebook.com",
|
|
15
|
-
authorization_endpoint: "https://facebook.com/dialog/oauth/",
|
|
16
|
-
jwks_uri: "https://www.facebook.com/.well-known/oauth/openid/jwks/",
|
|
17
|
-
token_endpoint: "https://graph.facebook.com/oauth/access_token",
|
|
18
|
-
userinfo_endpoint: "https://graph.facebook.com/oauth/access_token",
|
|
19
|
-
});
|
|
20
|
-
export const FacebookAdapter =
|
|
21
|
-
/* @__PURE__ */
|
|
22
|
-
(config) => {
|
|
23
|
-
return OauthAdapter({
|
|
24
|
-
issuer,
|
|
25
|
-
...config,
|
|
26
|
-
});
|
|
27
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OauthBasicConfig } from "./oauth.js";
|
|
2
|
-
import { OidcBasicConfig } from "./oidc.js";
|
|
3
|
-
type Config = ({
|
|
4
|
-
mode: "oauth";
|
|
5
|
-
} & OauthBasicConfig) | ({
|
|
6
|
-
mode: "oidc";
|
|
7
|
-
} & OidcBasicConfig);
|
|
8
|
-
export declare const GithubAdapter: (config: Config) => (routes: import("./adapter.js").AdapterRoute, ctx: import("./adapter.js").AdapterOptions<{
|
|
9
|
-
tokenset: import("openid-client").TokenSet;
|
|
10
|
-
client: import("openid-client").BaseClient;
|
|
11
|
-
}>) => Promise<void>;
|
|
12
|
-
export {};
|