@portaidentity/sdk 1.7.2 → 1.8.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.
Files changed (116) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +71 -42
  3. package/dist/agent.d.ts +15 -1
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +473 -69
  6. package/dist/agent.js.map +1 -1
  7. package/dist/auth/cli-auth.d.ts +45 -71
  8. package/dist/auth/cli-auth.d.ts.map +1 -1
  9. package/dist/auth/cli-auth.js +208 -144
  10. package/dist/auth/cli-auth.js.map +1 -1
  11. package/dist/auth/index.d.ts +1 -1
  12. package/dist/auth/index.d.ts.map +1 -1
  13. package/dist/domains/applications.d.ts +22 -3
  14. package/dist/domains/applications.d.ts.map +1 -1
  15. package/dist/domains/applications.js +90 -20
  16. package/dist/domains/applications.js.map +1 -1
  17. package/dist/domains/branding.d.ts +47 -16
  18. package/dist/domains/branding.d.ts.map +1 -1
  19. package/dist/domains/branding.js +28 -5
  20. package/dist/domains/branding.js.map +1 -1
  21. package/dist/domains/clients.d.ts +23 -6
  22. package/dist/domains/clients.d.ts.map +1 -1
  23. package/dist/domains/clients.js +121 -21
  24. package/dist/domains/clients.js.map +1 -1
  25. package/dist/domains/config.d.ts +20 -3
  26. package/dist/domains/config.d.ts.map +1 -1
  27. package/dist/domains/config.js +30 -3
  28. package/dist/domains/config.js.map +1 -1
  29. package/dist/domains/custom-claims.d.ts +2 -1
  30. package/dist/domains/custom-claims.d.ts.map +1 -1
  31. package/dist/domains/custom-claims.js +2 -2
  32. package/dist/domains/custom-claims.js.map +1 -1
  33. package/dist/domains/exports.d.ts +6 -1
  34. package/dist/domains/exports.d.ts.map +1 -1
  35. package/dist/domains/exports.js +27 -1
  36. package/dist/domains/exports.js.map +1 -1
  37. package/dist/domains/helpers.d.ts +31 -0
  38. package/dist/domains/helpers.d.ts.map +1 -1
  39. package/dist/domains/helpers.js +72 -1
  40. package/dist/domains/helpers.js.map +1 -1
  41. package/dist/domains/imports.d.ts +8 -7
  42. package/dist/domains/imports.d.ts.map +1 -1
  43. package/dist/domains/imports.js +158 -14
  44. package/dist/domains/imports.js.map +1 -1
  45. package/dist/domains/index.d.ts +1 -1
  46. package/dist/domains/index.d.ts.map +1 -1
  47. package/dist/domains/organizations.d.ts +2 -9
  48. package/dist/domains/organizations.d.ts.map +1 -1
  49. package/dist/domains/organizations.js +2 -13
  50. package/dist/domains/organizations.js.map +1 -1
  51. package/dist/domains/permissions.d.ts +22 -4
  52. package/dist/domains/permissions.d.ts.map +1 -1
  53. package/dist/domains/permissions.js +47 -13
  54. package/dist/domains/permissions.js.map +1 -1
  55. package/dist/domains/roles.d.ts +26 -16
  56. package/dist/domains/roles.d.ts.map +1 -1
  57. package/dist/domains/roles.js +61 -31
  58. package/dist/domains/roles.js.map +1 -1
  59. package/dist/domains/user-roles.d.ts +9 -4
  60. package/dist/domains/user-roles.d.ts.map +1 -1
  61. package/dist/domains/user-roles.js +32 -6
  62. package/dist/domains/user-roles.js.map +1 -1
  63. package/dist/domains/users.d.ts +31 -26
  64. package/dist/domains/users.d.ts.map +1 -1
  65. package/dist/domains/users.js +56 -46
  66. package/dist/domains/users.js.map +1 -1
  67. package/dist/errors/index.d.ts +2 -0
  68. package/dist/errors/index.d.ts.map +1 -1
  69. package/dist/errors/index.js +18 -1
  70. package/dist/errors/index.js.map +1 -1
  71. package/dist/index.d.ts +1 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js.map +1 -1
  74. package/dist/node.d.ts +1 -1
  75. package/dist/node.d.ts.map +1 -1
  76. package/dist/pagination/index.d.ts +5 -1
  77. package/dist/pagination/index.d.ts.map +1 -1
  78. package/dist/pagination/index.js +2 -2
  79. package/dist/pagination/index.js.map +1 -1
  80. package/dist/types/applications.d.ts +27 -6
  81. package/dist/types/applications.d.ts.map +1 -1
  82. package/dist/types/branding.d.ts +38 -11
  83. package/dist/types/branding.d.ts.map +1 -1
  84. package/dist/types/branding.js +0 -5
  85. package/dist/types/branding.js.map +1 -1
  86. package/dist/types/bulk.d.ts +2 -4
  87. package/dist/types/bulk.d.ts.map +1 -1
  88. package/dist/types/clients.d.ts +98 -13
  89. package/dist/types/clients.d.ts.map +1 -1
  90. package/dist/types/common.d.ts +26 -3
  91. package/dist/types/common.d.ts.map +1 -1
  92. package/dist/types/config.d.ts +57 -21
  93. package/dist/types/config.d.ts.map +1 -1
  94. package/dist/types/config.js +1 -8
  95. package/dist/types/config.js.map +1 -1
  96. package/dist/types/exports.d.ts +17 -0
  97. package/dist/types/exports.d.ts.map +1 -1
  98. package/dist/types/imports.d.ts +388 -84
  99. package/dist/types/imports.d.ts.map +1 -1
  100. package/dist/types/imports.js +1 -7
  101. package/dist/types/imports.js.map +1 -1
  102. package/dist/types/index.d.ts +14 -14
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/organizations.d.ts +5 -9
  105. package/dist/types/organizations.d.ts.map +1 -1
  106. package/dist/types/permissions.d.ts +21 -6
  107. package/dist/types/permissions.d.ts.map +1 -1
  108. package/dist/types/roles.d.ts +3 -1
  109. package/dist/types/roles.d.ts.map +1 -1
  110. package/dist/types/user-roles.d.ts +4 -10
  111. package/dist/types/user-roles.d.ts.map +1 -1
  112. package/dist/types/users.d.ts +102 -15
  113. package/dist/types/users.d.ts.map +1 -1
  114. package/dist/version.d.ts +1 -1
  115. package/dist/version.js +1 -1
  116. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.8.0] - 2026-09-23
