@nhost/nhost-js 3.2.7 → 5.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +67 -37
- package/dist/nhost-js/auth.cjs.js +2 -0
- package/dist/nhost-js/auth.cjs.js.map +1 -0
- package/dist/nhost-js/auth.es.js +261 -0
- package/dist/nhost-js/auth.es.js.map +1 -0
- package/dist/nhost-js/fetch.cjs.js +2 -0
- package/dist/nhost-js/fetch.cjs.js.map +1 -0
- package/dist/nhost-js/fetch.es.js +10 -0
- package/dist/nhost-js/fetch.es.js.map +1 -0
- package/dist/nhost-js/graphql.cjs.js +2 -0
- package/dist/nhost-js/graphql.cjs.js.map +1 -0
- package/dist/nhost-js/graphql.es.js +35 -0
- package/dist/nhost-js/graphql.es.js.map +1 -0
- package/dist/nhost-js/storage.cjs.js +2 -0
- package/dist/nhost-js/storage.cjs.js.map +1 -0
- package/dist/nhost-js/storage.es.js +205 -0
- package/dist/nhost-js/storage.es.js.map +1 -0
- package/dist/nhost-js.cjs.js +2 -0
- package/dist/nhost-js.cjs.js.map +1 -0
- package/dist/nhost-js.es.js +476 -0
- package/dist/nhost-js.es.js.map +1 -0
- package/dist/nhost-js.umd.js +2 -0
- package/dist/nhost-js.umd.js.map +1 -0
- package/dist/src/auth/client.d.ts +415 -0
- package/dist/src/auth/client.d.ts.map +1 -0
- package/dist/src/auth/client.js +330 -0
- package/dist/src/auth/client.js.map +1 -0
- package/dist/src/auth/index.d.ts +11 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/index.js +11 -0
- package/dist/src/auth/index.js.map +1 -0
- package/dist/src/auth/interface.d.ts +72 -0
- package/dist/src/auth/interface.d.ts.map +1 -0
- package/dist/src/auth/interface.js +2 -0
- package/dist/src/auth/interface.js.map +1 -0
- package/dist/src/fetch/index.d.ts +53 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/index.js +40 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/graphql/client.d.ts +89 -0
- package/dist/src/graphql/client.d.ts.map +1 -0
- package/dist/src/graphql/client.js +49 -0
- package/dist/src/graphql/client.js.map +1 -0
- package/dist/src/graphql/index.d.ts +10 -0
- package/dist/src/graphql/index.d.ts.map +1 -0
- package/dist/src/graphql/index.js +10 -0
- package/dist/src/graphql/index.js.map +1 -0
- package/dist/src/index.d.ts +169 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +237 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/middlewareAttachToken.d.ts +24 -0
- package/dist/src/middlewareAttachToken.d.ts.map +1 -0
- package/dist/src/middlewareAttachToken.js +60 -0
- package/dist/src/middlewareAttachToken.js.map +1 -0
- package/dist/src/middlewareRefreshSession.d.ts +43 -0
- package/dist/src/middlewareRefreshSession.d.ts.map +1 -0
- package/dist/src/middlewareRefreshSession.js +190 -0
- package/dist/src/middlewareRefreshSession.js.map +1 -0
- package/dist/src/middlewareResponseSession.d.ts +26 -0
- package/dist/src/middlewareResponseSession.d.ts.map +1 -0
- package/dist/src/middlewareResponseSession.js +83 -0
- package/dist/src/middlewareResponseSession.js.map +1 -0
- package/dist/src/sessionStorage.d.ts +123 -0
- package/dist/src/sessionStorage.d.ts.map +1 -0
- package/dist/src/sessionStorage.js +165 -0
- package/dist/src/sessionStorage.js.map +1 -0
- package/dist/src/storage/client.d.ts +184 -0
- package/dist/src/storage/client.d.ts.map +1 -0
- package/dist/src/storage/client.js +249 -0
- package/dist/src/storage/client.js.map +1 -0
- package/dist/src/storage/index.d.ts +11 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +11 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/interface.d.ts +52 -0
- package/dist/src/storage/interface.d.ts.map +1 -0
- package/dist/src/storage/interface.js +2 -0
- package/dist/src/storage/interface.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +94 -60
- package/dist/clients/auth.d.ts +0 -8
- package/dist/clients/auth.d.ts.map +0 -1
- package/dist/clients/functions/index.d.ts +0 -107
- package/dist/clients/functions/index.d.ts.map +0 -1
- package/dist/clients/functions/types.d.ts +0 -28
- package/dist/clients/functions/types.d.ts.map +0 -1
- package/dist/clients/graphql.d.ts +0 -8
- package/dist/clients/graphql.d.ts.map +0 -1
- package/dist/clients/index.d.ts +0 -6
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/nhost.d.ts +0 -83
- package/dist/clients/nhost.d.ts.map +0 -1
- package/dist/clients/storage.d.ts +0 -8
- package/dist/clients/storage.d.ts.map +0 -1
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -344
- package/dist/index.esm.js.map +0 -1
- package/dist/utils/helpers.d.ts +0 -20
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/types.d.ts +0 -57
- package/dist/utils/types.d.ts.map +0 -1
- package/umd/nhost-js.umd.js +0 -22
- package/umd/nhost-js.umd.js.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Storage implementations for session persistence in different environments.
|
|
3
|
+
*
|
|
4
|
+
* This module provides different storage adapters for persisting authentication sessions
|
|
5
|
+
* across page reloads and browser sessions.
|
|
6
|
+
*/
|
|
7
|
+
import {} from "./auth";
|
|
8
|
+
/**
|
|
9
|
+
* Default storage key used for storing the Nhost session
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_SESSION_KEY = "nhostSession";
|
|
12
|
+
/**
|
|
13
|
+
* Browser localStorage implementation of StorageInterface.
|
|
14
|
+
* Persists the session across page reloads and browser restarts.
|
|
15
|
+
*/
|
|
16
|
+
export class LocalStorage {
|
|
17
|
+
storageKey;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new LocalStorage instance
|
|
20
|
+
* @param storageKey - The key to use in localStorage (defaults to "nhostSession")
|
|
21
|
+
*/
|
|
22
|
+
constructor(storageKey = DEFAULT_SESSION_KEY) {
|
|
23
|
+
this.storageKey = storageKey;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Gets the session from localStorage
|
|
27
|
+
* @returns The stored session or null if not found
|
|
28
|
+
*/
|
|
29
|
+
get() {
|
|
30
|
+
try {
|
|
31
|
+
const value = window.localStorage.getItem(this.storageKey);
|
|
32
|
+
return value ? JSON.parse(value) : null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
this.remove();
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the session in localStorage
|
|
41
|
+
* @param value - The session to store
|
|
42
|
+
*/
|
|
43
|
+
set(value) {
|
|
44
|
+
window.localStorage.setItem(this.storageKey, JSON.stringify(value));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Removes the session from localStorage
|
|
48
|
+
*/
|
|
49
|
+
remove() {
|
|
50
|
+
window.localStorage.removeItem(this.storageKey);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* In-memory storage implementation for non-browser environments or when
|
|
55
|
+
* persistent storage is not available or desirable.
|
|
56
|
+
*/
|
|
57
|
+
export class MemoryStorage {
|
|
58
|
+
session = null;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the session from memory
|
|
61
|
+
* @returns The stored session or null if not set
|
|
62
|
+
*/
|
|
63
|
+
get() {
|
|
64
|
+
return this.session;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets the session in memory
|
|
68
|
+
* @param value - The session to store
|
|
69
|
+
*/
|
|
70
|
+
set(value) {
|
|
71
|
+
this.session = value;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Clears the session from memory
|
|
75
|
+
*/
|
|
76
|
+
remove() {
|
|
77
|
+
this.session = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Cookie-based storage implementation.
|
|
82
|
+
* This storage uses web browser cookies to store the session so it's not
|
|
83
|
+
* available in server-side environments. It is useful though for sinchronizing
|
|
84
|
+
* sessions between client and server environments.
|
|
85
|
+
*/
|
|
86
|
+
export class CookieStorage {
|
|
87
|
+
cookieName;
|
|
88
|
+
expirationDays;
|
|
89
|
+
secure;
|
|
90
|
+
sameSite;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new CookieStorage instance
|
|
93
|
+
* @param cookieName - Name of the cookie to use (defaults to "nhostSession")
|
|
94
|
+
* @param expirationDays - Number of days until the cookie expires (defaults to 30)
|
|
95
|
+
* @param secure - Whether to set the Secure flag on the cookie (defaults to true)
|
|
96
|
+
* @param sameSite - SameSite policy for the cookie (defaults to "lax")
|
|
97
|
+
*/
|
|
98
|
+
constructor(cookieName = DEFAULT_SESSION_KEY, expirationDays = 30, secure = true, sameSite = "lax") {
|
|
99
|
+
this.cookieName = cookieName;
|
|
100
|
+
this.expirationDays = expirationDays;
|
|
101
|
+
this.secure = secure;
|
|
102
|
+
this.sameSite = sameSite;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets the session from cookies
|
|
106
|
+
* @returns The stored session or null if not found
|
|
107
|
+
*/
|
|
108
|
+
get() {
|
|
109
|
+
const cookies = document.cookie.split(";");
|
|
110
|
+
for (const cookie of cookies) {
|
|
111
|
+
const [name, value] = cookie.trim().split("=");
|
|
112
|
+
if (name === this.cookieName) {
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(decodeURIComponent(value || ""));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
this.remove();
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sets the session in a cookie
|
|
126
|
+
* @param value - The session to store
|
|
127
|
+
*/
|
|
128
|
+
set(value) {
|
|
129
|
+
const expires = new Date();
|
|
130
|
+
expires.setTime(expires.getTime() + this.expirationDays * 24 * 60 * 60 * 1000);
|
|
131
|
+
const cookieValue = encodeURIComponent(JSON.stringify(value));
|
|
132
|
+
const cookieString = `${this.cookieName}=${cookieValue}; expires=${expires.toUTCString()}; path=/; ${this.secure ? "secure; " : ""}SameSite=${this.sameSite}`;
|
|
133
|
+
document.cookie = cookieString;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Removes the session cookie
|
|
137
|
+
*/
|
|
138
|
+
remove() {
|
|
139
|
+
document.cookie = `${this.cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; ${this.secure ? "secure; " : ""}SameSite=${this.sameSite}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Detects the best available storage implementation for the current environment.
|
|
144
|
+
*
|
|
145
|
+
* The detection process follows this order:
|
|
146
|
+
* 1. Try to use localStorage if we're in a browser environment
|
|
147
|
+
* 2. Fall back to in-memory storage if localStorage isn't available
|
|
148
|
+
*
|
|
149
|
+
* @returns The best available storage implementation for the current environment
|
|
150
|
+
*/
|
|
151
|
+
export const detectStorage = () => {
|
|
152
|
+
if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
|
|
153
|
+
try {
|
|
154
|
+
// Test if localStorage is actually available (could be disabled)
|
|
155
|
+
localStorage.setItem("__test", "__test");
|
|
156
|
+
localStorage.removeItem("__test");
|
|
157
|
+
return new LocalStorage();
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
console.warn(`localStorage is not available, using in-memory storage instead`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return new MemoryStorage();
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=sessionStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionStorage.js","sourceRoot":"","sources":["../../src/sessionStorage.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GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,MAAM,YAAY,GAAG,GAAG,IAAI,CAAC,UAAU,IAAI,WAAW,aAAa,OAAO,CAAC,WAAW,EAAE,aAAa,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,QAAQ,EAAE,CAAC;QAE9J,QAAQ,CAAC,MAAM,GAAG,YAAY,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,qDAAqD,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpJ,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAA4B,EAAE;IACzD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;QACzE,IAAI,CAAC;YACH,iEAAiE;YACjE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACzC,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,IAAI,YAAY,EAAE,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,IAAI,CACV,gEAAgE,CACjE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import type { ChainFunction } from "../fetch";
|
|
2
|
+
import type { Client } from "./interface";
|
|
3
|
+
/**
|
|
4
|
+
* Contains version information about the storage service.
|
|
5
|
+
*/
|
|
6
|
+
export interface VersionInformation {
|
|
7
|
+
/** The version number of the storage service build. */
|
|
8
|
+
buildVersion?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Basic information about a file in storage.
|
|
12
|
+
*/
|
|
13
|
+
export interface FileSummary {
|
|
14
|
+
/** Unique identifier for the file. */
|
|
15
|
+
id?: string;
|
|
16
|
+
/** Name of the file including extension. */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** ID of the bucket containing the file. */
|
|
19
|
+
bucketId?: string;
|
|
20
|
+
/** Whether the file has been successfully uploaded. */
|
|
21
|
+
isUploaded?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Custom metadata associated with the file.
|
|
25
|
+
*/
|
|
26
|
+
export type FileMetadataMetadata = {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Comprehensive metadata information about a file in storage.
|
|
31
|
+
*/
|
|
32
|
+
export interface FileMetadata {
|
|
33
|
+
/** Unique identifier for the file. */
|
|
34
|
+
id?: string;
|
|
35
|
+
/** Name of the file including extension. */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** Size of the file in bytes. */
|
|
38
|
+
size?: number;
|
|
39
|
+
/** ID of the bucket containing the file. */
|
|
40
|
+
bucketId?: string;
|
|
41
|
+
/** Entity tag for cache validation. */
|
|
42
|
+
etag?: string;
|
|
43
|
+
/** Timestamp when the file was created. */
|
|
44
|
+
createdAt?: string;
|
|
45
|
+
/** Timestamp when the file was last updated. */
|
|
46
|
+
updatedAt?: string;
|
|
47
|
+
/** Whether the file has been successfully uploaded. */
|
|
48
|
+
isUploaded?: boolean;
|
|
49
|
+
/** MIME type of the file. */
|
|
50
|
+
mimeType?: string;
|
|
51
|
+
/** ID of the user who uploaded the file. */
|
|
52
|
+
uploadedByUserId?: string;
|
|
53
|
+
/** Custom metadata associated with the file. */
|
|
54
|
+
metadata?: FileMetadataMetadata;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Custom metadata to associate with the file.
|
|
58
|
+
*/
|
|
59
|
+
export type UploadFileMetadataMetadata = {
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Metadata provided when uploading a new file.
|
|
64
|
+
*/
|
|
65
|
+
export interface UploadFileMetadata {
|
|
66
|
+
/** Optional custom ID for the file. If not provided, a UUID will be generated. */
|
|
67
|
+
id?: string;
|
|
68
|
+
/** Name to assign to the file. If not provided, the original filename will be used. */
|
|
69
|
+
name?: string;
|
|
70
|
+
/** Custom metadata to associate with the file. */
|
|
71
|
+
metadata?: UploadFileMetadataMetadata;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Updated custom metadata to associate with the file.
|
|
75
|
+
*/
|
|
76
|
+
export type UpdateFileMetadataMetadata = {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Metadata that can be updated for an existing file.
|
|
81
|
+
*/
|
|
82
|
+
export interface UpdateFileMetadata {
|
|
83
|
+
/** New name to assign to the file. */
|
|
84
|
+
name?: string;
|
|
85
|
+
/** Updated custom metadata to associate with the file. */
|
|
86
|
+
metadata?: UpdateFileMetadataMetadata;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Contains a presigned URL for direct file operations.
|
|
90
|
+
*/
|
|
91
|
+
export interface PresignedURLResponse {
|
|
92
|
+
/** The presigned URL for file operations. */
|
|
93
|
+
url?: string;
|
|
94
|
+
/** The time in seconds until the URL expires. */
|
|
95
|
+
expiration?: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Error details.
|
|
99
|
+
*/
|
|
100
|
+
export type ErrorError = {
|
|
101
|
+
/** Human-readable error message. */
|
|
102
|
+
message: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Error information returned by the API.
|
|
106
|
+
*/
|
|
107
|
+
export interface Error {
|
|
108
|
+
/** Error details. */
|
|
109
|
+
error?: ErrorError;
|
|
110
|
+
}
|
|
111
|
+
export type GetOpenAPISpec200 = {
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
};
|
|
114
|
+
export type UploadFilesBody = {
|
|
115
|
+
/** Target bucket identifier where files will be stored. */
|
|
116
|
+
"bucket-id"?: string;
|
|
117
|
+
/** Optional custom metadata for each uploaded file. Must match the order of the file[] array. */
|
|
118
|
+
"metadata[]"?: UploadFileMetadata[];
|
|
119
|
+
/** Array of files to upload. */
|
|
120
|
+
"file[]"?: Blob[];
|
|
121
|
+
};
|
|
122
|
+
export type UploadFiles201 = {
|
|
123
|
+
/** List of successfully processed files with their metadata. */
|
|
124
|
+
processedFiles?: FileMetadata[];
|
|
125
|
+
};
|
|
126
|
+
export type GetFileMetadataHeadersParams = {
|
|
127
|
+
/**
|
|
128
|
+
* Image quality (1-100). Only applies to JPEG, WebP and PNG files
|
|
129
|
+
*/
|
|
130
|
+
q?: number;
|
|
131
|
+
/**
|
|
132
|
+
* Maximum height to resize image to while maintaining aspect ratio. Only applies to image files
|
|
133
|
+
*/
|
|
134
|
+
h?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Maximum width to resize image to while maintaining aspect ratio. Only applies to image files
|
|
137
|
+
*/
|
|
138
|
+
w?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Blur the image using this sigma value. Only applies to image files
|
|
141
|
+
*/
|
|
142
|
+
b?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Output format for image files. Use 'auto' for content negotiation based on Accept header
|
|
145
|
+
*/
|
|
146
|
+
f?: GetFileMetadataHeadersF;
|
|
147
|
+
};
|
|
148
|
+
export type GetFileMetadataHeadersF = "auto" | "same" | "jpeg" | "webp" | "png" | "avif";
|
|
149
|
+
export type GetFileParams = {
|
|
150
|
+
/**
|
|
151
|
+
* Image quality (1-100). Only applies to JPEG, WebP and PNG files
|
|
152
|
+
*/
|
|
153
|
+
q?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Maximum height to resize image to while maintaining aspect ratio. Only applies to image files
|
|
156
|
+
*/
|
|
157
|
+
h?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum width to resize image to while maintaining aspect ratio. Only applies to image files
|
|
160
|
+
*/
|
|
161
|
+
w?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Blur the image using this sigma value. Only applies to image files
|
|
164
|
+
*/
|
|
165
|
+
b?: number;
|
|
166
|
+
/**
|
|
167
|
+
* Output format for image files. Use 'auto' for content negotiation based on Accept header
|
|
168
|
+
*/
|
|
169
|
+
f?: GetFileF;
|
|
170
|
+
};
|
|
171
|
+
export type GetFileF = "auto" | "same" | "jpeg" | "webp" | "png" | "avif";
|
|
172
|
+
export type ReplaceFileBody = {
|
|
173
|
+
/** Optional metadata to update for the file */
|
|
174
|
+
metadata?: UpdateFileMetadata;
|
|
175
|
+
/** New file content to replace the existing file */
|
|
176
|
+
file?: Blob;
|
|
177
|
+
};
|
|
178
|
+
export type FetchResponse<T> = {
|
|
179
|
+
body: T;
|
|
180
|
+
status: number;
|
|
181
|
+
headers: Record<string, string>;
|
|
182
|
+
};
|
|
183
|
+
export declare const createAPIClient: (baseURL: string, chainFunctions?: ChainFunction[]) => Client;
|
|
184
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/storage/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sCAAsC;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IA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M,aAAa,GAAG;IAC1B;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,CAAC,CAAC,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,CAAC,CAAC,EAAE,QAAQ,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,oDAAoD;IACpD,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,SAAS,MAAM,EACf,iBAAgB,aAAa,EAAO,KACnC,MAsUF,CAAC"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by orval v7.9.0 🍺
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Nhost Storage API
|
|
5
|
+
* Nhost Storage API - A service for managing and serving files with powerful access control capabilities
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
import { createEnhancedFetch } from "../fetch";
|
|
9
|
+
export const createAPIClient = (baseURL, chainFunctions = []) => {
|
|
10
|
+
let fetch = createEnhancedFetch(chainFunctions);
|
|
11
|
+
const pushChainFunction = (chainFunction) => {
|
|
12
|
+
chainFunctions.push(chainFunction);
|
|
13
|
+
fetch = createEnhancedFetch(chainFunctions);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns the OpenAPI schema definition for this API, allowing clients to understand the available endpoints and models.
|
|
17
|
+
* @summary Get OpenAPI specification
|
|
18
|
+
*/
|
|
19
|
+
const getOpenAPISpec = async (options) => {
|
|
20
|
+
const res = await fetch(getGetOpenAPISpecUrl(), {
|
|
21
|
+
...options,
|
|
22
|
+
method: "GET",
|
|
23
|
+
});
|
|
24
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
25
|
+
? null
|
|
26
|
+
: await res.text();
|
|
27
|
+
const payload = body ? JSON.parse(body) : {};
|
|
28
|
+
const response = {
|
|
29
|
+
body: payload,
|
|
30
|
+
status: res.status,
|
|
31
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
32
|
+
};
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw response;
|
|
35
|
+
}
|
|
36
|
+
return response;
|
|
37
|
+
};
|
|
38
|
+
const getGetOpenAPISpecUrl = () => {
|
|
39
|
+
return baseURL + `/openapi.yaml`;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves build and version information about the storage service. Useful for monitoring and debugging.
|
|
43
|
+
* @summary Get service version information
|
|
44
|
+
*/
|
|
45
|
+
const getVersion = async (options) => {
|
|
46
|
+
const res = await fetch(getGetVersionUrl(), {
|
|
47
|
+
...options,
|
|
48
|
+
method: "GET",
|
|
49
|
+
});
|
|
50
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
51
|
+
? null
|
|
52
|
+
: await res.text();
|
|
53
|
+
const payload = body ? JSON.parse(body) : {};
|
|
54
|
+
const response = {
|
|
55
|
+
body: payload,
|
|
56
|
+
status: res.status,
|
|
57
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
58
|
+
};
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw response;
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
};
|
|
64
|
+
const getGetVersionUrl = () => {
|
|
65
|
+
return baseURL + `/version`;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Upload one or more files to a specified bucket. Supports batch uploading with optional custom metadata for each file. If uploading multiple files, either provide metadata for all files or none.
|
|
69
|
+
* @summary Upload files
|
|
70
|
+
*/
|
|
71
|
+
const uploadFiles = async (uploadFilesBody, options) => {
|
|
72
|
+
const formData = new FormData();
|
|
73
|
+
if (uploadFilesBody["bucket-id"] !== undefined) {
|
|
74
|
+
formData.append(`bucket-id`, uploadFilesBody["bucket-id"]);
|
|
75
|
+
}
|
|
76
|
+
if (uploadFilesBody["metadata[]"] !== undefined) {
|
|
77
|
+
uploadFilesBody["metadata[]"].forEach((value) => formData.append(`metadata[]`, JSON.stringify(value)));
|
|
78
|
+
}
|
|
79
|
+
if (uploadFilesBody["file[]"] !== undefined) {
|
|
80
|
+
uploadFilesBody["file[]"].forEach((value) => formData.append(`file[]`, value));
|
|
81
|
+
}
|
|
82
|
+
const res = await fetch(getUploadFilesUrl(), {
|
|
83
|
+
...options,
|
|
84
|
+
method: "POST",
|
|
85
|
+
body: formData,
|
|
86
|
+
});
|
|
87
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
88
|
+
? null
|
|
89
|
+
: await res.text();
|
|
90
|
+
const payload = body ? JSON.parse(body) : {};
|
|
91
|
+
const response = {
|
|
92
|
+
body: payload,
|
|
93
|
+
status: res.status,
|
|
94
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
95
|
+
};
|
|
96
|
+
if (!res.ok) {
|
|
97
|
+
throw response;
|
|
98
|
+
}
|
|
99
|
+
return response;
|
|
100
|
+
};
|
|
101
|
+
const getUploadFilesUrl = () => {
|
|
102
|
+
return baseURL + `/files/`;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Retrieve file metadata headers without downloading the file content. Supports conditional requests and provides caching information.
|
|
106
|
+
* @summary Check file information
|
|
107
|
+
*/
|
|
108
|
+
const getFileMetadataHeaders = async (id, params, options) => {
|
|
109
|
+
const res = await fetch(getGetFileMetadataHeadersUrl(id, params), {
|
|
110
|
+
...options,
|
|
111
|
+
method: "HEAD",
|
|
112
|
+
});
|
|
113
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
114
|
+
? null
|
|
115
|
+
: await res.text();
|
|
116
|
+
const payload = body ? JSON.parse(body) : {};
|
|
117
|
+
const response = {
|
|
118
|
+
body: payload,
|
|
119
|
+
status: res.status,
|
|
120
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
121
|
+
};
|
|
122
|
+
if (!res.ok) {
|
|
123
|
+
throw response;
|
|
124
|
+
}
|
|
125
|
+
return response;
|
|
126
|
+
};
|
|
127
|
+
const getGetFileMetadataHeadersUrl = (id, params) => {
|
|
128
|
+
const normalizedParams = new URLSearchParams();
|
|
129
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
130
|
+
if (value !== undefined) {
|
|
131
|
+
normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const stringifiedParams = normalizedParams.toString();
|
|
135
|
+
return stringifiedParams.length > 0
|
|
136
|
+
? baseURL + `/files/${id}?${stringifiedParams}`
|
|
137
|
+
: baseURL + `/files/${id}`;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Retrieve and download the complete file content. Supports conditional requests, image transformations, and range requests for partial downloads.
|
|
141
|
+
* @summary Download file
|
|
142
|
+
*/
|
|
143
|
+
const getFile = async (id, params, options) => {
|
|
144
|
+
const res = await fetch(getGetFileUrl(id, params), {
|
|
145
|
+
...options,
|
|
146
|
+
method: "GET",
|
|
147
|
+
});
|
|
148
|
+
const payload = await res.blob();
|
|
149
|
+
const response = {
|
|
150
|
+
body: payload,
|
|
151
|
+
status: res.status,
|
|
152
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
153
|
+
};
|
|
154
|
+
if (!res.ok) {
|
|
155
|
+
throw response;
|
|
156
|
+
}
|
|
157
|
+
return response;
|
|
158
|
+
};
|
|
159
|
+
const getGetFileUrl = (id, params) => {
|
|
160
|
+
const normalizedParams = new URLSearchParams();
|
|
161
|
+
Object.entries(params || {}).forEach(([key, value]) => {
|
|
162
|
+
if (value !== undefined) {
|
|
163
|
+
normalizedParams.append(key, value === null ? "null" : value.toString());
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const stringifiedParams = normalizedParams.toString();
|
|
167
|
+
return stringifiedParams.length > 0
|
|
168
|
+
? baseURL + `/files/${id}?${stringifiedParams}`
|
|
169
|
+
: baseURL + `/files/${id}`;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Replace an existing file with new content while preserving the file ID. The operation follows these steps:
|
|
173
|
+
1. The isUploaded flag is set to false to mark the file as being updated
|
|
174
|
+
2. The file content is replaced in the storage backend
|
|
175
|
+
3. File metadata is updated (size, mime-type, isUploaded, etc.)
|
|
176
|
+
|
|
177
|
+
Each step is atomic, but if a step fails, previous steps will not be automatically rolled back.
|
|
178
|
+
|
|
179
|
+
* @summary Replace file
|
|
180
|
+
*/
|
|
181
|
+
const replaceFile = async (id, replaceFileBody, options) => {
|
|
182
|
+
const formData = new FormData();
|
|
183
|
+
if (replaceFileBody.metadata !== undefined) {
|
|
184
|
+
formData.append(`metadata`, JSON.stringify(replaceFileBody.metadata));
|
|
185
|
+
}
|
|
186
|
+
if (replaceFileBody.file !== undefined) {
|
|
187
|
+
formData.append(`file`, replaceFileBody.file);
|
|
188
|
+
}
|
|
189
|
+
const res = await fetch(getReplaceFileUrl(id), {
|
|
190
|
+
...options,
|
|
191
|
+
method: "PUT",
|
|
192
|
+
body: formData,
|
|
193
|
+
});
|
|
194
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
195
|
+
? null
|
|
196
|
+
: await res.text();
|
|
197
|
+
const payload = body ? JSON.parse(body) : {};
|
|
198
|
+
const response = {
|
|
199
|
+
body: payload,
|
|
200
|
+
status: res.status,
|
|
201
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
202
|
+
};
|
|
203
|
+
if (!res.ok) {
|
|
204
|
+
throw response;
|
|
205
|
+
}
|
|
206
|
+
return response;
|
|
207
|
+
};
|
|
208
|
+
const getReplaceFileUrl = (id) => {
|
|
209
|
+
return baseURL + `/files/${id}`;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Permanently delete a file from storage. This removes both the file content and its associated metadata.
|
|
213
|
+
* @summary Delete file
|
|
214
|
+
*/
|
|
215
|
+
const deleteFile = async (id, options) => {
|
|
216
|
+
const res = await fetch(getDeleteFileUrl(id), {
|
|
217
|
+
...options,
|
|
218
|
+
method: "DELETE",
|
|
219
|
+
});
|
|
220
|
+
const body = [204, 205, 304, 412].includes(res.status)
|
|
221
|
+
? null
|
|
222
|
+
: await res.text();
|
|
223
|
+
const payload = body ? JSON.parse(body) : {};
|
|
224
|
+
const response = {
|
|
225
|
+
body: payload,
|
|
226
|
+
status: res.status,
|
|
227
|
+
headers: Object.fromEntries(Array.from(res.headers.entries())),
|
|
228
|
+
};
|
|
229
|
+
if (!res.ok) {
|
|
230
|
+
throw response;
|
|
231
|
+
}
|
|
232
|
+
return response;
|
|
233
|
+
};
|
|
234
|
+
const getDeleteFileUrl = (id) => {
|
|
235
|
+
return baseURL + `/files/${id}`;
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
getOpenAPISpec,
|
|
239
|
+
getVersion,
|
|
240
|
+
uploadFiles,
|
|
241
|
+
getFileMetadataHeaders,
|
|
242
|
+
getFile,
|
|
243
|
+
replaceFile,
|
|
244
|
+
deleteFile,
|
|
245
|
+
pushChainFunction,
|
|
246
|
+
baseURL,
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/storage/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,mBAAmB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CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEnD,MAAM,QAAQ,GAAG;YACf,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAE,GAAG,CAAC,OAAe,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD,CAAC;QAEzB,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,QAAQ,CAAC;QACjB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAE,EAAE;QACtC,OAAO,OAAO,GAAG,UAAU,EAAE,EAAE,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO;QACL,cAAc;QACd,UAAU;QACV,WAAW;QACX,sBAAsB;QACtB,OAAO;QACP,WAAW;QACX,UAAU;QACV,iBAAiB;QACjB,OAAO;KACR,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's Storage service.
|
|
3
|
+
* Typically you would use this modula via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* @module storage
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from "./client";
|
|
10
|
+
export * from "./interface";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the main module to interact with Nhost's Storage service.
|
|
3
|
+
* Typically you would use this modula via the main [Nhost client](main#createclient)
|
|
4
|
+
* but you can also use it directly if you have a specific use case.
|
|
5
|
+
*
|
|
6
|
+
* @module storage
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from "./client";
|
|
10
|
+
export * from "./interface";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|