cdk-turso 0.2.0 → 0.3.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/.jsii +6202 -347
- package/API.md +320 -32
- package/lib/handler/index.d.ts +4 -21
- package/lib/handler/index.js +107 -20
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -2
- package/lib/turso-auth-token.d.ts +8 -3
- package/lib/turso-auth-token.js +7 -22
- package/lib/turso-database.d.ts +2 -4
- package/lib/turso-database.js +4 -21
- package/lib/turso-provider.d.ts +34 -0
- package/lib/turso-provider.js +40 -0
- package/package.json +7 -7
- package/lib/handler-auth-token/index.d.ts +0 -15
- package/lib/handler-auth-token/index.js +0 -708
package/API.md
CHANGED
|
@@ -43,6 +43,7 @@ new TursoAuthToken(scope: Construct, id: string, props: TursoAuthTokenProps)
|
|
|
43
43
|
| **Name** | **Description** |
|
|
44
44
|
| --- | --- |
|
|
45
45
|
| <code><a href="#cdk-turso.TursoAuthToken.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
46
|
+
| <code><a href="#cdk-turso.TursoAuthToken.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
46
47
|
|
|
47
48
|
---
|
|
48
49
|
|
|
@@ -54,6 +55,27 @@ public toString(): string
|
|
|
54
55
|
|
|
55
56
|
Returns a string representation of this construct.
|
|
56
57
|
|
|
58
|
+
##### `with` <a name="with" id="cdk-turso.TursoAuthToken.with"></a>
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Applies one or more mixins to this construct.
|
|
65
|
+
|
|
66
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
67
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
68
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
69
|
+
constructs.
|
|
70
|
+
|
|
71
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="cdk-turso.TursoAuthToken.with.parameter.mixins"></a>
|
|
72
|
+
|
|
73
|
+
- *Type:* ...constructs.IMixin[]
|
|
74
|
+
|
|
75
|
+
The mixins to apply.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
57
79
|
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
58
80
|
|
|
59
81
|
| **Name** | **Description** |
|
|
@@ -62,7 +84,7 @@ Returns a string representation of this construct.
|
|
|
62
84
|
|
|
63
85
|
---
|
|
64
86
|
|
|
65
|
-
#####
|
|
87
|
+
##### `isConstruct` <a name="isConstruct" id="cdk-turso.TursoAuthToken.isConstruct"></a>
|
|
66
88
|
|
|
67
89
|
```typescript
|
|
68
90
|
import { TursoAuthToken } from 'cdk-turso'
|
|
@@ -72,6 +94,20 @@ TursoAuthToken.isConstruct(x: any)
|
|
|
72
94
|
|
|
73
95
|
Checks if `x` is a construct.
|
|
74
96
|
|
|
97
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
98
|
+
instances, even when the construct library is symlinked.
|
|
99
|
+
|
|
100
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
101
|
+
disk are seen as independent, completely different libraries. As a
|
|
102
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
103
|
+
is seen as a different class, and an instance of one class will not test as
|
|
104
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
105
|
+
like this, but users may manually symlink construct libraries together or
|
|
106
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
107
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
108
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
109
|
+
this type-testing method instead.
|
|
110
|
+
|
|
75
111
|
###### `x`<sup>Required</sup> <a name="x" id="cdk-turso.TursoAuthToken.isConstruct.parameter.x"></a>
|
|
76
112
|
|
|
77
113
|
- *Type:* any
|
|
@@ -155,6 +191,7 @@ new TursoDatabase(scope: Construct, id: string, props: TursoDatabaseProps)
|
|
|
155
191
|
| **Name** | **Description** |
|
|
156
192
|
| --- | --- |
|
|
157
193
|
| <code><a href="#cdk-turso.TursoDatabase.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
194
|
+
| <code><a href="#cdk-turso.TursoDatabase.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
158
195
|
|
|
159
196
|
---
|
|
160
197
|
|
|
@@ -166,6 +203,27 @@ public toString(): string
|
|
|
166
203
|
|
|
167
204
|
Returns a string representation of this construct.
|
|
168
205
|
|
|
206
|
+
##### `with` <a name="with" id="cdk-turso.TursoDatabase.with"></a>
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Applies one or more mixins to this construct.
|
|
213
|
+
|
|
214
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
215
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
216
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
217
|
+
constructs.
|
|
218
|
+
|
|
219
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="cdk-turso.TursoDatabase.with.parameter.mixins"></a>
|
|
220
|
+
|
|
221
|
+
- *Type:* ...constructs.IMixin[]
|
|
222
|
+
|
|
223
|
+
The mixins to apply.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
169
227
|
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
170
228
|
|
|
171
229
|
| **Name** | **Description** |
|
|
@@ -174,7 +232,7 @@ Returns a string representation of this construct.
|
|
|
174
232
|
|
|
175
233
|
---
|
|
176
234
|
|
|
177
|
-
#####
|
|
235
|
+
##### `isConstruct` <a name="isConstruct" id="cdk-turso.TursoDatabase.isConstruct"></a>
|
|
178
236
|
|
|
179
237
|
```typescript
|
|
180
238
|
import { TursoDatabase } from 'cdk-turso'
|
|
@@ -184,6 +242,20 @@ TursoDatabase.isConstruct(x: any)
|
|
|
184
242
|
|
|
185
243
|
Checks if `x` is a construct.
|
|
186
244
|
|
|
245
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
246
|
+
instances, even when the construct library is symlinked.
|
|
247
|
+
|
|
248
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
249
|
+
disk are seen as independent, completely different libraries. As a
|
|
250
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
251
|
+
is seen as a different class, and an instance of one class will not test as
|
|
252
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
253
|
+
like this, but users may manually symlink construct libraries together or
|
|
254
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
255
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
256
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
257
|
+
this type-testing method instead.
|
|
258
|
+
|
|
187
259
|
###### `x`<sup>Required</sup> <a name="x" id="cdk-turso.TursoDatabase.isConstruct.parameter.x"></a>
|
|
188
260
|
|
|
189
261
|
- *Type:* any
|
|
@@ -197,11 +269,9 @@ Any object.
|
|
|
197
269
|
| **Name** | **Type** | **Description** |
|
|
198
270
|
| --- | --- | --- |
|
|
199
271
|
| <code><a href="#cdk-turso.TursoDatabase.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
200
|
-
| <code><a href="#cdk-turso.TursoDatabase.property.apiToken">apiToken</a></code> | <code>aws-cdk-lib.aws_ssm.IParameter</code> | *No description.* |
|
|
201
272
|
| <code><a href="#cdk-turso.TursoDatabase.property.databaseName">databaseName</a></code> | <code>string</code> | *No description.* |
|
|
202
273
|
| <code><a href="#cdk-turso.TursoDatabase.property.dbId">dbId</a></code> | <code>string</code> | *No description.* |
|
|
203
274
|
| <code><a href="#cdk-turso.TursoDatabase.property.hostname">hostname</a></code> | <code>string</code> | DNS hostname for the database (e.g., `my-db-my-org.turso.io`). Use with libSQL or HTTP connections. |
|
|
204
|
-
| <code><a href="#cdk-turso.TursoDatabase.property.organizationSlug">organizationSlug</a></code> | <code>string</code> | *No description.* |
|
|
205
275
|
|
|
206
276
|
---
|
|
207
277
|
|
|
@@ -217,16 +287,6 @@ The tree node.
|
|
|
217
287
|
|
|
218
288
|
---
|
|
219
289
|
|
|
220
|
-
##### `apiToken`<sup>Required</sup> <a name="apiToken" id="cdk-turso.TursoDatabase.property.apiToken"></a>
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
public readonly apiToken: IParameter;
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
- *Type:* aws-cdk-lib.aws_ssm.IParameter
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
290
|
##### `databaseName`<sup>Required</sup> <a name="databaseName" id="cdk-turso.TursoDatabase.property.databaseName"></a>
|
|
231
291
|
|
|
232
292
|
```typescript
|
|
@@ -259,16 +319,175 @@ DNS hostname for the database (e.g., `my-db-my-org.turso.io`). Use with libSQL o
|
|
|
259
319
|
|
|
260
320
|
---
|
|
261
321
|
|
|
262
|
-
|
|
322
|
+
|
|
323
|
+
### TursoProvider <a name="TursoProvider" id="cdk-turso.TursoProvider"></a>
|
|
324
|
+
|
|
325
|
+
Shared Lambda + CloudFormation custom-resource provider for all Turso resources.
|
|
326
|
+
|
|
327
|
+
Create one per stack and pass it to every
|
|
328
|
+
`TursoDatabase`, `TursoAuthToken`, etc.
|
|
329
|
+
|
|
330
|
+
#### Initializers <a name="Initializers" id="cdk-turso.TursoProvider.Initializer"></a>
|
|
263
331
|
|
|
264
332
|
```typescript
|
|
265
|
-
|
|
333
|
+
import { TursoProvider } from 'cdk-turso'
|
|
334
|
+
|
|
335
|
+
new TursoProvider(scope: Construct, id: string, props: TursoProviderProps)
|
|
266
336
|
```
|
|
267
337
|
|
|
338
|
+
| **Name** | **Type** | **Description** |
|
|
339
|
+
| --- | --- | --- |
|
|
340
|
+
| <code><a href="#cdk-turso.TursoProvider.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | *No description.* |
|
|
341
|
+
| <code><a href="#cdk-turso.TursoProvider.Initializer.parameter.id">id</a></code> | <code>string</code> | *No description.* |
|
|
342
|
+
| <code><a href="#cdk-turso.TursoProvider.Initializer.parameter.props">props</a></code> | <code><a href="#cdk-turso.TursoProviderProps">TursoProviderProps</a></code> | *No description.* |
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
##### `scope`<sup>Required</sup> <a name="scope" id="cdk-turso.TursoProvider.Initializer.parameter.scope"></a>
|
|
347
|
+
|
|
348
|
+
- *Type:* constructs.Construct
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
##### `id`<sup>Required</sup> <a name="id" id="cdk-turso.TursoProvider.Initializer.parameter.id"></a>
|
|
353
|
+
|
|
268
354
|
- *Type:* string
|
|
269
355
|
|
|
270
356
|
---
|
|
271
357
|
|
|
358
|
+
##### `props`<sup>Required</sup> <a name="props" id="cdk-turso.TursoProvider.Initializer.parameter.props"></a>
|
|
359
|
+
|
|
360
|
+
- *Type:* <a href="#cdk-turso.TursoProviderProps">TursoProviderProps</a>
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
#### Methods <a name="Methods" id="Methods"></a>
|
|
365
|
+
|
|
366
|
+
| **Name** | **Description** |
|
|
367
|
+
| --- | --- |
|
|
368
|
+
| <code><a href="#cdk-turso.TursoProvider.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
369
|
+
| <code><a href="#cdk-turso.TursoProvider.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
##### `toString` <a name="toString" id="cdk-turso.TursoProvider.toString"></a>
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
public toString(): string
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Returns a string representation of this construct.
|
|
380
|
+
|
|
381
|
+
##### `with` <a name="with" id="cdk-turso.TursoProvider.with"></a>
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Applies one or more mixins to this construct.
|
|
388
|
+
|
|
389
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
390
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
391
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
392
|
+
constructs.
|
|
393
|
+
|
|
394
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="cdk-turso.TursoProvider.with.parameter.mixins"></a>
|
|
395
|
+
|
|
396
|
+
- *Type:* ...constructs.IMixin[]
|
|
397
|
+
|
|
398
|
+
The mixins to apply.
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
403
|
+
|
|
404
|
+
| **Name** | **Description** |
|
|
405
|
+
| --- | --- |
|
|
406
|
+
| <code><a href="#cdk-turso.TursoProvider.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
##### `isConstruct` <a name="isConstruct" id="cdk-turso.TursoProvider.isConstruct"></a>
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
import { TursoProvider } from 'cdk-turso'
|
|
414
|
+
|
|
415
|
+
TursoProvider.isConstruct(x: any)
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Checks if `x` is a construct.
|
|
419
|
+
|
|
420
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
421
|
+
instances, even when the construct library is symlinked.
|
|
422
|
+
|
|
423
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
424
|
+
disk are seen as independent, completely different libraries. As a
|
|
425
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
426
|
+
is seen as a different class, and an instance of one class will not test as
|
|
427
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
428
|
+
like this, but users may manually symlink construct libraries together or
|
|
429
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
430
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
431
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
432
|
+
this type-testing method instead.
|
|
433
|
+
|
|
434
|
+
###### `x`<sup>Required</sup> <a name="x" id="cdk-turso.TursoProvider.isConstruct.parameter.x"></a>
|
|
435
|
+
|
|
436
|
+
- *Type:* any
|
|
437
|
+
|
|
438
|
+
Any object.
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
443
|
+
|
|
444
|
+
| **Name** | **Type** | **Description** |
|
|
445
|
+
| --- | --- | --- |
|
|
446
|
+
| <code><a href="#cdk-turso.TursoProvider.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
447
|
+
| <code><a href="#cdk-turso.TursoProvider.property.handler">handler</a></code> | <code>aws-cdk-lib.aws_lambda.Function</code> | The Lambda function backing all Turso custom resources. |
|
|
448
|
+
| <code><a href="#cdk-turso.TursoProvider.property.serviceToken">serviceToken</a></code> | <code>string</code> | The CDK custom-resource provider service token. |
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
##### `node`<sup>Required</sup> <a name="node" id="cdk-turso.TursoProvider.property.node"></a>
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
public readonly node: Node;
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
- *Type:* constructs.Node
|
|
459
|
+
|
|
460
|
+
The tree node.
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
##### `handler`<sup>Required</sup> <a name="handler" id="cdk-turso.TursoProvider.property.handler"></a>
|
|
465
|
+
|
|
466
|
+
```typescript
|
|
467
|
+
public readonly handler: Function;
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
- *Type:* aws-cdk-lib.aws_lambda.Function
|
|
471
|
+
|
|
472
|
+
The Lambda function backing all Turso custom resources.
|
|
473
|
+
|
|
474
|
+
Use this to attach additional IAM permissions when a resource
|
|
475
|
+
type needs them (e.g. `ssm:PutParameter` for auth-token storage).
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
##### `serviceToken`<sup>Required</sup> <a name="serviceToken" id="cdk-turso.TursoProvider.property.serviceToken"></a>
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
public readonly serviceToken: string;
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
- *Type:* string
|
|
486
|
+
|
|
487
|
+
The CDK custom-resource provider service token.
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
272
491
|
|
|
273
492
|
## Structs <a name="Structs" id="Structs"></a>
|
|
274
493
|
|
|
@@ -286,22 +505,36 @@ const tursoAuthTokenProps: TursoAuthTokenProps = { ... }
|
|
|
286
505
|
|
|
287
506
|
| **Name** | **Type** | **Description** |
|
|
288
507
|
| --- | --- | --- |
|
|
289
|
-
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.
|
|
508
|
+
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.databaseName">databaseName</a></code> | <code>string</code> | The name of the Turso database to create an auth token for. |
|
|
509
|
+
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.organizationSlug">organizationSlug</a></code> | <code>string</code> | The Turso organization slug that owns the database. |
|
|
290
510
|
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.parameterName">parameterName</a></code> | <code>string</code> | The SSM parameter name where the generated JWT will be stored as a SecureString. |
|
|
511
|
+
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.provider">provider</a></code> | <code><a href="#cdk-turso.TursoProvider">TursoProvider</a></code> | *No description.* |
|
|
291
512
|
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.authorization">authorization</a></code> | <code>string</code> | Authorization level for the token. |
|
|
292
513
|
| <code><a href="#cdk-turso.TursoAuthTokenProps.property.expiration">expiration</a></code> | <code>string</code> | Expiration time for the token (e.g., `"2w"`, `"1d30m"`). |
|
|
293
514
|
|
|
294
515
|
---
|
|
295
516
|
|
|
296
|
-
##### `
|
|
517
|
+
##### `databaseName`<sup>Required</sup> <a name="databaseName" id="cdk-turso.TursoAuthTokenProps.property.databaseName"></a>
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
public readonly databaseName: string;
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
- *Type:* string
|
|
524
|
+
|
|
525
|
+
The name of the Turso database to create an auth token for.
|
|
526
|
+
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
##### `organizationSlug`<sup>Required</sup> <a name="organizationSlug" id="cdk-turso.TursoAuthTokenProps.property.organizationSlug"></a>
|
|
297
530
|
|
|
298
531
|
```typescript
|
|
299
|
-
public readonly
|
|
532
|
+
public readonly organizationSlug: string;
|
|
300
533
|
```
|
|
301
534
|
|
|
302
|
-
- *Type:*
|
|
535
|
+
- *Type:* string
|
|
303
536
|
|
|
304
|
-
The Turso
|
|
537
|
+
The Turso organization slug that owns the database.
|
|
305
538
|
|
|
306
539
|
---
|
|
307
540
|
|
|
@@ -317,6 +550,16 @@ The SSM parameter name where the generated JWT will be stored as a SecureString.
|
|
|
317
550
|
|
|
318
551
|
---
|
|
319
552
|
|
|
553
|
+
##### `provider`<sup>Required</sup> <a name="provider" id="cdk-turso.TursoAuthTokenProps.property.provider"></a>
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
public readonly provider: TursoProvider;
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
- *Type:* <a href="#cdk-turso.TursoProvider">TursoProvider</a>
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
320
563
|
##### `authorization`<sup>Optional</sup> <a name="authorization" id="cdk-turso.TursoAuthTokenProps.property.authorization"></a>
|
|
321
564
|
|
|
322
565
|
```typescript
|
|
@@ -396,26 +639,16 @@ const tursoDatabaseProps: TursoDatabaseProps = { ... }
|
|
|
396
639
|
|
|
397
640
|
| **Name** | **Type** | **Description** |
|
|
398
641
|
| --- | --- | --- |
|
|
399
|
-
| <code><a href="#cdk-turso.TursoDatabaseProps.property.apiToken">apiToken</a></code> | <code>aws-cdk-lib.aws_ssm.IParameter</code> | *No description.* |
|
|
400
642
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.databaseName">databaseName</a></code> | <code>string</code> | *No description.* |
|
|
401
643
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.group">group</a></code> | <code>string</code> | *No description.* |
|
|
402
644
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.organizationSlug">organizationSlug</a></code> | <code>string</code> | *No description.* |
|
|
645
|
+
| <code><a href="#cdk-turso.TursoDatabaseProps.property.provider">provider</a></code> | <code><a href="#cdk-turso.TursoProvider">TursoProvider</a></code> | *No description.* |
|
|
403
646
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.encryption">encryption</a></code> | <code><a href="#cdk-turso.TursoDatabaseEncryption">TursoDatabaseEncryption</a></code> | *No description.* |
|
|
404
647
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.seed">seed</a></code> | <code><a href="#cdk-turso.TursoDatabaseSeed">TursoDatabaseSeed</a></code> | *No description.* |
|
|
405
648
|
| <code><a href="#cdk-turso.TursoDatabaseProps.property.sizeLimit">sizeLimit</a></code> | <code>string</code> | *No description.* |
|
|
406
649
|
|
|
407
650
|
---
|
|
408
651
|
|
|
409
|
-
##### `apiToken`<sup>Required</sup> <a name="apiToken" id="cdk-turso.TursoDatabaseProps.property.apiToken"></a>
|
|
410
|
-
|
|
411
|
-
```typescript
|
|
412
|
-
public readonly apiToken: IParameter;
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
- *Type:* aws-cdk-lib.aws_ssm.IParameter
|
|
416
|
-
|
|
417
|
-
---
|
|
418
|
-
|
|
419
652
|
##### `databaseName`<sup>Required</sup> <a name="databaseName" id="cdk-turso.TursoDatabaseProps.property.databaseName"></a>
|
|
420
653
|
|
|
421
654
|
```typescript
|
|
@@ -446,6 +679,16 @@ public readonly organizationSlug: string;
|
|
|
446
679
|
|
|
447
680
|
---
|
|
448
681
|
|
|
682
|
+
##### `provider`<sup>Required</sup> <a name="provider" id="cdk-turso.TursoDatabaseProps.property.provider"></a>
|
|
683
|
+
|
|
684
|
+
```typescript
|
|
685
|
+
public readonly provider: TursoProvider;
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
- *Type:* <a href="#cdk-turso.TursoProvider">TursoProvider</a>
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
449
692
|
##### `encryption`<sup>Optional</sup> <a name="encryption" id="cdk-turso.TursoDatabaseProps.property.encryption"></a>
|
|
450
693
|
|
|
451
694
|
```typescript
|
|
@@ -526,5 +769,50 @@ public readonly timestamp: string;
|
|
|
526
769
|
|
|
527
770
|
---
|
|
528
771
|
|
|
772
|
+
### TursoProviderProps <a name="TursoProviderProps" id="cdk-turso.TursoProviderProps"></a>
|
|
773
|
+
|
|
774
|
+
#### Initializer <a name="Initializer" id="cdk-turso.TursoProviderProps.Initializer"></a>
|
|
775
|
+
|
|
776
|
+
```typescript
|
|
777
|
+
import { TursoProviderProps } from 'cdk-turso'
|
|
778
|
+
|
|
779
|
+
const tursoProviderProps: TursoProviderProps = { ... }
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
783
|
+
|
|
784
|
+
| **Name** | **Type** | **Description** |
|
|
785
|
+
| --- | --- | --- |
|
|
786
|
+
| <code><a href="#cdk-turso.TursoProviderProps.property.apiToken">apiToken</a></code> | <code>aws-cdk-lib.aws_ssm.IParameter</code> | SSM parameter that holds the Turso platform API token (stored as SecureString). |
|
|
787
|
+
| <code><a href="#cdk-turso.TursoProviderProps.property.logGroup">logGroup</a></code> | <code>aws-cdk-lib.aws_logs.ILogGroup</code> | Optional log group for the Lambda function. |
|
|
788
|
+
|
|
789
|
+
---
|
|
790
|
+
|
|
791
|
+
##### `apiToken`<sup>Required</sup> <a name="apiToken" id="cdk-turso.TursoProviderProps.property.apiToken"></a>
|
|
792
|
+
|
|
793
|
+
```typescript
|
|
794
|
+
public readonly apiToken: IParameter;
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
- *Type:* aws-cdk-lib.aws_ssm.IParameter
|
|
798
|
+
|
|
799
|
+
SSM parameter that holds the Turso platform API token (stored as SecureString).
|
|
800
|
+
|
|
801
|
+
---
|
|
802
|
+
|
|
803
|
+
##### `logGroup`<sup>Optional</sup> <a name="logGroup" id="cdk-turso.TursoProviderProps.property.logGroup"></a>
|
|
804
|
+
|
|
805
|
+
```typescript
|
|
806
|
+
public readonly logGroup: ILogGroup;
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
- *Type:* aws-cdk-lib.aws_logs.ILogGroup
|
|
810
|
+
|
|
811
|
+
Optional log group for the Lambda function.
|
|
812
|
+
|
|
813
|
+
If not provided, a log group will be automatically created.
|
|
814
|
+
|
|
815
|
+
---
|
|
816
|
+
|
|
529
817
|
|
|
530
818
|
|
package/lib/handler/index.d.ts
CHANGED
|
@@ -3,31 +3,14 @@ export interface CloudFormationCustomResourceEvent {
|
|
|
3
3
|
PhysicalResourceId?: string;
|
|
4
4
|
ResourceProperties: {
|
|
5
5
|
ServiceToken: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
OrganizationSlug: string;
|
|
9
|
-
SizeLimit?: string;
|
|
10
|
-
Seed?: {
|
|
11
|
-
type: string;
|
|
12
|
-
name: string;
|
|
13
|
-
timestamp?: string;
|
|
14
|
-
};
|
|
15
|
-
Encryption?: {
|
|
16
|
-
encryptionKey: string;
|
|
17
|
-
encryptionCipher: string;
|
|
18
|
-
};
|
|
6
|
+
ResourceType: "Database" | "AuthToken";
|
|
7
|
+
[key: string]: unknown;
|
|
19
8
|
};
|
|
20
9
|
OldResourceProperties?: {
|
|
21
|
-
|
|
22
|
-
Group: string;
|
|
23
|
-
OrganizationSlug: string;
|
|
10
|
+
[key: string]: unknown;
|
|
24
11
|
};
|
|
25
12
|
}
|
|
26
13
|
export declare function handler(event: CloudFormationCustomResourceEvent): Promise<{
|
|
27
14
|
PhysicalResourceId: string;
|
|
28
|
-
Data?:
|
|
29
|
-
DbId: string;
|
|
30
|
-
Hostname: string;
|
|
31
|
-
Name: string;
|
|
32
|
-
};
|
|
15
|
+
Data?: Record<string, string>;
|
|
33
16
|
}>;
|
package/lib/handler/index.js
CHANGED
|
@@ -591,7 +591,7 @@ var retryOptions = {
|
|
|
591
591
|
numOfAttempts: 4,
|
|
592
592
|
jitter: "none"
|
|
593
593
|
};
|
|
594
|
-
async function fetchWithRetry(url, options, errorMessage, allow404) {
|
|
594
|
+
async function fetchWithRetry(url, options, errorMessage, allow404 = false) {
|
|
595
595
|
return (0, import_exponential_backoff.backOff)(async () => {
|
|
596
596
|
const response = await fetch(url, options);
|
|
597
597
|
if (!response.ok && !(allow404 && response.status === 404)) {
|
|
@@ -612,20 +612,8 @@ async function getApiToken(parameterName) {
|
|
|
612
612
|
}
|
|
613
613
|
return response.Parameter.Value;
|
|
614
614
|
}
|
|
615
|
-
async function
|
|
616
|
-
const {
|
|
617
|
-
RequestType,
|
|
618
|
-
PhysicalResourceId,
|
|
619
|
-
ResourceProperties,
|
|
620
|
-
OldResourceProperties
|
|
621
|
-
} = event;
|
|
622
|
-
const parameterName = process.env.TURSO_API_TOKEN_PARAMETER_NAME;
|
|
623
|
-
if (!parameterName) {
|
|
624
|
-
throw new Error(
|
|
625
|
-
"TURSO_API_TOKEN_PARAMETER_NAME environment variable not set"
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
const apiToken = await getApiToken(parameterName);
|
|
615
|
+
async function handleDatabase(event, apiToken) {
|
|
616
|
+
const { RequestType, PhysicalResourceId, ResourceProperties } = event;
|
|
629
617
|
const orgSlug = encodeURIComponent(ResourceProperties.OrganizationSlug);
|
|
630
618
|
const baseUrl = "https://api.turso.tech/v1";
|
|
631
619
|
if (RequestType === "Create") {
|
|
@@ -653,8 +641,7 @@ async function handler(event) {
|
|
|
653
641
|
},
|
|
654
642
|
body: JSON.stringify(body)
|
|
655
643
|
},
|
|
656
|
-
"Failed to create database"
|
|
657
|
-
false
|
|
644
|
+
"Failed to create database"
|
|
658
645
|
);
|
|
659
646
|
const data = await response.json();
|
|
660
647
|
return {
|
|
@@ -667,7 +654,7 @@ async function handler(event) {
|
|
|
667
654
|
};
|
|
668
655
|
}
|
|
669
656
|
if (RequestType === "Update") {
|
|
670
|
-
const oldDbName = OldResourceProperties?.DatabaseName;
|
|
657
|
+
const oldDbName = event.OldResourceProperties?.DatabaseName;
|
|
671
658
|
const newDbName = ResourceProperties.DatabaseName;
|
|
672
659
|
if (oldDbName && oldDbName !== newDbName) {
|
|
673
660
|
const body = {
|
|
@@ -684,8 +671,7 @@ async function handler(event) {
|
|
|
684
671
|
},
|
|
685
672
|
body: JSON.stringify(body)
|
|
686
673
|
},
|
|
687
|
-
"Failed to create database"
|
|
688
|
-
false
|
|
674
|
+
"Failed to create database"
|
|
689
675
|
);
|
|
690
676
|
const data = await response.json();
|
|
691
677
|
return {
|
|
@@ -724,6 +710,107 @@ async function handler(event) {
|
|
|
724
710
|
}
|
|
725
711
|
throw new Error(`Unknown request type: ${RequestType}`);
|
|
726
712
|
}
|
|
713
|
+
async function createToken(baseUrl, orgSlug, dbName, apiToken, expiration, authorization) {
|
|
714
|
+
const params = new URLSearchParams();
|
|
715
|
+
params.set("expiration", expiration);
|
|
716
|
+
params.set("authorization", authorization);
|
|
717
|
+
const response = await fetchWithRetry(
|
|
718
|
+
`${baseUrl}/organizations/${orgSlug}/databases/${dbName}/auth/tokens?${params.toString()}`,
|
|
719
|
+
{
|
|
720
|
+
method: "POST",
|
|
721
|
+
headers: {
|
|
722
|
+
Authorization: `Bearer ${apiToken}`
|
|
723
|
+
}
|
|
724
|
+
},
|
|
725
|
+
"Failed to create auth token"
|
|
726
|
+
);
|
|
727
|
+
const data = await response.json();
|
|
728
|
+
return data.jwt;
|
|
729
|
+
}
|
|
730
|
+
async function storeToken(parameterName, token) {
|
|
731
|
+
const command = new import_client_ssm.PutParameterCommand({
|
|
732
|
+
Name: parameterName,
|
|
733
|
+
Value: token,
|
|
734
|
+
Type: "SecureString",
|
|
735
|
+
Overwrite: true
|
|
736
|
+
});
|
|
737
|
+
await ssmClient.send(command);
|
|
738
|
+
}
|
|
739
|
+
async function deleteParameter(parameterName) {
|
|
740
|
+
try {
|
|
741
|
+
const command = new import_client_ssm.DeleteParameterCommand({
|
|
742
|
+
Name: parameterName
|
|
743
|
+
});
|
|
744
|
+
await ssmClient.send(command);
|
|
745
|
+
} catch (error) {
|
|
746
|
+
if (error instanceof Error && error.name === "ParameterNotFound") {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
throw error;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async function handleAuthToken(event, apiToken) {
|
|
753
|
+
const { RequestType, PhysicalResourceId, ResourceProperties } = event;
|
|
754
|
+
const orgSlug = encodeURIComponent(ResourceProperties.OrganizationSlug);
|
|
755
|
+
const dbName = encodeURIComponent(ResourceProperties.DatabaseName);
|
|
756
|
+
const baseUrl = "https://api.turso.tech/v1";
|
|
757
|
+
const parameterName = ResourceProperties.ParameterName;
|
|
758
|
+
const expiration = ResourceProperties.Expiration || "never";
|
|
759
|
+
const authorization = ResourceProperties.Authorization || "full-access";
|
|
760
|
+
if (RequestType === "Create") {
|
|
761
|
+
const jwt = await createToken(
|
|
762
|
+
baseUrl,
|
|
763
|
+
orgSlug,
|
|
764
|
+
dbName,
|
|
765
|
+
apiToken,
|
|
766
|
+
expiration,
|
|
767
|
+
authorization
|
|
768
|
+
);
|
|
769
|
+
await storeToken(parameterName, jwt);
|
|
770
|
+
return { PhysicalResourceId: parameterName };
|
|
771
|
+
}
|
|
772
|
+
if (RequestType === "Update") {
|
|
773
|
+
const jwt = await createToken(
|
|
774
|
+
baseUrl,
|
|
775
|
+
orgSlug,
|
|
776
|
+
dbName,
|
|
777
|
+
apiToken,
|
|
778
|
+
expiration,
|
|
779
|
+
authorization
|
|
780
|
+
);
|
|
781
|
+
await storeToken(parameterName, jwt);
|
|
782
|
+
return { PhysicalResourceId: parameterName };
|
|
783
|
+
}
|
|
784
|
+
if (RequestType === "Delete") {
|
|
785
|
+
if (!PhysicalResourceId) {
|
|
786
|
+
return { PhysicalResourceId: "unknown" };
|
|
787
|
+
}
|
|
788
|
+
if (PhysicalResourceId === "unknown" || PhysicalResourceId.startsWith("failed-")) {
|
|
789
|
+
return { PhysicalResourceId };
|
|
790
|
+
}
|
|
791
|
+
await deleteParameter(PhysicalResourceId);
|
|
792
|
+
return { PhysicalResourceId };
|
|
793
|
+
}
|
|
794
|
+
throw new Error(`Unknown request type: ${RequestType}`);
|
|
795
|
+
}
|
|
796
|
+
async function handler(event) {
|
|
797
|
+
const parameterName = process.env.TURSO_API_TOKEN_PARAMETER_NAME;
|
|
798
|
+
if (!parameterName) {
|
|
799
|
+
throw new Error(
|
|
800
|
+
"TURSO_API_TOKEN_PARAMETER_NAME environment variable not set"
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
const apiToken = await getApiToken(parameterName);
|
|
804
|
+
const resourceType = event.ResourceProperties.ResourceType;
|
|
805
|
+
switch (resourceType) {
|
|
806
|
+
case "Database":
|
|
807
|
+
return handleDatabase(event, apiToken);
|
|
808
|
+
case "AuthToken":
|
|
809
|
+
return handleAuthToken(event, apiToken);
|
|
810
|
+
default:
|
|
811
|
+
throw new Error(`Unknown resource type: ${resourceType}`);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
727
814
|
// Annotate the CommonJS export names for ESM import in node:
|
|
728
815
|
0 && (module.exports = {
|
|
729
816
|
handler
|