wirejs-deploy-amplify-basic 0.0.152-payments → 0.0.154-payments

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.
@@ -25,33 +25,37 @@ function deriveLocation(event: APIGatewayProxyEventV2) {
25
25
  }
26
26
 
27
27
  function createContext(event: APIGatewayProxyEventV2) {
28
- const cookies = new CookieJar(event.headers['cookie']);
29
- const location = deriveLocation(event);
30
- return new Context({
31
- cookies,
32
- location,
33
- httpMethod: event.requestContext.http.method,
34
- requestBody: event.body,
35
- requestHeaders: event.headers as Record<string, string>,
36
- runtimeAttributes: [
37
- new SystemAttribute('wirejs', 'deployment-type', {
38
- description: 'Deployment under which your system is running.',
39
- value: 'wirejs-deploy-amplify-basic'
40
- }),
41
- new SystemAttribute('wirejs', 'http-origin-local', {
42
- description: 'HTTP origin (base address) to use for local development.',
43
- value: null,
44
- }),
45
- new SystemAttribute('wirejs', 'http-origin-network', {
46
- description: 'HTTP origin (base address) for machines on your network to use.',
47
- value: null,
48
- }),
49
- new SystemAttribute('wirejs', 'http-origin-public', {
50
- description: 'HTTP origin (base address) for machines outside your network to use. Only populated for `npm run start:public`, and only accessible in environments that support NAT-PMP.',
51
- value: location.origin
52
- }),
53
- ]
54
- });
28
+ try {
29
+ const cookies = new CookieJar(event.headers['cookie']);
30
+ const location = deriveLocation(event);
31
+ return new Context({
32
+ cookies,
33
+ location,
34
+ httpMethod: event.requestContext.http.method,
35
+ requestBody: event.body,
36
+ requestHeaders: event.headers as Record<string, string>,
37
+ runtimeAttributes: [
38
+ new SystemAttribute('wirejs', 'deployment-type', {
39
+ description: 'Deployment under which your system is running.',
40
+ value: 'wirejs-deploy-amplify-basic'
41
+ }),
42
+ new SystemAttribute('wirejs', 'http-origin-local', {
43
+ description: 'HTTP origin (base address) to use for local development.',
44
+ value: null,
45
+ }),
46
+ new SystemAttribute('wirejs', 'http-origin-network', {
47
+ description: 'HTTP origin (base address) for machines on your network to use.',
48
+ value: null,
49
+ }),
50
+ new SystemAttribute('wirejs', 'http-origin-public', {
51
+ description: 'HTTP origin (base address) for machines outside your network to use. Only populated for `npm run start:public`, and only accessible in environments that support NAT-PMP.',
52
+ value: location.origin
53
+ }),
54
+ ]
55
+ });
56
+ } catch {
57
+ return undefined;
58
+ }
55
59
  }
56
60
 
57
61
  async function callApiMethod(api: any, call: any, context: any) {
@@ -136,11 +140,14 @@ function byPathLength(a: Endpoint, b: Endpoint) {
136
140
  }
137
141
 
138
142
  export const handler: LambdaFunctionURLHandler = async (event) => {
139
- const calls = JSON.parse(event.body!);
143
+ const calls = event.body ? JSON.parse(event.body) : undefined;
140
144
  const wjsContext = createContext(event);
141
- const path = wjsContext.location.pathname;
145
+ const path = wjsContext?.location.pathname;
142
146
 
143
- if ((path === '/api' || path.startsWith('/api/')) && Array.isArray(calls)) {
147
+ if (wjsContext
148
+ && (path === '/api' || path?.startsWith('/api/'))
149
+ && Array.isArray(calls)
150
+ ) {
144
151
  const responses = [];
145
152
  for (const call of calls) {
146
153
  console.log('handling API call', call);
@@ -155,6 +162,29 @@ export const handler: LambdaFunctionURLHandler = async (event) => {
155
162
  },
156
163
  body: JSON.stringify(responses)
157
164
  }
165
+ } else if (wjsContext) {
166
+ const allHandlers = [...Endpoint.list()];
167
+ const matchingHandlers = allHandlers
168
+ .filter(e => globMatch(e.path, wjsContext.location.pathname));
169
+ const matchingEndpoint = matchingHandlers.sort(byPathLength).pop();
170
+
171
+ if (!matchingEndpoint) {
172
+ console.error('Invalid request format', calls);
173
+ return {
174
+ statusCode: 400,
175
+ body: JSON.stringify({ error: 'Invalid request format' })
176
+ };
177
+ }
178
+
179
+ const response = await matchingEndpoint.handle(wjsContext);
180
+ return {
181
+ statusCode: wjsContext.responseCode ?? 200,
182
+ cookies: extractSetCookies(wjsContext),
183
+ headers: {
184
+ ...getResponseHeadersFromContext(wjsContext),
185
+ },
186
+ body: response
187
+ };
158
188
  } else if (typeof calls === 'object' && calls.async) {
159
189
  const sanitized = { ...calls };
160
190
  sanitized.selfInvocationId = sanitized.selfInvocationId.slice(0, 8);
@@ -196,27 +226,9 @@ export const handler: LambdaFunctionURLHandler = async (event) => {
196
226
  body: JSON.stringify({ message: 'Background job complete' })
197
227
  };
198
228
  } else {
199
- const allHandlers = [...Endpoint.list()];
200
- const matchingHandlers = allHandlers
201
- .filter(e => globMatch(e.path, wjsContext.location.pathname));
202
- const matchingEndpoint = matchingHandlers.sort(byPathLength).pop();
203
-
204
- if (!matchingEndpoint) {
205
- console.error('Invalid request format', calls);
206
- return {
207
- statusCode: 400,
208
- body: JSON.stringify({ error: 'Invalid request format' })
209
- };
210
- }
211
-
212
- const response = await matchingEndpoint.handle(wjsContext);
213
229
  return {
214
- statusCode: wjsContext.responseCode ?? 200,
215
- cookies: extractSetCookies(wjsContext),
216
- headers: {
217
- ...getResponseHeadersFromContext(wjsContext),
218
- },
219
- body: response
230
+ statusCode: 404,
231
+ body: "Not found"
220
232
  };
221
233
  }
222
234
  }
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.42",
6
- "wirejs-resources": "^0.1.120-payments"
6
+ "wirejs-resources": "^0.1.122-payments"
7
7
  }
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.0.152-payments",
3
+ "version": "0.0.154-payments",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "recursive-copy": "^2.0.14",
43
43
  "rimraf": "^6.0.1",
44
44
  "wirejs-dom": "^1.0.42",
45
- "wirejs-resources": "^0.1.120-payments"
45
+ "wirejs-resources": "^0.1.122-payments"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@aws-amplify/backend": "^1.14.0",