@outfoxx/sunday 2.0.0-beta.1 → 2.0.0-beta.11

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 (85) hide show
  1. package/README.md +94 -0
  2. package/build/client-settings.d.ts +23 -0
  3. package/build/client-settings.js +150 -0
  4. package/build/client-settings.js.map +1 -0
  5. package/build/credentials.d.ts +58 -0
  6. package/build/credentials.js +51 -0
  7. package/build/credentials.js.map +1 -0
  8. package/build/event-parser.d.ts +2 -0
  9. package/build/event-parser.js.map +1 -1
  10. package/build/fetch-event-source.d.ts +14 -5
  11. package/build/fetch-event-source.js +109 -44
  12. package/build/fetch-event-source.js.map +1 -1
  13. package/build/fetch-oauth-token-provider.d.ts +28 -0
  14. package/build/fetch-oauth-token-provider.js +171 -0
  15. package/build/fetch-oauth-token-provider.js.map +1 -0
  16. package/build/fetch-transport.d.ts +8 -0
  17. package/build/fetch-transport.js +84 -15
  18. package/build/fetch-transport.js.map +1 -1
  19. package/build/fetch.js +3 -2
  20. package/build/fetch.js.map +1 -1
  21. package/build/index.d.ts +12 -0
  22. package/build/index.js +12 -0
  23. package/build/index.js.map +1 -1
  24. package/build/media-type-codecs/cbor-encoder.d.ts +2 -2
  25. package/build/media-type-codecs/cbor-encoder.js +2 -2
  26. package/build/media-type-codecs/cbor-encoder.js.map +1 -1
  27. package/build/media-type-codecs/json-encoder.d.ts +3 -3
  28. package/build/media-type-codecs/json-encoder.js +4 -4
  29. package/build/media-type-codecs/json-encoder.js.map +1 -1
  30. package/build/media-type-codecs/media-type-encoder.d.ts +3 -3
  31. package/build/media-type-codecs/media-type-encoder.js.map +1 -1
  32. package/build/media-type-codecs/www-form-url-encoder.d.ts +2 -2
  33. package/build/media-type-codecs/www-form-url-encoder.js +2 -2
  34. package/build/media-type-codecs/www-form-url-encoder.js.map +1 -1
  35. package/build/model-construction.d.ts +5 -0
  36. package/build/model-construction.js +40 -0
  37. package/build/model-construction.js.map +1 -0
  38. package/build/model-schema.d.ts +9 -0
  39. package/build/model-schema.js +131 -0
  40. package/build/model-schema.js.map +1 -0
  41. package/build/oauth-wire.d.ts +33 -0
  42. package/build/oauth-wire.js +143 -0
  43. package/build/oauth-wire.js.map +1 -0
  44. package/build/operation.d.ts +11 -1
  45. package/build/operation.js +3 -0
  46. package/build/operation.js.map +1 -1
  47. package/build/problem.js +2 -1
  48. package/build/problem.js.map +1 -1
  49. package/build/request-security.d.ts +16 -0
  50. package/build/request-security.js +167 -0
  51. package/build/request-security.js.map +1 -0
  52. package/build/request-validation-error.d.ts +4 -0
  53. package/build/request-validation-error.js +21 -0
  54. package/build/request-validation-error.js.map +1 -0
  55. package/build/schema-builtins.js +11 -21
  56. package/build/schema-builtins.js.map +1 -1
  57. package/build/schema-runtime.d.ts +8 -1
  58. package/build/schema-runtime.js +12 -3
  59. package/build/schema-runtime.js.map +1 -1
  60. package/build/security-binding.d.ts +22 -0
  61. package/build/security-binding.js +15 -0
  62. package/build/security-binding.js.map +1 -0
  63. package/build/streaming-body.d.ts +21 -0
  64. package/build/streaming-body.js +65 -0
  65. package/build/streaming-body.js.map +1 -0
  66. package/build/token-manager-factory.d.ts +9 -0
  67. package/build/token-manager-factory.js +15 -0
  68. package/build/token-manager-factory.js.map +1 -0
  69. package/build/token-manager.d.ts +33 -0
  70. package/build/token-manager.js +199 -0
  71. package/build/token-manager.js.map +1 -0
  72. package/build/token-provider.d.ts +44 -0
  73. package/build/token-provider.js +31 -0
  74. package/build/token-provider.js.map +1 -0
  75. package/build/transport.d.ts +5 -0
  76. package/build/unknown-variant.d.ts +12 -0
  77. package/build/unknown-variant.js +45 -0
  78. package/build/unknown-variant.js.map +1 -0
  79. package/build/url-template.d.ts +3 -0
  80. package/build/url-template.js +30 -2
  81. package/build/url-template.js.map +1 -1
  82. package/build/util/base64.d.ts +4 -0
  83. package/build/util/base64.js +46 -0
  84. package/build/util/base64.js.map +1 -0
  85. package/package.json +6 -2
