picked 0.0.101-next.2 → 0.0.101

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 (175) hide show
  1. package/README.md +27 -12
  2. package/docs/explanation/conditions-and-the-logic-engine.md +94 -0
  3. package/docs/explanation/content-references.md +99 -0
  4. package/docs/explanation/feature-flag-allocation.md +218 -0
  5. package/docs/explanation/how-picked-works.md +124 -0
  6. package/docs/explanation/how-pickedql-works.md +76 -0
  7. package/docs/explanation/pages-and-flows.md +64 -0
  8. package/docs/explanation/the-content-model.md +87 -0
  9. package/docs/explanation/the-two-apis.md +68 -0
  10. package/docs/explanation/why-server-side-rendering.md +76 -0
  11. package/docs/explanation/workspaces-and-versions.md +71 -0
  12. package/docs/how-to/add-a-step-field-or-action.md +56 -0
  13. package/docs/how-to/analytics/index.md +324 -0
  14. package/docs/how-to/archive-or-delete-a-workspace.md +59 -0
  15. package/docs/how-to/authenticate-the-cli.md +101 -0
  16. package/docs/how-to/authenticate-with-a-magic-link.md +56 -0
  17. package/docs/how-to/authenticate-with-a-password.md +68 -0
  18. package/docs/how-to/authenticate-with-an-api-key.md +60 -0
  19. package/docs/how-to/authenticate-with-oauth.md +49 -0
  20. package/docs/how-to/build-a-flow.md +106 -0
  21. package/docs/how-to/call-an-external-api-from-a-workflow.md +116 -0
  22. package/docs/how-to/connect-the-mcp-server.md +46 -0
  23. package/docs/how-to/create-a-content-entry.md +58 -0
  24. package/docs/how-to/create-a-project.md +40 -0
  25. package/docs/how-to/create-an-experience.md +51 -0
  26. package/docs/how-to/create-and-revoke-an-api-key.md +54 -0
  27. package/docs/how-to/debug-with-the-chrome-extension.md +57 -0
  28. package/docs/how-to/define-a-page-layout.md +54 -0
  29. package/docs/how-to/fill-and-publish-a-page.md +82 -0
  30. package/docs/how-to/install-the-gtm-template.md +84 -0
  31. package/docs/how-to/install-the-sdk.md +93 -0
  32. package/docs/how-to/install-the-vite-plugin.md +69 -0
  33. package/docs/how-to/invite-and-remove-members.md +45 -0
  34. package/docs/how-to/point-one-entry-at-another.md +75 -0
  35. package/docs/how-to/preview-a-workspace.md +39 -0
  36. package/docs/how-to/publish-a-workspace.md +42 -0
  37. package/docs/how-to/read-a-feature-flag.md +113 -0
  38. package/docs/how-to/read-a-referenced-entry.md +109 -0
  39. package/docs/how-to/register-a-component.md +55 -0
  40. package/docs/how-to/register-an-action-handler.md +85 -0
  41. package/docs/how-to/register-an-api-that-uses-oauth2.md +107 -0
  42. package/docs/how-to/render-a-step-form.md +131 -0
  43. package/docs/how-to/render-an-unpublished-preview.md +41 -0
  44. package/docs/how-to/retry-a-failed-call-with-a-loop.md +81 -0
  45. package/docs/how-to/reuse-a-section.md +64 -0
  46. package/docs/how-to/reuse-a-step-field-or-action.md +39 -0
  47. package/docs/how-to/roll-back-a-published-version.md +39 -0
  48. package/docs/how-to/run-an-ab-test.md +59 -0
  49. package/docs/how-to/run-code-on-a-form-submission.md +125 -0
  50. package/docs/how-to/server-render-a-page.md +81 -0
  51. package/docs/how-to/set-a-content-security-policy.md +32 -0
  52. package/docs/how-to/set-up-mfa.md +126 -0
  53. package/docs/how-to/switch-workspaces.md +122 -0
  54. package/docs/how-to/upload-and-use-an-asset.mdx +87 -0
  55. package/docs/how-to/validate-a-field.md +52 -0
  56. package/docs/how-to/wait-for-an-action-response.md +182 -0
  57. package/docs/how-to/write-a-condition.md +57 -0
  58. package/docs/how-to/write-a-predicate.md +60 -0
  59. package/docs/index.md +59 -0
  60. package/docs/reference/dashboard/actions.mdx +65 -0
  61. package/docs/reference/dashboard/api-keys.mdx +47 -0
  62. package/docs/reference/dashboard/conditions.mdx +51 -0
  63. package/docs/reference/dashboard/content/asset-library.mdx +74 -0
  64. package/docs/reference/dashboard/content/blocks.mdx +66 -0
  65. package/docs/reference/dashboard/content/content-entries.mdx +109 -0
  66. package/docs/reference/dashboard/content/models.mdx +119 -0
  67. package/docs/reference/dashboard/content/pages.mdx +72 -0
  68. package/docs/reference/dashboard/experiences.mdx +61 -0
  69. package/docs/reference/dashboard/external-apis.md +182 -0
  70. package/docs/reference/dashboard/features.mdx +165 -0
  71. package/docs/reference/dashboard/fields.mdx +120 -0
  72. package/docs/reference/dashboard/flow-builder/canvas.mdx +58 -0
  73. package/docs/reference/dashboard/flow-builder/condition-builder.md +69 -0
  74. package/docs/reference/dashboard/flow-builder/keyboard-shortcuts.md +72 -0
  75. package/docs/reference/dashboard/flow-builder/nodes.md +74 -0
  76. package/docs/reference/dashboard/labels.md +321 -0
  77. package/docs/reference/dashboard/lead-search.md +235 -0
  78. package/docs/reference/dashboard/projects.mdx +53 -0
  79. package/docs/reference/dashboard/reports.mdx +53 -0
  80. package/docs/reference/dashboard/steps.mdx +47 -0
  81. package/docs/reference/dashboard/team-management.md +38 -0
  82. package/docs/reference/dashboard/workflow-runs.md +157 -0
  83. package/docs/reference/dashboard/workflow-templates.md +182 -0
  84. package/docs/reference/dashboard/workflow-test-runs.md +85 -0
  85. package/docs/reference/dashboard/workspace-versioning.mdx +42 -0
  86. package/docs/reference/dashboard/workspaces.mdx +91 -0
  87. package/docs/reference/delivery-api/experience-content.md +152 -0
  88. package/docs/reference/delivery-api/index.md +45 -0
  89. package/docs/reference/delivery-api/preview-caching-crawling.md +79 -0
  90. package/docs/reference/delivery-api/project-config.md +65 -0
  91. package/docs/reference/delivery-api/workspace-schema.md +107 -0
  92. package/docs/reference/glossary.md +201 -0
  93. package/docs/reference/management-api/authentication.md +87 -0
  94. package/docs/reference/management-api/authorization-and-scopes.md +291 -0
  95. package/docs/reference/management-api/error-handling.md +232 -0
  96. package/docs/reference/management-api/pagination.md +192 -0
  97. package/docs/reference/management-api/schema/action.md +261 -0
  98. package/docs/reference/management-api/schema/analytics-session.md +363 -0
  99. package/docs/reference/management-api/schema/analytics.md +73 -0
  100. package/docs/reference/management-api/schema/api-key.md +170 -0
  101. package/docs/reference/management-api/schema/auth.md +1177 -0
  102. package/docs/reference/management-api/schema/cms-fields.md +954 -0
  103. package/docs/reference/management-api/schema/cms-models.md +1155 -0
  104. package/docs/reference/management-api/schema/common.md +362 -0
  105. package/docs/reference/management-api/schema/condition.md +254 -0
  106. package/docs/reference/management-api/schema/design-system.md +199 -0
  107. package/docs/reference/management-api/schema/experience.md +1098 -0
  108. package/docs/reference/management-api/schema/external-api.md +637 -0
  109. package/docs/reference/management-api/schema/feature.md +350 -0
  110. package/docs/reference/management-api/schema/feedback.md +103 -0
  111. package/docs/reference/management-api/schema/field.md +400 -0
  112. package/docs/reference/management-api/schema/index.md +243 -0
  113. package/docs/reference/management-api/schema/integration.md +272 -0
  114. package/docs/reference/management-api/schema/label.md +349 -0
  115. package/docs/reference/management-api/schema/lead.md +340 -0
  116. package/docs/reference/management-api/schema/mcp-server.md +299 -0
  117. package/docs/reference/management-api/schema/metric.md +223 -0
  118. package/docs/reference/management-api/schema/operation.md +96 -0
  119. package/docs/reference/management-api/schema/organization.md +749 -0
  120. package/docs/reference/management-api/schema/project.md +607 -0
  121. package/docs/reference/management-api/schema/report.md +243 -0
  122. package/docs/reference/management-api/schema/saved-view.md +288 -0
  123. package/docs/reference/management-api/schema/shopify.md +795 -0
  124. package/docs/reference/management-api/schema/step.md +273 -0
  125. package/docs/reference/management-api/schema/tenant-branding.md +185 -0
  126. package/docs/reference/management-api/schema/workbench.md +246 -0
  127. package/docs/reference/management-api/schema/workflow-run.md +263 -0
  128. package/docs/reference/management-api/schema/workflow.md +1110 -0
  129. package/docs/reference/management-api/schema/workspace-version.md +823 -0
  130. package/docs/reference/management-api/schema/workspace.md +917 -0
  131. package/docs/reference/pickedql/data-sources.md +174 -0
  132. package/docs/reference/pickedql/dimensions.md +103 -0
  133. package/docs/reference/pickedql/filtering.md +64 -0
  134. package/docs/reference/pickedql/index.md +18 -0
  135. package/docs/reference/pickedql/schema.md +172 -0
  136. package/docs/reference/pickedql/virtual-functions.md +248 -0
  137. package/docs/reference/sdk/actions.md +154 -0
  138. package/docs/reference/sdk/analytics-events.md +453 -0
  139. package/docs/reference/sdk/conditions.md +147 -0
  140. package/docs/reference/sdk/content-security-policy.md +21 -0
  141. package/docs/reference/sdk/content.md +253 -0
  142. package/docs/reference/sdk/experiences.md +51 -0
  143. package/docs/reference/sdk/features.md +256 -0
  144. package/docs/reference/sdk/fields.md +255 -0
  145. package/docs/reference/sdk/index.md +68 -0
  146. package/docs/reference/sdk/plugins/create-experience.md +123 -0
  147. package/docs/reference/sdk/plugins/dynamic-experiences.md +74 -0
  148. package/docs/reference/sdk/plugins/fingerprintjs.md +39 -0
  149. package/docs/reference/sdk/plugins/hotjar.md +60 -0
  150. package/docs/reference/sdk/plugins/index.md +33 -0
  151. package/docs/reference/sdk/plugins/sentry.md +51 -0
  152. package/docs/reference/sdk/plugins/shopify.md +109 -0
  153. package/docs/reference/sdk/plugins/window-object.md +25 -0
  154. package/docs/reference/sdk/predicates.md +43 -0
  155. package/docs/reference/sdk/react.md +61 -0
  156. package/docs/reference/sdk/ssr/index.md +33 -0
  157. package/docs/reference/sdk/ssr/rendering-and-hydration.md +103 -0
  158. package/docs/reference/sdk/ssr/serialize.md +80 -0
  159. package/docs/reference/sdk/ssr/slots-and-placements.md +113 -0
  160. package/docs/reference/sdk/steps.md +86 -0
  161. package/docs/reference/sdk/svelte.md +74 -0
  162. package/docs/reference/sdk/type-generation.md +265 -0
  163. package/docs/reference/tools/admin-api-client.md +89 -0
  164. package/docs/reference/tools/chrome-extension.md +16 -0
  165. package/docs/reference/tools/cli.md +319 -0
  166. package/docs/reference/tools/delivery-api-client.md +60 -0
  167. package/docs/reference/tools/image-optimisation-service.md +104 -0
  168. package/docs/reference/tools/mcp-run.md +121 -0
  169. package/docs/reference/tools/mcp.md +391 -0
  170. package/docs/reference/tools/vite-plugin.md +163 -0
  171. package/docs/tutorials/first-api-call.md +253 -0
  172. package/docs/tutorials/first-experience-in-the-dashboard.mdx +160 -0
  173. package/docs/tutorials/first-experience.mdx +254 -0
  174. package/docs/tutorials/first-server-rendered-page.mdx +186 -0
  175. package/package.json +8 -7
