@venizia/ignis-connectors 0.2.1-3 → 0.2.1-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cjs/http/common/readers.d.ts +37 -0
  2. package/dist/cjs/http/common/readers.d.ts.map +1 -0
  3. package/dist/cjs/http/common/readers.js +76 -0
  4. package/dist/cjs/http/common/readers.js.map +1 -0
  5. package/dist/cjs/http/common/types.d.ts +29 -4
  6. package/dist/cjs/http/common/types.d.ts.map +1 -1
  7. package/dist/cjs/http/common/wire.d.ts +63 -0
  8. package/dist/cjs/http/common/wire.d.ts.map +1 -0
  9. package/dist/cjs/http/common/wire.js +132 -0
  10. package/dist/cjs/http/common/wire.js.map +1 -0
  11. package/dist/cjs/http/datasource.d.ts +35 -9
  12. package/dist/cjs/http/datasource.d.ts.map +1 -1
  13. package/dist/cjs/http/datasource.js +121 -180
  14. package/dist/cjs/http/datasource.js.map +1 -1
  15. package/dist/cjs/http/index.d.ts +1 -0
  16. package/dist/cjs/http/index.d.ts.map +1 -1
  17. package/dist/cjs/http/index.js +1 -0
  18. package/dist/cjs/http/index.js.map +1 -1
  19. package/dist/cjs/http/repository.d.ts +40 -26
  20. package/dist/cjs/http/repository.d.ts.map +1 -1
  21. package/dist/cjs/http/repository.js +34 -5
  22. package/dist/cjs/http/repository.js.map +1 -1
  23. package/dist/esm/http/common/readers.d.ts +37 -0
  24. package/dist/esm/http/common/readers.d.ts.map +1 -0
  25. package/dist/esm/http/common/readers.js +72 -0
  26. package/dist/esm/http/common/readers.js.map +1 -0
  27. package/dist/esm/http/common/types.d.ts +29 -4
  28. package/dist/esm/http/common/types.d.ts.map +1 -1
  29. package/dist/esm/http/common/wire.d.ts +63 -0
  30. package/dist/esm/http/common/wire.d.ts.map +1 -0
  31. package/dist/esm/http/common/wire.js +128 -0
  32. package/dist/esm/http/common/wire.js.map +1 -0
  33. package/dist/esm/http/datasource.d.ts +35 -9
  34. package/dist/esm/http/datasource.d.ts.map +1 -1
  35. package/dist/esm/http/datasource.js +121 -180
  36. package/dist/esm/http/datasource.js.map +1 -1
  37. package/dist/esm/http/index.d.ts +1 -0
  38. package/dist/esm/http/index.d.ts.map +1 -1
  39. package/dist/esm/http/index.js +1 -0
  40. package/dist/esm/http/index.js.map +1 -1
  41. package/dist/esm/http/repository.d.ts +40 -26
  42. package/dist/esm/http/repository.d.ts.map +1 -1
  43. package/dist/esm/http/repository.js +34 -5
  44. package/dist/esm/http/repository.js.map +1 -1
  45. package/package.json +2 -2
