# ajaxness

> extended fetch api with synch and auth apis

Latest version **0.0.22** (published 2024-02-07) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install ajaxness
pnpm add ajaxness
yarn add ajaxness
bun add ajaxness
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.22 |
| Published | 2024-02-07 |
| First published | 2024-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jonathan de sena ribeiro |
| Maintainers | jsenaribeiro |
| Keywords | jwt, oauth, authentication, minimalism, auth, fetch, synch |

## Links

- npm: https://www.npmjs.com/package/ajaxness
- npm.io page: https://npm.io/package/ajaxness

## Dependencies (5)

- [bun](https://npm.io/package/bun.md) latest
- [bun-types](https://npm.io/package/bun-types.md) latest
- [typescript](https://npm.io/package/typescript.md) latest
- [@types/node](https://npm.io/package/@types/node.md) latest
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) latest

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 0.0.22 (latest) — 2024-02-07
- 0.0.21 — 2024-02-07
- 0.0.20 — 2024-02-07
- 0.0.19 — 2024-02-07
- 0.0.18 — 2024-02-05
- 0.0.17 — 2024-02-05
- 0.0.16 — 2024-02-05
- 0.0.15 — 2024-02-05
- 0.0.14 — 2024-02-05
- 0.0.13 — 2024-02-05
- 0.0.12 — 2024-02-05
- 0.0.11 — 2024-02-03
- 0.0.9 — 2024-02-03
- 0.0.8 — 2024-02-03
- 0.0.5 — 2024-02-03
- … 4 more at https://npm.io/package/ajaxness/versions

## README

# AJAXNESS

Ajaxness contains an extended fetch API with SWR caching extensions. It also contains a specialized Synch API for RESTful CRUD and a minimalist Auth API for bearer authentication with JWT and oAuth.

## fetch API

Extended fetch api with SWR settings features (caching, retry, etc).

<aside cols=2>

```ts
import { fetch } from 'react-'

// swr caching support

const cache = 42000
const cacheKeys = ['todos', 'ok']

fetch(url, { cache })   
fetch(url, { cache: "7min" })
fetch(url, { cache, cacheKeys })   
fetch(url, { cache: "no-cache" })   
fetch(url, { cache: "force-cache" })   

// revalidate (clear cache)

fetch.clear(cacheKeys)
fetch.clear()  // all
```

```ts
// swr features

const callback = e => console.log(e)
const retry = { repeat:3, interval:1000 }
const reget = { interval:1000, callback }
await fetch("http://etc.com", { retry })
await fetch("http://etc.com", { reget })

// auth token state

fetch.token = `Bearer ${token}`

// easy interceptors

fetch.on("request", req => ...)
fetch.on("response", res => ...)
fetch.on("exception", err => ...)
````

</aside>

## Synch API

RESTful fluent API for synchornization semantics.

<aside cols=2>

```ts
import { syncher } from 'react-'

const messageApi = syncher<User>(true)
   .fetch("http://message.api/baseURL")
   .catch(e => "not found...")
   .match(x => x, "id")   

// message Api is a ISync type

interface ISync<T,E> {   
   value: T
   await: boolean
   error: E|undefined
   async(mutate?): Promise<void>
}
```

```ts
// sync search/mutate flag

sync()      // querying sync
sync(true)  // mutation sync

// support SWR methods

const messageApi = syncher<User>(true)
   .retry(3, 1000)
   .cache(1000, ["messages", 1])
   .reget(1000, x => "pooling...")
   .fetch("http://message.api/baseURL")
   .catch(e => "not found...")
   .match(x => x, "id")   
```

</aside>

## Auth API

Simple fluent authentication API for JWT Bearer and oAuth authentication.

<aside cols=2>

```ts
// JWT bearer + basic Auth

interface Token { access: string }
interface User { role: string }

const session = authenticate<User>()
   .fetch("http://www.api.com/login")
   .catch(x => "Login fails", "/login")
   .match<Token>(x => x.access, "/home")

// oAuth provider support

const googleAuth: OAuth = {
   scopings:"public_profile,email",
   clientId:"asdfasfsadfasdfasdf",
   secretId:"asdfasdfasdfasdfasd",
}

const session = authenticate(googleAuth)
   .fetch("http://www.google.com/login")
   .catch(x => "Login fails", "/login")
   .match<Token>(x => x.token, "/home")

// login and logout behavior

await session.login(username, password)
const user = session.logged
session.logout()
```

</aside>

<br/>

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