@@ -0,0 +1,248 @@
1
+ ---
2
+ type: reference
3
+ layout: docs
4
+ ---
5
+
6
+ # Virtual functions
7
+
8
+ A virtual function is a short form of an aggregate expression. Each one is
9
+ **table-aware**. The same function expands one way on `metrics`, where PickedQL
10
+ aggregates the data first. It expands another way on `events`, where there is one row
11
+ for each user.
12
+
13
+ ## A/B test metrics
14
+
15
+ | Function | Description |
16
+ |---|---|
17
+ | `control_users([condition])` | The different users in the Control group. A condition of your own can narrow them. |
18
+ | `variant_users([condition])` | The different users in the Variant group. A condition of your own can narrow them. |
19
+ | `all_users()` | Every different user |
20
+ | `control_sessions([condition])` | The different sessions in the Control group. A condition of your own can narrow them. |
21
+ | `variant_sessions([condition])` | The different sessions in the Variant group. A condition of your own can narrow them. |
22
+ | `all_sessions()` | Every different session |
23
+
24
+ ### Your own filters on `events`
25
+
26
+ On the `events` table, each `control_*` function and each `variant_*` function takes
27
+ **one optional filter argument**. The filter counts only a user or a session that
28
+ matches your expression. It applies together with the `variant_type` filter that
29
+ PickedQL adds. Give the argument in the first place, or by the name `filter=`.
30
+
31
+ The filter uses the same `column=value` syntax as a conversion-rate condition. It
32
+ takes the `AND` and `OR` operators, and parentheses can hold a set of terms.
33
+
34
+ ```sql
35
+ -- The default: every Control user.
36
+ SELECT control_users() FROM events
37
+
38
+ -- Your own filter, in the first place.
39
+ SELECT control_users('event_type=app_initialize') FROM events
40
+ SELECT variant_users('event_type=app_initialize AND step_id=xxx') FROM events
41
+
42
+ -- The AND and OR operators, with parentheses.
43
+ SELECT control_users('event_type=app_initialize OR event_type=app_load') FROM events
44
+ SELECT control_users('event_type=form_submit AND (step_id=lead-capture OR step_id=xxx)') FROM events
45
+
46
+ -- Sessions
47
+ SELECT control_sessions('event_type=step_enter') FROM events
48
+ SELECT variant_sessions('event_type=step_enter AND step_id=checkout') FROM events
49
+
50
+ -- Named form
51
+ SELECT control_users(filter='event_type=app_initialize AND step_id=xxx') FROM events
52
+ ```
53
+
54
+ :::note
55
+ A filter of your own is **not supported on `metrics`**, because PickedQL aggregates
56
+ that data first. On `metrics` these functions ignore every argument. They use the
57
+ default Control filter and Variant filter only.
58
+ :::
59
+
60
+ ## Conversion metrics
61
+
62
+ | Function | Description |
63
+ |---|---|
64
+ | `all_purchase_users()` | Users who completed a purchase |
65
+ | `control_purchase_users()` | Control users who purchased (`metrics` only) |
66
+ | `variant_purchase_users()` | Variant users who purchased (`metrics` only) |
67
+ | `all_purchase_sessions()` | Sessions with a purchase (`metrics` only) |
68
+ | `all_purchase_orders()` | Unique order count (`metrics` only) |
69
+ | `all_cart_add_users()` | Users who added to cart |
70
+
71
+ ## Conversion rates
72
+
73
+ | Function | Description |
74
+ |---|---|
75
+ | `control_conversion_rate([numerator [, denominator]])` | The conversion rate of the Control group. By default it divides the users with a purchase by all users. |
76
+ | `variant_conversion_rate([numerator [, denominator]])` | The conversion rate of the Variant group. It takes the same arguments. |
77
+ | `conversion_rate_uplift([numerator [, denominator]])` | The gain of the Variant over the Control: `(variant CR - control CR) / control CR`. It takes the same arguments. |
78
+
79
+ ### Your own conditions on `events`
80
+
81
+ On the `events` table, each conversion-rate function takes up to **two optional
82
+ arguments**. They set the numerator and the denominator. Each argument is either a
83
+ **condition expression string** or a **nested virtual function call**. See below.
84
+ Give the arguments in order, or by the names `numerator=` and `denominator=`.
85
+
86
+ Each condition expression uses `column=value`, with the `AND` and `OR` operators.
87
+ Parentheses can hold a set of terms.
88
+
89
+ ```sql
90
+ -- Default: purchase users / all users
91
+ SELECT control_conversion_rate() FROM events
92
+
93
+ -- Custom numerator, default denominator (all users)
94
+ SELECT control_conversion_rate('event_type=form_submit_success') FROM events
95
+
96
+ -- The AND and OR operators in a condition.
97
+ SELECT control_conversion_rate('event_type=checkout_complete OR event_type=order_create') FROM events
98
+ SELECT control_conversion_rate('step_id=lead-capture AND event_type=form_submit_success') FROM events
99
+
100
+ -- Parentheses hold a set of terms.
101
+ SELECT control_conversion_rate('event_type=form_submit AND (step_id=lead-capture OR step_id=xxx)') FROM events
102
+
103
+ -- Custom numerator AND denominator (positional)
104
+ SELECT control_conversion_rate('event_type=form_submit', 'step_id=lead-capture') FROM events
105
+
106
+ -- Named arguments (explicit, any order)
107
+ SELECT control_conversion_rate(numerator='event_type=form_submit', denominator='step_id=lead-capture') FROM events
108
+
109
+ -- Named: denominator only (numerator defaults to purchase)
110
+ SELECT control_conversion_rate(denominator='step_id=lead-capture') FROM events
111
+
112
+ -- The uplift, with the arguments given by name.
113
+ SELECT conversion_rate_uplift(numerator='event_type=form_submit', denominator='step_id=lead-capture') FROM events
114
+ ```
115
+
116
+ #### A nested virtual function as the numerator or the denominator
117
+
118
+ You can pass a **virtual function call** as the numerator or the denominator, in
119
+ place of a condition string. PickedQL puts the inner aggregate there directly. It
120
+ adds no `variant_type` filter above it, because the nested function sets its own
121
+ filter.
122
+
123
+ This form is the most flexible one when the numerator and the denominator come from
124
+ different segments. An example is the Control users who fired one event, over **all**
125
+ users of every variant:
126
+
127
+ ```sql
128
+ -- The Control users who fired `app_initialize`, over all users.
129
+ SELECT control_conversion_rate(
130
+ control_users('event_type=app_initialize'),
131
+ all_users()
132
+ ) FROM events
133
+
134
+ -- Mix string and nested forms
135
+ SELECT control_conversion_rate(
136
+ 'event_type=form_submit',
137
+ all_users()
138
+ ) FROM events
139
+
140
+ -- The uplift, with a nested function in each place.
141
+ SELECT conversion_rate_uplift(
142
+ control_users('event_type=app_initialize'),
143
+ all_users()
144
+ ) FROM events
145
+ ```
146
+
147
+ :::note
148
+ A condition of your own, and a nested virtual function, are both **not supported on
149
+ `metrics`**, because PickedQL aggregates that data first. On `metrics` these
150
+ functions always divide the users with a purchase by all users.
151
+ :::
152
+
153
+ ## Visitor segmentation (`metrics` only)
154
+
155
+ | Function | Description |
156
+ |---|---|
157
+ | `new_users()` | First-time visitors |
158
+ | `returning_users()` | Returning visitors |
159
+ | `new_sessions()` | Sessions from new visitors |
160
+ | `returning_sessions()` | Sessions from returning visitors |
161
+
162
+ ## Funnel metrics (`events` only)
163
+
164
+ :::note
165
+ We add to the funnel metrics all the time. Read this page again for a new function.
166
+ :::
167
+
168
+ | Function | Description |
169
+ |---|---|
170
+ | `step_enter_users()` | Users who entered a funnel step |
171
+ | `step_enter_sessions()` | Sessions that entered a funnel step |
172
+
173
+ ## Cohort filters (`events` only)
174
+
175
+ Each of these functions has the shape of a predicate. It writes a
176
+ `user_canonical_id IN (SELECT … FROM events …)` subquery. Put one in a `WHERE` clause
177
+ to limit any analysis to a user with at least one event that matches a condition of
178
+ your own.
179
+
180
+ | Function | Description |
181
+ |---|---|
182
+ | `user_cohort_filter('<condition>')` | Limits the query to a user with one or more `events` rows that match `<condition>` |
183
+ | `user_cohort_filter(filter='<condition>')` | The same, with the argument given by name |
184
+
185
+ `<condition>` uses the same short `column=value [AND\|OR …]` form as `control_users`
186
+ and `variant_users`.
187
+
188
+ ```sql
189
+ -- Funnel scoped to users who eventually submitted lead capture
190
+ SELECT all_users(), all_purchase_users()
191
+ FROM events
192
+ WHERE project_id = 'proj-abc'
193
+ AND user_cohort_filter('event_type=lead_capture')
194
+
195
+ -- Multi-condition cohort with OR-grouping
196
+ SELECT all_sessions()
197
+ FROM events
198
+ WHERE project_id = 'proj-abc'
199
+ AND user_cohort_filter('event_type=signup OR event_type=trial_start')
200
+ ```
201
+
202
+ The outer query MUST hold one `project_id` filter. The function puts that tenant into
203
+ the inner subquery. The read of the cohort therefore covers your project, and not the
204
+ whole warehouse.
205
+
206
+ ## Feature functions, on `features` and on `events`
207
+
208
+ Parameterized functions that accept the feature name, bucket, and an optional feature key:
209
+
210
+ | Function | Description |
211
+ |---|---|
212
+ | `feature_users('name', 'bucket' [, 'key'])` | Unique users in a feature bucket |
213
+ | `feature_sessions('name', 'bucket' [, 'key'])` | Unique sessions in a feature bucket |
214
+ | `feature_events('name', 'bucket' [, 'key'])` | Unique events in a feature bucket |
215
+
216
+ The bucket is what the SDK sent to the site of the visitor. A Boolean feature flag gives
217
+ `'true'` or `'false'`. A Text feature flag gives the value of one variant, or `'false'` for
218
+ the control group. The key is the version of the feature flag, such as `'v1'`.
219
+
220
+ ```sql
221
+ -- Compare the two buckets of a Boolean feature flag.
222
+ SELECT
223
+ feature_users('homepage_test', 'false') AS control,
224
+ feature_users('homepage_test', 'true') AS variant
225
+ FROM features
226
+
227
+ -- Compare the variants of a Text feature flag.
228
+ SELECT
229
+ feature_users('hero', 'false') AS control,
230
+ feature_users('hero', 'hero-a') AS hero_a,
231
+ feature_users('hero', 'hero-b') AS hero_b
232
+ FROM features
233
+
234
+ -- Count one version of the feature flag alone.
235
+ SELECT feature_users('homepage_test', 'false', 'v1') FROM features
236
+ ```
237
+
238
+ ## Other (`metrics` only)
239
+
240
+ | Function | Description |
241
+ |---|---|
242
+ | `event_count()` | Total event count (from pre-aggregation) |
243
+
244
+ ## Related
245
+
246
+ - [Filters](/reference/pickedql/filtering) — the filter string a function takes.
247
+ - [Analytics queries](/how-to/analytics)
248
+ - [About PickedQL](/explanation/how-pickedql-works)
@@ -0,0 +1,154 @@
1
+ ---
2
+ type: reference
3
+ layout: docs
4
+ ---
5
+
6
+ # Actions
7
+
8
+ An action is a function that the SDK runs by its key. An action comes from one of two
9
+ places:
10
+
11
+ - **Your application** registers a handler in `createClient({ actions })`.
12
+ - **Your project** publishes the action. Its handler sends the visitor's answers to Picked,
13
+ and the workflow of the action runs there.
14
+
15
+ A handler from your application replaces a published action that has the same key. The
16
+ workflow then does not start.
17
+
18
+ ## Response
19
+
20
+ The value that a handler returns is the response of the action. A handler can return any
21
+ value, or a promise of any value.
22
+
23
+ The response of a published action is the payload of the **Action response** node in its
24
+ workflow. A workflow that has no **Action response** node gives `undefined`.
25
+
26
+ ## Outcome and branch
27
+
28
+ | Handler outcome | Branch the flow takes |
29
+ | --- | --- |
30
+ | Throws, or its promise rejects | `onFail` |
31
+ | Resolves to any value, and that includes `false` | `onSuccess` |
32
+
33
+ An action node can also carry one plain connection, with no success or failure branch. The
34
+ flow then continues through it on either outcome.
35
+
36
+ An action does not interrupt your visitor. The current step stays on the screen while an
37
+ async action runs. While the action runs, the flow ignores a request to go to the next step
38
+ or to a specified step. The outcome of the action then chooses the branch. If your visitor
39
+ goes back before the action completes, the flow stays on that step. The signal that the
40
+ handler receives then stops.
41
+
42
+ ## Published actions
43
+
44
+ A published action waits for the response of its workflow. It stops after 30 seconds.
45
+
46
+ | Cause | The action rejects with |
47
+ | --- | --- |
48
+ | Picked refuses the request | An `Error` that names the HTTP status |
49
+ | Picked does not accept the request in 25 seconds | A `TimeoutError` |
50
+ | Picked accepts the request, but gives no run to wait for | An `Error` that says that no run is available |
51
+ | The workflow fails before it sends a response | `ActionRunFailedError` |
52
+ | Picked refuses a request for the response with a `4xx` status | An `Error` that names the HTTP status |
53
+ | No response in 30 seconds | `ActionResponseTimeoutError` |
54
+ | Your code stops the wait with a signal | The reason of the signal |
55
+
56
+ A request for the response can fail because of a network error, a timeout, a `5xx` status or
57
+ a body that the SDK cannot read. The SDK then sends the request again. It waits 1 second after
58
+ the first failure, and two times longer after each failure that follows. If the requests
59
+ continue to fail, the 30-second limit stops the wait with `ActionResponseTimeoutError`.
60
+
61
+ To identify `ActionRunFailedError` and `ActionResponseTimeoutError` with `instanceof`, import
62
+ them from `@picked/client/plugins/dynamic-experiences`. The `name` of each error is the same
63
+ as the name that you import.
64
+
65
+ ## Run an action from code
66
+
67
+ | API | Returns | Rejects |
68
+ | --- | --- | --- |
69
+ | `client.actions.run(key, options)` | A promise of the response | Yes, with the error of the action |
70
+ | `useAction(key, options)` (React) | For an action that starts a workflow: `{ run, status, response, error }`. For other actions: the action as a function. | `run`: No. The function: it returns or throws what the action returns or throws. |
71
+ | `getAction(key, options)` (Svelte) | A store of the same value | The same as `useAction` |
72
+ | `useActionResult(key, options)` (React) | The last result of your own action | No |
73
+ | `getActionResult(key, options)` (Svelte) | A store of the last result of your own action | No |
74
+ | `client.actions.getActionBinding(key, options)` | A store of the value that `useAction` and `getAction` give | The same as `useAction` |
75
+ | `client.actions.getActionResult(key, options)` | A store of the last result of your own action, which `useActionResult` and `getActionResult` read | No |
76
+
77
+ Type generation names the actions that start a workflow (`WorkflowActionKeys`). Without generated
78
+ types, `useAction` and `getAction` give the action as a function. For each key, the value also
79
+ includes `run`, `status`, `response` and `error`.
80
+
81
+ The handler receives the arguments of a call to the function in `args`. It also receives the
82
+ arguments of `run(...args)` in `args`.
83
+
84
+ `status` is `idle`, `running`, `succeeded` or `failed`, for the last run. When a run starts,
85
+ `response` and `error` are `undefined`. `run(...args)` resolves to
86
+ `{ status: 'succeeded', response }` or to `{ status: 'failed', error }`.
87
+
88
+ The SDK keeps one run state for each key and experience. All the components that use the
89
+ same key and the same experience share that run state, and they show the same last run. When
90
+ one of them calls `run`, all of them show that run.
91
+
92
+ `useActionResult` and `getActionResult` run your own action again when a response, a field or
93
+ the handler of the action changes. They also run it when a component that reads the result
94
+ starts. In React, the action runs when the component mounts, and when an `<Activity>` shows the
95
+ component again. In Svelte, it runs each time a component calls `getActionResult`. A change that
96
+ occurs outside Picked, for example a login, then shows in a component that starts after the
97
+ change.
98
+
99
+ The components that read the same key and the same experience share one result. The action
100
+ runs one time for each change. It also runs one time for the components that React renders
101
+ together. React can stop while it renders and continue later, for example in a transition. Then
102
+ the components that React renders after it continues run the action again.
103
+
104
+ The result is always from the run that started last. If that run throws, the result is
105
+ `undefined`. For a published action they give `undefined` and do not send a request. The types
106
+ refuse the key of an action that starts a workflow.
107
+
108
+ A result for an experience follows the changes only while `client.experienceInstances`
109
+ contains that experience. When `client.experienceInstances` adds the experience, the action
110
+ runs if a response, a field or the handler changed after the last run.
111
+
112
+ The options of `client.actions.run`:
113
+
114
+ | Option | Type | Description |
115
+ | --- | --- | --- |
116
+ | `args` | `unknown[]` | The values that the handler receives in `args`. |
117
+ | `experience` | `ExperienceInstance` | The experience that the handler receives as `context.experience`. |
118
+ | `signal` | `AbortSignal` | Stops the wait. The handler receives a signal that stops too. |
119
+ | `timeoutMs` | `number` | Stops the wait after this many milliseconds, with a `TimeoutError`. |
120
+
121
+ `useAction` and `getAction` take `experience` only.
122
+
123
+ ## Other methods of `client.actions`
124
+
125
+ | Method | Description |
126
+ | --- | --- |
127
+ | `refreshActionResult(key, options)` | Runs your own action again for the result that `getActionResult` gives. It does nothing until a component or your code reads that result. The calls in one task start one run. |
128
+ | `isPublished(key)` | Returns `true` when the handler of the key is a published action. |
129
+ | `unregister(key)` | Removes the handler of the key. If the key has no handler, nothing changes. |
130
+
131
+ `refreshActionResult` and `getActionResult` take `experience` only.
132
+
133
+ ## Rule logic
134
+
135
+ A rule reads the response of an action with `{ "invoke": [{ "var": "actions.<key>" }] }`. A
136
+ response that is a string, a number, a Boolean, `null`, or an array or object of these
137
+ reaches the rule. A different response reaches the rule as `undefined`.
138
+
139
+ A rule runs the action each time the SDK evaluates the rule.
140
+
141
+ A condition node can have a rule that runs an action. While the condition node waits for that
142
+ rule, the flow ignores a request to go to the next step or to a specified step. The result of
143
+ the rule then chooses the branch. If your visitor goes back before the rule has a result, the
144
+ flow ignores the result.
145
+
146
+ ## Related
147
+
148
+ - [How to wait for the response of an action](/how-to/wait-for-an-action-response) — show
149
+ the response in a component.
150
+ - [How to register an action handler](/how-to/register-an-action-handler) — the handler,
151
+ and when to throw.
152
+ - [About how Picked works](/explanation/how-picked-works#how-an-action-decides-which-way-to-go)
153
+ — why a returned `false` is a success.
154
+ - [Actions](/reference/dashboard/actions) — the dashboard options.