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