UNPKG

@mulutime/plugin-sdk

Version:

SDK for developing MuluTime booking platform plugins

131 lines 5.38 kB
"use strict"; // ============================================================================= // PLUGIN TEMPLATES AND DEVELOPMENT HELPERS // ============================================================================= Object.defineProperty(exports, "__esModule", { value: true }); exports.PluginTestUtils = void 0; // ============================================================================= // DEVELOPMENT AND TESTING UTILITIES // ============================================================================= class PluginTestUtils { createMockContext(overrides = {}) { const mockStorage = new Map(); const mockLogs = []; const mockEvents = []; const defaultContext = { userId: 'test-user-id', organizationId: 'test-org-id', pluginId: 'test-plugin-id', permissions: [], config: {}, logger: { debug: (message, meta) => mockLogs.push({ level: 'debug', message, meta }), info: (message, meta) => mockLogs.push({ level: 'info', message, meta }), warn: (message, meta) => mockLogs.push({ level: 'warn', message, meta }), error: (message, error, meta) => mockLogs.push({ level: 'error', message, meta: { ...meta, error } }) }, storage: { get: async (key) => mockStorage.get(key) || null, set: async (key, value) => { mockStorage.set(key, value); }, delete: async (key) => { mockStorage.delete(key); }, list: async (prefix) => { const keys = Array.from(mockStorage.keys()); return prefix ? keys.filter(k => k.startsWith(prefix)) : keys; } }, http: new MockPluginAPIClient(), errors: { reportUserError: (message, type, details) => { mockLogs.push({ level: type || 'error', message, meta: details }); }, reportSystemError: (error, context) => { mockLogs.push({ level: 'error', message: typeof error === 'string' ? error : error.message, meta: context }); }, clearErrors: () => { mockLogs.length = 0; }, getErrors: () => mockLogs .filter(log => ['error', 'critical'].includes(log.level)) .map((log, idx) => ({ id: `mock-error-${idx}`, pluginId: 'test-plugin-id', timestamp: new Date().toISOString(), resolved: false, message: log.message, type: (log.level === 'error' || log.level === 'critical' ? log.level : 'error'), details: log.meta })) }, api: new MockPluginAPIClient(), systemBaseUrl: 'https://test.mulutime.com', apiToken: 'test-token' }; return { ...defaultContext, ...overrides, mockStorage, mockLogs, mockEvents }; } createMockEvent(type, data) { return { id: `event-${Date.now()}`, type, data, timestamp: new Date().toISOString(), organizationId: 'test-org-id', userId: 'test-user-id' }; } createMockAPIRequest(path, method, data) { return { params: {}, query: {}, body: data, headers: { 'content-type': 'application/json' }, userId: 'test-user-id', organizationId: 'test-org-id' }; } validateManifest(manifest) { const errors = []; if (!manifest.id) errors.push('Manifest ID is required'); if (!manifest.name) errors.push('Manifest name is required'); if (!manifest.version) errors.push('Manifest version is required'); if (!manifest.provider) errors.push('Manifest provider is required'); if (!manifest.type || manifest.type.length === 0) errors.push('At least one integration type is required'); if (!manifest.category) errors.push('Manifest category is required'); if (!manifest.permissions) errors.push('Manifest permissions are required'); if (!manifest.main) errors.push('Manifest main entry point is required'); return { valid: errors.length === 0, errors: errors.length > 0 ? errors : undefined }; } } exports.PluginTestUtils = PluginTestUtils; // ============================================================================= // MOCK CLASSES FOR TESTING // ============================================================================= class MockPluginAPIClient { async get(url, options) { return new Response(JSON.stringify({}), { status: 200 }); } async post(url, data, options) { return new Response(JSON.stringify({}), { status: 200 }); } async put(url, data, options) { return new Response(JSON.stringify({}), { status: 200 }); } async delete(url, options) { return new Response(JSON.stringify({}), { status: 200 }); } } //# sourceMappingURL=testUtilities.js.map