@applicaster/zapp-react-native-utils 12.0.0-rc.56 → 12.0.0-rc.57

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.
@@ -24,7 +24,6 @@ import {
24
24
  EMPTY,
25
25
  FALLBACK,
26
26
  TRANSFORM,
27
- defaultColor,
28
27
  } from "./fixtures";
29
28
 
30
29
  describe("getKeyForLabel", () => {
@@ -395,9 +394,7 @@ describe("getColorFromData", () => {
395
394
  it("should return value directly if valid color", () => {
396
395
  const result = getColorFromData({
397
396
  data: entry,
398
- key: "background_color",
399
- getValue: getValue(componentStyle),
400
- defaultColor,
397
+ valueFromLayout: "#123456",
401
398
  });
402
399
 
403
400
  expect(result).toBe("#123456");
@@ -406,9 +403,7 @@ describe("getColorFromData", () => {
406
403
  it("should return valid rgba color name", () => {
407
404
  const result = getColorFromData({
408
405
  data: entry,
409
- key: "component_background_color",
410
- getValue: getValue(componentStyle),
411
- defaultColor,
406
+ valueFromLayout: "rgba(255, 255, 255, 0)",
412
407
  });
413
408
 
414
409
  expect(result).toBe("rgba(255, 255, 255, 0)");
@@ -417,33 +412,27 @@ describe("getColorFromData", () => {
417
412
  it("should return path value if path value is set and is valid color", () => {
418
413
  const result = getColorFromData({
419
414
  data: entry,
420
- key: VAL.colorKeyPath,
421
- getValue: getValue(componentStyle),
422
- defaultColor,
415
+ valueFromLayout: "background_color",
423
416
  });
424
417
 
425
418
  expect(result).toBe("#123456");
426
419
  });
427
420
 
428
- it("should return defaultColor if key value and path value are invalid", () => {
421
+ it("should return path value if path value is set, nested and is valid color", () => {
429
422
  const result = getColorFromData({
430
423
  data: entry,
431
- key: VAL.invalidColorKey,
432
- getValue: getValue(componentStyle),
433
- defaultColor,
424
+ valueFromLayout: "extensions.background_color",
434
425
  });
435
426
 
436
- expect(result).toBe(defaultColor);
427
+ expect(result).toBe("#123456");
437
428
  });
438
429
 
439
- it("should return defaultColor if path does not exist", () => {
430
+ it("should return valueFromLayout if path does not exist", () => {
440
431
  const result = getColorFromData({
441
432
  data: entry,
442
- key: VAL.invalidColorKeyPath,
443
- getValue: getValue(componentStyle),
444
- defaultColor,
433
+ valueFromLayout: "invalid_color",
445
434
  });
446
435
 
447
- expect(result).toBe(defaultColor);
436
+ expect(result).toBe("invalid_color");
448
437
  });
449
438
  });
@@ -447,30 +447,24 @@ export const toResizeMode = (
447
447
 
448
448
  type GetColorFromData = {
449
449
  data: Record<string, any>;
450
- key: string;
451
- getValue: Function;
452
- defaultColor: string;
450
+ valueFromLayout: string;
453
451
  };
454
452
 
455
453
  export const getColorFromData = ({
456
454
  data,
457
- key,
458
- getValue,
459
- defaultColor,
455
+ valueFromLayout,
460
456
  }: GetColorFromData): string => {
461
- const value = getValue(key);
462
-
463
457
  // Temporary hack to fix color validation when alpha is floating point number
464
458
  // https://github.com/dreamyguy/validate-color/issues/44
465
- if (validateColor(value.replace(".00", ""))) {
466
- return value;
459
+ if (validateColor(valueFromLayout.replace(".00", ""))) {
460
+ return valueFromLayout;
467
461
  }
468
462
 
469
- const pathValue = R.path(value.split("."), data);
463
+ const pathValue = R.path(valueFromLayout.split("."), data);
470
464
 
471
465
  if (pathValue && validateColor(pathValue)) {
472
466
  return pathValue;
473
467
  }
474
468
 
475
- return defaultColor;
469
+ return valueFromLayout;
476
470
  };
@@ -1,4 +1,4 @@
1
- import { last, head, isNil, includes, all, pathOr } from "ramda";
1
+ import { last, head, isNil, includes, pathOr } from "ramda";
2
2
 
3
3
  const stripBrackets = (path) => {
4
4
  const withoutPrepened = last(path.split("{{"));
@@ -13,15 +13,15 @@ const hasValue = (context) => (path) => {
13
13
  return !isNil(value);
14
14
  };
15
15
 
16
- export const isEnoughDataToInflateString = (context, string): boolean => {
16
+ export const getMissingValues = (context, string): string[] => {
17
17
  if (!includes("{{", string)) {
18
- return true;
18
+ return [];
19
19
  }
20
20
 
21
21
  const SEARCH_REGEX = new RegExp(/{{.*?}}/g);
22
22
  const paths = string.toString().match(SEARCH_REGEX);
23
23
 
24
- return all(hasValue(context), paths);
24
+ return paths.filter((path) => !hasValue(context)(path));
25
25
  };
26
26
 
27
27
  export const isNonInflatedUrl = (url: string): boolean =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-rc.56",
3
+ "version": "12.0.0-rc.57",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-rc.56",
31
+ "@applicaster/applicaster-types": "12.0.0-rc.57",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -12,9 +12,21 @@ const {
12
12
 
13
13
  const { reactHooksLogger } = require("../../logger");
14
14
 
15
+ let mockStore;
16
+
15
17
  describe("getInflatedDataSourceUrl", () => {
16
18
  beforeEach(() => {
17
19
  reactHooksLogger.warning.mockClear();
20
+
21
+ const {
22
+ appStore,
23
+ } = require("@applicaster/zapp-react-native-redux/AppStore");
24
+
25
+ mockStore = {
26
+ getState: jest.fn().mockReturnValue({ pipesEndpoints: {} }),
27
+ };
28
+
29
+ appStore.set(mockStore);
18
30
  });
19
31
 
20
32
  it("returns the url inflated with the right params", () => {
@@ -72,7 +84,7 @@ describe("getInflatedDataSourceUrl", () => {
72
84
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
73
85
 
74
86
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
75
- message: "Not enough data to fully inflate url",
87
+ message: "Not enough data to fully inflate url: {{entry.id}}",
76
88
  data: { source, contexts, mapping },
77
89
  });
78
90
  });
@@ -107,7 +119,8 @@ describe("getInflatedDataSourceUrl", () => {
107
119
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
108
120
 
109
121
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
110
- message: "Not enough data to fully inflate url",
122
+ message:
123
+ "Not enough data to fully inflate url: {{entry.extensions.groupName}}",
111
124
  data: { source, contexts, mapping },
112
125
  });
113
126
  });
@@ -148,7 +161,8 @@ describe("getInflatedDataSourceUrl", () => {
148
161
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
149
162
 
150
163
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
151
- message: "Not enough data to fully inflate url",
164
+ message:
165
+ "Not enough data to fully inflate url: {{entry.extensions.groupName2}}",
152
166
  data: { source, contexts, mapping },
153
167
  });
154
168
  });
@@ -9,9 +9,12 @@ import {
9
9
 
10
10
  import { inflateString } from "../../stringUtils";
11
11
  import { useRoute } from "../navigation";
12
- import { isEnoughDataToInflateString } from "../../inflatedUrlUtils";
12
+ import { getMissingValues } from "../../inflatedUrlUtils";
13
13
  import { reactHooksLogger as logger } from "../logger";
14
14
  import { isTV } from "../../reactUtils";
15
+ import { findEndpointForURL } from "@applicaster/zapp-pipes-v2-client";
16
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
17
+ import { ENDPOINT_TAGS } from "../../types";
15
18
 
16
19
  /**
17
20
  * will match any occurrence in a string of one or more word characters
@@ -105,24 +108,41 @@ export const getInflatedDataSourceUrl: GetInflatedDataSourceUrl = ({
105
108
  R.keys(mapping)
106
109
  );
107
110
 
108
- if (!isEnoughDataToInflateString(contexts, string)) {
109
- const message = "Not enough data to fully inflate url";
110
-
111
- // todo: add js only payload instead
112
- if (__DEV__) {
113
- logger.warning({
114
- message,
115
- data: { source, contexts, mapping },
116
- });
111
+ const missingValues = getMissingValues(contexts, string);
112
+
113
+ if (missingValues && missingValues.length > 0) {
114
+ const pipesEndpoints = appStore.get("pipesEndpoints");
115
+ const endpointURL = findEndpointForURL(string, pipesEndpoints);
116
+ const tags = pipesEndpoints?.[endpointURL]?.tags;
117
+ const allowMissingKeys = tags?.includes(ENDPOINT_TAGS.allow_missing_keys);
118
+
119
+ if (!allowMissingKeys) {
120
+ const message = `Not enough data to fully inflate url: ${missingValues.join(
121
+ ","
122
+ )}`;
123
+
124
+ // todo: add js only payload instead
125
+ if (__DEV__) {
126
+ logger.warning({
127
+ message,
128
+ data: { source, contexts, mapping },
129
+ });
130
+ } else {
131
+ // todo: log values we've failed to resolve
132
+ logger.warning({
133
+ message,
134
+ });
135
+ }
136
+
137
+ // return null in order to prevent start fetching data with invalid url
138
+ return null;
117
139
  } else {
118
- // todo: log values we've failed to resolve
119
- logger.warning({
120
- message,
140
+ logger.debug({
141
+ message: `Ignoring missing values in url because ${
142
+ ENDPOINT_TAGS.allow_missing_keys
143
+ } endpoint tag, keys: ${missingValues.join(",")}`,
121
144
  });
122
145
  }
123
-
124
- // return null in order to prevent start fetching data with invalid url
125
- return null;
126
146
  }
127
147
 
128
148
  return inflateString({ string, data: contexts });
package/types.ts CHANGED
@@ -5,3 +5,7 @@ export type ManifestField<T> = {
5
5
  group?: boolean;
6
6
  fields?: ManifestField<any>[];
7
7
  };
8
+
9
+ export enum ENDPOINT_TAGS {
10
+ allow_missing_keys = "allow_missing_keys",
11
+ }