@owlmeans/iam 0.1.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/build/consts.d.ts +5 -0
- package/build/consts.d.ts.map +1 -0
- package/build/consts.js +4 -0
- package/build/consts.js.map +1 -0
- package/build/errors.d.ts +14 -0
- package/build/errors.d.ts.map +1 -0
- package/build/errors.js +26 -0
- package/build/errors.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +3 -0
- package/build/index.js.map +1 -0
- package/build/types.d.ts +39 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +39 -0
- package/src/consts.ts +6 -0
- package/src/errors.ts +32 -0
- package/src/index.ts +3 -0
- package/src/types.ts +57 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DEFAULT_ALIAS = "iam-service";
|
|
2
|
+
export declare const IAM_MODE_KEYCLOAK = "keycloak";
|
|
3
|
+
export declare const IAM_MODE_INTEGRATED = "integrated";
|
|
4
|
+
export type IamMode = typeof IAM_MODE_KEYCLOAK | typeof IAM_MODE_INTEGRATED;
|
|
5
|
+
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,gBAAgB,CAAA;AAE1C,eAAO,MAAM,iBAAiB,aAAa,CAAA;AAC3C,eAAO,MAAM,mBAAmB,eAAe,CAAA;AAE/C,MAAM,MAAM,OAAO,GAAG,OAAO,iBAAiB,GAAG,OAAO,mBAAmB,CAAA"}
|
package/build/consts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAA;AAC3C,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ResilientError } from '@owlmeans/error';
|
|
2
|
+
export declare class IamError extends ResilientError {
|
|
3
|
+
static typeName: string;
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class IamClientError extends IamError {
|
|
7
|
+
static typeName: string;
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class IamResourceError extends IamError {
|
|
11
|
+
static typeName: string;
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,qBAAa,QAAS,SAAQ,cAAc;IAC1C,OAAuB,QAAQ,SAAkC;gBAErD,OAAO,SAAU;CAI9B;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,OAAuB,QAAQ,SAAwC;gBAE3D,OAAO,SAAU;CAI9B;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAuB,QAAQ,SAA0C;gBAE7D,OAAO,SAAU;CAI9B"}
|
package/build/errors.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ResilientError } from '@owlmeans/error';
|
|
2
|
+
export class IamError extends ResilientError {
|
|
3
|
+
static typeName = `Iam${ResilientError.typeName}`;
|
|
4
|
+
constructor(message = 'error') {
|
|
5
|
+
super(IamError.typeName, `iam:${message}`);
|
|
6
|
+
this.type = IamError.typeName;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class IamClientError extends IamError {
|
|
10
|
+
static typeName = `IamClient${ResilientError.typeName}`;
|
|
11
|
+
constructor(message = 'error') {
|
|
12
|
+
super(`client:${message}`);
|
|
13
|
+
this.type = IamClientError.typeName;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class IamResourceError extends IamError {
|
|
17
|
+
static typeName = `IamResource${ResilientError.typeName}`;
|
|
18
|
+
constructor(message = 'error') {
|
|
19
|
+
super(`resource:${message}`);
|
|
20
|
+
this.type = IamResourceError.typeName;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
ResilientError.registerErrorClass(IamError);
|
|
24
|
+
ResilientError.registerErrorClass(IamClientError);
|
|
25
|
+
ResilientError.registerErrorClass(IamResourceError);
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,OAAO,QAAS,SAAQ,cAAc;IACnC,MAAM,CAAU,QAAQ,GAAG,MAAM,cAAc,CAAC,QAAQ,EAAE,CAAA;IAEjE,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO,EAAE,CAAC,CAAA;QAC1C,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAA;IAC/B,CAAC;;AAGH,MAAM,OAAO,cAAe,SAAQ,QAAQ;IACnC,MAAM,CAAU,QAAQ,GAAG,YAAY,cAAc,CAAC,QAAQ,EAAE,CAAA;IAEvE,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,UAAU,OAAO,EAAE,CAAC,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAA;IACrC,CAAC;;AAGH,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IACrC,MAAM,CAAU,QAAQ,GAAG,cAAc,cAAc,CAAC,QAAQ,EAAE,CAAA;IAEzE,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,YAAY,OAAO,EAAE,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAA;IACvC,CAAC;;AAGH,cAAc,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;AAC3C,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;AACjD,cAAc,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { InitializedService } from '@owlmeans/context';
|
|
2
|
+
import type { OidcProviderConfig } from '@owlmeans/oidc';
|
|
3
|
+
export interface IamClient {
|
|
4
|
+
id?: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
secret?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
/** The entity realm this client belongs to — replaces the old (client as any)._realm hack */
|
|
9
|
+
realm?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IamCredentialsPair {
|
|
12
|
+
token: string;
|
|
13
|
+
realm: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IamPermissionArgs {
|
|
16
|
+
/** Action name. When absent the permission is unscoped (project-wide). */
|
|
17
|
+
permission?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface IamResourceSpec {
|
|
20
|
+
name: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Unified IAM provider interface — all platform/agent code calls only this, never a backend directly */
|
|
24
|
+
export interface IamService extends InitializedService {
|
|
25
|
+
getEntityAdminConfig: (entityId: string) => Promise<OidcProviderConfig>;
|
|
26
|
+
getCredentialsPair: (entityId: string) => Promise<IamCredentialsPair>;
|
|
27
|
+
ensureClient: (entityId: string, clientId: string) => Promise<IamClient>;
|
|
28
|
+
/**
|
|
29
|
+
* Ensures a permission/resource exists in the entity's client.
|
|
30
|
+
* Returns the canonical resource name (e.g. "res--action" or "res").
|
|
31
|
+
*/
|
|
32
|
+
ensurePermission: (entityId: string, clientId: string, resource?: string, args?: IamPermissionArgs) => Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Idempotent: creates a resource, a client role for it, and assigns that role to
|
|
35
|
+
* the entity-owner role. Used by payment provisioning for account/project/wl resources.
|
|
36
|
+
*/
|
|
37
|
+
ensureResourceOwnership: (entityId: string, clientId: string, resource: IamResourceSpec) => Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,MAAM,WAAW,SAAS;IACxB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,yGAAyG;AACzG,MAAM,WAAW,UAAW,SAAQ,kBAAkB;IAEpD,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACvE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAGrE,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAA;IAExE;;;OAGG;IACH,gBAAgB,EAAE,CAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,iBAAiB,KACrB,OAAO,CAAC,MAAM,CAAC,CAAA;IAEpB;;;OAGG;IACH,uBAAuB,EAAE,CACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,eAAe,KACtB,OAAO,CAAC,IAAI,CAAC,CAAA;CACnB"}
|
package/build/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@owlmeans/iam",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc -b",
|
|
8
|
+
"dev": "sleep 2 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
|
|
9
|
+
"watch": "tsc -b -w --preserveWatchOutput --pretty",
|
|
10
|
+
"test": "bun test ./tests"
|
|
11
|
+
},
|
|
12
|
+
"main": "build/index.js",
|
|
13
|
+
"module": "build/index.js",
|
|
14
|
+
"types": "build/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./build/index.js",
|
|
18
|
+
"require": "./build/index.js",
|
|
19
|
+
"default": "./build/index.js",
|
|
20
|
+
"module": "./build/index.js",
|
|
21
|
+
"types": "./build/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@owlmeans/context": "^0.1.5",
|
|
26
|
+
"@owlmeans/error": "^0.1.5",
|
|
27
|
+
"@owlmeans/oidc": "^0.1.5"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@owlmeans/dep-config": "workspace:*",
|
|
31
|
+
"@types/bun": "^1.3.0",
|
|
32
|
+
"nodemon": "^3.1.11",
|
|
33
|
+
"npm-check": "^6.0.1",
|
|
34
|
+
"typescript": "^6.0.2"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/consts.ts
ADDED
package/src/errors.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ResilientError } from '@owlmeans/error'
|
|
2
|
+
|
|
3
|
+
export class IamError extends ResilientError {
|
|
4
|
+
public static override typeName = `Iam${ResilientError.typeName}`
|
|
5
|
+
|
|
6
|
+
constructor(message = 'error') {
|
|
7
|
+
super(IamError.typeName, `iam:${message}`)
|
|
8
|
+
this.type = IamError.typeName
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class IamClientError extends IamError {
|
|
13
|
+
public static override typeName = `IamClient${ResilientError.typeName}`
|
|
14
|
+
|
|
15
|
+
constructor(message = 'error') {
|
|
16
|
+
super(`client:${message}`)
|
|
17
|
+
this.type = IamClientError.typeName
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class IamResourceError extends IamError {
|
|
22
|
+
public static override typeName = `IamResource${ResilientError.typeName}`
|
|
23
|
+
|
|
24
|
+
constructor(message = 'error') {
|
|
25
|
+
super(`resource:${message}`)
|
|
26
|
+
this.type = IamResourceError.typeName
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ResilientError.registerErrorClass(IamError)
|
|
31
|
+
ResilientError.registerErrorClass(IamClientError)
|
|
32
|
+
ResilientError.registerErrorClass(IamResourceError)
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { InitializedService } from '@owlmeans/context'
|
|
2
|
+
import type { OidcProviderConfig } from '@owlmeans/oidc'
|
|
3
|
+
|
|
4
|
+
export interface IamClient {
|
|
5
|
+
id?: string
|
|
6
|
+
clientId: string
|
|
7
|
+
secret?: string
|
|
8
|
+
name?: string
|
|
9
|
+
/** The entity realm this client belongs to — replaces the old (client as any)._realm hack */
|
|
10
|
+
realm?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IamCredentialsPair {
|
|
14
|
+
token: string
|
|
15
|
+
realm: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IamPermissionArgs {
|
|
19
|
+
/** Action name. When absent the permission is unscoped (project-wide). */
|
|
20
|
+
permission?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IamResourceSpec {
|
|
24
|
+
name: string
|
|
25
|
+
displayName?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Unified IAM provider interface — all platform/agent code calls only this, never a backend directly */
|
|
29
|
+
export interface IamService extends InitializedService {
|
|
30
|
+
// --- Admin config (backend → OIDC RP config, payment provisioning) ---
|
|
31
|
+
getEntityAdminConfig: (entityId: string) => Promise<OidcProviderConfig>
|
|
32
|
+
getCredentialsPair: (entityId: string) => Promise<IamCredentialsPair>
|
|
33
|
+
|
|
34
|
+
// --- Provisioning (agent → story development) ---
|
|
35
|
+
ensureClient: (entityId: string, clientId: string) => Promise<IamClient>
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Ensures a permission/resource exists in the entity's client.
|
|
39
|
+
* Returns the canonical resource name (e.g. "res--action" or "res").
|
|
40
|
+
*/
|
|
41
|
+
ensurePermission: (
|
|
42
|
+
entityId: string,
|
|
43
|
+
clientId: string,
|
|
44
|
+
resource?: string,
|
|
45
|
+
args?: IamPermissionArgs
|
|
46
|
+
) => Promise<string>
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Idempotent: creates a resource, a client role for it, and assigns that role to
|
|
50
|
+
* the entity-owner role. Used by payment provisioning for account/project/wl resources.
|
|
51
|
+
*/
|
|
52
|
+
ensureResourceOwnership: (
|
|
53
|
+
entityId: string,
|
|
54
|
+
clientId: string,
|
|
55
|
+
resource: IamResourceSpec
|
|
56
|
+
) => Promise<void>
|
|
57
|
+
}
|