@n1xyz/nord-ts 0.0.4 → 0.0.5
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/bridge/client.d.ts +4 -4
- package/dist/bridge/client.js +4 -4
- package/dist/bridge/const.d.ts +2 -2
- package/dist/bridge/const.js +22 -22
- package/dist/bridge/index.d.ts +4 -4
- package/dist/bridge/types.d.ts +3 -3
- package/dist/bridge/utils.d.ts +4 -4
- package/dist/bridge/utils.js +10 -10
- package/dist/const.d.ts +1 -1
- package/dist/const.js +17 -17
- package/dist/gen/nord.d.ts +1 -4
- package/dist/idl/bridge.d.ts +1 -1
- package/dist/idl/bridge.js +185 -185
- package/dist/index.d.ts +8 -8
- package/dist/nord/api/actions.d.ts +3 -3
- package/dist/nord/api/actions.js +21 -21
- package/dist/nord/api/core.d.ts +3 -3
- package/dist/nord/api/core.js +12 -12
- package/dist/nord/api/market.d.ts +1 -1
- package/dist/nord/api/market.js +12 -12
- package/dist/nord/api/metrics.d.ts +1 -1
- package/dist/nord/api/metrics.js +6 -6
- package/dist/nord/api/queries.d.ts +1 -1
- package/dist/nord/api/queries.js +9 -9
- package/dist/nord/client/Nord.d.ts +4 -4
- package/dist/nord/client/Nord.js +18 -18
- package/dist/nord/client/NordUser.d.ts +7 -7
- package/dist/nord/client/NordUser.js +45 -49
- package/dist/nord/index.d.ts +9 -9
- package/dist/nord/models/Subscriber.d.ts +6 -6
- package/dist/nord/models/Subscriber.js +1 -5
- package/dist/nord/utils/NordError.js +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +8 -8
- package/dist/websocket/NordWebSocketClient.d.ts +2 -2
- package/dist/websocket/NordWebSocketClient.js +38 -38
- package/dist/websocket/events.d.ts +1 -1
- package/dist/websocket/index.d.ts +2 -2
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +16 -16
- package/docs/assets/icons.js +17 -14
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +5 -4
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1423 -1227
- package/docs/classes/Nord.html +190 -31
- package/docs/classes/NordError.html +24 -0
- package/docs/classes/NordUser.html +120 -35
- package/docs/classes/NordWebSocketClient.html +335 -0
- package/docs/classes/SolanaBridgeClient.html +86 -0
- package/docs/classes/Subscriber.html +10 -0
- package/docs/enums/FillMode.html +5 -5
- package/docs/enums/KeyType.html +4 -4
- package/docs/enums/MetricPeriod.html +9 -0
- package/docs/enums/PdaSeedType.html +9 -0
- package/docs/enums/PeakTpsPeriodUnit.html +7 -7
- package/docs/enums/Side.html +3 -3
- package/docs/enums/WebSocketMessageType.html +7 -0
- package/docs/functions/actionQueryRollman.html +6 -0
- package/docs/functions/actionsQueryRollman.html +6 -0
- package/docs/functions/aggregateMetrics-1.html +7 -0
- package/docs/functions/assert.html +1 -1
- package/docs/functions/bigIntToProtoU128.html +3 -3
- package/docs/functions/blockQueryRollman.html +6 -0
- package/docs/functions/blockSummaryQueryRollman.html +6 -0
- package/docs/functions/bridgeToBN.html +5 -0
- package/docs/functions/bufferToHex.html +4 -0
- package/docs/functions/cancelOrder.html +1 -0
- package/docs/functions/checkPubKeyLength.html +1 -1
- package/docs/functions/checkedFetch.html +4 -4
- package/docs/functions/createSession.html +1 -0
- package/docs/functions/decodeLengthDelimited.html +7 -6
- package/docs/functions/encodeLengthDelimited.html +4 -4
- package/docs/functions/fillModeToProtoFillMode.html +4 -4
- package/docs/functions/findMarket.html +1 -1
- package/docs/functions/findPda.html +6 -0
- package/docs/functions/findToken.html +1 -1
- package/docs/functions/fromBN.html +5 -0
- package/docs/functions/getAccount.html +6 -0
- package/docs/functions/getActionNonce.html +5 -0
- package/docs/functions/getCurrentTps.html +6 -0
- package/docs/functions/getInfo.html +5 -0
- package/docs/functions/getMedianLatency.html +6 -0
- package/docs/functions/getOrderbook.html +6 -0
- package/docs/functions/getPeakTps.html +6 -0
- package/docs/functions/getTimestamp.html +5 -0
- package/docs/functions/getTotalTransactions.html +5 -0
- package/docs/functions/getTrades.html +6 -0
- package/docs/functions/getUserAccountIds.html +6 -0
- package/docs/functions/hexToBuffer.html +4 -0
- package/docs/functions/initWebSocketClient.html +12 -0
- package/docs/functions/keypairFromPrivateKey.html +4 -0
- package/docs/functions/makeSigningFunction.html +4 -0
- package/docs/functions/makeWalletSignFn.html +5 -5
- package/docs/functions/marketsStats.html +5 -0
- package/docs/functions/optExpect.html +4 -4
- package/docs/functions/optMap.html +5 -5
- package/docs/functions/optUnwrap.html +2 -2
- package/docs/functions/panic.html +1 -1
- package/docs/functions/placeOrder.html +1 -0
- package/docs/functions/queryAction.html +6 -0
- package/docs/functions/queryBlock.html +6 -0
- package/docs/functions/queryLastNBlocks.html +5 -0
- package/docs/functions/queryPrometheus.html +6 -0
- package/docs/functions/queryRecentActions.html +6 -0
- package/docs/functions/queryRecentBlocks.html +6 -0
- package/docs/functions/revokeSession.html +1 -0
- package/docs/functions/shortenPublicKey.html +5 -0
- package/docs/functions/signAction.html +2 -2
- package/docs/functions/toBN.html +5 -0
- package/docs/functions/toScaledU128.html +5 -5
- package/docs/functions/toScaledU64.html +5 -5
- package/docs/functions/transfer.html +1 -0
- package/docs/functions/withdraw.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +39 -20
- package/docs/interfaces/Account.html +8 -8
- package/docs/interfaces/ActionInfo.html +8 -8
- package/docs/interfaces/ActionNonceResponse.html +3 -0
- package/docs/interfaces/ActionQuery.html +4 -4
- package/docs/interfaces/ActionResponse.html +8 -8
- package/docs/interfaces/ActionsExtendedInfo.html +10 -10
- package/docs/interfaces/ActionsQuery.html +5 -5
- package/docs/interfaces/ActionsResponse.html +6 -6
- package/docs/interfaces/AggregateMetrics.html +12 -12
- package/docs/interfaces/BlockFacts.html +10 -0
- package/docs/interfaces/BlockQuery.html +6 -6
- package/docs/interfaces/BlockResponse.html +6 -6
- package/docs/interfaces/BlockSummary.html +8 -8
- package/docs/interfaces/BlockSummaryResponse.html +6 -6
- package/docs/interfaces/DeltaEvent.html +6 -6
- package/docs/interfaces/DepositSplParams.html +10 -0
- package/docs/interfaces/Info.html +3 -3
- package/docs/interfaces/Market.html +8 -6
- package/docs/interfaces/MarketStats.html +7 -7
- package/docs/interfaces/MarketsStatsResponse.html +2 -2
- package/docs/interfaces/NordConfig.html +14 -5
- package/docs/interfaces/NordWebSocketClientEvents.html +4 -0
- package/docs/interfaces/NordWebSocketEvents.html +8 -0
- package/docs/interfaces/Order.html +6 -6
- package/docs/interfaces/OrderInfo.html +6 -6
- package/docs/interfaces/OrderbookEntry.html +4 -0
- package/docs/interfaces/OrderbookQuery.html +6 -0
- package/docs/interfaces/OrderbookResponse.html +6 -0
- package/docs/interfaces/OrderbookSubscription.html +159 -0
- package/docs/interfaces/PerpMarketStats.html +5 -5
- package/docs/interfaces/RollmanActionExtendedInfo.html +4 -4
- package/docs/interfaces/RollmanActionInfo.html +4 -4
- package/docs/interfaces/RollmanActionResponse.html +4 -4
- package/docs/interfaces/RollmanActionsResponse.html +2 -2
- package/docs/interfaces/RollmanBlockResponse.html +3 -3
- package/docs/interfaces/SPLTokenInfo.html +10 -0
- package/docs/interfaces/SolanaBridgeConfig.html +10 -0
- package/docs/interfaces/StateFacts.html +10 -0
- package/docs/interfaces/SubscriberConfig.html +3 -3
- package/docs/interfaces/TimestampResponse.html +3 -0
- package/docs/interfaces/Token.html +5 -5
- package/docs/interfaces/TokenInfo.html +5 -0
- package/docs/interfaces/Trade.html +5 -5
- package/docs/interfaces/TradeSubscription.html +159 -0
- package/docs/interfaces/Trades.html +5 -5
- package/docs/interfaces/TradesQuery.html +6 -0
- package/docs/interfaces/TradesResponse.html +7 -0
- package/docs/interfaces/TransferParams.html +8 -0
- package/docs/interfaces/UserAccountIdsQuery.html +3 -0
- package/docs/interfaces/UserAccountIdsResponse.html +3 -0
- package/docs/interfaces/WebSocketDeltaUpdate.html +9 -0
- package/docs/interfaces/WebSocketSubscription.html +4 -0
- package/docs/interfaces/WebSocketTradeUpdate.html +6 -0
- package/docs/interfaces/WebSocketUserUpdate.html +6 -0
- package/docs/interfaces/WithdrawalClaim.html +14 -0
- package/docs/interfaces/WithdrawalParams.html +8 -0
- package/docs/modules.html +1 -70
- package/docs/types/BigIntValue.html +2 -2
- package/docs/types/WebSocketMessage.html +1 -0
- package/docs/variables/DEBUG_KEYS.html +1 -1
- package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
- package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
- package/docs/variables/DEV_URL.html +1 -1
- package/docs/variables/MAX_BUFFER_LEN.html +1 -1
- package/docs/variables/SESSION_TTL.html +1 -1
- package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
- package/docs/variables/ZERO_DECIMAL.html +1 -1
- package/docs/variables/_private.html +2 -0
- package/eslint.config.mjs +66 -0
- package/package.json +12 -13
- package/src/bridge/client.ts +10 -10
- package/src/bridge/const.ts +24 -24
- package/src/bridge/index.ts +4 -4
- package/src/bridge/types.ts +10 -10
- package/src/bridge/utils.ts +14 -14
- package/src/const.ts +18 -18
- package/src/gen/nord.ts +1 -4
- package/src/idl/bridge.ts +186 -186
- package/src/index.ts +8 -8
- package/src/nord/api/actions.ts +25 -25
- package/src/nord/api/core.ts +16 -16
- package/src/nord/api/market.ts +15 -15
- package/src/nord/api/metrics.ts +16 -16
- package/src/nord/api/queries.ts +12 -12
- package/src/nord/client/Nord.ts +27 -27
- package/src/nord/client/NordUser.ts +59 -63
- package/src/nord/index.ts +9 -9
- package/src/nord/models/Subscriber.ts +11 -12
- package/src/nord/utils/NordError.ts +2 -2
- package/src/types.ts +12 -12
- package/src/utils.ts +20 -20
- package/src/websocket/NordWebSocketClient.ts +42 -42
- package/src/websocket/events.ts +1 -1
- package/src/websocket/index.ts +2 -2
- package/tests/utils.spec.ts +24 -24
- package/tsconfig.eslint.json +12 -0
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -31
- package/dist/abis/ERC20_ABI.d.ts +0 -39
- package/dist/abis/ERC20_ABI.js +0 -313
- package/dist/abis/NORD_GETTERS_FACET_ABI.d.ts +0 -34
- package/dist/abis/NORD_GETTERS_FACET_ABI.js +0 -195
- package/dist/abis/NORD_RAMP_FACET_ABI.d.ts +0 -35
- package/dist/abis/NORD_RAMP_FACET_ABI.js +0 -144
- package/dist/abis/index.d.ts +0 -3
- package/dist/abis/index.js +0 -9
- package/dist/bridge/NordUser.d.ts +0 -78
- package/dist/bridge/NordUser.js +0 -196
- package/dist/client.d.ts +0 -70
- package/dist/client.js +0 -129
- package/dist/constants/endpoints.d.ts +0 -65
- package/dist/constants/endpoints.js +0 -68
- package/dist/models/account.d.ts +0 -58
- package/dist/models/account.js +0 -6
- package/dist/models/index.d.ts +0 -8
- package/dist/models/index.js +0 -28
- package/dist/models/market.d.ts +0 -137
- package/dist/models/market.js +0 -6
- package/dist/models/order.d.ts +0 -211
- package/dist/models/order.js +0 -6
- package/dist/models/token.d.ts +0 -50
- package/dist/models/token.js +0 -6
- package/dist/nord/Nord.d.ts +0 -249
- package/dist/nord/Nord.js +0 -388
- package/dist/nord/NordError.d.ts +0 -23
- package/dist/nord/NordError.js +0 -48
- package/dist/nord/NordImpl.d.ts +0 -11
- package/dist/nord/NordImpl.js +0 -26
- package/dist/nord/NordUser.d.ts +0 -243
- package/dist/nord/NordUser.js +0 -481
- package/dist/nord/Subscriber.d.ts +0 -37
- package/dist/nord/Subscriber.js +0 -29
- package/dist/nord/actions.d.ts +0 -101
- package/dist/nord/actions.js +0 -254
- package/dist/nord/api/index.d.ts +0 -1
- package/dist/nord/api/index.js +0 -17
- package/dist/nord/api/orderFunctions.d.ts +0 -168
- package/dist/nord/api/orderFunctions.js +0 -133
- package/dist/nord/core.d.ts +0 -48
- package/dist/nord/core.js +0 -97
- package/dist/nord/market.d.ts +0 -36
- package/dist/nord/market.js +0 -90
- package/dist/nord/metrics.d.ts +0 -67
- package/dist/nord/metrics.js +0 -124
- package/dist/nord/queries.d.ts +0 -81
- package/dist/nord/queries.js +0 -181
- package/dist/nord/types.d.ts +0 -88
- package/dist/nord/types.js +0 -2
- package/dist/nord/websocket.d.ts +0 -49
- package/dist/nord/websocket.js +0 -107
- package/dist/operations/account.d.ts +0 -58
- package/dist/operations/account.js +0 -112
- package/dist/operations/market.d.ts +0 -65
- package/dist/operations/market.js +0 -131
- package/dist/operations/orders.d.ts +0 -57
- package/dist/operations/orders.js +0 -129
- package/dist/solana/NordUser.d.ts +0 -78
- package/dist/solana/NordUser.js +0 -196
- package/dist/solana/client.d.ts +0 -139
- package/dist/solana/client.js +0 -360
- package/dist/solana/const.d.ts +0 -23
- package/dist/solana/const.js +0 -47
- package/dist/solana/index.d.ts +0 -5
- package/dist/solana/index.js +0 -23
- package/dist/solana/types.d.ts +0 -118
- package/dist/solana/types.js +0 -16
- package/dist/solana/utils.d.ts +0 -64
- package/dist/solana/utils.js +0 -131
- package/dist/types/api.d.ts +0 -152
- package/dist/types/api.js +0 -6
- package/dist/types/config.d.ts +0 -34
- package/dist/types/config.js +0 -6
- package/dist/utils/errors.d.ts +0 -96
- package/dist/utils/errors.js +0 -132
- package/dist/utils/http.d.ts +0 -35
- package/dist/utils/http.js +0 -105
- package/dist/websocket/client.d.ts +0 -93
- package/dist/websocket/client.js +0 -222
- package/dist/websocket.d.ts +0 -55
- package/dist/websocket.js +0 -211
- package/docs/interfaces/ERC20TokenInfo.html +0 -5
- package/docs/variables/DEV_CONTRACT_ADDRESS.html +0 -1
- package/docs/variables/ERC20_ABI.html +0 -1
- package/docs/variables/EVM_DEV_URL.html +0 -1
- package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +0 -1
- package/docs/variables/NORD_GETTERS_FACET_ABI.html +0 -1
- package/docs/variables/NORD_RAMP_FACET_ABI.html +0 -1
package/dist/solana/utils.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
7
|
-
exports.makeSigningFunction = makeSigningFunction;
|
|
8
|
-
exports.toBN = toBN;
|
|
9
|
-
exports.fromBN = fromBN;
|
|
10
|
-
exports.findPda = findPda;
|
|
11
|
-
exports.bufferToHex = bufferToHex;
|
|
12
|
-
exports.hexToBuffer = hexToBuffer;
|
|
13
|
-
exports.shortenPublicKey = shortenPublicKey;
|
|
14
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
17
|
-
/**
|
|
18
|
-
* Convert a private key string to a Solana Keypair
|
|
19
|
-
*
|
|
20
|
-
* @param privateKey Private key as base58 string, hex string, or Uint8Array
|
|
21
|
-
* @returns Solana Keypair
|
|
22
|
-
*/
|
|
23
|
-
function keypairFromPrivateKey(privateKey) {
|
|
24
|
-
if (typeof privateKey === 'string') {
|
|
25
|
-
// Check if it's a base58 encoded string
|
|
26
|
-
if (!privateKey.startsWith('0x')) {
|
|
27
|
-
return web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(privateKey));
|
|
28
|
-
}
|
|
29
|
-
// It's a hex string
|
|
30
|
-
const hex = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
31
|
-
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
|
32
|
-
return web3_js_1.Keypair.fromSecretKey(bytes);
|
|
33
|
-
}
|
|
34
|
-
// It's already a Uint8Array
|
|
35
|
-
return web3_js_1.Keypair.fromSecretKey(privateKey);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Create a signing function for Solana transactions
|
|
39
|
-
*
|
|
40
|
-
* @param keypair Solana keypair
|
|
41
|
-
* @returns Signing function
|
|
42
|
-
*/
|
|
43
|
-
function makeSigningFunction(keypair) {
|
|
44
|
-
return async (message) => {
|
|
45
|
-
// Use the correct API for signing with a Keypair
|
|
46
|
-
const signature = keypair.secretKey.slice(0, 32);
|
|
47
|
-
const publicKey = keypair.publicKey.toBytes();
|
|
48
|
-
// This is a simplified version - in a real implementation, you would use proper signing
|
|
49
|
-
// For now, we're just returning a placeholder signature
|
|
50
|
-
return new Uint8Array([...signature, ...publicKey].slice(0, 64));
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Convert a number to a BN with the specified number of decimals
|
|
55
|
-
*
|
|
56
|
-
* @param amount Amount as a number
|
|
57
|
-
* @param decimals Number of decimals
|
|
58
|
-
* @returns BN representation of the amount
|
|
59
|
-
*/
|
|
60
|
-
function toBN(amount, decimals) {
|
|
61
|
-
const factor = Math.pow(10, decimals);
|
|
62
|
-
const amountBN = new anchor_1.BN(Math.floor(amount * factor));
|
|
63
|
-
return amountBN;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Format a BN as a human-readable number with the specified number of decimals
|
|
67
|
-
*
|
|
68
|
-
* @param amount Amount as a BN
|
|
69
|
-
* @param decimals Number of decimals
|
|
70
|
-
* @returns Formatted number
|
|
71
|
-
*/
|
|
72
|
-
function fromBN(amount, decimals) {
|
|
73
|
-
const factor = Math.pow(10, decimals);
|
|
74
|
-
return amount.toNumber() / factor;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Derive a PDA (Program Derived Address) for the given seeds
|
|
78
|
-
*
|
|
79
|
-
* @param programId Program ID
|
|
80
|
-
* @param type PDA seed type
|
|
81
|
-
* @param seeds Additional seeds
|
|
82
|
-
* @returns [PDA, bump]
|
|
83
|
-
*/
|
|
84
|
-
function findPda(programId, type, ...seeds) {
|
|
85
|
-
const seedBuffers = [
|
|
86
|
-
Buffer.from(type),
|
|
87
|
-
...seeds.map(seed => {
|
|
88
|
-
if (seed instanceof web3_js_1.PublicKey) {
|
|
89
|
-
return seed.toBuffer();
|
|
90
|
-
}
|
|
91
|
-
else if (typeof seed === 'string') {
|
|
92
|
-
return Buffer.from(seed);
|
|
93
|
-
}
|
|
94
|
-
else if (typeof seed === 'number') {
|
|
95
|
-
return Buffer.from([seed]);
|
|
96
|
-
}
|
|
97
|
-
return seed;
|
|
98
|
-
})
|
|
99
|
-
];
|
|
100
|
-
return web3_js_1.PublicKey.findProgramAddressSync(seedBuffers, programId);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Convert a buffer to a hex string
|
|
104
|
-
*
|
|
105
|
-
* @param buffer Buffer to convert
|
|
106
|
-
* @returns Hex string
|
|
107
|
-
*/
|
|
108
|
-
function bufferToHex(buffer) {
|
|
109
|
-
return '0x' + Buffer.from(buffer).toString('hex');
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert a hex string to a buffer
|
|
113
|
-
*
|
|
114
|
-
* @param hex Hex string
|
|
115
|
-
* @returns Buffer
|
|
116
|
-
*/
|
|
117
|
-
function hexToBuffer(hex) {
|
|
118
|
-
const hexString = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
119
|
-
return Buffer.from(hexString, 'hex');
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Shorten a public key for display
|
|
123
|
-
*
|
|
124
|
-
* @param publicKey Public key to shorten
|
|
125
|
-
* @param chars Number of characters to show at the beginning and end
|
|
126
|
-
* @returns Shortened public key
|
|
127
|
-
*/
|
|
128
|
-
function shortenPublicKey(publicKey, chars = 4) {
|
|
129
|
-
const key = typeof publicKey === 'string' ? publicKey : publicKey.toBase58();
|
|
130
|
-
return `${key.slice(0, chars)}...${key.slice(-chars)}`;
|
|
131
|
-
}
|
package/dist/types/api.d.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API-related types for the Nord client
|
|
3
|
-
* @module types/api
|
|
4
|
-
*/
|
|
5
|
-
import { NordClientConfig } from './config';
|
|
6
|
-
import { Market, OrderbookData, Trade, Candle, Account, Balance, Order, OrderResult, PlaceOrderParams } from '../models';
|
|
7
|
-
import { WebSocketClient } from '../websocket/client';
|
|
8
|
-
/**
|
|
9
|
-
* Nord client interface with flat API structure
|
|
10
|
-
*/
|
|
11
|
-
export interface NordClient {
|
|
12
|
-
/**
|
|
13
|
-
* Client configuration
|
|
14
|
-
*/
|
|
15
|
-
config: NordClientConfig;
|
|
16
|
-
/**
|
|
17
|
-
* WebSocket client for real-time updates
|
|
18
|
-
*/
|
|
19
|
-
ws: WebSocketClient;
|
|
20
|
-
/**
|
|
21
|
-
* Get all available markets
|
|
22
|
-
*
|
|
23
|
-
* @returns Promise resolving to an array of markets
|
|
24
|
-
*/
|
|
25
|
-
getMarkets(): Promise<Market[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Get orderbook data for a specific market
|
|
28
|
-
*
|
|
29
|
-
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
30
|
-
* @returns Promise resolving to orderbook data
|
|
31
|
-
*/
|
|
32
|
-
getOrderbook(market: string): Promise<OrderbookData>;
|
|
33
|
-
/**
|
|
34
|
-
* Get recent trades for a specific market
|
|
35
|
-
*
|
|
36
|
-
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
37
|
-
* @param limit - Maximum number of trades to return (optional)
|
|
38
|
-
* @returns Promise resolving to an array of trades
|
|
39
|
-
*/
|
|
40
|
-
getTrades(market: string, limit?: number): Promise<Trade[]>;
|
|
41
|
-
/**
|
|
42
|
-
* Get candle data for a specific market and timeframe
|
|
43
|
-
*
|
|
44
|
-
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
45
|
-
* @param timeframe - Candle timeframe (e.g., "1m", "5m", "1h", "1d")
|
|
46
|
-
* @param limit - Maximum number of candles to return (optional)
|
|
47
|
-
* @returns Promise resolving to an array of candles
|
|
48
|
-
*/
|
|
49
|
-
getCandles(market: string, timeframe: string, limit?: number): Promise<Candle[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Get current server timestamp
|
|
52
|
-
*
|
|
53
|
-
* @returns Promise resolving to the current server timestamp in milliseconds
|
|
54
|
-
*/
|
|
55
|
-
getTimestamp(): Promise<number>;
|
|
56
|
-
/**
|
|
57
|
-
* Get account information
|
|
58
|
-
*
|
|
59
|
-
* @param accountId - Account ID
|
|
60
|
-
* @returns Promise resolving to account information
|
|
61
|
-
*/
|
|
62
|
-
getAccount(accountId: number): Promise<Account>;
|
|
63
|
-
/**
|
|
64
|
-
* Get all accounts for a specific address
|
|
65
|
-
*
|
|
66
|
-
* @param address - User's blockchain address
|
|
67
|
-
* @returns Promise resolving to an array of account IDs
|
|
68
|
-
*/
|
|
69
|
-
getAccounts(address: string): Promise<number[]>;
|
|
70
|
-
/**
|
|
71
|
-
* Get balance for a specific token in an account
|
|
72
|
-
*
|
|
73
|
-
* @param accountId - Account ID
|
|
74
|
-
* @param token - Token symbol (e.g., "BTC")
|
|
75
|
-
* @returns Promise resolving to balance information
|
|
76
|
-
*/
|
|
77
|
-
getBalance(accountId: number, token: string): Promise<Balance>;
|
|
78
|
-
/**
|
|
79
|
-
* Get all balances for an account
|
|
80
|
-
*
|
|
81
|
-
* @param accountId - Account ID
|
|
82
|
-
* @returns Promise resolving to an array of balances
|
|
83
|
-
*/
|
|
84
|
-
getBalances(accountId: number): Promise<Balance[]>;
|
|
85
|
-
/**
|
|
86
|
-
* Place a new order
|
|
87
|
-
*
|
|
88
|
-
* @param params - Order parameters
|
|
89
|
-
* @returns Promise resolving to order result
|
|
90
|
-
*/
|
|
91
|
-
placeOrder(params: PlaceOrderParams): Promise<OrderResult>;
|
|
92
|
-
/**
|
|
93
|
-
* Cancel an existing order
|
|
94
|
-
*
|
|
95
|
-
* @param orderId - Order ID to cancel
|
|
96
|
-
* @returns Promise resolving to true if successful
|
|
97
|
-
*/
|
|
98
|
-
cancelOrder(orderId: number): Promise<boolean>;
|
|
99
|
-
/**
|
|
100
|
-
* Get information about a specific order
|
|
101
|
-
*
|
|
102
|
-
* @param orderId - Order ID
|
|
103
|
-
* @returns Promise resolving to order information
|
|
104
|
-
*/
|
|
105
|
-
getOrder(orderId: number): Promise<Order>;
|
|
106
|
-
/**
|
|
107
|
-
* Get all orders for an account
|
|
108
|
-
*
|
|
109
|
-
* @param accountId - Account ID
|
|
110
|
-
* @returns Promise resolving to an array of orders
|
|
111
|
-
*/
|
|
112
|
-
getOrders(accountId: number): Promise<Order[]>;
|
|
113
|
-
metrics: {
|
|
114
|
-
/**
|
|
115
|
-
* Get aggregate metrics
|
|
116
|
-
*
|
|
117
|
-
* @returns Promise resolving to aggregate metrics
|
|
118
|
-
*/
|
|
119
|
-
getAggregate(): Promise<any>;
|
|
120
|
-
/**
|
|
121
|
-
* Get peak transactions per second for a specific timeframe
|
|
122
|
-
*
|
|
123
|
-
* @param timeframe - Timeframe (e.g., "1h", "1d", "7d")
|
|
124
|
-
* @returns Promise resolving to peak TPS value
|
|
125
|
-
*/
|
|
126
|
-
getPeakTps(timeframe: string): Promise<number>;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Subscribe to orderbook updates for a specific market
|
|
130
|
-
*
|
|
131
|
-
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
132
|
-
* @param callback - Callback function to handle updates
|
|
133
|
-
* @returns Subscription ID
|
|
134
|
-
*/
|
|
135
|
-
subscribeToOrderbook(market: string, callback: (data: OrderbookData) => void): string;
|
|
136
|
-
/**
|
|
137
|
-
* Subscribe to trade updates for a specific market
|
|
138
|
-
*
|
|
139
|
-
* @param market - Market symbol (e.g., "BTCUSDC")
|
|
140
|
-
* @param callback - Callback function to handle updates
|
|
141
|
-
* @returns Subscription ID
|
|
142
|
-
*/
|
|
143
|
-
subscribeToTrades(market: string, callback: (data: Trade[]) => void): string;
|
|
144
|
-
/**
|
|
145
|
-
* Subscribe to user updates for a specific account
|
|
146
|
-
*
|
|
147
|
-
* @param accountId - Account ID
|
|
148
|
-
* @param callback - Callback function to handle updates
|
|
149
|
-
* @returns Subscription ID
|
|
150
|
-
*/
|
|
151
|
-
subscribeToUserUpdates(accountId: number, callback: (data: any) => void): string;
|
|
152
|
-
}
|
package/dist/types/api.js
DELETED
package/dist/types/config.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration types for the Nord client
|
|
3
|
-
* @module types/config
|
|
4
|
-
*/
|
|
5
|
-
import { TokenInfo } from '../models/token';
|
|
6
|
-
/**
|
|
7
|
-
* Configuration options for the Nord client
|
|
8
|
-
*/
|
|
9
|
-
export interface NordClientConfig {
|
|
10
|
-
/**
|
|
11
|
-
* Base URL for the Nord web server
|
|
12
|
-
*/
|
|
13
|
-
webServerUrl: string;
|
|
14
|
-
/**
|
|
15
|
-
* Token information
|
|
16
|
-
*/
|
|
17
|
-
tokenInfos?: TokenInfo[];
|
|
18
|
-
/**
|
|
19
|
-
* Solana program ID (optional)
|
|
20
|
-
*/
|
|
21
|
-
solanaProgramId?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Solana RPC URL (optional)
|
|
24
|
-
*/
|
|
25
|
-
solanaUrl?: string;
|
|
26
|
-
/**
|
|
27
|
-
* EVM URL (optional)
|
|
28
|
-
*/
|
|
29
|
-
evmUrl?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Contract address (optional)
|
|
32
|
-
*/
|
|
33
|
-
contractAddress?: string;
|
|
34
|
-
}
|
package/dist/types/config.js
DELETED
package/dist/utils/errors.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error handling utilities
|
|
3
|
-
* @module utils/errors
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Base error class for Nord SDK
|
|
7
|
-
*/
|
|
8
|
-
export declare class NordError extends Error {
|
|
9
|
-
/**
|
|
10
|
-
* Original error that caused this error
|
|
11
|
-
*/
|
|
12
|
-
readonly cause?: Error;
|
|
13
|
-
/**
|
|
14
|
-
* Error code
|
|
15
|
-
*/
|
|
16
|
-
readonly code?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Create a new Nord error
|
|
19
|
-
*
|
|
20
|
-
* @param message - Error message
|
|
21
|
-
* @param options - Error options
|
|
22
|
-
*/
|
|
23
|
-
constructor(message: string, options?: {
|
|
24
|
-
cause?: Error;
|
|
25
|
-
code?: string;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Error class for API errors
|
|
30
|
-
*/
|
|
31
|
-
export declare class NordApiError extends NordError {
|
|
32
|
-
/**
|
|
33
|
-
* HTTP status code
|
|
34
|
-
*/
|
|
35
|
-
readonly statusCode: number;
|
|
36
|
-
/**
|
|
37
|
-
* API endpoint
|
|
38
|
-
*/
|
|
39
|
-
readonly endpoint: string;
|
|
40
|
-
/**
|
|
41
|
-
* Create a new API error
|
|
42
|
-
*
|
|
43
|
-
* @param message - Error message
|
|
44
|
-
* @param statusCode - HTTP status code
|
|
45
|
-
* @param endpoint - API endpoint
|
|
46
|
-
* @param cause - Original error
|
|
47
|
-
*/
|
|
48
|
-
constructor(message: string, statusCode: number, endpoint: string, cause?: Error);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Error class for validation errors
|
|
52
|
-
*/
|
|
53
|
-
export declare class NordValidationError extends NordError {
|
|
54
|
-
/**
|
|
55
|
-
* Field that failed validation
|
|
56
|
-
*/
|
|
57
|
-
readonly field: string;
|
|
58
|
-
/**
|
|
59
|
-
* Create a new validation error
|
|
60
|
-
*
|
|
61
|
-
* @param message - Error message
|
|
62
|
-
* @param field - Field that failed validation
|
|
63
|
-
*/
|
|
64
|
-
constructor(message: string, field: string);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Error class for WebSocket errors
|
|
68
|
-
*/
|
|
69
|
-
export declare class NordWebSocketError extends NordError {
|
|
70
|
-
/**
|
|
71
|
-
* Create a new WebSocket error
|
|
72
|
-
*
|
|
73
|
-
* @param message - Error message
|
|
74
|
-
* @param cause - Original error
|
|
75
|
-
*/
|
|
76
|
-
constructor(message: string, cause?: Error);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Error class for authentication errors
|
|
80
|
-
*/
|
|
81
|
-
export declare class NordAuthError extends NordError {
|
|
82
|
-
/**
|
|
83
|
-
* Create a new authentication error
|
|
84
|
-
*
|
|
85
|
-
* @param message - Error message
|
|
86
|
-
* @param cause - Original error
|
|
87
|
-
*/
|
|
88
|
-
constructor(message: string, cause?: Error);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Format an error for logging
|
|
92
|
-
*
|
|
93
|
-
* @param error - Error to format
|
|
94
|
-
* @returns Formatted error string
|
|
95
|
-
*/
|
|
96
|
-
export declare function formatError(error: unknown): string;
|
package/dist/utils/errors.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Error handling utilities
|
|
4
|
-
* @module utils/errors
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.NordAuthError = exports.NordWebSocketError = exports.NordValidationError = exports.NordApiError = exports.NordError = void 0;
|
|
8
|
-
exports.formatError = formatError;
|
|
9
|
-
/**
|
|
10
|
-
* Base error class for Nord SDK
|
|
11
|
-
*/
|
|
12
|
-
class NordError extends Error {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new Nord error
|
|
15
|
-
*
|
|
16
|
-
* @param message - Error message
|
|
17
|
-
* @param options - Error options
|
|
18
|
-
*/
|
|
19
|
-
constructor(message, options) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = 'NordError';
|
|
22
|
-
if (options?.cause) {
|
|
23
|
-
this.cause = options.cause;
|
|
24
|
-
}
|
|
25
|
-
if (options?.code) {
|
|
26
|
-
this.code = options.code;
|
|
27
|
-
}
|
|
28
|
-
// Ensure prototype chain is properly set up
|
|
29
|
-
Object.setPrototypeOf(this, NordError.prototype);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.NordError = NordError;
|
|
33
|
-
/**
|
|
34
|
-
* Error class for API errors
|
|
35
|
-
*/
|
|
36
|
-
class NordApiError extends NordError {
|
|
37
|
-
/**
|
|
38
|
-
* Create a new API error
|
|
39
|
-
*
|
|
40
|
-
* @param message - Error message
|
|
41
|
-
* @param statusCode - HTTP status code
|
|
42
|
-
* @param endpoint - API endpoint
|
|
43
|
-
* @param cause - Original error
|
|
44
|
-
*/
|
|
45
|
-
constructor(message, statusCode, endpoint, cause) {
|
|
46
|
-
super(message, { cause });
|
|
47
|
-
this.name = 'NordApiError';
|
|
48
|
-
this.statusCode = statusCode;
|
|
49
|
-
this.endpoint = endpoint;
|
|
50
|
-
// Ensure prototype chain is properly set up
|
|
51
|
-
Object.setPrototypeOf(this, NordApiError.prototype);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.NordApiError = NordApiError;
|
|
55
|
-
/**
|
|
56
|
-
* Error class for validation errors
|
|
57
|
-
*/
|
|
58
|
-
class NordValidationError extends NordError {
|
|
59
|
-
/**
|
|
60
|
-
* Create a new validation error
|
|
61
|
-
*
|
|
62
|
-
* @param message - Error message
|
|
63
|
-
* @param field - Field that failed validation
|
|
64
|
-
*/
|
|
65
|
-
constructor(message, field) {
|
|
66
|
-
super(message);
|
|
67
|
-
this.name = 'NordValidationError';
|
|
68
|
-
this.field = field;
|
|
69
|
-
// Ensure prototype chain is properly set up
|
|
70
|
-
Object.setPrototypeOf(this, NordValidationError.prototype);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.NordValidationError = NordValidationError;
|
|
74
|
-
/**
|
|
75
|
-
* Error class for WebSocket errors
|
|
76
|
-
*/
|
|
77
|
-
class NordWebSocketError extends NordError {
|
|
78
|
-
/**
|
|
79
|
-
* Create a new WebSocket error
|
|
80
|
-
*
|
|
81
|
-
* @param message - Error message
|
|
82
|
-
* @param cause - Original error
|
|
83
|
-
*/
|
|
84
|
-
constructor(message, cause) {
|
|
85
|
-
super(message, { cause });
|
|
86
|
-
this.name = 'NordWebSocketError';
|
|
87
|
-
// Ensure prototype chain is properly set up
|
|
88
|
-
Object.setPrototypeOf(this, NordWebSocketError.prototype);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
exports.NordWebSocketError = NordWebSocketError;
|
|
92
|
-
/**
|
|
93
|
-
* Error class for authentication errors
|
|
94
|
-
*/
|
|
95
|
-
class NordAuthError extends NordError {
|
|
96
|
-
/**
|
|
97
|
-
* Create a new authentication error
|
|
98
|
-
*
|
|
99
|
-
* @param message - Error message
|
|
100
|
-
* @param cause - Original error
|
|
101
|
-
*/
|
|
102
|
-
constructor(message, cause) {
|
|
103
|
-
super(message, { cause });
|
|
104
|
-
this.name = 'NordAuthError';
|
|
105
|
-
// Ensure prototype chain is properly set up
|
|
106
|
-
Object.setPrototypeOf(this, NordAuthError.prototype);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.NordAuthError = NordAuthError;
|
|
110
|
-
/**
|
|
111
|
-
* Format an error for logging
|
|
112
|
-
*
|
|
113
|
-
* @param error - Error to format
|
|
114
|
-
* @returns Formatted error string
|
|
115
|
-
*/
|
|
116
|
-
function formatError(error) {
|
|
117
|
-
if (error instanceof NordApiError) {
|
|
118
|
-
return `API Error (${error.statusCode}) for ${error.endpoint}: ${error.message}`;
|
|
119
|
-
}
|
|
120
|
-
else if (error instanceof NordValidationError) {
|
|
121
|
-
return `Validation Error for field '${error.field}': ${error.message}`;
|
|
122
|
-
}
|
|
123
|
-
else if (error instanceof NordError) {
|
|
124
|
-
return `Nord Error: ${error.message}`;
|
|
125
|
-
}
|
|
126
|
-
else if (error instanceof Error) {
|
|
127
|
-
return `Error: ${error.message}`;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
return `Unknown error: ${String(error)}`;
|
|
131
|
-
}
|
|
132
|
-
}
|
package/dist/utils/http.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP utilities for making API requests
|
|
3
|
-
* @module utils/http
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Make a GET request to the API
|
|
7
|
-
*
|
|
8
|
-
* @param baseUrl - Base URL for the API
|
|
9
|
-
* @param endpoint - API endpoint
|
|
10
|
-
* @param headers - Additional headers (optional)
|
|
11
|
-
* @returns Promise resolving to the response data
|
|
12
|
-
* @throws {NordApiError} If the request fails
|
|
13
|
-
*/
|
|
14
|
-
export declare function httpGet<T>(baseUrl: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Make a POST request to the API
|
|
17
|
-
*
|
|
18
|
-
* @param baseUrl - Base URL for the API
|
|
19
|
-
* @param endpoint - API endpoint
|
|
20
|
-
* @param data - Request data
|
|
21
|
-
* @param headers - Additional headers (optional)
|
|
22
|
-
* @returns Promise resolving to the response data
|
|
23
|
-
* @throws {NordApiError} If the request fails
|
|
24
|
-
*/
|
|
25
|
-
export declare function httpPost<T>(baseUrl: string, endpoint: string, data: any, headers?: Record<string, string>): Promise<T>;
|
|
26
|
-
/**
|
|
27
|
-
* Make a DELETE request to the API
|
|
28
|
-
*
|
|
29
|
-
* @param baseUrl - Base URL for the API
|
|
30
|
-
* @param endpoint - API endpoint
|
|
31
|
-
* @param headers - Additional headers (optional)
|
|
32
|
-
* @returns Promise resolving to the response data
|
|
33
|
-
* @throws {NordApiError} If the request fails
|
|
34
|
-
*/
|
|
35
|
-
export declare function httpDelete<T>(baseUrl: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
package/dist/utils/http.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* HTTP utilities for making API requests
|
|
4
|
-
* @module utils/http
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.httpGet = httpGet;
|
|
8
|
-
exports.httpPost = httpPost;
|
|
9
|
-
exports.httpDelete = httpDelete;
|
|
10
|
-
const errors_1 = require("./errors");
|
|
11
|
-
/**
|
|
12
|
-
* Make a GET request to the API
|
|
13
|
-
*
|
|
14
|
-
* @param baseUrl - Base URL for the API
|
|
15
|
-
* @param endpoint - API endpoint
|
|
16
|
-
* @param headers - Additional headers (optional)
|
|
17
|
-
* @returns Promise resolving to the response data
|
|
18
|
-
* @throws {NordApiError} If the request fails
|
|
19
|
-
*/
|
|
20
|
-
async function httpGet(baseUrl, endpoint, headers = {}) {
|
|
21
|
-
const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
|
|
22
|
-
try {
|
|
23
|
-
const response = await fetch(url, {
|
|
24
|
-
method: 'GET',
|
|
25
|
-
headers: {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
...headers,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
if (!response.ok) {
|
|
31
|
-
throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
|
|
32
|
-
}
|
|
33
|
-
return await response.json();
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error instanceof errors_1.NordApiError) {
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
throw new errors_1.NordApiError(`Failed to make GET request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Make a POST request to the API
|
|
44
|
-
*
|
|
45
|
-
* @param baseUrl - Base URL for the API
|
|
46
|
-
* @param endpoint - API endpoint
|
|
47
|
-
* @param data - Request data
|
|
48
|
-
* @param headers - Additional headers (optional)
|
|
49
|
-
* @returns Promise resolving to the response data
|
|
50
|
-
* @throws {NordApiError} If the request fails
|
|
51
|
-
*/
|
|
52
|
-
async function httpPost(baseUrl, endpoint, data, headers = {}) {
|
|
53
|
-
const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
|
|
54
|
-
try {
|
|
55
|
-
const response = await fetch(url, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'Content-Type': 'application/json',
|
|
59
|
-
...headers,
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(data),
|
|
62
|
-
});
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
|
|
65
|
-
}
|
|
66
|
-
return await response.json();
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (error instanceof errors_1.NordApiError) {
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
throw new errors_1.NordApiError(`Failed to make POST request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Make a DELETE request to the API
|
|
77
|
-
*
|
|
78
|
-
* @param baseUrl - Base URL for the API
|
|
79
|
-
* @param endpoint - API endpoint
|
|
80
|
-
* @param headers - Additional headers (optional)
|
|
81
|
-
* @returns Promise resolving to the response data
|
|
82
|
-
* @throws {NordApiError} If the request fails
|
|
83
|
-
*/
|
|
84
|
-
async function httpDelete(baseUrl, endpoint, headers = {}) {
|
|
85
|
-
const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(url, {
|
|
88
|
-
method: 'DELETE',
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
...headers,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
if (!response.ok) {
|
|
95
|
-
throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
|
|
96
|
-
}
|
|
97
|
-
return await response.json();
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
if (error instanceof errors_1.NordApiError) {
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
throw new errors_1.NordApiError(`Failed to make DELETE request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
|
|
104
|
-
}
|
|
105
|
-
}
|