@passflow/core 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5944 -0
- package/dist/index.d.ts +5944 -0
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -7
- package/dist/lib/api/app.d.ts +0 -11
- package/dist/lib/api/app.d.ts.map +0 -1
- package/dist/lib/api/auth.d.ts +0 -42
- package/dist/lib/api/auth.d.ts.map +0 -1
- package/dist/lib/api/axios-client.d.ts +0 -109
- package/dist/lib/api/axios-client.d.ts.map +0 -1
- package/dist/lib/api/cli-auth.d.ts +0 -12
- package/dist/lib/api/cli-auth.d.ts.map +0 -1
- package/dist/lib/api/index.d.ts +0 -11
- package/dist/lib/api/index.d.ts.map +0 -1
- package/dist/lib/api/invitation.d.ts +0 -80
- package/dist/lib/api/invitation.d.ts.map +0 -1
- package/dist/lib/api/model.d.ts +0 -844
- package/dist/lib/api/model.d.ts.map +0 -1
- package/dist/lib/api/setting.d.ts +0 -13
- package/dist/lib/api/setting.d.ts.map +0 -1
- package/dist/lib/api/tenant.d.ts +0 -216
- package/dist/lib/api/tenant.d.ts.map +0 -1
- package/dist/lib/api/two-factor.d.ts +0 -137
- package/dist/lib/api/two-factor.d.ts.map +0 -1
- package/dist/lib/api/upgrade.d.ts +0 -39
- package/dist/lib/api/upgrade.d.ts.map +0 -1
- package/dist/lib/api/user.d.ts +0 -22
- package/dist/lib/api/user.d.ts.map +0 -1
- package/dist/lib/constants/index.d.ts +0 -33
- package/dist/lib/constants/index.d.ts.map +0 -1
- package/dist/lib/device/index.d.ts +0 -17
- package/dist/lib/device/index.d.ts.map +0 -1
- package/dist/lib/index.d.ts +0 -22
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/interceptors/fetch-registry.d.ts +0 -96
- package/dist/lib/interceptors/fetch-registry.d.ts.map +0 -1
- package/dist/lib/m2m/client.d.ts +0 -196
- package/dist/lib/m2m/client.d.ts.map +0 -1
- package/dist/lib/m2m/errors.d.ts +0 -107
- package/dist/lib/m2m/errors.d.ts.map +0 -1
- package/dist/lib/m2m/index.d.ts +0 -27
- package/dist/lib/m2m/index.d.ts.map +0 -1
- package/dist/lib/m2m/types.d.ts +0 -217
- package/dist/lib/m2m/types.d.ts.map +0 -1
- package/dist/lib/passflow.d.ts +0 -1224
- package/dist/lib/passflow.d.ts.map +0 -1
- package/dist/lib/pkce.d.ts +0 -13
- package/dist/lib/pkce.d.ts.map +0 -1
- package/dist/lib/platform/index.d.ts +0 -4
- package/dist/lib/platform/index.d.ts.map +0 -1
- package/dist/lib/platform/types.d.ts +0 -206
- package/dist/lib/platform/types.d.ts.map +0 -1
- package/dist/lib/platform/web-adapter.d.ts +0 -104
- package/dist/lib/platform/web-adapter.d.ts.map +0 -1
- package/dist/lib/services/auth-service.d.ts +0 -197
- package/dist/lib/services/auth-service.d.ts.map +0 -1
- package/dist/lib/services/index.d.ts +0 -8
- package/dist/lib/services/index.d.ts.map +0 -1
- package/dist/lib/services/invitation-service.d.ts +0 -44
- package/dist/lib/services/invitation-service.d.ts.map +0 -1
- package/dist/lib/services/logger.d.ts +0 -24
- package/dist/lib/services/logger.d.ts.map +0 -1
- package/dist/lib/services/tenant-service.d.ts +0 -200
- package/dist/lib/services/tenant-service.d.ts.map +0 -1
- package/dist/lib/services/tenant-user-membership.d.ts +0 -76
- package/dist/lib/services/tenant-user-membership.d.ts.map +0 -1
- package/dist/lib/services/token-cache-service.d.ts +0 -36
- package/dist/lib/services/token-cache-service.d.ts.map +0 -1
- package/dist/lib/services/two-factor-service.d.ts +0 -193
- package/dist/lib/services/two-factor-service.d.ts.map +0 -1
- package/dist/lib/services/user-service.d.ts +0 -41
- package/dist/lib/services/user-service.d.ts.map +0 -1
- package/dist/lib/storage/index.d.ts +0 -106
- package/dist/lib/storage/index.d.ts.map +0 -1
- package/dist/lib/store.d.ts +0 -175
- package/dist/lib/store.d.ts.map +0 -1
- package/dist/lib/token/delivery-manager.d.ts +0 -121
- package/dist/lib/token/delivery-manager.d.ts.map +0 -1
- package/dist/lib/token/index.d.ts +0 -4
- package/dist/lib/token/index.d.ts.map +0 -1
- package/dist/lib/token/membership.d.ts +0 -37
- package/dist/lib/token/membership.d.ts.map +0 -1
- package/dist/lib/token/service.d.ts +0 -47
- package/dist/lib/token/service.d.ts.map +0 -1
- package/dist/lib/token/token.d.ts +0 -55
- package/dist/lib/token/token.d.ts.map +0 -1
- package/dist/lib/types/index.d.ts +0 -24
- package/dist/lib/types/index.d.ts.map +0 -1
- package/dist/lib/upgrade/acr.d.ts +0 -85
- package/dist/lib/upgrade/acr.d.ts.map +0 -1
- package/dist/lib/upgrade/axios-adapter.d.ts +0 -81
- package/dist/lib/upgrade/axios-adapter.d.ts.map +0 -1
- package/dist/lib/upgrade/challenge.d.ts +0 -217
- package/dist/lib/upgrade/challenge.d.ts.map +0 -1
- package/dist/lib/upgrade/client.d.ts +0 -29
- package/dist/lib/upgrade/client.d.ts.map +0 -1
- package/dist/lib/upgrade/controller.d.ts +0 -435
- package/dist/lib/upgrade/controller.d.ts.map +0 -1
- package/dist/lib/upgrade/core.d.ts +0 -353
- package/dist/lib/upgrade/core.d.ts.map +0 -1
- package/dist/lib/upgrade/errors.d.ts +0 -208
- package/dist/lib/upgrade/errors.d.ts.map +0 -1
- package/dist/lib/upgrade/facade.d.ts +0 -188
- package/dist/lib/upgrade/facade.d.ts.map +0 -1
- package/dist/lib/upgrade/factors.d.ts +0 -97
- package/dist/lib/upgrade/factors.d.ts.map +0 -1
- package/dist/lib/upgrade/fetch-adapter.d.ts +0 -30
- package/dist/lib/upgrade/fetch-adapter.d.ts.map +0 -1
- package/dist/lib/upgrade/index.d.ts +0 -17
- package/dist/lib/upgrade/index.d.ts.map +0 -1
- package/dist/lib/upgrade/markers.d.ts +0 -64
- package/dist/lib/upgrade/markers.d.ts.map +0 -1
- package/dist/lib/upgrade/replay.d.ts +0 -132
- package/dist/lib/upgrade/replay.d.ts.map +0 -1
- package/dist/lib/upgrade/select.d.ts +0 -48
- package/dist/lib/upgrade/select.d.ts.map +0 -1
- package/dist/lib/upgrade/session.d.ts +0 -72
- package/dist/lib/upgrade/session.d.ts.map +0 -1
- package/dist/lib/upgrade/snapshot.d.ts +0 -196
- package/dist/lib/upgrade/snapshot.d.ts.map +0 -1
- package/dist/lib/upgrade/transport.d.ts +0 -69
- package/dist/lib/upgrade/transport.d.ts.map +0 -1
- package/dist/lib/utils/validation.d.ts +0 -54
- package/dist/lib/utils/validation.d.ts.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One `fetch` patch point, many middlewares.
|
|
3
|
-
*
|
|
4
|
-
* This module exists because of a bug, not a requirement (architecture §4.3,
|
|
5
|
-
* reaffirmed by §13.5's "what survives supersession"). Two features that each do
|
|
6
|
-
* `globalThis.fetch = wrapper` in an effect and restore their captured original
|
|
7
|
-
* in cleanup compose as `A(B(native))`, and whichever cleanup runs first assigns
|
|
8
|
-
* a fetch that predates the other patch. React guarantees no cleanup ordering
|
|
9
|
-
* across sibling effects, nor across a parent/child boundary under Strict Mode
|
|
10
|
-
* double-invocation, so one of the two interceptors silently disappears —
|
|
11
|
-
* non-deterministically, and only in composed mounts.
|
|
12
|
-
*
|
|
13
|
-
* The fix is to make the patch a shared resource with reference-counted
|
|
14
|
-
* ownership: the registry installs exactly one wrapper on the first
|
|
15
|
-
* registration, composes the registered middlewares by priority on every call,
|
|
16
|
-
* and removes the wrapper on the last removal. **Teardown is the registry's
|
|
17
|
-
* responsibility, not any caller's** — no caller captures or restores
|
|
18
|
-
* `globalThis.fetch` itself, which is precisely the ownership mistake being
|
|
19
|
-
* retired.
|
|
20
|
-
*
|
|
21
|
-
* Composition is a Decorator chain, not a Chain of Responsibility: every
|
|
22
|
-
* middleware MUST delegate to `next`. A link that may legitimately swallow a
|
|
23
|
-
* request would mean a stranger's `fetch` call can vanish inside our wrapper, so
|
|
24
|
-
* non-delegation is detected per invocation and reported as a named error rather
|
|
25
|
-
* than left to surface as a hung promise (§9.4/R7).
|
|
26
|
-
*
|
|
27
|
-
* SSR safety is a stated non-functional requirement and is structural here:
|
|
28
|
-
* `globalThis` is read only inside `install()` and inside the state reader,
|
|
29
|
-
* never at module scope. Importing this module on a server touches no global and
|
|
30
|
-
* throws nothing; `registerFetchMiddleware` returns a no-op unregister when
|
|
31
|
-
* there is no `fetch` to patch (§9.4/R6).
|
|
32
|
-
*
|
|
33
|
-
* The module is generic. It knows nothing about upgrades, OIDC or Passflow
|
|
34
|
-
* endpoints — only about ordering, ownership and delegation.
|
|
35
|
-
*/
|
|
36
|
-
/** A `fetch`-shaped function: the platform `fetch`, or the next link in the chain. */
|
|
37
|
-
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
38
|
-
/**
|
|
39
|
-
* A registered interception layer.
|
|
40
|
-
*
|
|
41
|
-
* It receives the next link explicitly rather than closing over a captured
|
|
42
|
-
* global, which is what lets the chain be rebuilt per call and reordered by
|
|
43
|
-
* priority without any middleware knowing its neighbours.
|
|
44
|
-
*/
|
|
45
|
-
export type FetchMiddleware = (next: FetchLike, input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
46
|
-
export type RegisterOptions = {
|
|
47
|
-
/** Lower runs OUTER (further from the network). Ties break by registration order. */
|
|
48
|
-
priority: number;
|
|
49
|
-
/** Diagnostic label, surfaced in the error thrown when a middleware fails to delegate. */
|
|
50
|
-
name: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Outer layer. The OIDC AuthFlow interceptor must observe the response the
|
|
54
|
-
* caller will actually receive — including a replayed one — because it follows a
|
|
55
|
-
* `redirect_url` out of that body. Placed inside the upgrade middleware it would
|
|
56
|
-
* inspect the raw 401, do nothing, and the page would then navigate on a
|
|
57
|
-
* response the caller never saw.
|
|
58
|
-
*/
|
|
59
|
-
export declare const FETCH_PRIORITY_OIDC = 10;
|
|
60
|
-
/**
|
|
61
|
-
* Inner layer. The upgrade middleware must see the raw 401 and replace it before
|
|
62
|
-
* anything upstream forms an opinion about it.
|
|
63
|
-
*/
|
|
64
|
-
export declare const FETCH_PRIORITY_UPGRADE = 20;
|
|
65
|
-
/** Thrown when a registered middleware resolves without ever calling `next`. */
|
|
66
|
-
export declare class FetchMiddlewareContractError extends Error {
|
|
67
|
-
/** The `name` the offending middleware was registered under. */
|
|
68
|
-
readonly middlewareName: string;
|
|
69
|
-
constructor(middlewareName: string);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Registers a middleware, installing the one global patch on the FIRST
|
|
73
|
-
* registration, and returns an idempotent unregister that removes the patch on
|
|
74
|
-
* the LAST removal.
|
|
75
|
-
*
|
|
76
|
-
* Safe in both directions and under Strict Mode's double-invoke: ownership is by
|
|
77
|
-
* reference count over entry identity, so register/unregister/register of the
|
|
78
|
-
* same middleware, and removals in any order relative to other registrations,
|
|
79
|
-
* all converge. The returned function is bound to this one registration — a
|
|
80
|
-
* second call does nothing, and registering the same middleware twice yields two
|
|
81
|
-
* independent entries and two independent unregisters (§9.4/R8).
|
|
82
|
-
*/
|
|
83
|
-
export declare const registerFetchMiddleware: (middleware: FetchMiddleware, opts: RegisterOptions) => (() => void);
|
|
84
|
-
/**
|
|
85
|
-
* Test and diagnostic read of the registry.
|
|
86
|
-
*
|
|
87
|
-
* `names` is in execution order, outermost first. `foreignPatch` is computed
|
|
88
|
-
* live rather than remembered, so it reports a stranger's patch as soon as it
|
|
89
|
-
* lands, not only once a teardown has declined to restore over it.
|
|
90
|
-
*/
|
|
91
|
-
export declare const fetchRegistryState: () => {
|
|
92
|
-
installed: boolean;
|
|
93
|
-
names: string[];
|
|
94
|
-
foreignPatch: boolean;
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=fetch-registry.d.ts.map
|
|
@@ -1 +0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
* M2M (Machine-to-Machine) Authentication Client
|
|
3
|
-
*
|
|
4
|
-
* OAuth 2.0 Client Credentials Grant implementation for server-to-server
|
|
5
|
-
* authentication without user involvement.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const m2m = new M2MClient({
|
|
10
|
-
* url: 'https://auth.yourapp.com',
|
|
11
|
-
* clientId: 'your-client-id',
|
|
12
|
-
* clientSecret: 'your-client-secret',
|
|
13
|
-
* scopes: ['users:read', 'orders:write'],
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* const token = await m2m.getToken();
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
import type { M2MClientConfig, M2MTokenClaims, M2MTokenRequestOptions, M2MTokenResponse } from './types';
|
|
20
|
-
/**
|
|
21
|
-
* M2M Authentication Client
|
|
22
|
-
*
|
|
23
|
-
* Implements OAuth 2.0 Client Credentials Grant for machine-to-machine
|
|
24
|
-
* authentication. Provides automatic token caching, refresh, and retry logic.
|
|
25
|
-
*/
|
|
26
|
-
export declare class M2MClient {
|
|
27
|
-
private readonly config;
|
|
28
|
-
private readonly cache;
|
|
29
|
-
private readonly retryStrategy;
|
|
30
|
-
private readonly tokenEndpoint;
|
|
31
|
-
/**
|
|
32
|
-
* Create a new M2M client
|
|
33
|
-
*
|
|
34
|
-
* @param config - Client configuration
|
|
35
|
-
* @throws {M2MConfigError} If required configuration is missing
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const m2m = new M2MClient({
|
|
40
|
-
* url: 'https://auth.yourapp.com',
|
|
41
|
-
* clientId: 'your-client-id',
|
|
42
|
-
* clientSecret: 'your-client-secret',
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
constructor(config: M2MClientConfig);
|
|
47
|
-
/**
|
|
48
|
-
* Get the cache key for this client
|
|
49
|
-
*/
|
|
50
|
-
private getCacheKey;
|
|
51
|
-
/**
|
|
52
|
-
* Request an access token from the authorization server
|
|
53
|
-
*
|
|
54
|
-
* @param options - Optional request overrides
|
|
55
|
-
* @returns Token response
|
|
56
|
-
* @throws {M2MError} On authentication failure
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* // Basic usage
|
|
61
|
-
* const token = await m2m.getToken();
|
|
62
|
-
*
|
|
63
|
-
* // With options
|
|
64
|
-
* const token = await m2m.getToken({
|
|
65
|
-
* scopes: ['users:read'],
|
|
66
|
-
* forceRefresh: true,
|
|
67
|
-
* });
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
getToken(options?: M2MTokenRequestOptions): Promise<M2MTokenResponse>;
|
|
71
|
-
/**
|
|
72
|
-
* Get a valid token, automatically refreshing if needed
|
|
73
|
-
*
|
|
74
|
-
* When autoRefresh is enabled, this will proactively refresh tokens
|
|
75
|
-
* that are about to expire (within refreshThreshold seconds).
|
|
76
|
-
*
|
|
77
|
-
* @returns Valid token response
|
|
78
|
-
* @throws {M2MError} On authentication failure
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // Always returns a valid, non-expired token
|
|
83
|
-
* const token = await m2m.getValidToken();
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
getValidToken(): Promise<M2MTokenResponse>;
|
|
87
|
-
/**
|
|
88
|
-
* Request a new token from the authorization server
|
|
89
|
-
*/
|
|
90
|
-
private requestToken;
|
|
91
|
-
/**
|
|
92
|
-
* Execute the actual HTTP request to the token endpoint
|
|
93
|
-
*/
|
|
94
|
-
private doTokenRequest;
|
|
95
|
-
/**
|
|
96
|
-
* Execute a request with retry logic
|
|
97
|
-
*/
|
|
98
|
-
private executeWithRetry;
|
|
99
|
-
/**
|
|
100
|
-
* Sleep for a given duration
|
|
101
|
-
*/
|
|
102
|
-
private sleep;
|
|
103
|
-
/**
|
|
104
|
-
* Get the currently cached token without making a request
|
|
105
|
-
*
|
|
106
|
-
* @returns Cached token or null if not cached
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```typescript
|
|
110
|
-
* const token = m2m.getCachedToken();
|
|
111
|
-
* if (token && !m2m.isTokenExpired(token)) {
|
|
112
|
-
* console.log('Using cached token');
|
|
113
|
-
* }
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
getCachedToken(): M2MTokenResponse | null;
|
|
117
|
-
/**
|
|
118
|
-
* Check if a token is expired or about to expire
|
|
119
|
-
*
|
|
120
|
-
* @param token - Token to check (uses issued_at + expires_in if available)
|
|
121
|
-
* @param threshold - Seconds before actual expiry to consider expired (default: 0)
|
|
122
|
-
* @returns true if expired or about to expire
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* if (m2m.isTokenExpired(token)) {
|
|
127
|
-
* console.log('Token is expired');
|
|
128
|
-
* }
|
|
129
|
-
*
|
|
130
|
-
* // Check if expiring within 5 minutes
|
|
131
|
-
* if (m2m.isTokenExpired(token, 300)) {
|
|
132
|
-
* console.log('Token expires soon');
|
|
133
|
-
* }
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
isTokenExpired(token?: M2MTokenResponse | null, threshold?: number): boolean;
|
|
137
|
-
/**
|
|
138
|
-
* Parse token claims from a JWT access token
|
|
139
|
-
*
|
|
140
|
-
* @param token - JWT access token string
|
|
141
|
-
* @returns Decoded token claims
|
|
142
|
-
* @throws {M2MTokenParseError} If token format is invalid
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* const token = await m2m.getToken();
|
|
147
|
-
* const claims = m2m.parseToken(token.access_token);
|
|
148
|
-
* console.log('Client ID:', claims.client_id);
|
|
149
|
-
* console.log('Scopes:', claims.scopes);
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
parseToken(token: string): M2MTokenClaims;
|
|
153
|
-
/**
|
|
154
|
-
* Clear the token cache, forcing a new request on next getToken()
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* m2m.clearCache();
|
|
159
|
-
* // Next getToken() will request a new token
|
|
160
|
-
* const token = await m2m.getToken();
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
clearCache(): void;
|
|
164
|
-
/**
|
|
165
|
-
* Revoke the current token
|
|
166
|
-
*
|
|
167
|
-
* Note: Requires the server to support token revocation (RFC 7009).
|
|
168
|
-
* Not all Passflow deployments may support this endpoint.
|
|
169
|
-
*
|
|
170
|
-
* @throws {M2MError} If revocation fails
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* await m2m.revokeToken();
|
|
175
|
-
* console.log('Token revoked');
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
revokeToken(): Promise<void>;
|
|
179
|
-
/**
|
|
180
|
-
* Get the configured URL
|
|
181
|
-
*/
|
|
182
|
-
get url(): string;
|
|
183
|
-
/**
|
|
184
|
-
* Get the configured client ID
|
|
185
|
-
*/
|
|
186
|
-
get clientId(): string;
|
|
187
|
-
/**
|
|
188
|
-
* Get the configured scopes
|
|
189
|
-
*/
|
|
190
|
-
get scopes(): string[] | undefined;
|
|
191
|
-
/**
|
|
192
|
-
* Get the configured audience
|
|
193
|
-
*/
|
|
194
|
-
get audience(): string[] | undefined;
|
|
195
|
-
}
|
|
196
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../lib/m2m/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EACV,eAAe,EAGf,cAAc,EACd,sBAAsB,EAEtB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AA0DjB;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ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ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* M2M Authentication Error Classes
|
|
3
|
-
*
|
|
4
|
-
* Custom error classes for M2M authentication failures with
|
|
5
|
-
* OAuth 2.0 compliant error codes and detailed information.
|
|
6
|
-
*/
|
|
7
|
-
import type { M2MErrorCode, M2MRateLimitInfo } from './types';
|
|
8
|
-
/**
|
|
9
|
-
* M2M Authentication Error
|
|
10
|
-
*
|
|
11
|
-
* Thrown when M2M authentication fails. Contains OAuth 2.0 compliant
|
|
12
|
-
* error codes and additional debugging information.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* try {
|
|
17
|
-
* const token = await m2m.getToken();
|
|
18
|
-
* } catch (error) {
|
|
19
|
-
* if (error instanceof M2MError) {
|
|
20
|
-
* console.error(`Error: ${error.code} - ${error.message}`);
|
|
21
|
-
* if (error.code === 'rate_limit_exceeded') {
|
|
22
|
-
* console.log(`Retry after: ${error.rateLimitInfo?.reset}`);
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare class M2MError extends Error {
|
|
29
|
-
/** OAuth 2.0 error code */
|
|
30
|
-
readonly code: M2MErrorCode;
|
|
31
|
-
/** HTTP status code from the response */
|
|
32
|
-
readonly status: number;
|
|
33
|
-
/** URI with more information about the error (if provided) */
|
|
34
|
-
readonly errorUri?: string;
|
|
35
|
-
/** Rate limit information (if rate limited) */
|
|
36
|
-
readonly rateLimitInfo?: M2MRateLimitInfo;
|
|
37
|
-
/** Response headers from the server */
|
|
38
|
-
readonly headers?: Record<string, string>;
|
|
39
|
-
/** Original error (if this wraps another error) */
|
|
40
|
-
readonly cause?: Error;
|
|
41
|
-
/** Timestamp when the error occurred */
|
|
42
|
-
readonly timestamp: string;
|
|
43
|
-
constructor(options: {
|
|
44
|
-
code: M2MErrorCode;
|
|
45
|
-
message: string;
|
|
46
|
-
status?: number;
|
|
47
|
-
errorUri?: string;
|
|
48
|
-
rateLimitInfo?: M2MRateLimitInfo;
|
|
49
|
-
headers?: Record<string, string>;
|
|
50
|
-
cause?: Error;
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* Create an M2MError from an OAuth 2.0 error response
|
|
54
|
-
*/
|
|
55
|
-
static fromOAuthError(errorResponse: {
|
|
56
|
-
error: M2MErrorCode;
|
|
57
|
-
error_description?: string;
|
|
58
|
-
error_uri?: string;
|
|
59
|
-
}, status: number, headers?: Record<string, string>): M2MError;
|
|
60
|
-
/**
|
|
61
|
-
* Create an M2MError from a network or other error
|
|
62
|
-
*/
|
|
63
|
-
static fromError(error: Error, code?: M2MErrorCode): M2MError;
|
|
64
|
-
/**
|
|
65
|
-
* Parse rate limit headers from response
|
|
66
|
-
*/
|
|
67
|
-
static parseRateLimitHeaders(headers: Record<string, string>): M2MRateLimitInfo | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Get default error message for an error code
|
|
70
|
-
*/
|
|
71
|
-
static getDefaultMessage(code: M2MErrorCode): string;
|
|
72
|
-
/**
|
|
73
|
-
* Check if the error is retryable
|
|
74
|
-
*/
|
|
75
|
-
isRetryable(): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Get suggested wait time before retry (in milliseconds)
|
|
78
|
-
*/
|
|
79
|
-
getRetryAfter(): number;
|
|
80
|
-
/**
|
|
81
|
-
* Convert to JSON-serializable object
|
|
82
|
-
*/
|
|
83
|
-
toJSON(): Record<string, unknown>;
|
|
84
|
-
/**
|
|
85
|
-
* Create a human-readable string representation
|
|
86
|
-
*/
|
|
87
|
-
toString(): string;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Network error (connection failed, timeout, etc.)
|
|
91
|
-
*/
|
|
92
|
-
export declare class M2MNetworkError extends M2MError {
|
|
93
|
-
constructor(message: string, cause?: Error);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Token parsing error (invalid JWT format)
|
|
97
|
-
*/
|
|
98
|
-
export declare class M2MTokenParseError extends M2MError {
|
|
99
|
-
constructor(message: string, cause?: Error);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Configuration error (missing or invalid config)
|
|
103
|
-
*/
|
|
104
|
-
export declare class M2MConfigError extends M2MError {
|
|
105
|
-
constructor(message: string);
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../lib/m2m/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,2BAA2B;IAC3B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAE5B,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,8DAA8D;IAC9D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,QAAQ,CAAC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IAE1C,uCAAuC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1C,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YAAY,OAAO,EAAE;QACnB,IAAI,EAAE,YAAY,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,gBAAgB,CAAC;QACjC,OAAO,CAAC,EAAE,M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@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* M2M (Machine-to-Machine) Authentication Module
|
|
3
|
-
*
|
|
4
|
-
* OAuth 2.0 Client Credentials Grant implementation for server-to-server
|
|
5
|
-
* authentication without user involvement.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { M2MClient } from '@passflow/core';
|
|
10
|
-
*
|
|
11
|
-
* const m2m = new M2MClient({
|
|
12
|
-
* url: 'https://auth.yourapp.com',
|
|
13
|
-
* clientId: 'your-client-id',
|
|
14
|
-
* clientSecret: 'your-client-secret',
|
|
15
|
-
* scopes: ['users:read', 'orders:write'],
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* const token = await m2m.getToken();
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @packageDocumentation
|
|
22
|
-
*/
|
|
23
|
-
export { M2MClient } from './client';
|
|
24
|
-
export { M2MConfigError, M2MError, M2MNetworkError, M2MTokenParseError } from './errors';
|
|
25
|
-
export type { M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, RetryStrategy, } from './types';
|
|
26
|
-
export { M2M_DEFAULTS, M2MErrorCodes } from './types';
|
|
27
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/m2m/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGzF,YAAY,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/lib/m2m/types.d.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* M2M (Machine-to-Machine) Authentication Types
|
|
3
|
-
*
|
|
4
|
-
* OAuth 2.0 Client Credentials Grant implementation for server-to-server
|
|
5
|
-
* authentication without user involvement.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* M2M Client configuration options
|
|
9
|
-
*/
|
|
10
|
-
export type M2MClientConfig = {
|
|
11
|
-
/** Passflow server URL */
|
|
12
|
-
url: string;
|
|
13
|
-
/** M2M application client ID */
|
|
14
|
-
clientId: string;
|
|
15
|
-
/** M2M application client secret */
|
|
16
|
-
clientSecret: string;
|
|
17
|
-
/** Scopes to request (default: []) */
|
|
18
|
-
scopes?: string[];
|
|
19
|
-
/** Target audiences for the token */
|
|
20
|
-
audience?: string[];
|
|
21
|
-
/** Automatically refresh tokens before expiry (default: false) */
|
|
22
|
-
autoRefresh?: boolean;
|
|
23
|
-
/** Seconds before expiry to trigger refresh (default: 30) */
|
|
24
|
-
refreshThreshold?: number;
|
|
25
|
-
/** Request timeout in milliseconds (default: 10000) */
|
|
26
|
-
timeout?: number;
|
|
27
|
-
/** Number of retry attempts on failure (default: 3) */
|
|
28
|
-
retries?: number;
|
|
29
|
-
/** Delay between retries in milliseconds (default: 1000) */
|
|
30
|
-
retryDelay?: number;
|
|
31
|
-
/** Custom retry strategy */
|
|
32
|
-
retryStrategy?: RetryStrategy;
|
|
33
|
-
/** Custom token cache implementation */
|
|
34
|
-
cache?: M2MTokenCache;
|
|
35
|
-
/** Callback for token requests (for logging/metrics) */
|
|
36
|
-
onTokenRequest?: (request: M2MTokenRequestInfo) => void;
|
|
37
|
-
/** Callback for token responses (for logging/metrics) */
|
|
38
|
-
onTokenResponse?: (response: M2MTokenResponse) => void;
|
|
39
|
-
/** Callback for errors (for logging/metrics) */
|
|
40
|
-
onError?: (error: M2MErrorResponse) => void;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Token request options (can override defaults per-request)
|
|
44
|
-
*/
|
|
45
|
-
export type M2MTokenRequestOptions = {
|
|
46
|
-
/** Override default scopes for this request */
|
|
47
|
-
scopes?: string[];
|
|
48
|
-
/** Override default audience for this request */
|
|
49
|
-
audience?: string[];
|
|
50
|
-
/** Force a new token request, ignoring cache */
|
|
51
|
-
forceRefresh?: boolean;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Token request info (for logging callbacks)
|
|
55
|
-
*/
|
|
56
|
-
export type M2MTokenRequestInfo = {
|
|
57
|
-
/** Client ID being used */
|
|
58
|
-
clientId: string;
|
|
59
|
-
/** Scopes being requested */
|
|
60
|
-
scopes: string[];
|
|
61
|
-
/** Audiences being requested */
|
|
62
|
-
audience: string[];
|
|
63
|
-
/** Request timestamp */
|
|
64
|
-
timestamp: string;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* OAuth 2.0 token response from the authorization server
|
|
68
|
-
*/
|
|
69
|
-
export type M2MTokenResponse = {
|
|
70
|
-
/** The access token (JWT) */
|
|
71
|
-
access_token: string;
|
|
72
|
-
/** Token type (always "Bearer") */
|
|
73
|
-
token_type: 'Bearer';
|
|
74
|
-
/** Token lifetime in seconds */
|
|
75
|
-
expires_in: number;
|
|
76
|
-
/** Granted scopes (space-separated string) */
|
|
77
|
-
scope?: string;
|
|
78
|
-
/** Timestamp when token was issued (added by client) */
|
|
79
|
-
issued_at?: number;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* OAuth 2.0 error response from the authorization server
|
|
83
|
-
*/
|
|
84
|
-
export type M2MErrorResponse = {
|
|
85
|
-
/** OAuth 2.0 error code */
|
|
86
|
-
error: M2MErrorCode;
|
|
87
|
-
/** Human-readable error description */
|
|
88
|
-
error_description?: string;
|
|
89
|
-
/** URI with more information about the error */
|
|
90
|
-
error_uri?: string;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Parsed M2M JWT token claims
|
|
94
|
-
*/
|
|
95
|
-
export type M2MTokenClaims = {
|
|
96
|
-
/** Issuer (Passflow server URL) */
|
|
97
|
-
iss: string;
|
|
98
|
-
/** Subject (client_id) */
|
|
99
|
-
sub: string;
|
|
100
|
-
/** Audience (target APIs) */
|
|
101
|
-
aud: string | string[];
|
|
102
|
-
/** Issued at timestamp (Unix epoch seconds) */
|
|
103
|
-
iat: number;
|
|
104
|
-
/** Expiration timestamp (Unix epoch seconds) */
|
|
105
|
-
exp: number;
|
|
106
|
-
/** JWT ID (unique token identifier) */
|
|
107
|
-
jti?: string;
|
|
108
|
-
/** Token type ("m2m") */
|
|
109
|
-
type: 'm2m';
|
|
110
|
-
/** Client ID */
|
|
111
|
-
client_id: string;
|
|
112
|
-
/** Tenant ID (for tenant-scoped M2M apps) */
|
|
113
|
-
tenant_id?: string;
|
|
114
|
-
/** Granted scopes */
|
|
115
|
-
scopes: string[];
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* M2M error codes (OAuth 2.0 compliant)
|
|
119
|
-
*/
|
|
120
|
-
export type M2MErrorCode = 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_scope' | 'unauthorized_client' | 'unsupported_grant_type' | 'rate_limit_exceeded' | 'server_error' | 'temporarily_unavailable';
|
|
121
|
-
/**
|
|
122
|
-
* M2M error code enum for convenience
|
|
123
|
-
*/
|
|
124
|
-
export declare const M2MErrorCodes: {
|
|
125
|
-
InvalidRequest: 'invalid_request';
|
|
126
|
-
InvalidClient: 'invalid_client';
|
|
127
|
-
InvalidGrant: 'invalid_grant';
|
|
128
|
-
InvalidScope: 'invalid_scope';
|
|
129
|
-
UnauthorizedClient: 'unauthorized_client';
|
|
130
|
-
UnsupportedGrantType: 'unsupported_grant_type';
|
|
131
|
-
RateLimitExceeded: 'rate_limit_exceeded';
|
|
132
|
-
ServerError: 'server_error';
|
|
133
|
-
TemporarilyUnavailable: 'temporarily_unavailable';
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Custom token cache interface for external cache implementations
|
|
137
|
-
*/
|
|
138
|
-
export interface M2MTokenCache {
|
|
139
|
-
/**
|
|
140
|
-
* Get cached token by key
|
|
141
|
-
* @param key Cache key (typically clientId)
|
|
142
|
-
* @returns Cached token or null if not found/expired
|
|
143
|
-
*/
|
|
144
|
-
get(key: string): Promise<M2MTokenResponse | null>;
|
|
145
|
-
/**
|
|
146
|
-
* Cache a token with TTL
|
|
147
|
-
* @param key Cache key (typically clientId)
|
|
148
|
-
* @param token Token to cache
|
|
149
|
-
* @param ttl Time-to-live in seconds
|
|
150
|
-
*/
|
|
151
|
-
set(key: string, token: M2MTokenResponse, ttl: number): Promise<void>;
|
|
152
|
-
/**
|
|
153
|
-
* Delete cached token
|
|
154
|
-
* @param key Cache key (typically clientId)
|
|
155
|
-
*/
|
|
156
|
-
delete(key: string): Promise<void>;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Custom retry strategy interface
|
|
160
|
-
*/
|
|
161
|
-
export interface RetryStrategy {
|
|
162
|
-
/**
|
|
163
|
-
* Determine if the request should be retried
|
|
164
|
-
* @param error The error that occurred
|
|
165
|
-
* @param attempt Current attempt number (1-based)
|
|
166
|
-
* @returns true if request should be retried
|
|
167
|
-
*/
|
|
168
|
-
shouldRetry(error: {
|
|
169
|
-
code: M2MErrorCode;
|
|
170
|
-
status?: number;
|
|
171
|
-
}, attempt: number): boolean;
|
|
172
|
-
/**
|
|
173
|
-
* Get delay before next retry
|
|
174
|
-
* @param attempt Current attempt number (1-based)
|
|
175
|
-
* @returns Delay in milliseconds
|
|
176
|
-
*/
|
|
177
|
-
getDelay(attempt: number): number;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Internal token request payload sent to the authorization server
|
|
181
|
-
*/
|
|
182
|
-
export type M2MTokenRequestPayload = {
|
|
183
|
-
grant_type: 'client_credentials';
|
|
184
|
-
client_id: string;
|
|
185
|
-
client_secret: string;
|
|
186
|
-
scope?: string;
|
|
187
|
-
audience?: string;
|
|
188
|
-
};
|
|
189
|
-
/**
|
|
190
|
-
* Rate limit information from response headers
|
|
191
|
-
*/
|
|
192
|
-
export type M2MRateLimitInfo = {
|
|
193
|
-
/** Maximum requests allowed in the window */
|
|
194
|
-
limit: number;
|
|
195
|
-
/** Remaining requests in the current window */
|
|
196
|
-
remaining: number;
|
|
197
|
-
/** Unix timestamp when the window resets */
|
|
198
|
-
reset: number;
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* Default configuration values
|
|
202
|
-
*/
|
|
203
|
-
export declare const M2M_DEFAULTS: {
|
|
204
|
-
/** Default token endpoint path */
|
|
205
|
-
readonly TOKEN_ENDPOINT: '/oauth2/token';
|
|
206
|
-
/** Default request timeout in milliseconds */
|
|
207
|
-
readonly TIMEOUT: 10000;
|
|
208
|
-
/** Default number of retry attempts */
|
|
209
|
-
readonly RETRIES: 3;
|
|
210
|
-
/** Default delay between retries in milliseconds */
|
|
211
|
-
readonly RETRY_DELAY: 1000;
|
|
212
|
-
/** Default refresh threshold in seconds */
|
|
213
|
-
readonly REFRESH_THRESHOLD: 30;
|
|
214
|
-
/** Content-Type for token requests */
|
|
215
|
-
readonly CONTENT_TYPE: 'application/x-www-form-urlencoded';
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/m2m/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IAEZ,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IAEjB,oC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