# narvin-tpt-sdk

> ## Requirements

Latest version **0.6.3-0** (published 2023-12-29) · 0 weekly downloads

## Install

```sh
npm install narvin-tpt-sdk
pnpm add narvin-tpt-sdk
yarn add narvin-tpt-sdk
bun add narvin-tpt-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.3-0 |
| Published | 2023-12-29 |
| First published | 2023-11-28 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.10.0 |
| Dependencies | 5 |
| Unpacked size | 162.3 KB |
| Known vulnerabilities | 0 (+5 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | narvinpro |

## Links

- npm: https://www.npmjs.com/package/narvin-tpt-sdk
- npm.io page: https://npm.io/package/narvin-tpt-sdk

## Dependencies (5)

- [zod](https://npm.io/package/zod.md) 3.22.4
- [lodash](https://npm.io/package/lodash.md) 4.17.21
- [js-cookie](https://npm.io/package/js-cookie.md) 3.0.5
- [@faker-js/faker](https://npm.io/package/@faker-js/faker.md) 8.3.1
- [jsonapi-serializer](https://npm.io/package/jsonapi-serializer.md) 3.6.9

## Recent versions

- 0.6.3-0 (latest) — 2023-12-29
- 0.6.2-0 — 2023-12-29
- 0.6.1-0 — 2023-12-29
- 0.5.0-0 — 2023-12-28
- 0.4.0-0 — 2023-12-28
- 0.3.0-0 — 2023-12-18
- 0.2.0-0 — 2023-12-07
- 0.1.2-0 — 2023-11-28

## README

# narvin-tpt-sdk

## Requirements

- Node.js + npm. Versions are defined in `./package.json` and `.nvmrc`.

## How to use?

Import whatever you need from `narvin-tpt-sdk` module eg.

```ts
import { AuthorService } from 'narvin-tpt-sdk';

new authorService() = new AuthorService();

const author = authorService.getOne();
```

If you need some developers tools you can import them from `narvin-tpt-sdk/dev` eg.

```ts
import { AuthorMockService } from 'narvin-tpt-sdk/dev';

new authorMockService() = new AuthorMockService();

const author = authorMockService.getOne();
```

## Structure

SDK is devided into:

- **core** - place for config, errors, requests logic. Mostly for internal usage.
- **domain** - here we should place all our domain related logic. Every domain can consist of:

  - **services/** - directory where we put all domain related services.
    Each Service should use standarised protocol for communication:
    - Be class based
    - Make use of `FailedResult` and `CorrectResult` types as an return value from function
  - **repository.ts** - file where we fetch data.
  - **factory.ts** - place where we create our models.
  - **schemas.ts** - file where we defined zod schemas which are used during fetching.
  - **types.ts** - place to define our models/schema types.
  - **errors.ts** - fiel to define custom errors.
  - **index.ts** - entry file to our domain. We should only export elements which should be publicly available.
  - **index.dev.ts** - entry file to our domain but only for developer purposes only.

- **utils** - place for internal, not domain specific utils.

## API docs

Basic information about API is available [here](https://documenter.getpostman.com/view/25623546/2s93RWQXYJ#78417223-50df-4a98-b232-f6b1f1f9f795).

## Q&A

- **Why we don't use class based models?** - We are using typed plain object instead of contstructed ones (`new Modal()`) as models, because of React Server Components limitation which is forbidding use of them (serialization problem).
- **How to develop locally?** - Use `npm link` here and `npm link narvin-tpt-sdk` in your project directory.
- **How to publish?** - Login to company account via `npm login`, create new version with `npm version` and publish via `npm publish`

## TODO

- Translate error messages?
- Refactor apiRequest function
- Handle 204 apiRequest better (problem with missing schema)
- Split to smaller modules?
- Move error codes to static property of services
- Watch for cycle dependencies -> author <==> article
- Split author and category schema between detail and collection ones. In detail we will have articles, in collection not

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