@helebba/sdk 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@helebba/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Helebba SDK for external applications.",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
7
11
  "exports": {
8
12
  ".": {
9
- "development": "./src/index.ts",
13
+ "types": "./dist/index.d.ts",
10
14
  "import": "./dist/index.mjs",
11
15
  "default": "./dist/index.mjs"
12
16
  }
Binary file
package/src/client.ts DELETED
@@ -1,29 +0,0 @@
1
- import { createHttpClient } from './http';
2
- import type {
3
- Category,
4
- HelebbaClient,
5
- HelebbaClientOptions,
6
- InventoryBrand,
7
- OffsetPaginatedResult,
8
- Product,
9
- } from './types';
10
-
11
- export const createHelebbaClient = (options: HelebbaClientOptions): HelebbaClient => {
12
- const http = createHttpClient(options);
13
-
14
- return {
15
- products: {
16
- list: (params = {}) =>
17
- http.get<OffsetPaginatedResult<Product>>('/sdk/products', { query: params }),
18
- get: (productId) => http.get<Product>(`/sdk/products/${encodeURIComponent(productId)}`),
19
- },
20
- brands: {
21
- list: (params = {}) =>
22
- http.get<OffsetPaginatedResult<InventoryBrand>>('/sdk/brands', { query: params }),
23
- },
24
- categories: {
25
- list: (params = {}) =>
26
- http.get<OffsetPaginatedResult<Category>>('/sdk/categories', { query: params }),
27
- },
28
- };
29
- };
package/src/http.ts DELETED
@@ -1,81 +0,0 @@
1
- import type { HelebbaClientOptions, ListParams } from './types';
2
-
3
- type RequestOptions = {
4
- query?: ListParams;
5
- };
6
-
7
- export type HelebbaApiError = Error & {
8
- status: number;
9
- body: unknown;
10
- };
11
-
12
- export const createHelebbaApiError = (
13
- message: string,
14
- status: number,
15
- body: unknown,
16
- ): HelebbaApiError => {
17
- const error = new Error(message) as HelebbaApiError;
18
- error.name = 'HelebbaApiError';
19
- error.status = status;
20
- error.body = body;
21
- return error;
22
- };
23
-
24
- const trimTrailingSlash = (value: string) => value.replace(/\/+$/, '');
25
- const DEFAULT_BASE_URL = 'https://api.helebba.com/api/v1';
26
-
27
- const appendQuery = (url: URL, query: ListParams | undefined) => {
28
- if (!query) return;
29
-
30
- if (query.page !== undefined) url.searchParams.set('page', String(query.page));
31
- if (query.limit !== undefined) url.searchParams.set('limit', String(query.limit));
32
- if (query.search) url.searchParams.set('search', query.search);
33
- };
34
-
35
- export type HttpClient = {
36
- get: <T>(path: string, options?: RequestOptions) => Promise<T>;
37
- };
38
-
39
- export const createHttpClient = (options: HelebbaClientOptions): HttpClient => {
40
- if (!options.apiKey) throw new Error('Helebba SDK requires apiKey');
41
-
42
- const apiKey = options.apiKey;
43
- const baseUrl = trimTrailingSlash(options.baseUrl ?? DEFAULT_BASE_URL);
44
- const fetcher = options.fetcher ?? fetch;
45
-
46
- return {
47
- get: async <T>(path: string, options: RequestOptions = {}): Promise<T> => {
48
- const url = new URL(`${baseUrl}${path}`);
49
- appendQuery(url, options.query);
50
-
51
- const timestamp = Date.now().toString();
52
-
53
- const response = await fetcher(url, {
54
- method: 'GET',
55
- headers: {
56
- 'api-key': apiKey,
57
- 'x-timestamp': timestamp,
58
- 'x-path': url.pathname,
59
- 'x-client-user-agent': 'GSDK/0.1.0 (node)',
60
- Accept: 'application/json',
61
- },
62
- });
63
-
64
- const contentType = response.headers.get('content-type') ?? '';
65
- const body = contentType.includes('application/json')
66
- ? await response.json()
67
- : await response.text();
68
-
69
- if (!response.ok) {
70
- const message =
71
- typeof body === 'object' && body && 'message' in body
72
- ? String((body as { message: unknown }).message)
73
- : `Helebba API request failed with status ${response.status}`;
74
-
75
- throw createHelebbaApiError(message, response.status, body);
76
- }
77
-
78
- return body as T;
79
- },
80
- };
81
- };
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export { createHelebbaClient } from './client';
2
- export { createHelebbaApiError } from './http';
3
- export type { HelebbaApiError } from './http';
4
- export type {
5
- Category,
6
- HelebbaClient,
7
- HelebbaClientOptions,
8
- InventoryBrand,
9
- ListParams,
10
- OffsetPaginatedResult,
11
- Product,
12
- } from './types';
package/src/types.ts DELETED
@@ -1,61 +0,0 @@
1
- export type OffsetPageInfo = {
2
- page: number;
3
- pages: number;
4
- pageSize: number;
5
- totalItems: number;
6
- hasPreviousPage: boolean;
7
- hasNextPage: boolean;
8
- previousPage: number | null;
9
- nextPage: number | null;
10
- };
11
-
12
- export type OffsetPaginatedResult<T> = {
13
- kind: 'offset';
14
- count: number;
15
- items: T[];
16
- pageInfo: OffsetPageInfo;
17
- };
18
-
19
- export type ListParams = {
20
- page?: number;
21
- limit?: number;
22
- search?: string;
23
- };
24
-
25
- export type HelebbaClientOptions = {
26
- apiKey: string;
27
- baseUrl?: string;
28
- fetcher?: typeof fetch;
29
- };
30
-
31
- export type HelebbaClient = {
32
- products: {
33
- list: (params?: ListParams) => Promise<OffsetPaginatedResult<Product>>;
34
- get: (productId: string) => Promise<Product>;
35
- };
36
- brands: {
37
- list: (params?: ListParams) => Promise<OffsetPaginatedResult<InventoryBrand>>;
38
- };
39
- categories: {
40
- list: (params?: ListParams) => Promise<OffsetPaginatedResult<Category>>;
41
- };
42
- };
43
-
44
- export type Product = Record<string, unknown> & {
45
- id: string;
46
- name: string;
47
- sku?: string;
48
- description?: string;
49
- };
50
-
51
- export type InventoryBrand = Record<string, unknown> & {
52
- id: string;
53
- name: string;
54
- description?: string;
55
- };
56
-
57
- export type Category = Record<string, unknown> & {
58
- id: string;
59
- name: string;
60
- description?: string;
61
- };
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "@hlb/tooling/tsconfig/base.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "lib": ["ES2022", "DOM"]
7
- },
8
- "include": ["src/**/*.ts"]
9
- }
package/tsup.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm'],
6
- outExtension: () => ({ js: '.mjs' }),
7
- dts: true,
8
- sourcemap: true,
9
- clean: true,
10
- target: 'es2022',
11
- });
@@ -1,11 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm'],
6
- outExtension: () => ({ js: '.mjs' }),
7
- dts: false,
8
- sourcemap: true,
9
- clean: true,
10
- target: 'es2022',
11
- });