@owlmeans/iam 0.1.7 → 0.1.8

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/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @owlmeans/iam
2
+
3
+ Provider-agnostic IAM abstraction for the OwlMeans framework — `IamService` interface, client/realm types, and permission helpers.
4
+
5
+ ## Overview
6
+
7
+ - `IamService` — unified interface for provisioning clients, realms, and permissions across IAM backends (e.g. Keycloak, built-in)
8
+ - `IamClient` / `IamCredentialsPair` / `IamResourceSpec` — shared contract types used by server-side IAM implementations
9
+ - `IamPermissionArgs` — describes a named permission including resource-scope and human-readable title
10
+ - `hasPermission` — utility to check whether a set of grants covers a given permission/resource pair
11
+ - Errors: `IamError` and subtypes for client-provisioning and permission failures
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ bun add @owlmeans/iam
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```typescript
22
+ import type { IamService, IamClient } from '@owlmeans/iam'
23
+ import { hasPermission } from '@owlmeans/iam'
24
+
25
+ // Check whether an auth payload includes a required permission
26
+ const allowed = hasPermission(auth, { permission: 'manage-users', resourceScoped: false })
27
+ ```
28
+
29
+ Typically consumed via `@owlmeans/server-iam` which wires the concrete OIDC-backed implementation.
30
+
31
+ <!-- owlmeans:agent-guidance:start -->
32
+ ## Agent guidance
33
+
34
+ This package ships embedded Claude Code skills and GitHub Copilot instructions under
35
+ `agent-meta/`. After installing your `@owlmeans/*` packages, run the OwlMeans
36
+ agent-skills installer to place them into your project's native locations
37
+ (`.claude/skills/` and `.github/instructions/`):
38
+
39
+ ```sh
40
+ npx @owlmeans/agent-skills
41
+ ```
42
+
43
+ The embedded files are version-matched to this package release. Do not edit them
44
+ directly — they are regenerated on each publish. To contribute guidance edits,
45
+ open a PR against the source monorepo.
46
+ <!-- owlmeans:agent-guidance:end -->
@@ -0,0 +1,115 @@
1
+ ---
2
+ description: "IamService abstraction for provider-agnostic IAM provisioning. Load when wiring IAM operations, switching IAM mode, or implementing a new IAM provider."
3
+ applyTo: "**/services/iam*.ts, **/context.ts, **/types.ts"
4
+ ---
5
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
6
+
7
+ # Using `@owlmeans/iam`
8
+
9
+ Provider-agnostic IAM abstraction. Defines `IamService` interface and related types. Used by both the platform backend (`viable-backend`) and the agent library (`@owlmeans/viable`). Concrete implementations live in `@owlmeans/iam-keycloak` (full proxy) and `@owlmeans/iam-integrated`.
10
+
11
+ ## Public API surface
12
+
13
+ | Symbol | Kind | Purpose |
14
+ |--------|------|---------|
15
+ | `IamService` | type | Unified IAM interface — all provisioning + authorization operations |
16
+ | `IamClient` | type | Provisioned OIDC client `{ id?, clientId, secret?, name?, realm? }` |
17
+ | `IamCredentialsPair` | type | `{ token: string; realm: string }` |
18
+ | `IamPermissionArgs` | type | `{ permission?, resourceScoped?, title? }` — `permission` absent means unscoped resource name |
19
+ | `IamResourceSpec` | type | `{ name: string; displayName?: string }` |
20
+ | `IamPermissionDefinition` | type | Declared permission `{ name, resource, action?, resourceScoped?, title? }` |
21
+ | `IamGrantArgs` | type | `{ resources?: string[] }` — present = resource-scoped grant form |
22
+ | `IamGrant` | type | `{ profileId, clientId, permission, resources? }` |
23
+ | `hasPermission` | fn | `(auth, permission, { scope?, resourceId? }?)` — checks `Authorization.permissions` PermissionSet[]; an unscoped set satisfies a resourceId check |
24
+ | `DEFAULT_ALIAS` | const | Default service alias `'iam-service'` |
25
+ | `IAM_MODE_KEYCLOAK` | const | `'keycloak'` |
26
+ | `IAM_MODE_INTEGRATED` | const | `'integrated'` |
27
+ | `IamMode` | type | `'keycloak' \| 'integrated'` |
28
+ | `IamError` | class | Base IAM error |
29
+ | `IamClientError` | class | Thrown when an OIDC client is missing a required field (e.g. `secret`) |
30
+ | `IamResourceError` | class | Thrown when a KC resource returns with no name |
31
+ | `IamGrantError` | class | Grant subject missing or entity mismatch |
32
+ | `IamUnsupported` | class | Operation not supported by the active backend (e.g. resource-scoped grants on Keycloak) |
33
+
34
+ ## Permission model (two grant forms)
35
+
36
+ Permissions are declared per entity client (project) with `ensurePermission` and granted to end-user
37
+ subjects with `grantPermission`:
38
+
39
+ - **Unscoped (project-wide)**: `grantPermission(entityId, clientId, profileId, 'article--modify')`
40
+ - **Resource-scoped**: `grantPermission(entityId, clientId, profileId, 'department--modify', { resources: ['dep-123'] })` —
41
+ the grant only applies to the listed resource ids.
42
+
43
+ Grants materialize as OwlMeans `PermissionSet[]` (`scope` = clientId; resource-scoped grants live in a
44
+ dedicated set per permission carrying `resources[]`, because `resources` applies to all keys of a set).
45
+
46
+ ## `IamService` interface
47
+
48
+ ```ts
49
+ interface IamService extends InitializedService {
50
+ // Get the admin OIDC provider config for a tenant (used in payment provisioning, RP config)
51
+ getEntityAdminConfig: (entityId: string) => Promise<OidcProviderConfig>
52
+
53
+ // Get an admin { token, realm } pair for raw low-level calls (avoid unless necessary)
54
+ getCredentialsPair: (entityId: string) => Promise<IamCredentialsPair>
55
+
56
+ // Provision an OIDC client for a tenant and return its credentials
57
+ ensureClient: (entityId: string, clientId: string) => Promise<IamClient>
58
+
59
+ // Provision a named permission on a client resource; returns the resource name
60
+ ensurePermission: (entityId: string, clientId: string, resource?: string, args?: IamPermissionArgs) => Promise<string>
61
+
62
+ // Provision a resource and assign it to the tenant's owner role (used in payment provisioning)
63
+ ensureResourceOwnership: (entityId: string, clientId: string, resource: IamResourceSpec) => Promise<void>
64
+
65
+ // --- Authorization (permission definitions & grants) ---
66
+
67
+ // List permission definitions registered for the entity's client
68
+ listPermissions: (entityId: string, clientId: string) => Promise<IamPermissionDefinition[]>
69
+
70
+ // Grant a permission to an end-user subject; args.resources = resource-scoped form
71
+ grantPermission: (entityId: string, clientId: string, profileId: string, permission: string, args?: IamGrantArgs) => Promise<IamGrant>
72
+
73
+ // Revoke; with args.resources only those ids are removed, else the whole grant
74
+ revokePermission: (entityId: string, clientId: string, profileId: string, permission: string, args?: IamGrantArgs) => Promise<void>
75
+
76
+ // List grants for the client, optionally for one subject
77
+ listGrants: (entityId: string, clientId: string, profileId?: string) => Promise<IamGrant[]>
78
+ }
79
+ ```
80
+
81
+ ## `IamClient.realm` field
82
+
83
+ `realm` is set by the provider to the entity ID. Use it instead of accessing internal properties:
84
+
85
+ ```ts
86
+ // ✓ correct
87
+ await meta.update('oidcRealm', client.realm ?? fallbackEntityId)
88
+
89
+ // ✗ never do this — internal Keycloak implementation detail
90
+ await meta.update('oidcRealm', (client as any)._realm)
91
+ ```
92
+
93
+ ## Selecting the IAM provider
94
+
95
+ The platform wires the correct implementation via `IAM_MODE` environment variable. Default is `'keycloak'`. Do not read `IAM_MODE` directly from feature code — it belongs in the service-factory only:
96
+
97
+ ```ts
98
+ export const makeIamService = (mode = process.env.IAM_MODE ?? 'keycloak') => {
99
+ if (mode === 'integrated') return makeIamIntegratedService(VIABLE_IAM)
100
+ return makeIamKeycloakService(VIABLE_IAM, { oidcProductAlias: OIDC_PRODUCT })
101
+ }
102
+ ```
103
+
104
+ ## Rules
105
+
106
+ - Always depend on `IamService` from `@owlmeans/iam`, not on `KeycloakApiService` directly.
107
+ - Do not expose `getCredentialsPair` to request handlers — it returns a raw admin token.
108
+ - `IamClientError` means the provisioned client was invalid (missing secret, null token). The proxy already throws it; callers only need to handle it, not re-throw wrapped errors.
109
+ - The `realm` field on `IamClient` is guaranteed to be set by all concrete implementations.
110
+
111
+ ## Related instructions
112
+
113
+ - `@owlmeans/iam-keycloak` (internal) — full proxy over Keycloak; see `iam-keycloak.instructions.md`
114
+ - `@owlmeans/keycloak` (internal) — low-level KC admin API; see `keycloak.instructions.md`
115
+ - `@owlmeans/server-iam` — IAM gate asserting both grant forms; see `server-iam.instructions.md`
@@ -0,0 +1,16 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "package": "@owlmeans/iam",
4
+ "version": "0.1.8",
5
+ "generatedAt": "2026-06-11T16:30:27.190Z",
6
+ "canonicalRepo": "https://github.com/owlmeans/common",
7
+ "entries": [
8
+ {
9
+ "kind": "instruction",
10
+ "name": "iam",
11
+ "category": "package-specific",
12
+ "file": "instructions/iam.instructions.md",
13
+ "canonicalPath": ".github/instructions/iam.instructions.md"
14
+ }
15
+ ]
16
+ }
package/build/errors.d.ts CHANGED
@@ -19,4 +19,8 @@ export declare class IamUnsupported extends IamError {
19
19
  static typeName: string;
20
20
  constructor(message?: string);
21
21
  }
