@applicaster/zapp-react-native-ui-components 16.0.0-rc.75 → 16.0.0-rc.77

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.
@@ -134,7 +134,7 @@ export class CellComponent extends React.Component<Props, State> {
134
134
  }
135
135
  }
136
136
 
137
- onFocus(focusable, mouse) {
137
+ onFocus(focusable) {
138
138
  const {
139
139
  item: { id, title },
140
140
  shouldScrollVertically,
@@ -145,10 +145,7 @@ export class CellComponent extends React.Component<Props, State> {
145
145
  if (isFocusable) {
146
146
  this.setState({ cellFocused: true });
147
147
 
148
- if (
149
- shouldUpdate &&
150
- shouldScrollVertically?.(mouse, focusable, id, title)
151
- ) {
148
+ if (shouldUpdate && shouldScrollVertically?.(focusable, id, title)) {
152
149
  this.scrollVertically(focusable);
153
150
  }
154
151
  }
@@ -262,7 +259,7 @@ export class CellComponent extends React.Component<Props, State> {
262
259
  const handleFocus = (focusable, mouse) => {
263
260
  const focusFn = onFocus || noop;
264
261
  focusFn(focusable, mouse);
265
- this.onFocus(focusable, mouse);
262
+ this.onFocus(focusable);
266
263
  };
267
264
 
268
265
  if (this.state.hasFocusableInside) {
@@ -0,0 +1,294 @@
1
+ import {
2
+ looksLikeSkipExpression,
3
+ parseSkipExpression,
4
+ evaluateSkipExpression,
5
+ } from "../skipExpression";
6
+
7
+ jest.mock("../logger", () => ({
8
+ log_debug: jest.fn(),
9
+ log_error: jest.fn(),
10
+ log_info: jest.fn(),
11
+ }));
12
+
13
+ const TOKEN = "quick-brick-login-flow.access_token";
14
+ const PROFILE = "user_account.profile";
15
+
16
+ /**
17
+ * Stands in for `getKeyToSkipHook`: resolves a "namespace.key" store, so the
18
+ * expression evaluator is exercised against real lookups rather than mocks.
19
+ */
20
+ const storage = (store: Record<string, unknown>) =>
21
+ jest.fn((key: string, namespace?: string) =>
22
+ Promise.resolve(store[`${namespace}.${key}`])
23
+ );
24
+
25
+ const evaluate = (expression: unknown, store: Record<string, unknown> = {}) =>
26
+ evaluateSkipExpression(parseSkipExpression(expression), storage(store));
27
+
28
+ describe("looksLikeSkipExpression", () => {
29
+ it("recognises a JSON object, whatever its content", () => {
30
+ expect(looksLikeSkipExpression('{"exists":"ns.key"}')).toBe(true);
31
+ expect(looksLikeSkipExpression(' {"exists":"ns.key"} ')).toBe(true);
32
+ expect(looksLikeSkipExpression({ exists: "ns.key" })).toBe(true);
33
+ });
34
+
35
+ it("recognises a malformed expression, so it is never read as a key list", () => {
36
+ expect(looksLikeSkipExpression('{"any":')).toBe(true);
37
+ });
38
+
39
+ it("rejects a legacy comma-separated key list", () => {
40
+ expect(looksLikeSkipExpression("ns1.key1, ns2.key2")).toBe(false);
41
+ });
42
+
43
+ it("rejects empty and missing input", () => {
44
+ expect(looksLikeSkipExpression("")).toBe(false);
45
+ expect(looksLikeSkipExpression(" ")).toBe(false);
46
+ expect(looksLikeSkipExpression(undefined)).toBe(false);
47
+ });
48
+ });
49
+
50
+ describe("parseSkipExpression", () => {
51
+ it("parses a JSON string into an expression object", () => {
52
+ expect(parseSkipExpression('{"exists":"ns.key"}')).toEqual({
53
+ exists: "ns.key",
54
+ });
55
+ });
56
+
57
+ it("ignores leading and trailing whitespace around the JSON", () => {
58
+ expect(parseSkipExpression(' {"exists":"ns.key"} ')).toEqual({
59
+ exists: "ns.key",
60
+ });
61
+ });
62
+
63
+ it("accepts an expression that is already an object", () => {
64
+ expect(parseSkipExpression({ exists: "ns.key" })).toEqual({
65
+ exists: "ns.key",
66
+ });
67
+ });
68
+
69
+ it("returns null for a legacy comma-separated key list", () => {
70
+ expect(parseSkipExpression("ns1.key1, ns2.key2")).toBeNull();
71
+ });
72
+
73
+ it("returns null for a malformed JSON object", () => {
74
+ expect(parseSkipExpression('{"exists":')).toBeNull();
75
+ });
76
+
77
+ it("returns null for empty and missing input", () => {
78
+ expect(parseSkipExpression("")).toBeNull();
79
+ expect(parseSkipExpression(undefined)).toBeNull();
80
+ expect(parseSkipExpression(null)).toBeNull();
81
+ });
82
+
83
+ it("returns null for a JSON array, which is not a valid expression", () => {
84
+ expect(parseSkipExpression('["ns.key"]')).toBeNull();
85
+ });
86
+ });
87
+
88
+ describe("evaluateSkipExpression", () => {
89
+ it("returns false when there is no expression", async () => {
90
+ await expect(evaluateSkipExpression(null, storage({}))).resolves.toBe(
91
+ false
92
+ );
93
+ });
94
+
95
+ describe("exists", () => {
96
+ it("is true when the key holds a value", async () => {
97
+ await expect(
98
+ evaluate({ exists: "ns.key" }, { "ns.key": "value" })
99
+ ).resolves.toBe(true);
100
+ });
101
+
102
+ it("is false when the key is absent", async () => {
103
+ await expect(evaluate({ exists: "ns.key" })).resolves.toBe(false);
104
+ });
105
+
106
+ it("is false when the key holds an empty string", async () => {
107
+ await expect(
108
+ evaluate({ exists: "ns.key" }, { "ns.key": "" })
109
+ ).resolves.toBe(false);
110
+ });
111
+
112
+ it("splits the namespace on the last dot, like the legacy format", async () => {
113
+ const readKey = storage({ "com.applicaster.feature.someKey": "value" });
114
+
115
+ await evaluateSkipExpression(
116
+ { exists: "com.applicaster.feature.someKey" },
117
+ readKey
118
+ );
119
+
120
+ expect(readKey).toHaveBeenCalledWith(
121
+ "someKey",
122
+ "com.applicaster.feature"
123
+ );
124
+ });
125
+
126
+ it("treats a bare string operand as a shorthand for exists", async () => {
127
+ await expect(
128
+ evaluateSkipExpression("ns.key", storage({ "ns.key": "value" }))
129
+ ).resolves.toBe(true);
130
+ });
131
+ });
132
+
133
+ describe("missing", () => {
134
+ it("is true when the key is absent", async () => {
135
+ await expect(evaluate({ missing: "ns.key" })).resolves.toBe(true);
136
+ });
137
+
138
+ it("is false when the key holds a value", async () => {
139
+ await expect(
140
+ evaluate({ missing: "ns.key" }, { "ns.key": "value" })
141
+ ).resolves.toBe(false);
142
+ });
143
+ });
144
+
145
+ describe("equals", () => {
146
+ it("is true when the stored value matches", async () => {
147
+ await expect(
148
+ evaluate(
149
+ { equals: { key: "ns.key", value: "kids" } },
150
+ { "ns.key": "kids" }
151
+ )
152
+ ).resolves.toBe(true);
153
+ });
154
+
155
+ it("is false when the stored value differs", async () => {
156
+ await expect(
157
+ evaluate(
158
+ { equals: { key: "ns.key", value: "kids" } },
159
+ { "ns.key": "adults" }
160
+ )
161
+ ).resolves.toBe(false);
162
+ });
163
+
164
+ it("compares a non-string stored value by its string form", async () => {
165
+ await expect(
166
+ evaluate({ equals: { key: "ns.key", value: "42" } }, { "ns.key": 42 })
167
+ ).resolves.toBe(true);
168
+ });
169
+ });
170
+
171
+ describe("all", () => {
172
+ it("is true only when every operand is true", async () => {
173
+ await expect(
174
+ evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1", "ns.b": "2" })
175
+ ).resolves.toBe(true);
176
+ });
177
+
178
+ it("is false when one operand is false", async () => {
179
+ await expect(
180
+ evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1" })
181
+ ).resolves.toBe(false);
182
+ });
183
+
184
+ it("stops reading storage after the first false operand", async () => {
185
+ const readKey = storage({ "ns.b": "2" });
186
+
187
+ await evaluateSkipExpression({ all: ["ns.a", "ns.b"] }, readKey);
188
+
189
+ expect(readKey).toHaveBeenCalledTimes(1);
190
+ });
191
+
192
+ it("is false for an empty operand list", async () => {
193
+ await expect(evaluate({ all: [] })).resolves.toBe(false);
194
+ });
195
+ });
196
+
197
+ describe("any", () => {
198
+ it("is true when one operand is true", async () => {
199
+ await expect(
200
+ evaluate({ any: ["ns.a", "ns.b"] }, { "ns.b": "2" })
201
+ ).resolves.toBe(true);
202
+ });
203
+
204
+ it("is false when every operand is false", async () => {
205
+ await expect(evaluate({ any: ["ns.a", "ns.b"] })).resolves.toBe(false);
206
+ });
207
+
208
+ it("stops reading storage after the first true operand", async () => {
209
+ const readKey = storage({ "ns.a": "1", "ns.b": "2" });
210
+
211
+ await evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey);
212
+
213
+ expect(readKey).toHaveBeenCalledTimes(1);
214
+ });
215
+
216
+ it("is false for an empty operand list", async () => {
217
+ await expect(evaluate({ any: [] })).resolves.toBe(false);
218
+ });
219
+ });
220
+
221
+ describe("not", () => {
222
+ it("inverts a true operand", async () => {
223
+ await expect(
224
+ evaluate({ not: "ns.key" }, { "ns.key": "value" })
225
+ ).resolves.toBe(false);
226
+ });
227
+
228
+ it("inverts a false operand", async () => {
229
+ await expect(evaluate({ not: "ns.key" })).resolves.toBe(true);
230
+ });
231
+ });
232
+
233
+ describe("malformed expressions fail open", () => {
234
+ it("is false for an unknown operator", async () => {
235
+ await expect(evaluate({ matches: "ns.key" })).resolves.toBe(false);
236
+ });
237
+
238
+ it("is false for an operator carrying the wrong operand type", async () => {
239
+ await expect(evaluate({ exists: 42 })).resolves.toBe(false);
240
+ await expect(evaluate({ all: "ns.key" })).resolves.toBe(false);
241
+ });
242
+
243
+ it("is false for an operand list holding a malformed node", async () => {
244
+ await expect(
245
+ evaluate({ all: ["ns.a", { matches: "ns.b" }] }, { "ns.a": "1" })
246
+ ).resolves.toBe(false);
247
+ });
248
+
249
+ it("is false when a storage read throws", async () => {
250
+ const readKey = jest.fn(() => Promise.reject(new Error("storage error")));
251
+
252
+ await expect(
253
+ evaluateSkipExpression({ exists: "ns.key" }, readKey)
254
+ ).resolves.toBe(false);
255
+ });
256
+
257
+ it("keeps evaluating the other operands when one storage read throws", async () => {
258
+ const readKey = jest.fn((key: string) =>
259
+ key === "a"
260
+ ? Promise.reject(new Error("storage error"))
261
+ : Promise.resolve("value")
262
+ );
263
+
264
+ await expect(
265
+ evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey)
266
+ ).resolves.toBe(true);
267
+ });
268
+ });
269
+
270
+ describe("profile selector scenario", () => {
271
+ const skipProfileSelector = {
272
+ any: [{ missing: TOKEN }, { exists: PROFILE }],
273
+ };
274
+
275
+ it("shows the hook to a logged-in user who has not picked a profile yet", async () => {
276
+ await expect(
277
+ evaluate(skipProfileSelector, { [TOKEN]: "a-token" })
278
+ ).resolves.toBe(false);
279
+ });
280
+
281
+ it("skips the hook for a logged-out user", async () => {
282
+ await expect(evaluate(skipProfileSelector)).resolves.toBe(true);
283
+ });
284
+
285
+ it("skips the hook once a profile has been picked", async () => {
286
+ await expect(
287
+ evaluate(skipProfileSelector, {
288
+ [TOKEN]: "a-token",
289
+ [PROFILE]: "profile-id",
290
+ })
291
+ ).resolves.toBe(true);
292
+ });
293
+ });
294
+ });
@@ -122,3 +122,67 @@ describe("shouldSkipHook", () => {
122
122
  await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(true);
123
123
  });
124
124
  });
125
+
126
+ describe("shouldSkipHook with a packed expression", () => {
127
+ const SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE = JSON.stringify({
128
+ any: [
129
+ { missing: "quick-brick-login-flow.access_token" },
130
+ { exists: "user_account.profile" },
131
+ ],
132
+ });
133
+
134
+ const storedKeys = (store: Record<string, string>) => {
135
+ mockSessionGetItem.mockImplementation((key, namespace) =>
136
+ Promise.resolve(store[`${namespace}.${key}`] ?? null)
137
+ );
138
+
139
+ mockLocalGetItem.mockResolvedValue(null);
140
+ };
141
+
142
+ beforeEach(() => {
143
+ jest.clearAllMocks();
144
+ storedKeys({});
145
+ });
146
+
147
+ it("does not skip for a logged-in user who has not picked a profile yet", async () => {
148
+ storedKeys({ "quick-brick-login-flow.access_token": "a-token" });
149
+
150
+ await expect(
151
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
152
+ ).resolves.toBe(false);
153
+ });
154
+
155
+ it("skips for a logged-out user", async () => {
156
+ await expect(
157
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
158
+ ).resolves.toBe(true);
159
+ });
160
+
161
+ it("skips once a profile has been picked", async () => {
162
+ storedKeys({
163
+ "quick-brick-login-flow.access_token": "a-token",
164
+ "user_account.profile": "profile-id",
165
+ });
166
+
167
+ await expect(
168
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
169
+ ).resolves.toBe(true);
170
+ });
171
+
172
+ it("falls back to local storage for a key the session does not hold", async () => {
173
+ mockLocalGetItem.mockResolvedValue("a-token");
174
+
175
+ await expect(
176
+ shouldSkipHook(JSON.stringify({ exists: "ns.key" }))
177
+ ).resolves.toBe(true);
178
+
179
+ expect(mockSessionGetItem).toHaveBeenCalledWith("key", "ns");
180
+ expect(mockLocalGetItem).toHaveBeenCalledWith("key", "ns");
181
+ });
182
+
183
+ it("returns false for a malformed expression instead of reading storage", async () => {
184
+ await expect(shouldSkipHook('{"any":')).resolves.toBe(false);
185
+ expect(mockSessionGetItem).not.toHaveBeenCalled();
186
+ expect(mockLocalGetItem).not.toHaveBeenCalled();
187
+ });
188
+ });
@@ -0,0 +1,252 @@
1
+ import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
2
+ import { log_error, log_info } from "./logger";
3
+
4
+ /**
5
+ * Boolean expressions over storage keys, used by the General Content Screen
6
+ * hook adapter to decide whether a hook should be skipped.
7
+ *
8
+ * The `skip_hook_storage_key` rule normally holds a comma-separated list of
9
+ * keys, meaning "skip when any of these exists". That covers presence only, so
10
+ * a condition such as "the user is logged in but has not picked a profile yet"
11
+ * cannot be expressed. To keep the manifest field untouched, an expression may
12
+ * be packed into the very same string as JSON: anything starting with `{` is
13
+ * parsed as an expression, anything else keeps the legacy behaviour.
14
+ *
15
+ * The expression evaluates to the SKIP condition — true means "do not present
16
+ * the hook" — matching the name of the rule it is configured in.
17
+ *
18
+ * Keys are written as `namespace.key` and resolved exactly like the legacy
19
+ * format: everything before the LAST dot is the namespace, so
20
+ * `com.applicaster.feature.someKey` reads `someKey` from `com.applicaster.feature`.
21
+ * A key with no dot falls back to the default namespace.
22
+ *
23
+ * Operators:
24
+ *
25
+ * "ns.key" shorthand for { "exists": "ns.key" }
26
+ * { "exists": "ns.key" } the key holds a truthy value
27
+ * { "missing": "ns.key" } the key holds no value
28
+ * { "equals": { "key": "ns.key", "value": "kids" } }
29
+ * { "all": [ …operands ] } AND, short-circuits on the first false
30
+ * { "any": [ …operands ] } OR, short-circuits on the first true
31
+ * { "not": operand } negation
32
+ *
33
+ * @example Show the profile selector to a logged-in user who has no profile yet
34
+ * ```json
35
+ * {
36
+ * "any": [
37
+ * { "missing": "quick-brick-login-flow.access_token" },
38
+ * { "exists": "user_account.profile" }
39
+ * ]
40
+ * }
41
+ * ```
42
+ * As it is stored in the `skip_hook_storage_key` string field:
43
+ * ```json
44
+ * "skip_hook_storage_key": "{\"any\":[{\"missing\":\"quick-brick-login-flow.access_token\"},{\"exists\":\"user_account.profile\"}]}"
45
+ * ```
46
+ *
47
+ * @example Skip an onboarding hook once it has been seen on a subscribed device
48
+ * ```json
49
+ * {
50
+ * "all": [
51
+ * "onboarding.completed",
52
+ * { "equals": { "key": "user_account.plan", "value": "premium" } }
53
+ * ]
54
+ * }
55
+ * ```
56
+ *
57
+ * Every failure mode — malformed JSON, an unknown operator, an operand of the
58
+ * wrong type, a storage read that throws — evaluates to false, so a broken
59
+ * configuration presents the hook rather than silently hiding a screen.
60
+ */
61
+ export type SkipExpression =
62
+ | string
63
+ | { exists: string }
64
+ | { missing: string }
65
+ | { equals: { key: string; value: string } }
66
+ | { all: SkipExpression[] }
67
+ | { any: SkipExpression[] }
68
+ | { not: SkipExpression };
69
+
70
+ /** Reads a single storage key. Injected so evaluation stays storage-agnostic. */
71
+ export type ReadKey = (key: string, namespace?: string) => Promise<unknown>;
72
+
73
+ const isPlainObject = (value: unknown): value is Record<string, unknown> =>
74
+ typeof value === "object" && value !== null && !Array.isArray(value);
75
+
76
+ const hasOperator = (node: Record<string, unknown>, operator: string) =>
77
+ Object.prototype.hasOwnProperty.call(node, operator);
78
+
79
+ /**
80
+ * Whether a `skip_hook_storage_key` value is meant as an expression at all.
81
+ *
82
+ * Deliberately a shape check rather than a successful parse: a value that opens
83
+ * with `{` was written as an expression even when its JSON is broken, and must
84
+ * never fall back to being read as a list of storage keys.
85
+ */
86
+ export const looksLikeSkipExpression = (input: unknown): boolean =>
87
+ isPlainObject(input) ||
88
+ (typeof input === "string" && input.trim().startsWith("{"));
89
+
90
+ /**
91
+ * Reads a `skip_hook_storage_key` value as an expression, or returns null when
92
+ * it is not one — an empty value, a legacy comma-separated key list, or an
93
+ * expression whose JSON is malformed.
94
+ */
95
+ export const parseSkipExpression = (input: unknown): SkipExpression | null => {
96
+ if (isPlainObject(input)) {
97
+ return input as SkipExpression;
98
+ }
99
+
100
+ if (!looksLikeSkipExpression(input)) {
101
+ return null;
102
+ }
103
+
104
+ const trimmed = (input as string).trim();
105
+
106
+ try {
107
+ const parsed = JSON.parse(trimmed);
108
+
109
+ if (!isPlainObject(parsed)) {
110
+ log_error(
111
+ `parseSkipExpression: Expression must be an object, got: ${trimmed}`
112
+ );
113
+
114
+ return null;
115
+ }
116
+
117
+ return parsed as SkipExpression;
118
+ } catch (error) {
119
+ log_error(
120
+ `parseSkipExpression: Malformed expression: ${trimmed}. Error: ${error.message}`,
121
+ { error }
122
+ );
123
+
124
+ return null;
125
+ }
126
+ };
127
+
128
+ const keyIsTruthy = async (key: string, readKey: ReadKey): Promise<boolean> => {
129
+ const { namespace, key: name } = getNamespaceAndKey(key);
130
+
131
+ return Boolean(await readKey(name, namespace));
132
+ };
133
+
134
+ const evaluateEquals = async (
135
+ operand: { key: string; value: string },
136
+ readKey: ReadKey
137
+ ): Promise<boolean> => {
138
+ const { namespace, key: name } = getNamespaceAndKey(operand.key);
139
+ const value = await readKey(name, namespace);
140
+
141
+ return value == null ? false : String(value) === String(operand.value);
142
+ };
143
+
144
+ const evaluateNode = async (
145
+ node: SkipExpression,
146
+ readKey: ReadKey
147
+ ): Promise<boolean> => {
148
+ try {
149
+ if (typeof node === "string") {
150
+ return await keyIsTruthy(node, readKey);
151
+ }
152
+
153
+ if (!isPlainObject(node)) {
154
+ log_error(
155
+ `evaluateSkipExpression: Not an operator: ${JSON.stringify(node)}`
156
+ );
157
+
158
+ return false;
159
+ }
160
+
161
+ // The node came from configuration JSON, so every operand is read back as
162
+ // unknown and type-checked here rather than trusted from the union.
163
+ const operator = node as Record<string, unknown>;
164
+
165
+ if (
166
+ hasOperator(operator, "exists") &&
167
+ typeof operator.exists === "string"
168
+ ) {
169
+ return await keyIsTruthy(operator.exists, readKey);
170
+ }
171
+
172
+ if (
173
+ hasOperator(operator, "missing") &&
174
+ typeof operator.missing === "string"
175
+ ) {
176
+ return !(await keyIsTruthy(operator.missing, readKey));
177
+ }
178
+
179
+ if (hasOperator(operator, "equals") && isPlainObject(operator.equals)) {
180
+ return await evaluateEquals(
181
+ operator.equals as { key: string; value: string },
182
+ readKey
183
+ );
184
+ }
185
+
186
+ if (hasOperator(operator, "all") && Array.isArray(operator.all)) {
187
+ for (const operand of operator.all) {
188
+ if (!(await evaluateNode(operand, readKey))) {
189
+ return false;
190
+ }
191
+ }
192
+
193
+ // An empty operand list carries no condition, so it stays false rather
194
+ // than skipping the hook on the vacuous truth of an empty AND.
195
+ return operator.all.length > 0;
196
+ }
197
+
198
+ if (hasOperator(operator, "any") && Array.isArray(operator.any)) {
199
+ for (const operand of operator.any) {
200
+ if (await evaluateNode(operand, readKey)) {
201
+ return true;
202
+ }
203
+ }
204
+
205
+ return false;
206
+ }
207
+
208
+ if (hasOperator(operator, "not")) {
209
+ return !(await evaluateNode(operator.not as SkipExpression, readKey));
210
+ }
211
+
212
+ log_error(
213
+ `evaluateSkipExpression: Unknown or malformed operator: ${JSON.stringify(
214
+ node
215
+ )}`
216
+ );
217
+
218
+ return false;
219
+ } catch (error) {
220
+ log_error(
221
+ `evaluateSkipExpression: Error: ${error.message} evaluating: ${JSON.stringify(
222
+ node
223
+ )}`,
224
+ { error }
225
+ );
226
+
227
+ return false;
228
+ }
229
+ };
230
+
231
+ /**
232
+ * Evaluates a parsed expression to the skip decision. A null expression — the
233
+ * field held no expression — is not a condition, so nothing is skipped.
234
+ */
235
+ export const evaluateSkipExpression = async (
236
+ expression: SkipExpression | null,
237
+ readKey: ReadKey
238
+ ): Promise<boolean> => {
239
+ if (!expression) {
240
+ return false;
241
+ }
242
+
243
+ const shouldSkip = await evaluateNode(expression, readKey);
244
+
245
+ log_info(
246
+ `evaluateSkipExpression: Expression evaluated to ${shouldSkip}, ${
247
+ shouldSkip ? "skipping hook" : "proceeding with hook"
248
+ }`
249
+ );
250
+
251
+ return shouldSkip;
252
+ };
@@ -1,6 +1,11 @@
1
1
  import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
2
2
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
3
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
4
+ import {
5
+ looksLikeSkipExpression,
6
+ parseSkipExpression,
7
+ evaluateSkipExpression,
8
+ } from "./skipExpression";
4
9
  import { log_error, log_info } from "./logger";
5
10
 
6
11
  type ParseKey = { key: string; namespace?: string };
@@ -23,6 +28,12 @@ export const getKeyToSkipHook = async (key: string, namespace?: string) => {
23
28
  return await localStorage.getItem(key, namespace);
24
29
  };
25
30
 
31
+ /**
32
+ * Decides whether the hook should be skipped, from the `skip_hook_storage_key`
33
+ * rule. The value is either a comma-separated key list — skip when ANY of them
34
+ * exists — or, packed into the same string, a JSON boolean expression over
35
+ * storage keys. See `skipExpression.ts` for the expression format.
36
+ */
26
37
  export const shouldSkipHook = async (
27
38
  skipHookIfKeysExist?: string
28
39
  ): Promise<boolean> => {
@@ -32,6 +43,13 @@ export const shouldSkipHook = async (
32
43
  return false;
33
44
  }
34
45
 
46
+ if (looksLikeSkipExpression(skipHookIfKeysExist)) {
47
+ return await evaluateSkipExpression(
48
+ parseSkipExpression(skipHookIfKeysExist),
49
+ getKeyToSkipHook
50
+ );
51
+ }
52
+
35
53
  const keyEntries = parseKeyEntries(skipHookIfKeysExist);
36
54
 
37
55
  if (keyEntries.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.75",
3
+ "version": "16.0.0-rc.77",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-rc.75",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.75",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.75",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.75",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.77",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.77",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.77",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.77",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "react-native-sortables": "1.7.1",