@rocapine/react-native-onboarding 1.11.1 → 1.12.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.
Files changed (72) hide show
  1. package/dist/evaluateCondition.d.ts +6 -0
  2. package/dist/evaluateCondition.d.ts.map +1 -0
  3. package/dist/evaluateCondition.js +48 -0
  4. package/dist/evaluateCondition.js.map +1 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +12 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/infra/provider/OnboardingProvider.d.ts +2 -0
  10. package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
  11. package/dist/infra/provider/OnboardingProvider.js +8 -0
  12. package/dist/infra/provider/OnboardingProvider.js.map +1 -1
  13. package/dist/resolveNextStepNumber.d.ts +11 -0
  14. package/dist/resolveNextStepNumber.d.ts.map +1 -0
  15. package/dist/resolveNextStepNumber.js +39 -0
  16. package/dist/resolveNextStepNumber.js.map +1 -0
  17. package/dist/steps/Carousel/types.d.ts +29 -8
  18. package/dist/steps/Carousel/types.d.ts.map +1 -1
  19. package/dist/steps/Carousel/types.js +1 -8
  20. package/dist/steps/Carousel/types.js.map +1 -1
  21. package/dist/steps/Commitment/types.d.ts +29 -8
  22. package/dist/steps/Commitment/types.d.ts.map +1 -1
  23. package/dist/steps/Commitment/types.js +1 -8
  24. package/dist/steps/Commitment/types.js.map +1 -1
  25. package/dist/steps/ComposableScreen/elements/InputElement.d.ts +2 -2
  26. package/dist/steps/ComposableScreen/types.d.ts +29 -4
  27. package/dist/steps/ComposableScreen/types.d.ts.map +1 -1
  28. package/dist/steps/ComposableScreen/types.js +1 -7
  29. package/dist/steps/ComposableScreen/types.js.map +1 -1
  30. package/dist/steps/Loader/types.d.ts +29 -8
  31. package/dist/steps/Loader/types.d.ts.map +1 -1
  32. package/dist/steps/Loader/types.js +1 -8
  33. package/dist/steps/Loader/types.js.map +1 -1
  34. package/dist/steps/MediaContent/types.d.ts +29 -8
  35. package/dist/steps/MediaContent/types.d.ts.map +1 -1
  36. package/dist/steps/MediaContent/types.js +1 -8
  37. package/dist/steps/MediaContent/types.js.map +1 -1
  38. package/dist/steps/Picker/types.d.ts +30 -8
  39. package/dist/steps/Picker/types.d.ts.map +1 -1
  40. package/dist/steps/Picker/types.js +2 -8
  41. package/dist/steps/Picker/types.js.map +1 -1
  42. package/dist/steps/Question/types.d.ts +30 -8
  43. package/dist/steps/Question/types.d.ts.map +1 -1
  44. package/dist/steps/Question/types.js +2 -8
  45. package/dist/steps/Question/types.js.map +1 -1
  46. package/dist/steps/Ratings/types.d.ts +29 -8
  47. package/dist/steps/Ratings/types.d.ts.map +1 -1
  48. package/dist/steps/Ratings/types.js +1 -8
  49. package/dist/steps/Ratings/types.js.map +1 -1
  50. package/dist/steps/common.types.d.ts +109 -0
  51. package/dist/steps/common.types.d.ts.map +1 -1
  52. package/dist/steps/common.types.js +52 -1
  53. package/dist/steps/common.types.js.map +1 -1
  54. package/dist/types.d.ts +2 -0
  55. package/dist/types.d.ts.map +1 -1
  56. package/package.json +5 -2
  57. package/src/__tests__/evaluateCondition.test.ts +167 -0
  58. package/src/__tests__/resolveNextStepNumber.test.ts +309 -0
  59. package/src/evaluateCondition.ts +50 -0
  60. package/src/index.ts +19 -0
  61. package/src/infra/provider/OnboardingProvider.tsx +11 -1
  62. package/src/resolveNextStepNumber.ts +41 -0
  63. package/src/steps/Carousel/types.ts +2 -9
  64. package/src/steps/Commitment/types.ts +2 -9
  65. package/src/steps/ComposableScreen/types.ts +2 -8
  66. package/src/steps/Loader/types.ts +2 -9
  67. package/src/steps/MediaContent/types.ts +2 -14
  68. package/src/steps/Picker/types.ts +3 -9
  69. package/src/steps/Question/types.ts +3 -9
  70. package/src/steps/Ratings/types.ts +2 -9
  71. package/src/steps/common.types.ts +72 -0
  72. package/src/types.ts +3 -0
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ButtonSectionSchema, CustomPayloadSchema } from "../common.types";
2
+ import { BaseStepTypeSchema } from "../common.types";
3
3
 
