# @decipad_org/safejs

> This repo intends to safely run JavaScript into a website using web workers

Latest version **0.7.1** (published 2023-08-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @decipad_org/safejs
pnpm add @decipad_org/safejs
yarn add @decipad_org/safejs
bun add @decipad_org/safejs
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.7.1 |
| Published | 2023-08-11 |
| First published | 2023-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Decipad |
| Maintainers | martafernandes_deci, johncosta27_work, decipad_n1n |
| Keywords | codeblock, safe, javascript |

## Links

- npm: https://www.npmjs.com/package/@decipad_org/safejs
- Repository: https://github.com/decipad/safejs
- Homepage: https://github.com/decipad/safejs#readme
- Issues: https://github.com/decipad/safejs/issues
- npm.io page: https://npm.io/package/@decipad_org/safejs

## Recent versions

- 0.7.1 (latest) — 2023-08-11
- 0.6.3 — 2023-07-11
- 0.6.2 — 2023-07-10
- 0.6.1 — 2023-07-10
- 0.6.0 — 2023-07-10
- 0.5.0 — 2023-07-10
- 0.4.0 — 2023-06-05
- 0.3.4 — 2023-06-05
- 0.3.3 — 2023-06-05
- 0.3.2 — 2023-06-02
- 0.3.1 — 2023-06-02
- 0.3.0 — 2023-06-01
- 0.2.2 — 2023-05-31
- 0.2.1 — 2023-05-31
- 0.2.0 — 2023-05-31
- … 15 more at https://npm.io/package/@decipad_org/safejs/versions

## README

# safejs

This repo intends to safely run JavaScript into a website using web workers. It provides a controller class, with some defaults.

## Blog Post Link

[Decipad Blog Link](https://www.decipad.com/blog/introducing-safejs-a-secure-way-to-integrate-data)

## Usage example

```ts
const myWorker = new SafeJs(
  // Success callback
  (successMessage) => {
    console.log(successMessage);
  },
  // Errors callback
  (err) => console.error(err),
  {
    maxExecutingTime: 50000,
  }
);

myWorker.execute('return "Hello World"');
```

## Parameters

As seen above, the third parameter for the `SafeJS` constructor is a series of options.

```ts
export interface SafeJsOptions {
  maxWorkerReturn: number; // Number of characters the stringified result is allowed to return. Default 10000.
  maxExecutingTime: number; // Kill the worker after not returning this number of milliseconds. Default 20000.
  maxConsoleLog: number; // Max number of logs returned. Default 200.
  extraWhitelist: Array<string>; // Objects you wish to whitelist and thus allow the user to use in their code.

  fetchProxyUrl: string | undefined; // Replaces the default `fetch` URL if provided.
}
```

## dev install

to test this package you need to set up with `link` (insert zelda pun):

In this repo:

```
pnpm link
```

Wherever you are using it

```
pnpm link "@decipad_org/safejs
```

If you use a builder, like webpack, you might have to rebuild. This is an example of how that might look like (in the safejs repo):

```
pnpm run build
```

## Inspiration

This package was partially inspired by (Wumpus World)[https://github.com/Domiii/WumpusGame/blob/master/js/script/GuestScriptContext.js]

---
_Source: https://npm.io/package/@decipad_org/safejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
