@applica-software-guru/didonato-storage-client
v1.0.32
Published
Client per Didonato Storage (Node + Browser)
Downloads
421
Readme
@applica-software-guru/didonato-storage-client
Client TypeScript package for Didonato Storage.
Quick start
Install:
npm install @applica-software-guru/didonato-storage-clientUsage (ESM):
import DidonatoStorageClient from "@applica-software-guru/didonato-storage-client";
const c = new DidonatoStorageClient({ baseUrl: "https://example.com" });
console.log(await c.getSignedUrl("path/to/file"));Authentication
The client accepts an optional token option which can be provided in two ways:
- As a static token string:
new DidonatoStorageClient({ token: 'my-token' }). - As a function that returns a token (sync or async):
new DidonatoStorageClient({ token: () => fetchToken() }).
Examples
- Pass a static token:
import DidonatoStorageClient from "@applica-software-guru/didonato-storage-client";
const client = new DidonatoStorageClient({ baseUrl: "https://example.com", token: "MY_STATIC_TOKEN" });
// methods will include `Authorization: Bearer MY_STATIC_TOKEN` when calling the server- Pass a token factory (sync or async):
import DidonatoStorageClient from '@applica-software-guru/didonato-storage-client';
// sync factory
const clientSync = new DidonatoStorageClient({ baseUrl: 'https://example.com', token: () => 'token-from-fn' });
// async factory
const clientAsync = new DidonatoStorageClient({
baseUrl: 'https://example.com',
token: async () => {
// refresh or fetch token from secure storage
return await getFreshToken();
}
});
// The library will call your function before requests and attach
// `Authorization: Bearer <token>` header when present.
Notes
-----
- If you need to pass custom headers beyond Authorization, call the low-level endpoints
on your server or extend the client.
- The token option is optional; if omitted, requests are sent without an Authorization header.
