@haakco/custd-sdk 3.71.2 → 3.72.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.
- package/README.md +1 -1
- package/dist/admin-machine-access.d.ts +97 -0
- package/dist/admin-machine-access.js +58 -0
- package/dist/browser-manifest.json +1 -1
- package/dist/browser-sign-in.d.ts +9 -0
- package/dist/browser-sign-in.js +43 -2
- package/dist/index.d.ts +27 -1
- package/dist/index.js +19 -3
- package/dist/response-lists.generated.js +5 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ release **3.52.0** on 2026-11-17, including Node 26, pnpm 12 and Expo 58 consume
|
|
|
13
13
|
Both packages are public on npmjs and released at every SDK tag:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
pnpm add @haakco/custd-sdk@^3.
|
|
16
|
+
pnpm add @haakco/custd-sdk@^3.72.0
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
A pnpm project with `minimumReleaseAge` set should list `@haakco/*` in
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a company's machine credentials (OAuth clients) may do, per feature area, for the whole
|
|
3
|
+
* company and for each machine. The policy only narrows: an allowed area still needs the client's
|
|
4
|
+
* own scopes, and a blocked area refuses that company's machines with a problem coded
|
|
5
|
+
* `machine_access_blocked` whose `machineAccess` member names the setting.
|
|
6
|
+
*/
|
|
7
|
+
import type { RequestOptions } from "./index.js";
|
|
8
|
+
export declare const MACHINE_ACCESS_AREAS: {
|
|
9
|
+
readonly sites: "sites";
|
|
10
|
+
readonly reporting: "reporting";
|
|
11
|
+
readonly privacyErasure: "privacy_erasure";
|
|
12
|
+
readonly destructiveJobs: "destructive_jobs";
|
|
13
|
+
readonly usersAccess: "users_access";
|
|
14
|
+
readonly provisioning: "provisioning_credentials";
|
|
15
|
+
readonly ingestSchemas: "ingest_schemas";
|
|
16
|
+
readonly usageBilling: "usage_billing";
|
|
17
|
+
};
|
|
18
|
+
export type MachineAccessArea = (typeof MACHINE_ACCESS_AREAS)[keyof typeof MACHINE_ACCESS_AREAS];
|
|
19
|
+
/** A company setting is allowed or blocked; a machine override may also inherit the company's. */
|
|
20
|
+
export declare const MACHINE_ACCESS_STATES: {
|
|
21
|
+
readonly allowed: "allowed";
|
|
22
|
+
readonly blocked: "blocked";
|
|
23
|
+
readonly inherit: "inherit";
|
|
24
|
+
};
|
|
25
|
+
export type MachineAccessState = (typeof MACHINE_ACCESS_STATES)[keyof typeof MACHINE_ACCESS_STATES];
|
|
26
|
+
/** The setting that decided an area, or that refused a request. */
|
|
27
|
+
export declare const MACHINE_ACCESS_DECIDED_BY: {
|
|
28
|
+
readonly company: "company";
|
|
29
|
+
readonly machine: "machine";
|
|
30
|
+
/** The target company's "Allow Custd support automation" setting, for Custd's platform operator machine. */
|
|
31
|
+
readonly supportAutomation: "support_automation";
|
|
32
|
+
};
|
|
33
|
+
export type MachineAccessDecidedBy = (typeof MACHINE_ACCESS_DECIDED_BY)[keyof typeof MACHINE_ACCESS_DECIDED_BY];
|
|
34
|
+
/** Problem codes of a machine access refusal; `unavailable` is a bounded retry, not a setting to change. */
|
|
35
|
+
export declare const MACHINE_ACCESS_PROBLEM_CODES: {
|
|
36
|
+
readonly blocked: "machine_access_blocked";
|
|
37
|
+
readonly unavailable: "machine_access_unavailable";
|
|
38
|
+
};
|
|
39
|
+
/** The `machineAccess` member of a `machine_access_blocked` problem. */
|
|
40
|
+
export type MachineAccessBlock = {
|
|
41
|
+
area: MachineAccessArea;
|
|
42
|
+
blockedBy: MachineAccessDecidedBy;
|
|
43
|
+
companySlug: string;
|
|
44
|
+
clientId: string;
|
|
45
|
+
};
|
|
46
|
+
export type MachineAccessAreaSetting = {
|
|
47
|
+
area: MachineAccessArea;
|
|
48
|
+
state: MachineAccessState;
|
|
49
|
+
};
|
|
50
|
+
export type MachineAccessCompanyPolicy = {
|
|
51
|
+
companySlug: string;
|
|
52
|
+
allowSupportAutomation: boolean;
|
|
53
|
+
areas: MachineAccessAreaSetting[];
|
|
54
|
+
};
|
|
55
|
+
/** Changes the settings it names and leaves the rest; each area is allowed or blocked. */
|
|
56
|
+
export type MachineAccessCompanyUpdateRequest = {
|
|
57
|
+
allowSupportAutomation?: boolean;
|
|
58
|
+
areas?: MachineAccessAreaSetting[];
|
|
59
|
+
};
|
|
60
|
+
export type MachineAccessMachinePolicy = {
|
|
61
|
+
companySlug: string;
|
|
62
|
+
clientId: string;
|
|
63
|
+
areas: MachineAccessAreaSetting[];
|
|
64
|
+
};
|
|
65
|
+
/** Changes the areas it names for one machine; each is inherit, allowed or blocked. */
|
|
66
|
+
export type MachineAccessMachineUpdateRequest = {
|
|
67
|
+
areas: MachineAccessAreaSetting[];
|
|
68
|
+
};
|
|
69
|
+
export type MachineAccessEffectiveArea = {
|
|
70
|
+
area: MachineAccessArea;
|
|
71
|
+
allowed: boolean;
|
|
72
|
+
decidedBy: MachineAccessDecidedBy;
|
|
73
|
+
companyState: MachineAccessState;
|
|
74
|
+
machineState: MachineAccessState;
|
|
75
|
+
};
|
|
76
|
+
/** One machine's effective access next to the scopes it was issued; an allowed area still needs its scope. */
|
|
77
|
+
export type MachineAccessEffective = {
|
|
78
|
+
companySlug: string;
|
|
79
|
+
clientId: string;
|
|
80
|
+
scopes: string[];
|
|
81
|
+
allowedAreas: number;
|
|
82
|
+
totalAreas: number;
|
|
83
|
+
areas: MachineAccessEffectiveArea[];
|
|
84
|
+
};
|
|
85
|
+
type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
|
|
86
|
+
export declare class MachineAccessAdminClient {
|
|
87
|
+
private readonly request;
|
|
88
|
+
constructor(request: AdminRequester);
|
|
89
|
+
/** A tenant administrator omits companySlug; platform authority names the company. */
|
|
90
|
+
get(companySlug?: string, options?: RequestOptions): Promise<MachineAccessCompanyPolicy>;
|
|
91
|
+
update(body: MachineAccessCompanyUpdateRequest, companySlug?: string, options?: RequestOptions): Promise<MachineAccessCompanyPolicy>;
|
|
92
|
+
/** The machine's own company is the scope. */
|
|
93
|
+
getOverride(clientId: string, options?: RequestOptions): Promise<MachineAccessMachinePolicy>;
|
|
94
|
+
updateOverride(clientId: string, body: MachineAccessMachineUpdateRequest, options?: RequestOptions): Promise<MachineAccessMachinePolicy>;
|
|
95
|
+
getEffective(clientId: string, options?: RequestOptions): Promise<MachineAccessEffective>;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a company's machine credentials (OAuth clients) may do, per feature area, for the whole
|
|
3
|
+
* company and for each machine. The policy only narrows: an allowed area still needs the client's
|
|
4
|
+
* own scopes, and a blocked area refuses that company's machines with a problem coded
|
|
5
|
+
* `machine_access_blocked` whose `machineAccess` member names the setting.
|
|
6
|
+
*/
|
|
7
|
+
export const MACHINE_ACCESS_AREAS = {
|
|
8
|
+
sites: "sites",
|
|
9
|
+
reporting: "reporting",
|
|
10
|
+
privacyErasure: "privacy_erasure",
|
|
11
|
+
destructiveJobs: "destructive_jobs",
|
|
12
|
+
usersAccess: "users_access",
|
|
13
|
+
provisioning: "provisioning_credentials",
|
|
14
|
+
ingestSchemas: "ingest_schemas",
|
|
15
|
+
usageBilling: "usage_billing",
|
|
16
|
+
};
|
|
17
|
+
/** A company setting is allowed or blocked; a machine override may also inherit the company's. */
|
|
18
|
+
export const MACHINE_ACCESS_STATES = { allowed: "allowed", blocked: "blocked", inherit: "inherit" };
|
|
19
|
+
/** The setting that decided an area, or that refused a request. */
|
|
20
|
+
export const MACHINE_ACCESS_DECIDED_BY = {
|
|
21
|
+
company: "company",
|
|
22
|
+
machine: "machine",
|
|
23
|
+
/** The target company's "Allow Custd support automation" setting, for Custd's platform operator machine. */
|
|
24
|
+
supportAutomation: "support_automation",
|
|
25
|
+
};
|
|
26
|
+
/** Problem codes of a machine access refusal; `unavailable` is a bounded retry, not a setting to change. */
|
|
27
|
+
export const MACHINE_ACCESS_PROBLEM_CODES = {
|
|
28
|
+
blocked: "machine_access_blocked",
|
|
29
|
+
unavailable: "machine_access_unavailable",
|
|
30
|
+
};
|
|
31
|
+
export class MachineAccessAdminClient {
|
|
32
|
+
constructor(request) {
|
|
33
|
+
this.request = request;
|
|
34
|
+
}
|
|
35
|
+
/** A tenant administrator omits companySlug; platform authority names the company. */
|
|
36
|
+
get(companySlug, options) {
|
|
37
|
+
return this.request("GET", companyPath(companySlug), undefined, options);
|
|
38
|
+
}
|
|
39
|
+
update(body, companySlug, options) {
|
|
40
|
+
return this.request("PUT", companyPath(companySlug), body, options);
|
|
41
|
+
}
|
|
42
|
+
/** The machine's own company is the scope. */
|
|
43
|
+
getOverride(clientId, options) {
|
|
44
|
+
return this.request("GET", clientPath(clientId), undefined, options);
|
|
45
|
+
}
|
|
46
|
+
updateOverride(clientId, body, options) {
|
|
47
|
+
return this.request("PUT", clientPath(clientId), body, options);
|
|
48
|
+
}
|
|
49
|
+
getEffective(clientId, options) {
|
|
50
|
+
return this.request("GET", clientPath(clientId, "/effective"), undefined, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function companyPath(companySlug) {
|
|
54
|
+
return companySlug ? `/machine-access?companySlug=${encodeURIComponent(companySlug)}` : "/machine-access";
|
|
55
|
+
}
|
|
56
|
+
function clientPath(clientId, suffix = "") {
|
|
57
|
+
return `/machine-access/clients/${encodeURIComponent(clientId)}${suffix}`;
|
|
58
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type OpenAppAccountSettingsOptions } from "./app-account.js";
|
|
1
2
|
/** Sign-in block of the hosted app discovery file `/.well-known/custd.json`. */
|
|
2
3
|
export type CustdDiscoverySignIn = {
|
|
3
4
|
issuer: string;
|
|
@@ -25,6 +26,8 @@ export type BrowserSignInConfig = BrowserSignInEndpoints & {
|
|
|
25
26
|
fetch?: typeof fetch;
|
|
26
27
|
now?: () => number;
|
|
27
28
|
navigate?: (url: string) => void;
|
|
29
|
+
/** Opens hosted account settings after a sign-in settings asked for; replace it in tests. */
|
|
30
|
+
openAccountSettings?: (options: OpenAppAccountSettingsOptions) => Promise<void>;
|
|
28
31
|
};
|
|
29
32
|
export type SignInDiscoveryOptions = {
|
|
30
33
|
redirectUri: string;
|
|
@@ -42,6 +45,8 @@ export type SignInSession = {
|
|
|
42
45
|
export type SignInStartOptions = {
|
|
43
46
|
/** Same-origin path to return to after sign-in. Defaults to the current page. */
|
|
44
47
|
returnTo?: string;
|
|
48
|
+
/** Reopen hosted account settings, linking back to `returnTo`, once sign-in completes. */
|
|
49
|
+
openAccountSettings?: boolean;
|
|
45
50
|
};
|
|
46
51
|
export type SignInStart = {
|
|
47
52
|
authorizationUrl: string;
|
|
@@ -49,6 +54,7 @@ export type SignInStart = {
|
|
|
49
54
|
export type SignInCompletion = {
|
|
50
55
|
session: SignInSession;
|
|
51
56
|
returnTo: string;
|
|
57
|
+
openAccountSettings?: boolean;
|
|
52
58
|
};
|
|
53
59
|
export type SignOutOptions = {
|
|
54
60
|
postLogoutRedirectUri?: string;
|
|
@@ -109,6 +115,7 @@ export declare class BrowserSignIn {
|
|
|
109
115
|
private readonly fetchImpl;
|
|
110
116
|
private readonly now;
|
|
111
117
|
private readonly navigate;
|
|
118
|
+
private readonly openAccountSettings;
|
|
112
119
|
private readonly listeners;
|
|
113
120
|
private state;
|
|
114
121
|
private completion;
|
|
@@ -139,6 +146,8 @@ export declare class BrowserSignIn {
|
|
|
139
146
|
signOut(options?: SignOutOptions): SignOutResult;
|
|
140
147
|
private initialState;
|
|
141
148
|
private exchangeCallback;
|
|
149
|
+
/** Opens settings after the sign-in it asked for; a refusal leaves the person on the app page. */
|
|
150
|
+
private reopenAccountSettings;
|
|
142
151
|
private exchangeRefreshToken;
|
|
143
152
|
private requestTokens;
|
|
144
153
|
private sessionFromTokenResponse;
|
package/dist/browser-sign-in.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// The app is a public client, so no client secret is involved. Pending sign-in
|
|
4
4
|
// state and the token set live in sessionStorage by default. Tokens are never
|
|
5
5
|
// placed in error messages.
|
|
6
|
+
import { openAppAccountSettings } from "./app-account.js";
|
|
6
7
|
export const SIGN_IN_STATUSES = {
|
|
7
8
|
signedOut: "signed_out",
|
|
8
9
|
signingIn: "signing_in",
|
|
@@ -34,6 +35,12 @@ export const DEFAULT_SIGN_IN_SCOPES = ["openid", "profile", "offline_access"];
|
|
|
34
35
|
const STORAGE_PREFIX = "custd:sign-in";
|
|
35
36
|
const EXPIRY_SKEW_MS = 30000;
|
|
36
37
|
const RANDOM_BYTES = 32;
|
|
38
|
+
/**
|
|
39
|
+
* Hosted settings sends a person back with this query parameter when managing their sign-in methods
|
|
40
|
+
* needs a fresh sign-in. `restore()` then signs them in and reopens settings on the same page.
|
|
41
|
+
*/
|
|
42
|
+
const ACCOUNT_SIGN_IN_PARAM = "custd_account";
|
|
43
|
+
const ACCOUNT_SIGN_IN_AGAIN = "sign_in_again";
|
|
37
44
|
/** Reads and validates the sign-in endpoints from a discovery document. */
|
|
38
45
|
export function signInConfigFromDiscovery(document, options) {
|
|
39
46
|
const signIn = document.signIn;
|
|
@@ -69,12 +76,13 @@ export class BrowserSignIn {
|
|
|
69
76
|
this.completion = null;
|
|
70
77
|
this.refresh = null;
|
|
71
78
|
validateEndpoints(config);
|
|
72
|
-
const { storage, fetch: fetchImpl, now, navigate, ...endpoints } = config;
|
|
79
|
+
const { storage, fetch: fetchImpl, now, navigate, openAccountSettings, ...endpoints } = config;
|
|
73
80
|
this.config = endpoints;
|
|
74
81
|
this.storage = storage ?? defaultStorage();
|
|
75
82
|
this.fetchImpl = fetchImpl ?? ((input, init) => globalThis.fetch(input, init));
|
|
76
83
|
this.now = now ?? Date.now;
|
|
77
84
|
this.navigate = navigate ?? ((url) => window.location.assign(url));
|
|
85
|
+
this.openAccountSettings = openAccountSettings ?? openAppAccountSettings;
|
|
78
86
|
this.state = this.initialState();
|
|
79
87
|
}
|
|
80
88
|
/** Current state for UI bindings; replaced (never mutated) on each change. */
|
|
@@ -97,6 +105,8 @@ export class BrowserSignIn {
|
|
|
97
105
|
codeVerifier: randomToken(),
|
|
98
106
|
returnTo: safeReturnTo(options.returnTo ?? currentPath()),
|
|
99
107
|
};
|
|
108
|
+
if (options.openAccountSettings)
|
|
109
|
+
pending.openAccountSettings = true;
|
|
100
110
|
this.storage.setItem(this.storageKey("pending"), JSON.stringify(pending));
|
|
101
111
|
const url = new URL(this.config.authorizationEndpoint);
|
|
102
112
|
url.searchParams.set("response_type", "code");
|
|
@@ -141,10 +151,18 @@ export class BrowserSignIn {
|
|
|
141
151
|
* redirect URI, otherwise reads the stored session and refreshes it if expired.
|
|
142
152
|
*/
|
|
143
153
|
async restore(url = currentHref()) {
|
|
154
|
+
const settingsReturn = accountSignInReturn(url);
|
|
155
|
+
if (settingsReturn !== null) {
|
|
156
|
+
await this.signIn({ returnTo: settingsReturn, openAccountSettings: true });
|
|
157
|
+
return { state: this.state };
|
|
158
|
+
}
|
|
144
159
|
if (this.isPendingCallback(url)) {
|
|
145
160
|
this.setState({ status: SIGN_IN_STATUSES.signingIn });
|
|
146
161
|
try {
|
|
147
162
|
const completion = await this.completeSignIn(url);
|
|
163
|
+
if (completion.openAccountSettings && (await this.reopenAccountSettings(completion))) {
|
|
164
|
+
return { state: this.state };
|
|
165
|
+
}
|
|
148
166
|
return { state: this.state, returnTo: completion.returnTo };
|
|
149
167
|
}
|
|
150
168
|
catch (error) {
|
|
@@ -222,7 +240,22 @@ export class BrowserSignIn {
|
|
|
222
240
|
code_verifier: pending.codeVerifier,
|
|
223
241
|
});
|
|
224
242
|
this.saveSession(session);
|
|
225
|
-
return { session, returnTo: pending.returnTo };
|
|
243
|
+
return { session, returnTo: pending.returnTo, openAccountSettings: pending.openAccountSettings === true };
|
|
244
|
+
}
|
|
245
|
+
/** Opens settings after the sign-in it asked for; a refusal leaves the person on the app page. */
|
|
246
|
+
async reopenAccountSettings(completion) {
|
|
247
|
+
try {
|
|
248
|
+
await this.openAccountSettings({
|
|
249
|
+
issuer: this.config.issuer,
|
|
250
|
+
accessToken: completion.session.accessToken,
|
|
251
|
+
returnPath: completion.returnTo,
|
|
252
|
+
fetch: this.fetchImpl,
|
|
253
|
+
});
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
226
259
|
}
|
|
227
260
|
async exchangeRefreshToken() {
|
|
228
261
|
const refreshToken = this.currentSession()?.refreshToken;
|
|
@@ -331,6 +364,14 @@ function base64Url(bytes) {
|
|
|
331
364
|
binary += String.fromCharCode(byte);
|
|
332
365
|
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
333
366
|
}
|
|
367
|
+
/** The page to return to when `url` carries the settings sign-in request, otherwise null. */
|
|
368
|
+
function accountSignInReturn(url) {
|
|
369
|
+
const parsed = new URL(url);
|
|
370
|
+
if (parsed.searchParams.get(ACCOUNT_SIGN_IN_PARAM) !== ACCOUNT_SIGN_IN_AGAIN)
|
|
371
|
+
return null;
|
|
372
|
+
parsed.searchParams.delete(ACCOUNT_SIGN_IN_PARAM);
|
|
373
|
+
return `${parsed.pathname}${parsed.search}`;
|
|
374
|
+
}
|
|
334
375
|
function safeReturnTo(path) {
|
|
335
376
|
return path.startsWith("/") && !path.startsWith("//") ? path : "/";
|
|
336
377
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { ErrorIssueAdminClient } from "./admin-error-issues.js";
|
|
|
22
22
|
import { EventTypeAdminClient } from "./admin-event-types.js";
|
|
23
23
|
import { ImpersonationAdminClient } from "./admin-impersonation.js";
|
|
24
24
|
import { IngestClaimAdminClient } from "./admin-ingest-claims.js";
|
|
25
|
+
import { MachineAccessAdminClient, type MachineAccessBlock } from "./admin-machine-access.js";
|
|
25
26
|
import { ManagedAuditAdminClient } from "./admin-managed-audit.js";
|
|
26
27
|
import { AdminMeasurementNamespace } from "./admin-measurement-projects.js";
|
|
27
28
|
import { NotificationDestinationAdminClient } from "./admin-notification-destinations.js";
|
|
@@ -153,6 +154,8 @@ export type ProblemDetails = {
|
|
|
153
154
|
pollAfterSeconds?: number;
|
|
154
155
|
maxRetries?: number;
|
|
155
156
|
};
|
|
157
|
+
/** Present on a `machine_access_blocked` problem: the setting that refused the request. */
|
|
158
|
+
machineAccess?: MachineAccessBlock;
|
|
156
159
|
};
|
|
157
160
|
type EventResult = {
|
|
158
161
|
eventUuid?: string;
|
|
@@ -411,14 +414,27 @@ export type RequestOptions = {
|
|
|
411
414
|
* leaves it unset.
|
|
412
415
|
*/
|
|
413
416
|
owningUserUuid?: string;
|
|
417
|
+
/**
|
|
418
|
+
* Receives the server's request identifier of this call's answer, accepted or refused, so a
|
|
419
|
+
* caller can quote the request the server logged. A refusal also carries it as `requestId`.
|
|
420
|
+
*/
|
|
421
|
+
metadata?: ResponseMetadata;
|
|
422
|
+
};
|
|
423
|
+
/** The server-side identifiers of one answer. `requestId` is empty when the server sent none. */
|
|
424
|
+
export type ResponseMetadata = {
|
|
425
|
+
requestId: string;
|
|
414
426
|
};
|
|
415
427
|
export declare class AdminWorkflowError extends Error {
|
|
416
428
|
readonly status: number;
|
|
417
429
|
readonly reason: string;
|
|
418
430
|
readonly code: string;
|
|
419
431
|
readonly safeNextAction: string;
|
|
432
|
+
/** The server's request identifier, to quote in a support request; empty when unknown. */
|
|
433
|
+
readonly requestId: string;
|
|
420
434
|
readonly name = "AdminWorkflowError";
|
|
421
|
-
constructor(status: number, reason: string, code: string, safeNextAction: string
|
|
435
|
+
constructor(status: number, reason: string, code: string, safeNextAction: string,
|
|
436
|
+
/** The server's request identifier, to quote in a support request; empty when unknown. */
|
|
437
|
+
requestId?: string);
|
|
422
438
|
}
|
|
423
439
|
export declare class CustdRequestError extends Error {
|
|
424
440
|
readonly status: number | null;
|
|
@@ -428,8 +444,14 @@ export declare class CustdRequestError extends Error {
|
|
|
428
444
|
readonly problem?: ProblemDetails | undefined;
|
|
429
445
|
readonly name = "CustdRequestError";
|
|
430
446
|
readonly cause?: unknown;
|
|
447
|
+
/**
|
|
448
|
+
* The server's request identifier, to quote in a support request: X-Request-Id, or the
|
|
449
|
+
* problem's traceId where a browser cannot read that header. Empty when the server never answered.
|
|
450
|
+
*/
|
|
451
|
+
readonly requestId: string;
|
|
431
452
|
constructor(status: number | null, code: string, retryability: "none" | "bounded", nextAction: NonNullable<ProblemDetails["nextAction"]>, problem?: ProblemDetails | undefined, options?: {
|
|
432
453
|
cause?: unknown;
|
|
454
|
+
requestId?: string;
|
|
433
455
|
});
|
|
434
456
|
get unavailable(): boolean;
|
|
435
457
|
}
|
|
@@ -592,6 +614,8 @@ export type AdminOAuthClient = {
|
|
|
592
614
|
environment?: string;
|
|
593
615
|
profile?: string;
|
|
594
616
|
purposeProfile?: string;
|
|
617
|
+
/** RFC 3339 creation time; tells apart two clients issued the same ID. */
|
|
618
|
+
createdAt?: string;
|
|
595
619
|
};
|
|
596
620
|
/** What a person needs to sign a CLI or app in with a newly created client. */
|
|
597
621
|
export type AdminOAuthClientLoginSetup = {
|
|
@@ -2079,6 +2103,7 @@ declare class AdminNamespace {
|
|
|
2079
2103
|
readonly supportAccess: SupportAccessAdminClient;
|
|
2080
2104
|
readonly system: SystemAdminClient;
|
|
2081
2105
|
readonly environmentPolicy: EnvironmentPolicyAdminClient;
|
|
2106
|
+
readonly machineAccess: MachineAccessAdminClient;
|
|
2082
2107
|
readonly rls: RlsAdminClient;
|
|
2083
2108
|
readonly oauthClientAdmissions: OAuthClientAdmissionAdminClient;
|
|
2084
2109
|
readonly sdkUsage: SdkUsageAdminClient;
|
|
@@ -2301,6 +2326,7 @@ export * from "./admin-error-issues.js";
|
|
|
2301
2326
|
export * from "./admin-event-types.js";
|
|
2302
2327
|
export * from "./admin-impersonation.js";
|
|
2303
2328
|
export * from "./admin-ingest-claims.js";
|
|
2329
|
+
export * from "./admin-machine-access.js";
|
|
2304
2330
|
export * from "./admin-managed-audit.js";
|
|
2305
2331
|
export * from "./admin-measurement-projects.js";
|
|
2306
2332
|
export * from "./admin-notification-destinations.js";
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { ErrorIssueAdminClient } from "./admin-error-issues.js";
|
|
|
23
23
|
import { EventTypeAdminClient } from "./admin-event-types.js";
|
|
24
24
|
import { ImpersonationAdminClient } from "./admin-impersonation.js";
|
|
25
25
|
import { IngestClaimAdminClient } from "./admin-ingest-claims.js";
|
|
26
|
+
import { MachineAccessAdminClient } from "./admin-machine-access.js";
|
|
26
27
|
import { ManagedAuditAdminClient } from "./admin-managed-audit.js";
|
|
27
28
|
import { AdminMeasurementNamespace } from "./admin-measurement-projects.js";
|
|
28
29
|
import { NotificationDestinationAdminClient } from "./admin-notification-destinations.js";
|
|
@@ -101,7 +102,9 @@ export function createRawIngestRequest(input) {
|
|
|
101
102
|
return { ...input, idempotencyKey: createRawRequestIdempotencyKey() };
|
|
102
103
|
}
|
|
103
104
|
export class AdminWorkflowError extends Error {
|
|
104
|
-
constructor(status, reason, code, safeNextAction
|
|
105
|
+
constructor(status, reason, code, safeNextAction,
|
|
106
|
+
/** The server's request identifier, to quote in a support request; empty when unknown. */
|
|
107
|
+
requestId = "") {
|
|
105
108
|
let message = `custd: ${reason || "admin workflow request failed"} (status ${status})`;
|
|
106
109
|
if (code)
|
|
107
110
|
message += ` [code=${code}]`;
|
|
@@ -112,6 +115,7 @@ export class AdminWorkflowError extends Error {
|
|
|
112
115
|
this.reason = reason;
|
|
113
116
|
this.code = code;
|
|
114
117
|
this.safeNextAction = safeNextAction;
|
|
118
|
+
this.requestId = requestId;
|
|
115
119
|
this.name = "AdminWorkflowError";
|
|
116
120
|
}
|
|
117
121
|
}
|
|
@@ -125,6 +129,7 @@ export class CustdRequestError extends Error {
|
|
|
125
129
|
this.problem = problem;
|
|
126
130
|
this.name = "CustdRequestError";
|
|
127
131
|
this.cause = options?.cause;
|
|
132
|
+
this.requestId = options?.requestId ?? problem?.traceId ?? "";
|
|
128
133
|
}
|
|
129
134
|
get unavailable() {
|
|
130
135
|
return (this.code === "oauth_unavailable" ||
|
|
@@ -645,9 +650,13 @@ export class CustdClient {
|
|
|
645
650
|
catch (error) {
|
|
646
651
|
throw transportRequestError(error);
|
|
647
652
|
}
|
|
653
|
+
const requestId = response.headers.get(REQUEST_ID_HEADER) ?? "";
|
|
654
|
+
if (options?.metadata)
|
|
655
|
+
options.metadata.requestId = requestId;
|
|
648
656
|
if (!response.ok) {
|
|
649
657
|
const text = await response.text().catch(() => "");
|
|
650
658
|
let errorCode = "";
|
|
659
|
+
let flatRequestId = "";
|
|
651
660
|
let detail = "";
|
|
652
661
|
let safeNextAction = "";
|
|
653
662
|
let workflowEnvelope = false;
|
|
@@ -655,6 +664,7 @@ export class CustdClient {
|
|
|
655
664
|
try {
|
|
656
665
|
const parsed = JSON.parse(text);
|
|
657
666
|
errorCode = parsed.code || "";
|
|
667
|
+
flatRequestId = parsed.requestId || "";
|
|
658
668
|
detail = parsed.detail || parsed.error || parsed.message || parsed.title || "";
|
|
659
669
|
safeNextAction = parsed.safeNextAction || parsed.safe_next_action || "";
|
|
660
670
|
workflowEnvelope = typeof parsed.error === "string" && (errorCode.length > 0 || safeNextAction.length > 0);
|
|
@@ -673,7 +683,7 @@ export class CustdClient {
|
|
|
673
683
|
message = `${message} [safeNextAction=${safeNextAction}]`;
|
|
674
684
|
}
|
|
675
685
|
if (workflowEnvelope) {
|
|
676
|
-
throw new AdminWorkflowError(response.status, detail, errorCode, safeNextAction);
|
|
686
|
+
throw new AdminWorkflowError(response.status, detail, errorCode, safeNextAction, requestId || flatRequestId);
|
|
677
687
|
}
|
|
678
688
|
throw await responseRequestError(response, errorCode || "request_failed", message, text);
|
|
679
689
|
}
|
|
@@ -1128,6 +1138,7 @@ class AdminNamespace {
|
|
|
1128
1138
|
this.supportAccess = new SupportAccessAdminClient(request);
|
|
1129
1139
|
this.system = new SystemAdminClient(request);
|
|
1130
1140
|
this.environmentPolicy = new EnvironmentPolicyAdminClient(request);
|
|
1141
|
+
this.machineAccess = new MachineAccessAdminClient(request);
|
|
1131
1142
|
this.rls = new RlsAdminClient(request);
|
|
1132
1143
|
this.oauthClientAdmissions = new OAuthClientAdmissionAdminClient(request);
|
|
1133
1144
|
this.sdkUsage = new SdkUsageAdminClient(request);
|
|
@@ -1945,6 +1956,7 @@ function requireNonNegativeInteger(value, operationKey) {
|
|
|
1945
1956
|
}
|
|
1946
1957
|
export class RetryableError extends Error {
|
|
1947
1958
|
}
|
|
1959
|
+
const REQUEST_ID_HEADER = "x-request-id";
|
|
1948
1960
|
function transportRequestError(error) {
|
|
1949
1961
|
if (error instanceof Error && error.name === "AbortError")
|
|
1950
1962
|
return error;
|
|
@@ -1969,7 +1981,10 @@ async function responseRequestError(response, fallbackCode, fallbackMessage, res
|
|
|
1969
1981
|
const nextAction = problem?.nextAction ??
|
|
1970
1982
|
(retryability === "bounded" ? { action: "retry", maxRetries: 1 } : { action: "none" });
|
|
1971
1983
|
const code = problem?.code || fallbackCode;
|
|
1972
|
-
const
|
|
1984
|
+
const requestId = response.headers.get(REQUEST_ID_HEADER) || problem?.traceId || "";
|
|
1985
|
+
const requestError = new CustdRequestError(response.status, code, retryability, nextAction, problem, {
|
|
1986
|
+
requestId,
|
|
1987
|
+
});
|
|
1973
1988
|
if (fallbackMessage)
|
|
1974
1989
|
requestError.message = fallbackMessage;
|
|
1975
1990
|
return requestError;
|
|
@@ -2205,6 +2220,7 @@ export * from "./admin-error-issues.js";
|
|
|
2205
2220
|
export * from "./admin-event-types.js";
|
|
2206
2221
|
export * from "./admin-impersonation.js";
|
|
2207
2222
|
export * from "./admin-ingest-claims.js";
|
|
2223
|
+
export * from "./admin-machine-access.js";
|
|
2208
2224
|
export * from "./admin-managed-audit.js";
|
|
2209
2225
|
export * from "./admin-measurement-projects.js";
|
|
2210
2226
|
export * from "./admin-notification-destinations.js";
|
|
@@ -66,6 +66,9 @@ export const API_RESPONSE_LISTS = {
|
|
|
66
66
|
"GET /api/v1/admin/event-types": ["eventTypes"],
|
|
67
67
|
"GET /api/v1/admin/ingest/claims/{tenantSlug}": ["claims"],
|
|
68
68
|
"GET /api/v1/admin/jobs": ["outboxes", "queueCounts", "recentFailures"],
|
|
69
|
+
"GET /api/v1/admin/machine-access": ["areas"],
|
|
70
|
+
"GET /api/v1/admin/machine-access/clients/{clientId}": ["areas"],
|
|
71
|
+
"GET /api/v1/admin/machine-access/clients/{clientId}/effective": ["areas", "scopes"],
|
|
69
72
|
"GET /api/v1/admin/measurement/predictions/definitions": ["items"],
|
|
70
73
|
"GET /api/v1/admin/measurement/predictions/definitions/{definitionUuid}/outcomes": ["outcomes"],
|
|
71
74
|
"GET /api/v1/admin/measurement/predictions/definitions/{definitionUuid}/runs": ["runs"],
|
|
@@ -1534,6 +1537,8 @@ export const API_RESPONSE_LISTS = {
|
|
|
1534
1537
|
],
|
|
1535
1538
|
"POST /api/v1/site-domains/{domainUuid}/status-page/preview": ["components", "updates"],
|
|
1536
1539
|
"POST /api/v1/site-domains/{domainUuid}/status-page/updates": ["updates"],
|
|
1540
|
+
"PUT /api/v1/admin/machine-access": ["areas"],
|
|
1541
|
+
"PUT /api/v1/admin/machine-access/clients/{clientId}": ["areas"],
|
|
1537
1542
|
"PUT /api/v1/admin/privacy/rules": ["rules"],
|
|
1538
1543
|
"PUT /api/v1/admin/reporting-packs/drafts/{draftId}": [
|
|
1539
1544
|
"definition.accounting.allocations",
|
package/dist/version.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* VERSION and scripts/bump-version.sh updates it, so a release cannot leave it
|
|
4
4
|
* behind.
|
|
5
5
|
*/
|
|
6
|
-
export declare const SDK_VERSION = "3.
|
|
6
|
+
export declare const SDK_VERSION = "3.72.0";
|
|
7
7
|
/** Product named in X-Custd-Sdk, so Custd can report which callers use which release. */
|
|
8
8
|
export declare const SDK_PRODUCT = "js";
|
|
9
9
|
/** Value sent in the X-Custd-Sdk header. */
|
|
10
|
-
export declare const SDK_IDENTITY = "js/3.
|
|
10
|
+
export declare const SDK_IDENTITY = "js/3.72.0";
|
package/dist/version.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* VERSION and scripts/bump-version.sh updates it, so a release cannot leave it
|
|
4
4
|
* behind.
|
|
5
5
|
*/
|
|
6
|
-
export const SDK_VERSION = "3.
|
|
6
|
+
export const SDK_VERSION = "3.72.0";
|
|
7
7
|
/** Product named in X-Custd-Sdk, so Custd can report which callers use which release. */
|
|
8
8
|
export const SDK_PRODUCT = "js";
|
|
9
9
|
/** Value sent in the X-Custd-Sdk header. */
|