9
+
10
+ ### Changed
11
+ - Version bump to 1.8.0
12
+
13
+ ## [1.7.3] - 2026-08-26
14
+
15
+ ### Changed
16
+ - Version bump to 1.7.3
17
+
8
18
  ## [1.7.2] - 2026-08-26
9
19
 
10
20
  ### Changed
package/README.md CHANGED
@@ -24,16 +24,16 @@ yarn add @portaidentity/sdk
24
24
 
25
25
  ## Quick Start
26
26
 
27
- ### Browser (Admin GUI / BFF)
27
+ ### Browser
28
28
 
29
29
  ```typescript
30
30
  import { createPortaClient, createBrowserTransport } from '@portaidentity/sdk/browser';
31
31
 
32
32
  const transport = createBrowserTransport({
33
- baseUrl: '/api/admin', // BFF proxy path
34
- csrfCookieName: '_csrf', // CSRF cookie name
33
+ baseUrl: '/api/admin', // BFF proxy path
34
+ csrfCookieName: '_csrf', // CSRF cookie name
35
35
  csrfHeaderName: 'x-csrf-token',
36
- on401: () => window.location.href = '/login',
36
+ on401: () => (window.location.href = '/login'),
37
37
  });
38
38
 
39
39
  const client = createPortaClient(transport);
@@ -42,7 +42,8 @@ const client = createPortaClient(transport);
42
42
  const orgs = await client.organizations.list({ page: 1, pageSize: 20 });
43
43
 
44
44
  // Create a user
45
- const user = await client.users.create('org-id', {
45
+ const user = await client.users.create({
46
+ organizationId: 'org-id',
46
47
  email: 'user@example.com',
47
48
  givenName: 'Jane',
48
49
  familyName: 'Doe',
@@ -66,8 +67,8 @@ const client = createPortaClient(transport);
66
67
  // List all organizations (auto-pagination)
67
68
  const allOrgs = await client.organizations.listAll();
68
69
 
69
- // Suspend a user
70
- await client.users.suspend('org-id', 'user-id');
70
+ // Deactivate a user
71
+ await client.users.deactivate('org-id', 'user-id');
71
72
 
72
73
  // Assign a role
73
74
  await client.userRoles.assign('org-id', 'user-id', { roleId: 'role-id' });
@@ -76,10 +77,14 @@ await client.userRoles.assign('org-id', 'user-id', { roleId: 'role-id' });
76
77
  ### Client Credentials (Server-to-Server)
77
78
 
78
79
  ```typescript
