@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.
Files changed (79) hide show
  1. package/package.json +57 -45
  2. package/src/constants/agent.ts +51 -41
  3. package/src/constants/app.ts +34 -13
  4. package/src/constants/emoji.ts +9144 -8936
  5. package/src/constants/other.ts +1 -5
  6. package/src/constants/user.ts +16 -25
  7. package/src/constants/wsActions.ts +27 -0
  8. package/src/i18n/account.ts +129 -107
  9. package/src/i18n/agent.ts +331 -73
  10. package/src/i18n/agentToolBusiness.ts +196 -0
  11. package/src/i18n/agentToolGrid.ts +137 -0
  12. package/src/i18n/agentToolWorkflow.ts +101 -0
  13. package/src/i18n/agent_note.ts +109 -0
  14. package/src/i18n/app.ts +107 -91
  15. package/src/i18n/auth.ts +117 -102
  16. package/src/i18n/billing.ts +5 -92
  17. package/src/i18n/c.ts +907 -0
  18. package/src/i18n/campaign.ts +919 -0
  19. package/src/i18n/country.ts +248 -248
  20. package/src/i18n/datetime.ts +32 -26
  21. package/src/i18n/editor.ts +58 -0
  22. package/src/i18n/error.ts +577 -192
  23. package/src/i18n/field_doc_editor.ts +21 -0
  24. package/src/i18n/field_doc_programs.ts +52 -0
  25. package/src/i18n/field_docs.ts +190 -0
  26. package/src/i18n/index.ts +42 -19
  27. package/src/i18n/log.ts +272 -238
  28. package/src/i18n/memory.ts +53 -0
  29. package/src/i18n/message.ts +3 -4
  30. package/src/i18n/note.ts +19 -0
  31. package/src/i18n/org.ts +164 -109
  32. package/src/i18n/schedule.ts +209 -0
  33. package/src/i18n/sheet.ts +333 -4
  34. package/src/i18n/sheet_formula.ts +165 -0
  35. package/src/i18n/workflow.ts +109 -23
  36. package/src/main.ts +68 -64
  37. package/src/platform.ts +90 -49
  38. package/src/types/ai.d.ts +52 -23
  39. package/src/types/app.d.ts +95 -44
  40. package/src/types/auth.d.ts +66 -40
  41. package/src/types/console.d.ts +3 -0
  42. package/src/types/other.d.ts +13 -6
  43. package/src/types.d.ts +12 -14
  44. package/src/utils/account.ts +64 -58
  45. package/src/utils/api.ts +326 -77
  46. package/src/utils/authSession.ts +24 -0
  47. package/src/utils/clientIP.ts +213 -0
  48. package/src/utils/color.ts +279 -0
  49. package/src/utils/cron.ts +49 -18
  50. package/src/utils/csv.ts +19 -0
  51. package/src/utils/datetime.ts +445 -117
  52. package/src/utils/deferredSave.ts +89 -0
  53. package/src/utils/email.ts +50 -0
  54. package/src/utils/emoji.ts +107 -84
  55. package/src/utils/expression.helpers.ts +470 -0
  56. package/src/utils/expression.test.ts +793 -0
  57. package/src/utils/expression.ts +2261 -0
  58. package/src/utils/interval.ts +80 -0
  59. package/src/utils/language.ts +9 -0
  60. package/src/utils/logic.ts +141 -121
  61. package/src/utils/managedSession.ts +34 -0
  62. package/src/utils/managedSessionBff.test.ts +60 -0
  63. package/src/utils/managedSessionBff.ts +117 -0
  64. package/src/utils/number.ts +85 -38
  65. package/src/utils/object.ts +227 -30
  66. package/src/utils/promise.ts +98 -0
  67. package/src/utils/queryReset.ts +266 -0
  68. package/src/utils/recurringTask.ts +60 -0
  69. package/src/utils/schema.ts +293 -0
  70. package/src/utils/string.test.ts +205 -208
  71. package/src/utils/string.ts +426 -463
  72. package/src/utils/timeZone.ts +309 -851
  73. package/src/utils/url_client.ts +145 -72
  74. package/tsconfig.json +10 -10
  75. package/src/constants/billing.ts +0 -146
  76. package/src/i18n/form.ts +0 -376
  77. package/src/i18n/product.ts +0 -76
  78. package/src/types/form.d.ts +0 -97
  79. package/src/utils/billing.ts +0 -134
