@go-mondo/identity-sdk 0.0.2-beta.89 → 0.0.2-beta.91
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/.release-please-manifest.json +1 -1
- package/.tsbuildinfo/cjs.json +1 -1
- package/.tsbuildinfo/esm.json +1 -1
- package/CHANGELOG.md +14 -0
- package/README.md +384 -4
- package/dist/cjs/common/resources/init.d.ts.map +1 -1
- package/dist/cjs/common/resources/init.js +1 -1
- package/dist/cjs/common/resources/init.test.js +10 -10
- package/dist/esm/common/resources/init.d.ts.map +1 -1
- package/dist/esm/common/resources/init.js +1 -1
- package/dist/esm/common/resources/init.test.js +10 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-beta.91](https://github.com/go-mondo/identity-node-sdk/compare/identity-sdk-v0.0.2-beta.90...identity-sdk-v0.0.2-beta.91) (2026-05-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* updated readme ([86fec37](https://github.com/go-mondo/identity-node-sdk/commit/86fec373da6e8412e54690b4d914dcc694339e72))
|
|
9
|
+
|
|
10
|
+
## [0.0.2-beta.90](https://github.com/go-mondo/identity-node-sdk/compare/identity-sdk-v0.0.2-beta.89...identity-sdk-v0.0.2-beta.90) (2026-05-12)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* use Bearer token ([7211bf8](https://github.com/go-mondo/identity-node-sdk/commit/7211bf88756f446602acfaf86f9483038b4a0179))
|
|
16
|
+
|
|
3
17
|
## [0.0.2-beta.89](https://github.com/go-mondo/identity-node-sdk/compare/identity-sdk-v0.0.2-beta.88...identity-sdk-v0.0.2-beta.89) (2026-05-09)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,385 @@
|
|
|
1
|
-
# Mondo Identity
|
|
2
|
-
Coming Soon...
|
|
1
|
+
# Mondo Identity Node SDK
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
TypeScript SDK for working with the Mondo Identity API from Node.js. The SDK
|
|
4
|
+
provides a configured API instance, typed resource helpers, runtime validation
|
|
5
|
+
with Zod, and exported schemas for common Mondo Identity objects.
|
|
6
|
+
|
|
7
|
+
> This package is currently published as a beta. Public APIs may continue to
|
|
8
|
+
> evolve before a stable `1.0.0` release.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- Node.js 20 or newer
|
|
13
|
+
- A Mondo Identity access token
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @go-mondo/identity-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pnpm add @go-mondo/identity-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
yarn add @go-mondo/identity-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import MondoIdentity, {
|
|
33
|
+
HttpError,
|
|
34
|
+
ValidationError,
|
|
35
|
+
} from '@go-mondo/identity-sdk';
|
|
36
|
+
import { insertUser, listUsers } from '@go-mondo/identity-sdk/customer';
|
|
37
|
+
|
|
38
|
+
const mondo = new MondoIdentity({
|
|
39
|
+
accessToken: process.env.MONDO_ACCESS_TOKEN!,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const user = await insertUser(mondo, {
|
|
44
|
+
givenName: 'Ada',
|
|
45
|
+
familyName: 'Lovelace',
|
|
46
|
+
verifiedEmail: 'ada@example.com',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(user.id);
|
|
50
|
+
|
|
51
|
+
const users = await listUsers(mondo, {
|
|
52
|
+
pageSize: 25,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log(users.items);
|
|
56
|
+
console.log(users.pagination?.nextToken);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof ValidationError) {
|
|
59
|
+
console.error(error.fields);
|
|
60
|
+
} else if (error instanceof HttpError) {
|
|
61
|
+
console.error(error.statusCode, error.type, error.message);
|
|
62
|
+
} else {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
Create a reusable `MondoIdentity` instance and pass it to resource functions.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import MondoIdentity from '@go-mondo/identity-sdk';
|
|
74
|
+
|
|
75
|
+
const mondo = new MondoIdentity({
|
|
76
|
+
accessToken: 'access-token',
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
By default, requests are sent to `https://api.mondoidentity.com`. Override the
|
|
81
|
+
host for tests or private environments:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const mondo = new MondoIdentity({
|
|
85
|
+
host: 'https://api.example.com',
|
|
86
|
+
accessToken: 'access-token',
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`accessToken` can also be a provider function. When an API request receives a
|
|
91
|
+
`401` or `403`, the SDK retries once with `refresh: true`.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const mondo = new MondoIdentity({
|
|
95
|
+
accessToken: async ({ refresh } = {}) => {
|
|
96
|
+
const token = refresh ? await refreshToken() : await getCachedToken();
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
accessToken: token.value,
|
|
100
|
+
expiresAt: token.expiresAt,
|
|
101
|
+
scope: token.scope,
|
|
102
|
+
type: 'Bearer',
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Resource Helpers
|
|
109
|
+
|
|
110
|
+
Most API helpers are exported as functions from domain subpaths. Each helper
|
|
111
|
+
accepts a configured `MondoIdentity` instance as its first argument.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { listApps, insertApp } from '@go-mondo/identity-sdk/app';
|
|
115
|
+
|
|
116
|
+
const app = await insertApp(mondo, {
|
|
117
|
+
label: 'Portal',
|
|
118
|
+
description: 'Customer portal',
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const apps = await listApps(mondo, { pageSize: 10 });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Resource classes are also exported for code that prefers grouping operations:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { UserResources } from '@go-mondo/identity-sdk/customer';
|
|
128
|
+
|
|
129
|
+
const users = new UserResources(mondo);
|
|
130
|
+
const page = await users.listItems({ pageSize: 25 });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Modules
|
|
134
|
+
|
|
135
|
+
| Import path | Includes |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| `@go-mondo/identity-sdk` | `MondoIdentity`, common schemas, HTTP errors, authorization types |
|
|
138
|
+
| `@go-mondo/identity-sdk/action` | action payload schemas |
|
|
139
|
+
| `@go-mondo/identity-sdk/activity` | activity listing helpers and activity schemas |
|
|
140
|
+
| `@go-mondo/identity-sdk/app` | app CRUD, app authorization, OAuth, OIDC, registration, SAML, app schemas |
|
|
141
|
+
| `@go-mondo/identity-sdk/association` | association list, upsert, delete helpers and schemas |
|
|
142
|
+
| `@go-mondo/identity-sdk/authentication` | sessions, settings, strategies, factors, providers, authentication schemas |
|
|
143
|
+
| `@go-mondo/identity-sdk/authorization` | roles, permissions, authorization schemas |
|
|
144
|
+
| `@go-mondo/identity-sdk/customer` | users, organizations, customer schemas and user utilities |
|
|
145
|
+
| `@go-mondo/identity-sdk/identity` | identity identifier schemas |
|
|
146
|
+
| `@go-mondo/identity-sdk/oauth` | OAuth and OIDC request/response schemas |
|
|
147
|
+
| `@go-mondo/identity-sdk/workspace` | workspace authorization, branding, membership, registration, settings, tenant, user schemas |
|
|
148
|
+
|
|
149
|
+
## Common Operations
|
|
150
|
+
|
|
151
|
+
### Users
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import {
|
|
155
|
+
deleteUser,
|
|
156
|
+
getUser,
|
|
157
|
+
insertUser,
|
|
158
|
+
listUsers,
|
|
159
|
+
updateUser,
|
|
160
|
+
} from '@go-mondo/identity-sdk/customer';
|
|
161
|
+
|
|
162
|
+
const created = await insertUser(mondo, {
|
|
163
|
+
verifiedEmail: 'grace@example.com',
|
|
164
|
+
givenName: 'Grace',
|
|
165
|
+
familyName: 'Hopper',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const user = await getUser(mondo, created.id);
|
|
169
|
+
|
|
170
|
+
await updateUser(mondo, user.id, {
|
|
171
|
+
familyName: 'Murray Hopper',
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await deleteUser(mondo, user.id);
|
|
175
|
+
|
|
176
|
+
const page = await listUsers(mondo, {
|
|
177
|
+
pageSize: 50,
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Apps
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import {
|
|
185
|
+
getApp,
|
|
186
|
+
insertApp,
|
|
187
|
+
listApps,
|
|
188
|
+
updateApp,
|
|
189
|
+
} from '@go-mondo/identity-sdk/app';
|
|
190
|
+
|
|
191
|
+
const app = await insertApp(mondo, {
|
|
192
|
+
label: 'Admin Console',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
await updateApp(mondo, app.id, {
|
|
196
|
+
description: 'Internal administration app',
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const sameApp = await getApp(mondo, app.id);
|
|
200
|
+
const apps = await listApps(mondo, { pageSize: 25 });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Authorization
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import {
|
|
207
|
+
insertPermission,
|
|
208
|
+
insertRole,
|
|
209
|
+
listPermissions,
|
|
210
|
+
listRoles,
|
|
211
|
+
} from '@go-mondo/identity-sdk/authorization';
|
|
212
|
+
|
|
213
|
+
const permission = await insertPermission(mondo, {
|
|
214
|
+
name: 'Read users',
|
|
215
|
+
description: 'Read customer user records',
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const role = await insertRole(mondo, {
|
|
219
|
+
name: 'Support',
|
|
220
|
+
description: 'Customer support access',
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const permissions = await listPermissions(mondo);
|
|
224
|
+
const roles = await listRoles(mondo);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Authentication
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import {
|
|
231
|
+
deleteSession,
|
|
232
|
+
getSettings,
|
|
233
|
+
listSessions,
|
|
234
|
+
upsertSettings,
|
|
235
|
+
} from '@go-mondo/identity-sdk/authentication';
|
|
236
|
+
|
|
237
|
+
const sessions = await listSessions(mondo, {
|
|
238
|
+
filter: {
|
|
239
|
+
user: 'usr_...',
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
await deleteSession(mondo, sessions.items[0].id);
|
|
244
|
+
|
|
245
|
+
const settings = await getSettings(mondo);
|
|
246
|
+
|
|
247
|
+
await upsertSettings(mondo, {
|
|
248
|
+
metadata: {
|
|
249
|
+
loginExperience: 'default',
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Associations
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import {
|
|
258
|
+
deleteAssociation,
|
|
259
|
+
listAssociations,
|
|
260
|
+
upsertAssociation,
|
|
261
|
+
} from '@go-mondo/identity-sdk/association';
|
|
262
|
+
|
|
263
|
+
await upsertAssociation(mondo, 'usr_...', 'rol_...', {
|
|
264
|
+
metadata: {
|
|
265
|
+
source: 'admin',
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const associations = await listAssociations(mondo, 'usr_...', {
|
|
270
|
+
filter: {
|
|
271
|
+
type: 'Role',
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
await deleteAssociation(mondo, 'usr_...', 'rol_...');
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Pagination
|
|
279
|
+
|
|
280
|
+
List helpers accept an optional pagination object:
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
const firstPage = await listUsers(mondo, { pageSize: 25 });
|
|
284
|
+
|
|
285
|
+
if (firstPage.pagination?.nextToken) {
|
|
286
|
+
const nextPage = await listUsers(mondo, {
|
|
287
|
+
pageSize: 25,
|
|
288
|
+
nextToken: firstPage.pagination.nextToken,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
console.log(nextPage.items);
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Paginated responses have the shape:
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
type PaginationCollection<T> = {
|
|
299
|
+
items: T[];
|
|
300
|
+
pagination?: {
|
|
301
|
+
pageSize?: number;
|
|
302
|
+
nextToken?: string;
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Schemas and Types
|
|
308
|
+
|
|
309
|
+
Schemas and TypeScript types are exported from each module. Use schemas when
|
|
310
|
+
you want to validate data before calling the API or parse API-compatible data in
|
|
311
|
+
your own code.
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
import {
|
|
315
|
+
UserSchema,
|
|
316
|
+
UserStatus,
|
|
317
|
+
type User,
|
|
318
|
+
} from '@go-mondo/identity-sdk/customer';
|
|
319
|
+
|
|
320
|
+
const user: User = UserSchema.parse(payload);
|
|
321
|
+
|
|
322
|
+
if (user.status === UserStatus.ACTIVE) {
|
|
323
|
+
console.log(user.email);
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
The SDK uses Zod internally to validate mutation payloads and API responses.
|
|
328
|
+
|
|
329
|
+
## Error Handling
|
|
330
|
+
|
|
331
|
+
API and network failures are normalized to `HttpError`. API validation failures
|
|
332
|
+
with field-level errors are represented as `ValidationError`.
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { HttpError, ValidationError } from '@go-mondo/identity-sdk';
|
|
336
|
+
import { getUser } from '@go-mondo/identity-sdk/customer';
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
await getUser(mondo, 'usr_...');
|
|
340
|
+
} catch (error) {
|
|
341
|
+
if (error instanceof ValidationError) {
|
|
342
|
+
console.error(error.fields);
|
|
343
|
+
} else if (error instanceof HttpError) {
|
|
344
|
+
console.error({
|
|
345
|
+
statusCode: error.statusCode,
|
|
346
|
+
type: error.type,
|
|
347
|
+
isAuthorizationError: error.isAuthorizationError,
|
|
348
|
+
});
|
|
349
|
+
} else {
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## Development
|
|
356
|
+
|
|
357
|
+
Install dependencies:
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
pnpm install
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Run checks:
|
|
364
|
+
|
|
365
|
+
```sh
|
|
366
|
+
pnpm run check-types
|
|
367
|
+
pnpm run lint
|
|
368
|
+
pnpm test
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Build CommonJS and ESM outputs:
|
|
372
|
+
|
|
373
|
+
```sh
|
|
374
|
+
pnpm run build
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Format code:
|
|
378
|
+
|
|
379
|
+
```sh
|
|
380
|
+
pnpm run format:fix
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## License
|
|
384
|
+
|
|
385
|
+
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAmB5B,QAAA,MAAM,YAAY;;;iBAA0B,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAStE;AAED,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAgB,SAAS,EAAE,UAAU,CAAC;gBAEnB,MAAM,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAmB5B,QAAA,MAAM,YAAY;;;iBAA0B,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAStE;AAED,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAgB,SAAS,EAAE,UAAU,CAAC;gBAEnB,MAAM,EAAE,WAAW;IAiBtC,qCAAqC;IACrC,IAAW,OAAO,IAAI,GAAG,CAExB;CACF"}
|
|
@@ -75,7 +75,7 @@ class MondoIdentity {
|
|
|
75
75
|
? await this.config.accessToken(options)
|
|
76
76
|
: this.config.accessToken;
|
|
77
77
|
request.headers = new Headers(request.headers);
|
|
78
|
-
request.headers.set('authorization', (0, authorization_js_1.getAccessTokenValue)(accessToken));
|
|
78
|
+
request.headers.set('authorization', `Bearer ${(0, authorization_js_1.getAccessTokenValue)(accessToken)}`);
|
|
79
79
|
return request;
|
|
80
80
|
};
|
|
81
81
|
}
|
|
@@ -107,7 +107,7 @@ const init_js_1 = require("./init.js");
|
|
|
107
107
|
const authorizedRequest = await authorize(mockRequest);
|
|
108
108
|
(0, vitest_1.expect)(authorizedRequest.headers).toBeInstanceOf(Headers);
|
|
109
109
|
const headers = authorizedRequest.headers;
|
|
110
|
-
(0, vitest_1.expect)(headers.get('authorization')).toBe('bearer-token-123');
|
|
110
|
+
(0, vitest_1.expect)(headers.get('authorization')).toBe('Bearer bearer-token-123');
|
|
111
111
|
});
|
|
112
112
|
(0, vitest_1.test)('should preserve existing headers when adding authorization', async () => {
|
|
113
113
|
const config = {
|
|
@@ -124,7 +124,7 @@ const init_js_1 = require("./init.js");
|
|
|
124
124
|
};
|
|
125
125
|
const authorizedRequest = await authorize(mockRequest);
|
|
126
126
|
const headers = authorizedRequest.headers;
|
|
127
|
-
(0, vitest_1.expect)(headers.get('authorization')).toBe('test-token');
|
|
127
|
+
(0, vitest_1.expect)(headers.get('authorization')).toBe('Bearer test-token');
|
|
128
128
|
(0, vitest_1.expect)(headers.get('content-type')).toBe('application/json');
|
|
129
129
|
(0, vitest_1.expect)(headers.get('user-agent')).toBe('test-client');
|
|
130
130
|
});
|
|
@@ -143,7 +143,7 @@ const init_js_1 = require("./init.js");
|
|
|
143
143
|
};
|
|
144
144
|
const authorizedRequest = await authorize(mockRequest);
|
|
145
145
|
const headers = authorizedRequest.headers;
|
|
146
|
-
(0, vitest_1.expect)(headers.get('authorization')).toBe('header-token');
|
|
146
|
+
(0, vitest_1.expect)(headers.get('authorization')).toBe('Bearer header-token');
|
|
147
147
|
(0, vitest_1.expect)(headers.get('accept')).toBe('application/json');
|
|
148
148
|
});
|
|
149
149
|
(0, vitest_1.test)('should handle undefined headers', async () => {
|
|
@@ -158,7 +158,7 @@ const init_js_1 = require("./init.js");
|
|
|
158
158
|
};
|
|
159
159
|
const authorizedRequest = await authorize(mockRequest);
|
|
160
160
|
const headers = authorizedRequest.headers;
|
|
161
|
-
(0, vitest_1.expect)(headers.get('authorization')).toBe('undefined-headers-token');
|
|
161
|
+
(0, vitest_1.expect)(headers.get('authorization')).toBe('Bearer undefined-headers-token');
|
|
162
162
|
});
|
|
163
163
|
(0, vitest_1.test)('should return same request reference with modified headers', async () => {
|
|
164
164
|
const config = {
|
|
@@ -189,8 +189,8 @@ const init_js_1 = require("./init.js");
|
|
|
189
189
|
const result2 = await authorize2(mockRequest2);
|
|
190
190
|
const headers1 = result1.headers;
|
|
191
191
|
const headers2 = result2.headers;
|
|
192
|
-
(0, vitest_1.expect)(headers1.get('authorization')).toBe('consistent-token');
|
|
193
|
-
(0, vitest_1.expect)(headers2.get('authorization')).toBe('consistent-token');
|
|
192
|
+
(0, vitest_1.expect)(headers1.get('authorization')).toBe('Bearer consistent-token');
|
|
193
|
+
(0, vitest_1.expect)(headers2.get('authorization')).toBe('Bearer consistent-token');
|
|
194
194
|
});
|
|
195
195
|
(0, vitest_1.test)('should resolve access token providers with authorize options', async () => {
|
|
196
196
|
const accessToken = vitest_1.vi.fn((options) => options?.refresh ? 'refreshed-token' : 'cached-token');
|
|
@@ -199,8 +199,8 @@ const init_js_1 = require("./init.js");
|
|
|
199
199
|
const refreshedRequest = await mondoIdentity.authorize({ method: 'GET' }, { refresh: true });
|
|
200
200
|
(0, vitest_1.expect)(accessToken).toHaveBeenNthCalledWith(1, undefined);
|
|
201
201
|
(0, vitest_1.expect)(accessToken).toHaveBeenNthCalledWith(2, { refresh: true });
|
|
202
|
-
(0, vitest_1.expect)(cachedRequest.headers.get('authorization')).toBe('cached-token');
|
|
203
|
-
(0, vitest_1.expect)(refreshedRequest.headers.get('authorization')).toBe('refreshed-token');
|
|
202
|
+
(0, vitest_1.expect)(cachedRequest.headers.get('authorization')).toBe('Bearer cached-token');
|
|
203
|
+
(0, vitest_1.expect)(refreshedRequest.headers.get('authorization')).toBe('Bearer refreshed-token');
|
|
204
204
|
});
|
|
205
205
|
(0, vitest_1.test)('should use the accessToken value from provider token objects', async () => {
|
|
206
206
|
const accessToken = vitest_1.vi.fn(() => ({
|
|
@@ -211,7 +211,7 @@ const init_js_1 = require("./init.js");
|
|
|
211
211
|
}));
|
|
212
212
|
const mondoIdentity = new init_js_1.MondoIdentity({ accessToken });
|
|
213
213
|
const request = await mondoIdentity.authorize({ method: 'GET' });
|
|
214
|
-
(0, vitest_1.expect)(request.headers.get('authorization')).toBe('object-token');
|
|
214
|
+
(0, vitest_1.expect)(request.headers.get('authorization')).toBe('Bearer object-token');
|
|
215
215
|
});
|
|
216
216
|
});
|
|
217
217
|
(0, vitest_1.describe)('integration tests', () => {
|
|
@@ -236,7 +236,7 @@ const init_js_1 = require("./init.js");
|
|
|
236
236
|
};
|
|
237
237
|
const authorizedRequest = await authorize(apiRequest);
|
|
238
238
|
const headers = authorizedRequest.headers;
|
|
239
|
-
(0, vitest_1.expect)(headers.get('authorization')).toBe('prod_12345abcdef67890');
|
|
239
|
+
(0, vitest_1.expect)(headers.get('authorization')).toBe('Bearer prod_12345abcdef67890');
|
|
240
240
|
(0, vitest_1.expect)(headers.get('accept')).toBe('application/json');
|
|
241
241
|
(0, vitest_1.expect)(headers.get('user-agent')).toBe('mondo-identity-sdk/1.0.0');
|
|
242
242
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAmB5B,QAAA,MAAM,YAAY;;;iBAA0B,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAStE;AAED,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAgB,SAAS,EAAE,UAAU,CAAC;gBAEnB,MAAM,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/resources/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,oBAAoB,CAAC;AAmB5B,QAAA,MAAM,YAAY;;;iBAA0B,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACvD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAStE;AAED,qBAAa,aAAc,YAAW,aAAa;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAgB,SAAS,EAAE,UAAU,CAAC;gBAEnB,MAAM,EAAE,WAAW;IAiBtC,qCAAqC;IACrC,IAAW,OAAO,IAAI,GAAG,CAExB;CACF"}
|
|
@@ -38,7 +38,7 @@ export class MondoIdentity {
|
|
|
38
38
|
? await this.config.accessToken(options)
|
|
39
39
|
: this.config.accessToken;
|
|
40
40
|
request.headers = new Headers(request.headers);
|
|
41
|
-
request.headers.set('authorization', getAccessTokenValue(accessToken));
|
|
41
|
+
request.headers.set('authorization', `Bearer ${getAccessTokenValue(accessToken)}`);
|
|
42
42
|
return request;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
@@ -105,7 +105,7 @@ describe('Common Resources - Init', () => {
|
|
|
105
105
|
const authorizedRequest = await authorize(mockRequest);
|
|
106
106
|
expect(authorizedRequest.headers).toBeInstanceOf(Headers);
|
|
107
107
|
const headers = authorizedRequest.headers;
|
|
108
|
-
expect(headers.get('authorization')).toBe('bearer-token-123');
|
|
108
|
+
expect(headers.get('authorization')).toBe('Bearer bearer-token-123');
|
|
109
109
|
});
|
|
110
110
|
test('should preserve existing headers when adding authorization', async () => {
|
|
111
111
|
const config = {
|
|
@@ -122,7 +122,7 @@ describe('Common Resources - Init', () => {
|
|
|
122
122
|
};
|
|
123
123
|
const authorizedRequest = await authorize(mockRequest);
|
|
124
124
|
const headers = authorizedRequest.headers;
|
|
125
|
-
expect(headers.get('authorization')).toBe('test-token');
|
|
125
|
+
expect(headers.get('authorization')).toBe('Bearer test-token');
|
|
126
126
|
expect(headers.get('content-type')).toBe('application/json');
|
|
127
127
|
expect(headers.get('user-agent')).toBe('test-client');
|
|
128
128
|
});
|
|
@@ -141,7 +141,7 @@ describe('Common Resources - Init', () => {
|
|
|
141
141
|
};
|
|
142
142
|
const authorizedRequest = await authorize(mockRequest);
|
|
143
143
|
const headers = authorizedRequest.headers;
|
|
144
|
-
expect(headers.get('authorization')).toBe('header-token');
|
|
144
|
+
expect(headers.get('authorization')).toBe('Bearer header-token');
|
|
145
145
|
expect(headers.get('accept')).toBe('application/json');
|
|
146
146
|
});
|
|
147
147
|
test('should handle undefined headers', async () => {
|
|
@@ -156,7 +156,7 @@ describe('Common Resources - Init', () => {
|
|
|
156
156
|
};
|
|
157
157
|
const authorizedRequest = await authorize(mockRequest);
|
|
158
158
|
const headers = authorizedRequest.headers;
|
|
159
|
-
expect(headers.get('authorization')).toBe('undefined-headers-token');
|
|
159
|
+
expect(headers.get('authorization')).toBe('Bearer undefined-headers-token');
|
|
160
160
|
});
|
|
161
161
|
test('should return same request reference with modified headers', async () => {
|
|
162
162
|
const config = {
|
|
@@ -187,8 +187,8 @@ describe('Common Resources - Init', () => {
|
|
|
187
187
|
const result2 = await authorize2(mockRequest2);
|
|
188
188
|
const headers1 = result1.headers;
|
|
189
189
|
const headers2 = result2.headers;
|
|
190
|
-
expect(headers1.get('authorization')).toBe('consistent-token');
|
|
191
|
-
expect(headers2.get('authorization')).toBe('consistent-token');
|
|
190
|
+
expect(headers1.get('authorization')).toBe('Bearer consistent-token');
|
|
191
|
+
expect(headers2.get('authorization')).toBe('Bearer consistent-token');
|
|
192
192
|
});
|
|
193
193
|
test('should resolve access token providers with authorize options', async () => {
|
|
194
194
|
const accessToken = vi.fn((options) => options?.refresh ? 'refreshed-token' : 'cached-token');
|
|
@@ -197,8 +197,8 @@ describe('Common Resources - Init', () => {
|
|
|
197
197
|
const refreshedRequest = await mondoIdentity.authorize({ method: 'GET' }, { refresh: true });
|
|
198
198
|
expect(accessToken).toHaveBeenNthCalledWith(1, undefined);
|
|
199
199
|
expect(accessToken).toHaveBeenNthCalledWith(2, { refresh: true });
|
|
200
|
-
expect(cachedRequest.headers.get('authorization')).toBe('cached-token');
|
|
201
|
-
expect(refreshedRequest.headers.get('authorization')).toBe('refreshed-token');
|
|
200
|
+
expect(cachedRequest.headers.get('authorization')).toBe('Bearer cached-token');
|
|
201
|
+
expect(refreshedRequest.headers.get('authorization')).toBe('Bearer refreshed-token');
|
|
202
202
|
});
|
|
203
203
|
test('should use the accessToken value from provider token objects', async () => {
|
|
204
204
|
const accessToken = vi.fn(() => ({
|
|
@@ -209,7 +209,7 @@ describe('Common Resources - Init', () => {
|
|
|
209
209
|
}));
|
|
210
210
|
const mondoIdentity = new MondoIdentity({ accessToken });
|
|
211
211
|
const request = await mondoIdentity.authorize({ method: 'GET' });
|
|
212
|
-
expect(request.headers.get('authorization')).toBe('object-token');
|
|
212
|
+
expect(request.headers.get('authorization')).toBe('Bearer object-token');
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
215
|
describe('integration tests', () => {
|
|
@@ -234,7 +234,7 @@ describe('Common Resources - Init', () => {
|
|
|
234
234
|
};
|
|
235
235
|
const authorizedRequest = await authorize(apiRequest);
|
|
236
236
|
const headers = authorizedRequest.headers;
|
|
237
|
-
expect(headers.get('authorization')).toBe('prod_12345abcdef67890');
|
|
237
|
+
expect(headers.get('authorization')).toBe('Bearer prod_12345abcdef67890');
|
|
238
238
|
expect(headers.get('accept')).toBe('application/json');
|
|
239
239
|
expect(headers.get('user-agent')).toBe('mondo-identity-sdk/1.0.0');
|
|
240
240
|
});
|