Skip to content

Commit df2416f

Browse files
Merge pull request #19 from Software-Hardware-Integration-Lab/pasha-sus-spec
[Feature] Adding URL Shortener application
2 parents b4ceea0 + fcfd0be commit df2416f

File tree

10 files changed

+2972
-1
lines changed

10 files changed

+2972
-1
lines changed

.github/workflows/DeploySpecDocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: |
5050
DIST_FILE="swagger-ui/dist/swagger-initializer.js"
5151
# Remove the 'url:' property and insert the 'urls:' array
52-
sed -i '/url: /c\ urls: [\n {\n "url": "https://raw.githubusercontent.com/Software-Hardware-Integration-Lab/OpenAPI/refs/heads/main/specs/Data-Gateway.json",\n "name": "Data Gateway"\n },\n {\n "url": "https://raw.githubusercontent.com/Software-Hardware-Integration-Lab/OpenAPI/refs/heads/main/specs/SHIELD.json",\n "name": "SHIELD"\n }\n ],' "$DIST_FILE"
52+
sed -i '/url: /c\ urls: [\n{\n"url": "https://raw.githubusercontent.com/Software-Hardware-Integration-Lab/OpenAPI/refs/heads/main/specs/Data-Gateway.json",\n"name": "Data Gateway"\n},\n{\n"url": "https://raw.githubusercontent.com/Software-Hardware-Integration-Lab/OpenAPI/refs/heads/main/specs/SHIELD.json",\n"name": "SHIELD"\n}\n{\n"url": "https://raw.githubusercontent.com/Software-Hardware-Integration-Lab/OpenAPI/refs/heads/main/specs/Url-Shortener.json",\n"name": "Data Gateway"\n}\n],' "$DIST_FILE"
5353
5454
# Uploads the built artifact to github pages
5555
- name: Upload Artifact

OpenAPI.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"name": "SHIELD",
1313
"path": "src/shield"
1414
},
15+
{
16+
"name": "URL Shortener",
17+
"path": "src/urlShortener"
18+
},
1519
{
1620
"name": "GitHub Actions",
1721
"path": ".github/workflows"

specs/Url-Shortener.json

Lines changed: 1519 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ignore TypeScript source files while allowing library type descriptions
2+
*.ts
3+
!*.d.ts
4+
5+
# Ignore the TypeScript config
6+
tsconfig.json
7+
8+
# Ignore the generated SDK source code
9+
/sdk/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 SHI International Corp.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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).
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { assert, assertGuardEquals } from 'typia';
2+
import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure";
3+
import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
4+
import type { TokenCredential } from "@azure/core-auth";
5+
import { createUrlShortenerClient } from "./sdk/urlShortenerClient.js";
6+
7+
// Export all of the SDK's types
8+
export type * from './sdk/models/index.js';
9+
10+
/**
11+
* Function that initializes the URL Shortener SDK.
12+
* @param credential Configured authentication session from Entra ID.
13+
* @param baseUrl Root of the URL that should have endpoints appended to it by the query building system.
14+
* @param scopeList Where each array item is a different Entra ID standard scope to request on token retrieval. E.g. `['313f3894-325a-4aae-ba2b-bbdfdc1f063b/.default']`
15+
* @returns Configured API client that is able to make requests against the specified URL Shortener instance.
16+
*/
17+
export function urlShortenerClientFactory(credential: TokenCredential, baseUrl: URL, scopeList: string[]) {
18+
// #region Input Validation
19+
assert(credential);
20+
21+
assertGuardEquals(baseUrl);
22+
23+
assertGuardEquals(scopeList);
24+
// #endregion Input Validation
25+
26+
/** List of hosts that are allowed when making API calls, this is used to prevent token leaks to threat actors. */
27+
const allowedHostList = new Set([baseUrl.host]);
28+
29+
/** Authentication system that will be used to configure the SDK client. */
30+
const authProvider = new AzureIdentityAuthenticationProvider(credential, scopeList, void 0, allowedHostList);
31+
32+
/** Instance of the URL Shortener SDK client initialization configuration. */
33+
const urlShortenerAdapter = new FetchRequestAdapter(authProvider);
34+
35+
// Set the base URL to be what is provided, since the host name is unique every deployment
36+
urlShortenerAdapter.baseUrl = baseUrl.href.endsWith('/') ? baseUrl.href.substring(0, baseUrl.href.length - 1) : baseUrl.href;
37+
38+
/** Instance of the API client that can be used for URL Shortener access. */
39+
return createUrlShortenerClient(urlShortenerAdapter);
40+
}

0 commit comments

Comments
 (0)