@ever-works/screenshotone-plugin 1.0.0 → 1.0.3
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/dist/index.cjs +488 -0
- package/dist/index.d.cts +99 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.js +463 -0
- package/package.json +94 -81
- package/LICENSE +0 -661
- package/src/__tests__/screenshotone.plugin.spec.ts +0 -349
- package/src/index.ts +0 -2
- package/src/screenshotone.plugin.ts +0 -542
- package/tsconfig.json +0 -23
- package/tsup.config.ts +0 -12
- package/vitest.config.ts +0 -13
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { ScreenshotOnePlugin } from '../screenshotone.plugin.js';
|
|
3
|
-
import type { PluginContext, ScreenshotOptions } from '@ever-works/plugin';
|
|
4
|
-
|
|
5
|
-
// Mock the screenshotone-api-sdk module
|
|
6
|
-
vi.mock('screenshotone-api-sdk', () => {
|
|
7
|
-
const mockTakeOptions = {
|
|
8
|
-
url: vi.fn().mockReturnThis(),
|
|
9
|
-
viewportWidth: vi.fn().mockReturnThis(),
|
|
10
|
-
viewportHeight: vi.fn().mockReturnThis(),
|
|
11
|
-
format: vi.fn().mockReturnThis(),
|
|
12
|
-
fullPage: vi.fn().mockReturnThis(),
|
|
13
|
-
deviceScaleFactor: vi.fn().mockReturnThis(),
|
|
14
|
-
blockAds: vi.fn().mockReturnThis(),
|
|
15
|
-
blockTrackers: vi.fn().mockReturnThis(),
|
|
16
|
-
blockCookieBanners: vi.fn().mockReturnThis(),
|
|
17
|
-
delay: vi.fn().mockReturnThis(),
|
|
18
|
-
cache: vi.fn().mockReturnThis(),
|
|
19
|
-
cacheTtl: vi.fn().mockReturnThis(),
|
|
20
|
-
selector: vi.fn().mockReturnThis(),
|
|
21
|
-
userAgent: vi.fn().mockReturnThis()
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
Client: vi.fn().mockImplementation(function () {
|
|
26
|
-
return {
|
|
27
|
-
take: vi.fn().mockResolvedValue({
|
|
28
|
-
arrayBuffer: vi.fn().mockResolvedValue(new ArrayBuffer(100))
|
|
29
|
-
}),
|
|
30
|
-
generateTakeURL: vi.fn().mockReturnValue('https://api.screenshotone.com/take?url=test'),
|
|
31
|
-
generateSignedTakeURL: vi
|
|
32
|
-
.fn()
|
|
33
|
-
.mockReturnValue('https://api.screenshotone.com/take?url=test&signature=abc')
|
|
34
|
-
};
|
|
35
|
-
}),
|
|
36
|
-
TakeOptions: {
|
|
37
|
-
url: vi.fn().mockReturnValue(mockTakeOptions)
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('ScreenshotOnePlugin', () => {
|
|
43
|
-
let plugin: ScreenshotOnePlugin;
|
|
44
|
-
let mockContext: PluginContext;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
plugin = new ScreenshotOnePlugin();
|
|
48
|
-
mockContext = {
|
|
49
|
-
pluginId: 'screenshotone',
|
|
50
|
-
logger: {
|
|
51
|
-
log: vi.fn(),
|
|
52
|
-
error: vi.fn(),
|
|
53
|
-
warn: vi.fn(),
|
|
54
|
-
debug: vi.fn()
|
|
55
|
-
},
|
|
56
|
-
cache: {} as any,
|
|
57
|
-
http: {} as any,
|
|
58
|
-
env: {} as any,
|
|
59
|
-
envVars: {} as any,
|
|
60
|
-
services: {} as any,
|
|
61
|
-
getSettings: vi.fn().mockResolvedValue({}),
|
|
62
|
-
getResolvedSettings: vi.fn().mockResolvedValue({}),
|
|
63
|
-
onEvent: vi.fn(),
|
|
64
|
-
emitEvent: vi.fn(),
|
|
65
|
-
registerCustomCapability: vi.fn(),
|
|
66
|
-
getCustomCapability: vi.fn(),
|
|
67
|
-
hasCustomCapability: vi.fn(),
|
|
68
|
-
listCustomCapabilities: vi.fn()
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
vi.clearAllMocks();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('Plugin Metadata', () => {
|
|
77
|
-
it('should have correct plugin metadata', () => {
|
|
78
|
-
expect(plugin.id).toBe('screenshotone');
|
|
79
|
-
expect(plugin.name).toBe('ScreenshotOne');
|
|
80
|
-
expect(plugin.version).toBe('1.0.0');
|
|
81
|
-
expect(plugin.category).toBe('screenshot');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should have screenshot capability', () => {
|
|
85
|
-
expect(plugin.capabilities).toContain('screenshot');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should have provider name', () => {
|
|
89
|
-
expect(plugin.providerName).toBe('ScreenshotOne');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should have hybrid configuration mode', () => {
|
|
93
|
-
expect(plugin.configurationMode).toBe('hybrid');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('Settings Schema', () => {
|
|
98
|
-
it('should define accessKey as required', () => {
|
|
99
|
-
expect(plugin.settingsSchema.required).toContain('accessKey');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should mark accessKey as secret', () => {
|
|
103
|
-
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
104
|
-
expect(properties.accessKey['x-secret']).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should mark secretKey as secret', () => {
|
|
108
|
-
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
109
|
-
expect(properties.secretKey['x-secret']).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should have environment variable fallbacks', () => {
|
|
113
|
-
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
114
|
-
expect(properties.accessKey['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_ACCESS_KEY');
|
|
115
|
-
expect(properties.secretKey['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_SECRET_KEY');
|
|
116
|
-
expect(properties.viewportWidth['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_VIEWPORT_WIDTH');
|
|
117
|
-
expect(properties.viewportHeight['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_VIEWPORT_HEIGHT');
|
|
118
|
-
expect(properties.format['x-envVar']).toBe('PLUGIN_SCREENSHOTONE_FORMAT');
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should have default values for viewport settings', () => {
|
|
122
|
-
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
123
|
-
expect(properties.viewportWidth.default).toBe(1280);
|
|
124
|
-
expect(properties.viewportHeight.default).toBe(800);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should have default values for format and blocking options', () => {
|
|
128
|
-
const properties = plugin.settingsSchema.properties as Record<string, any>;
|
|
129
|
-
expect(properties.format.default).toBe('png');
|
|
130
|
-
expect(properties.fullPage.default).toBe(false);
|
|
131
|
-
expect(properties.blockAds.default).toBe(true);
|
|
132
|
-
expect(properties.blockTrackers.default).toBe(true);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('IScreenshotPlugin - capture', () => {
|
|
137
|
-
it('should capture screenshot successfully with settings', async () => {
|
|
138
|
-
await plugin.onLoad(mockContext);
|
|
139
|
-
|
|
140
|
-
const options: ScreenshotOptions = {
|
|
141
|
-
url: 'https://example.com',
|
|
142
|
-
settings: {
|
|
143
|
-
accessKey: 'test-access-key',
|
|
144
|
-
secretKey: 'test-secret-key'
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const result = await plugin.capture(options);
|
|
149
|
-
|
|
150
|
-
expect(result.success).toBe(true);
|
|
151
|
-
expect(result.imageBuffer).toBeDefined();
|
|
152
|
-
expect(result.imageBase64).toBeDefined();
|
|
153
|
-
expect(result.imageUrl).toBeDefined();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should fail when access key is not configured', async () => {
|
|
157
|
-
await plugin.onLoad(mockContext);
|
|
158
|
-
|
|
159
|
-
const options: ScreenshotOptions = {
|
|
160
|
-
url: 'https://example.com',
|
|
161
|
-
settings: {}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const result = await plugin.capture(options);
|
|
165
|
-
|
|
166
|
-
expect(result.success).toBe(false);
|
|
167
|
-
expect(result.error).toContain('access key not configured');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('should use provided viewport dimensions', async () => {
|
|
171
|
-
await plugin.onLoad(mockContext);
|
|
172
|
-
|
|
173
|
-
const options: ScreenshotOptions = {
|
|
174
|
-
url: 'https://example.com',
|
|
175
|
-
viewportWidth: 1920,
|
|
176
|
-
viewportHeight: 1080,
|
|
177
|
-
settings: {
|
|
178
|
-
accessKey: 'test-key'
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const result = await plugin.capture(options);
|
|
183
|
-
|
|
184
|
-
expect(result.success).toBe(true);
|
|
185
|
-
expect(result.width).toBe(1920);
|
|
186
|
-
expect(result.height).toBe(1080);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('IScreenshotPlugin - getScreenshotUrl', () => {
|
|
191
|
-
it('should generate URL with settings', async () => {
|
|
192
|
-
await plugin.onLoad(mockContext);
|
|
193
|
-
|
|
194
|
-
const options: ScreenshotOptions = {
|
|
195
|
-
url: 'https://example.com',
|
|
196
|
-
settings: {
|
|
197
|
-
accessKey: 'test-key'
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const url = await plugin.getScreenshotUrl(options);
|
|
202
|
-
|
|
203
|
-
expect(url).toBeDefined();
|
|
204
|
-
expect(url).toContain('api.screenshotone.com');
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('should generate signed URL when secret key is available', async () => {
|
|
208
|
-
await plugin.onLoad(mockContext);
|
|
209
|
-
|
|
210
|
-
const options: ScreenshotOptions = {
|
|
211
|
-
url: 'https://example.com',
|
|
212
|
-
settings: {
|
|
213
|
-
accessKey: 'test-key',
|
|
214
|
-
secretKey: 'test-secret'
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const url = await plugin.getScreenshotUrl(options);
|
|
219
|
-
|
|
220
|
-
expect(url).toBeDefined();
|
|
221
|
-
expect(url).toContain('signature');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('should return null when access key is missing', async () => {
|
|
225
|
-
await plugin.onLoad(mockContext);
|
|
226
|
-
|
|
227
|
-
const options: ScreenshotOptions = {
|
|
228
|
-
url: 'https://example.com',
|
|
229
|
-
settings: {}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const url = await plugin.getScreenshotUrl(options);
|
|
233
|
-
|
|
234
|
-
expect(url).toBeNull();
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
describe('IScreenshotPlugin - isAvailable', () => {
|
|
239
|
-
it('should return true when access key is configured', async () => {
|
|
240
|
-
(mockContext.getSettings as ReturnType<typeof vi.fn>).mockResolvedValue({ accessKey: 'test-key' });
|
|
241
|
-
await plugin.onLoad(mockContext);
|
|
242
|
-
const available = await plugin.isAvailable();
|
|
243
|
-
expect(available).toBe(true);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('should return false when not loaded', async () => {
|
|
247
|
-
const available = await plugin.isAvailable();
|
|
248
|
-
expect(available).toBe(false);
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
describe('IScreenshotPlugin - validateCredentials', () => {
|
|
253
|
-
it('should return invalid when plugin not initialized', async () => {
|
|
254
|
-
const result = await plugin.validateCredentials();
|
|
255
|
-
|
|
256
|
-
expect(result.valid).toBe(false);
|
|
257
|
-
expect(result.message).toContain('not initialized');
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('should return invalid when access key not configured', async () => {
|
|
261
|
-
vi.mocked(mockContext.getSettings).mockResolvedValue({});
|
|
262
|
-
await plugin.onLoad(mockContext);
|
|
263
|
-
|
|
264
|
-
const result = await plugin.validateCredentials();
|
|
265
|
-
|
|
266
|
-
expect(result.valid).toBe(false);
|
|
267
|
-
expect(result.message).toContain('Access key is not configured');
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('should return valid when credentials are configured', async () => {
|
|
271
|
-
vi.mocked(mockContext.getSettings).mockResolvedValue({
|
|
272
|
-
accessKey: 'test-key'
|
|
273
|
-
});
|
|
274
|
-
await plugin.onLoad(mockContext);
|
|
275
|
-
|
|
276
|
-
const result = await plugin.validateCredentials();
|
|
277
|
-
|
|
278
|
-
expect(result.valid).toBe(true);
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
describe('IScreenshotPlugin - getSupportedFormats', () => {
|
|
283
|
-
it('should return supported formats', () => {
|
|
284
|
-
const formats = plugin.getSupportedFormats();
|
|
285
|
-
|
|
286
|
-
expect(formats).toContain('png');
|
|
287
|
-
expect(formats).toContain('jpg');
|
|
288
|
-
expect(formats).toContain('jpeg');
|
|
289
|
-
expect(formats).toContain('webp');
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
describe('IScreenshotPlugin - getMaxDimensions', () => {
|
|
294
|
-
it('should return maximum viewport dimensions', () => {
|
|
295
|
-
const dimensions = plugin.getMaxDimensions();
|
|
296
|
-
|
|
297
|
-
expect(dimensions.width).toBe(3840);
|
|
298
|
-
expect(dimensions.height).toBe(2160);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
describe('Lifecycle', () => {
|
|
303
|
-
it('should log on load', async () => {
|
|
304
|
-
await plugin.onLoad(mockContext);
|
|
305
|
-
expect(mockContext.logger.log).toHaveBeenCalledWith('ScreenshotOne Plugin loaded');
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('should clear context on unload', async () => {
|
|
309
|
-
await plugin.onLoad(mockContext);
|
|
310
|
-
await plugin.onUnload();
|
|
311
|
-
// Context should be cleared - validateCredentials should fail
|
|
312
|
-
const result = await plugin.validateCredentials();
|
|
313
|
-
expect(result.valid).toBe(false);
|
|
314
|
-
expect(result.message).toContain('not initialized');
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe('healthCheck', () => {
|
|
319
|
-
it('should return healthy status', async () => {
|
|
320
|
-
const health = await plugin.healthCheck();
|
|
321
|
-
|
|
322
|
-
expect(health.status).toBe('healthy');
|
|
323
|
-
expect(health.checkedAt).toBeDefined();
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
describe('getManifest', () => {
|
|
328
|
-
it('should return correct manifest', () => {
|
|
329
|
-
const manifest = plugin.getManifest();
|
|
330
|
-
|
|
331
|
-
expect(manifest.id).toBe('screenshotone');
|
|
332
|
-
expect(manifest.name).toBe('ScreenshotOne');
|
|
333
|
-
expect(manifest.version).toBe('1.0.0');
|
|
334
|
-
expect(manifest.category).toBe('screenshot');
|
|
335
|
-
expect(manifest.capabilities).toContain('screenshot');
|
|
336
|
-
expect(manifest.builtIn).toBe(false);
|
|
337
|
-
expect(manifest.systemPlugin).toBe(false);
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
it('should have icon configuration', () => {
|
|
341
|
-
const manifest = plugin.getManifest();
|
|
342
|
-
|
|
343
|
-
expect(manifest.icon).toBeDefined();
|
|
344
|
-
expect(manifest.icon?.type).toBe('lucide');
|
|
345
|
-
expect(manifest.icon?.value).toBe('Camera');
|
|
346
|
-
expect(manifest.icon?.backgroundColor).toBe('#4f46e5');
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
});
|
package/src/index.ts
DELETED