rlz-engine 1.0.10 → 1.0.11

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.
@@ -6,4 +6,4 @@ export interface AuthParam {
6
6
  userId: string;
7
7
  tempPassword: string;
8
8
  }
9
- export declare function apiCall<T extends ZodType>(method: string, path: string, auth: AuthParam | null, queryString: Record<string, string> | null, request: object | null, validator: T): Promise<z.infer<T>>;
9
+ export declare function apiCall<T extends ZodType>(method: string, version: string, path: string, auth: AuthParam | null, queryString: Record<string, string> | null, request: object | null, validator: T): Promise<z.infer<T>>;
@@ -1,12 +1,12 @@
1
- import { PRODUCTION } from '../../back/config';
2
- const API_DOMAIN = PRODUCTION ? '/' : 'http://localhost:8080/';
1
+ import { getFrontConfig } from '../config';
2
+ const API_DOMAIN = getFrontConfig().callLocalhost ? 'http://localhost:8080/' : '/';
3
3
  export class Forbidden extends Error {
4
4
  constructor(url) {
5
5
  super(`Forbidden: ${url}`);
6
6
  }
7
7
  }
8
- function url(path, queryString) {
9
- const base = `${API_DOMAIN}api/v0/${path}`;
8
+ function url(version, path, queryString) {
9
+ const base = `${API_DOMAIN}api/${version}/${path}`;
10
10
  if (queryString === null) {
11
11
  return base;
12
12
  }
@@ -25,7 +25,7 @@ async function prepareBody(request) {
25
25
  const bodyStreamCompressed = bodyStream.pipeThrough(new CompressionStream('gzip'));
26
26
  return new Response(bodyStreamCompressed).blob();
27
27
  }
28
- export async function apiCall(method, path, auth, queryString, request, validator) {
28
+ export async function apiCall(method, version, path, auth, queryString, request, validator) {
29
29
  const headers = {};
30
30
  const body = request === null ? undefined : await prepareBody(request);
31
31
  if (body !== undefined) {
@@ -37,7 +37,7 @@ export async function apiCall(method, path, auth, queryString, request, validato
37
37
  if (auth !== null) {
38
38
  headers['authorization'] = `${auth.userId}:${auth.tempPassword}`;
39
39
  }
40
- const u = url(path, queryString);
40
+ const u = url(version, path, queryString);
41
41
  const resp = await fetch(u, {
42
42
  method,
43
43
  headers,
@@ -7,15 +7,15 @@ export async function apiSignup(name, email, password) {
7
7
  email,
8
8
  password
9
9
  };
10
- return apiCall('post', 'signup', null, null, req, API_AUTH_RESPONSE_SCHEMA_V0);
10
+ return apiCall('v0', 'post', 'signup', null, null, req, API_AUTH_RESPONSE_SCHEMA_V0);
11
11
  }
12
12
  export async function apiSignin(name, password) {
13
13
  const req = {
14
14
  name,
15
15
  password
16
16
  };
17
- return apiCall('post', 'signin', null, null, req, API_AUTH_RESPONSE_SCHEMA_V0);
17
+ return apiCall('v0', 'post', 'signin', null, null, req, API_AUTH_RESPONSE_SCHEMA_V0);
18
18
  }
19
19
  export async function apiLogout(auth) {
20
- await apiCall('post', 'logout', auth, null, null, z.undefined());
20
+ await apiCall('v0', 'post', 'logout', auth, null, null, z.undefined());
21
21
  }
@@ -0,0 +1,6 @@
1
+ export declare const PRODUCTION: boolean;
2
+ export interface FrontConfig {
3
+ callLocalhost: boolean;
4
+ }
5
+ export declare function initFrontConfig(cfg: FrontConfig): void;
6
+ export declare function getFrontConfig(): FrontConfig;
@@ -0,0 +1,16 @@
1
+ export const PRODUCTION = process.env.NODE_ENV === 'production';
2
+ let frontConfig = null;
3
+ export function initFrontConfig(cfg) {
4
+ if (frontConfig !== null) {
5
+ throw Error('frontConfig already initialized!');
6
+ }
7
+ frontConfig = cfg;
8
+ }
9
+ export function getFrontConfig() {
10
+ if (frontConfig === null) {
11
+ frontConfig = {
12
+ callLocalhost: !PRODUCTION
13
+ };
14
+ }
15
+ return frontConfig;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rlz-engine",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Deps and tools for my style of development",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -32,6 +32,7 @@
32
32
  "typescript-eslint": "^8.16.0"
33
33
  },
34
34
  "dependencies": {
35
+ "@fontsource/roboto": "^5.0.12",
35
36
  "@emotion/react": "^11.14.0",
36
37
  "@emotion/styled": "^11.14.0",
37
38
  "@fastify/compress": "^8.0.1",