@stacksjs/ts-cloud 0.1.8 → 0.1.9

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.
Files changed (75) hide show
  1. package/dist/bin/cli.js +1 -1
  2. package/package.json +18 -16
  3. package/src/aws/acm.ts +768 -0
  4. package/src/aws/application-autoscaling.ts +845 -0
  5. package/src/aws/bedrock.ts +4074 -0
  6. package/src/aws/client.ts +891 -0
  7. package/src/aws/cloudformation.ts +896 -0
  8. package/src/aws/cloudfront.ts +1531 -0
  9. package/src/aws/cloudwatch-logs.ts +154 -0
  10. package/src/aws/comprehend.ts +839 -0
  11. package/src/aws/connect.ts +1056 -0
  12. package/src/aws/deploy-imap.ts +384 -0
  13. package/src/aws/dynamodb.ts +340 -0
  14. package/src/aws/ec2.ts +1385 -0
  15. package/src/aws/ecr.ts +621 -0
  16. package/src/aws/ecs.ts +615 -0
  17. package/src/aws/elasticache.ts +301 -0
  18. package/src/aws/elbv2.ts +942 -0
  19. package/src/aws/email.ts +928 -0
  20. package/src/aws/eventbridge.ts +248 -0
  21. package/src/aws/iam.ts +1689 -0
  22. package/src/aws/imap-server.ts +2100 -0
  23. package/src/aws/index.ts +213 -0
  24. package/src/aws/kendra.ts +1097 -0
  25. package/src/aws/lambda.ts +786 -0
  26. package/src/aws/opensearch.ts +158 -0
  27. package/src/aws/personalize.ts +977 -0
  28. package/src/aws/polly.ts +559 -0
  29. package/src/aws/rds.ts +888 -0
  30. package/src/aws/rekognition.ts +846 -0
  31. package/src/aws/route53-domains.ts +359 -0
  32. package/src/aws/route53.ts +1046 -0
  33. package/src/aws/s3.ts +2334 -0
  34. package/src/aws/scheduler.ts +571 -0
  35. package/src/aws/secrets-manager.ts +769 -0
  36. package/src/aws/ses.ts +1081 -0
  37. package/src/aws/setup-phone.ts +104 -0
  38. package/src/aws/setup-sms.ts +580 -0
  39. package/src/aws/sms.ts +1735 -0
  40. package/src/aws/smtp-server.ts +531 -0
  41. package/src/aws/sns.ts +758 -0
  42. package/src/aws/sqs.ts +382 -0
  43. package/src/aws/ssm.ts +807 -0
  44. package/src/aws/sts.ts +92 -0
  45. package/src/aws/support.ts +391 -0
  46. package/src/aws/test-imap.ts +86 -0
  47. package/src/aws/textract.ts +780 -0
  48. package/src/aws/transcribe.ts +108 -0
  49. package/src/aws/translate.ts +641 -0
  50. package/src/aws/voice.ts +1379 -0
  51. package/src/config.ts +35 -0
  52. package/src/deploy/index.ts +7 -0
  53. package/src/deploy/static-site-external-dns.ts +945 -0
  54. package/src/deploy/static-site.ts +1175 -0
  55. package/src/dns/cloudflare.ts +548 -0
  56. package/src/dns/godaddy.ts +412 -0
  57. package/src/dns/index.ts +205 -0
  58. package/src/dns/porkbun.ts +362 -0
  59. package/src/dns/route53-adapter.ts +414 -0
  60. package/src/dns/types.ts +119 -0
  61. package/src/dns/validator.ts +369 -0
  62. package/src/generators/index.ts +5 -0
  63. package/src/generators/infrastructure.ts +1660 -0
  64. package/src/index.ts +163 -0
  65. package/src/push/apns.ts +452 -0
  66. package/src/push/fcm.ts +506 -0
  67. package/src/push/index.ts +58 -0
  68. package/src/security/pre-deploy-scanner.ts +655 -0
  69. package/src/ssl/acme-client.ts +478 -0
  70. package/src/ssl/index.ts +7 -0
  71. package/src/ssl/letsencrypt.ts +747 -0
  72. package/src/types.ts +2 -0
  73. package/src/utils/cli.ts +398 -0
  74. package/src/validation/index.ts +5 -0
  75. package/src/validation/template.ts +405 -0