package/README.md CHANGED
@@ -37,3 +37,97 @@ Package Name:
37
37
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
38
  See the License for the specific language governing permissions and
39
39
  limitations under the License.
40
+
41
+ ## Profiled credentials
42
+
43
+ Generated request specifications select `SecurityBinding` entries. Register application providers with
44
+ one shared `TokenManager` and pass it as `new FetchTransport(baseUrl, {tokenManager})`. Client secrets,
45
+ authorization codes, token storage, and interactive login remain application bindings.
46
+
47
+ `FetchOAuthTokenProvider` exchanges `clientCredentials` and application-authorized `authorizationCode`
48
+ grants and rotates refresh tokens. Configure `identity`, `clientId`, and explicit client authentication
49
+ (`client_secret_basic`, `client_secret_post`, or public-client `none`). An interactive application supplies
50
+ a fresh `grantIdentity` and an `authorization(request, signal)` callback returning
51
+ `{code, redirectUri, codeVerifier}` after its S256 PKCE browser flow has verified state, issuer, and redirect
52
+ URI. Codes are consumed once even when exchange fails or is canceled. Discovery requires a separately
53
+ configured `issuer`; acquisition endpoint overrides cannot change it. Public authorization-code/PKCE
54
+ clients using `authentication: 'none'` accept discovery that omits `none`, including an absent or empty
55
+ authentication-method list. Supplied lists must contain only strings. Confidential clients still
56
+ require their configured method; an absent list defaults to `client_secret_basic`. Discovery and
57
+ endpoint trust are checked again on refresh. Other authentication methods use
58
+ an application `TokenProvider`. Token endpoints require HTTPS except for loopback development URLs.
59
+
60
+ External and static providers implement `configure` and `acquire`, optionally `refresh`. A `TokenSet`
61
+ contains `accessToken`, optional `expiresAt` in Unix milliseconds, and optional `refreshToken`. A returned
62
+ refresh token replaces the previous one; omission retains it. Expired interactive sessions without refresh
63
+ capability and invalid interactive refresh grants require fresh application authorization.
64
+
65
+ Cache keys include provider/client identity, grant identity, profile, flow, resolved endpoints, scopes,
66
+ audience, and resource. Change provider identity with credential configuration and grant identity with
67
+ session/grant inputs. The manager defaults to 30 seconds of expiry skew, coalesces concurrent renewal,
68
+ and accepts application-owned `TokenStore` storage. Canceling one waiter preserves others; canceling the
69
+ last signals acquisition cancellation. Once persistence starts, saving a rotated token finishes even if
70
+ callers cancel. A provider result arriving after cancellation cannot start persistence; if an identity
71
+ server already consumed that refresh token despite cancellation, interactive clients must authorize again.
72
+
73
+ The transport attaches complete AND credential sets and checks them on every execution. Bodyless
74
+ GET/HEAD/OPTIONS requests may recover one explicit bearer `invalid_token` challenge; POST, streamed bodies,
75
+ and 403 responses are never automatically replayed. Managed credential requests use manual redirect
76
+ handling, and query credentials are redacted from response diagnostics. Providers never receive secrets
77
+ from generated metadata, and provider failures use safe runtime diagnostics.
78
+
79
+ Credentials are isolated by logical security scheme as well as provider and acquisition inputs.
80
+ Discovery metadata is fetched and verified on each acquisition or renewal. Temporary provider outages
81
+ allow event connections to reconnect; a rejected refresh grant triggers fresh client credentials only
82
+ for the client-credentials flow. Interactive sessions require fresh application authorization.
83
+ Built-in OAuth providers retain at most 1,024 consumed authorization-code hashes per provider instance.
84
+ After this limit, create a provider for a newly authorized application session; old hashes are never
85
+ evicted to allow code reuse. Refresh exchanges do not consume this history.
86
+
87
+ ### Typed request parameters
88
+
89
+ `parameterValidation` is an optional callback on the request specification. The transport invokes it
90
+ before encoding on every request build, including bodyless requests and event streams. Generated
91
+ callbacks validate captured typed parameters in request mode; reusing an operation checks mutable
92
+ values again. Custom transports must invoke the callback at the same boundary before transmission.
93
+
94
+ Parameter failures throw `RequestValidationError` with the native validation error as `cause`.
95
+ Event sources close on this error, and event stream iterators reject instead of reconnecting.
96
+
97
+ ## URI template variables
98
+
99
+ `URLTemplate.complete` preserves the distinction between an empty string and a missing,
100
+ `undefined`, or `null` value. For `/items{/id}`, `id: ''` produces `/items/`, while an
101
+ undefined `id` produces `/items`. An empty collection is undefined; a list containing
102
+ an empty string has a defined member. Per-call values override stored template parameters,
103
+ including explicit null or undefined values that remove a stored value for that expansion.
104
+
105
+ ## Application-owned token persistence
106
+
107
+ ```typescript
108
+ const settings = ClientSettings.resolve(baseUrl, alternatives, credentials, {}, {},
109
+ providers => new TokenManager(providers, {
110
+ store: applicationStore, expirySkewMs: 30_000, now: applicationClock,
111
+ }));
112
+ ```
113
+
114
+ The same optional `TokenManagerFactory` is the fourth constructor argument. The last two resolver
115
+ arguments before it are scheme selections and alternative-index selections. Clock values and expiry
116
+ skew are milliseconds. The native manager has no close/reset method: cancel application requests with
117
+ their abort signals, await completion, and discard the manager at session end. The factory does not
118
+ change cancellation behavior or take ownership of application resources.
119
+
120
+ The hook is invoked once with the resolved provider map, after security validation, and is skipped
121
+ when no providers are selected. It must only construct a manager: do not acquire tokens or read
122
+ storage in the hook. Omitting it keeps the existing in-memory default. Settings retain the returned
123
+ manager, not the factory. All operations on those settings share it; generated aggregate children
124
+ therefore retain the same cache and single-flight renewal. Independently created managers do not
125
+ coordinate concurrent refreshes, even if their stores are the same. Reuse a client/aggregate within
126
+ an active session; use successive managers to reopen saved sessions.
127
+
128
+ The application owns persistence, encryption, store access and session boundaries. Provider/client,
129
+ grant, profile and endpoint identities must distinguish environments and users; the API base URL
130
+ alone is not an implicit store namespace. Use a new grant identity for a fresh authorization session.
131
+ For logout, stop requests and wait for pending refresh/persistence to finish before removing the
132
+ session's store entries, then construct fresh settings. `invalidate` expires an access token for
133
+ renewal; it is not logout and deliberately retains refresh state. No disk storage is enabled automatically.
@@ -0,0 +1,23 @@
1
+ import { Credentials } from './credentials.js';
2
+ import { SecurityBinding } from './security-binding.js';
3
+ import { TokenManager } from './token-manager.js';
4
+ import { TokenManagerFactory } from './token-manager-factory.js';
5
+ /** Resolved, transport-independent inputs supplied to an application's transport factory. */
6
+ export declare class ClientSettings {
7
+ #private;
8
+ readonly baseUrl: string;
9
+ /** Prepared manager shared by this configuration's operations; construction never acquires tokens. */
10
+ readonly tokenManager: TokenManager | undefined;
11
+ readonly bindings: Readonly<Record<string, readonly SecurityBinding[]>>;
12
+ /** Snapshots operation bindings and credentials without acquiring tokens or making requests. */
13
+ constructor(baseUrl: string, bindings?: Readonly<Record<string, readonly SecurityBinding[]>>, credentials?: Readonly<Record<string, Credentials>>, tokenManagerFactory?: TokenManagerFactory);
14
+ /** Expands server variables once and resolves relative servers against their document location. */
15
+ static serverUrl(template: string, variables: Readonly<Record<string, string>>, documentBaseUrl?: string): string;
16
+ /**
17
+ * Chooses one complete alternative per operation using credentials and optional explicit scheme sets.
18
+ * `alternativeSelection` selects a zero-based candidate index, including its scopes and endpoint metadata.
19
+ */
20
+ static resolve(baseUrl: string, alternatives: Readonly<Record<string, readonly (readonly SecurityBinding[])[]>>, credentials: Readonly<Record<string, Credentials>>, selection?: Readonly<Record<string, readonly string[]>>, alternativeSelection?: Readonly<Record<string, number>>, tokenManagerFactory?: TokenManagerFactory): ClientSettings;
21
+ private prepareTokenManager;
22
+ private prepareProvider;
23
+ }
@@ -0,0 +1,150 @@
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 { validateCredentials } from './credentials.js';
15
+ import { TokenManager } from './token-manager.js';
16
+ /** Resolved, transport-independent inputs supplied to an application's transport factory. */
17
+ export class ClientSettings {
18
+ baseUrl;
19
+ /** Prepared manager shared by this configuration's operations; construction never acquires tokens. */
20
+ tokenManager;
21
+ bindings;
22
+ #credentials;
23
+ /** Snapshots operation bindings and credentials without acquiring tokens or making requests. */
24
+ constructor(baseUrl, bindings = {}, credentials = {}, tokenManagerFactory) {
25
+ const url = new URL(baseUrl);
26
+ if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.href.includes('?') || url.href.includes('#'))
27
+ throw new TypeError('Client endpoint must be HTTP or HTTPS');
28
+ this.baseUrl = url.href;
29
+ this.bindings = Object.freeze(Object.fromEntries(Object.entries(bindings).map(([operation, values]) => [operation, Object.freeze(values.map(value => Object.freeze({
30
+ ...value,
31
+ ...Object.fromEntries(['discoveryUrl', 'authorizationUrl', 'tokenUrl', 'refreshUrl'].flatMap(key => {
32
+ const endpoint = value[key];
33
+ if (typeof endpoint !== 'string')
34
+ return [];
35
+ if (/[{}]/.test(endpoint))
36
+ throw new TypeError('Security endpoint URLs do not support server variables');
37
+ return [[key, new URL(endpoint, baseUrl).href]];
38
+ })),
39
+ scopes: Object.freeze([...value.scopes]), transport: Object.freeze({ ...value.transport }),
40
+ })))])));
41
+ this.#credentials = new Map(Object.entries(credentials).map(([scheme, value]) => [scheme, Object.freeze({ ...value, ...(value.kind === 'oauth' && value.endpoints
42
+ ? { endpoints: Object.freeze(Object.fromEntries(Object.entries(value.endpoints).map(([key, endpoint]) => {
43
+ if (endpoint === undefined)
44
+ return [key, undefined];
45
+ if (/[{}]/.test(endpoint))
46
+ throw new TypeError('Security endpoint URLs do not support server variables');
47
+ return [key, new URL(endpoint, baseUrl).href];
48
+ }))) } : {}) })]));
49
+ for (const binding of Object.values(this.bindings).flat()) {
50
+ const credential = this.#credentials.get(binding.scheme);
51
+ if (!credential)
52
+ throw new TypeError(`Missing credentials for scheme '${binding.scheme}'`);
53
+ validateCredentials(credential, binding);
54
+ }
55
+ this.tokenManager = this.prepareTokenManager(tokenManagerFactory);
56
+ Object.freeze(this);
57
+ }
58
+ /** Expands server variables once and resolves relative servers against their document location. */
59
+ static serverUrl(template, variables, documentBaseUrl) {
60
+ const expanded = template.replace(/\{([^{}]+)\}/g, (_match, name) => {
61
+ if (!Object.hasOwn(variables, name))
62
+ throw new TypeError(`Missing server variable '${name}'`);
63
+ return variables[name];
64
+ });
65
+ const url = new URL(expanded, documentBaseUrl);
66
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
67
+ throw new TypeError('Invalid HTTP server endpoint');
68
+ }
69
+ return url.href;
70
+ }
71
+ /**
72
+ * Chooses one complete alternative per operation using credentials and optional explicit scheme sets.
73
+ * `alternativeSelection` selects a zero-based candidate index, including its scopes and endpoint metadata.
74
+ */
75
+ static resolve(baseUrl, alternatives, credentials, selection = {}, alternativeSelection = {}, tokenManagerFactory) {
76
+ if ([...Object.keys(selection), ...Object.keys(alternativeSelection)].some(operation => !Object.hasOwn(alternatives, operation))) {
77
+ throw new TypeError('Unknown operation selection');
78
+ }
79
+ const bindings = Object.create(null);
80
+ for (const [operation, candidates] of Object.entries(alternatives)) {
81
+ const selected = Object.hasOwn(selection, operation) ? selection[operation] : undefined;
82
+ const selectedIndex = Object.hasOwn(alternativeSelection, operation) ? alternativeSelection[operation] : undefined;
83
+ const usable = candidates.filter((candidate, index) => {
84
+ if (selectedIndex !== undefined && selectedIndex !== index)
85
+ return false;
86
+ if (selected && (selected.length !== candidate.length || candidate.some(binding => !selected.includes(binding.scheme))))
87
+ return false;
88
+ return candidate.every(binding => {
89
+ const credential = Object.hasOwn(credentials, binding.scheme) ? credentials[binding.scheme] : undefined;
90
+ if (!credential)
91
+ return false;
92
+ try {
93
+ validateCredentials(credential, binding);
94
+ return true;
95
+ }
96
+ catch {
97
+ return false;
98
+ }
99
+ });
100
+ });
101
+ if (usable.length !== 1)
102
+ throw new TypeError(`Operation '${operation}' requires one complete security alternative`);
103
+ bindings[operation] = usable[0];
104
+ }
105
+ return new ClientSettings(baseUrl, bindings, credentials, tokenManagerFactory);
106
+ }
107
+ prepareTokenManager(factory) {
108
+ const providers = new Map();
109
+ const owners = new Map();
110
+ for (const binding of Object.values(this.bindings).flat()) {
111
+ const previous = owners.get(binding.provider);
112
+ if (previous !== undefined && previous !== binding.scheme) {
113
+ throw new TypeError('Distinct credential schemes require distinct provider bindings');
114
+ }
115
+ if (previous !== undefined)
116
+ continue;
117
+ owners.set(binding.provider, binding.scheme);
118
+ providers.set(binding.provider, this.prepareProvider(this.#credentials.get(binding.scheme)));
119
+ }
120
+ if (!providers.size)
121
+ return undefined;
122
+ const resolved = Object.freeze(Object.fromEntries(providers));
123
+ return factory ? factory(resolved) : new TokenManager(resolved);
124
+ }
125
+ prepareProvider(credentials) {
126
+ if (credentials.kind === 'provider')
127
+ return credentials.provider;
128
+ if (credentials.kind === 'oauth')
129
+ return credentials.providerFactory(credentials);
130
+ const identity = crypto.randomUUID();
131
+ let token;
132
+ switch (credentials.kind) {
133
+ case 'bearer':
134
+ token = credentials.token;
135
+ break;
136
+ case 'apiKey':
137
+ token = credentials.key;
138
+ break;
139
+ case 'basic':
140
+ token = btoa(Array.from(new TextEncoder().encode(`${credentials.username}:${credentials.password}`), byte => String.fromCodePoint(byte)).join(''));
141
+ break;
142
+ }
143
+ return {
144
+ identity,
145
+ configure: () => ({ clientIdentity: identity }),
146
+ acquire: () => Promise.resolve({ accessToken: token }),
147
+ };
148
+ }
149
+ }
150
+ //# sourceMappingURL=client-settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-settings.js","sourceRoot":"","sources":["../src/client-settings.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,OAAO,EAAe,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,6FAA6F;AAC7F,MAAM,OAAO,cAAc;IAChB,OAAO,CAAS;IACzB,sGAAsG;IAC7F,YAAY,CAA2B;IACvC,QAAQ,CAAuD;IAC/D,YAAY,CAAmC;IAExD,gGAAgG;IAChG,YAAY,OAAe,EAAE,WAAiE,EAAE,EAC9F,cAAqD,EAAE,EAAE,mBAAyC;QAClG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,C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AAO;YACL,QAAQ;YACR,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC;YAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;SACvD,CAAC;IACJ,CAAC;CAEF"}
@@ -0,0 +1,58 @@
1
+ import type { SecurityBinding, SecurityEndpoints } from './security-binding.js';
2
+ import type { TokenProvider, TokenRequest } from './token-provider.js';
3
+ /** Fresh application-authorized PKCE result; interactive authorization remains application-owned. */
4
+ export interface AuthorizationGrant {
5
+ readonly code: string;
6
+ readonly redirectUri: string;
7
+ readonly codeVerifier: string;
8
+ }
9
+ /** Transport-independent OAuth client configuration. */
10
+ export interface OAuthCredentialOptions {
11
+ readonly identity: string;
12
+ readonly clientId: string;
13
+ readonly clientSecret?: string;
14
+ readonly authentication?: 'none' | 'client_secret_basic' | 'client_secret_post';
15
+ readonly grantIdentity?: string;
16
+ readonly authorization?: (request: TokenRequest, signal: AbortSignal) => Promise<AuthorizationGrant>;
17
+ readonly endpoints?: SecurityEndpoints;
18
+ readonly issuer?: string;
19
+ }
20
+ /** Application-supplied bearer token, without its wire prefix. */
21
+ export interface BearerCredentials {
22
+ readonly kind: 'bearer';
23
+ readonly token: string;
24
+ }
25
+ /** Application-supplied API key; the contract determines its wire location. */
26
+ export interface ApiKeyCredentials {
27
+ readonly kind: 'apiKey';
28
+ readonly key: string;
29
+ }
30
+ /** Basic authentication inputs; the runtime supplies the wire encoding. */
31
+ export interface BasicCredentials {
32
+ readonly kind: 'basic';
33
+ readonly username: string;
34
+ readonly password: string;
35
+ }
36
+ /** OAuth inputs narrowed to the selected acquisition flow. */
37
+ export type OAuthCredentials = {
38
+ /** Builds the installed module's provider without acquiring tokens. */
39
+ readonly providerFactory: (credentials: OAuthCredentials) => TokenProvider;
40
+ } & ((OAuthCredentialOptions & {
41
+ readonly kind: 'oauth';
42
+ readonly flow: 'clientCredentials';
43
+ }) | (OAuthCredentialOptions & {
44
+ readonly kind: 'oauth';
45
+ readonly flow: 'authorizationCode';
46
+ readonly grantIdentity: string;
47
+ readonly authorization: NonNullable<OAuthCredentialOptions['authorization']>;
48
+ }));
49
+ /** Escape hatch for application-owned acquisition and unsupported OAuth flows. */
50
+ export interface ProviderCredentials {
51
+ readonly kind: 'provider';
52
+ readonly provider: TokenProvider;
53
+ readonly flow?: SecurityBinding['flow'];
54
+ }
55
+ /** Shared credential family; generated code narrows this union for each declared scheme. */
56
+ export type Credentials = BearerCredentials | ApiKeyCredentials | BasicCredentials | OAuthCredentials | ProviderCredentials;
57
+ /** Reject incompatible inputs before constructing a transport or acquiring a token. */
58
+ export declare function validateCredentials(credentials: Credentials, binding: SecurityBinding): void;
@@ -0,0 +1,51 @@
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
+ /** Reject incompatible inputs before constructing a transport or acquiring a token. */
15
+ export function validateCredentials(credentials, binding) {
16
+ if (credentials.kind === 'provider') {
17
+ if (credentials.flow !== undefined && credentials.flow !== binding.flow)
18
+ throw new TypeError('Provider flow does not match');
19
+ return;
20
+ }
21
+ const prefix = binding.transport.prefix?.toLowerCase();
22
+ if (credentials.kind === 'oauth') {
23
+ validateOAuthCredentials(credentials, binding);
24
+ return;
25
+ }
26
+ if (binding.flow !== 'static' && binding.flow !== 'external') {
27
+ throw new TypeError('Static credentials cannot satisfy an OAuth acquisition binding');
28
+ }
29
+ if (credentials.kind === 'bearer' && (prefix !== 'bearer' || !credentials.token)) {
30
+ throw new TypeError('Bearer credentials do not match the selected security binding');
31
+ }
32
+ if (credentials.kind === 'apiKey' && (prefix !== undefined || !credentials.key)) {
33
+ throw new TypeError('API key credentials do not match the selected security binding');
34
+ }
35
+ if (credentials.kind === 'basic' && (prefix !== 'basic' || credentials.username.includes(':'))) {
36
+ throw new TypeError('Basic credentials do not match the selected security binding');
37
+ }
38
+ }
39
+ function validateOAuthCredentials(credentials, binding) {
40
+ const prefix = binding.transport.prefix?.toLowerCase();
41
+ if (prefix !== 'bearer' || credentials.flow !== binding.flow || !credentials.identity.trim() || !credentials.clientId.trim()) {
42
+ throw new TypeError('OAuth credentials do not match the selected security binding');
43
+ }
44
+ const authentication = credentials.authentication ?? 'none';
45
+ if (!['none', 'client_secret_basic', 'client_secret_post'].includes(authentication) || (authentication === 'none') !== (credentials.clientSecret === undefined) || credentials.clientSecret === '' ||
46
+ (credentials.flow === 'clientCredentials' && authentication === 'none') ||
47
+ (credentials.flow === 'authorizationCode' && (!credentials.grantIdentity.trim() || !credentials.authorization))) {
48
+ throw new TypeError('Invalid OAuth credential configuration');
49
+ }
50
+ }
51
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.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;AAiEjC,uFAAuF;AACvF,MAAM,UAAU,mBAAmB,CAAC,WAAwB,EAAE,OAAwB;IACpF,IAAI,WAAW,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACpC,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI;YAAE,MAAM,IAAI,SAAS,CAA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AC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7H,MAAM,IAAI,SAAS,CAAC,8DAA8D,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,IAAI,MAAM,CAAC;IAC5D,IAAI,CAAC,CAAC,MAAM,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,KAAK,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,KAAK,SAAS,CAAC,IAAI,WAAW,CAAC,YAAY,KAAK,EAAE;QAChM,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAmB,IAAI,cAAc,KAAK,MAAM,CAAC;QACvE,CAAC,WAAW,CAAC,IAAI,KAAK,mBAAmB,IAAI,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;QAClH,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
@@ -3,6 +3,8 @@ export interface EventInfo {
3
3
  event?: string;
4
4
  data?: string;
5
5
  retry?: string;
6
+ keepalive?: string;
7
+ 'retry-max'?: string;
6
8
  }
7
9
  export declare class EventParser {
8
10
  private readonly decoder;
@@ -1 +1 @@
1
- {"version":3,"file":"event-parser.js","sourceRoot":"","sources":["../src/event-parser.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;AASjC,MAAM,OAAO,WAAW;IACL,OAAO,GAAgB,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACzD,iBAAiB,CAAe;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AK,GAAG,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,mBAAmB,GAAG,YAAY,CAAC"}
@@ -6,9 +6,10 @@ export interface FetchEventSource {
6
6
  }
7
7
  export declare class FetchEventSource extends EventTarget implements ExtEventSource {
8
8
  private static readonly LAST_EVENT_ID_HEADER;
9
- private static readonly MAX_RETRY_TIME_MULTIPLIER;
10
- private static readonly RETRY_EXPONENT;
11
- private static readonly EVENT_TIMEOUT_DEFAULT;
9
+ private static readonly RETRY_TIME_DEFAULT;
10
+ private static readonly RETRY_MAX_MULTIPLIER_DEFAULT;
11
+ private static readonly KEEPALIVE_TIMEOUT_MULTIPLIER;
12
+ private static readonly KEEPALIVE_TIMEOUT_MINIMUM;
12
13
  private static readonly EVENT_TIMEOUT_CHECK_INTERVAL_DEFAULT;
13
14
  readonly CONNECTING = 0;
14
15
  readonly OPEN = 1;
@@ -21,25 +22,29 @@ export declare class FetchEventSource extends EventTarget implements ExtEventSou
21
22
  onopen: ((this: EventSource, ev: Event) => unknown) | null;
22
23
  get retryTime(): number;
23
24
  private readonly adapter;
25
+ private readonly fetchRequest;
24
26
  private readonly signal?;
25
27
  private connectionAbortController?;
26
28
  private connectionReader?;
27
29
  private externalAbortSignal?;
28
30
  private externalAbortHandler?;
29
31
  private internalRetryTime;
32
+ private internalRetryMax?;
30
33
  private retryAttempt;
31
- private connectionAttemptTime;
32
34
  private connectionOrigin?;
33
35
  private reconnectTimeoutHandle?;
34
36
  private lastEventId?;
35
37
  private readonly logger?;
36
- private readonly eventTimeout?;
38
+ private eventTimeout?;
39
+ private readonly eventTimeoutConfigured;
37
40
  private readonly eventTimeoutCheckInterval;
38
41
  private eventTimeoutCheckHandle?;
39
42
  private lastEventReceivedTime;
40
43
  private readonly eventParser;
41
44
  constructor(url: string, eventSourceInit?: EventSourceInit & {
42
45
  adapter?: (url: string, requestInit: RequestInit) => Promise<Request>;
46
+ /** Executes one connection using a subscription-owned authentication recovery budget. */
47
+ fetch?: (request: Request, signal: AbortSignal) => Promise<Response>;
43
48
  signal?: AbortSignal;
44
49
  eventTimeout?: number;
45
50
  eventTimeoutCheckInterval?: number;
@@ -56,11 +61,15 @@ export declare class FetchEventSource extends EventTarget implements ExtEventSou
56
61
  private receivedHeaders;
57
62
  private receivedData;
58
63
  private receivedError;
64
+ private receivedFatalError;
59
65
  private receivedComplete;
60
66
  private scheduleReconnect;
61
67
  private static calculateRetryTime;
62
68
  private clearReconnect;
63
69
  private readonly dispatchParsedEvent;
70
+ private static parseMilliseconds;
64
71
  fireErrorEvent(error: unknown): void;
65
72
  private abortConnection;
73
+ private startExternalAbortListener;
74
+ private stopExternalAbortListener;
66
75
  }