@stacksjs/ts-cloud 0.1.9 → 0.1.14

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 (150) hide show
  1. package/README.md +39 -377
  2. package/dist/bin/cli.js +1047 -424
  3. package/dist/index.d.ts +36 -3
  4. package/dist/index.js +76430 -7096
  5. package/package.json +7 -8
  6. package/dist/aws/acm.d.ts +0 -129
  7. package/dist/aws/application-autoscaling.d.ts +0 -282
  8. package/dist/aws/bedrock.d.ts +0 -2292
  9. package/dist/aws/client.d.ts +0 -79
  10. package/dist/aws/cloudformation.d.ts +0 -105
  11. package/dist/aws/cloudfront.d.ts +0 -265
  12. package/dist/aws/cloudwatch-logs.d.ts +0 -48
  13. package/dist/aws/comprehend.d.ts +0 -505
  14. package/dist/aws/connect.d.ts +0 -377
  15. package/dist/aws/deploy-imap.d.ts +0 -14
  16. package/dist/aws/dynamodb.d.ts +0 -176
  17. package/dist/aws/ec2.d.ts +0 -272
  18. package/dist/aws/ecr.d.ts +0 -149
  19. package/dist/aws/ecs.d.ts +0 -162
  20. package/dist/aws/elasticache.d.ts +0 -71
  21. package/dist/aws/elbv2.d.ts +0 -248
  22. package/dist/aws/email.d.ts +0 -175
  23. package/dist/aws/eventbridge.d.ts +0 -142
  24. package/dist/aws/iam.d.ts +0 -638
  25. package/dist/aws/imap-server.d.ts +0 -119
  26. package/dist/aws/index.d.ts +0 -192
  27. package/dist/aws/kendra.d.ts +0 -782
  28. package/dist/aws/lambda.d.ts +0 -232
  29. package/dist/aws/opensearch.d.ts +0 -87
  30. package/dist/aws/personalize.d.ts +0 -516
  31. package/dist/aws/polly.d.ts +0 -214
  32. package/dist/aws/rds.d.ts +0 -240
  33. package/dist/aws/rekognition.d.ts +0 -543
  34. package/dist/aws/route53-domains.d.ts +0 -113
  35. package/dist/aws/route53.d.ts +0 -215
  36. package/dist/aws/s3.d.ts +0 -212
  37. package/dist/aws/scheduler.d.ts +0 -140
  38. package/dist/aws/secrets-manager.d.ts +0 -170
  39. package/dist/aws/ses.d.ts +0 -288
  40. package/dist/aws/setup-phone.d.ts +0 -0
  41. package/dist/aws/setup-sms.d.ts +0 -115
  42. package/dist/aws/sms.d.ts +0 -304
  43. package/dist/aws/smtp-server.d.ts +0 -61
  44. package/dist/aws/sns.d.ts +0 -117
  45. package/dist/aws/sqs.d.ts +0 -65
  46. package/dist/aws/ssm.d.ts +0 -179
  47. package/dist/aws/sts.d.ts +0 -15
  48. package/dist/aws/support.d.ts +0 -104
  49. package/dist/aws/test-imap.d.ts +0 -0
  50. package/dist/aws/textract.d.ts +0 -403
  51. package/dist/aws/transcribe.d.ts +0 -60
  52. package/dist/aws/translate.d.ts +0 -358
  53. package/dist/aws/voice.d.ts +0 -219
  54. package/dist/config.d.ts +0 -7
  55. package/dist/deploy/index.d.ts +0 -2
  56. package/dist/deploy/static-site-external-dns.d.ts +0 -51
  57. package/dist/deploy/static-site.d.ts +0 -71
  58. package/dist/dns/cloudflare.d.ts +0 -52
  59. package/dist/dns/godaddy.d.ts +0 -38
  60. package/dist/dns/index.d.ts +0 -45
  61. package/dist/dns/porkbun.d.ts +0 -18
  62. package/dist/dns/route53-adapter.d.ts +0 -38
  63. package/dist/dns/types.d.ts +0 -77
  64. package/dist/dns/validator.d.ts +0 -78
  65. package/dist/generators/index.d.ts +0 -1
  66. package/dist/generators/infrastructure.d.ts +0 -30
  67. package/dist/push/apns.d.ts +0 -60
  68. package/dist/push/fcm.d.ts +0 -117
  69. package/dist/push/index.d.ts +0 -14
  70. package/dist/security/pre-deploy-scanner.d.ts +0 -69
  71. package/dist/ssl/acme-client.d.ts +0 -67
  72. package/dist/ssl/index.d.ts +0 -2
  73. package/dist/ssl/letsencrypt.d.ts +0 -48
  74. package/dist/types.d.ts +0 -1
  75. package/dist/utils/cli.d.ts +0 -123
  76. package/dist/validation/index.d.ts +0 -1
  77. package/dist/validation/template.d.ts +0 -23
  78. package/src/aws/acm.ts +0 -768
  79. package/src/aws/application-autoscaling.ts +0 -845
  80. package/src/aws/bedrock.ts +0 -4074
  81. package/src/aws/client.ts +0 -891
  82. package/src/aws/cloudformation.ts +0 -896
  83. package/src/aws/cloudfront.ts +0 -1531
  84. package/src/aws/cloudwatch-logs.ts +0 -154
  85. package/src/aws/comprehend.ts +0 -839
  86. package/src/aws/connect.ts +0 -1056
  87. package/src/aws/deploy-imap.ts +0 -384
  88. package/src/aws/dynamodb.ts +0 -340
  89. package/src/aws/ec2.ts +0 -1385
  90. package/src/aws/ecr.ts +0 -621
  91. package/src/aws/ecs.ts +0 -615
  92. package/src/aws/elasticache.ts +0 -301
  93. package/src/aws/elbv2.ts +0 -942
  94. package/src/aws/email.ts +0 -928
  95. package/src/aws/eventbridge.ts +0 -248
  96. package/src/aws/iam.ts +0 -1689
  97. package/src/aws/imap-server.ts +0 -2100
  98. package/src/aws/index.ts +0 -213
  99. package/src/aws/kendra.ts +0 -1097
  100. package/src/aws/lambda.ts +0 -786
  101. package/src/aws/opensearch.ts +0 -158
  102. package/src/aws/personalize.ts +0 -977
  103. package/src/aws/polly.ts +0 -559
  104. package/src/aws/rds.ts +0 -888
  105. package/src/aws/rekognition.ts +0 -846
  106. package/src/aws/route53-domains.ts +0 -359
  107. package/src/aws/route53.ts +0 -1046
  108. package/src/aws/s3.ts +0 -2334
  109. package/src/aws/scheduler.ts +0 -571
  110. package/src/aws/secrets-manager.ts +0 -769
  111. package/src/aws/ses.ts +0 -1081
  112. package/src/aws/setup-phone.ts +0 -104
  113. package/src/aws/setup-sms.ts +0 -580
  114. package/src/aws/sms.ts +0 -1735
  115. package/src/aws/smtp-server.ts +0 -531
  116. package/src/aws/sns.ts +0 -758
  117. package/src/aws/sqs.ts +0 -382
  118. package/src/aws/ssm.ts +0 -807
  119. package/src/aws/sts.ts +0 -92
  120. package/src/aws/support.ts +0 -391
  121. package/src/aws/test-imap.ts +0 -86
  122. package/src/aws/textract.ts +0 -780
  123. package/src/aws/transcribe.ts +0 -108
  124. package/src/aws/translate.ts +0 -641
  125. package/src/aws/voice.ts +0 -1379
  126. package/src/config.ts +0 -35
  127. package/src/deploy/index.ts +0 -7
  128. package/src/deploy/static-site-external-dns.ts +0 -945
  129. package/src/deploy/static-site.ts +0 -1175
  130. package/src/dns/cloudflare.ts +0 -548
  131. package/src/dns/godaddy.ts +0 -412
  132. package/src/dns/index.ts +0 -205
  133. package/src/dns/porkbun.ts +0 -362
  134. package/src/dns/route53-adapter.ts +0 -414
  135. package/src/dns/types.ts +0 -119
  136. package/src/dns/validator.ts +0 -369
  137. package/src/generators/index.ts +0 -5
  138. package/src/generators/infrastructure.ts +0 -1660
  139. package/src/index.ts +0 -163
  140. package/src/push/apns.ts +0 -452
  141. package/src/push/fcm.ts +0 -506
  142. package/src/push/index.ts +0 -58
  143. package/src/security/pre-deploy-scanner.ts +0 -655
  144. package/src/ssl/acme-client.ts +0 -478
  145. package/src/ssl/index.ts +0 -7
  146. package/src/ssl/letsencrypt.ts +0 -747
  147. package/src/types.ts +0 -2
  148. package/src/utils/cli.ts +0 -398
  149. package/src/validation/index.ts +0 -5
  150. package/src/validation/template.ts +0 -405
