@authhero/cloudflare-adapter 0.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cloudflare-adapter.cjs +2 -0
- package/dist/cloudflare-adapter.d.ts +13 -0
- package/dist/cloudflare-adapter.mjs +308 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 authhero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q="application/json",R="Content-Type",C=Symbol(),M=Symbol();function S(t={}){var e;const n=t instanceof Array?Object.fromEntries(t):t;return(e=Object.entries(n).find(([o])=>o.toLowerCase()===R.toLowerCase()))===null||e===void 0?void 0:e[1]}function D(t){return/^application\/.*json.*/.test(t)}const T=function(t,e,n=!1){return Object.entries(e).reduce((o,[i,l])=>{const h=t[i];return Array.isArray(h)&&Array.isArray(l)?o[i]=n?[...h,...l]:l:typeof h=="object"&&typeof l=="object"?o[i]=T(h,l,n):o[i]=l,o},{...t})},w={options:{},errorType:"text",polyfills:{},polyfill(t,e=!0,n=!1,...o){const i=this.polyfills[t]||(typeof self<"u"?self[t]:null)||(typeof global<"u"?global[t]:null);if(e&&!i)throw new Error(t+" is not defined");return n&&i?new i(...o):i}};function z(t,e=!1){w.options=e?t:T(w.options,t)}function F(t,e=!1){w.polyfills=e?t:T(w.polyfills,t)}function x(t){w.errorType=t}const L=t=>e=>t.reduceRight((n,o)=>o(n),e)||e;class k extends Error{}const N=t=>{const e=Object.create(null);t=t._addons.reduce((r,s)=>s.beforeRequest&&s.beforeRequest(r,t._options,e)||r,t);const{_url:n,_options:o,_config:i,_catchers:l,_resolvers:h,_middlewares:f,_addons:u}=t,a=new Map(l),m=T(i.options,o);let v=n;const E=L(f)((r,s)=>(v=r,i.polyfill("fetch")(r,s)))(n,m),d=new Error,g=E.catch(r=>{throw{[C]:r}}).then(r=>{var s;if(!r.ok){const c=new k;if(c.cause=d,c.stack=c.stack+`
|
|
2
|
+
CAUSE: `+d.stack,c.response=r,c.status=r.status,c.url=v,r.type==="opaque")throw c;const p=i.errorType==="json"||((s=r.headers.get("Content-Type"))===null||s===void 0?void 0:s.split(";")[0])==="application/json";return(i.errorType?p?r.text():r[i.errorType]():Promise.resolve(r.body)).then(y=>{throw c.message=typeof y=="string"?y:r.statusText,y&&(p&&typeof y=="string"?(c.text=y,c.json=JSON.parse(y)):c[i.errorType]=y),c})}return r}),P=r=>r.catch(s=>{const c=Object.prototype.hasOwnProperty.call(s,C),p=c?s[C]:s,A=(p==null?void 0:p.status)&&a.get(p.status)||a.get(p==null?void 0:p.name)||c&&a.has(C)&&a.get(C);if(A)return A(p,t);const y=a.get(M);if(y)return y(p,t);throw p}),_=r=>s=>P(r?g.then(c=>c&&c[r]()).then(c=>s?s(c):c):g.then(c=>s?s(c):c)),O={_wretchReq:t,_fetchReq:E,_sharedState:e,res:_(null),json:_("json"),blob:_("blob"),formData:_("formData"),arrayBuffer:_("arrayBuffer"),text:_("text"),error(r,s){return a.set(r,s),this},badRequest(r){return this.error(400,r)},unauthorized(r){return this.error(401,r)},forbidden(r){return this.error(403,r)},notFound(r){return this.error(404,r)},timeout(r){return this.error(408,r)},internalError(r){return this.error(500,r)},fetchError(r){return this.error(C,r)}},b=u.reduce((r,s)=>({...r,...typeof s.resolver=="function"?s.resolver(r):s.resolver}),O);return h.reduce((r,s)=>s(r,t),b)},B={_url:"",_options:{},_config:w,_catchers:new Map,_resolvers:[],_deferred:[],_middlewares:[],_addons:[],addon(t){return{...this,_addons:[...this._addons,t],...t.wretch}},errorType(t){return{...this,_config:{...this._config,errorType:t}}},polyfills(t,e=!1){return{...this,_config:{...this._config,polyfills:e?t:T(this._config.polyfills,t)}}},url(t,e=!1){if(e)return{...this,_url:t};const n=this._url.split("?");return{...this,_url:n.length>1?n[0]+t+"?"+n[1]:this._url+t}},options(t,e=!1){return{...this,_options:e?t:T(this._options,t)}},headers(t){const e=t?Array.isArray(t)?Object.fromEntries(t):"entries"in t?Object.fromEntries(t.entries()):t:{};return{...this,_options:T(this._options,{headers:e})}},accept(t){return this.headers({Accept:t})},content(t){return this.headers({[R]:t})},auth(t){return this.headers({Authorization:t})},catcher(t,e){const n=new Map(this._catchers);return n.set(t,e),{...this,_catchers:n}},catcherFallback(t){return this.catcher(M,t)},resolve(t,e=!1){return{...this,_resolvers:e?[t]:[...this._resolvers,t]}},defer(t,e=!1){return{...this,_deferred:e?[t]:[...this._deferred,t]}},middlewares(t,e=!1){return{...this,_middlewares:e?t:[...this._middlewares,...t]}},fetch(t=this._options.method,e="",n=null){let o=this.url(e).options({method:t});const i=S(o._options.headers),l=this._config.polyfill("FormData",!1),h=typeof n=="object"&&!(l&&n instanceof l)&&(!o._options.headers||!i||D(i));return o=n?h?o.json(n,i):o.body(n):o,N(o._deferred.reduce((f,u)=>u(f,f._url,f._options),o))},get(t=""){return this.fetch("GET",t)},delete(t=""){return this.fetch("DELETE",t)},put(t,e=""){return this.fetch("PUT",e,t)},post(t,e=""){return this.fetch("POST",e,t)},patch(t,e=""){return this.fetch("PATCH",e,t)},head(t=""){return this.fetch("HEAD",t)},opts(t=""){return this.fetch("OPTIONS",t)},body(t){return{...this,_options:{...this._options,body:t}}},json(t,e){const n=S(this._options.headers);return this.content(e||D(n)&&n||q).body(JSON.stringify(t))}};function j(t="",e={}){return{...B,_url:t,_options:e}}j.default=j;j.options=z;j.errorType=x;j.polyfills=F;j.WretchError=k;const J=(t,e)=>e.skipDedupe||e.method!=="GET",U=(t,e)=>e.method+"@"+t,$=t=>t.clone(),G=({skip:t=J,key:e=U,resolver:n=$}={})=>{const o=new Map;return i=>(l,h)=>{if(t(l,h))return i(l,h);const f=e(l,h);if(!o.has(f))o.set(f,[]);else return new Promise((u,a)=>{o.get(f).push([u,a])});try{return i(l,h).then(u=>(o.get(f).forEach(([a])=>a(n(u))),o.delete(f),u)).catch(u=>{throw o.get(f).forEach(([,a])=>a(u)),o.delete(f),u})}catch(u){return o.delete(f),Promise.reject(u)}}},I=(t,e)=>t*e,K=t=>t&&t.ok,W=({delayTimer:t=500,delayRamp:e=I,maxAttempts:n=10,until:o=K,onRetry:i=null,retryOnNetworkError:l=!1,resolveWithLatestResponse:h=!1,skip:f}={})=>u=>(a,m)=>{let v=0;if(f&&f(a,m))return u(a,m);const E=(d,g)=>Promise.resolve(o(d,g)).then(P=>P?d&&h?d:g?Promise.reject(g):d:(v++,!n||v<=n?new Promise(_=>{const O=e(t,v);setTimeout(()=>{typeof i=="function"?Promise.resolve(i({response:d,error:g,url:a,options:m})).then((b={})=>{var r,s;_(u((r=b&&b.url)!==null&&r!==void 0?r:a,(s=b&&b.options)!==null&&s!==void 0?s:m))}):_(u(a,m))},O)}).then(E).catch(_=>{if(!l)throw _;return E(null,_)}):d&&h?d:Promise.reject(g||new Error("Number of attempts exceeded."))));return u(a,m).then(E).catch(d=>{if(!l)throw d;return E(null,d)})};function H(t){return j(`https://api.cloudflare.com/client/v4/zones/${t.zone_id}`).headers({Authorization:`Bearer ${t.api_key}`,"Content-Type":"application/json"}).middlewares([W(),G()])}async function Y(t){return await H(t).post({hostname:t.domain,ssl:{method:"http",type:"dv"}},"/custom_hostnames").json()}async function Q(t){return await H(t).get(`/custom_hostnames/${t.domain}`).json()}exports.getCustomDomain=Q;exports.registerCustomDomain=Y;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
export interface CloudflareApiParams {
|
|
4
|
+
zone_id: string;
|
|
5
|
+
api_key: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CustomDomainsParams extends CloudflareApiParams {
|
|
8
|
+
domain: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerCustomDomain(params: CustomDomainsParams): Promise<unknown>;
|
|
11
|
+
export declare function getCustomDomain(params: CustomDomainsParams): Promise<unknown>;
|
|
12
|
+
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
const q = "application/json", D = "Content-Type", w = Symbol(), M = Symbol();
|
|
2
|
+
function R(t = {}) {
|
|
3
|
+
var e;
|
|
4
|
+
const n = t instanceof Array ? Object.fromEntries(t) : t;
|
|
5
|
+
return (e = Object.entries(n).find(([o]) => o.toLowerCase() === D.toLowerCase())) === null || e === void 0 ? void 0 : e[1];
|
|
6
|
+
}
|
|
7
|
+
function S(t) {
|
|
8
|
+
return /^application\/.*json.*/.test(t);
|
|
9
|
+
}
|
|
10
|
+
const T = function(t, e, n = !1) {
|
|
11
|
+
return Object.entries(e).reduce((o, [i, l]) => {
|
|
12
|
+
const h = t[i];
|
|
13
|
+
return Array.isArray(h) && Array.isArray(l) ? o[i] = n ? [...h, ...l] : l : typeof h == "object" && typeof l == "object" ? o[i] = T(h, l, n) : o[i] = l, o;
|
|
14
|
+
}, { ...t });
|
|
15
|
+
}, C = {
|
|
16
|
+
// Default options
|
|
17
|
+
options: {},
|
|
18
|
+
// Error type
|
|
19
|
+
errorType: "text",
|
|
20
|
+
// Polyfills
|
|
21
|
+
polyfills: {
|
|
22
|
+
// fetch: null,
|
|
23
|
+
// FormData: null,
|
|
24
|
+
// URL: null,
|
|
25
|
+
// URLSearchParams: null,
|
|
26
|
+
// performance: null,
|
|
27
|
+
// PerformanceObserver: null,
|
|
28
|
+
// AbortController: null,
|
|
29
|
+
},
|
|
30
|
+
polyfill(t, e = !0, n = !1, ...o) {
|
|
31
|
+
const i = this.polyfills[t] || (typeof self < "u" ? self[t] : null) || (typeof global < "u" ? global[t] : null);
|
|
32
|
+
if (e && !i)
|
|
33
|
+
throw new Error(t + " is not defined");
|
|
34
|
+
return n && i ? new i(...o) : i;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function x(t, e = !1) {
|
|
38
|
+
C.options = e ? t : T(C.options, t);
|
|
39
|
+
}
|
|
40
|
+
function z(t, e = !1) {
|
|
41
|
+
C.polyfills = e ? t : T(C.polyfills, t);
|
|
42
|
+
}
|
|
43
|
+
function F(t) {
|
|
44
|
+
C.errorType = t;
|
|
45
|
+
}
|
|
46
|
+
const L = (t) => (e) => t.reduceRight((n, o) => o(n), e) || e;
|
|
47
|
+
class k extends Error {
|
|
48
|
+
}
|
|
49
|
+
const N = (t) => {
|
|
50
|
+
const e = /* @__PURE__ */ Object.create(null);
|
|
51
|
+
t = t._addons.reduce((r, s) => s.beforeRequest && s.beforeRequest(r, t._options, e) || r, t);
|
|
52
|
+
const { _url: n, _options: o, _config: i, _catchers: l, _resolvers: h, _middlewares: f, _addons: u } = t, a = new Map(l), m = T(i.options, o);
|
|
53
|
+
let v = n;
|
|
54
|
+
const E = L(f)((r, s) => (v = r, i.polyfill("fetch")(r, s)))(n, m), d = new Error(), g = E.catch((r) => {
|
|
55
|
+
throw { [w]: r };
|
|
56
|
+
}).then((r) => {
|
|
57
|
+
var s;
|
|
58
|
+
if (!r.ok) {
|
|
59
|
+
const c = new k();
|
|
60
|
+
if (c.cause = d, c.stack = c.stack + `
|
|
61
|
+
CAUSE: ` + d.stack, c.response = r, c.status = r.status, c.url = v, r.type === "opaque")
|
|
62
|
+
throw c;
|
|
63
|
+
const p = i.errorType === "json" || ((s = r.headers.get("Content-Type")) === null || s === void 0 ? void 0 : s.split(";")[0]) === "application/json";
|
|
64
|
+
return (i.errorType ? p ? r.text() : r[i.errorType]() : Promise.resolve(r.body)).then((y) => {
|
|
65
|
+
throw c.message = typeof y == "string" ? y : r.statusText, y && (p && typeof y == "string" ? (c.text = y, c.json = JSON.parse(y)) : c[i.errorType] = y), c;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return r;
|
|
69
|
+
}), P = (r) => r.catch((s) => {
|
|
70
|
+
const c = Object.prototype.hasOwnProperty.call(s, w), p = c ? s[w] : s, A = (p == null ? void 0 : p.status) && a.get(p.status) || a.get(p == null ? void 0 : p.name) || c && a.has(w) && a.get(w);
|
|
71
|
+
if (A)
|
|
72
|
+
return A(p, t);
|
|
73
|
+
const y = a.get(M);
|
|
74
|
+
if (y)
|
|
75
|
+
return y(p, t);
|
|
76
|
+
throw p;
|
|
77
|
+
}), _ = (r) => (s) => /* If a callback is provided, then callback with the body result otherwise return the parsed body itself. */ P(r ? g.then((c) => c && c[r]()).then((c) => s ? s(c) : c) : g.then((c) => s ? s(c) : c)), O = {
|
|
78
|
+
_wretchReq: t,
|
|
79
|
+
_fetchReq: E,
|
|
80
|
+
_sharedState: e,
|
|
81
|
+
res: _(null),
|
|
82
|
+
json: _("json"),
|
|
83
|
+
blob: _("blob"),
|
|
84
|
+
formData: _("formData"),
|
|
85
|
+
arrayBuffer: _("arrayBuffer"),
|
|
86
|
+
text: _("text"),
|
|
87
|
+
error(r, s) {
|
|
88
|
+
return a.set(r, s), this;
|
|
89
|
+
},
|
|
90
|
+
badRequest(r) {
|
|
91
|
+
return this.error(400, r);
|
|
92
|
+
},
|
|
93
|
+
unauthorized(r) {
|
|
94
|
+
return this.error(401, r);
|
|
95
|
+
},
|
|
96
|
+
forbidden(r) {
|
|
97
|
+
return this.error(403, r);
|
|
98
|
+
},
|
|
99
|
+
notFound(r) {
|
|
100
|
+
return this.error(404, r);
|
|
101
|
+
},
|
|
102
|
+
timeout(r) {
|
|
103
|
+
return this.error(408, r);
|
|
104
|
+
},
|
|
105
|
+
internalError(r) {
|
|
106
|
+
return this.error(500, r);
|
|
107
|
+
},
|
|
108
|
+
fetchError(r) {
|
|
109
|
+
return this.error(w, r);
|
|
110
|
+
}
|
|
111
|
+
}, b = u.reduce((r, s) => ({
|
|
112
|
+
...r,
|
|
113
|
+
...typeof s.resolver == "function" ? s.resolver(r) : s.resolver
|
|
114
|
+
}), O);
|
|
115
|
+
return h.reduce((r, s) => s(r, t), b);
|
|
116
|
+
}, B = {
|
|
117
|
+
_url: "",
|
|
118
|
+
_options: {},
|
|
119
|
+
_config: C,
|
|
120
|
+
_catchers: /* @__PURE__ */ new Map(),
|
|
121
|
+
_resolvers: [],
|
|
122
|
+
_deferred: [],
|
|
123
|
+
_middlewares: [],
|
|
124
|
+
_addons: [],
|
|
125
|
+
addon(t) {
|
|
126
|
+
return { ...this, _addons: [...this._addons, t], ...t.wretch };
|
|
127
|
+
},
|
|
128
|
+
errorType(t) {
|
|
129
|
+
return {
|
|
130
|
+
...this,
|
|
131
|
+
_config: {
|
|
132
|
+
...this._config,
|
|
133
|
+
errorType: t
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
polyfills(t, e = !1) {
|
|
138
|
+
return {
|
|
139
|
+
...this,
|
|
140
|
+
_config: {
|
|
141
|
+
...this._config,
|
|
142
|
+
polyfills: e ? t : T(this._config.polyfills, t)
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
url(t, e = !1) {
|
|
147
|
+
if (e)
|
|
148
|
+
return { ...this, _url: t };
|
|
149
|
+
const n = this._url.split("?");
|
|
150
|
+
return {
|
|
151
|
+
...this,
|
|
152
|
+
_url: n.length > 1 ? n[0] + t + "?" + n[1] : this._url + t
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
options(t, e = !1) {
|
|
156
|
+
return { ...this, _options: e ? t : T(this._options, t) };
|
|
157
|
+
},
|
|
158
|
+
headers(t) {
|
|
159
|
+
const e = t ? Array.isArray(t) ? Object.fromEntries(t) : "entries" in t ? Object.fromEntries(t.entries()) : t : {};
|
|
160
|
+
return { ...this, _options: T(this._options, { headers: e }) };
|
|
161
|
+
},
|
|
162
|
+
accept(t) {
|
|
163
|
+
return this.headers({ Accept: t });
|
|
164
|
+
},
|
|
165
|
+
content(t) {
|
|
166
|
+
return this.headers({ [D]: t });
|
|
167
|
+
},
|
|
168
|
+
auth(t) {
|
|
169
|
+
return this.headers({ Authorization: t });
|
|
170
|
+
},
|
|
171
|
+
catcher(t, e) {
|
|
172
|
+
const n = new Map(this._catchers);
|
|
173
|
+
return n.set(t, e), { ...this, _catchers: n };
|
|
174
|
+
},
|
|
175
|
+
catcherFallback(t) {
|
|
176
|
+
return this.catcher(M, t);
|
|
177
|
+
},
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
179
|
+
resolve(t, e = !1) {
|
|
180
|
+
return { ...this, _resolvers: e ? [t] : [...this._resolvers, t] };
|
|
181
|
+
},
|
|
182
|
+
defer(t, e = !1) {
|
|
183
|
+
return {
|
|
184
|
+
...this,
|
|
185
|
+
_deferred: e ? [t] : [...this._deferred, t]
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
middlewares(t, e = !1) {
|
|
189
|
+
return {
|
|
190
|
+
...this,
|
|
191
|
+
_middlewares: e ? t : [...this._middlewares, ...t]
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
fetch(t = this._options.method, e = "", n = null) {
|
|
195
|
+
let o = this.url(e).options({ method: t });
|
|
196
|
+
const i = R(o._options.headers), l = this._config.polyfill("FormData", !1), h = typeof n == "object" && !(l && n instanceof l) && (!o._options.headers || !i || S(i));
|
|
197
|
+
return o = n ? h ? o.json(n, i) : o.body(n) : o, N(o._deferred.reduce((f, u) => u(f, f._url, f._options), o));
|
|
198
|
+
},
|
|
199
|
+
get(t = "") {
|
|
200
|
+
return this.fetch("GET", t);
|
|
201
|
+
},
|
|
202
|
+
delete(t = "") {
|
|
203
|
+
return this.fetch("DELETE", t);
|
|
204
|
+
},
|
|
205
|
+
put(t, e = "") {
|
|
206
|
+
return this.fetch("PUT", e, t);
|
|
207
|
+
},
|
|
208
|
+
post(t, e = "") {
|
|
209
|
+
return this.fetch("POST", e, t);
|
|
210
|
+
},
|
|
211
|
+
patch(t, e = "") {
|
|
212
|
+
return this.fetch("PATCH", e, t);
|
|
213
|
+
},
|
|
214
|
+
head(t = "") {
|
|
215
|
+
return this.fetch("HEAD", t);
|
|
216
|
+
},
|
|
217
|
+
opts(t = "") {
|
|
218
|
+
return this.fetch("OPTIONS", t);
|
|
219
|
+
},
|
|
220
|
+
body(t) {
|
|
221
|
+
return { ...this, _options: { ...this._options, body: t } };
|
|
222
|
+
},
|
|
223
|
+
json(t, e) {
|
|
224
|
+
const n = R(this._options.headers);
|
|
225
|
+
return this.content(e || S(n) && n || q).body(JSON.stringify(t));
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
function j(t = "", e = {}) {
|
|
229
|
+
return { ...B, _url: t, _options: e };
|
|
230
|
+
}
|
|
231
|
+
j.default = j;
|
|
232
|
+
j.options = x;
|
|
233
|
+
j.errorType = F;
|
|
234
|
+
j.polyfills = z;
|
|
235
|
+
j.WretchError = k;
|
|
236
|
+
const J = (t, e) => e.skipDedupe || e.method !== "GET", U = (t, e) => e.method + "@" + t, $ = (t) => t.clone(), G = ({ skip: t = J, key: e = U, resolver: n = $ } = {}) => {
|
|
237
|
+
const o = /* @__PURE__ */ new Map();
|
|
238
|
+
return (i) => (l, h) => {
|
|
239
|
+
if (t(l, h))
|
|
240
|
+
return i(l, h);
|
|
241
|
+
const f = e(l, h);
|
|
242
|
+
if (!o.has(f))
|
|
243
|
+
o.set(f, []);
|
|
244
|
+
else
|
|
245
|
+
return new Promise((u, a) => {
|
|
246
|
+
o.get(f).push([u, a]);
|
|
247
|
+
});
|
|
248
|
+
try {
|
|
249
|
+
return i(l, h).then((u) => (o.get(f).forEach(([a]) => a(n(u))), o.delete(f), u)).catch((u) => {
|
|
250
|
+
throw o.get(f).forEach(([, a]) => a(u)), o.delete(f), u;
|
|
251
|
+
});
|
|
252
|
+
} catch (u) {
|
|
253
|
+
return o.delete(f), Promise.reject(u);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}, I = (t, e) => t * e, K = (t) => t && t.ok, W = ({ delayTimer: t = 500, delayRamp: e = I, maxAttempts: n = 10, until: o = K, onRetry: i = null, retryOnNetworkError: l = !1, resolveWithLatestResponse: h = !1, skip: f } = {}) => (u) => (a, m) => {
|
|
257
|
+
let v = 0;
|
|
258
|
+
if (f && f(a, m))
|
|
259
|
+
return u(a, m);
|
|
260
|
+
const E = (d, g) => Promise.resolve(o(d, g)).then((P) => P ? d && h ? d : g ? Promise.reject(g) : d : (v++, !n || v <= n ? new Promise((_) => {
|
|
261
|
+
const O = e(t, v);
|
|
262
|
+
setTimeout(() => {
|
|
263
|
+
typeof i == "function" ? Promise.resolve(i({
|
|
264
|
+
response: d,
|
|
265
|
+
error: g,
|
|
266
|
+
url: a,
|
|
267
|
+
options: m
|
|
268
|
+
})).then((b = {}) => {
|
|
269
|
+
var r, s;
|
|
270
|
+
_(u((r = b && b.url) !== null && r !== void 0 ? r : a, (s = b && b.options) !== null && s !== void 0 ? s : m));
|
|
271
|
+
}) : _(u(a, m));
|
|
272
|
+
}, O);
|
|
273
|
+
}).then(E).catch((_) => {
|
|
274
|
+
if (!l)
|
|
275
|
+
throw _;
|
|
276
|
+
return E(null, _);
|
|
277
|
+
}) : d && h ? d : Promise.reject(g || new Error("Number of attempts exceeded."))));
|
|
278
|
+
return u(a, m).then(E).catch((d) => {
|
|
279
|
+
if (!l)
|
|
280
|
+
throw d;
|
|
281
|
+
return E(null, d);
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
function H(t) {
|
|
285
|
+
return j(`https://api.cloudflare.com/client/v4/zones/${t.zone_id}`).headers({
|
|
286
|
+
Authorization: `Bearer ${t.api_key}`,
|
|
287
|
+
"Content-Type": "application/json"
|
|
288
|
+
}).middlewares([W(), G()]);
|
|
289
|
+
}
|
|
290
|
+
async function Y(t) {
|
|
291
|
+
return await H(t).post(
|
|
292
|
+
{
|
|
293
|
+
hostname: t.domain,
|
|
294
|
+
ssl: {
|
|
295
|
+
method: "http",
|
|
296
|
+
type: "dv"
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
"/custom_hostnames"
|
|
300
|
+
).json();
|
|
301
|
+
}
|
|
302
|
+
async function Q(t) {
|
|
303
|
+
return await H(t).get(`/custom_hostnames/${t.domain}`).json();
|
|
304
|
+
}
|
|
305
|
+
export {
|
|
306
|
+
Q as getCustomDomain,
|
|
307
|
+
Y as registerCustomDomain
|
|
308
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@authhero/cloudflare-adapter",
|
|
3
|
+
"private": false,
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org/",
|
|
7
|
+
"tag": "latest"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://authhero.net",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
|
+
},
|
|
14
|
+
"version": "0.1.0",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/cloudflare-adapter.cjs",
|
|
19
|
+
"module": "dist/cloudflare-adapter.mjs",
|
|
20
|
+
"types": "dist/cloudflare-adapter.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"require": "./dist/cloudflare-adapter.cjs",
|
|
24
|
+
"import": "./dist/cloudflare-adapter.mjs",
|
|
25
|
+
"types": "./dist/cloudflare-adapter.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
30
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
31
|
+
"@types/node": "^22.9.1",
|
|
32
|
+
"dts-bundle-generator": "^9.5.1",
|
|
33
|
+
"typescript": "^5.6.3",
|
|
34
|
+
"vite": "^5.4.11",
|
|
35
|
+
"vitest": "^2.1.5",
|
|
36
|
+
"@authhero/adapter-interfaces": "0.48.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@authhero/adapter-interfaces": "0.48.0"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"wretch": "^2.11.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
|
|
46
|
+
"test": "vitest run"
|
|
47
|
+
}
|
|
48
|
+
}
|