@detergent-software/atk 8.0.2 → 8.0.3-dev.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.
- package/CHANGELOG.md +10 -0
- package/build/commands/freeze.js +1 -1
- package/build/commands/freeze.js.map +1 -1
- package/build/commands/info.js +1 -1
- package/build/commands/info.js.map +1 -1
- package/build/commands/list.js +1 -1
- package/build/commands/list.js.map +1 -1
- package/build/commands/login.d.ts +1 -1
- package/build/commands/login.d.ts.map +1 -1
- package/build/commands/login.js +2 -4
- package/build/commands/login.js.map +1 -1
- package/build/commands/outdated.js +1 -1
- package/build/commands/outdated.js.map +1 -1
- package/build/commands/pin.js +1 -1
- package/build/commands/pin.js.map +1 -1
- package/build/commands/promote.js +1 -1
- package/build/commands/promote.js.map +1 -1
- package/build/commands/register.js +1 -1
- package/build/commands/register.js.map +1 -1
- package/build/commands/schema.d.ts +1 -1
- package/build/commands/schema.js +3 -3
- package/build/commands/schema.js.map +1 -1
- package/build/commands/thaw.js +1 -1
- package/build/commands/thaw.js.map +1 -1
- package/build/commands/unpin.js +1 -1
- package/build/commands/unpin.js.map +1 -1
- package/build/commands/unpublish.js +1 -1
- package/build/commands/unpublish.js.map +1 -1
- package/build/commands/whoami.d.ts.map +1 -1
- package/build/commands/whoami.js +2 -4
- package/build/commands/whoami.js.map +1 -1
- package/build/commands/why.js +1 -1
- package/build/commands/why.js.map +1 -1
- package/build/components/AssetDetail.d.ts +1 -1
- package/build/components/AssetDetail.d.ts.map +1 -1
- package/build/components/BrowseExpandedBundle.d.ts +2 -2
- package/build/components/BrowseExpandedBundle.d.ts.map +1 -1
- package/build/components/BrowseExpandedRow.d.ts +1 -1
- package/build/components/BrowseExpandedRow.d.ts.map +1 -1
- package/build/components/BrowseList.d.ts +1 -1
- package/build/components/BrowseList.d.ts.map +1 -1
- package/build/components/BundleDetail.d.ts +1 -1
- package/build/components/BundleDetail.d.ts.map +1 -1
- package/build/components/RegistryChangeSummary.d.ts +2 -2
- package/build/components/RegistryChangeSummary.d.ts.map +1 -1
- package/build/hooks/useBrowseState.d.ts +2 -2
- package/build/hooks/useBrowseState.d.ts.map +1 -1
- package/build/hooks/useListState.d.ts +2 -2
- package/build/hooks/useListState.d.ts.map +1 -1
- package/build/hooks/usePublishState.d.ts.map +1 -1
- package/build/hooks/usePublishState.js +3 -1
- package/build/hooks/usePublishState.js.map +1 -1
- package/build/hooks/useRegistryChangeState.d.ts +4 -4
- package/build/hooks/useRegistryChangeState.d.ts.map +1 -1
- package/build/lib/adapter.d.ts +1 -1
- package/build/lib/adapter.d.ts.map +1 -1
- package/build/lib/api-client.d.ts +38 -47
- package/build/lib/api-client.d.ts.map +1 -1
- package/build/lib/api-client.js +127 -173
- package/build/lib/api-client.js.map +1 -1
- package/build/lib/atk-api/client.d.ts +148 -0
- package/build/lib/atk-api/client.d.ts.map +1 -0
- package/build/lib/atk-api/client.js +336 -0
- package/build/lib/atk-api/client.js.map +1 -0
- package/build/lib/atk-api/domain.d.ts +162 -0
- package/build/lib/atk-api/domain.d.ts.map +1 -0
- package/build/lib/atk-api/domain.js +54 -0
- package/build/lib/atk-api/domain.js.map +1 -0
- package/build/lib/atk-api/errors.d.ts +142 -0
- package/build/lib/atk-api/errors.d.ts.map +1 -0
- package/build/lib/atk-api/errors.js +148 -0
- package/build/lib/atk-api/errors.js.map +1 -0
- package/build/lib/atk-api/generated/client/client.gen.d.ts +3 -0
- package/build/lib/atk-api/generated/client/client.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/client/client.gen.js +4 -3
- package/build/lib/atk-api/generated/client/client.gen.js.map +1 -0
- package/build/lib/atk-api/generated/client/index.d.ts +11 -0
- package/build/lib/atk-api/generated/client/index.d.ts.map +1 -0
- package/build/lib/atk-api/generated/client/index.js +8 -0
- package/build/lib/atk-api/generated/client/index.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/client/types.gen.d.ts +4 -4
- package/build/lib/atk-api/generated/client/types.gen.d.ts.map +1 -0
- package/build/lib/atk-api/generated/client/types.gen.js +4 -0
- package/build/lib/atk-api/generated/client/types.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/client/utils.gen.d.ts +2 -2
- package/build/lib/atk-api/generated/client/utils.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/client/utils.gen.js +5 -4
- package/build/lib/atk-api/generated/client/utils.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/client.gen.d.ts +2 -2
- package/build/lib/atk-api/generated/client.gen.d.ts.map +1 -0
- package/build/lib/atk-api/generated/client.gen.js +5 -0
- package/build/lib/atk-api/generated/client.gen.js.map +1 -0
- package/build/lib/atk-api/generated/core/auth.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/auth.gen.js +1 -0
- package/build/lib/atk-api/generated/core/auth.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/bodySerializer.gen.d.ts +1 -1
- package/build/lib/atk-api/generated/core/bodySerializer.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/bodySerializer.gen.js +1 -0
- package/build/lib/atk-api/generated/core/bodySerializer.gen.js.map +1 -0
- package/build/lib/atk-api/generated/core/params.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/params.gen.js +1 -0
- package/build/lib/atk-api/generated/core/params.gen.js.map +1 -0
- package/build/lib/atk-api/generated/core/pathSerializer.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/pathSerializer.gen.js +1 -0
- package/build/lib/atk-api/generated/core/pathSerializer.gen.js.map +1 -0
- package/build/lib/atk-api/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/queryKeySerializer.gen.js +1 -0
- package/build/lib/atk-api/generated/core/queryKeySerializer.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/serverSentEvents.gen.d.ts +1 -1
- package/build/lib/atk-api/generated/core/serverSentEvents.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/serverSentEvents.gen.js +1 -0
- package/build/lib/atk-api/generated/core/serverSentEvents.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/types.gen.d.ts +2 -2
- package/build/lib/atk-api/generated/core/types.gen.d.ts.map +1 -0
- package/build/lib/atk-api/generated/core/types.gen.js +4 -0
- package/build/lib/atk-api/generated/core/types.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/utils.gen.d.ts +1 -1
- package/build/lib/atk-api/generated/core/utils.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/core/utils.gen.js +2 -1
- package/build/lib/atk-api/generated/core/utils.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/index.d.ts +2 -2
- package/build/lib/atk-api/generated/index.d.ts.map +1 -0
- package/build/lib/atk-api/generated/index.js +4 -0
- package/build/lib/atk-api/generated/index.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/sdk.gen.d.ts +6 -2
- package/build/lib/atk-api/generated/sdk.gen.d.ts.map +1 -0
- package/build/lib/{api → atk-api/generated}/sdk.gen.js +6 -1
- package/build/lib/atk-api/generated/sdk.gen.js.map +1 -0
- package/build/lib/{api → atk-api/generated}/types.gen.d.ts +27 -0
- package/build/lib/atk-api/generated/types.gen.d.ts.map +1 -0
- package/build/lib/atk-api/generated/types.gen.js +4 -0
- package/build/lib/atk-api/generated/types.gen.js.map +1 -0
- package/build/lib/atk-api/index.d.ts +29 -0
- package/build/lib/atk-api/index.d.ts.map +1 -0
- package/build/lib/atk-api/index.js +27 -0
- package/build/lib/atk-api/index.js.map +1 -0
- package/build/lib/atk-api/limits.d.ts +16 -0
- package/build/lib/atk-api/limits.d.ts.map +1 -0
- package/build/lib/atk-api/limits.js +17 -0
- package/build/lib/atk-api/limits.js.map +1 -0
- package/build/lib/atk-api/schemas/bundle.d.ts.map +1 -0
- package/build/lib/{schemas → atk-api/schemas}/bundle.js +2 -1
- package/build/lib/atk-api/schemas/bundle.js.map +1 -0
- package/build/lib/atk-api/schemas/index.d.ts +14 -0
- package/build/lib/atk-api/schemas/index.d.ts.map +1 -0
- package/build/lib/atk-api/schemas/index.js +15 -0
- package/build/lib/atk-api/schemas/index.js.map +1 -0
- package/build/lib/atk-api/schemas/manifest.d.ts.map +1 -0
- package/build/lib/{schemas → atk-api/schemas}/manifest.js +1 -0
- package/build/lib/atk-api/schemas/manifest.js.map +1 -0
- package/build/lib/atk-api/schemas/registry.d.ts.map +1 -0
- package/build/lib/{schemas → atk-api/schemas}/registry.js +3 -2
- package/build/lib/atk-api/schemas/registry.js.map +1 -0
- package/build/lib/atk-api/testing.d.ts +47 -0
- package/build/lib/atk-api/testing.d.ts.map +1 -0
- package/build/lib/atk-api/testing.js +88 -0
- package/build/lib/atk-api/testing.js.map +1 -0
- package/build/lib/atk-api/transport.d.ts +27 -0
- package/build/lib/atk-api/transport.d.ts.map +1 -0
- package/build/lib/atk-api/transport.js +84 -0
- package/build/lib/atk-api/transport.js.map +1 -0
- package/build/lib/atk-api/web-routes.d.ts +125 -0
- package/build/lib/atk-api/web-routes.d.ts.map +1 -0
- package/build/lib/atk-api/web-routes.js +199 -0
- package/build/lib/atk-api/web-routes.js.map +1 -0
- package/build/lib/auth.d.ts +1 -1
- package/build/lib/auth.d.ts.map +1 -1
- package/build/lib/auth.js +7 -13
- package/build/lib/auth.js.map +1 -1
- package/build/lib/config.d.ts +1 -1
- package/build/lib/config.d.ts.map +1 -1
- package/build/lib/diff-command.d.ts +1 -1
- package/build/lib/diff-command.d.ts.map +1 -1
- package/build/lib/hook-config.d.ts +1 -1
- package/build/lib/hook-config.d.ts.map +1 -1
- package/build/lib/init.d.ts +1 -1
- package/build/lib/init.d.ts.map +1 -1
- package/build/lib/init.js +2 -4
- package/build/lib/init.js.map +1 -1
- package/build/lib/lockfile.d.ts +1 -1
- package/build/lib/lockfile.d.ts.map +1 -1
- package/build/lib/manifest-diff.d.ts +2 -2
- package/build/lib/manifest-diff.d.ts.map +1 -1
- package/build/lib/manifest-diff.js +2 -2
- package/build/lib/manifest-diff.js.map +1 -1
- package/build/lib/publisher.d.ts +13 -14
- package/build/lib/publisher.d.ts.map +1 -1
- package/build/lib/publisher.js +55 -84
- package/build/lib/publisher.js.map +1 -1
- package/build/lib/registrar.d.ts +1 -1
- package/build/lib/registrar.d.ts.map +1 -1
- package/build/lib/registrar.js +1 -1
- package/build/lib/registrar.js.map +1 -1
- package/build/lib/registry-mutate.d.ts +11 -5
- package/build/lib/registry-mutate.d.ts.map +1 -1
- package/build/lib/registry-mutate.js +17 -25
- package/build/lib/registry-mutate.js.map +1 -1
- package/build/lib/registry.d.ts +6 -4
- package/build/lib/registry.d.ts.map +1 -1
- package/build/lib/registry.js +84 -101
- package/build/lib/registry.js.map +1 -1
- package/build/lib/release-notes.d.ts +1 -1
- package/build/lib/release-notes.d.ts.map +1 -1
- package/build/lib/release-notes.js +2 -4
- package/build/lib/release-notes.js.map +1 -1
- package/build/lib/resolver.d.ts +1 -1
- package/build/lib/resolver.d.ts.map +1 -1
- package/build/lib/sanitize.d.ts +1 -1
- package/build/lib/sanitize.d.ts.map +1 -1
- package/build/lib/schemas/adapter.js +1 -1
- package/build/lib/schemas/adapter.js.map +1 -1
- package/build/lib/schemas/config.js +1 -1
- package/build/lib/schemas/config.js.map +1 -1
- package/build/lib/schemas/index.d.ts +1 -3
- package/build/lib/schemas/index.d.ts.map +1 -1
- package/build/lib/schemas/index.js +2 -3
- package/build/lib/schemas/index.js.map +1 -1
- package/build/lib/schemas/lockfile.js +1 -1
- package/build/lib/schemas/lockfile.js.map +1 -1
- package/build/lib/search.d.ts +2 -2
- package/build/lib/search.d.ts.map +1 -1
- package/build/lib/search.js +1 -1
- package/build/lib/search.js.map +1 -1
- package/build/lib/sync.d.ts +1 -1
- package/build/lib/sync.d.ts.map +1 -1
- package/build/lib/updater.d.ts +2 -2
- package/build/lib/updater.d.ts.map +1 -1
- package/package.json +2 -4
- package/build/lib/api/client/client.gen.d.ts +0 -3
- package/build/lib/api/client/client.gen.d.ts.map +0 -1
- package/build/lib/api/client/client.gen.js.map +0 -1
- package/build/lib/api/client/index.d.ts +0 -11
- package/build/lib/api/client/index.d.ts.map +0 -1
- package/build/lib/api/client/index.js +0 -7
- package/build/lib/api/client/index.js.map +0 -1
- package/build/lib/api/client/types.gen.d.ts.map +0 -1
- package/build/lib/api/client/types.gen.js +0 -3
- package/build/lib/api/client/types.gen.js.map +0 -1
- package/build/lib/api/client/utils.gen.d.ts.map +0 -1
- package/build/lib/api/client/utils.gen.js.map +0 -1
- package/build/lib/api/client.gen.d.ts.map +0 -1
- package/build/lib/api/client.gen.js +0 -4
- package/build/lib/api/client.gen.js.map +0 -1
- package/build/lib/api/core/auth.gen.d.ts.map +0 -1
- package/build/lib/api/core/auth.gen.js.map +0 -1
- package/build/lib/api/core/bodySerializer.gen.d.ts.map +0 -1
- package/build/lib/api/core/bodySerializer.gen.js.map +0 -1
- package/build/lib/api/core/params.gen.d.ts.map +0 -1
- package/build/lib/api/core/params.gen.js.map +0 -1
- package/build/lib/api/core/pathSerializer.gen.d.ts.map +0 -1
- package/build/lib/api/core/pathSerializer.gen.js.map +0 -1
- package/build/lib/api/core/queryKeySerializer.gen.d.ts.map +0 -1
- package/build/lib/api/core/queryKeySerializer.gen.js.map +0 -1
- package/build/lib/api/core/serverSentEvents.gen.d.ts.map +0 -1
- package/build/lib/api/core/serverSentEvents.gen.js.map +0 -1
- package/build/lib/api/core/types.gen.d.ts.map +0 -1
- package/build/lib/api/core/types.gen.js +0 -3
- package/build/lib/api/core/types.gen.js.map +0 -1
- package/build/lib/api/core/utils.gen.d.ts.map +0 -1
- package/build/lib/api/core/utils.gen.js.map +0 -1
- package/build/lib/api/index.d.ts.map +0 -1
- package/build/lib/api/index.js +0 -3
- package/build/lib/api/index.js.map +0 -1
- package/build/lib/api/sdk.gen.d.ts.map +0 -1
- package/build/lib/api/sdk.gen.js.map +0 -1
- package/build/lib/api/types.gen.d.ts.map +0 -1
- package/build/lib/api/types.gen.js +0 -3
- package/build/lib/api/types.gen.js.map +0 -1
- package/build/lib/schemas/bundle.d.ts.map +0 -1
- package/build/lib/schemas/bundle.js.map +0 -1
- package/build/lib/schemas/manifest.d.ts.map +0 -1
- package/build/lib/schemas/manifest.js.map +0 -1
- package/build/lib/schemas/registry.d.ts.map +0 -1
- package/build/lib/schemas/registry.js.map +0 -1
- /package/build/lib/{api → atk-api/generated}/core/auth.gen.d.ts +0 -0
- /package/build/lib/{api → atk-api/generated}/core/params.gen.d.ts +0 -0
- /package/build/lib/{api → atk-api/generated}/core/pathSerializer.gen.d.ts +0 -0
- /package/build/lib/{api → atk-api/generated}/core/queryKeySerializer.gen.d.ts +0 -0
- /package/build/lib/{schemas → atk-api/schemas}/bundle.d.ts +0 -0
- /package/build/lib/{schemas → atk-api/schemas}/manifest.d.ts +0 -0
- /package/build/lib/{schemas → atk-api/schemas}/registry.d.ts +0 -0
|
@@ -1,79 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* CLI wiring for the shared ATK API client (`./atk-api`, vendored from
|
|
3
|
+
* packages/api-client). Owns only what is CLI-specific:
|
|
4
|
+
* - base URL resolution (`ATK_API_URL` env > `apiUrl` config > production);
|
|
5
|
+
* - the credential chain (`getCredential`) as the client's `getToken`;
|
|
6
|
+
* - the Sunset-observing base fetch (deleted in step 5d);
|
|
7
|
+
* - the CLI's words for a failed call: {@link presentProblem} turns an
|
|
8
|
+
* AtkError into the message, hint and command the CLI has always shown, and
|
|
9
|
+
* {@link callApi} throws them as an {@link ApiRequestError}.
|
|
3
10
|
*
|
|
4
|
-
*
|
|
5
|
-
* - Base URL resolution (`ATK_API_URL` env > `apiUrl` config > production).
|
|
6
|
-
* - Wiring: bearer auth from the credential chain (`getCredential`) and
|
|
7
|
-
* retries through {@link fetchWithRetry}; `Sunset` headers become notices.
|
|
8
|
-
* - Error mapping: every non-2xx result becomes an {@link ApiRequestError}
|
|
9
|
-
* with a stable `code`, an HTTP `status`, and CLI-friendly message/hint text.
|
|
10
|
-
*
|
|
11
|
-
* Nothing outside this module may import the generated default client in
|
|
12
|
-
* `api/client.gen.ts`; it is generated without a base URL or auth, and an
|
|
13
|
-
* ESLint `no-restricted-imports` rule enforces this.
|
|
11
|
+
* Call sites read as `await callApi('your identity', (atk) => atk.me())`.
|
|
14
12
|
*/
|
|
15
|
-
import type
|
|
16
|
-
import { type Client } from './api/client/index.js';
|
|
17
|
-
export type { ApiErrorDetail } from './api/types.gen.js';
|
|
13
|
+
import { type AtkClient, type AtkError } from './atk-api/index.js';
|
|
18
14
|
/** Production ATK API. Used when neither `ATK_API_URL` nor `apiUrl` is set. */
|
|
19
15
|
export declare const DEFAULT_API_URL = "https://func-atk-prod.azurewebsites.net";
|
|
20
16
|
/** Environment variable that overrides the configured API base URL. */
|
|
21
17
|
export declare const API_URL_ENV_VAR = "ATK_API_URL";
|
|
22
|
-
/** Shape of a generated SDK call result with `throwOnError: false` and `responseStyle: 'fields'`. */
|
|
23
|
-
export interface ApiResult<T> {
|
|
24
|
-
data?: T;
|
|
25
|
-
error?: unknown;
|
|
26
|
-
response?: Response;
|
|
27
|
-
}
|
|
28
18
|
/**
|
|
29
|
-
* Thrown by {@link
|
|
19
|
+
* Thrown by {@link callApi} for any failed ATK API call.
|
|
30
20
|
*
|
|
31
21
|
* `status` is the HTTP status (0 for a network failure). `code` is the API's
|
|
32
22
|
* machine-readable error code (`not_found`, `version_not_bumped`, ...), or a
|
|
33
23
|
* synthetic one (`network_error`, `http_error`) when the API did not send an
|
|
34
|
-
* envelope.
|
|
24
|
+
* envelope.
|
|
35
25
|
*/
|
|
36
26
|
export declare class ApiRequestError extends Error {
|
|
37
27
|
code: string;
|
|
38
28
|
command?: string;
|
|
39
|
-
details?: ApiErrorDetail[];
|
|
40
29
|
hint?: string;
|
|
41
30
|
status: number;
|
|
42
31
|
constructor(message: string, options: {
|
|
43
32
|
code: string;
|
|
44
33
|
command?: string;
|
|
45
|
-
details?: ApiErrorDetail[];
|
|
46
34
|
hint?: string;
|
|
47
35
|
status: number;
|
|
48
36
|
});
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
|
-
*
|
|
39
|
+
* Run one API call, turning an AtkError into an {@link ApiRequestError}
|
|
40
|
+
* worded for `resource`. Anything else (an AuthError from the credential
|
|
41
|
+
* chain, a config error) propagates unchanged.
|
|
52
42
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
43
|
+
* @param resource - Human-readable name of what was requested (used in messages)
|
|
44
|
+
* @param client - A specific client ({@link getAtkForToken}); the process-wide one by default
|
|
55
45
|
*/
|
|
56
|
-
export declare function
|
|
46
|
+
export declare function callApi<T>(resource: string, call: (atk: AtkClient) => Promise<T>, client?: AtkClient): Promise<T>;
|
|
57
47
|
/**
|
|
58
|
-
* The
|
|
59
|
-
*
|
|
48
|
+
* The process-wide client. Built once: base URL from {@link resolveApiUrl},
|
|
49
|
+
* bearer token resolved per request through `getCredential()`.
|
|
60
50
|
*/
|
|
61
|
-
export declare function
|
|
51
|
+
export declare function getAtk(): Promise<AtkClient>;
|
|
62
52
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Built once: base URL from {@link resolveApiUrl}, bearer auth resolved
|
|
66
|
-
* lazily per request via `getCredential()`, and every request routed
|
|
67
|
-
* through {@link fetchWithRetry}.
|
|
53
|
+
* A client bound to one explicit token, never the process-cached one
|
|
54
|
+
* (`atk login` confirming a fresh session, `atk doctor` validating a token).
|
|
68
55
|
*/
|
|
69
|
-
export declare function
|
|
56
|
+
export declare function getAtkForToken(token: string, baseUrl: string): AtkClient;
|
|
70
57
|
/**
|
|
71
58
|
* Type guard for {@link ApiRequestError}, optionally narrowed by API error
|
|
72
59
|
* code and/or HTTP status.
|
|
73
60
|
*/
|
|
74
61
|
export declare function isApiError(err: unknown, code?: string, status?: number): err is ApiRequestError;
|
|
75
62
|
/**
|
|
76
|
-
*
|
|
63
|
+
* The CLI's words for a failed call: the message (matching what the CLI
|
|
64
|
+
* showed before the API existed, where such a message existed), plus the hint
|
|
65
|
+
* and command that go with it. Exhaustive over the problem kinds.
|
|
66
|
+
*/
|
|
67
|
+
export declare function presentProblem(error: AtkError, resource: string): {
|
|
68
|
+
command?: string;
|
|
69
|
+
hint?: string;
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Drop the memoised client so the next {@link getAtk} call rebuilds it.
|
|
77
74
|
* Intended for tests and for commands that change `apiUrl` mid-process.
|
|
78
75
|
*/
|
|
79
76
|
export declare function resetApiClient(): void;
|
|
@@ -81,17 +78,11 @@ export declare function resetApiClient(): void;
|
|
|
81
78
|
* Resolve the ATK API base URL.
|
|
82
79
|
*
|
|
83
80
|
* Precedence: `ATK_API_URL` env var > `apiUrl` from `~/.atkrc.json` > production.
|
|
84
|
-
* A trailing slash is stripped so
|
|
81
|
+
* A trailing slash is stripped so paths can be appended.
|
|
85
82
|
*/
|
|
86
83
|
export declare function resolveApiUrl(config?: {
|
|
87
84
|
apiUrl?: string;
|
|
88
85
|
}): string;
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
* {@link ApiRequestError} describing why the call failed.
|
|
92
|
-
*
|
|
93
|
-
* @param result - The `{ data, error, response }` object returned by an SDK function
|
|
94
|
-
* @param resource - Human-readable name of what was requested (used in messages)
|
|
95
|
-
*/
|
|
96
|
-
export declare function unwrap<T>(result: ApiResult<T>, resource: string): T;
|
|
86
|
+
/** An AtkError as the {@link ApiRequestError} the CLI shows for `resource`. */
|
|
87
|
+
export declare function toApiRequestError(error: AtkError, resource: string): ApiRequestError;
|
|
97
88
|
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA;;;;;;;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C,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA+DtD;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAIlE;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAIpF"}
|
package/build/lib/api-client.js
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* CLI wiring for the shared ATK API client (`./atk-api`, vendored from
|
|
3
|
+
* packages/api-client). Owns only what is CLI-specific:
|
|
4
|
+
* - base URL resolution (`ATK_API_URL` env > `apiUrl` config > production);
|
|
5
|
+
* - the credential chain (`getCredential`) as the client's `getToken`;
|
|
6
|
+
* - the Sunset-observing base fetch (deleted in step 5d);
|
|
7
|
+
* - the CLI's words for a failed call: {@link presentProblem} turns an
|
|
8
|
+
* AtkError into the message, hint and command the CLI has always shown, and
|
|
9
|
+
* {@link callApi} throws them as an {@link ApiRequestError}.
|
|
3
10
|
*
|
|
4
|
-
*
|
|
5
|
-
* - Base URL resolution (`ATK_API_URL` env > `apiUrl` config > production).
|
|
6
|
-
* - Wiring: bearer auth from the credential chain (`getCredential`) and
|
|
7
|
-
* retries through {@link fetchWithRetry}; `Sunset` headers become notices.
|
|
8
|
-
* - Error mapping: every non-2xx result becomes an {@link ApiRequestError}
|
|
9
|
-
* with a stable `code`, an HTTP `status`, and CLI-friendly message/hint text.
|
|
10
|
-
*
|
|
11
|
-
* Nothing outside this module may import the generated default client in
|
|
12
|
-
* `api/client.gen.ts`; it is generated without a base URL or auth, and an
|
|
13
|
-
* ESLint `no-restricted-imports` rule enforces this.
|
|
11
|
+
* Call sites read as `await callApi('your identity', (atk) => atk.me())`.
|
|
14
12
|
*/
|
|
15
|
-
import {
|
|
13
|
+
import { createAtkClient, isAtkError } from './atk-api/index.js';
|
|
16
14
|
import { getCredential } from './auth.js';
|
|
17
15
|
import { loadConfig } from './config.js';
|
|
18
|
-
import { fetchWithRetry } from './fetch-retry.js';
|
|
19
16
|
import { addNotice } from './notices.js';
|
|
20
17
|
/** Production ATK API. Used when neither `ATK_API_URL` nor `apiUrl` is set. */
|
|
21
18
|
export const DEFAULT_API_URL = 'https://func-atk-prod.azurewebsites.net';
|
|
22
19
|
/** Environment variable that overrides the configured API base URL. */
|
|
23
20
|
export const API_URL_ENV_VAR = 'ATK_API_URL';
|
|
24
21
|
/**
|
|
25
|
-
* Thrown by {@link
|
|
22
|
+
* Thrown by {@link callApi} for any failed ATK API call.
|
|
26
23
|
*
|
|
27
24
|
* `status` is the HTTP status (0 for a network failure). `code` is the API's
|
|
28
25
|
* machine-readable error code (`not_found`, `version_not_bumped`, ...), or a
|
|
29
26
|
* synthetic one (`network_error`, `http_error`) when the API did not send an
|
|
30
|
-
* envelope.
|
|
27
|
+
* envelope.
|
|
31
28
|
*/
|
|
32
29
|
export class ApiRequestError extends Error {
|
|
33
30
|
code;
|
|
34
31
|
command;
|
|
35
|
-
details;
|
|
36
32
|
hint;
|
|
37
33
|
status;
|
|
38
34
|
constructor(message, options) {
|
|
@@ -40,7 +36,6 @@ export class ApiRequestError extends Error {
|
|
|
40
36
|
this.name = 'ApiRequestError';
|
|
41
37
|
this.status = options.status;
|
|
42
38
|
this.code = options.code;
|
|
43
|
-
this.details = options.details;
|
|
44
39
|
this.hint = options.hint;
|
|
45
40
|
this.command = options.command;
|
|
46
41
|
}
|
|
@@ -54,43 +49,49 @@ const NOT_MEMBER_HINT = 'Ask an org admin to add you, or re-authorise your token
|
|
|
54
49
|
const UNAVAILABLE_HINT = 'The registry may be temporarily unavailable. Retry in a moment.';
|
|
55
50
|
const AMBIGUOUS_NAME_HINT = 'Pass `--type <type>` (or `--type bundle`) to choose one.';
|
|
56
51
|
const REGISTRY_CHANGED_HINT = 'The registry changed while the pull request was being prepared. Retry the command.';
|
|
57
|
-
/**
|
|
58
|
-
const
|
|
59
|
-
|
|
52
|
+
/** `ApiRequestError.code` for problems the client made itself (no API code to carry). */
|
|
53
|
+
const SYNTHETIC_CODES = {
|
|
54
|
+
invalid_input: 'invalid_input',
|
|
55
|
+
network: 'network_error',
|
|
56
|
+
unexpected_response: 'unexpected_response',
|
|
57
|
+
};
|
|
58
|
+
let atkPromise;
|
|
60
59
|
/**
|
|
61
|
-
*
|
|
60
|
+
* Run one API call, turning an AtkError into an {@link ApiRequestError}
|
|
61
|
+
* worded for `resource`. Anything else (an AuthError from the credential
|
|
62
|
+
* chain, a config error) propagates unchanged.
|
|
62
63
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
64
|
+
* @param resource - Human-readable name of what was requested (used in messages)
|
|
65
|
+
* @param client - A specific client ({@link getAtkForToken}); the process-wide one by default
|
|
65
66
|
*/
|
|
66
|
-
export function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
export async function callApi(resource, call, client) {
|
|
68
|
+
const atk = client ?? (await getAtk());
|
|
69
|
+
try {
|
|
70
|
+
return await call(atk);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
throw isAtkError(err) ? toApiRequestError(err, resource) : err;
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
|
-
* The
|
|
76
|
-
*
|
|
77
|
+
* The process-wide client. Built once: base URL from {@link resolveApiUrl},
|
|
78
|
+
* bearer token resolved per request through `getCredential()`.
|
|
77
79
|
*/
|
|
78
|
-
export function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
export function getAtk() {
|
|
81
|
+
atkPromise ??= (async () => createAtkClient({
|
|
82
|
+
app: 'cli',
|
|
83
|
+
baseUrl: resolveApiUrl(await loadConfig()),
|
|
84
|
+
fetch: observingFetch,
|
|
85
|
+
getToken: async () => (await getCredential()).token,
|
|
86
|
+
}))();
|
|
87
|
+
return atkPromise;
|
|
83
88
|
}
|
|
84
89
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* Built once: base URL from {@link resolveApiUrl}, bearer auth resolved
|
|
88
|
-
* lazily per request via `getCredential()`, and every request routed
|
|
89
|
-
* through {@link fetchWithRetry}.
|
|
90
|
+
* A client bound to one explicit token, never the process-cached one
|
|
91
|
+
* (`atk login` confirming a fresh session, `atk doctor` validating a token).
|
|
90
92
|
*/
|
|
91
|
-
export function
|
|
92
|
-
|
|
93
|
-
return clientPromise;
|
|
93
|
+
export function getAtkForToken(token, baseUrl) {
|
|
94
|
+
return createAtkClient({ app: 'cli', baseUrl, fetch: observingFetch, getToken: async () => token });
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* Type guard for {@link ApiRequestError}, optionally narrowed by API error
|
|
@@ -109,59 +110,96 @@ export function isApiError(err, code, status) {
|
|
|
109
110
|
return true;
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
|
-
*
|
|
113
|
+
* The CLI's words for a failed call: the message (matching what the CLI
|
|
114
|
+
* showed before the API existed, where such a message existed), plus the hint
|
|
115
|
+
* and command that go with it. Exhaustive over the problem kinds.
|
|
116
|
+
*/
|
|
117
|
+
export function presentProblem(error, resource) {
|
|
118
|
+
const { apiCode, apiMessage, problem, status } = error;
|
|
119
|
+
const fallback = { message: apiMessage ?? `Failed to fetch ${resource}: HTTP ${status}` };
|
|
120
|
+
const listing = (lines) => [apiMessage, ...lines.map((line) => ` - ${line}`)].join('\n');
|
|
121
|
+
switch (problem.kind) {
|
|
122
|
+
case 'ambiguous':
|
|
123
|
+
return apiMessage ? { hint: AMBIGUOUS_NAME_HINT, message: listing(problem.candidates) } : fallback;
|
|
124
|
+
case 'auth_retired':
|
|
125
|
+
// The API's message names the date and the upgrade path; show it as-is.
|
|
126
|
+
return apiMessage
|
|
127
|
+
? { command: AUTH_COMMAND, message: apiMessage }
|
|
128
|
+
: { command: AUTH_COMMAND, hint: AUTH_HINT, message: AUTH_MESSAGE };
|
|
129
|
+
case 'conflict':
|
|
130
|
+
if ((problem.code === 'referenced_by_bundles' || problem.code === 'bundle_scope_invalid') && apiMessage) {
|
|
131
|
+
return { message: listing(problem.items) };
|
|
132
|
+
}
|
|
133
|
+
if (problem.code === 'registry_changed') {
|
|
134
|
+
return { hint: REGISTRY_CHANGED_HINT, message: apiMessage ?? 'The registry changed.' };
|
|
135
|
+
}
|
|
136
|
+
return fallback;
|
|
137
|
+
case 'forbidden':
|
|
138
|
+
if (problem.code === 'not_org_member' || problem.code === 'org_membership_unverifiable') {
|
|
139
|
+
return { hint: NOT_MEMBER_HINT, message: NOT_MEMBER_MESSAGE };
|
|
140
|
+
}
|
|
141
|
+
if (problem.code === 'guest_not_allowed' && apiMessage) {
|
|
142
|
+
return { hint: GUEST_HINT, message: apiMessage };
|
|
143
|
+
}
|
|
144
|
+
return { message: apiMessage ?? `Access denied while fetching ${resource}.` };
|
|
145
|
+
case 'invalid':
|
|
146
|
+
if ((problem.code === 'validation_failed' || problem.code === 'schema_invalid') && problem.issues.length > 0) {
|
|
147
|
+
const lines = problem.issues.map((issue) => ` ${issue.path ?? '-'}: ${issue.message}`);
|
|
148
|
+
return { message: [apiMessage ?? 'Validation failed.', ...lines].join('\n') };
|
|
149
|
+
}
|
|
150
|
+
return fallback;
|
|
151
|
+
case 'invalid_input':
|
|
152
|
+
return { message: problem.message };
|
|
153
|
+
case 'network':
|
|
154
|
+
return { hint: 'Check your internet connection.', message: `Failed to fetch ${resource}: ${problem.message}` };
|
|
155
|
+
case 'not_found':
|
|
156
|
+
return { message: apiMessage ?? `${resource} not found.` };
|
|
157
|
+
case 'rate_limited':
|
|
158
|
+
return {
|
|
159
|
+
hint: 'Wait a minute and retry.',
|
|
160
|
+
message: apiMessage ?? 'Too many requests to the ATK API. Try again later.',
|
|
161
|
+
};
|
|
162
|
+
case 'server_error':
|
|
163
|
+
case 'unavailable': {
|
|
164
|
+
if (status < 500) {
|
|
165
|
+
return fallback;
|
|
166
|
+
}
|
|
167
|
+
const detail = apiMessage ? ` (${apiCode ?? 'http_error'}: ${apiMessage})` : '';
|
|
168
|
+
return { hint: UNAVAILABLE_HINT, message: `Failed to fetch ${resource}: HTTP ${status}${detail}` };
|
|
169
|
+
}
|
|
170
|
+
case 'unauthenticated':
|
|
171
|
+
return { command: AUTH_COMMAND, hint: AUTH_HINT, message: AUTH_MESSAGE };
|
|
172
|
+
case 'unexpected_response':
|
|
173
|
+
return { message: `Unexpected response for ${resource}: ${problem.message}` };
|
|
174
|
+
default: {
|
|
175
|
+
const unhandled = problem;
|
|
176
|
+
return unhandled;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Drop the memoised client so the next {@link getAtk} call rebuilds it.
|
|
113
182
|
* Intended for tests and for commands that change `apiUrl` mid-process.
|
|
114
183
|
*/
|
|
115
184
|
export function resetApiClient() {
|
|
116
|
-
|
|
185
|
+
atkPromise = undefined;
|
|
117
186
|
}
|
|
118
187
|
/**
|
|
119
188
|
* Resolve the ATK API base URL.
|
|
120
189
|
*
|
|
121
190
|
* Precedence: `ATK_API_URL` env var > `apiUrl` from `~/.atkrc.json` > production.
|
|
122
|
-
* A trailing slash is stripped so
|
|
191
|
+
* A trailing slash is stripped so paths can be appended.
|
|
123
192
|
*/
|
|
124
193
|
export function resolveApiUrl(config) {
|
|
125
194
|
const envUrl = process.env[API_URL_ENV_VAR]?.trim();
|
|
126
195
|
const raw = envUrl || config?.apiUrl?.trim() || DEFAULT_API_URL;
|
|
127
196
|
return raw.replace(/\/+$/, '');
|
|
128
197
|
}
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
* @param resource - Human-readable name of what was requested (used in messages)
|
|
135
|
-
*/
|
|
136
|
-
export function unwrap(result, resource) {
|
|
137
|
-
const { data, error, response } = result;
|
|
138
|
-
if (response === undefined) {
|
|
139
|
-
// The client's auth hook (getCredential) threw before any request was
|
|
140
|
-
// sent: surface it as the auth problem it is, hint and command intact.
|
|
141
|
-
if (isAuthError(error)) {
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
// The fetch itself threw (DNS, connection refused, abort, ...).
|
|
145
|
-
const cause = error instanceof Error ? error.message : error ? String(error) : 'Network request failed';
|
|
146
|
-
throw new ApiRequestError(`Failed to fetch ${resource}: ${cause}`, {
|
|
147
|
-
code: 'network_error',
|
|
148
|
-
hint: 'Check your internet connection.',
|
|
149
|
-
status: 0,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
if (response.ok && error === undefined) {
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
155
|
-
throw toApiRequestError(response.status, error, resource);
|
|
156
|
-
}
|
|
157
|
-
async function buildClient() {
|
|
158
|
-
const config = await loadConfig();
|
|
159
|
-
return createClient({
|
|
160
|
-
auth: async () => (await getCredential()).token,
|
|
161
|
-
baseUrl: resolveApiUrl(config),
|
|
162
|
-
fetch: observingFetch,
|
|
163
|
-
throwOnError: false,
|
|
164
|
-
});
|
|
198
|
+
/** An AtkError as the {@link ApiRequestError} the CLI shows for `resource`. */
|
|
199
|
+
export function toApiRequestError(error, resource) {
|
|
200
|
+
const { message, ...guidance } = presentProblem(error, resource);
|
|
201
|
+
const code = error.apiCode ?? SYNTHETIC_CODES[error.problem.kind] ?? 'http_error';
|
|
202
|
+
return new ApiRequestError(message, { code, ...guidance, status: error.status });
|
|
165
203
|
}
|
|
166
204
|
/** `Sunset` is an HTTP-date; show it as `YYYY-MM-DD`, or verbatim if unparseable. */
|
|
167
205
|
function formatSunsetDate(headerValue) {
|
|
@@ -169,101 +207,17 @@ function formatSunsetDate(headerValue) {
|
|
|
169
207
|
return Number.isNaN(parsed.getTime()) ? headerValue : parsed.toISOString().slice(0, 10);
|
|
170
208
|
}
|
|
171
209
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return err instanceof Error && err.name === 'AuthError';
|
|
177
|
-
}
|
|
178
|
-
function isErrorEnvelope(value) {
|
|
179
|
-
return (typeof value === 'object' &&
|
|
180
|
-
value !== null &&
|
|
181
|
-
typeof value.error === 'string' &&
|
|
182
|
-
typeof value.message === 'string');
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* {@link fetchWithRetry} plus response observation: a `Sunset` header (sent
|
|
186
|
-
* on GitHub-authenticated requests while a GitHub sign-in cutoff is
|
|
187
|
-
* scheduled) records a once-per-run notice for the App shell.
|
|
210
|
+
* The client's base fetch: `globalThis.fetch` (looked up per request) plus
|
|
211
|
+
* response observation. A `Sunset` header (sent on GitHub-authenticated
|
|
212
|
+
* requests while a GitHub sign-in cutoff is scheduled) records a once-per-run
|
|
213
|
+
* notice for the App shell. It must not retry: the client retries around it.
|
|
188
214
|
*/
|
|
189
215
|
async function observingFetch(input, init) {
|
|
190
|
-
const response = await
|
|
216
|
+
const response = await globalThis.fetch(input, init);
|
|
191
217
|
const sunset = response.headers.get('Sunset');
|
|
192
218
|
if (sunset) {
|
|
193
219
|
addNotice({ date: formatSunsetDate(sunset), kind: 'github-sunset' });
|
|
194
220
|
}
|
|
195
221
|
return response;
|
|
196
222
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Map an HTTP status plus the API's error envelope (when present) to an
|
|
199
|
-
* {@link ApiRequestError} whose message matches what the CLI showed before
|
|
200
|
-
* the API existed, where such a message existed.
|
|
201
|
-
*/
|
|
202
|
-
function toApiRequestError(status, error, resource) {
|
|
203
|
-
const envelope = isErrorEnvelope(error) ? error : undefined;
|
|
204
|
-
const code = envelope?.error ?? 'http_error';
|
|
205
|
-
const apiMessage = envelope?.message ?? (typeof error === 'string' && error ? error : undefined);
|
|
206
|
-
const details = envelope?.details ?? undefined;
|
|
207
|
-
if (status === 401) {
|
|
208
|
-
if (code === 'github_auth_retired' && apiMessage) {
|
|
209
|
-
// The API's message names the date and the upgrade path; show it as-is.
|
|
210
|
-
return new ApiRequestError(apiMessage, { code, command: AUTH_COMMAND, status });
|
|
211
|
-
}
|
|
212
|
-
return new ApiRequestError(AUTH_MESSAGE, { code, command: AUTH_COMMAND, hint: AUTH_HINT, status });
|
|
213
|
-
}
|
|
214
|
-
if (status === 403) {
|
|
215
|
-
if (code === 'not_org_member' || code === 'org_membership_unverifiable') {
|
|
216
|
-
return new ApiRequestError(NOT_MEMBER_MESSAGE, { code, hint: NOT_MEMBER_HINT, status });
|
|
217
|
-
}
|
|
218
|
-
if (code === 'guest_not_allowed' && apiMessage) {
|
|
219
|
-
return new ApiRequestError(apiMessage, { code, hint: GUEST_HINT, status });
|
|
220
|
-
}
|
|
221
|
-
return new ApiRequestError(apiMessage ?? `Access denied while fetching ${resource}.`, { code, status });
|
|
222
|
-
}
|
|
223
|
-
if (status === 404) {
|
|
224
|
-
return new ApiRequestError(apiMessage ?? `${resource} not found.`, { code, status });
|
|
225
|
-
}
|
|
226
|
-
if (status === 429) {
|
|
227
|
-
return new ApiRequestError(apiMessage ?? 'Too many requests to the ATK API. Try again later.', {
|
|
228
|
-
code,
|
|
229
|
-
hint: 'Wait a minute and retry.',
|
|
230
|
-
status,
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (status === 400 && (code === 'validation_failed' || code === 'schema_invalid') && details?.length) {
|
|
234
|
-
const lines = details.map((d) => ` ${d.path ?? '-'}: ${d.message}`);
|
|
235
|
-
return new ApiRequestError([apiMessage ?? 'Validation failed.', ...lines].join('\n'), { code, details, status });
|
|
236
|
-
}
|
|
237
|
-
if (LISTING_CODES.has(code) && apiMessage) {
|
|
238
|
-
// The message is one sentence; the candidates / bundles / refs are in details.
|
|
239
|
-
const lines = (details ?? []).map((d) => ` - ${d.message}`);
|
|
240
|
-
return new ApiRequestError([apiMessage, ...lines].join('\n'), {
|
|
241
|
-
code,
|
|
242
|
-
details,
|
|
243
|
-
...(code === 'ambiguous_name' ? { hint: AMBIGUOUS_NAME_HINT } : {}),
|
|
244
|
-
status,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
if (code === 'registry_changed') {
|
|
248
|
-
return new ApiRequestError(apiMessage ?? 'The registry changed.', {
|
|
249
|
-
code,
|
|
250
|
-
hint: REGISTRY_CHANGED_HINT,
|
|
251
|
-
status,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
if (status >= 500) {
|
|
255
|
-
const detail = apiMessage ? ` (${code}: ${apiMessage})` : '';
|
|
256
|
-
return new ApiRequestError(`Failed to fetch ${resource}: HTTP ${status}${detail}`, {
|
|
257
|
-
code,
|
|
258
|
-
hint: UNAVAILABLE_HINT,
|
|
259
|
-
status,
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
// 400/409 and anything else: the API message is the best text we have.
|
|
263
|
-
return new ApiRequestError(apiMessage ?? `Failed to fetch ${resource}: HTTP ${status}`, {
|
|
264
|
-
code,
|
|
265
|
-
details,
|
|
266
|
-
status,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
223
|
//# sourceMappingURL=api-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAiC,eAAe,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,eAAe,GAAG,yCAAyC,CA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