@egdesk/next-api-plugin 1.5.13 → 1.5.14

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.
@@ -508,9 +508,11 @@ export async function renameTable(
508
508
  // ==========================================
509
509
 
510
510
  /**
511
- * Upload a file to a user data table row.
512
- * Data must be base64-encoded. Files <10KB are stored as uncompressed blobs,
513
- * 10-100KB as gzip-compressed blobs, >100KB on the filesystem via BucketManager.
511
+ * Upload a file attachment for a table row.
512
+ * Files are NOT table columns — they attach via a virtual columnName (e.g. "file").
513
+ * Workflow: insertRows(...) → uploadFile(tableName, rowId, 'file', filename, base64).
514
+ * Data must be base64 (raw or data URL). Files <10KB store as uncompressed blobs,
515
+ * 10-100KB as gzip blobs, >100KB on disk via BucketManager.
514
516
  */
515
517
  export async function uploadFile(
516
518
  tableName: string,
@@ -520,7 +522,7 @@ export async function uploadFile(
520
522
  data: string,
521
523
  options: {
522
524
  mimeType?: string;
523
- forceStorageType?: 'blob' | 'file';
525
+ forceStorageType?: 'blob' | 'filesystem';
524
526
  compress?: boolean;
525
527
  } = {}
526
528
  ) {
@@ -2891,6 +2893,157 @@ export async function setGeminiApiKey(options: {
2891
2893
  export async function listGeminiApiKeys() {
2892
2894
  return listApiKeys({ provider: 'google' });
2893
2895
  }
2896
+
2897
+ // ==========================================
2898
+ // Phone / Google Messages (MCP)
2899
+ // ==========================================
2900
+
2901
+ /**
2902
+ * Call EGDesk Phone MCP tool (Messages Web devices, inbox, SMS queue, consent).
2903
+ *
2904
+ * - Server: \`POST {apiUrl}/phone/tools/call\`
2905
+ * - Client: \`POST /__phone_proxy\` (see proxy.ts / middleware)
2906
+ */
2907
+ export async function callPhoneTool(
2908
+ toolName: string,
2909
+ args: Record<string, any> = {}
2910
+ ): Promise<any> {
2911
+ const body = JSON.stringify({ tool: toolName, arguments: args });
2912
+ const isServer = typeof window === 'undefined';
2913
+
2914
+ let response: Response;
2915
+ if (isServer) {
2916
+ const apiUrl =
2917
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
2918
+ EGDESK_CONFIG.apiUrl;
2919
+ response = await fetch(\`\${apiUrl}/phone/tools/call\`, {
2920
+ method: 'POST',
2921
+ headers: buildServerEgdeskHeaders(),
2922
+ body
2923
+ });
2924
+ } else {
2925
+ response = await apiFetch('/__phone_proxy', {
2926
+ method: 'POST',
2927
+ headers: { 'Content-Type': 'application/json' },
2928
+ body
2929
+ });
2930
+ }
2931
+
2932
+ return parseEgdeskMcpToolResponse(response);
2933
+ }
2934
+
2935
+ export async function listPhoneDevices() {
2936
+ return callPhoneTool('phone_list_devices', {});
2937
+ }
2938
+
2939
+ export async function createPhoneDevice(options: { label: string; id?: string }) {
2940
+ return callPhoneTool('phone_create_device', options);
2941
+ }
2942
+
2943
+ export async function deletePhoneDevice(deviceId: string) {
2944
+ return callPhoneTool('phone_delete_device', { deviceId });
2945
+ }
2946
+
2947
+ export async function connectPhoneDevice(deviceId: string) {
2948
+ return callPhoneTool('phone_connect', { deviceId });
2949
+ }
2950
+
2951
+ export async function checkPhoneDevice(deviceId: string) {
2952
+ return callPhoneTool('phone_check', { deviceId });
2953
+ }
2954
+
2955
+ export async function listPhoneConversations(deviceId: string) {
2956
+ return callPhoneTool('phone_list_conversations', { deviceId });
2957
+ }
2958
+
2959
+ export async function syncPhoneConversations(deviceId: string) {
2960
+ return callPhoneTool('phone_sync_conversations', { deviceId });
2961
+ }
2962
+
2963
+ export async function listPhoneConversationMessages(options: {
2964
+ deviceId: string;
2965
+ convKey: string;
2966
+ }) {
2967
+ return callPhoneTool('phone_list_conversation_messages', options);
2968
+ }
2969
+
2970
+ export async function syncPhoneConversationThread(options: {
2971
+ deviceId: string;
2972
+ convKey: string;
2973
+ title: string;
2974
+ }) {
2975
+ return callPhoneTool('phone_sync_conversation_thread', options);
2976
+ }
2977
+
2978
+ export async function listPhoneContacts(deviceId: string) {
2979
+ return callPhoneTool('phone_list_contacts', { deviceId });
2980
+ }
2981
+
2982
+ export async function syncPhoneContacts(deviceId: string) {
2983
+ return callPhoneTool('phone_sync_contacts', { deviceId });
2984
+ }
2985
+
2986
+ export async function sendPhoneSms(options: {
2987
+ deviceId: string;
2988
+ phoneNumber: string;
2989
+ message: string;
2990
+ snapshotId?: string;
2991
+ scheduledAt?: number;
2992
+ isMarketing?: boolean;
2993
+ brandName?: string;
2994
+ }) {
2995
+ return callPhoneTool('phone_send', options);
2996
+ }
2997
+
2998
+ export async function listPhoneQueue(options: {
2999
+ deviceId?: string;
3000
+ snapshotId?: string;
3001
+ limit?: number;
3002
+ } = {}) {
3003
+ return callPhoneTool('phone_list_queue', options);
3004
+ }
3005
+
3006
+ export async function cancelPhoneSend(jobId: string) {
3007
+ return callPhoneTool('phone_cancel_send', { jobId });
3008
+ }
3009
+
3010
+ export async function retryPhoneSend(jobId: string) {
3011
+ return callPhoneTool('phone_retry_send', { jobId });
3012
+ }
3013
+
3014
+ export async function listPhoneDevicesForSnapshot(snapshotId: string) {
3015
+ return callPhoneTool('phone_list_for_snapshot', { snapshotId });
3016
+ }
3017
+
3018
+ export async function linkPhoneSnapshot(options: {
3019
+ snapshotId: string;
3020
+ deviceId: string;
3021
+ }) {
3022
+ return callPhoneTool('phone_link_snapshot', options);
3023
+ }
3024
+
3025
+ export async function unlinkPhoneSnapshot(options: {
3026
+ snapshotId: string;
3027
+ deviceId: string;
3028
+ }) {
3029
+ return callPhoneTool('phone_unlink_snapshot', options);
3030
+ }
3031
+
3032
+ export async function getPhoneConsentLink(snapshotId: string) {
3033
+ return callPhoneTool('phone_consent_link_get', { snapshotId });
3034
+ }
3035
+
3036
+ export async function createPhoneConsentLink(options: {
3037
+ snapshotId: string;
3038
+ brandName?: string;
3039
+ optOutPhone?: string;
3040
+ }) {
3041
+ return callPhoneTool('phone_consent_link_create', options);
3042
+ }
3043
+
3044
+ export async function syncPhoneConsentEvents(snapshotId: string) {
3045
+ return callPhoneTool('phone_consent_events_sync', { snapshotId });
3046
+ }
2894
3047
  `;
2895
3048
  fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
2896
3049
  console.log(`✅ Generated ${helperPath}`);
@@ -75,7 +75,7 @@ import type { NextRequest } from 'next/server';
75
75
  /**
76
76
  * EGDesk Database Proxy (Next.js 16+)
77
77
  *
78
- * Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, and __kakao_proxy requests
78
+ * Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, and __phone_proxy requests
79
79
  * and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
80
80
  *
81
81
  * Generated by @egdesk/next-api-plugin
@@ -384,6 +384,28 @@ export async function proxy(request: NextRequest) {
384
384
  }
385
385
  }
386
386
 
387
+ if (pathname.includes('__phone_proxy')) {
388
+ try {
389
+ const body = await request.text();
390
+ const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
391
+
392
+ const response = await fetch(\`\${apiUrl}/phone/tools/call\`, {
393
+ method: 'POST',
394
+ headers: buildEgdeskHeaders(),
395
+ body,
396
+ });
397
+
398
+ const result = await response.json();
399
+
400
+ return NextResponse.json(result, { status: response.status });
401
+ } catch (error: any) {
402
+ return NextResponse.json(
403
+ { error: 'Proxy error', message: error.message },
404
+ { status: 500 }
405
+ );
406
+ }
407
+ }
408
+
387
409
  if (pathname.includes('__egdesk_config_proxy')) {
388
410
  try {
389
411
  const body = await request.text();
@@ -436,7 +458,7 @@ export const config = {
436
458
  matcher: [
437
459
  /*
438
460
  * Match all paths except static assets
439
- * The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy
461
+ * The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy
440
462
  */
441
463
  '/:path*',
442
464
  ],
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * The minimum EGDesk app version this plugin version is compatible with.
9
9
  * The app checks this at setup time and warns on mismatch.
10
10
  */
11
- export declare const COMPATIBLE_APP_VERSION = "1.4.24";
11
+ export declare const COMPATIBLE_APP_VERSION = "1.4.28";
12
12
  export interface SetupOptions {
13
13
  egdeskUrl?: string;
14
14
  /** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
46
46
  * The minimum EGDesk app version this plugin version is compatible with.
47
47
  * The app checks this at setup time and warns on mismatch.
48
48
  */
49
- exports.COMPATIBLE_APP_VERSION = '1.4.24';
49
+ exports.COMPATIBLE_APP_VERSION = '1.4.28';
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
52
  const setup_userdata_1 = require("./setup-userdata");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.5.13",
3
+ "version": "1.5.14",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",