@edirect/dynamics 11.0.45 → 11.0.46

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/dist/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @edirect/dynamics
2
+
3
+ Dynamics integration module for Edirect applications. Provides services and utilities to interact with Microsoft Dynamics APIs, including authentication, data posting, and configuration.
4
+
5
+ ## Features
6
+
7
+ - Handles OAuth2 authentication with Dynamics
8
+ - Provides service for posting and retrieving data
9
+ - Integrates with NestJS and Edirect config modules
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @edirect/dynamics
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Add the following environment variables to your .env file:
20
+
21
+ ```env
22
+ DYNAMICS_TOKEN_URL="https://login.windows.net/YOUR_TENANT/oauth2/token"
23
+ DYNAMICS_CLIENT_ID="YOUR_CLIENT_ID"
24
+ DYNAMICS_USER_NAME="YOUR_USER_NAME"
25
+ DYNAMICS_PASSWORD="YOUR_DYNAMICS_PASSWORD"
26
+ DYNAMICS_RESOURCE="YOUR_RESOURCE_URL"
27
+ DYNAMICS_ENABLED="true/false"
28
+ ```
29
+
30
+ Import and register the module in your app:
31
+
32
+ ```typescript
33
+ import { Module } from '@nestjs/common';
34
+ import { DynamicsModule } from '@edirect/dynamics';
35
+
36
+ @Module({
37
+ imports: [DynamicsModule],
38
+ ...
39
+ })
40
+ export class AppModule {}
41
+ ```
42
+
43
+ Use the service in your controllers:
44
+
45
+ ```typescript
46
+ import { Controller } from '@nestjs/common';
47
+ import { DynamicsService } from '@edirect/dynamics';
48
+
49
+ @Controller('cats')
50
+ export class CatsController {
51
+ constructor(private readonly dynamicsService: DynamicsService) {}
52
+
53
+ postSomethingToDynamics(): Promise<any> {
54
+ return this.dynamicsService.post('YOUR_URL', {
55
+ YOUR_ATTRIBUTE: 'YOUR_VALUE',
56
+ });
57
+ }
58
+ }
59
+ ```
60
+
61
+ ## Environment Variables
62
+
63
+ - `DYNAMICS_TOKEN_URL`: OAuth2 token endpoint for Dynamics
64
+ - `DYNAMICS_CLIENT_ID`: Client ID for authentication
65
+ - `DYNAMICS_USER_NAME`: Username for Dynamics
66
+ - `DYNAMICS_PASSWORD`: Password for Dynamics
67
+ - `DYNAMICS_RESOURCE`: Resource URL for Dynamics API
68
+ - `DYNAMICS_ENABLED`: Enable/disable Dynamics integration
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@edirect/dynamics",
3
+ "version": "11.0.46",
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.46",
20
+ "@nestjs/axios": "^4.0.1",
21
+ "@nestjs/common": "^11.1.12",
22
+ "axios": "^1.13.3",
23
+ "lodash": "^4.17.23",
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.23",
30
+ "@types/node": "^25.0.10"
31
+ },
32
+ "type": "commonjs"
33
+ }
@@ -0,0 +1,3 @@
1
+ export declare class DynamicsModule {
2
+ }
3
+ //# sourceMappingURL=dynamics.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamics.module.d.ts","sourceRoot":"","sources":["../../../src/dynamics/dynamics.module.ts"],"names":[],"mappings":"AAMA,qBAMa,cAAc;CAAG"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicsModule = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const config_1 = require("@edirect/config");
7
+ const axios_1 = require("@nestjs/axios");
8
+ const dynamics_service_1 = require("./dynamics.service");
9
+ let DynamicsModule = class DynamicsModule {
10
+ };
11
+ exports.DynamicsModule = DynamicsModule;
12
+ exports.DynamicsModule = DynamicsModule = tslib_1.__decorate([
13
+ (0, common_1.Global)(),
14
+ (0, common_1.Module)({
15
+ imports: [config_1.ConfigModule, axios_1.HttpModule],
16
+ providers: [dynamics_service_1.DynamicsService],
17
+ exports: [dynamics_service_1.DynamicsService],
18
+ })
19
+ ], DynamicsModule);
@@ -0,0 +1,18 @@
1
+ import { ConfigService } from '@edirect/config';
2
+ import { HttpService } from '@nestjs/axios';
3
+ import { AxiosRequestConfig } from 'axios';
4
+ import { ITokenSet } from '../interfaces/token-set.interface';
5
+ export declare class DynamicsService {
6
+ private readonly configService;
7
+ private readonly httpService;
8
+ private tokenSet;
9
+ constructor(configService: ConfigService, httpService: HttpService);
10
+ getAccessToken(): Promise<ITokenSet>;
11
+ getAccessTokenByClientCredentials(): Promise<ITokenSet>;
12
+ getRefreshToken(): Promise<ITokenSet>;
13
+ get(url: string, options?: AxiosRequestConfig, grantType?: string): Promise<object | null>;
14
+ post(url: string, data: object, options?: AxiosRequestConfig, grantType?: string): Promise<object | null>;
15
+ patch(url: string, data: object, options?: AxiosRequestConfig, grantType?: string): Promise<object | null>;
16
+ getTokenByGrantType(grantType?: string): Promise<ITokenSet>;
17
+ }
18
+ //# sourceMappingURL=dynamics.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamics.service.d.ts","sourceRoot":"","sources":["../../../src/dynamics/dynamics.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAiB,MAAM,OAAO,CAAC;AAI1D,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAE9D,qBACa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW;IAJ9B,OAAO,CAAC,QAAQ,CAAa;gBAGV,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW;IAGrC,cAAc,IAAI,OAAO,CAAC,SAAS,CAAC;IA6BpC,iCAAiC,IAAI,OAAO,CAAC,SAAS,CAAC;IAuBvD,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC;IAyBrC,GAAG,CACP,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,kBAAkB,EAC5B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsBnB,IAAI,CACR,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,EAC5B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAuBnB,KAAK,CACT,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,kBAAkB,EAC5B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAuBnB,mBAAmB,CAAC,SAAS,SAAa,GAAG,OAAO,CAAC,SAAS,CAAC;CAMtE"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicsService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const config_1 = require("@edirect/config");
6
+ const axios_1 = require("@nestjs/axios");
7
+ const common_1 = require("@nestjs/common");
8
+ const merge_1 = tslib_1.__importDefault(require("lodash/merge"));
9
+ const querystring_1 = require("querystring");
10
+ let DynamicsService = class DynamicsService {
11
+ configService;
12
+ httpService;
13
+ tokenSet;
14
+ constructor(configService, httpService) {
15
+ this.configService = configService;
16
+ this.httpService = httpService;
17
+ }
18
+ async getAccessToken() {
19
+ if (this.tokenSet &&
20
+ parseInt(this.tokenSet.expires_on, 10) * 1000 > Date.now()) {
21
+ return this.getRefreshToken();
22
+ }
23
+ this.tokenSet = await this.httpService.axiosRef
24
+ .post(this.configService.get('DYNAMICS_TOKEN_URL'), (0, querystring_1.stringify)({
25
+ client_id: this.configService.get('DYNAMICS_CLIENT_ID'),
26
+ username: this.configService.get('DYNAMICS_USER_NAME'),
27
+ password: this.configService.get('DYNAMICS_PASSWORD'),
28
+ resource: this.configService.get('DYNAMICS_RESOURCE'),
29
+ grant_type: 'password',
30
+ }), {
31
+ headers: {
32
+ 'Content-Type': 'application/x-www-form-urlencoded',
33
+ },
34
+ })
35
+ .then((response) => response.data);
36
+ return this.tokenSet;
37
+ }
38
+ async getAccessTokenByClientCredentials() {
39
+ this.tokenSet = await this.httpService.axiosRef
40
+ .post(this.configService.get('DYNAMICS_TOKEN_URL'), (0, querystring_1.stringify)({
41
+ client_id: this.configService.get('DYNAMICS_CLIENT_ID'),
42
+ client_secret: this.configService.get('DYNAMICS_CLIENT_SECRET'),
43
+ resource: this.configService.get('DYNAMICS_RESOURCE'),
44
+ grant_type: 'client_credentials',
45
+ }), {
46
+ headers: {
47
+ 'Content-Type': 'application/x-www-form-urlencoded',
48
+ },
49
+ })
50
+ .then((response) => response.data);
51
+ return this.tokenSet;
52
+ }
53
+ async getRefreshToken() {
54
+ try {
55
+ this.tokenSet = await this.httpService.axiosRef
56
+ .post(this.configService.get('DYNAMICS_TOKEN_URL'), (0, querystring_1.stringify)({
57
+ client_id: this.configService.get('DYNAMICS_CLIENT_ID'),
58
+ resource: this.configService.get('DYNAMICS_RESOURCE'),
59
+ refresh_token: this.tokenSet.refresh_token,
60
+ grant_type: 'refresh_token',
61
+ }), {
62
+ headers: {
63
+ 'Content-Type': 'application/x-www-form-urlencoded',
64
+ },
65
+ })
66
+ .then((response) => response.data);
67
+ }
68
+ catch {
69
+ return this.getAccessToken();
70
+ }
71
+ return this.tokenSet;
72
+ }
73
+ async get(url, options, grantType) {
74
+ if (!this.configService.get('DYNAMICS_ENABLED') ||
75
+ this.configService.get('DYNAMICS_ENABLED') === 'false') {
76
+ return null;
77
+ }
78
+ const tokenSet = await this.getTokenByGrantType(grantType);
79
+ const defaultConfig = {
80
+ headers: {
81
+ Authorization: `${tokenSet.token_type} ${tokenSet.access_token}`,
82
+ },
83
+ };
84
+ const config = (0, merge_1.default)(defaultConfig, options);
85
+ return this.httpService.axiosRef
86
+ .get(url, config)
87
+ .then((response) => response.data);
88
+ }
89
+ async post(url, data, options, grantType) {
90
+ if (!this.configService.get('DYNAMICS_ENABLED') ||
91
+ this.configService.get('DYNAMICS_ENABLED') === 'false') {
92
+ return null;
93
+ }
94
+ const tokenSet = await this.getTokenByGrantType(grantType);
95
+ const defaultConfig = {
96
+ headers: {
97
+ Authorization: `${tokenSet.token_type} ${tokenSet.access_token}`,
98
+ 'Content-Type': 'application/json',
99
+ },
100
+ };
101
+ const config = (0, merge_1.default)(defaultConfig, options);
102
+ return this.httpService.axiosRef
103
+ .post(url, data, config)
104
+ .then((response) => response.data);
105
+ }
106
+ async patch(url, data, options, grantType) {
107
+ if (!this.configService.get('DYNAMICS_ENABLED') ||
108
+ this.configService.get('DYNAMICS_ENABLED') === 'false') {
109
+ return null;
110
+ }
111
+ const tokenSet = await this.getTokenByGrantType(grantType);
112
+ const defaultConfig = {
113
+ headers: {
114
+ Authorization: `${tokenSet.token_type} ${tokenSet.access_token}`,
115
+ 'Content-Type': 'application/json',
116
+ },
117
+ };
118
+ const config = (0, merge_1.default)(defaultConfig, options);
119
+ return this.httpService.axiosRef
120
+ .patch(url, data, config)
121
+ .then((response) => response.data);
122
+ }
123
+ async getTokenByGrantType(grantType = 'password') {
124
+ if (grantType === 'client_credentials') {
125
+ return this.getAccessTokenByClientCredentials();
126
+ }
127
+ return this.getAccessToken();
128
+ }
129
+ };
130
+ exports.DynamicsService = DynamicsService;
131
+ exports.DynamicsService = DynamicsService = tslib_1.__decorate([
132
+ (0, common_1.Injectable)(),
133
+ tslib_1.__metadata("design:paramtypes", [config_1.ConfigService,
134
+ axios_1.HttpService])
135
+ ], DynamicsService);
@@ -0,0 +1,4 @@
1
+ export * from './dynamics/dynamics.module';
2
+ export * from './dynamics/dynamics.service';
3
+ export * from './interfaces/token-set.interface';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./dynamics/dynamics.module"), exports);
5
+ tslib_1.__exportStar(require("./dynamics/dynamics.service"), exports);
6
+ tslib_1.__exportStar(require("./interfaces/token-set.interface"), exports);
@@ -0,0 +1,12 @@
1
+ export interface ITokenSet {
2
+ token_type: string;
3
+ scope: string;
4
+ expires_in: string;
5
+ ext_expires_in: string;
6
+ expires_on: string;
7
+ not_before: string;
8
+ resource: string;
9
+ access_token: string;
10
+ refresh_token: string;
11
+ }
12
+ //# sourceMappingURL=token-set.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-set.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/token-set.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ {"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/dynamics",
3
- "version": "11.0.45",
3
+ "version": "11.0.46",
4
4
  "packageScope": "@edirect",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "axios": "^1.13.3",
23
23
  "lodash": "^4.17.23",
24
24
  "tslib": "^2.8.1",
25
- "@edirect/config": "11.0.45"
25
+ "@edirect/config": "11.0.46"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/express": "^5.0.6",