@jsb188/app 1.0.3 → 1.1.1
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 +2 -2
- package/constants/emoji.ts +16 -16
- package/constants/journal.ts +74 -0
- package/i18n/app.ts +2 -0
- package/i18n/auth.ts +12 -6
- package/i18n/datetime.ts +0 -1
- package/i18n/error.ts +11 -6
- package/i18n/form.ts +1 -0
- package/i18n/index.ts +0 -1
- package/i18n/user.ts +6 -3
- package/main.ts +36 -4
- package/package.json +10 -5
- package/platform.ts +125 -0
- package/types/ai.d.ts +30 -0
- package/types/app.d.ts +2 -0
- package/types/auth.d.ts +63 -0
- package/types/journal.d.ts +24 -0
- package/types/organization.d.ts +38 -0
- package/types.d.ts +8 -0
- package/utils/api.ts +77 -0
- package/utils/datetime.ts +473 -289
- package/utils/journal.ts +17 -0
- package/utils/logic.ts +81 -78
- package/utils/number.ts +92 -68
- package/utils/object.ts +277 -219
- package/utils/string.ts +219 -107
- package/utils/timeZone.ts +2369 -0
- package/types/datetime.d.ts +0 -10
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FIELD_LOG_ACTIVITY_ENUMS, HARVEST_LOG_ACTIVITY_ENUMS, JOURNAL_TYPE_ENUMS } from '../constants/journal.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Journal entry object
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface JournalEntryObj {
|
|
8
|
+
id: string
|
|
9
|
+
accountId: string
|
|
10
|
+
type: JournalTypeEnum
|
|
11
|
+
notes: string
|
|
12
|
+
date: string // ISO date string
|
|
13
|
+
editAt: string // ISO date string
|
|
14
|
+
|
|
15
|
+
activity: JournalEntryActivityEnum
|
|
16
|
+
item: string
|
|
17
|
+
quantity: number
|
|
18
|
+
unit: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type JournalTypeEnum = typeof JOURNAL_TYPE_ENUMS[number];
|
|
22
|
+
export type FieldLogActivityEnum = typeof FIELD_LOG_ACTIVITY_ENUMS[number];
|
|
23
|
+
export type HarvestLogActivityEnum = typeof HARVEST_LOG_ACTIVITY_ENUMS[number];
|
|
24
|
+
export type JournalEntryActivityEnum = FieldLogActivityEnum | HarvestLogActivityEnum;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* ACL
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type OrganizationRoleEnum = 'MEMBER' | 'ADMIN' | 'MANAGER' | 'OWNER';
|
|
7
|
+
|
|
8
|
+
export interface OrganizationACL {
|
|
9
|
+
id: string;
|
|
10
|
+
manageBilling: boolean | null;
|
|
11
|
+
manageIntegrations: boolean | null;
|
|
12
|
+
manageMembers: boolean | null;
|
|
13
|
+
manageProducts: boolean | null;
|
|
14
|
+
manageSettings: boolean | null;
|
|
15
|
+
viewMembers: boolean | null;
|
|
16
|
+
role: OrganizationRoleEnum | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Organization object
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export interface OrganizationShortData {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
primary: boolean;
|
|
27
|
+
acl: OrganizationACL;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface OrganizationData {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
primary: boolean;
|
|
34
|
+
acl: OrganizationACL;
|
|
35
|
+
stripeCustomerId: string | null;
|
|
36
|
+
domains: string[] | null;
|
|
37
|
+
// members: OrganizationMemberData[] | null;
|
|
38
|
+
}
|
package/types.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
declare global {
|
|
3
|
+
interface Console {
|
|
4
|
+
dev: (...args: any[]) => void;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
/** Declaration file generated by dts-gen */
|
|
2
9
|
|
|
3
10
|
declare class NodePolyglot {
|
|
@@ -20,4 +27,5 @@ declare class NodePolyglot {
|
|
|
20
27
|
static transformPhrase(phrase: any, substitutions: any, locale: any): any;
|
|
21
28
|
|
|
22
29
|
}
|
|
30
|
+
|
|
23
31
|
export = NodePolyglot;
|
package/utils/api.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import i18n from '../i18n/';
|
|
1
2
|
import { getENVVariable } from '../main';
|
|
3
|
+
import type { ServerErrorObj } from '../types/app.d';
|
|
2
4
|
|
|
3
5
|
let AUTH_TOKEN: string | null = null;
|
|
4
6
|
|
|
@@ -20,3 +22,78 @@ export function setAuthToken(token: string | null) {
|
|
|
20
22
|
export function getAuthToken(): string | null {
|
|
21
23
|
return getENVVariable('IS_BROWSER') ? AUTH_TOKEN : null;
|
|
22
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper; check if i18n exists for this error
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function i18nErrCodeExists(errorCode: string): boolean {
|
|
31
|
+
return !!(i18n.has(`error.${errorCode}`) ||
|
|
32
|
+
i18n.has(`error.${errorCode}_other`));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Helper; normalize all errors from server
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export function normalizeServerError(error?: any): ServerErrorObj {
|
|
40
|
+
let statusCode = 500;
|
|
41
|
+
let errorCode;
|
|
42
|
+
let errorValue;
|
|
43
|
+
let iconName;
|
|
44
|
+
let message;
|
|
45
|
+
|
|
46
|
+
if (!error || error instanceof Error) {
|
|
47
|
+
if (error?.message === 'Failed to fetch') {
|
|
48
|
+
errorCode = 'network_error';
|
|
49
|
+
iconName = 'wifi-off';
|
|
50
|
+
message = i18n.t('error.network_error');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!errorCode) {
|
|
55
|
+
if (error?.errors?.length) {
|
|
56
|
+
const loggedError = error.errors.find((gErr: ServerErrorObj) =>
|
|
57
|
+
gErr.errorCode &&
|
|
58
|
+
i18nErrCodeExists(gErr.errorCode)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (loggedError) {
|
|
62
|
+
statusCode = loggedError.statusCode;
|
|
63
|
+
errorCode = loggedError.errorCode;
|
|
64
|
+
errorValue = loggedError.variableWord;
|
|
65
|
+
} else {
|
|
66
|
+
statusCode = error.errors[0].statusCode;
|
|
67
|
+
errorCode = error.errors[0].errorCode;
|
|
68
|
+
errorValue = error.errors[0].variableWord;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!message) {
|
|
74
|
+
if (i18nErrCodeExists(errorCode)) {
|
|
75
|
+
message = i18n.t(`error.${errorCode}`, { value: errorValue });
|
|
76
|
+
} else {
|
|
77
|
+
message = i18n.t('error.unknown_error');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
getENVVariable('NODE_ENV') === 'development' &&
|
|
83
|
+
message === i18n.t('error.unknown_error')
|
|
84
|
+
) {
|
|
85
|
+
// Log for development so I can see what went wrong
|
|
86
|
+
console.warn(error);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const title = i18n.has(`error.${errorCode}_title`) ? i18n.t(`error.${errorCode}_title`) : i18n.t('error.error');
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
statusCode,
|
|
93
|
+
errorCode,
|
|
94
|
+
errorValue,
|
|
95
|
+
iconName,
|
|
96
|
+
title,
|
|
97
|
+
message,
|
|
98
|
+
};
|
|
99
|
+
}
|