|
| 1 | +# URL Shortener - TypeScript SDK |
| 2 | + |
| 3 | +This SDK provides a convenient TypeScript client for interacting with the SHI URL Shortener service. It is automatically generated from the OpenAPI specification located at [`Url-Shortener.json`](https://github.com/Software-Hardware-Integration-Lab/OpenAPI/blob/main/specs/Url-Shortener.json) using [Kiota](https://github.com/microsoft/kiota). |
| 4 | + |
| 5 | +All typing data is included in the package. |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +Install the SDK using npm: |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install @shi-corp/sdk-url-shortener |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Here's a basic example of how to use the SDK: |
| 18 | + |
| 19 | +```TypeScript |
| 20 | +import { DefaultAzureCredential } from '@azure/identity' |
| 21 | +import { urlShortenerClientFactory } from '@shi-corp/sdk-url-shortener'; |
| 22 | + |
| 23 | +/** Authentication session used to authenticate to URL Shortener. */ |
| 24 | +const credential = new DefaultAzureCredential(); |
| 25 | + |
| 26 | +/** Base URL for your URL Shortener instance. Protocol specifier (`http`/`https`) is required, even for localhost. */ |
| 27 | +const baseUrl = new URL('https://url-shortener.example.com'); |
| 28 | + |
| 29 | +/** |
| 30 | + * Configured client for URL Shortener that can make authenticated web requests against backend. |
| 31 | + * |
| 32 | + * The third param, the scope is the `Application ID` of the `End User Login` app registration. |
| 33 | + */ |
| 34 | +const urlShortenerClient = urlShortenerClientFactory(credential, baseUrl, ['b9689d4e-0036-4f2f-8430-07adedb9ae7c/.default']); |
| 35 | + |
| 36 | +/** List of available redirect entries. */ |
| 37 | +const results = await urlShortenerClient.api.redirect.get(); |
| 38 | + |
| 39 | +// Check if list is not empty |
| 40 | +if (results?.length > 0) { |
| 41 | + // Do something |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### Advanced Usage |
| 46 | + |
| 47 | +You can optionally configure the SDK client with a custom base URL, including support for it being nested deep in a L7 load balancer: |
| 48 | + |
| 49 | +```TypeScript |
| 50 | +/** Custom host and endpoint base to as an example for something behind a layer 7 load balancer, E.g. Azure App Gateway or Azure API Gateway. If in debug mode, run against localhost. */ |
| 51 | +const customBaseUrl = debugMode ? new URL('http://localhost:3004') : new URL('https://custom-host.example.com/Ballance/Instance1/'); |
| 52 | + |
| 53 | +/** Configured instance of the URL Shortener client. */ |
| 54 | +const customConfiguredClient = urlShortenerClientFactory(credential, customBaseUrl); |
| 55 | +``` |
| 56 | + |
| 57 | +and/or scope (permission) list: |
| 58 | + |
| 59 | +```TypeScript |
| 60 | +/** |
| 61 | + * `.default` and explicit permissions can't exist in the same custom scope list at the same time, Entra ID doesn't support this. |
| 62 | + * |
| 63 | + * If not providing the `.default` scope, you can have any number of scopes (permissions) listed in different array indexes. |
| 64 | + */ |
| 65 | +const customScopes = ['your-custom-scope/something.read.all', 'your-custom-scope/everything.readwrite.all']; |
| 66 | + |
| 67 | +// Initialize the SDK client with custom configuration. |
| 68 | +const customConfiguredClient = urlShortenerClientFactory(credential, void 0, customScopes); |
| 69 | +``` |
| 70 | + |
| 71 | +## Project Structure |
| 72 | + |
| 73 | +- `bin/`: Compiled JavaScript files and type definitions. |
| 74 | +- `sdk/`: Source TypeScript files generated by Kiota. |
| 75 | + - `api/`: API endpoint definitions. |
| 76 | + - `models/`: Data models used by the SDK. |
| 77 | + |
| 78 | +## Development |
| 79 | + |
| 80 | +### Prerequisites |
| 81 | + |
| 82 | +- [Node.js](https://nodejs.org/) - Latest LTS version |
| 83 | +- [Kiota](https://github.com/microsoft/kiota) |
| 84 | + |
| 85 | +### Generating the SDK |
| 86 | + |
| 87 | +To regenerate the SDK from the OpenAPI specification, run: |
| 88 | + |
| 89 | +```bash |
| 90 | +npm run-script generate:Sdk |
| 91 | +``` |
| 92 | + |
| 93 | +### Building the SDK |
| 94 | + |
| 95 | +To build the SDK for production, run: |
| 96 | + |
| 97 | +```bash |
| 98 | +npm run-script build:Prod |
| 99 | +``` |
| 100 | + |
| 101 | +## License |
| 102 | + |
| 103 | +This SDK is licensed under the [MIT License](./LICENSE). |
| 104 | + |
| 105 | +## Support |
| 106 | + |
| 107 | +For issues or feature requests, please visit the [GitHub Issues page](https://github.com/Software-Hardware-Integration-Lab/OpenAPI/issues). |
| 108 | + |
| 109 | +For more information, visit the [official documentation](https://docs.shilab.com). |
0 commit comments