22
+ export declare class IamUserError extends IamError {
23
+ static typeName: string;
24
+ constructor(message?: string);
25
+ }
22
26
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +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;AAED,qBAAa,aAAc,SAAQ,QAAQ;IACzC,OAAuB,QAAQ,SAAuC;gBAE1D,OAAO,SAAU;CAI9B;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,OAAuB,QAAQ,SAA6C;gBAEhE,OAAO,SAAU;CAI9B"}
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;AAED,qBAAa,aAAc,SAAQ,QAAQ;IACzC,OAAuB,QAAQ,SAAuC;gBAE1D,OAAO,SAAU;CAI9B;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,OAAuB,QAAQ,SAA6C;gBAEhE,OAAO,SAAU;CAI9B;AAED,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAuB,QAAQ,SAAsC;gBAEzD,OAAO,SAAU;CAI9B"}
package/build/errors.js CHANGED
@@ -34,9 +34,17 @@ export class IamUnsupported extends IamError {
34
34
  this.type = IamUnsupported.typeName;
35
35
  }
36
36
  }
37
+ export class IamUserError extends IamError {
38
+ static typeName = `IamUser${ResilientError.typeName}`;
39
+ constructor(message = 'error') {
40
+ super(`user:${message}`);
41
+ this.type = IamUserError.typeName;
42
+ }
43
+ }
37
44
  ResilientError.registerErrorClass(IamError);