@@ -0,0 +1,37 @@
1
+ import type { TResponsedError } from '@venizia/ignis-helpers/core';
2
+ /**
3
+ * What an IGNIS server answers, read the way `HttpDataSource` reads it - exported so another client
4
+ * of the same server shares the parsing instead of copying it.
5
+ */
6
+ export declare class HttpResponseReader {
7
+ /**
8
+ * A `Content-Range` header as the IGNIS server writes it: `records 0-24/137` -> skip 0, total 137;
9
+ * an empty page, `records *\/137` -> total 137. Anything else, including an absent header or an
10
+ * unknown total, is `undefined`.
11
+ */
12
+ static parseContentRange(opts: {
13
+ header?: string | null;
14
+ }): {
15
+ skip?: number;
16
+ total: number;
17
+ } | undefined;
18
+ /**
19
+ * The IGNIS error envelope - `{ message, statusCode, normalized: { text, code, args }, requestId,
20
+ * extra, details }` - read off a parsed response body. A server configured with `error.rootKey`
21
+ * wraps it under that key; pass the same `rootKey` to unwrap it. A body without that key, or with a
22
+ * non-object under it (a proxy's `{ error: 'Bad Gateway' }`), is read as it stands.
23
+ *
24
+ * A body that is not a plain object yields `{}`; any other body yields its known fields, each
25
+ * `undefined` when absent or mistyped. An empty string reads as absent.
26
+ */
27
+ static readErrorEnvelope(opts: {
28
+ body: unknown;
29
+ rootKey?: string;
30
+ }): TResponsedError;
31
+ /** A failed response's envelope. A body that is not JSON yields `{}`, and the status alone still describes it. */
32
+ static readError(opts: {
33
+ response: Response;
34
+ rootKey?: string;
35
+ }): Promise<TResponsedError>;
36
+ }
37
+ //# sourceMappingURL=readers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readers.d.ts","sourceRoot":"","sources":["../../../../src/http/common/readers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAoBhD;;;;;;;;OAQG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe;IA4BpF,kHAAkH;WACrG,SAAS,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAYjG"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpResponseReader = void 0;
4
+ const wire_1 = require("./wire");
5
+ /**
6
+ * What an IGNIS server answers, read the way `HttpDataSource` reads it - exported so another client
7
+ * of the same server shares the parsing instead of copying it.
8
+ */
9
+ class HttpResponseReader {
10
+ /**
11
+ * A `Content-Range` header as the IGNIS server writes it: `records 0-24/137` -> skip 0, total 137;
12
+ * an empty page, `records *\/137` -> total 137. Anything else, including an absent header or an
13
+ * unknown total, is `undefined`.
14
+ */
15
+ static parseContentRange(opts) {
16
+ const { header } = opts;
17
+ if (!header) {
18
+ return undefined;
19
+ }
20
+ const range = header.match(/(\d+)\s*-\s*(\d+)\s*\/\s*(\d+)/);
21
+ if (range) {
22
+ return { skip: Number(range[1]), total: Number(range[3]) };
23
+ }
24
+ const unsatisfied = header.match(/\*\s*\/\s*(\d+)/);
25
+ if (unsatisfied) {
26
+ return { total: Number(unsatisfied[1]) };
27
+ }
28
+ return undefined;
29
+ }
30
+ /**
31
+ * The IGNIS error envelope - `{ message, statusCode, normalized: { text, code, args }, requestId,
32
+ * extra, details }` - read off a parsed response body. A server configured with `error.rootKey`
33
+ * wraps it under that key; pass the same `rootKey` to unwrap it. A body without that key, or with a
34
+ * non-object under it (a proxy's `{ error: 'Bad Gateway' }`), is read as it stands.
35
+ *
36
+ * A body that is not a plain object yields `{}`; any other body yields its known fields, each
37
+ * `undefined` when absent or mistyped. An empty string reads as absent.
38
+ */
39
+ static readErrorEnvelope(opts) {
40
+ const { body, rootKey } = opts;
41
+ const wrapped = rootKey && wire_1.HttpWire.isPlainObject(body) ? body[rootKey] : undefined;
42
+ const envelope = wire_1.HttpWire.isPlainObject(wrapped) ? wrapped : body;
43
+ if (!wire_1.HttpWire.isPlainObject(envelope)) {
44
+ return {};
45
+ }
46
+ const { message, statusCode, normalized, requestId, extra, details } = envelope;
47
+ const normalizedRecord = wire_1.HttpWire.isPlainObject(normalized) ? normalized : {};
48
+ const { text, code, args } = normalizedRecord;
49
+ return {
50
+ message: wire_1.HttpWire.toText(message),
51
+ statusCode: typeof statusCode === 'number' ? statusCode : undefined,
52
+ normalized: {
53
+ text: wire_1.HttpWire.toText(text),
54
+ code: wire_1.HttpWire.toText(code),
55
+ args: wire_1.HttpWire.isPlainObject(args) ? { ...args } : undefined,
56
+ },
57
+ requestId: wire_1.HttpWire.toText(requestId),
58
+ extra: wire_1.HttpWire.isPlainObject(extra) ? { ...extra } : undefined,
59
+ details: wire_1.HttpWire.isPlainObject(details) ? { ...details } : undefined,
60
+ };
61
+ }
62
+ /** A failed response's envelope. A body that is not JSON yields `{}`, and the status alone still describes it. */
63
+ static async readError(opts) {
64
+ const text = await opts.response.text().catch(() => '');
65
+ let body;
66
+ try {
67
+ body = text ? JSON.parse(text) : undefined;
68
+ }
69
+ catch {
70
+ return {};
71
+ }
72
+ return HttpResponseReader.readErrorEnvelope({ body, rootKey: opts.rootKey });
73
+ }
74
+ }
75
+ exports.HttpResponseReader = HttpResponseReader;
76
+ //# sourceMappingURL=readers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readers.js","sourceRoot":"","sources":["../../../../src/http/common/readers.ts"],"names":[],"mappings":";;;AACA,iCAAkC;AAElC;;;GAGG;AACH,MAAa,kBAAkB;IAC7B;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAExB;QACC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC7D,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACpD,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAyC;QAChE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAE/B,MAAM,OAAO,GAAG,OAAO,IAAI,eAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpF,MAA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;SACtE,CAAC;IACJ,CAAC;IAED,kHAAkH;IAClH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAA8C;QACnE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAExD,IAAI,IAAa,CAAC;QAClB,IAAI,CAAC;YACH,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC/E,CAAC;CACF;AA9ED,gDA8EC"}
@@ -4,8 +4,18 @@ export interface IAuthToken {
4
4
  type?: string;
5
5
  provider?: string;
6
6
  }
