@capxul/sdk 4.20.0-beta.3 → 4.20.0-beta.31
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/README.md +252 -33
- package/dist/access-B-2qmxF_.mjs +23227 -0
- package/dist/index-DidkO1aY.d.mts +34071 -0
- package/dist/index.d.mts +2 -653
- package/dist/index.mjs +84 -235
- package/dist/node/index.d.mts +9 -9
- package/dist/node/index.mjs +29 -38
- package/dist/organizations-wucUfgJr.mjs +12546 -0
- package/dist/permission-approvals-BLI_uadD.mjs +138 -0
- package/dist/production-2L76NWS5.mjs +4882 -0
- package/dist/testing/index.d.mts +32 -15
- package/dist/testing/index.mjs +296 -146
- package/package.json +48 -15
- package/dist/OAuthBearerAuthClient-C-ip-z8M.d.mts +0 -628
- package/dist/OAuthBearerAuthClient-DWkofxdZ.mjs +0 -2488
- package/dist/production-CJwxgI8u.d.mts +0 -3141
- package/dist/production-M4dWz5g4.mjs +0 -17131
package/dist/index.mjs
CHANGED
|
@@ -1,239 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as
|
|
3
|
-
import {
|
|
1
|
+
import { p as decodePermissionIntent } from "./organizations-wucUfgJr.mjs";
|
|
2
|
+
import { $ as formatAssetAmount, Ar as EVM_ADDRESS_RE, Bn as FixedOfferDraftSchema, Cr as toPermissionId, Dn as isCapxulOperation, Dr as toAssetId, Dt as TOKENS, En as CAPXUL_OPERATIONS, Er as currencySymbolFor, F as decodePayrollRunInput, I as toPayrollGroupId, Ii as Errors, Jn as ORGANIZATION_SETUP_REASONS, Jt as SDK_VERSION, Li as CapxulError, Mr as toAddress, On as normalizeCapxulOperation, Or as toCurrencyCode, Q as assetSymbolFor, Qn as toOrgId, Qr as EXPECTED_OPERATION_OUTCOMES, Qt as safeExceptionLabel, Ri as isCapxulError, Rn as PayrollGroupIdSchema, S as valueIn, Sr as toPermissionAssignmentId, Tt as CAPXUL_PAYMENTS_V2_ADDRESS, Vt as CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, Xn as CHAIN_UPSTREAMS, Xt as normalizeExceptionOperation, Yt as normalizeExceptionErrorKind, Zr as CAPXUL_ERROR_CODES, Zt as projectSdkException, _n as toPartyId, _r as PAYMENT_DIRECTIONS, a as paymentPhase, cn as signerFailure, dr as PaymentDocumentOptionsSchema, en as isSettingUpLifecycle, et as parseAssetAmount, fn as toCountryCode, gn as toHandle, hn as HANDLE_RE, i as inboxPhase, it as parseMoney, ln as resolveFailureMode, nt as toRaw, o as requestPhase, ot as fingerprintPaymentIntent, q as isCheckoutSettlementConsumed, qt as EXCEPTION_MESSAGE, rn as injectedWalletSigner, rt as isMoneyParseError, tt as requireAsset, ur as toAccountId, vr as PAYMENT_STATUSES, wn as EXCEPTION_EVENT_NAME, x as valueActivitySummary, xr as toBudgetId, y as positionPeg, zi as FAILURE_MODES, zn as PayrollGroupInputSchema, zt as failureDetail } from "./access-B-2qmxF_.mjs";
|
|
3
|
+
import { d as devPrivateKeySigner, f as createOpenfortBrowserSigner, h as openfortEmbeddedWalletPort, i as postHogObservability, m as openfortEmbeddedSignerFromWallet, p as embeddedSigner, t as createCapxulClient$1, u as deriveDevPrivateKey } from "./production-2L76NWS5.mjs";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
6
|
-
//#region src/
|
|
7
|
-
const PENDING = Object.freeze({
|
|
8
|
-
terminal: false,
|
|
9
|
-
outcome: null,
|
|
10
|
-
needsAction: false
|
|
11
|
-
});
|
|
12
|
-
const AWAITING_ACTOR = Object.freeze({
|
|
13
|
-
terminal: false,
|
|
14
|
-
outcome: null,
|
|
15
|
-
needsAction: true
|
|
16
|
-
});
|
|
17
|
-
const COMPLETED = Object.freeze({
|
|
18
|
-
terminal: true,
|
|
19
|
-
outcome: "good",
|
|
20
|
-
needsAction: false
|
|
21
|
-
});
|
|
22
|
-
const FAILED = Object.freeze({
|
|
23
|
-
terminal: true,
|
|
24
|
-
outcome: "bad",
|
|
25
|
-
needsAction: false
|
|
26
|
-
});
|
|
27
|
-
const WITHDRAWN = Object.freeze({
|
|
28
|
-
terminal: true,
|
|
29
|
-
outcome: "neutral",
|
|
30
|
-
needsAction: false
|
|
31
|
-
});
|
|
6
|
+
//#region src/access/identity/selectors.ts
|
|
32
7
|
/**
|
|
33
|
-
* The
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* package does not build.
|
|
38
|
-
*
|
|
39
|
-
* The refusal covers run time. A wire status is a type claim about a string
|
|
40
|
-
* that no code narrows, so an unknown status can arrive. This function refuses
|
|
41
|
-
* it. It does not let an `undefined` typed `ActivityPhase` reach a screen,
|
|
42
|
-
* where the first property read fails.
|
|
43
|
-
*/
|
|
44
|
-
function unknownStatus(status) {
|
|
45
|
-
throw Errors.invalidInput("status", "unknown activity status");
|
|
46
|
-
}
|
|
47
|
-
/** Interpret a Payment status. `pending_claim` waits for the actor who reads it. */
|
|
48
|
-
function paymentPhase(status) {
|
|
49
|
-
switch (status) {
|
|
50
|
-
case "pending":
|
|
51
|
-
case "settling":
|
|
52
|
-
case "scheduled":
|
|
53
|
-
case "streaming": return PENDING;
|
|
54
|
-
case "pending_claim": return AWAITING_ACTOR;
|
|
55
|
-
case "settled": return COMPLETED;
|
|
56
|
-
case "cancelled": return WITHDRAWN;
|
|
57
|
-
case "failed":
|
|
58
|
-
case "unresolved": return FAILED;
|
|
59
|
-
default: return unknownStatus(status);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/** Interpret a payment Request as its ISSUER sees it. An issuer does not wait for itself. */
|
|
63
|
-
function requestPhase(status) {
|
|
64
|
-
switch (status) {
|
|
65
|
-
case "draft":
|
|
66
|
-
case "sent":
|
|
67
|
-
case "viewed":
|
|
68
|
-
case "pending_settlement": return PENDING;
|
|
69
|
-
case "paid": return COMPLETED;
|
|
70
|
-
case "declined":
|
|
71
|
-
case "expired": return FAILED;
|
|
72
|
-
case "cancelled": return WITHDRAWN;
|
|
73
|
-
default: return unknownStatus(status);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** Interpret the same request as its RECIPIENT sees it. `open` waits for the recipient. */
|
|
77
|
-
function inboxPhase(status) {
|
|
78
|
-
switch (status) {
|
|
79
|
-
case "open": return AWAITING_ACTOR;
|
|
80
|
-
case "approved": return PENDING;
|
|
81
|
-
case "paid": return COMPLETED;
|
|
82
|
-
case "declined":
|
|
83
|
-
case "expired": return FAILED;
|
|
84
|
-
case "cancelled": return WITHDRAWN;
|
|
85
|
-
default: return unknownStatus(status);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/domain/money/parse-money.ts
|
|
90
|
-
/**
|
|
91
|
-
* ADR-0023 R1: the reason is a closed code and the ONLY failure vocabulary —
|
|
92
|
-
* the consuming app maps each code to its own sentence. The SDK ships no
|
|
93
|
-
* English for user-text failure.
|
|
8
|
+
* The post-auth destination and provisioning lane merge as one total switch
|
|
9
|
+
* over the nest. "An active journey outranks default
|
|
10
|
+
* routing; org-list contents never choose a destination" holds by construction:
|
|
11
|
+
* there is no org list in the state, only the ONE active lane.
|
|
94
12
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
currency: asset.currency,
|
|
104
|
-
value: parsed.value,
|
|
105
|
-
decimals: asset.decimals
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/** Shared input grammar. Callers retain their own amount size limits. */
|
|
109
|
-
function parseDecimalInput(input, decimals, maximumLength) {
|
|
110
|
-
if (!Number.isInteger(decimals) || decimals < 0) throw Errors.invalidInput("asset.decimals", "must be a non-negative integer");
|
|
111
|
-
const value = input.trim();
|
|
112
|
-
if (value.length === 0) return {
|
|
113
|
-
kind: "error",
|
|
114
|
-
reason: "required"
|
|
115
|
-
};
|
|
116
|
-
if (value.length > maximumLength) return {
|
|
117
|
-
kind: "error",
|
|
118
|
-
reason: "too-long"
|
|
119
|
-
};
|
|
120
|
-
const negative = value.startsWith("-");
|
|
121
|
-
const unsigned = negative ? value.slice(1) : value;
|
|
122
|
-
if (!AMOUNT_PATTERN.test(unsigned)) return {
|
|
123
|
-
kind: "error",
|
|
124
|
-
reason: "invalid-format"
|
|
13
|
+
const destination = (state) => {
|
|
14
|
+
if (state.phase === "restoring") return null;
|
|
15
|
+
if (state.phase !== "authenticated") return { to: "home" };
|
|
16
|
+
if (!state.profileComplete) return { to: "selectUserType" };
|
|
17
|
+
if (state.account.at === "unknown") return null;
|
|
18
|
+
if (state.account.at !== "claimed") return {
|
|
19
|
+
to: "provisioning",
|
|
20
|
+
scope: "personal"
|
|
125
21
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const fraction = normalized.split(".")[1];
|
|
132
|
-
if (fraction !== void 0 && fraction.length > decimals) return {
|
|
133
|
-
kind: "error",
|
|
134
|
-
reason: "too-many-decimals"
|
|
135
|
-
};
|
|
136
|
-
if (ZERO_PATTERN.test(normalized)) return {
|
|
137
|
-
kind: "error",
|
|
138
|
-
reason: "non-positive"
|
|
139
|
-
};
|
|
140
|
-
return { value: normalized };
|
|
141
|
-
}
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/domain/money/asset-amount.ts
|
|
144
|
-
/** Exact scaling. This rejects excess precision instead of rounding it. */
|
|
145
|
-
function toRaw(amount, asset) {
|
|
146
|
-
validateMetadata(asset);
|
|
147
|
-
if (amount.asset !== asset.assetId) throw Errors.invalidInput("amount.asset", "must match the selected asset on its chain");
|
|
148
|
-
return decimalToRaw(amount.value, asset.decimals);
|
|
149
|
-
}
|
|
150
|
-
function parseAssetAmount(input, asset) {
|
|
151
|
-
validateMetadata(asset);
|
|
152
|
-
const parsed = parseDecimalInput(input, asset.decimals, 100);
|
|
153
|
-
return "kind" in parsed ? parsed : {
|
|
154
|
-
asset: asset.assetId,
|
|
155
|
-
value: parsed.value.replace(/^0+(?=\d)/, "")
|
|
22
|
+
const org = state.account.org;
|
|
23
|
+
if (org === null) return { to: "dashboardPersonal" };
|
|
24
|
+
if (org.setup?.status === "ready" && org.observation === "connected" && org.orgId !== null) return {
|
|
25
|
+
to: "dashboardOrganization",
|
|
26
|
+
orgId: org.orgId
|
|
156
27
|
};
|
|
157
|
-
}
|
|
158
|
-
/** Display the full quantity. Only fiat formatting rounds for display. */
|
|
159
|
-
function formatAssetAmount(amount) {
|
|
160
|
-
const asset = requireAsset(amount.asset);
|
|
161
|
-
const [integer = "0", fraction] = formatUnits(toRaw(amount, asset), asset.decimals).split(".");
|
|
162
|
-
return `${integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}${fraction === void 0 ? "" : `.${fraction}`} ${asset.symbol}`;
|
|
163
|
-
}
|
|
164
|
-
function assetSymbolFor(asset) {
|
|
165
|
-
return requireAsset(asset).symbol;
|
|
166
|
-
}
|
|
167
|
-
function requireAsset(id) {
|
|
168
|
-
const asset = configuredMoneyAssetById(id);
|
|
169
|
-
if (asset === null) throw Errors.invalidInput("amount.asset", "is not a registered asset");
|
|
170
|
-
return asset;
|
|
171
|
-
}
|
|
172
|
-
function decimalToRaw(value, decimals) {
|
|
173
|
-
validatePrecision(decimals);
|
|
174
|
-
if (!/^\d+(?:\.\d+)?$/.test(value) || value.trim() !== value || value.length > 512) throw Errors.invalidInput("amount.value", "must be a non-negative decimal string of at most 512 characters");
|
|
175
|
-
const [integer = "0", fraction = ""] = value.split(".");
|
|
176
|
-
if (fraction.length > decimals) throw Errors.invalidInput("amount.value", "fraction exceeds asset precision");
|
|
177
|
-
return BigInt(integer) * 10n ** BigInt(decimals) + BigInt(fraction.padEnd(decimals, "0") || "0");
|
|
178
|
-
}
|
|
179
|
-
function validatePrecision(decimals) {
|
|
180
|
-
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255) throw Errors.invalidInput("decimals", "must be an integer from 0 to 255");
|
|
181
|
-
}
|
|
182
|
-
function validateMetadata(asset) {
|
|
183
|
-
validatePrecision(asset.decimals);
|
|
184
|
-
if (asset.assetId !== assetIdFor(asset.chainId, asset.tokenAddress)) throw Errors.invalidInput("amount.asset", "metadata must match its chain and token");
|
|
185
|
-
}
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/domain/money/valuation.ts
|
|
188
|
-
const PEG_RATES = (source, into) => (typeof source === "string" ? source : source.peg) === into ? {
|
|
189
|
-
value: "1",
|
|
190
|
-
decimals: 0
|
|
191
|
-
} : null;
|
|
192
|
-
/** Sum exact fixed-point values. Missing rates never contribute zero. */
|
|
193
|
-
function valueIn(amounts, displayCurrency, rates = PEG_RATES) {
|
|
194
|
-
const currency = toCurrencyCode(displayCurrency);
|
|
195
|
-
const counted = [];
|
|
196
|
-
const unrated = [];
|
|
197
|
-
let sum = 0n;
|
|
198
|
-
let scale = 0;
|
|
199
|
-
for (const amount of amounts) {
|
|
200
|
-
let source;
|
|
201
|
-
let raw;
|
|
202
|
-
let decimals;
|
|
203
|
-
if ("asset" in amount) {
|
|
204
|
-
source = requireAsset(amount.asset);
|
|
205
|
-
raw = toRaw(amount, source);
|
|
206
|
-
decimals = source.decimals;
|
|
207
|
-
} else {
|
|
208
|
-
source = toCurrencyCode(amount.currency);
|
|
209
|
-
raw = decimalToRaw(amount.value, amount.decimals);
|
|
210
|
-
decimals = amount.decimals;
|
|
211
|
-
}
|
|
212
|
-
const rate = rates(source, currency);
|
|
213
|
-
if (rate === null) {
|
|
214
|
-
unrated.push(amount);
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
validatePrecision(rate.decimals);
|
|
218
|
-
if (!/^\d+$/.test(rate.value) || rate.value.trim() !== rate.value || rate.value.length > 256 || BigInt(rate.value) <= 0n) throw Errors.invalidInput("rate.value", "must be a positive fixed-point integer");
|
|
219
|
-
const termScale = decimals + rate.decimals;
|
|
220
|
-
const nextScale = Math.max(scale, termScale);
|
|
221
|
-
sum = sum * 10n ** BigInt(nextScale - scale) + raw * BigInt(rate.value) * 10n ** BigInt(nextScale - termScale);
|
|
222
|
-
scale = nextScale;
|
|
223
|
-
counted.push(amount);
|
|
224
|
-
}
|
|
225
28
|
return {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
decimals: scale
|
|
230
|
-
},
|
|
231
|
-
counted,
|
|
232
|
-
unrated
|
|
29
|
+
to: "provisioning",
|
|
30
|
+
scope: "organization",
|
|
31
|
+
orgId: org.orgId
|
|
233
32
|
};
|
|
234
|
-
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* True while the machine has not settled enough to route or to gate on.
|
|
36
|
+
*
|
|
37
|
+
* Every phase is named, so a phase added to the type fails to compile here
|
|
38
|
+
* until someone decides whether it holds or settles. A phase this build does
|
|
39
|
+
* not know that still arrives at run time (a newer actor) holds: it must never
|
|
40
|
+
* redirect a member who is in fact signed in, so the default arm does not
|
|
41
|
+
* throw. Terminal for the account lane is `claimed | failed`.
|
|
42
|
+
*
|
|
43
|
+
* The org lane's own settledness (`ready | failed`) is the route gate's
|
|
44
|
+
* question, not this one: every org lane sits under a CLAIMED account, and
|
|
45
|
+
* `destination()` already names a real screen for each of its positions.
|
|
46
|
+
*/
|
|
47
|
+
const isRestoring = (state) => {
|
|
48
|
+
switch (state.phase) {
|
|
49
|
+
case "signed_out":
|
|
50
|
+
case "otp_sending":
|
|
51
|
+
case "otp_pending":
|
|
52
|
+
case "otp_verifying":
|
|
53
|
+
case "signing_out":
|
|
54
|
+
case "faulted": return false;
|
|
55
|
+
case "authenticated": return state.account.at !== "claimed" && state.account.at !== "failed";
|
|
56
|
+
case "restoring": return true;
|
|
57
|
+
default: return true;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/** The claimed-account gate as one function. The inlined consumers move onto
|
|
61
|
+
* it in #1521; this ticket ships the selector they move onto. */
|
|
62
|
+
const isClaimed = (state) => state.phase === "authenticated" && state.account.at === "claimed";
|
|
235
63
|
//#endregion
|
|
236
|
-
//#region src/
|
|
64
|
+
//#region src/money/format.ts
|
|
237
65
|
function formatMoney(money, options = {}) {
|
|
238
66
|
if (!Number.isInteger(money.decimals) || money.decimals < 0) throw Errors.invalidInput("money.decimals", "must be a non-negative integer");
|
|
239
67
|
const symbol = currencySymbolFor(toCurrencyCode(money.currency));
|
|
@@ -242,10 +70,10 @@ function formatMoney(money, options = {}) {
|
|
|
242
70
|
const grouped = rounded.integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
243
71
|
const signed = `${rounded.negative ? "-" : ""}${grouped}`;
|
|
244
72
|
if (options.grammar === "code") {
|
|
245
|
-
if (!rounded.hadFraction) return `${signed} ${
|
|
73
|
+
if (!rounded.hadFraction) return `${signed} ${money.currency}`;
|
|
246
74
|
let displayedFraction = rounded.fraction;
|
|
247
75
|
while (displayedFraction.length > 2 && displayedFraction.endsWith("0")) displayedFraction = displayedFraction.slice(0, -1);
|
|
248
|
-
return `${signed}.${displayedFraction} ${
|
|
76
|
+
return `${signed}.${displayedFraction} ${money.currency}`;
|
|
249
77
|
}
|
|
250
78
|
return `${symbol}${signed}.${rounded.fraction}`;
|
|
251
79
|
}
|
|
@@ -267,7 +95,7 @@ function roundDecimal(value, decimals, maximumFractionDigits) {
|
|
|
267
95
|
};
|
|
268
96
|
}
|
|
269
97
|
//#endregion
|
|
270
|
-
//#region src/
|
|
98
|
+
//#region src/signing/account-providers.ts
|
|
271
99
|
function localPrivateKeyAccountProvider(input) {
|
|
272
100
|
const account = privateKeyToAccount(input.privateKey);
|
|
273
101
|
const address = toAddress(account.address);
|
|
@@ -337,13 +165,13 @@ function firstAccount(value) {
|
|
|
337
165
|
return typeof first === "string" ? first : null;
|
|
338
166
|
}
|
|
339
167
|
//#endregion
|
|
340
|
-
//#region src/
|
|
168
|
+
//#region src/platform/client/create.ts
|
|
341
169
|
/** Consumer-facing factory — accepts only production-meaningful inputs (#326). */
|
|
342
170
|
async function createCapxulClient(input) {
|
|
343
171
|
return createCapxulClient$1(input);
|
|
344
172
|
}
|
|
345
173
|
//#endregion
|
|
346
|
-
//#region src/telemetry/stack-frame-parser.ts
|
|
174
|
+
//#region src/observability/telemetry/stack-frame-parser.ts
|
|
347
175
|
/**
|
|
348
176
|
* Regex for V8/Chrome stack trace frame lines.
|
|
349
177
|
* Matches:
|
|
@@ -425,7 +253,7 @@ function buildExceptionList(input) {
|
|
|
425
253
|
}];
|
|
426
254
|
}
|
|
427
255
|
//#endregion
|
|
428
|
-
//#region src/telemetry/capture-exception.ts
|
|
256
|
+
//#region src/observability/telemetry/capture-exception.ts
|
|
429
257
|
/**
|
|
430
258
|
* Capture an error as a `$exception` event through the telemetry port,
|
|
431
259
|
* formatted for PostHog Error Tracking.
|
|
@@ -479,7 +307,7 @@ function captureException(telemetry, error, context) {
|
|
|
479
307
|
})
|
|
480
308
|
});
|
|
481
309
|
return telemetry.emit({
|
|
482
|
-
name:
|
|
310
|
+
name: EXCEPTION_EVENT_NAME,
|
|
483
311
|
props
|
|
484
312
|
});
|
|
485
313
|
}).pipe(Effect.flatten), () => Effect.void);
|
|
@@ -496,4 +324,25 @@ function captureExceptionSync(telemetry, error, context) {
|
|
|
496
324
|
} catch {}
|
|
497
325
|
}
|
|
498
326
|
//#endregion
|
|
499
|
-
|
|
327
|
+
//#region ../protocol/src/requests/model.ts
|
|
328
|
+
/** Build a reference URL. The consumer still reads authoritative terms from the backend. */
|
|
329
|
+
function checkoutUrl(frontendOrigin, reference) {
|
|
330
|
+
const origin = new URL(frontendOrigin);
|
|
331
|
+
const loopback = [
|
|
332
|
+
"localhost",
|
|
333
|
+
"127.0.0.1",
|
|
334
|
+
"[::1]"
|
|
335
|
+
].includes(origin.hostname);
|
|
336
|
+
if (origin.protocol !== "https:" && !(origin.protocol === "http:" && loopback) || origin.username !== "" || origin.password !== "" || origin.pathname !== "/" || origin.search !== "" || origin.hash !== "") throw new TypeError("Provide an approved frontend origin");
|
|
337
|
+
const id = reference.kind === "offer" ? reference.offerId : reference.linkToken;
|
|
338
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/u.test(id)) throw new TypeError("Invalid checkout reference");
|
|
339
|
+
const route = reference.kind === "offer" ? "offers" : reference.kind === "request" ? "requests" : "invoices";
|
|
340
|
+
const result = new URL(`/checkout/${route}/${encodeURIComponent(id)}`, origin);
|
|
341
|
+
if (reference.kind === "offer" && reference.quantity !== void 0) {
|
|
342
|
+
if (!Number.isSafeInteger(reference.quantity) || reference.quantity < 1) throw new TypeError("Invalid checkout quantity");
|
|
343
|
+
result.searchParams.set("quantity", String(reference.quantity));
|
|
344
|
+
}
|
|
345
|
+
return result.href;
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
export { CAPXUL_ERROR_CODES, CAPXUL_OPERATIONS, CAPXUL_PAYMENTS_V2_ADDRESS, CAPXUL_SDK_EXPECTED_OUTCOME_EVENT, CHAIN_UPSTREAMS, CapxulError, EVM_ADDRESS_RE, EXPECTED_OPERATION_OUTCOMES, Errors, FAILURE_MODES, FixedOfferDraftSchema, HANDLE_RE, ORGANIZATION_SETUP_REASONS, PAYMENT_DIRECTIONS, PAYMENT_STATUSES, PaymentDocumentOptionsSchema, PayrollGroupIdSchema, PayrollGroupInputSchema, TOKENS, assetSymbolFor, captureException, captureExceptionSync, checkoutUrl, createCapxulClient, createOpenfortBrowserSigner, decodePayrollRunInput, decodePermissionIntent, deriveDevPrivateKey, devPrivateKeySigner, eip1193AccountProvider, embeddedSigner, fingerprintPaymentIntent, formatAssetAmount, formatMoney, inboxPhase, injectedWalletSigner, isCapxulError, isCapxulOperation, isCheckoutSettlementConsumed, isClaimed, isMoneyParseError, isRestoring, isSettingUpLifecycle, localPrivateKeyAccountProvider, normalizeCapxulOperation, openfortEmbeddedSignerFromWallet, openfortEmbeddedWalletPort, parseAssetAmount, parseMoney, paymentPhase, positionPeg, postHogObservability, requestPhase, requireAsset, destination as resolveIdentityDestination, toAccountId, toAssetId, toBudgetId, toCountryCode, toCurrencyCode, toAddress as toEvmAddress, toHandle, toOrgId, toPartyId, toPayrollGroupId, toPermissionAssignmentId, toPermissionId, toRaw, valueActivitySummary, valueIn };
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Hex } from "viem";
|
|
1
|
+
import { Ji as CapxulSigner, Yo as AuthSession, bo as AuthCachePortTag, fo as OAuthBearerAuthClientInput, po as oauthBearerAuthClient, vo as AuthCacheError, xo as CachedJwt, yo as AuthCachePort } from "../index-DidkO1aY.mjs";
|
|
3
2
|
import { Effect, FileSystem, Layer, Path } from "effect";
|
|
4
|
-
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
//#region src/access/auth-cache/file-system.d.ts
|
|
5
5
|
type FileSystemRuntime = FileSystem.FileSystem | Path.Path;
|
|
6
|
-
declare class FileSystemAuthCacheAdapter implements AuthCachePort {
|
|
6
|
+
export declare class FileSystemAuthCacheAdapter implements AuthCachePort {
|
|
7
7
|
private readonly path;
|
|
8
8
|
private readonly runtime;
|
|
9
9
|
readonly getSession: Effect.Effect<AuthSession | null, AuthCacheError>;
|
|
@@ -17,13 +17,13 @@ declare class FileSystemAuthCacheAdapter implements AuthCachePort {
|
|
|
17
17
|
private write;
|
|
18
18
|
private run;
|
|
19
19
|
}
|
|
20
|
-
declare function FileSystemAuthCacheLayer(input: {
|
|
20
|
+
export declare function FileSystemAuthCacheLayer(input: {
|
|
21
21
|
readonly path: string;
|
|
22
22
|
readonly runtime?: Layer.Layer<FileSystemRuntime>;
|
|
23
23
|
}): Layer.Layer<AuthCachePortTag, AuthCacheError>;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/node/index.d.ts
|
|
26
|
-
interface DetectNodeAuthCacheAdapterOptions {
|
|
26
|
+
export interface DetectNodeAuthCacheAdapterOptions {
|
|
27
27
|
readonly authCachePath?: string;
|
|
28
28
|
readonly resolveHomeDirectory?: () => string;
|
|
29
29
|
}
|
|
@@ -32,7 +32,7 @@ interface DetectNodeAuthCacheAdapterOptions {
|
|
|
32
32
|
* digest the backend returns for a prepared deployment UserOperation. The
|
|
33
33
|
* The reference CLI builds this from `DEPLOYER_PRIVATE_KEY` for live tests.
|
|
34
34
|
*/
|
|
35
|
-
declare function localPrivateKeySigner(input: {
|
|
35
|
+
export declare function localPrivateKeySigner(input: {
|
|
36
36
|
readonly privateKey: Hex;
|
|
37
37
|
}): CapxulSigner;
|
|
38
38
|
/**
|
|
@@ -45,6 +45,6 @@ declare function localPrivateKeySigner(input: {
|
|
|
45
45
|
* Use this from a Node entrypoint and pass the result to
|
|
46
46
|
* `createCapxulClient({ authCache })` for on-disk session persistence.
|
|
47
47
|
*/
|
|
48
|
-
declare function detectNodeAuthCacheAdapter(options?: DetectNodeAuthCacheAdapterOptions): AuthCachePort;
|
|
48
|
+
export declare function detectNodeAuthCacheAdapter(options?: DetectNodeAuthCacheAdapterOptions): AuthCachePort;
|
|
49
49
|
//#endregion
|
|
50
|
-
export {
|
|
50
|
+
export { type OAuthBearerAuthClientInput, oauthBearerAuthClient };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Effect, FileSystem, Layer, Path } from "effect";
|
|
1
|
+
import { Di as parseAuthSession, Ei as BrowserAuthCacheAdapter, Mr as toAddress, Oi as parseCachedJwt, Ti as InMemoryAuthCacheAdapter, Ui as AuthCacheError, Vi as isRecord, Wi as AuthCachePortTag, ni as oauthBearerAuthClient, wi as globalLocalStorage } from "../access-B-2qmxF_.mjs";
|
|
2
|
+
import { Effect, FileSystem, Layer, Option, Path } from "effect";
|
|
3
3
|
import { privateKeyToAccount } from "viem/accounts";
|
|
4
4
|
import * as os from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { NodeFileSystem, NodePath } from "@effect/platform-node";
|
|
7
|
-
//#region src/
|
|
7
|
+
//#region src/access/auth-cache/file-system.ts
|
|
8
8
|
function emptyPayload() {
|
|
9
9
|
return {
|
|
10
10
|
session: null,
|
|
@@ -24,69 +24,60 @@ var FileSystemAuthCacheAdapter = class {
|
|
|
24
24
|
constructor(path, runtime = nodeFileSystemRuntime) {
|
|
25
25
|
this.path = path;
|
|
26
26
|
this.runtime = runtime;
|
|
27
|
-
const self = this;
|
|
28
27
|
this.getSession = this.run("getSession", this.read().pipe(Effect.map((payload) => payload.session)));
|
|
29
|
-
this.setSession = (session) => this.run("setSession", Effect.gen(function* () {
|
|
30
|
-
const cur = yield*
|
|
31
|
-
yield*
|
|
28
|
+
this.setSession = (session) => this.run("setSession", Effect.gen({ self: this }, function* () {
|
|
29
|
+
const cur = yield* this.read();
|
|
30
|
+
yield* this.write({
|
|
32
31
|
session,
|
|
33
32
|
jwt: cur.jwt
|
|
34
33
|
});
|
|
35
34
|
}));
|
|
36
|
-
this.clearSession = this.run("clearSession", Effect.gen(function* () {
|
|
37
|
-
const cur = yield*
|
|
38
|
-
yield*
|
|
35
|
+
this.clearSession = this.run("clearSession", Effect.gen({ self: this }, function* () {
|
|
36
|
+
const cur = yield* this.read();
|
|
37
|
+
yield* this.write({
|
|
39
38
|
session: null,
|
|
40
39
|
jwt: cur.jwt
|
|
41
40
|
});
|
|
42
41
|
}));
|
|
43
42
|
this.getJwt = this.run("getJwt", this.read().pipe(Effect.map((payload) => payload.jwt)));
|
|
44
|
-
this.setJwt = (jwt) => this.run("setJwt", Effect.gen(function* () {
|
|
45
|
-
const cur = yield*
|
|
46
|
-
yield*
|
|
43
|
+
this.setJwt = (jwt) => this.run("setJwt", Effect.gen({ self: this }, function* () {
|
|
44
|
+
const cur = yield* this.read();
|
|
45
|
+
yield* this.write({
|
|
47
46
|
session: cur.session,
|
|
48
47
|
jwt
|
|
49
48
|
});
|
|
50
49
|
}));
|
|
51
|
-
this.clearJwt = this.run("clearJwt", Effect.gen(function* () {
|
|
52
|
-
const cur = yield*
|
|
53
|
-
yield*
|
|
50
|
+
this.clearJwt = this.run("clearJwt", Effect.gen({ self: this }, function* () {
|
|
51
|
+
const cur = yield* this.read();
|
|
52
|
+
yield* this.write({
|
|
54
53
|
session: cur.session,
|
|
55
54
|
jwt: null
|
|
56
55
|
});
|
|
57
56
|
}));
|
|
58
57
|
}
|
|
59
58
|
read() {
|
|
60
|
-
|
|
61
|
-
return Effect.gen(function* () {
|
|
59
|
+
return Effect.gen({ self: this }, function* () {
|
|
62
60
|
const fs = yield* FileSystem.FileSystem;
|
|
63
|
-
if (!(yield* fs.exists(
|
|
64
|
-
const raw = yield* fs.readFileString(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
parsed = JSON.parse(raw);
|
|
68
|
-
} catch {
|
|
69
|
-
return emptyPayload();
|
|
70
|
-
}
|
|
71
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return emptyPayload();
|
|
72
|
-
const payload = parsed;
|
|
61
|
+
if (!(yield* fs.exists(this.path))) return emptyPayload();
|
|
62
|
+
const raw = yield* fs.readFileString(this.path, "utf-8");
|
|
63
|
+
const parsed = Option.getOrUndefined(yield* Effect.try(() => JSON.parse(raw)).pipe(Effect.option));
|
|
64
|
+
if (!isRecord(parsed)) return emptyPayload();
|
|
73
65
|
return {
|
|
74
|
-
session: parseAuthSession(
|
|
75
|
-
jwt: parseCachedJwt(
|
|
66
|
+
session: parseAuthSession(parsed.session),
|
|
67
|
+
jwt: parseCachedJwt(parsed.jwt)
|
|
76
68
|
};
|
|
77
69
|
});
|
|
78
70
|
}
|
|
79
71
|
write(payload) {
|
|
80
|
-
|
|
81
|
-
return Effect.gen(function* () {
|
|
72
|
+
return Effect.gen({ self: this }, function* () {
|
|
82
73
|
const fs = yield* FileSystem.FileSystem;
|
|
83
|
-
const dir = (yield* Path.Path).dirname(
|
|
74
|
+
const dir = (yield* Path.Path).dirname(this.path);
|
|
84
75
|
if (!(yield* fs.exists(dir))) yield* fs.makeDirectory(dir, {
|
|
85
76
|
recursive: true,
|
|
86
77
|
mode: 448
|
|
87
78
|
});
|
|
88
|
-
yield* fs.writeFileString(
|
|
89
|
-
yield* fs.chmod(
|
|
79
|
+
yield* fs.writeFileString(this.path, JSON.stringify(payload), { mode: 384 });
|
|
80
|
+
yield* fs.chmod(this.path, 384);
|
|
90
81
|
});
|
|
91
82
|
}
|
|
92
83
|
run(operation, effect) {
|
|
@@ -132,9 +123,9 @@ function localPrivateKeySigner(input) {
|
|
|
132
123
|
* `createCapxulClient({ authCache })` for on-disk session persistence.
|
|
133
124
|
*/
|
|
134
125
|
function detectNodeAuthCacheAdapter(options = {}) {
|
|
135
|
-
const
|
|
136
|
-
if (
|
|
137
|
-
if (
|
|
126
|
+
const localStorage = globalLocalStorage();
|
|
127
|
+
if (localStorage !== void 0) return new BrowserAuthCacheAdapter(localStorage);
|
|
128
|
+
if (globalThis.process?.versions?.node !== void 0) {
|
|
138
129
|
const authCachePath = normalizeConfiguredAuthCachePath(options.authCachePath) ?? resolveDefaultAuthCachePath(options.resolveHomeDirectory ?? os.homedir);
|
|
139
130
|
if (authCachePath !== null) return new FileSystemAuthCacheAdapter(authCachePath);
|
|
140
131
|
}
|