@hypequery/cloud-client 0.0.0-canary-20261113132821 → 0.0.0-stage

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.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export { createCloudClient, DEFAULT_CLOUD_URL } from './client.js';
2
- export type { CloudClient, CloudClientOptions, OperationInputArgs } from './client.js';
3
- export { CloudApiError, isCloudApiError } from './errors.js';
4
- export type { ClientErrorCode, CloudApiErrorInit, CloudErrorBody, CloudInputIssue } from './errors.js';
5
- export { parseErrorEnvelope } from './utils/error-envelope.js';
6
- export { buildRequest } from './utils/request.js';
7
- export type { BuiltRequest, RequestContext } from './utils/request.js';
8
- export type { CallOptions, CloudErrorSpec, HttpMethod, OperationMeta } from './types.js';
9
- export * from './generated/operations.js';
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzF,cAAc,2BAA2B,CAAC"}
package/dist/index.js DELETED
@@ -1,5 +0,0 @@
1
- export { createCloudClient, DEFAULT_CLOUD_URL } from './client.js';
2
- export { CloudApiError, isCloudApiError } from './errors.js';
3
- export { parseErrorEnvelope } from './utils/error-envelope.js';
4
- export { buildRequest } from './utils/request.js';
5
- export * from './generated/operations.js';
package/dist/types.d.ts DELETED
@@ -1,35 +0,0 @@
1
- /** Shared shapes the generated module and the runtime both use. */
2
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
3
- /** Route and policy for one operation, as listed in `OPERATIONS`. */
4
- export interface OperationMeta {
5
- readonly name: string;
6
- readonly summary: string;
7
- readonly scope: 'organization' | 'project';
8
- /** The capability the caller's role needs. */
9
- readonly capability: string;
10
- /** Destructive operations need `confirm: true` in their input. */
11
- readonly destructive: boolean;
12
- readonly method: HttpMethod;
13
- /** Path under the `/v1` base path; `{name}` segments come from the input. */
14
- readonly path: string;
15
- readonly pathParams: readonly string[];
16
- /** Every error code this operation can return. */
17
- readonly errors: readonly string[];
18
- }
19
- /** One entry of the error catalog. */
20
- export interface CloudErrorSpec {
21
- readonly status: number;
22
- readonly category: string;
23
- readonly retryable: boolean;
24
- /** The next action, in one sentence. */
25
- readonly hint: string;
26
- readonly docsUrl: string;
27
- }
28
- /** Per-call options for any operation method. */
29
- export interface CallOptions {
30
- /** Abort the request. The fetch's own abort error is rethrown unchanged. */
31
- readonly signal?: AbortSignal;
32
- /** Extra headers for this call. */
33
- readonly headers?: Readonly<Record<string, string>>;
34
- }
35
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,CAAC;IAC3C,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,kDAAkD;IAClD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,iDAAiD;AACjD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,mCAAmC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- /** Shared shapes the generated module and the runtime both use. */
2
- export {};
@@ -1,8 +0,0 @@
1
- import type { CloudErrorBody } from '../errors.js';
2
- /**
3
- * Reads Cloud's `{ error: { code, message, ... } }` envelope, or `undefined`
4
- * when `body` isn't one (a proxy's HTML page, an empty body). Only `code` and
5
- * `message` are required, so an older or partial envelope still parses.
6
- */
7
- export declare function parseErrorEnvelope(body: unknown): CloudErrorBody | undefined;
8
- //# sourceMappingURL=error-envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-envelope.d.ts","sourceRoot":"","sources":["../../src/utils/error-envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,cAAc,CAAC;AAepE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAkB5E"}
@@ -1,34 +0,0 @@
1
- function isRecord(value) {
2
- return typeof value === 'object' && value !== null && !Array.isArray(value);
3
- }
4
- function readIssues(value) {
5
- if (!Array.isArray(value))
6
- return undefined;
7
- const issues = value.filter((issue) => isRecord(issue) && typeof issue.path === 'string' && typeof issue.message === 'string');
8
- return issues.length ? issues.map(({ path, message }) => ({ path, message })) : undefined;
9
- }
10
- /**
11
- * Reads Cloud's `{ error: { code, message, ... } }` envelope, or `undefined`
12
- * when `body` isn't one (a proxy's HTML page, an empty body). Only `code` and
13
- * `message` are required, so an older or partial envelope still parses.
14
- */
15
- export function parseErrorEnvelope(body) {
16
- if (!isRecord(body) || !isRecord(body.error))
17
- return undefined;
18
- const error = body.error;
19
- if (typeof error.code !== 'string' || typeof error.message !== 'string')
20
- return undefined;
21
- const category = typeof error.category === 'string' ? error.category : 'internal';
22
- const issues = readIssues(error.issues);
23
- return {
24
- code: error.code,
25
- message: error.message,
26
- hint: typeof error.hint === 'string' ? error.hint : '',
27
- docsUrl: typeof error.docsUrl === 'string' ? error.docsUrl : '',
28
- category,
29
- retryable: error.retryable === true,
30
- correctable: typeof error.correctable === 'boolean' ? error.correctable : category === 'correctable_input',
31
- requestId: typeof error.requestId === 'string' ? error.requestId : '',
32
- ...(issues ? { issues } : {}),
33
- };
34
- }
@@ -1,20 +0,0 @@
1
- import type { OperationMeta } from '../types.js';
2
- export interface BuiltRequest {
3
- readonly url: string;
4
- readonly method: OperationMeta['method'];
5
- readonly headers: Record<string, string>;
6
- readonly body?: string;
7
- }
8
- export interface RequestContext {
9
- readonly baseUrl: string;
10
- readonly basePath: string;
11
- readonly token: string;
12
- readonly headers?: Readonly<Record<string, string>>;
13
- }
14
- /**
15
- * The HTTP request for one operation call, matching Cloud's `/v1` handler:
16
- * path parameters come out of the input, GET and DELETE send the rest as the
17
- * query string, every other method as a JSON body.
18
- */
19
- export declare function buildRequest(operation: OperationMeta, input: Readonly<Record<string, unknown>>, context: RequestContext): BuiltRequest;
20
- //# sourceMappingURL=request.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/utils/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD;AAkBD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,aAAa,EACxB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACxC,OAAO,EAAE,cAAc,GACtB,YAAY,CA8Bd"}
@@ -1,41 +0,0 @@
1
- function pathValue(operation, name, value) {
2
- if ((typeof value === 'string' && value.length > 0) || typeof value === 'number') {
3
- return encodeURIComponent(String(value));
4
- }
5
- throw new TypeError(`${operation.name}: "${name}" is required (it's part of the path).`);
6
- }
7
- function queryValue(operation, name, value) {
8
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
9
- return String(value);
10
- }
11
- throw new TypeError(`${operation.name}: "${name}" can't be sent in a query string (only strings, numbers and booleans can).`);
12
- }
13
- /**
14
- * The HTTP request for one operation call, matching Cloud's `/v1` handler:
15
- * path parameters come out of the input, GET and DELETE send the rest as the
16
- * query string, every other method as a JSON body.
17
- */
18
- export function buildRequest(operation, input, context) {
19
- const pathParams = new Set(operation.pathParams);
20
- const path = operation.path.replace(/\{([A-Za-z][A-Za-z0-9]*)\}/g, (_, name) => pathValue(operation, name, input[name]));
21
- const rest = Object.entries(input).filter(([name, value]) => !pathParams.has(name) && value !== undefined);
22
- const url = new URL(`${context.baseUrl.replace(/\/+$/, '')}${context.basePath}${path}`);
23
- const headers = {
24
- accept: 'application/json',
25
- // Lower-cased so a caller's `Authorization` can't sit beside the token.
26
- ...Object.fromEntries(Object.entries(context.headers ?? {}).map(([name, value]) => [name.toLowerCase(), value])),
27
- authorization: `Bearer ${context.token}`,
28
- };
29
- if (operation.method === 'GET' || operation.method === 'DELETE') {
30
- for (const [name, value] of rest)
31
- url.searchParams.set(name, queryValue(operation, name, value));
32
- return { url: url.toString(), method: operation.method, headers };
33
- }
34
- headers['content-type'] = 'application/json';
35
- return {
36
- url: url.toString(),
37
- method: operation.method,
38
- headers,
39
- body: JSON.stringify(Object.fromEntries(rest)),
40
- };
41
- }