@jsb188/app 1.1.10 → 1.1.12
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/package.json +57 -45
- package/src/constants/agent.ts +51 -41
- package/src/constants/app.ts +34 -13
- package/src/constants/emoji.ts +9144 -8936
- package/src/constants/other.ts +1 -5
- package/src/constants/user.ts +16 -25
- package/src/constants/wsActions.ts +27 -0
- package/src/i18n/account.ts +129 -107
- package/src/i18n/agent.ts +331 -73
- package/src/i18n/agentToolBusiness.ts +196 -0
- package/src/i18n/agentToolGrid.ts +137 -0
- package/src/i18n/agentToolWorkflow.ts +101 -0
- package/src/i18n/agent_note.ts +109 -0
- package/src/i18n/app.ts +107 -91
- package/src/i18n/auth.ts +117 -102
- package/src/i18n/billing.ts +5 -92
- package/src/i18n/c.ts +907 -0
- package/src/i18n/campaign.ts +919 -0
- package/src/i18n/country.ts +248 -248
- package/src/i18n/datetime.ts +32 -26
- package/src/i18n/editor.ts +58 -0
- package/src/i18n/error.ts +577 -192
- package/src/i18n/field_doc_editor.ts +21 -0
- package/src/i18n/field_doc_programs.ts +52 -0
- package/src/i18n/field_docs.ts +190 -0
- package/src/i18n/index.ts +42 -19
- package/src/i18n/log.ts +272 -238
- package/src/i18n/memory.ts +53 -0
- package/src/i18n/message.ts +3 -4
- package/src/i18n/note.ts +19 -0
- package/src/i18n/org.ts +164 -109
- package/src/i18n/schedule.ts +209 -0
- package/src/i18n/sheet.ts +333 -4
- package/src/i18n/sheet_formula.ts +165 -0
- package/src/i18n/workflow.ts +109 -23
- package/src/main.ts +68 -64
- package/src/platform.ts +90 -49
- package/src/types/ai.d.ts +52 -23
- package/src/types/app.d.ts +95 -44
- package/src/types/auth.d.ts +66 -40
- package/src/types/console.d.ts +3 -0
- package/src/types/other.d.ts +13 -6
- package/src/types.d.ts +12 -14
- package/src/utils/account.ts +64 -58
- package/src/utils/api.ts +326 -77
- package/src/utils/authSession.ts +24 -0
- package/src/utils/clientIP.ts +213 -0
- package/src/utils/color.ts +279 -0
- package/src/utils/cron.ts +49 -18
- package/src/utils/csv.ts +19 -0
- package/src/utils/datetime.ts +445 -117
- package/src/utils/deferredSave.ts +89 -0
- package/src/utils/email.ts +50 -0
- package/src/utils/emoji.ts +107 -84
- package/src/utils/expression.helpers.ts +470 -0
- package/src/utils/expression.test.ts +793 -0
- package/src/utils/expression.ts +2261 -0
- package/src/utils/interval.ts +80 -0
- package/src/utils/language.ts +9 -0
- package/src/utils/logic.ts +141 -121
- package/src/utils/managedSession.ts +34 -0
- package/src/utils/managedSessionBff.test.ts +60 -0
- package/src/utils/managedSessionBff.ts +117 -0
- package/src/utils/number.ts +85 -38
- package/src/utils/object.ts +227 -30
- package/src/utils/promise.ts +98 -0
- package/src/utils/queryReset.ts +266 -0
- package/src/utils/recurringTask.ts +60 -0
- package/src/utils/schema.ts +293 -0
- package/src/utils/string.test.ts +205 -208
- package/src/utils/string.ts +426 -463
- package/src/utils/timeZone.ts +309 -851
- package/src/utils/url_client.ts +145 -72
- package/tsconfig.json +10 -10
- package/src/constants/billing.ts +0 -146
- package/src/i18n/form.ts +0 -376
- package/src/i18n/product.ts +0 -76
- package/src/types/form.d.ts +0 -97
- package/src/utils/billing.ts +0 -134
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* English UI copy for the formula editor guide of the shared formula
|
|
2
|
+
* functions (descriptions and argument hints). Keys mirror the
|
|
3
|
+
* descriptionI18nKey values in @jsb188/mday sheetFormulaReference*.ts. */
|
|
4
|
+
export default {
|
|
5
|
+
en: {
|
|
6
|
+
function_name_guide_description:
|
|
7
|
+
'Choose a function to insert it with its opening parenthesis.',
|
|
8
|
+
function_name_guide_title: 'Formula functions',
|
|
9
|
+
and_description: 'Returns TRUE when every argument is TRUE.',
|
|
10
|
+
arg_criteria_range: 'Range tested against the criterion that follows it.',
|
|
11
|
+
arg_criterion:
|
|
12
|
+
'Value, or text such as ">5", "<>x", "ap*" or ">="&A1, that each cell must match.',
|
|
13
|
+
arg_date: 'Date to inspect.',
|
|
14
|
+
arg_end_date: 'Date to end at.',
|
|
15
|
+
arg_holidays: 'Optional dates to skip as non-working days.',
|
|
16
|
+
arg_info_value: 'Value, cell, or formula to test.',
|
|
17
|
+
arg_is_sorted:
|
|
18
|
+
'TRUE (default, as in Excel) for an approximate match on sorted keys; pass FALSE for an exact match.',
|
|
19
|
+
arg_join_value: 'Values or ranges to join; ranges are read row by row.',
|
|
20
|
+
arg_logical:
|
|
21
|
+
'Condition, TRUE/FALSE value, number, or range; additional arguments are allowed.',
|
|
22
|
+
arg_months: 'Months to move; negative moves back.',
|
|
23
|
+
arg_number: 'Number to calculate.',
|
|
24
|
+
arg_number_of_characters: 'How many characters to return; defaults to 1.',
|
|
25
|
+
arg_search_for: 'Text to look for.',
|
|
26
|
+
arg_search_key: 'Value to look for.',
|
|
27
|
+
arg_start_date: 'Date to start from.',
|
|
28
|
+
arg_starting_at: 'Position to start searching from; defaults to 1.',
|
|
29
|
+
arg_text: 'Text, or a number or TRUE/FALSE read as text.',
|
|
30
|
+
arg_text_to_search: 'Text to search in.',
|
|
31
|
+
arg_week_type: 'Numbering system; defaults to 1 (weeks start on Sunday).',
|
|
32
|
+
averageif_arg_average_range:
|
|
33
|
+
'Same-size range whose values are averaged; defaults to range.',
|
|
34
|
+
averageif_arg_range: 'Range tested by the criterion.',
|
|
35
|
+
averageif_description:
|
|
36
|
+
'Averages the values whose cells meet one criterion.',
|
|
37
|
+
averageifs_arg_average_range: 'Range whose values are averaged.',
|
|
38
|
+
averageifs_description:
|
|
39
|
+
'Averages the values whose rows meet every criterion.',
|
|
40
|
+
concat_description: 'Joins values and ranges into one text.',
|
|
41
|
+
concatenate_description: 'Joins values into one text; the same as CONCAT.',
|
|
42
|
+
countblank_arg_range: 'Range to inspect.',
|
|
43
|
+
countblank_description: 'Counts the empty cells in a range.',
|
|
44
|
+
countif_arg_range: 'Range to test.',
|
|
45
|
+
countif_description: 'Counts the cells in a range that meet one criterion.',
|
|
46
|
+
countifs_description: 'Counts the rows that meet every criterion.',
|
|
47
|
+
datedif_arg_unit:
|
|
48
|
+
'"Y" years, "M" months, "D" days, "YM" months after whole years, "YD" days after whole years, "MD" days after whole months.',
|
|
49
|
+
datedif_description:
|
|
50
|
+
'Returns the whole years, months or days between two dates.',
|
|
51
|
+
days_description: 'Returns the number of days between two dates.',
|
|
52
|
+
edate_description: 'Returns the same day a number of months away.',
|
|
53
|
+
eomonth_description:
|
|
54
|
+
'Returns the last day of the month a number of months away.',
|
|
55
|
+
find_description: 'Returns the position of text inside another text.',
|
|
56
|
+
hlookup_arg_index: '1-based row of the range to return.',
|
|
57
|
+
hlookup_arg_range: 'Range whose first row holds the keys.',
|
|
58
|
+
hlookup_description:
|
|
59
|
+
'Finds a key in the first row of a range and returns the value from another row of the same column.',
|
|
60
|
+
ifs_arg_condition: 'Condition checked in order.',
|
|
61
|
+
ifs_arg_value:
|
|
62
|
+
'Value returned, and evaluated, only when its condition is the first TRUE one.',
|
|
63
|
+
ifs_description: 'Returns the value paired with the first TRUE condition.',
|
|
64
|
+
index_arg_column:
|
|
65
|
+
'1-based column; required when the range has several rows and columns.',
|
|
66
|
+
index_arg_range: 'Range or UNIQUE result to read.',
|
|
67
|
+
index_arg_row:
|
|
68
|
+
'1-based row; for a one-row range, a single index is the column.',
|
|
69
|
+
index_description:
|
|
70
|
+
'Returns the value at a row and column position of a range.',
|
|
71
|
+
int_description: 'Rounds a number down to the nearest integer.',
|
|
72
|
+
isblank_description: 'Returns TRUE when a value is empty.',
|
|
73
|
+
iserror_description: 'Returns TRUE when a value is any formula error.',
|
|
74
|
+
isna_description:
|
|
75
|
+
'Returns TRUE when a value is the #N/A (not found) error.',
|
|
76
|
+
isnumber_description: 'Returns TRUE when a value is a number.',
|
|
77
|
+
istext_description: 'Returns TRUE when a value is nonempty text.',
|
|
78
|
+
left_description: 'Returns characters from the start of a text.',
|
|
79
|
+
len_description: 'Returns the number of characters in a text.',
|
|
80
|
+
lower_description: 'Converts a text to lowercase.',
|
|
81
|
+
match_arg_match_type:
|
|
82
|
+
'1 (default): largest value <= key in ascending data; 0: exact; -1: smallest value >= key in descending data.',
|
|
83
|
+
match_arg_range: 'One-row or one-column range to search.',
|
|
84
|
+
match_description:
|
|
85
|
+
'Returns the 1-based position of a key in a one-row or one-column range.',
|
|
86
|
+
mid_arg_extract_length: 'How many characters to return.',
|
|
87
|
+
mid_arg_starting_at: '1-based position of the first character.',
|
|
88
|
+
mid_description: 'Returns characters from the middle of a text.',
|
|
89
|
+
networkdays_description: 'Counts the working days between two dates.',
|
|
90
|
+
not_arg_logical: 'Condition or TRUE/FALSE value to reverse.',
|
|
91
|
+
not_description: 'Reverses a TRUE/FALSE value.',
|
|
92
|
+
or_description: 'Returns TRUE when any argument is TRUE.',
|
|
93
|
+
proper_description: 'Capitalizes the first letter of each word.',
|
|
94
|
+
replace_arg_length: 'How many characters to replace.',
|
|
95
|
+
replace_arg_new_text: 'Text inserted in their place.',
|
|
96
|
+
replace_arg_position: '1-based position where the replacement starts.',
|
|
97
|
+
replace_description: 'Replaces part of a text by position.',
|
|
98
|
+
right_description: 'Returns characters from the end of a text.',
|
|
99
|
+
search_description:
|
|
100
|
+
'Returns the position of text inside another text, ignoring case.',
|
|
101
|
+
sign_description:
|
|
102
|
+
'Returns -1, 0 or 1 for a negative, zero or positive number.',
|
|
103
|
+
sqrt_description: 'Returns the positive square root of a number.',
|
|
104
|
+
substitute_arg_occurrence_number:
|
|
105
|
+
'Replace only this occurrence; omit to replace all.',
|
|
106
|
+
substitute_arg_replace_with: 'Replacement text.',
|
|
107
|
+
substitute_arg_search_for: 'Text to replace (case-sensitive).',
|
|
108
|
+
substitute_arg_text_to_search: 'Text to change.',
|
|
109
|
+
substitute_description: 'Replaces text by content.',
|
|
110
|
+
sumif_arg_range: 'Range tested by the criterion.',
|
|
111
|
+
sumif_arg_sum_range:
|
|
112
|
+
'Same-size range whose values are added; defaults to range.',
|
|
113
|
+
sumif_description: 'Adds the values whose cells meet one criterion.',
|
|
114
|
+
sumifs_arg_sum_range: 'Range whose values are added.',
|
|
115
|
+
sumifs_description: 'Adds the values whose rows meet every criterion.',
|
|
116
|
+
sumproduct_arg_range:
|
|
117
|
+
'Same-size ranges whose values are multiplied position by position.',
|
|
118
|
+
sumproduct_description:
|
|
119
|
+
'Multiplies same-position values of ranges and adds the products.',
|
|
120
|
+
switch_arg_case: 'Value to compare with the expression.',
|
|
121
|
+
switch_arg_expression: 'Value compared with each case.',
|
|
122
|
+
switch_arg_value:
|
|
123
|
+
'Result for its case; a lone final argument is the default.',
|
|
124
|
+
switch_description:
|
|
125
|
+
'Returns the value of the first case equal to the expression, or the default.',
|
|
126
|
+
text_arg_format: 'Number format pattern such as "#,##0.00" or "mmm d".',
|
|
127
|
+
text_arg_value: 'Number or date to format.',
|
|
128
|
+
text_description: 'Formats a number or date as text with a format pattern.',
|
|
129
|
+
textjoin_arg_delimiter: 'Text placed between the values, such as ", ".',
|
|
130
|
+
textjoin_arg_ignore_empty: 'TRUE skips empty cells and empty text.',
|
|
131
|
+
textjoin_description: 'Joins values and ranges with a delimiter.',
|
|
132
|
+
trim_description: 'Removes extra spaces from a text.',
|
|
133
|
+
trunc_arg_places:
|
|
134
|
+
'Decimal places to keep; defaults to 0. Negative places zero out tens, hundreds, and so on.',
|
|
135
|
+
trunc_description: 'Cuts off digits of a number toward zero.',
|
|
136
|
+
unique_arg_by_column:
|
|
137
|
+
'TRUE compares columns instead of rows. Defaults to FALSE.',
|
|
138
|
+
unique_arg_exactly_once:
|
|
139
|
+
'TRUE keeps only rows that appear once. Defaults to FALSE.',
|
|
140
|
+
unique_arg_range: 'Range whose distinct rows are kept.',
|
|
141
|
+
unique_description:
|
|
142
|
+
'Returns the distinct rows of a range as a list for COUNTA, INDEX, SUM, or other functions that read ranges.',
|
|
143
|
+
upper_description: 'Converts a text to uppercase.',
|
|
144
|
+
value_arg_text: 'Text that reads as a number, such as "1,234.50".',
|
|
145
|
+
value_description: 'Converts text that looks like a number into a number.',
|
|
146
|
+
vlookup_arg_index: '1-based column of the range to return.',
|
|
147
|
+
vlookup_arg_range: 'Range whose first column holds the keys.',
|
|
148
|
+
vlookup_description:
|
|
149
|
+
'Finds a key in the first column of a range and returns the value from another column of the same row.',
|
|
150
|
+
weekday_description: 'Returns the day of the week as a number.',
|
|
151
|
+
weeknum_description: 'Returns the week number of a date within its year.',
|
|
152
|
+
workday_arg_num_days: 'Working days to move; negative moves back.',
|
|
153
|
+
workday_description: 'Returns the date a number of working days away.',
|
|
154
|
+
xlookup_arg_if_not_found:
|
|
155
|
+
'Evaluated and returned only when nothing matches.',
|
|
156
|
+
xlookup_arg_lookup_range: 'One-row or one-column range to search.',
|
|
157
|
+
xlookup_arg_match_mode:
|
|
158
|
+
'0 exact (default), -1 or next smaller, 1 or next larger, 2 wildcard.',
|
|
159
|
+
xlookup_arg_result_range: 'Same-size range to return from.',
|
|
160
|
+
xlookup_arg_search_mode: '1 first to last (default), -1 last to first.',
|
|
161
|
+
xlookup_description:
|
|
162
|
+
'Finds a key in one range and returns the value at the same position of another range.',
|
|
163
|
+
xor_description: 'Returns TRUE when an odd number of arguments are TRUE.',
|
|
164
|
+
},
|
|
165
|
+
};
|
package/src/i18n/workflow.ts
CHANGED
|
@@ -1,25 +1,111 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
en: {
|
|
3
|
+
active_only: 'Active only',
|
|
4
|
+
operation_workflows: 'Operation workflows',
|
|
5
|
+
workflow_missing: 'Workflow is missing',
|
|
6
|
+
workflow_missing_msg: "The workflow you're looking for could not be found.",
|
|
7
|
+
not_active_msg: 'Not active – no upcoming jobs',
|
|
8
|
+
active_msg: 'Active – waiting for %{logType} logs',
|
|
9
|
+
|
|
10
|
+
// Reminders
|
|
11
|
+
reminders: 'Scheduled',
|
|
12
|
+
reminder_missing: 'Reminder is missing',
|
|
13
|
+
reminder_missing_msg: "The reminder you're looking for could not be found.",
|
|
14
|
+
one_time: 'One-time',
|
|
15
|
+
in_progress_msg: 'In progress – waiting on a reply or follow-up',
|
|
16
|
+
completed_msg: 'Completed – no further follow-ups',
|
|
17
|
+
completed: 'Completed',
|
|
18
|
+
cancel_reminder: 'Cancel reminder',
|
|
19
|
+
delete_scheduled_task: 'Delete scheduled task',
|
|
20
|
+
delete_scheduled_task_failed: 'The scheduled task could not be deleted. Try again.',
|
|
21
|
+
cancel_reminder_confirm_msg: 'This reminder will not be delivered and any in-progress runs will be stopped. Cancel this reminder?',
|
|
22
|
+
canceled: 'Canceled',
|
|
23
|
+
run_history: 'Run history',
|
|
24
|
+
progress_report: 'Progress report',
|
|
25
|
+
no_runs_msg: 'This reminder has not run yet.',
|
|
26
|
+
sent_message: 'Sent message',
|
|
27
|
+
waiting_for_reply_msg: 'Waiting for a reply from %{name} until %{until}',
|
|
28
|
+
follow_up_at_msg: 'Next follow-up: %{followUpAt}',
|
|
29
|
+
created_by: 'Created by %{name}',
|
|
30
|
+
recipients: 'Recipients',
|
|
31
|
+
|
|
32
|
+
run_status: {
|
|
33
|
+
STARTED: 'In progress',
|
|
34
|
+
COMPLETED: 'Completed',
|
|
35
|
+
COMPLETED_PARTIAL: 'Partial',
|
|
36
|
+
ERRORED: 'Failed',
|
|
37
|
+
QUEUED: 'Queued',
|
|
38
|
+
CANCELED: 'Canceled',
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// Workflow runs page
|
|
42
|
+
workflow_runs: 'Workflow runs',
|
|
43
|
+
workflows_end:
|
|
44
|
+
'There is %{smart_count} workflow for this organization.||||' + 'There are %{smart_count} workflows for this organization.',
|
|
45
|
+
workflows_empty: "There aren't any workflows for this organization.",
|
|
46
|
+
workflow_runs_end:
|
|
47
|
+
'There is %{smart_count} workflow run for this organization.||||' +
|
|
48
|
+
'There are %{smart_count} workflow runs for this organization.',
|
|
49
|
+
workflow_runs_empty: "There aren't any workflow runs for this organization.",
|
|
50
|
+
runs_end: 'There is %{smart_count} run for this workflow.||||' + 'There are %{smart_count} runs for this workflow.',
|
|
51
|
+
runs_empty: "There aren't any runs for this workflow.",
|
|
52
|
+
view_runs: 'View workflow runs',
|
|
53
|
+
run_missing: 'Run is missing',
|
|
54
|
+
run_missing_msg: "The workflow run you're looking for could not be found.",
|
|
55
|
+
no_runs_found_msg: 'No workflow runs found.',
|
|
56
|
+
|
|
57
|
+
// Workflow kind filter
|
|
58
|
+
filter_by_kind: 'Filter by type',
|
|
59
|
+
all_kinds: 'Workflows + Scheduled',
|
|
60
|
+
workflows_only: 'Workflows only',
|
|
61
|
+
reminders_only: 'Scheduled only',
|
|
62
|
+
|
|
63
|
+
kind: {
|
|
64
|
+
WORKFLOW: 'Workflow',
|
|
65
|
+
REMINDER: 'Scheduled',
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// Program-managed workflows
|
|
69
|
+
program_managed: 'Managed by %{program}',
|
|
70
|
+
program_managed_msg:
|
|
71
|
+
'This workflow comes with the %{program} program and stays up to date with it. You can pause it or add your own instructions.',
|
|
72
|
+
program_workflow: 'Program workflow',
|
|
73
|
+
program_trigger_msg: 'When a log is added to this document',
|
|
74
|
+
program_active_msg: 'Active – waiting for logs added to this document',
|
|
75
|
+
program_unenrolled_msg:
|
|
76
|
+
"This workflow's program was removed from your organization. Restore the program in App Settings → Programs to resume it.",
|
|
77
|
+
program_restore_expired_msg:
|
|
78
|
+
"This workflow's program was removed from your organization more than 90 days ago and can no longer be restored, so this workflow can't be resumed. It will be deleted soon.",
|
|
79
|
+
program_removed_paused_msg:
|
|
80
|
+
'Paused when the %{program} program was removed. Restore the program in App Settings → Programs to resume this workflow.',
|
|
81
|
+
pause_workflow: 'Pause workflow',
|
|
82
|
+
resume_workflow: 'Resume workflow',
|
|
83
|
+
user_instructions: 'User instructions',
|
|
84
|
+
user_instructions_ph: 'Instructions for your organization (optional)',
|
|
85
|
+
user_instructions_empty: 'No user instructions yet.',
|
|
86
|
+
edit_user_instructions: 'Edit instructions',
|
|
87
|
+
user_instructions_msg: 'Your instructions are added after the program instructions each time this workflow runs.',
|
|
88
|
+
user_instructions_max: 'Use at most %{smart_count} character.||||Use at most %{smart_count} characters.',
|
|
89
|
+
catalog_instructions: 'Program instructions',
|
|
90
|
+
composed_instructions: 'What AI reads',
|
|
91
|
+
save_user_instructions: 'Save instructions',
|
|
92
|
+
user_instructions_saved: 'User instructions saved.',
|
|
93
|
+
|
|
94
|
+
// Below is old but some may be useful
|
|
95
|
+
|
|
96
|
+
// Actions related
|
|
97
|
+
not_started_msg: "Tasks haven't started",
|
|
98
|
+
waiting_for_task_msg: 'Waiting for the task to start...',
|
|
99
|
+
waiting_for_tasks_to_be_created: 'Waiting for tasks to be created...',
|
|
100
|
+
view_workflow: 'View workflow',
|
|
101
|
+
delete_workflow: 'Delete workflow',
|
|
102
|
+
yes_delete_workflow: 'Yes, delete workflow',
|
|
103
|
+
delete_workflow_failed: 'The workflow could not be deleted. Try again.',
|
|
104
|
+
workflows_empty_msg: 'Please email us at hello@marketday.ai to create workflows for your %{orgType}.',
|
|
105
|
+
|
|
106
|
+
for_operation: {
|
|
107
|
+
FARMERS_MARKET: 'Vendor',
|
|
108
|
+
GROWER_NETWORK: 'Grower',
|
|
109
|
+
},
|
|
110
|
+
},
|
|
25
111
|
};
|
package/src/main.ts
CHANGED
|
@@ -1,85 +1,89 @@
|
|
|
1
|
+
/// <reference path="./types/console.d.ts" />
|
|
2
|
+
|
|
1
3
|
import i18n, { i18nTranslations } from './i18n/index.ts';
|
|
2
4
|
|
|
3
5
|
// Get the correct type for ENV
|
|
4
|
-
|
|
6
|
+
const ENV = new Map<string, string | boolean | number>();
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Extend i18n with app specific texts
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
export function configI18n(texts?: Record<string, any>) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
13
|
+
// Locale support for later
|
|
14
|
+
const locale = 'en';
|
|
15
|
+
|
|
16
|
+
const extendedObj: Record<string, any> = {};
|
|
17
|
+
|
|
18
|
+
for (const key in i18nTranslations) {
|
|
19
|
+
extendedObj[key] = i18nTranslations[key][locale];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (texts) {
|
|
23
|
+
for (const key in texts) {
|
|
24
|
+
const obj = texts[key][locale];
|
|
25
|
+
|
|
26
|
+
if (extendedObj[key]) {
|
|
27
|
+
extendedObj[key] = {
|
|
28
|
+
...extendedObj[key],
|
|
29
|
+
...obj,
|
|
30
|
+
};
|
|
31
|
+
} else {
|
|
32
|
+
extendedObj[key] = obj;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
i18n.extend(extendedObj);
|
|
38
|
+
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Register environment variables so the package may use it
|
|
41
42
|
*/
|
|
42
43
|
|
|
43
|
-
export function registerENV(env: Record<string, string>) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
44
|
+
export function registerENV(env: Record<string, string | boolean | number>) {
|
|
45
|
+
// Do not use process.env; because this package is used in client + server
|
|
46
|
+
|
|
47
|
+
for (const key in env) {
|
|
48
|
+
if (
|
|
49
|
+
typeof key !== 'undefined' &&
|
|
50
|
+
Object.prototype.hasOwnProperty.call(env, key)
|
|
51
|
+
) {
|
|
52
|
+
ENV.set(key, env[key]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Shim some development commands
|
|
57
|
+
console.dev = (str: string, ...args: any[]) => {
|
|
58
|
+
if (ENV.get('NODE_ENV') === 'development') {
|
|
59
|
+
const [preset, ...otherArgs] = args;
|
|
60
|
+
|
|
61
|
+
let style;
|
|
62
|
+
switch (preset) {
|
|
63
|
+
case 'em':
|
|
64
|
+
style = 'background: #FFF380;';
|
|
65
|
+
break;
|
|
66
|
+
case 'warning':
|
|
67
|
+
style = 'background: #E64545; color: #FFF;';
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log(
|
|
73
|
+
`%c${str}`,
|
|
74
|
+
`${style || 'background: #F2F0DA;'} padding: 3px 5px;`,
|
|
75
|
+
...(style ? otherArgs : args),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
/**
|
|
80
82
|
* Get environment variables
|
|
81
83
|
*/
|
|
82
84
|
|
|
83
|
-
export function getENVVariable(
|
|
84
|
-
|
|
85
|
+
export function getENVVariable(
|
|
86
|
+
namespace: string,
|
|
87
|
+
): string | boolean | number | undefined {
|
|
88
|
+
return ENV.get(namespace);
|
|
85
89
|
}
|
package/src/platform.ts
CHANGED
|
@@ -1,64 +1,102 @@
|
|
|
1
|
+
import { STORAGE_KEYS } from './constants/app.ts';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
interface PlatformOptions {
|
|
4
|
+
defaultTheme: string;
|
|
5
|
+
clearAppCache?: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let platformOptions: PlatformOptions = { defaultTheme: '' };
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Configure app-owned theme and cache behavior without replacing browser defaults.
|
|
12
|
+
*/
|
|
13
|
+
export function configurePlatform(options: PlatformOptions): void {
|
|
14
|
+
platformOptions = { ...options };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Read the system dark-mode preference when the runtime supports it.
|
|
19
|
+
*/
|
|
20
|
+
export function isSystemDarkMode(): boolean {
|
|
21
|
+
return !!globalThis.matchMedia?.('(prefers-color-scheme: dark)').matches;
|
|
22
|
+
}
|
|
3
23
|
|
|
4
24
|
/**
|
|
5
25
|
* Get current platform
|
|
6
26
|
*/
|
|
7
27
|
|
|
8
28
|
export function getPlatform(): 'WEB' | 'MOBILE' | 'UNKNOWN' {
|
|
9
|
-
|
|
29
|
+
return 'WEB';
|
|
10
30
|
}
|
|
11
31
|
|
|
12
32
|
/**
|
|
13
33
|
* Fetch last used login token
|
|
14
34
|
*/
|
|
15
35
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
36
|
+
export function fetchAuthToken(cb: (token: string | null) => void): void {
|
|
37
|
+
if (typeof document !== 'undefined') {
|
|
38
|
+
const authToken: string =
|
|
39
|
+
localStorage.getItem(STORAGE_KEYS.AUTH_TOKEN) ?? '';
|
|
40
|
+
cb(authToken);
|
|
41
|
+
} else {
|
|
42
|
+
cb(null);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
19
45
|
|
|
20
46
|
/**
|
|
21
47
|
* Delete auth token
|
|
22
48
|
*/
|
|
23
49
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
50
|
+
export function deleteAuthToken(): void {
|
|
51
|
+
if (typeof document !== 'undefined') {
|
|
52
|
+
localStorage.removeItem(STORAGE_KEYS.AUTH_TOKEN);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
27
55
|
|
|
28
56
|
/**
|
|
29
57
|
* Save token after login
|
|
30
58
|
*/
|
|
31
59
|
|
|
32
|
-
export function saveAuthTokenToPlatform(
|
|
33
|
-
|
|
60
|
+
export function saveAuthTokenToPlatform(_token: string, cb: () => void) {
|
|
61
|
+
// In Web, there is nothing saved to local storage because we use SSR
|
|
62
|
+
cb();
|
|
34
63
|
}
|
|
35
64
|
|
|
36
65
|
/**
|
|
37
|
-
* Clear
|
|
38
|
-
* Change this based on what the app uses
|
|
66
|
+
* Clear app-owned caches using the callback configured at startup.
|
|
39
67
|
*/
|
|
40
68
|
|
|
41
69
|
export function clearAppCache() {
|
|
42
|
-
|
|
70
|
+
platformOptions.clearAppCache?.();
|
|
43
71
|
}
|
|
44
72
|
|
|
45
73
|
/**
|
|
46
74
|
* Fetch last used light mode setting
|
|
47
75
|
*/
|
|
48
76
|
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
): void
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
export function fetchLightModeSetting(
|
|
78
|
+
accountId: number | null,
|
|
79
|
+
cb: (lightMode: string) => void,
|
|
80
|
+
): void {
|
|
81
|
+
if (typeof document === 'undefined') {
|
|
82
|
+
cb('');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const key = `${STORAGE_KEYS.LIGHT_MODE}${accountId || 'guest'}`;
|
|
87
|
+
const lightModeSetting = localStorage.getItem(key) || '';
|
|
88
|
+
cb(lightModeSetting);
|
|
89
|
+
}
|
|
55
90
|
|
|
56
91
|
/**
|
|
57
92
|
* Get correct platform
|
|
58
93
|
*/
|
|
59
94
|
|
|
60
95
|
export function getOS() {
|
|
61
|
-
|
|
96
|
+
const isApple = /(Mac|iPhone|iPod|iPad)/i.test(
|
|
97
|
+
globalThis.navigator?.platform || '',
|
|
98
|
+
);
|
|
99
|
+
return isApple ? 'mac_os' : 'windows';
|
|
62
100
|
}
|
|
63
101
|
|
|
64
102
|
/**
|
|
@@ -66,7 +104,23 @@ export function getOS() {
|
|
|
66
104
|
*/
|
|
67
105
|
|
|
68
106
|
export function updateAppTheme(lightMode: string, theme: string) {
|
|
69
|
-
|
|
107
|
+
if (typeof document === 'undefined') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const lightModeVal =
|
|
112
|
+
lightMode === 'SYSTEM'
|
|
113
|
+
? isSystemDarkMode()
|
|
114
|
+
? 'dark'
|
|
115
|
+
: 'light'
|
|
116
|
+
: lightMode === 'DARK'
|
|
117
|
+
? 'dark'
|
|
118
|
+
: 'light';
|
|
119
|
+
|
|
120
|
+
const fullThemeName = `${theme || platformOptions.defaultTheme}_${lightModeVal}`;
|
|
121
|
+
|
|
122
|
+
document.body.setAttribute('data-mode', lightModeVal);
|
|
123
|
+
document.body.setAttribute('data-theme', fullThemeName);
|
|
70
124
|
}
|
|
71
125
|
|
|
72
126
|
/**
|
|
@@ -74,7 +128,13 @@ export function updateAppTheme(lightMode: string, theme: string) {
|
|
|
74
128
|
*/
|
|
75
129
|
|
|
76
130
|
export function getLocalLastVersion(accountId: string) {
|
|
77
|
-
|
|
131
|
+
if (typeof document === 'undefined') {
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const lastVersion: string =
|
|
136
|
+
localStorage.getItem(STORAGE_KEYS.LAST_VERSION + accountId) ?? '';
|
|
137
|
+
return lastVersion;
|
|
78
138
|
}
|
|
79
139
|
|
|
80
140
|
/**
|
|
@@ -82,7 +142,11 @@ export function getLocalLastVersion(accountId: string) {
|
|
|
82
142
|
*/
|
|
83
143
|
|
|
84
144
|
export function saveLocalLastVersion(accountId: string, version: string) {
|
|
85
|
-
|
|
145
|
+
if (typeof document === 'undefined') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
localStorage.setItem(STORAGE_KEYS.LAST_VERSION + accountId, version);
|
|
86
150
|
}
|
|
87
151
|
|
|
88
152
|
/**
|
|
@@ -90,36 +154,13 @@ export function saveLocalLastVersion(accountId: string, version: string) {
|
|
|
90
154
|
*/
|
|
91
155
|
|
|
92
156
|
export function getFileInputObject(fileInput: File) {
|
|
93
|
-
|
|
157
|
+
return fileInput;
|
|
94
158
|
}
|
|
95
159
|
|
|
96
160
|
/**
|
|
97
161
|
* Get buffer data from file
|
|
98
162
|
*/
|
|
99
163
|
|
|
100
|
-
export function getBufferDataFromFile(file:
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Check if system is dark mode
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export function isSystemDarkMode() {
|
|
109
|
-
return PLATFORM_HANDLERS?.isSystemDarkMode?.();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Register platform specific handlers
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
export function registerPlatformHandlers(handlers: Record<string, any>) {
|
|
117
|
-
for (const key in handlers) {
|
|
118
|
-
if (
|
|
119
|
-
Object.prototype.hasOwnProperty.call(handlers, key) &&
|
|
120
|
-
typeof handlers[key] === 'function'
|
|
121
|
-
) {
|
|
122
|
-
PLATFORM_HANDLERS[key] = handlers[key];
|
|
123
|
-
}
|
|
124
|
-
}
|
|
164
|
+
export function getBufferDataFromFile<T>(file: T) {
|
|
165
|
+
return file;
|
|
125
166
|
}
|