# @apiida/obsidian-api-helper

> apiida obsidian api helper

Latest version **7.1.6** (published 2023-11-08) · ISC license · 0 weekly downloads

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

## Install

```sh
npm install @apiida/obsidian-api-helper
pnpm add @apiida/obsidian-api-helper
yarn add @apiida/obsidian-api-helper
bun add @apiida/obsidian-api-helper
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 7.1.6 |
| Published | 2023-11-08 |
| First published | 2022-04-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 208.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | apiida |

## Links

- npm: https://www.npmjs.com/package/@apiida/obsidian-api-helper
- Repository: https://github.com/apiida/obsidian-api-helper
- Homepage: https://github.com/apiida/obsidian-api-helper#readme
- Issues: https://github.com/apiida/obsidian-api-helper/issues
- npm.io page: https://npm.io/package/@apiida/obsidian-api-helper

## Dependencies (6)

- [vue](https://npm.io/package/vue.md) ^3
- [axios](https://npm.io/package/axios.md) ^1
- [dayjs](https://npm.io/package/dayjs.md) ^1.11.5
- [pinia](https://npm.io/package/pinia.md) ^2.0.22
- [webstomp-client](https://npm.io/package/webstomp-client.md) ^1.2.6
- [tsconfig-paths-webpack-plugin](https://npm.io/package/tsconfig-paths-webpack-plugin.md) ^4.0.0

## Recent versions

- 7.1.6 (latest) — 2023-11-08
- 7.1.5 — 2023-11-06
- 7.1.4 — 2023-11-06
- 7.1.3 — 2023-10-18
- 7.1.2 — 2023-09-21
- 7.1.1 — 2023-08-31
- 7.1.0 — 2023-08-30
- 7.0.2 — 2023-08-04
- 7.0.1 — 2023-08-04
- 7.0.0 — 2023-08-04
- 6.3.0 — 2023-08-04
- 6.2.2 — 2023-08-03
- 6.2.1 — 2023-08-03
- 6.2.0 — 2023-08-03
- 6.1.1 — 2023-08-03
- … 194 more at https://npm.io/package/@apiida/obsidian-api-helper/versions

## README

# apiida obsidian api helper

https://apiida.com/product/obsidian/

https://pinia.vuejs.org/

https://axios-http.com/docs/intro

https://www.npmjs.com/package/webstomp-client

# Merge conflicts / version conflicts
The branches "master" and "fallback" are published on npm. Npm always takes the highest version number, the branch doesn't matter. The "master" should always contain the highest version (see examples below).
If there are problems with the versions during parallel development:
1) In case of a merge conflict you have to check if there are breaking changes in the other frontends. If so, the merge must be aborted and the fallback must be used.
2) There a new version number is set.
3) With this new version number you can continue to work in the other frontends.
4) Set the version number in the frontend:
```
npm install @apiida/obsidian-api-helper@2.1.0
```
5) Discuss with the team and merge the version number.

```
// local version of obsidian-api-helper
npm list @apiida/obsidian-api-helper

// Highest verion in npm (online)
npm view @apiida/obsidian-api-helper
```


## Usage

### Examples

Create the following two classes.
How to implement the classes

#### ApiClient.ts

```
import axios, { AxiosInstance } from 'axios';
import { ApiClient } from '@apiida/obsidian-api-helper';
import { notify } from 'notiwind';
import config from '../config';
import { insertTenantId } from '../helper/TenantHelper';

function getBackendUrl(): string {
  return `${config.backendUrl}/`;
}

const apiClient: AxiosInstance = axios.create({
  baseURL: getBackendUrl(),
  headers: {
    'Content-Type': 'application/json',
  },
  timeout: 30000,
  validateStatus(status: number) {
    return status < 500; // Resolve only if the status code is less than 500
  },
});

// Set the AUTH token for any request
apiClient.interceptors.request.use((axiosConfig) => {
  const token = localStorage.getItem('accessToken');

  if (axiosConfig != null && axiosConfig.headers !== undefined && token != null) {
    axiosConfig.headers.Authorization = token;
  }

  return axiosConfig;
});

export default new ApiClient(apiClient, notify);
```

#### BasicService.ts

```
import { BasicType, BasicService as TheBasicService } from '@apiida/obsidian-api-helper';
import apiClient from './ApiClient';

export default abstract class BasicService<T extends BasicType> extends TheBasicService<T> {
  protected constructor(url: string, entityName: string) {
    super(url, entityName, apiClient);
  }
}
```

Now you can create a Pinia Store and a service for your entity.

#### SubscriptionStore.ts

```
import { defineStore } from 'pinia';
import Subscription from '../types/applications/Subscription';

const subscription = defineStore({
  id: 'subscription',
  state: () => ({
    subscriptions: [] as Subscription[],
  }),
});

export default subscription;
```

#### SubscriptionService.ts

```
import Subscription from '../../types/applications/Subscription';
import subscriptionStore from '../../stores/SubscriptionStore';
import BasicService from '../BasicService';

class SubscriptionService extends BasicService<Subscription> {
  constructor() {
    super('/subscriptions', 'Subscription');
  }

  storeFill(entitys: Subscription[]): void {
    this.getStore().subscriptions = entitys;
  }

  storeGetAllEntitys(): Subscription[] {
    return this.getStore().subscriptions;
  }

  getStore(): any {
    return subscriptionStore();
  }
}

export default new SubscriptionService();
```

You can send CRUD calls to the API with the SubscriptionService and the BasicService takes care of
the caching.

## Contribute

### Version

The version is made up as follows.

```
BreakingChange.CreateOrUpdateComponent.BugFix (1.2.598)
```

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