wirejs-deploy-amplify-basic 0.0.151-payments → 0.0.153-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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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) {
|
|
@@ -138,9 +142,12 @@ function byPathLength(a: Endpoint, b: Endpoint) {
|
|
|
138
142
|
export const handler: LambdaFunctionURLHandler = async (event) => {
|
|
139
143
|
const calls = JSON.parse(event.body!);
|
|
140
144
|
const wjsContext = createContext(event);
|
|
141
|
-
const path = wjsContext
|
|
145
|
+
const path = wjsContext?.location.pathname;
|
|
142
146
|
|
|
143
|
-
if (
|
|
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:
|
|
215
|
-
|
|
216
|
-
headers: {
|
|
217
|
-
...getResponseHeadersFromContext(wjsContext),
|
|
218
|
-
},
|
|
219
|
-
body: response
|
|
230
|
+
statusCode: 404,
|
|
231
|
+
body: "Not found"
|
|
220
232
|
};
|
|
221
233
|
}
|
|
222
234
|
}
|
package/dist/client/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.153-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.
|
|
45
|
+
"wirejs-resources": "^0.1.121-payments"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@aws-amplify/backend": "^1.14.0",
|