@authhero/aws-adapter 0.2.0
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/LICENSE +21 -0
- package/README.md +126 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 authhero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @authhero/aws-adapter
|
|
2
|
+
|
|
3
|
+
AWS DynamoDB adapter for AuthHero. This adapter implements the AuthHero data adapters using Amazon DynamoDB as the storage backend.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Single-table design for efficient DynamoDB usage
|
|
8
|
+
- Works with AWS Lambda and Cloudflare Workers
|
|
9
|
+
- Type-safe with full TypeScript support
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @authhero/aws-adapter
|
|
15
|
+
# or
|
|
16
|
+
pnpm add @authhero/aws-adapter
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### With AWS Lambda
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
25
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
26
|
+
import createAdapters from "@authhero/aws-adapter";
|
|
27
|
+
|
|
28
|
+
const client = new DynamoDBClient({});
|
|
29
|
+
const docClient = DynamoDBDocumentClient.from(client);
|
|
30
|
+
|
|
31
|
+
const adapters = createAdapters(docClient, {
|
|
32
|
+
tableName: "authhero",
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### With Cloudflare Workers
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
40
|
+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
41
|
+
import createAdapters from "@authhero/aws-adapter";
|
|
42
|
+
|
|
43
|
+
// In Cloudflare Workers, you need to provide credentials explicitly
|
|
44
|
+
const client = new DynamoDBClient({
|
|
45
|
+
region: env.AWS_REGION,
|
|
46
|
+
credentials: {
|
|
47
|
+
accessKeyId: env.AWS_ACCESS_KEY_ID,
|
|
48
|
+
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const docClient = DynamoDBDocumentClient.from(client);
|
|
52
|
+
|
|
53
|
+
const adapters = createAdapters(docClient, {
|
|
54
|
+
tableName: "authhero",
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Table Design
|
|
59
|
+
|
|
60
|
+
This adapter uses a single-table design with the following key structure:
|
|
61
|
+
|
|
62
|
+
| Entity | PK | SK |
|
|
63
|
+
| ---------- | ----------------------------------- | ---------------------------- |
|
|
64
|
+
| Tenant | `TENANT#{tenant_id}` | `TENANT` |
|
|
65
|
+
| User | `TENANT#{tenant_id}` | `USER#{user_id}` |
|
|
66
|
+
| Session | `TENANT#{tenant_id}` | `SESSION#{session_id}` |
|
|
67
|
+
| Client | `TENANT#{tenant_id}` | `CLIENT#{client_id}` |
|
|
68
|
+
| Connection | `TENANT#{tenant_id}` | `CONNECTION#{connection_id}` |
|
|
69
|
+
| Code | `TENANT#{tenant_id}` | `CODE#{code_id}` |
|
|
70
|
+
| Password | `TENANT#{tenant_id}#USER#{user_id}` | `PASSWORD#{password_id}` |
|
|
71
|
+
| ... | ... | ... |
|
|
72
|
+
|
|
73
|
+
### Global Secondary Indexes
|
|
74
|
+
|
|
75
|
+
- **GSI1**: For querying by email across users
|
|
76
|
+
- GSI1PK: `TENANT#{tenant_id}#EMAIL#{email}`
|
|
77
|
+
- GSI1SK: `USER`
|
|
78
|
+
|
|
79
|
+
- **GSI2**: For querying custom domains
|
|
80
|
+
- GSI2PK: `DOMAIN#{domain}`
|
|
81
|
+
- GSI2SK: `CUSTOM_DOMAIN`
|
|
82
|
+
|
|
83
|
+
## DynamoDB Table Setup
|
|
84
|
+
|
|
85
|
+
Create a DynamoDB table with the following configuration:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"TableName": "authhero",
|
|
90
|
+
"KeySchema": [
|
|
91
|
+
{ "AttributeName": "PK", "KeyType": "HASH" },
|
|
92
|
+
{ "AttributeName": "SK", "KeyType": "RANGE" }
|
|
93
|
+
],
|
|
94
|
+
"AttributeDefinitions": [
|
|
95
|
+
{ "AttributeName": "PK", "AttributeType": "S" },
|
|
96
|
+
{ "AttributeName": "SK", "AttributeType": "S" },
|
|
97
|
+
{ "AttributeName": "GSI1PK", "AttributeType": "S" },
|
|
98
|
+
{ "AttributeName": "GSI1SK", "AttributeType": "S" },
|
|
99
|
+
{ "AttributeName": "GSI2PK", "AttributeType": "S" },
|
|
100
|
+
{ "AttributeName": "GSI2SK", "AttributeType": "S" }
|
|
101
|
+
],
|
|
102
|
+
"GlobalSecondaryIndexes": [
|
|
103
|
+
{
|
|
104
|
+
"IndexName": "GSI1",
|
|
105
|
+
"KeySchema": [
|
|
106
|
+
{ "AttributeName": "GSI1PK", "KeyType": "HASH" },
|
|
107
|
+
{ "AttributeName": "GSI1SK", "KeyType": "RANGE" }
|
|
108
|
+
],
|
|
109
|
+
"Projection": { "ProjectionType": "ALL" }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"IndexName": "GSI2",
|
|
113
|
+
"KeySchema": [
|
|
114
|
+
{ "AttributeName": "GSI2PK", "KeyType": "HASH" },
|
|
115
|
+
{ "AttributeName": "GSI2SK", "KeyType": "RANGE" }
|
|
116
|
+
],
|
|
117
|
+
"Projection": { "ProjectionType": "ALL" }
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
"BillingMode": "PAY_PER_REQUEST"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@authhero/aws-adapter",
|
|
3
|
+
"private": false,
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org/",
|
|
7
|
+
"tag": "latest"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://authhero.net",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
|
+
},
|
|
14
|
+
"version": "0.2.0",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/aws-adapter.cjs",
|
|
19
|
+
"module": "dist/aws-adapter.mjs",
|
|
20
|
+
"types": "dist/aws-adapter.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/aws-adapter.d.ts",
|
|
24
|
+
"require": "./dist/aws-adapter.cjs",
|
|
25
|
+
"import": "./dist/aws-adapter.mjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@hono/zod-openapi": "^0.19.10",
|
|
30
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
31
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
32
|
+
"@types/node": "^24.10.0",
|
|
33
|
+
"dts-bundle-generator": "^9.5.1",
|
|
34
|
+
"dynalite": "^3.2.2",
|
|
35
|
+
"hono": "^4.10.4",
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vite": "^7.2.2",
|
|
38
|
+
"vitest": "^4.0.7"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@hono/zod-openapi": "^0.19.10",
|
|
42
|
+
"hono": "^4.6.8"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@aws-sdk/client-dynamodb": "^3.700.0",
|
|
46
|
+
"@aws-sdk/lib-dynamodb": "^3.700.0",
|
|
47
|
+
"nanoid": "^5.1.6",
|
|
48
|
+
"@authhero/adapter-interfaces": "^0.108.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest"
|
|
54
|
+
}
|
|
55
|
+
}
|