@app-connect/core 1.5.8 → 1.6.4

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/README.md CHANGED
@@ -1,434 +1,434 @@
1
- # App Connect Core
2
-
3
- Core package for RingCentral App Connect project providing modular APIs for CRM integration, authentication, contact management, and call logging.
4
-
5
- ## Features
6
-
7
- - **Modular API Design**: Flexible Express app setup with customizable middleware and routes
8
- - **CRM Adapter Registry**: Centralized adapter management for multiple CRM platforms
9
- - **Authentication**: OAuth and API key authentication support
10
- - **Contact Management**: Find, create, and manage contacts across CRM platforms
11
- - **Call Logging**: Comprehensive call and message logging capabilities
12
- - **Analytics**: Built-in analytics tracking for all operations
13
- - **Database Integration**: Sequelize.js ORM with automatic table management
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @app-connect/core
19
- ```
20
-
21
- ## Quick Start
22
-
23
- ### Basic Usage
24
-
25
- ```javascript
26
- const { createCoreApp, adapterRegistry } = require('@app-connect/core');
27
- const myCRMAdapter = require('./adapters/myCRM');
28
- const manifest = require('./adapters/manifest.json');
29
- // Set the default manifest for the adapter registry. This ensures that all adapters
30
- // have access to the necessary configuration and metadata before registration.
31
- adapterRegistry.setDefaultManifest(manifest);
32
- // Register your CRM adapters. The default manifest must be set before registration
33
- // to ensure proper initialization of the adapter with the required settings.
34
- adapterRegistry.registerAdapter('myCRM', myCRMAdapter, manifest);
35
-
36
- // Create Express app with all core functionality
37
- const app = createCoreApp();
38
-
39
- // Add your custom routes
40
- app.get('/my-custom-route', (req, res) => {
41
- res.send('Hello from custom route!');
42
- });
43
-
44
- exports.getServer = () => app;
45
- ```
46
-
47
- ### Adapter Interface Registration
48
-
49
- The adapter registry supports dynamic interface registration, allowing you to extend adapter functionality without modifying the original adapter:
50
-
51
- ```javascript
52
- const { adapterRegistry } = require('@app-connect/core');
53
-
54
- // Register interface functions for a platform
55
- async function customCreateCallLog({ user, contactInfo, authHeader, callLog, note }) {
56
- // Custom implementation
57
- return {
58
- logId: 'custom-log-id',
59
- returnMessage: {
60
- message: 'Call logged with custom implementation',
61
- messageType: 'success',
62
- ttl: 2000
63
- }
64
- };
65
- }
66
-
67
- async function customFindContact({ user, authHeader, phoneNumber }) {
68
- // Custom implementation
69
- return [
70
- {
71
- id: 'custom-contact-id',
72
- name: 'Custom Contact',
73
- type: 'Contact',
74
- phone: phoneNumber,
75
- additionalInfo: null
76
- }
77
- ];
78
- }
79
-
80
- // Register interface functions
81
- adapterRegistry.registerAdapterInterface('myCRM', 'createCallLog', customCreateCallLog);
82
- adapterRegistry.registerAdapterInterface('myCRM', 'findContact', customFindContact);
83
-
84
- // Register the base adapter
85
- adapterRegistry.registerAdapter('myCRM', myCRMAdapter);
86
-
87
- // Get composed adapter with interfaces
88
- const composedAdapter = adapterRegistry.getAdapter('myCRM');
89
- ```
90
-
91
- **Interface-Only Adapters (No Base Adapter):**
92
-
93
- ```javascript
94
- // Register only interface functions, no base adapter
95
- adapterRegistry.registerAdapterInterface('interfaceOnlyCRM', 'createCallLog', customCreateCallLog);
96
- adapterRegistry.registerAdapterInterface('interfaceOnlyCRM', 'findContact', customFindContact);
97
-
98
- // Get interface-only adapter
99
- const interfaceOnlyAdapter = adapterRegistry.getAdapter('interfaceOnlyCRM');
100
- console.log('Interface-only methods:', Object.keys(interfaceOnlyAdapter));
101
- // Output: ['createCallLog', 'findContact']
102
-
103
- // Later, you can add a base adapter
104
- adapterRegistry.registerAdapter('interfaceOnlyCRM', myCRMAdapter);
105
- const fullAdapter = adapterRegistry.getAdapter('interfaceOnlyCRM');
106
- console.log('Full adapter methods:', Object.keys(fullAdapter));
107
- // Output: ['getAuthType', 'getUserInfo', 'updateCallLog', 'unAuthorize', 'createContact', 'createCallLog', 'findContact']
108
- ```
109
-
110
- ### Advanced Usage with Custom Middleware
111
-
112
- ```javascript
113
- const express = require('express');
114
- const {
115
- createCoreRouter,
116
- createCoreMiddleware,
117
- initializeCore,
118
- adapterRegistry
119
- } = require('@app-connect/core');
120
-
121
- const myCRMAdapter = require('./adapters/myCRM');
122
- const manifest = require('./adapters/manifest.json');
123
- // Set manifest
124
- adapterRegistry.setDefaultManifest(manifest);
125
- // Register adapters
126
- adapterRegistry.registerAdapter('myCRM', myCRMAdapter, manifest);
127
-
128
- // Initialize core services
129
- initializeCore();
130
-
131
- // Create your own Express app
132
- const app = express();
133
-
134
- // Add custom middleware first
135
- app.use(express.static('public'));
136
- app.use('/api/v2', customApiMiddleware);
137
-
138
- // Apply core middleware
139
- const coreMiddleware = createCoreMiddleware();
140
- coreMiddleware.forEach(middleware => app.use(middleware));
141
-
142
- // Add core routes
143
- const coreRouter = createCoreRouter();
144
- app.use('/', coreRouter);
145
-
146
- // Add custom routes
147
- app.get('/my-custom-route', (req, res) => {
148
- res.send('Hello from custom route!');
149
- });
150
- ```
151
-
152
- ## API Reference
153
-
154
- ### Core Functions
155
-
156
- #### `createCoreApp(options)`
157
- Creates a complete Express app with all core functionality.
158
-
159
- **Parameters:**
160
- - `options` (Object, optional): Configuration options
161
- - `skipDatabaseInit` (Boolean): Skip database initialization (default: false)
162
- - `skipAnalyticsInit` (Boolean): Skip analytics initialization (default: false)
163
-
164
- **Returns:** Express application instance
165
-
166
- #### `createCoreRouter()`
167
- Creates an Express router with all core routes.
168
-
169
- **Returns:** Express router instance
170
-
171
- #### `createCoreMiddleware()`
172
- Returns an array of core middleware functions.
173
-
174
- **Returns:** Array of middleware functions
175
-
176
- #### `initializeCore(options)`
177
- Initializes core services (database, analytics).
178
-
179
- **Parameters:**
180
- - `options` (Object, optional): Configuration options
181
- - `skipDatabaseInit` (Boolean): Skip database initialization (default: false)
182
- - `skipAnalyticsInit` (Boolean): Skip analytics initialization (default: false)
183
-
184
- ### Adapter Registry
185
-
186
- #### `adapterRegistry.setDefaultManifest(manifest)`
187
- Sets the default manifest for adapters.
188
-
189
- **Parameters:**
190
- - `manifest` (Object): Default manifest
191
-
192
- #### `adapterRegistry.registerAdapter(name, adapter, manifest)`
193
- Registers a CRM adapter.
194
-
195
- **Parameters:**
196
- - `name` (String): Adapter name
197
- - `adapter` (Object): Adapter implementation
198
- - `manifest` (Object, optional): Adapter manifest
199
-
200
- #### `adapterRegistry.registerAdapterInterface(platformName, interfaceName, interfaceFunction)`
201
- Registers an interface function for a specific platform that will be composed with the adapter at retrieval time.
202
-
203
- **Parameters:**
204
- - `platformName` (String): Platform identifier (e.g., 'pipedrive', 'salesforce')
205
- - `interfaceName` (String): Interface function name (e.g., 'createCallLog', 'findContact')
206
- - `interfaceFunction` (Function): The interface function to register
207
-
208
- **Example:**
209
- ```javascript
210
- async function customCreateCallLog({ user, contactInfo, authHeader, callLog, note }) {
211
- // Custom implementation
212
- return {
213
- logId: 'custom-log-id',
214
- returnMessage: {
215
- message: 'Call logged with custom implementation',
216
- messageType: 'success',
217
- ttl: 2000
218
- }
219
- };
220
- }
221
-
222
- adapterRegistry.registerAdapterInterface('myCRM', 'createCallLog', customCreateCallLog);
223
- ```
224
-
225
- #### `adapterRegistry.getAdapter(name)`
226
- Retrieves a registered adapter with composed interfaces.
227
-
228
- **Parameters:**
229
- - `name` (String): Adapter name
230
-
231
- **Returns:** Composed adapter object or interface-only object
232
-
233
- **Behavior:**
234
- - If adapter exists and interfaces exist: Returns composed adapter with both
235
- - If adapter exists but no interfaces: Returns original adapter
236
- - If no adapter but interfaces exist: Returns object with just interface functions
237
- - If no adapter and no interfaces: Throws error
238
-
239
- #### `adapterRegistry.getOriginalAdapter(name)`
240
- Retrieves the original adapter without any composed interface functions.
241
-
242
- **Parameters:**
243
- - `name` (String): Adapter name
244
-
245
- **Returns:** Original adapter object
246
-
247
- #### `adapterRegistry.getPlatformInterfaces(platformName)`
248
- Returns a Map of registered interface functions for a platform.
249
-
250
- **Parameters:**
251
- - `platformName` (String): Platform identifier
252
-
253
- **Returns:** Map of interface functions
254
-
255
- #### `adapterRegistry.hasPlatformInterface(platformName, interfaceName)`
256
- Checks if a specific interface function is registered for a platform.
257
-
258
- **Parameters:**
259
- - `platformName` (String): Platform identifier
260
- - `interfaceName` (String): Interface function name
261
-
262
- **Returns:** Boolean indicating if interface exists
263
-
264
- #### `adapterRegistry.unregisterAdapterInterface(platformName, interfaceName)`
265
- Unregisters an interface function for a platform.
266
-
267
- **Parameters:**
268
- - `platformName` (String): Platform identifier
269
- - `interfaceName` (String): Interface function name
270
-
271
- #### `adapterRegistry.getAdapterCapabilities(platformName)`
272
- Gets comprehensive information about an adapter including its capabilities and registered interfaces.
273
-
274
- **Parameters:**
275
- - `platformName` (String): Platform identifier
276
-
277
- **Returns:** Object with adapter capabilities information
278
-
279
- ### Exported Components
280
-
281
- #### Handlers
282
- ```javascript
283
- const authHandler = require('@app-connect/core/handlers/auth');
284
- const contactHandler = require('@app-connect/core/handlers/contact');
285
- const logHandler = require('@app-connect/core/handlers/log');
286
- const adminHandler = require('@app-connect/core/handlers/admin');
287
- const userHandler = require('@app-connect/core/handlers/user');
288
- const dispositionHandler = require('@app-connect/core/handlers/disposition');
289
-
290
- // Available handlers:
291
- // authHandler - Authentication operations
292
- // contactHandler - Contact management
293
- // logHandler - Call/message logging
294
- // adminHandler - Admin operations
295
- // userHandler - User management
296
- // dispositionHandler - Call disposition
297
- ```
298
-
299
- #### Models
300
- ```javascript
301
- const { UserModel } = require('@app-connect/core/models/userModel');
302
- const { CallLogModel } = require('@app-connect/core/models/callLogModel');
303
- const { MessageLogModel } = require('@app-connect/core/models/messageLogModel');
304
- const { AdminConfigModel } = require('@app-connect/core/models/adminConfigModel');
305
- const { CacheModel } = require('@app-connect/core/models/cacheModel');
306
-
307
- // Available models:
308
- // UserModel - User data model
309
- // CallLogModel - Call log data model
310
- // MessageLogModel - Message log data model
311
- // AdminConfigModel - Admin configuration model
312
- // CacheModel - Cache data model
313
- ```
314
-
315
- #### Utilities
316
- ```javascript
317
- const jwt = require('@app-connect/core/lib/jwt');
318
- const analytics = require('@app-connect/core/lib/analytics');
319
- const util = require('@app-connect/core/lib/util');
320
-
321
- // Available utilities:
322
- // jwt - JWT token management
323
- // analytics - Analytics tracking
324
- // util - General utilities
325
- ```
326
-
327
- ## Core Routes
328
-
329
- The core package provides the following API endpoints:
330
-
331
- ### Authentication
332
- - `GET /authValidation` - Validate user authentication
333
- - `GET /oauth-callback` - OAuth callback handler
334
- - `POST /apiKeyLogin` - API key authentication
335
- - `POST /unAuthorize` - Logout user
336
-
337
- ### Contact Management
338
- - `GET /contact` - Find contacts by phone number
339
- - `POST /contact` - Create new contact
340
- - `GET /custom/contact/search` - Search contacts by name
341
-
342
- ### Call Logging
343
- - `GET /callLog` - Retrieve call logs
344
- - `POST /callLog` - Create call log
345
- - `PATCH /callLog` - Update call log
346
- - `PUT /callDisposition` - Set call disposition
347
- - `POST /messageLog` - Create message log
348
-
349
- ### User Management
350
- - `GET /user/settings` - Get user settings
351
- - `POST /user/settings` - Update user settings
352
- - `GET /user/preloadSettings` - Preload user settings
353
-
354
- ### Admin Operations
355
- - `GET /admin/settings` - Get admin settings
356
- - `POST /admin/settings` - Update admin settings
357
- - `GET /admin/serverLoggingSettings` - Get server logging settings
358
- - `POST /admin/serverLoggingSettings` - Update server logging settings
359
-
360
- ### System
361
- - `GET /releaseNotes` - Get release notes
362
- - `GET /crmManifest` - Get CRM manifest
363
- - `GET /is-alive` - Health check
364
- - `GET /serverVersionInfo` - Get server version
365
- - `GET /hostname` - Get user hostname
366
- - `GET /userInfoHash` - Get hashed user info
367
-
368
- ## Environment Variables
369
-
370
- The core package uses the following environment variables:
371
-
372
- - `DATABASE_URL` - Database connection string for Sequelize ORM
373
- - `DISABLE_SYNC_DB_TABLE` - Skip database table synchronization
374
- - `OVERRIDE_APP_SERVER` - Override app server URL in manifests
375
- - `HASH_KEY` - Key for hashing user information
376
- - `APP_SERVER_SECRET_KEY` - Server secret key
377
- - `IS_PROD` - Production environment flag
378
- - `DYNAMODB_LOCALHOST` - Local DynamoDB endpoint for development, used for lock cache
379
-
380
- ## Adapter Interface Registration Benefits
381
-
382
- ### Key Features
383
-
384
- - **Composition over Mutation**: Interface functions are composed with adapters at retrieval time, preserving the original adapter
385
- - **Dynamic Registration**: Register interface functions before or after adapter registration
386
- - **Immutability**: Original adapter objects remain unchanged
387
- - **Clean Separation**: Interface functions are kept separate from core adapter logic
388
- - **Flexibility**: Support for interface-only adapters (no base adapter required)
389
-
390
- ### Best Practices
391
-
392
- 1. **Register Required Interfaces**: Register all required interface functions before using the adapter
393
- 2. **Use Descriptive Names**: Use clear, descriptive names for interface functions
394
- 3. **Handle Errors**: Implement proper error handling in interface functions
395
- 4. **Test Composed Adapters**: Test the final composed adapter to ensure interfaces work correctly
396
- 5. **Document Interfaces**: Document what each interface function does and expects
397
-
398
- ### Use Cases
399
-
400
- - **Extending Existing Adapters**: Add new functionality to existing adapters without modification
401
- - **Progressive Enhancement**: Start with interfaces, add base adapter later
402
- - **Testing**: Test interface functions separately from base adapters
403
- - **Modular Development**: Develop interface functions independently
404
- - **Plugin Architecture**: Create pluggable interface functions for different scenarios
405
-
406
- ## Architecture
407
-
408
- ```
409
- Core Package
410
- ├── Handlers (Business Logic)
411
- │ ├── auth.js - Authentication logic
412
- │ ├── contact.js - Contact management
413
- │ ├── log.js - Call/message logging
414
- │ ├── admin.js - Admin operations
415
- │ ├── user.js - User management
416
- │ └── disposition.js - Call disposition
417
- ├── Models (Data Layer)
418
- │ ├── userModel.js
419
- │ ├── callLogModel.js
420
- │ ├── messageLogModel.js
421
- │ ├── adminConfigModel.js
422
- │ └── cacheModel.js
423
- ├── Utils (Utilities)
424
- │ ├── jwt.js - JWT operations
425
- │ ├── analytics.js - Analytics tracking
426
- │ └── util.js - General utilities
427
- ├── Adapter Registry
428
- │ └── registry.js - CRM adapter management
429
- └── API Layer
430
- ├── createCoreApp() - Complete app setup
431
- ├── createCoreRouter() - Route management
432
- ├── createCoreMiddleware() - Middleware management
433
- └── initializeCore() - Service initialization
434
- ```
1
+ # App Connect Core
2
+
3
+ Core package for RingCentral App Connect project providing modular APIs for CRM integration, authentication, contact management, and call logging.
4
+
5
+ ## Features
6
+
7
+ - **Modular API Design**: Flexible Express app setup with customizable middleware and routes
8
+ - **CRM Adapter Registry**: Centralized adapter management for multiple CRM platforms
9
+ - **Authentication**: OAuth and API key authentication support
10
+ - **Contact Management**: Find, create, and manage contacts across CRM platforms
11
+ - **Call Logging**: Comprehensive call and message logging capabilities
12
+ - **Analytics**: Built-in analytics tracking for all operations
13
+ - **Database Integration**: Sequelize.js ORM with automatic table management
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @app-connect/core
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Basic Usage
24
+
25
+ ```javascript
26
+ const { createCoreApp, adapterRegistry } = require('@app-connect/core');
27
+ const myCRMAdapter = require('./adapters/myCRM');
28
+ const manifest = require('./adapters/manifest.json');
29
+ // Set the default manifest for the adapter registry. This ensures that all adapters
30
+ // have access to the necessary configuration and metadata before registration.
31
+ adapterRegistry.setDefaultManifest(manifest);
32
+ // Register your CRM adapters. The default manifest must be set before registration
33
+ // to ensure proper initialization of the adapter with the required settings.
34
+ adapterRegistry.registerAdapter('myCRM', myCRMAdapter, manifest);
35
+
36
+ // Create Express app with all core functionality
37
+ const app = createCoreApp();
38
+
39
+ // Add your custom routes
40
+ app.get('/my-custom-route', (req, res) => {
41
+ res.send('Hello from custom route!');
42
+ });
43
+
44
+ exports.getServer = () => app;
45
+ ```
46
+
47
+ ### Adapter Interface Registration
48
+
49
+ The adapter registry supports dynamic interface registration, allowing you to extend adapter functionality without modifying the original adapter:
50
+
51
+ ```javascript
52
+ const { adapterRegistry } = require('@app-connect/core');
53
+
54
+ // Register interface functions for a platform
55
+ async function customCreateCallLog({ user, contactInfo, authHeader, callLog, note }) {
56
+ // Custom implementation
57
+ return {
58
+ logId: 'custom-log-id',
59
+ returnMessage: {
60
+ message: 'Call logged with custom implementation',
61
+ messageType: 'success',
62
+ ttl: 2000
63
+ }
64
+ };
65
+ }
66
+
67
+ async function customFindContact({ user, authHeader, phoneNumber }) {
68
+ // Custom implementation
69
+ return [
70
+ {
71
+ id: 'custom-contact-id',
72
+ name: 'Custom Contact',
73
+ type: 'Contact',
74
+ phone: phoneNumber,
75
+ additionalInfo: null
76
+ }
77
+ ];
78
+ }
79
+
80
+ // Register interface functions
81
+ adapterRegistry.registerAdapterInterface('myCRM', 'createCallLog', customCreateCallLog);
82
+ adapterRegistry.registerAdapterInterface('myCRM', 'findContact', customFindContact);
83
+
84
+ // Register the base adapter
85
+ adapterRegistry.registerAdapter('myCRM', myCRMAdapter);
86
+
87
+ // Get composed adapter with interfaces
88
+ const composedAdapter = adapterRegistry.getAdapter('myCRM');
89
+ ```
90
+
91
+ **Interface-Only Adapters (No Base Adapter):**
92
+
93
+ ```javascript
94
+ // Register only interface functions, no base adapter
95
+ adapterRegistry.registerAdapterInterface('interfaceOnlyCRM', 'createCallLog', customCreateCallLog);
96
+ adapterRegistry.registerAdapterInterface('interfaceOnlyCRM', 'findContact', customFindContact);
97
+
98
+ // Get interface-only adapter
99
+ const interfaceOnlyAdapter = adapterRegistry.getAdapter('interfaceOnlyCRM');
100
+ console.log('Interface-only methods:', Object.keys(interfaceOnlyAdapter));
101
+ // Output: ['createCallLog', 'findContact']
102
+
103
+ // Later, you can add a base adapter
104
+ adapterRegistry.registerAdapter('interfaceOnlyCRM', myCRMAdapter);
105
+ const fullAdapter = adapterRegistry.getAdapter('interfaceOnlyCRM');
106
+ console.log('Full adapter methods:', Object.keys(fullAdapter));
107
+ // Output: ['getAuthType', 'getUserInfo', 'updateCallLog', 'unAuthorize', 'createContact', 'createCallLog', 'findContact']
108
+ ```
109
+
110
+ ### Advanced Usage with Custom Middleware
111
+
112
+ ```javascript
113
+ const express = require('express');
114
+ const {
115
+ createCoreRouter,
116
+ createCoreMiddleware,
117
+ initializeCore,
118
+ adapterRegistry
119
+ } = require('@app-connect/core');
120
+
121
+ const myCRMAdapter = require('./adapters/myCRM');
122
+ const manifest = require('./adapters/manifest.json');
123
+ // Set manifest
124
+ adapterRegistry.setDefaultManifest(manifest);
125
+ // Register adapters
126
+ adapterRegistry.registerAdapter('myCRM', myCRMAdapter, manifest);
127
+
128
+ // Initialize core services
129
+ initializeCore();
130
+
131
+ // Create your own Express app
132
+ const app = express();
133
+
134
+ // Add custom middleware first
135
+ app.use(express.static('public'));
136
+ app.use('/api/v2', customApiMiddleware);
137
+
138
+ // Apply core middleware
139
+ const coreMiddleware = createCoreMiddleware();
140
+ coreMiddleware.forEach(middleware => app.use(middleware));
141
+
142
+ // Add core routes
143
+ const coreRouter = createCoreRouter();
144
+ app.use('/', coreRouter);
145
+
146
+ // Add custom routes
147
+ app.get('/my-custom-route', (req, res) => {
148
+ res.send('Hello from custom route!');
149
+ });
150
+ ```
151
+
152
+ ## API Reference
153
+
154
+ ### Core Functions
155
+
156
+ #### `createCoreApp(options)`
157
+ Creates a complete Express app with all core functionality.
158
+
159
+ **Parameters:**
160
+ - `options` (Object, optional): Configuration options
161
+ - `skipDatabaseInit` (Boolean): Skip database initialization (default: false)
162
+ - `skipAnalyticsInit` (Boolean): Skip analytics initialization (default: false)
163
+
164
+ **Returns:** Express application instance
165
+
166
+ #### `createCoreRouter()`
167
+ Creates an Express router with all core routes.
168
+
169
+ **Returns:** Express router instance
170
+
171
+ #### `createCoreMiddleware()`
172
+ Returns an array of core middleware functions.
173
+
174
+ **Returns:** Array of middleware functions
175
+
176
+ #### `initializeCore(options)`
177
+ Initializes core services (database, analytics).
178
+
179
+ **Parameters:**
180
+ - `options` (Object, optional): Configuration options
181
+ - `skipDatabaseInit` (Boolean): Skip database initialization (default: false)
182
+ - `skipAnalyticsInit` (Boolean): Skip analytics initialization (default: false)
183
+
184
+ ### Adapter Registry
185
+
186
+ #### `adapterRegistry.setDefaultManifest(manifest)`
187
+ Sets the default manifest for adapters.
188
+
189
+ **Parameters:**
190
+ - `manifest` (Object): Default manifest
191
+
192
+ #### `adapterRegistry.registerAdapter(name, adapter, manifest)`
193
+ Registers a CRM adapter.
194
+
195
+ **Parameters:**
196
+ - `name` (String): Adapter name
197
+ - `adapter` (Object): Adapter implementation
198
+ - `manifest` (Object, optional): Adapter manifest
199
+
200
+ #### `adapterRegistry.registerAdapterInterface(platformName, interfaceName, interfaceFunction)`
201
+ Registers an interface function for a specific platform that will be composed with the adapter at retrieval time.
202
+
203
+ **Parameters:**
204
+ - `platformName` (String): Platform identifier (e.g., 'pipedrive', 'salesforce')
205
+ - `interfaceName` (String): Interface function name (e.g., 'createCallLog', 'findContact')
206
+ - `interfaceFunction` (Function): The interface function to register
207
+
208
+ **Example:**
209
+ ```javascript
210
+ async function customCreateCallLog({ user, contactInfo, authHeader, callLog, note }) {
211
+ // Custom implementation
212
+ return {
213
+ logId: 'custom-log-id',
214
+ returnMessage: {
215
+ message: 'Call logged with custom implementation',
216
+ messageType: 'success',
217
+ ttl: 2000
218
+ }
219
+ };
220
+ }
221
+
222
+ adapterRegistry.registerAdapterInterface('myCRM', 'createCallLog', customCreateCallLog);
223
+ ```
224
+
225
+ #### `adapterRegistry.getAdapter(name)`
226
+ Retrieves a registered adapter with composed interfaces.
227
+
228
+ **Parameters:**
229
+ - `name` (String): Adapter name
230
+
231
+ **Returns:** Composed adapter object or interface-only object
232
+
233
+ **Behavior:**
234
+ - If adapter exists and interfaces exist: Returns composed adapter with both
235
+ - If adapter exists but no interfaces: Returns original adapter
236
+ - If no adapter but interfaces exist: Returns object with just interface functions
237
+ - If no adapter and no interfaces: Throws error
238
+
239
+ #### `adapterRegistry.getOriginalAdapter(name)`
240
+ Retrieves the original adapter without any composed interface functions.
241
+
242
+ **Parameters:**
243
+ - `name` (String): Adapter name
244
+
245
+ **Returns:** Original adapter object
246
+
247
+ #### `adapterRegistry.getPlatformInterfaces(platformName)`
248
+ Returns a Map of registered interface functions for a platform.
249
+
250
+ **Parameters:**
251
+ - `platformName` (String): Platform identifier
252
+
253
+ **Returns:** Map of interface functions
254
+
255
+ #### `adapterRegistry.hasPlatformInterface(platformName, interfaceName)`
256
+ Checks if a specific interface function is registered for a platform.
257
+
258
+ **Parameters:**
259
+ - `platformName` (String): Platform identifier
260
+ - `interfaceName` (String): Interface function name
261
+
262
+ **Returns:** Boolean indicating if interface exists
263
+
264
+ #### `adapterRegistry.unregisterAdapterInterface(platformName, interfaceName)`
265
+ Unregisters an interface function for a platform.
266
+
267
+ **Parameters:**
268
+ - `platformName` (String): Platform identifier
269
+ - `interfaceName` (String): Interface function name
270
+
271
+ #### `adapterRegistry.getAdapterCapabilities(platformName)`
272
+ Gets comprehensive information about an adapter including its capabilities and registered interfaces.
273
+
274
+ **Parameters:**
275
+ - `platformName` (String): Platform identifier
276
+
277
+ **Returns:** Object with adapter capabilities information
278
+
279
+ ### Exported Components
280
+
281
+ #### Handlers
282
+ ```javascript
283
+ const authHandler = require('@app-connect/core/handlers/auth');
284
+ const contactHandler = require('@app-connect/core/handlers/contact');
285
+ const logHandler = require('@app-connect/core/handlers/log');
286
+ const adminHandler = require('@app-connect/core/handlers/admin');
287
+ const userHandler = require('@app-connect/core/handlers/user');
288
+ const dispositionHandler = require('@app-connect/core/handlers/disposition');
289
+
290
+ // Available handlers:
291
+ // authHandler - Authentication operations
292
+ // contactHandler - Contact management
293
+ // logHandler - Call/message logging
294
+ // adminHandler - Admin operations
295
+ // userHandler - User management
296
+ // dispositionHandler - Call disposition
297
+ ```
298
+
299
+ #### Models
300
+ ```javascript
301
+ const { UserModel } = require('@app-connect/core/models/userModel');
302
+ const { CallLogModel } = require('@app-connect/core/models/callLogModel');
303
+ const { MessageLogModel } = require('@app-connect/core/models/messageLogModel');
304
+ const { AdminConfigModel } = require('@app-connect/core/models/adminConfigModel');
305
+ const { CacheModel } = require('@app-connect/core/models/cacheModel');
306
+
307
+ // Available models:
308
+ // UserModel - User data model
309
+ // CallLogModel - Call log data model
310
+ // MessageLogModel - Message log data model
311
+ // AdminConfigModel - Admin configuration model
312
+ // CacheModel - Cache data model
313
+ ```
314
+
315
+ #### Utilities
316
+ ```javascript
317
+ const jwt = require('@app-connect/core/lib/jwt');
318
+ const analytics = require('@app-connect/core/lib/analytics');
319
+ const util = require('@app-connect/core/lib/util');
320
+
321
+ // Available utilities:
322
+ // jwt - JWT token management
323
+ // analytics - Analytics tracking
324
+ // util - General utilities
325
+ ```
326
+
327
+ ## Core Routes
328
+
329
+ The core package provides the following API endpoints:
330
+
331
+ ### Authentication
332
+ - `GET /authValidation` - Validate user authentication
333
+ - `GET /oauth-callback` - OAuth callback handler
334
+ - `POST /apiKeyLogin` - API key authentication
335
+ - `POST /unAuthorize` - Logout user
336
+
337
+ ### Contact Management
338
+ - `GET /contact` - Find contacts by phone number
339
+ - `POST /contact` - Create new contact
340
+ - `GET /custom/contact/search` - Search contacts by name
341
+
342
+ ### Call Logging
343
+ - `GET /callLog` - Retrieve call logs
344
+ - `POST /callLog` - Create call log
345
+ - `PATCH /callLog` - Update call log
346
+ - `PUT /callDisposition` - Set call disposition
347
+ - `POST /messageLog` - Create message log
348
+
349
+ ### User Management
350
+ - `GET /user/settings` - Get user settings
351
+ - `POST /user/settings` - Update user settings
352
+ - `GET /user/preloadSettings` - Preload user settings
353
+
354
+ ### Admin Operations
355
+ - `GET /admin/settings` - Get admin settings
356
+ - `POST /admin/settings` - Update admin settings
357
+ - `GET /admin/serverLoggingSettings` - Get server logging settings
358
+ - `POST /admin/serverLoggingSettings` - Update server logging settings
359
+
360
+ ### System
361
+ - `GET /releaseNotes` - Get release notes
362
+ - `GET /crmManifest` - Get CRM manifest
363
+ - `GET /is-alive` - Health check
364
+ - `GET /serverVersionInfo` - Get server version
365
+ - `GET /hostname` - Get user hostname
366
+ - `GET /userInfoHash` - Get hashed user info
367
+
368
+ ## Environment Variables
369
+
370
+ The core package uses the following environment variables:
371
+
372
+ - `DATABASE_URL` - Database connection string for Sequelize ORM
373
+ - `DISABLE_SYNC_DB_TABLE` - Skip database table synchronization
374
+ - `OVERRIDE_APP_SERVER` - Override app server URL in manifests
375
+ - `HASH_KEY` - Key for hashing user information
376
+ - `APP_SERVER_SECRET_KEY` - Server secret key
377
+ - `IS_PROD` - Production environment flag
378
+ - `DYNAMODB_LOCALHOST` - Local DynamoDB endpoint for development, used for lock cache
379
+
380
+ ## Adapter Interface Registration Benefits
381
+
382
+ ### Key Features
383
+
384
+ - **Composition over Mutation**: Interface functions are composed with adapters at retrieval time, preserving the original adapter
385
+ - **Dynamic Registration**: Register interface functions before or after adapter registration
386
+ - **Immutability**: Original adapter objects remain unchanged
387
+ - **Clean Separation**: Interface functions are kept separate from core adapter logic
388
+ - **Flexibility**: Support for interface-only adapters (no base adapter required)
389
+
390
+ ### Best Practices
391
+
392
+ 1. **Register Required Interfaces**: Register all required interface functions before using the adapter
393
+ 2. **Use Descriptive Names**: Use clear, descriptive names for interface functions
394
+ 3. **Handle Errors**: Implement proper error handling in interface functions
395
+ 4. **Test Composed Adapters**: Test the final composed adapter to ensure interfaces work correctly
396
+ 5. **Document Interfaces**: Document what each interface function does and expects
397
+
398
+ ### Use Cases
399
+
400
+ - **Extending Existing Adapters**: Add new functionality to existing adapters without modification
401
+ - **Progressive Enhancement**: Start with interfaces, add base adapter later
402
+ - **Testing**: Test interface functions separately from base adapters
403
+ - **Modular Development**: Develop interface functions independently
404
+ - **Plugin Architecture**: Create pluggable interface functions for different scenarios
405
+
406
+ ## Architecture
407
+
408
+ ```
409
+ Core Package
410
+ ├── Handlers (Business Logic)
411
+ │ ├── auth.js - Authentication logic
412
+ │ ├── contact.js - Contact management
413
+ │ ├── log.js - Call/message logging
414
+ │ ├── admin.js - Admin operations
415
+ │ ├── user.js - User management
416
+ │ └── disposition.js - Call disposition
417
+ ├── Models (Data Layer)
418
+ │ ├── userModel.js
419
+ │ ├── callLogModel.js
420
+ │ ├── messageLogModel.js
421
+ │ ├── adminConfigModel.js
422
+ │ └── cacheModel.js
423
+ ├── Utils (Utilities)
424
+ │ ├── jwt.js - JWT operations
425
+ │ ├── analytics.js - Analytics tracking
426
+ │ └── util.js - General utilities
427
+ ├── Adapter Registry
428
+ │ └── registry.js - CRM adapter management
429
+ └── API Layer
430
+ ├── createCoreApp() - Complete app setup
431
+ ├── createCoreRouter() - Route management
432
+ ├── createCoreMiddleware() - Middleware management
433
+ └── initializeCore() - Service initialization
434
+ ```