@letpeoplework/lighthouse-client 0.3.1 → 0.5.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/dist/index.cjs +177 -3
- package/dist/index.d.cts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +174 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,9 @@ __export(index_exports, {
|
|
|
25
25
|
getClientPackageContract: () => getClientPackageContract,
|
|
26
26
|
getDefaultMetricsDateRange: () => getDefaultMetricsDateRange,
|
|
27
27
|
parseStandaloneDiscoveryContract: () => parseStandaloneDiscoveryContract,
|
|
28
|
+
pollCliAuthSession: () => pollCliAuthSession,
|
|
29
|
+
queryServerAuthMode: () => queryServerAuthMode,
|
|
30
|
+
startCliAuthSession: () => startCliAuthSession,
|
|
28
31
|
validateLighthouseConnectivity: () => validateLighthouseConnectivity
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -41,6 +44,25 @@ var SUPPORTED_DISCOVERY_CONTRACT_VERSION = 1;
|
|
|
41
44
|
var isObjectRecord = (value) => {
|
|
42
45
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
46
|
};
|
|
47
|
+
var getErrorMessageWithCause = (error, fallback) => {
|
|
48
|
+
if (!(error instanceof Error)) {
|
|
49
|
+
return fallback;
|
|
50
|
+
}
|
|
51
|
+
const cause = error.cause;
|
|
52
|
+
if (cause instanceof Error && cause.message.trim().length > 0) {
|
|
53
|
+
if (cause.message === error.message) {
|
|
54
|
+
return error.message;
|
|
55
|
+
}
|
|
56
|
+
return `${error.message} (${cause.message})`;
|
|
57
|
+
}
|
|
58
|
+
if (typeof cause === "string" && cause.trim().length > 0) {
|
|
59
|
+
if (cause === error.message) {
|
|
60
|
+
return error.message;
|
|
61
|
+
}
|
|
62
|
+
return `${error.message} (${cause})`;
|
|
63
|
+
}
|
|
64
|
+
return error.message;
|
|
65
|
+
};
|
|
44
66
|
var getNormalizedLighthouseUrl = (value) => {
|
|
45
67
|
const trimmed = value.trim();
|
|
46
68
|
if (trimmed.length === 0) {
|
|
@@ -139,7 +161,7 @@ var getResolvedEndpoint = (mode, lighthouseUrl) => {
|
|
|
139
161
|
mode,
|
|
140
162
|
lighthouseUrl,
|
|
141
163
|
apiBaseUrl,
|
|
142
|
-
healthCheckUrl: `${apiBaseUrl}/v1/version`
|
|
164
|
+
healthCheckUrl: `${apiBaseUrl}/v1/version/current`
|
|
143
165
|
};
|
|
144
166
|
};
|
|
145
167
|
var getMisconfiguredResult = (reason) => ({
|
|
@@ -224,7 +246,10 @@ var validateLighthouseConnectivity = async (configuration, dependencies, request
|
|
|
224
246
|
endpoint
|
|
225
247
|
};
|
|
226
248
|
} catch (error) {
|
|
227
|
-
const message =
|
|
249
|
+
const message = getErrorMessageWithCause(
|
|
250
|
+
error,
|
|
251
|
+
"Connectivity request failed."
|
|
252
|
+
);
|
|
228
253
|
return {
|
|
229
254
|
category: "unreachable",
|
|
230
255
|
reason: message,
|
|
@@ -313,6 +338,152 @@ var createLighthouseAuthContext = (store) => ({
|
|
|
313
338
|
return getStatusFromAuth({ kind: "none" }, "none");
|
|
314
339
|
}
|
|
315
340
|
});
|
|
341
|
+
var mapAuthMode = (serverMode) => {
|
|
342
|
+
switch (serverMode.toLowerCase()) {
|
|
343
|
+
case "enabled":
|
|
344
|
+
return "required";
|
|
345
|
+
case "disabled":
|
|
346
|
+
return "disabled";
|
|
347
|
+
case "blocked":
|
|
348
|
+
return "blocked";
|
|
349
|
+
default:
|
|
350
|
+
return "misconfigured";
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var getAuthStartFailureCategory = (statusCode) => {
|
|
354
|
+
if (statusCode === 401 || statusCode === 403) {
|
|
355
|
+
return "unauthorized";
|
|
356
|
+
}
|
|
357
|
+
if (statusCode === 404) {
|
|
358
|
+
return "misconfigured";
|
|
359
|
+
}
|
|
360
|
+
if (statusCode >= 500 && statusCode <= 599) {
|
|
361
|
+
return "dependency-failure";
|
|
362
|
+
}
|
|
363
|
+
return "unexpected";
|
|
364
|
+
};
|
|
365
|
+
var getErrorReasonFromResponse = async (response, fallback) => {
|
|
366
|
+
try {
|
|
367
|
+
const body = (await response.text()).trim();
|
|
368
|
+
if (body.length > 0) {
|
|
369
|
+
return body;
|
|
370
|
+
}
|
|
371
|
+
} catch {
|
|
372
|
+
}
|
|
373
|
+
return fallback;
|
|
374
|
+
};
|
|
375
|
+
var queryServerAuthMode = async (endpointUrl, dependencies) => {
|
|
376
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
377
|
+
if (normalizedEndpointUrl === null) {
|
|
378
|
+
return {
|
|
379
|
+
mode: "misconfigured",
|
|
380
|
+
misconfigurationMessage: "Server URL is invalid."
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
384
|
+
try {
|
|
385
|
+
const response = await dependencies.fetch(`${apiBase}/v1/auth/mode`);
|
|
386
|
+
if (!response.ok) {
|
|
387
|
+
return {
|
|
388
|
+
mode: "misconfigured",
|
|
389
|
+
misconfigurationMessage: await getErrorReasonFromResponse(
|
|
390
|
+
response,
|
|
391
|
+
`HTTP ${response.status}`
|
|
392
|
+
)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const json = await response.json();
|
|
396
|
+
return {
|
|
397
|
+
mode: mapAuthMode(json.mode),
|
|
398
|
+
misconfigurationMessage: json.misconfigurationMessage
|
|
399
|
+
};
|
|
400
|
+
} catch (error) {
|
|
401
|
+
return {
|
|
402
|
+
mode: "misconfigured",
|
|
403
|
+
misconfigurationMessage: getErrorMessageWithCause(
|
|
404
|
+
error,
|
|
405
|
+
"Could not reach auth mode endpoint."
|
|
406
|
+
)
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
var startCliAuthSession = async (endpointUrl, dependencies) => {
|
|
411
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
412
|
+
if (normalizedEndpointUrl === null) {
|
|
413
|
+
return {
|
|
414
|
+
status: "error",
|
|
415
|
+
category: "misconfigured",
|
|
416
|
+
reason: "Server URL is invalid."
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
420
|
+
try {
|
|
421
|
+
const response = await dependencies.fetch(
|
|
422
|
+
`${apiBase}/v1/auth/cli/session`,
|
|
423
|
+
{
|
|
424
|
+
method: "POST"
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
if (!response.ok) {
|
|
428
|
+
return {
|
|
429
|
+
status: "error",
|
|
430
|
+
category: getAuthStartFailureCategory(response.status),
|
|
431
|
+
reason: await getErrorReasonFromResponse(
|
|
432
|
+
response,
|
|
433
|
+
`HTTP ${response.status}`
|
|
434
|
+
),
|
|
435
|
+
statusCode: response.status
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
const json = await response.json();
|
|
439
|
+
return {
|
|
440
|
+
status: "started",
|
|
441
|
+
sessionId: json.sessionId,
|
|
442
|
+
verificationUrl: json.verificationUrl,
|
|
443
|
+
expiresAt: json.expiresAt
|
|
444
|
+
};
|
|
445
|
+
} catch (error) {
|
|
446
|
+
return {
|
|
447
|
+
status: "error",
|
|
448
|
+
category: "unreachable",
|
|
449
|
+
reason: getErrorMessageWithCause(
|
|
450
|
+
error,
|
|
451
|
+
"Could not reach auth session endpoint."
|
|
452
|
+
)
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var pollCliAuthSession = async (endpointUrl, sessionId, dependencies) => {
|
|
457
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
458
|
+
if (normalizedEndpointUrl === null) {
|
|
459
|
+
return { status: "expired" };
|
|
460
|
+
}
|
|
461
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
462
|
+
try {
|
|
463
|
+
const response = await dependencies.fetch(
|
|
464
|
+
`${apiBase}/v1/auth/cli/poll/${encodeURIComponent(sessionId)}`
|
|
465
|
+
);
|
|
466
|
+
if (response.status === 404) {
|
|
467
|
+
return { status: "not-found" };
|
|
468
|
+
}
|
|
469
|
+
if (!response.ok) {
|
|
470
|
+
return { status: "expired" };
|
|
471
|
+
}
|
|
472
|
+
const json = await response.json();
|
|
473
|
+
if (json.status === "approved" && json.token && json.userName) {
|
|
474
|
+
return { status: "approved", token: json.token, userName: json.userName };
|
|
475
|
+
}
|
|
476
|
+
if (json.status === "expired") {
|
|
477
|
+
return { status: "expired" };
|
|
478
|
+
}
|
|
479
|
+
if (json.status === "denied") {
|
|
480
|
+
return { status: "denied" };
|
|
481
|
+
}
|
|
482
|
+
return { status: "pending" };
|
|
483
|
+
} catch {
|
|
484
|
+
return { status: "expired" };
|
|
485
|
+
}
|
|
486
|
+
};
|
|
316
487
|
var getDefaultMetricsDateRange = () => {
|
|
317
488
|
const end = /* @__PURE__ */ new Date();
|
|
318
489
|
const start = /* @__PURE__ */ new Date();
|
|
@@ -499,7 +670,7 @@ var createLighthouseClient = (configuration, dependencies = {}) => ({
|
|
|
499
670
|
getRequestInit(configuration.auth)
|
|
500
671
|
);
|
|
501
672
|
},
|
|
502
|
-
getVersion: async () => requestText(configuration, dependencies, "/v1/version"),
|
|
673
|
+
getVersion: async () => requestText(configuration, dependencies, "/v1/version/current"),
|
|
503
674
|
listWorkTrackingConnections: async () => requestJson(
|
|
504
675
|
configuration,
|
|
505
676
|
dependencies,
|
|
@@ -702,5 +873,8 @@ var createLighthouseClient = (configuration, dependencies = {}) => ({
|
|
|
702
873
|
getClientPackageContract,
|
|
703
874
|
getDefaultMetricsDateRange,
|
|
704
875
|
parseStandaloneDiscoveryContract,
|
|
876
|
+
pollCliAuthSession,
|
|
877
|
+
queryServerAuthMode,
|
|
878
|
+
startCliAuthSession,
|
|
705
879
|
validateLighthouseConnectivity
|
|
706
880
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -86,6 +86,55 @@ type LighthouseAuthContext = {
|
|
|
86
86
|
readonly getStatus: (overrides?: LighthouseAuthOverrides) => Promise<LighthouseAuthStatus>;
|
|
87
87
|
};
|
|
88
88
|
declare const createLighthouseAuthContext: (store: LighthouseAuthStore) => LighthouseAuthContext;
|
|
89
|
+
type CliServerAuthMode = "disabled" | "required" | "blocked" | "misconfigured";
|
|
90
|
+
type ServerAuthModeResult = {
|
|
91
|
+
readonly mode: CliServerAuthMode;
|
|
92
|
+
readonly misconfigurationMessage?: string;
|
|
93
|
+
};
|
|
94
|
+
type CliAuthSessionStartResult = {
|
|
95
|
+
readonly status: "started";
|
|
96
|
+
readonly sessionId: string;
|
|
97
|
+
readonly verificationUrl: string;
|
|
98
|
+
readonly expiresAt: string;
|
|
99
|
+
};
|
|
100
|
+
type CliAuthSessionStartError = {
|
|
101
|
+
readonly status: "error";
|
|
102
|
+
readonly category: Exclude<ConnectivityCategory, "success">;
|
|
103
|
+
readonly reason: string;
|
|
104
|
+
readonly statusCode?: number;
|
|
105
|
+
};
|
|
106
|
+
type CliAuthSessionStartOutcome = CliAuthSessionStartResult | CliAuthSessionStartError;
|
|
107
|
+
type CliAuthSessionPollResult = {
|
|
108
|
+
readonly status: "pending";
|
|
109
|
+
} | {
|
|
110
|
+
readonly status: "approved";
|
|
111
|
+
readonly token: string;
|
|
112
|
+
readonly userName: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly status: "expired";
|
|
115
|
+
} | {
|
|
116
|
+
readonly status: "denied";
|
|
117
|
+
} | {
|
|
118
|
+
readonly status: "not-found";
|
|
119
|
+
};
|
|
120
|
+
type CliServerConnection = {
|
|
121
|
+
readonly mode: "server";
|
|
122
|
+
readonly endpointUrl: string;
|
|
123
|
+
readonly authMode: "disabled" | "required";
|
|
124
|
+
readonly insecure?: boolean;
|
|
125
|
+
readonly auth?: StoredLighthouseAuth;
|
|
126
|
+
};
|
|
127
|
+
type CliStandaloneConnection = {
|
|
128
|
+
readonly mode: "standalone";
|
|
129
|
+
readonly authMode: "disabled";
|
|
130
|
+
};
|
|
131
|
+
type CliConnection = CliServerConnection | CliStandaloneConnection;
|
|
132
|
+
type CliAuthDependencies = {
|
|
133
|
+
readonly fetch: typeof globalThis.fetch;
|
|
134
|
+
};
|
|
135
|
+
declare const queryServerAuthMode: (endpointUrl: string, dependencies: CliAuthDependencies) => Promise<ServerAuthModeResult>;
|
|
136
|
+
declare const startCliAuthSession: (endpointUrl: string, dependencies: CliAuthDependencies) => Promise<CliAuthSessionStartOutcome>;
|
|
137
|
+
declare const pollCliAuthSession: (endpointUrl: string, sessionId: string, dependencies: CliAuthDependencies) => Promise<CliAuthSessionPollResult>;
|
|
89
138
|
type LighthouseClientConfiguration = {
|
|
90
139
|
readonly connection: LighthouseConnectionConfiguration;
|
|
91
140
|
readonly auth?: LighthouseClientAuth;
|
|
@@ -156,4 +205,4 @@ type LighthouseClientDependencies = {
|
|
|
156
205
|
};
|
|
157
206
|
declare const createLighthouseClient: (configuration: LighthouseClientConfiguration, dependencies?: LighthouseClientDependencies) => LighthouseClient;
|
|
158
207
|
|
|
159
|
-
export { type BacktestInput, type ClientCapability, type ClientPackageContract, type ConnectivityCategory, type ConnectivityDependencies, type ConnectivityFetchResponse, type ConnectivityValidationResult, type LighthouseApiError, type LighthouseApiResult, type LighthouseAuthContext, type LighthouseAuthOverrides, type LighthouseAuthStatus, type LighthouseAuthStore, type LighthouseClient, type LighthouseClientAuth, type LighthouseClientConfiguration, type LighthouseClientDependencies, type LighthouseConnectionConfiguration, type LighthouseWritePayload, type ManualForecastInput, type MetricsDateRange, type ResolvedLighthouseEndpoint, type StandaloneDiscoveryContract, type StandaloneDiscoveryContractParseResult, type StoredLighthouseAuth, createLighthouseAuthContext, createLighthouseClient, getClientPackageContract, getDefaultMetricsDateRange, parseStandaloneDiscoveryContract, validateLighthouseConnectivity };
|
|
208
|
+
export { type BacktestInput, type CliAuthSessionPollResult, type CliAuthSessionStartError, type CliAuthSessionStartOutcome, type CliAuthSessionStartResult, type CliConnection, type CliServerAuthMode, type CliServerConnection, type CliStandaloneConnection, type ClientCapability, type ClientPackageContract, type ConnectivityCategory, type ConnectivityDependencies, type ConnectivityFetchResponse, type ConnectivityValidationResult, type LighthouseApiError, type LighthouseApiResult, type LighthouseAuthContext, type LighthouseAuthOverrides, type LighthouseAuthStatus, type LighthouseAuthStore, type LighthouseClient, type LighthouseClientAuth, type LighthouseClientConfiguration, type LighthouseClientDependencies, type LighthouseConnectionConfiguration, type LighthouseWritePayload, type ManualForecastInput, type MetricsDateRange, type ResolvedLighthouseEndpoint, type ServerAuthModeResult, type StandaloneDiscoveryContract, type StandaloneDiscoveryContractParseResult, type StoredLighthouseAuth, createLighthouseAuthContext, createLighthouseClient, getClientPackageContract, getDefaultMetricsDateRange, parseStandaloneDiscoveryContract, pollCliAuthSession, queryServerAuthMode, startCliAuthSession, validateLighthouseConnectivity };
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,55 @@ type LighthouseAuthContext = {
|
|
|
86
86
|
readonly getStatus: (overrides?: LighthouseAuthOverrides) => Promise<LighthouseAuthStatus>;
|
|
87
87
|
};
|
|
88
88
|
declare const createLighthouseAuthContext: (store: LighthouseAuthStore) => LighthouseAuthContext;
|
|
89
|
+
type CliServerAuthMode = "disabled" | "required" | "blocked" | "misconfigured";
|
|
90
|
+
type ServerAuthModeResult = {
|
|
91
|
+
readonly mode: CliServerAuthMode;
|
|
92
|
+
readonly misconfigurationMessage?: string;
|
|
93
|
+
};
|
|
94
|
+
type CliAuthSessionStartResult = {
|
|
95
|
+
readonly status: "started";
|
|
96
|
+
readonly sessionId: string;
|
|
97
|
+
readonly verificationUrl: string;
|
|
98
|
+
readonly expiresAt: string;
|
|
99
|
+
};
|
|
100
|
+
type CliAuthSessionStartError = {
|
|
101
|
+
readonly status: "error";
|
|
102
|
+
readonly category: Exclude<ConnectivityCategory, "success">;
|
|
103
|
+
readonly reason: string;
|
|
104
|
+
readonly statusCode?: number;
|
|
105
|
+
};
|
|
106
|
+
type CliAuthSessionStartOutcome = CliAuthSessionStartResult | CliAuthSessionStartError;
|
|
107
|
+
type CliAuthSessionPollResult = {
|
|
108
|
+
readonly status: "pending";
|
|
109
|
+
} | {
|
|
110
|
+
readonly status: "approved";
|
|
111
|
+
readonly token: string;
|
|
112
|
+
readonly userName: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly status: "expired";
|
|
115
|
+
} | {
|
|
116
|
+
readonly status: "denied";
|
|
117
|
+
} | {
|
|
118
|
+
readonly status: "not-found";
|
|
119
|
+
};
|
|
120
|
+
type CliServerConnection = {
|
|
121
|
+
readonly mode: "server";
|
|
122
|
+
readonly endpointUrl: string;
|
|
123
|
+
readonly authMode: "disabled" | "required";
|
|
124
|
+
readonly insecure?: boolean;
|
|
125
|
+
readonly auth?: StoredLighthouseAuth;
|
|
126
|
+
};
|
|
127
|
+
type CliStandaloneConnection = {
|
|
128
|
+
readonly mode: "standalone";
|
|
129
|
+
readonly authMode: "disabled";
|
|
130
|
+
};
|
|
131
|
+
type CliConnection = CliServerConnection | CliStandaloneConnection;
|
|
132
|
+
type CliAuthDependencies = {
|
|
133
|
+
readonly fetch: typeof globalThis.fetch;
|
|
134
|
+
};
|
|
135
|
+
declare const queryServerAuthMode: (endpointUrl: string, dependencies: CliAuthDependencies) => Promise<ServerAuthModeResult>;
|
|
136
|
+
declare const startCliAuthSession: (endpointUrl: string, dependencies: CliAuthDependencies) => Promise<CliAuthSessionStartOutcome>;
|
|
137
|
+
declare const pollCliAuthSession: (endpointUrl: string, sessionId: string, dependencies: CliAuthDependencies) => Promise<CliAuthSessionPollResult>;
|
|
89
138
|
type LighthouseClientConfiguration = {
|
|
90
139
|
readonly connection: LighthouseConnectionConfiguration;
|
|
91
140
|
readonly auth?: LighthouseClientAuth;
|
|
@@ -156,4 +205,4 @@ type LighthouseClientDependencies = {
|
|
|
156
205
|
};
|
|
157
206
|
declare const createLighthouseClient: (configuration: LighthouseClientConfiguration, dependencies?: LighthouseClientDependencies) => LighthouseClient;
|
|
158
207
|
|
|
159
|
-
export { type BacktestInput, type ClientCapability, type ClientPackageContract, type ConnectivityCategory, type ConnectivityDependencies, type ConnectivityFetchResponse, type ConnectivityValidationResult, type LighthouseApiError, type LighthouseApiResult, type LighthouseAuthContext, type LighthouseAuthOverrides, type LighthouseAuthStatus, type LighthouseAuthStore, type LighthouseClient, type LighthouseClientAuth, type LighthouseClientConfiguration, type LighthouseClientDependencies, type LighthouseConnectionConfiguration, type LighthouseWritePayload, type ManualForecastInput, type MetricsDateRange, type ResolvedLighthouseEndpoint, type StandaloneDiscoveryContract, type StandaloneDiscoveryContractParseResult, type StoredLighthouseAuth, createLighthouseAuthContext, createLighthouseClient, getClientPackageContract, getDefaultMetricsDateRange, parseStandaloneDiscoveryContract, validateLighthouseConnectivity };
|
|
208
|
+
export { type BacktestInput, type CliAuthSessionPollResult, type CliAuthSessionStartError, type CliAuthSessionStartOutcome, type CliAuthSessionStartResult, type CliConnection, type CliServerAuthMode, type CliServerConnection, type CliStandaloneConnection, type ClientCapability, type ClientPackageContract, type ConnectivityCategory, type ConnectivityDependencies, type ConnectivityFetchResponse, type ConnectivityValidationResult, type LighthouseApiError, type LighthouseApiResult, type LighthouseAuthContext, type LighthouseAuthOverrides, type LighthouseAuthStatus, type LighthouseAuthStore, type LighthouseClient, type LighthouseClientAuth, type LighthouseClientConfiguration, type LighthouseClientDependencies, type LighthouseConnectionConfiguration, type LighthouseWritePayload, type ManualForecastInput, type MetricsDateRange, type ResolvedLighthouseEndpoint, type ServerAuthModeResult, type StandaloneDiscoveryContract, type StandaloneDiscoveryContractParseResult, type StoredLighthouseAuth, createLighthouseAuthContext, createLighthouseClient, getClientPackageContract, getDefaultMetricsDateRange, parseStandaloneDiscoveryContract, pollCliAuthSession, queryServerAuthMode, startCliAuthSession, validateLighthouseConnectivity };
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,25 @@ var SUPPORTED_DISCOVERY_CONTRACT_VERSION = 1;
|
|
|
12
12
|
var isObjectRecord = (value) => {
|
|
13
13
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
14
|
};
|
|
15
|
+
var getErrorMessageWithCause = (error, fallback) => {
|
|
16
|
+
if (!(error instanceof Error)) {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
const cause = error.cause;
|
|
20
|
+
if (cause instanceof Error && cause.message.trim().length > 0) {
|
|
21
|
+
if (cause.message === error.message) {
|
|
22
|
+
return error.message;
|
|
23
|
+
}
|
|
24
|
+
return `${error.message} (${cause.message})`;
|
|
25
|
+
}
|
|
26
|
+
if (typeof cause === "string" && cause.trim().length > 0) {
|
|
27
|
+
if (cause === error.message) {
|
|
28
|
+
return error.message;
|
|
29
|
+
}
|
|
30
|
+
return `${error.message} (${cause})`;
|
|
31
|
+
}
|
|
32
|
+
return error.message;
|
|
33
|
+
};
|
|
15
34
|
var getNormalizedLighthouseUrl = (value) => {
|
|
16
35
|
const trimmed = value.trim();
|
|
17
36
|
if (trimmed.length === 0) {
|
|
@@ -110,7 +129,7 @@ var getResolvedEndpoint = (mode, lighthouseUrl) => {
|
|
|
110
129
|
mode,
|
|
111
130
|
lighthouseUrl,
|
|
112
131
|
apiBaseUrl,
|
|
113
|
-
healthCheckUrl: `${apiBaseUrl}/v1/version`
|
|
132
|
+
healthCheckUrl: `${apiBaseUrl}/v1/version/current`
|
|
114
133
|
};
|
|
115
134
|
};
|
|
116
135
|
var getMisconfiguredResult = (reason) => ({
|
|
@@ -195,7 +214,10 @@ var validateLighthouseConnectivity = async (configuration, dependencies, request
|
|
|
195
214
|
endpoint
|
|
196
215
|
};
|
|
197
216
|
} catch (error) {
|
|
198
|
-
const message =
|
|
217
|
+
const message = getErrorMessageWithCause(
|
|
218
|
+
error,
|
|
219
|
+
"Connectivity request failed."
|
|
220
|
+
);
|
|
199
221
|
return {
|
|
200
222
|
category: "unreachable",
|
|
201
223
|
reason: message,
|
|
@@ -284,6 +306,152 @@ var createLighthouseAuthContext = (store) => ({
|
|
|
284
306
|
return getStatusFromAuth({ kind: "none" }, "none");
|
|
285
307
|
}
|
|
286
308
|
});
|
|
309
|
+
var mapAuthMode = (serverMode) => {
|
|
310
|
+
switch (serverMode.toLowerCase()) {
|
|
311
|
+
case "enabled":
|
|
312
|
+
return "required";
|
|
313
|
+
case "disabled":
|
|
314
|
+
return "disabled";
|
|
315
|
+
case "blocked":
|
|
316
|
+
return "blocked";
|
|
317
|
+
default:
|
|
318
|
+
return "misconfigured";
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var getAuthStartFailureCategory = (statusCode) => {
|
|
322
|
+
if (statusCode === 401 || statusCode === 403) {
|
|
323
|
+
return "unauthorized";
|
|
324
|
+
}
|
|
325
|
+
if (statusCode === 404) {
|
|
326
|
+
return "misconfigured";
|
|
327
|
+
}
|
|
328
|
+
if (statusCode >= 500 && statusCode <= 599) {
|
|
329
|
+
return "dependency-failure";
|
|
330
|
+
}
|
|
331
|
+
return "unexpected";
|
|
332
|
+
};
|
|
333
|
+
var getErrorReasonFromResponse = async (response, fallback) => {
|
|
334
|
+
try {
|
|
335
|
+
const body = (await response.text()).trim();
|
|
336
|
+
if (body.length > 0) {
|
|
337
|
+
return body;
|
|
338
|
+
}
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
return fallback;
|
|
342
|
+
};
|
|
343
|
+
var queryServerAuthMode = async (endpointUrl, dependencies) => {
|
|
344
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
345
|
+
if (normalizedEndpointUrl === null) {
|
|
346
|
+
return {
|
|
347
|
+
mode: "misconfigured",
|
|
348
|
+
misconfigurationMessage: "Server URL is invalid."
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
352
|
+
try {
|
|
353
|
+
const response = await dependencies.fetch(`${apiBase}/v1/auth/mode`);
|
|
354
|
+
if (!response.ok) {
|
|
355
|
+
return {
|
|
356
|
+
mode: "misconfigured",
|
|
357
|
+
misconfigurationMessage: await getErrorReasonFromResponse(
|
|
358
|
+
response,
|
|
359
|
+
`HTTP ${response.status}`
|
|
360
|
+
)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
const json = await response.json();
|
|
364
|
+
return {
|
|
365
|
+
mode: mapAuthMode(json.mode),
|
|
366
|
+
misconfigurationMessage: json.misconfigurationMessage
|
|
367
|
+
};
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return {
|
|
370
|
+
mode: "misconfigured",
|
|
371
|
+
misconfigurationMessage: getErrorMessageWithCause(
|
|
372
|
+
error,
|
|
373
|
+
"Could not reach auth mode endpoint."
|
|
374
|
+
)
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
var startCliAuthSession = async (endpointUrl, dependencies) => {
|
|
379
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
380
|
+
if (normalizedEndpointUrl === null) {
|
|
381
|
+
return {
|
|
382
|
+
status: "error",
|
|
383
|
+
category: "misconfigured",
|
|
384
|
+
reason: "Server URL is invalid."
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
388
|
+
try {
|
|
389
|
+
const response = await dependencies.fetch(
|
|
390
|
+
`${apiBase}/v1/auth/cli/session`,
|
|
391
|
+
{
|
|
392
|
+
method: "POST"
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
if (!response.ok) {
|
|
396
|
+
return {
|
|
397
|
+
status: "error",
|
|
398
|
+
category: getAuthStartFailureCategory(response.status),
|
|
399
|
+
reason: await getErrorReasonFromResponse(
|
|
400
|
+
response,
|
|
401
|
+
`HTTP ${response.status}`
|
|
402
|
+
),
|
|
403
|
+
statusCode: response.status
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
const json = await response.json();
|
|
407
|
+
return {
|
|
408
|
+
status: "started",
|
|
409
|
+
sessionId: json.sessionId,
|
|
410
|
+
verificationUrl: json.verificationUrl,
|
|
411
|
+
expiresAt: json.expiresAt
|
|
412
|
+
};
|
|
413
|
+
} catch (error) {
|
|
414
|
+
return {
|
|
415
|
+
status: "error",
|
|
416
|
+
category: "unreachable",
|
|
417
|
+
reason: getErrorMessageWithCause(
|
|
418
|
+
error,
|
|
419
|
+
"Could not reach auth session endpoint."
|
|
420
|
+
)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var pollCliAuthSession = async (endpointUrl, sessionId, dependencies) => {
|
|
425
|
+
const normalizedEndpointUrl = getNormalizedLighthouseUrl(endpointUrl);
|
|
426
|
+
if (normalizedEndpointUrl === null) {
|
|
427
|
+
return { status: "expired" };
|
|
428
|
+
}
|
|
429
|
+
const apiBase = getApiBaseUrl(normalizedEndpointUrl);
|
|
430
|
+
try {
|
|
431
|
+
const response = await dependencies.fetch(
|
|
432
|
+
`${apiBase}/v1/auth/cli/poll/${encodeURIComponent(sessionId)}`
|
|
433
|
+
);
|
|
434
|
+
if (response.status === 404) {
|
|
435
|
+
return { status: "not-found" };
|
|
436
|
+
}
|
|
437
|
+
if (!response.ok) {
|
|
438
|
+
return { status: "expired" };
|
|
439
|
+
}
|
|
440
|
+
const json = await response.json();
|
|
441
|
+
if (json.status === "approved" && json.token && json.userName) {
|
|
442
|
+
return { status: "approved", token: json.token, userName: json.userName };
|
|
443
|
+
}
|
|
444
|
+
if (json.status === "expired") {
|
|
445
|
+
return { status: "expired" };
|
|
446
|
+
}
|
|
447
|
+
if (json.status === "denied") {
|
|
448
|
+
return { status: "denied" };
|
|
449
|
+
}
|
|
450
|
+
return { status: "pending" };
|
|
451
|
+
} catch {
|
|
452
|
+
return { status: "expired" };
|
|
453
|
+
}
|
|
454
|
+
};
|
|
287
455
|
var getDefaultMetricsDateRange = () => {
|
|
288
456
|
const end = /* @__PURE__ */ new Date();
|
|
289
457
|
const start = /* @__PURE__ */ new Date();
|
|
@@ -470,7 +638,7 @@ var createLighthouseClient = (configuration, dependencies = {}) => ({
|
|
|
470
638
|
getRequestInit(configuration.auth)
|
|
471
639
|
);
|
|
472
640
|
},
|
|
473
|
-
getVersion: async () => requestText(configuration, dependencies, "/v1/version"),
|
|
641
|
+
getVersion: async () => requestText(configuration, dependencies, "/v1/version/current"),
|
|
474
642
|
listWorkTrackingConnections: async () => requestJson(
|
|
475
643
|
configuration,
|
|
476
644
|
dependencies,
|
|
@@ -672,5 +840,8 @@ export {
|
|
|
672
840
|
getClientPackageContract,
|
|
673
841
|
getDefaultMetricsDateRange,
|
|
674
842
|
parseStandaloneDiscoveryContract,
|
|
843
|
+
pollCliAuthSession,
|
|
844
|
+
queryServerAuthMode,
|
|
845
|
+
startCliAuthSession,
|
|
675
846
|
validateLighthouseConnectivity
|
|
676
847
|
};
|
package/package.json
CHANGED