@arca-network/sdk 1.1.0
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/LICENSE +91 -0
- package/README.md +65 -0
- package/dist/admin.d.ts +159 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +399 -0
- package/dist/admin.js.map +1 -0
- package/dist/arca.d.ts +1343 -0
- package/dist/arca.d.ts.map +1 -0
- package/dist/arca.js +3454 -0
- package/dist/arca.js.map +1 -0
- package/dist/cache.d.ts +29 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +74 -0
- package/dist/cache.js.map +1 -0
- package/dist/candle-cdn.d.ts +17 -0
- package/dist/candle-cdn.d.ts.map +1 -0
- package/dist/candle-cdn.js +138 -0
- package/dist/candle-cdn.js.map +1 -0
- package/dist/client.d.ts +98 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +225 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +153 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +243 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +2 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +6 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +71 -0
- package/dist/index.js.map +1 -0
- package/dist/ladder.d.ts +40 -0
- package/dist/ladder.d.ts.map +1 -0
- package/dist/ladder.js +145 -0
- package/dist/ladder.js.map +1 -0
- package/dist/ladder.test.d.ts +2 -0
- package/dist/ladder.test.d.ts.map +1 -0
- package/dist/ladder.test.js +112 -0
- package/dist/ladder.test.js.map +1 -0
- package/dist/operation-handle.d.ts +88 -0
- package/dist/operation-handle.d.ts.map +1 -0
- package/dist/operation-handle.js +262 -0
- package/dist/operation-handle.js.map +1 -0
- package/dist/recovery.d.ts +20 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +91 -0
- package/dist/recovery.js.map +1 -0
- package/dist/revalue.d.ts +22 -0
- package/dist/revalue.d.ts.map +1 -0
- package/dist/revalue.js +153 -0
- package/dist/revalue.js.map +1 -0
- package/dist/streams.d.ts +661 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +2272 -0
- package/dist/streams.js.map +1 -0
- package/dist/types.d.ts +2814 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +118 -0
- package/dist/types.js.map +1 -0
- package/dist/websocket.d.ts +240 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +1288 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +48 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArcaClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const TRANSIENT_STATUSES = new Set([502, 503, 504]);
|
|
6
|
+
const MAX_RETRIES = 2;
|
|
7
|
+
// Backoff with full jitter: a shorter first delay than the old fixed 1s, and
|
|
8
|
+
// randomized so many clients retrying a briefly-degraded upstream don't fire
|
|
9
|
+
// in lockstep. Capped well under a second so a transient blip adds at most a
|
|
10
|
+
// few hundred ms to a request instead of stacking into seconds.
|
|
11
|
+
const RETRY_BASE_DELAY_MS = 250;
|
|
12
|
+
const RETRY_MAX_DELAY_MS = 2000;
|
|
13
|
+
function retryDelayMs(attempt) {
|
|
14
|
+
const ceil = Math.min(RETRY_MAX_DELAY_MS, RETRY_BASE_DELAY_MS * 2 ** attempt);
|
|
15
|
+
return Math.floor(Math.random() * ceil);
|
|
16
|
+
}
|
|
17
|
+
function isTransient(err, status) {
|
|
18
|
+
if (status !== undefined && TRANSIENT_STATUSES.has(status))
|
|
19
|
+
return true;
|
|
20
|
+
if (err instanceof TypeError)
|
|
21
|
+
return true; // network failure
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Low-level HTTP client for the Arca API.
|
|
26
|
+
* Handles authentication, request construction, response envelope unwrapping,
|
|
27
|
+
* and automatic retries for transient errors (502/503/504 + network failures).
|
|
28
|
+
*/
|
|
29
|
+
class ArcaClient {
|
|
30
|
+
credential;
|
|
31
|
+
credentialType;
|
|
32
|
+
baseUrl;
|
|
33
|
+
onUnauthorizedCb;
|
|
34
|
+
onAuthErrorCb;
|
|
35
|
+
stepUpHandler;
|
|
36
|
+
// Re-entrancy guard: prevents a step-up retry from itself triggering
|
|
37
|
+
// another step-up cycle on a 412 (mirrors the CLI's stepUpInFlight
|
|
38
|
+
// flag in cli/internal/api/client.go).
|
|
39
|
+
stepUpInFlight = false;
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.credential = config.credential;
|
|
42
|
+
this.credentialType = config.credentialType;
|
|
43
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, '');
|
|
44
|
+
this.onUnauthorizedCb = config.onUnauthorized;
|
|
45
|
+
this.onAuthErrorCb = config.onAuthError;
|
|
46
|
+
this.stepUpHandler = config.onStepUpRequired;
|
|
47
|
+
}
|
|
48
|
+
/** Replace the credential used for subsequent requests. */
|
|
49
|
+
updateCredential(credential) {
|
|
50
|
+
this.credential = credential;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Register or clear the step-up handler that intercepts 412
|
|
54
|
+
* `STEP_UP_REQUIRED` responses. Mirrors the CLI's `SetStepUpHandler`
|
|
55
|
+
* — used by the portal to wire an in-app confirmation modal after
|
|
56
|
+
* the client is constructed.
|
|
57
|
+
*/
|
|
58
|
+
setStepUpHandler(handler) {
|
|
59
|
+
this.stepUpHandler = handler;
|
|
60
|
+
}
|
|
61
|
+
async get(path, params) {
|
|
62
|
+
return this.executeWithAuthRetry('GET', path, params);
|
|
63
|
+
}
|
|
64
|
+
async post(path, body) {
|
|
65
|
+
return this.executeWithAuthRetry('POST', path, undefined, body);
|
|
66
|
+
}
|
|
67
|
+
async patch(path, params, body) {
|
|
68
|
+
return this.executeWithAuthRetry('PATCH', path, params, body);
|
|
69
|
+
}
|
|
70
|
+
async put(path, body) {
|
|
71
|
+
return this.executeWithAuthRetry('PUT', path, undefined, body);
|
|
72
|
+
}
|
|
73
|
+
async delete(path) {
|
|
74
|
+
return this.executeWithAuthRetry('DELETE', path);
|
|
75
|
+
}
|
|
76
|
+
// ---- Private helpers ----
|
|
77
|
+
/**
|
|
78
|
+
* Wraps requestWithRetry with a single 401 retry: on UnauthorizedError,
|
|
79
|
+
* calls onUnauthorized to get a fresh credential, then retries once.
|
|
80
|
+
* Emits onAuthError when the 401 is not recoverable.
|
|
81
|
+
*
|
|
82
|
+
* Also handles {@link StepUpRequiredError} (HTTP 412) by invoking the
|
|
83
|
+
* registered step-up handler and retrying the request once with the
|
|
84
|
+
* resulting step-up token as the bearer. The original credential is
|
|
85
|
+
* restored after the retry — the step-up token is never persisted
|
|
86
|
+
* (per `.cursor/rules/step-up-auth.mdc`).
|
|
87
|
+
*/
|
|
88
|
+
async executeWithAuthRetry(method, path, params, body) {
|
|
89
|
+
try {
|
|
90
|
+
return await this.requestWithRetry(method, path, params, body);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof errors_1.UnauthorizedError && this.onUnauthorizedCb) {
|
|
94
|
+
try {
|
|
95
|
+
const newCredential = await this.onUnauthorizedCb();
|
|
96
|
+
this.credential = newCredential;
|
|
97
|
+
return await this.requestWithRetry(method, path, params, body);
|
|
98
|
+
}
|
|
99
|
+
catch (retryErr) {
|
|
100
|
+
const reportErr = retryErr instanceof Error ? retryErr : err;
|
|
101
|
+
this.onAuthErrorCb?.(reportErr instanceof errors_1.UnauthorizedError ? reportErr : new errors_1.UnauthorizedError(reportErr.message));
|
|
102
|
+
throw retryErr;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (err instanceof errors_1.UnauthorizedError) {
|
|
106
|
+
this.onAuthErrorCb?.(err);
|
|
107
|
+
}
|
|
108
|
+
if (err instanceof errors_1.StepUpRequiredError &&
|
|
109
|
+
this.stepUpHandler &&
|
|
110
|
+
!this.stepUpInFlight) {
|
|
111
|
+
return await this.runStepUpRetry(err, method, path, params, body);
|
|
112
|
+
}
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Drives the step-up confirmation flow and retries the original
|
|
118
|
+
* request once with the resulting step-up token.
|
|
119
|
+
*
|
|
120
|
+
* - Invokes the handler with the `{ action, resources }` challenge
|
|
121
|
+
* extracted from the 412 response.
|
|
122
|
+
* - Swaps `this.credential` with the returned step-up token for the
|
|
123
|
+
* duration of the retry only; restores the original credential in a
|
|
124
|
+
* `finally` so a subsequent unrelated request continues to use the
|
|
125
|
+
* builder JWT / API key.
|
|
126
|
+
* - The handler rejecting (e.g. user cancelled) surfaces as a
|
|
127
|
+
* {@link StepUpCancelledError} carrying the handler's reason.
|
|
128
|
+
*/
|
|
129
|
+
async runStepUpRetry(err, method, path, params, body) {
|
|
130
|
+
this.stepUpInFlight = true;
|
|
131
|
+
let stepUpToken;
|
|
132
|
+
try {
|
|
133
|
+
stepUpToken = await this.stepUpHandler({ action: err.action, resources: err.resources });
|
|
134
|
+
}
|
|
135
|
+
catch (handlerErr) {
|
|
136
|
+
this.stepUpInFlight = false;
|
|
137
|
+
if (handlerErr instanceof errors_1.StepUpCancelledError)
|
|
138
|
+
throw handlerErr;
|
|
139
|
+
const message = handlerErr instanceof Error ? handlerErr.message : 'Step-up confirmation was cancelled';
|
|
140
|
+
throw new errors_1.StepUpCancelledError(message);
|
|
141
|
+
}
|
|
142
|
+
const originalCredential = this.credential;
|
|
143
|
+
this.credential = stepUpToken;
|
|
144
|
+
try {
|
|
145
|
+
return await this.requestWithRetry(method, path, params, body);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
this.credential = originalCredential;
|
|
149
|
+
this.stepUpInFlight = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async requestWithRetry(method, path, params, body) {
|
|
153
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
154
|
+
try {
|
|
155
|
+
return await this.requestOnce(method, path, params, body);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
const status = err instanceof TransientHttpError ? err.status : undefined;
|
|
159
|
+
if (!isTransient(err, status) || attempt === MAX_RETRIES)
|
|
160
|
+
throw err;
|
|
161
|
+
await new Promise((r) => setTimeout(r, retryDelayMs(attempt)));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw new Error('unreachable');
|
|
165
|
+
}
|
|
166
|
+
async requestOnce(method, path, params, body) {
|
|
167
|
+
const url = this.buildUrl(path, params);
|
|
168
|
+
const res = await fetch(url, {
|
|
169
|
+
method,
|
|
170
|
+
headers: this.headers(),
|
|
171
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
172
|
+
});
|
|
173
|
+
if (TRANSIENT_STATUSES.has(res.status)) {
|
|
174
|
+
throw new TransientHttpError(res.status);
|
|
175
|
+
}
|
|
176
|
+
return this.unwrap(res);
|
|
177
|
+
}
|
|
178
|
+
headers() {
|
|
179
|
+
return {
|
|
180
|
+
'Content-Type': 'application/json',
|
|
181
|
+
'Authorization': `Bearer ${this.credential}`,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
buildUrl(path, params) {
|
|
185
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
186
|
+
if (params) {
|
|
187
|
+
for (const [key, value] of Object.entries(params)) {
|
|
188
|
+
if (value !== undefined && value !== null) {
|
|
189
|
+
url.searchParams.set(key, value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return url.toString();
|
|
194
|
+
}
|
|
195
|
+
async unwrap(res) {
|
|
196
|
+
const text = await res.text();
|
|
197
|
+
let body;
|
|
198
|
+
try {
|
|
199
|
+
body = JSON.parse(text);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
const preview = text.length > 200 ? text.slice(0, 200) + '…' : text;
|
|
203
|
+
throw new errors_1.ArcaError('NON_JSON_RESPONSE', `Server returned non-JSON response (HTTP ${res.status}): ${preview}`);
|
|
204
|
+
}
|
|
205
|
+
if (!body.success || !body.data) {
|
|
206
|
+
if (res.status === 401) {
|
|
207
|
+
throw new errors_1.UnauthorizedError(body.error?.message, body.error?.errorId);
|
|
208
|
+
}
|
|
209
|
+
if (body.error) {
|
|
210
|
+
throw (0, errors_1.mapApiError)(body.error.code, body.error.message, body.error.errorId, body.error.details);
|
|
211
|
+
}
|
|
212
|
+
throw new errors_1.ArcaError('UNKNOWN', `Request failed with status ${res.status}`);
|
|
213
|
+
}
|
|
214
|
+
return body.data;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.ArcaClient = ArcaClient;
|
|
218
|
+
class TransientHttpError extends Error {
|
|
219
|
+
status;
|
|
220
|
+
constructor(status) {
|
|
221
|
+
super(`Transient HTTP ${status}`);
|
|
222
|
+
this.status = status;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,qCAOkB;AAwClB,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACpD,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,gEAAgE;AAChE,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,SAAS,YAAY,CAAC,OAAe;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,mBAAmB,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC;IAC9E,OAAO,IAAI,C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AK,CAAC,kBAAkB,MAAM,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Arca SDK errors.
|
|
3
|
+
* Every error carries an optional `errorId` (UUID) that can be used to
|
|
4
|
+
* correlate with server-side logs.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ArcaError extends Error {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly errorId?: string;
|
|
9
|
+
constructor(code: string, message: string, errorId?: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Thrown when the API returns a validation error (400).
|
|
13
|
+
*/
|
|
14
|
+
export declare class ValidationError extends ArcaError {
|
|
15
|
+
constructor(message: string, errorId?: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when authentication fails (401).
|
|
19
|
+
*/
|
|
20
|
+
export declare class UnauthorizedError extends ArcaError {
|
|
21
|
+
constructor(message?: string, errorId?: string);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Thrown when a resource is not found (404).
|
|
25
|
+
*/
|
|
26
|
+
export declare class NotFoundError extends ArcaError {
|
|
27
|
+
constructor(message?: string, errorId?: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Thrown when there is a conflict (409).
|
|
31
|
+
*/
|
|
32
|
+
export declare class ConflictError extends ArcaError {
|
|
33
|
+
constructor(message: string, errorId?: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when the server returns an unexpected error (500).
|
|
37
|
+
*/
|
|
38
|
+
export declare class InternalError extends ArcaError {
|
|
39
|
+
constructor(message?: string, errorId?: string);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when an upstream exchange service returns an error (502).
|
|
43
|
+
* Covers both user-facing exchange errors (e.g., ORDER_FAILED) and
|
|
44
|
+
* infrastructure failures (EXCHANGE_UNAVAILABLE).
|
|
45
|
+
*/
|
|
46
|
+
export declare class ExchangeError extends ArcaError {
|
|
47
|
+
constructor(code?: string, message?: string, errorId?: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Thrown when an operation reaches a non-success terminal state (`failed` or `expired`).
|
|
51
|
+
* The full Operation object is available on the `operation` property.
|
|
52
|
+
*
|
|
53
|
+
* `error.message` is a human-readable string from `failureMessage` when available,
|
|
54
|
+
* falling back to a generic message. The raw `outcome` JSON is still accessible on
|
|
55
|
+
* `error.operation.outcome` for programmatic inspection.
|
|
56
|
+
*/
|
|
57
|
+
export declare class OperationFailedError extends ArcaError {
|
|
58
|
+
readonly operation: {
|
|
59
|
+
id: string;
|
|
60
|
+
state: string;
|
|
61
|
+
outcome: string | null;
|
|
62
|
+
failureMessage: string | null;
|
|
63
|
+
};
|
|
64
|
+
constructor(operation: {
|
|
65
|
+
id: string;
|
|
66
|
+
state: string;
|
|
67
|
+
outcome: string | null;
|
|
68
|
+
failureMessage?: string | null;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown when {@link Arca.waitForOperation} (or `await` on an `OperationHandle`)
|
|
73
|
+
* times out before the operation reaches a terminal state.
|
|
74
|
+
*
|
|
75
|
+
* Distinct from {@link OperationFailedError}, which signals a definitive
|
|
76
|
+
* backend failure. `OperationStalledError` means the wait budget elapsed
|
|
77
|
+
* while the operation was still pending — it may still complete or fail
|
|
78
|
+
* later.
|
|
79
|
+
*
|
|
80
|
+
* The error carries the last known {@link operation} snapshot (best effort
|
|
81
|
+
* via a final REST fetch on timeout) so callers can inspect the in-flight
|
|
82
|
+
* state, and the {@link timeoutMs} that was applied. The error message
|
|
83
|
+
* preserves the legacy `Timed out waiting for operation <id>` substring
|
|
84
|
+
* for backwards compatibility with consumers that match on it.
|
|
85
|
+
*/
|
|
86
|
+
export declare class OperationStalledError extends ArcaError {
|
|
87
|
+
readonly operationId: string;
|
|
88
|
+
readonly timeoutMs: number;
|
|
89
|
+
/**
|
|
90
|
+
* Last known operation snapshot (from the final fetch attempt or the most
|
|
91
|
+
* recent `operation.updated` event). May be `null` if the SDK never
|
|
92
|
+
* received a snapshot — e.g. the operation was never returned by an
|
|
93
|
+
* initial GET.
|
|
94
|
+
*/
|
|
95
|
+
readonly operation: {
|
|
96
|
+
id: string;
|
|
97
|
+
state: string;
|
|
98
|
+
outcome: string | null;
|
|
99
|
+
failureMessage: string | null;
|
|
100
|
+
} | null;
|
|
101
|
+
constructor(operationId: string, timeoutMs: number, operation: {
|
|
102
|
+
id: string;
|
|
103
|
+
state: string;
|
|
104
|
+
outcome: string | null;
|
|
105
|
+
failureMessage?: string | null;
|
|
106
|
+
} | null);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Structured challenge payload accompanying a 412 `STEP_UP_REQUIRED` response.
|
|
110
|
+
*
|
|
111
|
+
* `action` is the {@link permission} action the server is gating (e.g.
|
|
112
|
+
* `arca:DeleteObject`); `resources` is the list of resource identifiers
|
|
113
|
+
* the step-up token must authorize.
|
|
114
|
+
*/
|
|
115
|
+
export interface StepUpChallenge {
|
|
116
|
+
action: string;
|
|
117
|
+
resources: string[];
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Thrown when the server requires browser confirmation for a destructive
|
|
121
|
+
* action on a production realm (HTTP 412 with code `STEP_UP_REQUIRED`).
|
|
122
|
+
*
|
|
123
|
+
* The {@link action} and {@link resources} carried on the error mirror the
|
|
124
|
+
* server's structured challenge payload (`error.details`) and are used to
|
|
125
|
+
* mint a single-use step-up token via `POST /api/v1/auth/step-up-requests`.
|
|
126
|
+
*
|
|
127
|
+
* In normal SDK use this is intercepted by an `onStepUpRequired` handler
|
|
128
|
+
* registered on the client; the SDK then transparently retries the
|
|
129
|
+
* original request once with the resulting step-up token. The error only
|
|
130
|
+
* propagates to caller code when no handler is wired or the handler
|
|
131
|
+
* rejects.
|
|
132
|
+
*/
|
|
133
|
+
export declare class StepUpRequiredError extends ArcaError {
|
|
134
|
+
readonly action: string;
|
|
135
|
+
readonly resources: string[];
|
|
136
|
+
constructor(message: string, challenge: StepUpChallenge, errorId?: string);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Thrown when an `onStepUpRequired` handler signals that the user
|
|
140
|
+
* cancelled the confirmation flow (or it expired / errored).
|
|
141
|
+
*
|
|
142
|
+
* Distinct from {@link StepUpRequiredError} which describes the server
|
|
143
|
+
* gate; this error is raised by the SDK retry shim when the handler's
|
|
144
|
+
* Promise rejects.
|
|
145
|
+
*/
|
|
146
|
+
export declare class StepUpCancelledError extends ArcaError {
|
|
147
|
+
constructor(message?: string);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Maps an API error response to a typed SDK error.
|
|
151
|
+
*/
|
|
152
|
+
export declare function mapApiError(code: string, message: string, errorId?: string, details?: Record<string, unknown> | null): ArcaError;
|
|
153
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAErB,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAM5D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI9C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,GAAE,MAA4C,EAAE,OAAO,CAAC,EAAE,MAAM;CAIpF;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,OAA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;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,IAAI;CAY1G;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,SAAS,EAAE,MAAM,EAAE,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM;CAM1E;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,OAAO,GAAE,MAA6C;CAInE;AAkBD;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACvC,SAAS,CA0CX"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StepUpCancelledError = exports.StepUpRequiredError = exports.OperationStalledError = exports.OperationFailedError = exports.ExchangeError = exports.InternalError = exports.ConflictError = exports.NotFoundError = exports.UnauthorizedError = exports.ValidationError = exports.ArcaError = void 0;
|
|
4
|
+
exports.mapApiError = mapApiError;
|
|
5
|
+
/**
|
|
6
|
+
* Base error class for all Arca SDK errors.
|
|
7
|
+
* Every error carries an optional `errorId` (UUID) that can be used to
|
|
8
|
+
* correlate with server-side logs.
|
|
9
|
+
*/
|
|
10
|
+
class ArcaError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
errorId;
|
|
13
|
+
constructor(code, message, errorId) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ArcaError';
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.errorId = errorId;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ArcaError = ArcaError;
|
|
21
|
+
/**
|
|
22
|
+
* Thrown when the API returns a validation error (400).
|
|
23
|
+
*/
|
|
24
|
+
class ValidationError extends ArcaError {
|
|
25
|
+
constructor(message, errorId) {
|
|
26
|
+
super('VALIDATION_ERROR', message, errorId);
|
|
27
|
+
this.name = 'ValidationError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ValidationError = ValidationError;
|
|
31
|
+
/**
|
|
32
|
+
* Thrown when authentication fails (401).
|
|
33
|
+
*/
|
|
34
|
+
class UnauthorizedError extends ArcaError {
|
|
35
|
+
constructor(message = 'Invalid or expired authentication', errorId) {
|
|
36
|
+
super('UNAUTHORIZED', message, errorId);
|
|
37
|
+
this.name = 'UnauthorizedError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when a resource is not found (404).
|
|
43
|
+
*/
|
|
44
|
+
class NotFoundError extends ArcaError {
|
|
45
|
+
constructor(message = 'Resource not found', errorId) {
|
|
46
|
+
super('NOT_FOUND', message, errorId);
|
|
47
|
+
this.name = 'NotFoundError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.NotFoundError = NotFoundError;
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when there is a conflict (409).
|
|
53
|
+
*/
|
|
54
|
+
class ConflictError extends ArcaError {
|
|
55
|
+
constructor(message, errorId) {
|
|
56
|
+
super('CONFLICT', message, errorId);
|
|
57
|
+
this.name = 'ConflictError';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.ConflictError = ConflictError;
|
|
61
|
+
/**
|
|
62
|
+
* Thrown when the server returns an unexpected error (500).
|
|
63
|
+
*/
|
|
64
|
+
class InternalError extends ArcaError {
|
|
65
|
+
constructor(message = 'An unexpected error occurred', errorId) {
|
|
66
|
+
super('INTERNAL_ERROR', message, errorId);
|
|
67
|
+
this.name = 'InternalError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.InternalError = InternalError;
|
|
71
|
+
/**
|
|
72
|
+
* Thrown when an upstream exchange service returns an error (502).
|
|
73
|
+
* Covers both user-facing exchange errors (e.g., ORDER_FAILED) and
|
|
74
|
+
* infrastructure failures (EXCHANGE_UNAVAILABLE).
|
|
75
|
+
*/
|
|
76
|
+
class ExchangeError extends ArcaError {
|
|
77
|
+
constructor(code = 'EXCHANGE_ERROR', message = 'An exchange service error occurred', errorId) {
|
|
78
|
+
super(code, message, errorId);
|
|
79
|
+
this.name = 'ExchangeError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ExchangeError = ExchangeError;
|
|
83
|
+
/**
|
|
84
|
+
* Thrown when an operation reaches a non-success terminal state (`failed` or `expired`).
|
|
85
|
+
* The full Operation object is available on the `operation` property.
|
|
86
|
+
*
|
|
87
|
+
* `error.message` is a human-readable string from `failureMessage` when available,
|
|
88
|
+
* falling back to a generic message. The raw `outcome` JSON is still accessible on
|
|
89
|
+
* `error.operation.outcome` for programmatic inspection.
|
|
90
|
+
*/
|
|
91
|
+
class OperationFailedError extends ArcaError {
|
|
92
|
+
operation;
|
|
93
|
+
constructor(operation) {
|
|
94
|
+
const displayMessage = operation.failureMessage ?? 'This operation could not be completed.';
|
|
95
|
+
super('OPERATION_FAILED', displayMessage);
|
|
96
|
+
this.name = 'OperationFailedError';
|
|
97
|
+
this.operation = { ...operation, failureMessage: operation.failureMessage ?? null };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.OperationFailedError = OperationFailedError;
|
|
101
|
+
/**
|
|
102
|
+
* Thrown when {@link Arca.waitForOperation} (or `await` on an `OperationHandle`)
|
|
103
|
+
* times out before the operation reaches a terminal state.
|
|
104
|
+
*
|
|
105
|
+
* Distinct from {@link OperationFailedError}, which signals a definitive
|
|
106
|
+
* backend failure. `OperationStalledError` means the wait budget elapsed
|
|
107
|
+
* while the operation was still pending — it may still complete or fail
|
|
108
|
+
* later.
|
|
109
|
+
*
|
|
110
|
+
* The error carries the last known {@link operation} snapshot (best effort
|
|
111
|
+
* via a final REST fetch on timeout) so callers can inspect the in-flight
|
|
112
|
+
* state, and the {@link timeoutMs} that was applied. The error message
|
|
113
|
+
* preserves the legacy `Timed out waiting for operation <id>` substring
|
|
114
|
+
* for backwards compatibility with consumers that match on it.
|
|
115
|
+
*/
|
|
116
|
+
class OperationStalledError extends ArcaError {
|
|
117
|
+
operationId;
|
|
118
|
+
timeoutMs;
|
|
119
|
+
/**
|
|
120
|
+
* Last known operation snapshot (from the final fetch attempt or the most
|
|
121
|
+
* recent `operation.updated` event). May be `null` if the SDK never
|
|
122
|
+
* received a snapshot — e.g. the operation was never returned by an
|
|
123
|
+
* initial GET.
|
|
124
|
+
*/
|
|
125
|
+
operation;
|
|
126
|
+
constructor(operationId, timeoutMs, operation) {
|
|
127
|
+
const lastState = operation?.state ?? 'unknown';
|
|
128
|
+
const message = `Timed out waiting for operation ${operationId} to reach a terminal state after ${timeoutMs}ms (last known state: ${lastState})`;
|
|
129
|
+
super('OPERATION_STALLED', message);
|
|
130
|
+
this.name = 'OperationStalledError';
|
|
131
|
+
this.operationId = operationId;
|
|
132
|
+
this.timeoutMs = timeoutMs;
|
|
133
|
+
this.operation = operation
|
|
134
|
+
? { ...operation, failureMessage: operation.failureMessage ?? null }
|
|
135
|
+
: null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.OperationStalledError = OperationStalledError;
|
|
139
|
+
/**
|
|
140
|
+
* Thrown when the server requires browser confirmation for a destructive
|
|
141
|
+
* action on a production realm (HTTP 412 with code `STEP_UP_REQUIRED`).
|
|
142
|
+
*
|
|
143
|
+
* The {@link action} and {@link resources} carried on the error mirror the
|
|
144
|
+
* server's structured challenge payload (`error.details`) and are used to
|
|
145
|
+
* mint a single-use step-up token via `POST /api/v1/auth/step-up-requests`.
|
|
146
|
+
*
|
|
147
|
+
* In normal SDK use this is intercepted by an `onStepUpRequired` handler
|
|
148
|
+
* registered on the client; the SDK then transparently retries the
|
|
149
|
+
* original request once with the resulting step-up token. The error only
|
|
150
|
+
* propagates to caller code when no handler is wired or the handler
|
|
151
|
+
* rejects.
|
|
152
|
+
*/
|
|
153
|
+
class StepUpRequiredError extends ArcaError {
|
|
154
|
+
action;
|
|
155
|
+
resources;
|
|
156
|
+
constructor(message, challenge, errorId) {
|
|
157
|
+
super('STEP_UP_REQUIRED', message, errorId);
|
|
158
|
+
this.name = 'StepUpRequiredError';
|
|
159
|
+
this.action = challenge.action;
|
|
160
|
+
this.resources = challenge.resources;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.StepUpRequiredError = StepUpRequiredError;
|
|
164
|
+
/**
|
|
165
|
+
* Thrown when an `onStepUpRequired` handler signals that the user
|
|
166
|
+
* cancelled the confirmation flow (or it expired / errored).
|
|
167
|
+
*
|
|
168
|
+
* Distinct from {@link StepUpRequiredError} which describes the server
|
|
169
|
+
* gate; this error is raised by the SDK retry shim when the handler's
|
|
170
|
+
* Promise rejects.
|
|
171
|
+
*/
|
|
172
|
+
class StepUpCancelledError extends ArcaError {
|
|
173
|
+
constructor(message = 'Step-up confirmation was cancelled') {
|
|
174
|
+
super('STEP_UP_CANCELLED', message);
|
|
175
|
+
this.name = 'StepUpCancelledError';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.StepUpCancelledError = StepUpCancelledError;
|
|
179
|
+
/**
|
|
180
|
+
* Extracts `{ action, resources }` from a server-supplied `details` map.
|
|
181
|
+
* Returns `null` if either field is missing or malformed.
|
|
182
|
+
*/
|
|
183
|
+
function parseStepUpChallenge(details) {
|
|
184
|
+
if (!details || typeof details !== 'object')
|
|
185
|
+
return null;
|
|
186
|
+
const action = details['action'];
|
|
187
|
+
const resources = details['resources'];
|
|
188
|
+
if (typeof action !== 'string' || !Array.isArray(resources))
|
|
189
|
+
return null;
|
|
190
|
+
const resourceStrings = [];
|
|
191
|
+
for (const r of resources) {
|
|
192
|
+
if (typeof r === 'string')
|
|
193
|
+
resourceStrings.push(r);
|
|
194
|
+
}
|
|
195
|
+
return { action, resources: resourceStrings };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Maps an API error response to a typed SDK error.
|
|
199
|
+
*/
|
|
200
|
+
function mapApiError(code, message, errorId, details) {
|
|
201
|
+
switch (code) {
|
|
202
|
+
case 'VALIDATION_ERROR':
|
|
203
|
+
return new ValidationError(message, errorId);
|
|
204
|
+
case 'UNAUTHORIZED':
|
|
205
|
+
return new UnauthorizedError(message, errorId);
|
|
206
|
+
case 'NOT_FOUND':
|
|
207
|
+
case 'USER_NOT_FOUND':
|
|
208
|
+
case 'REALM_NOT_FOUND':
|
|
209
|
+
case 'OBJECT_NOT_FOUND':
|
|
210
|
+
case 'ORG_NOT_FOUND':
|
|
211
|
+
case 'ORDER_NOT_FOUND':
|
|
212
|
+
case 'ACCOUNT_NOT_FOUND':
|
|
213
|
+
case 'MEMBER_NOT_FOUND':
|
|
214
|
+
case 'PROFILE_NOT_FOUND':
|
|
215
|
+
case 'INVITATION_NOT_FOUND':
|
|
216
|
+
return new NotFoundError(message, errorId);
|
|
217
|
+
case 'CONFLICT':
|
|
218
|
+
case 'ALREADY_EXISTS':
|
|
219
|
+
case 'ALREADY_MEMBER':
|
|
220
|
+
case 'ALREADY_DELETED':
|
|
221
|
+
case 'DUPLICATE_REALM':
|
|
222
|
+
case 'ALREADY_REVOKED':
|
|
223
|
+
case 'IDEMPOTENCY_VIOLATION':
|
|
224
|
+
return new ConflictError(message, errorId);
|
|
225
|
+
case 'INTERNAL_ERROR':
|
|
226
|
+
return new InternalError(message, errorId);
|
|
227
|
+
case 'EXCHANGE_ERROR':
|
|
228
|
+
case 'EXCHANGE_UNAVAILABLE':
|
|
229
|
+
case 'ORDER_FAILED':
|
|
230
|
+
case 'INVALID_REQUEST':
|
|
231
|
+
return new ExchangeError(code, message, errorId);
|
|
232
|
+
case 'STEP_UP_REQUIRED': {
|
|
233
|
+
const challenge = parseStepUpChallenge(details);
|
|
234
|
+
if (challenge) {
|
|
235
|
+
return new StepUpRequiredError(message, challenge, errorId);
|
|
236
|
+
}
|
|
237
|
+
return new ArcaError(code, message, errorId);
|
|
238
|
+
}
|
|
239
|
+
default:
|
|
240
|
+
return new ArcaError(code, message, errorId);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAqNA,kCA+CC;AApQD;;;;GAIG;AACH,MAAa,SAAU,SAAQ,KAAK;IAClB,IAAI,CAAS;IACb,OAAO,CAAU;IAEjC,YAAY,IAAY,EAAE,OAAe,EAAE,OAAgB;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,8BAUC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,SAAS;IAC5C,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED;;GAEG;AACH,MAAa,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,UAAkB,mCAAmC,EAAE,OAAgB;QACjF,KAAK,CAA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B,KAAK,mBAAmB,CAAC;QACzB,KAAK,kBAAkB,CAAC;QACxB,KAAK,mBAAmB,CAAC;QACzB,KAAK,sBAAsB;YACzB,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,KAAK,UAAU,CAAC;QAChB,KAAK,gBAAgB,CAAC;QACtB,KAAK,gBAAgB,CAAC;QACtB,KAAK,iBAAiB,CAAC;QACvB,KAAK,iBAAiB,CAAC;QACvB,KAAK,iBAAiB,CAAC;QACvB,KAAK,uBAAuB;YAC1B,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,KAAK,gBAAgB;YACnB,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,KAAK,gBAAgB,CAAC;QACtB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,cAAc,CAAC;QACpB,KAAK,iBAAiB;YACpB,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACnD,KAAK,kBAAkB,CAAC,CAAC,CAAC;YACxB,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAChD,IAAI,SAAS,EAAE,CAAC;gBACd,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD;YACE,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;AACH,CAAC"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketManager = void 0;
|
|
4
|
+
var websocket_1 = require("./websocket");
|
|
5
|
+
Object.defineProperty(exports, "WebSocketManager", { enumerable: true, get: function () { return websocket_1.WebSocketManager; } });
|
|
6
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAAA,yCAA+C;AAAtC,6GAAA,gBAAgB,OAAA"}
|