@ericminassian/platform-engine 0.3.0 → 0.4.1

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 (98) hide show
  1. package/dist/clients.d.ts +8 -0
  2. package/dist/clients.js +22 -1
  3. package/dist/clients.js.map +1 -1
  4. package/dist/compat.d.ts +21 -9
  5. package/dist/compat.js +27 -7
  6. package/dist/compat.js.map +1 -1
  7. package/dist/drivers/appsync.d.ts +49 -0
  8. package/dist/drivers/appsync.js +155 -0
  9. package/dist/drivers/appsync.js.map +1 -0
  10. package/dist/drivers/cognito.d.ts +9 -3
  11. package/dist/drivers/cognito.js +18 -7
  12. package/dist/drivers/cognito.js.map +1 -1
  13. package/dist/drivers/ecr.d.ts +109 -0
  14. package/dist/drivers/ecr.js +303 -0
  15. package/dist/drivers/ecr.js.map +1 -0
  16. package/dist/drivers/ecs.d.ts +163 -0
  17. package/dist/drivers/ecs.js +447 -0
  18. package/dist/drivers/ecs.js.map +1 -0
  19. package/dist/drivers/events.d.ts +10 -0
  20. package/dist/drivers/events.js +13 -1
  21. package/dist/drivers/events.js.map +1 -1
  22. package/dist/drivers/index.d.ts +5 -0
  23. package/dist/drivers/index.js +5 -0
  24. package/dist/drivers/index.js.map +1 -1
  25. package/dist/drivers/kvs.d.ts +3 -0
  26. package/dist/drivers/kvs.js +14 -7
  27. package/dist/drivers/kvs.js.map +1 -1
  28. package/dist/drivers/lambda.d.ts +22 -0
  29. package/dist/drivers/lambda.js +74 -3
  30. package/dist/drivers/lambda.js.map +1 -1
  31. package/dist/drivers/request-function.d.ts +60 -0
  32. package/dist/drivers/request-function.js +167 -0
  33. package/dist/drivers/request-function.js.map +1 -0
  34. package/dist/drivers/s3.d.ts +5 -0
  35. package/dist/drivers/s3.js +26 -0
  36. package/dist/drivers/s3.js.map +1 -1
  37. package/dist/drivers/scheduler.d.ts +24 -0
  38. package/dist/drivers/scheduler.js +60 -5
  39. package/dist/drivers/scheduler.js.map +1 -1
  40. package/dist/drivers/ses.d.ts +77 -0
  41. package/dist/drivers/ses.js +181 -0
  42. package/dist/drivers/ses.js.map +1 -0
  43. package/dist/drivers/sqs.d.ts +11 -0
  44. package/dist/drivers/sqs.js +67 -1
  45. package/dist/drivers/sqs.js.map +1 -1
  46. package/dist/drivers/web-function.d.ts +11 -3
  47. package/dist/drivers/web-function.js +22 -5
  48. package/dist/drivers/web-function.js.map +1 -1
  49. package/dist/emulator.js.map +1 -1
  50. package/dist/images.d.ts +104 -0
  51. package/dist/images.js +182 -0
  52. package/dist/images.js.map +1 -0
  53. package/dist/index.d.ts +130 -6
  54. package/dist/index.js +11 -2
  55. package/dist/index.js.map +1 -1
  56. package/dist/local.js +222 -7
  57. package/dist/local.js.map +1 -1
  58. package/dist/policy.d.ts +47 -4
  59. package/dist/policy.js +365 -13
  60. package/dist/policy.js.map +1 -1
  61. package/dist/services.d.ts +155 -0
  62. package/dist/services.js +464 -0
  63. package/dist/services.js.map +1 -0
  64. package/dist/stage.d.ts +33 -8
  65. package/dist/stage.js +598 -125
  66. package/dist/stage.js.map +1 -1
  67. package/dist/static.d.ts +1 -1
  68. package/dist/static.js +2 -36
  69. package/dist/static.js.map +1 -1
  70. package/dist/util.d.ts +22 -0
  71. package/dist/util.js +18 -2
  72. package/dist/util.js.map +1 -1
  73. package/package.json +20 -14
  74. package/src/clients.ts +25 -1
  75. package/src/compat.ts +34 -11
  76. package/src/drivers/appsync.ts +220 -0
  77. package/src/drivers/cognito.ts +19 -9
  78. package/src/drivers/ecr.ts +457 -0
  79. package/src/drivers/ecs.ts +661 -0
  80. package/src/drivers/events.ts +29 -2
  81. package/src/drivers/index.ts +5 -0
  82. package/src/drivers/kvs.ts +21 -12
  83. package/src/drivers/lambda.ts +103 -2
  84. package/src/drivers/request-function.ts +295 -0
  85. package/src/drivers/s3.ts +38 -0
  86. package/src/drivers/scheduler.ts +88 -5
  87. package/src/drivers/ses.ts +267 -0
  88. package/src/drivers/sqs.ts +95 -0
  89. package/src/drivers/web-function.ts +29 -9
  90. package/src/emulator.ts +3 -3
  91. package/src/images.ts +254 -0
  92. package/src/index.ts +129 -7
  93. package/src/local.ts +251 -7
  94. package/src/policy.ts +446 -24
  95. package/src/services.ts +663 -0
  96. package/src/stage.ts +753 -140
  97. package/src/static.ts +2 -37
  98. package/src/util.ts +38 -4
