screenright-client 0.9.8 → 0.9.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/dist/index.mjs +0 -69
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screenright-client",
3
- "version": "0.9.8",
3
+ "version": "0.9.9",
4
4
  "description": "screenright's nodejs client library",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
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
- });