@outfoxx/sunday 2.0.0-beta.2 → 2.0.0-beta.21

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 (141) hide show
  1. package/README.md +346 -4
  2. package/build/authentication-adapter.d.ts +21 -0
  3. package/build/authentication-adapter.js +74 -0
  4. package/build/authentication-adapter.js.map +1 -0
  5. package/build/bearer-token-rejection-adapter.d.ts +6 -0
  6. package/build/bearer-token-rejection-adapter.js +25 -0
  7. package/build/bearer-token-rejection-adapter.js.map +1 -0
  8. package/build/client-settings.d.ts +22 -0
  9. package/build/client-settings.js +180 -0
  10. package/build/client-settings.js.map +1 -0
  11. package/build/credentials.d.ts +58 -0
  12. package/build/credentials.js +51 -0
  13. package/build/credentials.js.map +1 -0
  14. package/build/event-parser.d.ts +23 -8
  15. package/build/event-parser.js +93 -121
  16. package/build/event-parser.js.map +1 -1
  17. package/build/fetch-copy.d.ts +15 -0
  18. package/build/fetch-copy.js +71 -0
  19. package/build/fetch-copy.js.map +1 -0
  20. package/build/fetch-event-source.d.ts +18 -8
  21. package/build/fetch-event-source.js +241 -144
  22. package/build/fetch-event-source.js.map +1 -1
  23. package/build/fetch-oauth-token-provider.d.ts +28 -0
  24. package/build/fetch-oauth-token-provider.js +213 -0
  25. package/build/fetch-oauth-token-provider.js.map +1 -0
  26. package/build/fetch-transport.d.ts +15 -1
  27. package/build/fetch-transport.js +142 -132
  28. package/build/fetch-transport.js.map +1 -1
  29. package/build/fetch.js +24 -10
  30. package/build/fetch.js.map +1 -1
  31. package/build/header-token-adapters.d.ts +28 -0
  32. package/build/header-token-adapters.js +121 -0
  33. package/build/header-token-adapters.js.map +1 -0
  34. package/build/index.d.ts +23 -1
  35. package/build/index.js +22 -1
  36. package/build/index.js.map +1 -1
  37. package/build/media-type-codecs/binary-decoder.d.ts +1 -0
  38. package/build/media-type-codecs/binary-decoder.js +4 -11
  39. package/build/media-type-codecs/binary-decoder.js.map +1 -1
  40. package/build/media-type-codecs/cbor-encoder.d.ts +2 -2
  41. package/build/media-type-codecs/cbor-encoder.js +2 -2
  42. package/build/media-type-codecs/cbor-encoder.js.map +1 -1
  43. package/build/media-type-codecs/json-encoder.d.ts +3 -3
  44. package/build/media-type-codecs/json-encoder.js +4 -4
  45. package/build/media-type-codecs/json-encoder.js.map +1 -1
  46. package/build/media-type-codecs/media-type-encoder.d.ts +3 -3
  47. package/build/media-type-codecs/media-type-encoder.js.map +1 -1
  48. package/build/media-type-codecs/www-form-url-encoder.d.ts +2 -2
  49. package/build/media-type-codecs/www-form-url-encoder.js +2 -2
  50. package/build/media-type-codecs/www-form-url-encoder.js.map +1 -1
  51. package/build/model-construction.d.ts +5 -0
  52. package/build/model-construction.js +40 -0
  53. package/build/model-construction.js.map +1 -0
  54. package/build/model-schema.d.ts +9 -0
  55. package/build/model-schema.js +131 -0
  56. package/build/model-schema.js.map +1 -0
  57. package/build/oauth-wire.d.ts +33 -0
  58. package/build/oauth-wire.js +143 -0
  59. package/build/oauth-wire.js.map +1 -0
  60. package/build/operation.d.ts +3 -1
  61. package/build/problem.d.ts +39 -16
  62. package/build/problem.js +88 -32
  63. package/build/problem.js.map +1 -1
  64. package/build/request-adapter.d.ts +8 -0
  65. package/build/request-adapter.js +15 -0
  66. package/build/request-adapter.js.map +1 -0
  67. package/build/request-adapters-compat.d.ts +6 -0
  68. package/build/request-adapters-compat.js +19 -0
  69. package/build/request-adapters-compat.js.map +1 -0
  70. package/build/request-adapters.d.ts +13 -23
  71. package/build/request-adapters.js +40 -31
  72. package/build/request-adapters.js.map +1 -1
  73. package/build/request-body.d.ts +24 -0
  74. package/build/request-body.js +104 -0
  75. package/build/request-body.js.map +1 -0
  76. package/build/request-cancellation-error.d.ts +13 -0
  77. package/build/request-cancellation-error.js +43 -0
  78. package/build/request-cancellation-error.js.map +1 -0
  79. package/build/request-context.d.ts +4 -0
  80. package/build/request-context.js +29 -0
  81. package/build/request-context.js.map +1 -0
  82. package/build/request-execution.d.ts +13 -0
  83. package/build/request-execution.js +80 -0
  84. package/build/request-execution.js.map +1 -0
  85. package/build/request-security-bindings.d.ts +5 -0
  86. package/build/request-security-bindings.js +30 -0
  87. package/build/request-security-bindings.js.map +1 -0
  88. package/build/request-security.d.ts +20 -0
  89. package/build/request-security.js +223 -0
  90. package/build/request-security.js.map +1 -0
  91. package/build/request-validation-error.d.ts +4 -0
  92. package/build/request-validation-error.js +21 -0
  93. package/build/request-validation-error.js.map +1 -0
  94. package/build/response-adapter.d.ts +10 -0
  95. package/build/response-adapter.js +15 -0
  96. package/build/response-adapter.js.map +1 -0
  97. package/build/response-adapters.d.ts +13 -0
  98. package/build/response-adapters.js +75 -0
  99. package/build/response-adapters.js.map +1 -0
  100. package/build/schema-builtins.js +11 -21
  101. package/build/schema-builtins.js.map +1 -1
  102. package/build/schema-runtime.d.ts +8 -1
  103. package/build/schema-runtime.js +12 -3
  104. package/build/schema-runtime.js.map +1 -1
  105. package/build/security-binding.d.ts +22 -0
  106. package/build/security-binding.js +15 -0
  107. package/build/security-binding.js.map +1 -0
  108. package/build/standard-authentication-adapter.d.ts +18 -0
  109. package/build/standard-authentication-adapter.js +58 -0
  110. package/build/standard-authentication-adapter.js.map +1 -0
  111. package/build/token-manager.d.ts +42 -0
  112. package/build/token-manager.js +276 -0
  113. package/build/token-manager.js.map +1 -0
  114. package/build/token-provider.d.ts +52 -0
  115. package/build/token-provider.js +102 -0
  116. package/build/token-provider.js.map +1 -0
  117. package/build/transport.d.ts +10 -3
  118. package/build/unknown-variant.d.ts +12 -0
  119. package/build/unknown-variant.js +45 -0
  120. package/build/unknown-variant.js.map +1 -0
  121. package/build/url-template.d.ts +3 -0
  122. package/build/url-template.js +30 -2
  123. package/build/url-template.js.map +1 -1
  124. package/build/util/abort.d.ts +3 -0
  125. package/build/util/abort.js +42 -0
  126. package/build/util/abort.js.map +1 -0
  127. package/build/util/base64.d.ts +4 -0
  128. package/build/util/base64.js +46 -0
  129. package/build/util/base64.js.map +1 -0
  130. package/build/util/native-fetch.d.ts +2 -0
  131. package/build/util/native-fetch.js +39 -0
  132. package/build/util/native-fetch.js.map +1 -0
  133. package/build/util/nullify.js +12 -5
  134. package/build/util/nullify.js.map +1 -1
  135. package/build/util/owned-body.d.ts +12 -0
  136. package/build/util/owned-body.js +243 -0
  137. package/build/util/owned-body.js.map +1 -0
  138. package/build/util/status-title.d.ts +2 -0
  139. package/build/util/status-title.js +83 -0
  140. package/build/util/status-title.js.map +1 -0
  141. package/package.json +18 -6
