@jsb188/app 1.0.1 → 1.0.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/constants/app.ts +27 -0
- package/i18n/app.ts +1 -1
- package/i18n/billing.ts +2 -3
- package/main.ts +19 -0
- package/package.json +2 -1
- package/types/app.d.ts +1 -8
- package/utils/api.ts +22 -0
- package/utils/datetime.ts +4 -2
- package/utils/logic.ts +25 -0
package/constants/app.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
|
|
2
|
+
// App constants
|
|
3
|
+
|
|
4
|
+
export const NOTIF_EXPIRE_DAYS = 30;
|
|
5
|
+
|
|
6
|
+
// DOM element names (ids)
|
|
7
|
+
|
|
8
|
+
export const DOM_IDS = {
|
|
9
|
+
sidebarInput: 'sidebar_input',
|
|
10
|
+
mainFocusTextarea: 'main_tx_',
|
|
11
|
+
};
|
|
12
|
+
|
|
2
13
|
// Local storage
|
|
3
14
|
|
|
4
15
|
export const STORAGE_KEYS = {
|
|
@@ -18,3 +29,19 @@ export const SUPPORT_EMAILS = {
|
|
|
18
29
|
big_planet: 'hi@kajiwoto.ai',
|
|
19
30
|
cosmic: 'hi@kajiwoto.ai',
|
|
20
31
|
} as Record<string, string>;
|
|
32
|
+
|
|
33
|
+
// Social media
|
|
34
|
+
|
|
35
|
+
export const SOCIAL_URLS = {
|
|
36
|
+
big_planet: {
|
|
37
|
+
x: 'https://x.com/bigplanetai',
|
|
38
|
+
x_username: 'BigPlanetAI',
|
|
39
|
+
},
|
|
40
|
+
cosmic: {
|
|
41
|
+
x: 'https://x.com/bigplanetai',
|
|
42
|
+
x_username: 'BigPlanetAI',
|
|
43
|
+
}
|
|
44
|
+
} as Record<string, {
|
|
45
|
+
x: string;
|
|
46
|
+
x_username: string;
|
|
47
|
+
}>;
|
package/i18n/app.ts
CHANGED
package/i18n/billing.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { SOCIAL_URLS } from "../constants/app";
|
|
2
2
|
|
|
3
3
|
// NOTE: Can't use /constants/ here because this file is loaded before all else
|
|
4
|
-
const XAccountUsername = 'BigPlanetAI';
|
|
5
4
|
const PerksSubDays = 14;
|
|
6
5
|
|
|
7
6
|
export default {
|
|
@@ -41,7 +40,7 @@ export default {
|
|
|
41
40
|
choose_payment_opt: 'Choose a payment option',
|
|
42
41
|
|
|
43
42
|
PERKS_desc_1: 'Say something nice on YouTube, TikTok, Instagram, X, personal blog, or anywhere you want.',
|
|
44
|
-
PERKS_desc_2: `Follow us on X and share your message mentioning us (@${
|
|
43
|
+
PERKS_desc_2: `Follow us on X and share your message mentioning us (@${SOCIAL_URLS.big_planet.x_username}) with your Big Planet ID or username.`,
|
|
45
44
|
PERKS_desc_3: `Wait until you receive a reply on X, Perks subscription (${PerksSubDays} days) will be added to your account.`,
|
|
46
45
|
|
|
47
46
|
PLUS_year: 'Plus (yearly)',
|
package/main.ts
CHANGED
|
@@ -7,6 +7,8 @@ import error from './i18n/error';
|
|
|
7
7
|
import form from './i18n/form';
|
|
8
8
|
import user from './i18n/user';
|
|
9
9
|
|
|
10
|
+
let ENV: Record<string, string> = {};
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Extend i18n with app specific texts
|
|
12
14
|
*/
|
|
@@ -41,3 +43,20 @@ export function configI18n(texts: Record<string, any>) {
|
|
|
41
43
|
|
|
42
44
|
i18n.extend(extendedObj);
|
|
43
45
|
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Register environment variables so the package may use it
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
export function registerENV(env: Record<string, string>) {
|
|
52
|
+
// Do not use process.env; because this package is used in client + server
|
|
53
|
+
ENV = { ...env };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get environment variables
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
export function getENVVariable(namespace: string): string | undefined {
|
|
61
|
+
return ENV[namespace];
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/app",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Contains all the basic requirements for all @jsb188 apps.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"./constants/emoji": "./constants/emoji.ts",
|
|
16
16
|
"./constants/user": "./constants/user.ts",
|
|
17
17
|
"./constants/ws": "./constants/ws.ts",
|
|
18
|
+
"./utils/api": "./utils/api.ts",
|
|
18
19
|
"./utils/billing": "./utils/billing.ts",
|
|
19
20
|
"./utils/datetime": "./utils/datetime.ts",
|
|
20
21
|
"./utils/emoji": "./utils/emoji.ts",
|
package/types/app.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type DarkOrLightEnum = 'light' | 'dark';
|
|
|
28
28
|
|
|
29
29
|
export type PlatformProductGroupEnum = 'PERKS' | 'PLUS' | 'PRO' | 'COINS';
|
|
30
30
|
|
|
31
|
-
// Server types
|
|
31
|
+
// Server/API related types
|
|
32
32
|
|
|
33
33
|
export interface ServerErrorObj {
|
|
34
34
|
statusCode: number;
|
|
@@ -44,10 +44,3 @@ export interface SimpleErrorType {
|
|
|
44
44
|
title?: string;
|
|
45
45
|
message: string;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
export interface APIRequestOutput {
|
|
49
|
-
aborted?: boolean;
|
|
50
|
-
error: ServerErrorObj | null;
|
|
51
|
-
[apiName: string]: any; // Different data depends on API
|
|
52
|
-
}
|
|
53
|
-
|
package/utils/api.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getENVVariable } from '../main';
|
|
2
|
+
|
|
3
|
+
let AUTH_TOKEN: string | null = null;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global; save auth token to memory
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export function setAuthToken(token: string | null) {
|
|
10
|
+
if (getENVVariable('IS_BROWSER')) {
|
|
11
|
+
// Only set auth token if it's browser; we don't want to share it across users
|
|
12
|
+
AUTH_TOKEN = token || null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Global; get auth token for all API middleware use
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export function getAuthToken(): string | null {
|
|
21
|
+
return getENVVariable('IS_BROWSER') ? AUTH_TOKEN : null;
|
|
22
|
+
}
|
package/utils/datetime.ts
CHANGED
|
@@ -153,10 +153,12 @@ export function getTimeAgo(
|
|
|
153
153
|
|
|
154
154
|
let d;
|
|
155
155
|
if (_d instanceof Date) {
|
|
156
|
-
d = _d
|
|
156
|
+
d = _d
|
|
157
|
+
} else if (!isNaN(Number(_d))) {
|
|
158
|
+
d = new Date(Number(_d))
|
|
157
159
|
} else {
|
|
158
160
|
// Make sure date is not null, before using this function
|
|
159
|
-
d = _d ? new Date(_d) : new Date(-1)
|
|
161
|
+
d = _d ? new Date(_d) : new Date(-1)
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
const ts = d.getTime();
|
package/utils/logic.ts
CHANGED
|
@@ -88,3 +88,28 @@ export function checkLastSetTime(time?: number, minsThreshold: number = 5) {
|
|
|
88
88
|
export function delay(ms: number) {
|
|
89
89
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Promise with timeout
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
// export function timeoutPromise(promiseFn: Function, ms = 10000) {
|
|
97
|
+
// return new Promise((resolve, reject) => {
|
|
98
|
+
// // Set up the timeout
|
|
99
|
+
// const timer = setTimeout(() => {
|
|
100
|
+
// reject(new Error(`Promise timed out after ${ms} ms`));
|
|
101
|
+
// }, ms);
|
|
102
|
+
|
|
103
|
+
// // Set up the real work
|
|
104
|
+
// promiseFn(
|
|
105
|
+
// (value: any) => {
|
|
106
|
+
// clearTimeout(timer);
|
|
107
|
+
// resolve(value);
|
|
108
|
+
// },
|
|
109
|
+
// (error: any) => {
|
|
110
|
+
// clearTimeout(timer);
|
|
111
|
+
// reject(error);
|
|
112
|
+
// }
|
|
113
|
+
// );
|
|
114
|
+
// });
|
|
115
|
+
// }
|