@nsshunt/stsutils 1.15.34 → 1.15.35
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/stsutils.mjs +26 -21
- package/dist/stsutils.mjs.map +1 -1
- package/dist/stsutils.umd.js +1 -1
- package/dist/stsutils.umd.js.map +1 -1
- package/package.json +5 -5
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/stsutils.test.d.ts +1 -0
package/dist/stsutils.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var n = (E, e, o) => (
|
|
4
|
-
import
|
|
1
|
+
var t = Object.defineProperty;
|
|
2
|
+
var N = (E, e, o) => e in E ? t(E, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : E[e] = o;
|
|
3
|
+
var n = (E, e, o) => (N(E, typeof e != "symbol" ? e + "" : e, o), o);
|
|
4
|
+
import f from "ajv/dist/jtd";
|
|
5
5
|
function I(E, e = null) {
|
|
6
6
|
return {
|
|
7
7
|
error: E.code,
|
|
@@ -12,26 +12,29 @@ function I(E, e = null) {
|
|
|
12
12
|
details: e
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
function
|
|
17
|
-
|
|
15
|
+
const i = new f(), T = (E, e) => E(e) ? null : E.errors;
|
|
16
|
+
function g(E, e) {
|
|
17
|
+
i.addSchema(e, E);
|
|
18
|
+
}
|
|
19
|
+
function S(E, e) {
|
|
20
|
+
const o = i.getSchema(E);
|
|
18
21
|
if (o)
|
|
19
22
|
return T(o, e);
|
|
20
23
|
}
|
|
21
|
-
class
|
|
24
|
+
class F {
|
|
22
25
|
constructor(e = null) {
|
|
23
26
|
n(this, "_options");
|
|
24
|
-
this._options = e, e !== null && (typeof e.validator > "u" ||
|
|
27
|
+
this._options = e, e !== null && (typeof e.validator > "u" || S(e.validator, e));
|
|
25
28
|
}
|
|
26
29
|
get options() {
|
|
27
30
|
return this._options;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
|
-
async function
|
|
33
|
+
async function l(E = 1e3) {
|
|
31
34
|
return new Promise((e) => setTimeout(e, E));
|
|
32
35
|
}
|
|
33
|
-
async function
|
|
34
|
-
return
|
|
36
|
+
async function A() {
|
|
37
|
+
return l(100);
|
|
35
38
|
}
|
|
36
39
|
var U = /* @__PURE__ */ ((E) => (E.AUDIENCE = "AUDIENCE", E.CLIENT_ID = "client_id", E.CLIENT_SECRET = "client_secret", E.RESPONSE_TYPE = "response_type", E.SCOPE = "scope", E.STATE = "state", E.REDIRECT_URI = "redirect_uri", E.ERROR = "error", E.ERROR_DESCRIPTION = "error_description", E.ERROR_CODES = "error_codes", E.ERROR_URI = "error_uri", E.GRANT_TYPE = "grant_type", E.CODE = "code", E.ACCESS_TOKEN = "access_token", E.TOKEN_TYPE = "token_type", E.EXPIRES_IN = "expires_in", E.USERNAME = "username", E.PASSWORD = "password", E.REFRESH_TOKEN = "refresh_token", E.RESPONSE_MODE = "response_mode", E.TIMESTAMP = "timestamp", E.TRACE_ID = "trace_id", E.CORRELATION_ID = "correlation_id", E))(U || {}), L = /* @__PURE__ */ ((E) => (E.SUB = "sub", E.NAME = "name", E.GIVEN_NAME = "given_name", E.FAMILY_NAME = "family_name", E.MIDDLE_NAME = "middle_name", E.NICKNAME = "nickname", E.PREFERRED_USERNAME = "preferred_username", E.PROFILE = "profile", E.PICTURE = "picture", E.WEBSITE = "website", E.EMAIL = "email", E.EMAIL_VERIFIED = "email_verified", E.GENDER = "gender", E.BIRTHDATE = "birthdate", E.ZONEINFO = "zoneinfo", E.LOCALE = "locale", E.PHONE_NUMBER = "phone_number", E.PHONE_NUMBER_VERIFIED = "phone_number_verified", E.ADDRESS = "address", E.CLIENT_SECRET = "client_secret", E.NONCE = "nonce", E))(L || {}), M = /* @__PURE__ */ ((E) => (E.FORMATTED = "formatted", E.STREET_ADDRESS = "street_address", E.LOCALITY = "locality", E.REGION = "region", E.COUNTRY = "country", E))(M || {});
|
|
37
40
|
class _ {
|
|
@@ -52,34 +55,36 @@ n(_, "NOT_EQUAL", {
|
|
|
52
55
|
function H(E, e, o) {
|
|
53
56
|
const c = [];
|
|
54
57
|
for (let s = 0; s < o.length; s++) {
|
|
55
|
-
const
|
|
58
|
+
const R = o[s];
|
|
56
59
|
if (E[s].localeCompare(e[s]) !== 0) {
|
|
57
|
-
const
|
|
60
|
+
const r = {
|
|
58
61
|
error: _.NOT_EQUAL.code,
|
|
59
62
|
error_description: _.NOT_EQUAL.description,
|
|
60
63
|
timestamp: Date.now(),
|
|
61
|
-
details: `${_.NOT_EQUAL.description}: Parameter: [${
|
|
64
|
+
details: `${_.NOT_EQUAL.description}: Parameter: [${R}]`
|
|
62
65
|
};
|
|
63
|
-
c.push(
|
|
66
|
+
c.push(r);
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
return c;
|
|
67
70
|
}
|
|
68
71
|
const v = {};
|
|
69
|
-
function
|
|
72
|
+
function d() {
|
|
70
73
|
return v;
|
|
71
74
|
}
|
|
72
75
|
export {
|
|
73
76
|
v as $stsgd,
|
|
74
|
-
|
|
77
|
+
d as $stsgdf,
|
|
78
|
+
g as AddSchema,
|
|
75
79
|
I as GetErrorPayload,
|
|
76
|
-
|
|
80
|
+
A as JestSleep,
|
|
77
81
|
_ as OAuth2ParameterErrorType,
|
|
78
82
|
U as OAuth2ParameterType,
|
|
79
83
|
M as OIDCAddressClaim,
|
|
80
84
|
L as OIDCStandardClaim,
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
F as STSOptionsBase,
|
|
86
|
+
l as Sleep,
|
|
87
|
+
S as Validate,
|
|
83
88
|
H as compareParameterTypes
|
|
84
89
|
};
|
|
85
90
|
//# sourceMappingURL=stsutils.mjs.map
|
package/dist/stsutils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stsutils.mjs","sources":["../src/errorhandling.ts","../src/validate.ts","../src/stsoptionsbase.ts","../src/sleep.ts","../src/oauth2terms.ts","../src/index.ts"],"sourcesContent":["export type errorCode = {\n\tcode: string\n\tdescription: string\n}\n\nexport type errorPayload = {\n\terror: string,\n\terror_description: string,\n\ttimestamp: number,\n\t//trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n\t//correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n\tdetails?: unknown\n}\n\nexport function GetErrorPayload(errorCode: errorCode, details: unknown = null): errorPayload {\n return {\n error: errorCode.code,\n error_description: errorCode.description,\n timestamp: Date.now(),\n //trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n //correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n details: details\n }\n}\n","import Ajv, { Schema } from 'ajv/dist/jtd'\n\nimport { JSONObject } from './index'\nimport { AnyValidateFunction } from 'ajv/dist/core';\n\nconst ajv = new Ajv();\n\nconst _Validate = (validator: AnyValidateFunction<unknown>, payload: JSONObject): unknown | null => {\n const valid: boolean = validator(payload) as boolean;\n if (!valid) {\n return validator.errors;\n } else {\n return null;\n }\n /*\n\t\tconsole.error(validator.errors);\n\t\tconsole.trace('Invalid Schema');\n\t\tconsole.log('Payload:-');\n\t\tconsole.log(JSON.stringify(payload));\n\t\tprocess.exit(1);\n\t\t*/\n};\n\nexport function AddSchema(name: string, schema: Schema): void {\n ajv.addSchema(schema, name);\n /*\n\treturn (payload) => {\n\t\tconst validator = ajv.getSchema(name)\n\t\t_Validate(validator, payload)\n\t}*/\n\n}\n\nexport function Validate(name: string, payload: JSONObject): unknown {\n const validator: AnyValidateFunction<unknown> | undefined = ajv.getSchema(name)\n if (validator) {\n return _Validate(validator, payload);\n }\n}\n","import { Validate } from './validate.js'\n\nimport { JSONObject } from './index'\n\nexport class STSOptionsBase\n{\n private _options: JSONObject | null;\n\n constructor(options: JSONObject | null = null)\n {\n this._options = options;\n\n if (options !== null) {\n if (typeof options.validator === 'undefined') {\n //console.log(JSON.stringify(options));\n //console.trace(\"Options Here ------------------------------------------------------------------------------------------\")\n } else {\n Validate(options.validator as string, options);\n }\n }\n }\n\n get options()\n {\n return this._options;\n }\n}\n","export async function Sleep(milliseconds = 1000): Promise<void> { \n return new Promise(resolve => setTimeout(resolve, milliseconds))\n}\n \n// poolsleep is required to avoid JEST reporting unclosed handles during shutdown of all tests\nexport async function JestSleep(): Promise<void> {\n return Sleep(100);\n}\n","import { errorCode, errorPayload } from './errorhandling'\n\n// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A\nexport enum OAuth2ParameterType {\n\tAUDIENCE = 'AUDIENCE', // STS Extension\n\tCLIENT_ID = 'client_id',\n\tCLIENT_SECRET = 'client_secret',\n\tRESPONSE_TYPE = 'response_type',\n\tSCOPE = 'scope',\n\tSTATE = 'state',\n\tREDIRECT_URI = 'redirect_uri',\n\tERROR = 'error',\n\tERROR_DESCRIPTION = 'error_description',\n\tERROR_CODES = 'error_codes', // STS Extension\n\tERROR_URI = 'error_uri',\n\tGRANT_TYPE = 'grant_type',\n\tCODE = 'code',\n\tACCESS_TOKEN = 'access_token',\n\tTOKEN_TYPE = 'token_type',\n\tEXPIRES_IN = 'expires_in',\n\tUSERNAME = 'username',\n\tPASSWORD = 'password',\n\tREFRESH_TOKEN = 'refresh_token',\n\tRESPONSE_MODE = 'response_mode', // STS Extension\n\tTIMESTAMP = 'timestamp', // STS Extension\n\tTRACE_ID = 'trace_id', // STS Extension\n\tCORRELATION_ID = 'correlation_id' // STS Extension\n}\n\n// OIDC Standard Claims\n// Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims\nexport enum OIDCStandardClaim {\n\tSUB = 'sub',\n\tNAME = 'name',\n\tGIVEN_NAME = 'given_name',\n\tFAMILY_NAME = 'family_name',\n\tMIDDLE_NAME = 'middle_name',\n\tNICKNAME = 'nickname',\n\tPREFERRED_USERNAME = 'preferred_username',\n\tPROFILE = 'profile',\n\tPICTURE = 'picture',\n\tWEBSITE = 'website',\n\tEMAIL = 'email',\n\tEMAIL_VERIFIED = 'email_verified',\n\tGENDER = 'gender',\n\tBIRTHDATE = 'birthdate',\n\tZONEINFO = 'zoneinfo',\n\tLOCALE = 'locale',\n\tPHONE_NUMBER = 'phone_number',\n\tPHONE_NUMBER_VERIFIED = 'phone_number_verified',\n\tADDRESS = 'address',\n\tCLIENT_SECRET = 'client_secret',\n\tNONCE = 'nonce' // STS Extension\n}\n\nexport enum OIDCAddressClaim {\n\tFORMATTED = 'formatted',\n\tSTREET_ADDRESS = 'street_address',\n\tLOCALITY = 'locality',\n\tREGION = 'region',\n\tCOUNTRY = 'country'\n}\n\nexport class OAuth2ParameterErrorType {\n static readonly NOT_EQUAL: errorCode = {\n code: 'STS_OAUTH2_ERR_0001',\n description: 'Parameter values not equal.'\n }\n static readonly NOT_PRESENT: errorCode = {\n code: 'STS_OAUTH2_ERR_0002',\n description: 'Parameter not provided.'\n }\n static readonly INVALID_FORMAT: errorCode = {\n code: 'STS_OAUTH2_ERR_0003',\n description: 'Parameter value format invalid.'\n }\n static readonly EXPIRED: errorCode = {\n code: 'STS_OAUTH2_ERR_0004',\n description: 'Parameter value expired.'\n }\n}\n\nexport function compareParameterTypes(source1: string[], source2: string[], authParameterTypes: OAuth2ParameterType[]): errorPayload[] {\n const errors: errorPayload[] = [ ];\n for (let i=0 ; i < authParameterTypes.length; i++) {\n const authParameterType = authParameterTypes[i];\n if (source1[i].localeCompare(source2[i]) !== 0) {\n const error: errorPayload = {\n error: OAuth2ParameterErrorType.NOT_EQUAL.code,\n error_description: OAuth2ParameterErrorType.NOT_EQUAL.description,\n timestamp: Date.now(),\n details: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`\n }\n errors.push(error);\n }\n }\n return errors;\n}\n","/*\nexport interface JSONObject {\n [x: string]: string | number | boolean | string[] | number[] | boolean[] | Array<JSONObject> | JSONObject | ((p: any) => any) | undefined\n}\n// This also works :-\n//interface JSONObject2 extends Record<string, string | number | string[] | Array<JSONObject2> | JSONObject2> {};\n*/\n\nexport interface JSONObject {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [x: string]: any | JSONObject | undefined\n}\n\nexport * from './errorhandling'\nexport * from './stsoptionsbase'\nexport * from './sleep'\n//export * from './validate'\nexport * from './oauth2terms'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const $stsgd: Record<string, any> = { };\n\nexport function $stsgdf<T>(): Record<string, T> {\n return $stsgd as Record<string, T>;\n}\n"],"names":["GetErrorPayload","errorCode","details","ajv","Ajv","_Validate","validator","payload","Validate","name","STSOptionsBase","options","__publicField","Sleep","milliseconds","resolve","JestSleep","OAuth2ParameterType","OIDCStandardClaim","OIDCAddressClaim","OAuth2ParameterErrorType","compareParameterTypes","source1","source2","authParameterTypes","errors","i","authParameterType","error","$stsgd","$stsgdf"],"mappings":";;;;AAcgB,SAAAA,EAAgBC,GAAsBC,IAAmB,MAAoB;AAClF,SAAA;AAAA,IACH,OAAOD,EAAU;AAAA,IACjB,mBAAmBA,EAAU;AAAA,IAC7B,WAAW,KAAK,IAAI;AAAA;AAAA;AAAA,IAGpB,SAAAC;AAAA,EAAA;AAER;AClBA,MAAMC,IAAM,IAAIC,KAEVC,IAAY,CAACC,GAAyCC,MACjCD,EAAUC,CAAO,IAI7B,OAFAD,EAAU;AAuBT,SAAAE,EAASC,GAAcF,GAA8B;AAC3D,QAAAD,IAAsDH,EAAI,UAAUM,CAAI;AAC9E,MAAIH;AACO,WAAAD,EAAUC,GAAWC,CAAO;AAE3C;AClCO,MAAMG,EACb;AAAA,EAGI,YAAYC,IAA6B,MACzC;AAHQ,IAAAC,EAAA;AAIJ,SAAK,WAAWD,GAEZA,MAAY,SACR,OAAOA,EAAQ,YAAc,OAIpBH,EAAAG,EAAQ,WAAqBA,CAAO;AAAA,EAGzD;AAAA,EAEA,IAAI,UACJ;AACI,WAAO,KAAK;AAAA,EAChB;AACJ;AC1BsB,eAAAE,EAAMC,IAAe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AAQL,MAAMC,EAAyB;AAiBtC;AAhBIR,EADSQ,GACO,aAAuB;AAAA,EACnC,MAAM;AAAA,EACN,aAAa;AAAA,IAEjBR,EALSQ,GAKO,eAAyB;AAAA,EACrC,MAAM;AAAA,EACN,aAAa;AAAA,IAEjBR,EATSQ,GASO,kBAA4B;AAAA,EACxC,MAAM;AAAA,EACN,aAAa;AAAA,IAEjBR,EAbSQ,GAaO,WAAqB;AAAA,EACjC,MAAM;AAAA,EACN,aAAa;AAAA;AAIL,SAAAC,EAAsBC,GAAmBC,GAAmBC,GAA2D;AACnI,QAAMC,IAAyB,CAAA;AAC/B,WAASC,IAAE,GAAIA,IAAIF,EAAmB,QAAQE,KAAK;AACzC,UAAAC,IAAoBH,EAAmBE,CAAC;AAC1C,QAAAJ,EAAQI,CAAC,EAAE,cAAcH,EAAQG,CAAC,CAAC,MAAM,GAAG;AAC5C,YAAME,IAAsB;AAAA,QACxB,OAAOR,EAAyB,UAAU;AAAA,QAC1C,mBAAmBA,EAAyB,UAAU;AAAA,QACtD,WAAW,KAAK,IAAI;AAAA,QACpB,SAAS,GAAGA,EAAyB,UAAU,4BAA4BO;AAAA,MAAA;AAE/E,MAAAF,EAAO,KAAKG,CAAK;AAAA;AAAA;AAGlB,SAAAH;AACX;AC7EO,MAAMI,IAA8B,CAAE;AAEtC,SAASC,IAAgC;AACrC,SAAAD;AACX;"}
|
|
1
|
+
{"version":3,"file":"stsutils.mjs","sources":["../src/errorhandling.ts","../src/validate.ts","../src/stsoptionsbase.ts","../src/sleep.ts","../src/oauth2terms.ts","../src/index.ts"],"sourcesContent":["export type errorCode = {\n\tcode: string\n\tdescription: string\n}\n\nexport type errorPayload = {\n\terror: string,\n\terror_description: string,\n\ttimestamp: number,\n\t//trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n\t//correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n\tdetails?: unknown\n}\n\nexport function GetErrorPayload(errorCode: errorCode, details: unknown = null): errorPayload {\n return {\n error: errorCode.code,\n error_description: errorCode.description,\n timestamp: Date.now(),\n //trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n //correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n details: details\n }\n}\n","import Ajv, { Schema } from 'ajv/dist/jtd'\n\nimport { JSONObject } from './index'\nimport { AnyValidateFunction } from 'ajv/dist/core';\n\nconst ajv = new Ajv();\n\nconst _Validate = (validator: AnyValidateFunction<unknown>, payload: JSONObject): unknown | null => {\n const valid: boolean = validator(payload) as boolean;\n if (!valid) {\n return validator.errors;\n } else {\n return null;\n }\n /*\n\t\tconsole.error(validator.errors);\n\t\tconsole.trace('Invalid Schema');\n\t\tconsole.log('Payload:-');\n\t\tconsole.log(JSON.stringify(payload));\n\t\tprocess.exit(1);\n\t\t*/\n};\n\nexport function AddSchema(name: string, schema: Schema): void {\n ajv.addSchema(schema, name);\n /*\n\treturn (payload) => {\n\t\tconst validator = ajv.getSchema(name)\n\t\t_Validate(validator, payload)\n\t}*/\n\n}\n\nexport function Validate(name: string, payload: JSONObject): unknown {\n const validator: AnyValidateFunction<unknown> | undefined = ajv.getSchema(name)\n if (validator) {\n return _Validate(validator, payload);\n }\n}\n","import { Validate } from './validate.js'\n\nimport { JSONObject } from './index'\n\nexport class STSOptionsBase\n{\n private _options: JSONObject | null;\n\n constructor(options: JSONObject | null = null)\n {\n this._options = options;\n\n if (options !== null) {\n if (typeof options.validator === 'undefined') {\n //console.log(JSON.stringify(options));\n //console.trace(\"Options Here ------------------------------------------------------------------------------------------\")\n } else {\n Validate(options.validator as string, options);\n }\n }\n }\n\n get options()\n {\n return this._options;\n }\n}\n","export async function Sleep(milliseconds = 1000): Promise<void> { \n return new Promise(resolve => setTimeout(resolve, milliseconds))\n}\n \n// poolsleep is required to avoid JEST reporting unclosed handles during shutdown of all tests\nexport async function JestSleep(): Promise<void> {\n return Sleep(100);\n}\n","import { errorCode, errorPayload } from './errorhandling'\n\n// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A\nexport enum OAuth2ParameterType {\n\tAUDIENCE = 'AUDIENCE', // STS Extension\n\tCLIENT_ID = 'client_id',\n\tCLIENT_SECRET = 'client_secret',\n\tRESPONSE_TYPE = 'response_type',\n\tSCOPE = 'scope',\n\tSTATE = 'state',\n\tREDIRECT_URI = 'redirect_uri',\n\tERROR = 'error',\n\tERROR_DESCRIPTION = 'error_description',\n\tERROR_CODES = 'error_codes', // STS Extension\n\tERROR_URI = 'error_uri',\n\tGRANT_TYPE = 'grant_type',\n\tCODE = 'code',\n\tACCESS_TOKEN = 'access_token',\n\tTOKEN_TYPE = 'token_type',\n\tEXPIRES_IN = 'expires_in',\n\tUSERNAME = 'username',\n\tPASSWORD = 'password',\n\tREFRESH_TOKEN = 'refresh_token',\n\tRESPONSE_MODE = 'response_mode', // STS Extension\n\tTIMESTAMP = 'timestamp', // STS Extension\n\tTRACE_ID = 'trace_id', // STS Extension\n\tCORRELATION_ID = 'correlation_id' // STS Extension\n}\n\n// OIDC Standard Claims\n// Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims\nexport enum OIDCStandardClaim {\n\tSUB = 'sub',\n\tNAME = 'name',\n\tGIVEN_NAME = 'given_name',\n\tFAMILY_NAME = 'family_name',\n\tMIDDLE_NAME = 'middle_name',\n\tNICKNAME = 'nickname',\n\tPREFERRED_USERNAME = 'preferred_username',\n\tPROFILE = 'profile',\n\tPICTURE = 'picture',\n\tWEBSITE = 'website',\n\tEMAIL = 'email',\n\tEMAIL_VERIFIED = 'email_verified',\n\tGENDER = 'gender',\n\tBIRTHDATE = 'birthdate',\n\tZONEINFO = 'zoneinfo',\n\tLOCALE = 'locale',\n\tPHONE_NUMBER = 'phone_number',\n\tPHONE_NUMBER_VERIFIED = 'phone_number_verified',\n\tADDRESS = 'address',\n\tCLIENT_SECRET = 'client_secret',\n\tNONCE = 'nonce' // STS Extension\n}\n\nexport enum OIDCAddressClaim {\n\tFORMATTED = 'formatted',\n\tSTREET_ADDRESS = 'street_address',\n\tLOCALITY = 'locality',\n\tREGION = 'region',\n\tCOUNTRY = 'country'\n}\n\nexport class OAuth2ParameterErrorType {\n static readonly NOT_EQUAL: errorCode = {\n code: 'STS_OAUTH2_ERR_0001',\n description: 'Parameter values not equal.'\n }\n static readonly NOT_PRESENT: errorCode = {\n code: 'STS_OAUTH2_ERR_0002',\n description: 'Parameter not provided.'\n }\n static readonly INVALID_FORMAT: errorCode = {\n code: 'STS_OAUTH2_ERR_0003',\n description: 'Parameter value format invalid.'\n }\n static readonly EXPIRED: errorCode = {\n code: 'STS_OAUTH2_ERR_0004',\n description: 'Parameter value expired.'\n }\n}\n\nexport function compareParameterTypes(source1: string[], source2: string[], authParameterTypes: OAuth2ParameterType[]): errorPayload[] {\n const errors: errorPayload[] = [ ];\n for (let i=0 ; i < authParameterTypes.length; i++) {\n const authParameterType = authParameterTypes[i];\n if (source1[i].localeCompare(source2[i]) !== 0) {\n const error: errorPayload = {\n error: OAuth2ParameterErrorType.NOT_EQUAL.code,\n error_description: OAuth2ParameterErrorType.NOT_EQUAL.description,\n timestamp: Date.now(),\n details: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`\n }\n errors.push(error);\n }\n }\n return errors;\n}\n","/*\nexport interface JSONObject {\n [x: string]: string | number | boolean | string[] | number[] | boolean[] | Array<JSONObject> | JSONObject | ((p: any) => any) | undefined\n}\n// This also works :-\n//interface JSONObject2 extends Record<string, string | number | string[] | Array<JSONObject2> | JSONObject2> {};\n*/\n\nexport interface JSONObject {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [x: string]: any | JSONObject | undefined\n}\n\nexport * from './errorhandling'\nexport * from './stsoptionsbase'\nexport * from './sleep'\nexport * from './validate'\nexport * from './oauth2terms'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const $stsgd: Record<string, any> = { };\n\nexport function $stsgdf<T>(): Record<string, T> {\n return $stsgd as Record<string, T>;\n}\n"],"names":["GetErrorPayload","errorCode","details","ajv","Ajv","_Validate","validator","payload","AddSchema","name","schema","Validate","STSOptionsBase","options","__publicField","Sleep","milliseconds","resolve","JestSleep","OAuth2ParameterType","OIDCStandardClaim","OIDCAddressClaim","OAuth2ParameterErrorType","compareParameterTypes","source1","source2","authParameterTypes","errors","i","authParameterType","error","$stsgd","$stsgdf"],"mappings":";;;;AAcgB,SAAAA,EAAgBC,GAAsBC,IAAmB,MAAoB;AAClF,SAAA;AAAA,IACH,OAAOD,EAAU;AAAA,IACjB,mBAAmBA,EAAU;AAAA,IAC7B,WAAW,KAAK,IAAI;AAAA;AAAA;AAAA,IAGpB,SAAAC;AAAA,EAAA;AAER;AClBA,MAAMC,IAAM,IAAIC,KAEVC,IAAY,CAACC,GAAyCC,MACjCD,EAAUC,CAAO,IAI7B,OAFAD,EAAU;AAaT,SAAAE,EAAUC,GAAcC,GAAsB;AACtD,EAAAP,EAAA,UAAUO,GAAQD,CAAI;AAO9B;AAEgB,SAAAE,EAASF,GAAcF,GAA8B;AAC3D,QAAAD,IAAsDH,EAAI,UAAUM,CAAI;AAC9E,MAAIH;AACO,WAAAD,EAAUC,GAAWC,CAAO;AAE3C;AClCO,MAAMK,EACb;AAAA,EAGI,YAAYC,IAA6B,MACzC;AAHQ,IAAAC,EAAA;AAIJ,SAAK,WAAWD,GAEZA,MAAY,SACR,OAAOA,EAAQ,YAAc,OAIpBF,EAAAE,EAAQ,WAAqBA,CAAO;AAAA,EAGzD;AAAA,EAEA,IAAI,UACJ;AACI,WAAO,KAAK;AAAA,EAChB;AACJ;AC1BsB,eAAAE,EAAMC,IAAe,KAAqB;AAC5D,SAAO,IAAI,QAAQ,CAAAC,MAAW,WAAWA,GAASD,CAAY,CAAC;AACnE;AAGA,eAAsBE,IAA2B;AAC7C,SAAOH,EAAM,GAAG;AACpB;ACJY,IAAAI,sBAAAA,OACXA,EAAA,WAAW,YACXA,EAAA,YAAY,aACZA,EAAA,gBAAgB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AM;AAAA,EACN,aAAa;AAAA,IAEjBR,EAbSQ,GAaO,WAAqB;AAAA,EACjC,MAAM;AAAA,EACN,aAAa;AAAA;AAIL,SAAAC,EAAsBC,GAAmBC,GAAmBC,GAA2D;AACnI,QAAMC,IAAyB,CAAA;AAC/B,WAASC,IAAE,GAAIA,IAAIF,EAAmB,QAAQE,KAAK;AACzC,UAAAC,IAAoBH,EAAmBE,CAAC;AAC1C,QAAAJ,EAAQI,CAAC,EAAE,cAAcH,EAAQG,CAAC,CAAC,MAAM,GAAG;AAC5C,YAAME,IAAsB;AAAA,QACxB,OAAOR,EAAyB,UAAU;AAAA,QAC1C,mBAAmBA,EAAyB,UAAU;AAAA,QACtD,WAAW,KAAK,IAAI;AAAA,QACpB,SAAS,GAAGA,EAAyB,UAAU,4BAA4BO;AAAA,MAAA;AAE/E,MAAAF,EAAO,KAAKG,CAAK;AAAA;AAAA;AAGlB,SAAAH;AACX;AC7EO,MAAMI,IAA8B,CAAE;AAEtC,SAASC,IAAgC;AACrC,SAAAD;AACX;"}
|
package/dist/stsutils.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(E,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("ajv/dist/jtd")):typeof define=="function"&&define.amd?define(["exports","ajv/dist/jtd"],o):(E=typeof globalThis<"u"?globalThis:E||self,o(E["@nsshunt/stsutils"]={},E.Ajv))})(this,function(E,o){"use strict";var
|
|
1
|
+
(function(E,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("ajv/dist/jtd")):typeof define=="function"&&define.amd?define(["exports","ajv/dist/jtd"],o):(E=typeof globalThis<"u"?globalThis:E||self,o(E["@nsshunt/stsutils"]={},E.Ajv))})(this,function(E,o){"use strict";var A=Object.defineProperty;var F=(E,o,s)=>o in E?A(E,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):E[o]=s;var c=(E,o,s)=>(F(E,typeof o!="symbol"?o+"":o,s),s);function s(e,n=null){return{error:e.code,error_description:e.description,timestamp:Date.now(),details:n}}const R=new o,u=(e,n)=>e(n)?null:e.errors;function v(e,n){R.addSchema(n,e)}function r(e,n){const _=R.getSchema(e);if(_)return u(_,n)}class M{constructor(n=null){c(this,"_options");this._options=n,n!==null&&(typeof n.validator>"u"||r(n.validator,n))}get options(){return this._options}}async function N(e=1e3){return new Promise(n=>setTimeout(n,e))}async function U(){return N(100)}var f=(e=>(e.AUDIENCE="AUDIENCE",e.CLIENT_ID="client_id",e.CLIENT_SECRET="client_secret",e.RESPONSE_TYPE="response_type",e.SCOPE="scope",e.STATE="state",e.REDIRECT_URI="redirect_uri",e.ERROR="error",e.ERROR_DESCRIPTION="error_description",e.ERROR_CODES="error_codes",e.ERROR_URI="error_uri",e.GRANT_TYPE="grant_type",e.CODE="code",e.ACCESS_TOKEN="access_token",e.TOKEN_TYPE="token_type",e.EXPIRES_IN="expires_in",e.USERNAME="username",e.PASSWORD="password",e.REFRESH_TOKEN="refresh_token",e.RESPONSE_MODE="response_mode",e.TIMESTAMP="timestamp",e.TRACE_ID="trace_id",e.CORRELATION_ID="correlation_id",e))(f||{}),d=(e=>(e.SUB="sub",e.NAME="name",e.GIVEN_NAME="given_name",e.FAMILY_NAME="family_name",e.MIDDLE_NAME="middle_name",e.NICKNAME="nickname",e.PREFERRED_USERNAME="preferred_username",e.PROFILE="profile",e.PICTURE="picture",e.WEBSITE="website",e.EMAIL="email",e.EMAIL_VERIFIED="email_verified",e.GENDER="gender",e.BIRTHDATE="birthdate",e.ZONEINFO="zoneinfo",e.LOCALE="locale",e.PHONE_NUMBER="phone_number",e.PHONE_NUMBER_VERIFIED="phone_number_verified",e.ADDRESS="address",e.CLIENT_SECRET="client_secret",e.NONCE="nonce",e))(d||{}),l=(e=>(e.FORMATTED="formatted",e.STREET_ADDRESS="street_address",e.LOCALITY="locality",e.REGION="region",e.COUNTRY="country",e))(l||{});class i{}c(i,"NOT_EQUAL",{code:"STS_OAUTH2_ERR_0001",description:"Parameter values not equal."}),c(i,"NOT_PRESENT",{code:"STS_OAUTH2_ERR_0002",description:"Parameter not provided."}),c(i,"INVALID_FORMAT",{code:"STS_OAUTH2_ERR_0003",description:"Parameter value format invalid."}),c(i,"EXPIRED",{code:"STS_OAUTH2_ERR_0004",description:"Parameter value expired."});function L(e,n,_){const T=[];for(let t=0;t<_.length;t++){const p=_[t];if(e[t].localeCompare(n[t])!==0){const g={error:i.NOT_EQUAL.code,error_description:i.NOT_EQUAL.description,timestamp:Date.now(),details:`${i.NOT_EQUAL.description}: Parameter: [${p}]`};T.push(g)}}return T}const S={};function I(){return S}E.$stsgd=S,E.$stsgdf=I,E.AddSchema=v,E.GetErrorPayload=s,E.JestSleep=U,E.OAuth2ParameterErrorType=i,E.OAuth2ParameterType=f,E.OIDCAddressClaim=l,E.OIDCStandardClaim=d,E.STSOptionsBase=M,E.Sleep=N,E.Validate=r,E.compareParameterTypes=L,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=stsutils.umd.js.map
|
package/dist/stsutils.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stsutils.umd.js","sources":["../src/errorhandling.ts","../src/validate.ts","../src/stsoptionsbase.ts","../src/sleep.ts","../src/oauth2terms.ts","../src/index.ts"],"sourcesContent":["export type errorCode = {\n\tcode: string\n\tdescription: string\n}\n\nexport type errorPayload = {\n\terror: string,\n\terror_description: string,\n\ttimestamp: number,\n\t//trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n\t//correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n\tdetails?: unknown\n}\n\nexport function GetErrorPayload(errorCode: errorCode, details: unknown = null): errorPayload {\n return {\n error: errorCode.code,\n error_description: errorCode.description,\n timestamp: Date.now(),\n //trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n //correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n details: details\n }\n}\n","import Ajv, { Schema } from 'ajv/dist/jtd'\n\nimport { JSONObject } from './index'\nimport { AnyValidateFunction } from 'ajv/dist/core';\n\nconst ajv = new Ajv();\n\nconst _Validate = (validator: AnyValidateFunction<unknown>, payload: JSONObject): unknown | null => {\n const valid: boolean = validator(payload) as boolean;\n if (!valid) {\n return validator.errors;\n } else {\n return null;\n }\n /*\n\t\tconsole.error(validator.errors);\n\t\tconsole.trace('Invalid Schema');\n\t\tconsole.log('Payload:-');\n\t\tconsole.log(JSON.stringify(payload));\n\t\tprocess.exit(1);\n\t\t*/\n};\n\nexport function AddSchema(name: string, schema: Schema): void {\n ajv.addSchema(schema, name);\n /*\n\treturn (payload) => {\n\t\tconst validator = ajv.getSchema(name)\n\t\t_Validate(validator, payload)\n\t}*/\n\n}\n\nexport function Validate(name: string, payload: JSONObject): unknown {\n const validator: AnyValidateFunction<unknown> | undefined = ajv.getSchema(name)\n if (validator) {\n return _Validate(validator, payload);\n }\n}\n","import { Validate } from './validate.js'\n\nimport { JSONObject } from './index'\n\nexport class STSOptionsBase\n{\n private _options: JSONObject | null;\n\n constructor(options: JSONObject | null = null)\n {\n this._options = options;\n\n if (options !== null) {\n if (typeof options.validator === 'undefined') {\n //console.log(JSON.stringify(options));\n //console.trace(\"Options Here ------------------------------------------------------------------------------------------\")\n } else {\n Validate(options.validator as string, options);\n }\n }\n }\n\n get options()\n {\n return this._options;\n }\n}\n","export async function Sleep(milliseconds = 1000): Promise<void> { \n return new Promise(resolve => setTimeout(resolve, milliseconds))\n}\n \n// poolsleep is required to avoid JEST reporting unclosed handles during shutdown of all tests\nexport async function JestSleep(): Promise<void> {\n return Sleep(100);\n}\n","import { errorCode, errorPayload } from './errorhandling'\n\n// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A\nexport enum OAuth2ParameterType {\n\tAUDIENCE = 'AUDIENCE', // STS Extension\n\tCLIENT_ID = 'client_id',\n\tCLIENT_SECRET = 'client_secret',\n\tRESPONSE_TYPE = 'response_type',\n\tSCOPE = 'scope',\n\tSTATE = 'state',\n\tREDIRECT_URI = 'redirect_uri',\n\tERROR = 'error',\n\tERROR_DESCRIPTION = 'error_description',\n\tERROR_CODES = 'error_codes', // STS Extension\n\tERROR_URI = 'error_uri',\n\tGRANT_TYPE = 'grant_type',\n\tCODE = 'code',\n\tACCESS_TOKEN = 'access_token',\n\tTOKEN_TYPE = 'token_type',\n\tEXPIRES_IN = 'expires_in',\n\tUSERNAME = 'username',\n\tPASSWORD = 'password',\n\tREFRESH_TOKEN = 'refresh_token',\n\tRESPONSE_MODE = 'response_mode', // STS Extension\n\tTIMESTAMP = 'timestamp', // STS Extension\n\tTRACE_ID = 'trace_id', // STS Extension\n\tCORRELATION_ID = 'correlation_id' // STS Extension\n}\n\n// OIDC Standard Claims\n// Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims\nexport enum OIDCStandardClaim {\n\tSUB = 'sub',\n\tNAME = 'name',\n\tGIVEN_NAME = 'given_name',\n\tFAMILY_NAME = 'family_name',\n\tMIDDLE_NAME = 'middle_name',\n\tNICKNAME = 'nickname',\n\tPREFERRED_USERNAME = 'preferred_username',\n\tPROFILE = 'profile',\n\tPICTURE = 'picture',\n\tWEBSITE = 'website',\n\tEMAIL = 'email',\n\tEMAIL_VERIFIED = 'email_verified',\n\tGENDER = 'gender',\n\tBIRTHDATE = 'birthdate',\n\tZONEINFO = 'zoneinfo',\n\tLOCALE = 'locale',\n\tPHONE_NUMBER = 'phone_number',\n\tPHONE_NUMBER_VERIFIED = 'phone_number_verified',\n\tADDRESS = 'address',\n\tCLIENT_SECRET = 'client_secret',\n\tNONCE = 'nonce' // STS Extension\n}\n\nexport enum OIDCAddressClaim {\n\tFORMATTED = 'formatted',\n\tSTREET_ADDRESS = 'street_address',\n\tLOCALITY = 'locality',\n\tREGION = 'region',\n\tCOUNTRY = 'country'\n}\n\nexport class OAuth2ParameterErrorType {\n static readonly NOT_EQUAL: errorCode = {\n code: 'STS_OAUTH2_ERR_0001',\n description: 'Parameter values not equal.'\n }\n static readonly NOT_PRESENT: errorCode = {\n code: 'STS_OAUTH2_ERR_0002',\n description: 'Parameter not provided.'\n }\n static readonly INVALID_FORMAT: errorCode = {\n code: 'STS_OAUTH2_ERR_0003',\n description: 'Parameter value format invalid.'\n }\n static readonly EXPIRED: errorCode = {\n code: 'STS_OAUTH2_ERR_0004',\n description: 'Parameter value expired.'\n }\n}\n\nexport function compareParameterTypes(source1: string[], source2: string[], authParameterTypes: OAuth2ParameterType[]): errorPayload[] {\n const errors: errorPayload[] = [ ];\n for (let i=0 ; i < authParameterTypes.length; i++) {\n const authParameterType = authParameterTypes[i];\n if (source1[i].localeCompare(source2[i]) !== 0) {\n const error: errorPayload = {\n error: OAuth2ParameterErrorType.NOT_EQUAL.code,\n error_description: OAuth2ParameterErrorType.NOT_EQUAL.description,\n timestamp: Date.now(),\n details: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`\n }\n errors.push(error);\n }\n }\n return errors;\n}\n","/*\nexport interface JSONObject {\n [x: string]: string | number | boolean | string[] | number[] | boolean[] | Array<JSONObject> | JSONObject | ((p: any) => any) | undefined\n}\n// This also works :-\n//interface JSONObject2 extends Record<string, string | number | string[] | Array<JSONObject2> | JSONObject2> {};\n*/\n\nexport interface JSONObject {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [x: string]: any | JSONObject | undefined\n}\n\nexport * from './errorhandling'\nexport * from './stsoptionsbase'\nexport * from './sleep'\
|
|
1
|
+
{"version":3,"file":"stsutils.umd.js","sources":["../src/errorhandling.ts","../src/validate.ts","../src/stsoptionsbase.ts","../src/sleep.ts","../src/oauth2terms.ts","../src/index.ts"],"sourcesContent":["export type errorCode = {\n\tcode: string\n\tdescription: string\n}\n\nexport type errorPayload = {\n\terror: string,\n\terror_description: string,\n\ttimestamp: number,\n\t//trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n\t//correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n\tdetails?: unknown\n}\n\nexport function GetErrorPayload(errorCode: errorCode, details: unknown = null): errorPayload {\n return {\n error: errorCode.code,\n error_description: errorCode.description,\n timestamp: Date.now(),\n //trace_id: \"255d1aef-8c98-452f-ac51-23d051240864\", //@@\n //correlation_id: \"fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\", //@@\n details: details\n }\n}\n","import Ajv, { Schema } from 'ajv/dist/jtd'\n\nimport { JSONObject } from './index'\nimport { AnyValidateFunction } from 'ajv/dist/core';\n\nconst ajv = new Ajv();\n\nconst _Validate = (validator: AnyValidateFunction<unknown>, payload: JSONObject): unknown | null => {\n const valid: boolean = validator(payload) as boolean;\n if (!valid) {\n return validator.errors;\n } else {\n return null;\n }\n /*\n\t\tconsole.error(validator.errors);\n\t\tconsole.trace('Invalid Schema');\n\t\tconsole.log('Payload:-');\n\t\tconsole.log(JSON.stringify(payload));\n\t\tprocess.exit(1);\n\t\t*/\n};\n\nexport function AddSchema(name: string, schema: Schema): void {\n ajv.addSchema(schema, name);\n /*\n\treturn (payload) => {\n\t\tconst validator = ajv.getSchema(name)\n\t\t_Validate(validator, payload)\n\t}*/\n\n}\n\nexport function Validate(name: string, payload: JSONObject): unknown {\n const validator: AnyValidateFunction<unknown> | undefined = ajv.getSchema(name)\n if (validator) {\n return _Validate(validator, payload);\n }\n}\n","import { Validate } from './validate.js'\n\nimport { JSONObject } from './index'\n\nexport class STSOptionsBase\n{\n private _options: JSONObject | null;\n\n constructor(options: JSONObject | null = null)\n {\n this._options = options;\n\n if (options !== null) {\n if (typeof options.validator === 'undefined') {\n //console.log(JSON.stringify(options));\n //console.trace(\"Options Here ------------------------------------------------------------------------------------------\")\n } else {\n Validate(options.validator as string, options);\n }\n }\n }\n\n get options()\n {\n return this._options;\n }\n}\n","export async function Sleep(milliseconds = 1000): Promise<void> { \n return new Promise(resolve => setTimeout(resolve, milliseconds))\n}\n \n// poolsleep is required to avoid JEST reporting unclosed handles during shutdown of all tests\nexport async function JestSleep(): Promise<void> {\n return Sleep(100);\n}\n","import { errorCode, errorPayload } from './errorhandling'\n\n// Ref: https://datatracker.ietf.org/doc/html/rfc6749#appendix-A\nexport enum OAuth2ParameterType {\n\tAUDIENCE = 'AUDIENCE', // STS Extension\n\tCLIENT_ID = 'client_id',\n\tCLIENT_SECRET = 'client_secret',\n\tRESPONSE_TYPE = 'response_type',\n\tSCOPE = 'scope',\n\tSTATE = 'state',\n\tREDIRECT_URI = 'redirect_uri',\n\tERROR = 'error',\n\tERROR_DESCRIPTION = 'error_description',\n\tERROR_CODES = 'error_codes', // STS Extension\n\tERROR_URI = 'error_uri',\n\tGRANT_TYPE = 'grant_type',\n\tCODE = 'code',\n\tACCESS_TOKEN = 'access_token',\n\tTOKEN_TYPE = 'token_type',\n\tEXPIRES_IN = 'expires_in',\n\tUSERNAME = 'username',\n\tPASSWORD = 'password',\n\tREFRESH_TOKEN = 'refresh_token',\n\tRESPONSE_MODE = 'response_mode', // STS Extension\n\tTIMESTAMP = 'timestamp', // STS Extension\n\tTRACE_ID = 'trace_id', // STS Extension\n\tCORRELATION_ID = 'correlation_id' // STS Extension\n}\n\n// OIDC Standard Claims\n// Ref: https://openid.net/specs/openid-connect-core-1_0.html#Claims\nexport enum OIDCStandardClaim {\n\tSUB = 'sub',\n\tNAME = 'name',\n\tGIVEN_NAME = 'given_name',\n\tFAMILY_NAME = 'family_name',\n\tMIDDLE_NAME = 'middle_name',\n\tNICKNAME = 'nickname',\n\tPREFERRED_USERNAME = 'preferred_username',\n\tPROFILE = 'profile',\n\tPICTURE = 'picture',\n\tWEBSITE = 'website',\n\tEMAIL = 'email',\n\tEMAIL_VERIFIED = 'email_verified',\n\tGENDER = 'gender',\n\tBIRTHDATE = 'birthdate',\n\tZONEINFO = 'zoneinfo',\n\tLOCALE = 'locale',\n\tPHONE_NUMBER = 'phone_number',\n\tPHONE_NUMBER_VERIFIED = 'phone_number_verified',\n\tADDRESS = 'address',\n\tCLIENT_SECRET = 'client_secret',\n\tNONCE = 'nonce' // STS Extension\n}\n\nexport enum OIDCAddressClaim {\n\tFORMATTED = 'formatted',\n\tSTREET_ADDRESS = 'street_address',\n\tLOCALITY = 'locality',\n\tREGION = 'region',\n\tCOUNTRY = 'country'\n}\n\nexport class OAuth2ParameterErrorType {\n static readonly NOT_EQUAL: errorCode = {\n code: 'STS_OAUTH2_ERR_0001',\n description: 'Parameter values not equal.'\n }\n static readonly NOT_PRESENT: errorCode = {\n code: 'STS_OAUTH2_ERR_0002',\n description: 'Parameter not provided.'\n }\n static readonly INVALID_FORMAT: errorCode = {\n code: 'STS_OAUTH2_ERR_0003',\n description: 'Parameter value format invalid.'\n }\n static readonly EXPIRED: errorCode = {\n code: 'STS_OAUTH2_ERR_0004',\n description: 'Parameter value expired.'\n }\n}\n\nexport function compareParameterTypes(source1: string[], source2: string[], authParameterTypes: OAuth2ParameterType[]): errorPayload[] {\n const errors: errorPayload[] = [ ];\n for (let i=0 ; i < authParameterTypes.length; i++) {\n const authParameterType = authParameterTypes[i];\n if (source1[i].localeCompare(source2[i]) !== 0) {\n const error: errorPayload = {\n error: OAuth2ParameterErrorType.NOT_EQUAL.code,\n error_description: OAuth2ParameterErrorType.NOT_EQUAL.description,\n timestamp: Date.now(),\n details: `${OAuth2ParameterErrorType.NOT_EQUAL.description}: Parameter: [${authParameterType}]`\n }\n errors.push(error);\n }\n }\n return errors;\n}\n","/*\nexport interface JSONObject {\n [x: string]: string | number | boolean | string[] | number[] | boolean[] | Array<JSONObject> | JSONObject | ((p: any) => any) | undefined\n}\n// This also works :-\n//interface JSONObject2 extends Record<string, string | number | string[] | Array<JSONObject2> | JSONObject2> {};\n*/\n\nexport interface JSONObject {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [x: string]: any | JSONObject | undefined\n}\n\nexport * from './errorhandling'\nexport * from './stsoptionsbase'\nexport * from './sleep'\nexport * from './validate'\nexport * from './oauth2terms'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const $stsgd: Record<string, any> = { };\n\nexport function $stsgdf<T>(): Record<string, T> {\n return $stsgd as Record<string, T>;\n}\n"],"names":["GetErrorPayload","errorCode","details","ajv","Ajv","_Validate","validator","payload","AddSchema","name","schema","Validate","STSOptionsBase","options","__publicField","Sleep","milliseconds","resolve","JestSleep","OAuth2ParameterType","OIDCStandardClaim","OIDCAddressClaim","OAuth2ParameterErrorType","compareParameterTypes","source1","source2","authParameterTypes","errors","i","authParameterType","error","$stsgd","$stsgdf"],"mappings":"mcAcgB,SAAAA,EAAgBC,EAAsBC,EAAmB,KAAoB,CAClF,MAAA,CACH,MAAOD,EAAU,KACjB,kBAAmBA,EAAU,YAC7B,UAAW,KAAK,IAAI,EAGpB,QAAAC,CAAA,CAER,CClBA,MAAMC,EAAM,IAAIC,EAEVC,EAAY,CAACC,EAAyCC,IACjCD,EAAUC,CAAO,EAI7B,KAFAD,EAAU,OAaT,SAAAE,EAAUC,EAAcC,EAAsB,CACtDP,EAAA,UAAUO,EAAQD,CAAI,CAO9B,CAEgB,SAAAE,EAASF,EAAcF,EAA8B,CAC3D,MAAAD,EAAsDH,EAAI,UAAUM,CAAI,EAC9E,GAAIH,EACO,OAAAD,EAAUC,EAAWC,CAAO,CAE3C,CClCO,MAAMK,CACb,CAGI,YAAYC,EAA6B,KACzC,CAHQC,EAAA,iBAIJ,KAAK,SAAWD,EAEZA,IAAY,OACR,OAAOA,EAAQ,UAAc,KAIpBF,EAAAE,EAAQ,UAAqBA,CAAO,EAGzD,CAEA,IAAI,SACJ,CACI,OAAO,KAAK,QAChB,CACJ,CC1BsB,eAAAE,EAAMC,EAAe,IAAqB,CAC5D,OAAO,IAAI,QAAQC,GAAW,WAAWA,EAASD,CAAY,CAAC,CACnE,CAGA,eAAsBE,GAA2B,CAC7C,OAAOH,EAAM,GAAG,CACpB,CCJY,IAAAI,GAAAA,IACXA,EAAA,SAAW,WACXA,EAAA,UAAY,YACZA,EAAA,cAAgB,gBAChBA,EAAA,cAAgB,gBA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BACN,YAAa,0BAAA,GAIL,SAAAC,EAAsBC,EAAmBC,EAAmBC,EAA2D,CACnI,MAAMC,EAAyB,CAAA,EAC/B,QAASC,EAAE,EAAIA,EAAIF,EAAmB,OAAQE,IAAK,CACzC,MAAAC,EAAoBH,EAAmBE,CAAC,EAC1C,GAAAJ,EAAQI,CAAC,EAAE,cAAcH,EAAQG,CAAC,CAAC,IAAM,EAAG,CAC5C,MAAME,EAAsB,CACxB,MAAOR,EAAyB,UAAU,KAC1C,kBAAmBA,EAAyB,UAAU,YACtD,UAAW,KAAK,IAAI,EACpB,QAAS,GAAGA,EAAyB,UAAU,4BAA4BO,IAAA,EAE/EF,EAAO,KAAKG,CAAK,GAGlB,OAAAH,CACX,CC7Ea,MAAAI,EAA8B,CAAE,EAEtC,SAASC,GAAgC,CACrC,OAAAD,CACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsutils",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.35",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/stsutils.umd.js",
|
|
6
6
|
"module": "./dist/stsutils.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"lint": "eslint . --ext js,jsx,ts,tsx",
|
|
21
21
|
"lintex": "eslint . --ext js,jsx,ts,tsx --fix",
|
|
22
|
-
"test": "
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test2": "jest --detectOpenHandles --no-cache",
|
|
23
24
|
"testwatch": "jest --watchAll --detectOpenHandles --no-cache",
|
|
24
25
|
"build": "tsc && vite build",
|
|
25
26
|
"build2": "vite build"
|
|
@@ -38,8 +39,6 @@
|
|
|
38
39
|
"parser": "@babel/eslint-parser"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@babel/preset-env": "^7.21.4",
|
|
42
|
-
"@babel/preset-typescript": "^7.21.4",
|
|
43
42
|
"@tsconfig/node18": "^1.0.1",
|
|
44
43
|
"@types/debug": "^4.1.7",
|
|
45
44
|
"@types/jest": "^29.5.0",
|
|
@@ -51,7 +50,8 @@
|
|
|
51
50
|
"rollup-plugin-visualizer": "^5.9.0",
|
|
52
51
|
"supertest": "^6.3.3",
|
|
53
52
|
"typescript": "^5.0.3",
|
|
54
|
-
"vite": "^4.2.1"
|
|
53
|
+
"vite": "^4.2.1",
|
|
54
|
+
"vitest": "^0.29.8"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"ajv": "^8.12.0"
|
package/types/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface JSONObject {
|
|
|
4
4
|
export * from './errorhandling';
|
|
5
5
|
export * from './stsoptionsbase';
|
|
6
6
|
export * from './sleep';
|
|
7
|
+
export * from './validate';
|
|
7
8
|
export * from './oauth2terms';
|
|
8
9
|
export declare const $stsgd: Record<string, any>;
|
|
9
10
|
export declare function $stsgdf<T>(): Record<string, T>;
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IAEvB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,GAAG,SAAS,CAAA;CAC5C;AAED,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IAEvB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,GAAG,SAAS,CAAA;CAC5C;AAED,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAG7B,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAO,CAAC;AAE/C,wBAAgB,OAAO,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAE9C"}
|
package/types/stsutils.test.d.ts
CHANGED