38
45
  ResilientError.registerErrorClass(IamClientError);
39
46
  ResilientError.registerErrorClass(IamResourceError);
40
47
  ResilientError.registerErrorClass(IamGrantError);
41
48
  ResilientError.registerErrorClass(IamUnsupported);
49
+ ResilientError.registerErrorClass(IamUserError);
42
50
  //# sourceMappingURL=errors.js.map
@@ -1 +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,cA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OAAO,cAAe,SAAQ,QAAQ;IACnC,MAAM,CAAU,QAAQ,GAAG,iBAAiB,cAAc,CAAC,QAAQ,EAAE,CAAA;IAE5E,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAA;QAC/B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAA;IACrC,CAAC;;AAGH,MAAM,OAAO,YAAa,SAAQ,QAAQ;IACjC,MAAM,CAAU,QAAQ,GAAG,UAAU,cAAc,CAAC,QAAQ,EAAE,CAAA;IAErE,YAAY,OAAO,GAAG,OAAO;QAC3B,KAAK,CAAC,QAAQ,OAAO,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAA;IACnC,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;AACnD,cAAc,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;AAChD,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAA;AACjD,cAAc,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA"}
package/build/types.d.ts CHANGED
@@ -47,6 +47,32 @@ export interface IamGrant {
47
47
  /** Present only for resource-scoped grants. */
48
48
  resources?: string[];
49
49
  }
