@mohsinonxrm/pptb-dataverse-request-studio 1.1.4 → 1.4.0-beta.1

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 (53) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +190 -101
  3. package/SECURITY.md +9 -6
  4. package/dist/assets/AssociateMode-BVHaHiUu.js +1 -0
  5. package/dist/assets/AssociateTargetsEditor-C-QKaWaJ.js +1 -0
  6. package/dist/assets/BatchMode-D1J8HcNO.js +11 -0
  7. package/dist/assets/BinaryColumnPickers-DLIbx4hp.js +1 -0
  8. package/dist/assets/BulkDeleteMode-CFcjcWta.js +1 -0
  9. package/dist/assets/BulkWriteMode-C3ZGwTjw.js +6 -0
  10. package/dist/assets/DisassociateMode-BwMK4UvP.js +2 -0
  11. package/dist/assets/ExecuteWorkflowMode-CkZdayJ4.js +1 -0
  12. package/dist/assets/ManageFileMode-DP3KXgFw.js +1 -0
  13. package/dist/assets/ManageImageMode-F0Dki5VQ.js +1 -0
  14. package/dist/assets/MergeMode-PeKTZ75X.js +1 -0
  15. package/dist/assets/PredefinedQueryMode-CDuc-WrN.js +1 -0
  16. package/dist/assets/RetrieveNextLinkMode-DenFlpEh.js +1 -0
  17. package/dist/assets/cssMode-DXyl4xBX.js +4 -0
  18. package/dist/assets/{freemarker2-CY0Qd_yj.js → freemarker2-CR_qGQP2.js} +2 -2
  19. package/dist/assets/handlebars-Buz2RscQ.js +1 -0
  20. package/dist/assets/html-B66Hfdqd.js +1 -0
  21. package/dist/assets/htmlMode-3ft3GC0g.js +4 -0
  22. package/dist/assets/index-C4fO68cu.js +704 -0
  23. package/dist/assets/javascript-Cy8u5Pbx.js +1 -0
  24. package/dist/assets/jsonMode-CvLp-1ik.js +10 -0
  25. package/dist/assets/liquid-BxIE_8lr.js +1 -0
  26. package/dist/assets/mdx-Bbo0ENZs.js +1 -0
  27. package/dist/assets/{monaco-editor-ErGqj9vD.js → monacoSetup-C4aSY1Tw.js} +193 -183
  28. package/dist/assets/monacoSetup-DvqauXKu.css +1 -0
  29. package/dist/assets/python-B6K3FYWG.js +1 -0
  30. package/dist/assets/razor-7sN2ZaJq.js +1 -0
  31. package/dist/assets/{tsMode-B1b3lx86.js → tsMode-CIH2Hja3.js} +2 -2
  32. package/dist/assets/typescript-rqW7IEk7.js +1 -0
  33. package/dist/assets/xml-Bm2nJGx3.js +1 -0
  34. package/dist/assets/yaml-Z6ahf7o7.js +1 -0
  35. package/dist/icons/icon.svg +10 -13
  36. package/dist/index.html +61 -4
  37. package/index.html +60 -1
  38. package/package.json +12 -4
  39. package/dist/assets/cssMode-DHcTSP5p.js +0 -4
  40. package/dist/assets/handlebars-BQEEw1Ke.js +0 -1
  41. package/dist/assets/html-BXibA6yW.js +0 -1
  42. package/dist/assets/htmlMode-BIOKXbRP.js +0 -4
  43. package/dist/assets/index-Dap9jY4Q.js +0 -682
  44. package/dist/assets/javascript-BY4qn0pJ.js +0 -1
  45. package/dist/assets/jsonMode-BzZNqTrE.js +0 -10
  46. package/dist/assets/liquid-noPAIv1T.js +0 -1
  47. package/dist/assets/mdx-Ccyf8KqT.js +0 -1
  48. package/dist/assets/monaco-editor-I3pIE735.css +0 -1
  49. package/dist/assets/python-CTl0fa86.js +0 -1
  50. package/dist/assets/razor-DoNzFhT2.js +0 -1
  51. package/dist/assets/typescript-ONTfb8eq.js +0 -1
  52. package/dist/assets/xml-6DyixHd0.js +0 -1
  53. package/dist/assets/yaml-B9La2-TQ.js +0 -1
package/README.md CHANGED
@@ -1,84 +1,123 @@
1
1
  # Dataverse Request Studio for Power Platform ToolBox
2
2
 
3
3
  A metadata-driven studio for composing, previewing, and executing Microsoft
4
- Dataverse Web API requests — covering OData reads, record writes, table
5
- associations, bound and unbound action/function invocation, on-demand workflows,
6
- and file / image / attachment operations.
4
+ Dataverse Web API requests — covering OData reads, record writes, bulk writes
5
+ and bulk-delete jobs, table associations, bound and unbound action/function
6
+ invocation, on-demand workflows, `$batch` / ExecuteMultiple envelopes, and
7
+ file / image / attachment operations.
7
8
 
