|
| 1 | +# Migration Notes: Moving from v1 Client to Logically Grouped Packages |
| 2 | + |
| 3 | +This guide goes over how to migrate your code from using the monolithic `@datadog/datadog-api-client` package to the new logically grouped packages structure. |
| 4 | + |
| 5 | +## Major changes |
| 6 | + |
| 7 | +### Package structure changes |
| 8 | +- The `@datadog/datadog-api-client` package now only contains core components and configuration objects. |
| 9 | +- Service-specific code (e.g., `Monitor`) has been moved to individual packages in `services/` directory |
| 10 | + - Each API grouping is in its own dedicated package following the naming convention `@datadog/datadog-api-client-{apiName}` |
| 11 | + |
| 12 | +### Configuration object updates |
| 13 | +- `serverVariables`, `operationServerVariables` and `unstableOperation` keys in the configuration object now follow the same format: |
| 14 | + |
| 15 | + ``` |
| 16 | + { apiName }.{ apiVersion }.{operation} |
| 17 | + ``` |
| 18 | + |
| 19 | +## Migration steps |
| 20 | + |
| 21 | +### 1. Package installation |
| 22 | + |
| 23 | +Install the required packages: |
| 24 | + |
| 25 | +```bash |
| 26 | +# Service-specific packages (install only the ones you need) |
| 27 | +npm install @datadog/datadog-api-client-monitors |
| 28 | +# OR |
| 29 | +yarn add @datadog/datadog-api-client-monitors |
| 30 | +# ... and so on for other services |
| 31 | +``` |
| 32 | + |
| 33 | +All of the clients directly depend on the `@datadog/datadog-api-client` package for core components such as `Configuration` object. |
| 34 | +You can manually install the client using: |
| 35 | + |
| 36 | +```bash |
| 37 | +npm install @datadog/datadog-api-client@^2.0.0-beta.1 |
| 38 | +# OR |
| 39 | +yarn add @datadog/datadog-api-client@^2.0.0-beta.1 |
| 40 | +``` |
| 41 | + |
| 42 | +### 2. Update core imports |
| 43 | +Replace imports of core components from the main package: |
| 44 | + |
| 45 | +```typescript |
| 46 | +// Old |
| 47 | +import { client } from "@datadog/datadog-api-client"; |
| 48 | + |
| 49 | +const configuration = client.createConfiguration() |
| 50 | +``` |
| 51 | + |
| 52 | +```typescript |
| 53 | +// New |
| 54 | +import { createConfiguration } from "@datadog/datadog-api-client"; |
| 55 | + |
| 56 | +const configuration = createConfiguration() |
| 57 | +``` |
| 58 | + |
| 59 | +### 3. Update service specific imports |
| 60 | +Update imports for service-specific models and APIs: |
| 61 | + |
| 62 | +```typescript |
| 63 | +// Old |
| 64 | +import { v1 } from "@datadog/datadog-api-client"; |
| 65 | + |
| 66 | +const apiInstance = new v1.MonitorsApi(); |
| 67 | +``` |
| 68 | + |
| 69 | +```typescript |
| 70 | +// New |
| 71 | +import { v1 } from "@datadog/datadog-api-client-monitors"; |
| 72 | + |
| 73 | +const apiInstance = new v1.MonitorsApi(); |
| 74 | +``` |
| 75 | + |
| 76 | +### 4. Update configuration |
| 77 | +Update your configuration object to use the new format `{ apiName }.{ apiVersion }.{ operation }` |
| 78 | + |
| 79 | +```typescript |
| 80 | +// Old |
| 81 | +const configuration = createConfiguration({ |
| 82 | + operationServerIndices: { |
| 83 | + "v2.LogsApi.submitLog": 0 |
| 84 | + }, |
| 85 | + unstableOperations: { |
| 86 | + "v2.createOpenAPI": true |
| 87 | + } |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +```typescript |
| 92 | +// New |
| 93 | +const configuration = createConfiguration({ |
| 94 | + operationServerIndices: { |
| 95 | + "LogsApi.v2.submitLog": 0 |
| 96 | + }, |
| 97 | + operationServerVariables: { |
| 98 | + "LogsApi.v2.submitLog": { |
| 99 | + "site": "datadoghq.eu" |
| 100 | + } |
| 101 | + }, |
| 102 | + unstableOperations: { |
| 103 | + "APIManagementApi.v2.createOpenAPI": true |
| 104 | + } |
| 105 | +}); |
| 106 | +``` |
| 107 | + |
| 108 | +## Example migration |
| 109 | + |
| 110 | +Here's a complete example showing how to migrate a typical use case: |
| 111 | + |
| 112 | +```typescript |
| 113 | +// Old |
| 114 | +import { v1, client } from "@datadog/datadog-api-client"; |
| 115 | + |
| 116 | +const configuration = client.createConfiguration({ |
| 117 | + authMethods: { |
| 118 | + apiKeyAuth: "YOUR_API_KEY", |
| 119 | + appKeyAuth: "YOUR_APP_KEY" |
| 120 | + } |
| 121 | +}); |
| 122 | + |
| 123 | +const api = new v1.MonitorsApi(configuration); |
| 124 | +``` |
| 125 | + |
| 126 | +```typescript |
| 127 | +// New |
| 128 | +import { Configuration, createConfiguration } from "@datadog/datadog-api-client"; |
| 129 | +import { v1 } from "@datadog/datadog-api-client-monitors"; |
| 130 | + |
| 131 | +const configuration = createConfiguration({ |
| 132 | + authMethods: { |
| 133 | + apiKeyAuth: "YOUR_API_KEY", |
| 134 | + appKeyAuth: "YOUR_APP_KEY" |
| 135 | + } |
| 136 | +}); |
| 137 | + |
| 138 | +const api = new v1.MonitorsApi(configuration); |
| 139 | +``` |
| 140 | + |
| 141 | +## Available service packages |
| 142 | + |
| 143 | +See [#Clients] section in the following [README.md](./packages/datadog-api-client/README.md#clients) |
| 144 | + |
| 145 | +## Support |
| 146 | + |
| 147 | +If you encounter any issues during migration, please: |
| 148 | +1. Check the [API documentation](https://docs.datadoghq.com/api/) |
| 149 | +2. Open an issue in the [GitHub repository](https://github.com/DataDog/datadog-api-client-typescript) |
| 150 | +3. Contact [Datadog Support](https://www.datadoghq.com/support/) |
0 commit comments