@drawbridge/drawbridge-utils 0.0.12 → 0.0.14
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/cdn.cjs +37 -0
- package/dist/cdn.d.cts +20 -0
- package/dist/cdn.d.ts +20 -0
- package/dist/cdn.js +13 -0
- package/dist/fetch.cjs +128 -0
- package/dist/fetch.d.cts +125 -0
- package/dist/fetch.d.ts +125 -0
- package/dist/fetch.js +92 -0
- package/dist/slugify.cjs +52 -0
- package/dist/slugify.d.cts +20 -0
- package/dist/slugify.d.ts +20 -0
- package/dist/slugify.js +18 -0
- package/package.json +18 -1
package/dist/cdn.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// cdn.js
|
|
20
|
+
var cdn_exports = {};
|
|
21
|
+
__export(cdn_exports, {
|
|
22
|
+
cdnSrc: () => cdnSrc
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cdn_exports);
|
|
25
|
+
var cdnSrc = (asset, size, timestamp) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const src = (_a = asset == null ? void 0 : asset.sizes) == null ? void 0 : _a[size];
|
|
28
|
+
if (!src || !timestamp) return void 0;
|
|
29
|
+
return [
|
|
30
|
+
src,
|
|
31
|
+
"?query=" + timestamp
|
|
32
|
+
].join("");
|
|
33
|
+
};
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
cdnSrc
|
|
37
|
+
});
|
package/dist/cdn.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
|
|
2
|
+
// `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
|
|
3
|
+
// '100x100', 'original', 'hsl'). `timestamp` is required — without it the
|
|
4
|
+
// URL would never change across uploads and the CDN/browser would serve a
|
|
5
|
+
// stale asset. Pass the asset's own `updatedAt` when it has one, or the
|
|
6
|
+
// parent document's `updatedAt` for embedded assets like `user.image`.
|
|
7
|
+
const cdnSrc = ( asset, size, timestamp ) => {
|
|
8
|
+
|
|
9
|
+
const src = asset?.sizes?.[ size ];
|
|
10
|
+
|
|
11
|
+
if( ! src || ! timestamp ) return undefined;
|
|
12
|
+
|
|
13
|
+
return [
|
|
14
|
+
src,
|
|
15
|
+
'?query=' + timestamp
|
|
16
|
+
].join( '' );
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { cdnSrc };
|
package/dist/cdn.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
|
|
2
|
+
// `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
|
|
3
|
+
// '100x100', 'original', 'hsl'). `timestamp` is required — without it the
|
|
4
|
+
// URL would never change across uploads and the CDN/browser would serve a
|
|
5
|
+
// stale asset. Pass the asset's own `updatedAt` when it has one, or the
|
|
6
|
+
// parent document's `updatedAt` for embedded assets like `user.image`.
|
|
7
|
+
const cdnSrc = ( asset, size, timestamp ) => {
|
|
8
|
+
|
|
9
|
+
const src = asset?.sizes?.[ size ];
|
|
10
|
+
|
|
11
|
+
if( ! src || ! timestamp ) return undefined;
|
|
12
|
+
|
|
13
|
+
return [
|
|
14
|
+
src,
|
|
15
|
+
'?query=' + timestamp
|
|
16
|
+
].join( '' );
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { cdnSrc };
|
package/dist/cdn.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// cdn.js
|
|
2
|
+
var cdnSrc = (asset, size, timestamp) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const src = (_a = asset == null ? void 0 : asset.sizes) == null ? void 0 : _a[size];
|
|
5
|
+
if (!src || !timestamp) return void 0;
|
|
6
|
+
return [
|
|
7
|
+
src,
|
|
8
|
+
"?query=" + timestamp
|
|
9
|
+
].join("");
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
cdnSrc
|
|
13
|
+
};
|
package/dist/fetch.cjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// fetch.js
|
|
30
|
+
var fetch_exports = {};
|
|
31
|
+
__export(fetch_exports, {
|
|
32
|
+
queryString: () => queryString,
|
|
33
|
+
request: () => request,
|
|
34
|
+
setMemoryToken: () => setMemoryToken
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(fetch_exports);
|
|
37
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
38
|
+
var import_qs = __toESM(require("qs"), 1);
|
|
39
|
+
var queryString = import_qs.default;
|
|
40
|
+
var memoryToken = null;
|
|
41
|
+
var setMemoryToken = (value) => {
|
|
42
|
+
if (typeof window === "undefined") return;
|
|
43
|
+
memoryToken = value || null;
|
|
44
|
+
};
|
|
45
|
+
var readCsrf = () => {
|
|
46
|
+
if (typeof document === "undefined") return null;
|
|
47
|
+
const match = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/);
|
|
48
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
49
|
+
};
|
|
50
|
+
var client = import_axios.default.create({
|
|
51
|
+
paramsSerializer: {
|
|
52
|
+
serialize: (params) => import_qs.default.stringify(
|
|
53
|
+
params,
|
|
54
|
+
{
|
|
55
|
+
encode: false
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
client.interceptors.request.use((config) => {
|
|
61
|
+
const token = config.__token || (typeof window !== "undefined" ? memoryToken : null);
|
|
62
|
+
if (token) {
|
|
63
|
+
config.headers["authorization"] = "Bearer " + token;
|
|
64
|
+
}
|
|
65
|
+
;
|
|
66
|
+
const csrf = readCsrf();
|
|
67
|
+
if (csrf) {
|
|
68
|
+
config.headers["x-drawbridge-csrf"] = csrf;
|
|
69
|
+
}
|
|
70
|
+
;
|
|
71
|
+
delete config.__token;
|
|
72
|
+
return config;
|
|
73
|
+
});
|
|
74
|
+
client.interceptors.response.use(
|
|
75
|
+
(response) => response.data,
|
|
76
|
+
(error) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const status = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status;
|
|
79
|
+
const data = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
80
|
+
const message = (data == null ? void 0 : data.message) || (error == null ? void 0 : error.message) || "Request failed";
|
|
81
|
+
const err = new Error(message);
|
|
82
|
+
err.status = status;
|
|
83
|
+
err.data = data;
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
var request = async ({
|
|
88
|
+
body,
|
|
89
|
+
endpoint,
|
|
90
|
+
headers = {
|
|
91
|
+
"accept": "application/json",
|
|
92
|
+
"content-type": "application/json"
|
|
93
|
+
},
|
|
94
|
+
method = "GET",
|
|
95
|
+
params,
|
|
96
|
+
token,
|
|
97
|
+
url = process.env.NEXT_PUBLIC_API_URI,
|
|
98
|
+
...options
|
|
99
|
+
}) => {
|
|
100
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
101
|
+
const requestHeaders = {
|
|
102
|
+
"origin": process.env.NEXT_PUBLIC_APP_URI,
|
|
103
|
+
...headers
|
|
104
|
+
};
|
|
105
|
+
if (isFormData) {
|
|
106
|
+
delete requestHeaders["content-type"];
|
|
107
|
+
}
|
|
108
|
+
;
|
|
109
|
+
return client.request({
|
|
110
|
+
...options,
|
|
111
|
+
url: [url, endpoint].join(""),
|
|
112
|
+
method,
|
|
113
|
+
headers: requestHeaders,
|
|
114
|
+
...body !== void 0 && {
|
|
115
|
+
data: body
|
|
116
|
+
},
|
|
117
|
+
...params && {
|
|
118
|
+
params
|
|
119
|
+
},
|
|
120
|
+
__token: token
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
+
0 && (module.exports = {
|
|
125
|
+
queryString,
|
|
126
|
+
request,
|
|
127
|
+
setMemoryToken
|
|
128
|
+
});
|
package/dist/fetch.d.cts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import axiosLib from 'axios';
|
|
2
|
+
import qs from 'qs';
|
|
3
|
+
|
|
4
|
+
const queryString = qs;
|
|
5
|
+
|
|
6
|
+
// In-memory token store for client-side authenticated calls. Guarded
|
|
7
|
+
// against server writes — Next.js shares module state across requests on
|
|
8
|
+
// the server, which would leak tokens between users. Server-side callers
|
|
9
|
+
// must pass `token` explicitly via the rest() options.
|
|
10
|
+
let memoryToken = null;
|
|
11
|
+
|
|
12
|
+
const setMemoryToken = ( value ) => {
|
|
13
|
+
|
|
14
|
+
if( typeof window === 'undefined' ) return;
|
|
15
|
+
|
|
16
|
+
memoryToken = value || null;
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Reads the double-submit CSRF cookie set server-side at session creation
|
|
21
|
+
// (drawbridge.csrf — non-HttpOnly so JS can read it). Returns null on the
|
|
22
|
+
// server or when the cookie isn't present.
|
|
23
|
+
const readCsrf = () => {
|
|
24
|
+
|
|
25
|
+
if( typeof document === 'undefined' ) return null;
|
|
26
|
+
|
|
27
|
+
const match = document.cookie.match( /(?:^|;\s*)drawbridge\.csrf=([^;]+)/ );
|
|
28
|
+
|
|
29
|
+
return match ? decodeURIComponent( match[ 1 ] ) : null;
|
|
30
|
+
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const client = axiosLib.create({
|
|
34
|
+
paramsSerializer : {
|
|
35
|
+
serialize : ( params ) => qs.stringify(
|
|
36
|
+
params,
|
|
37
|
+
{
|
|
38
|
+
encode : false
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
client.interceptors.request.use( ( config ) => {
|
|
45
|
+
|
|
46
|
+
const token = config.__token || ( typeof window !== 'undefined' ? memoryToken : null );
|
|
47
|
+
|
|
48
|
+
if( token ){
|
|
49
|
+
|
|
50
|
+
config.headers[ 'authorization' ] = 'Bearer ' + token;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
const csrf = readCsrf();
|
|
54
|
+
|
|
55
|
+
if( csrf ){
|
|
56
|
+
|
|
57
|
+
config.headers[ 'x-drawbridge-csrf' ] = csrf;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
delete config.__token;
|
|
61
|
+
|
|
62
|
+
return config;
|
|
63
|
+
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
client.interceptors.response.use(
|
|
67
|
+
( response ) => response.data,
|
|
68
|
+
( error ) => {
|
|
69
|
+
|
|
70
|
+
const status = error?.response?.status;
|
|
71
|
+
const data = error?.response?.data;
|
|
72
|
+
const message = data?.message || error?.message || 'Request failed';
|
|
73
|
+
const err = new Error( message );
|
|
74
|
+
|
|
75
|
+
err.status = status;
|
|
76
|
+
err.data = data;
|
|
77
|
+
|
|
78
|
+
throw err;
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const request = async ({
|
|
84
|
+
body,
|
|
85
|
+
endpoint,
|
|
86
|
+
headers = {
|
|
87
|
+
'accept' : 'application/json',
|
|
88
|
+
'content-type' : 'application/json'
|
|
89
|
+
},
|
|
90
|
+
method = 'GET',
|
|
91
|
+
params,
|
|
92
|
+
token,
|
|
93
|
+
url = process.env.NEXT_PUBLIC_API_URI,
|
|
94
|
+
...options
|
|
95
|
+
}) => {
|
|
96
|
+
|
|
97
|
+
const isFormData = ( typeof FormData !== 'undefined' && body instanceof FormData );
|
|
98
|
+
|
|
99
|
+
const requestHeaders = {
|
|
100
|
+
'origin' : process.env.NEXT_PUBLIC_APP_URI,
|
|
101
|
+
...headers
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if( isFormData ){
|
|
105
|
+
|
|
106
|
+
delete requestHeaders[ 'content-type' ];
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
return client.request({
|
|
110
|
+
...options,
|
|
111
|
+
url : [ url, endpoint ].join( '' ),
|
|
112
|
+
method,
|
|
113
|
+
headers : requestHeaders,
|
|
114
|
+
...( body !== undefined && {
|
|
115
|
+
data : body
|
|
116
|
+
}),
|
|
117
|
+
...( params && {
|
|
118
|
+
params
|
|
119
|
+
}),
|
|
120
|
+
__token : token
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { queryString, request, setMemoryToken };
|
package/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import axiosLib from 'axios';
|
|
2
|
+
import qs from 'qs';
|
|
3
|
+
|
|
4
|
+
const queryString = qs;
|
|
5
|
+
|
|
6
|
+
// In-memory token store for client-side authenticated calls. Guarded
|
|
7
|
+
// against server writes — Next.js shares module state across requests on
|
|
8
|
+
// the server, which would leak tokens between users. Server-side callers
|
|
9
|
+
// must pass `token` explicitly via the rest() options.
|
|
10
|
+
let memoryToken = null;
|
|
11
|
+
|
|
12
|
+
const setMemoryToken = ( value ) => {
|
|
13
|
+
|
|
14
|
+
if( typeof window === 'undefined' ) return;
|
|
15
|
+
|
|
16
|
+
memoryToken = value || null;
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Reads the double-submit CSRF cookie set server-side at session creation
|
|
21
|
+
// (drawbridge.csrf — non-HttpOnly so JS can read it). Returns null on the
|
|
22
|
+
// server or when the cookie isn't present.
|
|
23
|
+
const readCsrf = () => {
|
|
24
|
+
|
|
25
|
+
if( typeof document === 'undefined' ) return null;
|
|
26
|
+
|
|
27
|
+
const match = document.cookie.match( /(?:^|;\s*)drawbridge\.csrf=([^;]+)/ );
|
|
28
|
+
|
|
29
|
+
return match ? decodeURIComponent( match[ 1 ] ) : null;
|
|
30
|
+
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const client = axiosLib.create({
|
|
34
|
+
paramsSerializer : {
|
|
35
|
+
serialize : ( params ) => qs.stringify(
|
|
36
|
+
params,
|
|
37
|
+
{
|
|
38
|
+
encode : false
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
client.interceptors.request.use( ( config ) => {
|
|
45
|
+
|
|
46
|
+
const token = config.__token || ( typeof window !== 'undefined' ? memoryToken : null );
|
|
47
|
+
|
|
48
|
+
if( token ){
|
|
49
|
+
|
|
50
|
+
config.headers[ 'authorization' ] = 'Bearer ' + token;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
const csrf = readCsrf();
|
|
54
|
+
|
|
55
|
+
if( csrf ){
|
|
56
|
+
|
|
57
|
+
config.headers[ 'x-drawbridge-csrf' ] = csrf;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
delete config.__token;
|
|
61
|
+
|
|
62
|
+
return config;
|
|
63
|
+
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
client.interceptors.response.use(
|
|
67
|
+
( response ) => response.data,
|
|
68
|
+
( error ) => {
|
|
69
|
+
|
|
70
|
+
const status = error?.response?.status;
|
|
71
|
+
const data = error?.response?.data;
|
|
72
|
+
const message = data?.message || error?.message || 'Request failed';
|
|
73
|
+
const err = new Error( message );
|
|
74
|
+
|
|
75
|
+
err.status = status;
|
|
76
|
+
err.data = data;
|
|
77
|
+
|
|
78
|
+
throw err;
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const request = async ({
|
|
84
|
+
body,
|
|
85
|
+
endpoint,
|
|
86
|
+
headers = {
|
|
87
|
+
'accept' : 'application/json',
|
|
88
|
+
'content-type' : 'application/json'
|
|
89
|
+
},
|
|
90
|
+
method = 'GET',
|
|
91
|
+
params,
|
|
92
|
+
token,
|
|
93
|
+
url = process.env.NEXT_PUBLIC_API_URI,
|
|
94
|
+
...options
|
|
95
|
+
}) => {
|
|
96
|
+
|
|
97
|
+
const isFormData = ( typeof FormData !== 'undefined' && body instanceof FormData );
|
|
98
|
+
|
|
99
|
+
const requestHeaders = {
|
|
100
|
+
'origin' : process.env.NEXT_PUBLIC_APP_URI,
|
|
101
|
+
...headers
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
if( isFormData ){
|
|
105
|
+
|
|
106
|
+
delete requestHeaders[ 'content-type' ];
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
return client.request({
|
|
110
|
+
...options,
|
|
111
|
+
url : [ url, endpoint ].join( '' ),
|
|
112
|
+
method,
|
|
113
|
+
headers : requestHeaders,
|
|
114
|
+
...( body !== undefined && {
|
|
115
|
+
data : body
|
|
116
|
+
}),
|
|
117
|
+
...( params && {
|
|
118
|
+
params
|
|
119
|
+
}),
|
|
120
|
+
__token : token
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { queryString, request, setMemoryToken };
|
package/dist/fetch.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// fetch.js
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import qs from "qs";
|
|
4
|
+
var queryString = qs;
|
|
5
|
+
var memoryToken = null;
|
|
6
|
+
var setMemoryToken = (value) => {
|
|
7
|
+
if (typeof window === "undefined") return;
|
|
8
|
+
memoryToken = value || null;
|
|
9
|
+
};
|
|
10
|
+
var readCsrf = () => {
|
|
11
|
+
if (typeof document === "undefined") return null;
|
|
12
|
+
const match = document.cookie.match(/(?:^|;\s*)drawbridge\.csrf=([^;]+)/);
|
|
13
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
14
|
+
};
|
|
15
|
+
var client = axios.create({
|
|
16
|
+
paramsSerializer: {
|
|
17
|
+
serialize: (params) => qs.stringify(
|
|
18
|
+
params,
|
|
19
|
+
{
|
|
20
|
+
encode: false
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
client.interceptors.request.use((config) => {
|
|
26
|
+
const token = config.__token || (typeof window !== "undefined" ? memoryToken : null);
|
|
27
|
+
if (token) {
|
|
28
|
+
config.headers["authorization"] = "Bearer " + token;
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
const csrf = readCsrf();
|
|
32
|
+
if (csrf) {
|
|
33
|
+
config.headers["x-drawbridge-csrf"] = csrf;
|
|
34
|
+
}
|
|
35
|
+
;
|
|
36
|
+
delete config.__token;
|
|
37
|
+
return config;
|
|
38
|
+
});
|
|
39
|
+
client.interceptors.response.use(
|
|
40
|
+
(response) => response.data,
|
|
41
|
+
(error) => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const status = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status;
|
|
44
|
+
const data = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
45
|
+
const message = (data == null ? void 0 : data.message) || (error == null ? void 0 : error.message) || "Request failed";
|
|
46
|
+
const err = new Error(message);
|
|
47
|
+
err.status = status;
|
|
48
|
+
err.data = data;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
var request = async ({
|
|
53
|
+
body,
|
|
54
|
+
endpoint,
|
|
55
|
+
headers = {
|
|
56
|
+
"accept": "application/json",
|
|
57
|
+
"content-type": "application/json"
|
|
58
|
+
},
|
|
59
|
+
method = "GET",
|
|
60
|
+
params,
|
|
61
|
+
token,
|
|
62
|
+
url = process.env.NEXT_PUBLIC_API_URI,
|
|
63
|
+
...options
|
|
64
|
+
}) => {
|
|
65
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
66
|
+
const requestHeaders = {
|
|
67
|
+
"origin": process.env.NEXT_PUBLIC_APP_URI,
|
|
68
|
+
...headers
|
|
69
|
+
};
|
|
70
|
+
if (isFormData) {
|
|
71
|
+
delete requestHeaders["content-type"];
|
|
72
|
+
}
|
|
73
|
+
;
|
|
74
|
+
return client.request({
|
|
75
|
+
...options,
|
|
76
|
+
url: [url, endpoint].join(""),
|
|
77
|
+
method,
|
|
78
|
+
headers: requestHeaders,
|
|
79
|
+
...body !== void 0 && {
|
|
80
|
+
data: body
|
|
81
|
+
},
|
|
82
|
+
...params && {
|
|
83
|
+
params
|
|
84
|
+
},
|
|
85
|
+
__token: token
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
queryString,
|
|
90
|
+
request,
|
|
91
|
+
setMemoryToken
|
|
92
|
+
};
|
package/dist/slugify.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// slugify.js
|
|
30
|
+
var slugify_exports = {};
|
|
31
|
+
__export(slugify_exports, {
|
|
32
|
+
slugify: () => slugify
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(slugify_exports);
|
|
35
|
+
var import_slugify = __toESM(require("slugify"), 1);
|
|
36
|
+
var slugify = (value, nochars = false) => {
|
|
37
|
+
const remove = nochars ? /[-?*+~.()'"!:@#^_{}\[\];,/\\]/g : /[?*+~.()'"!:@#^_{}\[\];,/\\]/g;
|
|
38
|
+
const replacement = nochars ? "" : "-";
|
|
39
|
+
return (0, import_slugify.default)(
|
|
40
|
+
value,
|
|
41
|
+
{
|
|
42
|
+
remove,
|
|
43
|
+
replacement,
|
|
44
|
+
lower: true,
|
|
45
|
+
trim: true
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
slugify
|
|
52
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import slug from 'slugify';
|
|
2
|
+
|
|
3
|
+
const slugify = ( value, nochars = false ) => {
|
|
4
|
+
|
|
5
|
+
const remove = nochars ? /[-?*+~.()'"!:@#^_{}\[\];,/\\]/g : /[?*+~.()'"!:@#^_{}\[\];,/\\]/g;
|
|
6
|
+
const replacement = nochars ? '' : '-';
|
|
7
|
+
|
|
8
|
+
return slug(
|
|
9
|
+
value,
|
|
10
|
+
{
|
|
11
|
+
remove,
|
|
12
|
+
replacement,
|
|
13
|
+
lower : true,
|
|
14
|
+
trim : true
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { slugify };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import slug from 'slugify';
|
|
2
|
+
|
|
3
|
+
const slugify = ( value, nochars = false ) => {
|
|
4
|
+
|
|
5
|
+
const remove = nochars ? /[-?*+~.()'"!:@#^_{}\[\];,/\\]/g : /[?*+~.()'"!:@#^_{}\[\];,/\\]/g;
|
|
6
|
+
const replacement = nochars ? '' : '-';
|
|
7
|
+
|
|
8
|
+
return slug(
|
|
9
|
+
value,
|
|
10
|
+
{
|
|
11
|
+
remove,
|
|
12
|
+
replacement,
|
|
13
|
+
lower : true,
|
|
14
|
+
trim : true
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { slugify };
|
package/dist/slugify.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// slugify.js
|
|
2
|
+
import slug from "slugify";
|
|
3
|
+
var slugify = (value, nochars = false) => {
|
|
4
|
+
const remove = nochars ? /[-?*+~.()'"!:@#^_{}\[\];,/\\]/g : /[?*+~.()'"!:@#^_{}\[\];,/\\]/g;
|
|
5
|
+
const replacement = nochars ? "" : "-";
|
|
6
|
+
return slug(
|
|
7
|
+
value,
|
|
8
|
+
{
|
|
9
|
+
remove,
|
|
10
|
+
replacement,
|
|
11
|
+
lower: true,
|
|
12
|
+
trim: true
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
slugify
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
"axios": "1.16.0",
|
|
5
5
|
"currency-codes": "2.2.0",
|
|
6
6
|
"nanoid": "3.3.8",
|
|
7
|
+
"qs": "6.15.1",
|
|
8
|
+
"slugify": "1.6.6",
|
|
7
9
|
"tsup": "8.5.1",
|
|
8
10
|
"typescript": "5.9.3"
|
|
9
11
|
},
|
|
@@ -42,6 +44,21 @@
|
|
|
42
44
|
"types": "./dist/redirect.d.ts",
|
|
43
45
|
"import": "./dist/redirect.js",
|
|
44
46
|
"require": "./dist/redirect.cjs"
|
|
47
|
+
},
|
|
48
|
+
"./cdn": {
|
|
49
|
+
"types": "./dist/cdn.d.ts",
|
|
50
|
+
"import": "./dist/cdn.js",
|
|
51
|
+
"require": "./dist/cdn.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./fetch": {
|
|
54
|
+
"types": "./dist/fetch.d.ts",
|
|
55
|
+
"import": "./dist/fetch.js",
|
|
56
|
+
"require": "./dist/fetch.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./slugify": {
|
|
59
|
+
"types": "./dist/slugify.d.ts",
|
|
60
|
+
"import": "./dist/slugify.js",
|
|
61
|
+
"require": "./dist/slugify.cjs"
|
|
45
62
|
}
|
|
46
63
|
},
|
|
47
64
|
"files": [
|
|
@@ -58,5 +75,5 @@
|
|
|
58
75
|
"build": "tsup && npm publish"
|
|
59
76
|
},
|
|
60
77
|
"types": "dist/index.d.ts",
|
|
61
|
-
"version": "0.0.
|
|
78
|
+
"version": "0.0.14"
|
|
62
79
|
}
|