@xrmforge/typegen 0.8.3 → 0.8.5
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.
- package/LICENSE +21 -21
- package/MIGRATION.md +194 -194
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/docs/architecture/00-README.md +26 -26
- package/docs/architecture/01-executive-summary.md +11 -11
- package/docs/architecture/02-packages.md +110 -110
- package/docs/architecture/03-generated-types.md +172 -172
- package/docs/architecture/04-cli.md +58 -58
- package/docs/architecture/05-build.md +50 -50
- package/docs/architecture/06-incremental.md +42 -42
- package/docs/architecture/07-http-client.md +59 -59
- package/docs/architecture/08-authentication.md +18 -18
- package/docs/architecture/09-testing.md +55 -55
- package/docs/architecture/10-eslint-plugin.md +82 -82
- package/docs/architecture/11-agent-md.md +38 -38
- package/docs/architecture/12-xrm-pitfalls.md +14 -14
- package/docs/architecture/13-helpers.md +50 -50
- package/docs/architecture/14-showcases.md +21 -21
- package/docs/architecture/15-ci-cd.md +49 -49
- package/docs/architecture/16-technical-debt.md +17 -17
- package/docs/architecture/17-roadmap.md +25 -25
- package/docs/architecture/18-design-principles.md +22 -22
- package/docs/architektur/00-README.md +26 -26
- package/docs/architektur/01-zusammenfassung.md +11 -11
- package/docs/architektur/02-packages.md +110 -110
- package/docs/architektur/03-generierte-typen.md +172 -172
- package/docs/architektur/04-cli.md +58 -58
- package/docs/architektur/05-build.md +50 -50
- package/docs/architektur/06-inkrementell.md +42 -42
- package/docs/architektur/07-http-client.md +59 -59
- package/docs/architektur/08-authentifizierung.md +18 -18
- package/docs/architektur/09-testing.md +55 -55
- package/docs/architektur/10-eslint-plugin.md +82 -82
- package/docs/architektur/11-agent-md.md +38 -38
- package/docs/architektur/12-xrm-fallstricke.md +14 -14
- package/docs/architektur/13-helpers.md +50 -50
- package/docs/architektur/14-showcases.md +21 -21
- package/docs/architektur/15-ci-cd.md +49 -49
- package/docs/architektur/16-technische-schulden.md +17 -17
- package/docs/architektur/17-roadmap.md +25 -25
- package/docs/architektur/18-designprinzipien.md +22 -22
- package/package.json +1 -1
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
# CLI Commands
|
|
2
|
-
|
|
3
|
-
### 4.1 `xrmforge generate`
|
|
4
|
-
|
|
5
|
-
Generates TypeScript declarations from a Dataverse environment.
|
|
6
|
-
|
|
7
|
-
| Flag | Type | Default | Description |
|
|
8
|
-
|------|------|---------|-------------|
|
|
9
|
-
| `--url <url>` | string | required | Dataverse environment URL |
|
|
10
|
-
| `--auth <method>` | string | required | Auth method: client-credentials, interactive, device-code, token |
|
|
11
|
-
| `--tenant-id <id>` | string | varies | Azure AD tenant ID |
|
|
12
|
-
| `--client-id <id>` | string | varies | Azure AD application ID |
|
|
13
|
-
| `--client-secret <s>` | string | varies | Client secret (client-credentials only) |
|
|
14
|
-
| `--token <token>` | string | varies | Pre-acquired bearer token (token auth only) |
|
|
15
|
-
| `--entities <list>` | string | - | Comma-separated entity logical names |
|
|
16
|
-
| `--solutions <list>` | string | - | Comma-separated solution unique names |
|
|
17
|
-
| `--output <dir>` | string | ./generated | Output directory |
|
|
18
|
-
| `--label-language <n>` | string | 1033 | Primary label language (LCID) |
|
|
19
|
-
| `--secondary-language <n>` | string | - | Secondary label language for JSDoc |
|
|
20
|
-
| `--no-forms` | flag | - | Skip form interface generation |
|
|
21
|
-
| `--no-optionsets` | flag | - | Skip OptionSet enum generation |
|
|
22
|
-
| `--actions` | flag | false | Generate Custom API executors |
|
|
23
|
-
| `--actions-filter <prefix>` | string | - | Filter Custom APIs by uniquename prefix |
|
|
24
|
-
| `--cache` | flag | false | Enable metadata caching for incremental generation |
|
|
25
|
-
| `--no-cache` | flag | - | Force full metadata refresh |
|
|
26
|
-
| `--cache-dir <dir>` | string | .xrmforge/cache | Cache directory |
|
|
27
|
-
| `-v, --verbose` | flag | false | Debug logging |
|
|
28
|
-
|
|
29
|
-
At least one of `--entities` or `--solutions` is required.
|
|
30
|
-
|
|
31
|
-
### 4.2 `xrmforge build`
|
|
32
|
-
|
|
33
|
-
Builds WebResources as IIFE bundles using esbuild (via @xrmforge/devkit).
|
|
34
|
-
|
|
35
|
-
| Flag | Type | Default | Description |
|
|
36
|
-
|------|------|---------|-------------|
|
|
37
|
-
| `--watch` | flag | false | Watch mode with incremental rebuilds |
|
|
38
|
-
| `--minify` | flag | from config | Override minification setting |
|
|
39
|
-
| `--no-sourcemap` | flag | - | Disable source maps |
|
|
40
|
-
| `--out-dir <dir>` | string | from config | Override output directory |
|
|
41
|
-
| `-v, --verbose` | flag | false | Show error stacks |
|
|
42
|
-
|
|
43
|
-
Reads configuration from `xrmforge.config.json`.
|
|
44
|
-
|
|
45
|
-
### 4.3 `xrmforge init`
|
|
46
|
-
|
|
47
|
-
Scaffolds a new D365 form scripting project.
|
|
48
|
-
|
|
49
|
-
| Flag | Type | Default | Description |
|
|
50
|
-
|------|------|---------|-------------|
|
|
51
|
-
| `[dir]` | positional | . | Target directory |
|
|
52
|
-
| `--name <name>` | string | dir name | Project name for package.json |
|
|
53
|
-
| `--prefix <prefix>` | string | contoso | Publisher prefix |
|
|
54
|
-
| `--namespace <ns>` | string | PascalCase(prefix) | Base namespace for scripts |
|
|
55
|
-
| `--skip-install` | flag | false | Skip npm install |
|
|
56
|
-
| `--force` | flag | false | Allow non-empty directories |
|
|
57
|
-
|
|
58
|
-
Generates 11 files: package.json, tsconfig.json, xrmforge.config.json, vitest.config.ts, .gitignore, AGENT.md, example-form.ts, example-form.test.ts, generated/.gitkeep, GitHub Actions CI, Azure DevOps Pipeline.
|
|
1
|
+
# CLI Commands
|
|
2
|
+
|
|
3
|
+
### 4.1 `xrmforge generate`
|
|
4
|
+
|
|
5
|
+
Generates TypeScript declarations from a Dataverse environment.
|
|
6
|
+
|
|
7
|
+
| Flag | Type | Default | Description |
|
|
8
|
+
|------|------|---------|-------------|
|
|
9
|
+
| `--url <url>` | string | required | Dataverse environment URL |
|
|
10
|
+
| `--auth <method>` | string | required | Auth method: client-credentials, interactive, device-code, token |
|
|
11
|
+
| `--tenant-id <id>` | string | varies | Azure AD tenant ID |
|
|
12
|
+
| `--client-id <id>` | string | varies | Azure AD application ID |
|
|
13
|
+
| `--client-secret <s>` | string | varies | Client secret (client-credentials only) |
|
|
14
|
+
| `--token <token>` | string | varies | Pre-acquired bearer token (token auth only) |
|
|
15
|
+
| `--entities <list>` | string | - | Comma-separated entity logical names |
|
|
16
|
+
| `--solutions <list>` | string | - | Comma-separated solution unique names |
|
|
17
|
+
| `--output <dir>` | string | ./generated | Output directory |
|
|
18
|
+
| `--label-language <n>` | string | 1033 | Primary label language (LCID) |
|
|
19
|
+
| `--secondary-language <n>` | string | - | Secondary label language for JSDoc |
|
|
20
|
+
| `--no-forms` | flag | - | Skip form interface generation |
|
|
21
|
+
| `--no-optionsets` | flag | - | Skip OptionSet enum generation |
|
|
22
|
+
| `--actions` | flag | false | Generate Custom API executors |
|
|
23
|
+
| `--actions-filter <prefix>` | string | - | Filter Custom APIs by uniquename prefix |
|
|
24
|
+
| `--cache` | flag | false | Enable metadata caching for incremental generation |
|
|
25
|
+
| `--no-cache` | flag | - | Force full metadata refresh |
|
|
26
|
+
| `--cache-dir <dir>` | string | .xrmforge/cache | Cache directory |
|
|
27
|
+
| `-v, --verbose` | flag | false | Debug logging |
|
|
28
|
+
|
|
29
|
+
At least one of `--entities` or `--solutions` is required.
|
|
30
|
+
|
|
31
|
+
### 4.2 `xrmforge build`
|
|
32
|
+
|
|
33
|
+
Builds WebResources as IIFE bundles using esbuild (via @xrmforge/devkit).
|
|
34
|
+
|
|
35
|
+
| Flag | Type | Default | Description |
|
|
36
|
+
|------|------|---------|-------------|
|
|
37
|
+
| `--watch` | flag | false | Watch mode with incremental rebuilds |
|
|
38
|
+
| `--minify` | flag | from config | Override minification setting |
|
|
39
|
+
| `--no-sourcemap` | flag | - | Disable source maps |
|
|
40
|
+
| `--out-dir <dir>` | string | from config | Override output directory |
|
|
41
|
+
| `-v, --verbose` | flag | false | Show error stacks |
|
|
42
|
+
|
|
43
|
+
Reads configuration from `xrmforge.config.json`.
|
|
44
|
+
|
|
45
|
+
### 4.3 `xrmforge init`
|
|
46
|
+
|
|
47
|
+
Scaffolds a new D365 form scripting project.
|
|
48
|
+
|
|
49
|
+
| Flag | Type | Default | Description |
|
|
50
|
+
|------|------|---------|-------------|
|
|
51
|
+
| `[dir]` | positional | . | Target directory |
|
|
52
|
+
| `--name <name>` | string | dir name | Project name for package.json |
|
|
53
|
+
| `--prefix <prefix>` | string | contoso | Publisher prefix |
|
|
54
|
+
| `--namespace <ns>` | string | PascalCase(prefix) | Base namespace for scripts |
|
|
55
|
+
| `--skip-install` | flag | false | Skip npm install |
|
|
56
|
+
| `--force` | flag | false | Allow non-empty directories |
|
|
57
|
+
|
|
58
|
+
Generates 11 files: package.json, tsconfig.json, xrmforge.config.json, vitest.config.ts, .gitignore, AGENT.md, example-form.ts, example-form.test.ts, generated/.gitkeep, GitHub Actions CI, Azure DevOps Pipeline.
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
# Build Architecture
|
|
2
|
-
|
|
3
|
-
### 5.1 esbuild IIFE Bundles
|
|
4
|
-
|
|
5
|
-
XrmForge uses esbuild to create IIFE (Immediately Invoked Function Expression) bundles for Dynamics 365. D365 requires scripts to be registered as namespace.function (e.g. `Contoso.Account.onLoad`).
|
|
6
|
-
|
|
7
|
-
**esbuild configuration per entry:**
|
|
8
|
-
```
|
|
9
|
-
format: 'iife'
|
|
10
|
-
bundle: true
|
|
11
|
-
globalName: entry.namespace // e.g. 'Contoso.Account'
|
|
12
|
-
target: config.target // default: 'es2020'
|
|
13
|
-
minify: config.minify
|
|
14
|
-
sourcemap: config.sourcemap
|
|
15
|
-
external: config.external // e.g. ['fs', 'path'] for Node.js deps
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
All entries are built in parallel using `Promise.allSettled()`, allowing partial success.
|
|
19
|
-
|
|
20
|
-
### 5.2 xrmforge.config.json Schema
|
|
21
|
-
|
|
22
|
-
```json
|
|
23
|
-
{
|
|
24
|
-
"build": {
|
|
25
|
-
"outDir": "./dist/prefix_/JS",
|
|
26
|
-
"target": "es2020",
|
|
27
|
-
"sourcemap": true,
|
|
28
|
-
"minify": true,
|
|
29
|
-
"external": [],
|
|
30
|
-
"entries": {
|
|
31
|
-
"entry_name": {
|
|
32
|
-
"input": "./src/forms/account-form.ts",
|
|
33
|
-
"namespace": "Contoso.Account",
|
|
34
|
-
"out": "Account/OnLoad.js"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### 5.3 globalName Handling
|
|
42
|
-
|
|
43
|
-
esbuild automatically creates nested globals from dotted namespaces:
|
|
44
|
-
```javascript
|
|
45
|
-
// namespace: "Contoso.Account" produces:
|
|
46
|
-
var Contoso = Contoso || {};
|
|
47
|
-
Contoso.Account = (() => { return { onLoad, onSave }; })();
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
D365 event registration: `Contoso.Account.onLoad`.
|
|
1
|
+
# Build Architecture
|
|
2
|
+
|
|
3
|
+
### 5.1 esbuild IIFE Bundles
|
|
4
|
+
|
|
5
|
+
XrmForge uses esbuild to create IIFE (Immediately Invoked Function Expression) bundles for Dynamics 365. D365 requires scripts to be registered as namespace.function (e.g. `Contoso.Account.onLoad`).
|
|
6
|
+
|
|
7
|
+
**esbuild configuration per entry:**
|
|
8
|
+
```
|
|
9
|
+
format: 'iife'
|
|
10
|
+
bundle: true
|
|
11
|
+
globalName: entry.namespace // e.g. 'Contoso.Account'
|
|
12
|
+
target: config.target // default: 'es2020'
|
|
13
|
+
minify: config.minify
|
|
14
|
+
sourcemap: config.sourcemap
|
|
15
|
+
external: config.external // e.g. ['fs', 'path'] for Node.js deps
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
All entries are built in parallel using `Promise.allSettled()`, allowing partial success.
|
|
19
|
+
|
|
20
|
+
### 5.2 xrmforge.config.json Schema
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"build": {
|
|
25
|
+
"outDir": "./dist/prefix_/JS",
|
|
26
|
+
"target": "es2020",
|
|
27
|
+
"sourcemap": true,
|
|
28
|
+
"minify": true,
|
|
29
|
+
"external": [],
|
|
30
|
+
"entries": {
|
|
31
|
+
"entry_name": {
|
|
32
|
+
"input": "./src/forms/account-form.ts",
|
|
33
|
+
"namespace": "Contoso.Account",
|
|
34
|
+
"out": "Account/OnLoad.js"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 5.3 globalName Handling
|
|
42
|
+
|
|
43
|
+
esbuild automatically creates nested globals from dotted namespaces:
|
|
44
|
+
```javascript
|
|
45
|
+
// namespace: "Contoso.Account" produces:
|
|
46
|
+
var Contoso = Contoso || {};
|
|
47
|
+
Contoso.Account = (() => { return { onLoad, onSave }; })();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
D365 event registration: `Contoso.Account.onLoad`.
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
# Incremental Generation
|
|
2
|
-
|
|
3
|
-
### 6.1 Overview
|
|
4
|
-
|
|
5
|
-
Incremental generation uses the Dataverse `RetrieveMetadataChanges` function to detect which entities have changed since the last generation. This reduces generation time from seconds to milliseconds (measured: 4720ms to 473ms, 10x improvement).
|
|
6
|
-
|
|
7
|
-
### 6.2 Components
|
|
8
|
-
|
|
9
|
-
**ChangeDetector** (`src/metadata/change-detector.ts`):
|
|
10
|
-
- `getInitialVersionStamp()` - First run: fetches the initial ServerVersionStamp
|
|
11
|
-
- `detectChanges(clientVersionStamp)` - Subsequent runs: returns changedEntityNames, deletedEntityNames, newVersionStamp
|
|
12
|
-
|
|
13
|
-
**MetadataCache** (`src/metadata/cache.ts`):
|
|
14
|
-
- Filesystem-based: `.xrmforge/cache/metadata.json`
|
|
15
|
-
- Stores: manifest (version, environment URL, ServerVersionStamp, last refreshed, entity list) + entityTypeInfos per entity
|
|
16
|
-
- Validation: checks cache version, environment URL match, file existence
|
|
17
|
-
|
|
18
|
-
### 6.3 Flow
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
First run (no cache):
|
|
22
|
-
1. Fetch all entity metadata
|
|
23
|
-
2. getInitialVersionStamp()
|
|
24
|
-
3. Save cache with ServerVersionStamp
|
|
25
|
-
|
|
26
|
-
Subsequent run (cache exists):
|
|
27
|
-
1. Load cache, validate environment URL
|
|
28
|
-
2. detectChanges(cachedVersionStamp)
|
|
29
|
-
3. Fetch only changed entities
|
|
30
|
-
4. Remove deleted entities from cache
|
|
31
|
-
5. Save cache with new ServerVersionStamp
|
|
32
|
-
|
|
33
|
-
Expired stamp (>90 days):
|
|
34
|
-
Error code 0x80044352 detected
|
|
35
|
-
Fall back to full refresh
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### 6.4 RetrieveMetadataChanges API
|
|
39
|
-
|
|
40
|
-
- **Type:** OData Function (GET, not POST)
|
|
41
|
-
- **URL:** `/RetrieveMetadataChanges(Query=@q,ClientVersionStamp=@s)?@q={...}&@s='...'`
|
|
42
|
-
- **Response:** EntityMetadata[] with HasChanged flag, ServerVersionStamp, DeletedMetadata
|
|
1
|
+
# Incremental Generation
|
|
2
|
+
|
|
3
|
+
### 6.1 Overview
|
|
4
|
+
|
|
5
|
+
Incremental generation uses the Dataverse `RetrieveMetadataChanges` function to detect which entities have changed since the last generation. This reduces generation time from seconds to milliseconds (measured: 4720ms to 473ms, 10x improvement).
|
|
6
|
+
|
|
7
|
+
### 6.2 Components
|
|
8
|
+
|
|
9
|
+
**ChangeDetector** (`src/metadata/change-detector.ts`):
|
|
10
|
+
- `getInitialVersionStamp()` - First run: fetches the initial ServerVersionStamp
|
|
11
|
+
- `detectChanges(clientVersionStamp)` - Subsequent runs: returns changedEntityNames, deletedEntityNames, newVersionStamp
|
|
12
|
+
|
|
13
|
+
**MetadataCache** (`src/metadata/cache.ts`):
|
|
14
|
+
- Filesystem-based: `.xrmforge/cache/metadata.json`
|
|
15
|
+
- Stores: manifest (version, environment URL, ServerVersionStamp, last refreshed, entity list) + entityTypeInfos per entity
|
|
16
|
+
- Validation: checks cache version, environment URL match, file existence
|
|
17
|
+
|
|
18
|
+
### 6.3 Flow
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
First run (no cache):
|
|
22
|
+
1. Fetch all entity metadata
|
|
23
|
+
2. getInitialVersionStamp()
|
|
24
|
+
3. Save cache with ServerVersionStamp
|
|
25
|
+
|
|
26
|
+
Subsequent run (cache exists):
|
|
27
|
+
1. Load cache, validate environment URL
|
|
28
|
+
2. detectChanges(cachedVersionStamp)
|
|
29
|
+
3. Fetch only changed entities
|
|
30
|
+
4. Remove deleted entities from cache
|
|
31
|
+
5. Save cache with new ServerVersionStamp
|
|
32
|
+
|
|
33
|
+
Expired stamp (>90 days):
|
|
34
|
+
Error code 0x80044352 detected
|
|
35
|
+
Fall back to full refresh
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 6.4 RetrieveMetadataChanges API
|
|
39
|
+
|
|
40
|
+
- **Type:** OData Function (GET, not POST)
|
|
41
|
+
- **URL:** `/RetrieveMetadataChanges(Query=@q,ClientVersionStamp=@s)?@q={...}&@s='...'`
|
|
42
|
+
- **Response:** EntityMetadata[] with HasChanged flag, ServerVersionStamp, DeletedMetadata
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
# HTTP Client
|
|
2
|
-
|
|
3
|
-
### 7.1 DataverseHttpClient
|
|
4
|
-
|
|
5
|
-
The core HTTP client (`src/http/client.ts`) provides resilient communication with the Dataverse Web API.
|
|
6
|
-
|
|
7
|
-
**Key methods:**
|
|
8
|
-
- `get<T>(path, signal?)` - Single GET request with retry
|
|
9
|
-
- `getAll<T>(path, signal?)` - GET with automatic @odata.nextLink paging (max 100 pages)
|
|
10
|
-
|
|
11
|
-
### 7.2 Read-Only Default
|
|
12
|
-
|
|
13
|
-
The client defaults to `readOnly: true`, blocking POST/PATCH/PUT/DELETE requests. This prevents accidental data mutations during type generation. Write access requires explicit `readOnly: false`.
|
|
14
|
-
|
|
15
|
-
### 7.3 Retry with Exponential Backoff
|
|
16
|
-
|
|
17
|
-
- **Base delay:** 1000ms (configurable)
|
|
18
|
-
- **Max backoff:** 60 seconds
|
|
19
|
-
- **Jitter:** Random delay up to base delay
|
|
20
|
-
- **Formula:** `min(baseDelay * 2^(attempt-1) + jitter, 60000)`
|
|
21
|
-
- **Max retries:** configurable (default: 3)
|
|
22
|
-
|
|
23
|
-
### 7.4 Rate Limiting (HTTP 429)
|
|
24
|
-
|
|
25
|
-
- **Separate counter** from standard retries (not mixed)
|
|
26
|
-
- **Retry-After header** respected (seconds converted to milliseconds)
|
|
27
|
-
- **Max 10 consecutive 429 retries** (DEFAULT_MAX_RATE_LIMIT_RETRIES)
|
|
28
|
-
- 429 responses do NOT increment the standard retry counter
|
|
29
|
-
|
|
30
|
-
### 7.5 Concurrency Control
|
|
31
|
-
|
|
32
|
-
Non-recursive semaphore pattern:
|
|
33
|
-
- **maxConcurrency:** 5 (default)
|
|
34
|
-
- Wait queue with FIFO ordering
|
|
35
|
-
- All retries happen inside a single slot (prevents slot exhaustion)
|
|
36
|
-
|
|
37
|
-
### 7.6 Token Caching
|
|
38
|
-
|
|
39
|
-
- In-memory only (never persisted to disk)
|
|
40
|
-
- 5-minute buffer before expiry (TOKEN_BUFFER_MS = 300000)
|
|
41
|
-
- Pending token refresh promise prevents concurrent token requests
|
|
42
|
-
|
|
43
|
-
### 7.7 Input Sanitization
|
|
44
|
-
|
|
45
|
-
OData injection prevention:
|
|
46
|
-
- `sanitizeIdentifier()` - Regex `[a-zA-Z_][a-zA-Z0-9_]*`
|
|
47
|
-
- `sanitizeGuid()` - GUID format validation
|
|
48
|
-
- `escapeODataString()` - Single quote doubling
|
|
49
|
-
|
|
50
|
-
### 7.8 Error Handling
|
|
51
|
-
|
|
52
|
-
| HTTP Status | Behavior | Retried |
|
|
53
|
-
|-------------|----------|---------|
|
|
54
|
-
| 2xx | Success | No |
|
|
55
|
-
| 401 | Clear token cache, retry once | Yes (1x) |
|
|
56
|
-
| 429 | Respect Retry-After, separate counter | Yes (up to 10x) |
|
|
57
|
-
| 5xx | Exponential backoff | Yes (up to maxRetries) |
|
|
58
|
-
| 404, 403 | Non-retryable | No |
|
|
59
|
-
| Network error | Exponential backoff | Yes |
|
|
1
|
+
# HTTP Client
|
|
2
|
+
|
|
3
|
+
### 7.1 DataverseHttpClient
|
|
4
|
+
|
|
5
|
+
The core HTTP client (`src/http/client.ts`) provides resilient communication with the Dataverse Web API.
|
|
6
|
+
|
|
7
|
+
**Key methods:**
|
|
8
|
+
- `get<T>(path, signal?)` - Single GET request with retry
|
|
9
|
+
- `getAll<T>(path, signal?)` - GET with automatic @odata.nextLink paging (max 100 pages)
|
|
10
|
+
|
|
11
|
+
### 7.2 Read-Only Default
|
|
12
|
+
|
|
13
|
+
The client defaults to `readOnly: true`, blocking POST/PATCH/PUT/DELETE requests. This prevents accidental data mutations during type generation. Write access requires explicit `readOnly: false`.
|
|
14
|
+
|
|
15
|
+
### 7.3 Retry with Exponential Backoff
|
|
16
|
+
|
|
17
|
+
- **Base delay:** 1000ms (configurable)
|
|
18
|
+
- **Max backoff:** 60 seconds
|
|
19
|
+
- **Jitter:** Random delay up to base delay
|
|
20
|
+
- **Formula:** `min(baseDelay * 2^(attempt-1) + jitter, 60000)`
|
|
21
|
+
- **Max retries:** configurable (default: 3)
|
|
22
|
+
|
|
23
|
+
### 7.4 Rate Limiting (HTTP 429)
|
|
24
|
+
|
|
25
|
+
- **Separate counter** from standard retries (not mixed)
|
|
26
|
+
- **Retry-After header** respected (seconds converted to milliseconds)
|
|
27
|
+
- **Max 10 consecutive 429 retries** (DEFAULT_MAX_RATE_LIMIT_RETRIES)
|
|
28
|
+
- 429 responses do NOT increment the standard retry counter
|
|
29
|
+
|
|
30
|
+
### 7.5 Concurrency Control
|
|
31
|
+
|
|
32
|
+
Non-recursive semaphore pattern:
|
|
33
|
+
- **maxConcurrency:** 5 (default)
|
|
34
|
+
- Wait queue with FIFO ordering
|
|
35
|
+
- All retries happen inside a single slot (prevents slot exhaustion)
|
|
36
|
+
|
|
37
|
+
### 7.6 Token Caching
|
|
38
|
+
|
|
39
|
+
- In-memory only (never persisted to disk)
|
|
40
|
+
- 5-minute buffer before expiry (TOKEN_BUFFER_MS = 300000)
|
|
41
|
+
- Pending token refresh promise prevents concurrent token requests
|
|
42
|
+
|
|
43
|
+
### 7.7 Input Sanitization
|
|
44
|
+
|
|
45
|
+
OData injection prevention:
|
|
46
|
+
- `sanitizeIdentifier()` - Regex `[a-zA-Z_][a-zA-Z0-9_]*`
|
|
47
|
+
- `sanitizeGuid()` - GUID format validation
|
|
48
|
+
- `escapeODataString()` - Single quote doubling
|
|
49
|
+
|
|
50
|
+
### 7.8 Error Handling
|
|
51
|
+
|
|
52
|
+
| HTTP Status | Behavior | Retried |
|
|
53
|
+
|-------------|----------|---------|
|
|
54
|
+
| 2xx | Success | No |
|
|
55
|
+
| 401 | Clear token cache, retry once | Yes (1x) |
|
|
56
|
+
| 429 | Respect Retry-After, separate counter | Yes (up to 10x) |
|
|
57
|
+
| 5xx | Exponential backoff | Yes (up to maxRetries) |
|
|
58
|
+
| 404, 403 | Non-retryable | No |
|
|
59
|
+
| Network error | Exponential backoff | Yes |
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# Authentication
|
|
2
|
-
|
|
3
|
-
### 8.1 Credential Factory
|
|
4
|
-
|
|
5
|
-
`createCredential(config: AuthConfig)` returns a `TokenCredential` (from @azure/identity) based on the auth method:
|
|
6
|
-
|
|
7
|
-
### 8.2 Four Auth Flows
|
|
8
|
-
|
|
9
|
-
| Method | Config | @azure/identity Class | Use Case |
|
|
10
|
-
|--------|--------|-----------------------|----------|
|
|
11
|
-
| client-credentials | tenantId, clientId, clientSecret | ClientSecretCredential | CI/CD, automated pipelines |
|
|
12
|
-
| interactive | tenantId, clientId? | InteractiveBrowserCredential | Developer workstation |
|
|
13
|
-
| device-code | tenantId, clientId? | DeviceCodeCredential | Headless CLI environments |
|
|
14
|
-
| token | token (string) | StaticTokenCredential | Pre-acquired tokens (e.g. from TokenVault) |
|
|
15
|
-
|
|
16
|
-
### 8.3 Token Scope
|
|
17
|
-
|
|
18
|
-
All auth flows request the scope: `{environmentUrl}/.default`
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
### 8.1 Credential Factory
|
|
4
|
+
|
|
5
|
+
`createCredential(config: AuthConfig)` returns a `TokenCredential` (from @azure/identity) based on the auth method:
|
|
6
|
+
|
|
7
|
+
### 8.2 Four Auth Flows
|
|
8
|
+
|
|
9
|
+
| Method | Config | @azure/identity Class | Use Case |
|
|
10
|
+
|--------|--------|-----------------------|----------|
|
|
11
|
+
| client-credentials | tenantId, clientId, clientSecret | ClientSecretCredential | CI/CD, automated pipelines |
|
|
12
|
+
| interactive | tenantId, clientId? | InteractiveBrowserCredential | Developer workstation |
|
|
13
|
+
| device-code | tenantId, clientId? | DeviceCodeCredential | Headless CLI environments |
|
|
14
|
+
| token | token (string) | StaticTokenCredential | Pre-acquired tokens (e.g. from TokenVault) |
|
|
15
|
+
|
|
16
|
+
### 8.3 Token Scope
|
|
17
|
+
|
|
18
|
+
All auth flows request the scope: `{environmentUrl}/.default`
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
# Testing Framework
|
|
2
|
-
|
|
3
|
-
### 9.1 createFormMock
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { createFormMock } from '@xrmforge/testing';
|
|
7
|
-
import type { AccountMainForm, AccountMainFormMockValues } from '../generated/forms/account';
|
|
8
|
-
|
|
9
|
-
const mock = createFormMock<AccountMainForm, AccountMainFormMockValues>({
|
|
10
|
-
name: 'Contoso Ltd',
|
|
11
|
-
statuscode: 0,
|
|
12
|
-
revenue: 1000000,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// Use in tests:
|
|
16
|
-
onLoad(mock.executionContext);
|
|
17
|
-
expect(mock.formContext.getControl('revenue').getVisible()).toBe(true);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
**What it mocks:**
|
|
21
|
-
- Attributes: MockAttribute instances with getValue/setValue, dirty tracking, onChange handlers, required level, submit mode
|
|
22
|
-
- Controls: MockControl instances with visible/disabled/label/notification state
|
|
23
|
-
- UI: Form notifications, tab/section stubs
|
|
24
|
-
- Entity: ID, entity name, primary attribute
|
|
25
|
-
- Data: refresh(), save() stubs returning Promise-like
|
|
26
|
-
- Navigation: openForm/openAlertDialog stubs
|
|
27
|
-
|
|
28
|
-
**Lazy initialization:** Attributes accessed via `getAttribute()` that were not in the initial values are created on-the-fly with null value.
|
|
29
|
-
|
|
30
|
-
### 9.2 fireOnChange
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
mock.fireOnChange('statuscode');
|
|
34
|
-
// Triggers all handlers registered via getAttribute('statuscode').addOnChange(handler)
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
Creates a MockEventContext with the attribute as event source.
|
|
38
|
-
|
|
39
|
-
### 9.3 setupXrmMock / teardownXrmMock
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { setupXrmMock, teardownXrmMock } from '@xrmforge/testing';
|
|
43
|
-
|
|
44
|
-
beforeEach(() => setupXrmMock());
|
|
45
|
-
afterEach(() => teardownXrmMock());
|
|
46
|
-
|
|
47
|
-
// With WebApi overrides:
|
|
48
|
-
setupXrmMock({
|
|
49
|
-
webApiOverrides: {
|
|
50
|
-
retrieveMultipleRecords: async () => ({ entities: [{ name: 'Test' }] }),
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Sets up a global `Xrm` object on `globalThis` with minimal WebApi, Navigation, and Utility stubs.
|
|
1
|
+
# Testing Framework
|
|
2
|
+
|
|
3
|
+
### 9.1 createFormMock
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { createFormMock } from '@xrmforge/testing';
|
|
7
|
+
import type { AccountMainForm, AccountMainFormMockValues } from '../generated/forms/account';
|
|
8
|
+
|
|
9
|
+
const mock = createFormMock<AccountMainForm, AccountMainFormMockValues>({
|
|
10
|
+
name: 'Contoso Ltd',
|
|
11
|
+
statuscode: 0,
|
|
12
|
+
revenue: 1000000,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Use in tests:
|
|
16
|
+
onLoad(mock.executionContext);
|
|
17
|
+
expect(mock.formContext.getControl('revenue').getVisible()).toBe(true);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**What it mocks:**
|
|
21
|
+
- Attributes: MockAttribute instances with getValue/setValue, dirty tracking, onChange handlers, required level, submit mode
|
|
22
|
+
- Controls: MockControl instances with visible/disabled/label/notification state
|
|
23
|
+
- UI: Form notifications, tab/section stubs
|
|
24
|
+
- Entity: ID, entity name, primary attribute
|
|
25
|
+
- Data: refresh(), save() stubs returning Promise-like
|
|
26
|
+
- Navigation: openForm/openAlertDialog stubs
|
|
27
|
+
|
|
28
|
+
**Lazy initialization:** Attributes accessed via `getAttribute()` that were not in the initial values are created on-the-fly with null value.
|
|
29
|
+
|
|
30
|
+
### 9.2 fireOnChange
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
mock.fireOnChange('statuscode');
|
|
34
|
+
// Triggers all handlers registered via getAttribute('statuscode').addOnChange(handler)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Creates a MockEventContext with the attribute as event source.
|
|
38
|
+
|
|
39
|
+
### 9.3 setupXrmMock / teardownXrmMock
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { setupXrmMock, teardownXrmMock } from '@xrmforge/testing';
|
|
43
|
+
|
|
44
|
+
beforeEach(() => setupXrmMock());
|
|
45
|
+
afterEach(() => teardownXrmMock());
|
|
46
|
+
|
|
47
|
+
// With WebApi overrides:
|
|
48
|
+
setupXrmMock({
|
|
49
|
+
webApiOverrides: {
|
|
50
|
+
retrieveMultipleRecords: async () => ({ entities: [{ name: 'Test' }] }),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Sets up a global `Xrm` object on `globalThis` with minimal WebApi, Navigation, and Utility stubs.
|