@milaboratories/pl-model-common 1.20.1 → 1.21.0
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/httpAuth.cjs +30 -0
- package/dist/httpAuth.cjs.map +1 -0
- package/dist/httpAuth.d.ts +9 -0
- package/dist/httpAuth.d.ts.map +1 -0
- package/dist/httpAuth.js +27 -0
- package/dist/httpAuth.js.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/httpAuth.ts +34 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */
|
|
4
|
+
function parseHttpAuth(input) {
|
|
5
|
+
const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);
|
|
6
|
+
if (match?.groups?.scheme === 'Basic') {
|
|
7
|
+
const credentialsMatch = /(?<username>.*?):(?<password>.*)/
|
|
8
|
+
.exec(atob(match.groups.parameters));
|
|
9
|
+
if (!credentialsMatch?.groups) {
|
|
10
|
+
throw new Error(`Malformed credentials.`);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
scheme: 'Basic',
|
|
14
|
+
username: credentialsMatch.groups.username,
|
|
15
|
+
password: credentialsMatch.groups.password,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
19
|
+
}
|
|
20
|
+
function serializeHttpAuth(input) {
|
|
21
|
+
if (input.scheme === 'Basic') {
|
|
22
|
+
return `Basic ${btoa(`${input.username}:${input.password}`)}`;
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
25
|
+
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.parseHttpAuth = parseHttpAuth;
|
|
29
|
+
exports.serializeHttpAuth = serializeHttpAuth;
|
|
30
|
+
//# sourceMappingURL=httpAuth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAuth.cjs","sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === 'Basic') {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/\n .exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: 'Basic',\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === 'Basic') {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Unsupported auth scheme: ${input.scheme}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: 'Basic';\n username: string;\n password: string;\n}\n"],"names":[],"mappings":";;AAAA;AAEM,SAAU,aAAa,CAAC,KAAa,EAAA;IACzC,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,KAAK,CAAC;IAC5D,IAAI,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,EAAE;QACrC,MAAM,gBAAgB,GAAG;aACtB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACtC,QAAA,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE;AAC7B,YAAA,MAAM,IAAI,KAAK,CAAC,CAAA,sBAAA,CAAwB,CAAC;QAC3C;QACA,OAAO;AACL,YAAA,MAAM,EAAE,OAAO;AACf,YAAA,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;AAC1C,YAAA,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;SAC3C;IACH;IACA,MAAM,IAAI,KAAK,CAAC,CAAA,yBAAA,EAA4B,KAAK,EAAE,MAAM,EAAE,MAAM,CAAA,CAAA,CAAG,CAAC;AACvE;AAEM,SAAU,iBAAiB,CAAC,KAAe,EAAA;AAC/C,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE;AAC5B,QAAA,OAAO,CAAA,MAAA,EAAS,IAAI,CAAC,CAAA,EAAG,KAAK,CAAC,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,QAAQ,CAAA,CAAE,CAAC,EAAE;IAC/D;;IAEA,MAAM,IAAI,KAAK,CAAC,CAAA,yBAAA,EAA4B,KAAK,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;AAC9D;;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function parseHttpAuth(input: string): HttpAuth;
|
|
2
|
+
export declare function serializeHttpAuth(input: HttpAuth): string;
|
|
3
|
+
export type HttpAuth = BasicHttpAuth;
|
|
4
|
+
export interface BasicHttpAuth {
|
|
5
|
+
scheme: 'Basic';
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=httpAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAuth.d.ts","sourceRoot":"","sources":["../src/httpAuth.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAerD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAMzD;AAED,MAAM,MAAM,QAAQ,GAAG,aAAa,CAAC;AAErC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/httpAuth.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */
|
|
2
|
+
function parseHttpAuth(input) {
|
|
3
|
+
const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);
|
|
4
|
+
if (match?.groups?.scheme === 'Basic') {
|
|
5
|
+
const credentialsMatch = /(?<username>.*?):(?<password>.*)/
|
|
6
|
+
.exec(atob(match.groups.parameters));
|
|
7
|
+
if (!credentialsMatch?.groups) {
|
|
8
|
+
throw new Error(`Malformed credentials.`);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
scheme: 'Basic',
|
|
12
|
+
username: credentialsMatch.groups.username,
|
|
13
|
+
password: credentialsMatch.groups.password,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
17
|
+
}
|
|
18
|
+
function serializeHttpAuth(input) {
|
|
19
|
+
if (input.scheme === 'Basic') {
|
|
20
|
+
return `Basic ${btoa(`${input.username}:${input.password}`)}`;
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
23
|
+
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { parseHttpAuth, serializeHttpAuth };
|
|
27
|
+
//# sourceMappingURL=httpAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAuth.js","sources":["../src/httpAuth.ts"],"sourcesContent":["/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */\n\nexport function parseHttpAuth(input: string): HttpAuth {\n const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);\n if (match?.groups?.scheme === 'Basic') {\n const credentialsMatch = /(?<username>.*?):(?<password>.*)/\n .exec(atob(match.groups.parameters));\n if (!credentialsMatch?.groups) {\n throw new Error(`Malformed credentials.`);\n }\n return {\n scheme: 'Basic',\n username: credentialsMatch.groups.username,\n password: credentialsMatch.groups.password,\n };\n }\n throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);\n}\n\nexport function serializeHttpAuth(input: HttpAuth): string {\n if (input.scheme === 'Basic') {\n return `Basic ${btoa(`${input.username}:${input.password}`)}`;\n }\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Unsupported auth scheme: ${input.scheme}.`);\n}\n\nexport type HttpAuth = BasicHttpAuth;\n\nexport interface BasicHttpAuth {\n scheme: 'Basic';\n username: string;\n password: string;\n}\n"],"names":[],"mappings":"AAAA;AAEM,SAAU,aAAa,CAAC,KAAa,EAAA;IACzC,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,KAAK,CAAC;IAC5D,IAAI,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,EAAE;QACrC,MAAM,gBAAgB,GAAG;aACtB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACtC,QAAA,IAAI,CAAC,gBAAgB,EAAE,MAAM,EAAE;AAC7B,YAAA,MAAM,IAAI,KAAK,CAAC,CAAA,sBAAA,CAAwB,CAAC;QAC3C;QACA,OAAO;AACL,YAAA,MAAM,EAAE,OAAO;AACf,YAAA,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;AAC1C,YAAA,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAAQ;SAC3C;IACH;IACA,MAAM,IAAI,KAAK,CAAC,CAAA,yBAAA,EAA4B,KAAK,EAAE,MAAM,EAAE,MAAM,CAAA,CAAA,CAAG,CAAC;AACvE;AAEM,SAAU,iBAAiB,CAAC,KAAe,EAAA;AAC/C,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,EAAE;AAC5B,QAAA,OAAO,CAAA,MAAA,EAAS,IAAI,CAAC,CAAA,EAAG,KAAK,CAAC,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,QAAQ,CAAA,CAAE,CAAC,EAAE;IAC/D;;IAEA,MAAM,IAAI,KAAK,CAAC,CAAA,yBAAA,EAA4B,KAAK,CAAC,MAAM,CAAA,CAAA,CAAG,CAAC;AAC9D;;;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var ref = require('./ref.cjs');
|
|
|
29
29
|
var value_or_error = require('./value_or_error.cjs');
|
|
30
30
|
var base64 = require('./base64.cjs');
|
|
31
31
|
var util = require('./util.cjs');
|
|
32
|
+
var httpAuth = require('./httpAuth.cjs');
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
@@ -153,4 +154,6 @@ exports.base64Decode = base64.base64Decode;
|
|
|
153
154
|
exports.base64Encode = base64.base64Encode;
|
|
154
155
|
exports.assertNever = util.assertNever;
|
|
155
156
|
exports.uniqueBy = util.uniqueBy;
|
|
157
|
+
exports.parseHttpAuth = httpAuth.parseHttpAuth;
|
|
158
|
+
exports.serializeHttpAuth = httpAuth.serializeHttpAuth;
|
|
156
159
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -27,4 +27,5 @@ export { PlRef, createPlRef, isPlRef, plRefsEqual, withEnrichments } from './ref
|
|
|
27
27
|
export { mapValueInVOE } from './value_or_error.js';
|
|
28
28
|
export { base64Decode, base64Encode } from './base64.js';
|
|
29
29
|
export { assertNever, uniqueBy } from './util.js';
|
|
30
|
+
export { parseHttpAuth, serializeHttpAuth } from './httpAuth.js';
|
|
30
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-model-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Platforma SDK Model",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"eslint": "^9.25.1",
|
|
26
26
|
"typescript": "~5.6.3",
|
|
27
27
|
"vitest": "^2.1.9",
|
|
28
|
-
"@
|
|
28
|
+
"@platforma-sdk/eslint-config": "1.1.0",
|
|
29
29
|
"@milaboratories/ts-builder": "1.0.5",
|
|
30
30
|
"@milaboratories/ts-configs": "1.0.6",
|
|
31
|
-
"@
|
|
31
|
+
"@milaboratories/build-configs": "1.0.8"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"type-check": "ts-builder types --target node",
|
package/src/httpAuth.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* TODO: replace atob/btoa with Uint8Array.toBase64/fromBase64 in the future */
|
|
2
|
+
|
|
3
|
+
export function parseHttpAuth(input: string): HttpAuth {
|
|
4
|
+
const match = /(?<scheme>.*?) (?<parameters>.*)/.exec(input);
|
|
5
|
+
if (match?.groups?.scheme === 'Basic') {
|
|
6
|
+
const credentialsMatch = /(?<username>.*?):(?<password>.*)/
|
|
7
|
+
.exec(atob(match.groups.parameters));
|
|
8
|
+
if (!credentialsMatch?.groups) {
|
|
9
|
+
throw new Error(`Malformed credentials.`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
scheme: 'Basic',
|
|
13
|
+
username: credentialsMatch.groups.username,
|
|
14
|
+
password: credentialsMatch.groups.password,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
throw new Error(`Unsupported auth scheme: ${match?.groups?.scheme}.`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function serializeHttpAuth(input: HttpAuth): string {
|
|
21
|
+
if (input.scheme === 'Basic') {
|
|
22
|
+
return `Basic ${btoa(`${input.username}:${input.password}`)}`;
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
25
|
+
throw new Error(`Unsupported auth scheme: ${input.scheme}.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type HttpAuth = BasicHttpAuth;
|
|
29
|
+
|
|
30
|
+
export interface BasicHttpAuth {
|
|
31
|
+
scheme: 'Basic';
|
|
32
|
+
username: string;
|
|
33
|
+
password: string;
|
|
34
|
+
}
|
package/src/index.ts
CHANGED