@candlerip/shared 0.0.97 → 0.0.98

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/common/index.d.ts CHANGED
@@ -12,7 +12,6 @@ export * from './page/index.js';
12
12
  export * from './page-data/index.js';
13
13
  export * from './page-menu/index.js';
14
14
  export * from './person/index.js';
15
- export * from './request/index.js';
16
15
  export * from './server-data/index.js';
17
16
  export * from './service/index.js';
18
17
  export * from './styles/index.js';
package/common/index.js CHANGED
@@ -12,7 +12,6 @@ export * from './page/index.js';
12
12
  export * from './page-data/index.js';
13
13
  export * from './page-menu/index.js';
14
14
  export * from './person/index.js';
15
- export * from './request/index.js';
16
15
  export * from './server-data/index.js';
17
16
  export * from './service/index.js';
18
17
  export * from './styles/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared",
3
- "version": "0.0.97",
3
+ "version": "0.0.98",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "=22.19.0"
@@ -1 +0,0 @@
1
- export declare const APIS: string[];
@@ -1,17 +0,0 @@
1
- export const APIS = [
2
- 'deleteCandle',
3
- 'deletePerson',
4
- 'getCandles',
5
- 'getCountries',
6
- 'getCountryNamesTranslation',
7
- 'getPersons',
8
- 'homePage',
9
- 'myCandle',
10
- 'patchCandle',
11
- 'patchPerson',
12
- 'postCandle',
13
- 'postContact',
14
- 'postPerson',
15
- 'relightCandle',
16
- 'getPageDictionary',
17
- ];
@@ -1,2 +0,0 @@
1
- import { APIS } from './config.js';
2
- export type Api = (typeof APIS)[number];
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './domain.js';
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './domain.js';
@@ -1,9 +0,0 @@
1
- import { Api } from '../api/index.js';
2
- type ApiRoutes = {
3
- [key in Api]: {
4
- method: 'DELETE' | 'GET' | 'PATCH' | 'POST';
5
- path: string;
6
- };
7
- };
8
- export declare const API_ROUTES: ApiRoutes;
9
- export {};
@@ -1,66 +0,0 @@
1
- export const API_ROUTES = {
2
- deleteCandle: {
3
- method: 'DELETE',
4
- path: '/candles/[candleId]',
5
- },
6
- deletePerson: {
7
- method: 'DELETE',
8
- path: '/persons/[personId]',
9
- },
10
- getCandles: {
11
- method: 'GET',
12
- path: '/candles',
13
- },
14
- getCountries: {
15
- method: 'GET',
16
- path: '/countries',
17
- },
18
- getCountryNamesTranslation: {
19
- method: 'GET',
20
- path: '/country/names/translation',
21
- },
22
- getPersons: {
23
- method: 'GET',
24
- path: '/persons',
25
- },
26
- homePage: {
27
- method: 'GET',
28
- path: '/pages/home',
29
- },
30
- myCandle: {
31
- method: 'PATCH',
32
- path: '/candles/my/[candleId]',
33
- },
34
- patchCandle: {
35
- method: 'PATCH',
36
- path: '/candles/[candleId]',
37
- },
38
- patchPerson: {
39
- method: 'PATCH',
40
- path: '/persons/[personId]',
41
- },
42
- postCandle: {
43
- method: 'POST',
44
- path: '/candles',
45
- },
46
- postContact: {
47
- method: 'POST',
48
- path: '/contacts',
49
- },
50
- postPerson: {
51
- method: 'POST',
52
- path: '/persons',
53
- },
54
- relightCandle: {
55
- method: 'POST',
56
- path: '/candles/relight/[candleId]',
57
- },
58
- getPageDictionary: {
59
- method: 'GET',
60
- path: '/dictionary/page',
61
- },
62
- getLanguageDictionary: {
63
- method: 'GET',
64
- path: '/dictionary/language',
65
- },
66
- };
@@ -1 +0,0 @@
1
- export * from './config.js';
@@ -1 +0,0 @@
1
- export * from './config.js';
@@ -1,3 +0,0 @@
1
- export * from './api/index.js';
2
- export * from '../api-request/index.js';
3
- export * from './api-route/index.js';
@@ -1,3 +0,0 @@
1
- export * from './api/index.js';
2
- export * from '../api-request/index.js';
3
- export * from './api-route/index.js';
@@ -1,2 +0,0 @@
1
- import { ApiRequest } from './type.js';
2
- export declare const apiRequest: ApiRequest;
@@ -1,47 +0,0 @@
1
- import { composeRequestQuery } from '../request-query/index.js';
2
- import { API_ROUTES } from '../api/api-route/index.js';
3
- export const apiRequest = async (BACKEND_URL, { api, body, params, query }) => {
4
- const headers = {
5
- 'Content-type': 'application/json; charset=UTF-8',
6
- };
7
- const { method, path: pathTemplate } = API_ROUTES[api];
8
- let path = pathTemplate;
9
- if (params) {
10
- Object.keys(params).forEach((key) => {
11
- path = pathTemplate.replace(`[${key}]`, params[key]);
12
- });
13
- }
14
- let url = `${BACKEND_URL}${path}`;
15
- if (query) {
16
- url += `?${composeRequestQuery(query)}`;
17
- }
18
- try {
19
- const resp = await fetch(url, {
20
- credentials: 'include',
21
- headers,
22
- method,
23
- ...(body && { body: JSON.stringify(body) }),
24
- });
25
- const { status } = resp;
26
- if (status === 204) {
27
- return { data: null };
28
- }
29
- const data = await resp.json();
30
- if (status === 200) {
31
- return data;
32
- }
33
- return {
34
- error: {
35
- errorId: data.error?.id,
36
- status,
37
- },
38
- };
39
- }
40
- catch {
41
- return {
42
- error: {
43
- status: 503,
44
- },
45
- };
46
- }
47
- };
@@ -1,14 +0,0 @@
1
- import { Api } from '../api/api/index.js';
2
- export type ApiRequest = <T = never>(BACKEND_URL: string, options: {
3
- api: Api;
4
- body?: Record<string, unknown>;
5
- params?: Record<string, string>;
6
- query?: unknown;
7
- }) => Promise<{
8
- data: T;
9
- } | {
10
- error: {
11
- errorId: string;
12
- status: number;
13
- };
14
- }>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export * from './api/index.js';
2
- export * from './api-request/index.js';
3
- export * from './request-query/index.js';
@@ -1,3 +0,0 @@
1
- export * from './api/index.js';
2
- export * from './api-request/index.js';
3
- export * from './request-query/index.js';
@@ -1,2 +0,0 @@
1
- import { ComposeRequestQuery } from './type.js';
2
- export declare const composeRequestQuery: ComposeRequestQuery;
@@ -1,12 +0,0 @@
1
- import { isObject } from '../../../index.js';
2
- export const composeRequestQuery = (query) => {
3
- if (!isObject(query)) {
4
- return '';
5
- }
6
- return Object.keys(query)
7
- .map((it) => `${it
8
- .split(/(?=[A-Z])/)
9
- .join('_')
10
- .toLowerCase()}=${query[it]}`)
11
- .join('&');
12
- };
@@ -1 +0,0 @@
1
- export type ComposeRequestQuery = (query: unknown) => string;
@@ -1 +0,0 @@
1
- export * from './compose-request-query/index.js';
@@ -1 +0,0 @@
1
- export * from './compose-request-query/index.js';