-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
67 lines (56 loc) · 1.97 KB
/
Copy pathexample.js
File metadata and controls
67 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { EdgeAddonsAPIClient } from './src/api-client.js';
/**
* Example: Upload and publish an Edge extension
*
* This example demonstrates how to use the EdgeAddonsAPIClient
* programmatically (without the CLI).
*/
async function main() {
// Initialize the client
const client = new EdgeAddonsAPIClient({
clientId: 'your-client-id',
apiKey: 'your-api-key',
productId: 'your-product-id',
apiEndpoint: 'https://api.addons.microsoftedge.microsoft.com' // optional
});
try {
// 1. Upload the package
console.log('Uploading package...');
const uploadResult = await client.uploadPackage('./path/to/your-extension.zip');
console.log('Upload initiated:', uploadResult.operationId);
// 2. Wait for upload to complete
console.log('Waiting for upload to complete...');
const uploadStatus = await client.waitForOperation(
uploadResult.operationId,
'upload',
10, // retry limit
5 // retry delay in seconds
);
if (uploadStatus.status !== 'Succeeded') {
throw new Error(`Upload failed: ${uploadStatus.message}`);
}
console.log('Upload completed successfully!');
// 3. Publish the submission
console.log('Publishing submission...');
const publishResult = await client.publishSubmission('Bug fixes and improvements');
console.log('Publish initiated:', publishResult.operationId);
// 4. Wait for publish to complete
console.log('Waiting for publish to complete...');
const publishStatus = await client.waitForOperation(
publishResult.operationId,
'publish',
20, // retry limit (publishing may take longer)
10 // retry delay in seconds
);
if (publishStatus.status !== 'Succeeded') {
throw new Error(`Publish failed: ${publishStatus.message}`);
}
console.log('Extension published successfully!');
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
// Uncomment to run:
// main();
export { main };