@@ -1,548 +0,0 @@
1
- /**
2
- * Cloudflare DNS Provider
3
- * API documentation: https://developers.cloudflare.com/api/resources/dns/subresources/records/
4
- */
5
-
6
- import type {
7
- CreateRecordResult,
8
- DeleteRecordResult,
9
- DnsProvider,
10
- DnsRecord,
11
- DnsRecordResult,
12
- DnsRecordType,
13
- ListRecordsResult,
14
- } from './types'
15
-
16
- const CLOUDFLARE_API_URL = 'https://api.cloudflare.com/client/v4'
17
-
18
- interface CloudflareApiResponse<T = any> {
19
- success: boolean
20
- errors: Array<{ code: number, message: string }>
21
- messages: string[]
22
- result: T
23
- result_info?: {
24
- page: number
25
- per_page: number
26
- total_pages: number
27
- count: number
28
- total_count: number
29
- }
30
- }
31
-
32
- interface CloudflareRecord {
33
- id: string
34
- zone_id: string
35
- zone_name: string
36
- name: string
37
- type: string
38
- content: string
39
- proxiable: boolean
40
- proxied: boolean
41
- ttl: number
42
- locked: boolean
43
- meta: Record<string, any>
44
- comment?: string
45
- tags?: string[]
46
- created_on: string
47
- modified_on: string
48
- priority?: number
49
- }
50
-
51
- interface CloudflareZone {
52
- id: string
53
- name: string
54
- status: string
55
- paused: boolean
56
- type: string
57
- development_mode: number
58
- name_servers: string[]
59
- }
60
-
61
- export class CloudflareProvider implements DnsProvider {
62
- readonly name = 'cloudflare'
63
- private apiToken: string
64
- private zoneCache: Map<string, string> = new Map()
65
-
66
- constructor(apiToken: string) {
67
- this.apiToken = apiToken
68
- }
69
-
70
- /**
71
- * Make an authenticated API request to Cloudflare
72
- */
73
- private async request<T>(
74
- method: string,
75
- endpoint: string,
76
- body?: any,
77
- ): Promise<CloudflareApiResponse<T>> {
78
- const url = `${CLOUDFLARE_API_URL}${endpoint}`
79
-
80
- const headers: Record<string, string> = {
81
- 'Authorization': `Bearer ${this.apiToken}`,
82
- 'Content-Type': 'application/json',
83
- }
84
-
85
- const options: RequestInit = {
86
- method,
87
- headers,
88
- }
89
-
90
- if (body) {
91
- options.body = JSON.stringify(body)
92
- }
93
-
94
- const response = await fetch(url, options)
95
- const data = await response.json() as CloudflareApiResponse<T>
96
-
97
- if (!data.success) {
98
- const errorMessages = data.errors.map(e => e.message).join(', ')
99
- throw new Error(`Cloudflare API error: ${errorMessages}`)
100
- }
101
-
102
- return data
103
- }
104
-
105
- /**
106
- * Get the root domain from a full domain name
107
- * e.g., "api.example.com" -> "example.com"
108
- */
109
- private getRootDomain(domain: string): string {
110
- const parts = domain.replace(/\.$/, '').split('.')
111
- if (parts.length >= 2) {
112
- return parts.slice(-2).join('.')
113
- }
114
- return domain
115
- }
116
-
117
- /**
118
- * Get Zone ID for a domain (with caching)
119
- */
120
- private async getZoneId(domain: string): Promise<string> {
121
- const rootDomain = this.getRootDomain(domain)
122
-
123
- // Check cache first
124
- const cached = this.zoneCache.get(rootDomain)
125
- if (cached) {
126
- return cached
127
- }
128
-
129
- // Look up zone by name
130
- const response = await this.request<CloudflareZone[]>(
131
- 'GET',
132
- `/zones?name=${encodeURIComponent(rootDomain)}`,
133
- )
134
-
135
- if (!response.result || response.result.length === 0) {
136
- throw new Error(`Zone not found for domain: ${rootDomain}`)
137
- }
138
-
139
- const zoneId = response.result[0].id
140
- this.zoneCache.set(rootDomain, zoneId)
141
- return zoneId
142
- }
143
-
144
- /**
145
- * Get the full record name
146
- * Cloudflare stores records with full domain names
147
- */
148
- private getFullRecordName(name: string, domain: string): string {
149
- const rootDomain = this.getRootDomain(domain)
150
- const cleanName = name.replace(/\.$/, '')
151
-
152
- // If name is empty or equals root domain, return root domain
153
- if (!cleanName || cleanName === rootDomain || cleanName === '@') {
154
- return rootDomain
155
- }
156
-
157
- // If name already ends with root domain, return as-is
158
- if (cleanName.endsWith(`.${rootDomain}`)) {
159
- return cleanName
160
- }
161
-
162
- // Otherwise, append root domain
163
- return `${cleanName}.${rootDomain}`
164
- }
165
-
166
- /**
167
- * Convert DnsRecord to Cloudflare record format
168
- */
169
- private toCloudflareRecord(record: DnsRecord, domain: string): Partial<CloudflareRecord> {
170
- const cfRecord: Partial<CloudflareRecord> = {
171
- type: record.type,
172
- name: this.getFullRecordName(record.name, domain),
173
- content: record.content || record.value || '',
174
- ttl: record.ttl || 1, // 1 = automatic in Cloudflare
175
- }
176
-
177
- // MX records require priority
178
- if (record.type === 'MX' && record.priority !== undefined) {
179
- cfRecord.priority = record.priority
180
- }
181
-
182
- // SRV records have special format
183
- if (record.type === 'SRV') {
184
- if (record.priority !== undefined) {
185
- cfRecord.priority = record.priority
186
- }
187
- }
188
-
189
- return cfRecord
190
- }
191
-
192
- /**
193
- * Convert Cloudflare record to DnsRecordResult format
194
- */
195
- private fromCloudflareRecord(record: CloudflareRecord): DnsRecordResult {
196
- return {
197
- id: record.id,
198
- name: record.name,
199
- type: record.type as DnsRecordType,
200
- content: record.content,
201
- ttl: record.ttl,
202
- priority: record.priority,
203
- }
204
- }
205
-
206
- async createRecord(domain: string, record: DnsRecord): Promise<CreateRecordResult> {
207
- try {
208
- const zoneId = await this.getZoneId(domain)
209
- const cfRecord = this.toCloudflareRecord(record, domain)
210
-
211
- const response = await this.request<CloudflareRecord>(
212
- 'POST',
213
- `/zones/${zoneId}/dns_records`,
214
- cfRecord,
215
- )
216
-
217
- return {
218
- success: true,
219
- id: response.result.id,
220
- message: 'Record created successfully',
221
- }
222
- }
223
- catch (error) {
224
- return {
225
- success: false,
226
- message: error instanceof Error ? error.message : 'Unknown error',
227
- }
228
- }
229
- }
230
-
231
- async upsertRecord(domain: string, record: DnsRecord): Promise<CreateRecordResult> {
232
- try {
233
- const zoneId = await this.getZoneId(domain)
234
- const fullName = this.getFullRecordName(record.name, domain)
235
-
236
- // First, try to find existing record
237
- const existingResponse = await this.request<CloudflareRecord[]>(
238
- 'GET',
239
- `/zones/${zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(fullName)}`,
240
- )
241
-
242
- const cfRecord = this.toCloudflareRecord(record, domain)
243
-
244
- if (existingResponse.result && existingResponse.result.length > 0) {
245
- // Update existing record
246
- const existingId = existingResponse.result[0].id
247
- const response = await this.request<CloudflareRecord>(
248
- 'PUT',
249
- `/zones/${zoneId}/dns_records/${existingId}`,
250
- cfRecord,
251
- )
252
-
253
- return {
254
- success: true,
255
- id: response.result.id,
256
- message: 'Record updated successfully',
257
- }
258
- }
259
-
260
- // Create new record
261
- const response = await this.request<CloudflareRecord>(
262
- 'POST',
263
- `/zones/${zoneId}/dns_records`,
264
- cfRecord,
265
- )
266
-
267
- return {
268
- success: true,
269
- id: response.result.id,
270
- message: 'Record created successfully',
271
- }
272
- }
273
- catch (error) {
274
- // If upsert fails, try create
275
- return this.createRecord(domain, record)
276
- }
277
- }
278
-
279
- async deleteRecord(domain: string, record: DnsRecord): Promise<DeleteRecordResult> {
280
- try {
281
- const zoneId = await this.getZoneId(domain)
282
- const fullName = this.getFullRecordName(record.name, domain)
283
-
284
- // Find the record to delete
285
- const existingResponse = await this.request<CloudflareRecord[]>(
286
- 'GET',
287
- `/zones/${zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(fullName)}`,
288
- )
289
-
290
- if (!existingResponse.result || existingResponse.result.length === 0) {
291
- return {
292
- success: false,
293
- message: 'Record not found',
294
- }
295
- }
296
-
297
- // Find matching record by content
298
- const matchingRecord = existingResponse.result.find(
299
- r => r.content === record.content,
300
- )
301
-
302
- if (!matchingRecord) {
303
- return {
304
- success: false,
305
- message: 'Record with matching content not found',
306
- }
307
- }
308
-
309
- await this.request(
310
- 'DELETE',
311
- `/zones/${zoneId}/dns_records/${matchingRecord.id}`,
312
- )
313
-
314
- return {
315
- success: true,
316
- message: 'Record deleted successfully',
317
- }
318
- }
319
- catch (error) {
320
- return {
321
- success: false,
322
- message: error instanceof Error ? error.message : 'Unknown error',
323
- }
324
- }
325
- }
326
-
327
- async listRecords(domain: string, type?: DnsRecordType): Promise<ListRecordsResult> {
328
- try {
329
- const zoneId = await this.getZoneId(domain)
330
-
331
- let endpoint = `/zones/${zoneId}/dns_records?per_page=100`
332
- if (type) {
333
- endpoint += `&type=${type}`
334
- }
335
-
336
- const allRecords: CloudflareRecord[] = []
337
- let page = 1
338
- let hasMore = true
339
-
340
- // Paginate through all records
341
- while (hasMore) {
342
- const response = await this.request<CloudflareRecord[]>(
343
- 'GET',
344
- `${endpoint}&page=${page}`,
345
- )
346
-
347
- allRecords.push(...(response.result || []))
348
-
349
- if (response.result_info) {
350
- hasMore = page < response.result_info.total_pages
351
- page++
352
- }
353
- else {
354
- hasMore = false
355
- }
356
- }
357
-
358
- return {
359
- success: true,
360
- records: allRecords.map(r => this.fromCloudflareRecord(r)),
361
- }
362
- }
363
- catch (error) {
364
- return {
365
- success: false,
366
- records: [],
367
- message: error instanceof Error ? error.message : 'Unknown error',
368
- }
369
- }
370
- }
371
-
372
- async canManageDomain(domain: string): Promise<boolean> {
373
- try {
374
- await this.getZoneId(domain)
375
- return true
376
- }
377
- catch {
378
- return false
379
- }
380
- }
381
-
382
- /**
383
- * List all domains (zones) managed by this Cloudflare account
384
- */
385
- async listDomains(): Promise<string[]> {
386
- try {
387
- const allZones: CloudflareZone[] = []
388
- let page = 1
389
- let hasMore = true
390
-
391
- while (hasMore) {
392
- const response = await this.request<CloudflareZone[]>(
393
- 'GET',
394
- `/zones?per_page=50&page=${page}`,
395
- )
396
-
397
- allZones.push(...(response.result || []))
398
-
399
- if (response.result_info) {
400
- hasMore = page < response.result_info.total_pages
401
- page++
402
- }
403
- else {
404
- hasMore = false
405
- }
406
- }
407
-
408
- return allZones.map(z => z.name)
409
- }
410
- catch {
411
- return []
412
- }
413
- }
414
-
415
- /**
416
- * Get zone details (Cloudflare-specific)
417
- */
418
- async getZoneDetails(domain: string): Promise<{
419
- id: string
420
- name: string
421
- status: string
422
- nameServers: string[]
423
- paused: boolean
424
- } | null> {
425
- try {
426
- const zoneId = await this.getZoneId(domain)
427
- const response = await this.request<CloudflareZone>(
428
- 'GET',
429
- `/zones/${zoneId}`,
430
- )
431
-
432
- return {
433
- id: response.result.id,
434
- name: response.result.name,
435
- status: response.result.status,
436
- nameServers: response.result.name_servers,
437
- paused: response.result.paused,
438
- }
439
- }
440
- catch {
441
- return null
442
- }
443
- }
444
-
445
- /**
446
- * Purge cache for a domain (Cloudflare-specific)
447
- */
448
- async purgeCache(domain: string, options?: {
449
- purgeEverything?: boolean
450
- files?: string[]
451
- tags?: string[]
452
- hosts?: string[]
453
- }): Promise<boolean> {
454
- try {
455
- const zoneId = await this.getZoneId(domain)
456
-
457
- const body: Record<string, any> = {}
458
-
459
- if (options?.purgeEverything) {
460
- body.purge_everything = true
461
- }
462
- else {
463
- if (options?.files) body.files = options.files
464
- if (options?.tags) body.tags = options.tags
465
- if (options?.hosts) body.hosts = options.hosts
466
- }
467
-
468
- // Default to purge everything if no options specified
469
- if (Object.keys(body).length === 0) {
470
- body.purge_everything = true
471
- }
472
-
473
- await this.request(
474
- 'POST',
475
- `/zones/${zoneId}/purge_cache`,
476
- body,
477
- )
478
-
479
- return true
480
- }
481
- catch {
482
- return false
483
- }
484
- }
485
-
486
- /**
487
- * Get proxy status for a record (Cloudflare-specific)
488
- * Returns whether a record is proxied through Cloudflare
489
- */
490
- async getRecordProxyStatus(domain: string, record: DnsRecord): Promise<boolean | null> {
491
- try {
492
- const zoneId = await this.getZoneId(domain)
493
- const fullName = this.getFullRecordName(record.name, domain)
494
-
495
- const response = await this.request<CloudflareRecord[]>(
496
- 'GET',
497
- `/zones/${zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(fullName)}`,
498
- )
499
-
500
- if (response.result && response.result.length > 0) {
501
- const matchingRecord = response.result.find(r => r.content === record.content)
502
- return matchingRecord?.proxied ?? null
503
- }
504
-
505
- return null
506
- }
507
- catch {
508
- return null
509
- }
510
- }
511
-
512
- /**
513
- * Update proxy status for a record (Cloudflare-specific)
514
- */
515
- async setRecordProxyStatus(domain: string, record: DnsRecord, proxied: boolean): Promise<boolean> {
516
- try {
517
- const zoneId = await this.getZoneId(domain)
518
- const fullName = this.getFullRecordName(record.name, domain)
519
-
520
- // Find the record
521
- const response = await this.request<CloudflareRecord[]>(
522
- 'GET',
523
- `/zones/${zoneId}/dns_records?type=${record.type}&name=${encodeURIComponent(fullName)}`,
524
- )
525
-
526
- if (!response.result || response.result.length === 0) {
527
- return false
528
- }
529
-
530
- const matchingRecord = response.result.find(r => r.content === record.content)
531
- if (!matchingRecord) {
532
- return false
533
- }
534
-
535
- // Update the record with new proxy status
536
- await this.request(
537
- 'PATCH',
538
- `/zones/${zoneId}/dns_records/${matchingRecord.id}`,
539
- { proxied },
540
- )
541
-
542
- return true
543
- }
544
- catch {
545
- return false
546
- }
547
- }
548
- }