@rhq/rover 0.0.0-stage → 0.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.
@@ -0,0 +1,476 @@
1
+ /**
2
+ * @rhq/rover (Relay Rover)
3
+ * First-Class React Native & Expo implementation powered by Rust Core + UniFFI + JSI.
4
+ * Zero-dependency, native-speed in-memory execution for Hermes without Node.js built-ins.
5
+ */
6
+
7
+ let nativeEngine = null;
8
+
9
+ /**
10
+ * Discover and acquire the native Rover engine in React Native or Expo runtime.
11
+ * Order of discovery:
12
+ * 1. Direct JSI global host object (installed synchronously into Hermes runtime)
13
+ * 2. Expo Modules API (RelayRover module)
14
+ * 3. React Native NativeModules bridge
15
+ *
16
+ * @returns {object|null} Native engine binding
17
+ */
18
+ export function getNativeEngine() {
19
+ if (nativeEngine) {
20
+ return nativeEngine;
21
+ }
22
+
23
+ // 1. Direct JSI global installed by RoverHostObject (highest performance, zero bridge overhead)
24
+ if (typeof globalThis !== 'undefined' && globalThis.__RELAY_ROVER_NATIVE__) {
25
+ nativeEngine = globalThis.__RELAY_ROVER_NATIVE__;
26
+ return nativeEngine;
27
+ }
28
+
29
+ // 2. Expo Modules API: globalThis.expo.modules.RelayRover or dynamic requireNativeModule
30
+ if (typeof globalThis !== 'undefined' && globalThis.expo?.modules?.RelayRover) {
31
+ nativeEngine = globalThis.expo.modules.RelayRover;
32
+ return nativeEngine;
33
+ }
34
+
35
+ try {
36
+ // Dynamically resolve Expo Modules if running in Expo Go or custom dev client
37
+ const { requireNativeModule } = require('expo-modules-core');
38
+ if (typeof requireNativeModule === 'function') {
39
+ const expoModule = requireNativeModule('RelayRover');
40
+ if (expoModule) {
41
+ nativeEngine = expoModule;
42
+ return nativeEngine;
43
+ }
44
+ }
45
+ } catch (_) { }
46
+
47
+ // 3. React Native NativeModules (vanilla React Native bridge)
48
+ try {
49
+ const { NativeModules } = require('react-native');
50
+ const rnModule = NativeModules?.RelayRover || NativeModules?.Rover;
51
+ if (rnModule) {
52
+ if (typeof rnModule.installJsi === 'function') {
53
+ rnModule.installJsi();
54
+ if (typeof globalThis !== 'undefined' && globalThis.__RELAY_ROVER_NATIVE__) {
55
+ nativeEngine = globalThis.__RELAY_ROVER_NATIVE__;
56
+ return nativeEngine;
57
+ }
58
+ }
59
+ nativeEngine = rnModule;
60
+ return nativeEngine;
61
+ }
62
+ } catch (_) { }
63
+
64
+ return null;
65
+ }
66
+
67
+ /**
68
+ * Explicitly initialize or inject the native Rover engine.
69
+ * Maintains complete signature parity with RelayRover.init().
70
+ *
71
+ * @param {any} [customEngineOrBytes] Optional injected engine or binary buffer
72
+ * @returns {object} Native engine reference
73
+ */
74
+ export function init(customEngineOrBytes) {
75
+ if (customEngineOrBytes && typeof customEngineOrBytes === 'object' && !customEngineOrBytes.byteLength) {
76
+ nativeEngine = customEngineOrBytes;
77
+ return nativeEngine;
78
+ }
79
+
80
+ const engine = getNativeEngine();
81
+ if (engine) {
82
+ return engine;
83
+ }
84
+
85
+ return {
86
+ status: 'initialized',
87
+ platform: 'react-native-hermes',
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Convert HTML email content to clean, readable plain text.
93
+ * Strips script tags, style blocks, HTML tags, unescapes entities, and normalizes whitespace.
94
+ *
95
+ * @param {string} html Raw HTML email string
96
+ * @returns {string} Clean plain-text message
97
+ */
98
+ export function htmlToText(html) {
99
+ if (!html || typeof html !== 'string') return '';
100
+
101
+ const engine = getNativeEngine();
102
+ if (engine && typeof engine.htmlToText === 'function') {
103
+ try {
104
+ return engine.htmlToText(html);
105
+ } catch (_) { }
106
+ }
107
+
108
+ // Hermes-safe regex fallback
109
+ return html
110
+ .replace(/<style[^>]*>[\s\S]*?<\/style>/gi, ' ')
111
+ .replace(/<script[^>]*>[\s\S]*?<\/script>/gi, ' ')
112
+ .replace(/<head[^>]*>[\s\S]*?<\/head>/gi, ' ')
113
+ .replace(/<\/(p|div|tr|h[1-6]|li|blockquote)>/gi, '\n')
114
+ .replace(/<(br|hr)\s*\/?>/gi, '\n')
115
+ .replace(/<[^>]+>/g, ' ')
116
+ .replace(/&nbsp;/gi, ' ')
117
+ .replace(/&amp;/gi, '&')
118
+ .replace(/&lt;/gi, '<')
119
+ .replace(/&gt;/gi, '>')
120
+ .replace(/&quot;/gi, '"')
121
+ .replace(/&#39;/gi, "'")
122
+ .replace(/&apos;/gi, "'")
123
+ .replace(/[ \t]+/g, ' ')
124
+ .replace(/\r?\n\s*\r?\n+/g, '\n\n')
125
+ .trim();
126
+ }
127
+
128
+ /**
129
+ * Extract clean, readable normal message text from an email object or text.
130
+ * Handles massive HTML emails, raw multipart text bodies, and synthetic email formats.
131
+ *
132
+ * @param {object|string} email Email record or body string
133
+ * @returns {string} Clean message text
134
+ */
135
+ export function cleanEmailBody(email) {
136
+ if (!email) return '';
137
+ if (typeof email === 'string') {
138
+ if (/<[a-z][\s\S]*>/i.test(email)) {
139
+ return htmlToText(email);
140
+ }
141
+ return email.replace(/\r\n/g, '\n').trim();
142
+ }
143
+
144
+ const textCandidate = email.textBody || email.body || email.content || '';
145
+ if (typeof textCandidate === 'string' && textCandidate.trim().length > 0) {
146
+ if (/<[a-z][\s\S]*>/i.test(textCandidate)) {
147
+ return htmlToText(textCandidate);
148
+ }
149
+ return textCandidate.replace(/\r\n/g, '\n').trim();
150
+ }
151
+
152
+ if (email.htmlBody && typeof email.htmlBody === 'string') {
153
+ return htmlToText(email.htmlBody);
154
+ }
155
+
156
+ return '';
157
+ }
158
+
159
+ /**
160
+ * Normalize an email of any format (Relay Mail, RFC822-style, or synthetic)
161
+ * into a standardized structured object ready for processing and display.
162
+ *
163
+ * @param {object} email Raw email object
164
+ * @returns {object} Normalized email object
165
+ */
166
+ export function normalizeEmail(email) {
167
+ if (!email || typeof email !== 'object') {
168
+ throw new TypeError('Expected an email object');
169
+ }
170
+
171
+ let sender = 'unknown@example.com';
172
+ let senderName = '';
173
+
174
+ if (email.from) {
175
+ if (Array.isArray(email.from) && email.from.length > 0) {
176
+ sender = email.from[0].email || sender;
177
+ senderName = email.from[0].name || '';
178
+ } else if (typeof email.from === 'object') {
179
+ sender = email.from.email || sender;
180
+ senderName = email.from.name || '';
181
+ } else if (typeof email.from === 'string') {
182
+ const match = email.from.match(/(.*?)\s*<([^>]+)>/);
183
+ if (match) {
184
+ senderName = match[1].trim();
185
+ sender = match[2].trim();
186
+ } else {
187
+ sender = email.from.trim();
188
+ senderName = '';
189
+ }
190
+ }
191
+ } else {
192
+ if (email.sender) sender = email.sender;
193
+ if (email.sender_name) senderName = email.sender_name;
194
+ }
195
+
196
+ const subject = (email.subject || '').replace(/\r?\n/g, ' ').trim();
197
+ const body = cleanEmailBody(email);
198
+ const receivedAt = email.date || email.received_at || new Date().toISOString();
199
+ const id = email.id || `email_${Date.now()}`;
200
+
201
+ return {
202
+ id,
203
+ sender,
204
+ senderName,
205
+ subject,
206
+ body,
207
+ receivedAt,
208
+ isHtml: Boolean(!email.textBody && email.htmlBody),
209
+ };
210
+ }
211
+
212
+ /**
213
+ * Generate a concise snippet/summary from an email body for inbox listings.
214
+ *
215
+ * @param {object|string} email Email record or text
216
+ * @param {number} [maxLength=100] Maximum character length
217
+ * @returns {string} Truncated message summary
218
+ */
219
+ export function extractSummary(email, maxLength = 100) {
220
+ const text = typeof email === 'string' ? email : cleanEmailBody(email);
221
+ const clean = text.replace(/\s+/g, ' ').trim();
222
+ if (clean.length <= maxLength) return clean;
223
+ return clean.slice(0, maxLength - 3).trim() + '...';
224
+ }
225
+
226
+ /**
227
+ * Rover Intelligence Index
228
+ * Organizes emails into connected purchase, project, and activity timelines.
229
+ */
230
+ export const RoverIndex = {
231
+ buildTimelines(processedEmails) {
232
+ const timelines = {};
233
+ const unlinked = [];
234
+
235
+ for (const email of processedEmails) {
236
+ const key = email.timeline_key || email.timelineKey;
237
+ if (key) {
238
+ if (!timelines[key]) {
239
+ timelines[key] = {
240
+ timelineKey: key,
241
+ primaryCategory: email.primary_category,
242
+ events: [],
243
+ };
244
+ }
245
+ timelines[key].events.push(email);
246
+ } else {
247
+ unlinked.push(email);
248
+ }
249
+ }
250
+
251
+ return { timelines, unlinked };
252
+ },
253
+ };
254
+
255
+ export const RelayRover = {
256
+ /**
257
+ * Explicitly initialize the native engine (optional).
258
+ */
259
+ init,
260
+
261
+ /**
262
+ * Fast category detection for any arbitrary email subject and body.
263
+ * @param {string} subject
264
+ * @param {string} body
265
+ * @returns {string} Category name (e.g. 'Payment', 'OTP', 'Jobs', 'Travel', etc.)
266
+ */
267
+ classify(subject, body) {
268
+ const engine = getNativeEngine();
269
+ if (engine && typeof engine.classify === 'function') {
270
+ return engine.classify(subject || '', body || '');
271
+ }
272
+ return 'General';
273
+ },
274
+
275
+ /**
276
+ * Generate concise contextual preview line (< 100 characters).
277
+ * @param {string} subject
278
+ * @param {string} body
279
+ * @returns {string} Preview text
280
+ */
281
+ generatePreview(subject, body) {
282
+ const engine = getNativeEngine();
283
+ if (engine && typeof engine.generatePreview === 'function') {
284
+ return engine.generatePreview(subject || '', body || '');
285
+ }
286
+ return '';
287
+ },
288
+
289
+ /**
290
+ * Process email with full category detection, typed extraction, and preview generation.
291
+ * @param {string} subject
292
+ * @param {string} body
293
+ * @returns {object} ProcessedEmail result
294
+ */
295
+ processEmail(subject, body) {
296
+ const engine = getNativeEngine();
297
+ if (engine && typeof engine.processEmail === 'function') {
298
+ const res = engine.processEmail(subject || '', body || '');
299
+ return typeof res === 'string' ? JSON.parse(res) : res;
300
+ }
301
+ throw new Error('Relay Rover native engine not available in this environment.');
302
+ },
303
+
304
+ /**
305
+ * Process a single email from any email object (Relay Mail, HTML, or synthetic) or string.
306
+ * Automatically normalizes headers, cleans HTML if present, and attaches cleanBody.
307
+ *
308
+ * @param {object|string} input Email object or text
309
+ * @returns {object} ProcessedEmail result with cleanBody
310
+ */
311
+ process(input) {
312
+ if (typeof input === 'string') {
313
+ const clean = cleanEmailBody(input);
314
+ const res = this.processEmail('', clean);
315
+ return { ...res, cleanBody: clean };
316
+ }
317
+ if (input && typeof input === 'object') {
318
+ const normalized = normalizeEmail(input);
319
+ const engine = getNativeEngine();
320
+ let res;
321
+ if (engine && typeof engine.processEmailJson === 'function') {
322
+ const jsonStr = JSON.stringify(normalized);
323
+ const out = engine.processEmailJson(jsonStr);
324
+ res = typeof out === 'string' ? JSON.parse(out) : out;
325
+ } else {
326
+ res = this.processEmail(normalized.subject, normalized.body);
327
+ }
328
+ return {
329
+ ...res,
330
+ id: normalized.id,
331
+ cleanBody: normalized.body,
332
+ sender: normalized.sender,
333
+ senderName: normalized.senderName,
334
+ };
335
+ }
336
+ throw new TypeError('Expected email object or string');
337
+ },
338
+
339
+ /**
340
+ * Process multiple emails in a single in-memory native Rust engine call.
341
+ * Accepts an array of email objects (including raw Relay Mail with htmlBody) or a serialized JSON string.
342
+ *
343
+ * @param {Array<object>|string} emails Array of email records
344
+ * @returns {Array<object>} Array of ProcessedEmail results with cleanBody
345
+ */
346
+ processBatch(emails) {
347
+ const engine = getNativeEngine();
348
+ const emailsArray = typeof emails === 'string' ? JSON.parse(emails) : emails;
349
+
350
+ const normalizedArray = emailsArray.map(m => {
351
+ if (typeof m === 'object' && m !== null) {
352
+ return normalizeEmail(m);
353
+ }
354
+ return m;
355
+ });
356
+
357
+ let parsed;
358
+ if (engine && typeof engine.processBatchJson === 'function') {
359
+ const jsonString = JSON.stringify(normalizedArray);
360
+ const out = engine.processBatchJson(jsonString);
361
+ parsed = typeof out === 'string' ? JSON.parse(out) : out;
362
+ } else {
363
+ parsed = normalizedArray.map(m => this.process(m));
364
+ }
365
+
366
+ if (Array.isArray(parsed)) {
367
+ return parsed.map((item, idx) => ({
368
+ ...item,
369
+ cleanBody: normalizedArray[idx]?.body || '',
370
+ }));
371
+ }
372
+ return parsed;
373
+ },
374
+
375
+ /**
376
+ * Alias for processBatch to process an array of JSON email records.
377
+ * @param {Array<object>|string} emails
378
+ * @returns {Array<object>}
379
+ */
380
+ processEmailsJson(emails) {
381
+ return this.processBatch(emails);
382
+ },
383
+
384
+ /**
385
+ * Asynchronously process a single email off the UI thread.
386
+ * @param {object|string} input Email object or text
387
+ * @returns {Promise<object>} ProcessedEmail result
388
+ */
389
+ async processAsync(input) {
390
+ const engine = getNativeEngine();
391
+ if (typeof input === 'string') {
392
+ const clean = cleanEmailBody(input);
393
+ if (engine && typeof engine.processEmailAsync === 'function') {
394
+ const out = await engine.processEmailAsync(JSON.stringify({ subject: '', body: clean }));
395
+ const res = typeof out === 'string' ? JSON.parse(out) : out;
396
+ return { ...res, cleanBody: clean };
397
+ }
398
+ return this.process(input);
399
+ }
400
+ if (input && typeof input === 'object') {
401
+ const normalized = normalizeEmail(input);
402
+ if (engine && typeof engine.processEmailAsync === 'function') {
403
+ const jsonStr = JSON.stringify(normalized);
404
+ const out = await engine.processEmailAsync(jsonStr);
405
+ const res = typeof out === 'string' ? JSON.parse(out) : out;
406
+ return {
407
+ ...res,
408
+ id: normalized.id,
409
+ cleanBody: normalized.body,
410
+ sender: normalized.sender,
411
+ senderName: normalized.senderName,
412
+ };
413
+ }
414
+ return this.process(input);
415
+ }
416
+ throw new TypeError('Expected email object or string');
417
+ },
418
+
419
+ /**
420
+ * Asynchronously process a batch of emails off the UI thread without blocking Hermes.
421
+ * @param {Array<object>|string} emails Array of email records
422
+ * @returns {Promise<Array<object>>}
423
+ */
424
+ async processBatchAsync(emails) {
425
+ const engine = getNativeEngine();
426
+ const emailsArray = typeof emails === 'string' ? JSON.parse(emails) : emails;
427
+ const normalizedArray = emailsArray.map(m => {
428
+ if (typeof m === 'object' && m !== null) {
429
+ return normalizeEmail(m);
430
+ }
431
+ return m;
432
+ });
433
+
434
+ if (engine && typeof engine.processBatchAsync === 'function') {
435
+ const jsonString = JSON.stringify(normalizedArray);
436
+ const out = await engine.processBatchAsync(jsonString);
437
+ const parsed = typeof out === 'string' ? JSON.parse(out) : out;
438
+ if (Array.isArray(parsed)) {
439
+ return parsed.map((item, idx) => ({
440
+ ...item,
441
+ cleanBody: normalizedArray[idx]?.body || '',
442
+ }));
443
+ }
444
+ return parsed;
445
+ }
446
+
447
+ return this.processBatch(emails);
448
+ },
449
+
450
+ /**
451
+ * Convert HTML email content to clean, readable plain text.
452
+ */
453
+ htmlToText,
454
+
455
+ /**
456
+ * Extract clean, readable normal message text from an email object or text.
457
+ */
458
+ cleanEmailBody,
459
+
460
+ /**
461
+ * Normalize an email of any format into a standardized structured object.
462
+ */
463
+ normalizeEmail,
464
+
465
+ /**
466
+ * Generate a concise summary snippet from an email body.
467
+ */
468
+ extractSummary,
469
+
470
+ /**
471
+ * Rover Intelligence Index timeline grouping engine.
472
+ */
473
+ index: RoverIndex,
474
+ };
475
+
476
+ export default RelayRover;
@@ -0,0 +1 @@
1
+ #import "relay_roverFFI.h"
@@ -0,0 +1,117 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTBridge+Private.h>
3
+ #import "RoverJsi.h"
4
+
5
+ extern "C" {
6
+ char* rover_native_classify(const char* subject, const char* body);
7
+ char* rover_native_generate_preview(const char* subject, const char* body);
8
+ char* rover_native_process_email(const char* subject, const char* body);
9
+ char* rover_native_process_email_json(const char* email_json);
10
+ char* rover_native_process_batch_json(const char* batch_json);
11
+ char* rover_native_html_to_text(const char* html);
12
+ char* rover_native_clean_email_body(const char* text);
13
+ void rover_native_free_string(char* ptr);
14
+ }
15
+
16
+ @interface RelayRover : NSObject <RCTBridgeModule>
17
+ @property (nonatomic, weak) RCTBridge *bridge;
18
+ @end
19
+
20
+ @implementation RelayRover
21
+ @synthesize bridge = _bridge;
22
+
23
+ RCT_EXPORT_MODULE(RelayRover)
24
+
25
+ + (BOOL)requiresMainQueueSetup {
26
+ return YES;
27
+ }
28
+
29
+ - (void)setBridge:(RCTBridge *)bridge {
30
+ _bridge = bridge;
31
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
32
+ if (cxxBridge.runtime) {
33
+ relay_rover::RoverHostObject::install(*(facebook::jsi::Runtime *)cxxBridge.runtime);
34
+ }
35
+ }
36
+
37
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installJsi) {
38
+ RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
39
+ if (cxxBridge.runtime) {
40
+ relay_rover::RoverHostObject::install(*(facebook::jsi::Runtime *)cxxBridge.runtime);
41
+ return @YES;
42
+ }
43
+ return @NO;
44
+ }
45
+
46
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(classify:(NSString *)subject body:(NSString *)body) {
47
+ char *res = rover_native_classify([subject UTF8String], [body UTF8String]);
48
+ NSString *str = [NSString stringWithUTF8String:res ? res : "General"];
49
+ rover_native_free_string(res);
50
+ return str;
51
+ }
52
+
53
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(generatePreview:(NSString *)subject body:(NSString *)body) {
54
+ char *res = rover_native_generate_preview([subject UTF8String], [body UTF8String]);
55
+ NSString *str = [NSString stringWithUTF8String:res ? res : ""];
56
+ rover_native_free_string(res);
57
+ return str;
58
+ }
59
+
60
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(processEmail:(NSString *)subject body:(NSString *)body) {
61
+ char *res = rover_native_process_email([subject UTF8String], [body UTF8String]);
62
+ NSString *str = [NSString stringWithUTF8String:res ? res : "{}"];
63
+ rover_native_free_string(res);
64
+ return str;
65
+ }
66
+
67
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(processEmailJson:(NSString *)emailJson) {
68
+ char *res = rover_native_process_email_json([emailJson UTF8String]);
69
+ NSString *str = [NSString stringWithUTF8String:res ? res : "{}"];
70
+ rover_native_free_string(res);
71
+ return str;
72
+ }
73
+
74
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(processBatchJson:(NSString *)batchJson) {
75
+ char *res = rover_native_process_batch_json([batchJson UTF8String]);
76
+ NSString *str = [NSString stringWithUTF8String:res ? res : "[]"];
77
+ rover_native_free_string(res);
78
+ return str;
79
+ }
80
+
81
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(htmlToText:(NSString *)html) {
82
+ char *res = rover_native_html_to_text([html UTF8String]);
83
+ NSString *str = [NSString stringWithUTF8String:res ? res : ""];
84
+ rover_native_free_string(res);
85
+ return str;
86
+ }
87
+
88
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(cleanEmailBody:(NSString *)bodyOrHtml) {
89
+ char *res = rover_native_clean_email_body([bodyOrHtml UTF8String]);
90
+ NSString *str = [NSString stringWithUTF8String:res ? res : ""];
91
+ rover_native_free_string(res);
92
+ return str;
93
+ }
94
+
95
+ RCT_EXPORT_METHOD(processEmailAsync:(NSString *)emailJson
96
+ resolver:(RCTPromiseResolveBlock)resolve
97
+ rejecter:(RCTPromiseRejectBlock)reject) {
98
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
99
+ char *res = rover_native_process_email_json([emailJson UTF8String]);
100
+ NSString *str = [NSString stringWithUTF8String:res ? res : "{}"];
101
+ rover_native_free_string(res);
102
+ resolve(str);
103
+ });
104
+ }
105
+
106
+ RCT_EXPORT_METHOD(processBatchAsync:(NSString *)batchJson
107
+ resolver:(RCTPromiseResolveBlock)resolve
108
+ rejecter:(RCTPromiseRejectBlock)reject) {
109
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
110
+ char *res = rover_native_process_batch_json([batchJson UTF8String]);
111
+ NSString *str = [NSString stringWithUTF8String:res ? res : "[]"];
112
+ rover_native_free_string(res);
113
+ resolve(str);
114
+ });
115
+ }
116
+
117
+ @end
@@ -0,0 +1,54 @@
1
+ import ExpoModulesCore
2
+ import Foundation
3
+
4
+ /**
5
+ * Expo Module implementation for Relay Rover on iOS.
6
+ * Integrates Rust core through UniFFI Swift bindings and exposes high-performance JSI methods.
7
+ */
8
+ public class RoverModule: Module {
9
+ public func definition() -> ModuleDefinition {
10
+ Name("RelayRover")
11
+
12
+ Function("classify") { (subject: String, body: String) -> String in
13
+ return classify(subject: subject, body: body)
14
+ }
15
+
16
+ Function("generatePreview") { (subject: String, body: String) -> String in
17
+ return generatePreview(subject: subject, body: body)
18
+ }
19
+
20
+ Function("processEmail") { (subject: String, body: String) -> String in
21
+ return processEmail(subject: subject, body: body)
22
+ }
23
+
24
+ Function("processEmailJson") { (emailJson: String) -> String in
25
+ return processEmailJson(emailJson: emailJson)
26
+ }
27
+
28
+ Function("processBatchJson") { (batchJson: String) -> String in
29
+ return processBatchJson(batchJson: batchJson)
30
+ }
31
+
32
+ Function("htmlToText") { (html: String) -> String in
33
+ return htmlToText(html: html)
34
+ }
35
+
36
+ Function("cleanEmailBody") { (bodyOrHtml: String) -> String in
37
+ return cleanEmailBody(bodyOrHtml: bodyOrHtml)
38
+ }
39
+
40
+ AsyncFunction("processEmailAsync") { (emailJson: String, promise: Promise) in
41
+ DispatchQueue.global(qos: .userInitiated).async {
42
+ let result = processEmailJson(emailJson: emailJson)
43
+ promise.resolve(result)
44
+ }
45
+ }
46
+
47
+ AsyncFunction("processBatchAsync") { (batchJson: String, promise: Promise) in
48
+ DispatchQueue.global(qos: .userInitiated).async {
49
+ let result = processBatchJson(batchJson: batchJson)
50
+ promise.resolve(result)
51
+ }
52
+ }
53
+ }
54
+ }