package/src/i18n/form.ts DELETED
@@ -1,376 +0,0 @@
1
- export default {
2
- en: {
3
- yes: 'Yes',
4
- no: 'No',
5
- no_nevermind: 'No, nevermind',
6
- ok: 'OK',
7
- or: 'or',
8
- n_a: 'N/A',
9
- unknown: 'Unknown',
10
- void: 'Void', // Use uppercase if needed
11
- void_status: 'Void status',
12
- voided: 'Voided',
13
- valid: 'Valid',
14
- location: 'Location',
15
- location_name: 'Location name',
16
- warning: 'Warning',
17
- cancel: 'Cancel',
18
- continue: 'Continue',
19
- continue_editing: 'Continue editing',
20
- class: 'Class',
21
- classification: 'Classification',
22
- overview: 'Overview',
23
- latest: 'Latest',
24
- latest_activity: 'Latest Activity',
25
- incomplete: 'Incomplete',
26
- dob: 'DOB',
27
- date_of_birth: 'Date of birth',
28
- deceased: 'Deceased',
29
- confirmation: 'Confirmation',
30
- primary: 'Primary',
31
- role: 'Role',
32
- id: 'ID',
33
- for: 'For',
34
- sort_by: 'Sort by',
35
- sort_list: 'Sort list',
36
- apply: 'Apply',
37
- apply_filters: 'Apply filters',
38
- missing: 'Missing',
39
- content_missing: 'Content missing',
40
- content_not_found_msg: 'The content you are looking for could not be found.',
41
- reports: 'Reports',
42
- dataTables: 'DataTables',
43
- form: 'Form',
44
- ranch: 'Ranch',
45
- section: 'Section',
46
- title: 'Title',
47
- hide: 'Hide',
48
- show: 'Show',
49
- open: 'Open',
50
- deleted: 'Deleted',
51
- delete: 'Delete',
52
- delete_file: 'Delete file',
53
- delete_file_msg: 'Are you sure you want to delete this file<br /><span class=\"em_text\">"%{fileName}"</span>?',
54
- delete_document_msg: 'Are you sure you want to delete this\n document and all its pages?',
55
- yes_delete_file: 'Yes, delete this file',
56
- balance: 'Balance',
57
- number: 'Number',
58
- livestock: 'Livestock',
59
- frequency: 'Frequency',
60
- expiration: 'Expiration',
61
- expiration_date: 'Expiration date',
62
- file: 'File',
63
- files: 'Files',
64
- flag: 'Flag',
65
- document: 'Document',
66
- documents: 'Documents',
67
- view_document: 'View document',
68
- edit_document: 'Edit document',
69
- delete_document: 'Delete document',
70
- document_type: 'Document type',
71
- untitled_document: 'Untitled document',
72
- yes_remove: 'Yes, please remove',
73
- yes_active: 'Yes, active',
74
- no_disabled: 'No, disabled',
75
- e_g_: 'e.g., %{example}',
76
- prev: 'Prev',
77
- next: 'Next',
78
- prev_doc: 'Previous document',
79
- next_doc: 'Next document',
80
- try_again: 'Try again',
81
- refresh_page: 'Refresh page',
82
- authenticate: 'Authenticate',
83
- enter_password: 'Enter password',
84
- please_verify: 'Please verify',
85
- check_email: 'Check your email',
86
- request_will_complete_once_verified_msg: 'Your request will be completed once the verification is complete.',
87
- your_request_is_completed_msg: 'Your request is completed.',
88
- page: 'Page',
89
- page_of: 'Page %{number} of %{total}',
90
- subtotal: 'Subtotal',
91
- total: 'Total',
92
- receipts: 'Receipts',
93
- market_receipts: 'Market receipts',
94
- search: 'Search',
95
- submitted: 'Submitted',
96
- no_results: 'No results',
97
- not_editable: 'Not editable',
98
- change: 'Change',
99
- loading_: 'Loading...',
100
- save: 'Save',
101
- save_contacts: 'Save contacts',
102
- press_enter_to_save: 'Press the enter key to save',
103
- saving_: 'Saving...',
104
- uploading_: 'Uploading...',
105
- undo_changes: 'Undo changes',
106
- save_changes: 'Save changes',
107
- unsaved_changes_msg: 'You have unsaved changes.',
108
- table_of_contents: 'Table of contents',
109
- copy_to_clipboard: 'Copy to clipboard',
110
- ai: 'AI',
111
- you: 'You',
112
- copied_: 'Copied!',
113
- copied_text_: 'Copied "%{text}"',
114
- go_back: 'Go back',
115
- read_more: 'Read more',
116
- scroll_for_more: 'Scroll for more',
117
- search_: 'Search: "%{query}"',
118
- close: 'Close',
119
- join: 'Join',
120
- change_img: 'Change image',
121
- upload_img: 'Upload image',
122
- upload_file: 'Upload file',
123
- upload_document: 'Upload document',
124
- keep_current_img: 'Keep current image',
125
- select_file: 'Select file',
126
- select_file_from_computer: 'Click here to pick a file from your computer.',
127
- tasks: 'Tasks',
128
- latest_update: 'Latest update',
129
- name: 'Name',
130
- item: 'Item',
131
- items: 'Items',
132
- tax: 'Tax',
133
- price: 'Price',
134
- unit: 'Unit',
135
- unit_price: 'Unit Price',
136
- price_ph: '1000.50',
137
- tax_ph: '78.20',
138
- purchase_summary: 'Purchase summary',
139
- order_summary: 'Order summary',
140
- amount: 'Amount',
141
- address: 'Address',
142
- addresses: 'Addresses',
143
- unknown_address: 'Unknown address',
144
- line1: 'Line 1',
145
- line1_ph: '1234 Main St.',
146
- line2_optional: 'Line 2 (optional)',
147
- line2_ph: 'Apartment, suite, unit, building, floor, etc.',
148
- city: 'City',
149
- city_ph: 'Some City',
150
- state: 'State',
151
- state_ph: 'CA',
152
- country: 'Country',
153
- country_ph: 'United States, Canada, etc.',
154
- postalCode: 'Zip code', // USA uses zip code
155
- postalCode_ph: '12345',
156
- guide: 'Guide',
157
- workflow: 'Workflow',
158
- workflows: 'Workflows',
159
- information: 'Information',
160
- instructions: 'Instructions',
161
- metadata: 'Metadata',
162
- summary: 'Summary',
163
- instructions_summary: 'Instructions summary',
164
- status: 'Status',
165
- active: 'Active',
166
- not_active: 'Not active',
167
- orders: 'Orders',
168
- 'order_#': 'Order #',
169
- order_details: 'Order details',
170
- record_details: 'Record details',
171
- images: 'Images',
172
- type: 'Type',
173
- pin_to_top: 'Pin to top',
174
- create_new: 'Create new',
175
- download_file: 'Download file',
176
- upload: 'Upload',
177
- uploaded_ct: 'Uploaded %{count}/%{max}',
178
- create: 'Create',
179
- invite: 'Invite',
180
- invited: 'Invited',
181
- invoice: 'Invoice',
182
- invoice_date: 'Invoice date',
183
- sales: 'Sales',
184
- sales_orders: 'Sales orders',
185
- actions: 'Actions',
186
- ai_workflows: 'AI workflows',
187
- add: 'Add',
188
- add_file: 'Add file',
189
- add_document: 'Add document',
190
- add_contact: 'Add contact',
191
- copy_id: 'Copy ID',
192
- remove: 'Remove',
193
- remove_line: 'Remove line',
194
- remove_member: 'Remove member',
195
- removed: 'Removed',
196
- references: 'References',
197
- history: 'History',
198
- manage: 'Manage',
199
- connect: 'Connect',
200
- connected: 'Connected',
201
- disconnect: 'Disconnect',
202
- disconnected: 'Disconnected',
203
- edit: 'Edit',
204
- edit_address: 'Edit address',
205
- edit_information: 'Edit information',
206
- edit_location: 'Edit location',
207
- edit_note: 'Edit note',
208
- edit_line: 'Edit line',
209
- enter: 'Enter',
210
- accept: 'Accept',
211
- decline: 'Decline',
212
- dismiss: 'Dismiss',
213
- description: 'Description',
214
- desc: 'Desc.',
215
- no_desc: 'No description.',
216
- no_additional_notes: 'No additional notes.',
217
- use_default: 'Use default',
218
- use_personal: 'Use personal',
219
- learn_more: 'Learn more',
220
- department: 'Department',
221
- email: 'Email',
222
- phone: 'Phone',
223
- phone_number: 'Phone number',
224
- verification_code: 'Verification code',
225
- partners: 'Partners',
226
- partner: 'Partner',
227
- contact_person: 'Contact person',
228
- farms: 'Farms',
229
- region: 'Region',
230
- commodities: 'Commodities',
231
- fsvp: 'FSVP',
232
- risk: 'Risk',
233
- operation: 'Operation',
234
- module: 'Module',
235
- condition: 'Condition',
236
- enabled: 'Enabled',
237
- grower: 'Grower',
238
- growers: 'Growers',
239
- domestic_growers: 'Domestic growers',
240
- foreign_growers: 'Foreign growers',
241
- customer: 'Customer',
242
- inbound_contacts: 'Inbound contacts',
243
- vendors: 'Vendors',
244
- 'vendors_#': 'Vendors #',
245
- vendor: 'Vendor',
246
- vendor_info: 'Vendor information',
247
- vendor_name: 'Vendor name',
248
- markets: 'Markets',
249
- market: 'Market',
250
- organization: 'Organization',
251
- coordinator: 'Co-ordinator',
252
- contact: 'Contact',
253
- contacts: 'Contacts',
254
- profile: 'Profile',
255
- compliance: 'Compliance',
256
- requirement: 'Requirement',
257
- person: 'Person',
258
- person_name: 'Person name',
259
- primary_contact: 'Primary contact',
260
- thank_you: 'Thank you',
261
- click_here: 'Click here',
262
- finished: 'Finished',
263
- success: 'Success',
264
- success_: 'Success!',
265
- help: 'Help',
266
- show_help: 'Show help',
267
- show_document_guidelines: 'Show document guidelines',
268
- hide_document_guidelines: 'Hide document guidelines',
269
- advanced: 'Advanced',
270
- start: 'Start',
271
- started: 'Started',
272
- end: 'End',
273
- time: 'Time',
274
- start_time: 'Start time',
275
- end_time: 'End time',
276
- time_with_zone: 'Time (%{timeZone})',
277
- time_zone_: 'Time zone: %{timeZone}',
278
- not_specified: 'Not specified',
279
- attendance: 'Attendance',
280
- attended_: 'Attended?',
281
- ct_attending: '%{count} / %{total} attending',
282
- ct_attended: '%{count} / %{total} attended',
283
- at_: 'at %{time}',
284
- day: 'Day',
285
- all_day: 'All day',
286
- date: 'Date',
287
- mm_dd_yyyy: 'MM/DD/YYYY',
288
- daily: 'Daily',
289
- weekly: 'Weekly',
290
- monthly: 'Monthly',
291
- schedule: 'Schedule',
292
- scheduled: 'Scheduled',
293
- added_by: 'Added by',
294
- created: 'Created',
295
- created_by: 'Created by',
296
- tasked_by: 'Tasked by',
297
- updated: 'Updated',
298
- next_due: 'Next due',
299
- next_run: 'Next run',
300
- recurring: 'Recurring',
301
- start_date: 'Start date',
302
- end_date: 'End date',
303
- event: 'Event',
304
- esc: 'ESC',
305
- esc_to_close: 'Press ESC to close',
306
- settings: 'Settings',
307
- note: 'Note',
308
- notes: 'Notes',
309
- memory: 'Memory',
310
- memories: 'Memories',
311
- ai_memories_desc: 'AI may periodically update or replace its own memories with new information.',
312
- answer: 'Answer',
313
- details: 'Details',
314
- source: 'Source',
315
- directory: 'Directory',
316
- temperature: 'Temperature',
317
- water: 'Water',
318
- quantity: 'Quantity',
319
- quantity_ph: '7.5',
320
- cropId: 'Crop',
321
- logged_edited_at: 'Logged %{logDate}. Updated %{editDate}.',
322
- saved_: 'Saved %{date}.',
323
- saved_source_: 'Saved %{date} via %{source}.',
324
- category: 'Category',
325
- activity: 'Activity',
326
- activity_ph: 'Type of activity',
327
- crop: 'Crop',
328
- crop_ph: 'Select crop',
329
- concentration: 'Concentration',
330
- concentration_ph: '0.5',
331
- concentration_unit: 'Concentration unit',
332
- concentration_unit_ph: 'mg/L',
333
- water_quantity: 'Quantity (water)',
334
- water_unit: 'Unit (water)',
335
- water_unit_ph: 'gallons, litres',
336
-
337
- // Day periods
338
- greet_MORNING: 'Good morning, %{name}.',
339
- greet_AFTERNOON: 'Good afternoon, %{name}.',
340
- greet_EVENING: 'Good evening, %{name}.',
341
- greet_NIGHT: 'Good evening, %{name}.',
342
-
343
- // Communication types
344
- comm_type_EMAIL: 'Email',
345
- comm_type_SMS: 'SMS',
346
-
347
- // Languages
348
- lang: {
349
- en: 'English',
350
- es: 'Spanish',
351
- },
352
-
353
- _are_required: '%{value} is required.||||%{value} are required.',
354
- category_: 'Category: %{value}',
355
- task_: 'Task: %{value}',
356
- activity_: 'Activity: %{value}',
357
- details_: 'Details: %{value}',
358
- location_: 'Location: %{value}',
359
- date_: 'Date: %{value}',
360
- scheduled_date_: 'Scheduled date: %{value}',
361
- effective_date_: 'Effective date: %{value}',
362
- ended_: 'Ended: %{value}',
363
- start_: 'Start: %{value}',
364
- end_: 'End: %{value}',
365
- worker_: 'Worker: %{value}',
366
- logged_by_: 'Logged by: %{value}',
367
- tasked_by_: 'Tasked by: %{value}',
368
- task: 'Task',
369
-
370
- log: 'Log',
371
- task_instructions: 'Task instructions',
372
- total_price: 'Total price',
373
- receipt_number: 'Receipt number',
374
- invoice_number: 'Invoice number',
375
- },
376
- };
@@ -1,76 +0,0 @@
1
- export default {
2
- en: {
3
- animal_id: 'Animal ID',
4
- dam_id: 'Dam ID',
5
- breed: 'Breed',
6
-
7
- upcoming_markets: 'Upcoming markets',
8
- markets_empty_msg: 'Talk to your AI to create farmers market events.',
9
- event_not_scheduled_msg: 'This event is not scheduled for this date.',
10
- attendance_list_empty_msg: 'Attendance list is empty for this date.',
11
- workflow: 'Workflow',
12
-
13
- // Report
14
- collected_total_ct_evidences: 'Collected a total of %{smart_count} evidence.||||Collected a total of %{smart_count} evidences.',
15
- reporting_year: 'Reporting year',
16
- not_answered_msg: 'This question hasn\'t been answered yet.',
17
- report_summary_not_done: 'AI is still generating the report summary.',
18
-
19
- // Content names
20
- view_document: 'View document',
21
- view_event: 'View event',
22
- view_market: 'View market',
23
-
24
- edit_document: 'Edit document',
25
- edit_event: 'Edit event',
26
- edit_market: 'Edit market',
27
-
28
- delete_document: 'Delete document',
29
- delete_event: 'Delete event',
30
- delete_market: 'Delete market',
31
-
32
- // Enums
33
- status: {
34
- ALIVE: 'Alive',
35
- SICK: 'Sick',
36
- SOLD: 'Sold',
37
- DECEASED: 'Deceased',
38
- PASS: 'Pass',
39
- WARNING: 'Warning',
40
- FAIL: 'Fail',
41
- },
42
-
43
- event_frequency_msg: {
44
- ONCE: 'This event does not repeat.',
45
- WEEKLY: 'This event repeats weekly.',
46
- },
47
-
48
- contentName_plural: {
49
- market: 'Markets',
50
- },
51
-
52
- feature_short: {
53
- NORMAL_LOGGING: 'Logs',
54
- SITE_INSPECTION: 'Site inspection',
55
- FOOD_SAFETY: 'Food safety',
56
- GLOBAL_GAP: 'GLOBALG.A.P.',
57
- LIVESTOCK_MANAGEMENT: 'Livestock',
58
- },
59
-
60
- feature_title: {
61
- NORMAL_LOGGING: 'Logs',
62
- SITE_INSPECTION: 'Site inspection',
63
- FOOD_SAFETY: 'Food safety',
64
- GLOBAL_GAP: 'GLOBALG.A.P.',
65
- LIVESTOCK_MANAGEMENT: 'Livestock management',
66
- },
67
-
68
- // Reports
69
-
70
- report: {
71
- GLOBAL_GAP: 'GLOBALG.A.P.',
72
- },
73
-
74
- back_to_globalgap: 'Back to GLOBALG.A.P.',
75
- },
76
- };
@@ -1,97 +0,0 @@
1
-
2
- /**
3
- * Types; form schema
4
- */
5
-
6
- export type FormValuesObj = {
7
- [key: string]: any;
8
- __errorFields?: string[];
9
- };
10
-
11
- export type FormValueSetter<TFormValues extends FormValuesObj = any> = (
12
- values: TFormValues | ((prev: TFormValues) => TFormValues)
13
- ) => void;
14
-
15
- export type FormItemType =
16
- | 'subtitle'
17
- | 'break'
18
- | 'group'
19
- | 'input'
20
- | 'section_title'
21
- | 'input_click'
22
- | 'input_w_button'
23
- | 'input_time_from_date'
24
- | 'password'
25
- | 'textarea'
26
- | 'none'
27
- | (string & {});
28
-
29
- interface SchemaItemAny<TCurrentData = any, TDataForSchema = any> {
30
- [key: string]: any;
31
- __typename?: string;
32
- setter?: (currentData?: TCurrentData, dataForSchema?: TDataForSchema) => any;
33
- }
34
-
35
- export interface FormItemSchemaObj<TCurrentData = any, TDataForSchema = any> {
36
- __type: FormItemType;
37
- autoFocus?: boolean;
38
- disabled?: boolean;
39
- hidden?: boolean | ((dataForSchema: TDataForSchema) => boolean);
40
- locked?: boolean | ((dataForSchema: TDataForSchema) => boolean);
41
- labelClassName?: string;
42
- listenToInput?: boolean;
43
- value?: any;
44
- item: SchemaItemAny<TCurrentData, TDataForSchema>;
45
- }
46
-
47
- interface SchemaRule<TFormValues extends FormValuesObj = any> {
48
- for: string;
49
- rule: (value: any, formValues: TFormValues) => boolean;
50
- error: any;
51
- };
52
-
53
- export interface FormSchemaObj<
54
- TFormValues extends FormValuesObj = any,
55
- TCurrentData = any,
56
- TDataForSchema = any,
57
- > {
58
- listData: FormItemSchemaObj<TCurrentData, TDataForSchema>[];
59
- rules?: SchemaRule<TFormValues>[];
60
- isButtonDisabled?: (formValues: TFormValues) => boolean;
61
- }
62
-
63
- /**
64
- * Types; form items
65
- */
66
-
67
- interface FormGroupType<
68
- TFormValues extends FormValuesObj = any,
69
- TCurrentData = any,
70
- TDataForSchema = any,
71
- > {
72
- id?: string;
73
- name: string;
74
- label?: string;
75
- value: string | number | null;
76
- items: Array<FormItemIfaceObj<TFormValues, TCurrentData, TDataForSchema>>;
77
- }
78
-
79
- export interface FormItemIfaceObj<
80
- TFormValues extends FormValuesObj = any,
81
- TCurrentData = any,
82
- TDataForSchema = any,
83
- > extends FormItemSchemaObj<TCurrentData, TDataForSchema> {
84
- name: string;
85
- preset?: string;
86
- className?: string;
87
- inputClassName?: string;
88
- focusStyle?: string;
89
- hidden?: boolean | ((dataForSchema: TDataForSchema) => boolean);
90
- locked?: boolean | ((dataForSchema: TDataForSchema) => boolean);
91
- formValues: TFormValues;
92
- setFormValues: FormValueSetter<TFormValues>;
93
- onInput?: (e: React.FormEvent, name: string) => void;
94
- onKeyDown?: (e: React.KeyboardEvent, name: string) => void;
95
- onSubmit?: (e: React.MouseEvent, name: string) => void;
96
- onChange?: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, name: string) => void;
97
- }
@@ -1,134 +0,0 @@
1
- import { SUBSCRIPTION_CATALOG, SUBSCRIPTION_CATALOG_TEST } from '../constants/billing.ts';
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
- }