7
- /** `undefined` means no token. */
8
- export type TAuthTokenResolver = () => IAuthToken | undefined;
7
+ /** The request a hook is asked about: the repository `paths`, the method, and the final URL with its query. */
8
+ export interface IHttpRequestContext {
9
+ paths: Array<string>;
10
+ method: string;
11
+ url: string;
12
+ /** The call's own signal: a hook may stop waiting on it. A refresh shared by other calls should not be aborted by one. */
13
+ signal?: AbortSignal;
14
+ }
15
+ /** `undefined` means no token for this request. A throw fails the request with that error. */
16
+ export type TAuthTokenResolver = (context: IHttpRequestContext) => IAuthToken | undefined;
17
+ /** Headers for this request. A throw fails the request with that error. */
18
+ export type THttpHeadersResolver = (context: IHttpRequestContext) => THttpHeaders | undefined;
9
19
  /** Not `Record` alone: header names are case-insensitive, and an object merge appends two spellings. */
10
20
  export type THttpHeaders = Headers | Array<[string, string]> | Record<string, string>;
11
21
  /**
@@ -14,15 +24,30 @@ export type THttpHeaders = Headers | Array<[string, string]> | Record<string, st
14
24
  * sends the same body twice.
15
25
  */
16
26
  export type THttpBody = string | object;
27
+ /** What one call may add: its own headers (they win over the configured ones) and a signal to abort it. */
28
+ export interface IHttpCallOptions {
29
+ headers?: THttpHeaders;
30
+ signal?: AbortSignal;
31
+ }
17
32
  export interface IHttpDataSourceSettings {
33
+ /** An absolute URL, or a path from the page origin (`/api`). A path-relative one is refused. */
18
34
  baseUrl: string;
35
+ /** The server's `error.rootKey`: an error envelope wrapped under it is unwrapped before it is read. */
36
+ errorRootKey?: string;
19
37
  /** Sent on every request. `x-request-count` is refused - the connector owns it. */
20
38
  headers?: THttpHeaders;
21
- /** Wins over `authTokenResolver`. */
39
+ /**
40
+ * Run on every send, the 401 retry included. Wins over `headers`; a call's own headers win over
41
+ * it. `x-request-count` is refused here too; an `authorization` here stands only when no token is
42
+ * resolved.
43
+ */
44
+ headersResolver?: THttpHeadersResolver;
45
+ /** Wins over `authTokenResolver`, and is sent whatever the request. */
22
46
  authToken?: IAuthToken;
47
+ /** Run on every send, the 401 retry included. */
23
48
  authTokenResolver?: TAuthTokenResolver;
24
49
  /** Runs on a 401: `true` retries once (re-resolving the token), `false` lets the 401 stand. */
25
- onUnauthorized?: () => Promise<boolean> | boolean;
50
+ onUnauthorized?: (context: IHttpRequestContext) => Promise<boolean> | boolean;
26
51
  }
