@routr/common 2.31.4 → 2.31.5
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/dist/identity.d.ts +22 -3
- package/dist/identity.js +30 -5
- package/package.json +2 -2
package/dist/identity.d.ts
CHANGED
|
@@ -25,12 +25,22 @@ export interface Identity {
|
|
|
25
25
|
port?: number;
|
|
26
26
|
userParam?: string;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The port a SIP URI names, or undefined when it names none (the EdgePort's
|
|
30
|
+
* converter spells "no port" as -1, an unset field reads 0).
|
|
31
|
+
*
|
|
32
|
+
* @param {SipURI} uri - The URI
|
|
33
|
+
* @return {number | undefined} The port
|
|
34
|
+
*/
|
|
35
|
+
export declare const portOf: (uri: SipURI) => number | undefined;
|
|
28
36
|
/**
|
|
29
37
|
* Encodes an identity as base64url, which keeps it a SIP token (RFC 3261
|
|
30
|
-
* section 25.1)
|
|
38
|
+
* section 25.1) and unreserved in a URI user part (section 25.1, "unreserved"):
|
|
39
|
+
* no quoting or escaping, and it survives every hop unchanged.
|
|
31
40
|
*
|
|
32
|
-
* @param {SipURI} uri - The URI whose user, host and user parameter to
|
|
33
|
-
*
|
|
41
|
+
* @param {SipURI} uri - The URI whose user, host, port and user parameter to
|
|
42
|
+
* encode; the port only when it names one
|
|
43
|
+
* @return {string} The base64url value of user@host[:port][;user=...]
|
|
34
44
|
*/
|
|
35
45
|
export declare const encodeIdentity: (uri: SipURI) => string;
|
|
36
46
|
/**
|
|
@@ -51,3 +61,12 @@ export declare const decodeIdentity: (value?: string) => Identity | undefined;
|
|
|
51
61
|
* parameter name, or undefined when the user part is not of this form
|
|
52
62
|
*/
|
|
53
63
|
export declare const decodeIdentityUser: (user?: string) => Record<string, string> | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Writes the identity mapping as a Route URI user part, the form
|
|
66
|
+
* decodeIdentityUser reads: rfo.<b64>.rfn.<b64>.rco.<b64>.rcn.<b64>, in that
|
|
67
|
+
* order, absent pairs left out.
|
|
68
|
+
*
|
|
69
|
+
* @param {Record<string, string>} values - The base64url values by parameter name
|
|
70
|
+
* @return {string | undefined} The user part, or undefined when there are none
|
|
71
|
+
*/
|
|
72
|
+
export declare const encodeIdentityUser: (values: Record<string, string>) => string | undefined;
|
package/dist/identity.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeIdentityUser = exports.decodeIdentity = exports.encodeIdentity = exports.IDENTITY_PARAMETER_NAMES = exports.IDENTITY_PARAMETERS = void 0;
|
|
3
|
+
exports.encodeIdentityUser = exports.decodeIdentityUser = exports.decodeIdentity = exports.encodeIdentity = exports.portOf = exports.IDENTITY_PARAMETER_NAMES = exports.IDENTITY_PARAMETERS = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The caller identity Routr rewrites toward a Trunk travels in its own
|
|
6
6
|
* Record-Route, as parameters or in the URI user part, so the dialog's later
|
|
@@ -20,16 +20,28 @@ exports.IDENTITY_PARAMETERS = {
|
|
|
20
20
|
};
|
|
21
21
|
/** Every identity parameter name, in the order above. */
|
|
22
22
|
exports.IDENTITY_PARAMETER_NAMES = Object.values(exports.IDENTITY_PARAMETERS);
|
|
23
|
+
/**
|
|
24
|
+
* The port a SIP URI names, or undefined when it names none (the EdgePort's
|
|
25
|
+
* converter spells "no port" as -1, an unset field reads 0).
|
|
26
|
+
*
|
|
27
|
+
* @param {SipURI} uri - The URI
|
|
28
|
+
* @return {number | undefined} The port
|
|
29
|
+
*/
|
|
30
|
+
const portOf = (uri) => uri.port > 0 ? uri.port : undefined;
|
|
31
|
+
exports.portOf = portOf;
|
|
23
32
|
/**
|
|
24
33
|
* Encodes an identity as base64url, which keeps it a SIP token (RFC 3261
|
|
25
|
-
* section 25.1)
|
|
34
|
+
* section 25.1) and unreserved in a URI user part (section 25.1, "unreserved"):
|
|
35
|
+
* no quoting or escaping, and it survives every hop unchanged.
|
|
26
36
|
*
|
|
27
|
-
* @param {SipURI} uri - The URI whose user, host and user parameter to
|
|
28
|
-
*
|
|
37
|
+
* @param {SipURI} uri - The URI whose user, host, port and user parameter to
|
|
38
|
+
* encode; the port only when it names one
|
|
39
|
+
* @return {string} The base64url value of user@host[:port][;user=...]
|
|
29
40
|
*/
|
|
30
41
|
const encodeIdentity = (uri) => {
|
|
31
42
|
var _a;
|
|
32
|
-
|
|
43
|
+
const port = (0, exports.portOf)(uri);
|
|
44
|
+
return Buffer.from(`${(_a = uri.user) !== null && _a !== void 0 ? _a : ""}@${uri.host}${port ? `:${port}` : ""}${uri.userParam ? `;user=${uri.userParam}` : ""}`).toString("base64url");
|
|
33
45
|
};
|
|
34
46
|
exports.encodeIdentity = encodeIdentity;
|
|
35
47
|
/**
|
|
@@ -77,3 +89,16 @@ const decodeIdentityUser = (user) => {
|
|
|
77
89
|
return valid ? Object.fromEntries(pairs) : undefined;
|
|
78
90
|
};
|
|
79
91
|
exports.decodeIdentityUser = decodeIdentityUser;
|
|
92
|
+
/**
|
|
93
|
+
* Writes the identity mapping as a Route URI user part, the form
|
|
94
|
+
* decodeIdentityUser reads: rfo.<b64>.rfn.<b64>.rco.<b64>.rcn.<b64>, in that
|
|
95
|
+
* order, absent pairs left out.
|
|
96
|
+
*
|
|
97
|
+
* @param {Record<string, string>} values - The base64url values by parameter name
|
|
98
|
+
* @return {string | undefined} The user part, or undefined when there are none
|
|
99
|
+
*/
|
|
100
|
+
const encodeIdentityUser = (values) => {
|
|
101
|
+
const pairs = exports.IDENTITY_PARAMETER_NAMES.filter((name) => values[name]).map((name) => `${name}.${values[name]}`);
|
|
102
|
+
return pairs.length > 0 ? pairs.join(".") : undefined;
|
|
103
|
+
};
|
|
104
|
+
exports.encodeIdentityUser = encodeIdentityUser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/common",
|
|
3
|
-
"version": "2.31.
|
|
3
|
+
"version": "2.31.5",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/js-yaml": "^4.0.5"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "c0b54abe054aee1c28d6bc5c3402ba4bedba31a9"
|
|
65
65
|
}
|