@epcc-sdk/sdks-shopper 0.0.36 → 0.0.38
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/README.md +79 -0
- package/dist/auth/configure-client.cjs +94 -0
- package/dist/auth/configure-client.cjs.map +1 -0
- package/dist/auth/configure-client.d.cts +59 -0
- package/dist/auth/configure-client.d.ts +59 -0
- package/dist/auth/configure-client.mjs +74 -0
- package/dist/auth/configure-client.mjs.map +1 -0
- package/dist/auth/kit.cjs +97 -0
- package/dist/auth/kit.cjs.map +1 -0
- package/dist/auth/kit.d.cts +15 -0
- package/dist/auth/kit.d.ts +15 -0
- package/dist/auth/kit.mjs +73 -0
- package/dist/auth/kit.mjs.map +1 -0
- package/dist/auth/make-auth-fetch.cjs +53 -0
- package/dist/auth/make-auth-fetch.cjs.map +1 -0
- package/dist/auth/make-auth-fetch.d.cts +16 -0
- package/dist/auth/make-auth-fetch.d.ts +16 -0
- package/dist/auth/make-auth-fetch.mjs +29 -0
- package/dist/auth/make-auth-fetch.mjs.map +1 -0
- package/dist/auth/storage.cjs +118 -0
- package/dist/auth/storage.cjs.map +1 -0
- package/dist/auth/storage.d.cts +23 -0
- package/dist/auth/storage.d.ts +23 -0
- package/dist/auth/storage.mjs +92 -0
- package/dist/auth/storage.mjs.map +1 -0
- package/dist/auth/token-providers.cjs +82 -0
- package/dist/auth/token-providers.cjs.map +1 -0
- package/dist/auth/token-providers.d.cts +28 -0
- package/dist/auth/token-providers.d.ts +28 -0
- package/dist/auth/token-providers.mjs +57 -0
- package/dist/auth/token-providers.mjs.map +1 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/dist/test/utils.cjs +38 -0
- package/dist/test/utils.cjs.map +1 -0
- package/dist/test/utils.d.cts +10 -0
- package/dist/test/utils.d.ts +10 -0
- package/dist/test/utils.mjs +13 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var make_auth_fetch_exports = {};
|
|
20
|
+
__export(make_auth_fetch_exports, {
|
|
21
|
+
makeAuthFetch: () => makeAuthFetch
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(make_auth_fetch_exports);
|
|
24
|
+
function makeAuthFetch(auth, baseFetch, opts) {
|
|
25
|
+
const fetchFn = baseFetch || ((request) => globalThis.fetch(request));
|
|
26
|
+
return async (request) => {
|
|
27
|
+
const url = request.url;
|
|
28
|
+
if (opts?.isAuthRequest?.(url, {}) ?? url.includes("/oauth/")) {
|
|
29
|
+
return fetchFn(request);
|
|
30
|
+
}
|
|
31
|
+
const token = await auth.getValidAccessToken();
|
|
32
|
+
const h1 = new Headers(request.headers);
|
|
33
|
+
if (!h1.has("Authorization")) h1.set("Authorization", `Bearer ${token}`);
|
|
34
|
+
const authedRequest = new Request(request, { headers: h1 });
|
|
35
|
+
let res = await fetchFn(authedRequest);
|
|
36
|
+
if (res.status !== 401) return res;
|
|
37
|
+
try {
|
|
38
|
+
const fresh = await auth.refresh();
|
|
39
|
+
const h2 = new Headers(request.headers);
|
|
40
|
+
if (!h2.has("Authorization")) h2.set("Authorization", `Bearer ${fresh}`);
|
|
41
|
+
const retryRequest = new Request(request, { headers: h2 });
|
|
42
|
+
return fetchFn(retryRequest);
|
|
43
|
+
} catch {
|
|
44
|
+
auth.clear();
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
makeAuthFetch
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=make-auth-fetch.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/make-auth-fetch.ts"],"sourcesContent":["import type { Auth } from \"./kit\"\nimport { Config } from \"@hey-api/client-fetch\"\n\n/**\n * Wrap a base fetch (default: global fetch) with:\n * - Authorization: Bearer <token> (unless caller already set it)\n * - single forced re-auth + one retry on 401\n * - optional skip for OAuth endpoints\n */\nexport function makeAuthFetch(\n auth: Auth,\n baseFetch?: Config[\"fetch\"],\n opts?: { isAuthRequest?: (url: string, init: RequestInit) => boolean },\n): Config[\"fetch\"] {\n // Default to global fetch if not provided\n const fetchFn = baseFetch || ((request: Request) => globalThis.fetch(request))\n\n return async (request: Request) => {\n const url = request.url\n\n // Never intercept OAuth calls (avoid loops)\n if (opts?.isAuthRequest?.(url, {}) ?? url.includes(\"/oauth/\")) {\n return fetchFn(request)\n }\n\n // Clone the request to modify headers\n const token = await auth.getValidAccessToken()\n const h1 = new Headers(request.headers)\n if (!h1.has(\"Authorization\")) h1.set(\"Authorization\", `Bearer ${token}`)\n\n const authedRequest = new Request(request, { headers: h1 })\n let res = await fetchFn(authedRequest)\n\n if (res.status !== 401) return res\n\n // Retry once after forced re-auth\n try {\n const fresh = await auth.refresh()\n const h2 = new Headers(request.headers)\n if (!h2.has(\"Authorization\")) h2.set(\"Authorization\", `Bearer ${fresh}`)\n\n const retryRequest = new Request(request, { headers: h2 })\n return fetchFn(retryRequest)\n } catch {\n auth.clear()\n return res // bubble the 401\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,cACd,MACA,WACA,MACiB;AAEjB,QAAM,UAAU,cAAc,CAAC,YAAqB,WAAW,MAAM,OAAO;AAE5E,SAAO,OAAO,YAAqB;AACjC,UAAM,MAAM,QAAQ;AAGpB,QAAI,MAAM,gBAAgB,KAAK,CAAC,CAAC,KAAK,IAAI,SAAS,SAAS,GAAG;AAC7D,aAAO,QAAQ,OAAO;AAAA,IACxB;AAGA,UAAM,QAAQ,MAAM,KAAK,oBAAoB;AAC7C,UAAM,KAAK,IAAI,QAAQ,QAAQ,OAAO;AACtC,QAAI,CAAC,GAAG,IAAI,eAAe,EAAG,IAAG,IAAI,iBAAiB,UAAU,KAAK,EAAE;AAEvE,UAAM,gBAAgB,IAAI,QAAQ,SAAS,EAAE,SAAS,GAAG,CAAC;AAC1D,QAAI,MAAM,MAAM,QAAQ,aAAa;AAErC,QAAI,IAAI,WAAW,IAAK,QAAO;AAG/B,QAAI;AACF,YAAM,QAAQ,MAAM,KAAK,QAAQ;AACjC,YAAM,KAAK,IAAI,QAAQ,QAAQ,OAAO;AACtC,UAAI,CAAC,GAAG,IAAI,eAAe,EAAG,IAAG,IAAI,iBAAiB,UAAU,KAAK,EAAE;AAEvE,YAAM,eAAe,IAAI,QAAQ,SAAS,EAAE,SAAS,GAAG,CAAC;AACzD,aAAO,QAAQ,YAAY;AAAA,IAC7B,QAAQ;AACN,WAAK,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Auth } from './kit.cjs';
|
|
2
|
+
import { Config } from '@hey-api/client-fetch';
|
|
3
|
+
import './storage.cjs';
|
|
4
|
+
import '../client/types.gen.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a base fetch (default: global fetch) with:
|
|
8
|
+
* - Authorization: Bearer <token> (unless caller already set it)
|
|
9
|
+
* - single forced re-auth + one retry on 401
|
|
10
|
+
* - optional skip for OAuth endpoints
|
|
11
|
+
*/
|
|
12
|
+
declare function makeAuthFetch(auth: Auth, baseFetch?: Config["fetch"], opts?: {
|
|
13
|
+
isAuthRequest?: (url: string, init: RequestInit) => boolean;
|
|
14
|
+
}): Config["fetch"];
|
|
15
|
+
|
|
16
|
+
export { makeAuthFetch };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Auth } from './kit.js';
|
|
2
|
+
import { Config } from '@hey-api/client-fetch';
|
|
3
|
+
import './storage.js';
|
|
4
|
+
import '../client/types.gen.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a base fetch (default: global fetch) with:
|
|
8
|
+
* - Authorization: Bearer <token> (unless caller already set it)
|
|
9
|
+
* - single forced re-auth + one retry on 401
|
|
10
|
+
* - optional skip for OAuth endpoints
|
|
11
|
+
*/
|
|
12
|
+
declare function makeAuthFetch(auth: Auth, baseFetch?: Config["fetch"], opts?: {
|
|
13
|
+
isAuthRequest?: (url: string, init: RequestInit) => boolean;
|
|
14
|
+
}): Config["fetch"];
|
|
15
|
+
|
|
16
|
+
export { makeAuthFetch };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function makeAuthFetch(auth, baseFetch, opts) {
|
|
2
|
+
const fetchFn = baseFetch || ((request) => globalThis.fetch(request));
|
|
3
|
+
return async (request) => {
|
|
4
|
+
const url = request.url;
|
|
5
|
+
if (opts?.isAuthRequest?.(url, {}) ?? url.includes("/oauth/")) {
|
|
6
|
+
return fetchFn(request);
|
|
7
|
+
}
|
|
8
|
+
const token = await auth.getValidAccessToken();
|
|
9
|
+
const h1 = new Headers(request.headers);
|
|
10
|
+
if (!h1.has("Authorization")) h1.set("Authorization", `Bearer ${token}`);
|
|
11
|
+
const authedRequest = new Request(request, { headers: h1 });
|
|
12
|
+
let res = await fetchFn(authedRequest);
|
|
13
|
+
if (res.status !== 401) return res;
|
|
14
|
+
try {
|
|
15
|
+
const fresh = await auth.refresh();
|
|
16
|
+
const h2 = new Headers(request.headers);
|
|
17
|
+
if (!h2.has("Authorization")) h2.set("Authorization", `Bearer ${fresh}`);
|
|
18
|
+
const retryRequest = new Request(request, { headers: h2 });
|
|
19
|
+
return fetchFn(retryRequest);
|
|
20
|
+
} catch {
|
|
21
|
+
auth.clear();
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
makeAuthFetch
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=make-auth-fetch.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/make-auth-fetch.ts"],"sourcesContent":["import type { Auth } from \"./kit\"\nimport { Config } from \"@hey-api/client-fetch\"\n\n/**\n * Wrap a base fetch (default: global fetch) with:\n * - Authorization: Bearer <token> (unless caller already set it)\n * - single forced re-auth + one retry on 401\n * - optional skip for OAuth endpoints\n */\nexport function makeAuthFetch(\n auth: Auth,\n baseFetch?: Config[\"fetch\"],\n opts?: { isAuthRequest?: (url: string, init: RequestInit) => boolean },\n): Config[\"fetch\"] {\n // Default to global fetch if not provided\n const fetchFn = baseFetch || ((request: Request) => globalThis.fetch(request))\n\n return async (request: Request) => {\n const url = request.url\n\n // Never intercept OAuth calls (avoid loops)\n if (opts?.isAuthRequest?.(url, {}) ?? url.includes(\"/oauth/\")) {\n return fetchFn(request)\n }\n\n // Clone the request to modify headers\n const token = await auth.getValidAccessToken()\n const h1 = new Headers(request.headers)\n if (!h1.has(\"Authorization\")) h1.set(\"Authorization\", `Bearer ${token}`)\n\n const authedRequest = new Request(request, { headers: h1 })\n let res = await fetchFn(authedRequest)\n\n if (res.status !== 401) return res\n\n // Retry once after forced re-auth\n try {\n const fresh = await auth.refresh()\n const h2 = new Headers(request.headers)\n if (!h2.has(\"Authorization\")) h2.set(\"Authorization\", `Bearer ${fresh}`)\n\n const retryRequest = new Request(request, { headers: h2 })\n return fetchFn(retryRequest)\n } catch {\n auth.clear()\n return res // bubble the 401\n }\n }\n}\n"],"mappings":"AASO,SAAS,cACd,MACA,WACA,MACiB;AAEjB,QAAM,UAAU,cAAc,CAAC,YAAqB,WAAW,MAAM,OAAO;AAE5E,SAAO,OAAO,YAAqB;AACjC,UAAM,MAAM,QAAQ;AAGpB,QAAI,MAAM,gBAAgB,KAAK,CAAC,CAAC,KAAK,IAAI,SAAS,SAAS,GAAG;AAC7D,aAAO,QAAQ,OAAO;AAAA,IACxB;AAGA,UAAM,QAAQ,MAAM,KAAK,oBAAoB;AAC7C,UAAM,KAAK,IAAI,QAAQ,QAAQ,OAAO;AACtC,QAAI,CAAC,GAAG,IAAI,eAAe,EAAG,IAAG,IAAI,iBAAiB,UAAU,KAAK,EAAE;AAEvE,UAAM,gBAAgB,IAAI,QAAQ,SAAS,EAAE,SAAS,GAAG,CAAC;AAC1D,QAAI,MAAM,MAAM,QAAQ,aAAa;AAErC,QAAI,IAAI,WAAW,IAAK,QAAO;AAG/B,QAAI;AACF,YAAM,QAAQ,MAAM,KAAK,QAAQ;AACjC,YAAM,KAAK,IAAI,QAAQ,QAAQ,OAAO;AACtC,UAAI,CAAC,GAAG,IAAI,eAAe,EAAG,IAAG,IAAI,iBAAiB,UAAU,KAAK,EAAE;AAEvE,YAAM,eAAe,IAAI,QAAQ,SAAS,EAAE,SAAS,GAAG,CAAC;AACzD,aAAO,QAAQ,YAAY;AAAA,IAC7B,QAAQ;AACN,WAAK,MAAM;AACX,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var storage_exports = {};
|
|
20
|
+
__export(storage_exports, {
|
|
21
|
+
cookieAdapter: () => cookieAdapter,
|
|
22
|
+
localStorageAdapter: () => localStorageAdapter,
|
|
23
|
+
memoryAdapter: () => memoryAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(storage_exports);
|
|
26
|
+
var import_credentials = require('../constants/credentials.cjs');
|
|
27
|
+
function localStorageAdapter(key = import_credentials.CREDENTIALS_STORAGE_KEY) {
|
|
28
|
+
const subs = /* @__PURE__ */ new Set();
|
|
29
|
+
const onStorage = (e) => {
|
|
30
|
+
if (e.key === key) subs.forEach((fn) => fn());
|
|
31
|
+
};
|
|
32
|
+
const safeGet = () => {
|
|
33
|
+
try {
|
|
34
|
+
if (typeof window === "undefined" || !("localStorage" in window))
|
|
35
|
+
return void 0;
|
|
36
|
+
return window.localStorage.getItem(key) ?? void 0;
|
|
37
|
+
} catch {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const safeSet = (t) => {
|
|
42
|
+
try {
|
|
43
|
+
if (typeof window === "undefined" || !("localStorage" in window)) return;
|
|
44
|
+
if (!t) window.localStorage.removeItem(key);
|
|
45
|
+
else window.localStorage.setItem(key, t);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
get: safeGet,
|
|
51
|
+
set: safeSet,
|
|
52
|
+
subscribe(cb) {
|
|
53
|
+
subs.add(cb);
|
|
54
|
+
if (typeof window !== "undefined") {
|
|
55
|
+
window.addEventListener("storage", onStorage);
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
subs.delete(cb);
|
|
59
|
+
if (!subs.size && typeof window !== "undefined") {
|
|
60
|
+
window.removeEventListener("storage", onStorage);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function cookieAdapter(options = {}) {
|
|
67
|
+
const { name = import_credentials.CREDENTIALS_STORAGE_KEY, ...attrs } = options;
|
|
68
|
+
const { path = "/", sameSite = "Lax" } = attrs;
|
|
69
|
+
const read = () => {
|
|
70
|
+
if (typeof document === "undefined") return void 0;
|
|
71
|
+
const raw = document.cookie.split("; ").find((c) => c.startsWith(name + "="));
|
|
72
|
+
if (!raw) return void 0;
|
|
73
|
+
try {
|
|
74
|
+
return decodeURIComponent(raw.split("=").slice(1).join("="));
|
|
75
|
+
} catch {
|
|
76
|
+
return raw.split("=").slice(1).join("=");
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const write = (v) => {
|
|
80
|
+
if (typeof document === "undefined") return;
|
|
81
|
+
let s = `${name}=${encodeURIComponent(v)}; Path=${path}; SameSite=${sameSite}`;
|
|
82
|
+
if (attrs.domain) s += `; Domain=${attrs.domain}`;
|
|
83
|
+
if (attrs.secure) s += `; Secure`;
|
|
84
|
+
if (attrs.maxAge) s += `; Max-Age=${attrs.maxAge}`;
|
|
85
|
+
document.cookie = s;
|
|
86
|
+
};
|
|
87
|
+
const clear = () => {
|
|
88
|
+
if (typeof document === "undefined") return;
|
|
89
|
+
document.cookie = `${name}=; Max-Age=0; Path=${path}`;
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
get: read,
|
|
93
|
+
set: (t) => t ? write(t) : clear()
|
|
94
|
+
// No reliable cookie change event across tabs; omit subscribe
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function memoryAdapter(initial) {
|
|
98
|
+
let value = initial;
|
|
99
|
+
const subs = /* @__PURE__ */ new Set();
|
|
100
|
+
return {
|
|
101
|
+
get: () => value,
|
|
102
|
+
set: (t) => {
|
|
103
|
+
value = t;
|
|
104
|
+
subs.forEach((fn) => fn());
|
|
105
|
+
},
|
|
106
|
+
subscribe(cb) {
|
|
107
|
+
subs.add(cb);
|
|
108
|
+
return () => subs.delete(cb);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
cookieAdapter,
|
|
115
|
+
localStorageAdapter,
|
|
116
|
+
memoryAdapter
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/storage.ts"],"sourcesContent":["import { CREDENTIALS_STORAGE_KEY } from \"../constants/credentials\"\n\nexport interface StorageAdapter {\n /** Return the current access token (string) or undefined if none. */\n get(): string | undefined\n /** Persist or remove the access token. */\n set(token?: string): void\n /** Optional: subscribe to external changes (e.g., other tabs). Returns an unsubscribe. */\n subscribe?(cb: () => void): () => void\n}\n\n/** Safe localStorage adapter with cross-tab sync (via 'storage' event). */\nexport function localStorageAdapter(\n key = CREDENTIALS_STORAGE_KEY,\n): StorageAdapter {\n const subs = new Set<() => void>()\n\n const onStorage = (e: StorageEvent) => {\n if (e.key === key) subs.forEach((fn) => fn())\n }\n\n const safeGet = () => {\n try {\n if (typeof window === \"undefined\" || !(\"localStorage\" in window))\n return undefined\n return window.localStorage.getItem(key) ?? undefined\n } catch {\n return undefined\n }\n }\n\n const safeSet = (t?: string) => {\n try {\n if (typeof window === \"undefined\" || !(\"localStorage\" in window)) return\n if (!t) window.localStorage.removeItem(key)\n else window.localStorage.setItem(key, t)\n } catch {\n /* no-op */\n }\n }\n\n return {\n get: safeGet,\n set: safeSet,\n subscribe(cb) {\n subs.add(cb)\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"storage\", onStorage)\n }\n return () => {\n subs.delete(cb)\n if (!subs.size && typeof window !== \"undefined\") {\n window.removeEventListener(\"storage\", onStorage)\n }\n }\n },\n }\n}\n\n/** JS-readable cookie adapter (NOT httpOnly). For httpOnly cookies, keep access token here only. */\nexport function cookieAdapter(\n options: {\n name?: string\n path?: string\n domain?: string\n sameSite?: \"Lax\" | \"Strict\" | \"None\"\n secure?: boolean\n maxAge?: number // seconds\n } = {},\n): StorageAdapter {\n const { name = CREDENTIALS_STORAGE_KEY, ...attrs } = options\n const { path = \"/\", sameSite = \"Lax\" } = attrs\n const read = () => {\n if (typeof document === \"undefined\") return undefined\n const raw = document.cookie\n .split(\"; \")\n .find((c) => c.startsWith(name + \"=\"))\n if (!raw) return undefined\n try {\n return decodeURIComponent(raw.split(\"=\").slice(1).join(\"=\"))\n } catch {\n return raw.split(\"=\").slice(1).join(\"=\")\n }\n }\n\n const write = (v: string) => {\n if (typeof document === \"undefined\") return\n let s =\n `${name}=${encodeURIComponent(v)}; Path=${path}` +\n `; SameSite=${sameSite}`\n if (attrs.domain) s += `; Domain=${attrs.domain}`\n if (attrs.secure) s += `; Secure`\n if (attrs.maxAge) s += `; Max-Age=${attrs.maxAge}`\n document.cookie = s\n }\n\n const clear = () => {\n if (typeof document === \"undefined\") return\n document.cookie = `${name}=; Max-Age=0; Path=${path}`\n }\n\n return {\n get: read,\n set: (t) => (t ? write(t) : clear()),\n // No reliable cookie change event across tabs; omit subscribe\n }\n}\n\n/** In-memory adapter (useful for SSR/tests). */\nexport function memoryAdapter(initial?: string): StorageAdapter {\n let value = initial\n const subs = new Set<() => void>()\n return {\n get: () => value,\n set: (t) => {\n value = t\n subs.forEach((fn) => fn())\n },\n subscribe(cb) {\n subs.add(cb)\n return () => subs.delete(cb)\n },\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface StorageAdapter {
|
|
2
|
+
/** Return the current access token (string) or undefined if none. */
|
|
3
|
+
get(): string | undefined;
|
|
4
|
+
/** Persist or remove the access token. */
|
|
5
|
+
set(token?: string): void;
|
|
6
|
+
/** Optional: subscribe to external changes (e.g., other tabs). Returns an unsubscribe. */
|
|
7
|
+
subscribe?(cb: () => void): () => void;
|
|
8
|
+
}
|
|
9
|
+
/** Safe localStorage adapter with cross-tab sync (via 'storage' event). */
|
|
10
|
+
declare function localStorageAdapter(key?: string): StorageAdapter;
|
|
11
|
+
/** JS-readable cookie adapter (NOT httpOnly). For httpOnly cookies, keep access token here only. */
|
|
12
|
+
declare function cookieAdapter(options?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
domain?: string;
|
|
16
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}): StorageAdapter;
|
|
20
|
+
/** In-memory adapter (useful for SSR/tests). */
|
|
21
|
+
declare function memoryAdapter(initial?: string): StorageAdapter;
|
|
22
|
+
|
|
23
|
+
export { type StorageAdapter, cookieAdapter, localStorageAdapter, memoryAdapter };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface StorageAdapter {
|
|
2
|
+
/** Return the current access token (string) or undefined if none. */
|
|
3
|
+
get(): string | undefined;
|
|
4
|
+
/** Persist or remove the access token. */
|
|
5
|
+
set(token?: string): void;
|
|
6
|
+
/** Optional: subscribe to external changes (e.g., other tabs). Returns an unsubscribe. */
|
|
7
|
+
subscribe?(cb: () => void): () => void;
|
|
8
|
+
}
|
|
9
|
+
/** Safe localStorage adapter with cross-tab sync (via 'storage' event). */
|
|
10
|
+
declare function localStorageAdapter(key?: string): StorageAdapter;
|
|
11
|
+
/** JS-readable cookie adapter (NOT httpOnly). For httpOnly cookies, keep access token here only. */
|
|
12
|
+
declare function cookieAdapter(options?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
domain?: string;
|
|
16
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
17
|
+
secure?: boolean;
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
}): StorageAdapter;
|
|
20
|
+
/** In-memory adapter (useful for SSR/tests). */
|
|
21
|
+
declare function memoryAdapter(initial?: string): StorageAdapter;
|
|
22
|
+
|
|
23
|
+
export { type StorageAdapter, cookieAdapter, localStorageAdapter, memoryAdapter };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CREDENTIALS_STORAGE_KEY } from "../constants/credentials.mjs";
|
|
2
|
+
function localStorageAdapter(key = CREDENTIALS_STORAGE_KEY) {
|
|
3
|
+
const subs = /* @__PURE__ */ new Set();
|
|
4
|
+
const onStorage = (e) => {
|
|
5
|
+
if (e.key === key) subs.forEach((fn) => fn());
|
|
6
|
+
};
|
|
7
|
+
const safeGet = () => {
|
|
8
|
+
try {
|
|
9
|
+
if (typeof window === "undefined" || !("localStorage" in window))
|
|
10
|
+
return void 0;
|
|
11
|
+
return window.localStorage.getItem(key) ?? void 0;
|
|
12
|
+
} catch {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const safeSet = (t) => {
|
|
17
|
+
try {
|
|
18
|
+
if (typeof window === "undefined" || !("localStorage" in window)) return;
|
|
19
|
+
if (!t) window.localStorage.removeItem(key);
|
|
20
|
+
else window.localStorage.setItem(key, t);
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
get: safeGet,
|
|
26
|
+
set: safeSet,
|
|
27
|
+
subscribe(cb) {
|
|
28
|
+
subs.add(cb);
|
|
29
|
+
if (typeof window !== "undefined") {
|
|
30
|
+
window.addEventListener("storage", onStorage);
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
subs.delete(cb);
|
|
34
|
+
if (!subs.size && typeof window !== "undefined") {
|
|
35
|
+
window.removeEventListener("storage", onStorage);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function cookieAdapter(options = {}) {
|
|
42
|
+
const { name = CREDENTIALS_STORAGE_KEY, ...attrs } = options;
|
|
43
|
+
const { path = "/", sameSite = "Lax" } = attrs;
|
|
44
|
+
const read = () => {
|
|
45
|
+
if (typeof document === "undefined") return void 0;
|
|
46
|
+
const raw = document.cookie.split("; ").find((c) => c.startsWith(name + "="));
|
|
47
|
+
if (!raw) return void 0;
|
|
48
|
+
try {
|
|
49
|
+
return decodeURIComponent(raw.split("=").slice(1).join("="));
|
|
50
|
+
} catch {
|
|
51
|
+
return raw.split("=").slice(1).join("=");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const write = (v) => {
|
|
55
|
+
if (typeof document === "undefined") return;
|
|
56
|
+
let s = `${name}=${encodeURIComponent(v)}; Path=${path}; SameSite=${sameSite}`;
|
|
57
|
+
if (attrs.domain) s += `; Domain=${attrs.domain}`;
|
|
58
|
+
if (attrs.secure) s += `; Secure`;
|
|
59
|
+
if (attrs.maxAge) s += `; Max-Age=${attrs.maxAge}`;
|
|
60
|
+
document.cookie = s;
|
|
61
|
+
};
|
|
62
|
+
const clear = () => {
|
|
63
|
+
if (typeof document === "undefined") return;
|
|
64
|
+
document.cookie = `${name}=; Max-Age=0; Path=${path}`;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
get: read,
|
|
68
|
+
set: (t) => t ? write(t) : clear()
|
|
69
|
+
// No reliable cookie change event across tabs; omit subscribe
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function memoryAdapter(initial) {
|
|
73
|
+
let value = initial;
|
|
74
|
+
const subs = /* @__PURE__ */ new Set();
|
|
75
|
+
return {
|
|
76
|
+
get: () => value,
|
|
77
|
+
set: (t) => {
|
|
78
|
+
value = t;
|
|
79
|
+
subs.forEach((fn) => fn());
|
|
80
|
+
},
|
|
81
|
+
subscribe(cb) {
|
|
82
|
+
subs.add(cb);
|
|
83
|
+
return () => subs.delete(cb);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
cookieAdapter,
|
|
89
|
+
localStorageAdapter,
|
|
90
|
+
memoryAdapter
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=storage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/storage.ts"],"sourcesContent":["import { CREDENTIALS_STORAGE_KEY } from \"../constants/credentials\"\n\nexport interface StorageAdapter {\n /** Return the current access token (string) or undefined if none. */\n get(): string | undefined\n /** Persist or remove the access token. */\n set(token?: string): void\n /** Optional: subscribe to external changes (e.g., other tabs). Returns an unsubscribe. */\n subscribe?(cb: () => void): () => void\n}\n\n/** Safe localStorage adapter with cross-tab sync (via 'storage' event). */\nexport function localStorageAdapter(\n key = CREDENTIALS_STORAGE_KEY,\n): StorageAdapter {\n const subs = new Set<() => void>()\n\n const onStorage = (e: StorageEvent) => {\n if (e.key === key) subs.forEach((fn) => fn())\n }\n\n const safeGet = () => {\n try {\n if (typeof window === \"undefined\" || !(\"localStorage\" in window))\n return undefined\n return window.localStorage.getItem(key) ?? undefined\n } catch {\n return undefined\n }\n }\n\n const safeSet = (t?: string) => {\n try {\n if (typeof window === \"undefined\" || !(\"localStorage\" in window)) return\n if (!t) window.localStorage.removeItem(key)\n else window.localStorage.setItem(key, t)\n } catch {\n /* no-op */\n }\n }\n\n return {\n get: safeGet,\n set: safeSet,\n subscribe(cb) {\n subs.add(cb)\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"storage\", onStorage)\n }\n return () => {\n subs.delete(cb)\n if (!subs.size && typeof window !== \"undefined\") {\n window.removeEventListener(\"storage\", onStorage)\n }\n }\n },\n }\n}\n\n/** JS-readable cookie adapter (NOT httpOnly). For httpOnly cookies, keep access token here only. */\nexport function cookieAdapter(\n options: {\n name?: string\n path?: string\n domain?: string\n sameSite?: \"Lax\" | \"Strict\" | \"None\"\n secure?: boolean\n maxAge?: number // seconds\n } = {},\n): StorageAdapter {\n const { name = CREDENTIALS_STORAGE_KEY, ...attrs } = options\n const { path = \"/\", sameSite = \"Lax\" } = attrs\n const read = () => {\n if (typeof document === \"undefined\") return undefined\n const raw = document.cookie\n .split(\"; \")\n .find((c) => c.startsWith(name + \"=\"))\n if (!raw) return undefined\n try {\n return decodeURIComponent(raw.split(\"=\").slice(1).join(\"=\"))\n } catch {\n return raw.split(\"=\").slice(1).join(\"=\")\n }\n }\n\n const write = (v: string) => {\n if (typeof document === \"undefined\") return\n let s =\n `${name}=${encodeURIComponent(v)}; Path=${path}` +\n `; SameSite=${sameSite}`\n if (attrs.domain) s += `; Domain=${attrs.domain}`\n if (attrs.secure) s += `; Secure`\n if (attrs.maxAge) s += `; Max-Age=${attrs.maxAge}`\n document.cookie = s\n }\n\n const clear = () => {\n if (typeof document === \"undefined\") return\n document.cookie = `${name}=; Max-Age=0; Path=${path}`\n }\n\n return {\n get: read,\n set: (t) => (t ? write(t) : clear()),\n // No reliable cookie change event across tabs; omit subscribe\n }\n}\n\n/** In-memory adapter (useful for SSR/tests). */\nexport function memoryAdapter(initial?: string): StorageAdapter {\n let value = initial\n const subs = new Set<() => void>()\n return {\n get: () => value,\n set: (t) => {\n value = t\n subs.forEach((fn) => fn())\n },\n subscribe(cb) {\n subs.add(cb)\n return () => subs.delete(cb)\n },\n }\n}\n"],"mappings":"AAAA,SAAS,+BAA+B;AAYjC,SAAS,oBACd,MAAM,yBACU;AAChB,QAAM,OAAO,oBAAI,IAAgB;AAEjC,QAAM,YAAY,CAAC,MAAoB;AACrC,QAAI,EAAE,QAAQ,IAAK,MAAK,QAAQ,CAAC,OAAO,GAAG,CAAC;AAAA,EAC9C;AAEA,QAAM,UAAU,MAAM;AACpB,QAAI;AACF,UAAI,OAAO,WAAW,eAAe,EAAE,kBAAkB;AACvD,eAAO;AACT,aAAO,OAAO,aAAa,QAAQ,GAAG,KAAK;AAAA,IAC7C,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,UAAU,CAAC,MAAe;AAC9B,QAAI;AACF,UAAI,OAAO,WAAW,eAAe,EAAE,kBAAkB,QAAS;AAClE,UAAI,CAAC,EAAG,QAAO,aAAa,WAAW,GAAG;AAAA,UACrC,QAAO,aAAa,QAAQ,KAAK,CAAC;AAAA,IACzC,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,UAAU,IAAI;AACZ,WAAK,IAAI,EAAE;AACX,UAAI,OAAO,WAAW,aAAa;AACjC,eAAO,iBAAiB,WAAW,SAAS;AAAA,MAC9C;AACA,aAAO,MAAM;AACX,aAAK,OAAO,EAAE;AACd,YAAI,CAAC,KAAK,QAAQ,OAAO,WAAW,aAAa;AAC/C,iBAAO,oBAAoB,WAAW,SAAS;AAAA,QACjD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,cACd,UAOI,CAAC,GACW;AAChB,QAAM,EAAE,OAAO,yBAAyB,GAAG,MAAM,IAAI;AACrD,QAAM,EAAE,OAAO,KAAK,WAAW,MAAM,IAAI;AACzC,QAAM,OAAO,MAAM;AACjB,QAAI,OAAO,aAAa,YAAa,QAAO;AAC5C,UAAM,MAAM,SAAS,OAClB,MAAM,IAAI,EACV,KAAK,CAAC,MAAM,EAAE,WAAW,OAAO,GAAG,CAAC;AACvC,QAAI,CAAC,IAAK,QAAO;AACjB,QAAI;AACF,aAAO,mBAAmB,IAAI,MAAM,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAAA,IAC7D,QAAQ;AACN,aAAO,IAAI,MAAM,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG;AAAA,IACzC;AAAA,EACF;AAEA,QAAM,QAAQ,CAAC,MAAc;AAC3B,QAAI,OAAO,aAAa,YAAa;AACrC,QAAI,IACF,GAAG,IAAI,IAAI,mBAAmB,CAAC,CAAC,UAAU,IAAI,cAChC,QAAQ;AACxB,QAAI,MAAM,OAAQ,MAAK,YAAY,MAAM,MAAM;AAC/C,QAAI,MAAM,OAAQ,MAAK;AACvB,QAAI,MAAM,OAAQ,MAAK,aAAa,MAAM,MAAM;AAChD,aAAS,SAAS;AAAA,EACpB;AAEA,QAAM,QAAQ,MAAM;AAClB,QAAI,OAAO,aAAa,YAAa;AACrC,aAAS,SAAS,GAAG,IAAI,sBAAsB,IAAI;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,KAAK,CAAC,MAAO,IAAI,MAAM,CAAC,IAAI,MAAM;AAAA;AAAA,EAEpC;AACF;AAGO,SAAS,cAAc,SAAkC;AAC9D,MAAI,QAAQ;AACZ,QAAM,OAAO,oBAAI,IAAgB;AACjC,SAAO;AAAA,IACL,KAAK,MAAM;AAAA,IACX,KAAK,CAAC,MAAM;AACV,cAAQ;AACR,WAAK,QAAQ,CAAC,OAAO,GAAG,CAAC;AAAA,IAC3B;AAAA,IACA,UAAU,IAAI;AACZ,WAAK,IAAI,EAAE;AACX,aAAO,MAAM,KAAK,OAAO,EAAE;AAAA,IAC7B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var token_providers_exports = {};
|
|
20
|
+
__export(token_providers_exports, {
|
|
21
|
+
makeImplicitTokenProviderCachedBare: () => makeImplicitTokenProviderCachedBare,
|
|
22
|
+
makeImplicitTokenProviderWithFreshSdk: () => makeImplicitTokenProviderWithFreshSdk
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(token_providers_exports);
|
|
25
|
+
var import_client_fetch = require("@hey-api/client-fetch");
|
|
26
|
+
var import_sdk = require('../client/sdk.gen.cjs');
|
|
27
|
+
function makeImplicitTokenProviderWithFreshSdk(opts) {
|
|
28
|
+
return async () => {
|
|
29
|
+
const bare = (0, import_client_fetch.createClient)({
|
|
30
|
+
baseUrl: opts.baseUrl,
|
|
31
|
+
fetch: opts.fetch,
|
|
32
|
+
headers: opts.headers
|
|
33
|
+
});
|
|
34
|
+
const resp = await (0, import_sdk.createAnAccessToken)({
|
|
35
|
+
client: bare,
|
|
36
|
+
body: { grant_type: "implicit", client_id: opts.clientId }
|
|
37
|
+
});
|
|
38
|
+
if (resp.error) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"makeImplicitTokenProviderWithFreshSdk: Failed to get access token"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const x = resp.data;
|
|
44
|
+
return {
|
|
45
|
+
access_token: x.access_token,
|
|
46
|
+
expires_in: x.expires_in ?? void 0,
|
|
47
|
+
expires: x.expires ?? void 0,
|
|
48
|
+
token_type: x.token_type ?? void 0
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function makeImplicitTokenProviderCachedBare(opts) {
|
|
53
|
+
let bare = (0, import_client_fetch.createClient)({
|
|
54
|
+
baseUrl: opts.baseUrl,
|
|
55
|
+
fetch: opts.fetch,
|
|
56
|
+
headers: opts.headers
|
|
57
|
+
});
|
|
58
|
+
return async () => {
|
|
59
|
+
const resp = await (0, import_sdk.createAnAccessToken)({
|
|
60
|
+
client: bare,
|
|
61
|
+
body: { grant_type: "implicit", client_id: opts.clientId }
|
|
62
|
+
});
|
|
63
|
+
if (resp.error) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"makeImplicitTokenProviderCachedBare: Failed to get access token"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const x = resp.data;
|
|
69
|
+
return {
|
|
70
|
+
access_token: x.access_token,
|
|
71
|
+
expires_in: x.expires_in,
|
|
72
|
+
expires: x.expires,
|
|
73
|
+
token_type: x.token_type
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
makeImplicitTokenProviderCachedBare,
|
|
80
|
+
makeImplicitTokenProviderWithFreshSdk
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=token-providers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/token-providers.ts"],"sourcesContent":["import type { TokenProvider } from \"./kit\"\nimport { type Config, createClient } from \"@hey-api/client-fetch\"\nimport { createAnAccessToken } from \"../client/sdk.gen\"\n\n/**\n * Fresh-instance implicit token provider.\n * Always constructs a new, BARE sdk client (no auth wrapper, no interceptors) and calls the OAuth op.\n * This is loop-proof because it never uses the authed client.\n */\nexport function makeImplicitTokenProviderWithFreshSdk(opts: {\n baseUrl: string\n clientId: string\n fetch?: Config[\"fetch\"]\n headers?: HeadersInit | Record<string, string>\n // If your SDK needs any other createClient options, add them here and pass through.\n}): TokenProvider {\n return async () => {\n const bare = createClient({\n baseUrl: opts.baseUrl,\n fetch: opts.fetch,\n headers: opts.headers,\n })\n\n const resp = await createAnAccessToken({\n client: bare,\n body: { grant_type: \"implicit\", client_id: opts.clientId },\n })\n\n if (resp.error) {\n throw new Error(\n \"makeImplicitTokenProviderWithFreshSdk: Failed to get access token\",\n )\n }\n\n const x = resp.data\n\n return {\n access_token: x.access_token,\n expires_in: x.expires_in ?? undefined,\n expires: x.expires ?? undefined,\n token_type: x.token_type ?? undefined,\n }\n }\n}\n\n/**\n * Cached bare instance (minor perf win, still loop-proof).\n * Reuses a single bare client for all OAuth calls.\n */\nexport function makeImplicitTokenProviderCachedBare(opts: {\n baseUrl: string\n clientId: string\n fetch?: Config[\"fetch\"]\n headers?: HeadersInit | Record<string, string>\n}): TokenProvider {\n let bare = createClient({\n baseUrl: opts.baseUrl,\n fetch: opts.fetch,\n headers: opts.headers,\n })\n\n return async () => {\n const resp = await createAnAccessToken({\n client: bare,\n body: { grant_type: \"implicit\", client_id: opts.clientId },\n })\n\n if (resp.error) {\n throw new Error(\n \"makeImplicitTokenProviderCachedBare: Failed to get access token\",\n )\n }\n\n const x = resp.data\n return {\n access_token: x.access_token,\n expires_in: x.expires_in,\n expires: x.expires,\n token_type: x.token_type,\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA0C;AAC1C,iBAAoC;AAO7B,SAAS,sCAAsC,MAMpC;AAChB,SAAO,YAAY;AACjB,UAAM,WAAO,kCAAa;AAAA,MACxB,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK;AAAA,IAChB,CAAC;AAED,UAAM,OAAO,UAAM,gCAAoB;AAAA,MACrC,QAAQ;AAAA,MACR,MAAM,EAAE,YAAY,YAAY,WAAW,KAAK,SAAS;AAAA,IAC3D,CAAC;AAED,QAAI,KAAK,OAAO;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,KAAK;AAEf,WAAO;AAAA,MACL,cAAc,EAAE;AAAA,MAChB,YAAY,EAAE,cAAc;AAAA,MAC5B,SAAS,EAAE,WAAW;AAAA,MACtB,YAAY,EAAE,cAAc;AAAA,IAC9B;AAAA,EACF;AACF;AAMO,SAAS,oCAAoC,MAKlC;AAChB,MAAI,WAAO,kCAAa;AAAA,IACtB,SAAS,KAAK;AAAA,IACd,OAAO,KAAK;AAAA,IACZ,SAAS,KAAK;AAAA,EAChB,CAAC;AAED,SAAO,YAAY;AACjB,UAAM,OAAO,UAAM,gCAAoB;AAAA,MACrC,QAAQ;AAAA,MACR,MAAM,EAAE,YAAY,YAAY,WAAW,KAAK,SAAS;AAAA,IAC3D,CAAC;AAED,QAAI,KAAK,OAAO;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,KAAK;AACf,WAAO;AAAA,MACL,cAAc,EAAE;AAAA,MAChB,YAAY,EAAE;AAAA,MACd,SAAS,EAAE;AAAA,MACX,YAAY,EAAE;AAAA,IAChB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TokenProvider } from './kit.cjs';
|
|
2
|
+
import { Config } from '@hey-api/client-fetch';
|
|
3
|
+
import './storage.cjs';
|
|
4
|
+
import '../client/types.gen.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fresh-instance implicit token provider.
|
|
8
|
+
* Always constructs a new, BARE sdk client (no auth wrapper, no interceptors) and calls the OAuth op.
|
|
9
|
+
* This is loop-proof because it never uses the authed client.
|
|
10
|
+
*/
|
|
11
|
+
declare function makeImplicitTokenProviderWithFreshSdk(opts: {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
fetch?: Config["fetch"];
|
|
15
|
+
headers?: HeadersInit | Record<string, string>;
|
|
16
|
+
}): TokenProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Cached bare instance (minor perf win, still loop-proof).
|
|
19
|
+
* Reuses a single bare client for all OAuth calls.
|
|
20
|
+
*/
|
|
21
|
+
declare function makeImplicitTokenProviderCachedBare(opts: {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
clientId: string;
|
|
24
|
+
fetch?: Config["fetch"];
|
|
25
|
+
headers?: HeadersInit | Record<string, string>;
|
|
26
|
+
}): TokenProvider;
|
|
27
|
+
|
|
28
|
+
export { makeImplicitTokenProviderCachedBare, makeImplicitTokenProviderWithFreshSdk };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TokenProvider } from './kit.js';
|
|
2
|
+
import { Config } from '@hey-api/client-fetch';
|
|
3
|
+
import './storage.js';
|
|
4
|
+
import '../client/types.gen.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fresh-instance implicit token provider.
|
|
8
|
+
* Always constructs a new, BARE sdk client (no auth wrapper, no interceptors) and calls the OAuth op.
|
|
9
|
+
* This is loop-proof because it never uses the authed client.
|
|
10
|
+
*/
|
|
11
|
+
declare function makeImplicitTokenProviderWithFreshSdk(opts: {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
fetch?: Config["fetch"];
|
|
15
|
+
headers?: HeadersInit | Record<string, string>;
|
|
16
|
+
}): TokenProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Cached bare instance (minor perf win, still loop-proof).
|
|
19
|
+
* Reuses a single bare client for all OAuth calls.
|
|
20
|
+
*/
|
|
21
|
+
declare function makeImplicitTokenProviderCachedBare(opts: {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
clientId: string;
|
|
24
|
+
fetch?: Config["fetch"];
|
|
25
|
+
headers?: HeadersInit | Record<string, string>;
|
|
26
|
+
}): TokenProvider;
|
|
27
|
+
|
|
28
|
+
export { makeImplicitTokenProviderCachedBare, makeImplicitTokenProviderWithFreshSdk };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createClient } from "@hey-api/client-fetch";
|
|
2
|
+
import { createAnAccessToken } from "../client/sdk.gen.mjs";
|
|
3
|
+
function makeImplicitTokenProviderWithFreshSdk(opts) {
|
|
4
|
+
return async () => {
|
|
5
|
+
const bare = createClient({
|
|
6
|
+
baseUrl: opts.baseUrl,
|
|
7
|
+
fetch: opts.fetch,
|
|
8
|
+
headers: opts.headers
|
|
9
|
+
});
|
|
10
|
+
const resp = await createAnAccessToken({
|
|
11
|
+
client: bare,
|
|
12
|
+
body: { grant_type: "implicit", client_id: opts.clientId }
|
|
13
|
+
});
|
|
14
|
+
if (resp.error) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
"makeImplicitTokenProviderWithFreshSdk: Failed to get access token"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
const x = resp.data;
|
|
20
|
+
return {
|
|
21
|
+
access_token: x.access_token,
|
|
22
|
+
expires_in: x.expires_in ?? void 0,
|
|
23
|
+
expires: x.expires ?? void 0,
|
|
24
|
+
token_type: x.token_type ?? void 0
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function makeImplicitTokenProviderCachedBare(opts) {
|
|
29
|
+
let bare = createClient({
|
|
30
|
+
baseUrl: opts.baseUrl,
|
|
31
|
+
fetch: opts.fetch,
|
|
32
|
+
headers: opts.headers
|
|
33
|
+
});
|
|
34
|
+
return async () => {
|
|
35
|
+
const resp = await createAnAccessToken({
|
|
36
|
+
client: bare,
|
|
37
|
+
body: { grant_type: "implicit", client_id: opts.clientId }
|
|
38
|
+
});
|
|
39
|
+
if (resp.error) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"makeImplicitTokenProviderCachedBare: Failed to get access token"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const x = resp.data;
|
|
45
|
+
return {
|
|
46
|
+
access_token: x.access_token,
|
|
47
|
+
expires_in: x.expires_in,
|
|
48
|
+
expires: x.expires,
|
|
49
|
+
token_type: x.token_type
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
makeImplicitTokenProviderCachedBare,
|
|
55
|
+
makeImplicitTokenProviderWithFreshSdk
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=token-providers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/token-providers.ts"],"sourcesContent":["import type { TokenProvider } from \"./kit\"\nimport { type Config, createClient } from \"@hey-api/client-fetch\"\nimport { createAnAccessToken } from \"../client/sdk.gen\"\n\n/**\n * Fresh-instance implicit token provider.\n * Always constructs a new, BARE sdk client (no auth wrapper, no interceptors) and calls the OAuth op.\n * This is loop-proof because it never uses the authed client.\n */\nexport function makeImplicitTokenProviderWithFreshSdk(opts: {\n baseUrl: string\n clientId: string\n fetch?: Config[\"fetch\"]\n headers?: HeadersInit | Record<string, string>\n // If your SDK needs any other createClient options, add them here and pass through.\n}): TokenProvider {\n return async () => {\n const bare = createClient({\n baseUrl: opts.baseUrl,\n fetch: opts.fetch,\n headers: opts.headers,\n })\n\n const resp = await createAnAccessToken({\n client: bare,\n body: { grant_type: \"implicit\", client_id: opts.clientId },\n })\n\n if (resp.error) {\n throw new Error(\n \"makeImplicitTokenProviderWithFreshSdk: Failed to get access token\",\n )\n }\n\n const x = resp.data\n\n return {\n access_token: x.access_token,\n expires_in: x.expires_in ?? undefined,\n expires: x.expires ?? undefined,\n token_type: x.token_type ?? undefined,\n }\n }\n}\n\n/**\n * Cached bare instance (minor perf win, still loop-proof).\n * Reuses a single bare client for all OAuth calls.\n */\nexport function makeImplicitTokenProviderCachedBare(opts: {\n baseUrl: string\n clientId: string\n fetch?: Config[\"fetch\"]\n headers?: HeadersInit | Record<string, string>\n}): TokenProvider {\n let bare = createClient({\n baseUrl: opts.baseUrl,\n fetch: opts.fetch,\n headers: opts.headers,\n })\n\n return async () => {\n const resp = await createAnAccessToken({\n client: bare,\n body: { grant_type: \"implicit\", client_id: opts.clientId },\n })\n\n if (resp.error) {\n throw new Error(\n \"makeImplicitTokenProviderCachedBare: Failed to get access token\",\n )\n }\n\n const x = resp.data\n return {\n access_token: x.access_token,\n expires_in: x.expires_in,\n expires: x.expires,\n token_type: x.token_type,\n }\n }\n}\n"],"mappings":"AACA,SAAsB,oBAAoB;AAC1C,SAAS,2BAA2B;AAO7B,SAAS,sCAAsC,MAMpC;AAChB,SAAO,YAAY;AACjB,UAAM,OAAO,aAAa;AAAA,MACxB,SAAS,KAAK;AAAA,MACd,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK;AAAA,IAChB,CAAC;AAED,UAAM,OAAO,MAAM,oBAAoB;AAAA,MACrC,QAAQ;AAAA,MACR,MAAM,EAAE,YAAY,YAAY,WAAW,KAAK,SAAS;AAAA,IAC3D,CAAC;AAED,QAAI,KAAK,OAAO;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,KAAK;AAEf,WAAO;AAAA,MACL,cAAc,EAAE;AAAA,MAChB,YAAY,EAAE,cAAc;AAAA,MAC5B,SAAS,EAAE,WAAW;AAAA,MACtB,YAAY,EAAE,cAAc;AAAA,IAC9B;AAAA,EACF;AACF;AAMO,SAAS,oCAAoC,MAKlC;AAChB,MAAI,OAAO,aAAa;AAAA,IACtB,SAAS,KAAK;AAAA,IACd,OAAO,KAAK;AAAA,IACZ,SAAS,KAAK;AAAA,EAChB,CAAC;AAED,SAAO,YAAY;AACjB,UAAM,OAAO,MAAM,oBAAoB;AAAA,MACrC,QAAQ;AAAA,MACR,MAAM,EAAE,YAAY,YAAY,WAAW,KAAK,SAAS;AAAA,IAC3D,CAAC;AAED,QAAI,KAAK,OAAO;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,KAAK;AACf,WAAO;AAAA,MACL,cAAc,EAAE;AAAA,MAChB,YAAY,EAAE;AAAA,MACd,SAAS,EAAE;AAAA,MACX,YAAY,EAAE;AAAA,IAChB;AAAA,EACF;AACF;","names":[]}
|