79
- import { createPortaClient, createNodeTransport, createClientCredentialsAuth } from '@portaidentity/sdk/node';
80
+ import {
81
+ createPortaClient,
82
+ createNodeTransport,
83
+ createClientCredentialsAuth,
84
+ } from '@portaidentity/sdk/node';
80
85
 
81
86
  const auth = createClientCredentialsAuth({
82
- tokenUrl: 'https://porta.local:3443/super-admin/oidc/token',
87
+ tokenUrl: 'https://porta.local:3443/super-admin/token',
83
88
  clientId: 'my-service',
84
89
  clientSecret: 'my-secret',
85
90
  scope: 'openid',
@@ -105,7 +110,7 @@ const tools = getToolDefinitions();
105
110
 
106
111
  // Execute a tool call from an AI agent
107
112
  const client = createPortaClient(
108
- createNodeTransport({ baseUrl: '...', auth: createTokenAuth('...') })
113
+ createNodeTransport({ baseUrl: '...', auth: createTokenAuth('...') }),
109
114
  );
110
115
 
111
116
  const result = await executeTool(client, 'organizations.list', { page: 1 });
@@ -113,35 +118,55 @@ const result = await executeTool(client, 'organizations.list', { page: 1 });
113
118
 
114
119
  ## Domain Namespaces
115
120
 
116
- | Namespace | Methods | Description |
117
- |-----------|---------|-------------|
118
- | `organizations` | 12 | CRUD, status lifecycle, slug validation, history |
119
- | `applications` | 13 | CRUD, status, modules management, history |
120
- | `clients` | 12 | CRUD, status, secret management, history |
121
- | `users` | 19 | CRUD, 6 status transitions, password, email, export, purge |
122
- | `roles` | 9 | CRUD, archive, permission assignment |
123
- | `permissions` | 6 | CRUD, archive |
124
- | `userRoles` | 3 | List, assign, remove role assignments |
125
- | `userClaims` | 3 | List, set, remove claim values |
126
- | `customClaims` | 6 | Claim definitions CRUD, archive |
127
- | `config` | 3 | System configuration get/set/list |
128
- | `keys` | 3 | Signing key list/generate/rotate |
129
- | `audit` | 1 | Audit log listing with filters |
130
- | `stats` | 1 | Dashboard statistics |
131
- | `sessions` | 3 | Session listing and revocation |
132
- | `bulk` | 1 | Bulk status operations |
133
- | `branding` | 5 | Org branding settings and asset management |
134
- | `exports` | 1 | CSV/JSON data export |
135
- | `twoFactor` | 3 | 2FA status, disable, reset |
136
- | `imports` | 1 | Declarative provisioning |
121
+ | Namespace | Methods | Description |
122
+ | --------------- | ------- | ----------------------------------------------------- |
123
+ | `organizations` | 10 | CRUD, status lifecycle, slug validation, history |
124
+ | `applications` | 13 | CRUD, status, module management, history |
125
+ | `clients` | 12 | CRUD, status, secret management, history |
126
+ | `users` | 19 | CRUD, status transitions, password, email, and export |
127
+ | `roles` | 9 | CRUD and permission assignment |
128
+ | `permissions` | 6 | CRUD |
129
+ | `userRoles` | 3 | List, assign, remove role assignments |
130
+ | `userClaims` | 3 | List, set, remove claim values |
131
+ | `customClaims` | 6 | Claim definition CRUD |
132
+ | `config` | 3 | System configuration get/set/list |
133
+ | `keys` | 3 | Signing key list/generate/rotate |
134
+ | `audit` | 1 | Audit log listing with filters |
135
+ | `stats` | 1 | Dashboard statistics |
136
+ | `sessions` | 3 | Session listing and revocation |
137
+ | `bulk` | 1 | Bulk status operations |
138
+ | `branding` | 5 | Org branding settings and asset management |
139
+ | `exports` | 2 | CSV/JSON reports and selective manifest export |
140
+ | `twoFactor` | 3 | 2FA status, disable, reset |
141
+ | `imports` | 2 | Manifest preview and atomic import |
142
+
143
+ ## Environment Portability
144
+
145
+ ```typescript
146
+ const exported = await client.exports.manifest({
147
+ scope: { kind: 'organization', organization_slug: 'acme' },
148
+ categories: ['organizations', 'applications_authorization'],
149
+ application_selection: { all_applications: true, application_slugs: [] },
150
+ });
151
+
152
+ const preview = await client.imports.preview(exported.manifest);
153
+ if (preview.errors.length === 0) {
154
+ const applied = await client.imports.apply(exported.manifest, 'keep-existing');
155
+ // Store any applied.credentials secrets now; Porta returns them only once.
156
+ }
157
+ ```
158
+
159
+ The SDK returns parsed data and never writes files. Manifest export excludes existing credentials
160
+ and other authentication material. Import callers should always preview first; apply repeats all
161
+ server validation and commits atomically.
137
162
 
138
163
  ## Auth Providers
139
164
 
140
- | Provider | Use Case |
141
- |----------|----------|
142
- | `createTokenAuth(token)` | Static Bearer token (scripts, testing) |
143
- | `createClientCredentialsAuth(opts)` | Server-to-server OAuth2 (with caching and concurrent dedup) |
144
- | `createCliAuth(opts)` | CLI credentials file (`~/.porta/credentials.json`) with auto-refresh |
165
+ | Provider | Use Case |
166
+ | ----------------------------------- | -------------------------------------------------------------------- |
167
+ | `createTokenAuth(token)` | Static Bearer token (scripts, testing) |
168
+ | `createClientCredentialsAuth(opts)` | Server-to-server OAuth2 (with caching and concurrent dedup) |
169
+ | `createCliAuth(opts)` | CLI credentials file (`~/.porta/credentials.json`) with auto-refresh |
145
170
 
146
171
  ## Error Handling
147
172
 
@@ -173,6 +198,10 @@ const allUsers = await client.users.listAll('org-id');
173
198
  // → User[]
174
199
  ```
175
200
 
201
+ `users.invite()` returns an `InviteUserResult`. Administrators can activate and deactivate users.
202
+ User lockout is automatic and is not an administrator mutation. `users.getHistory()` returns the
203
+ first-page `{ data, hasMore, nextCursor }` history envelope.
204
+
176
205
  ## Architecture
177
206
 
178
207
  ```
@@ -199,12 +228,12 @@ const allUsers = await client.users.listAll('org-id');
199
228
 
200
229
  ## Entrypoints
201
230
 
202
- | Import Path | Includes | Excludes |
203
- |------------|----------|----------|
204
- | `@portaidentity/sdk` | Types, errors, pagination, client factory | Transport, auth (bring your own) |
205
- | `@portaidentity/sdk/browser` | + BrowserTransport | NodeTransport, auth providers |
206
- | `@portaidentity/sdk/node` | + NodeTransport, all auth providers | BrowserTransport |
207
- | `@portaidentity/sdk/agent` | + Tool definitions, executeTool | Transports, auth |
231
+ | Import Path | Includes | Excludes |
232
+ | ---------------------------- | ----------------------------------------- | -------------------------------- |
233
+ | `@portaidentity/sdk` | Types, errors, pagination, client factory | Transport, auth (bring your own) |
234
+ | `@portaidentity/sdk/browser` | + BrowserTransport | NodeTransport, auth providers |
235
+ | `@portaidentity/sdk/node` | + NodeTransport, all auth providers | BrowserTransport |
236
+ | `@portaidentity/sdk/agent` | + Tool definitions, executeTool | Transports, auth |
208
237
 
209
238
  ## Testing
210
239
 
package/dist/agent.d.ts CHANGED
@@ -8,21 +8,35 @@
8
8
  */
9
9
  import type { PortaClient } from './client.js';
10
10
  export interface ToolParameter {
11
+ /** Argument name passed to the executor. */
11
12
  name: string;
12
- type: 'string' | 'number' | 'boolean' | 'object';
13
+ /** JSON-compatible argument category exposed to agent clients. */
14
+ type: 'string' | 'number' | 'number|string' | 'boolean' | 'object' | 'array';
15
+ /** Human-readable explanation of the argument. */
13
16
  description: string;
17
+ /** Whether callers must provide the argument. */
14
18
  required: boolean;
19
+ /** Optional closed set of accepted string values. */
15
20
  enum?: string[];
16
21
  }
22
+ /** Metadata that describes one callable SDK operation. */
17
23
  export interface ToolDefinition {
24
+ /** Dot-separated SDK domain and method name. */
18
25
  name: string;
26
+ /** Human-readable explanation of the operation. */
19
27
  description: string;
28
+ /** Ordered arguments forwarded to the SDK method. */
20
29
  parameters: ToolParameter[];
30
+ /** Human-readable TypeScript-style result description. */
21
31
  returns: string;
22
32
  }
33
+ /** Result returned by the generic tool executor. */
23
34
  export interface ToolResult {
35
+ /** Whether the SDK method completed successfully. */
24
36
  success: boolean;
37
+ /** SDK result when the operation succeeds. */
25
38
  data?: unknown;
39
+ /** Safe error description when the operation fails. */
26
40
  error?: string;
27
41
  }
28
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,K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