|
| 1 | +# @epcc-sdk/sdks-authentication-realms SDK |
| 2 | + |
| 3 | +Below you’ll find instructions on how to install, set up, and use the client, along with a list of available operations. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- type-safe response data and errors |
| 8 | +- response data validation and transformation |
| 9 | +- access to the original request and response |
| 10 | +- granular request and response customization options |
| 11 | +- minimal learning curve thanks to extending the underlying technology |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install @epcc-sdk/sdks-authentication-realms |
| 19 | +# or |
| 20 | +pnpm install @epcc-sdk/sdks-authentication-realms |
| 21 | +# or |
| 22 | +yarn add @epcc-sdk/sdks-authentication-realms |
| 23 | +``` |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Client Usage |
| 28 | + |
| 29 | + |
| 30 | +Clients are responsible for sending the actual HTTP requests. |
| 31 | + |
| 32 | +The Fetch client is built as a thin wrapper on top of Fetch API, extending its functionality. If you're already familiar with Fetch, configuring your client will feel like working directly with Fetch API. |
| 33 | + |
| 34 | +You can configure the client in two ways: |
| 35 | + |
| 36 | +- Configuring the internal `client` instance directly |
| 37 | +- Using the `createClient` function |
| 38 | + |
| 39 | +**When using the operation function to make requests, by default the global client will be used unless another is provided.** |
| 40 | + |
| 41 | + |
| 42 | +### 1. Configure the internal `client` instance directly |
| 43 | + |
| 44 | +This is the simpler approach. You can call the setConfig() method at the beginning of your application or anytime you need to update the client configuration. You can pass any Fetch API configuration option to setConfig(), and even your own Fetch implementation. |
| 45 | + |
| 46 | +```ts |
| 47 | +import { client } from "@epcc-sdk/sdks-authentication-realms"; |
| 48 | + |
| 49 | +client.setConfig({ |
| 50 | +// set default base url for requests |
| 51 | +baseUrl: 'https://euwest.api.elasticpath.com', |
| 52 | + |
| 53 | +// set default headers for requests |
| 54 | +headers: { |
| 55 | +Authorization: 'Bearer YOUR_AUTH_TOKEN', |
| 56 | +}, |
| 57 | +}); |
| 58 | +``` |
| 59 | + |
| 60 | +The disadvantage of this approach is that your code may call the client instance before it's configured for the first time. Depending on your use case, you might need to use the second approach. |
| 61 | + |
| 62 | +### 2. Using the `createClient` function |
| 63 | + |
| 64 | +This is useful when you want to use a different instance of the client for different parts of your application or when you want to use different configurations for different parts of your application. |
| 65 | + |
| 66 | +```ts |
| 67 | +import { createClient } from "@epcc-sdk/sdks-authentication-realms"; |
| 68 | + |
| 69 | +// Create the client with your API base URL. |
| 70 | +const client = createClient({ |
| 71 | + // set default base url for requests |
| 72 | + baseUrl: "https://euwest.api.elasticpath.com", |
| 73 | + /** |
| 74 | + * Set default headers only for requests made by this client. |
| 75 | + */ |
| 76 | + headers: { |
| 77 | + "Custom-Header": 'My Value', |
| 78 | + }, |
| 79 | +}); |
| 80 | +``` |
| 81 | + |
| 82 | +You can also pass this instance to any SDK function through the client option. This will override the default instance from `import { client } from "@epcc-sdk/sdks-authentication-realms>". |
| 83 | + |
| 84 | +```ts |
| 85 | +const response = await getPasswordProfileInfo({ |
| 86 | + client: myClient, |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +### Direct configuration |
| 91 | + |
| 92 | +Alternatively, you can pass the client configuration options to each SDK function. This is useful if you don't want to create a client instance for one-off use cases. |
| 93 | + |
| 94 | +```ts |
| 95 | +const response = await getPasswordProfileInfo({ |
| 96 | + baseUrl: 'https://example.com', // <-- override default configuration |
| 97 | +}); |
| 98 | +``` |
| 99 | + |
| 100 | +## Interceptors (Middleware) |
| 101 | + |
| 102 | +Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to your application. They can be added with use and removed with eject. Below is an example request interceptor |
| 103 | + |
| 104 | +```ts |
| 105 | +import { client } from "@epcc-sdk/sdks-authentication-realms"; |
| 106 | + |
| 107 | +// Supports async functions |
| 108 | +client.interceptors.request.use(async (request) => { |
| 109 | + // do something |
| 110 | + return request; |
| 111 | +}); |
| 112 | + |
| 113 | +client.interceptors.request.eject((request) => { |
| 114 | + // do something |
| 115 | + return request; |
| 116 | +}); |
| 117 | + |
| 118 | +``` |
| 119 | + |
| 120 | +and an example response interceptor |
| 121 | + |
| 122 | +```ts |
| 123 | +import { client } from "@epcc-sdk/sdks-authentication-realms"; |
| 124 | + |
| 125 | +client.interceptors.response.use((response) => { |
| 126 | + // do something |
| 127 | + return response; |
| 128 | +}); |
| 129 | + |
| 130 | +client.interceptors.response.eject((response) => { |
| 131 | + // do something |
| 132 | + return response; |
| 133 | +}); |
| 134 | +``` |
| 135 | + |
| 136 | +> **_Tip:_** To eject, you must provide a reference to the function that was passed to use(). |
| 137 | +
|
| 138 | +## Authentication |
| 139 | + |
| 140 | +We are working to provide helpers to handle auth easier for you but for now using an interceptor is the easiest method. |
| 141 | + |
| 142 | +```ts |
| 143 | +import { client } from "@epcc-sdk/sdks-authentication-realms"; |
| 144 | + |
| 145 | +client.interceptors.request.use((request, options) => { |
| 146 | + request.headers.set('Authorization', 'Bearer MY_TOKEN'); |
| 147 | + return request; |
| 148 | +}); |
| 149 | +``` |
| 150 | + |
| 151 | +## Build URL |
| 152 | + |
| 153 | +If you need to access the compiled URL, you can use the buildUrl() method. It's loosely typed by default to accept almost any value; in practice, you will want to pass a type hint. |
| 154 | + |
| 155 | +```ts |
| 156 | +type FooData = { |
| 157 | + path: { |
| 158 | + fooId: number; |
| 159 | + }; |
| 160 | + query?: { |
| 161 | + bar?: string; |
| 162 | + }; |
| 163 | + url: '/foo/{fooId}'; |
| 164 | +}; |
| 165 | + |
| 166 | +const url = client.buildUrl<FooData>({ |
| 167 | + path: { |
| 168 | + fooId: 1, |
| 169 | + }, |
| 170 | + query: { |
| 171 | + bar: 'baz', |
| 172 | + }, |
| 173 | + url: '/foo/{fooId}', |
| 174 | +}); |
| 175 | +console.log(url); // prints '/foo/1?bar=baz' |
| 176 | +``` |
| 177 | + |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +## Operation Usage |
| 186 | +The following examples demonstrate how to use the operation function to make requests. |
| 187 | + |
| 188 | +```ts |
| 189 | +import { getPasswordProfileInfo } from "@epcc-sdk/sdks-authentication-realms"; |
| 190 | + |
| 191 | +const product = await getPasswordProfileInfo({ |
| 192 | + // client: localClient, // optional if you have a client instance you want to use otherwise the global client will be used |
| 193 | + path: { |
| 194 | + ... |
| 195 | + }, |
| 196 | + query: { |
| 197 | + ... |
| 198 | + }, |
| 199 | +}); |
| 200 | +``` |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | +## Available Operations |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +- **`getAllAuthenticationRealms`** (`GET /v2/authentication-realms`) |
| 211 | + |
| 212 | +- **`getAuthenticationRealm`** (`GET /v2/authentication-realms/{realmId}`) |
| 213 | + |
| 214 | +- **`updateAuthenticationRealm`** (`PUT /v2/authentication-realms/{realmId}`) |
| 215 | + |
| 216 | +- **`getAllOidcProfiles`** (`GET /v2/authentication-realms/{realmId}/openid-connect-profiles`) |
| 217 | + |
| 218 | +- **`createOidcProfile`** (`POST /v2/authentication-realms/{realmId}/openid-connect-profiles`) |
| 219 | + |
| 220 | +- **`deleteOidcProfile`** (`DELETE /v2/authentication-realms/{realmId}/openid-connect-profiles/{oidcProfileId}`) |
| 221 | + |
| 222 | +- **`getOidcProfile`** (`GET /v2/authentication-realms/{realmId}/openid-connect-profiles/{oidcProfileId}`) |
| 223 | + |
| 224 | +- **`updateOidcProfile`** (`PUT /v2/authentication-realms/{realmId}/openid-connect-profiles/{oidcProfileId}`) |
| 225 | + |
| 226 | +- **`getAllPasswordProfiles`** (`GET /v2/authentication-realms/{realmId}/password-profiles`) |
| 227 | + |
| 228 | +- **`createPasswordProfile`** (`POST /v2/authentication-realms/{realmId}/password-profiles`) |
| 229 | + |
| 230 | +- **`deletePasswordProfile`** (`DELETE /v2/authentication-realms/{realmId}/password-profiles/{passwordProfileId}`) |
| 231 | + |
| 232 | +- **`getPasswordProfile`** (`GET /v2/authentication-realms/{realmId}/password-profiles/{passwordProfileId}`) |
| 233 | + |
| 234 | +- **`updatePasswordProfile`** (`PUT /v2/authentication-realms/{realmId}/password-profiles/{passwordProfileId}`) |
| 235 | + |
| 236 | +- **`createOneTimePasswordTokenRequest`** (`POST /v2/authentication-realms/{realmId}/password-profiles/one-time-password-token-request`) |
| 237 | + |
| 238 | +- **`getAllUserAuthenticationInfo`** (`GET /v2/authentication-realms/{realmId}/user-authentication-info`) |
| 239 | + |
| 240 | +- **`createUserAuthenticationInfo`** (`POST /v2/authentication-realms/{realmId}/user-authentication-info`) |
| 241 | + |
| 242 | +- **`deleteUserAuthenticationInfo`** (`DELETE /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}`) |
| 243 | + |
| 244 | +- **`getUserAuthenticationInfo`** (`GET /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}`) |
| 245 | + |
| 246 | +- **`updateUserAuthenticationInfo`** (`PUT /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}`) |
| 247 | + |
| 248 | +- **`getAllUserAuthenticationOidcProfileInfo`** (`GET /v2/authentication-realms/{realmId}/user-authentication-openid-connect-profile-info`) |
| 249 | + |
| 250 | +- **`createUserAuthenticationOidcProfileInfo`** (`POST /v2/authentication-realms/{realmId}/user-authentication-openid-connect-profile-info`) |
| 251 | + |
| 252 | +- **`deleteUserAuthenticationOidcProfileInfo`** (`DELETE /v2/authentication-realms/{realmId}/user-authentication-openid-connect-profile-info/{userAuthenticationOidcProfileInfoId}`) |
| 253 | + |
| 254 | +- **`getUserAuthenticationOidcProfileInfo`** (`GET /v2/authentication-realms/{realmId}/user-authentication-openid-connect-profile-info/{userAuthenticationOidcProfileInfoId}`) |
| 255 | + |
| 256 | +- **`updateUserAuthenticationOidcProfileInfo`** (`PUT /v2/authentication-realms/{realmId}/user-authentication-openid-connect-profile-info/{userAuthenticationOidcProfileInfoId}`) |
| 257 | + |
| 258 | +- **`listPasswordProfileInfos`** (`GET /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}/user-authentication-password-profile-info`) |
| 259 | + |
| 260 | +- **`createPasswordProfileInfo`** (`POST /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}/user-authentication-password-profile-info`) |
| 261 | + |
| 262 | +- **`deletePasswordProfileInfo`** (`DELETE /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}/user-authentication-password-profile-info/{userAuthenticationPasswordProfileInfoId}`) |
| 263 | + |
| 264 | +- **`getPasswordProfileInfo`** (`GET /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}/user-authentication-password-profile-info/{userAuthenticationPasswordProfileInfoId}`) |
| 265 | + |
| 266 | +- **`updatePasswordProfileInfo`** (`PUT /v2/authentication-realms/{realmId}/user-authentication-info/{userAuthenticationInfoId}/user-authentication-password-profile-info/{userAuthenticationPasswordProfileInfoId}`) |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | +--- |
0 commit comments