spoko-design-system 0.2.60 → 0.2.62

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/index.ts CHANGED
@@ -53,10 +53,7 @@ export { default as getProductChecklist } from './src/utils/product/getProductCh
53
53
  export { default as getShorterDescription } from './src/utils/seo/getShorterDescription';
54
54
 
55
55
  // Utils: Text
56
- export { default as getData} from './src/utils/getData';
57
- // export { default as getData } from './src/utils/getData';
58
- // export { getData } from './src/utils/getData';
59
- export { getTranslation, text2paragraphs, countWords, firstSentence, removeSemicolon } from './src/utils/text';
56
+ export { getTranslation, text2paragraphs, countWords, firstSentence, removeSemicolon, apiInfo } from './src/utils/text';
60
57
  export { default as formatDate } from './src/utils/text/formatDate';
61
58
  export { default as formatLocaleNumber } from './src/utils/text/formatLocaleNumber';
62
59
  export { default as formatPad } from './src/utils/text/formatPad';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spoko-design-system",
3
- "version": "0.2.60",
3
+ "version": "0.2.62",
4
4
  "private": false,
5
5
  "main": "./index.ts",
6
6
  "module": "./index.ts",
@@ -1,14 +1,12 @@
1
- //
2
-
3
1
  const API_URL = import.meta.env.API_URL;
4
2
  const version = (Math.random() + 1).toString(36).substring(7); // random version to refresh cache from Cloudflare
5
3
 
6
- interface ApiResponse {
4
+ interface ApiResponse<T> {
7
5
  success: boolean;
8
- data: any; // Zamień `any` na właściwy typ, jeśli struktura danych jest znana
6
+ data: T;
9
7
  }
10
8
 
11
- export const getData = async (type: string): Promise<any | null> => {
9
+ export const getData = async <T>(type: string): Promise<T | null> => {
12
10
  const API = `${API_URL}${type}?version=${version}`;
13
11
 
14
12
  try {
@@ -19,7 +17,7 @@ export const getData = async (type: string): Promise<any | null> => {
19
17
  return null;
20
18
  }
21
19
 
22
- const jsonObject: ApiResponse = await response.json();
20
+ const jsonObject: ApiResponse<T> = await response.json();
23
21
 
24
22
  // Return data if API call is successful
25
23
  if (jsonObject.success) {
@@ -33,4 +31,5 @@ export const getData = async (type: string): Promise<any | null> => {
33
31
  return null;
34
32
  }
35
33
  };
34
+
36
35
  export default getData;
package/src/utils/text.ts CHANGED
@@ -1,6 +1,24 @@
1
-
2
1
  import i18next, { t } from "i18next";
3
2
 
3
+ export function getEnvVariable(key, defaultValue = null) {
4
+ // First we check import.meta.env (for ES6 environments)
5
+ if (typeof import.meta !== 'undefined' && typeof import.meta.env !== 'undefined') {
6
+ return import.meta.env[key] || defaultValue;
7
+ }
8
+
9
+ // Then check process.env (for Node.js environment)
10
+ if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
11
+ return process.env[key] || defaultValue;
12
+ }
13
+
14
+ // If no variable is found, the default value is returned
15
+ return defaultValue;
16
+ }
17
+ const API_URL = getEnvVariable('API_URL', 'http://default-api.com');
18
+
19
+
20
+
21
+
4
22
  // import { t } from "i18next";
5
23
 
6
24
  export const getTranslation = (translationKey: string) => {
@@ -25,4 +43,8 @@ export const firstSentence = (str: string) => {
25
43
 
26
44
  export const removeSemicolon = (name: string) => {
27
45
  return name.replace(';', '')
46
+ }
47
+
48
+ export const apiInfo = (name: string) => {
49
+ return API_URL
28
50
  }