@@ -0,0 +1,1097 @@
1
+ /**
2
+ * AWS Kendra Client
3
+ * Enterprise search service
4
+ * No external SDK dependencies - implements AWS Signature V4 directly
5
+ */
6
+
7
+ import { AWSClient } from './client'
8
+
9
+ // ============================================================================
10
+ // Types
11
+ // ============================================================================
12
+
13
+ export interface CreateIndexCommandInput {
14
+ Name: string
15
+ Edition?: 'DEVELOPER_EDITION' | 'ENTERPRISE_EDITION'
16
+ RoleArn: string
17
+ ServerSideEncryptionConfiguration?: {
18
+ KmsKeyId?: string
19
+ }
20
+ Description?: string
21
+ ClientToken?: string
22
+ Tags?: Array<{ Key: string; Value: string }>
23
+ UserTokenConfigurations?: Array<{
24
+ JwtTokenTypeConfiguration?: {
25
+ KeyLocation: 'URL' | 'SECRET_MANAGER'
26
+ URL?: string
27
+ SecretManagerArn?: string
28
+ UserNameAttributeField?: string
29
+ GroupAttributeField?: string
30
+ Issuer?: string
31
+ ClaimRegex?: string
32
+ }
33
+ JsonTokenTypeConfiguration?: {
34
+ UserNameAttributeField: string
35
+ GroupAttributeField: string
36
+ }
37
+ }>
38
+ UserContextPolicy?: 'ATTRIBUTE_FILTER' | 'USER_TOKEN'
39
+ UserGroupResolutionConfiguration?: {
40
+ UserGroupResolutionMode: 'AWS_SSO' | 'NONE'
41
+ }
42
+ }
43
+
44
+ export interface CreateIndexCommandOutput {
45
+ Id?: string
46
+ }
47
+
48
+ export interface DescribeIndexCommandInput {
49
+ Id: string
50
+ }
51
+
52
+ export interface Index {
53
+ Name?: string
54
+ Id?: string
55
+ Edition?: 'DEVELOPER_EDITION' | 'ENTERPRISE_EDITION'
56
+ RoleArn?: string
57
+ ServerSideEncryptionConfiguration?: {
58
+ KmsKeyId?: string
59
+ }
60
+ Status?: 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED' | 'UPDATING' | 'SYSTEM_UPDATING'
61
+ Description?: string
62
+ CreatedAt?: string
63
+ UpdatedAt?: string
64
+ DocumentMetadataConfigurations?: Array<{
65
+ Name?: string
66
+ Type?: 'STRING_VALUE' | 'STRING_LIST_VALUE' | 'LONG_VALUE' | 'DATE_VALUE'
67
+ Relevance?: {
68
+ Freshness?: boolean
69
+ Importance?: number
70
+ Duration?: string
71
+ RankOrder?: 'ASCENDING' | 'DESCENDING'
72
+ ValueImportanceMap?: Record<string, number>
73
+ }
74
+ Search?: {
75
+ Facetable?: boolean
76
+ Searchable?: boolean
77
+ Displayable?: boolean
78
+ Sortable?: boolean
79
+ }
80
+ }>
81
+ IndexStatistics?: {
82
+ FaqStatistics?: {
83
+ IndexedQuestionAnswersCount?: number
84
+ }
85
+ TextDocumentStatistics?: {
86
+ IndexedTextDocumentsCount?: number
87
+ IndexedTextBytes?: number
88
+ }
89
+ }
90
+ ErrorMessage?: string
91
+ CapacityUnits?: {
92
+ StorageCapacityUnits: number
93
+ QueryCapacityUnits: number
94
+ }
95
+ UserTokenConfigurations?: Array<{
96
+ JwtTokenTypeConfiguration?: {
97
+ KeyLocation?: string
98
+ URL?: string
99
+ SecretManagerArn?: string
100
+ UserNameAttributeField?: string
101
+ GroupAttributeField?: string
102
+ Issuer?: string
103
+ ClaimRegex?: string
104
+ }
105
+ JsonTokenTypeConfiguration?: {
106
+ UserNameAttributeField?: string
107
+ GroupAttributeField?: string
108
+ }
109
+ }>
110
+ UserContextPolicy?: 'ATTRIBUTE_FILTER' | 'USER_TOKEN'
111
+ UserGroupResolutionConfiguration?: {
112
+ UserGroupResolutionMode?: 'AWS_SSO' | 'NONE'
113
+ }
114
+ }
115
+
116
+ export interface DescribeIndexCommandOutput {
117
+ Name?: string
118
+ Id?: string
119
+ Edition?: 'DEVELOPER_EDITION' | 'ENTERPRISE_EDITION'
120
+ RoleArn?: string
121
+ ServerSideEncryptionConfiguration?: {
122
+ KmsKeyId?: string
123
+ }
124
+ Status?: 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED' | 'UPDATING' | 'SYSTEM_UPDATING'
125
+ Description?: string
126
+ CreatedAt?: string
127
+ UpdatedAt?: string
128
+ DocumentMetadataConfigurations?: Index['DocumentMetadataConfigurations']
129
+ IndexStatistics?: Index['IndexStatistics']
130
+ ErrorMessage?: string
131
+ CapacityUnits?: Index['CapacityUnits']
132
+ }
133
+
134
+ export interface ListIndicesCommandInput {
135
+ NextToken?: string
136
+ MaxResults?: number
137
+ }
138
+
139
+ export interface IndexSummary {
140
+ Name?: string
141
+ Id?: string
142
+ Edition?: 'DEVELOPER_EDITION' | 'ENTERPRISE_EDITION'
143
+ CreatedAt?: string
144
+ UpdatedAt?: string
145
+ Status?: 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED' | 'UPDATING' | 'SYSTEM_UPDATING'
146
+ }
147
+
148
+ export interface ListIndicesCommandOutput {
149
+ IndexConfigurationSummaryItems?: IndexSummary[]
150
+ NextToken?: string
151
+ }
152
+
153
+ export interface DeleteIndexCommandInput {
154
+ Id: string
155
+ }
156
+
157
+ export interface DeleteIndexCommandOutput {
158
+ // Empty
159
+ }
160
+
161
+ export interface CreateDataSourceCommandInput {
162
+ Name: string
163
+ IndexId: string
164
+ Type: 'S3' | 'SHAREPOINT' | 'DATABASE' | 'SALESFORCE' | 'ONEDRIVE' | 'SERVICENOW' | 'CUSTOM' | 'CONFLUENCE' | 'GOOGLEDRIVE' | 'WEBCRAWLER' | 'WORKDOCS' | 'FSX' | 'SLACK' | 'BOX' | 'QUIP' | 'JIRA' | 'GITHUB' | 'ALFRESCO' | 'TEMPLATE'
165
+ Configuration?: {
166
+ S3Configuration?: {
167
+ BucketName: string
168
+ InclusionPrefixes?: string[]
169
+ InclusionPatterns?: string[]
170
+ ExclusionPatterns?: string[]
171
+ DocumentsMetadataConfiguration?: {
172
+ S3Prefix?: string
173
+ }
174
+ AccessControlListConfiguration?: {
175
+ KeyPath?: string
176
+ }
177
+ }
178
+ WebCrawlerConfiguration?: {
179
+ Urls: {
180
+ SeedUrlConfiguration?: {
181
+ SeedUrls: string[]
182
+ WebCrawlerMode?: 'HOST_ONLY' | 'SUBDOMAINS' | 'EVERYTHING'
183
+ }
184
+ SiteMapsConfiguration?: {
185
+ SiteMaps: string[]
186
+ }
187
+ }
188
+ CrawlDepth?: number
189
+ MaxLinksPerPage?: number
190
+ MaxContentSizePerPageInMegaBytes?: number
191
+ MaxUrlsPerMinuteCrawlRate?: number
192
+ UrlInclusionPatterns?: string[]
193
+ UrlExclusionPatterns?: string[]
194
+ ProxyConfiguration?: {
195
+ Host: string
196
+ Port: number
197
+ Credentials?: string
198
+ }
199
+ AuthenticationConfiguration?: {
200
+ BasicAuthentication?: Array<{
201
+ Host: string
202
+ Port: number
203
+ Credentials: string
204
+ }>
205
+ }
206
+ }
207
+ ConfluenceConfiguration?: {
208
+ ServerUrl: string
209
+ SecretArn: string
210
+ Version: 'CLOUD' | 'SERVER'
211
+ SpaceConfiguration?: {
212
+ CrawlPersonalSpaces?: boolean
213
+ CrawlArchivedSpaces?: boolean
214
+ IncludeSpaces?: string[]
215
+ ExcludeSpaces?: string[]
216
+ SpaceFieldMappings?: Array<{
217
+ DataSourceFieldName?: string
218
+ DateFieldFormat?: string
219
+ IndexFieldName?: string
220
+ }>
221
+ }
222
+ PageConfiguration?: {
223
+ PageFieldMappings?: Array<{
224
+ DataSourceFieldName?: string
225
+ DateFieldFormat?: string
226
+ IndexFieldName?: string
227
+ }>
228
+ }
229
+ BlogConfiguration?: {
230
+ BlogFieldMappings?: Array<{
231
+ DataSourceFieldName?: string
232
+ DateFieldFormat?: string
233
+ IndexFieldName?: string
234
+ }>
235
+ }
236
+ AttachmentConfiguration?: {
237
+ CrawlAttachments?: boolean
238
+ AttachmentFieldMappings?: Array<{
239
+ DataSourceFieldName?: string
240
+ DateFieldFormat?: string
241
+ IndexFieldName?: string
242
+ }>
243
+ }
244
+ VpcConfiguration?: {
245
+ SubnetIds: string[]
246
+ SecurityGroupIds: string[]
247
+ }
248
+ InclusionPatterns?: string[]
249
+ ExclusionPatterns?: string[]
250
+ ProxyConfiguration?: {
251
+ Host: string
252
+ Port: number
253
+ Credentials?: string
254
+ }
255
+ AuthenticationType?: 'HTTP_BASIC' | 'PAT'
256
+ }
257
+ }
258
+ VpcConfiguration?: {
259
+ SubnetIds: string[]
260
+ SecurityGroupIds: string[]
261
+ }
262
+ Description?: string
263
+ Schedule?: string
264
+ RoleArn?: string
265
+ Tags?: Array<{ Key: string; Value: string }>
266
+ ClientToken?: string
267
+ LanguageCode?: string
268
+ CustomDocumentEnrichmentConfiguration?: {
269
+ InlineConfigurations?: Array<{
270
+ Condition?: {
271
+ ConditionDocumentAttributeKey: string
272
+ Operator: 'GreaterThan' | 'GreaterThanOrEquals' | 'LessThan' | 'LessThanOrEquals' | 'Equals' | 'NotEquals' | 'Contains' | 'NotContains' | 'Exists' | 'NotExists' | 'BeginsWith'
273
+ ConditionOnValue?: {
274
+ StringValue?: string
275
+ StringListValue?: string[]
276
+ LongValue?: number
277
+ DateValue?: string
278
+ }
279
+ }
280
+ Target?: {
281
+ TargetDocumentAttributeKey?: string
282
+ TargetDocumentAttributeValueDeletion?: boolean
283
+ TargetDocumentAttributeValue?: {
284
+ StringValue?: string
285
+ StringListValue?: string[]
286
+ LongValue?: number
287
+ DateValue?: string
288
+ }
289
+ }
290
+ DocumentContentDeletion?: boolean
291
+ }>
292
+ PreExtractionHookConfiguration?: {
293
+ InvocationCondition?: {
294
+ ConditionDocumentAttributeKey: string
295
+ Operator: string
296
+ ConditionOnValue?: {
297
+ StringValue?: string
298
+ StringListValue?: string[]
299
+ LongValue?: number
300
+ DateValue?: string
301
+ }
302
+ }
303
+ LambdaArn: string
304
+ S3Bucket: string
305
+ }
306
+ PostExtractionHookConfiguration?: {
307
+ InvocationCondition?: {
308
+ ConditionDocumentAttributeKey: string
309
+ Operator: string
310
+ ConditionOnValue?: {
311
+ StringValue?: string
312
+ StringListValue?: string[]
313
+ LongValue?: number
314
+ DateValue?: string
315
+ }
316
+ }
317
+ LambdaArn: string
318
+ S3Bucket: string
319
+ }
320
+ RoleArn?: string
321
+ }
322
+ }
323
+
324
+ export interface CreateDataSourceCommandOutput {
325
+ Id?: string
326
+ }
327
+
328
+ export interface DescribeDataSourceCommandInput {
329
+ Id: string
330
+ IndexId: string
331
+ }
332
+
333
+ export interface DataSource {
334
+ Id?: string
335
+ IndexId?: string
336
+ Name?: string
337
+ Type?: string
338
+ Configuration?: Record<string, unknown>
339
+ VpcConfiguration?: {
340
+ SubnetIds?: string[]
341
+ SecurityGroupIds?: string[]
342
+ }
343
+ CreatedAt?: string
344
+ UpdatedAt?: string
345
+ Description?: string
346
+ Status?: 'CREATING' | 'DELETING' | 'FAILED' | 'UPDATING' | 'ACTIVE'
347
+ Schedule?: string
348
+ RoleArn?: string
349
+ ErrorMessage?: string
350
+ LanguageCode?: string
351
+ CustomDocumentEnrichmentConfiguration?: Record<string, unknown>
352
+ }
353
+
354
+ export interface DescribeDataSourceCommandOutput extends DataSource {}
355
+
356
+ export interface ListDataSourcesCommandInput {
357
+ IndexId: string
358
+ NextToken?: string
359
+ MaxResults?: number
360
+ }
361
+
362
+ export interface DataSourceSummary {
363
+ Name?: string
364
+ Id?: string
365
+ Type?: string
366
+ CreatedAt?: string
367
+ UpdatedAt?: string
368
+ Status?: 'CREATING' | 'DELETING' | 'FAILED' | 'UPDATING' | 'ACTIVE'
369
+ LanguageCode?: string
370
+ }
371
+
372
+ export interface ListDataSourcesCommandOutput {
373
+ SummaryItems?: DataSourceSummary[]
374
+ NextToken?: string
375
+ }
376
+
377
+ export interface StartDataSourceSyncJobCommandInput {
378
+ Id: string
379
+ IndexId: string
380
+ }
381
+
382
+ export interface StartDataSourceSyncJobCommandOutput {
383
+ ExecutionId?: string
384
+ }
385
+
386
+ export interface StopDataSourceSyncJobCommandInput {
387
+ Id: string
388
+ IndexId: string
389
+ }
390
+
391
+ export interface StopDataSourceSyncJobCommandOutput {
392
+ // Empty
393
+ }
394
+
395
+ export interface QueryCommandInput {
396
+ IndexId: string
397
+ QueryText?: string
398
+ AttributeFilter?: {
399
+ AndAllFilters?: QueryCommandInput['AttributeFilter'][]
400
+ OrAllFilters?: QueryCommandInput['AttributeFilter'][]
401
+ NotFilter?: QueryCommandInput['AttributeFilter']
402
+ EqualsTo?: {
403
+ Key: string
404
+ Value: {
405
+ StringValue?: string
406
+ StringListValue?: string[]
407
+ LongValue?: number
408
+ DateValue?: string
409
+ }
410
+ }
411
+ ContainsAll?: {
412
+ Key: string
413
+ Value: {
414
+ StringValue?: string
415
+ StringListValue?: string[]
416
+ LongValue?: number
417
+ DateValue?: string
418
+ }
419
+ }
420
+ ContainsAny?: {
421
+ Key: string
422
+ Value: {
423
+ StringValue?: string
424
+ StringListValue?: string[]
425
+ LongValue?: number
426
+ DateValue?: string
427
+ }
428
+ }
429
+ GreaterThan?: {
430
+ Key: string
431
+ Value: {
432
+ StringValue?: string
433
+ StringListValue?: string[]
434
+ LongValue?: number
435
+ DateValue?: string
436
+ }
437
+ }
438
+ GreaterThanOrEquals?: {
439
+ Key: string
440
+ Value: {
441
+ StringValue?: string
442
+ StringListValue?: string[]
443
+ LongValue?: number
444
+ DateValue?: string
445
+ }
446
+ }
447
+ LessThan?: {
448
+ Key: string
449
+ Value: {
450
+ StringValue?: string
451
+ StringListValue?: string[]
452
+ LongValue?: number
453
+ DateValue?: string
454
+ }
455
+ }
456
+ LessThanOrEquals?: {
457
+ Key: string
458
+ Value: {
459
+ StringValue?: string
460
+ StringListValue?: string[]
461
+ LongValue?: number
462
+ DateValue?: string
463
+ }
464
+ }
465
+ }
466
+ Facets?: Array<{
467
+ DocumentAttributeKey?: string
468
+ Facets?: QueryCommandInput['Facets']
469
+ MaxResults?: number
470
+ }>
471
+ RequestedDocumentAttributes?: string[]
472
+ QueryResultTypeFilter?: 'DOCUMENT' | 'QUESTION_ANSWER' | 'ANSWER'
473
+ DocumentRelevanceOverrideConfigurations?: Array<{
474
+ Name: string
475
+ Relevance: {
476
+ Freshness?: boolean
477
+ Importance?: number
478
+ Duration?: string
479
+ RankOrder?: 'ASCENDING' | 'DESCENDING'
480
+ ValueImportanceMap?: Record<string, number>
481
+ }
482
+ }>
483
+ PageNumber?: number
484
+ PageSize?: number
485
+ SortingConfiguration?: {
486
+ DocumentAttributeKey: string
487
+ SortOrder: 'DESC' | 'ASC'
488
+ }
489
+ SortingConfigurations?: Array<{
490
+ DocumentAttributeKey: string
491
+ SortOrder: 'DESC' | 'ASC'
492
+ }>
493
+ UserContext?: {
494
+ Token?: string
495
+ UserId?: string
496
+ Groups?: string[]
497
+ DataSourceGroups?: Array<{
498
+ GroupId: string
499
+ DataSourceId: string
500
+ }>
501
+ }
502
+ VisitorId?: string
503
+ SpellCorrectionConfiguration?: {
504
+ IncludeQuerySpellCheckSuggestions: boolean
505
+ }
506
+ CollapseConfiguration?: {
507
+ DocumentAttributeKey: string
508
+ SortingConfigurations?: Array<{
509
+ DocumentAttributeKey: string
510
+ SortOrder: 'DESC' | 'ASC'
511
+ }>
512
+ MissingAttributeKeyStrategy?: 'IGNORE' | 'COLLAPSE' | 'EXPAND'
513
+ Expand?: boolean
514
+ ExpandConfiguration?: {
515
+ MaxResultItemsToExpand?: number
516
+ MaxExpandedResultsPerItem?: number
517
+ }
518
+ }
519
+ }
520
+
521
+ export interface QueryResultItem {
522
+ Id?: string
523
+ Type?: 'DOCUMENT' | 'QUESTION_ANSWER' | 'ANSWER'
524
+ Format?: 'TABLE' | 'TEXT'
525
+ AdditionalAttributes?: Array<{
526
+ Key?: string
527
+ ValueType?: 'TEXT_WITH_HIGHLIGHTS_VALUE' | 'ANSWER_VALUE'
528
+ Value?: {
529
+ TextWithHighlightsValue?: {
530
+ Text?: string
531
+ Highlights?: Array<{
532
+ BeginOffset?: number
533
+ EndOffset?: number
534
+ TopAnswer?: boolean
535
+ Type?: 'STANDARD' | 'THESAURUS_SYNONYM'
536
+ }>
537
+ }
538
+ }
539
+ }>
540
+ DocumentId?: string
541
+ DocumentTitle?: {
542
+ Text?: string
543
+ Highlights?: Array<{
544
+ BeginOffset?: number
545
+ EndOffset?: number
546
+ TopAnswer?: boolean
547
+ Type?: 'STANDARD' | 'THESAURUS_SYNONYM'
548
+ }>
549
+ }
550
+ DocumentExcerpt?: {
551
+ Text?: string
552
+ Highlights?: Array<{
553
+ BeginOffset?: number
554
+ EndOffset?: number
555
+ TopAnswer?: boolean
556
+ Type?: 'STANDARD' | 'THESAURUS_SYNONYM'
557
+ }>
558
+ }
559
+ DocumentURI?: string
560
+ DocumentAttributes?: Array<{
561
+ Key?: string
562
+ Value?: {
563
+ StringValue?: string
564
+ StringListValue?: string[]
565
+ LongValue?: number
566
+ DateValue?: string
567
+ }
568
+ }>
569
+ ScoreAttributes?: {
570
+ ScoreConfidence?: 'VERY_HIGH' | 'HIGH' | 'MEDIUM' | 'LOW' | 'NOT_AVAILABLE'
571
+ }
572
+ FeedbackToken?: string
573
+ TableExcerpt?: {
574
+ Rows?: Array<{
575
+ Cells?: Array<{
576
+ Value?: string
577
+ TopAnswer?: boolean
578
+ Highlighted?: boolean
579
+ Header?: boolean
580
+ }>
581
+ }>
582
+ TotalNumberOfRows?: number
583
+ }
584
+ CollapsedResultDetail?: {
585
+ DocumentAttribute?: {
586
+ Key?: string
587
+ Value?: {
588
+ StringValue?: string
589
+ StringListValue?: string[]
590
+ LongValue?: number
591
+ DateValue?: string
592
+ }
593
+ }
594
+ ExpandedResults?: QueryResultItem[]
595
+ }
596
+ }
597
+
598
+ export interface FacetResult {
599
+ DocumentAttributeKey?: string
600
+ DocumentAttributeValueType?: 'STRING_VALUE' | 'STRING_LIST_VALUE' | 'LONG_VALUE' | 'DATE_VALUE'
601
+ DocumentAttributeValueCountPairs?: Array<{
602
+ DocumentAttributeValue?: {
603
+ StringValue?: string
604
+ StringListValue?: string[]
605
+ LongValue?: number
606
+ DateValue?: string
607
+ }
608
+ Count?: number
609
+ FacetResults?: FacetResult[]
610
+ }>
611
+ }
612
+
613
+ export interface QueryCommandOutput {
614
+ QueryId?: string
615
+ ResultItems?: QueryResultItem[]
616
+ FacetResults?: FacetResult[]
617
+ TotalNumberOfResults?: number
618
+ Warnings?: Array<{
619
+ Message?: string
620
+ Code?: 'QUERY_LANGUAGE_INVALID_SYNTAX'
621
+ }>
622
+ SpellCorrectedQueries?: Array<{
623
+ SuggestedQueryText?: string
624
+ Corrections?: Array<{
625
+ BeginOffset?: number
626
+ EndOffset?: number
627
+ Term?: string
628
+ CorrectedTerm?: string
629
+ }>
630
+ }>
631
+ FeaturedResultsItems?: Array<{
632
+ Id?: string
633
+ Type?: 'DOCUMENT' | 'QUESTION_ANSWER' | 'ANSWER'
634
+ AdditionalAttributes?: Array<{
635
+ Key?: string
636
+ ValueType?: string
637
+ Value?: Record<string, unknown>
638
+ }>
639
+ DocumentId?: string
640
+ DocumentTitle?: {
641
+ Text?: string
642
+ Highlights?: Array<{
643
+ BeginOffset?: number
644
+ EndOffset?: number
645
+ TopAnswer?: boolean
646
+ Type?: string
647
+ }>
648
+ }
649
+ DocumentExcerpt?: {
650
+ Text?: string
651
+ Highlights?: Array<{
652
+ BeginOffset?: number
653
+ EndOffset?: number
654
+ TopAnswer?: boolean
655
+ Type?: string
656
+ }>
657
+ }
658
+ DocumentURI?: string
659
+ DocumentAttributes?: Array<{
660
+ Key?: string
661
+ Value?: Record<string, unknown>
662
+ }>
663
+ FeedbackToken?: string
664
+ }>
665
+ }
666
+
667
+ export interface RetrieveCommandInput {
668
+ IndexId: string
669
+ QueryText: string
670
+ AttributeFilter?: QueryCommandInput['AttributeFilter']
671
+ RequestedDocumentAttributes?: string[]
672
+ DocumentRelevanceOverrideConfigurations?: QueryCommandInput['DocumentRelevanceOverrideConfigurations']
673
+ PageNumber?: number
674
+ PageSize?: number
675
+ UserContext?: QueryCommandInput['UserContext']
676
+ }
677
+
678
+ export interface RetrieveResultItem {
679
+ Id?: string
680
+ DocumentId?: string
681
+ DocumentTitle?: string
682
+ Content?: string
683
+ DocumentURI?: string
684
+ DocumentAttributes?: Array<{
685
+ Key?: string
686
+ Value?: {
687
+ StringValue?: string
688
+ StringListValue?: string[]
689
+ LongValue?: number
690
+ DateValue?: string
691
+ }
692
+ }>
693
+ ScoreAttributes?: {
694
+ ScoreConfidence?: 'VERY_HIGH' | 'HIGH' | 'MEDIUM' | 'LOW' | 'NOT_AVAILABLE'
695
+ }
696
+ }
697
+
698
+ export interface RetrieveCommandOutput {
699
+ QueryId?: string
700
+ ResultItems?: RetrieveResultItem[]
701
+ }
702
+
703
+ export interface BatchPutDocumentCommandInput {
704
+ IndexId: string
705
+ RoleArn?: string
706
+ Documents: Array<{
707
+ Id: string
708
+ Title?: string
709
+ Blob?: Uint8Array
710
+ S3Path?: {
711
+ Bucket: string
712
+ Key: string
713
+ }
714
+ Attributes?: Array<{
715
+ Key: string
716
+ Value: {
717
+ StringValue?: string
718
+ StringListValue?: string[]
719
+ LongValue?: number
720
+ DateValue?: string
721
+ }
722
+ }>
723
+ AccessControlList?: Array<{
724
+ Name: string
725
+ Type: 'USER' | 'GROUP'
726
+ Access: 'ALLOW' | 'DENY'
727
+ DataSourceId?: string
728
+ }>
729
+ HierarchicalAccessControlList?: Array<{
730
+ PrincipalList: Array<{
731
+ Name: string
732
+ Type: 'USER' | 'GROUP'
733
+ Access: 'ALLOW' | 'DENY'
734
+ DataSourceId?: string
735
+ }>
736
+ }>
737
+ ContentType?: 'PDF' | 'HTML' | 'MS_WORD' | 'PLAIN_TEXT' | 'PPT' | 'RTF' | 'XML' | 'XSLT' | 'MS_EXCEL' | 'CSV' | 'JSON' | 'MD'
738
+ AccessControlConfigurationId?: string
739
+ }>
740
+ CustomDocumentEnrichmentConfiguration?: CreateDataSourceCommandInput['CustomDocumentEnrichmentConfiguration']
741
+ }
742
+
743
+ export interface BatchPutDocumentCommandOutput {
744
+ FailedDocuments?: Array<{
745
+ Id?: string
746
+ ErrorCode?: 'InternalError' | 'InvalidRequest'
747
+ ErrorMessage?: string
748
+ }>
749
+ }
750
+
751
+ export interface BatchDeleteDocumentCommandInput {
752
+ IndexId: string
753
+ DocumentIdList: string[]
754
+ DataSourceSyncJobMetricTarget?: {
755
+ DataSourceId: string
756
+ DataSourceSyncJobId?: string
757
+ }
758
+ }
759
+
760
+ export interface BatchDeleteDocumentCommandOutput {
761
+ FailedDocuments?: Array<{
762
+ Id?: string
763
+ ErrorCode?: 'InternalError' | 'InvalidRequest'
764
+ ErrorMessage?: string
765
+ }>
766
+ }
767
+
768
+ // ============================================================================
769
+ // Kendra Client
770
+ // ============================================================================
771
+
772
+ export class KendraClient {
773
+ private client: AWSClient
774
+ private region: string
775
+
776
+ constructor(region: string = 'us-east-1') {
777
+ this.region = region
778
+ this.client = new AWSClient()
779
+ }
780
+
781
+ private async request<T>(action: string, params: Record<string, unknown>): Promise<T> {
782
+ return this.client.request({
783
+ service: 'kendra',
784
+ region: this.region,
785
+ method: 'POST',
786
+ path: '/',
787
+ headers: {
788
+ 'Content-Type': 'application/x-amz-json-1.1',
789
+ 'X-Amz-Target': `AWSKendraFrontendService.${action}`,
790
+ },
791
+ body: JSON.stringify(params),
792
+ })
793
+ }
794
+
795
+ // -------------------------------------------------------------------------
796
+ // Index Management
797
+ // -------------------------------------------------------------------------
798
+
799
+ async createIndex(params: CreateIndexCommandInput): Promise<CreateIndexCommandOutput> {
800
+ return this.request('CreateIndex', params as unknown as Record<string, unknown>)
801
+ }
802
+
803
+ async describeIndex(params: DescribeIndexCommandInput): Promise<DescribeIndexCommandOutput> {
804
+ return this.request('DescribeIndex', params as unknown as Record<string, unknown>)
805
+ }
806
+
807
+ async listIndices(params?: ListIndicesCommandInput): Promise<ListIndicesCommandOutput> {
808
+ return this.request('ListIndices', (params || {}) as unknown as Record<string, unknown>)
809
+ }
810
+
811
+ async deleteIndex(params: DeleteIndexCommandInput): Promise<DeleteIndexCommandOutput> {
812
+ return this.request('DeleteIndex', params as unknown as Record<string, unknown>)
813
+ }
814
+
815
+ // -------------------------------------------------------------------------
816
+ // Data Source Management
817
+ // -------------------------------------------------------------------------
818
+
819
+ async createDataSource(params: CreateDataSourceCommandInput): Promise<CreateDataSourceCommandOutput> {
820
+ return this.request('CreateDataSource', params as unknown as Record<string, unknown>)
821
+ }
822
+
823
+ async describeDataSource(params: DescribeDataSourceCommandInput): Promise<DescribeDataSourceCommandOutput> {
824
+ return this.request('DescribeDataSource', params as unknown as Record<string, unknown>)
825
+ }
826
+
827
+ async listDataSources(params: ListDataSourcesCommandInput): Promise<ListDataSourcesCommandOutput> {
828
+ return this.request('ListDataSources', params as unknown as Record<string, unknown>)
829
+ }
830
+
831
+ async startDataSourceSyncJob(params: StartDataSourceSyncJobCommandInput): Promise<StartDataSourceSyncJobCommandOutput> {
832
+ return this.request('StartDataSourceSyncJob', params as unknown as Record<string, unknown>)
833
+ }
834
+
835
+ async stopDataSourceSyncJob(params: StopDataSourceSyncJobCommandInput): Promise<StopDataSourceSyncJobCommandOutput> {
836
+ return this.request('StopDataSourceSyncJob', params as unknown as Record<string, unknown>)
837
+ }
838
+
839
+ // -------------------------------------------------------------------------
840
+ // Search
841
+ // -------------------------------------------------------------------------
842
+
843
+ async query(params: QueryCommandInput): Promise<QueryCommandOutput> {
844
+ return this.request('Query', params as unknown as Record<string, unknown>)
845
+ }
846
+
847
+ async retrieve(params: RetrieveCommandInput): Promise<RetrieveCommandOutput> {
848
+ return this.request('Retrieve', params as unknown as Record<string, unknown>)
849
+ }
850
+
851
+ // -------------------------------------------------------------------------
852
+ // Document Management
853
+ // -------------------------------------------------------------------------
854
+
855
+ async batchPutDocument(params: BatchPutDocumentCommandInput): Promise<BatchPutDocumentCommandOutput> {
856
+ return this.request('BatchPutDocument', params as unknown as Record<string, unknown>)
857
+ }
858
+
859
+ async batchDeleteDocument(params: BatchDeleteDocumentCommandInput): Promise<BatchDeleteDocumentCommandOutput> {
860
+ return this.request('BatchDeleteDocument', params as unknown as Record<string, unknown>)
861
+ }
862
+
863
+ // -------------------------------------------------------------------------
864
+ // Convenience Methods
865
+ // -------------------------------------------------------------------------
866
+
867
+ /**
868
+ * Simple search query
869
+ */
870
+ async search(indexId: string, queryText: string, options?: {
871
+ pageSize?: number
872
+ pageNumber?: number
873
+ attributeFilter?: QueryCommandInput['AttributeFilter']
874
+ }): Promise<QueryResultItem[]> {
875
+ const result = await this.query({
876
+ IndexId: indexId,
877
+ QueryText: queryText,
878
+ PageSize: options?.pageSize,
879
+ PageNumber: options?.pageNumber,
880
+ AttributeFilter: options?.attributeFilter,
881
+ })
882
+ return result.ResultItems || []
883
+ }
884
+
885
+ /**
886
+ * Retrieve documents (for RAG)
887
+ */
888
+ async retrieveDocuments(indexId: string, queryText: string, options?: {
889
+ pageSize?: number
890
+ pageNumber?: number
891
+ }): Promise<RetrieveResultItem[]> {
892
+ const result = await this.retrieve({
893
+ IndexId: indexId,
894
+ QueryText: queryText,
895
+ PageSize: options?.pageSize,
896
+ PageNumber: options?.pageNumber,
897
+ })
898
+ return result.ResultItems || []
899
+ }
900
+
901
+ /**
902
+ * Add a text document to the index
903
+ */
904
+ async addDocument(indexId: string, document: {
905
+ id: string
906
+ title?: string
907
+ content: string
908
+ attributes?: Record<string, string | string[] | number>
909
+ }): Promise<void> {
910
+ const attributes = document.attributes
911
+ ? Object.entries(document.attributes).map(([key, value]) => ({
912
+ Key: key,
913
+ Value: typeof value === 'number'
914
+ ? { LongValue: value }
915
+ : Array.isArray(value)
916
+ ? { StringListValue: value }
917
+ : { StringValue: value },
918
+ }))
919
+ : undefined
920
+
921
+ const result = await this.batchPutDocument({
922
+ IndexId: indexId,
923
+ Documents: [
924
+ {
925
+ Id: document.id,
926
+ Title: document.title,
927
+ Blob: new TextEncoder().encode(document.content),
928
+ ContentType: 'PLAIN_TEXT',
929
+ Attributes: attributes,
930
+ },
931
+ ],
932
+ })
933
+
934
+ if (result.FailedDocuments?.length) {
935
+ throw new Error(`Failed to add document: ${result.FailedDocuments[0].ErrorMessage}`)
936
+ }
937
+ }
938
+
939
+ /**
940
+ * Add multiple documents
941
+ */
942
+ async addDocuments(indexId: string, documents: Array<{
943
+ id: string
944
+ title?: string
945
+ content: string
946
+ attributes?: Record<string, string | string[] | number>
947
+ }>): Promise<{ succeeded: number; failed: Array<{ id: string; error: string }> }> {
948
+ const docs = documents.map(doc => {
949
+ const attributes = doc.attributes
950
+ ? Object.entries(doc.attributes).map(([key, value]) => ({
951
+ Key: key,
952
+ Value: typeof value === 'number'
953
+ ? { LongValue: value }
954
+ : Array.isArray(value)
955
+ ? { StringListValue: value }
956
+ : { StringValue: value },
957
+ }))
958
+ : undefined
959
+
960
+ return {
961
+ Id: doc.id,
962
+ Title: doc.title,
963
+ Blob: new TextEncoder().encode(doc.content),
964
+ ContentType: 'PLAIN_TEXT' as const,
965
+ Attributes: attributes,
966
+ }
967
+ })
968
+
969
+ const result = await this.batchPutDocument({
970
+ IndexId: indexId,
971
+ Documents: docs,
972
+ })
973
+
974
+ const failed = result.FailedDocuments?.map(f => ({
975
+ id: f.Id || 'unknown',
976
+ error: f.ErrorMessage || 'Unknown error',
977
+ })) || []
978
+
979
+ return {
980
+ succeeded: documents.length - failed.length,
981
+ failed,
982
+ }
983
+ }
984
+
985
+ /**
986
+ * Delete documents
987
+ */
988
+ async deleteDocuments(indexId: string, documentIds: string[]): Promise<void> {
989
+ const result = await this.batchDeleteDocument({
990
+ IndexId: indexId,
991
+ DocumentIdList: documentIds,
992
+ })
993
+
994
+ if (result.FailedDocuments?.length) {
995
+ throw new Error(`Failed to delete documents: ${result.FailedDocuments.map(f => f.Id).join(', ')}`)
996
+ }
997
+ }
998
+
999
+ /**
1000
+ * Wait for index to be active
1001
+ */
1002
+ async waitForIndex(
1003
+ indexId: string,
1004
+ options?: { maxWaitMs?: number; pollIntervalMs?: number },
1005
+ ): Promise<Index> {
1006
+ const maxWaitMs = options?.maxWaitMs ?? 3600000 // 1 hour
1007
+ const pollIntervalMs = options?.pollIntervalMs ?? 30000
1008
+ const startTime = Date.now()
1009
+
1010
+ while (Date.now() - startTime < maxWaitMs) {
1011
+ const result = await this.describeIndex({ Id: indexId })
1012
+
1013
+ if (result.Status === 'ACTIVE') {
1014
+ return result as Index
1015
+ }
1016
+ if (result.Status === 'FAILED') {
1017
+ throw new Error(`Index creation failed: ${result.ErrorMessage}`)
1018
+ }
1019
+
1020
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs))
1021
+ }
1022
+
1023
+ throw new Error(`Timeout waiting for index ${indexId}`)
1024
+ }
1025
+
1026
+ /**
1027
+ * Wait for data source to be active
1028
+ */
1029
+ async waitForDataSource(
1030
+ indexId: string,
1031
+ dataSourceId: string,
1032
+ options?: { maxWaitMs?: number; pollIntervalMs?: number },
1033
+ ): Promise<DataSource> {
1034
+ const maxWaitMs = options?.maxWaitMs ?? 1800000 // 30 minutes
1035
+ const pollIntervalMs = options?.pollIntervalMs ?? 30000
1036
+ const startTime = Date.now()
1037
+
1038
+ while (Date.now() - startTime < maxWaitMs) {
1039
+ const result = await this.describeDataSource({
1040
+ Id: dataSourceId,
1041
+ IndexId: indexId,
1042
+ })
1043
+
1044
+ if (result.Status === 'ACTIVE') {
1045
+ return result
1046
+ }
1047
+ if (result.Status === 'FAILED') {
1048
+ throw new Error(`Data source creation failed: ${result.ErrorMessage}`)
1049
+ }
1050
+
1051
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs))
1052
+ }
1053
+
1054
+ throw new Error(`Timeout waiting for data source ${dataSourceId}`)
1055
+ }
1056
+ }
1057
+
1058
+ // ============================================================================
1059
+ // Helper Functions
1060
+ // ============================================================================
1061
+
1062
+ /**
1063
+ * Quick search
1064
+ */
1065
+ export async function search(
1066
+ indexId: string,
1067
+ query: string,
1068
+ options?: { region?: string; pageSize?: number },
1069
+ ): Promise<Array<{ title: string; excerpt: string; uri: string; score: string }>> {
1070
+ const client = new KendraClient(options?.region || 'us-east-1')
1071
+ const results = await client.search(indexId, query, { pageSize: options?.pageSize })
1072
+
1073
+ return results.map(r => ({
1074
+ title: r.DocumentTitle?.Text || '',
1075
+ excerpt: r.DocumentExcerpt?.Text || '',
1076
+ uri: r.DocumentURI || '',
1077
+ score: r.ScoreAttributes?.ScoreConfidence || 'NOT_AVAILABLE',
1078
+ }))
1079
+ }
1080
+
1081
+ /**
1082
+ * Retrieve for RAG
1083
+ */
1084
+ export async function retrieveForRag(
1085
+ indexId: string,
1086
+ query: string,
1087
+ options?: { region?: string; pageSize?: number },
1088
+ ): Promise<Array<{ content: string; uri: string; score: string }>> {
1089
+ const client = new KendraClient(options?.region || 'us-east-1')
1090
+ const results = await client.retrieveDocuments(indexId, query, { pageSize: options?.pageSize })
1091
+
1092
+ return results.map(r => ({
1093
+ content: r.Content || '',
1094
+ uri: r.DocumentURI || '',
1095
+ score: r.ScoreAttributes?.ScoreConfidence || 'NOT_AVAILABLE',
1096
+ }))
1097
+ }