next-tinacms-azure 0.0.0-f608f48-20250617065117 → 0.0.0-f717193-20251205011605
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/auth.js +202 -213
- package/dist/delivery-handlers.js +120 -126
- package/dist/handlers.js +120 -129
- package/dist/index.js +138 -141
- package/package.json +6 -6
- package/dist/index.mjs +0 -146
package/dist/index.js
CHANGED
|
@@ -1,149 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.ERR_TYPE = "MediaListError";
|
|
9
|
-
this.title = config.title;
|
|
10
|
-
this.docsLink = config.docsLink;
|
|
11
|
-
}
|
|
1
|
+
import { DEFAULT_MEDIA_UPLOAD_TYPES } from "tinacms";
|
|
2
|
+
class MediaListError extends Error {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
super(config.message);
|
|
5
|
+
this.ERR_TYPE = "MediaListError";
|
|
6
|
+
this.title = config.title;
|
|
7
|
+
this.docsLink = config.docsLink;
|
|
12
8
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
9
|
+
}
|
|
10
|
+
const E_DEFAULT = new MediaListError({
|
|
11
|
+
title: "An Error Occurred",
|
|
12
|
+
message: "Something went wrong fetching your media from Azure Blob Storage.",
|
|
13
|
+
docsLink: "https://tina.io/docs/r/aws-s3-bucket"
|
|
14
|
+
});
|
|
15
|
+
const E_UNAUTHORIZED = new MediaListError({
|
|
16
|
+
title: "Unauthorized",
|
|
17
|
+
message: "You don't have access to this resource.",
|
|
18
|
+
docsLink: "https://tina.io/docs/r/cloudinary"
|
|
19
|
+
});
|
|
20
|
+
const E_CONFIG = new MediaListError({
|
|
21
|
+
title: "Missing Credentials",
|
|
22
|
+
message: "Unable to connect to Cloudinary because one or more environment variables are missing.",
|
|
23
|
+
docsLink: "https://tina.io/docs/r/cloudinary/"
|
|
24
|
+
});
|
|
25
|
+
const E_KEY_FAIL = new MediaListError({
|
|
26
|
+
title: "Bad Credentials",
|
|
27
|
+
message: "Unable to connect to Cloudinary because one or more environment variables are misconfigured.",
|
|
28
|
+
docsLink: "https://tina.io/docs/r/cloudinary/"
|
|
29
|
+
});
|
|
30
|
+
const E_BAD_ROUTE = new MediaListError({
|
|
31
|
+
title: "Bad Route",
|
|
32
|
+
message: "The Cloudinary API route is missing or misconfigured.",
|
|
33
|
+
docsLink: "https://tina.io/docs/r/cloudinary"
|
|
34
|
+
});
|
|
35
|
+
const interpretErrorMessage = (message) => {
|
|
36
|
+
switch (message) {
|
|
37
|
+
case "Must supply cloud_name":
|
|
38
|
+
case "Must supply api_key":
|
|
39
|
+
case "Must supply api_secret":
|
|
40
|
+
return E_CONFIG;
|
|
41
|
+
case "unknown api_key":
|
|
42
|
+
return E_KEY_FAIL;
|
|
43
|
+
default:
|
|
44
|
+
return E_DEFAULT;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
class AzureMediaStore {
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.fetchFunction = (input, init) => fetch(input, init);
|
|
50
|
+
this.accept = DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
51
|
+
this.parse = (img) => {
|
|
52
|
+
return img.src;
|
|
53
|
+
};
|
|
54
|
+
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/azure/media";
|
|
55
|
+
}
|
|
56
|
+
async persist(media) {
|
|
57
|
+
const newFiles = [];
|
|
58
|
+
for (const item of media) {
|
|
59
|
+
const { file, directory } = item;
|
|
60
|
+
const formData = new FormData();
|
|
61
|
+
formData.append("file", file);
|
|
62
|
+
formData.append("directory", directory);
|
|
63
|
+
formData.append("filename", file.name);
|
|
64
|
+
const res = await this.fetchFunction(this.baseUrl, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: formData
|
|
67
|
+
});
|
|
68
|
+
if (res.status !== 200) {
|
|
69
|
+
const responseData = await res.json();
|
|
70
|
+
throw new Error(responseData.message);
|
|
71
|
+
}
|
|
72
|
+
const fileRes = await res.json();
|
|
73
|
+
const parsedRes = {
|
|
74
|
+
type: "file",
|
|
75
|
+
id: fileRes.name,
|
|
76
|
+
filename: fileRes.filename,
|
|
77
|
+
directory: "/",
|
|
78
|
+
thumbnails: {
|
|
79
|
+
"75x75": fileRes.url,
|
|
80
|
+
"400x400": fileRes.url,
|
|
81
|
+
"1000x1000": fileRes.url
|
|
82
|
+
},
|
|
83
|
+
src: fileRes.url
|
|
56
84
|
};
|
|
57
|
-
|
|
85
|
+
newFiles.push(parsedRes);
|
|
58
86
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
formData.append("filename", file.name);
|
|
67
|
-
const res = await this.fetchFunction(this.baseUrl, {
|
|
68
|
-
method: "POST",
|
|
69
|
-
body: formData
|
|
70
|
-
});
|
|
71
|
-
if (res.status !== 200) {
|
|
72
|
-
const responseData = await res.json();
|
|
73
|
-
throw new Error(responseData.message);
|
|
74
|
-
}
|
|
75
|
-
const fileRes = await res.json();
|
|
76
|
-
const parsedRes = {
|
|
77
|
-
type: "file",
|
|
78
|
-
id: fileRes.name,
|
|
79
|
-
filename: fileRes.filename,
|
|
80
|
-
directory: "/",
|
|
81
|
-
thumbnails: {
|
|
82
|
-
"75x75": fileRes.url,
|
|
83
|
-
"400x400": fileRes.url,
|
|
84
|
-
"1000x1000": fileRes.url
|
|
85
|
-
},
|
|
86
|
-
src: fileRes.url
|
|
87
|
-
};
|
|
88
|
-
newFiles.push(parsedRes);
|
|
87
|
+
return newFiles;
|
|
88
|
+
}
|
|
89
|
+
async delete(media) {
|
|
90
|
+
await this.fetchFunction(
|
|
91
|
+
`${this.baseUrl}/${encodeURIComponent(media.id)}`,
|
|
92
|
+
{
|
|
93
|
+
method: "DELETE"
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
);
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async list(options) {
|
|
98
|
+
const query = this.buildQuery(options);
|
|
99
|
+
const response = await this.fetchFunction(this.baseUrl + query);
|
|
100
|
+
if (response.status === 401) {
|
|
101
|
+
throw E_UNAUTHORIZED;
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const response = await this.fetchFunction(this.baseUrl + query);
|
|
103
|
-
if (response.status === 401) {
|
|
104
|
-
throw E_UNAUTHORIZED;
|
|
105
|
-
}
|
|
106
|
-
if (response.status === 404) {
|
|
107
|
-
throw E_BAD_ROUTE;
|
|
108
|
-
}
|
|
109
|
-
if (response.status >= 500) {
|
|
110
|
-
const { e } = await response.json();
|
|
111
|
-
const error = interpretErrorMessage(e);
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
const { items, offset } = await response.json();
|
|
115
|
-
return {
|
|
116
|
-
items: items.map((item) => item),
|
|
117
|
-
nextOffset: offset
|
|
118
|
-
};
|
|
103
|
+
if (response.status === 404) {
|
|
104
|
+
throw E_BAD_ROUTE;
|
|
119
105
|
}
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return `?${params}`;
|
|
106
|
+
if (response.status >= 500) {
|
|
107
|
+
const { e } = await response.json();
|
|
108
|
+
const error = interpretErrorMessage(e);
|
|
109
|
+
throw error;
|
|
125
110
|
}
|
|
111
|
+
const { items, offset } = await response.json();
|
|
112
|
+
return {
|
|
113
|
+
items: items.map((item) => item),
|
|
114
|
+
nextOffset: offset
|
|
115
|
+
};
|
|
126
116
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
117
|
+
buildQuery(options) {
|
|
118
|
+
const params = Object.entries(options).filter(([_, value]) => value !== "" && value !== void 0).map(([key, value]) => {
|
|
119
|
+
return typeof value === "object" ? `${key}=${encodeURIComponent(JSON.stringify(value))}` : `${key}=${encodeURIComponent(String(value))}`;
|
|
120
|
+
}).join("&");
|
|
121
|
+
return `?${params}`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const createTinaCloudAzureMediaStore = (options = { baseUrl: "/api/azure/media" }) => class TinaCloudAzureMediaStore extends AzureMediaStore {
|
|
125
|
+
constructor(client) {
|
|
126
|
+
super(options);
|
|
127
|
+
this.client = client;
|
|
128
|
+
this.fetchFunction = async (input, init) => {
|
|
129
|
+
try {
|
|
130
|
+
const url = input.toString();
|
|
131
|
+
const query = `${url.includes("?") ? "&" : "?"}clientID=${client.clientId}`;
|
|
132
|
+
const res = client.authProvider.fetchWithToken(url + query, init);
|
|
133
|
+
return res;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(error);
|
|
136
|
+
return new Response(null, { status: 500 });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const TinaCloudAzureMediaStore = createTinaCloudAzureMediaStore();
|
|
142
|
+
export {
|
|
143
|
+
AzureMediaStore,
|
|
144
|
+
TinaCloudAzureMediaStore,
|
|
145
|
+
createTinaCloudAzureMediaStore
|
|
146
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-azure",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-f717193-20251205011605",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"react": "^18.3.1",
|
|
39
39
|
"react-dom": "^18.3.1",
|
|
40
40
|
"typescript": "^5.7.3",
|
|
41
|
-
"@tinacms/scripts": "
|
|
42
|
-
"tinacms": "0.0.0-
|
|
41
|
+
"@tinacms/scripts": "1.4.1",
|
|
42
|
+
"tinacms": "0.0.0-f717193-20251205011605"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"tinacms": "0.0.0-
|
|
46
|
-
"@tinacms/auth": "
|
|
45
|
+
"tinacms": "0.0.0-f717193-20251205011605",
|
|
46
|
+
"@tinacms/auth": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"registry": "https://registry.npmjs.org"
|
package/dist/index.mjs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_MEDIA_UPLOAD_TYPES } from "tinacms";
|
|
2
|
-
class MediaListError extends Error {
|
|
3
|
-
constructor(config) {
|
|
4
|
-
super(config.message);
|
|
5
|
-
this.ERR_TYPE = "MediaListError";
|
|
6
|
-
this.title = config.title;
|
|
7
|
-
this.docsLink = config.docsLink;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
const E_DEFAULT = new MediaListError({
|
|
11
|
-
title: "An Error Occurred",
|
|
12
|
-
message: "Something went wrong fetching your media from Azure Blob Storage.",
|
|
13
|
-
docsLink: "https://tina.io/docs/reference/media/external/azure"
|
|
14
|
-
});
|
|
15
|
-
const E_UNAUTHORIZED = new MediaListError({
|
|
16
|
-
title: "Unauthorized",
|
|
17
|
-
message: "You don't have access to this resource.",
|
|
18
|
-
docsLink: "https://tina.io/docs/reference/media/external/cloudinary/#set-up-api-routes-nextjs-example"
|
|
19
|
-
});
|
|
20
|
-
const E_CONFIG = new MediaListError({
|
|
21
|
-
title: "Missing Credentials",
|
|
22
|
-
message: "Unable to connect to Cloudinary because one or more environment variables are missing.",
|
|
23
|
-
docsLink: "https://tina.io/docs/media-cloudinary/"
|
|
24
|
-
});
|
|
25
|
-
const E_KEY_FAIL = new MediaListError({
|
|
26
|
-
title: "Bad Credentials",
|
|
27
|
-
message: "Unable to connect to Cloudinary because one or more environment variables are misconfigured.",
|
|
28
|
-
docsLink: "https://tina.io/docs/media-cloudinary/"
|
|
29
|
-
});
|
|
30
|
-
const E_BAD_ROUTE = new MediaListError({
|
|
31
|
-
title: "Bad Route",
|
|
32
|
-
message: "The Cloudinary API route is missing or misconfigured.",
|
|
33
|
-
docsLink: "https://tina.io/docs/reference/media/external/cloudinary/#set-up-api-routes-nextjs-example"
|
|
34
|
-
});
|
|
35
|
-
const interpretErrorMessage = (message) => {
|
|
36
|
-
switch (message) {
|
|
37
|
-
case "Must supply cloud_name":
|
|
38
|
-
case "Must supply api_key":
|
|
39
|
-
case "Must supply api_secret":
|
|
40
|
-
return E_CONFIG;
|
|
41
|
-
case "unknown api_key":
|
|
42
|
-
return E_KEY_FAIL;
|
|
43
|
-
default:
|
|
44
|
-
return E_DEFAULT;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
class AzureMediaStore {
|
|
48
|
-
constructor(options) {
|
|
49
|
-
this.fetchFunction = (input, init) => fetch(input, init);
|
|
50
|
-
this.accept = DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
51
|
-
this.parse = (img) => {
|
|
52
|
-
return img.src;
|
|
53
|
-
};
|
|
54
|
-
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/azure/media";
|
|
55
|
-
}
|
|
56
|
-
async persist(media) {
|
|
57
|
-
const newFiles = [];
|
|
58
|
-
for (const item of media) {
|
|
59
|
-
const { file, directory } = item;
|
|
60
|
-
const formData = new FormData();
|
|
61
|
-
formData.append("file", file);
|
|
62
|
-
formData.append("directory", directory);
|
|
63
|
-
formData.append("filename", file.name);
|
|
64
|
-
const res = await this.fetchFunction(this.baseUrl, {
|
|
65
|
-
method: "POST",
|
|
66
|
-
body: formData
|
|
67
|
-
});
|
|
68
|
-
if (res.status !== 200) {
|
|
69
|
-
const responseData = await res.json();
|
|
70
|
-
throw new Error(responseData.message);
|
|
71
|
-
}
|
|
72
|
-
const fileRes = await res.json();
|
|
73
|
-
const parsedRes = {
|
|
74
|
-
type: "file",
|
|
75
|
-
id: fileRes.name,
|
|
76
|
-
filename: fileRes.filename,
|
|
77
|
-
directory: "/",
|
|
78
|
-
thumbnails: {
|
|
79
|
-
"75x75": fileRes.url,
|
|
80
|
-
"400x400": fileRes.url,
|
|
81
|
-
"1000x1000": fileRes.url
|
|
82
|
-
},
|
|
83
|
-
src: fileRes.url
|
|
84
|
-
};
|
|
85
|
-
newFiles.push(parsedRes);
|
|
86
|
-
}
|
|
87
|
-
return newFiles;
|
|
88
|
-
}
|
|
89
|
-
async delete(media) {
|
|
90
|
-
await this.fetchFunction(
|
|
91
|
-
`${this.baseUrl}/${encodeURIComponent(media.id)}`,
|
|
92
|
-
{
|
|
93
|
-
method: "DELETE"
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
async list(options) {
|
|
98
|
-
const query = this.buildQuery(options);
|
|
99
|
-
const response = await this.fetchFunction(this.baseUrl + query);
|
|
100
|
-
if (response.status === 401) {
|
|
101
|
-
throw E_UNAUTHORIZED;
|
|
102
|
-
}
|
|
103
|
-
if (response.status === 404) {
|
|
104
|
-
throw E_BAD_ROUTE;
|
|
105
|
-
}
|
|
106
|
-
if (response.status >= 500) {
|
|
107
|
-
const { e } = await response.json();
|
|
108
|
-
const error = interpretErrorMessage(e);
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
const { items, offset } = await response.json();
|
|
112
|
-
return {
|
|
113
|
-
items: items.map((item) => item),
|
|
114
|
-
nextOffset: offset
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
buildQuery(options) {
|
|
118
|
-
const params = Object.entries(options).filter(([_, value]) => value !== "" && value !== void 0).map(([key, value]) => {
|
|
119
|
-
return typeof value === "object" ? `${key}=${encodeURIComponent(JSON.stringify(value))}` : `${key}=${encodeURIComponent(String(value))}`;
|
|
120
|
-
}).join("&");
|
|
121
|
-
return `?${params}`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const createTinaCloudAzureMediaStore = (options = { baseUrl: "/api/azure/media" }) => class TinaCloudAzureMediaStore extends AzureMediaStore {
|
|
125
|
-
constructor(client) {
|
|
126
|
-
super(options);
|
|
127
|
-
this.client = client;
|
|
128
|
-
this.fetchFunction = async (input, init) => {
|
|
129
|
-
try {
|
|
130
|
-
const url = input.toString();
|
|
131
|
-
const query = `${url.includes("?") ? "&" : "?"}clientID=${client.clientId}`;
|
|
132
|
-
const res = client.authProvider.fetchWithToken(url + query, init);
|
|
133
|
-
return res;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.error(error);
|
|
136
|
-
return new Response(null, { status: 500 });
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const TinaCloudAzureMediaStore = createTinaCloudAzureMediaStore();
|
|
142
|
-
export {
|
|
143
|
-
AzureMediaStore,
|
|
144
|
-
TinaCloudAzureMediaStore,
|
|
145
|
-
createTinaCloudAzureMediaStore
|
|
146
|
-
};
|