@pax2pay/model-banking 0.1.221 → 0.1.223

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/Identity.ts CHANGED
@@ -3,6 +3,11 @@ import { Key } from "./Key"
3
3
  import { Realm } from "./Realm"
4
4
 
5
5
  export class Identity {
6
+ #realms: Realm[] | undefined
7
+ get realms(): Realm[] | undefined {
8
+ return (this.#realms ??= Identity.getRealms(this.key.permissions))
9
+ }
10
+
6
11
  constructor(readonly key: Key, readonly realm?: Realm, readonly organization?: string) {}
7
12
  check(constraint: Key.Permissions, realm?: Realm, organization?: string): boolean {
8
13
  return [
@@ -12,12 +17,12 @@ export class Identity {
12
17
  { [`*-*`]: constraint },
13
18
  ].some(e => userwidgets.User.Permissions.check(this.key.permissions, e))
14
19
  }
15
- #realms: Realm[] | undefined
16
- get realms(): Realm[] | undefined {
17
- return (this.#realms ??= Object.keys(this.key.permissions).flatMap(code =>
18
- code.split("-")[0] == "*" ? Realm.realms : code.split("-")[0]
19
- ) as Realm[])
20
+ collectionCheck(collection: string): boolean {
21
+ return Object.values(this.key.permissions).some(
22
+ value => (typeof value == "object" && value[collection]) || value == true
23
+ )
20
24
  }
25
+
21
26
  static async authenticate(
22
27
  header: { authorization?: string | undefined; realm?: Realm; organization?: string },
23
28
  constraint: Key.Permissions,
@@ -26,11 +31,26 @@ export class Identity {
26
31
  const authorization = header.authorization?.startsWith("Bearer ")
27
32
  ? header.authorization.replace("Bearer ", "")
28
33
  : undefined
29
- const key = await verifier.verify(authorization)
34
+ const key = await Identity.verify(authorization, verifier)
30
35
  const result =
31
36
  key &&
32
37
  new Identity(key, (key.realm ?? header.realm) as Realm, (key.organization ?? header.organization) as string)
33
- return result?.check(constraint) ? result : undefined
38
+ return !constraint || result?.check(constraint) ? result : undefined
39
+ }
40
+ static async verify(
41
+ authorization: string | undefined,
42
+ verifier: userwidgets.User.Key.Verifier<Key> = productionVerifier
43
+ ): Promise<Key | undefined> {
44
+ return await verifier.verify(authorization)
45
+ }
46
+ static getRealms(permissions: Key.Permissions) {
47
+ return [
48
+ ...new Set(
49
+ Object.keys(permissions).flatMap(code =>
50
+ code.split("-")[0] == "*" ? Realm.realms : code.split("-")[0]
51
+ ) as Realm[]
52
+ ),
53
+ ]
34
54
  }
35
55
  }
36
56
  const publicKey =
@@ -6,12 +6,15 @@ export declare class Identity {
6
6
  readonly key: Key;
7
7
  readonly realm?: "eu" | "uk" | "test" | "testUK" | "upcheck" | undefined;
8
8
  readonly organization?: string | undefined;
9
+ get realms(): Realm[] | undefined;
9
10
  constructor(key: Key, realm?: "eu" | "uk" | "test" | "testUK" | "upcheck" | undefined, organization?: string | undefined);
10
11
  check(constraint: Key.Permissions, realm?: Realm, organization?: string): boolean;
11
- get realms(): Realm[] | undefined;
12
+ collectionCheck(collection: string): boolean;
12
13
  static authenticate(header: {
13
14
  authorization?: string | undefined;
14
15
  realm?: Realm;
15
16
  organization?: string;
16
17
  }, constraint: Key.Permissions, verifier?: userwidgets.User.Key.Verifier<Key>): Promise<Identity | undefined>;
18
+ static verify(authorization: string | undefined, verifier?: userwidgets.User.Key.Verifier<Key>): Promise<Key | undefined>;
19
+ static getRealms(permissions: Key.Permissions): ("eu" | "uk" | "test" | "testUK" | "upcheck")[];
17
20
  }
package/dist/Identity.js CHANGED
@@ -13,6 +13,9 @@ var _Identity_realms;
13
13
  import { userwidgets } from "@userwidgets/model";
14
14
  import { Realm } from "./Realm";
15
15
  export class Identity {
16
+ get realms() {
17
+ return (__classPrivateFieldSet(this, _Identity_realms, __classPrivateFieldGet(this, _Identity_realms, "f") ?? Identity.getRealms(this.key.permissions), "f"));
18
+ }
16
19
  constructor(key, realm, organization) {
17
20
  this.key = key;
18
21
  this.realm = realm;
@@ -27,17 +30,25 @@ export class Identity {
27
30
  { [`*-*`]: constraint },
28
31
  ].some(e => userwidgets.User.Permissions.check(this.key.permissions, e));
29
32
  }
30
- get realms() {
31
- return (__classPrivateFieldSet(this, _Identity_realms, __classPrivateFieldGet(this, _Identity_realms, "f") ?? Object.keys(this.key.permissions).flatMap(code => code.split("-")[0] == "*" ? Realm.realms : code.split("-")[0]), "f"));
33
+ collectionCheck(collection) {
34
+ return Object.values(this.key.permissions).some(value => (typeof value == "object" && value[collection]) || value == true);
32
35
  }
33
36
  static async authenticate(header, constraint, verifier = productionVerifier) {
34
37
  const authorization = header.authorization?.startsWith("Bearer ")
35
38
  ? header.authorization.replace("Bearer ", "")
36
39
  : undefined;
37
- const key = await verifier.verify(authorization);
40
+ const key = await Identity.verify(authorization, verifier);
38
41
  const result = key &&
39
42
  new Identity(key, (key.realm ?? header.realm), (key.organization ?? header.organization));
40
- return result?.check(constraint) ? result : undefined;
43
+ return !constraint || result?.check(constraint) ? result : undefined;
44
+ }
45
+ static async verify(authorization, verifier = productionVerifier) {
46
+ return await verifier.verify(authorization);
47
+ }
48
+ static getRealms(permissions) {
49
+ return [
50
+ ...new Set(Object.keys(permissions).flatMap(code => code.split("-")[0] == "*" ? Realm.realms : code.split("-")[0])),
51
+ ];
41
52
  }
42
53
  }
43
54
  _Identity_realms = new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"file":"Identity.js","sourceRoot":"../","sources":["Identity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,MAAM,OAAO,QAAQ;IACpB,YAAqB,GAAQ,EAAW,KAAa,EAAW,YAAqB;QAAhE,QAAG,GAAH,GAAG,CAAK;QAAW,UAAK,GAAL,KAAK,CAAQ;QAAW,iBAAY,GAAZ,YAAY,CAAS;QASrF,mCAA4B;IAT4D,CAAC;IACzF,KAAK,CAAC,UAA2B,EAAE,KAAa,EAAE,YAAqB;QACtE,OAAO;YACN,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,YAAY,IAAI,IAAI,CAAC,YAAY,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aAAa,CAAC,CAAA;IAC5C,CAAC;IACD,MAAM,CAAC,SAAS,CAAC,WAA4B;QAC5C,OAAO;YACN,GAAG,IAAI,GAAG,CACT,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAClD,CACZ;SACD,CAAA;IACF,CAAC;CACD;;AACD,MAAM,SAAS,GACd,kuBAAkuB,CAAA;AACnuB,MAAM,kBAAkB,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAM,SAAS,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pax2pay/model-banking",
3
- "version": "0.1.221",
3
+ "version": "0.1.223",
4
4
  "description": "Library containing data model types and functions for the Pax2Pay Banking API.",
5
5
  "author": "Pax2Pay Ltd",
6
6
  "license": "MIT",