8
9
  Built for [Power Platform ToolBox](https://www.powerplatformtoolbox.com/) with
9
10
  React 18, Fluent UI v9, TypeScript, and live Dataverse metadata integration.
10
11
 
11
12
  [![npm](https://img.shields.io/npm/v/@mohsinonxrm/pptb-dataverse-request-studio?label=npm)](https://www.npmjs.com/package/@mohsinonxrm/pptb-dataverse-request-studio)
13
+ [![npm beta](https://img.shields.io/npm/v/@mohsinonxrm/pptb-dataverse-request-studio/beta?label=beta&color=orange)](https://www.npmjs.com/package/@mohsinonxrm/pptb-dataverse-request-studio?activeTab=versions)
12
14
  ![React](https://img.shields.io/badge/React-18-61DAFB?logo=react)
13
15
  ![TypeScript](https://img.shields.io/badge/TypeScript-5.9-3178C6?logo=typescript)
14
16
  ![Fluent UI](https://img.shields.io/badge/Fluent%20UI-v9-0078D4?logo=microsoft)
15
- ![PPTB Types](https://img.shields.io/badge/%40pptb%2Ftypes-1.2.1-orange)
17
+ ![PPTB Types](https://img.shields.io/badge/%40pptb%2Ftypes-1.2.7-orange)
16
18
  ![License](https://img.shields.io/badge/license-AGPL--3.0--only-green)
17
19
 
18
20
  ---
19
21
 
20
22
  ## ✨ Features
21
23
 
22
- DRS ships with **17 request modes** organized into 5 functional groups. Every
23
- mode is metadata-driven, generates the correct OData / Web API shape, and
24
- emits ready-to-copy code in five languages (xrm.WebApi single + batch, fetch,
25
- curl, PowerShell).
24
+ DRS ships with **23 request modes** in 7 groups. Every mode is
25
+ metadata-driven and generates the correct OData / Web API shape. The
26
+ single-request modes emit ready-to-copy code in ten formats: `fetch`, `Xrm.WebApi`,
27
+ `Xrm.WebApi.executeMultiple`, `XMLHttpRequest`, Power Automate, C#, PowerShell,
28
+ cURL, JSON, and an OpenAPI 3 document; the `$batch` and ExecuteMultiple
29
+ modes have their own HTTP / fetch / C# / PPTB outputs.
26
30
 
27
31
  ### 📖 Read group
28
32
 
29
33
  - **Retrieve Multiple** — full OData query composer with `$select`, `$filter`,
30
- `$orderby`, `$expand`, `$top`, `$skip`, `$count`, `$apply` (groupby /
31
- aggregate), and a virtualized results grid with infinite scroll via
32
- `@odata.nextLink`.
33
- - **Retrieve Single** — by primary key OR by alternate key (composite
34
- alternate keys supported).
34
+ `$orderby`, `$expand` (nested, with inner `$filter` / `$orderby` / `$top`),
35
+ `$top`, `$count`, `$apply` (groupby / aggregate), and a virtualized results
36
+ grid with infinite scroll via `@odata.nextLink`, **Retrieve all**, CSV / JSON
37
+ export, per-column filters, row search, density and persisted column widths.
38
+ Address shortcut chips in the `$filter` builder; paste any OData URL to load
39
+ it into the builder.
40
+ - **Retrieve Single** — one record by primary key (GUID), with `$select` /
41
+ `$expand`.
35
42
  - **Retrieve NextLink** — paste a `@odata.nextLink` URL to continue paging
36
43
  any query.
37
44
  - **Predefined Query** — execute saved-query (`?savedQuery=<id>`) and
38
- user-query (`?userQuery=<id>`) URLs against an entity set; layout-aware
39
- results grid that matches the source view's column order.
45
+ user-query (`?userQuery=<id>`) URLs against an entity set, or over a row's
46
+ related records; layout-aware results grid that matches the source view's
47
+ column order.
40
48
 
41
49
  ### ✏️ Write group
42
50
 
43
- - **Create Record** — `POST /<set>` with metadata-driven field-set editor.
44
- Required-field guard with red `req` badges, `Prefer: return=representation`
45
- toggle, optional `$select` return list, `MSCRM.*` bypass-header family.
51
+ - **Create Record** — `POST /<set>` with a metadata-driven field-set editor or
52
+ a raw JSON body. Required-field guard, `Prefer: return=representation`,
53
+ optional `$select` return list, duplicate detection and the `MSCRM.*`
54
+ bypass-header family. **Retrieve this record** from the result card.
46
55
  - **Update Record** — `PATCH /<set>(<id>)` multi-field OR
47
- `PUT /<set>(<id>)/<col>` single-column. Diff view (before → after) with
48
- per-row drill-down to switch to PUT mode.
49
- - **Upsert Record** — full upsert / create-only / update-only / etag-guarded
50
- variants. By GUID OR alternate key.
56
+ `PUT /<set>(<id>)/<col>` single-column (Code tab only), with a before →
57
+ after diff.
58
+ **Require existing record** (`If-Match: *`) is the default, so a wrong GUID
59
+ returns 404 instead of creating a record.
60
+ - **Upsert Record** — full upsert / create-only / update-only / ETag-guarded
61
+ variants, by GUID or alternate key (alternate key: Code tab only).
51
62
  - **Delete Record** — `DELETE /<set>(<id>)` with a typed-confirmation safety
52
63
  affordance + cascade-impact preview. Single-property delete via
53
- `DELETE /<set>(<id>)/<col>` also supported.
54
- - **Merge Records** — `POST /Merge` for `account` / `contact` / `incident`
55
- with target + subordinate record cards, field-override matrix, and
56
- PerformParentingChecks / SuppressDuplicateDetection settings.
64
+ `DELETE /<set>(<id>)/<col>` is composed for the Code tab.
65
+ - **Merge Records** — `POST /Merge` for `account` / `contact` / `lead` /
66
+ `incident` with target + subordinate record cards, field-override matrix,
67
+ and PerformParentingChecks / SuppressDuplicateDetection settings.
68
+
69
+ ### 📦 Bulk group
70
+
71
+ - **Bulk Write** — `CreateMultiple` / `UpdateMultiple` / `UpsertMultiple` /
72
+ `DeleteMultiple` over a grid of rows, with a per-table support check.
73
+ - **Bulk Delete Job** — a `BulkDelete` system job built from a query, with a
74
+ scheduled or immediate start and live job-status polling.
57
75
 
58
76
  ### 🔗 Relate group
59
77
 
60
78
  - **Associate** — links related records via `POST /<set>(<id>)/<nav>/$ref`
61
- for collection-valued navs, or `PATCH @odata.bind` for single-valued.
62
- Cardinality detected from metadata; verb auto-flips with the picker.
63
- Polymorphic lookups (Customer / Owner / `regardingobjectid`) fully
64
- supported with target-disambiguated nav properties.
79
+ for collection-valued navs (one request per target, already-linked targets
80
+ skipped), or `PATCH @odata.bind` for single-valued. Cardinality detected
81
+ from metadata; verb auto-flips with the picker. Polymorphic lookups
82
+ (Customer / Owner / `regardingobjectid`) fully supported.
65
83
  - **Disassociate** — `DELETE /$ref` for collection-valued, `PATCH @odata.bind: null`
66
84
  for single-valued. Same polymorphism story.
85
+ - Single-valued PATCHes carry `If-Match: *`, so a wrong source id can't create
86
+ a record. Multi-target results are reported per target.
67
87
 
68
88
  ### ⚡ Execute group
69
89
 
70
- - **Execute Action** — OOB / Custom API / Custom Action invocation via
71
- bound `POST /<set>(<id>)/Microsoft.Dynamics.CRM.<Action>` OR unbound
72
- `POST /<Action>`. CSDL-driven parameter form with type-aware controls:
73
- required-first UX, Form ↔ JSON toggle, EntityReference / EntityCollection
74
- / Edm primitives / Enum / Status-code OptionSet enrichment.
90
+ - **Execute Action** — OOB action invocation via bound
91
+ `POST /<set>(<id>)/Microsoft.Dynamics.CRM.<Action>`, collection-bound, OR
92
+ unbound `POST /<Action>`. CSDL-driven parameter form with type-aware
93
+ controls: required-first UX, Form ↔ JSON toggle, EntityReference (existing
94
+ record) or EntitySpecific (existing record or new instance) /
95
+ EntityCollection / Edm primitives / collections / Enum / OptionSet
96
+ enrichment.
97
+ - **Execute Custom API** / **Execute Custom Action** — the same composer,
98
+ listing every Custom API and every custom process action, Microsoft's own
99
+ included. Classification comes from Dataverse data (`customapi`,
100
+ `workflow` + `sdkmessage`); the name is only a fallback when those lookups
101
+ fail.
75
102
  - **Execute Function** — OData function calls with parameter aliasing
76
- (`?@p1=...`) vs inline literal toggle. CSDL-driven param form with the
77
- same type-aware controls as actions.
103
+ (`?@p1=...`) vs inline literals, valid OData literals and escaping, run from
104
+ the built URL.
78
105
  - **Execute Workflow** — runs on-demand workflows via
79
106
  `POST /workflows(<id>)/Microsoft.Dynamics.CRM.ExecuteWorkflow` with the
80
- bound record id. Live picker over activated, on-demand process workflows
81
- (`statecode eq 1 and type eq 1 and ondemand eq true and category eq 0`).
107
+ bound record id, showing the workflow's declared input arguments.
108
+
109
+ ### 🧺 Batch group
110
+
111
+ - **`$batch` Request** — compose a `$batch` from groups of requests: change
112
+ sets (atomic, with `$n` Content-ID references) or independent requests, with
113
+ continue-on-error. Add the last request of a read, write, relate or execute
114
+ mode; per-part results with
115
+ status and body. A batch that mixes change sets and independent requests
116
+ is sent as consecutive ToolBox calls. Needs PPTB 1.2.7+.
117
+ - **ExecuteMultiple** — the ExecuteMultiple pattern (independent requests,
118
+ continue-on-error, return responses) on the `$batch` engine, with SDK
119
+ `ExecuteMultipleRequest` (C#), raw `$batch` and PPTB code. Needs PPTB
120
+ 1.2.7+.
82
121
 
83
122
  ### 💾 Binary group
84
123
 
@@ -98,13 +137,22 @@ curl, PowerShell).
98
137
  GET `/$value` OR `Initialize{...}BlocksDownload` / `DownloadBlock` for
99
138
  download.
100
139
 
140
+ > The binary modes compose the request pipeline and its code, but the PPTB
141
+ > Dataverse API doesn't expose these chunked operations, so **Execute returns
142
+ > `501 Not Implemented`** in this group. Run the generated code from the Code
143
+ > tab instead.
144
+
101
145
  ### 🔍 Cross-cutting capabilities
102
146
 
103
147
  - **Live metadata** — Tables, columns, relationships, alternate keys, action
104
- / function CSDL all fetched lazily from the host's `dataverseAPI`. Per-org
105
- TTL cache with in-flight promise dedup. Type-specific column properties
106
- (Targets, OptionSet, MaxLength, MinValue/MaxValue, Format) loaded on-demand
107
- by the editor that needs them.
148
+ / function CSDL all fetched lazily from the host's `dataverseAPI`, cached per
149
+ org with in-flight promise dedup. Switching the PPTB connection resets the
150
+ prepared request and reloads metadata for the new environment.
151
+ - **Request headers through PPTB 1.2.7+** — Create / Update / Upsert /
152
+ Delete / Merge / Bulk Write headers (preconditions, `MSCRM.*` bypass, duplicate detection, impersonation) are
153
+ sent as additional headers after you approve them once in ToolBox. On older
154
+ hosts, requests that depend on a header are blocked with an explanation.
155
+ `Authorization` / `Cookie` headers are never sent, saved or exported.
108
156
  - **Antipattern advisories** — Surfaces real-time guidance per the
109
157
  [Microsoft query-antipatterns doc](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/query-antipatterns):
110
158
  `FilteringOnCalculatedColumns`, `LargeAmountOfLogicalAttributes`, large-text
@@ -113,17 +161,23 @@ curl, PowerShell).
113
161
  - **Polymorphic lookup support** — Customer, Owner, and multi-target lookups
114
162
  (`regardingobjectid`) emit the correct target-disambiguated
115
163
  `<navName>@odata.bind` binding shape automatically.
116
- - **Code generators** — Every mode emits the same request as
117
- `Xrm.WebApi.online.execute` (single + `executeMultiple` batch),
118
- `fetch`, `curl`, and PowerShell `Invoke-RestMethod` snippets. Multi-request
119
- pipelines (chunked uploads, message-based binary ops) render as full
120
- ordered sequences.
121
- - **Saved-request library** — Per-org localStorage persistence with
122
- auto-suggested names (`account · 3 sel · 2 flt · 2026-05-23`),
123
- rename / delete / overwrite, dirty-state detection, and cross-tab sync.
124
- - **PPTB host integration** — `isEmbedded()`-aware UI: theme sync,
125
- environment-aware URLs, header pass-through, host-stripped header
126
- advisories. Header / theme controls hide when the host owns them.
164
+ - **Code generators** — Every single-request mode emits the same request as `fetch`,
165
+ `Xrm.WebApi` (CRUD helpers or `Xrm.WebApi.online.execute`),
166
+ `Xrm.WebApi.online.executeMultiple`, `XMLHttpRequest`, C# `HttpClient`,
167
+ PowerShell `Invoke-RestMethod`, cURL, a JSON description and an OpenAPI 3
168
+ document, plus a field-by-field Power Automate (Dataverse connector) sheet.
169
+ Multi-request pipelines render as full ordered sequences.
170
+ - **Saved-request library** — per-connection, versioned, up to 200 requests
171
+ across all modes, with auto-suggested names, rename / delete / overwrite and
172
+ dirty-state detection. Export / import as JSON, export as a Postman /
173
+ Insomnia / Bruno collection, and copy or move requests from other
174
+ connections. A library that can't be read is never overwritten.
175
+ - **Recent runs** — click a run to restore it into its mode. Each mode keeps
176
+ its unsaved request when you switch modes.
177
+ - **Results** — CSV export (formulas neutralised for spreadsheets), JSON
178
+ export, Copy as TSV, and response-size hints.
179
+ - **Accessibility** — labelled inputs, readable badges and live-region
180
+ announcements; render errors are contained per pane.
127
181
 
128
182
  ---
129
183
 
@@ -162,14 +216,20 @@ curl, PowerShell).
162
216
 
163
217
  ### Prerequisites
164
218
 
165
- - [Power Platform ToolBox](https://www.powerplatformtoolbox.com/) (for embedded use)
219
+ - [Power Platform ToolBox](https://www.powerplatformtoolbox.com/) **1.2.0 or
220
+ later** (the tool declares `minAPI: 1.2.0`). **1.2.7 or later** is
221
+ recommended: it sends the write modes' request headers and is required for
222
+ the `$batch` and ExecuteMultiple modes.
166
223
  - A connection to a Dataverse environment
167
- - For local development: **Node.js ≥ 20.19** and **npm**
224
+ - For local development: **Node.js 22.22.2+, 24.15+ or 26+** and **npm** (see
225
+ `engines` in `package.json`)
168
226
 
169
227
  ### Installation
170
228
 
171
229
  Dataverse Request Studio is available as a tool in Power Platform ToolBox.
172
- Install it from the tool gallery or load it as a custom tool.
230
+ Install it from the tool gallery or load it as a custom tool. Prereleases are
231
+ published to npm under the `beta` tag (for example `1.4.0-beta.1`) and use the
232
+ gold Insider icon.
173
233
 
174
234
  ---
175
235
 
@@ -192,9 +252,15 @@ npm run dev
192
252
  # TypeScript-only check (fast)
193
253
  npm run typecheck
194
254
 
255
+ # Unit tests (Vitest)
256
+ npm test
257
+
195
258
  # Production build
196
259
  npm run build
197
260
 
261
+ # Bundle size report
262
+ npm run build:analyze
263
+
198
264
  # Preview the production build locally
199
265
  npm run preview
200
266
 
@@ -210,9 +276,9 @@ npm run finalize-package
210
276
  DRS runs in two modes:
211
277
 
212
278
  - **Standalone** (`npm run dev`) — opens in a regular browser tab. Useful
213
- for UI iteration. Execute will return `501 Not Implemented` for any
214
- operation because the host bridge isn't present; you can still build
215
- requests, preview URLs, and use the Code tab.
279
+ for UI iteration only: without the host bridge no live metadata loads, and
280
+ Execute returns `501 Not Implemented` ("Running standalone: Execute needs
281
+ the PPTB host"); the Bulk modes report it as an error result.
216
282
  - **Embedded in PPTB** — loads inside the PPTB iframe. The host injects
217
283
  `window.dataverseAPI` (typed) and `window.toolboxAPI`. Execute runs
218
284
  against the active Dataverse connection.
@@ -233,7 +299,8 @@ commit style, code style, and PR guidance.
233
299
  | **Monaco Editor** | 0.54 | JSON / code editor for body authoring and Code tab |
234
300
  | **@fluentui-contrib/react-data-grid-react-window** | 1.4 | Virtualized results grid |
235
301
  | **@dnd-kit** | 6.3 | Drag-reordering for filter / orderby / select clauses |
236
- | **@pptb/types** | 1.2.1 | Power Platform ToolBox host API types |
302
+ | **@pptb/types** | 1.2.7 | Power Platform ToolBox host API types |
303
+ | **Vitest** | 5 | Unit tests (request engine, code generators, storage) |
237
304
 
238
305
  ---
239
306
 
@@ -244,7 +311,7 @@ src/
244
311
  App.tsx — root, ThemedApp, Frame, mode router
245
312
  main.tsx — Vite entry point
246
313
 
247
- modes/ — one file per request mode (17 modes)
314
+ modes/ — request-mode components (23 modes)
248
315
  RetrieveMultipleMode.tsx
249
316
  RetrieveSingleMode.tsx
250
317
  RetrieveNextLinkMode.tsx
@@ -252,27 +319,41 @@ src/
252
319
  CreateMode.tsx / UpdateMode.tsx / UpsertMode.tsx / DeleteMode.tsx
253
320
  MergeMode.tsx
254
321
  AssociateMode.tsx / DisassociateMode.tsx
255
- ExecuteActionMode.tsx / ExecuteFunctionMode.tsx / ExecuteWorkflowMode.tsx
322
+ ExecuteActionMode.tsx — Execute Action / Custom API / Custom Action
323
+ ExecuteFunctionMode.tsx / ExecuteWorkflowMode.tsx
256
324
  ManageFileMode.tsx / ManageImageMode.tsx / ManageAttachmentMode.tsx
325
+ BulkWriteMode.tsx / BulkDeleteMode.tsx
326
+ BatchMode.tsx + batch/ — $batch Request and ExecuteMultiple
327
+ StubMode.tsx — fallback for an unknown mode id
257
328
 
258
329
  editors/ — clause editors shared across modes
259
330
  filter/ — FilterEditor + value inputs + operator catalog
331
+ expand/ — $expand tree navigation
260
332
  FieldSetEditor.tsx — metadata-driven write-side form
261
333
  SelectEditor.tsx, OrderbyEditor.tsx, ExpandEditor.tsx, ApplyEditor.tsx
262
334
  ActionParamForm.tsx — CSDL-driven action / function params
263
335
  BinarySourceCard.tsx, BinaryPipelineCard.tsx, BinaryColumnPickers.tsx
264
- HeadersEditor.tsx, BypassEditor.tsx
265
- ActionPicker.tsx, RecordPicker.tsx, EntityListPicker.tsx
336
+ HeadersEditor.tsx, BypassEditor.tsx, PreconditionEditor.tsx
337
+ ActionPicker.tsx, NavPropertyPicker.tsx, PasteODataDialog.tsx
266
338
  ...
267
339
 
268
340
  engine/ — URL / body construction + code generation
269
341
  urlBuilder.ts — central URL builder for every mode
270
342
  executeBuilders.ts — action / function / workflow body builders
271
343
  binaryBuilders.ts — file / image / attachment pipelines
272
- codeGenerators.ts — xrm, xrm-batch, fetch, curl, PowerShell
344
+ codeGenerators.ts — fetch, Xrm.WebApi (+ executeMultiple), XHR,
345
+ Power Automate, C#, PowerShell, cURL, JSON
346
+ openApiGenerator.ts — OpenAPI 3 document for the current request
347
+ collectionFormats.ts, savedToCollection.ts
348
+ — Postman / Insomnia / Bruno collection export
349
+ bulkWrite*.ts, bulkDelete*.ts, batch/
350
+ — Bulk Write, Bulk Delete Job, $batch engine
351
+ sensitiveHeaders.ts — credential / impersonation header policy
273
352
  runtime.ts — single dispatch point for execute
274
353
  dataverseExecutor.ts — live executor over the host's dataverseAPI
275
354
  odataParser.ts — round-trips OData URL strings ↔ state
355
+ antipatterns.tsx, bypassAdvisories.tsx, hostHeaderAdvisories.tsx
356
+ — advisory detectors
276
357
 
277
358
  host/ — PPTB bridge + metadata loaders
278
359
  pptbBridge.ts — typed wrapper over window.dataverseAPI
@@ -282,26 +363,30 @@ src/
282
363
  useLiveMetadata.ts, useColumnDetail.ts, useScopedEntities.ts, …
283
364
 
284
365
  primitives/ — small reusable UI bits
285
- Sidebar.tsx, ClauseTreeItem.tsx, SectionHeader.tsx, ModeCard.tsx
366
+ ClauseTreeItem.tsx, SectionHeader.tsx, ModeCard.tsx, RequestTypePicker.tsx
286
367
  StatusPill.tsx, MethodPill.tsx, AdvisoryDrawer.tsx, advisories.ts
287
368
  NavPathColumnPicker.tsx — N:1 drill-down column picker for filter / apply
288
- KvGrid.tsx, Sortable.tsx, SegmentedToggle.tsx, …
369
+ RecordPicker.tsx, KvGrid.tsx, Sortable.tsx, SegmentedToggle.tsx, …
289
370
 
290
- shell/ — frame / header / URL bar / tabs / drawers
291
- Frame.tsx, FrameHeader.tsx, ModeShell.tsx
292
- UrlBar.tsx, MainTabs.tsx, SettingsDrawer.tsx
371
+ shell/ — header / sidebar / URL bar / tabs / drawers
372
+ FrameHeader.tsx, ModeShell.tsx, Sidebar.tsx
373
+ UrlBar.tsx, UrlTokens.tsx, MainTabs.tsx, SettingsDrawer.tsx
293
374
 
294
375
  state/ — per-mode state shapes + persistence
295
376
  readState.ts, writeState.ts, relateState.ts, executeState.ts, binaryState.ts
296
377
  savedRequests.ts — localStorage persistence (per-org scope)
378
+ useSavedRequests.tsx — shared saved-request store
379
+ modeDrafts.ts — unsaved request per mode (this session)
297
380
  SaveContext.tsx — cross-mode save/load context
381
+ validateRequest.tsx — pre-execute request validation
298
382
  displaySettings.ts — display preferences
299
383
 
300
384
  registry/ — request-type catalogue
301
- requestTypes.ts — 17 request types grouped into 5 groups
385
+ requestTypes.ts — 23 request types grouped into 7 groups
302
386
 
303
387
  views/ — output panes
304
- CodeView.tsx — Code tab: xrm/xrm-batch/fetch/curl/powershell
388
+ CodeView.tsx — Code tab: one sub-tab per code format
389
+ PowerAutomatePane.tsx — Power Automate field-by-field sheet
305
390
  ResultsView.tsx — tabs (Detail/Grid/JSON/Headers) + error state
306
391
  results/ — grid + cell renderers + flattening
307
392
  detail/ — record detail card
@@ -313,34 +398,38 @@ src/
313
398
 
314
399
  ## 📋 Web API coverage
315
400
 
401
+ ✅ = compose + Execute in PPTB · ✅ 1.2.7+ = Execute needs PPTB 1.2.7 or
402
+ later · 📝 = compose + Code tab only (not available through the PPTB
403
+ Dataverse API)
404
+
316
405
  | Operation | Status |
317
406
  |---|---|
318
407
  | Retrieve Multiple (full OData) | ✅ |
319
- | Retrieve Single (by GUID / alt key) | ✅ |
320
- | `@odata.nextLink` paging | ✅ |
321
- | Predefined / user queries | ✅ |
408
+ | Retrieve Single (by GUID) | ✅ |
409
+ | `@odata.nextLink` paging, Retrieve all | ✅ |
410
+ | Predefined / user queries (incl. over related records) | ✅ |
322
411
  | `$apply` (groupby / aggregate) | ✅ |
323
412
  | Lambda filter (`any` / `all`) | ✅ |
324
413
  | `$expand` (single + collection, nested) | ✅ |
325
414
  | Polymorphic lookups (Customer, Owner, regardingobjectid) | ✅ |
326
415
  | Create / Update / Upsert / Delete | ✅ |
327
- | `Prefer: return=representation` | ✅ |
328
- | Optimistic concurrency (`If-Match` ETag) | ✅ |
329
- | `MSCRM.*` bypass family (custom plug-ins, flows, async) | ✅ |
330
- | Single-property PUT / DELETE | ✅ |
331
- | Alternate-key upsert | ✅ |
416
+ | `Prefer: return=representation` | ✅ (ToolBox always sends it on writes) |
417
+ | Optimistic concurrency (`If-Match` / `If-None-Match`) | ✅ 1.2.7+ |
418
+ | `MSCRM.*` bypass family (custom plug-ins, flows, async) | ✅ 1.2.7+ |
419
+ | Single-property PUT / DELETE | 📝 |
420
+ | Alternate-key upsert | 📝 |
332
421
  | Associate / Disassociate (collection + single-valued) | ✅ |
333
- | Merge (account / contact / incident) | ✅ |
422
+ | Merge (account / contact / lead / incident) | ✅ |
334
423
  | Execute Action (OOB / Custom API / Custom Action) | ✅ |
335
424
  | Execute Function | ✅ |
336
425
  | Execute Workflow | ✅ |
337
- | File column (upload / download / delete) | ✅ |
338
- | Image column (thumbnail / full-size) | ✅ |
339
- | Attachment / Note (inline + message-based) | ✅ |
340
- | `$batch` envelope composer | ⏳ (see roadmap) |
341
- | `CreateMultiple` / `UpdateMultiple` / `DeleteMultiple` | ⏳ |
342
- | `BulkDelete` async job | ⏳ |
343
- | `ExecuteMultiple` envelope | ⏳ |
426
+ | `CreateMultiple` / `UpdateMultiple` / `UpsertMultiple` / `DeleteMultiple` | ✅ |
427
+ | `BulkDelete` async job | ✅ |
428
+ | `$batch` (change sets + independent requests) | ✅ 1.2.7+ |
429
+ | `ExecuteMultiple` pattern | ✅ 1.2.7+ |
430
+ | File column (upload / download / delete) | 📝 |
431
+ | Image column (thumbnail / full-size) | 📝 |
432
+ | Attachment / Note (inline + message-based) | 📝 |
344
433
 
345
434
  ---
346
435
 
@@ -353,18 +442,18 @@ commit style, code style, repo layout, and PR guidance.
353
442
 
354
443
  ## 📋 Roadmap
355
444
 
356
- - `$batch` envelope composer mode
357
- - Bulk-write modes (`CreateMultiple`, `UpdateMultiple`, `DeleteMultiple`)
358
- - `BulkDelete` async-job composer
359
- - `ExecuteMultiple` request envelope
360
- - Recent-runs click-to-reload
361
- - WriteResultCard "Retrieve this record" cross-mode jump
362
- - EntitySpecific param — reference vs new-instance toggle
363
- - Workflow input parameters (parse XAML `InArgument`)
364
- - Predefined Query — apply to related collection
365
- - CSV / JSON export from results grid
366
- - Column resize with persisted widths
367
- - Smoke-test suite covering URL builders + code generators
445
+ Planned work is tracked in the repository's
446
+ [milestones](https://github.com/mohsinonxrm/pptb-mxrm-dataverse-request-studio/milestones)
447
+ and [issues](https://github.com/mohsinonxrm/pptb-mxrm-dataverse-request-studio/issues).
448
+ Ideas under consideration include:
449
+
450
+ - Request variables (`{{var}}`) and persistent request history
451
+ - FetchXML and Dataverse Search API modes
452
+ - A metadata browser mode
453
+ - Comparing responses across runs or environments
454
+ - Importing Postman / Insomnia collections and cURL commands
455
+ - More code-generation targets (C# ServiceClient / IOrganizationService,
456
+ Python, the PowerShell Dataverse module)
368
457
 
369
458
  ---
370
459
 
package/SECURITY.md CHANGED
@@ -30,16 +30,19 @@ in a browser. Vulnerability reports of interest:
30
30
  triggers code execution on load, exfiltrates localStorage from another
31
31
  org scope, or escapes the per-org scoping bucket.
32
32
  - **Dependency vulnerabilities** — known CVEs in production dependencies
33
- (`@fluentui/*`, `monaco-editor`, `@pptb/types`, etc.) that affect the
34
- shipped bundle.
33
+ (`@fluentui/*`, `monaco-editor`, `@monaco-editor/react`, `@dnd-kit/*`,
34
+ `react`, etc.) that affect the shipped bundle. Dev-only tooling
35
+ (`@pptb/types`, Vite, TypeScript, Prettier) isn't shipped.
35
36
 
36
37
  ## Out of scope
37
38
 
38
39
  - **Mistakes the user makes against their own environment** — DRS lets you
39
- Delete, Update, and Merge records. Destructive operations require typed
40
- confirmation; beyond that, the user is responsible for what they send.
41
- - **Standalone-mode network errors** — the standalone build (`npm run dev`)
42
- has no host bridge; Execute returns 501. This is by design, not a bug.
40
+ Delete, Update, and Merge records. Delete and Bulk Delete Job require typed
41
+ confirmation; bulk and batch deletes and Merge don't. Beyond that, the user
42
+ is responsible for what they send.
43
+ - **Standalone-mode Execute errors** — the standalone build (`npm run dev`)
44
+ has no host bridge, so Execute returns `501 Not Implemented` ("Running
45
+ standalone: Execute needs the PPTB host"). This is by design, not a bug.
43
46
  - **Antipattern advisories** — the studio surfaces guidance per the
44
47
  Microsoft query-antipatterns doc, but it's advisory only; the request
45
48
  still goes through if the user proceeds.
@@ -0,0 +1 @@
1
+ import{c as ae,b5 as se,bK as U,r,u as re,e as oe,bL as ne,bM as ie,bN as le,f as de,bO as ce,bP as ue,b9 as ge,i as I,j as he,T as be,k as pe,bQ as me,bR as ye,bF as ve,bG as fe,bS as R,L as Se,p as xe,q as a,H as Pe,A as Te,B as Ne,I as je,v as ke,bT as we,x as Ce,y as Me,z as Ie,D as Re,R as Ae,bU as D,U as He,S as Fe,G as Le,bl as Be,aS as $e,bm as qe,b4 as Ee,a8 as Oe,X as T,bk as Ue,Y as De,a_ as ze}from"./index-C4fO68cu.js";import{A as Ve,N as We}from"./AssociateTargetsEditor-C-QKaWaJ.js";const Ge=()=>({table:"",sourceId:null,navProperty:null,targets:[],targetNames:{},headers:Le(),dirty:new Set});function Xe({themeMode:d}){const p=ae("associate"),n=se("associate",U,Ge),[e,c]=r.useState(n.state),{table:N}=re(e.table||null),{entities:A}=oe(),[H,F]=r.useState("source"),[m,j]=r.useState("builder"),[L,k]=r.useState(null),[V,B]=r.useState(!1),[W,G]=r.useState([]),[y,v]=r.useState(n.lastSavedId),[f,S]=r.useState(n.lastSavedHash),[$,w]=r.useState(""),b=r.useMemo(()=>ne(e),[e,N]),_=r.useMemo(()=>ie(e),[e,N]),i=r.useMemo(()=>le(e),[e,N]),x=de(e.table),o=e.navProperty?x?.navigationProperties.find(t=>t.name===e.navProperty):void 0,q=o?ce(o):!1,u=q?"PATCH":"POST",C=t=>c(s=>{const l=new Set(s.dirty);return l.add(t),{...s,dirty:l}}),P=(t,s,l)=>{c(M=>({...M,[t]:s})),l&&C(l)},J=x?e.sourceId?e.navProperty?e.targets.length===0?"Pick at least one target record.":e.headers.some(t=>t.enabled&&!t.name)?"Fix empty header name.":null:"Pick a navigation property.":"Pick a source record.":"Pick a source table first.",K=async()=>{B(!0);const t=await $e.associate(e);k(t),B(!1),j("results"),G(s=>[{id:`r-${Date.now()}`,snapshot:g,modeId:"associate",url:b.relativeUrl,method:u,ts:Date.now(),status:t.status,ms:t.ms,rowCount:D(t,i.length)??0},...s].slice(0,8)),c(s=>({...s,dirty:new Set}))},g=r.useMemo(()=>ue(e),[e]);ge("associate",g,y,f);const Q=r.useMemo(()=>I(g),[g]),E=f===null?!0:Q!==f,X=t=>{v(t.id),S(I(t.state))},O=t=>{if(t.modeId!=="associate")return;const s=t.state;if(A.length>0&&!A.some(l=>l.logicalName===s.table)){Be(`Can't load "${t.name}": entity \`${s.table}\` isn't available in this environment. The solution may have been removed or you may be connected to a different org.`);return}c(U(s)),v(t.id),S(I(s)),k(null),w(""),F("source")},Y=t=>{const s=qe(t,"associate");if(!s)return;const l=y,M=f;O(s),v(l),S(M)};he(r.useMemo(()=>e.table?{state:g,modeId:"associate",dirty:E,lastSavedId:y,onSaved:X,onLoadSaved:O}:null,[g,E,y,e.table]));const Z=[{id:"source",label:"Target",meta:x?.displayName??"Pick a table",items:[{id:"source",icon:pe,iconFilled:be,label:e.sourceId?$||`${x?.displayName??""} (selected)`:"Pick a record",badge:o?u:null,badgeAppearance:"tint",badgeColor:"brand",dirty:e.dirty.has("source")}]},{id:"relationship",label:"Relationship",meta:o?z(o.cardinality):"pick one",items:[{id:"nav",icon:ye,iconFilled:me,label:o?o.name:"Navigation property",code:!!o,badge:o?z(o.cardinality):null,badgeAppearance:"ghost",dirty:e.dirty.has("nav")}]},{id:"targets",label:"Related",meta:e.targets.length?`${e.targets.length} target${e.targets.length===1?"":"s"}`:"none",items:[{id:"targets",icon:fe,iconFilled:ve,label:q?"Target record":"Target records",badge:e.targets.length||null,badgeAppearance:"tint",badgeColor:e.targets.length>0?"success":"subtle",dirty:e.dirty.has("targets")},...i.length>0?[{id:"preview",icon:R,iconFilled:R,label:`${i.length} request${i.length===1?"":"s"}`,badge:i.length,badgeAppearance:"ghost"}]:[]]},{id:"headers",label:"Headers",meta:`${e.headers.filter(t=>t.enabled).length} active`,items:[{id:"headers",icon:xe,iconFilled:Se,label:"HTTP headers",badge:e.headers.filter(t=>t.enabled).length||null,dirty:e.dirty.has("headers")}]}];let h;switch(H){case"source":h=a.jsx(ke,{table:e.table,onTableChange:t=>{c(s=>({...s,table:t,sourceId:null,navProperty:null,targets:[],targetNames:{},dirty:new Set(["source","nav","targets"])})),w(""),k(null),v(void 0),S(null)},recordId:e.sourceId,onRecordChange:(t,s)=>{P("sourceId",t,"source"),w(s??"")},group:"relate",sub:"Pick the source entity and the record that the relationship anchors on."});break;case"nav":h=a.jsx(We,{table:e.table,value:e.navProperty,onChange:t=>{c(s=>({...s,navProperty:t,targets:[],targetNames:{}})),C("nav"),C("targets")},group:"relate",forOperation:"associate",footer:a.jsx(Te,{layout:"multiline",intent:"info",children:a.jsxs(Ne,{children:[a.jsx(je,{children:"How cardinality drives the request"}),a.jsx("strong",{children:"Collection-valued"})," (1:N / N:N) → ",a.jsx("code",{children:"POST /…/$ref"})," with one request per target. ",a.jsx("strong",{children:"Single-valued"})," (N:1) →"," ",a.jsx("code",{children:"PATCH /source(id)"})," with body"," ",a.jsx("code",{children:'{ "<nav>@odata.bind": "<target-set>(<id>)" }'})," (one target). This is the docs-preferred shape — the URL bar verb updates automatically. The PATCH is sent with ",a.jsx("code",{children:"If-Match: *"}),", so a wrong source id fails with 404 instead of creating a record; Power Platform ToolBox asks you to approve that header once."," ",a.jsx("a",{href:"https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/associate-disassociate-entities-using-web-api",target:"_blank",rel:"noopener noreferrer",style:{color:"inherit"},children:"MS Learn ↗"})]})})});break;case"targets":h=a.jsx(Ve,{table:e.table,navProperty:e.navProperty,targets:e.targets,setTargets:t=>P("targets",t,"targets"),targetNames:e.targetNames,setTargetNames:t=>P("targetNames",t),group:"relate",resolvedMethod:o?u:null});break;case"preview":h=a.jsx(_e,{requests:i});break;case"headers":h=a.jsx(Pe,{items:e.headers,setItems:t=>P("headers",t,"headers"),group:"relate"});break}const ee=we(u,Ce(e.headers,null)),te={method:u,built:b,headers:ee,body:_,entityLogical:b.entityLogical,multiRequests:i.length>1?i.map(t=>({method:t.method,relativeUrl:t.relativeUrl,body:t.body,description:`target ${t.targetId}`})):void 0};return a.jsx(Me,{sidebar:a.jsx(Fe,{type:p,urlPreview:b.relativeNoBase,sections:Z,activeNode:H,onSelect:t=>{F(t),j("builder")},recents:W,onRecentClick:Y}),urlBar:a.jsx(He,{method:u,url:b.relativeUrl,executeVerb:p.executeVerb,disabledReason:J,loading:V,onExecute:K}),children:a.jsxs(Ie,{tab:m,onTabChange:j,resultCount:D(L,i.length),children:[m==="builder"&&h,m==="code"&&a.jsx(Re,{themeMode:d,inputs:te}),m==="results"&&a.jsx(Ae,{result:L,mode:"single",table:e.table,writeContext:{operation:"associate",table:e.table,recordId:e.sourceId,recordName:$||null,navProperty:e.navProperty??void 0,targetCount:e.targets.length,targetNames:e.targets.map(t=>e.targetNames[t]).filter(t=>!!t),targetNameById:e.targetNames}})]})})}function _e({requests:d}){const p=Ee();return a.jsxs("div",{children:[a.jsx(Oe,{icon:R,title:`Generated requests (${d.length})`,sub:"Each target queues a separate HTTP request. For large counts, prefer a $batch request.",group:"relate"}),a.jsxs("div",{className:ze(p.inlineCard),style:{padding:12,maxWidth:980,fontFamily:T.fontFamilyMonospace,fontSize:11},children:[d.map((n,e)=>a.jsxs("div",{style:{display:"grid",gridTemplateColumns:"60px 1fr",gap:8,padding:"8px 0",borderBottom:e<d.length-1?`1px solid ${T.colorNeutralStroke3}`:"none"},children:[a.jsx(Ue,{appearance:"filled",color:n.method==="POST"?"success":"warning",style:{fontWeight:700,justifySelf:"start"},children:n.method}),a.jsxs("div",{style:{minWidth:0},children:[a.jsx("div",{style:{wordBreak:"break-all"},children:n.relativeUrl}),a.jsx("div",{style:{marginTop:4,color:T.colorNeutralForeground3},children:JSON.stringify(n.body)})]})]},n.targetId)),d.length===0&&a.jsx(De,{style:{color:T.colorNeutralForeground3,fontStyle:"italic",padding:"12px 4px",textAlign:"center",display:"block"},children:"No requests queued — pick at least one target on the Related pane."})]})]})}function z(d){switch(d){case"OneToMany":return"1:N";case"ManyToOne":return"N:1";case"ManyToMany":return"N:N"}}export{Xe as AssociateMode};
@@ -0,0 +1 @@
1
+ import{f as j,u as I,q as e,a8 as k,bQ as v,a4 as M,bi as L,b2 as U,X as r,bk as p,Y as b,r as S,b4 as G,A as P,B as O,aC as E,b$ as H,bJ as K,N as V,aO as _,a_ as J,b3 as Q,aA as X,I as Y}from"./index-C4fO68cu.js";function ne({table:t,value:s,onChange:n,group:o="relate",forOperation:u,footer:y}){const g=j(t)?.navigationProperties??[],d=g.find(i=>i.name===s);return I(d?.targetEntity??null),e.jsxs("div",{children:[e.jsx(k,{icon:v,title:"Navigation property",sub:"Cardinality is detected from metadata — the URL bar verb + shape adapt automatically.",group:o}),e.jsxs("div",{style:{maxWidth:720},children:[e.jsx(M,{label:"Navigation property",children:e.jsx(L,{value:d?.name??"",selectedOptions:d?[d.name]:[],onOptionSelect:(i,x)=>n(x.optionValue??null),placeholder:"Pick a navigation property…",children:g.map(i=>e.jsx(U,{value:i.name,text:i.name,children:e.jsx(Z,{nav:i,forOperation:u})},i.name))})}),d&&e.jsx("div",{style:{marginTop:16},children:e.jsx(ee,{nav:d,forOperation:u})}),y&&e.jsx("div",{style:{marginTop:14},children:y})]})]})}function Z({nav:t,forOperation:s}){const n=j(t.targetEntity),o=C(t,s);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{fontFamily:r.fontFamilyMonospace,fontWeight:600},children:t.name}),e.jsx(p,{appearance:"ghost",size:"extra-small",children:B(t.cardinality)}),e.jsx(p,{appearance:"tint",color:"brand",size:"extra-small",style:{marginLeft:"auto"},children:o})]}),e.jsxs(b,{style:{color:r.colorNeutralForeground3},children:["→ ",n?.displayName??t.targetEntity," · ",te(t.cardinality)]})]})}function ee({nav:t,forOperation:s}){const n=j(t.targetEntity),o=C(t,s),u=t.cardinality==="ManyToOne"?"single-valued":"collection-valued",y=o==="POST"?r.colorPaletteGreenForeground1:o==="PATCH"?r.colorPaletteDarkOrangeForeground1:r.colorPaletteRedForeground1;return e.jsxs("div",{style:{border:`1px solid ${r.colorNeutralStroke2}`,borderRadius:r.borderRadiusMedium,padding:12,background:r.colorNeutralBackground1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx(v,{style:{width:18,height:18,color:r.colorBrandForeground1}}),e.jsx("strong",{style:{fontFamily:r.fontFamilyMonospace,fontSize:13},children:t.name}),e.jsx(p,{appearance:"tint",color:"brand",children:B(t.cardinality)}),e.jsx("span",{style:{flexGrow:1}}),e.jsx(p,{appearance:"filled",style:{background:y,color:r.colorNeutralForegroundOnBrand,fontWeight:700},children:o})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"120px 1fr",rowGap:4,fontSize:11},children:[e.jsx("span",{style:{color:r.colorNeutralForeground3},children:"Target entity"}),e.jsxs("span",{style:{fontFamily:r.fontFamilyMonospace},children:[n?.entitySetName??t.targetEntity," ",e.jsxs(b,{style:{color:r.colorNeutralForeground3},children:["· ",n?.displayName??t.targetEntity]})]}),e.jsx("span",{style:{color:r.colorNeutralForeground3},children:"Cardinality"}),e.jsxs("span",{children:[u," (",t.cardinality,")"]}),e.jsx("span",{style:{color:r.colorNeutralForeground3},children:"Relationship"}),e.jsx("span",{style:{fontFamily:r.fontFamilyMonospace,fontSize:10},children:t.relationshipName})]})]})}function B(t){switch(t){case"OneToMany":return"1:N";case"ManyToOne":return"N:1";case"ManyToMany":return"N:N"}}function te(t){return t==="ManyToOne"?"single-valued lookup":"collection-valued"}function C(t,s){return t.cardinality==="ManyToOne"?"PATCH":s==="disassociate"?"DELETE":"POST"}function ae({table:t,navProperty:s,targets:n,setTargets:o,targetNames:u,setTargetNames:y,group:N="relate",resolvedMethod:g}){const[d,i]=S.useState({}),x=u??d,F=y??i,R=G(),W=j(t),h=s?W?.navigationProperties.find(a=>a.name===s):void 0,m=h?j(h.targetEntity):void 0,l=h?.cardinality==="ManyToOne",A=l?1:1/0,[w,q]=S.useState(0);if(!h)return e.jsxs("div",{children:[e.jsx(k,{icon:v,title:"Target records",sub:"Pick a navigation property first.",group:N}),e.jsx(P,{layout:"multiline",intent:"info",style:{maxWidth:720},children:e.jsxs(O,{children:["Switch to the ",e.jsx("strong",{children:"Navigation property"})," pane and pick one — the target entity comes from there."]})})]});const T=n.length>=A,z=(a,c)=>{if(!a||n.includes(a)||T)return;const f=l?[a]:[...n,a];o(f),c&&F({...x,[a]:c}),q(D=>D+1)},$=a=>{if(o(n.filter(c=>c!==a)),x[a]!=null){const c={...x};delete c[a],F(c)}};return e.jsxs("div",{children:[e.jsxs(k,{icon:v,title:l?"Target record":"Target records",sub:e.jsx("span",{children:l?e.jsxs(e.Fragment,{children:["One target is allowed for ",e.jsx("code",{children:h.cardinality})," nav props — the server PUT sets the lookup."]}):e.jsxs(e.Fragment,{children:["One or more targets — each fires a separate POST request. For many targets, Dataverse recommends a ",e.jsx("code",{children:"$batch"})," request."]})}),group:N,children:[e.jsxs(p,{appearance:"tint",color:n.length>0?"brand":"subtle",children:[n.length," target",n.length===1?"":"s"]}),g&&e.jsx(p,{appearance:"filled",color:g==="POST"?"success":"informative",style:{fontWeight:700},children:g}),!l&&n.length>1&&e.jsx(E,{content:"Will fire one request per target — Dataverse recommends $batch for large counts. Batch transport lands in a later pass.",relationship:"description",children:e.jsxs(p,{appearance:"ghost",icon:e.jsx(H,{style:{width:12,height:12}}),children:[n.length," requests queued"]})})]}),e.jsx("div",{className:J(R.inlineCard),style:{padding:12,marginBottom:14,maxWidth:880},children:n.length===0?e.jsxs(b,{style:{padding:"12px 4px",color:r.colorNeutralForeground3,fontStyle:"italic",display:"block",textAlign:"center"},children:["No targets selected — use the picker below to choose"," ",l?"one":"one or more"," ",e.jsx("strong",{children:m?.displayName??h.targetEntity})," record",l?"":"s","."]}):e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n.map((a,c)=>{const f=x[a];return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 4px",borderBottom:c<n.length-1?`1px solid ${r.colorNeutralStroke3}`:"none"},children:[e.jsx(K,{size:"small",name:f??"?",avatar:{color:"colorful"}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12,fontWeight:600},children:f??e.jsx("span",{style:{fontStyle:"italic",color:r.colorNeutralForeground3},children:"(name not resolved)"})}),e.jsxs("div",{style:{fontFamily:r.fontFamilyMonospace,fontSize:10,color:r.colorNeutralForeground3},children:["/",m?.entitySetName??"?","(",a,")"]})]}),e.jsx(E,{content:"Remove target",relationship:"label",children:e.jsx(V,{size:"small",appearance:"subtle",icon:e.jsx(_,{}),onClick:()=>$(a),"aria-label":"Remove target"})})]},a)})})}),!T&&e.jsxs("div",{style:{maxWidth:560},children:[e.jsx(M,{label:l?"Pick target":"Add target",hint:l?`Pick a single ${m?.displayName??"record"} — the PUT sets this as the lookup value.`:`Each pick queues a separate POST. Currently ${n.length} target${n.length===1?"":"s"} queued.`,children:e.jsx(Q,{table:m?.logicalName??h.targetEntity,selectedId:null,onPick:a=>z(a?.id??null,a?.primary),placeholder:`Search ${m?.displayName??"record"}s…`},w)}),!l&&e.jsxs(b,{style:{display:"block",marginTop:6,color:r.colorNeutralForeground3},children:[e.jsx(X,{style:{width:12,height:12,verticalAlign:"middle"}})," picking a record adds it to the queue and resets the picker for the next pick."]})]}),T&&l&&e.jsx(P,{layout:"multiline",intent:"info",style:{maxWidth:720,marginTop:12},children:e.jsxs(O,{children:[e.jsx(Y,{children:"Single-valued nav property — one target only."}),"To change the target, remove the current one first. The server PUT atomically replaces the previous lookup value."]})})]})}export{ae as A,ne as N};