27
52
  /** A list with no `Content-Range` has no total - `hasRange` says so rather than using the page size. */
28
53
  export interface IHttpReadResult<R> {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/http/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,kCAAkC;AAClC,MAAM,MAAM,kBAAkB,GAAG,MAAM,UAAU,GAAG,SAAS,CAAC;AAE9D,wGAAwG;A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AG,OAAO,CAAC;CAC/E;AAED,wGAAwG;AACxG,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,sFAAsF;AACtF,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,63 @@
1
+ import type { THttpBody, THttpHeaders } from './types';
2
+ /**
3
+ * What `HttpDataSource` puts on the wire and reads back off it: headers, request bodies, rows and
4
+ * the path an error message names. Internal - not part of the `http` entry.
5
+ */
6
+ export declare class HttpWire {
7
+ static isPlainObject(value: unknown): value is Record<string, unknown>;
8
+ /** An empty string reads as absent, so a fallback still applies. */
9
+ static toText(value: unknown): string | undefined;
10
+ /**
11
+ * Caller headers as unique lowercase pairs, last spelling winning.
12
+ *
13
+ * Never `new Headers(input)`: that constructor APPENDS, so `{ 'X-Tenant': 'north', 'x-tenant':
14
+ * 'south' }` - which a merge of two config objects produces - reaches the wire as `"north, south"`,
15
+ * a value neither caller wrote. A `Headers` instance arrives already joined; that one is the
16
+ * caller's own, and is passed through as it stands.
17
+ */
18
+ static toHeaderEntries(opts: {
19
+ headers?: THttpHeaders;
20
+ }): Array<[string, string]>;
21
+ /** The connector always sends `x-request-count: false`; a caller header carrying it would contradict that. */
22
+ static assertNoRequestCountHeader(opts: {
23
+ entries: Array<[string, string]>;
24
+ name: string;
25
+ }): void;
26
+ /**
27
+ * The body as `fetch` takes it. Anything `fetch` already sends as a body passes through untouched;
28
+ * any other object is JSON. Serialised ONCE, so the 401 retry sends the same bytes.
29
+ */
30
+ static toRequestBody(opts: {
31
+ body?: THttpBody;
32
+ }): {
33
+ payload: RequestInit['body'];
34
+ isJson: boolean;
35
+ isFormData: boolean;
36
+ };
37
+ /** JSON, or a 400 naming what failed: a bigint or a cycle would otherwise escape as a bare TypeError. */
38
+ static toJson(opts: {
39
+ value: unknown;
40
+ label: string;
41
+ }): string;
42
+ /**
43
+ * A list is a bare array or the `{ count, data }` envelope; `one` is never unwrapped, since a record
44
+ * may carry `data` and `count` columns. The envelope `count` is the page size, never the total.
45
+ *
46
+ * Anything else asked for as a list throws: counting it as one row is how `existsWith` answers true
47
+ * for an empty result and a page reports a length it does not have.
48
+ */
49
+ static unwrapRows<R>(opts: {
50
+ body: unknown;
51
+ shape: 'list' | 'one';
52
+ url: string;
53
+ }): R;
54
+ /**
55
+ * The path a message names - never the host or the query. A server that relays this error would
56
+ * otherwise send an internal host and a filter's values to its own clients. 414/431 add the length.
57
+ */
58
+ static describeUrl(opts: {
59
+ url: string;
60
+ status?: number;
61
+ }): string;
62
+ }
63
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../../src/http/common/wire.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvD;;;GAGG;AACH,qBAAa,QAAQ;IACnB,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAMtE,oEAAoE;IACpE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IAIjD;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;QAAE,OAAO,CAAC,EAAE,YAAY,CAAA;KAAE,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAsBjF,8GAA8G;IAC9G,MAAM,CAAC,0BAA0B,CAAC,IAAI,EAAE;QACtC,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACjC,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,IAAI;IAWR;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG;QAChD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QAC7B,MAAM,EAAE,OAAO,CAAC;QAChB,UAAU,EAAE,OAAO,CAAC;KACrB;IAmCD,yGAAyG;IACzG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAa9D;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,CAAC;IAiBpF;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;CAYnE"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpWire = void 0;
4
+ const common_1 = require("@venizia/ignis-helpers/common");
5
+ const core_1 = require("@venizia/ignis-helpers/core");
6
+ /**
7
+ * What `HttpDataSource` puts on the wire and reads back off it: headers, request bodies, rows and
8
+ * the path an error message names. Internal - not part of the `http` entry.
9
+ */
10
+ class HttpWire {
11
+ static isPlainObject(value) {
12
+ return (!!value && typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype);
13
+ }
14
+ /** An empty string reads as absent, so a fallback still applies. */
15
+ static toText(value) {
16
+ return typeof value === 'string' && value !== '' ? value : undefined;
17
+ }
18
+ /**
19
+ * Caller headers as unique lowercase pairs, last spelling winning.
20
+ *
21
+ * Never `new Headers(input)`: that constructor APPENDS, so `{ 'X-Tenant': 'north', 'x-tenant':
22
+ * 'south' }` - which a merge of two config objects produces - reaches the wire as `"north, south"`,
23
+ * a value neither caller wrote. A `Headers` instance arrives already joined; that one is the
24
+ * caller's own, and is passed through as it stands.
25
+ */
26
+ static toHeaderEntries(opts) {
27
+ const { headers } = opts;
28
+ if (!headers) {
29
+ return [];
30
+ }
31
+ const source = headers instanceof Headers
32
+ ? [...headers.entries()]
33
+ : Array.isArray(headers)
34
+ ? headers
35
+ : Object.entries(headers);
36
+ const merged = new Map();
37
+ for (const [name, value] of source) {
38
+ merged.set(name.toLowerCase(), value);
39
+ }
40
+ return [...merged.entries()];
41
+ }
42
+ /** The connector always sends `x-request-count: false`; a caller header carrying it would contradict that. */
43
+ static assertNoRequestCountHeader(opts) {
44
+ const { entries, name } = opts;
45
+ if (entries.some(([headerName]) => headerName === common_1.HTTP.Headers.REQUEST_COUNT_DATA)) {
46
+ throw (0, core_1.getError)({
47
+ statusCode: common_1.HTTP.ResultCodes.RS_5.InternalServerError,
48
+ message: `[${name}] ${common_1.HTTP.Headers.REQUEST_COUNT_DATA} is owned by HttpDataSource and always sent as false: rows come back bare, the total in Content-Range.`,
49
+ });
50
+ }
51
+ }
52
+ /**
53
+ * The body as `fetch` takes it. Anything `fetch` already sends as a body passes through untouched;
54
+ * any other object is JSON. Serialised ONCE, so the 401 retry sends the same bytes.
55
+ */
56
+ static toRequestBody(opts) {
57
+ const { body } = opts;
58
+ if (body === undefined) {
59
+ return { payload: undefined, isJson: false, isFormData: false };
60
+ }
61
+ const isFormData = body instanceof FormData;
62
+ const isSentAsIs = isFormData ||
63
+ typeof body === 'string' ||
64
+ body instanceof Blob ||
65
+ body instanceof URLSearchParams ||
66
+ body instanceof ArrayBuffer;
67
+ if (isSentAsIs) {
68
+ return { payload: body, isJson: false, isFormData };
69
+ }
70
+ // A typed array may sit on a SharedArrayBuffer, which `fetch` refuses; a Blob copy never does.
71
+ if (ArrayBuffer.isView(body)) {
72
+ return {
73
+ payload: new Blob([new Uint8Array(body.buffer, body.byteOffset, body.byteLength).slice()]),
74
+ isJson: false,
75
+ isFormData: false,
76
+ };
77
+ }
78
+ return {
79
+ payload: HttpWire.toJson({ value: body, label: 'The request body' }),
80
+ isJson: true,
81
+ isFormData: false,
82
+ };
83
+ }
84
+ /** JSON, or a 400 naming what failed: a bigint or a cycle would otherwise escape as a bare TypeError. */
85
+ static toJson(opts) {
86
+ const { value, label } = opts;
87
+ try {
88
+ return JSON.stringify(value);
89
+ }
90
+ catch (error) {
91
+ throw (0, core_1.getError)({
92
+ statusCode: common_1.HTTP.ResultCodes.RS_4.BadRequest,
93
+ message: `${label} cannot be sent as JSON | ${error instanceof Error ? error.message : String(error)}`,
94
+ });
95
+ }
96
+ }
97
+ /**
98
+ * A list is a bare array or the `{ count, data }` envelope; `one` is never unwrapped, since a record
99
+ * may carry `data` and `count` columns. The envelope `count` is the page size, never the total.
100
+ *
101
+ * Anything else asked for as a list throws: counting it as one row is how `existsWith` answers true
102
+ * for an empty result and a page reports a length it does not have.
103
+ */
104
+ static unwrapRows(opts) {
105
+ const { body, shape, url } = opts;
106
+ if (shape === 'one' || Array.isArray(body)) {
107
+ return body;
108
+ }
109
+ if (body && typeof body === 'object' && 'data' in body && 'count' in body) {
110
+ return body.data;
111
+ }
112
+ throw (0, core_1.getError)({
113
+ statusCode: common_1.HTTP.ResultCodes.RS_5.InternalServerError,
114
+ message: `[read] A list was asked for and the response is neither an array nor a { count, data } envelope | ${HttpWire.describeUrl({ url })}`,
115
+ });
116
+ }
117
+ /**
118
+ * The path a message names - never the host or the query. A server that relays this error would
119
+ * otherwise send an internal host and a filter's values to its own clients. 414/431 add the length.
120
+ */
121
+ static describeUrl(opts) {
122
+ const { url, status } = opts;
123
+ const { pathname } = new URL(url);
124
+ const isTooLong = status === common_1.HTTP.ResultCodes.RS_4.URITooLong ||
125
+ status === common_1.HTTP.ResultCodes.RS_4.RequestHeaderFieldsTooLarge;
126
+ return isTooLong
127
+ ? `${pathname} (${url.length} chars) | The URL is too long for a GET - split the filter (a long inq) into smaller requests.`
128
+ : pathname;
129
+ }
130
+ }
131
+ exports.HttpWire = HttpWire;
132
+ //# sourceMappingURL=wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../../../src/http/common/wire.ts"],"names":[],"mappings":";;;AAAA,0DAAqD;AACrD,sDAAuD;AAGvD;;;GAGG;AACH,MAAa,QAAQ;IACnB,MAAM,CAAC,aAAa,CAAC,KAAc;QACjC,OAAO,CACL,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,CAC1F,CAAC;IACJ,CAAC;IAED,oEAAoE;IACpE,MAAM,CAAC,MAAM,CAAC,KAAc;QAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvE,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,eAAe,CAAC,IAAgC;QACrD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QAEzB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GACV,OAAO,YAAY,OAAO;YACxB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;gBACtB,CAAC,CAAC,OAAO;gBACT,CAAC,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AK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAS,CAAC;QACnB,CAAC;QAED,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YAC1E,OAAQ,IAAoB,CAAC,IAAI,CAAC;QACpC,CAAC;QAED,MAAM,IAAA,eAAQ,EAAC;YACb,UAAU,EAAE,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;YACrD,OAAO,EAAE,qGAAqG,QAAQ,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;SAC9I,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,IAAsC;QACvD,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAC7B,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,MAAM,SAAS,GACb,MAAM,KAAK,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;YAC3C,MAAM,KAAK,aAAI,CAAC,WAAW,CAAC,IAAI,CAAC,2BAA2B,CAAC;QAE/D,OAAO,SAAS;YACd,CAAC,CAAC,GAAG,QAAQ,KAAK,GAAG,CAAC,MAAM,gGAAgG;YAC5H,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC;CACF;AA1JD,4BA0JC"}
@@ -1,6 +1,6 @@
1
1
  import { AbstractDataSource } from '@venizia/ignis-kernel/repository';
2
2
  import { NodeFetchNetworkRequest } from '@venizia/ignis-helpers/core';
3
- import type { IAuthToken, IHttpDataSourceSettings, IHttpReadResult, IHttpWriteResult, THttpBody, THttpHeaders } from './common/types';
3
+ import type { IAuthToken, IHttpCallOptions, IHttpDataSourceSettings, IHttpReadResult, IHttpRequestContext, IHttpWriteResult, THttpBody } from './common/types';
4
4
  /** Reads an IGNIS REST server through the repository contract. Targets IGNIS, not any REST API. */
5
5
  export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSettings> {
6
6
  name: string;
@@ -9,7 +9,7 @@ export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSe
9
9
  protected network: NodeFetchNetworkRequest;
10
10
  /** Normalised once: every request copies these, never re-parses `settings.headers`. */
11
11
  protected configuredHeaders: Array<[string, string]>;
12
- /** Decided once: a relative baseUrl (`/api`) needs a location to resolve against on every request. */
12
+ /** Decided once: a relative baseUrl (`/api`) is resolved against the page origin on every request. */
13
13
  protected isRelativeBaseUrl: boolean;
14
14
  constructor(opts: IHttpDataSourceSettings & {
15
15
  name?: string;
@@ -18,11 +18,18 @@ export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSe
18
18
  getCapabilities(): {
19
19
  transactions: boolean;
20
20
  };
21
- protected resolveAuthToken(): IAuthToken | undefined;
21
+ protected resolveAuthToken(opts: {
22
+ context: IHttpRequestContext;
23
+ }): IAuthToken | undefined;
24
+ /** Re-run on every send, so a header the app changed since the last request is the one sent. */
25
+ protected resolveHeaders(opts: {
26
+ context: IHttpRequestContext;
27
+ }): Array<[string, string]>;
22
28
  protected buildHeaders(opts: {
23
29
  token?: IAuthToken;
24
30
  requestHeaders?: Array<[string, string]>;
25
31
  isJsonBody?: boolean;
32
+ isFormDataBody?: boolean;
26
33
  }): Headers;
27
34
  buildUrl(opts: {
28
35
  paths: Array<string>;
@@ -37,9 +44,29 @@ export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSe
37
44
  query?: Record<string, unknown>;
38
45
  method?: string;
39
46
  body?: THttpBody;
40
- headers?: THttpHeaders;
41
- }): Promise<Response>;
42
- /** A failed response as an error carrying the server's own status, message and message code. */
47
+ } & IHttpCallOptions): Promise<Response>;
48
+ /** `request` on a URL already built: `read` and `write` serialise a long query once, not per use. */
49
+ protected sendRequest(opts: {
50
+ paths: Array<string>;
51
+ url: string;
52
+ method?: string;
53
+ body?: THttpBody;
54
+ } & IHttpCallOptions): Promise<Response>;
55
+ /**
56
+ * The body as JSON, `null` when there is none; a body that is not JSON is the server's fault, named
57
+ * as such. Its content stays out of the message, which a relaying server may pass to its clients.
58
+ */
59
+ protected readJsonBody(opts: {
60
+ response: Response;
61
+ url: string;
62
+ verb: string;
63
+ }): Promise<any>;
64
+ /**
65
+ * A failed response as the error the server threw: its status, code, args and text, and its
66
+ * `extra` with the `requestId` added. `message` adds where it failed, for logs; `normalized.text`
67
+ * stays the server's, for display - `HTTP <status>` when the server sent none. `cause` is the server's `details.cause` - a 422's per-field
68
+ * issues, `{ path, message, code }`.
69
+ */
43
70
  protected toResponseError(opts: {
44
71
  response: Response;
45
72
  url: string;
@@ -55,7 +82,7 @@ export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSe
55
82
  shape?: 'list' | 'one';
56
83
  method?: string;
57
84
  body?: THttpBody;
58
- }): Promise<IHttpReadResult<R>>;
85
+ } & IHttpCallOptions): Promise<IHttpReadResult<R>>;
59
86
  /**
60
87
  * A write, and what it answered: the body as the rows, the count from `x-response-count`. The
61
88
  * connector asks for bare rows, so an IGNIS write answers the row or the rows, never the envelope.
@@ -65,7 +92,6 @@ export declare class HttpDataSource extends AbstractDataSource<IHttpDataSourceSe
65
92
  query?: Record<string, unknown>;
66
93
  method: string;
67
94
  body?: THttpBody;
68
- headers?: THttpHeaders;
69
- }): Promise<IHttpWriteResult<R>>;
95
+ } & IHttpCallOptions): Promise<IHttpWriteResult<R>>;
70
96
  }
71
97
  //# sourceMappingURL=datasource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../../src/http/datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC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