@haakco/custd-sdk 2.4.0 → 3.71.2

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +586 -40
  3. package/dist/admin-accounting-evidence.d.ts +48 -0
  4. package/dist/admin-accounting-evidence.js +24 -0
  5. package/dist/admin-app-releases.d.ts +116 -0
  6. package/dist/admin-app-releases.js +8 -0
  7. package/dist/admin-apps.d.ts +120 -0
  8. package/dist/admin-apps.js +47 -0
  9. package/dist/admin-auth-project-domain.d.ts +125 -0
  10. package/dist/admin-auth-project-domain.js +37 -0
  11. package/dist/admin-auth-projects.d.ts +989 -0
  12. package/dist/admin-auth-projects.js +527 -0
  13. package/dist/admin-campaign-email.d.ts +120 -0
  14. package/dist/admin-campaign-email.js +64 -0
  15. package/dist/admin-client-setup.d.ts +22 -0
  16. package/dist/admin-client-setup.js +11 -1
  17. package/dist/admin-data-scopes.d.ts +93 -0
  18. package/dist/admin-data-scopes.js +154 -0
  19. package/dist/admin-email-relay.d.ts +66 -0
  20. package/dist/admin-email-relay.js +25 -0
  21. package/dist/admin-environment-policy.d.ts +32 -0
  22. package/dist/admin-environment-policy.js +26 -0
  23. package/dist/admin-error-issues.d.ts +91 -0
  24. package/dist/admin-error-issues.js +52 -0
  25. package/dist/admin-event-types.d.ts +57 -0
  26. package/dist/admin-event-types.js +28 -0
  27. package/dist/admin-impersonation.d.ts +48 -0
  28. package/dist/admin-impersonation.js +27 -0
  29. package/dist/admin-ingest-claims.d.ts +35 -0
  30. package/dist/admin-ingest-claims.js +26 -0
  31. package/dist/admin-managed-audit.d.ts +13 -0
  32. package/dist/admin-managed-audit.js +13 -0
  33. package/dist/admin-measurement-projects.d.ts +166 -0
  34. package/dist/admin-measurement-projects.js +120 -0
  35. package/dist/admin-notification-destinations.d.ts +31 -0
  36. package/dist/admin-notification-destinations.js +19 -0
  37. package/dist/admin-notification-webhooks.d.ts +64 -0
  38. package/dist/admin-notification-webhooks.js +42 -0
  39. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  40. package/dist/admin-oauth-client-admissions.js +46 -0
  41. package/dist/admin-offboarding.d.ts +20 -6
  42. package/dist/admin-offboarding.js +27 -6
  43. package/dist/admin-predictions.d.ts +127 -8
  44. package/dist/admin-predictions.js +22 -12
  45. package/dist/admin-privacy-erasures.d.ts +24 -12
  46. package/dist/admin-privacy-erasures.js +3 -2
  47. package/dist/admin-retention.d.ts +72 -24
  48. package/dist/admin-retention.js +38 -13
  49. package/dist/admin-rls.d.ts +94 -0
  50. package/dist/admin-rls.js +33 -0
  51. package/dist/admin-sdk-usage.d.ts +41 -0
  52. package/dist/admin-sdk-usage.js +23 -0
  53. package/dist/admin-site-ai.d.ts +72 -0
  54. package/dist/admin-site-ai.js +1 -0
  55. package/dist/admin-site-analytics.d.ts +52 -0
  56. package/dist/admin-site-analytics.js +14 -0
  57. package/dist/admin-site-audit-pages.d.ts +76 -0
  58. package/dist/admin-site-audit-pages.js +27 -0
  59. package/dist/admin-site-campaign-links.d.ts +40 -0
  60. package/dist/admin-site-campaign-links.js +9 -0
  61. package/dist/admin-site-domains.d.ts +733 -0
  62. package/dist/admin-site-domains.js +768 -0
  63. package/dist/admin-site-export.d.ts +76 -0
  64. package/dist/admin-site-export.js +15 -0
  65. package/dist/admin-site-insights-tasks.d.ts +44 -0
  66. package/dist/admin-site-insights-tasks.js +28 -0
  67. package/dist/admin-site-insights.d.ts +527 -0
  68. package/dist/admin-site-insights.js +61 -0
  69. package/dist/admin-site-links.d.ts +87 -0
  70. package/dist/admin-site-links.js +16 -0
  71. package/dist/admin-site-monitors.d.ts +110 -0
  72. package/dist/admin-site-monitors.js +25 -0
  73. package/dist/admin-site-next-actions.d.ts +93 -0
  74. package/dist/admin-site-next-actions.js +36 -0
  75. package/dist/admin-site-page-queries.d.ts +63 -0
  76. package/dist/admin-site-page-queries.js +20 -0
  77. package/dist/admin-site-rankings.d.ts +98 -0
  78. package/dist/admin-site-rankings.js +46 -0
  79. package/dist/admin-site-regional-trends.d.ts +30 -0
  80. package/dist/admin-site-regional-trends.js +1 -0
  81. package/dist/admin-site-saved-reports.d.ts +45 -0
  82. package/dist/admin-site-saved-reports.js +13 -0
  83. package/dist/admin-site-search-pool.d.ts +77 -0
  84. package/dist/admin-site-search-pool.js +41 -0
  85. package/dist/admin-site-search-value.d.ts +97 -0
  86. package/dist/admin-site-search-value.js +29 -0
  87. package/dist/admin-site-status-page.d.ts +57 -0
  88. package/dist/admin-site-status-page.js +10 -0
  89. package/dist/admin-site-traffic.d.ts +145 -0
  90. package/dist/admin-site-traffic.js +32 -0
  91. package/dist/admin-site-web-data.d.ts +258 -0
  92. package/dist/admin-site-web-data.js +60 -0
  93. package/dist/admin-subject-exports.d.ts +58 -27
  94. package/dist/admin-subject-exports.js +32 -16
  95. package/dist/admin-support-access.d.ts +32 -0
  96. package/dist/admin-support-access.js +21 -0
  97. package/dist/admin-system.d.ts +283 -0
  98. package/dist/admin-system.js +65 -0
  99. package/dist/admin-tenant-storage.d.ts +22 -14
  100. package/dist/admin-tenant-storage.js +13 -14
  101. package/dist/admin-timeplans.d.ts +276 -2
  102. package/dist/admin-timeplans.js +54 -0
  103. package/dist/admin-uncertainty-models.d.ts +42 -0
  104. package/dist/admin-uncertainty-models.js +53 -0
  105. package/dist/admin-usage.d.ts +124 -0
  106. package/dist/admin-usage.js +169 -0
  107. package/dist/admin-users.d.ts +124 -0
  108. package/dist/admin-users.js +82 -0
  109. package/dist/admin-workflow-timings.d.ts +367 -0
  110. package/dist/admin-workflow-timings.js +117 -0
  111. package/dist/analytics-events.d.ts +82 -0
  112. package/dist/analytics-events.js +157 -0
  113. package/dist/analytics-reads.d.ts +81 -0
  114. package/dist/analytics-reads.js +5 -0
  115. package/dist/app-account.d.ts +84 -0
  116. package/dist/app-account.js +177 -0
  117. package/dist/app-alerts.d.ts +120 -0
  118. package/dist/app-alerts.js +44 -0
  119. package/dist/app-items.d.ts +786 -0
  120. package/dist/app-items.js +524 -0
  121. package/dist/app-live.d.ts +84 -0
  122. package/dist/app-live.js +228 -0
  123. package/dist/app-meetings.d.ts +95 -0
  124. package/dist/app-meetings.js +26 -0
  125. package/dist/app-models.d.ts +271 -0
  126. package/dist/app-models.js +83 -0
  127. package/dist/app-push.d.ts +64 -0
  128. package/dist/app-push.js +178 -0
  129. package/dist/backend-lifecycle.d.ts +2 -2
  130. package/dist/browser-manifest.json +5 -5
  131. package/dist/browser-script-BWnwDjAC.js +711 -0
  132. package/dist/browser-sign-in.d.ts +153 -0
  133. package/dist/browser-sign-in.js +410 -0
  134. package/dist/browser-tracker.d.ts +95 -0
  135. package/dist/browser-tracker.js +362 -40
  136. package/dist/browser-web-vitals.d.ts +22 -0
  137. package/dist/browser-web-vitals.js +116 -0
  138. package/dist/browser.d.ts +9 -0
  139. package/dist/browser.js +9 -0
  140. package/dist/download-stream.d.ts +16 -0
  141. package/dist/download-stream.js +55 -0
  142. package/dist/error-capture.d.ts +62 -0
  143. package/dist/error-capture.js +168 -0
  144. package/dist/hosted-app.d.ts +115 -0
  145. package/dist/hosted-app.js +275 -0
  146. package/dist/index.d.ts +1168 -154
  147. package/dist/index.js +682 -162
  148. package/dist/ingest-operations.d.ts +483 -0
  149. package/dist/ingest-operations.js +154 -0
  150. package/dist/measurement.d.ts +164 -0
  151. package/dist/measurement.js +104 -0
  152. package/dist/parsers.d.ts +149 -0
  153. package/dist/parsers.js +115 -0
  154. package/dist/public-reads.d.ts +79 -0
  155. package/dist/public-reads.js +57 -0
  156. package/dist/reporting-catalogue.d.ts +264 -0
  157. package/dist/reporting-catalogue.js +5 -0
  158. package/dist/response-lists.d.ts +16 -0
  159. package/dist/response-lists.generated.d.ts +7 -0
  160. package/dist/response-lists.generated.js +1927 -0
  161. package/dist/response-lists.js +70 -0
  162. package/dist/response-validation.d.ts +30 -0
  163. package/dist/response-validation.js +94 -0
  164. package/dist/schema-registry.d.ts +45 -0
  165. package/dist/schema-registry.js +9 -0
  166. package/dist/secure-url.d.ts +4 -0
  167. package/dist/secure-url.js +23 -0
  168. package/dist/site-ai-owner.d.ts +34 -0
  169. package/dist/site-ai-owner.js +99 -0
  170. package/dist/site-monitor-reports.d.ts +15 -0
  171. package/dist/site-monitor-reports.js +87 -0
  172. package/dist/testing/fake-custd.d.ts +150 -0
  173. package/dist/testing/fake-custd.js +842 -0
  174. package/dist/testing/fake-results.d.ts +30 -0
  175. package/dist/testing/fake-results.js +293 -0
  176. package/dist/testing.d.ts +2 -0
  177. package/dist/testing.js +3 -0
  178. package/dist/version.d.ts +2 -2
  179. package/dist/version.js +1 -1
  180. package/package.json +25 -14
  181. package/dist/browser-script-BvgjdZSO.js +0 -429
  182. package/dist/fixtures.d.ts +0 -10
  183. package/dist/fixtures.js +0 -57
