@equinor/fusion-framework-module-services 7.2.1 → 8.0.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 (139) hide show
  1. package/CHANGELOG.md +24 -16
  2. package/README.md +125 -0
  3. package/dist/esm/bookmarks/api-version.js +3 -0
  4. package/dist/esm/bookmarks/api-version.js.map +1 -1
  5. package/dist/esm/bookmarks/index.js +13 -0
  6. package/dist/esm/bookmarks/index.js.map +1 -1
  7. package/dist/esm/bookmarks/schemas.js +10 -0
  8. package/dist/esm/bookmarks/schemas.js.map +1 -1
  9. package/dist/esm/bookmarks/types.js +5 -0
  10. package/dist/esm/bookmarks/types.js.map +1 -1
  11. package/dist/esm/configurator.js +7 -0
  12. package/dist/esm/configurator.js.map +1 -1
  13. package/dist/esm/context/client.js +32 -6
  14. package/dist/esm/context/client.js.map +1 -1
  15. package/dist/esm/context/get/client.js +9 -4
  16. package/dist/esm/context/get/client.js.map +1 -1
  17. package/dist/esm/context/index.js +13 -0
  18. package/dist/esm/context/index.js.map +1 -1
  19. package/dist/esm/context/query/client.js +9 -1
  20. package/dist/esm/context/query/client.js.map +1 -1
  21. package/dist/esm/context/related/client.js +9 -1
  22. package/dist/esm/context/related/client.js.map +1 -1
  23. package/dist/esm/context/static.js +3 -2
  24. package/dist/esm/context/static.js.map +1 -1
  25. package/dist/esm/errors.js +14 -0
  26. package/dist/esm/errors.js.map +1 -1
  27. package/dist/esm/index.js +14 -0
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/module.js +39 -7
  30. package/dist/esm/module.js.map +1 -1
  31. package/dist/esm/notification/client.js +56 -14
  32. package/dist/esm/notification/client.js.map +1 -1
  33. package/dist/esm/notification/index.js +14 -0
  34. package/dist/esm/notification/index.js.map +1 -1
  35. package/dist/esm/notification/static.js +3 -2
  36. package/dist/esm/notification/static.js.map +1 -1
  37. package/dist/esm/people/client.js +58 -5
  38. package/dist/esm/people/client.js.map +1 -1
  39. package/dist/esm/people/index.js +13 -0
  40. package/dist/esm/people/index.js.map +1 -1
  41. package/dist/esm/people/person-details/client.js +10 -4
  42. package/dist/esm/people/person-details/client.js.map +1 -1
  43. package/dist/esm/people/person-photo/client.js +10 -4
  44. package/dist/esm/people/person-photo/client.js.map +1 -1
  45. package/dist/esm/people/query/client.js +10 -4
  46. package/dist/esm/people/query/client.js.map +1 -1
  47. package/dist/esm/people/static.js +3 -0
  48. package/dist/esm/people/static.js.map +1 -1
  49. package/dist/esm/people/utils.js +19 -0
  50. package/dist/esm/people/utils.js.map +1 -1
  51. package/dist/esm/provider.js +37 -2
  52. package/dist/esm/provider.js.map +1 -1
  53. package/dist/esm/utils.js +2 -11
  54. package/dist/esm/utils.js.map +1 -1
  55. package/dist/esm/version.js +1 -1
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/dist/types/bookmarks/api-version.d.ts +3 -0
  58. package/dist/types/bookmarks/index.d.ts +13 -0
  59. package/dist/types/bookmarks/schemas.d.ts +10 -0
  60. package/dist/types/bookmarks/types.d.ts +17 -0
  61. package/dist/types/configurator.d.ts +15 -1
  62. package/dist/types/context/api-models.d.ts +16 -0
  63. package/dist/types/context/client.d.ts +32 -6
  64. package/dist/types/context/get/client.d.ts +9 -4
  65. package/dist/types/context/get/types.d.ts +27 -0
  66. package/dist/types/context/index.d.ts +13 -0
  67. package/dist/types/context/query/client.d.ts +9 -1
  68. package/dist/types/context/query/types.d.ts +35 -0
  69. package/dist/types/context/related/client.d.ts +9 -1
  70. package/dist/types/context/related/types.d.ts +36 -0
  71. package/dist/types/context/static.d.ts +3 -2
  72. package/dist/types/errors.d.ts +14 -0
  73. package/dist/types/index.d.ts +14 -0
  74. package/dist/types/module.d.ts +41 -6
  75. package/dist/types/notification/api-models.d.ts +20 -1
  76. package/dist/types/notification/client.d.ts +56 -14
  77. package/dist/types/notification/index.d.ts +14 -0
  78. package/dist/types/notification/static.d.ts +3 -2
  79. package/dist/types/people/api-models.d.ts +26 -0
  80. package/dist/types/people/api-models.v2.d.ts +1 -0
  81. package/dist/types/people/api-models.v4.d.ts +24 -0
  82. package/dist/types/people/client.d.ts +58 -5
  83. package/dist/types/people/index.d.ts +13 -0
  84. package/dist/types/people/person-details/client.d.ts +10 -4
  85. package/dist/types/people/person-details/types.d.ts +21 -0
  86. package/dist/types/people/person-photo/client.d.ts +10 -4
  87. package/dist/types/people/person-photo/types.d.ts +17 -0
  88. package/dist/types/people/query/client.d.ts +10 -4
  89. package/dist/types/people/query/types.d.ts +19 -0
  90. package/dist/types/people/resolve/types.d.ts +7 -0
  91. package/dist/types/people/static.d.ts +3 -0
  92. package/dist/types/people/suggest/types.d.ts +7 -0
  93. package/dist/types/people/utils.d.ts +19 -0
  94. package/dist/types/provider.d.ts +69 -4
  95. package/dist/types/types.d.ts +40 -15
  96. package/dist/types/utils.d.ts +2 -11
  97. package/dist/types/version.d.ts +1 -1
  98. package/package.json +9 -9
  99. package/src/bookmarks/api-version.ts +3 -0
  100. package/src/bookmarks/index.ts +14 -0
  101. package/src/bookmarks/schemas.ts +10 -0
  102. package/src/bookmarks/types.ts +18 -0
  103. package/src/configurator.ts +15 -1
  104. package/src/context/api-models.ts +16 -0
  105. package/src/context/client.ts +32 -6
  106. package/src/context/get/client.ts +9 -4
  107. package/src/context/get/types.ts +27 -0
  108. package/src/context/index.ts +14 -0
  109. package/src/context/query/client.ts +9 -1
  110. package/src/context/query/types.ts +35 -0
  111. package/src/context/related/client.ts +9 -1
  112. package/src/context/related/types.ts +36 -0
  113. package/src/context/static.ts +3 -2
  114. package/src/errors.ts +14 -0
  115. package/src/index.ts +15 -0
  116. package/src/module.ts +47 -7
  117. package/src/notification/api-models.ts +20 -1
  118. package/src/notification/client.ts +56 -14
  119. package/src/notification/index.ts +15 -0
  120. package/src/notification/static.ts +3 -2
  121. package/src/people/api-models.ts +26 -1
  122. package/src/people/api-models.v2.ts +1 -0
  123. package/src/people/api-models.v4.ts +24 -0
  124. package/src/people/client.ts +58 -5
  125. package/src/people/index.ts +14 -0
  126. package/src/people/person-details/client.ts +10 -4
  127. package/src/people/person-details/types.ts +21 -0
  128. package/src/people/person-photo/client.ts +10 -4
  129. package/src/people/person-photo/types.ts +17 -0
  130. package/src/people/query/client.ts +10 -4
  131. package/src/people/query/types.ts +19 -0
  132. package/src/people/resolve/types.ts +7 -0
  133. package/src/people/static.ts +3 -0
  134. package/src/people/suggest/types.ts +7 -0
  135. package/src/people/utils.ts +19 -0
  136. package/src/provider.ts +79 -8
  137. package/src/types.ts +40 -15
  138. package/src/utils.ts +2 -11
  139. package/src/version.ts +1 -1
