telepact 1.0.0-alpha.331 → 1.0.0-alpha.335
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/README.md +2 -2
- package/dist/index.cjs.js +70 -31
- package/dist/index.esm.js +70 -31
- package/dist/index.iife.js +70 -31
- package/dist/src/FunctionRouter.d.ts +7 -2
- package/dist/src/FunctionRouter.js +25 -4
- package/dist/src/FunctionRouter.js.map +1 -1
- package/dist/src/MockServer.js +2 -2
- package/dist/src/MockServer.js.map +1 -1
- package/dist/src/Server.d.ts +3 -3
- package/dist/src/Server.js +7 -9
- package/dist/src/Server.js.map +1 -1
- package/dist/src/internal/HandleMessage.d.ts +3 -6
- package/dist/src/internal/HandleMessage.js +17 -5
- package/dist/src/internal/HandleMessage.js.map +1 -1
- package/dist/src/internal/ProcessBytes.d.ts +2 -1
- package/dist/src/internal/ProcessBytes.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,6 @@ const functionRoutes = {
|
|
|
39
39
|
|
|
40
40
|
const options = new ServerOptions();
|
|
41
41
|
// Set this to false when your schema does not define union.Auth_.
|
|
42
|
-
options.authRequired = false;
|
|
43
42
|
options.middleware = async (requestMessage: Message, functionRouter): Promise<Message> => {
|
|
44
43
|
const functionName = requestMessage.getBodyTarget();
|
|
45
44
|
try {
|
|
@@ -49,7 +48,8 @@ options.middleware = async (requestMessage: Message, functionRouter): Promise<Me
|
|
|
49
48
|
log.info("Function finished", {function: functionName});
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
|
-
const functionRouter = new FunctionRouter(
|
|
51
|
+
const functionRouter = new FunctionRouter();
|
|
52
|
+
functionRouter.registerUnauthenticatedRoutes(functionRoutes);
|
|
53
53
|
const server = new Server(schema, functionRouter, options);
|
|
54
54
|
|
|
55
55
|
// Wire up request/response bytes from your transport of choice
|
package/dist/index.cjs.js
CHANGED
|
@@ -1100,13 +1100,34 @@ class ClientOptions {
|
|
|
1100
1100
|
}
|
|
1101
1101
|
|
|
1102
1102
|
class FunctionRouter {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1103
|
+
authenticatedFunctionRoutes;
|
|
1104
|
+
unauthenticatedFunctionRoutes;
|
|
1105
|
+
constructor() {
|
|
1106
|
+
this.authenticatedFunctionRoutes = {};
|
|
1107
|
+
this.unauthenticatedFunctionRoutes = {};
|
|
1108
|
+
}
|
|
1109
|
+
registerAuthenticatedRoutes(functionRoutes) {
|
|
1110
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1111
|
+
this.authenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1112
|
+
delete this.unauthenticatedFunctionRoutes[functionName];
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
registerUnauthenticatedRoutes(functionRoutes) {
|
|
1116
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1117
|
+
this.unauthenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1118
|
+
delete this.authenticatedFunctionRoutes[functionName];
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
hasAuthenticatedRoutes() {
|
|
1122
|
+
return Object.keys(this.authenticatedFunctionRoutes).length > 0;
|
|
1123
|
+
}
|
|
1124
|
+
requiresAuthentication(functionName) {
|
|
1125
|
+
return functionName in this.authenticatedFunctionRoutes;
|
|
1106
1126
|
}
|
|
1107
1127
|
async route(requestMessage) {
|
|
1108
1128
|
const functionName = requestMessage.getBodyTarget();
|
|
1109
|
-
const functionRoute = this.
|
|
1129
|
+
const functionRoute = this.authenticatedFunctionRoutes[functionName]
|
|
1130
|
+
?? this.unauthenticatedFunctionRoutes[functionName];
|
|
1110
1131
|
if (functionRoute === undefined) {
|
|
1111
1132
|
throw new Error(`Unknown function: ${functionName}`);
|
|
1112
1133
|
}
|
|
@@ -1853,7 +1874,7 @@ function buildUnknownErrorMessage(error, headers = {}) {
|
|
|
1853
1874
|
return new Message(headers, { ErrorUnknown_: { caseId: error.caseId } });
|
|
1854
1875
|
}
|
|
1855
1876
|
|
|
1856
|
-
const
|
|
1877
|
+
const UNAUTHENTICATED_MESSAGE = 'Valid authentication is required.';
|
|
1857
1878
|
async function handleMessage(requestMessage, updateHeaders, telepactSchema, middleware, functionRouter, onError, onAuth) {
|
|
1858
1879
|
const responseHeaders = {};
|
|
1859
1880
|
const requestHeaders = requestMessage.headers;
|
|
@@ -1863,7 +1884,6 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1863
1884
|
updateHeaders?.(requestHeaders);
|
|
1864
1885
|
const requestTargetInit = requestEntry[0];
|
|
1865
1886
|
const requestPayload = requestEntry[1];
|
|
1866
|
-
const bypassAuthForFunction = INTERNAL_FUNCTIONS_BYPASSING_AUTH.has(requestTargetInit);
|
|
1867
1887
|
let unknownTarget;
|
|
1868
1888
|
let requestTarget;
|
|
1869
1889
|
if (!(requestTargetInit in parsedTelepactSchema)) {
|
|
@@ -1877,6 +1897,7 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1877
1897
|
const functionName = requestTarget;
|
|
1878
1898
|
const callType = parsedTelepactSchema[requestTarget];
|
|
1879
1899
|
const resultUnionType = parsedTelepactSchema[`${requestTarget}.->`];
|
|
1900
|
+
const requiresAuthentication = unknownTarget === null && functionRouter.requiresAuthentication(functionName);
|
|
1880
1901
|
const callId = requestHeaders['@id_'];
|
|
1881
1902
|
if (callId !== undefined) {
|
|
1882
1903
|
responseHeaders['@id_'] = callId;
|
|
@@ -1893,9 +1914,12 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1893
1914
|
if (requestHeaderValidationFailures.length > 0) {
|
|
1894
1915
|
return getInvalidErrorMessage('ErrorInvalidRequestHeaders_', requestHeaderValidationFailures, resultUnionType, responseHeaders);
|
|
1895
1916
|
}
|
|
1896
|
-
if ('@auth_' in requestHeaders
|
|
1917
|
+
if (requiresAuthentication && !('@auth_' in requestHeaders)) {
|
|
1918
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1919
|
+
}
|
|
1920
|
+
if (requiresAuthentication) {
|
|
1897
1921
|
try {
|
|
1898
|
-
const authHeaders = onAuth(requestHeaders) ?? {};
|
|
1922
|
+
const authHeaders = (await onAuth(requestHeaders)) ?? {};
|
|
1899
1923
|
Object.assign(requestHeaders, authHeaders);
|
|
1900
1924
|
}
|
|
1901
1925
|
catch (error) {
|
|
@@ -1905,7 +1929,7 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1905
1929
|
}
|
|
1906
1930
|
catch (ignored) {
|
|
1907
1931
|
}
|
|
1908
|
-
return
|
|
1932
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1909
1933
|
}
|
|
1910
1934
|
}
|
|
1911
1935
|
if ('@bin_' in requestHeaders) {
|
|
@@ -1916,6 +1940,15 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1916
1940
|
responseHeaders['@pac_'] = requestHeaders['@pac_'];
|
|
1917
1941
|
}
|
|
1918
1942
|
}
|
|
1943
|
+
function buildUnauthenticatedErrorMessage(resultUnionType, headers) {
|
|
1944
|
+
const result = {
|
|
1945
|
+
ErrorUnauthenticated_: {
|
|
1946
|
+
'message!': UNAUTHENTICATED_MESSAGE,
|
|
1947
|
+
},
|
|
1948
|
+
};
|
|
1949
|
+
validateResult(resultUnionType, result);
|
|
1950
|
+
return new Message(headers, result);
|
|
1951
|
+
}
|
|
1919
1952
|
const selectStructFieldsHeader = requestHeaders['@select_'] || null;
|
|
1920
1953
|
if (unknownTarget !== null) {
|
|
1921
1954
|
const newErrorResult = {
|
|
@@ -2379,11 +2412,11 @@ class Server {
|
|
|
2379
2412
|
telepactSchema;
|
|
2380
2413
|
serializer;
|
|
2381
2414
|
constructor(telepactSchema, functionRouter, options) {
|
|
2382
|
-
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter(
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2415
|
+
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter();
|
|
2416
|
+
if (!(functionRouter instanceof FunctionRouter)) {
|
|
2417
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(functionRouter);
|
|
2418
|
+
}
|
|
2419
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(createInternalFunctionRoutes(telepactSchema));
|
|
2387
2420
|
this.functionRouter = normalizedFunctionRouter;
|
|
2388
2421
|
this.middleware = options.middleware;
|
|
2389
2422
|
this.onError = options.onError;
|
|
@@ -2395,8 +2428,8 @@ class Server {
|
|
|
2395
2428
|
const binaryEncoder = new ServerBinaryEncoder(binaryEncoding);
|
|
2396
2429
|
const base64Encoder = new ServerBase64Encoder();
|
|
2397
2430
|
this.serializer = new Serializer(options.serialization, binaryEncoder, base64Encoder);
|
|
2398
|
-
if (!('union.Auth_' in this.telepactSchema.parsed) &&
|
|
2399
|
-
throw new Error('
|
|
2431
|
+
if (!('union.Auth_' in this.telepactSchema.parsed) && this.functionRouter.hasAuthenticatedRoutes()) {
|
|
2432
|
+
throw new Error('Authenticated routes require `union.Auth_` in your schema.');
|
|
2400
2433
|
}
|
|
2401
2434
|
}
|
|
2402
2435
|
async process(requestMessageBytes, updateHeaders) {
|
|
@@ -2409,7 +2442,6 @@ class ServerOptions {
|
|
|
2409
2442
|
onResponse;
|
|
2410
2443
|
onAuth;
|
|
2411
2444
|
middleware;
|
|
2412
|
-
authRequired;
|
|
2413
2445
|
serialization;
|
|
2414
2446
|
constructor() {
|
|
2415
2447
|
this.onError = (_error) => { };
|
|
@@ -2417,7 +2449,6 @@ class ServerOptions {
|
|
|
2417
2449
|
this.onResponse = (m) => { };
|
|
2418
2450
|
this.onAuth = (headers) => ({});
|
|
2419
2451
|
this.middleware = async (requestMessage, functionRouter) => await functionRouter.route(requestMessage);
|
|
2420
|
-
this.authRequired = true;
|
|
2421
2452
|
this.serialization = new DefaultSerialization();
|
|
2422
2453
|
}
|
|
2423
2454
|
}
|
|
@@ -3366,6 +3397,8 @@ class Alias extends NodeBase {
|
|
|
3366
3397
|
* instance of the `source` anchor before this node.
|
|
3367
3398
|
*/
|
|
3368
3399
|
resolve(doc, ctx) {
|
|
3400
|
+
if (ctx?.maxAliasCount === 0)
|
|
3401
|
+
throw new ReferenceError('Alias resolution is disabled');
|
|
3369
3402
|
let nodes;
|
|
3370
3403
|
if (ctx?.aliasResolveCache) {
|
|
3371
3404
|
nodes = ctx.aliasResolveCache;
|
|
@@ -4496,18 +4529,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
4496
4529
|
merge.identify(key.value))) &&
|
|
4497
4530
|
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
4498
4531
|
function addMergeToJSMap(ctx, map, value) {
|
|
4499
|
-
|
|
4500
|
-
if (isSeq(
|
|
4501
|
-
for (const it of
|
|
4532
|
+
const source = resolveAliasValue(ctx, value);
|
|
4533
|
+
if (isSeq(source))
|
|
4534
|
+
for (const it of source.items)
|
|
4502
4535
|
mergeValue(ctx, map, it);
|
|
4503
|
-
else if (Array.isArray(
|
|
4504
|
-
for (const it of
|
|
4536
|
+
else if (Array.isArray(source))
|
|
4537
|
+
for (const it of source)
|
|
4505
4538
|
mergeValue(ctx, map, it);
|
|
4506
4539
|
else
|
|
4507
|
-
mergeValue(ctx, map,
|
|
4540
|
+
mergeValue(ctx, map, source);
|
|
4508
4541
|
}
|
|
4509
4542
|
function mergeValue(ctx, map, value) {
|
|
4510
|
-
const source = ctx
|
|
4543
|
+
const source = resolveAliasValue(ctx, value);
|
|
4511
4544
|
if (!isMap(source))
|
|
4512
4545
|
throw new Error('Merge sources must be maps or map aliases');
|
|
4513
4546
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
@@ -4530,6 +4563,9 @@ function mergeValue(ctx, map, value) {
|
|
|
4530
4563
|
}
|
|
4531
4564
|
return map;
|
|
4532
4565
|
}
|
|
4566
|
+
function resolveAliasValue(ctx, value) {
|
|
4567
|
+
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
4568
|
+
}
|
|
4533
4569
|
|
|
4534
4570
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
4535
4571
|
if (isNode(key) && key.addToJSMap)
|
|
@@ -5081,7 +5117,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
|
5081
5117
|
if (!format &&
|
|
5082
5118
|
minFractionDigits &&
|
|
5083
5119
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
5084
|
-
|
|
5120
|
+
/^-?\d/.test(n) &&
|
|
5121
|
+
!n.includes('e')) {
|
|
5085
5122
|
let i = n.indexOf('.');
|
|
5086
5123
|
if (i < 0) {
|
|
5087
5124
|
i = n.length;
|
|
@@ -7340,7 +7377,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
7340
7377
|
next = source[++i + 1];
|
|
7341
7378
|
}
|
|
7342
7379
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
7343
|
-
const length =
|
|
7380
|
+
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
|
|
7344
7381
|
res += parseCharCode(source, i + 1, length, onError);
|
|
7345
7382
|
i += length;
|
|
7346
7383
|
}
|
|
@@ -7410,12 +7447,14 @@ function parseCharCode(source, offset, length, onError) {
|
|
|
7410
7447
|
const cc = source.substr(offset, length);
|
|
7411
7448
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
7412
7449
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
7413
|
-
|
|
7450
|
+
try {
|
|
7451
|
+
return String.fromCodePoint(code);
|
|
7452
|
+
}
|
|
7453
|
+
catch {
|
|
7414
7454
|
const raw = source.substr(offset - 2, length + 2);
|
|
7415
7455
|
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
7416
7456
|
return raw;
|
|
7417
7457
|
}
|
|
7418
|
-
return String.fromCodePoint(code);
|
|
7419
7458
|
}
|
|
7420
7459
|
|
|
7421
7460
|
function composeScalar(ctx, token, tagToken, onError) {
|
|
@@ -11900,9 +11939,9 @@ class MockServer {
|
|
|
11900
11939
|
this.invocations = [];
|
|
11901
11940
|
const serverOptions = new ServerOptions();
|
|
11902
11941
|
serverOptions.onError = options.onError;
|
|
11903
|
-
serverOptions.authRequired = false;
|
|
11904
11942
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11905
|
-
const functionRouter = new FunctionRouter(
|
|
11943
|
+
const functionRouter = new FunctionRouter();
|
|
11944
|
+
functionRouter.registerUnauthenticatedRoutes(this.createFunctionRoutes(telepactSchema));
|
|
11906
11945
|
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11907
11946
|
}
|
|
11908
11947
|
random;
|
package/dist/index.esm.js
CHANGED
|
@@ -1098,13 +1098,34 @@ class ClientOptions {
|
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
1100
|
class FunctionRouter {
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1101
|
+
authenticatedFunctionRoutes;
|
|
1102
|
+
unauthenticatedFunctionRoutes;
|
|
1103
|
+
constructor() {
|
|
1104
|
+
this.authenticatedFunctionRoutes = {};
|
|
1105
|
+
this.unauthenticatedFunctionRoutes = {};
|
|
1106
|
+
}
|
|
1107
|
+
registerAuthenticatedRoutes(functionRoutes) {
|
|
1108
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1109
|
+
this.authenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1110
|
+
delete this.unauthenticatedFunctionRoutes[functionName];
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
registerUnauthenticatedRoutes(functionRoutes) {
|
|
1114
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1115
|
+
this.unauthenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1116
|
+
delete this.authenticatedFunctionRoutes[functionName];
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
hasAuthenticatedRoutes() {
|
|
1120
|
+
return Object.keys(this.authenticatedFunctionRoutes).length > 0;
|
|
1121
|
+
}
|
|
1122
|
+
requiresAuthentication(functionName) {
|
|
1123
|
+
return functionName in this.authenticatedFunctionRoutes;
|
|
1104
1124
|
}
|
|
1105
1125
|
async route(requestMessage) {
|
|
1106
1126
|
const functionName = requestMessage.getBodyTarget();
|
|
1107
|
-
const functionRoute = this.
|
|
1127
|
+
const functionRoute = this.authenticatedFunctionRoutes[functionName]
|
|
1128
|
+
?? this.unauthenticatedFunctionRoutes[functionName];
|
|
1108
1129
|
if (functionRoute === undefined) {
|
|
1109
1130
|
throw new Error(`Unknown function: ${functionName}`);
|
|
1110
1131
|
}
|
|
@@ -1851,7 +1872,7 @@ function buildUnknownErrorMessage(error, headers = {}) {
|
|
|
1851
1872
|
return new Message(headers, { ErrorUnknown_: { caseId: error.caseId } });
|
|
1852
1873
|
}
|
|
1853
1874
|
|
|
1854
|
-
const
|
|
1875
|
+
const UNAUTHENTICATED_MESSAGE = 'Valid authentication is required.';
|
|
1855
1876
|
async function handleMessage(requestMessage, updateHeaders, telepactSchema, middleware, functionRouter, onError, onAuth) {
|
|
1856
1877
|
const responseHeaders = {};
|
|
1857
1878
|
const requestHeaders = requestMessage.headers;
|
|
@@ -1861,7 +1882,6 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1861
1882
|
updateHeaders?.(requestHeaders);
|
|
1862
1883
|
const requestTargetInit = requestEntry[0];
|
|
1863
1884
|
const requestPayload = requestEntry[1];
|
|
1864
|
-
const bypassAuthForFunction = INTERNAL_FUNCTIONS_BYPASSING_AUTH.has(requestTargetInit);
|
|
1865
1885
|
let unknownTarget;
|
|
1866
1886
|
let requestTarget;
|
|
1867
1887
|
if (!(requestTargetInit in parsedTelepactSchema)) {
|
|
@@ -1875,6 +1895,7 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1875
1895
|
const functionName = requestTarget;
|
|
1876
1896
|
const callType = parsedTelepactSchema[requestTarget];
|
|
1877
1897
|
const resultUnionType = parsedTelepactSchema[`${requestTarget}.->`];
|
|
1898
|
+
const requiresAuthentication = unknownTarget === null && functionRouter.requiresAuthentication(functionName);
|
|
1878
1899
|
const callId = requestHeaders['@id_'];
|
|
1879
1900
|
if (callId !== undefined) {
|
|
1880
1901
|
responseHeaders['@id_'] = callId;
|
|
@@ -1891,9 +1912,12 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1891
1912
|
if (requestHeaderValidationFailures.length > 0) {
|
|
1892
1913
|
return getInvalidErrorMessage('ErrorInvalidRequestHeaders_', requestHeaderValidationFailures, resultUnionType, responseHeaders);
|
|
1893
1914
|
}
|
|
1894
|
-
if ('@auth_' in requestHeaders
|
|
1915
|
+
if (requiresAuthentication && !('@auth_' in requestHeaders)) {
|
|
1916
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1917
|
+
}
|
|
1918
|
+
if (requiresAuthentication) {
|
|
1895
1919
|
try {
|
|
1896
|
-
const authHeaders = onAuth(requestHeaders) ?? {};
|
|
1920
|
+
const authHeaders = (await onAuth(requestHeaders)) ?? {};
|
|
1897
1921
|
Object.assign(requestHeaders, authHeaders);
|
|
1898
1922
|
}
|
|
1899
1923
|
catch (error) {
|
|
@@ -1903,7 +1927,7 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1903
1927
|
}
|
|
1904
1928
|
catch (ignored) {
|
|
1905
1929
|
}
|
|
1906
|
-
return
|
|
1930
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1907
1931
|
}
|
|
1908
1932
|
}
|
|
1909
1933
|
if ('@bin_' in requestHeaders) {
|
|
@@ -1914,6 +1938,15 @@ async function handleMessage(requestMessage, updateHeaders, telepactSchema, midd
|
|
|
1914
1938
|
responseHeaders['@pac_'] = requestHeaders['@pac_'];
|
|
1915
1939
|
}
|
|
1916
1940
|
}
|
|
1941
|
+
function buildUnauthenticatedErrorMessage(resultUnionType, headers) {
|
|
1942
|
+
const result = {
|
|
1943
|
+
ErrorUnauthenticated_: {
|
|
1944
|
+
'message!': UNAUTHENTICATED_MESSAGE,
|
|
1945
|
+
},
|
|
1946
|
+
};
|
|
1947
|
+
validateResult(resultUnionType, result);
|
|
1948
|
+
return new Message(headers, result);
|
|
1949
|
+
}
|
|
1917
1950
|
const selectStructFieldsHeader = requestHeaders['@select_'] || null;
|
|
1918
1951
|
if (unknownTarget !== null) {
|
|
1919
1952
|
const newErrorResult = {
|
|
@@ -2377,11 +2410,11 @@ class Server {
|
|
|
2377
2410
|
telepactSchema;
|
|
2378
2411
|
serializer;
|
|
2379
2412
|
constructor(telepactSchema, functionRouter, options) {
|
|
2380
|
-
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter(
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2413
|
+
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter();
|
|
2414
|
+
if (!(functionRouter instanceof FunctionRouter)) {
|
|
2415
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(functionRouter);
|
|
2416
|
+
}
|
|
2417
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(createInternalFunctionRoutes(telepactSchema));
|
|
2385
2418
|
this.functionRouter = normalizedFunctionRouter;
|
|
2386
2419
|
this.middleware = options.middleware;
|
|
2387
2420
|
this.onError = options.onError;
|
|
@@ -2393,8 +2426,8 @@ class Server {
|
|
|
2393
2426
|
const binaryEncoder = new ServerBinaryEncoder(binaryEncoding);
|
|
2394
2427
|
const base64Encoder = new ServerBase64Encoder();
|
|
2395
2428
|
this.serializer = new Serializer(options.serialization, binaryEncoder, base64Encoder);
|
|
2396
|
-
if (!('union.Auth_' in this.telepactSchema.parsed) &&
|
|
2397
|
-
throw new Error('
|
|
2429
|
+
if (!('union.Auth_' in this.telepactSchema.parsed) && this.functionRouter.hasAuthenticatedRoutes()) {
|
|
2430
|
+
throw new Error('Authenticated routes require `union.Auth_` in your schema.');
|
|
2398
2431
|
}
|
|
2399
2432
|
}
|
|
2400
2433
|
async process(requestMessageBytes, updateHeaders) {
|
|
@@ -2407,7 +2440,6 @@ class ServerOptions {
|
|
|
2407
2440
|
onResponse;
|
|
2408
2441
|
onAuth;
|
|
2409
2442
|
middleware;
|
|
2410
|
-
authRequired;
|
|
2411
2443
|
serialization;
|
|
2412
2444
|
constructor() {
|
|
2413
2445
|
this.onError = (_error) => { };
|
|
@@ -2415,7 +2447,6 @@ class ServerOptions {
|
|
|
2415
2447
|
this.onResponse = (m) => { };
|
|
2416
2448
|
this.onAuth = (headers) => ({});
|
|
2417
2449
|
this.middleware = async (requestMessage, functionRouter) => await functionRouter.route(requestMessage);
|
|
2418
|
-
this.authRequired = true;
|
|
2419
2450
|
this.serialization = new DefaultSerialization();
|
|
2420
2451
|
}
|
|
2421
2452
|
}
|
|
@@ -3364,6 +3395,8 @@ class Alias extends NodeBase {
|
|
|
3364
3395
|
* instance of the `source` anchor before this node.
|
|
3365
3396
|
*/
|
|
3366
3397
|
resolve(doc, ctx) {
|
|
3398
|
+
if (ctx?.maxAliasCount === 0)
|
|
3399
|
+
throw new ReferenceError('Alias resolution is disabled');
|
|
3367
3400
|
let nodes;
|
|
3368
3401
|
if (ctx?.aliasResolveCache) {
|
|
3369
3402
|
nodes = ctx.aliasResolveCache;
|
|
@@ -4494,18 +4527,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
4494
4527
|
merge.identify(key.value))) &&
|
|
4495
4528
|
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
4496
4529
|
function addMergeToJSMap(ctx, map, value) {
|
|
4497
|
-
|
|
4498
|
-
if (isSeq(
|
|
4499
|
-
for (const it of
|
|
4530
|
+
const source = resolveAliasValue(ctx, value);
|
|
4531
|
+
if (isSeq(source))
|
|
4532
|
+
for (const it of source.items)
|
|
4500
4533
|
mergeValue(ctx, map, it);
|
|
4501
|
-
else if (Array.isArray(
|
|
4502
|
-
for (const it of
|
|
4534
|
+
else if (Array.isArray(source))
|
|
4535
|
+
for (const it of source)
|
|
4503
4536
|
mergeValue(ctx, map, it);
|
|
4504
4537
|
else
|
|
4505
|
-
mergeValue(ctx, map,
|
|
4538
|
+
mergeValue(ctx, map, source);
|
|
4506
4539
|
}
|
|
4507
4540
|
function mergeValue(ctx, map, value) {
|
|
4508
|
-
const source = ctx
|
|
4541
|
+
const source = resolveAliasValue(ctx, value);
|
|
4509
4542
|
if (!isMap(source))
|
|
4510
4543
|
throw new Error('Merge sources must be maps or map aliases');
|
|
4511
4544
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
@@ -4528,6 +4561,9 @@ function mergeValue(ctx, map, value) {
|
|
|
4528
4561
|
}
|
|
4529
4562
|
return map;
|
|
4530
4563
|
}
|
|
4564
|
+
function resolveAliasValue(ctx, value) {
|
|
4565
|
+
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
4566
|
+
}
|
|
4531
4567
|
|
|
4532
4568
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
4533
4569
|
if (isNode(key) && key.addToJSMap)
|
|
@@ -5079,7 +5115,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
|
5079
5115
|
if (!format &&
|
|
5080
5116
|
minFractionDigits &&
|
|
5081
5117
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
5082
|
-
|
|
5118
|
+
/^-?\d/.test(n) &&
|
|
5119
|
+
!n.includes('e')) {
|
|
5083
5120
|
let i = n.indexOf('.');
|
|
5084
5121
|
if (i < 0) {
|
|
5085
5122
|
i = n.length;
|
|
@@ -7338,7 +7375,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
7338
7375
|
next = source[++i + 1];
|
|
7339
7376
|
}
|
|
7340
7377
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
7341
|
-
const length =
|
|
7378
|
+
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
|
|
7342
7379
|
res += parseCharCode(source, i + 1, length, onError);
|
|
7343
7380
|
i += length;
|
|
7344
7381
|
}
|
|
@@ -7408,12 +7445,14 @@ function parseCharCode(source, offset, length, onError) {
|
|
|
7408
7445
|
const cc = source.substr(offset, length);
|
|
7409
7446
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
7410
7447
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
7411
|
-
|
|
7448
|
+
try {
|
|
7449
|
+
return String.fromCodePoint(code);
|
|
7450
|
+
}
|
|
7451
|
+
catch {
|
|
7412
7452
|
const raw = source.substr(offset - 2, length + 2);
|
|
7413
7453
|
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
7414
7454
|
return raw;
|
|
7415
7455
|
}
|
|
7416
|
-
return String.fromCodePoint(code);
|
|
7417
7456
|
}
|
|
7418
7457
|
|
|
7419
7458
|
function composeScalar(ctx, token, tagToken, onError) {
|
|
@@ -11898,9 +11937,9 @@ class MockServer {
|
|
|
11898
11937
|
this.invocations = [];
|
|
11899
11938
|
const serverOptions = new ServerOptions();
|
|
11900
11939
|
serverOptions.onError = options.onError;
|
|
11901
|
-
serverOptions.authRequired = false;
|
|
11902
11940
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11903
|
-
const functionRouter = new FunctionRouter(
|
|
11941
|
+
const functionRouter = new FunctionRouter();
|
|
11942
|
+
functionRouter.registerUnauthenticatedRoutes(this.createFunctionRoutes(telepactSchema));
|
|
11904
11943
|
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11905
11944
|
}
|
|
11906
11945
|
random;
|
package/dist/index.iife.js
CHANGED
|
@@ -1098,13 +1098,34 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
1100
|
class FunctionRouter {
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1101
|
+
authenticatedFunctionRoutes;
|
|
1102
|
+
unauthenticatedFunctionRoutes;
|
|
1103
|
+
constructor() {
|
|
1104
|
+
this.authenticatedFunctionRoutes = {};
|
|
1105
|
+
this.unauthenticatedFunctionRoutes = {};
|
|
1106
|
+
}
|
|
1107
|
+
registerAuthenticatedRoutes(functionRoutes) {
|
|
1108
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1109
|
+
this.authenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1110
|
+
delete this.unauthenticatedFunctionRoutes[functionName];
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
registerUnauthenticatedRoutes(functionRoutes) {
|
|
1114
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
1115
|
+
this.unauthenticatedFunctionRoutes[functionName] = functionRoute;
|
|
1116
|
+
delete this.authenticatedFunctionRoutes[functionName];
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
hasAuthenticatedRoutes() {
|
|
1120
|
+
return Object.keys(this.authenticatedFunctionRoutes).length > 0;
|
|
1121
|
+
}
|
|
1122
|
+
requiresAuthentication(functionName) {
|
|
1123
|
+
return functionName in this.authenticatedFunctionRoutes;
|
|
1104
1124
|
}
|
|
1105
1125
|
async route(requestMessage) {
|
|
1106
1126
|
const functionName = requestMessage.getBodyTarget();
|
|
1107
|
-
const functionRoute = this.
|
|
1127
|
+
const functionRoute = this.authenticatedFunctionRoutes[functionName]
|
|
1128
|
+
?? this.unauthenticatedFunctionRoutes[functionName];
|
|
1108
1129
|
if (functionRoute === undefined) {
|
|
1109
1130
|
throw new Error(`Unknown function: ${functionName}`);
|
|
1110
1131
|
}
|
|
@@ -1851,7 +1872,7 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1851
1872
|
return new Message(headers, { ErrorUnknown_: { caseId: error.caseId } });
|
|
1852
1873
|
}
|
|
1853
1874
|
|
|
1854
|
-
const
|
|
1875
|
+
const UNAUTHENTICATED_MESSAGE = 'Valid authentication is required.';
|
|
1855
1876
|
async function handleMessage(requestMessage, updateHeaders, telepactSchema, middleware, functionRouter, onError, onAuth) {
|
|
1856
1877
|
const responseHeaders = {};
|
|
1857
1878
|
const requestHeaders = requestMessage.headers;
|
|
@@ -1861,7 +1882,6 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1861
1882
|
updateHeaders?.(requestHeaders);
|
|
1862
1883
|
const requestTargetInit = requestEntry[0];
|
|
1863
1884
|
const requestPayload = requestEntry[1];
|
|
1864
|
-
const bypassAuthForFunction = INTERNAL_FUNCTIONS_BYPASSING_AUTH.has(requestTargetInit);
|
|
1865
1885
|
let unknownTarget;
|
|
1866
1886
|
let requestTarget;
|
|
1867
1887
|
if (!(requestTargetInit in parsedTelepactSchema)) {
|
|
@@ -1875,6 +1895,7 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1875
1895
|
const functionName = requestTarget;
|
|
1876
1896
|
const callType = parsedTelepactSchema[requestTarget];
|
|
1877
1897
|
const resultUnionType = parsedTelepactSchema[`${requestTarget}.->`];
|
|
1898
|
+
const requiresAuthentication = unknownTarget === null && functionRouter.requiresAuthentication(functionName);
|
|
1878
1899
|
const callId = requestHeaders['@id_'];
|
|
1879
1900
|
if (callId !== undefined) {
|
|
1880
1901
|
responseHeaders['@id_'] = callId;
|
|
@@ -1891,9 +1912,12 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1891
1912
|
if (requestHeaderValidationFailures.length > 0) {
|
|
1892
1913
|
return getInvalidErrorMessage('ErrorInvalidRequestHeaders_', requestHeaderValidationFailures, resultUnionType, responseHeaders);
|
|
1893
1914
|
}
|
|
1894
|
-
if ('@auth_' in requestHeaders
|
|
1915
|
+
if (requiresAuthentication && !('@auth_' in requestHeaders)) {
|
|
1916
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1917
|
+
}
|
|
1918
|
+
if (requiresAuthentication) {
|
|
1895
1919
|
try {
|
|
1896
|
-
const authHeaders = onAuth(requestHeaders) ?? {};
|
|
1920
|
+
const authHeaders = (await onAuth(requestHeaders)) ?? {};
|
|
1897
1921
|
Object.assign(requestHeaders, authHeaders);
|
|
1898
1922
|
}
|
|
1899
1923
|
catch (error) {
|
|
@@ -1903,7 +1927,7 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1903
1927
|
}
|
|
1904
1928
|
catch (ignored) {
|
|
1905
1929
|
}
|
|
1906
|
-
return
|
|
1930
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
1907
1931
|
}
|
|
1908
1932
|
}
|
|
1909
1933
|
if ('@bin_' in requestHeaders) {
|
|
@@ -1914,6 +1938,15 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
1914
1938
|
responseHeaders['@pac_'] = requestHeaders['@pac_'];
|
|
1915
1939
|
}
|
|
1916
1940
|
}
|
|
1941
|
+
function buildUnauthenticatedErrorMessage(resultUnionType, headers) {
|
|
1942
|
+
const result = {
|
|
1943
|
+
ErrorUnauthenticated_: {
|
|
1944
|
+
'message!': UNAUTHENTICATED_MESSAGE,
|
|
1945
|
+
},
|
|
1946
|
+
};
|
|
1947
|
+
validateResult(resultUnionType, result);
|
|
1948
|
+
return new Message(headers, result);
|
|
1949
|
+
}
|
|
1917
1950
|
const selectStructFieldsHeader = requestHeaders['@select_'] || null;
|
|
1918
1951
|
if (unknownTarget !== null) {
|
|
1919
1952
|
const newErrorResult = {
|
|
@@ -2377,11 +2410,11 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2377
2410
|
telepactSchema;
|
|
2378
2411
|
serializer;
|
|
2379
2412
|
constructor(telepactSchema, functionRouter, options) {
|
|
2380
|
-
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter(
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2413
|
+
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter();
|
|
2414
|
+
if (!(functionRouter instanceof FunctionRouter)) {
|
|
2415
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(functionRouter);
|
|
2416
|
+
}
|
|
2417
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(createInternalFunctionRoutes(telepactSchema));
|
|
2385
2418
|
this.functionRouter = normalizedFunctionRouter;
|
|
2386
2419
|
this.middleware = options.middleware;
|
|
2387
2420
|
this.onError = options.onError;
|
|
@@ -2393,8 +2426,8 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2393
2426
|
const binaryEncoder = new ServerBinaryEncoder(binaryEncoding);
|
|
2394
2427
|
const base64Encoder = new ServerBase64Encoder();
|
|
2395
2428
|
this.serializer = new Serializer(options.serialization, binaryEncoder, base64Encoder);
|
|
2396
|
-
if (!('union.Auth_' in this.telepactSchema.parsed) &&
|
|
2397
|
-
throw new Error('
|
|
2429
|
+
if (!('union.Auth_' in this.telepactSchema.parsed) && this.functionRouter.hasAuthenticatedRoutes()) {
|
|
2430
|
+
throw new Error('Authenticated routes require `union.Auth_` in your schema.');
|
|
2398
2431
|
}
|
|
2399
2432
|
}
|
|
2400
2433
|
async process(requestMessageBytes, updateHeaders) {
|
|
@@ -2407,7 +2440,6 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2407
2440
|
onResponse;
|
|
2408
2441
|
onAuth;
|
|
2409
2442
|
middleware;
|
|
2410
|
-
authRequired;
|
|
2411
2443
|
serialization;
|
|
2412
2444
|
constructor() {
|
|
2413
2445
|
this.onError = (_error) => { };
|
|
@@ -2415,7 +2447,6 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
2415
2447
|
this.onResponse = (m) => { };
|
|
2416
2448
|
this.onAuth = (headers) => ({});
|
|
2417
2449
|
this.middleware = async (requestMessage, functionRouter) => await functionRouter.route(requestMessage);
|
|
2418
|
-
this.authRequired = true;
|
|
2419
2450
|
this.serialization = new DefaultSerialization();
|
|
2420
2451
|
}
|
|
2421
2452
|
}
|
|
@@ -3364,6 +3395,8 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
3364
3395
|
* instance of the `source` anchor before this node.
|
|
3365
3396
|
*/
|
|
3366
3397
|
resolve(doc, ctx) {
|
|
3398
|
+
if (ctx?.maxAliasCount === 0)
|
|
3399
|
+
throw new ReferenceError('Alias resolution is disabled');
|
|
3367
3400
|
let nodes;
|
|
3368
3401
|
if (ctx?.aliasResolveCache) {
|
|
3369
3402
|
nodes = ctx.aliasResolveCache;
|
|
@@ -4494,18 +4527,18 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
4494
4527
|
merge.identify(key.value))) &&
|
|
4495
4528
|
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
4496
4529
|
function addMergeToJSMap(ctx, map, value) {
|
|
4497
|
-
|
|
4498
|
-
if (isSeq(
|
|
4499
|
-
for (const it of
|
|
4530
|
+
const source = resolveAliasValue(ctx, value);
|
|
4531
|
+
if (isSeq(source))
|
|
4532
|
+
for (const it of source.items)
|
|
4500
4533
|
mergeValue(ctx, map, it);
|
|
4501
|
-
else if (Array.isArray(
|
|
4502
|
-
for (const it of
|
|
4534
|
+
else if (Array.isArray(source))
|
|
4535
|
+
for (const it of source)
|
|
4503
4536
|
mergeValue(ctx, map, it);
|
|
4504
4537
|
else
|
|
4505
|
-
mergeValue(ctx, map,
|
|
4538
|
+
mergeValue(ctx, map, source);
|
|
4506
4539
|
}
|
|
4507
4540
|
function mergeValue(ctx, map, value) {
|
|
4508
|
-
const source = ctx
|
|
4541
|
+
const source = resolveAliasValue(ctx, value);
|
|
4509
4542
|
if (!isMap(source))
|
|
4510
4543
|
throw new Error('Merge sources must be maps or map aliases');
|
|
4511
4544
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
@@ -4528,6 +4561,9 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
4528
4561
|
}
|
|
4529
4562
|
return map;
|
|
4530
4563
|
}
|
|
4564
|
+
function resolveAliasValue(ctx, value) {
|
|
4565
|
+
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
4566
|
+
}
|
|
4531
4567
|
|
|
4532
4568
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
4533
4569
|
if (isNode(key) && key.addToJSMap)
|
|
@@ -5079,7 +5115,8 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
5079
5115
|
if (!format &&
|
|
5080
5116
|
minFractionDigits &&
|
|
5081
5117
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
5082
|
-
|
|
5118
|
+
/^-?\d/.test(n) &&
|
|
5119
|
+
!n.includes('e')) {
|
|
5083
5120
|
let i = n.indexOf('.');
|
|
5084
5121
|
if (i < 0) {
|
|
5085
5122
|
i = n.length;
|
|
@@ -7338,7 +7375,7 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
7338
7375
|
next = source[++i + 1];
|
|
7339
7376
|
}
|
|
7340
7377
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
7341
|
-
const length =
|
|
7378
|
+
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
|
|
7342
7379
|
res += parseCharCode(source, i + 1, length, onError);
|
|
7343
7380
|
i += length;
|
|
7344
7381
|
}
|
|
@@ -7408,12 +7445,14 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
7408
7445
|
const cc = source.substr(offset, length);
|
|
7409
7446
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
7410
7447
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
7411
|
-
|
|
7448
|
+
try {
|
|
7449
|
+
return String.fromCodePoint(code);
|
|
7450
|
+
}
|
|
7451
|
+
catch {
|
|
7412
7452
|
const raw = source.substr(offset - 2, length + 2);
|
|
7413
7453
|
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
7414
7454
|
return raw;
|
|
7415
7455
|
}
|
|
7416
|
-
return String.fromCodePoint(code);
|
|
7417
7456
|
}
|
|
7418
7457
|
|
|
7419
7458
|
function composeScalar(ctx, token, tagToken, onError) {
|
|
@@ -11898,9 +11937,9 @@ var Telepact = (function (exports, msgpackr, crc32) {
|
|
|
11898
11937
|
this.invocations = [];
|
|
11899
11938
|
const serverOptions = new ServerOptions();
|
|
11900
11939
|
serverOptions.onError = options.onError;
|
|
11901
|
-
serverOptions.authRequired = false;
|
|
11902
11940
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
11903
|
-
const functionRouter = new FunctionRouter(
|
|
11941
|
+
const functionRouter = new FunctionRouter();
|
|
11942
|
+
functionRouter.registerUnauthenticatedRoutes(this.createFunctionRoutes(telepactSchema));
|
|
11904
11943
|
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
11905
11944
|
}
|
|
11906
11945
|
random;
|
|
@@ -2,7 +2,12 @@ import { Message } from './Message.js';
|
|
|
2
2
|
export type FunctionRoute = (functionName: string, requestMessage: Message) => Promise<Message>;
|
|
3
3
|
export type FunctionRoutes = Record<string, FunctionRoute>;
|
|
4
4
|
export declare class FunctionRouter {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
authenticatedFunctionRoutes: FunctionRoutes;
|
|
6
|
+
unauthenticatedFunctionRoutes: FunctionRoutes;
|
|
7
|
+
constructor();
|
|
8
|
+
registerAuthenticatedRoutes(functionRoutes: FunctionRoutes): void;
|
|
9
|
+
registerUnauthenticatedRoutes(functionRoutes: FunctionRoutes): void;
|
|
10
|
+
hasAuthenticatedRoutes(): boolean;
|
|
11
|
+
requiresAuthentication(functionName: string): boolean;
|
|
7
12
|
route(requestMessage: Message): Promise<Message>;
|
|
8
13
|
}
|
|
@@ -14,13 +14,34 @@
|
|
|
14
14
|
//| limitations under the License.
|
|
15
15
|
//|
|
|
16
16
|
export class FunctionRouter {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
authenticatedFunctionRoutes;
|
|
18
|
+
unauthenticatedFunctionRoutes;
|
|
19
|
+
constructor() {
|
|
20
|
+
this.authenticatedFunctionRoutes = {};
|
|
21
|
+
this.unauthenticatedFunctionRoutes = {};
|
|
22
|
+
}
|
|
23
|
+
registerAuthenticatedRoutes(functionRoutes) {
|
|
24
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
25
|
+
this.authenticatedFunctionRoutes[functionName] = functionRoute;
|
|
26
|
+
delete this.unauthenticatedFunctionRoutes[functionName];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
registerUnauthenticatedRoutes(functionRoutes) {
|
|
30
|
+
for (const [functionName, functionRoute] of Object.entries(functionRoutes)) {
|
|
31
|
+
this.unauthenticatedFunctionRoutes[functionName] = functionRoute;
|
|
32
|
+
delete this.authenticatedFunctionRoutes[functionName];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
hasAuthenticatedRoutes() {
|
|
36
|
+
return Object.keys(this.authenticatedFunctionRoutes).length > 0;
|
|
37
|
+
}
|
|
38
|
+
requiresAuthentication(functionName) {
|
|
39
|
+
return functionName in this.authenticatedFunctionRoutes;
|
|
20
40
|
}
|
|
21
41
|
async route(requestMessage) {
|
|
22
42
|
const functionName = requestMessage.getBodyTarget();
|
|
23
|
-
const functionRoute = this.
|
|
43
|
+
const functionRoute = this.authenticatedFunctionRoutes[functionName]
|
|
44
|
+
?? this.unauthenticatedFunctionRoutes[functionName];
|
|
24
45
|
if (functionRoute === undefined) {
|
|
25
46
|
throw new Error(`Unknown function: ${functionName}`);
|
|
26
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionRouter.js","sourceRoot":"","sources":["../../src/FunctionRouter.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAOH,MAAM,OAAO,cAAc;IACvB,
|
|
1
|
+
{"version":3,"file":"FunctionRouter.js","sourceRoot":"","sources":["../../src/FunctionRouter.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAOH,MAAM,OAAO,cAAc;IACvB,2BAA2B,CAAiB;IAC5C,6BAA6B,CAAiB;IAE9C;QACI,IAAI,CAAC,2BAA2B,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,6BAA6B,GAAG,EAAE,CAAC;IAC5C,CAAC;IAED,2BAA2B,CAAC,cAA8B;QACtD,KAAK,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,2BAA2B,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC;YAC/D,OAAO,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;IAED,6BAA6B,CAAC,cAA8B;QACxD,KAAK,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACzE,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC;YACjE,OAAO,IAAI,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC;IACL,CAAC;IAED,sBAAsB;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,CAAC;IAED,sBAAsB,CAAC,YAAoB;QACvC,OAAO,YAAY,IAAI,IAAI,CAAC,2BAA2B,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,cAAuB;QAC/B,MAAM,YAAY,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;QACpD,MAAM,aAAa,GAAG,IAAI,CAAC,2BAA2B,CAAC,YAAY,CAAC;eAC7D,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAAC,CAAC;QACxD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAC7D,CAAC;CACJ"}
|
package/dist/src/MockServer.js
CHANGED
|
@@ -30,9 +30,9 @@ export class MockServer {
|
|
|
30
30
|
this.invocations = [];
|
|
31
31
|
const serverOptions = new ServerOptions();
|
|
32
32
|
serverOptions.onError = options.onError;
|
|
33
|
-
serverOptions.authRequired = false;
|
|
34
33
|
const telepactSchema = new TelepactSchema(mockTelepactSchema.original, mockTelepactSchema.full, mockTelepactSchema.parsed, mockTelepactSchema.parsedRequestHeaders, mockTelepactSchema.parsedResponseHeaders);
|
|
35
|
-
const functionRouter = new FunctionRouter(
|
|
34
|
+
const functionRouter = new FunctionRouter();
|
|
35
|
+
functionRouter.registerUnauthenticatedRoutes(this.createFunctionRoutes(telepactSchema));
|
|
36
36
|
this.server = new Server(telepactSchema, functionRouter, serverOptions);
|
|
37
37
|
}
|
|
38
38
|
random;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MockServer.js","sourceRoot":"","sources":["../../src/MockServer.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAkB,MAAM,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACH,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,8BAA8B,GACjC,MAAM,+BAA+B,CAAC;AAKvC,MAAM,OAAO,UAAU;IACnB;;OAEG;IAEH,YAAY,kBAAsC,EAAE,OAA0B;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,4BAA4B,EAAE,OAAO,CAAC,4BAA4B,CAAC,CAAC;QAC9G,IAAI,CAAC,0BAA0B,GAAG,OAAO,CAAC,+BAA+B,CAAC;QAC1E,IAAI,CAAC,6BAA6B,GAAG,OAAO,CAAC,6BAA6B,CAAC;QAC3E,IAAI,CAAC,gCAAgC,GAAG,OAAO,CAAC,gCAAgC,CAAC;QAEjF,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QAEtB,MAAM,aAAa,GAAG,IAAI,aAAa,EA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outer.js';
|
|
7
7
|
import { TelepactError } from './TelepactError.js';
|
|
8
8
|
export type Middleware = (requestMessage: Message, functionRouter: FunctionRouter) => Promise<Message>;
|
|
9
|
+
export type AuthHandler = (headers: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
|
|
9
10
|
export type UpdateHeaders = (headers: Record<string, any>) => void;
|
|
10
11
|
export { FunctionRouter } from './FunctionRouter.js';
|
|
11
12
|
export type { FunctionRoute, FunctionRoutes } from './FunctionRouter.js';
|
|
@@ -15,7 +16,7 @@ export declare class Server {
|
|
|
15
16
|
onError: (error: TelepactError) => void;
|
|
16
17
|
onRequest: (message: Message) => void;
|
|
17
18
|
onResponse: (message: Message) => void;
|
|
18
|
-
onAuth:
|
|
19
|
+
onAuth: AuthHandler;
|
|
19
20
|
telepactSchema: TelepactSchema;
|
|
20
21
|
serializer: Serializer;
|
|
21
22
|
constructor(telepactSchema: TelepactSchema, functionRouter: FunctionRouter | FunctionRoutes, options: ServerOptions);
|
|
@@ -25,9 +26,8 @@ export declare class ServerOptions {
|
|
|
25
26
|
onError: (error: TelepactError) => void;
|
|
26
27
|
onRequest: (message: Message) => void;
|
|
27
28
|
onResponse: (message: Message) => void;
|
|
28
|
-
onAuth:
|
|
29
|
+
onAuth: AuthHandler;
|
|
29
30
|
middleware: Middleware;
|
|
30
|
-
authRequired: boolean;
|
|
31
31
|
serialization: Serialization;
|
|
32
32
|
constructor();
|
|
33
33
|
}
|
package/dist/src/Server.js
CHANGED
|
@@ -32,11 +32,11 @@ export class Server {
|
|
|
32
32
|
telepactSchema;
|
|
33
33
|
serializer;
|
|
34
34
|
constructor(telepactSchema, functionRouter, options) {
|
|
35
|
-
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const normalizedFunctionRouter = functionRouter instanceof FunctionRouter ? functionRouter : new FunctionRouter();
|
|
36
|
+
if (!(functionRouter instanceof FunctionRouter)) {
|
|
37
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(functionRouter);
|
|
38
|
+
}
|
|
39
|
+
normalizedFunctionRouter.registerUnauthenticatedRoutes(createInternalFunctionRoutes(telepactSchema));
|
|
40
40
|
this.functionRouter = normalizedFunctionRouter;
|
|
41
41
|
this.middleware = options.middleware;
|
|
42
42
|
this.onError = options.onError;
|
|
@@ -48,8 +48,8 @@ export class Server {
|
|
|
48
48
|
const binaryEncoder = new ServerBinaryEncoder(binaryEncoding);
|
|
49
49
|
const base64Encoder = new ServerBase64Encoder();
|
|
50
50
|
this.serializer = new Serializer(options.serialization, binaryEncoder, base64Encoder);
|
|
51
|
-
if (!('union.Auth_' in this.telepactSchema.parsed) &&
|
|
52
|
-
throw new Error('
|
|
51
|
+
if (!('union.Auth_' in this.telepactSchema.parsed) && this.functionRouter.hasAuthenticatedRoutes()) {
|
|
52
|
+
throw new Error('Authenticated routes require `union.Auth_` in your schema.');
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
async process(requestMessageBytes, updateHeaders) {
|
|
@@ -62,7 +62,6 @@ export class ServerOptions {
|
|
|
62
62
|
onResponse;
|
|
63
63
|
onAuth;
|
|
64
64
|
middleware;
|
|
65
|
-
authRequired;
|
|
66
65
|
serialization;
|
|
67
66
|
constructor() {
|
|
68
67
|
this.onError = (_error) => { };
|
|
@@ -70,7 +69,6 @@ export class ServerOptions {
|
|
|
70
69
|
this.onResponse = (m) => { };
|
|
71
70
|
this.onAuth = (headers) => ({});
|
|
72
71
|
this.middleware = async (requestMessage, functionRouter) => await functionRouter.route(requestMessage);
|
|
73
|
-
this.authRequired = true;
|
|
74
72
|
this.serialization = new DefaultSerialization();
|
|
75
73
|
}
|
|
76
74
|
}
|
package/dist/src/Server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/Server.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAA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C;CACJ"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Message } from '../Message.js';
|
|
2
2
|
import { TelepactSchema } from '../TelepactSchema.js';
|
|
3
3
|
import { TelepactError } from '../TelepactError.js';
|
|
4
|
-
import { UpdateHeaders } from '../Server.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}) => Promise<Message>, functionRouter: {
|
|
8
|
-
route: (message: Message) => Promise<Message>;
|
|
9
|
-
}, onError: (error: TelepactError) => void, onAuth: (headers: Record<string, any>) => Record<string, any>): Promise<Message>;
|
|
4
|
+
import type { AuthHandler, UpdateHeaders } from '../Server.js';
|
|
5
|
+
import type { FunctionRouter, Middleware } from './ProcessBytes.js';
|
|
6
|
+
export declare function handleMessage(requestMessage: Message, updateHeaders: UpdateHeaders | undefined, telepactSchema: TelepactSchema, middleware: Middleware, functionRouter: FunctionRouter, onError: (error: TelepactError) => void, onAuth: AuthHandler): Promise<Message>;
|
|
@@ -24,7 +24,7 @@ import { ValidateContext } from './validation/ValidateContext.js';
|
|
|
24
24
|
import { serverBase64Decode } from './binary/ServerBase64Decode.js';
|
|
25
25
|
import { TelepactError } from '../TelepactError.js';
|
|
26
26
|
import { buildUnknownErrorMessage } from './UnknownError.js';
|
|
27
|
-
const
|
|
27
|
+
const UNAUTHENTICATED_MESSAGE = 'Valid authentication is required.';
|
|
28
28
|
export async function handleMessage(requestMessage, updateHeaders, telepactSchema, middleware, functionRouter, onError, onAuth) {
|
|
29
29
|
const responseHeaders = {};
|
|
30
30
|
const requestHeaders = requestMessage.headers;
|
|
@@ -34,7 +34,6 @@ export async function handleMessage(requestMessage, updateHeaders, telepactSchem
|
|
|
34
34
|
updateHeaders?.(requestHeaders);
|
|
35
35
|
const requestTargetInit = requestEntry[0];
|
|
36
36
|
const requestPayload = requestEntry[1];
|
|
37
|
-
const bypassAuthForFunction = INTERNAL_FUNCTIONS_BYPASSING_AUTH.has(requestTargetInit);
|
|
38
37
|
let unknownTarget;
|
|
39
38
|
let requestTarget;
|
|
40
39
|
if (!(requestTargetInit in parsedTelepactSchema)) {
|
|
@@ -48,6 +47,7 @@ export async function handleMessage(requestMessage, updateHeaders, telepactSchem
|
|
|
48
47
|
const functionName = requestTarget;
|
|
49
48
|
const callType = parsedTelepactSchema[requestTarget];
|
|
50
49
|
const resultUnionType = parsedTelepactSchema[`${requestTarget}.->`];
|
|
50
|
+
const requiresAuthentication = unknownTarget === null && functionRouter.requiresAuthentication(functionName);
|
|
51
51
|
const callId = requestHeaders['@id_'];
|
|
52
52
|
if (callId !== undefined) {
|
|
53
53
|
responseHeaders['@id_'] = callId;
|
|
@@ -64,9 +64,12 @@ export async function handleMessage(requestMessage, updateHeaders, telepactSchem
|
|
|
64
64
|
if (requestHeaderValidationFailures.length > 0) {
|
|
65
65
|
return getInvalidErrorMessage('ErrorInvalidRequestHeaders_', requestHeaderValidationFailures, resultUnionType, responseHeaders);
|
|
66
66
|
}
|
|
67
|
-
if ('@auth_' in requestHeaders
|
|
67
|
+
if (requiresAuthentication && !('@auth_' in requestHeaders)) {
|
|
68
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
69
|
+
}
|
|
70
|
+
if (requiresAuthentication) {
|
|
68
71
|
try {
|
|
69
|
-
const authHeaders = onAuth(requestHeaders) ?? {};
|
|
72
|
+
const authHeaders = (await onAuth(requestHeaders)) ?? {};
|
|
70
73
|
Object.assign(requestHeaders, authHeaders);
|
|
71
74
|
}
|
|
72
75
|
catch (error) {
|
|
@@ -76,7 +79,7 @@ export async function handleMessage(requestMessage, updateHeaders, telepactSchem
|
|
|
76
79
|
}
|
|
77
80
|
catch (ignored) {
|
|
78
81
|
}
|
|
79
|
-
return
|
|
82
|
+
return buildUnauthenticatedErrorMessage(resultUnionType, responseHeaders);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
if ('@bin_' in requestHeaders) {
|
|
@@ -87,6 +90,15 @@ export async function handleMessage(requestMessage, updateHeaders, telepactSchem
|
|
|
87
90
|
responseHeaders['@pac_'] = requestHeaders['@pac_'];
|
|
88
91
|
}
|
|
89
92
|
}
|
|
93
|
+
function buildUnauthenticatedErrorMessage(resultUnionType, headers) {
|
|
94
|
+
const result = {
|
|
95
|
+
ErrorUnauthenticated_: {
|
|
96
|
+
'message!': UNAUTHENTICATED_MESSAGE,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
validateResult(resultUnionType, result);
|
|
100
|
+
return new Message(headers, result);
|
|
101
|
+
}
|
|
90
102
|
const selectStructFieldsHeader = requestHeaders['@select_'] || null;
|
|
91
103
|
if (unknownTarget !== null) {
|
|
92
104
|
const newErrorResult = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HandleMessage.js","sourceRoot":"","sources":["../../../src/internal/HandleMessage.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAAE,wCAAwC,EAAE,MAAM,0DAA0D,CAAC;AACpH,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAA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7,9 +7,10 @@ import { UpdateHeaders } from '../Server.js';
|
|
|
7
7
|
export type ErrorHandler = (error: TelepactError) => void;
|
|
8
8
|
export type RequestHandler = (message: Message) => void;
|
|
9
9
|
export type ResponseHandler = (message: Message) => void;
|
|
10
|
-
export type AuthHandler = (headers: Record<string, any>) => Record<string, any
|
|
10
|
+
export type AuthHandler = (headers: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
|
|
11
11
|
export type FunctionRouter = {
|
|
12
12
|
route: (message: Message) => Promise<Message>;
|
|
13
|
+
requiresAuthentication: (functionName: string) => boolean;
|
|
13
14
|
};
|
|
14
15
|
export type Middleware = (requestMessage: Message, functionRouter: FunctionRouter) => Promise<Message>;
|
|
15
16
|
export declare function processBytes(requestMessageBytes: Uint8Array, updateHeaders: UpdateHeaders | undefined, serializer: Serializer, telepactSchema: TelepactSchema, onError: ErrorHandler, onRequest: RequestHandler, onResponse: ResponseHandler, onAuth: AuthHandler, middleware: Middleware, functionRouter: FunctionRouter): Promise<Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessBytes.js","sourceRoot":"","sources":["../../../src/internal/ProcessBytes.ts"],"names":[],"mappings":"AAAA,GAAG;AACH,mCAAmC;AACnC,GAAG;AACH,oEAAoE;AACpE,qEAAqE;AACrE,4CAA4C;AAC5C,GAAG;AACH,gDAAgD;AAChD,GAAG;AACH,wEAAwE;AACxE,sEAAsE;AACtE,6EAA6E;AAC7E,wEAAwE;AACxE,mCAAmC;AACnC,GAAG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"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