open-index/open-npm huggingface dataset:
npm package: @roadiz/abstract-api-client
Description: Roadiz abstract API Typescript client interfaces and SDK
Author: Ambroise Maupate
Latest version: 3.1.4

# abstract-api-client
Abstract API Typescript client interfaces and SDK.

Based on *Axios* HTTP client.

## Usage

Version 3.x should only be used with Roadiz v2.1+, for older versions use version 2.x

```bash
yarn add @roadiz/abstract-api-client
```

tsconfig.json
```json
{
  "compilerOptions": {
    "types": [
      "@roadiz/abstract-api-client"
    ]
  }
}
```

### Customize Roadiz API client against your own API schema

- Download latest `d.ts` definition file from Roadiz backoffice
- Extend `RoadizApi` class

```ts
export default class MyAwesomeRoadizApi extends RoadizApi {
    /*
     * Page node-type
     */
    getPages(params: RoadizRequestNSParams) {
        return this.get<HydraCollection<NSPage>, RoadizRequestNSParams>('pages', { params })
    }
    
    /*
     * BlogPost node-type
     */
    getBlogPosts(params: RoadizRequestNSParams) {
        // Additional default params…
        params = {
            order: {
                publishedAt: 'DESC'
            },
            ...params,
        }
        return this.get<HydraCollection<NSBlockPost>, RoadizRequestNSParams>('blog_posts', { params })
    }
}
```

### Fetch all URLs for a sitemap

```ts
const api = new RoadizApi(process.env.API_BASE_URL,)

return api.fetchAllUrlsForLocale('fr').then((urls: Array<string>) => {
    // build your sitemap
})
```

### Get all alternative URLs for a node-source

Alternative links are useful to build language navigation for each website page. It's based
on HTTP response header `Link`.
API `getAlternateLinks` method will return a `Array<AlternateLink>` from an `AxiosResponse`:

```ts
const api = new RoadizApi(process.env.API_BASE_URL)

api.getWebResponseByPath('/').then((response) => {
    /*
     * [{
     *     url: '/',
     *     locale: 'en'
     * }, {
     *     url: '/fr',
     *     locale: 'fr'
     * }]
     */
    api.getAlternateLinks(response)
})
```

## Test

Tests use *jest* and require a working Roadiz headless API to fetch responses from. Copy `.env.dist` to `.env` 
and fill your server credentials.

```
yarn
cp .env.dist .env
yarn test
```
npm package: @roadiz/nuxt-module
Description: Nuxt Typescript module for Roadiz API client.
Author: Ambroise Maupate
Latest version: 3.0.1

# nuxt-module
Nuxt Typescript module for Roadiz API client.

## Usage

`yarn add @roadiz/nuxt-module`

### Configuration

Add module in you `nuxt.config.js` file and fill you API configuration values in `publicRuntimeConfig`:

```js
// nuxt.config.js

modules: [
    '@roadiz/nuxt-module'
],
    
publicRuntimeConfig: {
    roadiz: {
        baseURL: 'https://myroadizapi.test/api/1.0',
        apiKey: 'xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx',
        allowClientPreview: true,
        debug: false,
        origin: 'https://mywebsite.test'
    }
}
```

Make sure to add a default `origin` for any server side requests if you Roadiz API is secured by *RefererRegex*.

Add typescript declarations in your `tsconfig.json`:

```json
{
  "compilerOptions": {
    "types": [
      "@roadiz/nuxt-module"
    ]
  }
}
```

### API SDK

Here is a simple example how to fetch Roadiz API content during `asyncData`:

```ts
async asyncData({ $roadiz, route, req }: Context): Promise<object | void> | object | void {
    const path = route.params.pathMatch
    const response = await $roadiz.getWebResponseByPath(path)
    const pageData = response.data
    const altLinks = await $roadiz.getAlternateLinks(response)
    
    return {
        pageData,
        altLinks
    }
}
```

### Client previewing

If you enable `allowClientPreview` config, NuxtRoadizApi will append `_preview` and `token` query parameters to any
API request to your Roadiz API. `_preview` parameter will be passed-through, and `token` parameter will be added as 
`Authorization: Bearer ${token}` header.

If your user is currently *previewing* with a JWT, `$roadiz.previewingJwt` (`RoadizPreviewJwt`) object will be available 
to display information on your website.