50
+ /** An end-user of an entity (customer-wide; shared across that entity's projects). */
51
+ export interface IamUser {
52
+ /** Backend-specific subject id: integrated = IdentityProfile.profileId, keycloak = KC user id. */
53
+ profileId: string;
54
+ /** Primary login identifier (email for the integrated OTP path). */
55
+ email?: string;
56
+ name?: string;
57
+ /** AuthRole value. */
58
+ role: string;
59
+ disabled?: boolean;
60
+ /** Convenience count of permission grants the user holds (across clients, or for one client). */
61
+ grantCount?: number;
62
+ }
63
+ /** Args to invite/create an end-user under an entity. */
64
+ export interface IamUserInvite {
65
+ email: string;
66
+ name?: string;
67
+ /** AuthRole value; defaults to the backend's standard end-user role. */
68
+ role?: string;
69
+ }
70
+ /** Args to update an existing end-user. */
71
+ export interface IamUserUpdate {
72
+ name?: string;
73
+ role?: string;
74
+ disabled?: boolean;
75
+ }
50
76
  /** Unified IAM provider interface — all platform/agent code calls only this, never a backend directly */
51
77
  export interface IamService extends InitializedService {
52
78
  getEntityAdminConfig: (entityId: string) => Promise<OidcProviderConfig>;
@@ -76,5 +102,18 @@ export interface IamService extends InitializedService {
76
102
  revokePermission: (entityId: string, clientId: string, profileId: string, permission: string, args?: IamGrantArgs) => Promise<void>;
77
103
  /** Lists grants for the entity's client, optionally for a single subject. */
78
104
  listGrants: (entityId: string, clientId: string, profileId?: string) => Promise<IamGrant[]>;
105
+ /**
106
+ * Lists the entity's end-users. With clientId, narrows to users holding at least
107
+ * one grant for that client (per-project view).
108
+ */
109
+ listUsers: (entityId: string, clientId?: string) => Promise<IamUser[]>;
110
+ /** Loads a single end-user by subject id, or null when absent. */
111
+ getUser: (entityId: string, profileId: string) => Promise<IamUser | null>;
112
+ /** Creates (or resolves, idempotently by email) an end-user under the entity. */
113
+ inviteUser: (entityId: string, invite: IamUserInvite) => Promise<IamUser>;
114
+ /** Updates an end-user's mutable fields (name, role, disabled). */
115
+ updateUser: (entityId: string, profileId: string, update: IamUserUpdate) => Promise<IamUser>;
116
+ /** Removes an end-user from the entity (their grants go with them). */
117
+ removeUser: (entityId: string, profileId: string) => Promise<void>;
79
118
  }
80
119
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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,C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EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAE5F,uEAAuE;IACvE,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACnE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/iam",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,10 +22,10 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@owlmeans/auth": "^0.1.7",
26
- "@owlmeans/context": "^0.1.7",
27
- "@owlmeans/error": "^0.1.7",
28
- "@owlmeans/oidc": "^0.1.7"
25
+ "@owlmeans/auth": "^0.1.8",
26
+ "@owlmeans/context": "^0.1.8",
27
+ "@owlmeans/error": "^0.1.8",
28
+ "@owlmeans/oidc": "^0.1.8"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@owlmeans/dep-config": "workspace:*",
package/src/errors.ts CHANGED
@@ -45,8 +45,18 @@ export class IamUnsupported extends IamError {
45
45
  }
46
46
  }
