@edirect/dynamics 11.0.65 → 11.0.66
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/package.json +11 -28
- package/dist/README.md +0 -137
- package/dist/package.json +0 -33
- package/dist/tsconfig.lib.tsbuildinfo +0 -1
- /package/{dist/src → src}/dynamics/dynamics.module.d.ts +0 -0
- /package/{dist/src → src}/dynamics/dynamics.module.d.ts.map +0 -0
- /package/{dist/src → src}/dynamics/dynamics.module.js +0 -0
- /package/{dist/src → src}/dynamics/dynamics.service.d.ts +0 -0
- /package/{dist/src → src}/dynamics/dynamics.service.d.ts.map +0 -0
- /package/{dist/src → src}/dynamics/dynamics.service.js +0 -0
- /package/{dist/src → src}/index.d.ts +0 -0
- /package/{dist/src → src}/index.d.ts.map +0 -0
- /package/{dist/src → src}/index.js +0 -0
- /package/{dist/src → src}/interfaces/token-set.interface.d.ts +0 -0
- /package/{dist/src → src}/interfaces/token-set.interface.d.ts.map +0 -0
- /package/{dist/src → src}/interfaces/token-set.interface.js +0 -0
package/package.json
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/dynamics",
|
|
3
|
-
"version": "11.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"types": "./dist/src/index.d.ts",
|
|
3
|
+
"version": "11.0.66",
|
|
4
|
+
"main": "./src/index.js",
|
|
5
|
+
"types": "./src/index.d.ts",
|
|
7
6
|
"exports": {
|
|
8
7
|
".": {
|
|
9
|
-
"import": "./
|
|
10
|
-
"default": "./
|
|
11
|
-
"require": "./
|
|
12
|
-
"types": "./
|
|
8
|
+
"import": "./src/index.js",
|
|
9
|
+
"default": "./src/index.js",
|
|
10
|
+
"require": "./src/index.js",
|
|
11
|
+
"types": "./src/index.d.ts"
|
|
13
12
|
},
|
|
14
13
|
"./package.json": "./package.json"
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
|
17
|
-
"
|
|
16
|
+
"src"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
19
|
+
"@edirect/config": "11.0.66",
|
|
20
20
|
"@nestjs/axios": "^4.0.1",
|
|
21
21
|
"@nestjs/common": "^11.2.1",
|
|
22
22
|
"axios": "^1.19.0",
|
|
23
23
|
"lodash": "^4.18.1",
|
|
24
|
-
"tslib": "^2.8.1"
|
|
25
|
-
"@edirect/config": "11.0.65"
|
|
24
|
+
"tslib": "^2.8.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/express": "^5.0.6",
|
|
@@ -30,21 +29,5 @@
|
|
|
30
29
|
"@types/lodash": "4.17.25",
|
|
31
30
|
"@types/node": "^26.2.0"
|
|
32
31
|
},
|
|
33
|
-
"
|
|
34
|
-
"name": "@edirect/dynamics",
|
|
35
|
-
"targets": {
|
|
36
|
-
"build": {
|
|
37
|
-
"executor": "@nx/js:tsc",
|
|
38
|
-
"options": {
|
|
39
|
-
"main": "{workspaceRoot}/packages/edirect-dynamics/src/index.ts",
|
|
40
|
-
"tsConfig": "{workspaceRoot}/packages/edirect-dynamics/tsconfig.lib.json",
|
|
41
|
-
"outputPath": "{workspaceRoot}/packages/edirect-dynamics/dist",
|
|
42
|
-
"assets": [
|
|
43
|
-
"{workspaceRoot}/packages/edirect-dynamics/package.json",
|
|
44
|
-
"{workspaceRoot}/packages/edirect-dynamics/README.md"
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
32
|
+
"type": "commonjs"
|
|
50
33
|
}
|
package/dist/README.md
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# @edirect/dynamics
|
|
2
|
-
|
|
3
|
-
Microsoft Dynamics 365 integration module for eDirect NestJS applications. Handles OAuth2 token acquisition (password grant and client credentials), automatic token refresh, and provides `get`, `post`, and `patch` methods for Dynamics API calls.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- OAuth2 `password` grant and `client_credentials` grant support
|
|
8
|
-
- Automatic token caching and refresh (falls back to full re-auth on refresh failure)
|
|
9
|
-
- `get`, `post`, `patch` HTTP methods with automatic Bearer token injection
|
|
10
|
-
- `DYNAMICS_ENABLED` flag to safely disable all Dynamics calls without removing code
|
|
11
|
-
- NestJS module — integrates with `@edirect/config`
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
pnpm add @edirect/dynamics
|
|
17
|
-
# or
|
|
18
|
-
npm install @edirect/dynamics
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Setup
|
|
22
|
-
|
|
23
|
-
### 1. Set environment variables
|
|
24
|
-
|
|
25
|
-
```env
|
|
26
|
-
DYNAMICS_TOKEN_URL=https://login.windows.net/YOUR_TENANT_ID/oauth2/token
|
|
27
|
-
DYNAMICS_CLIENT_ID=your-client-id
|
|
28
|
-
DYNAMICS_CLIENT_SECRET=your-client-secret # required for client_credentials grant
|
|
29
|
-
DYNAMICS_USER_NAME=service@yourorg.onmicrosoft.com # required for password grant
|
|
30
|
-
DYNAMICS_PASSWORD=your-dynamics-password # required for password grant
|
|
31
|
-
DYNAMICS_RESOURCE=https://yourorg.crm.dynamics.com
|
|
32
|
-
DYNAMICS_ENABLED=true
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 2. Register `DynamicsModule` in your AppModule
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { Module } from '@nestjs/common';
|
|
39
|
-
import { DynamicsModule } from '@edirect/dynamics';
|
|
40
|
-
|
|
41
|
-
@Module({
|
|
42
|
-
imports: [DynamicsModule],
|
|
43
|
-
})
|
|
44
|
-
export class AppModule {}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 3. Inject and use `DynamicsService`
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import { Injectable } from '@nestjs/common';
|
|
51
|
-
import { DynamicsService } from '@edirect/dynamics';
|
|
52
|
-
|
|
53
|
-
@Injectable()
|
|
54
|
-
export class PolicySyncService {
|
|
55
|
-
constructor(private readonly dynamics: DynamicsService) {}
|
|
56
|
-
|
|
57
|
-
// POST using password grant (default)
|
|
58
|
-
async createContact(data: object): Promise<object | null> {
|
|
59
|
-
return this.dynamics.post(
|
|
60
|
-
'https://yourorg.crm.dynamics.com/api/data/v9.2/contacts',
|
|
61
|
-
data,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// PATCH using password grant
|
|
66
|
-
async updateContact(id: string, data: object): Promise<object | null> {
|
|
67
|
-
return this.dynamics.patch(
|
|
68
|
-
`https://yourorg.crm.dynamics.com/api/data/v9.2/contacts(${id})`,
|
|
69
|
-
data,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// GET using client_credentials grant
|
|
74
|
-
async getAccounts(): Promise<object | null> {
|
|
75
|
-
return this.dynamics.get(
|
|
76
|
-
'https://yourorg.crm.dynamics.com/api/data/v9.2/accounts',
|
|
77
|
-
{},
|
|
78
|
-
'client_credentials',
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## API
|
|
85
|
-
|
|
86
|
-
### `DynamicsService`
|
|
87
|
-
|
|
88
|
-
#### `get(url, options?, grantType?): Promise<object | null>`
|
|
89
|
-
|
|
90
|
-
Performs a GET request to the Dynamics API. Returns `null` if `DYNAMICS_ENABLED` is `false`.
|
|
91
|
-
|
|
92
|
-
| Parameter | Type | Default | Description |
|
|
93
|
-
| ----------- | ------------------------------------ | ------------ | -------------------------------- |
|
|
94
|
-
| `url` | `string` | — | Full Dynamics API endpoint URL |
|
|
95
|
-
| `options` | `AxiosRequestConfig` | — | Additional Axios request options |
|
|
96
|
-
| `grantType` | `'password' \| 'client_credentials'` | `'password'` | OAuth2 grant type to use |
|
|
97
|
-
|
|
98
|
-
#### `post(url, data, options?, grantType?): Promise<object | null>`
|
|
99
|
-
|
|
100
|
-
Performs a POST request. Returns `null` if `DYNAMICS_ENABLED` is `false`.
|
|
101
|
-
|
|
102
|
-
#### `patch(url, data, options?, grantType?): Promise<object | null>`
|
|
103
|
-
|
|
104
|
-
Performs a PATCH request. Returns `null` if `DYNAMICS_ENABLED` is `false`.
|
|
105
|
-
|
|
106
|
-
#### `getAccessToken(): Promise<ITokenSet>`
|
|
107
|
-
|
|
108
|
-
Acquires a token using the `password` grant. Automatically refreshes if expired.
|
|
109
|
-
|
|
110
|
-
#### `getAccessTokenByClientCredentials(): Promise<ITokenSet>`
|
|
111
|
-
|
|
112
|
-
Acquires a token using `client_credentials` grant.
|
|
113
|
-
|
|
114
|
-
#### `getRefreshToken(): Promise<ITokenSet>`
|
|
115
|
-
|
|
116
|
-
Refreshes the current token. Falls back to `getAccessToken()` on failure.
|
|
117
|
-
|
|
118
|
-
## Environment Variables
|
|
119
|
-
|
|
120
|
-
| Variable | Description | Required For |
|
|
121
|
-
| ------------------------ | ----------------------------------------------------------------- | -------------------- |
|
|
122
|
-
| `DYNAMICS_TOKEN_URL` | Azure AD OAuth2 token endpoint | All grant types |
|
|
123
|
-
| `DYNAMICS_CLIENT_ID` | Application client ID | All grant types |
|
|
124
|
-
| `DYNAMICS_CLIENT_SECRET` | Client secret | `client_credentials` |
|
|
125
|
-
| `DYNAMICS_USER_NAME` | Service account username | `password` |
|
|
126
|
-
| `DYNAMICS_PASSWORD` | Service account password | `password` |
|
|
127
|
-
| `DYNAMICS_RESOURCE` | Dynamics CRM resource URL | All grant types |
|
|
128
|
-
| `DYNAMICS_ENABLED` | Set to `'true'` to enable; any other value disables all API calls | All |
|
|
129
|
-
|
|
130
|
-
## Token Flow
|
|
131
|
-
|
|
132
|
-
```
|
|
133
|
-
1. First call → acquire token (password or client_credentials)
|
|
134
|
-
2. Subsequent calls → if token not expired, use refresh_token grant
|
|
135
|
-
3. If refresh fails → fall back to full re-authentication
|
|
136
|
-
4. Token is cached in memory (service singleton)
|
|
137
|
-
```
|
package/dist/package.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@edirect/dynamics",
|
|
3
|
-
"version": "11.0.65",
|
|
4
|
-
"main": "./dist/src/index.js",
|
|
5
|
-
"types": "./dist/src/index.d.ts",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/src/index.js",
|
|
9
|
-
"default": "./dist/src/index.js",
|
|
10
|
-
"require": "./dist/src/index.js",
|
|
11
|
-
"types": "./dist/src/index.d.ts"
|
|
12
|
-
},
|
|
13
|
-
"./package.json": "./package.json"
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist"
|
|
17
|
-
],
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@edirect/config": "^11.0.65",
|
|
20
|
-
"@nestjs/axios": "^4.0.1",
|
|
21
|
-
"@nestjs/common": "^11.2.1",
|
|
22
|
-
"axios": "^1.19.0",
|
|
23
|
-
"lodash": "^4.18.1",
|
|
24
|
-
"tslib": "^2.8.1"
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@types/express": "^5.0.6",
|
|
28
|
-
"@types/jest": "30.0.0",
|
|
29
|
-
"@types/lodash": "4.17.25",
|
|
30
|
-
"@types/node": "^26.2.0"
|
|
31
|
-
},
|
|
32
|
-
"type": "commonjs"
|
|
33
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"5.9.3"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|