@@ -0,0 +1,6 @@
1
+ /** Compatibility entry point for the original public request-adapters subpath.
2
+ * Internal transports import the token-independent chain module directly.
3
+ */
4
+ export * from './request-adapters.js';
5
+ export { HeaderTokenAuthorizingAdapter, StaticHeaderTokenAuthorizingAdapter, RefreshingHeaderTokenAuthorizingAdapter, } from './header-token-adapters.js';
6
+ export type { TokenAuthorization } from './header-token-adapters.js';
@@ -0,0 +1,19 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /** Compatibility entry point for the original public request-adapters subpath.
15
+ * Internal transports import the token-independent chain module directly.
16
+ */
17
+ export * from './request-adapters.js';
18
+ export { HeaderTokenAuthorizingAdapter, StaticHeaderTokenAuthorizingAdapter, RefreshingHeaderTokenAuthorizingAdapter, } from './header-token-adapters.js';
19
+ //# sourceMappingURL=request-adapters-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-adapters-compat.js","sourceRoot":"","sources":["../src/request-adapters-compat.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;GAEG;AACH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,6BAA6B,EAC7B,mCAAmC,EACnC,uCAAuC,GACxC,MAAM,4BAA4B,CAAC"}
@@ -1,23 +1,13 @@
1
- import { RequestAdapter, Transport } from './transport.js';
2
- export declare abstract class HeaderTokenAuthorizingAdapter implements RequestAdapter {
3
- header: string;
4
- tokenHeaderType: string;
5
- applyToken(request: Request, accessToken: string): Request;
6
- abstract adapt(transport: Transport, request: Request): Promise<Request>;
7
- }
8
- export declare class StaticHeaderTokenAuthorizingAdapter extends HeaderTokenAuthorizingAdapter {
9
- private readonly accessToken;
10
- constructor(accessToken: string);
11
- adapt(_transport: Transport, request: Request): Promise<Request>;
12
- }
13
- export interface TokenAuthorization {
14
- token: string;
15
- expires: Date;
16
- }
17
- export declare class RefreshingHeaderTokenAuthorizingAdapter extends HeaderTokenAuthorizingAdapter {
18
- private readonly refresh;
19
- private authorization?;
20
- constructor(refresh: (transport: Transport) => Promise<TokenAuthorization>);
21
- shouldRefresh(): boolean;
22
- adapt(transport: Transport, request: Request): Promise<Request>;
23
- }
1
+ import { RequestAdapter } from './request-adapter.js';
2
+ /** Flat, ordered composition; adapters may be ordinary objects with an adapt method. */
3
+ export declare class RequestAdapters implements RequestAdapter {
4
+ readonly adapters: readonly RequestAdapter[];
5
+ constructor(...adapters: readonly RequestAdapter[]);
6
+ /** Appends adapters without nesting execution pipelines. */
7
+ chainTo(...next: readonly RequestAdapter[]): RequestAdapters;
8
+ adapt(request: Request): Promise<Request>;
9
+ }
10
+ /** @internal Reports the effective signal while keeping invocation state out of the shared chain. */
11
+ export declare function adaptRequest(adapters: readonly RequestAdapter[], request: Request, observeSignal?: (signal: AbortSignal) => void): Promise<Request>;
12
+ /** Composes plain object adapters without requiring inheritance or modifying native prototypes. */
13
+ export declare function chainRequestAdapters(...adapters: readonly RequestAdapter[]): RequestAdapters;
@@ -11,43 +11,52 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- export class HeaderTokenAuthorizingAdapter {
15
- header = 'Authorization';
16
- tokenHeaderType = 'Bearer';
17
- applyToken(request, accessToken) {
18
- const requestClone = request.clone();
19
- requestClone.headers.set(this.header, `${this.tokenHeaderType} ${accessToken}`);
20
- return requestClone;
14
+ import { inheritRequestContext } from './request-context.js';
15
+ import { bodyReads } from './util/owned-body.js';
16
+ import { copyRequest } from './fetch-copy.js';
17
+ import { withAbort, discardBody } from './util/abort.js';
18
+ /** Flat, ordered composition; adapters may be ordinary objects with an adapt method. */
19
+ export class RequestAdapters {
20
+ adapters;
21
+ constructor(...adapters) {
22
+ this.adapters = Object.freeze(adapters.flatMap((adapter) => adapter instanceof RequestAdapters ? adapter.adapters : [adapter]));
21
23
  }
22
- }
23
- export class StaticHeaderTokenAuthorizingAdapter extends HeaderTokenAuthorizingAdapter {
24
- accessToken;
25
- constructor(accessToken) {
26
- super();
27
- this.accessToken = accessToken;
24
+ /** Appends adapters without nesting execution pipelines. */
25
+ chainTo(...next) {
26
+ return new RequestAdapters(this, ...next);
28
27
  }
29
- async adapt(_transport, request) {
30
- return this.applyToken(request, this.accessToken);
28
+ async adapt(request) {
29
+ return adaptRequest(this.adapters, request);
31
30
  }
32
31
  }
33
- export class RefreshingHeaderTokenAuthorizingAdapter extends HeaderTokenAuthorizingAdapter {
34
- refresh;
35
- authorization;
36
- constructor(refresh) {
37
- super();
38
- this.refresh = refresh;
39
- }
40
- shouldRefresh() {
41
- if (!this.authorization) {
42
- return true;
32
+ /** @internal Reports the effective signal while keeping invocation state out of the shared chain. */
33
+ export async function adaptRequest(adapters, request, observeSignal = () => { }) {
34
+ let signal = request.signal;
35
+ try {
36
+ bodyReads(request);
37
+ for (const adapter of adapters) {
38
+ const original = request;
39
+ request = await withAbort(() => adapter.adapt(request), signal, discardBody);
40
+ inheritRequestContext(original, request);
41
+ if (request.signal !== signal)
42
+ request = copyRequest(request, {
43
+ signal: AbortSignal.any([signal, request.signal]),
44
+ });
45
+ bodyReads(request);
46
+ signal = request.signal;
47
+ observeSignal(signal);
48
+ signal.throwIfAborted();
43
49
  }
44
- return this.authorization.expires.getTime() <= Date.now();
50
+ signal.throwIfAborted();
51
+ return request;
45
52
  }
46
- async adapt(transport, request) {
47
- if (!this.authorization || this.shouldRefresh()) {
48
- this.authorization = await this.refresh(transport);
49
- }
50
- return this.applyToken(request, this.authorization.token);
53
+ catch (error) {
54
+ discardBody(request, error);
55
+ throw error;
51
56
  }
52
57
  }
58
+ /** Composes plain object adapters without requiring inheritance or modifying native prototypes. */
59
+ export function chainRequestAdapters(...adapters) {
60
+ return new RequestAdapters(...adapters);
61
+ }
53
62
  //# sourceMappingURL=request-adapters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-adapters.js","sourceRoot":"","sources":["../src/request-adapters.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,MAAM,OAAgB,6BAA6B;IACjD,MAAM,GAAG,eAAe,CAAC;IACzB,eAAe,GAAG,QAAQ,CAAC;IAE3B,UAAU,CAAC,OAAgB,EAAE,WAAmB;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QACrC,YAAY,CAAC,OAAO,CAAC,GAAG,CACtB,IAAI,CAAC,MAAM,EACX,GAAG,IAAI,CAAC,eAAe,IAAI,WAAW,EAAE,CACzC,CAAC;QACF,OAAO,YAAY,CAAC;IAC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BAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACzC,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;gBAC3B,OAAO,GAAG,WAAW,CAAC,OAAO,EAAE;oBAC7B,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;iBAClD,CAAC,CAAC;YACL,SAAS,CAAC,OAAO,CAAC,CAAC;YACnB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YACxB,aAAa,CAAC,MAAM,CAAC,CAAC;YACtB,MAAM,CAAC,cAAc,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,oBAAoB,CAClC,GAAG,QAAmC;IAEtC,OAAO,IAAI,eAAe,CAAC,GAAG,QAAQ,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,24 @@
1
+ /** Cancellation and memory bound for converting an upload stream into a Blob. */
2
+ export interface RequestBodyBufferOptions {
3
+ /** Cancels reading and preserves the original abort reason. */
4
+ signal?: AbortSignal;
5
+ /** Maximum buffered bytes; defaults to 16 MiB. Does not limit native streaming uploads. */
6
+ maxBytes?: number;
7
+ }
8
+ /**
9
+ * Checks runtime support without sending a request. This does not test server/protocol support.
10
+ * The result is cached for the current runtime's native Fetch implementation.
11
+ */
12
+ export declare function supportsStreamingUploads(): boolean;
13
+ /**
14
+ * Prepares a BodyInit before constructing a Request, buffering streams only when unsupported.
15
+ * Adapters replacing bodies should call this before copyRequest/new Request. Supported streams
16
+ * retain streaming and receive cooperative cancellation; other bodies pass through unchanged.
17
+ * This does not confer permission to retry.
18
+ */
19
+ export declare function prepareRequestBody<T extends BodyInit | null | undefined>(body: T, options?: RequestBodyBufferOptions): Promise<T | Blob | ReadableStream<Uint8Array>>;
20
+ /**
21
+ * Consumes a byte stream into a bounded Blob. Cancels the source on failure without waiting for
22
+ * its cleanup, and rethrows the original read error or abort reason. No stream tee or retry occurs.
23
+ */
24
+ export declare function bufferToBlob(stream: ReadableStream<Uint8Array>, { signal, maxBytes }?: RequestBodyBufferOptions): Promise<Blob>;
@@ -0,0 +1,104 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { ownBody } from './util/owned-body.js';
15
+ let streamingUploadsSupported;
16
+ /**
17
+ * Checks runtime support without sending a request. This does not test server/protocol support.
18
+ * The result is cached for the current runtime's native Fetch implementation.
19
+ */
20
+ export function supportsStreamingUploads() {
21
+ if (streamingUploadsSupported !== undefined)
22
+ return streamingUploadsSupported;
23
+ let duplexAccessed = false;
24
+ try {
25
+ const request = new Request('https://localhost/', {
26
+ method: 'POST',
27
+ body: new ReadableStream({
28
+ start(controller) {
29
+ controller.close();
30
+ },
31
+ }),
32
+ get duplex() {
33
+ duplexAccessed = true;
34
+ return 'half';
35
+ },
36
+ });
37
+ // Bun supports streaming uploads without reading duplex. Firefox instead coerces the
38
+ // stream to a string and adds Content-Type; older WebKit accepts it but ignores duplex.
39
+ streamingUploadsSupported =
40
+ !request.headers.has('Content-Type') &&
41
+ (duplexAccessed || 'Bun' in globalThis);
42
+ }
43
+ catch {
44
+ streamingUploadsSupported = false;
45
+ }
46
+ return streamingUploadsSupported;
47
+ }
48
+ /**
49
+ * Prepares a BodyInit before constructing a Request, buffering streams only when unsupported.
50
+ * Adapters replacing bodies should call this before copyRequest/new Request. Supported streams
51
+ * retain streaming and receive cooperative cancellation; other bodies pass through unchanged.
52
+ * This does not confer permission to retry.
53
+ */
54
+ export async function prepareRequestBody(body, options = {}) {
55
+ if (body instanceof ReadableStream) {
56
+ if (!supportsStreamingUploads())
57
+ return bufferToBlob(body, options);
58
+ const stream = ownBody(body, options.signal);
59
+ options.signal?.throwIfAborted();
60
+ return stream;
61
+ }
62
+ options.signal?.throwIfAborted();
63
+ return body;
64
+ }
65
+ /**
66
+ * Consumes a byte stream into a bounded Blob. Cancels the source on failure without waiting for
67
+ * its cleanup, and rethrows the original read error or abort reason. No stream tee or retry occurs.
68
+ */
69
+ export async function bufferToBlob(stream, { signal, maxBytes = 16 * 1024 * 1024 } = {}) {
70
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 0) {
71
+ throw new RangeError('maxBytes must be a non-negative safe integer');
72
+ }
73
+ const reader = ownBody(stream, signal).getReader();
74
+ const parts = [];
75
+ let size = 0;
76
+ try {
77
+ signal?.throwIfAborted();
78
+ while (true) {
79
+ const { done, value } = await reader.read();
80
+ if (done)
81
+ break;
82
+ if (!(value instanceof Uint8Array)) {
83
+ throw new TypeError('Upload streams must produce Uint8Array chunks');
84
+ }
85
+ if (value.byteLength > maxBytes - size) {
86
+ throw new RangeError(`Buffered request body exceeds ${maxBytes} bytes`);
87
+ }
88
+ // Snapshot each chunk before asking the producer for more; it may reuse its buffer.
89
+ if (value.byteLength)
90
+ parts.push(new Uint8Array(value));
91
+ size += value.byteLength;
92
+ }
93
+ signal?.throwIfAborted();
94
+ return new Blob(parts);
95
+ }
96
+ catch (error) {
97
+ void reader.cancel(error).catch(() => undefined);
98
+ throw error;
99
+ }
100
+ finally {
101
+ reader.releaseLock();
102
+ }
103
+ }
104
+ //# sourceMappingURL=request-body.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-body.js","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AAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACxD,IAAI,IAAI,KAAK,CAAC,UAAU,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACjD,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /** A runtime marker shared by separate copies of Sunday in the same JavaScript realm. */
2
+ export declare const requestCancellation: unique symbol;
3
+ /** An unconditional stop signal. Sunday rethrows the original instance without retry or reconnect. */
4
+ export declare class RequestCancellationError extends Error {
5
+ readonly [requestCancellation] = true;
6
+ constructor(message?: string, options?: ErrorOptions);
7
+ }
8
+ /** Recognizes stop errors, including application errors implementing the exported runtime marker. */
9
+ export declare function isRequestCancellationError(error: unknown): boolean;
10
+ /** Native abort errors also stop an invocation; an absent marker never authorizes a retry. */
11
+ export declare function isRequestStopped(error: unknown): boolean;
12
+ /** @internal Caller cancellation takes precedence without inspecting application error causes. */
13
+ export declare function requestFailure(error: unknown, signal?: AbortSignal): unknown;
@@ -0,0 +1,43 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /** A runtime marker shared by separate copies of Sunday in the same JavaScript realm. */
15
+ export const requestCancellation = Symbol.for('@outfoxx/sunday/RequestCancellationError');
16
+ /** An unconditional stop signal. Sunday rethrows the original instance without retry or reconnect. */
17
+ export class RequestCancellationError extends Error {
18
+ [requestCancellation] = true;
19
+ constructor(message = 'Request cancelled', options) {
20
+ super(message, options);
21
+ this.name = 'RequestCancellationError';
22
+ }
23
+ }
24
+ /** Recognizes stop errors, including application errors implementing the exported runtime marker. */
25
+ export function isRequestCancellationError(error) {
26
+ return (typeof error === 'object' &&
27
+ error !== null &&
28
+ requestCancellation in error &&
29
+ error[requestCancellation] === true);
30
+ }
31
+ /** Native abort errors also stop an invocation; an absent marker never authorizes a retry. */
32
+ export function isRequestStopped(error) {
33
+ return (isRequestCancellationError(error) ||
34
+ (typeof error === 'object' &&
35
+ error !== null &&
36
+ 'name' in error &&
37
+ error.name === 'AbortError'));
38
+ }
39
+ /** @internal Caller cancellation takes precedence without inspecting application error causes. */
40
+ export function requestFailure(error, signal) {
41
+ return signal?.aborted ? signal.reason : error;
42
+ }
43
+ //# sourceMappingURL=request-cancellation-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-cancellation-error.js","sourceRoot":"","sources":["../src/request-cancellation-error.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,yFAAyF;AACzF,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAC3C,0CAA0C,CAC3C,CAAC;AAEF,sGAAsG;AACtG,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC;IAEtC,YAAY,OAAO,GAAG,mBAAmB,EAAE,OAAsB;QAC/D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,qGAAqG;AACrG,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACvD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,mBAAmB,IAAI,KAAK;QAC5B,KAAK,CAAC,mBAAmB,CAAC,KAAK,IAAI,CACpC,CAAC;AACJ,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,CACL,0BAA0B,CAAC,KAAK,CAAC;QACjC,CAAC,OAAO,KAAK,KAAK,QAAQ;YACxB,KAAK,KAAK,IAAI;YACd,MAAM,IAAI,KAAK;YACf,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAC/B,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,KAAc,EAAE,MAAoB;IACjE,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Application-owned metadata retained across Sunday request copies and adapter replacements. */
2
+ export declare function requestContext(request: Request): Map<symbol, unknown>;
3
+ /** @internal Preserve metadata while allowing an adapter to replace its own entries. */
4
+ export declare function inheritRequestContext(source: Request, target: Request): Request;
@@ -0,0 +1,29 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ const contexts = new WeakMap();
15
+ /** Application-owned metadata retained across Sunday request copies and adapter replacements. */
16
+ export function requestContext(request) {
17
+ let context = contexts.get(request);
18
+ if (!context) {
19
+ context = new Map();
20
+ contexts.set(request, context);
21
+ }
22
+ return context;
23
+ }
24
+ /** @internal Preserve metadata while allowing an adapter to replace its own entries. */
25
+ export function inheritRequestContext(source, target) {
26
+ contexts.set(target, new Map([...requestContext(source), ...requestContext(target)]));
27
+ return target;
28
+ }
29
+ //# sourceMappingURL=request-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.js","sourceRoot":"","sources":["../src/request-context.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAiC,CAAC;AAE9D,iGAAiG;AACjG,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,IAAI,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACpB,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,MAAe;IAEf,QAAQ,CAAC,GAAG,CACV,MAAM,EACN,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAChE,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { RequestAdapter } from './request-adapter.js';
2
+ import { ResponseAdapter } from './response-adapter.js';
3
+ import { SecurityBinding } from './security-binding.js';
4
+ /** @internal Shared configuration; receipts, cancellation, and retry state belong to each invocation. */
5
+ export declare class RequestExecution {
6
+ private readonly requests;
7
+ private readonly responses;
8
+ constructor(requestAdapter?: RequestAdapter, responseAdapter?: ResponseAdapter);
9
+ /** Materializes once; the consumer owns the resulting native request and its execution. */
10
+ export(request: Request, bindings: readonly SecurityBinding[]): Promise<Request>;
11
+ /** Executes one logical operation, including the caller's body consumption when provided. */
12
+ execute<T>(prepared: Request, bindings: readonly SecurityBinding[], consume: (response: Response, request: Request) => T | Promise<T>, observeSignal?: (signal: AbortSignal) => void): Promise<T>;
13
+ }
@@ -0,0 +1,80 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { nativeFetch } from './util/native-fetch.js';
15
+ import { copyRequest } from './fetch-copy.js';
16
+ import { RequestAdapters, adaptRequest } from './request-adapters.js';
17
+ import { ResponseAdapters, adaptResponse } from './response-adapters.js';
18
+ import { setRequestSecurityBindings } from './request-security-bindings.js';
19
+ import { requestFailure } from './request-cancellation-error.js';
20
+ import { discardBody, withAbort } from './util/abort.js';
21
+ /** @internal Shared configuration; receipts, cancellation, and retry state belong to each invocation. */
22
+ export class RequestExecution {
23
+ requests;
24
+ responses;
25
+ constructor(requestAdapter, responseAdapter) {
26
+ this.requests = new RequestAdapters(...(requestAdapter ? [requestAdapter] : []));
27
+ this.responses = new ResponseAdapters(...(responseAdapter ? [responseAdapter] : []));
28
+ }
29
+ /** Materializes once; the consumer owns the resulting native request and its execution. */
30
+ async export(request, bindings) {
31
+ try {
32
+ setRequestSecurityBindings(request, bindings);
33
+ return setRequestSecurityBindings(await this.requests.adapt(request), []);
34
+ }
35
+ catch (error) {
36
+ discardBody(request, error);
37
+ throw error;
38
+ }
39
+ }
40
+ /** Executes one logical operation, including the caller's body consumption when provided. */
41
+ async execute(prepared, bindings, consume, observeSignal = () => { }) {
42
+ const controller = new AbortController();
43
+ let signal = prepared.signal;
44
+ observeSignal(signal);
45
+ let sent = prepared;
46
+ let response;
47
+ try {
48
+ signal.throwIfAborted();
49
+ sent = setRequestSecurityBindings(copyRequest(prepared, { signal }), bindings);
50
+ sent = await adaptRequest(this.requests.adapters, sent, (effective) => {
51
+ signal = effective;
52
+ observeSignal(signal);
53
+ });
54
+ // Fetch does not expose intermediate redirect responses in browsers. Credentialed calls
55
+ // must return the redirect instead of forwarding credentials beyond their selected origin.
56
+ if (bindings.length ||
57
+ sent.headers.has('Authorization') ||
58
+ sent.headers.has('Cookie')) {
59
+ sent = copyRequest(sent, { redirect: 'manual', credentials: 'omit' });
60
+ }
61
+ const request = sent;
62
+ response = await withAbort(
63
+ // Keep cleanup cancellation separate from caller/adapter cancellation so an ordinary
64
+ // network failure remains eligible for the event source's reconnect policy.
65
+ () => nativeFetch(request, AbortSignal.any([request.signal, controller.signal])), request.signal, discardBody);
66
+ response = await adaptResponse(this.responses.adapters, response, request, true);
67
+ const accepted = response;
68
+ return await withAbort(() => consume(accepted, request), request.signal);
69
+ }
70
+ catch (error) {
71
+ const failure = requestFailure(error, signal);
72
+ controller.abort(failure);
73
+ if (response)
74
+ discardBody(response, failure);
75
+ discardBody(sent, failure);
76
+ throw failure;
77
+ }
78
+ }
79
+ }
80
+ //# sourceMappingURL=request-execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-execution.js","sourceRoot":"","sources":["../src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AqF;YACrF,4EAA4E;YAC5E,GAAG,EAAE,CACH,WAAW,CACT,OAAO,EACP,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CACrD,EACH,OAAO,CAAC,MAAM,EACd,WAAW,CACZ,CAAC;YACF,QAAQ,GAAG,MAAM,aAAa,CAC5B,IAAI,CAAC,SAAS,CAAC,QAAQ,EACvB,QAAQ,EACR,OAAO,EACP,IAAI,CACL,CAAC;YACF,MAAM,QAAQ,GAAG,QAAQ,CAAC;YAC1B,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAC9C,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC1B,IAAI,QAAQ;gBAAE,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7C,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC3B,MAAM,OAAO,CAAC;QAChB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import type { SecurityBinding } from './security-binding.js';
2
+ /** Returns operation security metadata for application-owned HTTP adapters, without token state. */
3
+ export declare function requestSecurityBindings(request: Request): readonly SecurityBinding[];
4
+ /** @internal Snapshots metadata without adding wire headers or credential receipts. */
5
+ export declare function setRequestSecurityBindings(request: Request, values: readonly SecurityBinding[]): Request;
@@ -0,0 +1,30 @@
1
+ // Copyright 2020 Outfox, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { requestContext } from './request-context.js';
15
+ const bindings = Symbol('operationSecurityBindings');
16
+ const empty = Object.freeze([]);
17
+ /** Returns operation security metadata for application-owned HTTP adapters, without token state. */
18
+ export function requestSecurityBindings(request) {
19
+ return (requestContext(request).get(bindings) ?? empty);
20
+ }
21
+ /** @internal Snapshots metadata without adding wire headers or credential receipts. */
22
+ export function setRequestSecurityBindings(request, values) {
23
+ requestContext(request).set(bindings, Object.freeze(values.map((value) => Object.freeze({
24
+ ...value,
25
+ scopes: Object.freeze([...value.scopes]),
26
+ transport: Object.freeze({ ...value.transport }),
27
+ }))));
28
+ return request;
29
+ }
30
+ //# sourceMappingURL=request-security-bindings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-security-bindings.js","sourceRoot":"","sources":["../src/request-security-bindings.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,gDAAgD;AAChD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,QAAQ,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AACrD,MAAM,KAAK,GAA+B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAE5D,oGAAoG;AACpG,MAAM,UAAU,uBAAuB,CACrC,OAAgB;IAEhB,OAAO,CACJ,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAEvB,IAAI,KAAK,CACxB,CAAC;AACJ,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,0BAA0B,CACxC,OAAgB,EAChB,MAAkC;IAElC,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,CACzB,QAAQ,EACR,MAAM,CAAC,MAAM,CACX,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,GAAG,KAAK;QACR,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACxC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;KACjD,CAAC,CACH,CACF,CACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { SecurityBinding } from './security-binding.js';
2
+ import { TokenLease } from './token-manager.js';
3
+ import { TokenProvider } from './token-provider.js';
4
+ /** Per-request credentials, retained only for conditional invalidation and bounded recovery. */
5
+ export interface AuthorizedRequest {
6
+ readonly request: Request;
7
+ readonly bindings: readonly SecurityBinding[];
8
+ readonly leases: readonly TokenLease[];
9
+ }
10
+ /** Adds all credentials atomically after every provider succeeds. */
11
+ export declare function authorizeRequest(request: Request, bindings: readonly SecurityBinding[], providers: Readonly<Record<string, TokenProvider>>, maxBufferedRequestBytes?: number): Promise<AuthorizedRequest>;
12
+ /** Recognizes explicit rejection of the bearer credential sent on this request. */
13
+ export declare function isBearerTokenRejection(request: Request, response: Response): boolean;
14
+ /** Returns only bearer receipts rejected by an invalid-token challenge, preserving other conjuncts. */
15
+ export declare function rejectedBearerLeases(request: AuthorizedRequest): readonly TokenLease[];
16
+ /** Removes query credentials from responses before error translation or diagnostic rendering. */
17
+ export declare function redactSecurityResponse(response: Response, bindings: readonly SecurityBinding[]): Response;
18
+ export declare function hasInvalidBearerChallenge(header: string): boolean;
19
+ /** Reports all matching rejections, including unsafe requests and exhausted recovery budgets. */
20
+ export declare function rejectCredentials(request: AuthorizedRequest, response: Response): Promise<void>;