next-tinacms-azure 0.0.0-f401991-20250801014410 → 0.0.0-f4e24d9-20251203015701

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/index.js CHANGED
@@ -1,149 +1,146 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("tinacms")) : typeof define === "function" && define.amd ? define(["exports", "tinacms"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["next-tinacms-azure"] = {}, global.NOOP));
3
- })(this, function(exports2, tinacms) {
4
- "use strict";
5
- class MediaListError extends Error {
6
- constructor(config) {
7
- super(config.message);
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
- const E_DEFAULT = new MediaListError({
14
- title: "An Error Occurred",
15
- message: "Something went wrong fetching your media from Azure Blob Storage.",
16
- docsLink: "https://tina.io/docs/reference/media/external/azure"
17
- });
18
- const E_UNAUTHORIZED = new MediaListError({
19
- title: "Unauthorized",
20
- message: "You don't have access to this resource.",
21
- docsLink: "https://tina.io/docs/reference/media/external/cloudinary/#set-up-api-routes-nextjs-example"
22
- });
23
- const E_CONFIG = new MediaListError({
24
- title: "Missing Credentials",
25
- message: "Unable to connect to Cloudinary because one or more environment variables are missing.",
26
- docsLink: "https://tina.io/docs/media-cloudinary/"
27
- });
28
- const E_KEY_FAIL = new MediaListError({
29
- title: "Bad Credentials",
30
- message: "Unable to connect to Cloudinary because one or more environment variables are misconfigured.",
31
- docsLink: "https://tina.io/docs/media-cloudinary/"
32
- });
33
- const E_BAD_ROUTE = new MediaListError({
34
- title: "Bad Route",
35
- message: "The Cloudinary API route is missing or misconfigured.",
36
- docsLink: "https://tina.io/docs/reference/media/external/cloudinary/#set-up-api-routes-nextjs-example"
37
- });
38
- const interpretErrorMessage = (message) => {
39
- switch (message) {
40
- case "Must supply cloud_name":
41
- case "Must supply api_key":
42
- case "Must supply api_secret":
43
- return E_CONFIG;
44
- case "unknown api_key":
45
- return E_KEY_FAIL;
46
- default:
47
- return E_DEFAULT;
48
- }
49
- };
50
- class AzureMediaStore {
51
- constructor(options) {
52
- this.fetchFunction = (input, init) => fetch(input, init);
53
- this.accept = tinacms.DEFAULT_MEDIA_UPLOAD_TYPES;
54
- this.parse = (img) => {
55
- return img.src;
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
- this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/azure/media";
85
+ newFiles.push(parsedRes);
58
86
  }
59
- async persist(media) {
60
- const newFiles = [];
61
- for (const item of media) {
62
- const { file, directory } = item;
63
- const formData = new FormData();
64
- formData.append("file", file);
65
- formData.append("directory", directory);
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
- return newFiles;
91
- }
92
- async delete(media) {
93
- await this.fetchFunction(
94
- `${this.baseUrl}/${encodeURIComponent(media.id)}`,
95
- {
96
- method: "DELETE"
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
- async list(options) {
101
- const query = this.buildQuery(options);
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
- buildQuery(options) {
121
- const params = Object.entries(options).filter(([_, value]) => value !== "" && value !== void 0).map(([key, value]) => {
122
- return typeof value === "object" ? `${key}=${encodeURIComponent(JSON.stringify(value))}` : `${key}=${encodeURIComponent(String(value))}`;
123
- }).join("&");
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
- const createTinaCloudAzureMediaStore = (options = { baseUrl: "/api/azure/media" }) => class TinaCloudAzureMediaStore extends AzureMediaStore {
128
- constructor(client) {
129
- super(options);
130
- this.client = client;
131
- this.fetchFunction = async (input, init) => {
132
- try {
133
- const url = input.toString();
134
- const query = `${url.includes("?") ? "&" : "?"}clientID=${client.clientId}`;
135
- const res = client.authProvider.fetchWithToken(url + query, init);
136
- return res;
137
- } catch (error) {
138
- console.error(error);
139
- return new Response(null, { status: 500 });
140
- }
141
- };
142
- }
143
- };
144
- const TinaCloudAzureMediaStore = createTinaCloudAzureMediaStore();
145
- exports2.AzureMediaStore = AzureMediaStore;
146
- exports2.TinaCloudAzureMediaStore = TinaCloudAzureMediaStore;
147
- exports2.createTinaCloudAzureMediaStore = createTinaCloudAzureMediaStore;
148
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
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-f401991-20250801014410",
3
+ "version": "0.0.0-f4e24d9-20251203015701",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
6
+ "module": "./dist/index.js",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
@@ -38,11 +38,11 @@
38
38
  "react": "^18.3.1",
39
39
  "react-dom": "^18.3.1",
40
40
  "typescript": "^5.7.3",
41
- "@tinacms/scripts": "1.4.0",
42
- "tinacms": "0.0.0-f401991-20250801014410"
41
+ "@tinacms/scripts": "1.4.1",
42
+ "tinacms": "0.0.0-f4e24d9-20251203015701"
43
43
  },
44
44
  "peerDependencies": {
45
- "tinacms": "0.0.0-f401991-20250801014410",
45
+ "tinacms": "0.0.0-f4e24d9-20251203015701",
46
46
  "@tinacms/auth": "1.1.0"
47
47
  },
48
48
  "publishConfig": {
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
- };