@lowdefy/operators-js 7.0.0 → 7.2.0

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.
@@ -13,11 +13,27 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { runClass } from '@lowdefy/operators';
16
+ // atob and btoa work on Latin-1 characters, one byte each. Encode the UTF-8 bytes instead, like the
17
+ // server and build _base64, so any string encodes and decodes to the same value everywhere.
16
18
  function decode(input) {
17
- return atob(input);
19
+ // Buffer.from(input, 'base64') on the server also accepts base64url and missing padding.
20
+ // Remove whitespace first, as atob does, so the padding is computed from the base64 characters.
21
+ const base64 = input.replace(/[\t\n\f\r ]/g, '').replace(/-/g, '+').replace(/_/g, '/').replace(/=+$/, '');
22
+ const binary = atob(base64.padEnd(Math.ceil(base64.length / 4) * 4, '='));
23
+ const bytes = Uint8Array.from(binary, (char)=>char.charCodeAt(0));
24
+ // Throw on bytes that are not valid UTF-8 instead of replacing them with U+FFFD, so data that is
25
+ // not UTF-8 text, such as Latin-1 values encoded by earlier versions, surfaces as an error.
26
+ try {
27
+ return new TextDecoder('utf-8', {
28
+ fatal: true
29
+ }).decode(bytes);
30
+ } catch {
31
+ throw new Error('_base64.decode received base64 that does not decode to valid UTF-8 text.');
32
+ }
18
33
  }
19
34
  function encode(input) {
20
- return btoa(input);
35
+ const bytes = new TextEncoder().encode(input);
36
+ return btoa(Array.from(bytes, (byte)=>String.fromCharCode(byte)).join(''));
21
37
  }
22
38
  const functions = {
23
39
  encode,
@@ -12,7 +12,8 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { getFromObject, getMediaViewport, getObjectReadKeys } from '@lowdefy/operators';
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import { getFromObject, getMediaViewport, getObjectReadKeys } from '@lowdefy/operators';
16
17
  // The client keeps the preference it reads from storage, under the app's key.
17
18
  function getDarkModePreference(window) {
18
19
  return window.__lowdefy_darkModePreference ?? 'system';
@@ -22,7 +23,9 @@ function getDarkMode(window) {
22
23
  }
23
24
  function _media({ arrayIndices, location, params, globals }) {
24
25
  const { window } = globals;
25
- if (!window?.innerWidth) {
26
+ // A page loading in a hidden or background tab reports a width of 0 until it is shown, and the
27
+ // resize listener reports the real width then.
28
+ if (type.isNone(window?.innerWidth)) {
26
29
  throw new Error(`device window width not available for _media.`);
27
30
  }
28
31
  const media = {
@@ -12,7 +12,18 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ function _log({ params }) {
15
+ */ import { type } from '@lowdefy/helpers';
16
+ function _log({ logger, params }) {
17
+ // On the server the line goes through the request's logger, so the secret
18
+ // scrub and _credential apply to it as to every other log line. The browser
19
+ // has no server logger and writes to its console.
20
+ if (!type.isNone(logger)) {
21
+ logger.info({
22
+ event: 'operator_log',
23
+ value: params
24
+ }, '_log');
25
+ return params;
26
+ }
16
27
  // eslint-disable-next-line no-console
17
28
  console.log(params);
18
29
  return params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/operators-js",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -48,19 +48,17 @@
48
48
  "dist/*"
49
49
  ],
50
50
  "dependencies": {
51
- "@lowdefy/errors": "7.0.0",
52
- "@lowdefy/helpers": "7.0.0",
53
- "@lowdefy/operators": "7.0.0",
51
+ "@lowdefy/errors": "7.2.0",
52
+ "@lowdefy/helpers": "7.2.0",
53
+ "@lowdefy/operators": "7.2.0",
54
54
  "intl-messageformat": "11.2.7"
55
55
  },
56
56
  "devDependencies": {
57
- "@jest/globals": "28.1.3",
58
- "@lowdefy/node-utils": "7.0.0",
57
+ "@lowdefy/node-utils": "7.2.0",
59
58
  "@swc/cli": "0.8.1",
60
59
  "@swc/core": "1.15.32",
61
- "@swc/jest": "0.2.39",
62
- "jest": "28.1.3",
63
- "jest-environment-jsdom": "28.1.3"
60
+ "jsdom": "19.0.0",
61
+ "vitest": "4.1.12"
64
62
  },
65
63
  "publishConfig": {
66
64
  "access": "public"
@@ -68,6 +66,6 @@
68
66
  "scripts": {
69
67
  "build": "swc src --out-dir dist --config-file ../../../../.swcrc --cli-config-file ../../../../.swc-cli.json --copy-files",
70
68
  "clean": "rm -rf dist",
71
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
69
+ "test": "vitest run"
72
70
  }
73
71
  }