@forumviriumhelsinki/podio-mcp 2.3.0
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/LICENSE +21 -0
- package/README.md +491 -0
- package/build/__tests__/integration/setup.integration.d.ts +104 -0
- package/build/__tests__/integration/setup.integration.d.ts.map +1 -0
- package/build/__tests__/integration/setup.integration.js +233 -0
- package/build/__tests__/integration/setup.integration.js.map +1 -0
- package/build/__tests__/mock-data/items-mock-data.d.ts +168 -0
- package/build/__tests__/mock-data/items-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/items-mock-data.js +370 -0
- package/build/__tests__/mock-data/items-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/notification-mock-data.d.ts +55 -0
- package/build/__tests__/mock-data/notification-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/notification-mock-data.js +190 -0
- package/build/__tests__/mock-data/notification-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/project-epic-mock-data.d.ts +45 -0
- package/build/__tests__/mock-data/project-epic-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/project-epic-mock-data.js +85 -0
- package/build/__tests__/mock-data/project-epic-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/tasks-mock-data.d.ts +27 -0
- package/build/__tests__/mock-data/tasks-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/tasks-mock-data.js +104 -0
- package/build/__tests__/mock-data/tasks-mock-data.js.map +1 -0
- package/build/__tests__/mock-data/utility-mock-data.d.ts +19 -0
- package/build/__tests__/mock-data/utility-mock-data.d.ts.map +1 -0
- package/build/__tests__/mock-data/utility-mock-data.js +165 -0
- package/build/__tests__/mock-data/utility-mock-data.js.map +1 -0
- package/build/__tests__/setup.d.ts +8 -0
- package/build/__tests__/setup.d.ts.map +1 -0
- package/build/__tests__/setup.js +31 -0
- package/build/__tests__/setup.js.map +1 -0
- package/build/__tests__/utils/test-helpers.d.ts +110 -0
- package/build/__tests__/utils/test-helpers.d.ts.map +1 -0
- package/build/__tests__/utils/test-helpers.js +222 -0
- package/build/__tests__/utils/test-helpers.js.map +1 -0
- package/build/api/podio-api-client.d.ts +364 -0
- package/build/api/podio-api-client.d.ts.map +1 -0
- package/build/api/podio-api-client.js +696 -0
- package/build/api/podio-api-client.js.map +1 -0
- package/build/cache/app-cache.d.ts +77 -0
- package/build/cache/app-cache.d.ts.map +1 -0
- package/build/cache/app-cache.js +230 -0
- package/build/cache/app-cache.js.map +1 -0
- package/build/cache/base-cache-manager.d.ts +149 -0
- package/build/cache/base-cache-manager.d.ts.map +1 -0
- package/build/cache/base-cache-manager.js +312 -0
- package/build/cache/base-cache-manager.js.map +1 -0
- package/build/cache/cache-manager.d.ts +230 -0
- package/build/cache/cache-manager.d.ts.map +1 -0
- package/build/cache/cache-manager.js +362 -0
- package/build/cache/cache-manager.js.map +1 -0
- package/build/cache/cache-test.d.ts +9 -0
- package/build/cache/cache-test.d.ts.map +1 -0
- package/build/cache/cache-test.js +169 -0
- package/build/cache/cache-test.js.map +1 -0
- package/build/cache/index.d.ts +18 -0
- package/build/cache/index.d.ts.map +1 -0
- package/build/cache/index.js +20 -0
- package/build/cache/index.js.map +1 -0
- package/build/cache/migration-helper.d.ts +44 -0
- package/build/cache/migration-helper.d.ts.map +1 -0
- package/build/cache/migration-helper.js +235 -0
- package/build/cache/migration-helper.js.map +1 -0
- package/build/cache/project-epic-cache.d.ts +108 -0
- package/build/cache/project-epic-cache.d.ts.map +1 -0
- package/build/cache/project-epic-cache.js +278 -0
- package/build/cache/project-epic-cache.js.map +1 -0
- package/build/cache/space-members-cache.d.ts +99 -0
- package/build/cache/space-members-cache.d.ts.map +1 -0
- package/build/cache/space-members-cache.js +305 -0
- package/build/cache/space-members-cache.js.map +1 -0
- package/build/cache/storage-adapters.d.ts +100 -0
- package/build/cache/storage-adapters.d.ts.map +1 -0
- package/build/cache/storage-adapters.js +297 -0
- package/build/cache/storage-adapters.js.map +1 -0
- package/build/errors/api-errors.d.ts +52 -0
- package/build/errors/api-errors.d.ts.map +1 -0
- package/build/errors/api-errors.js +86 -0
- package/build/errors/api-errors.js.map +1 -0
- package/build/errors/auth-errors.d.ts +67 -0
- package/build/errors/auth-errors.d.ts.map +1 -0
- package/build/errors/auth-errors.js +114 -0
- package/build/errors/auth-errors.js.map +1 -0
- package/build/errors/base.d.ts +102 -0
- package/build/errors/base.d.ts.map +1 -0
- package/build/errors/base.js +131 -0
- package/build/errors/base.js.map +1 -0
- package/build/errors/cache-errors.d.ts +53 -0
- package/build/errors/cache-errors.d.ts.map +1 -0
- package/build/errors/cache-errors.js +83 -0
- package/build/errors/cache-errors.js.map +1 -0
- package/build/errors/config-errors.d.ts +58 -0
- package/build/errors/config-errors.d.ts.map +1 -0
- package/build/errors/config-errors.js +96 -0
- package/build/errors/config-errors.js.map +1 -0
- package/build/errors/index.d.ts +101 -0
- package/build/errors/index.d.ts.map +1 -0
- package/build/errors/index.js +135 -0
- package/build/errors/index.js.map +1 -0
- package/build/errors/structure-errors.d.ts +89 -0
- package/build/errors/structure-errors.d.ts.map +1 -0
- package/build/errors/structure-errors.js +182 -0
- package/build/errors/structure-errors.js.map +1 -0
- package/build/errors/validation-errors.d.ts +81 -0
- package/build/errors/validation-errors.d.ts.map +1 -0
- package/build/errors/validation-errors.js +169 -0
- package/build/errors/validation-errors.js.map +1 -0
- package/build/fields/field-mapper.d.ts +245 -0
- package/build/fields/field-mapper.d.ts.map +1 -0
- package/build/fields/field-mapper.js +404 -0
- package/build/fields/field-mapper.js.map +1 -0
- package/build/index.d.ts +550 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1527 -0
- package/build/index.js.map +1 -0
- package/build/oauth-helper.d.ts +189 -0
- package/build/oauth-helper.d.ts.map +1 -0
- package/build/oauth-helper.js +422 -0
- package/build/oauth-helper.js.map +1 -0
- package/build/services/app-structure-service.d.ts +49 -0
- package/build/services/app-structure-service.d.ts.map +1 -0
- package/build/services/app-structure-service.js +122 -0
- package/build/services/app-structure-service.js.map +1 -0
- package/build/services/code-execution-service.d.ts +88 -0
- package/build/services/code-execution-service.d.ts.map +1 -0
- package/build/services/code-execution-service.js +342 -0
- package/build/services/code-execution-service.js.map +1 -0
- package/build/services/comment-service.d.ts +66 -0
- package/build/services/comment-service.d.ts.map +1 -0
- package/build/services/comment-service.js +139 -0
- package/build/services/comment-service.js.map +1 -0
- package/build/services/index.d.ts +16 -0
- package/build/services/index.d.ts.map +1 -0
- package/build/services/index.js +15 -0
- package/build/services/index.js.map +1 -0
- package/build/services/item-service.d.ts +104 -0
- package/build/services/item-service.d.ts.map +1 -0
- package/build/services/item-service.js +368 -0
- package/build/services/item-service.js.map +1 -0
- package/build/services/notification-service.d.ts +125 -0
- package/build/services/notification-service.d.ts.map +1 -0
- package/build/services/notification-service.js +321 -0
- package/build/services/notification-service.js.map +1 -0
- package/build/services/project-epic-service.d.ts +73 -0
- package/build/services/project-epic-service.d.ts.map +1 -0
- package/build/services/project-epic-service.js +248 -0
- package/build/services/project-epic-service.js.map +1 -0
- package/build/services/response-formatter.d.ts +190 -0
- package/build/services/response-formatter.d.ts.map +1 -0
- package/build/services/response-formatter.js +1221 -0
- package/build/services/response-formatter.js.map +1 -0
- package/build/services/search-service.d.ts +103 -0
- package/build/services/search-service.d.ts.map +1 -0
- package/build/services/search-service.js +273 -0
- package/build/services/search-service.js.map +1 -0
- package/build/services/task-service.d.ts +70 -0
- package/build/services/task-service.d.ts.map +1 -0
- package/build/services/task-service.js +156 -0
- package/build/services/task-service.js.map +1 -0
- package/build/tools/index.d.ts +8 -0
- package/build/tools/index.d.ts.map +1 -0
- package/build/tools/index.js +8 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/tool-definitions.d.ts +89 -0
- package/build/tools/tool-definitions.d.ts.map +1 -0
- package/build/tools/tool-definitions.js +1167 -0
- package/build/tools/tool-definitions.js.map +1 -0
- package/build/types/api-types.d.ts +106 -0
- package/build/types/api-types.d.ts.map +1 -0
- package/build/types/api-types.js +11 -0
- package/build/types/api-types.js.map +1 -0
- package/build/types/cache-types.d.ts +52 -0
- package/build/types/cache-types.d.ts.map +1 -0
- package/build/types/cache-types.js +12 -0
- package/build/types/cache-types.js.map +1 -0
- package/build/types/index.d.ts +31 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +25 -0
- package/build/types/index.js.map +1 -0
- package/build/types/notification-types.d.ts +154 -0
- package/build/types/notification-types.d.ts.map +1 -0
- package/build/types/notification-types.js +7 -0
- package/build/types/notification-types.js.map +1 -0
- package/build/types/podio-types.d.ts +250 -0
- package/build/types/podio-types.d.ts.map +1 -0
- package/build/types/podio-types.js +11 -0
- package/build/types/podio-types.js.map +1 -0
- package/build/types/search-types.d.ts +188 -0
- package/build/types/search-types.d.ts.map +1 -0
- package/build/types/search-types.js +43 -0
- package/build/types/search-types.js.map +1 -0
- package/build/utils/debug.d.ts +58 -0
- package/build/utils/debug.d.ts.map +1 -0
- package/build/utils/debug.js +147 -0
- package/build/utils/debug.js.map +1 -0
- package/examples/claude-config-example.json +13 -0
- package/package.json +87 -0
- package/scripts/generate-claude-config.js +107 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Notification Service for managing Podio notifications
|
|
3
|
+
*
|
|
4
|
+
* This service handles all notification-related operations including fetching,
|
|
5
|
+
* filtering, caching, and formatting notification data.
|
|
6
|
+
*/
|
|
7
|
+
import { PodioApiError, PodioConfigError } from '../errors/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Service for managing Podio notifications
|
|
10
|
+
*
|
|
11
|
+
* This service provides a high-level interface for notification operations,
|
|
12
|
+
* including data fetching, filtering, caching, and transformation.
|
|
13
|
+
*/
|
|
14
|
+
export class NotificationService {
|
|
15
|
+
apiClient;
|
|
16
|
+
cacheManager;
|
|
17
|
+
/** Simple in-memory cache for notifications */
|
|
18
|
+
simpleCache = new Map();
|
|
19
|
+
/** Cache key prefix for notifications */
|
|
20
|
+
CACHE_PREFIX = 'notifications';
|
|
21
|
+
/** Default cache duration for notifications (5 minutes) */
|
|
22
|
+
CACHE_DURATION = 5 * 60 * 1000;
|
|
23
|
+
/** Cache key for unread count */
|
|
24
|
+
UNREAD_COUNT_KEY = 'unread_count';
|
|
25
|
+
constructor(apiClient, cacheManager) {
|
|
26
|
+
this.apiClient = apiClient;
|
|
27
|
+
this.cacheManager = cacheManager;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Simple cache get method with expiry check
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param key - Cache key
|
|
34
|
+
* @returns Cached data or null if expired/not found
|
|
35
|
+
*/
|
|
36
|
+
getCached(key) {
|
|
37
|
+
const item = this.simpleCache.get(key);
|
|
38
|
+
if (!item) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (Date.now() > item.expiry) {
|
|
42
|
+
this.simpleCache.delete(key);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return item.data;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Simple cache set method with expiry
|
|
49
|
+
*
|
|
50
|
+
* @private
|
|
51
|
+
* @param key - Cache key
|
|
52
|
+
* @param data - Data to cache
|
|
53
|
+
* @param ttl - Time to live in milliseconds
|
|
54
|
+
*/
|
|
55
|
+
setCached(key, data, ttl) {
|
|
56
|
+
const expiry = Date.now() + ttl;
|
|
57
|
+
this.simpleCache.set(key, { data, expiry });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Simple cache delete method
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
* @param key - Cache key
|
|
64
|
+
*/
|
|
65
|
+
deleteCached(key) {
|
|
66
|
+
this.simpleCache.delete(key);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* List notifications with optional filtering and caching
|
|
70
|
+
*
|
|
71
|
+
* @param filters - Notification filters
|
|
72
|
+
* @param useCache - Whether to use cached data if available
|
|
73
|
+
* @returns Notifications response
|
|
74
|
+
*/
|
|
75
|
+
async listNotifications(filters = {}, useCache = true) {
|
|
76
|
+
const cacheKey = this.buildCacheKey(filters);
|
|
77
|
+
// Check cache first
|
|
78
|
+
if (useCache) {
|
|
79
|
+
const cached = this.getCached(cacheKey);
|
|
80
|
+
if (cached) {
|
|
81
|
+
console.error('📬 Using cached notifications data');
|
|
82
|
+
return cached;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Fetch from API
|
|
86
|
+
console.error('📬 Fetching notifications from Podio API...');
|
|
87
|
+
try {
|
|
88
|
+
const response = await this.apiClient.getNotifications(filters);
|
|
89
|
+
// Cache the response
|
|
90
|
+
this.setCached(cacheKey, response, this.CACHE_DURATION);
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error instanceof PodioApiError) {
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
throw PodioApiError.networkError('/notification/', error instanceof Error ? error : new Error('Unknown error'));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get a specific notification by ID
|
|
102
|
+
*
|
|
103
|
+
* @param notificationId - Notification ID
|
|
104
|
+
* @param useCache - Whether to use cached data if available
|
|
105
|
+
* @returns Notification details
|
|
106
|
+
*/
|
|
107
|
+
async getNotification(notificationId, useCache = true) {
|
|
108
|
+
if (!notificationId || notificationId <= 0) {
|
|
109
|
+
throw PodioConfigError.invalidValue('notification_id', notificationId, 'positive number');
|
|
110
|
+
}
|
|
111
|
+
const cacheKey = `${this.CACHE_PREFIX}_notification_${notificationId}`;
|
|
112
|
+
// Check cache first
|
|
113
|
+
if (useCache) {
|
|
114
|
+
const cached = this.getCached(cacheKey);
|
|
115
|
+
if (cached) {
|
|
116
|
+
console.error(`📬 Using cached notification ${notificationId}`);
|
|
117
|
+
return cached;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Fetch from API
|
|
121
|
+
console.error(`📬 Fetching notification ${notificationId} from Podio API...`);
|
|
122
|
+
try {
|
|
123
|
+
const notification = await this.apiClient.getNotification(notificationId);
|
|
124
|
+
// Cache the notification
|
|
125
|
+
this.setCached(cacheKey, notification, this.CACHE_DURATION);
|
|
126
|
+
return notification;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof PodioApiError) {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
throw PodioApiError.networkError(`/notification/${notificationId}`, error instanceof Error ? error : new Error('Unknown error'));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get unread notification count
|
|
137
|
+
*
|
|
138
|
+
* @param useCache - Whether to use cached data if available
|
|
139
|
+
* @returns Unread count information
|
|
140
|
+
*/
|
|
141
|
+
async getUnreadCount(useCache = true) {
|
|
142
|
+
const cacheKey = `${this.CACHE_PREFIX}_${this.UNREAD_COUNT_KEY}`;
|
|
143
|
+
// Check cache first (shorter cache for count - 1 minute)
|
|
144
|
+
if (useCache) {
|
|
145
|
+
const cached = this.getCached(cacheKey);
|
|
146
|
+
if (cached) {
|
|
147
|
+
console.error('📬 Using cached unread count');
|
|
148
|
+
return cached;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Fetch from API
|
|
152
|
+
console.error('📬 Fetching unread count from Podio API...');
|
|
153
|
+
try {
|
|
154
|
+
const count = await this.apiClient.getInboxNewCount();
|
|
155
|
+
// Cache for 1 minute (shorter cache for frequently changing data)
|
|
156
|
+
this.setCached(cacheKey, count, 60 * 1000);
|
|
157
|
+
return count;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error instanceof PodioApiError) {
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
throw PodioApiError.networkError('/notification/inbox/new/count', error instanceof Error ? error : new Error('Unknown error'));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get notification settings
|
|
168
|
+
*
|
|
169
|
+
* @param useCache - Whether to use cached data if available
|
|
170
|
+
* @returns Notification settings
|
|
171
|
+
*/
|
|
172
|
+
async getNotificationSettings(useCache = true) {
|
|
173
|
+
const cacheKey = `${this.CACHE_PREFIX}_settings`;
|
|
174
|
+
// Check cache first (longer cache for settings - 15 minutes)
|
|
175
|
+
if (useCache) {
|
|
176
|
+
const cached = this.getCached(cacheKey);
|
|
177
|
+
if (cached) {
|
|
178
|
+
console.error('📬 Using cached notification settings');
|
|
179
|
+
return cached;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Fetch from API
|
|
183
|
+
console.error('📬 Fetching notification settings from Podio API...');
|
|
184
|
+
try {
|
|
185
|
+
const settings = await this.apiClient.getNotificationSettings();
|
|
186
|
+
// Cache for 15 minutes (settings don't change often)
|
|
187
|
+
this.setCached(cacheKey, settings, 15 * 60 * 1000);
|
|
188
|
+
return settings;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error instanceof PodioApiError) {
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
throw PodioApiError.networkError('/notification/settings', error instanceof Error ? error : new Error('Unknown error'));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Transform notifications into summary format for display
|
|
199
|
+
*
|
|
200
|
+
* @param notifications - Raw notifications from API
|
|
201
|
+
* @returns Summarized notifications
|
|
202
|
+
*/
|
|
203
|
+
transformToSummary(notifications) {
|
|
204
|
+
return notifications.map((notification) => ({
|
|
205
|
+
id: notification.notification_id,
|
|
206
|
+
type: notification.type,
|
|
207
|
+
text: this.cleanNotificationText(notification.text),
|
|
208
|
+
created_on: notification.created_on,
|
|
209
|
+
viewed: notification.viewed,
|
|
210
|
+
status: notification.status,
|
|
211
|
+
created_by: notification.created_by?.name || 'Unknown',
|
|
212
|
+
context: notification.context?.title || notification.context?.type || 'None',
|
|
213
|
+
space: notification.space?.name || '',
|
|
214
|
+
app: notification.app?.name || '',
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Filter notifications by various criteria
|
|
219
|
+
*
|
|
220
|
+
* @param notifications - Notifications to filter
|
|
221
|
+
* @param criteria - Filter criteria
|
|
222
|
+
* @returns Filtered notifications
|
|
223
|
+
*/
|
|
224
|
+
filterNotifications(notifications, criteria = {}) {
|
|
225
|
+
let filtered = notifications;
|
|
226
|
+
if (criteria.unreadOnly) {
|
|
227
|
+
filtered = filtered.filter((n) => !n.viewed);
|
|
228
|
+
}
|
|
229
|
+
if (criteria.types && criteria.types.length > 0) {
|
|
230
|
+
filtered = filtered.filter((n) => criteria.types.includes(n.type));
|
|
231
|
+
}
|
|
232
|
+
if (criteria.hasContext) {
|
|
233
|
+
filtered = filtered.filter((n) => n.context && n.context.title);
|
|
234
|
+
}
|
|
235
|
+
if (criteria.fromDate) {
|
|
236
|
+
filtered = filtered.filter((n) => new Date(n.created_on) >= criteria.fromDate);
|
|
237
|
+
}
|
|
238
|
+
return filtered;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Clear notification-related cache
|
|
242
|
+
*
|
|
243
|
+
* @param specific - Clear specific cache key (optional)
|
|
244
|
+
*/
|
|
245
|
+
async clearCache(specific) {
|
|
246
|
+
if (specific) {
|
|
247
|
+
this.deleteCached(`${this.CACHE_PREFIX}_${specific}`);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
// Clear all notification cache keys
|
|
251
|
+
const keys = [
|
|
252
|
+
`${this.CACHE_PREFIX}_${this.UNREAD_COUNT_KEY}`,
|
|
253
|
+
`${this.CACHE_PREFIX}_settings`,
|
|
254
|
+
];
|
|
255
|
+
for (const key of keys) {
|
|
256
|
+
this.deleteCached(key);
|
|
257
|
+
}
|
|
258
|
+
// Clear all cached notifications (any key that starts with our prefix)
|
|
259
|
+
for (const [key] of this.simpleCache) {
|
|
260
|
+
if (key.startsWith(this.CACHE_PREFIX)) {
|
|
261
|
+
this.simpleCache.delete(key);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
console.error('📬 Cleared all notification caches');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Build cache key from notification filters
|
|
269
|
+
*
|
|
270
|
+
* @private
|
|
271
|
+
* @param filters - Notification filters
|
|
272
|
+
* @returns Cache key
|
|
273
|
+
*/
|
|
274
|
+
buildCacheKey(filters) {
|
|
275
|
+
const parts = [this.CACHE_PREFIX, 'list'];
|
|
276
|
+
if (filters.status)
|
|
277
|
+
parts.push(`status_${filters.status}`);
|
|
278
|
+
if (filters.type)
|
|
279
|
+
parts.push(`type_${filters.type}`);
|
|
280
|
+
if (filters.viewed !== undefined)
|
|
281
|
+
parts.push(`viewed_${filters.viewed}`);
|
|
282
|
+
if (filters.limit)
|
|
283
|
+
parts.push(`limit_${filters.limit}`);
|
|
284
|
+
if (filters.offset)
|
|
285
|
+
parts.push(`offset_${filters.offset}`);
|
|
286
|
+
if (filters.space_id)
|
|
287
|
+
parts.push(`space_${filters.space_id}`);
|
|
288
|
+
if (filters.app_id)
|
|
289
|
+
parts.push(`app_${filters.app_id}`);
|
|
290
|
+
return parts.join('_');
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Clean notification text for display (remove HTML, trim, etc.)
|
|
294
|
+
*
|
|
295
|
+
* @private
|
|
296
|
+
* @param text - Raw notification text
|
|
297
|
+
* @returns Cleaned text
|
|
298
|
+
*/
|
|
299
|
+
cleanNotificationText(text) {
|
|
300
|
+
if (!text)
|
|
301
|
+
return '';
|
|
302
|
+
// Remove HTML tags
|
|
303
|
+
let cleaned = text.replace(/<[^>]*>/g, '');
|
|
304
|
+
// Decode common HTML entities
|
|
305
|
+
cleaned = cleaned
|
|
306
|
+
.replace(/&/g, '&')
|
|
307
|
+
.replace(/</g, '<')
|
|
308
|
+
.replace(/>/g, '>')
|
|
309
|
+
.replace(/"/g, '"')
|
|
310
|
+
.replace(/'/g, "'")
|
|
311
|
+
.replace(/ /g, ' ');
|
|
312
|
+
// Trim and normalize whitespace
|
|
313
|
+
cleaned = cleaned.trim().replace(/\s+/g, ' ');
|
|
314
|
+
// Truncate if too long
|
|
315
|
+
if (cleaned.length > 200) {
|
|
316
|
+
cleaned = cleaned.substring(0, 197) + '...';
|
|
317
|
+
}
|
|
318
|
+
return cleaned;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
//# sourceMappingURL=notification-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-service.js","sourceRoot":"","sources":["../../src/services/notification-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,OAAO,EAAE,aAAa,EAAwB,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3F;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IACb,SAAS,CAAiB;IAC1B,YAAY,CAAe;IAE5C,+CAA+C;IAC9B,WAAW,GAA+C,IAAI,GAAG,EAAE,CAAC;IAErF,yCAAyC;IACxB,YAAY,GAAG,eAAe,CAAC;IAEhD,2DAA2D;IAC1C,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IAEhD,iCAAiC;IAChB,gBAAgB,GAAG,cAAc,CAAC;IAEnD,YAAY,SAAyB,EAAE,YAA0B;QAC/D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACK,SAAS,CAAI,GAAW;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;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OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Project and Epic Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles all project and epic related operations including
|
|
5
|
+
* fetching, caching, and suggestion logic.
|
|
6
|
+
*/
|
|
7
|
+
import type { PodioApiClient } from '../api/podio-api-client.js';
|
|
8
|
+
import type { CacheManager } from '../cache/cache-manager.js';
|
|
9
|
+
import type { FieldMapper } from '../fields/field-mapper.js';
|
|
10
|
+
import type { ProjectOrEpicItem } from '../types/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* Service class for handling project and epic operations.
|
|
13
|
+
*
|
|
14
|
+
* This class encapsulates all project and epic related business logic
|
|
15
|
+
* and coordinates between the API client, cache manager, and field mapper.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ProjectEpicService {
|
|
18
|
+
private readonly apiClient;
|
|
19
|
+
private readonly cacheManager;
|
|
20
|
+
constructor(apiClient: PodioApiClient, cacheManager: CacheManager);
|
|
21
|
+
/**
|
|
22
|
+
* List projects with optional cache refresh
|
|
23
|
+
*/
|
|
24
|
+
listProjects(appId: number, fieldMapper: FieldMapper, refreshCache?: boolean): Promise<ProjectOrEpicItem[]>;
|
|
25
|
+
/**
|
|
26
|
+
* List epics with optional cache refresh
|
|
27
|
+
*/
|
|
28
|
+
listEpics(appId: number, fieldMapper: FieldMapper, refreshCache?: boolean): Promise<ProjectOrEpicItem[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Get project and epic suggestions based on input
|
|
31
|
+
*/
|
|
32
|
+
getSuggestions(title: string, description?: string, appId?: number): Promise<{
|
|
33
|
+
projects: any[];
|
|
34
|
+
epics: any[];
|
|
35
|
+
}>;
|
|
36
|
+
private readonly TITLE_FIELD_NAMES;
|
|
37
|
+
private readonly DEFAULT_ITEM_TITLE;
|
|
38
|
+
private readonly DEFAULT_ITEM_FETCH_LIMIT;
|
|
39
|
+
private readonly MAX_ITEM_FETCH_LIMIT;
|
|
40
|
+
/**
|
|
41
|
+
* Extract title from an item without requiring a field mapper
|
|
42
|
+
* This is used when fetching items from referenced apps that may have different field structures
|
|
43
|
+
*
|
|
44
|
+
* Performance optimized: Single pass through fields array with early returns
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* // Returns "Project Alpha" from a title field
|
|
48
|
+
* extractItemTitle({ fields: [{ label: 'Title', values: ['Project Alpha'] }] })
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Returns "Task 123" from a name field
|
|
52
|
+
* extractItemTitle({ fields: [{ external_id: 'name', values: [{ value: 'Task 123' }] }] })
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Returns default for null item
|
|
56
|
+
* extractItemTitle(null) // "Untitled Item"
|
|
57
|
+
*/
|
|
58
|
+
private extractItemTitle;
|
|
59
|
+
/**
|
|
60
|
+
* Fetch projects from referenced app field
|
|
61
|
+
*/
|
|
62
|
+
private fetchProjectsFromReferencedApp;
|
|
63
|
+
/**
|
|
64
|
+
* Fetch epics from referenced app field
|
|
65
|
+
*/
|
|
66
|
+
private fetchEpicsFromReferencedApp;
|
|
67
|
+
/**
|
|
68
|
+
* Generic method to fetch items from a referenced app field
|
|
69
|
+
* Reduces code duplication between project and epic fetching
|
|
70
|
+
*/
|
|
71
|
+
private fetchItemsFromReferencedApp;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=project-epic-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-epic-service.d.ts","sourceRoot":"","sources":["../../src/services/project-epic-service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAa,MAAM,mBAAmB,CAAC;AA8BtE;;;;;GAKG;AACH,qBAAa,kBAAkB;IAE3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,SAAS,EAAE,cAAc,EACzB,YAAY,EAAE,YAAY;IAG7C;;OAEG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,EACxB,YAAY,UAAQ,GACnB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAY/B;;OAEG;IACG,SAAS,CACb,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,WAAW,EACxB,YAAY,UAAQ,GACnB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAY/B;;OAEG;IACG,cAAc,CAClB,KAAK,EAAE,MAAM,EACb,WAAW,SAAK,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAC;QAAC,KAAK,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC;IAc7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwC;IAC1E,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IACtD,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAO;IAChD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAO;IAE5C;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,gBAAgB;IA2DxB;;OAEG;YACW,8BAA8B;IAM5C;;OAEG;YACW,2BAA2B;IAMzC;;;OAGG;YACW,2BAA2B;CAgI1C"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Project and Epic Service
|
|
3
|
+
*
|
|
4
|
+
* This service handles all project and epic related operations including
|
|
5
|
+
* fetching, caching, and suggestion logic.
|
|
6
|
+
*/
|
|
7
|
+
import { debug } from '../utils/debug.js';
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to check if a value is an app reference
|
|
10
|
+
*/
|
|
11
|
+
function isAppReference(value) {
|
|
12
|
+
return (typeof value === 'object' &&
|
|
13
|
+
value !== null &&
|
|
14
|
+
'app_id' in value &&
|
|
15
|
+
typeof value.app_id === 'number');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to check if an item is valid (not null or undefined)
|
|
19
|
+
*/
|
|
20
|
+
function isValidPodioItem(item) {
|
|
21
|
+
return item !== null && item !== undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Service class for handling project and epic operations.
|
|
25
|
+
*
|
|
26
|
+
* This class encapsulates all project and epic related business logic
|
|
27
|
+
* and coordinates between the API client, cache manager, and field mapper.
|
|
28
|
+
*/
|
|
29
|
+
export class ProjectEpicService {
|
|
30
|
+
apiClient;
|
|
31
|
+
cacheManager;
|
|
32
|
+
constructor(apiClient, cacheManager) {
|
|
33
|
+
this.apiClient = apiClient;
|
|
34
|
+
this.cacheManager = cacheManager;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* List projects with optional cache refresh
|
|
38
|
+
*/
|
|
39
|
+
async listProjects(appId, fieldMapper, refreshCache = false) {
|
|
40
|
+
if (!refreshCache && (await this.cacheManager.getProjects(appId))) {
|
|
41
|
+
return await this.cacheManager.getProjects(appId);
|
|
42
|
+
}
|
|
43
|
+
// Fetch projects and cache them
|
|
44
|
+
const projects = await this.fetchProjectsFromReferencedApp(fieldMapper);
|
|
45
|
+
await this.cacheManager.setProjects(appId, projects);
|
|
46
|
+
return projects;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List epics with optional cache refresh
|
|
50
|
+
*/
|
|
51
|
+
async listEpics(appId, fieldMapper, refreshCache = false) {
|
|
52
|
+
if (!refreshCache && (await this.cacheManager.getEpics(appId))) {
|
|
53
|
+
return await this.cacheManager.getEpics(appId);
|
|
54
|
+
}
|
|
55
|
+
// Fetch epics and cache them
|
|
56
|
+
const epics = await this.fetchEpicsFromReferencedApp(fieldMapper);
|
|
57
|
+
await this.cacheManager.setEpics(appId, epics);
|
|
58
|
+
return epics;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get project and epic suggestions based on input
|
|
62
|
+
*/
|
|
63
|
+
async getSuggestions(title, description = '', appId) {
|
|
64
|
+
const input = `${title} ${description}`;
|
|
65
|
+
const projects = await this.cacheManager.getProjectSuggestions(input, appId);
|
|
66
|
+
const epics = await this.cacheManager.getEpicSuggestions(input, appId);
|
|
67
|
+
return { projects, epics };
|
|
68
|
+
}
|
|
69
|
+
// ===============================
|
|
70
|
+
// PRIVATE HELPER METHODS
|
|
71
|
+
// ===============================
|
|
72
|
+
// Constants for field name patterns and limits
|
|
73
|
+
TITLE_FIELD_NAMES = ['title', 'name'];
|
|
74
|
+
DEFAULT_ITEM_TITLE = 'Untitled Item';
|
|
75
|
+
DEFAULT_ITEM_FETCH_LIMIT = 100;
|
|
76
|
+
MAX_ITEM_FETCH_LIMIT = 500;
|
|
77
|
+
/**
|
|
78
|
+
* Extract title from an item without requiring a field mapper
|
|
79
|
+
* This is used when fetching items from referenced apps that may have different field structures
|
|
80
|
+
*
|
|
81
|
+
* Performance optimized: Single pass through fields array with early returns
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* // Returns "Project Alpha" from a title field
|
|
85
|
+
* extractItemTitle({ fields: [{ label: 'Title', values: ['Project Alpha'] }] })
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // Returns "Task 123" from a name field
|
|
89
|
+
* extractItemTitle({ fields: [{ external_id: 'name', values: [{ value: 'Task 123' }] }] })
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Returns default for null item
|
|
93
|
+
* extractItemTitle(null) // "Untitled Item"
|
|
94
|
+
*/
|
|
95
|
+
extractItemTitle(item) {
|
|
96
|
+
// Use type guard for explicit null/undefined handling
|
|
97
|
+
if (!isValidPodioItem(item)) {
|
|
98
|
+
return this.DEFAULT_ITEM_TITLE;
|
|
99
|
+
}
|
|
100
|
+
// Try to find a title field in the item's fields
|
|
101
|
+
if (item.fields && Array.isArray(item.fields)) {
|
|
102
|
+
let firstTextField = null;
|
|
103
|
+
// Single pass through fields for better performance
|
|
104
|
+
for (const field of item.fields) {
|
|
105
|
+
// Pre-compute lowercase values once to avoid repeated calls
|
|
106
|
+
const lowerLabel = field.label?.toLowerCase();
|
|
107
|
+
const lowerExternalId = field.external_id?.toLowerCase();
|
|
108
|
+
// Check for title/name fields first (highest priority)
|
|
109
|
+
if ((lowerLabel && this.TITLE_FIELD_NAMES.includes(lowerLabel)) ||
|
|
110
|
+
(lowerExternalId && this.TITLE_FIELD_NAMES.includes(lowerExternalId))) {
|
|
111
|
+
// Found a title field - extract value and return immediately
|
|
112
|
+
if (field.values && field.values.length > 0) {
|
|
113
|
+
const value = field.values[0];
|
|
114
|
+
// Handle object values with nested structure
|
|
115
|
+
if (typeof value === 'object' && value?.value) {
|
|
116
|
+
return String(value.value);
|
|
117
|
+
}
|
|
118
|
+
// Handle direct string values
|
|
119
|
+
if (typeof value === 'string') {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Track first text field as fallback (only if we haven't found one yet)
|
|
125
|
+
if (!firstTextField && field.type === 'text') {
|
|
126
|
+
firstTextField = field;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Use first text field as fallback
|
|
130
|
+
if (firstTextField && firstTextField.values && firstTextField.values.length > 0) {
|
|
131
|
+
const value = firstTextField.values[0];
|
|
132
|
+
if (typeof value === 'object' && value?.value) {
|
|
133
|
+
return String(value.value);
|
|
134
|
+
}
|
|
135
|
+
if (typeof value === 'string') {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Fallback to app_item_id_formatted or item_id
|
|
141
|
+
return item.app_item_id_formatted || `Item #${item.item_id}`;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Fetch projects from referenced app field
|
|
145
|
+
*/
|
|
146
|
+
async fetchProjectsFromReferencedApp(fieldMapper) {
|
|
147
|
+
return this.fetchItemsFromReferencedApp(fieldMapper, 'project', 'Project');
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Fetch epics from referenced app field
|
|
151
|
+
*/
|
|
152
|
+
async fetchEpicsFromReferencedApp(fieldMapper) {
|
|
153
|
+
return this.fetchItemsFromReferencedApp(fieldMapper, 'epic', 'Epic');
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Generic method to fetch items from a referenced app field
|
|
157
|
+
* Reduces code duplication between project and epic fetching
|
|
158
|
+
*/
|
|
159
|
+
async fetchItemsFromReferencedApp(fieldMapper, fieldName, displayName) {
|
|
160
|
+
const serviceName = `${displayName} Service`;
|
|
161
|
+
const field = fieldMapper.findField(fieldName);
|
|
162
|
+
// Log field discovery for debugging
|
|
163
|
+
if (!field) {
|
|
164
|
+
debug.log(serviceName, `No ${fieldName} field found in app structure`);
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
if (field.type !== 'app') {
|
|
168
|
+
debug.warn(serviceName, `${displayName} field exists but is type '${field.type}' instead of 'app'`);
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
// Log the field configuration for debugging
|
|
172
|
+
debug.log(serviceName, `${displayName} field found:`, {
|
|
173
|
+
field_id: field.field_id,
|
|
174
|
+
external_id: field.external_id,
|
|
175
|
+
type: field.type,
|
|
176
|
+
config: field.config,
|
|
177
|
+
});
|
|
178
|
+
// Try to get referenced app from multiple possible locations
|
|
179
|
+
let referencedApp = field.config?.referenced_apps?.[0];
|
|
180
|
+
// Fallback to settings.referenceable_types if referenced_apps is not available
|
|
181
|
+
if (!referencedApp && field.config?.settings?.referenceable_types) {
|
|
182
|
+
const referenceableTypes = field.config.settings.referenceable_types;
|
|
183
|
+
debug.log(serviceName, 'No referenced_apps found, checking referenceable_types:', referenceableTypes);
|
|
184
|
+
// Validate that referenceable_types is an array before processing
|
|
185
|
+
if (Array.isArray(referenceableTypes) && referenceableTypes.length > 0) {
|
|
186
|
+
const firstType = referenceableTypes[0];
|
|
187
|
+
if (typeof firstType === 'number') {
|
|
188
|
+
referencedApp = { app_id: firstType, name: `${displayName} App` };
|
|
189
|
+
debug.log(serviceName, `Using numeric app ID from referenceable_types: ${firstType}`);
|
|
190
|
+
}
|
|
191
|
+
else if (isAppReference(firstType)) {
|
|
192
|
+
referencedApp = firstType;
|
|
193
|
+
debug.log(serviceName, `Using app object from referenceable_types: ${firstType.app_id}`);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
debug.warn(serviceName, 'First referenceable_type is not a valid app reference:', firstType);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (!Array.isArray(referenceableTypes)) {
|
|
200
|
+
debug.warn(serviceName, 'referenceable_types is not an array:', typeof referenceableTypes);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Check for app_id directly in config
|
|
204
|
+
if (!referencedApp && field.config?.app_id) {
|
|
205
|
+
debug.log(serviceName, `Using app_id directly from config: ${field.config.app_id}`);
|
|
206
|
+
referencedApp = { app_id: field.config.app_id, name: `${displayName} App` };
|
|
207
|
+
}
|
|
208
|
+
if (!referencedApp) {
|
|
209
|
+
debug.warn(serviceName, `${displayName} field has no referenced app configuration`);
|
|
210
|
+
debug.log(serviceName, 'Full field config:', JSON.stringify(field.config, null, 2));
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
debug.info(serviceName, `Fetching ${fieldName}s from referenced app ID: ${referencedApp.app_id}`);
|
|
214
|
+
// Get item fetch limit from environment variable with validation
|
|
215
|
+
let itemLimit = this.DEFAULT_ITEM_FETCH_LIMIT;
|
|
216
|
+
if (process.env.PODIO_ITEM_FETCH_LIMIT) {
|
|
217
|
+
const parsedLimit = parseInt(process.env.PODIO_ITEM_FETCH_LIMIT, 10);
|
|
218
|
+
if (!isNaN(parsedLimit) && parsedLimit > 0 && parsedLimit <= this.MAX_ITEM_FETCH_LIMIT) {
|
|
219
|
+
itemLimit = parsedLimit;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
debug.warn(serviceName, `Invalid PODIO_ITEM_FETCH_LIMIT: ${process.env.PODIO_ITEM_FETCH_LIMIT}, using default: ${this.DEFAULT_ITEM_FETCH_LIMIT}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const response = await this.apiClient.filterItems(referencedApp.app_id, {}, itemLimit);
|
|
227
|
+
debug.info(serviceName, `Found ${response.items.length} ${fieldName}s from app ${referencedApp.app_id} (limit: ${itemLimit})`);
|
|
228
|
+
return response.items.map((item) => ({
|
|
229
|
+
item_id: item.item_id,
|
|
230
|
+
// Use item's title property directly or fallback to extracting from fields
|
|
231
|
+
title: item.title || this.extractItemTitle(item),
|
|
232
|
+
link: item.link,
|
|
233
|
+
app: {
|
|
234
|
+
app_id: referencedApp.app_id,
|
|
235
|
+
name: referencedApp.name || `${displayName} App`,
|
|
236
|
+
},
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
debug.error(serviceName, `Error fetching ${fieldName}s from app ${referencedApp.app_id}:`, error);
|
|
241
|
+
// Implement graceful error recovery - return empty array instead of throwing
|
|
242
|
+
// This allows the application to continue functioning even if one data source fails
|
|
243
|
+
debug.warn(serviceName, `Returning empty array for ${fieldName}s due to API error. The application will continue with limited functionality.`);
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=project-epic-service.js.map
|