|
1 | 1 | import createDebug from 'debug'; |
2 | 2 |
|
3 | 3 | import { AuthManager } from './auth'; |
4 | | -import { CollectionTypeManager, SingleTypeManager } from './content-types'; |
| 4 | +import { |
| 5 | + CollectionTypeManager, |
| 6 | + SingleTypeManager, |
| 7 | + UsersPermissionsUsersManager, |
| 8 | +} from './content-types'; |
5 | 9 | import { getWellKnownCollection, getWellKnownSingle } from './content-types/constants'; |
6 | 10 | import { StrapiError, StrapiInitializationError } from './errors'; |
7 | 11 | import { FilesManager } from './files'; |
8 | 12 | import { HttpClient } from './http'; |
9 | 13 | import { AuthInterceptors, HttpInterceptors } from './interceptors'; |
10 | 14 | import { StrapiConfigValidator } from './validators'; |
11 | 15 |
|
| 16 | +import type { UsersPermissionsUsersIdOverloads } from './content-types'; |
12 | 17 | import type { ContentTypeManagerOptions } from './content-types/abstract'; |
13 | 18 | import type { HttpClientConfig } from './http'; |
14 | 19 |
|
@@ -360,15 +365,32 @@ export class StrapiClient { |
360 | 365 | * @see CollectionTypeManager |
361 | 366 | * @see StrapiClient |
362 | 367 | */ |
363 | | - collection(resource: string, options: ClientCollectionOptions = {}) { |
| 368 | + collection<T extends string>( |
| 369 | + resource: T, |
| 370 | + options: ClientCollectionOptions = {} |
| 371 | + ): T extends 'users' |
| 372 | + ? UsersPermissionsUsersManager & UsersPermissionsUsersIdOverloads |
| 373 | + : CollectionTypeManager { |
364 | 374 | const { path, plugin } = options; |
365 | 375 |
|
366 | 376 | // Auto-detect well-known collection resources and apply their plugin configuration |
367 | 377 | // if no explicit plugin option is provided |
368 | 378 | const wellKnownConfig = getWellKnownCollection(resource); |
369 | 379 | const effectivePlugin = plugin ?? wellKnownConfig?.plugin ?? undefined; |
370 | 380 |
|
371 | | - return new CollectionTypeManager({ resource, path, plugin: effectivePlugin }, this._httpClient); |
| 381 | + if (resource === 'users' && effectivePlugin?.name === 'users-permissions') { |
| 382 | + const manager = new UsersPermissionsUsersManager( |
| 383 | + { resource, path, plugin: effectivePlugin }, |
| 384 | + this._httpClient |
| 385 | + ); |
| 386 | + |
| 387 | + return manager as any; |
| 388 | + } |
| 389 | + |
| 390 | + return new CollectionTypeManager( |
| 391 | + { resource, path, plugin: effectivePlugin }, |
| 392 | + this._httpClient |
| 393 | + ) as any; |
372 | 394 | } |
373 | 395 |
|
374 | 396 | /** |
|
0 commit comments