next-tinacms-cloudinary 7.0.0 → 7.1.0
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/dist/cloudinary-media-store.d.ts +6 -1
- package/dist/cloudinary-tina-cloud-media-store.d.ts +27 -8
- package/dist/index.js +13 -15
- package/dist/index.mjs +14 -16
- package/package.json +3 -3
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Media, MediaList, MediaListOptions, MediaStore, MediaUploadOptions } from 'tinacms';
|
|
2
|
+
export declare type CloudinaryMediaStoreOptions = {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
};
|
|
2
5
|
export declare class CloudinaryMediaStore implements MediaStore {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
constructor(options?: CloudinaryMediaStoreOptions);
|
|
3
8
|
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
4
9
|
accept: string;
|
|
5
10
|
persist(media: MediaUploadOptions[]): Promise<Media[]>;
|
|
6
11
|
delete(media: Media): Promise<void>;
|
|
7
12
|
list(options: MediaListOptions): Promise<MediaList>;
|
|
8
13
|
parse: (img: any) => any;
|
|
9
|
-
|
|
14
|
+
buildQuery(options: MediaListOptions): string;
|
|
10
15
|
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { CloudinaryMediaStore } from './cloudinary-media-store';
|
|
5
1
|
import type { Client } from 'tinacms';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import type { CloudinaryMediaStoreOptions } from './cloudinary-media-store';
|
|
3
|
+
export declare const createTinaCloudCloudinaryMediaStore: (options?: CloudinaryMediaStoreOptions) => {
|
|
4
|
+
new (client: Client): {
|
|
5
|
+
client: Client;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
8
|
+
accept: string;
|
|
9
|
+
persist(media: import("tinacms").MediaUploadOptions[]): Promise<import("tinacms").Media[]>;
|
|
10
|
+
delete(media: import("tinacms").Media): Promise<void>;
|
|
11
|
+
list(options: import("tinacms").MediaListOptions): Promise<import("tinacms").MediaList>;
|
|
12
|
+
parse: (img: any) => any;
|
|
13
|
+
buildQuery(options: import("tinacms").MediaListOptions): string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const TinaCloudCloudinaryMediaStore: {
|
|
17
|
+
new (client: Client): {
|
|
18
|
+
client: Client;
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
21
|
+
accept: string;
|
|
22
|
+
persist(media: import("tinacms").MediaUploadOptions[]): Promise<import("tinacms").Media[]>;
|
|
23
|
+
delete(media: import("tinacms").Media): Promise<void>;
|
|
24
|
+
list(options: import("tinacms").MediaListOptions): Promise<import("tinacms").MediaList>;
|
|
25
|
+
parse: (img: any) => any;
|
|
26
|
+
buildQuery(options: import("tinacms").MediaListOptions): string;
|
|
27
|
+
};
|
|
28
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -48,14 +48,13 @@
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
class CloudinaryMediaStore {
|
|
51
|
-
constructor() {
|
|
52
|
-
this.fetchFunction = (input, init) =>
|
|
53
|
-
return fetch(input, init);
|
|
54
|
-
};
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.fetchFunction = (input, init) => fetch(input, init);
|
|
55
53
|
this.accept = tinacms.DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
56
54
|
this.parse = (img) => {
|
|
57
55
|
return img.src;
|
|
58
56
|
};
|
|
57
|
+
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/cloudinary/media";
|
|
59
58
|
}
|
|
60
59
|
async persist(media) {
|
|
61
60
|
const newFiles = [];
|
|
@@ -65,7 +64,7 @@
|
|
|
65
64
|
formData.append("file", file);
|
|
66
65
|
formData.append("directory", directory);
|
|
67
66
|
formData.append("filename", file.name);
|
|
68
|
-
const res = await this.fetchFunction(
|
|
67
|
+
const res = await this.fetchFunction(this.baseUrl, {
|
|
69
68
|
method: "POST",
|
|
70
69
|
body: formData
|
|
71
70
|
});
|
|
@@ -94,16 +93,13 @@
|
|
|
94
93
|
return newFiles;
|
|
95
94
|
}
|
|
96
95
|
async delete(media) {
|
|
97
|
-
await this.fetchFunction(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
method: "DELETE"
|
|
101
|
-
}
|
|
102
|
-
);
|
|
96
|
+
await this.fetchFunction(`${this.baseUrl}/${encodeURIComponent(media.id)}`, {
|
|
97
|
+
method: "DELETE"
|
|
98
|
+
});
|
|
103
99
|
}
|
|
104
100
|
async list(options) {
|
|
105
101
|
const query = this.buildQuery(options);
|
|
106
|
-
const response = await this.fetchFunction(
|
|
102
|
+
const response = await this.fetchFunction(this.baseUrl + query);
|
|
107
103
|
if (response.status == 401) {
|
|
108
104
|
throw E_UNAUTHORIZED;
|
|
109
105
|
}
|
|
@@ -126,9 +122,9 @@
|
|
|
126
122
|
return `?${params}`;
|
|
127
123
|
}
|
|
128
124
|
}
|
|
129
|
-
class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
125
|
+
const createTinaCloudCloudinaryMediaStore = (options = { baseUrl: "/api/cloudinary/media" }) => class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
130
126
|
constructor(client) {
|
|
131
|
-
super();
|
|
127
|
+
super(options);
|
|
132
128
|
this.client = client;
|
|
133
129
|
this.fetchFunction = async (input, init) => {
|
|
134
130
|
try {
|
|
@@ -141,8 +137,10 @@
|
|
|
141
137
|
}
|
|
142
138
|
};
|
|
143
139
|
}
|
|
144
|
-
}
|
|
140
|
+
};
|
|
141
|
+
const TinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore();
|
|
145
142
|
exports2.CloudinaryMediaStore = CloudinaryMediaStore;
|
|
146
143
|
exports2.TinaCloudCloudinaryMediaStore = TinaCloudCloudinaryMediaStore;
|
|
144
|
+
exports2.createTinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore;
|
|
147
145
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
148
146
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -45,14 +45,13 @@ const interpretErrorMessage = (message) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
class CloudinaryMediaStore {
|
|
48
|
-
constructor() {
|
|
49
|
-
this.fetchFunction = (input, init) =>
|
|
50
|
-
return fetch(input, init);
|
|
51
|
-
};
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.fetchFunction = (input, init) => fetch(input, init);
|
|
52
50
|
this.accept = DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
53
51
|
this.parse = (img) => {
|
|
54
52
|
return img.src;
|
|
55
53
|
};
|
|
54
|
+
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/cloudinary/media";
|
|
56
55
|
}
|
|
57
56
|
async persist(media) {
|
|
58
57
|
const newFiles = [];
|
|
@@ -62,7 +61,7 @@ class CloudinaryMediaStore {
|
|
|
62
61
|
formData.append("file", file);
|
|
63
62
|
formData.append("directory", directory);
|
|
64
63
|
formData.append("filename", file.name);
|
|
65
|
-
const res = await this.fetchFunction(
|
|
64
|
+
const res = await this.fetchFunction(this.baseUrl, {
|
|
66
65
|
method: "POST",
|
|
67
66
|
body: formData
|
|
68
67
|
});
|
|
@@ -91,16 +90,13 @@ class CloudinaryMediaStore {
|
|
|
91
90
|
return newFiles;
|
|
92
91
|
}
|
|
93
92
|
async delete(media) {
|
|
94
|
-
await this.fetchFunction(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
method: "DELETE"
|
|
98
|
-
}
|
|
99
|
-
);
|
|
93
|
+
await this.fetchFunction(`${this.baseUrl}/${encodeURIComponent(media.id)}`, {
|
|
94
|
+
method: "DELETE"
|
|
95
|
+
});
|
|
100
96
|
}
|
|
101
97
|
async list(options) {
|
|
102
98
|
const query = this.buildQuery(options);
|
|
103
|
-
const response = await this.fetchFunction(
|
|
99
|
+
const response = await this.fetchFunction(this.baseUrl + query);
|
|
104
100
|
if (response.status == 401) {
|
|
105
101
|
throw E_UNAUTHORIZED;
|
|
106
102
|
}
|
|
@@ -123,9 +119,9 @@ class CloudinaryMediaStore {
|
|
|
123
119
|
return `?${params}`;
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
|
-
class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
122
|
+
const createTinaCloudCloudinaryMediaStore = (options = { baseUrl: "/api/cloudinary/media" }) => class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
127
123
|
constructor(client) {
|
|
128
|
-
super();
|
|
124
|
+
super(options);
|
|
129
125
|
this.client = client;
|
|
130
126
|
this.fetchFunction = async (input, init) => {
|
|
131
127
|
try {
|
|
@@ -138,8 +134,10 @@ class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
|
138
134
|
}
|
|
139
135
|
};
|
|
140
136
|
}
|
|
141
|
-
}
|
|
137
|
+
};
|
|
138
|
+
const TinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore();
|
|
142
139
|
export {
|
|
143
140
|
CloudinaryMediaStore,
|
|
144
|
-
TinaCloudCloudinaryMediaStore
|
|
141
|
+
TinaCloudCloudinaryMediaStore,
|
|
142
|
+
createTinaCloudCloudinaryMediaStore
|
|
145
143
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-cloudinary",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"react-dom": "^18.3.1",
|
|
31
31
|
"typescript": "4.6.4",
|
|
32
32
|
"@tinacms/scripts": "1.1.6",
|
|
33
|
-
"tinacms": "2.1.
|
|
33
|
+
"tinacms": "2.1.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"tinacms": "2.1.
|
|
36
|
+
"tinacms": "2.1.1"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"registry": "https://registry.npmjs.org"
|