@openstax/ts-utils 1.44.4 → 1.45.1

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.
@@ -2,4 +2,3 @@ export * from './misc/hashValue.js';
2
2
  export * from './misc/helpers.js';
3
3
  export * from './misc/merge.js';
4
4
  export * from './misc/partitionSequence.js';
5
- export * from './misc/timingSafeCompareStrings.js';
package/dist/esm/index.js CHANGED
@@ -2,4 +2,3 @@ export * from './misc/hashValue.js';
2
2
  export * from './misc/helpers.js';
3
3
  export * from './misc/merge.js';
4
4
  export * from './misc/partitionSequence.js';
5
- export * from './misc/timingSafeCompareStrings.js';
@@ -1,7 +1,7 @@
1
1
  import { ConfigProviderForConfig } from '../../config/index.js';
2
2
  import { GenericFetch } from '../../fetch/index.js';
3
3
  import { JsonCompatibleStruct } from '../../routing/index.js';
4
- import { ApiUser } from '../authProvider/index.js';
4
+ import { ApiUser, ExternalId } from '../authProvider/index.js';
5
5
  import { Logger } from '../logger/index.js';
6
6
  export type Config = {
7
7
  accountsBase: string;
@@ -36,12 +36,12 @@ export type FindOrCreateUserPayload = {
36
36
  export type FindOrCreateUserResponse = {
37
37
  id: number;
38
38
  uuid: string;
39
- external_ids: string[];
39
+ external_ids: ExternalId[];
40
40
  is_test: boolean;
41
41
  sso: string;
42
42
  };
43
43
  export type FindUserResponse = (FindOrCreateUserResponse & {
44
- external_ids: string[];
44
+ external_ids: ExternalId[];
45
45
  }) | undefined;
46
46
  export type LinkUserPayload = {
47
47
  userId: number;
@@ -59,7 +59,7 @@ export type SearchUsersPayload = {
59
59
  };
60
60
  export type SearchUsersResponse = {
61
61
  items: Array<ApiUser & {
62
- external_ids: string[];
62
+ external_ids: ExternalId[];
63
63
  } & JsonCompatibleStruct>;
64
64
  total_count: number;
65
65
  };
@@ -72,6 +72,10 @@ export type MappedUserInfo<T> = {
72
72
  platformUserId?: string;
73
73
  uuid: string;
74
74
  };
75
+ /**
76
+ * Normalize an external_id to always return the string representation.
77
+ */
78
+ export declare const normalizeExternalId: (externalId: ExternalId) => string;
75
79
  export declare const accountsGateway: <C extends string = "accounts">(initializer: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => ({ logger }: {
76
80
  logger: Logger;
77
81
  }) => {
@@ -11,6 +11,12 @@ class ApiError extends Error {
11
11
  this.status = status;
12
12
  }
13
13
  }
14
+ /**
15
+ * Normalize an external_id to always return the string representation.
16
+ */
17
+ export const normalizeExternalId = (externalId) => {
18
+ return typeof externalId === 'string' ? externalId : externalId.external_id;
19
+ };
14
20
  export const accountsGateway = (initializer) => (configProvider) => {
15
21
  const config = configProvider[ifDefined(initializer.configSpace, 'accounts')];
16
22
  const accountsBase = once(() => resolveConfigValue(config.accountsBase));
@@ -59,7 +65,8 @@ export const accountsGateway = (initializer) => (configProvider) => {
59
65
  const searchUsers = async (payload) => request(METHOD.GET, `users?${queryString.stringify(payload)}`, {});
60
66
  const updateUser = async (token, body) => request(METHOD.PUT, 'user', { body, token });
61
67
  const getPlatformUserId = (externalIds, platformId) => {
62
- for (const externalId of externalIds) {
68
+ const normalizedIds = externalIds.map(normalizeExternalId);
69
+ for (const externalId of normalizedIds) {
63
70
  const [userPlatformId, userId] = externalId.split('/', 2);
64
71
  if (userPlatformId === platformId) {
65
72
  return userId;
@@ -11,6 +11,11 @@ export type TokenUser = {
11
11
  name: string;
12
12
  uuid: string;
13
13
  };
14
+ export type ExternalId = string | {
15
+ external_id: string;
16
+ user_id?: number;
17
+ role: string;
18
+ };
14
19
  export type ApiUser = TokenUser & {
15
20
  id: number;
16
21
  first_name: string;
@@ -27,7 +32,7 @@ export type ApiUser = TokenUser & {
27
32
  name: string;
28
33
  roles: string[];
29
34
  }>;
30
- external_ids: string[];
35
+ external_ids: ExternalId[];
31
36
  faculty_status: string;
32
37
  is_admin: boolean;
33
38
  is_not_gdpr_location: boolean;