@percy/core 1.27.4-beta.1 → 1.27.4-beta.2

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/api.js CHANGED
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import { createRequire } from 'module';
4
4
  import logger from '@percy/logger';
5
5
  import { normalize } from '@percy/config/utils';
6
- import { getPackageJSON, Server, percyAutomateRequestHandler } from './utils.js';
6
+ import { getPackageJSON, Server, percyAutomateRequestHandler, percyBuildEventHandler } from './utils.js';
7
7
  import WebdriverUtils from '@percy/webdriver-utils';
8
8
  // need require.resolve until import.meta.resolve can be transpiled
9
9
  export const PERCY_DOM = createRequire(import.meta.url).resolve('@percy/dom');
@@ -144,6 +144,15 @@ export function createPercyServer(percy, port) {
144
144
  success: true
145
145
  });
146
146
  })
147
+ // Recieves events from sdk's.
148
+ .route('post', '/percy/events', async (req, res) => {
149
+ var _percy$build2;
150
+ const body = percyBuildEventHandler(req, pkg.version);
151
+ await percy.client.sendBuildEvents((_percy$build2 = percy.build) === null || _percy$build2 === void 0 ? void 0 : _percy$build2.id, body);
152
+ res.json(200, {
153
+ success: true
154
+ });
155
+ })
147
156
  // stops percy at the end of the current event loop
148
157
  .route('/percy/stop', (req, res) => {
149
158
  setImmediate(() => percy.stop());
package/dist/utils.js CHANGED
@@ -55,6 +55,40 @@ export function percyAutomateRequestHandler(req, percy) {
55
55
  req.body.buildInfo = percy.build;
56
56
  }
57
57
 
58
+ // Returns the body for sendEvent structure
59
+ export function percyBuildEventHandler(req, cliVersion) {
60
+ if (Array.isArray(req.body)) {
61
+ return req.body.map(item => processSendEventData(item, cliVersion));
62
+ } else {
63
+ // Treat the input as an object and perform instructions
64
+ return processSendEventData(req.body, cliVersion);
65
+ }
66
+ }
67
+
68
+ // Process sendEvent object
69
+ function processSendEventData(input, cliVersion) {
70
+ // Add Properties here to send to eventData
71
+ const allowedEventProperties = ['message', 'cliVersion', 'clientInfo', 'errorKind', 'extra'];
72
+ const extractedData = {};
73
+ for (const property of allowedEventProperties) {
74
+ if (Object.prototype.hasOwnProperty.call(input, property)) {
75
+ extractedData[property] = input[property];
76
+ }
77
+ }
78
+ if (extractedData.clientInfo) {
79
+ const [client, clientVersion] = extractedData.clientInfo.split('/');
80
+
81
+ // Add the client and clientVersion fields to the object
82
+ extractedData.client = client;
83
+ extractedData.clientVersion = clientVersion;
84
+ delete extractedData.clientInfo;
85
+ }
86
+ if (!input.cliVersion) {
87
+ extractedData.cliVersion = cliVersion;
88
+ }
89
+ return extractedData;
90
+ }
91
+
58
92
  // Creates a local resource object containing the resource URL, mimetype, content, sha, and any
59
93
  // other additional resources attributes.
60
94
  export function createResource(url, content, mimetype, attrs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.27.4-beta.1",
3
+ "version": "1.27.4-beta.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,11 +43,11 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.27.4-beta.1",
47
- "@percy/config": "1.27.4-beta.1",
48
- "@percy/dom": "1.27.4-beta.1",
49
- "@percy/logger": "1.27.4-beta.1",
50
- "@percy/webdriver-utils": "1.27.4-beta.1",
46
+ "@percy/client": "1.27.4-beta.2",
47
+ "@percy/config": "1.27.4-beta.2",
48
+ "@percy/dom": "1.27.4-beta.2",
49
+ "@percy/logger": "1.27.4-beta.2",
50
+ "@percy/webdriver-utils": "1.27.4-beta.2",
51
51
  "content-disposition": "^0.5.4",
52
52
  "cross-spawn": "^7.0.3",
53
53
  "extract-zip": "^2.0.1",
@@ -58,5 +58,5 @@
58
58
  "rimraf": "^3.0.2",
59
59
  "ws": "^8.0.0"
60
60
  },
61
- "gitHead": "d0eea0c0d75cb6c034dceba122b1bc1f946b679a"
61
+ "gitHead": "9dc3b46642f608a762a7c4a1ca564813ece1b370"
62
62
  }