Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ lab/files
*.dat

build
.npmrc
.npmrc
dist
81,544 changes: 0 additions & 81,544 deletions dist/inxt.es6.js

This file was deleted.

51 changes: 26 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,61 @@
"build"
],
"scripts": {
"build": "tsc",
"clean": "rimraf dist build coverage",
"build": "yarn clean && tsc",
"build:js": "yarn run build && browserify -s 'inxt' ./build/index.js -o dist/inxt.es6.js",
"test": "jest",
"test:watch": "jest --watch --detectOpenHandles",
"lint": "eslint ./src",
"lint:fix": "yarn run lint --fix",
"cli": "ts-node --files src/cli/index.ts",
"format": "prettier --write src/**/*.{js,jsx,tsx,ts} tests/**/*.{js,jsx,tsx,ts}"
"format": "prettier --write src/**/*.{js,jsx,tsx,ts} tests/**/*.{js,jsx,tsx,ts}",
"prepare": "husky"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@internxt/eslint-config-internxt": "2.0.1",
"@internxt/prettier-config": "internxt/prettier-config#v1.0.2",
"@types/archiver": "6.0.3",
"@jest/globals": "30.2.0",
"@types/archiver": "7.0.0",
"@types/async": "3.2.9",
"@types/chai": "5.2.2",
"@types/chai": "5.2.3",
"@types/chai-as-promised": "8.0.2",
"@types/express": "5.0.3",
"@types/express": "5.0.6",
"@types/jest": "30.0.0",
"@types/node": "22.18.3",
"@types/sinon": "17.0.4",
"@typescript-eslint/eslint-plugin": "8.44.0",
"@typescript-eslint/parser": "8.44.0",
"@types/node": "25.2.2",
"@types/sinon": "21.0.0",
"archiver": "7.0.1",
"browserify": "17.0.1",
"chai": "6.0.1",
"chai": "6.2.2",
"chai-as-promised": "8.0.2",
"commander": "14.0.1",
"dotenv": "17.2.2",
"eslint": "9.35.0",
"express": "^5.1.0",
"commander": "14.0.3",
"dotenv": "17.2.4",
"eslint": "9.39.2",
"express": "5.2.1",
"husky": "9.1.7",
"jest": "30.1.3",
"jest": "30.2.0",
"lint-staged": "16.2.7",
"mocha": "11.7.2",
"prettier": "3.6.2",
"rimraf": "6.0.1",
"sinon": "21.0.0",
"ts-jest": "29.4.3",
"mocha": "11.7.5",
"prettier": "3.8.1",
"rimraf": "6.1.2",
"sinon": "21.0.1",
"ts-jest": "29.4.6",
"ts-mocha": "11.1.0",
"ts-node": "10.9.2",
"typescript": "5.8.3",
"typescript": "5.9.3",
"uuid": "13.0.0"
},
"dependencies": {
"@internxt/lib": "1.3.1",
"@internxt/sdk": "1.11.10",
"@internxt/lib": "1.4.1",
"@internxt/sdk": "1.12.6",
"async": "3.2.6",
"axios": "1.12.2",
"axios": "1.13.5",
"bip39": "3.1.0",
"undici": "5.29.0",
"winston": "3.17.0"
"winston": "3.19.0"
},
"lint-staged": {
"*.{js,jsx,tsx,ts}": [
Expand Down
20 changes: 10 additions & 10 deletions src/api/Bucket.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface Bucket {
id: string
user: string
encryptionKey: string
publicPermissions: string[]
created: Date
name: string
pubkeys: string[]
status: string
transfer: number,
storage: number
id: string;
user: string;
encryptionKey: string;
publicPermissions: string[];
created: Date;
name: string;
pubkeys: string[];
status: string;
transfer: number;
storage: number;
}
2 changes: 1 addition & 1 deletion src/api/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ContractMeta {
nodeID: string;
lastSeen: number;
};
url: string
url: string;
}

export class Contract {
Expand Down
4 changes: 2 additions & 2 deletions src/api/ExchangeReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export class ExchangeReport {

error() {
this.DownloadError();
this.sendReport().catch(() => { });
this.sendReport().catch(() => {});
}

success() {
this.DownloadOk();
this.sendReport().catch(() => { });
this.sendReport().catch(() => {});
}
}
2 changes: 1 addition & 1 deletion src/api/FileObjectUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FileObjectUpload extends EventEmitter implements FileObjectUploadPr
index: Buffer;
frameId: string;
bucketId: string;
fileEncryptionKey = Buffer.alloc(0);
fileEncryptionKey: Buffer<ArrayBufferLike> = Buffer.alloc(0);

constructor(config: EnvironmentConfig, name: string, bucketId: string, uploader: UploadStrategy, api?: InxtApiI) {
super();
Expand Down
64 changes: 32 additions & 32 deletions src/api/ShardObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ export class ShardObject extends EventEmitter {
return get<{ result: string }>(url, { useProxy }).then((res) => res.result);
}

static async getPutStream(
url: PutUrl,
useProxy: boolean,
): Promise<Writable> {
static async getPutStream(url: PutUrl, useProxy: boolean): Promise<Writable> {
let free: undefined | (() => void);
let targetUrl = url;

Expand All @@ -90,34 +87,37 @@ export class ShardObject extends EventEmitter {
}
const formattedUrl = new URL(targetUrl);
const request = formattedUrl.protocol === 'http:' ? httpRequest : httpsRequest;

return request({
headers: {
'Content-Type': 'application/octet-stream'

return request(
{
headers: {
'Content-Type': 'application/octet-stream',
},
hostname: formattedUrl.hostname,
port: formattedUrl.port,
protocol: formattedUrl.protocol,
path: formattedUrl.pathname + '?' + formattedUrl.searchParams.toString(),
method: 'PUT',
},
hostname: formattedUrl.hostname,
port: formattedUrl.port,
protocol: formattedUrl.protocol,
path: formattedUrl.pathname + '?' + formattedUrl.searchParams.toString(),
method: 'PUT',
}, (res) => {
if (res.statusCode !== 200) {
console.log('Request failed with status ' + res.statusCode);
}

const chunks: Buffer[] = [];

res.on('data', chunks.push.bind(chunks));
res.once('error', (err) => {
console.log('err', err);
});
res.once('end', () => {
// const body = Buffer.concat(chunks);
// console.log(body.toString());
free?.();
});
});
}
(res) => {
if (res.statusCode !== 200) {
console.log('Request failed with status ' + res.statusCode);
}

const chunks: Buffer[] = [];

res.on('data', chunks.push.bind(chunks));
res.once('error', (err) => {
console.log('err', err);
});
res.once('end', () => {
// const body = Buffer.concat(chunks);
// console.log(body.toString());
free?.();
});
},
);
}

static async putStreamTwo(
url: PutUrl,
Expand All @@ -138,7 +138,7 @@ export class ShardObject extends EventEmitter {
const putRequest = request(
{
headers: {
'Content-Type': 'application/octet-stream'
'Content-Type': 'application/octet-stream',
},
hostname: formattedUrl.hostname,
port: formattedUrl.port,
Expand Down
39 changes: 19 additions & 20 deletions src/cli/EnvService.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
export interface EnvKeys {
readonly BRIDGE_USER: string;
readonly BRIDGE_PASS: string;
readonly MNEMONIC: string;
readonly BUCKET_ID: string;
readonly BRIDGE_URL: string;
readonly STAGE: string;
readonly BRIDGE_USER: string;
readonly BRIDGE_PASS: string;
readonly MNEMONIC: string;
readonly BUCKET_ID: string;
readonly BRIDGE_URL: string;
readonly STAGE: string;
}


export class EnvService {
public static readonly instance: EnvService = new EnvService();
public static readonly instance: EnvService = new EnvService();

/**
* Gets the value from an environment key
* @param key The environment key to retrieve
* @throws {Error} If key is not found in process.env
* @returns The value from the environment variable
**/
public get = (key: keyof EnvKeys): string => {
const value = process.env[key];
if (!value) throw new Error(`Config key ${key} was not found in process.env`);
return value;
};
}
/**
* Gets the value from an environment key
* @param key The environment key to retrieve
* @throws {Error} If key is not found in process.env
* @returns The value from the environment variable
**/
public get = (key: keyof EnvKeys): string => {
const value = process.env[key];
if (!value) throw new Error(`Config key ${key} was not found in process.env`);
return value;
};
}
27 changes: 12 additions & 15 deletions src/cli/upload-file-multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ export async function uploadFileMultipart(filepath: string) {
const bucketId = EnvService.instance.get('BUCKET_ID');

const fileId = await new Promise((resolve: (fileId: string) => void, reject) => {
const state = network.uploadMultipartFile(
bucketId,
{
progressCallback: (progress: number) => {
logger.info('Progress %s%', (progress * 100).toFixed(2));
},
finishedCallback: (err: Error | null, res: string | null) => {
if (err) {
return reject(err);
}
const state = network.uploadMultipartFile(bucketId, {
progressCallback: (progress: number) => {
logger.info('Progress %s%', (progress * 100).toFixed(2));
},
finishedCallback: (err: Error | null, res: string | null) => {
if (err) {
return reject(err);
}

resolve(res as string);
},
fileSize: statSync(filepath).size,
source: createReadStream(filepath),
resolve(res as string);
},
);
fileSize: statSync(filepath).size,
source: createReadStream(filepath),
});

process.on('SIGINT', () => {
logger.info('Aborting upload');
Expand Down
33 changes: 15 additions & 18 deletions src/cli/upload-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@ export async function uploadFile(filepath: string) {
const bucketId = EnvService.instance.get('BUCKET_ID');

const fileId = await new Promise((resolve: (fileId: string) => void, reject) => {
const state = network.upload(
bucketId,
{
progressCallback: (progress: number) => {
logger.info('Progress %s%', (progress * 100).toFixed(2));
},
finishedCallback: (err: Error | null, res: string | null) => {
if (err) {
return reject(err);
} else if (!res) {
return reject('No response received from Network download');
}
resolve(res);
},
fileSize: statSync(filepath).size,
source: createReadStream(filepath)
}
);
const state = network.upload(bucketId, {
progressCallback: (progress: number) => {
logger.info('Progress %s%', (progress * 100).toFixed(2));
},
finishedCallback: (err: Error | null, res: string | null) => {
if (err) {
return reject(err);
} else if (!res) {
return reject('No response received from Network download');
}
resolve(res);
},
fileSize: statSync(filepath).size,
source: createReadStream(filepath),
});

process.on('SIGINT', () => {
logger.info('Aborting upload');
Expand Down
Loading