@koralabs/kora-labs-common 6.7.4 → 6.7.6
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.
package/fn/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const flattenHeaders = (h) => {
|
|
|
32
32
|
* @returns the response body (Buffer or string); status + headers are set on ctx.httpGateway
|
|
33
33
|
*/
|
|
34
34
|
const invokeExpressViaAlb = async (albHandler, ctx, input) => {
|
|
35
|
-
var _a;
|
|
35
|
+
var _a, _b, _c;
|
|
36
36
|
const h = ctx.httpGateway;
|
|
37
37
|
if (!h)
|
|
38
38
|
throw new Error('invokeExpressViaAlb: ctx.httpGateway missing (the function must be HTTP-triggered)');
|
|
@@ -48,18 +48,30 @@ const invokeExpressViaAlb = async (albHandler, ctx, input) => {
|
|
|
48
48
|
const bodyBuf = input == null
|
|
49
49
|
? Buffer.alloc(0)
|
|
50
50
|
: Buffer.isBuffer(input) ? input : Buffer.from(input);
|
|
51
|
+
const headers = flattenHeaders(h.headers);
|
|
52
|
+
// Mirror ALB body semantics: ALB delivers TEXT content-types as a raw UTF-8 string
|
|
53
|
+
// (isBase64Encoded=false) and only BINARY as base64. Handlers written for ALB read text
|
|
54
|
+
// bodies directly (e.g. JSON.parse(event.body)) and only base64-decode when isBase64Encoded
|
|
55
|
+
// is true. Unconditional base64 here broke every JSON/text POST (the handler JSON.parsed the
|
|
56
|
+
// base64 string and threw -> 500). Treat text/*, json, xml, x-www-form-urlencoded, javascript
|
|
57
|
+
// and the no-content-type default as text; everything else (images, multipart, octet-stream)
|
|
58
|
+
// as binary.
|
|
59
|
+
const ctype = String((_b = (_a = Object.entries(headers).find(([k]) => k.toLowerCase() === 'content-type')) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '').toLowerCase();
|
|
60
|
+
const isBinaryBody = ctype !== '' &&
|
|
61
|
+
!/^text\//.test(ctype) &&
|
|
62
|
+
!/(json|xml|x-www-form-urlencoded|javascript|graphql)/.test(ctype);
|
|
51
63
|
const event = {
|
|
52
64
|
requestContext: { elb: { targetGroupArn: 'arn:kora:fn' } },
|
|
53
65
|
httpMethod: h.method,
|
|
54
66
|
path: url.pathname,
|
|
55
67
|
queryStringParameters: Object.keys(qs).length ? qs : null,
|
|
56
68
|
multiValueQueryStringParameters: Object.keys(mqs).length ? mqs : null,
|
|
57
|
-
headers
|
|
58
|
-
body: bodyBuf.length ? bodyBuf.toString('base64') : null,
|
|
59
|
-
isBase64Encoded:
|
|
69
|
+
headers,
|
|
70
|
+
body: bodyBuf.length ? (isBinaryBody ? bodyBuf.toString('base64') : bodyBuf.toString('utf8')) : null,
|
|
71
|
+
isBase64Encoded: bodyBuf.length > 0 && isBinaryBody
|
|
60
72
|
};
|
|
61
73
|
const res = (await albHandler(event, {})) || {};
|
|
62
|
-
h.statusCode = (
|
|
74
|
+
h.statusCode = (_c = res.statusCode) !== null && _c !== void 0 ? _c : 200;
|
|
63
75
|
if (res.headers) {
|
|
64
76
|
for (const [k, v] of Object.entries(res.headers))
|
|
65
77
|
h.setResponseHeader(k, String(v));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface BasicAsset {
|
|
2
|
+
policyId: string;
|
|
3
|
+
hex: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Asset extends BasicAsset {
|
|
6
|
+
name: string;
|
|
7
|
+
count?: number;
|
|
8
|
+
utxo?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
src?: string;
|
|
11
|
+
price?: number;
|
|
12
|
+
cost?: number;
|
|
13
|
+
validUntilDate?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface WalletHandle extends Asset {
|
|
16
|
+
active: unknown;
|
|
17
|
+
default: boolean;
|
|
18
|
+
image?: string;
|
|
19
|
+
imageUrl?: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Browser-safe wallet/asset contracts (handle.me#938). Self-contained — NO runtime/backend
|
|
3
|
+
// imports — so ESM consumers like @koralabs/handles-shared-lit-components can use them (via
|
|
4
|
+
// `import type`) without the CJS/ESM interop break the package's heavier modules would cause.
|
|
5
|
+
// These canonicalize the duplicated local shapes in handles-shared-lit-components.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.AvailabilityResponseCode = exports.OAuthSocial = exports.SubHandleType = exports.HandleType = exports.Rarity = void 0;
|
|
4
18
|
var Rarity;
|
|
@@ -50,3 +64,4 @@ var AvailabilityResponseCode;
|
|
|
50
64
|
AvailabilityResponseCode[AvailabilityResponseCode["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
51
65
|
AvailabilityResponseCode[AvailabilityResponseCode["LOCKED"] = 423] = "LOCKED";
|
|
52
66
|
})(AvailabilityResponseCode = exports.AvailabilityResponseCode || (exports.AvailabilityResponseCode = {}));
|
|
67
|
+
__exportStar(require("./WalletHandle"), exports);
|