screenright-client 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -9
- package/package.json +1 -1
- package/src/index.ts +10 -9
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Page } from '@playwright/test';
|
2
|
-
export declare const initializeScreenwright: () => Promise<void>;
|
2
|
+
export declare const initializeScreenwright: (diagramId?: string) => Promise<void>;
|
3
3
|
export declare const finalize: () => Promise<void>;
|
4
4
|
/**
|
5
5
|
* Get screen capture.
|
package/dist/index.js
CHANGED
@@ -11,7 +11,7 @@ import fetch from 'node-fetch';
|
|
11
11
|
import process from 'node:process';
|
12
12
|
import FormData from 'form-data';
|
13
13
|
import { setTimeout } from 'timers/promises';
|
14
|
-
const result = { screenshotItemAttributes: [] };
|
14
|
+
const result = { diagramId: "", screenshotItemAttributes: [] };
|
15
15
|
let deploymentId = null;
|
16
16
|
const deploymentToken = process.env.SCREENRIGHT_DEPLOYMENT_TOKEN || '';
|
17
17
|
const baseUrl = () => {
|
@@ -21,14 +21,15 @@ const errorOccurred = (message) => {
|
|
21
21
|
console.error('[ScreenRight] Error occurred', message);
|
22
22
|
deploymentId = null;
|
23
23
|
};
|
24
|
-
export const initializeScreenwright = () => __awaiter(void 0, void 0, void 0, function* () {
|
25
|
-
const
|
26
|
-
if (!
|
24
|
+
export const initializeScreenwright = (diagramId) => __awaiter(void 0, void 0, void 0, function* () {
|
25
|
+
const _diagramId = process.env.SCREENRIGHT_DIAGRAM_ID;
|
26
|
+
if (!_diagramId || !deploymentToken) {
|
27
27
|
errorOccurred('Not set require environments.');
|
28
28
|
return;
|
29
29
|
}
|
30
|
+
result.diagramId = _diagramId;
|
30
31
|
try {
|
31
|
-
const response = yield fetch(`${baseUrl()}/diagrams/${diagramId}/deployments`, {
|
32
|
+
const response = yield fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments`, {
|
32
33
|
method: 'POST',
|
33
34
|
body: JSON.stringify({ deployment_token: deploymentToken }),
|
34
35
|
headers: { 'Content-Type': 'application/json' }
|
@@ -48,8 +49,7 @@ export const finalize = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
49
|
if (!deploymentId) {
|
49
50
|
return;
|
50
51
|
}
|
51
|
-
|
52
|
-
yield fetch(`${baseUrl()}/diagrams/${diagramId}/deployments/${deploymentId}/done_upload`, {
|
52
|
+
yield fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments/${deploymentId}/done_upload`, {
|
53
53
|
method: 'PUT',
|
54
54
|
body: JSON.stringify({ deployment_token: deploymentToken, blueprint: JSON.stringify({ screenshotItemAttributes: result.screenshotItemAttributes }) }),
|
55
55
|
headers: { 'Content-Type': 'application/json' }
|
@@ -84,8 +84,7 @@ export const capture = (page, key, title, parentKey, options = { waitMillisecond
|
|
84
84
|
const buffer = yield page.screenshot({ fullPage: true, type: 'jpeg' });
|
85
85
|
const formData = new FormData();
|
86
86
|
formData.append('file', buffer, fileName);
|
87
|
-
const
|
88
|
-
const response = yield fetch(`${baseUrl()}/diagrams/${diagramId}/deployments/${deploymentId}/screenshot`, {
|
87
|
+
const response = yield fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments/${deploymentId}/screenshot`, {
|
89
88
|
method: 'POST',
|
90
89
|
headers: {
|
91
90
|
'X-File-Key': key,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -13,10 +13,11 @@ type ScreenshotItemAttribute = {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
type Result = {
|
16
|
+
diagramId: string
|
16
17
|
screenshotItemAttributes: ScreenshotItemAttribute[]
|
17
18
|
}
|
18
19
|
|
19
|
-
const result: Result = { screenshotItemAttributes: [] }
|
20
|
+
const result: Result = { diagramId: "", screenshotItemAttributes: [] }
|
20
21
|
|
21
22
|
let deploymentId: string | null = null
|
22
23
|
const deploymentToken: string = process.env.SCREENRIGHT_DEPLOYMENT_TOKEN || ''
|
@@ -30,16 +31,18 @@ const errorOccurred = (message: string) => {
|
|
30
31
|
deploymentId = null
|
31
32
|
}
|
32
33
|
|
33
|
-
export const initializeScreenwright = async () => {
|
34
|
+
export const initializeScreenwright = async (diagramId?: string) => {
|
34
35
|
|
35
|
-
const
|
36
|
-
if (!
|
36
|
+
const _diagramId = process.env.SCREENRIGHT_DIAGRAM_ID
|
37
|
+
if (!_diagramId || !deploymentToken) {
|
37
38
|
errorOccurred('Not set require environments.')
|
38
39
|
return
|
39
40
|
}
|
40
41
|
|
42
|
+
result.diagramId = _diagramId
|
43
|
+
|
41
44
|
try {
|
42
|
-
const response = await fetch(`${baseUrl()}/diagrams/${diagramId}/deployments`, {
|
45
|
+
const response = await fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments`, {
|
43
46
|
method: 'POST',
|
44
47
|
body: JSON.stringify({ deployment_token: deploymentToken }),
|
45
48
|
headers: { 'Content-Type': 'application/json' }
|
@@ -62,8 +65,7 @@ export const finalize = async () => {
|
|
62
65
|
return
|
63
66
|
}
|
64
67
|
|
65
|
-
|
66
|
-
await fetch(`${baseUrl()}/diagrams/${diagramId}/deployments/${deploymentId}/done_upload`, {
|
68
|
+
await fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments/${deploymentId}/done_upload`, {
|
67
69
|
method: 'PUT',
|
68
70
|
body: JSON.stringify({ deployment_token: deploymentToken, blueprint: JSON.stringify({ screenshotItemAttributes: result.screenshotItemAttributes}) }),
|
69
71
|
headers: { 'Content-Type': 'application/json' }
|
@@ -112,8 +114,7 @@ export const capture = async (
|
|
112
114
|
|
113
115
|
formData.append('file', buffer, fileName)
|
114
116
|
|
115
|
-
const
|
116
|
-
const response = await fetch(`${baseUrl()}/diagrams/${diagramId}/deployments/${deploymentId}/screenshot`, {
|
117
|
+
const response = await fetch(`${baseUrl()}/diagrams/${result.diagramId}/deployments/${deploymentId}/screenshot`, {
|
117
118
|
method: 'POST',
|
118
119
|
headers: {
|
119
120
|
'X-File-Key': key,
|