@algorandfoundation/algokit-utils 1.0.0-beta.8 → 1.0.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/account.d.ts +91 -0
- package/account.d.ts.map +1 -0
- package/account.js +158 -0
- package/account.js.map +1 -0
- package/amount.d.ts +8 -0
- package/amount.d.ts.map +1 -0
- package/amount.js +24 -0
- package/amount.js.map +1 -0
- package/app.d.ts +108 -0
- package/app.d.ts.map +1 -0
- package/app.js +423 -0
- package/app.js.map +1 -0
- package/application-client.d.ts +10 -0
- package/application-client.d.ts.map +1 -0
- package/application-client.js +15 -0
- package/application-client.js.map +1 -0
- package/deploy-app.d.ts +93 -0
- package/deploy-app.d.ts.map +1 -0
- package/deploy-app.js +410 -0
- package/deploy-app.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -2
- package/index.js.map +1 -0
- package/indexer-lookup.d.ts +31 -0
- package/indexer-lookup.d.ts.map +1 -0
- package/indexer-lookup.js +96 -0
- package/indexer-lookup.js.map +1 -0
- package/localnet.d.ts +54 -0
- package/localnet.d.ts.map +1 -0
- package/localnet.js +121 -0
- package/localnet.js.map +1 -0
- package/network-client.d.ts +93 -0
- package/network-client.d.ts.map +1 -0
- package/network-client.js +182 -0
- package/network-client.js.map +1 -0
- package/package.json +3 -3
- package/testing/account.d.ts +14 -0
- package/testing/account.d.ts.map +1 -0
- package/testing/account.js +31 -0
- package/testing/account.js.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/testing/fixtures/algorand-fixture.d.ts +20 -0
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/testing/fixtures/algorand-fixture.js +49 -0
- package/testing/fixtures/algorand-fixture.js.map +1 -0
- package/testing/fixtures/index.d.ts +3 -0
- package/testing/fixtures/index.d.ts.map +1 -0
- package/testing/fixtures/index.js +19 -0
- package/testing/fixtures/index.js.map +1 -0
- package/testing/index.d.ts +6 -0
- package/testing/index.d.ts.map +1 -0
- package/testing/index.js +22 -0
- package/testing/index.js.map +1 -0
- package/testing/indexer.d.ts +12 -0
- package/testing/indexer.d.ts.map +1 -0
- package/testing/indexer.js +39 -0
- package/testing/indexer.js.map +1 -0
- package/testing/test-logger.d.ts +39 -0
- package/testing/test-logger.d.ts.map +1 -0
- package/testing/test-logger.js +69 -0
- package/testing/test-logger.js.map +1 -0
- package/testing/transaction-logger.d.ts +29 -0
- package/testing/transaction-logger.d.ts.map +1 -0
- package/testing/transaction-logger.js +71 -0
- package/testing/transaction-logger.js.map +1 -0
- package/transaction.d.ts +80 -0
- package/transaction.d.ts.map +1 -0
- package/transaction.js +256 -0
- package/transaction.js.map +1 -0
- package/transfer.d.ts +21 -0
- package/transfer.d.ts.map +1 -0
- package/transfer.js +65 -0
- package/transfer.js.map +1 -0
- package/types/account.d.ts +52 -0
- package/types/account.d.ts.map +1 -0
- package/types/account.js +86 -0
- package/types/account.js.map +1 -0
- package/types/algo-http-client-with-retry.d.ts +14 -0
- package/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/types/algo-http-client-with-retry.js +62 -0
- package/types/algo-http-client-with-retry.js.map +1 -0
- package/types/algod.d.ts +137 -0
- package/types/algod.d.ts.map +1 -0
- package/types/algod.js +3 -0
- package/types/algod.js.map +1 -0
- package/types/amount.d.ts +20 -0
- package/types/amount.d.ts.map +1 -0
- package/types/amount.js +37 -0
- package/types/amount.js.map +1 -0
- package/types/app.d.ts +279 -0
- package/types/app.d.ts.map +1 -0
- package/types/app.js +32 -0
- package/types/app.js.map +1 -0
- package/types/application-client.d.ts +229 -0
- package/types/application-client.d.ts.map +1 -0
- package/types/application-client.js +470 -0
- package/types/application-client.js.map +1 -0
- package/types/appspec.d.ts +77 -0
- package/types/appspec.d.ts.map +1 -0
- package/types/appspec.js +15 -0
- package/types/appspec.js.map +1 -0
- package/types/config.d.ts +15 -0
- package/types/config.d.ts.map +1 -0
- package/types/config.js +27 -0
- package/types/config.js.map +1 -0
- package/types/indexer.d.ts +313 -0
- package/types/indexer.d.ts.map +1 -0
- package/types/indexer.js +25 -0
- package/types/indexer.js.map +1 -0
- package/types/logging.d.ts +13 -0
- package/types/logging.d.ts.map +1 -0
- package/types/logging.js +27 -0
- package/types/logging.js.map +1 -0
- package/types/logic-error.d.ts +33 -0
- package/types/logic-error.d.ts.map +1 -0
- package/types/logic-error.js +46 -0
- package/types/logic-error.js.map +1 -0
- package/types/network-client.d.ts +11 -0
- package/types/network-client.d.ts.map +1 -0
- package/types/network-client.js +3 -0
- package/types/network-client.js.map +1 -0
- package/types/testing.d.ts +89 -0
- package/types/testing.d.ts.map +1 -0
- package/types/testing.js +3 -0
- package/types/testing.js.map +1 -0
- package/types/transaction.d.ts +67 -0
- package/types/transaction.d.ts.map +1 -0
- package/types/transaction.js +3 -0
- package/types/transaction.js.map +1 -0
- package/types/transfer.d.ts +32 -0
- package/types/transfer.d.ts.map +1 -0
- package/types/transfer.js +3 -0
- package/types/transfer.js.map +1 -0
- package/types/urlTokenBaseHTTPClient.d.ts +41 -0
- package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/types/urlTokenBaseHTTPClient.js +151 -0
- package/types/urlTokenBaseHTTPClient.js.map +1 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Account, LogicSigAccount, Transaction } from 'algosdk';
|
|
2
|
+
import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account';
|
|
3
|
+
import { PendingTransactionResponse } from './algod';
|
|
4
|
+
import { AlgoAmount } from './amount';
|
|
5
|
+
export type TransactionNote = Uint8Array | TransactionNoteData | Arc2TransactionNote;
|
|
6
|
+
export type TransactionNoteData = string | null | undefined | number | any[] | Record<string, any>;
|
|
7
|
+
/** ARC-0002 compatible transaction note components, @see https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md */
|
|
8
|
+
export type Arc2TransactionNote = {
|
|
9
|
+
dAppName: string;
|
|
10
|
+
format: 'm' | 'b' | 'u';
|
|
11
|
+
data: string;
|
|
12
|
+
} | {
|
|
13
|
+
dAppName: string;
|
|
14
|
+
format: 'j';
|
|
15
|
+
data: TransactionNoteData;
|
|
16
|
+
};
|
|
17
|
+
/** The sending configuration for a transaction */
|
|
18
|
+
export interface SendTransactionParams {
|
|
19
|
+
/** Whether to skip signing and sending the transaction to the chain (default: transaction signed and sent to chain)
|
|
20
|
+
* (and instead just return the raw transaction, e.g. so you can add it to a group of transactions) */
|
|
21
|
+
skipSending?: boolean;
|
|
22
|
+
/** Whether to skip waiting for the submitted transaction (only relevant if `skipSending` is `false` or unset) */
|
|
23
|
+
skipWaiting?: boolean;
|
|
24
|
+
/** Whether to suppress log messages from transaction send, default: do not suppress */
|
|
25
|
+
suppressLog?: boolean;
|
|
26
|
+
/** The flat fee you want to pay, useful for covering extra fees in a transaction group or app call */
|
|
27
|
+
fee?: AlgoAmount;
|
|
28
|
+
/** The maximum fee that you are happy to pay (default: unbounded) - if this is set it's possible the transaction could get rejected during network congestion */
|
|
29
|
+
maxFee?: AlgoAmount;
|
|
30
|
+
/** The maximum number of rounds to wait for confirmation, only applies if `skipWaiting` is `undefined` or `false`, default: wait up to 5 rounds */
|
|
31
|
+
maxRoundsToWaitForConfirmation?: number;
|
|
32
|
+
}
|
|
33
|
+
/** The result of sending a transaction */
|
|
34
|
+
export interface SendTransactionResult {
|
|
35
|
+
/** The transaction */
|
|
36
|
+
transaction: Transaction;
|
|
37
|
+
/** The response if the transaction was sent and waited for */
|
|
38
|
+
confirmation?: PendingTransactionResponse;
|
|
39
|
+
}
|
|
40
|
+
/** The result of sending and confirming a transaction */
|
|
41
|
+
export interface ConfirmedTransactionResult extends SendTransactionResult {
|
|
42
|
+
/** The response if the transaction was sent and waited for */
|
|
43
|
+
confirmation: PendingTransactionResponse;
|
|
44
|
+
}
|
|
45
|
+
export type SendTransactionFrom = Account | SigningAccount | LogicSigAccount | MultisigAccount | TransactionSignerAccount;
|
|
46
|
+
/** Defines an unsigned transaction that will appear in a group of transactions along with its signing information */
|
|
47
|
+
export interface TransactionToSign {
|
|
48
|
+
/** The unsigned transaction to sign and send */
|
|
49
|
+
transaction: Transaction;
|
|
50
|
+
/** The account to use to sign the transaction, either an account (with private key loaded) or a logic signature account */
|
|
51
|
+
signer: SendTransactionFrom;
|
|
52
|
+
}
|
|
53
|
+
/** A group of transactions to send together as an atomic group
|
|
54
|
+
* @see https://developer.algorand.org/docs/get-details/atomic_transfers/
|
|
55
|
+
*/
|
|
56
|
+
export interface TransactionGroupToSend {
|
|
57
|
+
/** Any parameters to control the semantics of the send to the network */
|
|
58
|
+
sendParams?: Omit<Omit<SendTransactionParams, 'maxFee'>, 'skipSending'>;
|
|
59
|
+
/** The list of transactions to send, which can either be a raw transaction (in which case `signer` is required),
|
|
60
|
+
* the async result of an AlgoKit utils method that returns a @see SendTransactionResult (saves unwrapping the promise, be sure to pass `skipSending: true`, `signer` is required)
|
|
61
|
+
* or the transaction with its signer
|
|
62
|
+
**/
|
|
63
|
+
transactions: (TransactionToSign | Transaction | Promise<SendTransactionResult>)[];
|
|
64
|
+
/** Optional signer to pass in, required if at least one transaction provided is just the transaction, ignored otherwise */
|
|
65
|
+
signer?: SendTransactionFrom;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AACpD,O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A;AAEzH,qHAAqH;AACrH,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,WAAW,EAAE,WAAW,CAAA;IACxB,2HAA2H;IAC3H,MAAM,EAAE,mBAAmB,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,yEAAyE;IACzE,UAAU,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAA;IACvE;;;QAGI;IACJ,YAAY,EAAE,CAAC,iBAAiB,GAAG,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAA;IAClF,2HAA2H;IAC3H,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/types/transaction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SuggestedParams } from 'algosdk';
|
|
2
|
+
import { AlgoAmount } from './amount';
|
|
3
|
+
import { SendTransactionFrom, SendTransactionParams, TransactionNote } from './transaction';
|
|
4
|
+
/** Parameters for @see transferAlgos call. */
|
|
5
|
+
export interface AlgoTransferParams extends SendTransactionParams {
|
|
6
|
+
/** The account (with private key loaded) that will send the µALGOs */
|
|
7
|
+
from: SendTransactionFrom;
|
|
8
|
+
/** The account address that will receive the ALGOs */
|
|
9
|
+
to: string;
|
|
10
|
+
/** The amount to send */
|
|
11
|
+
amount: AlgoAmount;
|
|
12
|
+
/** Optional transaction parameters */
|
|
13
|
+
transactionParams?: SuggestedParams;
|
|
14
|
+
/** The (optional) transaction note */
|
|
15
|
+
note?: TransactionNote;
|
|
16
|
+
}
|
|
17
|
+
/** Parameters for @see ensureFunded call. */
|
|
18
|
+
export interface EnsureFundedParams extends SendTransactionParams {
|
|
19
|
+
/** The account to fund */
|
|
20
|
+
accountToFund: SendTransactionFrom | string;
|
|
21
|
+
/** The account to use as a funding source */
|
|
22
|
+
fundingSource: SendTransactionFrom;
|
|
23
|
+
/** The minimum balance of ALGOs that the account should have available to spend (i.e. on top of minimum balance requirement) */
|
|
24
|
+
minSpendingBalance: AlgoAmount;
|
|
25
|
+
/** When issuing a funding amount, the minimum amount to transfer (avoids many small transfers if this gets called often on an active account) */
|
|
26
|
+
minFundingIncrement?: AlgoAmount;
|
|
27
|
+
/** Optional transaction parameters */
|
|
28
|
+
transactionParams?: SuggestedParams;
|
|
29
|
+
/** The (optional) transaction note, default: "Funding account to meet minimum requirement" */
|
|
30
|
+
note?: TransactionNote;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=transfer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../../src/types/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE3F,8CAA8C;AAC9C,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,sEAAsE;IACtE,IAAI,EAAE,mBAAmB,CAAA;IACzB,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAA;IACV,yBAAyB;IACzB,MAAM,EAAE,UAAU,CAAA;IAClB,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,eAAe,CAAA;IACnC,sCAAsC;IACtC,IAAI,CAAC,EAAE,eAAe,CAAA;CACvB;AAED,6CAA6C;AAC7C,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,0BAA0B;IAC1B,aAAa,EAAE,mBAAmB,GAAG,MAAM,CAAA;IAC3C,6CAA6C;IAC7C,aAAa,EAAE,mBAAmB,CAAA;IAClC,gIAAgI;IAChI,kBAAkB,EAAE,UAAU,CAAA;IAC9B,iJAAiJ;IACjJ,mBAAmB,CAAC,EAAE,UAAU,CAAA;IAChC,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,eAAe,CAAA;IACnC,8FAA8F;IAC9F,IAAI,CAAC,EAAE,eAAe,CAAA;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../src/types/transfer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseHTTPClient, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient';
|
|
2
|
+
export interface AlgodTokenHeader {
|
|
3
|
+
'X-Algo-API-Token': string;
|
|
4
|
+
}
|
|
5
|
+
export interface IndexerTokenHeader {
|
|
6
|
+
'X-Indexer-API-Token': string;
|
|
7
|
+
}
|
|
8
|
+
export interface KMDTokenHeader {
|
|
9
|
+
'X-KMD-API-Token': string;
|
|
10
|
+
}
|
|
11
|
+
export interface CustomTokenHeader {
|
|
12
|
+
[headerName: string]: string;
|
|
13
|
+
}
|
|
14
|
+
export type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader;
|
|
15
|
+
/**
|
|
16
|
+
* Implementation of BaseHTTPClient that uses a URL and a token
|
|
17
|
+
* and make the REST queries using fetch.
|
|
18
|
+
* This is the default implementation of BaseHTTPClient.
|
|
19
|
+
*/
|
|
20
|
+
export declare class URLTokenBaseHTTPClient implements BaseHTTPClient {
|
|
21
|
+
private defaultHeaders;
|
|
22
|
+
private readonly baseURL;
|
|
23
|
+
private readonly tokenHeader;
|
|
24
|
+
constructor(tokenHeader: TokenHeader, baseServer: string, port?: string | number, defaultHeaders?: Record<string, any>);
|
|
25
|
+
/**
|
|
26
|
+
* Compute the URL for a path relative to the instance's address
|
|
27
|
+
* @param relativePath - A path string
|
|
28
|
+
* @param query - An optional key-value object of query parameters to add to the URL. If the
|
|
29
|
+
* relativePath already has query parameters on it, the additional parameters defined here will
|
|
30
|
+
* be added to the URL without modifying those (unless a key collision occurs).
|
|
31
|
+
* @returns A URL string
|
|
32
|
+
*/
|
|
33
|
+
private getURL;
|
|
34
|
+
private static formatFetchResponseHeaders;
|
|
35
|
+
private static checkHttpError;
|
|
36
|
+
private static formatFetchResponse;
|
|
37
|
+
get(relativePath: string, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
38
|
+
post(relativePath: string, data: Uint8Array, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
39
|
+
delete(relativePath: string, data: Uint8Array, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=urlTokenBaseHTTPClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.d.ts","sourceRoot":"","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAuB,sBAAsB,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAA;AAI7H,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;CAC7B;AAUD,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,cAAc,GAAG,iBAAiB,CAAA;AAEpG;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAKuB,OAAO,CAAC,cAAc;IAJxG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;gBAG7B,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAU,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAkBlI;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM;IAkBd,OAAO,CAAC,MAAM,CAAC,0BAA0B;mBAQpB,cAAc;mBA+Bd,mBAAmB;IASlC,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAgB9H,IAAI,CACR,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;IAkB5B,MAAM,CACV,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;CAiBnC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.URLTokenBaseHTTPClient = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
6
|
+
class URLTokenBaseHTTPError extends Error {
|
|
7
|
+
constructor(message, response) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.name = 'URLTokenBaseHTTPError';
|
|
11
|
+
this.response = response;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Implementation of BaseHTTPClient that uses a URL and a token
|
|
16
|
+
* and make the REST queries using fetch.
|
|
17
|
+
* This is the default implementation of BaseHTTPClient.
|
|
18
|
+
*/
|
|
19
|
+
class URLTokenBaseHTTPClient {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
constructor(tokenHeader, baseServer, port, defaultHeaders = {}) {
|
|
22
|
+
this.defaultHeaders = defaultHeaders;
|
|
23
|
+
// Append a trailing slash so we can use relative paths. Without the trailing
|
|
24
|
+
// slash, the last path segment will be replaced by the relative path. See
|
|
25
|
+
// usage in `addressWithPath`.
|
|
26
|
+
const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`;
|
|
27
|
+
const baseServerURL = new URL(fixedBaseServer);
|
|
28
|
+
if (typeof port !== 'undefined') {
|
|
29
|
+
baseServerURL.port = port.toString();
|
|
30
|
+
}
|
|
31
|
+
if (baseServerURL.protocol.length === 0) {
|
|
32
|
+
throw new Error('Invalid base server URL, protocol must be defined.');
|
|
33
|
+
}
|
|
34
|
+
this.baseURL = baseServerURL;
|
|
35
|
+
this.tokenHeader = tokenHeader;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compute the URL for a path relative to the instance's address
|
|
39
|
+
* @param relativePath - A path string
|
|
40
|
+
* @param query - An optional key-value object of query parameters to add to the URL. If the
|
|
41
|
+
* relativePath already has query parameters on it, the additional parameters defined here will
|
|
42
|
+
* be added to the URL without modifying those (unless a key collision occurs).
|
|
43
|
+
* @returns A URL string
|
|
44
|
+
*/
|
|
45
|
+
getURL(relativePath, query) {
|
|
46
|
+
let fixedRelativePath;
|
|
47
|
+
if (relativePath.startsWith('./')) {
|
|
48
|
+
fixedRelativePath = relativePath;
|
|
49
|
+
}
|
|
50
|
+
else if (relativePath.startsWith('/')) {
|
|
51
|
+
fixedRelativePath = `.${relativePath}`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
fixedRelativePath = `./${relativePath}`;
|
|
55
|
+
}
|
|
56
|
+
const address = new URL(fixedRelativePath, this.baseURL);
|
|
57
|
+
if (query) {
|
|
58
|
+
for (const [key, value] of Object.entries(query)) {
|
|
59
|
+
address.searchParams.set(key, value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return address.toString();
|
|
63
|
+
}
|
|
64
|
+
static formatFetchResponseHeaders(headers) {
|
|
65
|
+
const headersObj = {};
|
|
66
|
+
headers.forEach((key, value) => {
|
|
67
|
+
headersObj[key] = value;
|
|
68
|
+
});
|
|
69
|
+
return headersObj;
|
|
70
|
+
}
|
|
71
|
+
static async checkHttpError(res) {
|
|
72
|
+
if (res.ok) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let body = null;
|
|
76
|
+
let bodyErrorMessage = null;
|
|
77
|
+
try {
|
|
78
|
+
body = new Uint8Array(await res.arrayBuffer());
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const decoded = JSON.parse(buffer_1.Buffer.from(body).toString());
|
|
81
|
+
if (decoded.message) {
|
|
82
|
+
bodyErrorMessage = decoded.message;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (_) {
|
|
86
|
+
// ignore any error that happened while we are parsing the error response
|
|
87
|
+
}
|
|
88
|
+
let message = `Network request error. Received status ${res.status} (${res.statusText})`;
|
|
89
|
+
if (bodyErrorMessage) {
|
|
90
|
+
message += `: ${bodyErrorMessage}`;
|
|
91
|
+
}
|
|
92
|
+
throw new URLTokenBaseHTTPError(message, {
|
|
93
|
+
body: body !== null ? body : new Uint8Array(),
|
|
94
|
+
status: res.status,
|
|
95
|
+
headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static async formatFetchResponse(res) {
|
|
99
|
+
await this.checkHttpError(res);
|
|
100
|
+
return {
|
|
101
|
+
body: new Uint8Array(await res.arrayBuffer()),
|
|
102
|
+
status: res.status,
|
|
103
|
+
headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async get(relativePath, query, requestHeaders = {}) {
|
|
107
|
+
// Expand headers for use in fetch
|
|
108
|
+
const headers = {
|
|
109
|
+
...this.tokenHeader,
|
|
110
|
+
...this.defaultHeaders,
|
|
111
|
+
...requestHeaders,
|
|
112
|
+
};
|
|
113
|
+
const res = await (0, cross_fetch_1.fetch)(this.getURL(relativePath, query), {
|
|
114
|
+
mode: 'cors',
|
|
115
|
+
headers,
|
|
116
|
+
});
|
|
117
|
+
return URLTokenBaseHTTPClient.formatFetchResponse(res);
|
|
118
|
+
}
|
|
119
|
+
async post(relativePath, data, query, requestHeaders = {}) {
|
|
120
|
+
// Expand headers for use in fetch
|
|
121
|
+
const headers = {
|
|
122
|
+
...this.tokenHeader,
|
|
123
|
+
...this.defaultHeaders,
|
|
124
|
+
...requestHeaders,
|
|
125
|
+
};
|
|
126
|
+
const res = await (0, cross_fetch_1.fetch)(this.getURL(relativePath, query), {
|
|
127
|
+
method: 'POST',
|
|
128
|
+
mode: 'cors',
|
|
129
|
+
body: data,
|
|
130
|
+
headers,
|
|
131
|
+
});
|
|
132
|
+
return URLTokenBaseHTTPClient.formatFetchResponse(res);
|
|
133
|
+
}
|
|
134
|
+
async delete(relativePath, data, query, requestHeaders = {}) {
|
|
135
|
+
// Expand headers for use in fetch
|
|
136
|
+
const headers = {
|
|
137
|
+
...this.tokenHeader,
|
|
138
|
+
...this.defaultHeaders,
|
|
139
|
+
...requestHeaders,
|
|
140
|
+
};
|
|
141
|
+
const res = await (0, cross_fetch_1.fetch)(this.getURL(relativePath, query), {
|
|
142
|
+
method: 'DELETE',
|
|
143
|
+
mode: 'cors',
|
|
144
|
+
body: data,
|
|
145
|
+
headers,
|
|
146
|
+
});
|
|
147
|
+
return URLTokenBaseHTTPClient.formatFetchResponse(res);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.URLTokenBaseHTTPClient = URLTokenBaseHTTPClient;
|
|
151
|
+
//# sourceMappingURL=urlTokenBaseHTTPClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.js","sourceRoot":"","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"names":[],"mappings":";;;AAKA,mCAA+B;AAC/B,6CAAmC;AAkBnC,MAAM,qBAAsB,SAAQ,KAAK;IACvC,YAAY,OAAe,EAAS,QAAgC;QAClE,KAAK,CAAC,OAAO,CAAC,CAAA;QADoB,aAAQ,GAAR,QAAQ,CAAwB;QAElE,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAID;;;;GAIG;AACH,MAAa,sBAAsB;IAIjC,8DAA8D;IAC9D,YAAY,WAAwB,EAAE,UAAkB,EAAE,IAAsB,EAAU,iBAAsC,EAAE;QAAxC,mBAAc,GAAd,cAAc,CAA0B;QAChI,6EAA6E;QAC7E,0EAA0E;QAC1E,8BAA8B;QAC9B,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,GAAG,CAAA;QAChF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;QAC9C,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;YAC/B,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;SACrC;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;SACtE;QAED,IAAI,CAAC,OAAO,GAAG,aAAa,CAAA;QAC5B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;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