-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: manifest v3 changes * feat: add library * fix: manifest v3 fixes * fix: manifest v3 fixes * test: fix manifest v3 tests * fix: fix global postage batch in interceptors * fix: fix subdomain redirection * chore: fix merge issues * ci: build library in ci * test: fix hashes of test pages * ci: whitelist bzz protocol * ci: fix whitelist script * ci: fix ci script * ci: tests fix * test: log bzz page errors * test: add timeout * fix: remove google blocker * Revert "fix: remove google blocker" This reverts commit 7dde3fc. * feat: library improvements (#144) * fix: various fixes * chore: update library readme * fix: various fixes * fix: dapp registration * fix: various manifest v3 fixes * chore: test fixes * chore: fix eslint conflict * fix: declarative request handlers fix * test: fix tests * feat: add subdomain redirection (#147) * feat: add subdomain redirection * fix: fix interceptor ids * feat: support hash sign in url * feat: add echo debug method (#148) * feat: add echo debug method * chore: update library readme * chore: fix library redme example * chore: update readme * feat: remove session-id from url (#150) * chore: update readme * fix: fix subdomain redirection * fix: fix cors error * feat: change default bee address * chore: update readme * chore: fix typo in readme
- Loading branch information
1 parent
961a9c2
commit 287edee
Showing
83 changed files
with
12,437 additions
and
1,564 deletions.
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 +1,2 @@ | ||
dist/** | ||
test/**/swarm/** |
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 |
---|---|---|
|
@@ -26,3 +26,6 @@ extension.zip | |
|
||
# Dependency directory | ||
node_modules | ||
|
||
# test library | ||
test/**/swarm |
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,2 @@ | ||
dist/** | ||
test/**/swarm/** |
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,86 @@ | ||
module.exports = { | ||
extends: ['prettier'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2018, | ||
}, | ||
globals: { | ||
browser: true, | ||
page: true, | ||
}, | ||
rules: { | ||
'array-bracket-newline': ['error', { multiline: true }], | ||
strict: ['error', 'safe'], | ||
curly: 'error', | ||
'block-scoped-var': 'error', | ||
complexity: 'warn', | ||
'default-case': 'error', | ||
'dot-notation': 'warn', | ||
eqeqeq: 'error', | ||
'guard-for-in': 'warn', | ||
'linebreak-style': ['warn', 'unix'], | ||
'no-alert': 'error', | ||
'no-case-declarations': 'error', | ||
'no-constant-condition': 'error', | ||
'no-div-regex': 'error', | ||
'no-empty': 'warn', | ||
'no-empty-pattern': 'error', | ||
'no-implicit-coercion': 'error', | ||
'prefer-arrow-callback': 'warn', | ||
'no-labels': 'error', | ||
'no-loop-func': 'error', | ||
'no-nested-ternary': 'warn', | ||
'no-script-url': 'error', | ||
'no-warning-comments': 'warn', | ||
'quote-props': ['error', 'as-needed'], | ||
'require-yield': 'error', | ||
'max-nested-callbacks': ['error', 4], | ||
'max-depth': ['error', 4], | ||
'require-await': 'error', | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'space-before-function-paren': [ | ||
'error', | ||
{ | ||
anonymous: 'never', | ||
named: 'never', | ||
asyncArrow: 'always', | ||
}, | ||
], | ||
'padding-line-between-statements': [ | ||
'error', | ||
{ blankLine: 'always', prev: '*', next: 'if' }, | ||
{ blankLine: 'always', prev: '*', next: 'function' }, | ||
{ blankLine: 'always', prev: '*', next: 'return' }, | ||
], | ||
'no-useless-constructor': 'off', | ||
'no-dupe-class-members': 'off', | ||
'no-unused-expressions': 'off', | ||
curly: ['error', 'multi-line'], | ||
'object-curly-spacing': ['error', 'always'], | ||
'comma-dangle': ['error', 'always-multiline'], | ||
'@typescript-eslint/no-useless-constructor': 'error', | ||
'@typescript-eslint/no-unused-expressions': 'error', | ||
'@typescript-eslint/member-delimiter-style': [ | ||
'error', | ||
{ | ||
multiline: { | ||
delimiter: 'none', | ||
requireLast: true, | ||
}, | ||
singleline: { | ||
delimiter: 'semi', | ||
requireLast: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*.spec.ts'], | ||
rules: { | ||
// '@typescript-eslint/ban-ts-ignore': 'off', | ||
'max-nested-callbacks': ['error', 10], // allow describe/it nesting | ||
}, | ||
}, | ||
], | ||
} |
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,2 @@ | ||
node_modules | ||
build |
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,13 @@ | ||
{ | ||
"printWidth": 110, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"bracketSpacing": true, | ||
"semi": false, | ||
"singleQuote": true, | ||
"quoteProps": "as-needed", | ||
"trailingComma": "all", | ||
"endOfLine": "lf", | ||
"arrowParens": "avoid", | ||
"proseWrap": "always" | ||
} |
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,90 @@ | ||
# Swarm Browser Extension JS Library | ||
|
||
Library for interaction with the Swarm Browser Extension, from Dapps or other browser extensions. | ||
|
||
## Installation | ||
|
||
The library can be installed via npm: | ||
|
||
```bash | ||
npm install --save @ethersphere/swarm-extension | ||
``` | ||
|
||
## Usage | ||
|
||
### Swarm class | ||
|
||
All interaction with the Swarm browser extension is established through the Swarm class: | ||
|
||
```typescript | ||
import { Swarm } from '@fairdatasociety/swarm-extension' | ||
``` | ||
|
||
By default the class will connect to the Swarm browser extension using its ID from the Google store. If you | ||
are running your version of the extension the class can be configured with a different extension ID. | ||
|
||
```typescript | ||
const swarm = new Swarm() // Using the default Swarm ID from the Google store | ||
``` | ||
|
||
```typescript | ||
const swarm = new Swarm('Swarm Extension ID...') // Using custom Swarm ID | ||
``` | ||
|
||
To test if connection with the Swarm extension is established, call the `echo` method: | ||
|
||
```typescript | ||
const text = await swarm.echo<string>('test') | ||
console.log(text) // 'test' | ||
``` | ||
|
||
### Swarm class functionalities | ||
|
||
Before interacting with the library, Dapp should register new session by calling: | ||
|
||
```typescript | ||
await swarm.register() | ||
``` | ||
|
||
or new session will be implicitly created when calling any method for the first time. | ||
|
||
After registering a new session, session ID will be available as: | ||
|
||
```typescript | ||
swarm.sessionId | ||
``` | ||
|
||
There are four different objects available in the Swarm calass: | ||
|
||
- swarm.bzzLink - utility functions for converting bzz links | ||
- swarm.localStorage - methods for interacting with local storage | ||
- swarm.postageBatch - checking postage batch status | ||
- swarm.web2Helper - getting information about bee URL | ||
|
||
### Terminating connection | ||
|
||
Once when the instance of the Swarm class is not needed anymore, connection with the extension can be terminated. | ||
|
||
```typescript | ||
swarm.closeConnection() | ||
``` | ||
|
||
### Swarm HTML | ||
|
||
To enable Swarm HTML features, include the `swarm-html.js` script into HTML page. For more details check [Swarm HTML in the main readme](../README.md#swarm-html) | ||
|
||
## Development | ||
|
||
To watch for changes in the source code and recompile the library on change: | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
## Build | ||
|
||
To build the library: | ||
|
||
```bash | ||
npm run build | ||
``` |
Oops, something went wrong.