@jsb188/app 1.0.0

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/main.ts ADDED
@@ -0,0 +1,21 @@
1
+ import i18n from './i18n/';
2
+ import app from './i18n/app';
3
+ import auth from './i18n/auth';
4
+ import billing from './i18n/billing';
5
+ import datetime from './i18n/datetime';
6
+ import error from './i18n/error';
7
+ import form from './i18n/form';
8
+ import user from './i18n/user';
9
+
10
+ export function configI18n(texts: Record<string, any>) {
11
+ i18n.extend({
12
+ app: app.en,
13
+ auth: auth.en,
14
+ billing: billing.en,
15
+ datetime: datetime.en,
16
+ error: error.en,
17
+ form: form.en,
18
+ user: user.en,
19
+ ...texts
20
+ });
21
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@jsb188/app",
3
+ "version": "1.0.0",
4
+ "description": "Contains all the basic requirements for all @jsb188 apps.",
5
+ "license": "ISC",
6
+ "author": "jsb188",
7
+ "type": "module",
8
+ "main": "main.ts",
9
+ "types": "types.d.ts",
10
+ "exports": {
11
+ ".": "./main.ts",
12
+ "./i18n": "./i18n/index.ts",
13
+ "./constants/billing": "./constants/billing.ts",
14
+ "./constants/emoji": "./constants/emoji.ts",
15
+ "./constants/user": "./constants/user.ts",
16
+ "./constants/ws": "./constants/ws.ts",
17
+ "./utils/billing": "./utils/billing.ts",
18
+ "./utils/datetime": "./utils/datetime.ts",
19
+ "./utils/emoji": "./utils/emoji.ts",
20
+ "./utils/logic": "./utils/logic.ts",
21
+ "./utils/number": "./utils/number.ts",
22
+ "./utils/object": "./utils/object.ts",
23
+ "./utils/string": "./utils/string.ts",
24
+ "./utils/url_client": "./utils/url_client.ts",
25
+ "./utils/user": "./utils/user.ts",
26
+ "./types/app": "./types/app.d.ts",
27
+ "./types/datetime": "./types/datetime.d.ts",
28
+ "./types/form": "./types/form.d.ts",
29
+ "./types/user": "./types/user.d.ts"
30
+ },
31
+ "dependencies": {
32
+ "node-polyglot": "^2.6.0"
33
+ },
34
+ "scripts": {
35
+ "test": "echo \"Error: no test specified\" && exit 1"
36
+ }
37
+ }
package/types/app.d.ts ADDED
@@ -0,0 +1,53 @@
1
+
2
+ // Modal; App settings
3
+
4
+ export interface EditIfaceModalProps {
5
+ containerClassName: string;
6
+ saveCounter: number;
7
+ saving: boolean;
8
+ hasChanges: boolean;
9
+ openModalPopUp: (opts: any) => void;
10
+ onChangeDiff: (diff: boolean) => void;
11
+ }
12
+
13
+ export interface EditUserModalProps extends EditIfaceModalProps {
14
+ user: any;
15
+ editUser: (obj: object) => void;
16
+ }
17
+
18
+ export interface EditUserPlusModalProps extends EditIfaceModalProps {
19
+ user: any;
20
+ editUserPlus: (obj: object) => void;
21
+ }
22
+
23
+ // App types
24
+
25
+ export type DarkOrLightEnum = 'light' | 'dark';
26
+
27
+ // Stripe types
28
+
29
+ export type PlatformProductGroupEnum = 'PERKS' | 'PLUS' | 'PRO' | 'COINS';
30
+
31
+ // Server types
32
+
33
+ export interface ServerErrorObj {
34
+ statusCode: number;
35
+ errorCode: string;
36
+ errorValue?: string;
37
+ iconName?: string;
38
+ title: string;
39
+ message: string;
40
+ }
41
+
42
+ export interface SimpleErrorType {
43
+ iconName?: string;
44
+ title?: string;
45
+ message: string;
46
+ }
47
+
48
+ export interface APIRequestOutput {
49
+ aborted?: boolean;
50
+ error: ServerErrorObj | null;
51
+ [apiName: string]: any; // Different data depends on API
52
+ }
53
+
@@ -0,0 +1,10 @@
1
+
2
+ // Date types
3
+
4
+ export type DatePeriodEnum = 'UPCOMING' | 'TOMORROW' | 'TODAY' | 'YESTERDAY' | 'THIS_WEEK' | 'THIS_MONTH' | 'LAST_WEEK' | 'LAST_MONTH' | 'OLDER';
5
+
6
+ export interface DatePeriodObj {
7
+ datePeriod: DatePeriodEnum;
8
+ date: Date;
9
+ item: any;
10
+ }
@@ -0,0 +1,53 @@
1
+
2
+ /**
3
+ * Types; form schema
4
+ */
5
+
6
+ interface SchemaItemSetter {
7
+ setter?: (currentData?: any, dataForSchema?: any) => any;
8
+ }
9
+
10
+ export interface FormItemSchemaObj {
11
+ __type: 'group' | 'input' | 'password' | 'textarea' | 'select' | string;
12
+ autoFocus?: boolean;
13
+ disabled?: boolean;
14
+ hidden?: boolean | ((dataForSchema: any) => boolean);
15
+ locked?: boolean | ((dataForSchema: any) => boolean);
16
+ labelClassName?: string;
17
+ listenToInput?: boolean;
18
+ value?: any;
19
+ item: Record<string, any> & SchemaItemSetter;
20
+ }
21
+
22
+ interface SchemaRule {
23
+ for: string;
24
+ rule: (value: any, formValues: any) => boolean;
25
+ error: any;
26
+ };
27
+
28
+ export interface FormSchemaObj {
29
+ listData: FormItemSchemaObj[];
30
+ rules?: SchemaRule[];
31
+ isButtonDisabled?: (formValues: any) => boolean;
32
+ }
33
+
34
+ /**
35
+ * Types; form items
36
+ */
37
+
38
+ interface FormGroupType {
39
+ id?: string;
40
+ name: string;
41
+ label?: string;
42
+ value: string | number | null;
43
+ items: Array<FormItemIfaceObj>;
44
+ }
45
+
46
+ export interface FormItemIfaceObj extends FormItemSchemaObj {
47
+ formValues: any;
48
+ setFormValues: (values: any) => void;
49
+ onInput?: (e: React.FormEvent, name: string) => void;
50
+ onKeyDown?: (e: React.KeyboardEvent, name: string) => void;
51
+ onSubmit?: (e: React.MouseEvent, name: string) => void;
52
+ onChange?: (e: React.ChangeEvent, name: string) => void;
53
+ }
@@ -0,0 +1,52 @@
1
+ import type { PersonaObj } from './chat';
2
+
3
+ type OnlineStatusEnum = null | 'AWAY' | 'BUSY' | 'APPEAR_OFFLINE';
4
+ type PlusStatusEnum = 'PRO' | 'PLUS' | 'PERKS' | 'NORMAL';
5
+
6
+ export interface AppUser {
7
+ id: string;
8
+ username: string;
9
+ displayName: string;
10
+
11
+ moderator: boolean;
12
+ activated: boolean;
13
+
14
+ plusStatus: PlusStatusEnum;
15
+ onlineStatus: OnlineStatusEnum;
16
+
17
+ plus: {
18
+ id: string;
19
+ expireAt: string;
20
+ cancelled: boolean;
21
+ type: string;
22
+ };
23
+
24
+ theme: {
25
+ id: string;
26
+ name: string;
27
+ backgroundPhotoUri: string;
28
+ };
29
+
30
+ profile: {
31
+ id: string;
32
+ description: string;
33
+ pronouns: string;
34
+ photoUri: string;
35
+ backgroundPhotoUri: string;
36
+ adult: boolean;
37
+ };
38
+
39
+ email: {
40
+ id: string;
41
+ address: string;
42
+ verified: boolean;
43
+ };
44
+
45
+ phone: {
46
+ id: string;
47
+ number: string;
48
+ verified: boolean;
49
+ };
50
+
51
+ personas: PersonaObj[];
52
+ }
package/types.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** Declaration file generated by dts-gen */
2
+
3
+ declare class NodePolyglot {
4
+ constructor(options?: any);
5
+
6
+ clear(): void;
7
+
8
+ extend(morePhrases: any, prefix?: any): void;
9
+
10
+ has(key: any): any;
11
+
12
+ locale(newLocale: any): any;
13
+
14
+ replace(newPhrases: any): void;
15
+
16
+ t(key: any, options?: any): any;
17
+
18
+ unset(morePhrases: any, prefix: any): void;
19
+
20
+ static transformPhrase(phrase: any, substitutions: any, locale: any): any;
21
+
22
+ }
23
+ export = NodePolyglot;
@@ -0,0 +1,134 @@
1
+ import { SUBSCRIPTION_CATALOG, SUBSCRIPTION_CATALOG_TEST } from '../constants/billing';
2
+
3
+ /**
4
+ * Types
5
+ */
6
+
7
+ type SubscriptionCatalogItem = {
8
+ group: string;
9
+ notReady: boolean;
10
+ priceLabel: string | null;
11
+ startingPrice: number;
12
+ currency: string;
13
+ recurringInterval: string;
14
+ recurringIntervalCount: number;
15
+ };
16
+
17
+ type SubscriptionPricingOption = {
18
+ id: string;
19
+ group: string;
20
+ notReady: boolean;
21
+ priceLabel: string;
22
+ price: number;
23
+ currency: string;
24
+ recurringInterval: string;
25
+ recurringIntervalCount: number;
26
+ };
27
+
28
+ /**
29
+ * Get development or production catalog
30
+ */
31
+
32
+ function getSubscriptionCatalog(isDev = false) {
33
+ return isDev ? SUBSCRIPTION_CATALOG_TEST : SUBSCRIPTION_CATALOG;
34
+ }
35
+
36
+ /**
37
+ * Get list of subscription catalogs
38
+ */
39
+
40
+ export function getPlatformSubscriptionCatalog(platformProducts?: any[], isDev?: boolean): SubscriptionCatalogItem[] {
41
+
42
+ return getSubscriptionCatalog(isDev).map((sub) => {
43
+ const [groupName, stripeProductId, stripePriceId] = sub;
44
+ const product = platformProducts?.find((pr: any) => pr.id === stripeProductId);
45
+ const startingPrice = product?.prices?.find((pc: any) => pc.id === stripePriceId);
46
+
47
+ if (!startingPrice) {
48
+ // Data is not ready; or the Stripe API Key used by the server is _not_ the live key
49
+ return {
50
+ group: groupName,
51
+ notReady: true,
52
+ priceLabel: null,
53
+ startingPrice: 0,
54
+ currency: 'USD',
55
+ recurringInterval: 'month',
56
+ recurringIntervalCount: 1
57
+ };
58
+ }
59
+
60
+ // Add locale here later
61
+ const locale = undefined;
62
+
63
+ const priceLabel = (
64
+ startingPrice.unitAmount / 100
65
+ ).toLocaleString(locale, {
66
+ style: 'currency',
67
+ currency: startingPrice.currency,
68
+ });
69
+
70
+ return {
71
+ group: groupName,
72
+ notReady: false,
73
+ priceLabel,
74
+ startingPrice: startingPrice.unitAmount,
75
+ currency: startingPrice.currency,
76
+ recurringInterval: startingPrice.recurringInterval,
77
+ recurringIntervalCount: startingPrice.recurringIntervalCount,
78
+ };
79
+ });
80
+ }
81
+
82
+
83
+ /**
84
+ * Get list of subscription options for each tier
85
+ */
86
+
87
+ export function getPlatformSubscriptionPricingOptions(
88
+ platformProducts?: any[],
89
+ subGroup?: 'PERKS' | 'PLUS' | 'PRO' | 'COINS',
90
+ isDev?: boolean
91
+ ): SubscriptionPricingOption[] {
92
+
93
+ const catalogItem = getSubscriptionCatalog(isDev).find((item: any) => item[0] === subGroup);
94
+ if (!catalogItem) {
95
+ console.warn('Unknown subscription group: ' + subGroup);
96
+ return [];
97
+ }
98
+
99
+ const [, stripeProductId] = catalogItem;
100
+ const product = platformProducts?.find((pr: any) => pr.id === stripeProductId);
101
+ if (!product) {
102
+ if (platformProducts) {
103
+ console.warn('Platform product not found for: ' + stripeProductId);
104
+ }
105
+ return [];
106
+ }
107
+
108
+ const pricingList = product.prices
109
+ .filter((pc: any) => pc.productGroup === subGroup)
110
+ .sort((pc: any) => pc.recurringInterval === 'year' ? -1 : 1);
111
+
112
+ return pricingList.map((pc: any) => {
113
+ // Add locale here later
114
+ const locale = undefined;
115
+
116
+ const priceLabel = (
117
+ pc.unitAmount / 100
118
+ ).toLocaleString(locale, {
119
+ style: 'currency',
120
+ currency: pc.currency,
121
+ });
122
+
123
+ return {
124
+ id: pc.id,
125
+ group: pc.productGroup,
126
+ notReady: false,
127
+ priceLabel,
128
+ price: pc.unitAmount,
129
+ currency: pc.currency,
130
+ recurringInterval: pc.recurringInterval,
131
+ recurringIntervalCount: pc.recurringIntervalCount,
132
+ };
133
+ });
134
+ }