@@ -0,0 +1,169 @@
1
+ // UsageAdminClient reads attributed usage and retained storage. `get` reads the
2
+ // authenticated tenant's own usage through GET /api/v1/admin/usage/me; the
3
+ // tenant is derived from the credential. `listUsage` and `exportUsage` are the
4
+ // system-admin views that may name a company, and `listStorageUsage` /
5
+ // `getRetainedUsage` report retained storage against each tenant's limit.
6
+ //
7
+ // Usage is server-derived and includes provisional, final, and corrected state.
8
+ // `containsProvisional` and `containsIncomplete` are the server's own assessment
9
+ // of the returned rows, so a caller deciding whether a number is settled reads
10
+ // them rather than assuming every row is final.
11
+ import { optionalString, requireBoolean, requireInteger, requireObjectList, requireRecord, requireString, } from "./response-validation.js";
12
+ /** The row cap the service applies when a request omits a limit. */
13
+ export const USAGE_DEFAULT_LIMIT = 500;
14
+ /** The most rows the usage endpoint returns in one request. */
15
+ export const USAGE_MAX_LIMIT = 5000;
16
+ export class UsageAdminClient {
17
+ constructor(request) {
18
+ this.request = request;
19
+ }
20
+ /**
21
+ * Return the attributed usage for the token's own tenant. The tenant is
22
+ * derived from the credential, so the caller never supplies a company slug.
23
+ */
24
+ get(query = {}, options) {
25
+ let params;
26
+ try {
27
+ params = usageQueryParams(query).toString();
28
+ }
29
+ catch (error) {
30
+ return Promise.reject(error);
31
+ }
32
+ return this.request("GET", `/usage/me${params.length > 0 ? `?${params}` : ""}`, undefined, options).then(assertUsageReport);
33
+ }
34
+ /** System administrators: attributed usage across tenants, or one company's. */
35
+ listUsage(query = {}, options) {
36
+ return this.adminUsage("/usage", query, options);
37
+ }
38
+ /** System administrators: the same rows as `listUsage`, as a JSON billing export. */
39
+ exportUsage(query = {}, options) {
40
+ return this.adminUsage("/usage/export", query, options, { format: "json" });
41
+ }
42
+ /** System administrators: retained storage for every tenant. */
43
+ async listStorageUsage(options) {
44
+ const summary = await this.request("GET", "/storage-usage", undefined, options);
45
+ return { ...summary, tenants: summary.tenants ?? [] };
46
+ }
47
+ /** The token's own tenant's retained storage. */
48
+ getRetainedUsage(options) {
49
+ return this.request("GET", "/storage-usage/me", undefined, options);
50
+ }
51
+ adminUsage(path, query, options, fixed = {}) {
52
+ const { companySlug, ...window } = query;
53
+ let params;
54
+ try {
55
+ params = usageQueryParams(window);
56
+ }
57
+ catch (error) {
58
+ return Promise.reject(error);
59
+ }
60
+ if (companySlug)
61
+ params.set("companySlug", companySlug);
62
+ for (const [name, value] of Object.entries(fixed))
63
+ params.set(name, value);
64
+ const encoded = params.toString();
65
+ return this.request("GET", encoded ? `${path}?${encoded}` : path, undefined, options).then(assertUsageReport);
66
+ }
67
+ }
68
+ // assertUsageReport validates the named response DTO. The service emits every
69
+ // required field, so a truncated or wrongly shaped body fails here instead of
70
+ // surfacing as a zero-valued report.
71
+ function assertUsageReport(value) {
72
+ const context = "usage response";
73
+ const report = requireRecord(value, context);
74
+ requireString(report, "schemaVersion", context);
75
+ requireString(report, "start", context);
76
+ requireString(report, "end", context);
77
+ requireInteger(report, "sourceWatermark", context);
78
+ requireBoolean(report, "containsProvisional", context);
79
+ requireBoolean(report, "containsIncomplete", context);
80
+ optionalString(report, "companySlug", context);
81
+ for (const [index, row] of requireObjectList(report, "rows", context).entries()) {
82
+ const rowContext = `${context} rows[${index}]`;
83
+ requireString(row, "accountCompanySlug", rowContext);
84
+ requireString(row, "dataSpaceCompanySlug", rowContext);
85
+ requireString(row, "meterSlug", rowContext);
86
+ requireInteger(row, "meterVersion", rowContext);
87
+ requireString(row, "unit", rowContext);
88
+ requireString(row, "windowStart", rowContext);
89
+ requireString(row, "windowEnd", rowContext);
90
+ requireInteger(row, "quantity", rowContext);
91
+ requireInteger(row, "sourceWatermark", rowContext);
92
+ requireString(row, "completenessState", rowContext);
93
+ requireInteger(row, "correctionGeneration", rowContext);
94
+ requireInteger(row, "calculationVersion", rowContext);
95
+ }
96
+ for (const [index, total] of requireObjectList(report, "totals", context).entries()) {
97
+ const totalContext = `${context} totals[${index}]`;
98
+ requireString(total, "accountCompanySlug", totalContext);
99
+ requireString(total, "dataSpaceCompanySlug", totalContext);
100
+ requireString(total, "meterSlug", totalContext);
101
+ requireString(total, "unit", totalContext);
102
+ requireInteger(total, "quantity", totalContext);
103
+ }
104
+ return report;
105
+ }
106
+ // RFC3339_PATTERN is the documented usage-window grammar: a full timestamp with
107
+ // the T separator, an explicit Z or numeric offset, and captured date and clock
108
+ // components. It rejects values Date.parse accepts, such as a date-only string
109
+ // or a space-separated timestamp.
110
+ const RFC3339_PATTERN = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
111
+ function parseInstant(value, field) {
112
+ const match = RFC3339_PATTERN.exec(value);
113
+ if (match === null) {
114
+ throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
115
+ }
116
+ // Date.parse normalizes values that are not valid RFC3339 clock times: hour 24
117
+ // rolls to the next day and second 60 rolls to the next minute. Bound the
118
+ // clock components before trusting the parse, exactly as the calendar date is
119
+ // checked below.
120
+ const hour = Number(match[4]);
121
+ const minute = Number(match[5]);
122
+ const second = Number(match[6]);
123
+ if (hour > 23 || minute > 59 || second > 59) {
124
+ throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
125
+ }
126
+ // Date.parse normalizes an impossible day such as February 30, so verify the
127
+ // calendar date itself before trusting the parsed instant.
128
+ const year = Number(match[1]);
129
+ const month = Number(match[2]);
130
+ const day = Number(match[3]);
131
+ const utc = new Date(Date.UTC(year, month - 1, day));
132
+ if (utc.getUTCFullYear() !== year || utc.getUTCMonth() !== month - 1 || utc.getUTCDate() !== day) {
133
+ throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
134
+ }
135
+ const parsed = Date.parse(value);
136
+ if (Number.isNaN(parsed)) {
137
+ throw new RangeError(`custd: usage ${field} must be an RFC3339 timestamp`);
138
+ }
139
+ return parsed;
140
+ }
141
+ /**
142
+ * Build the query string and reject locally what the service would reject
143
+ * anyway, so an invalid window never costs a round trip.
144
+ */
145
+ function usageQueryParams(query) {
146
+ if (query.limit !== undefined &&
147
+ (!Number.isInteger(query.limit) || query.limit < 1 || query.limit > USAGE_MAX_LIMIT)) {
148
+ throw new RangeError(`custd: usage limit must be between 1 and ${USAGE_MAX_LIMIT}`);
149
+ }
150
+ const start = query.start === undefined ? undefined : parseInstant(query.start, "start");
151
+ const end = query.end === undefined ? undefined : parseInstant(query.end, "end");
152
+ if (start !== undefined && end !== undefined && start >= end) {
153
+ throw new RangeError("custd: usage start must be before end");
154
+ }
155
+ const params = new URLSearchParams();
156
+ if (query.end !== undefined) {
157
+ params.set("end", query.end);
158
+ }
159
+ if (query.limit !== undefined) {
160
+ params.set("limit", String(query.limit));
161
+ }
162
+ if (query.meterSlug !== undefined) {
163
+ params.set("meter", query.meterSlug);
164
+ }
165
+ if (query.start !== undefined) {
166
+ params.set("start", query.start);
167
+ }
168
+ return params;
169
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Tenant administrator users and their roles. A user has a global identity state and a
3
+ * per-company membership state, reported separately: disabling an identity and ending a
4
+ * membership are different decisions.
5
+ */
6
+ import type { RequestOptions } from "./index.js";
7
+ /** The roles a tenant membership can carry. */
8
+ export declare const ADMIN_USER_ROLES: {
9
+ readonly tenantAdmin: "tenant_admin";
10
+ readonly tenantIngestManager: "tenant_ingest_manager";
11
+ readonly tenantAnalyst: "tenant_analyst";
12
+ };
13
+ export type AdminUserRole = (typeof ADMIN_USER_ROLES)[keyof typeof ADMIN_USER_ROLES];
14
+ export declare const ADMIN_USER_GLOBAL_STATES: {
15
+ readonly enabled: "enabled";
16
+ readonly suspended: "suspended";
17
+ };
18
+ export type AdminUserGlobalState = (typeof ADMIN_USER_GLOBAL_STATES)[keyof typeof ADMIN_USER_GLOBAL_STATES];
19
+ export declare const ADMIN_USER_MEMBERSHIP_STATES: {
20
+ readonly active: "active";
21
+ readonly ended: "ended";
22
+ };
23
+ export type AdminUserMembershipState = (typeof ADMIN_USER_MEMBERSHIP_STATES)[keyof typeof ADMIN_USER_MEMBERSHIP_STATES];
24
+ /** One administrator user in one company. The removal fields are null until the user is removed. */
25
+ export type AdminUser = {
26
+ userUuid: string;
27
+ email: string;
28
+ companySlug: string;
29
+ roles: AdminUserRole[];
30
+ globalUserState: AdminUserGlobalState;
31
+ membershipState: AdminUserMembershipState;
32
+ createdAt: string;
33
+ lastLoginAt: string | null;
34
+ welcomeNotificationStatus: string;
35
+ deletedAt: string | null;
36
+ deletedByUserUuid: string | null;
37
+ deleteReason: string | null;
38
+ };
39
+ export type AdminUserListResponse = {
40
+ users: AdminUser[];
41
+ };
42
+ /** A role a membership can carry, with its display name. */
43
+ export type AdminUserRoleDescription = {
44
+ slug: AdminUserRole;
45
+ name: string;
46
+ description: string;
47
+ };
48
+ export type AdminUserRoleListResponse = {
49
+ roles: AdminUserRoleDescription[];
50
+ };
51
+ /** Filters for a user list. A tenant administrator always sees only its own company. */
52
+ export type AdminUserListQuery = {
53
+ companySlug?: string;
54
+ role?: AdminUserRole;
55
+ globalState?: AdminUserGlobalState;
56
+ membershipState?: AdminUserMembershipState;
57
+ welcomeStatus?: string;
58
+ includeEnded?: boolean;
59
+ /** Lists removed users too. System administrators only. */
60
+ includeDeleted?: boolean;
61
+ };
62
+ /** Narrows a single-user read or action to one company, optionally including ended memberships. */
63
+ export type AdminUserScope = {
64
+ companySlug?: string;
65
+ includeEnded?: boolean;
66
+ };
67
+ export type AdminUserCreateRequest = {
68
+ companySlug: string;
69
+ email: string;
70
+ roles: AdminUserRole[];
71
+ };
72
+ export type AdminUserUpdateRequest = {
73
+ roles: AdminUserRole[];
74
+ };
75
+ export type AdminUserMembershipCreateRequest = {
76
+ companySlug: string;
77
+ roles: AdminUserRole[];
78
+ };
79
+ /** A disable. `globalUser` disables the identity rather than one membership (system administrators only). */
80
+ export type AdminUserDisableRequest = {
81
+ reason?: string;
82
+ companySlug?: string;
83
+ globalUser?: boolean;
84
+ };
85
+ /** An enable. A membership reopens only with the roles it carries. */
86
+ export type AdminUserEnableRequest = {
87
+ roles: AdminUserRole[];
88
+ companySlug?: string;
89
+ globalUser?: boolean;
90
+ };
91
+ /** The reason for a soft delete or restore; it lands in the tenant's audit stream. */
92
+ export type AdminUserRemovalRequest = {
93
+ reason: string;
94
+ };
95
+ /** The notification a reset queued, not a password: the server never returns the credential. */
96
+ export type AdminUserPasswordReset = {
97
+ messageUuid: string;
98
+ deliveryUuids: string[];
99
+ };
100
+ type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
101
+ export declare class AdminUserAdminClient {
102
+ private readonly request;
103
+ constructor(request: AdminRequester);
104
+ list(query?: AdminUserListQuery, options?: RequestOptions): Promise<AdminUserListResponse>;
105
+ /** The roles a membership can be given. */
106
+ listRoles(options?: RequestOptions): Promise<AdminUserRoleListResponse>;
107
+ get(userUuid: string, scope?: AdminUserScope, options?: RequestOptions): Promise<AdminUser>;
108
+ /** Creates a user with a membership in one company and queues the welcome notification. */
109
+ create(body: AdminUserCreateRequest, options?: RequestOptions): Promise<AdminUser>;
110
+ /** Replaces the user's roles in one company. */
111
+ update(userUuid: string, body: AdminUserUpdateRequest, companySlug?: string, options?: RequestOptions): Promise<AdminUser>;
112
+ disable(userUuid: string, request?: AdminUserDisableRequest, options?: RequestOptions): Promise<void>;
113
+ enable(userUuid: string, request: AdminUserEnableRequest, options?: RequestOptions): Promise<void>;
114
+ /** Adds an existing user to another company with the given roles. */
115
+ addMembership(userUuid: string, body: AdminUserMembershipCreateRequest, options?: RequestOptions): Promise<AdminUser>;
116
+ resetPassword(userUuid: string, scope?: AdminUserScope, options?: RequestOptions): Promise<AdminUserPasswordReset>;
117
+ /** Removes the user's access in one company while keeping the record. */
118
+ softDelete(userUuid: string, companySlug: string, body: AdminUserRemovalRequest, options?: RequestOptions): Promise<AdminUser>;
119
+ /** Reverses a soft delete in one company. */
120
+ restore(userUuid: string, companySlug: string, body: AdminUserRemovalRequest, options?: RequestOptions): Promise<AdminUser>;
121
+ /** Re-sends the welcome notification. */
122
+ retryWelcome(userUuid: string, scope?: AdminUserScope, options?: RequestOptions): Promise<void>;
123
+ }
124
+ export {};
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Tenant administrator users and their roles. A user has a global identity state and a
3
+ * per-company membership state, reported separately: disabling an identity and ending a
4
+ * membership are different decisions.
5
+ */
6
+ /** The roles a tenant membership can carry. */
7
+ export const ADMIN_USER_ROLES = {
8
+ tenantAdmin: "tenant_admin",
9
+ tenantIngestManager: "tenant_ingest_manager",
10
+ tenantAnalyst: "tenant_analyst",
11
+ };
12
+ export const ADMIN_USER_GLOBAL_STATES = { enabled: "enabled", suspended: "suspended" };
13
+ export const ADMIN_USER_MEMBERSHIP_STATES = { active: "active", ended: "ended" };
14
+ const usersPath = "/users";
15
+ export class AdminUserAdminClient {
16
+ constructor(request) {
17
+ this.request = request;
18
+ }
19
+ async list(query = {}, options) {
20
+ const response = await this.request("GET", withQuery(usersPath, query), undefined, options);
21
+ return { users: response.users ?? [] };
22
+ }
23
+ /** The roles a membership can be given. */
24
+ async listRoles(options) {
25
+ const response = await this.request("GET", "/user-roles", undefined, options);
26
+ return { roles: response.roles ?? [] };
27
+ }
28
+ get(userUuid, scope = {}, options) {
29
+ return this.request("GET", withQuery(userPath(userUuid), scope), undefined, options);
30
+ }
31
+ /** Creates a user with a membership in one company and queues the welcome notification. */
32
+ create(body, options) {
33
+ return this.request("POST", usersPath, body, options);
34
+ }
35
+ /** Replaces the user's roles in one company. */
36
+ update(userUuid, body, companySlug, options) {
37
+ return this.request("PUT", withQuery(userPath(userUuid), { companySlug }), body, options);
38
+ }
39
+ disable(userUuid, request = {}, options) {
40
+ const { reason, ...query } = request;
41
+ const body = reason === undefined ? undefined : { reason };
42
+ return this.request("POST", withQuery(`${userPath(userUuid)}/disable`, query), body, options);
43
+ }
44
+ enable(userUuid, request, options) {
45
+ const { roles, ...query } = request;
46
+ return this.request("POST", withQuery(`${userPath(userUuid)}/enable`, query), { roles }, options);
47
+ }
48
+ /** Adds an existing user to another company with the given roles. */
49
+ addMembership(userUuid, body, options) {
50
+ return this.request("POST", `${userPath(userUuid)}/memberships`, body, options);
51
+ }
52
+ async resetPassword(userUuid, scope = {}, options) {
53
+ const path = withQuery(`${userPath(userUuid)}/reset-password`, scope);
54
+ const reset = await this.request("POST", path, undefined, options);
55
+ return { messageUuid: reset.messageUuid, deliveryUuids: reset.deliveryUuids ?? [] };
56
+ }
57
+ /** Removes the user's access in one company while keeping the record. */
58
+ softDelete(userUuid, companySlug, body, options) {
59
+ return this.request("POST", withQuery(`${userPath(userUuid)}/soft-delete`, { companySlug }), body, options);
60
+ }
61
+ /** Reverses a soft delete in one company. */
62
+ restore(userUuid, companySlug, body, options) {
63
+ return this.request("POST", withQuery(`${userPath(userUuid)}/restore`, { companySlug }), body, options);
64
+ }
65
+ /** Re-sends the welcome notification. */
66
+ retryWelcome(userUuid, scope = {}, options) {
67
+ return this.request("POST", withQuery(`${userPath(userUuid)}/retry-welcome`, scope), undefined, options);
68
+ }
69
+ }
70
+ function userPath(userUuid) {
71
+ return `${usersPath}/${encodeURIComponent(userUuid)}`;
72
+ }
73
+ function withQuery(path, query) {
74
+ const params = new URLSearchParams();
75
+ for (const [key, value] of Object.entries(query)) {
76
+ if (value === undefined || value === "" || value === false)
77
+ continue;
78
+ params.set(key, String(value));
79
+ }
80
+ const encoded = params.toString();
81
+ return encoded ? `${path}?${encoded}` : path;
82
+ }