4
4
  export const CommitmentItemSchema = z.object({
5
5
  text: z.string(),
@@ -14,16 +14,9 @@ export const CommitmentStepPayloadSchema = z.object({
14
14
  variant: z.enum(["signature", "simple"]).default("signature"),
15
15
  });
16
16
 
17
- export const CommitmentStepTypeSchema = z.object({
18
- id: z.string(),
17
+ export const CommitmentStepTypeSchema = BaseStepTypeSchema.extend({
19
18
  type: z.literal("Commitment"),
20
- name: z.string(),
21
- displayProgressHeader: z.boolean(),
22
19
  payload: CommitmentStepPayloadSchema,
23
- customPayload: CustomPayloadSchema,
24
- continueButtonLabel: z.string().optional().default("Continue"),
25
- buttonSection: ButtonSectionSchema.optional(),
26
- figmaUrl: z.string().nullish(),
27
20
  });
28
21
 
29
22
  export type CommitmentStepType = z.infer<typeof CommitmentStepTypeSchema>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { CustomPayloadSchema } from "../common.types";
2
+ import { BaseStepTypeSchema } from "../common.types";
3
3
  import { type StackElementProps, StackElementPropsSchema } from "./elements/StackElement";
4
4
  import { type TextElementProps, TextElementPropsSchema } from "./elements/TextElement";
5
5
  import { type ImageElementProps, ImageElementPropsSchema } from "./elements/ImageElement";
@@ -203,15 +203,9 @@ export const ComposableScreenStepPayloadSchema = z.object({
203
203
  elements: z.array(UIElementSchema),
204
204
  });
205
205
 
206
- export const ComposableScreenStepTypeSchema = z.object({
207
- id: z.string(),
206
+ export const ComposableScreenStepTypeSchema = BaseStepTypeSchema.extend({
208
207
  type: z.literal("ComposableScreen"),
209
- name: z.string(),
210
- displayProgressHeader: z.boolean(),
211
208
  payload: ComposableScreenStepPayloadSchema,
212
- customPayload: CustomPayloadSchema,
213
- continueButtonLabel: z.string().optional().default("Continue"),
214
- figmaUrl: z.string().nullable(),
215
209
  });
216
210
 
217
211
  export type ComposableScreenStepType = z.infer<typeof ComposableScreenStepTypeSchema>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ButtonSectionSchema, CustomPayloadSchema, MediaSourceSchema } from "../common.types";
2
+ import { BaseStepTypeSchema, MediaSourceSchema } from "../common.types";
3
3
 
4
4
  export const LoaderStepSchema = z.object({
5
5
  label: z.string(),
@@ -17,16 +17,9 @@ export const LoaderStepPayloadSchema = z.object({
17
17
  .default("bars"),
18
18
  });
19
19
 
20
- export const LoaderStepTypeSchema = z.object({
21
- id: z.string(),
20
+ export const LoaderStepTypeSchema = BaseStepTypeSchema.extend({
22
21
  type: z.literal("Loader"),
23
- name: z.string(),
24
- displayProgressHeader: z.boolean(),
25
22
  payload: LoaderStepPayloadSchema,
26
- customPayload: CustomPayloadSchema,
27
- continueButtonLabel: z.string().optional().default("Continue"),
28
- buttonSection: ButtonSectionSchema.optional(),
29
- figmaUrl: z.string().nullish(),
30
23
  });
31
24
 
32
25
  export type LoaderStepType = z.infer<typeof LoaderStepTypeSchema>;
@@ -1,10 +1,5 @@
1
1
  import { z } from "zod";
2
- import {
3
- ButtonSectionSchema,
4
- CustomPayloadSchema,
5
- MediaSourceSchema,
6
- SocialProofSchema,
7
- } from "../common.types";
2
+ import { BaseStepTypeSchema, MediaSourceSchema, SocialProofSchema } from "../common.types";
8
3
 
9
4
  export const MediaContentLayoutStyleSchema = z.enum(["default", "media_top", "media_bottom"]).default("default");
10
5
 
@@ -16,16 +11,9 @@ export const MediaContentStepPayloadSchema = z.object({
16
11
  layoutStyle: MediaContentLayoutStyleSchema.optional(),
17
12
  });
18
13
 
19
- export const MediaContentStepTypeSchema = z.object({
20
- id: z.string(),
14
+ export const MediaContentStepTypeSchema = BaseStepTypeSchema.extend({
21
15
  type: z.literal("MediaContent"),
22
- name: z.string(),
23
- displayProgressHeader: z.boolean(),
24
16
  payload: MediaContentStepPayloadSchema,
25
- customPayload: CustomPayloadSchema,
26
- continueButtonLabel: z.string().optional().default("Continue"),
27
- buttonSection: ButtonSectionSchema.optional(),
28
- figmaUrl: z.string().nullish(),
29
17
  });
30
18
 
31
19
  export type MediaContentStepType = z.infer<typeof MediaContentStepTypeSchema>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ButtonSectionSchema, CustomPayloadSchema } from "../common.types";
2
+ import { BaseStepTypeSchema } from "../common.types";
3
3
 
4
4
  export const PickerTypeEnum = z.enum([
5
5
  "height",
@@ -17,16 +17,10 @@ export const PickerStepPayloadSchema = z.object({
17
17
  pickerType: z.union([PickerTypeEnum, z.string()]),
18
18
  });
19
19
 
20
- export const PickerStepTypeSchema = z.object({
21
- id: z.string(),
20
+ export const PickerStepTypeSchema = BaseStepTypeSchema.extend({
22
21
  type: z.literal("Picker"),
23
- name: z.string(),
24
- displayProgressHeader: z.boolean(),
25
22
  payload: PickerStepPayloadSchema,
26
- customPayload: CustomPayloadSchema,
27
- continueButtonLabel: z.string().optional().default("Continue"),
28
- buttonSection: ButtonSectionSchema.optional(),
29
- figmaUrl: z.string().nullish(),
23
+ variableName: z.string().min(1).optional(),
30
24
  });
31
25
 
32
26
  export type PickerStepType = z.infer<typeof PickerStepTypeSchema>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ButtonSectionSchema, CustomPayloadSchema, InfoBoxSchema } from "../common.types";
2
+ import { BaseStepTypeSchema, InfoBoxSchema } from "../common.types";
3
3
 
4
4
  export const AnswerSchema = z.object({
5
5
  label: z.string(),
@@ -16,16 +16,10 @@ export const QuestionStepPayloadSchema = z.object({
16
16
  infoBox: InfoBoxSchema.nullish(),
17
17
  });
18
18
 
19
- export const QuestionStepTypeSchema = z.object({
20
- id: z.string(),
19
+ export const QuestionStepTypeSchema = BaseStepTypeSchema.extend({
21
20
  type: z.literal("Question"),
22
- name: z.string(),
23
- displayProgressHeader: z.boolean(),
24
21
  payload: QuestionStepPayloadSchema,
25
- customPayload: CustomPayloadSchema,
26
- continueButtonLabel: z.string().optional().default("Continue"),
27
- buttonSection: ButtonSectionSchema.optional(),
28
- figmaUrl: z.string().nullish(),
22
+ variableName: z.string().min(1).optional(),
29
23
  });
30
24
 
31
25
  export type QuestionStepType = z.infer<typeof QuestionStepTypeSchema>;
@@ -1,5 +1,5 @@
1
1
  import z from "zod";
2
- import { ButtonSectionSchema, CustomPayloadSchema, SocialProofSchema } from "../common.types";
2
+ import { BaseStepTypeSchema, SocialProofSchema } from "../common.types";
3
3
 
4
4
  export const RatingsStepPayloadSchema = z.object({
5
5
  title: z.string(),
@@ -8,16 +8,9 @@ export const RatingsStepPayloadSchema = z.object({
8
8
  rateTheAppButtonLabel: z.string().optional().default("Rate the app"),
9
9
  });
10
10
 
11
- export const RatingsStepTypeSchema = z.object({
12
- id: z.string(),
11
+ export const RatingsStepTypeSchema = BaseStepTypeSchema.extend({
13
12
  type: z.literal("Ratings"),
14
- name: z.string(),
15
- displayProgressHeader: z.boolean(),
16
13
  payload: RatingsStepPayloadSchema,
17
- customPayload: CustomPayloadSchema,
18
- continueButtonLabel: z.string().optional().default("Continue"),
19
- buttonSection: ButtonSectionSchema.optional(),
20
- figmaUrl: z.string().nullish(),
21
14
  });
22
15
 
23
16
  export type RatingsStepType = z.infer<typeof RatingsStepTypeSchema>;
@@ -28,3 +28,75 @@ export const ButtonSectionSchema = z.object({
28
28
  label: z.string().optional(),
29
29
  icon: z.string().nullish(),
30
30
  });
31
+
32
+ // ── Branching / nextStep schemas ─────────────────────────────────────────────
33
+
34
+ export const ConditionOperatorSchema = z.enum([
35
+ "eq",
36
+ "neq",
37
+ "gt",
38
+ "lt",
39
+ "gte",
40
+ "lte",
41
+ "contains",
42
+ "in",
43
+ "not_in",
44
+ ]);
45
+ export type ConditionOperator = z.infer<typeof ConditionOperatorSchema>;
46
+
47
+ export const ConditionValueSchema = z.union([
48
+ z.string(),
49
+ z.number(),
50
+ z.boolean(),
51
+ z.array(z.union([z.string(), z.number(), z.boolean()])),
52
+ ]);
53
+ export type ConditionValue = z.infer<typeof ConditionValueSchema>;
54
+
55
+ export const LeafConditionSchema = z.object({
56
+ variable: z.string().min(1),
57
+ operator: ConditionOperatorSchema,
58
+ value: ConditionValueSchema,
59
+ });
60
+ export type LeafCondition = z.infer<typeof LeafConditionSchema>;
61
+
62
+ export type ConditionGroup = {
63
+ logic: "and" | "or";
64
+ conditions: Array<LeafCondition | ConditionGroup>;
65
+ };
66
+
67
+ export const ConditionGroupSchema: z.ZodType<ConditionGroup> = z.lazy(() =>
68
+ z.object({
69
+ logic: z.enum(["and", "or"]),
70
+ conditions: z
71
+ .array(z.union([LeafConditionSchema, ConditionGroupSchema]))
72
+ .min(1),
73
+ })
74
+ );
75
+
76
+ export const BranchSchema = z.object({
77
+ condition: z.union([LeafConditionSchema, ConditionGroupSchema]).nullable().default(null),
78
+ targetStepId: z.string().min(1),
79
+ });
80
+ export type Branch = z.infer<typeof BranchSchema>;
81
+
82
+ export const NextStepSchema = z
83
+ .object({
84
+ defaultTargetStepId: z.string().min(1),
85
+ branches: z.array(BranchSchema).default([]),
86
+ })
87
+ .nullable()
88
+ .default(null);
89
+ export type NextStep = z.infer<typeof NextStepSchema>;
90
+
91
+ // ── Base step schema ──────────────────────────────────────────────────────────
92
+
93
+ export const BaseStepTypeSchema = z.object({
94
+ id: z.string(),
95
+ name: z.string(),
96
+ displayProgressHeader: z.boolean(),
97
+ customPayload: CustomPayloadSchema,
98
+ continueButtonLabel: z.string().optional().default("Continue"),
99
+ buttonSection: ButtonSectionSchema.optional(),
100
+ figmaUrl: z.string().nullish(),
101
+ nextStep: NextStepSchema,
102
+ });
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { NextStep } from "./steps/common.types";
2
+
1
3
  /**
2
4
  * Base step type that all onboarding steps must conform to.
3
5
  * This is the minimal interface required by the headless SDK.
@@ -11,6 +13,7 @@ export type BaseStepType = {
11
13
  customPayload?: any;
12
14
  continueButtonLabel?: string;
13
15
  figmaUrl?: string | null;
16
+ nextStep?: NextStep;
14
17
  };
15
18
 
16
19
  export type OnboardingStudioClientOptions<