package/src/static.ts CHANGED
@@ -1,40 +1,5 @@
1
- /** Content types for static assets served from the sites bucket. */
2
- const TYPES: Record<string, string> = {
3
- html: 'text/html; charset=utf-8',
4
- htm: 'text/html; charset=utf-8',
5
- css: 'text/css; charset=utf-8',
6
- js: 'text/javascript; charset=utf-8',
7
- mjs: 'text/javascript; charset=utf-8',
8
- cjs: 'text/javascript; charset=utf-8',
9
- map: 'application/json; charset=utf-8',
10
- json: 'application/json; charset=utf-8',
11
- webmanifest: 'application/manifest+json',
12
- txt: 'text/plain; charset=utf-8',
13
- xml: 'application/xml; charset=utf-8',
14
- svg: 'image/svg+xml',
15
- png: 'image/png',
16
- jpg: 'image/jpeg',
17
- jpeg: 'image/jpeg',
18
- gif: 'image/gif',
19
- webp: 'image/webp',
20
- avif: 'image/avif',
21
- ico: 'image/x-icon',
22
- woff: 'font/woff',
23
- woff2: 'font/woff2',
24
- ttf: 'font/ttf',
25
- otf: 'font/otf',
26
- wasm: 'application/wasm',
27
- pdf: 'application/pdf',
28
- mp4: 'video/mp4',
29
- webm: 'video/webm',
30
- mp3: 'audio/mpeg',
31
- wav: 'audio/wav',
32
- };
33
-
34
- export function contentTypeFor(path: string): string {
35
- const ext = path.slice(path.lastIndexOf('.') + 1).toLowerCase();
36
- return TYPES[ext] ?? 'application/octet-stream';
37
- }
1
+ // Shared with store files put without a content type.
2
+ export { contentTypeFor } from '@ericminassian/platform-core';
38
3
 
39
4
  export const IMMUTABLE = 'public, max-age=31536000, immutable';
40
5
  export const REVALIDATE = 'public, max-age=0, must-revalidate';
package/src/util.ts CHANGED
@@ -41,6 +41,10 @@ const NOT_FOUND = new Set([
41
41
  'NoSuchCachePolicy',
42
42
  'NoSuchDistribution',
43
43
  'EntityNotFound',
44
+ 'ServiceNotFoundException',
45
+ 'ClusterNotFoundException',
46
+ 'RepositoryNotFoundException',
47
+ 'ImageNotFoundException',
44
48
  ]);
45
49
 
46
50
  export function isNotFound(e: unknown): boolean {
@@ -105,7 +109,7 @@ export async function mapLimit<T, R>(
105
109
  limit: number,
106
110
  fn: (item: T) => Promise<R>,
107
111
  ): Promise<R[]> {
108
- const out: R[] = new Array(items.length);
112
+ const out = Array.from<R>({ length: items.length });
109
113
  let next = 0;
110
114
  const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
111
115
  while (next < items.length) {
@@ -117,6 +121,36 @@ export async function mapLimit<T, R>(
117
121
  return out;
118
122
  }
119
123
 
124
+ export interface RawRequest {
125
+ method: string;
126
+ protocol: string;
127
+ hostname: string;
128
+ port?: number;
129
+ path: string;
130
+ query?: Record<string, string>;
131
+ headers: Record<string, string>;
132
+ body?: string;
133
+ }
134
+
135
+ /**
136
+ * Send a request outside the SDK's operations through a client's own HTTP
137
+ * handler, so it gets the same TLS setup (the emulator's CA) as the client.
138
+ */
139
+ export async function sendRaw(
140
+ client: { config: { requestHandler: unknown } },
141
+ request: RawRequest,
142
+ ): Promise<{ statusCode: number; body: Uint8Array }> {
143
+ const handler = client.config.requestHandler as {
144
+ handle(
145
+ request: RawRequest,
146
+ ): Promise<{ response: { statusCode: number; body: AsyncIterable<Uint8Array> } }>;
147
+ };
148
+ const { response } = await handler.handle(request);
149
+ const chunks: Uint8Array[] = [];
150
+ for await (const c of response.body) chunks.push(c);
151
+ return { statusCode: response.statusCode, body: new Uint8Array(Buffer.concat(chunks)) };
152
+ }
153
+
120
154
  // ------------------------------------------------------------------ tags
121
155
 
122
156
  export function stageTags(app: string, stage: string): Record<string, string> {
@@ -159,15 +193,15 @@ export function policy(...statements: PolicyStatement[]): PolicyDocument {
159
193
  /** Deep-equal for policy documents that may come back URL-encoded from IAM. */
160
194
  export function samePolicy(a: string | PolicyDocument | undefined, b: PolicyDocument): boolean {
161
195
  if (!a) return false;
162
- const parsed = typeof a === 'string' ? JSON.parse(decodeURIComponent(a)) : a;
196
+ const parsed = typeof a === 'string' ? (JSON.parse(decodeURIComponent(a)) as unknown) : a;
163
197
  return canonical(parsed) === canonical(b);
164
198
  }
165
199
 
166
200
  function canonical(v: unknown): string {
167
201
  if (Array.isArray(v)) return `[${v.map(canonical).join(',')}]`;
168
202
  if (v && typeof v === 'object') {
169
- return `{${Object.keys(v as object)
170
- .sort()
203
+ return `{${Object.keys(v)
204
+ .toSorted()
171
205
  .map((k) => `${JSON.stringify(k)}:${canonical((v as Record<string, unknown>)[k])}`)
172
206
  .join(',')}}`;
173
207
  }