47
47
 
48
+ export class IamUserError extends IamError {
49
+ public static override typeName = `IamUser${ResilientError.typeName}`
50
+
51
+ constructor(message = 'error') {
52
+ super(`user:${message}`)
53
+ this.type = IamUserError.typeName
54
+ }
55
+ }
56
+
48
57
  ResilientError.registerErrorClass(IamError)
49
58
  ResilientError.registerErrorClass(IamClientError)
50
59
  ResilientError.registerErrorClass(IamResourceError)
51
60
  ResilientError.registerErrorClass(IamGrantError)
52
61
  ResilientError.registerErrorClass(IamUnsupported)
62
+ ResilientError.registerErrorClass(IamUserError)
package/src/types.ts CHANGED
@@ -55,6 +55,35 @@ export interface IamGrant {
55
55
  resources?: string[]
56
56
  }
57
57
 
58
+ /** An end-user of an entity (customer-wide; shared across that entity's projects). */
59
+ export interface IamUser {
60
+ /** Backend-specific subject id: integrated = IdentityProfile.profileId, keycloak = KC user id. */
61
+ profileId: string
62
+ /** Primary login identifier (email for the integrated OTP path). */
63
+ email?: string
64
+ name?: string
65
+ /** AuthRole value. */
66
+ role: string
67
+ disabled?: boolean
68
+ /** Convenience count of permission grants the user holds (across clients, or for one client). */
69
+ grantCount?: number
70
+ }
71
+
72
+ /** Args to invite/create an end-user under an entity. */
73
+ export interface IamUserInvite {
74
+ email: string
75
+ name?: string
76
+ /** AuthRole value; defaults to the backend's standard end-user role. */
77
+ role?: string
78
+ }
79
+
80
+ /** Args to update an existing end-user. */
81
+ export interface IamUserUpdate {
82
+ name?: string
83
+ role?: string
84
+ disabled?: boolean
85
+ }
86
+
58
87
  /** Unified IAM provider interface — all platform/agent code calls only this, never a backend directly */
59
88
  export interface IamService extends InitializedService {
60
89
  // --- Admin config (backend → OIDC RP config, payment provisioning) ---
@@ -116,4 +145,24 @@ export interface IamService extends InitializedService {
116
145
 
117
146
  /** Lists grants for the entity's client, optionally for a single subject. */
118
147
  listGrants: (entityId: string, clientId: string, profileId?: string) => Promise<IamGrant[]>
148
+
149
+ // --- End-user management (customer-wide users, shared per entityId) ---
150
+
151
+ /**
152
+ * Lists the entity's end-users. With clientId, narrows to users holding at least
153
+ * one grant for that client (per-project view).
154
+ */
155
+ listUsers: (entityId: string, clientId?: string) => Promise<IamUser[]>
156
+
157
+ /** Loads a single end-user by subject id, or null when absent. */
158
+ getUser: (entityId: string, profileId: string) => Promise<IamUser | null>
159
+
160
+ /** Creates (or resolves, idempotently by email) an end-user under the entity. */
161
+ inviteUser: (entityId: string, invite: IamUserInvite) => Promise<IamUser>
162
+
163
+ /** Updates an end-user's mutable fields (name, role, disabled). */
164
+ updateUser: (entityId: string, profileId: string, update: IamUserUpdate) => Promise<IamUser>
165
+
166
+ /** Removes an end-user from the entity (their grants go with them). */
167
+ removeUser: (entityId: string, profileId: string) => Promise<void>
119
168
  }