screenright-client 0.9.8 → 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.mjs +0 -69
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,
|
package/dist/index.mjs
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
|
-
import * as fs from 'fs';
|
11
|
-
import fetch from 'node-fetch';
|
12
|
-
const tmpDir = 'screenright/tmp';
|
13
|
-
const result = { screenshotItemAttributes: [] };
|
14
|
-
let deploymentId = null;
|
15
|
-
export const initializeScreenwright = () => __awaiter(void 0, void 0, void 0, function* () {
|
16
|
-
const baseUrl = `${process.env.SCREENRIGHT_ENDPOINT}/client_api`;
|
17
|
-
const diagramId = process.env.SCREENRIGHT_DIAGRAM_ID;
|
18
|
-
const deploymentToken = process.env.SCREENRIGHT_DEVELOPMENT_TOKEN;
|
19
|
-
const response = yield fetch(`${baseUrl}/diagrams/${diagramId}/deployments`, {
|
20
|
-
method: 'POST',
|
21
|
-
body: JSON.stringify({ deployment_token: deploymentToken }),
|
22
|
-
headers: { 'Content-Type': 'application/json' }
|
23
|
-
});
|
24
|
-
const body = yield response.text();
|
25
|
-
const json = JSON.parse(body);
|
26
|
-
deploymentId = json.id;
|
27
|
-
process.on('exit', (exitCode) => __awaiter(void 0, void 0, void 0, function* () {
|
28
|
-
if (exitCode === 0) {
|
29
|
-
fs.writeFileSync(`${tmpDir}/result.json`, JSON.stringify({
|
30
|
-
screenshotItemAttributes: result.screenshotItemAttributes,
|
31
|
-
}));
|
32
|
-
yield fetch(`${baseUrl}/diagrams/${diagramId}/deployments/${deploymentId}/done_upload`, {
|
33
|
-
method: 'PUT',
|
34
|
-
body: JSON.stringify({ deployment_token: deploymentToken }),
|
35
|
-
headers: { 'Content-Type': 'application/json' }
|
36
|
-
});
|
37
|
-
}
|
38
|
-
}));
|
39
|
-
});
|
40
|
-
initializeScreenwright();
|
41
|
-
export const capture = (page, key, title, parentKey) => __awaiter(void 0, void 0, void 0, function* () {
|
42
|
-
if (deploymentId === null) {
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
46
|
-
const path = `${tmpDir}/${key}.png`;
|
47
|
-
yield page.screenshot({ path, fullPage: true });
|
48
|
-
const attribute = {
|
49
|
-
key,
|
50
|
-
title,
|
51
|
-
src: path,
|
52
|
-
childrens: [],
|
53
|
-
};
|
54
|
-
if (parentKey) {
|
55
|
-
const searchParent = (attributes) => {
|
56
|
-
for (let i = 0; i < attributes.length; i++) {
|
57
|
-
if (attributes[i].key === parentKey) {
|
58
|
-
attributes[i].childrens.push(attribute);
|
59
|
-
break;
|
60
|
-
}
|
61
|
-
searchParent(attributes[i].childrens);
|
62
|
-
}
|
63
|
-
};
|
64
|
-
searchParent(result.screenshotItemAttributes);
|
65
|
-
}
|
66
|
-
else {
|
67
|
-
result.screenshotItemAttributes.push(attribute);
|
68
|
-
}
|
69
|
-
});
|