@@ -7,6 +7,12 @@ import type {
7
7
  ApiProjectMaster,
8
8
  } from './api-models';
9
9
 
10
+ /**
11
+ * Map of expandable properties available on a v4 person entity.
12
+ *
13
+ * Use the `expand` parameter in API requests to include these
14
+ * nested collections alongside the core person data.
15
+ */
10
16
  export type ApiPersonExpandMap_v4 = {
11
17
  roles: Array<ApiPersonRole_v4>;
12
18
  positions: Array<ApiPersonPosition_v4>;
@@ -15,8 +21,18 @@ export type ApiPersonExpandMap_v4 = {
15
21
  companies: Array<ApiCompanyInfo_v4>;
16
22
  };
17
23
 
24
+ /** Union of valid expand property keys for the v4 person entity. */
18
25
  export type ApiPersonExpandProps_v4 = keyof ApiPersonExpandMap_v4;
19
26
 
27
+ /**
28
+ * Person entity returned by the v4 people API.
29
+ *
30
+ * Includes only the expanded properties specified by `TExpand`.
31
+ * Non-expanded properties from {@link ApiPersonExpandMap_v4} remain
32
+ * `Partial` (i.e. `undefined` at runtime).
33
+ *
34
+ * @template TExpand - Array of expand property keys to include.
35
+ */
20
36
  export type ApiPerson_v4<TExpand extends Array<ApiPersonExpandProps_v4> = []> = {
21
37
  azureUniqueId: string;
22
38
  mail?: string;
@@ -46,11 +62,13 @@ export type ApiPerson_v4<TExpand extends Array<ApiPersonExpandProps_v4> = []> =
46
62
  [K in TExpand[number]]: ApiPersonExpandMap_v4[K];
47
63
  };
48
64
 
65
+ /** Company information associated with a v4 person entity. */
49
66
  export type ApiCompanyInfo_v4 = {
50
67
  id: string;
51
68
  name?: string;
52
69
  };
53
70
 
71
+ /** Role assigned to a person in the v4 API. */
54
72
  export type ApiPersonRole_v4 = {
55
73
  name?: string;
56
74
  displayName?: string;
@@ -62,12 +80,14 @@ export type ApiPersonRole_v4 = {
62
80
  scopes?: Array<ApiPersonRoleScope_v4>;
63
81
  };
64
82
 
83
+ /** Scope constraint on a person role. */
65
84
  export type ApiPersonRoleScope_v4 = {
66
85
  type?: string;
67
86
  values?: string[];
68
87
  valueType?: string;
69
88
  };
70
89
 
90
+ /** Position instance held by a person in the v4 API. */
71
91
  export type ApiPersonPosition_v4 = {
72
92
  positionId: string;
73
93
  positionExternalId?: string;
@@ -83,6 +103,7 @@ export type ApiPersonPosition_v4 = {
83
103
  workload?: number;
84
104
  };
85
105
 
106
+ /** Base position reference for a person position. */
86
107
  export type ApiPersonBasePosition_v4 = {
87
108
  id: string;
88
109
  name?: string;
@@ -90,6 +111,7 @@ export type ApiPersonBasePosition_v4 = {
90
111
  discipline?: string;
91
112
  };
92
113
 
114
+ /** Project reference for a person position or contract. */
93
115
  export type ApiPersonProject_v4 = {
94
116
  id: string;
95
117
  name?: string;
@@ -97,6 +119,7 @@ export type ApiPersonProject_v4 = {
97
119
  type?: string;
98
120
  };
99
121
 
122
+ /** Contract associated with a person in the v4 API. */
100
123
  export type ApiPersonContract_v4 = {
101
124
  id: string;
102
125
  name?: string;
@@ -108,6 +131,7 @@ export type ApiPersonContract_v4 = {
108
131
  positions: Array<ApiPersonPosition_v4>;
109
132
  };
110
133
 
134
+ /** @deprecated Use {@link ApiCompanyInfo_v4} instead. */
111
135
  export type ApiCompanyInfoV4 = {
112
136
  id: string;
113
137
  name?: string;
@@ -39,18 +39,39 @@ import {
39
39
  type ApiResult as PersonResolveResult,
40
40
  } from './resolve';
41
41
 
42
+ /**
43
+ * Typed API client for the Fusion people service.
44
+ *
45
+ * Provides methods for fetching person details, querying persons,
46
+ * retrieving profile photos, getting suggestions, and resolving
47
+ * person identifiers.
48
+ *
49
+ * @template TClient - The underlying HTTP client type.
50
+ */
42
51
  export class PeopleApiClient<
43
52
  // TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
44
53
  TClient extends IHttpClient = IHttpClient,
45
54
  > {
55
+ /** Returns the {@link ApiVersion} enum for version-constant access. */
46
56
  get Version(): typeof ApiVersion {
47
57
  return ApiVersion;
48
58
  }
49
59
 
60
+ /** @param _client - The HTTP client used to execute people requests. */
50
61
  constructor(protected _client: TClient) {}
51
62
 
52
63
  /**
53
- * Fetch person by id
64
+ * Fetch detailed information about a person by their Azure unique ID.
65
+ *
66
+ * @template TVersion - The API version key (e.g. `'v4'`).
67
+ * @template TArgs - Request argument type.
68
+ * @template TResult - Expected response type.
69
+ * @template TMethod - Client execution method (`'json'` or `'json$'`).
70
+ * @param version - API version to use.
71
+ * @param method - Client execution method.
72
+ * @param args - Request arguments including `azureId`.
73
+ * @param init - Optional request init overrides.
74
+ * @returns The person details.
54
75
  */
55
76
  public get<
56
77
  TVersion extends PersonDetailSupportedApiVersion,
@@ -68,7 +89,17 @@ export class PeopleApiClient<
68
89
  }
69
90
 
70
91
  /**
71
- * Query person service
92
+ * Search for persons matching query criteria.
93
+ *
94
+ * @template TVersion - The API version key (e.g. `'v2'`).
95
+ * @template TArgs - Request argument type.
96
+ * @template TResult - Expected response type.
97
+ * @template TMethod - Client execution method.
98
+ * @param version - API version to use.
99
+ * @param method - Client execution method.
100
+ * @param args - Request arguments including `search` string.
101
+ * @param init - Optional request init overrides.
102
+ * @returns An array of matching person entities.
72
103
  */
73
104
  public query<
74
105
  TVersion extends PersonQuerySupportedApiVersion,
@@ -86,7 +117,17 @@ export class PeopleApiClient<
86
117
  }
87
118
 
88
119
  /**
89
- * Photo person service
120
+ * Fetch a person's profile photo as binary blob data.
121
+ *
122
+ * @template TVersion - The API version key (e.g. `'v2'`).
123
+ * @template TArgs - Request argument type.
124
+ * @template TResult - Expected response type.
125
+ * @template TMethod - Client execution method (`'blob'` or `'blob$'`).
126
+ * @param version - API version to use.
127
+ * @param method - Client execution method.
128
+ * @param args - Request arguments including `azureId`.
129
+ * @param init - Optional request init overrides.
130
+ * @returns The person's photo as a blob.
90
131
  */
91
132
  public photo<
92
133
  TVersion extends PersonPhotoSupportedApiVersion,
@@ -104,7 +145,13 @@ export class PeopleApiClient<
104
145
  }
105
146
 
106
147
  /**
107
- * Suggest person service
148
+ * Fetch person suggestions (type-ahead / autocomplete).
149
+ *
150
+ * @template TResult - Expected response type.
151
+ * @template TMethod - Client execution method.
152
+ * @param method - Client execution method.
153
+ * @param init - Optional request init overrides.
154
+ * @returns Paginated suggestion results.
108
155
  */
109
156
  public suggest<
110
157
  TResult = PersonSuggestApiResponse,
@@ -118,7 +165,13 @@ export class PeopleApiClient<
118
165
  }
119
166
 
120
167
  /**
121
- * Resolve person service
168
+ * Resolve person identifiers to account information.
169
+ *
170
+ * @template TResult - Expected response type.
171
+ * @template TMethod - Client execution method.
172
+ * @param method - Client execution method.
173
+ * @param init - Optional request init overrides.
174
+ * @returns Array of resolved person results.
122
175
  */
123
176
  public resolve<
124
177
  TResult = PersonResolveApiResponse,
@@ -1,3 +1,17 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * People API client and types.
5
+ *
6
+ * Provides {@link PeopleApiClient} for person lookups, search, photo retrieval,
7
+ * suggestions, and identifier resolution, with versioned endpoints (`v2`, `v4`).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { PeopleApiClient } from '@equinor/fusion-framework-module-services/people';
12
+ * ```
13
+ */
14
+
1
15
  export { PeopleApiClient, default } from './client';
2
16
 
3
17
  export { ApiVersion } from './static';
@@ -6,10 +6,16 @@ import type { ClientMethod } from '../../types';
6
6
  import type { ApiResponse, ApiResult, ApiRequestArgs, SupportedApiVersion } from './types';
7
7
 
8
8
  /**
9
- * Method for fetching context item from context service
10
- * @param client - client for execution of request
11
- * @param version - version of API to call
12
- * @param method - client method to call
9
+ * Creates a curried function that fetches detailed person information.
10
+ *
11
+ * @template TVersion - Supported API version (e.g. `'v4'`).
12
+ * @template TMethod - Client execution method (`'json'` or `'json$'`).
13
+ * @template TClient - The underlying HTTP client type.
14
+ * @template TArgs - Request argument type.
15
+ * @param client - HTTP client used to execute the request.
16
+ * @param version - API version to call.
17
+ * @param method - Client method to use (defaults to `'json'`).
18
+ * @returns A function that accepts person detail args and returns the result.
13
19
  */
14
20
  export const client =
15
21
  <
@@ -2,6 +2,7 @@ import { ApiVersion } from '../static';
2
2
  import type { ApiPerson_v4, ApiPersonExpandProps_v4 } from '../api-models.v4';
3
3
  import type { ClientMethod } from '../../types';
4
4
 
5
+ /** API versions that support the person-details endpoint. */
5
6
  export type SupportedApiVersion = Extract<keyof typeof ApiVersion, 'v4'>;
6
7
 
7
8
  type ApiRequestArgsMap = {
@@ -11,8 +12,14 @@ type ApiRequestArgsMap = {
11
12
  };
12
13
  };
13
14
 
15
+ /** Union of all valid request argument shapes across supported versions. */
14
16
  export type AllowedArgs = ApiRequestArgsMap[keyof ApiRequestArgsMap];
15
17
 
18
+ /**
19
+ * Version-aware request argument type for the person-details endpoint.
20
+ *
21
+ * @template T - Supported API version key.
22
+ */
16
23
  export type ApiRequestArgs<T extends SupportedApiVersion> =
17
24
  ApiRequestArgsMap[(typeof ApiVersion)[T]];
18
25
 
@@ -20,11 +27,25 @@ type ApiResponseTypes<TArgs extends AllowedArgs> = {
20
27
  [ApiVersion.v4]: ApiPerson_v4<TArgs['expand'] extends [] ? TArgs['expand'] : []>;
21
28
  };
22
29
 
30
+ /**
31
+ * Version-aware response type for the person-details endpoint.
32
+ *
33
+ * @template T - Supported API version key.
34
+ * @template TArgs - Request argument type.
35
+ */
23
36
  export type ApiResponse<
24
37
  T extends SupportedApiVersion,
25
38
  TArgs extends AllowedArgs,
26
39
  > = ApiResponseTypes<TArgs>[(typeof ApiVersion)[T]];
27
40
 
41
+ /**
42
+ * Result type for the person-details endpoint.
43
+ *
44
+ * @template TVersion - Supported API version key.
45
+ * @template TArgs - Request argument type.
46
+ * @template TMethod - Client execution method.
47
+ * @template TResult - Expected response type.
48
+ */
28
49
  export type ApiResult<
29
50
  TVersion extends SupportedApiVersion,
30
51
  TArgs extends ApiRequestArgs<TVersion>,
@@ -6,10 +6,16 @@ import type { ClientDataMethod } from '../../types';
6
6
  import type { ApiResponse, ApiRequestArgs, SupportedApiVersion } from './types';
7
7
 
8
8
  /**
9
- * Method for fetching context item from context service
10
- * @param client - client for execution of request
11
- * @param version - version of API to call
12
- * @param method - client method to call
9
+ * Creates a curried function that fetches a person's profile photo.
10
+ *
11
+ * @template TVersion - Supported API version (e.g. `'v2'`).
12
+ * @template TMethod - Client execution method (`'blob'` or `'blob$'`).
13
+ * @template TClient - The underlying HTTP client type.
14
+ * @template TArgs - Request argument type.
15
+ * @param client - HTTP client used to execute the request.
16
+ * @param version - API version to call.
17
+ * @param method - Client method to use (defaults to `'blob'`).
18
+ * @returns A function that accepts photo args and returns blob data.
13
19
  */
14
20
  export const client =
15
21
  <
@@ -2,6 +2,7 @@ import type { BlobResult } from '@equinor/fusion-framework-module-http/client';
2
2
  import { ApiVersion } from '../static';
3
3
  import type { ClientDataMethod } from '../../types';
4
4
 
5
+ /** API versions that support the person photo endpoint. */
5
6
  export type SupportedApiVersion = Extract<keyof typeof ApiVersion, 'v2'>;
6
7
 
7
8
  type ApiRequestArgsMap = {
@@ -10,8 +11,14 @@ type ApiRequestArgsMap = {
10
11
  };
11
12
  };
12
13
 
14
+ /** Union of all valid request argument shapes across supported versions. */
13
15
  export type AllowedArgs = ApiRequestArgsMap[keyof ApiRequestArgsMap];
14
16
 
17
+ /**
18
+ * Version-aware request argument type for the person photo endpoint.
19
+ *
20
+ * @template T - Supported API version key.
21
+ */
15
22
  export type ApiRequestArgs<T extends SupportedApiVersion> =
16
23
  ApiRequestArgsMap[(typeof ApiVersion)[T]];
17
24
 
@@ -19,7 +26,17 @@ type ApiResponseTypes = {
19
26
  [ApiVersion.v2]: BlobResult;
20
27
  };
21
28
 
29
+ /**
30
+ * Version-aware response type for the person photo endpoint.
31
+ *
32
+ * @template T - Supported API version key.
33
+ */
22
34
  export type ApiResponse<T extends SupportedApiVersion> = ApiResponseTypes[(typeof ApiVersion)[T]];
23
35
 
36
+ /**
37
+ * Result type for the person photo endpoint.
38
+ *
39
+ * @template TMethod - Client execution method (`'blob'` or `'blob$'`).
40
+ */
24
41
  export type ApiResult<TMethod extends keyof ClientDataMethod = keyof ClientDataMethod> =
25
42
  ClientDataMethod[TMethod];
@@ -6,10 +6,16 @@ import type { ClientMethod } from '../../types';
6
6
  import type { ApiResponse, ApiResult, ApiRequestArgs, SupportedApiVersion } from './types';
7
7
 
8
8
  /**
9
- * Method for fetching context item from context service
10
- * @param client - client for execution of request
11
- * @param version - version of API to call
12
- * @param method - client method to call
9
+ * Creates a curried function that queries the people service.
10
+ *
11
+ * @template TVersion - Supported API version (e.g. `'v2'`).
12
+ * @template TMethod - Client execution method.
13
+ * @template TClient - The underlying HTTP client type.
14
+ * @template TArgs - Request argument type.
15
+ * @param client - HTTP client used to execute the request.
16
+ * @param version - API version to call.
17
+ * @param method - Client method to use (defaults to `'json'`).
18
+ * @returns A function that accepts query args and returns person results.
13
19
  */
14
20
  export const client =
15
21
  <
@@ -2,6 +2,7 @@ import { ApiVersion } from '../static';
2
2
  import type { ApiPerson_v2 } from '../api-models.v2';
3
3
  import type { ClientMethod } from '../../types';
4
4
 
5
+ /** API versions that support the people query endpoint. */
5
6
  export type SupportedApiVersion = Extract<keyof typeof ApiVersion, 'v2'>;
6
7
 
7
8
  type ApiRequestArgsMap = {
@@ -10,8 +11,14 @@ type ApiRequestArgsMap = {
10
11
  };
11
12
  };
12
13
 
14
+ /** Union of all valid request argument shapes across supported versions. */
13
15
  export type AllowedArgs = ApiRequestArgsMap[keyof ApiRequestArgsMap];
14
16
 
17
+ /**
18
+ * Version-aware request argument type for the people query endpoint.
19
+ *
20
+ * @template T - Supported API version key.
21
+ */
15
22
  export type ApiRequestArgs<T extends SupportedApiVersion> =
16
23
  ApiRequestArgsMap[(typeof ApiVersion)[T]];
17
24
 
@@ -19,8 +26,20 @@ type ApiResponseTypes = {
19
26
  [ApiVersion.v2]: Array<ApiPerson_v2>;
20
27
  };
21
28
 
29
+ /**
30
+ * Version-aware response type for the people query endpoint.
31
+ *
32
+ * @template T - Supported API version key.
33
+ */
22
34
  export type ApiResponse<T extends SupportedApiVersion> = ApiResponseTypes[(typeof ApiVersion)[T]];
23
35
 
36
+ /**
37
+ * Result type for the people query endpoint.
38
+ *
39
+ * @template TVersion - Supported API version key.
40
+ * @template TMethod - Client execution method.
41
+ * @template TResult - Expected response type.
42
+ */
24
43
  export type ApiResult<
25
44
  TVersion extends SupportedApiVersion,
26
45
  TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
@@ -1,8 +1,15 @@
1
1
  import type { ApiResolved } from '../api-models';
2
2
  import type { ClientMethod } from '../../types';
3
3
 
4
+ /** Response type for the people resolve endpoint. */
4
5
  export type ApiResponse = ApiResolved;
5
6
 
7
+ /**
8
+ * Result type for the people resolve endpoint.
9
+ *
10
+ * @template TMethod - Client execution method.
11
+ * @template TResult - Expected response type.
12
+ */
6
13
  export type ApiResult<
7
14
  TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
8
15
  TResult = ApiResponse,
@@ -1,4 +1,7 @@
1
+ /** Supported API versions for the people service. */
1
2
  export enum ApiVersion {
3
+ /** People API version 2.0. */
2
4
  v2 = '2.0',
5
+ /** People API version 4.0. */
3
6
  v4 = '4.0',
4
7
  }
@@ -1,8 +1,15 @@
1
1
  import type { ApiSuggestions } from '../api-models';
2
2
  import type { ClientMethod } from '../../types';
3
3
 
4
+ /** Response type for the people suggest endpoint. */
4
5
  export type ApiResponse = ApiSuggestions;
5
6
 
7
+ /**
8
+ * Result type for the people suggest endpoint.
9
+ *
10
+ * @template TMethod - Client execution method.
11
+ * @template TResult - Expected response type.
12
+ */
6
13
  export type ApiResult<
7
14
  TMethod extends keyof ClientMethod<unknown> = keyof ClientMethod<unknown>,
8
15
  TResult = ApiResponse,
@@ -14,6 +14,25 @@ const requiredApiPersonAttributes = {
14
14
  ] satisfies Array<keyof ApiPerson<'v4'>>,
15
15
  };
16
16
 
17
+ /**
18
+ * Creates a type-guard function that validates whether a value conforms
19
+ * to the {@link ApiPerson} shape for a given API version.
20
+ *
21
+ * The guard checks that the value contains all required attributes
22
+ * defined for the specified version.
23
+ *
24
+ * @template V - API version key (e.g. `'v2'` or `'v4'`).
25
+ * @param version - The API version to validate against.
26
+ * @returns A type-guard function that narrows `T` to `ApiPerson<V>`.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const isV4Person = isApiPerson('v4');
31
+ * if (isV4Person(data)) {
32
+ * console.log(data.azureUniqueId);
33
+ * }
34
+ * ```
35
+ */
17
36
  export const isApiPerson = <V extends keyof typeof ApiVersion>(version: V) => {
18
37
  /** todo add options for more strict check */
19
38
  return <T>(value: T): value is T extends ApiPerson<V> ? T : never => {
package/src/provider.ts CHANGED
@@ -10,38 +10,69 @@ import BookmarksApiClient from './bookmarks/client';
10
10
  import { NotificationApiClient } from './notification';
11
11
  import { PeopleApiClient } from './people/client';
12
12
 
13
+ /**
14
+ * Public interface for the services module provider.
15
+ *
16
+ * Exposes factory methods for creating domain-specific API clients
17
+ * for bookmarks, context, notification, and people services.
18
+ * Each factory resolves a named HTTP client, attaches response
19
+ * validation, and returns a typed client instance.
20
+ *
21
+ * @template TClient - The underlying HTTP client type.
22
+ */
13
23
  export interface IApiProvider<TClient extends IHttpClient = IHttpClient> {
14
24
  /**
15
- * @param method - Version of the service to use
25
+ * Creates a typed client for the bookmarks API.
26
+ *
27
+ * @template TMethod - The client execution method (`'json'` or `'json$'`).
28
+ * @param method - The execution method to use for requests.
29
+ * @returns A configured {@link BookmarksApiClient} instance.
16
30
  */
17
31
  createBookmarksClient<TMethod extends keyof ClientMethod>(
18
32
  method: TMethod,
19
33
  ): Promise<BookmarksApiClient<TMethod, TClient>>;
20
34
 
21
35
  /**
22
- * @param method - Version of the service to use
36
+ * Creates a typed client for the context API.
37
+ *
38
+ * @template TMethod - The client execution method (`'json'` or `'json$'`).
39
+ * @param method - The execution method to use for requests.
40
+ * @returns A configured {@link ContextApiClient} instance.
23
41
  */
24
42
  createContextClient<TMethod extends keyof ClientMethod>(
25
43
  method: TMethod,
26
44
  ): Promise<ContextApiClient<TMethod, TClient>>;
27
45
  /**
28
- * @param method - Version of the service to use
46
+ * Creates a typed client for the notification API.
47
+ *
48
+ * @template TMethod - The client execution method (`'json'` or `'json$'`).
49
+ * @param method - The execution method to use for requests.
50
+ * @returns A configured {@link NotificationApiClient} instance.
29
51
  */
30
52
  createNotificationClient<TMethod extends keyof ClientMethod>(
31
53
  method: TMethod,
32
54
  ): Promise<NotificationApiClient<TMethod, TClient>>;
33
55
  /**
34
- * @param method - Version of the service to use
56
+ * Creates a typed client for the people API.
57
+ *
58
+ * @returns A configured {@link PeopleApiClient} instance.
35
59
  */
36
60
  createPeopleClient(): Promise<PeopleApiClient<TClient>>;
37
61
  }
38
62
 
63
+ /**
64
+ * Constructor arguments for {@link ApiProvider}.
65
+ *
66
+ * @template TClient - The underlying HTTP client type.
67
+ */
39
68
  type ApiProviderCtorArgs<TClient extends IHttpClient = IHttpClient> = {
40
- /** method for creating IHttpClients for api clients */
69
+ /** Factory function for creating named HTTP clients used by API sub-clients. */
41
70
  createClient: ApiClientFactory<TClient>;
42
71
  };
43
72
 
44
- // TODO move to own file
73
+ /**
74
+ * Shape of the structured error response attached to an {@link ApiProviderError}.
75
+ */
45
76
  type ApiProviderErrorResponse = {
46
77
  type: ResponseType;
47
78
  status: number;
@@ -51,10 +82,32 @@ type ApiProviderErrorResponse = {
51
82
  data: unknown;
52
83
  };
53
84
 
54
- // TODO move to own file
85
+ /**
86
+ * Error thrown when an API response indicates a non-OK HTTP status.
87
+ *
88
+ * Contains the full {@link ApiProviderErrorResponse} (status, headers, body)
89
+ * so callers can inspect the failure details.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * try {
94
+ * await provider.createNotificationClient('json');
95
+ * } catch (err) {
96
+ * if (err instanceof ApiProviderError) {
97
+ * console.error(err.response.status, err.response.data);
98
+ * }
99
+ * }
100
+ * ```
101
+ */
55
102
  export class ApiProviderError extends Error {
103
+ /** Structured HTTP response data associated with this error. */
56
104
  readonly response: ApiProviderErrorResponse;
57
105
 
106
+ /**
107
+ * @param msg - Human-readable error message.
108
+ * @param response - The parsed HTTP response details.
109
+ * @param options - Standard `ErrorOptions` (e.g. `cause`).
110
+ */
58
111
  constructor(msg: string, response: ApiProviderErrorResponse, options?: ErrorOptions) {
59
112
  super(msg, options);
60
113
  this.response = response;
@@ -62,7 +115,10 @@ export class ApiProviderError extends Error {
62
115
  }
63
116
  }
64
117
 
65
- // TODO move to own file
118
+ /**
119
+ * Validates that an HTTP response has an OK status.
120
+ * Throws an {@link ApiProviderError} with parsed body data when the response is not OK.
121
+ */
66
122
  const validateResponse = async (response: Response) => {
67
123
  if (!response.ok) {
68
124
  const { headers, status, statusText, type, url, bodyUsed } = response;
@@ -79,10 +135,25 @@ const validateResponse = async (response: Response) => {
79
135
  }
80
136
  };
81
137
 
138
+ /**
139
+ * Internal configuration shape for {@link ApiProvider}.
140
+ *
141
+ * @template TClient - The underlying HTTP client type.
142
+ */
82
143
  type ApiProviderConfig<TClient extends IHttpClient = IHttpClient> = {
83
144
  createClient: ApiClientFactory<TClient>;
84
145
  };
85
146
 
147
+ /**
148
+ * Default implementation of {@link IApiProvider}.
149
+ *
150
+ * Manages the lifecycle of domain-specific API clients (bookmarks, context,
151
+ * notification, people) by resolving named HTTP clients through the
152
+ * configured {@link ApiClientFactory} and attaching response-validation
153
+ * middleware.
154
+ *
155
+ * @template TClient - The underlying HTTP client type.
156
+ */
86
157
  export class ApiProvider<TClient extends IHttpClient = IHttpClient>
87
158
  extends BaseModuleProvider<ApiProviderConfig<TClient>>
88
159
  implements IApiProvider<TClient>