Skip to content

Commit

Permalink
Merge branch 'master' into borsh-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
frol authored Oct 31, 2023
2 parents df9ab61 + 7cc6f7f commit 54f6708
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changeset/funny-jars-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@near-js/accounts": patch
"near-api-js": patch
"@near-js/providers": patch
"@near-js/utils": patch
---

add check for global 'process' object
5 changes: 5 additions & 0 deletions .changeset/nice-worms-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@near-js/biometric-ed25519": minor
---

Handing null response on create key flow
6 changes: 6 additions & 0 deletions .changeset/wet-jars-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"near-api-js": patch
"@near-js/providers": patch
---

fixes override of global fetch property
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/epic-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Epic Template
about: Epics are milestones or groups of alike issues
title: ''
labels: Epic
assignees: ''

---

### Description

(Overview of milestone or function governed by this epic)

### Resources

(Relevant documentation, Figma links, and other reference material)

Item 1

Item 2

Item 3

```[tasklist]
### Related Issues
```
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Issue Template
about: Regular issues like defects or tasks.
title: ''
labels: ''
assignees: ''

---

### Description

(Summary of task, purpose, impact)

### Optional: User Story

(As a [user], I need [function, outcome, enhancement] that [provides value].)
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
environment: NPM
steps:
- name: Checkout Repo
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class Account {
* @param beneficiaryId The NEAR account that will receive the remaining Ⓝ balance from the account being deleted
*/
async deleteAccount(beneficiaryId: string) {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log('Deleting an account does not automatically transfer NFTs and FTs to the beneficiary address. Ensure to transfer assets before deleting.');
}
return this.signAndSendTransaction({
Expand Down
2 changes: 1 addition & 1 deletion packages/biometric-ed25519/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@near-js/biometric-ed25519",
"description": "JavaScript library to handle webauthn and biometric keys",
"version": "0.3.0",
"version": "0.4.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions packages/biometric-ed25519/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function setBufferIfUndefined() {
}
}

export class PasskeyProcessCanceled extends Error {
constructor(message) {
super(message);
this.name = 'PasskeyProcessCanceled';
}
}

export const createKey = async (username: string): Promise<KeyPair> => {
const cleanUserName = validateUsername(username);
if (!f2l.f2l) {
Expand All @@ -51,6 +58,10 @@ export const createKey = async (username: string): Promise<KeyPair> => {
setBufferIfUndefined();
return navigator.credentials.create({ publicKey })
.then(async (res) => {
if (!res) {
throw new PasskeyProcessCanceled('Failed to retrieve response from navigator.credentials.create');
}

const result = await f2l.attestation({
clientAttestationResponse: res,
origin,
Expand Down
5 changes: 1 addition & 4 deletions packages/near-api-js/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
import { readKeyFile } from './key_stores/unencrypted_file_system_keystore';
import { InMemoryKeyStore, MergeKeyStore } from './key_stores';
import { Near, NearConfig } from './near';
import fetch from './utils/setup-node-fetch';
import { logWarning } from './utils';

global.fetch = fetch;

export interface ConnectConfig extends NearConfig {
/**
* Initialize an {@link key_stores/in_memory_key_store!InMemoryKeyStore} by reading the file at keyPath.
Expand Down Expand Up @@ -57,7 +54,7 @@ export async function connect(config: ConnectConfig): Promise<Near> {
keyPathStore,
config.keyStore || config.deps?.keyStore
], { writeKeyStoreIndex: 1 });
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.log(`Loaded master account ${accountKeyFile[0]} key from ${config.keyPath} with public key = ${keyPair.getPublicKey()}`);
}
}
Expand Down
7 changes: 2 additions & 5 deletions packages/providers/src/fetch_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ConnectionInfo {
headers?: { [key: string]: string | number };
}

const logWarning = (...args) => !process.env['NEAR_NO_LOGS'] && console.warn(...args);
const logWarning = (...args) => !(typeof process === 'object' && process.env['NEAR_NO_LOGS']) && console.warn(...args);

export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any> {
let connectionInfo: ConnectionInfo = { url: null };
Expand All @@ -28,11 +28,8 @@ export async function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, js

const response = await exponentialBackoff(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, async () => {
try {
if (!global.fetch) {
global.fetch = (await import('./fetch')).default;
}

const response = await global.fetch(connectionInfo.url, {
const response = await (global.fetch ?? (await import('./fetch')).default)(connectionInfo.url, {
method: json ? 'POST' : 'GET',
body: json ? json : undefined,
headers: { ...connectionInfo.headers, 'Content-Type': 'application/json' }
Expand Down
2 changes: 1 addition & 1 deletion packages/providers/src/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class JsonRpcProvider extends Provider {
return response;
} catch (error) {
if (error.type === 'TimeoutError') {
if (!process.env['NEAR_NO_LOGS']) {
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])) {
console.warn(`Retrying request to ${method} as it has timed out`, params);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/errors/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function logWarning(...args: any[]): void {
if (!process.env['NEAR_NO_LOGS']){
if (!(typeof process === 'object' && process.env['NEAR_NO_LOGS'])){
console.warn(...args);
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FinalExecutionOutcome } from '@near-js/types';

import { parseRpcError } from './errors';

const SUPPRESS_LOGGING = !!process.env.NEAR_NO_LOGS;
const SUPPRESS_LOGGING = !!(typeof process === 'object' && process.env.NEAR_NO_LOGS);

/**
* Parse and print details from a query execution response
Expand Down

0 comments on commit 54f6708

Please sign in to comment.