Skip to content

Commit

Permalink
Merge branch 'release/v1.18.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
algolucky committed Jul 5, 2022
2 parents b31187f + 50ebbe6 commit 2b36126
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 114 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# v1.18.1

## What's Changed

- Properly set maxWidth in trace by @joe-p in https://github.com/algorand/js-algorand-sdk/pull/593
- fix: safe intDecoding by @AlgoDoggo in https://github.com/algorand/js-algorand-sdk/pull/599
- Remove code that relies on node's path module by @bmdelacruz in https://github.com/algorand/js-algorand-sdk/pull/598

## New Contributors

- @AlgoDoggo made their first contribution in https://github.com/algorand/js-algorand-sdk/pull/599
- @bmdelacruz made their first contribution in https://github.com/algorand/js-algorand-sdk/pull/598

# v1.18.0

## What's Changed
Expand Down
12 changes: 1 addition & 11 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@ With Vite, you would see:
Uncaught ReferenceError: Buffer is not defined
```

You will have to install `buffer` and `path-browserify` as dependencies.

In `vite.config.js`, specify:

```js
resolve: {
alias: {
path: 'path-browserify';
}
}
```
You will have to install `buffer` as dependency.

In `index.html`, add the following:

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Include a minified browser bundle directly in your HTML like so:

```html
<script
src="https://unpkg.com/[email protected].0/dist/browser/algosdk.min.js"
integrity="sha384-sUsnfiP7rGkgddTfqUUdb66b2cVxVmYkCyrJBCcWWSmpccI73Vm9wkUrCLsEcG6f"
src="https://unpkg.com/[email protected].1/dist/browser/algosdk.min.js"
integrity="sha384-XUkDNLM09jpiPklD96D68Y77m6KhnWov0ZKy8xtca/UO8HIQ0f9OzI05Jxkt+ozd"
crossorigin="anonymous"
></script>
```
Expand All @@ -32,8 +32,8 @@ or

```html
<script
src="https://cdn.jsdelivr.net/npm/[email protected].0/dist/browser/algosdk.min.js"
integrity="sha384-sUsnfiP7rGkgddTfqUUdb66b2cVxVmYkCyrJBCcWWSmpccI73Vm9wkUrCLsEcG6f"
src="https://cdn.jsdelivr.net/npm/[email protected].1/dist/browser/algosdk.min.js"
integrity="sha384-XUkDNLM09jpiPklD96D68Y77m6KhnWov0ZKy8xtca/UO8HIQ0f9OzI05Jxkt+ozd"
crossorigin="anonymous"
></script>
```
Expand Down
58 changes: 3 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algosdk",
"version": "1.18.0",
"version": "1.18.1",
"description": "The official JavaScript SDK for Algorand",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand All @@ -25,8 +25,7 @@
"js-sha512": "^0.8.0",
"json-bigint": "^1.0.0",
"superagent": "^6.1.0",
"tweetnacl": "^1.0.3",
"url-parse": "^1.5.1"
"tweetnacl": "^1.0.3"
},
"devDependencies": {
"@types/json-bigint": "^1.0.0",
Expand All @@ -53,7 +52,6 @@
"mocha": "^9.0.0",
"mocha-lcov-reporter": "^1.3.0",
"mock-http-server": "^1.4.3",
"path-browserify": "^1.0.1",
"prettier": "2.2.1",
"selenium-webdriver": "^4.2.0",
"source-map-loader": "^2.0.2",
Expand Down
27 changes: 18 additions & 9 deletions src/client/urlTokenBaseHTTPClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Url from 'url-parse';
import path from 'path';
import * as request from 'superagent';
import {
BaseHTTPClient,
Expand Down Expand Up @@ -35,7 +33,7 @@ export type TokenHeader =
* This is the default implementation of BaseHTTPClient.
*/
export class URLTokenBaseHTTPClient implements BaseHTTPClient {
private readonly baseURL: Url;
private readonly baseURL: URL;
private readonly tokenHeader: TokenHeader;

constructor(
Expand All @@ -44,9 +42,15 @@ export class URLTokenBaseHTTPClient implements BaseHTTPClient {
port?: string | number,
private defaultHeaders: Record<string, any> = {}
) {
const baseServerURL = new Url(baseServer, {});
// Append a trailing slash so we can use relative paths. Without the trailing
// slash, the last path segment will be replaced by the relative path. See
// usage in `addressWithPath`.
const fixedBaseServer = baseServer.endsWith('/')
? baseServer
: `${baseServer}/`;
const baseServerURL = new URL(fixedBaseServer);
if (typeof port !== 'undefined') {
baseServerURL.set('port', port.toString());
baseServerURL.port = port.toString();
}

if (baseServerURL.protocol.length === 0) {
Expand All @@ -63,10 +67,15 @@ export class URLTokenBaseHTTPClient implements BaseHTTPClient {
* @returns A URL string
*/
private addressWithPath(relativePath: string) {
const address = new Url(
path.posix.join(this.baseURL.pathname, relativePath),
this.baseURL
);
let fixedRelativePath: string;
if (relativePath.startsWith('./')) {
fixedRelativePath = relativePath;
} else if (relativePath.startsWith('/')) {
fixedRelativePath = `.${relativePath}`;
} else {
fixedRelativePath = `./${relativePath}`;
}
const address = new URL(fixedRelativePath, this.baseURL);
return address.toString();
}

Expand Down
3 changes: 1 addition & 2 deletions src/dryrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ class DryrunTransactionResult {
disassembly: string[],
spc: StackPrinterConfig
): string {
let maxWidth = defaultMaxWidth;
if (spc.maxValueWidth === undefined) maxWidth = spc.maxValueWidth;
const maxWidth = spc.maxValueWidth || defaultMaxWidth;

// Create the array of arrays, each sub array contains N columns
const lines = [['pc#', 'ln#', 'source', 'scratch', 'stack']];
Expand Down
22 changes: 9 additions & 13 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface JSONOptions {
/**
* Parse JSON with additional options.
* @param str - The JSON string to parse.
* @param options - Parsing options.
* @param options - Options object to configure how integers in
* this request's JSON response will be decoded. Use the `intDecoding`
* property with one of the following options:
Expand All @@ -28,34 +27,32 @@ export interface JSONOptions {
export function parseJSON(str: string, options?: JSONOptions) {
const intDecoding =
options && options.intDecoding ? options.intDecoding : IntDecoding.DEFAULT;
const parsed = JSONbig.parse(str, (_, value) => {
return JSONbig.parse(str, (_, value) => {
if (
value != null &&
typeof value === 'object' &&
Object.getPrototypeOf(value) == null
) {
// for some reason the Objects returned by JSONbig.parse have a null prototype, so we
// need to fix that.
// JSONbig.parse objects are created with Object.create(null) and thus have a null prototype
// let us remedy that
Object.setPrototypeOf(value, Object.prototype);
}

if (typeof value === 'bigint') {
if (intDecoding === 'safe' && value > Number.MAX_SAFE_INTEGER) {
throw new Error(
`Integer exceeds maximum safe integer: ${value.toString()}. Try parsing with a different intDecoding option.`
);
}
if (
intDecoding === 'bigint' ||
(intDecoding === 'mixed' && value > Number.MAX_SAFE_INTEGER)
) {
return value;
}

// JSONbig.parse converts number to BigInts if they are >= 10**15. This is smaller than
// Number.MAX_SAFE_INTEGER, so we can convert some BigInts back to normal numbers.
if (intDecoding === 'default' || intDecoding === 'mixed') {
return Number(value);
}

throw new Error(
`Integer exceeds maximum safe integer: ${value.toString()}. Try parsing with a different intDecoding option.`
);
return Number(value);
}

if (typeof value === 'number') {
Expand All @@ -66,7 +63,6 @@ export function parseJSON(str: string, options?: JSONOptions) {

return value;
});
return parsed;
}

/**
Expand Down
23 changes: 12 additions & 11 deletions tests/2.Encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,18 @@ describe('encoding', () => {
});

it('should parse number', () => {
const input = '17';

for (const intDecoding of ['default', 'safe', 'mixed', 'bigint']) {
const actual = utils.parseJSON(input, { intDecoding });
const expected = intDecoding === 'bigint' ? 17n : 17;

assert.deepStrictEqual(
actual,
expected,
`Error when intDecoding = ${intDecoding}`
);
const inputs = ['17', '9007199254740991'];
for (const input of inputs) {
for (const intDecoding of ['default', 'safe', 'mixed', 'bigint']) {
const actual = utils.parseJSON(input, { intDecoding });
const expected =
intDecoding === 'bigint' ? BigInt(input) : Number(input);
assert.deepStrictEqual(
actual,
expected,
`Error when intDecoding = ${intDecoding}`
);
}
}
});

Expand Down
5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ module.exports = {
resolve: {
// Add '.ts' as resolvable extensions
extensions: ['.ts', '.js'],

// Support `path` in the browser
fallback: {
path: require.resolve('path-browserify'),
},
},
plugins: [
new webpack.ProvidePlugin({
Expand Down

0 comments on commit 2b36126

Please sign in to comment.