-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api bzz react native #98
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
161774c
[react-native] added universal-url, changed Blob to object
vmaark c5438b8
fix linter issues
vmaark 20d20e6
Merge remote-tracking branch 'origin/typescript' into api-bzz-react-n…
vmaark 4219c00
Merge remote-tracking branch 'origin/typescript' into api-bzz-react-n…
vmaark 5b67655
change file to .ts
vmaark 0357c77
fix commands in package.json
vmaark 742cacc
Merge remote-tracking branch 'origin/master' into api-bzz-react-native
vmaark 11c58a3
convert react-native version to ts
vmaark 010f9af
fix dependencies
vmaark 3a3afb7
fix linter errors
vmaark 40bb8d1
add api-bzz-react-native to readme.md
vmaark 0ada85f
fix devDependencies
vmaark d2a4491
re-add accidentally deleted typings
vmaark 01606bd
remove flow from the lockfile
vmaark 285c70d
Merge branch 'master' into api-bzz-react-native
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.log | ||
/.idea | ||
/.vscode | ||
/packages/*/cjs | ||
/packages/*/dist | ||
/packages/*/esm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "../../.babelrc" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@erebos/api-bzz-react-native", | ||
"version": "0.9.0", | ||
"description": "Bzz API for react-native", | ||
"repository": "git@github.com:MainframeHQ/erebos.git", | ||
"main": "cjs/index.js", | ||
"module": "esm/index.js", | ||
"types": "types/index.d.ts", | ||
"author": "Mainframe", | ||
"license": "MIT", | ||
"files": [ | ||
"cjs/*", | ||
"esm/*", | ||
"types/*" | ||
], | ||
"scripts": { | ||
"clean": "del cjs esm types", | ||
"build:cjs": "BABEL_ENV='browser-cjs' babel src --out-dir cjs --extensions \".ts\"", | ||
"build:esm": "BABEL_ENV='browser-esm' babel src --out-dir esm --extensions \".ts\"", | ||
"build:js": "yarn build:cjs && yarn build:esm", | ||
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json", | ||
"build": "yarn clean && yarn build:js && yarn build:types", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.5.5", | ||
"@erebos/api-bzz-base": "^0.9.0", | ||
"universal-url": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "3.5.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-env browser */ | ||
// @ts-ignore | ||
import { URL } from 'universal-url' | ||
import { | ||
BaseBzz, | ||
BzzConfig, | ||
DirectoryData, | ||
UploadOptions, | ||
} from '@erebos/api-bzz-base' | ||
import { hexValue } from '@erebos/hex' | ||
|
||
export * from '@erebos/api-bzz-base' | ||
|
||
export class Bzz extends BaseBzz<Response> { | ||
public constructor(config: BzzConfig) { | ||
const { url, ...cfg } = config | ||
super(window.fetch.bind(window), { ...cfg, url: new URL(url).href }) | ||
} | ||
|
||
public uploadDirectory( | ||
directory: DirectoryData, | ||
options: UploadOptions = {}, | ||
): Promise<hexValue> { | ||
const form = new FormData() | ||
Object.keys(directory).forEach(key => { | ||
form.append( | ||
key, | ||
{ | ||
uri: directory[key].data, | ||
type: directory[key].contentType, | ||
name: key, | ||
} as any, | ||
key, | ||
) | ||
}) | ||
if (options.defaultPath != null) { | ||
const file = directory[options.defaultPath] | ||
if (file != null) { | ||
form.append( | ||
'', | ||
{ | ||
uri: directory[options.defaultPath].data, | ||
type: directory[options.defaultPath].contentType, | ||
name: options.defaultPath, | ||
} as any, | ||
'', | ||
) | ||
} | ||
} | ||
return this.uploadBody(form, options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.build.json", | ||
"compilerOptions": { | ||
"lib": ["dom", "es2015"], | ||
"outDir": "./types" | ||
}, | ||
"include": ["./src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BaseBzz, BzzConfig, DirectoryData, UploadOptions } from '@erebos/api-bzz-base'; | ||
import { hexValue } from '@erebos/hex'; | ||
export * from '@erebos/api-bzz-base'; | ||
export declare class Bzz extends BaseBzz<Response> { | ||
constructor(config: BzzConfig); | ||
uploadDirectory(directory: DirectoryData, options?: UploadOptions): Promise<hexValue>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use
global
instead ofwindow
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is needed, fetch is available globally in react-native, should we just pass in
fetch
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure in RN but on the Web it needed to be bound to the proper context, there was some issue without.