Composition API Component: Check the console for API output.
```
---
## TypeScript Augmentation (Optional)
To get TypeScript IntelliSense for `this.$myApi`, you can manually augment the `vue` module. You can create a declaration file (e.g., `my-api.d.ts`) in the API Folder:
```ts
import type MyApi from "@shell/plugins/internal-api/my-api.api";
export {};
declare module "vue" {
interface ComponentCustomProperties {
$myApi: MyApi;
}
}
```
Now, TypeScript will recognize `this.$myApi` in your Vue components.
---
## File Structure Example
Below is an example file structure showing multiple APIs in subdirectories:
```
shell/plugins/internal-api/
├── my-api.api.ts
├── cluster/
│ ├── cluster-tools.api.ts
│ └── some-helper.ts <-- not injected
└── rancher/
└── rancher.api.ts
```
Each `.api.ts` file is automatically discovered and instantiated. Helpers or partial modules that do not follow the `.api.ts` naming scheme (like `some-helper.ts`) won’t be injected.
---
## How It Works
- **`install-plugins.js`** includes `internalApiPlugin` in `installInjectedPlugins()`.
- **`internalApiPlugin`** uses `require.context` to scan subdirectories under `shell/plugins/internal-api/`.
- For each file matching `*.api.ts`, it:
1. Imports the file.
2. Reads the default export (your class).
3. Checks for a static `apiName` method; if not found, it falls back to the file name (An error will be thrown if extending the `BaseApi` class).
4. Instantiates the class, passing in the Vuex store.
5. Calls `inject(key, instance)`, which attaches your API to `Vue.prototype.$key`.
---
## Conclusion
With this setup:
1. **Create** a `.api.ts` class in `shell/plugins/internal-api/`.
2. **Define** `static apiName() { return 'something'; }`.
3. **Use** it in Vue components via `this.$something`.
Everything else—from discovery to injection—happens automatically. This approach keeps your code organized, fosters easy extension, and saves you from having to manually edit the main injection logic each time you add a new API.