Setup
Install the library using npm or yarn:
npm install my-library --save
Then import it in your project:
import { MyComponent } from 'my-library';
```html
Install the library using npm or yarn:
npm install my-library --save
Then import it in your project:
import { MyComponent } from 'my-library';
All configurable settings are passed as an object to initialize():
MyComponent.initialize({
apiKey: 'YOUR_API_KEY',
timeout: 5000,
debug: false
});
apiKey (string, required) – Your authentication token.timeout (number, optional) – Request timeout in milliseconds. Default 3000.debug (boolean, optional) – Enable verbose logging. Default false.The library uses token‑based authentication. Retrieve a token via the /auth/token endpoint and store it securely.
fetch('/auth/token', {
method: 'POST',
body: JSON.stringify({username, password}),
headers: {'Content-Type': 'application/json'}
}).then(r=>r.json()).then(data=> {
MyComponent.setToken(data.token);
});
Operations may return the following error codes:
| Code | Description |
|---|---|
| 400 | Bad request – check your parameters. |
| 401 | Unauthorized – invalid or missing token. |
| 403 | Forbidden – insufficient permissions. |
| 404 | Not found – resource does not exist. |
| 500 | Server error – try again later. |
Common helper functions are available under MyComponent.utils:
formatDate(date, pattern) – Format a Date object.debounce(fn, wait) – Create a debounced version of a function.deepClone(obj) – Perform a deep copy of an object.