@civic/auth 0.6.0-beta.3 → 0.6.1-beta.1
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/shared/components/CivicAuthIframeContainer.js +1 -1
- package/dist/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.d.ts +7 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.d.ts.map +1 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.js +15 -2
- package/dist/shared/lib/BrowserAuthenticationRefresher.js.map +1 -1
- package/dist/shared/lib/util.d.ts +1 -1
- package/dist/shared/lib/util.d.ts.map +1 -1
- package/dist/shared/lib/util.js +6 -1
- package/dist/shared/lib/util.js.map +1 -1
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/dist/vanillajs/auth/AuthenticationEvents.d.ts +11 -0
- package/dist/vanillajs/auth/AuthenticationEvents.d.ts.map +1 -0
- package/dist/vanillajs/auth/AuthenticationEvents.js +36 -0
- package/dist/vanillajs/auth/AuthenticationEvents.js.map +1 -0
- package/dist/vanillajs/auth/CivicAuth.d.ts +205 -0
- package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -0
- package/dist/vanillajs/auth/CivicAuth.js +689 -0
- package/dist/vanillajs/auth/CivicAuth.js.map +1 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.d.ts +90 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.d.ts.map +1 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.js +143 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.js.map +1 -0
- package/dist/vanillajs/auth/SessionManager.d.ts +48 -0
- package/dist/vanillajs/auth/SessionManager.d.ts.map +1 -0
- package/dist/vanillajs/auth/SessionManager.js +121 -0
- package/dist/vanillajs/auth/SessionManager.js.map +1 -0
- package/dist/vanillajs/auth/TokenRefresher.d.ts +54 -0
- package/dist/vanillajs/auth/TokenRefresher.d.ts.map +1 -0
- package/dist/vanillajs/auth/TokenRefresher.js +166 -0
- package/dist/vanillajs/auth/TokenRefresher.js.map +1 -0
- package/dist/vanillajs/iframe/IframeManager.d.ts +82 -0
- package/dist/vanillajs/iframe/IframeManager.d.ts.map +1 -0
- package/dist/vanillajs/iframe/IframeManager.js +487 -0
- package/dist/vanillajs/iframe/IframeManager.js.map +1 -0
- package/dist/vanillajs/iframe/IframeResizer.d.ts +15 -0
- package/dist/vanillajs/iframe/IframeResizer.d.ts.map +1 -0
- package/dist/vanillajs/iframe/IframeResizer.js +127 -0
- package/dist/vanillajs/iframe/IframeResizer.js.map +1 -0
- package/dist/vanillajs/iframe/SignalObserver.d.ts +33 -0
- package/dist/vanillajs/iframe/SignalObserver.d.ts.map +1 -0
- package/dist/vanillajs/iframe/SignalObserver.js +162 -0
- package/dist/vanillajs/iframe/SignalObserver.js.map +1 -0
- package/dist/vanillajs/index.d.ts +17 -0
- package/dist/vanillajs/index.d.ts.map +1 -0
- package/dist/vanillajs/index.js +18 -0
- package/dist/vanillajs/index.js.map +1 -0
- package/dist/vanillajs/services/ApiService.d.ts +22 -0
- package/dist/vanillajs/services/ApiService.d.ts.map +1 -0
- package/dist/vanillajs/services/ApiService.js +82 -0
- package/dist/vanillajs/services/ApiService.js.map +1 -0
- package/dist/vanillajs/types/index.d.ts +28 -0
- package/dist/vanillajs/types/index.d.ts.map +1 -0
- package/dist/vanillajs/types/index.js +14 -0
- package/dist/vanillajs/types/index.js.map +1 -0
- package/dist/vanillajs/ui/LoadingComponents.d.ts +51 -0
- package/dist/vanillajs/ui/LoadingComponents.d.ts.map +1 -0
- package/dist/vanillajs/ui/LoadingComponents.js +363 -0
- package/dist/vanillajs/ui/LoadingComponents.js.map +1 -0
- package/dist/vanillajs/utils/auth-utils.d.ts +13 -0
- package/dist/vanillajs/utils/auth-utils.d.ts.map +1 -0
- package/dist/vanillajs/utils/auth-utils.js +15 -0
- package/dist/vanillajs/utils/auth-utils.js.map +1 -0
- package/dist/vanillajs/utils/logger.d.ts +29 -0
- package/dist/vanillajs/utils/logger.d.ts.map +1 -0
- package/dist/vanillajs/utils/logger.js +62 -0
- package/dist/vanillajs/utils/logger.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI Components for Civic Auth Vanilla JS implementation
|
|
3
|
+
* Converted from React components to vanilla DOM elements
|
|
4
|
+
*/
|
|
5
|
+
export interface ShimmerLoaderOptions {
|
|
6
|
+
backgroundColor?: string;
|
|
7
|
+
width?: string;
|
|
8
|
+
height?: string;
|
|
9
|
+
borderRadius?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a horizontal shimmer loader element (SVG-based)
|
|
13
|
+
* Equivalent to the SVGLoading component from React implementation
|
|
14
|
+
*/
|
|
15
|
+
export declare function createShimmerLoader(options?: ShimmerLoaderOptions): HTMLElement;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a shimmer loader for iframe loading states
|
|
18
|
+
* Positioned to center within an iframe container
|
|
19
|
+
*/
|
|
20
|
+
export declare function createIframeShimmerLoader(backgroundColor?: string, maxWidth?: string): HTMLElement;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a simple horizontal skeleton loader (CSS-based alternative)
|
|
23
|
+
* Lighter weight alternative to SVG shimmer
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSkeletonLoader(options?: ShimmerLoaderOptions): HTMLElement;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a button content loader that hides content and shows a skeleton
|
|
28
|
+
* Equivalent to ButtonContentOrLoader from React implementation
|
|
29
|
+
*/
|
|
30
|
+
export declare function createButtonContentLoader(content: string | HTMLElement): {
|
|
31
|
+
container: HTMLElement;
|
|
32
|
+
showLoader: () => void;
|
|
33
|
+
hideLoader: () => void;
|
|
34
|
+
setContent: (newContent: string | HTMLElement) => void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a close icon (X) SVG element
|
|
38
|
+
* Equivalent to the CloseIcon component from React implementation
|
|
39
|
+
*/
|
|
40
|
+
export declare function createCloseIcon(): SVGElement;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a close button for modal iframes
|
|
43
|
+
* Positioned absolutely in the top-right corner
|
|
44
|
+
*/
|
|
45
|
+
export declare function createCloseButton(onClose: () => void): HTMLButtonElement;
|
|
46
|
+
/**
|
|
47
|
+
* Utility function to remove all civic auth loading styles from the document
|
|
48
|
+
* Useful for cleanup
|
|
49
|
+
*/
|
|
50
|
+
export declare function cleanupLoadingStyles(): void;
|
|
51
|
+
//# sourceMappingURL=LoadingComponents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingComponents.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/ui/LoadingComponents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA2BH,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,oBAAyB,GACjC,WAAW,CAmIb;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,eAAe,SAAY,EAC3B,QAAQ,CAAC,EAAE,MAAM,GAChB,WAAW,CAoCb;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,oBAAyB,GACjC,WAAW,CAqCb;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,GAAG;IACxE,SAAS,EAAE,WAAW,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,KAAK,IAAI,CAAC;CACxD,CA0EA;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,UAAU,CA8B5C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,iBAAiB,CAwCxE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAW3C"}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI Components for Civic Auth Vanilla JS implementation
|
|
3
|
+
* Converted from React components to vanilla DOM elements
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Utility function to set multiple styles on an element using a key-value object
|
|
7
|
+
*/
|
|
8
|
+
function setStyles(element, styles) {
|
|
9
|
+
Object.entries(styles).forEach(([property, value]) => {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- CSSStyleDeclaration has read-only properties that prevent proper typing
|
|
11
|
+
element.style[property] = value;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Utility function to set multiple attributes on an element using a key-value object
|
|
16
|
+
*/
|
|
17
|
+
function setAttributes(element, attributes) {
|
|
18
|
+
Object.entries(attributes).forEach(([name, value]) => {
|
|
19
|
+
element.setAttribute(name, value);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a horizontal shimmer loader element (SVG-based)
|
|
24
|
+
* Equivalent to the SVGLoading component from React implementation
|
|
25
|
+
*/
|
|
26
|
+
export function createShimmerLoader(options = {}) {
|
|
27
|
+
const { backgroundColor = "#ffffff", width = "100%", height = "40px", borderRadius = "0.5rem", } = options;
|
|
28
|
+
// Create container div
|
|
29
|
+
const container = document.createElement("div");
|
|
30
|
+
setStyles(container, {
|
|
31
|
+
position: "absolute",
|
|
32
|
+
top: "-6px",
|
|
33
|
+
left: "0",
|
|
34
|
+
borderRadius,
|
|
35
|
+
backgroundColor,
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
opacity: "1",
|
|
39
|
+
});
|
|
40
|
+
setAttributes(container, {
|
|
41
|
+
class: "civic-auth-shimmer-loader",
|
|
42
|
+
});
|
|
43
|
+
// Add CSS animation keyframes
|
|
44
|
+
const style = document.createElement("style");
|
|
45
|
+
style.textContent = `
|
|
46
|
+
@keyframes civic-shimmer {
|
|
47
|
+
0% {
|
|
48
|
+
transform: translate(-328px, 0);
|
|
49
|
+
}
|
|
50
|
+
100% {
|
|
51
|
+
transform: translate(328px, 0);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
// Only add the style if it doesn't already exist
|
|
56
|
+
if (!document.querySelector("style[data-civic-shimmer]")) {
|
|
57
|
+
style.setAttribute("data-civic-shimmer", "true");
|
|
58
|
+
document.head.appendChild(style);
|
|
59
|
+
}
|
|
60
|
+
// Create SVG element
|
|
61
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
62
|
+
setAttributes(svg, {
|
|
63
|
+
"shape-rendering": "geometricPrecision",
|
|
64
|
+
"text-rendering": "geometricPrecision",
|
|
65
|
+
viewBox: "0 0 324 28",
|
|
66
|
+
height: "40",
|
|
67
|
+
width: "100%",
|
|
68
|
+
class: "civic-auth-svg-loading",
|
|
69
|
+
});
|
|
70
|
+
setStyles(svg, {
|
|
71
|
+
position: "absolute",
|
|
72
|
+
top: "-6px",
|
|
73
|
+
left: "0",
|
|
74
|
+
borderRadius,
|
|
75
|
+
backgroundColor,
|
|
76
|
+
});
|
|
77
|
+
// Create gradient definition
|
|
78
|
+
const defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
79
|
+
const gradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
|
|
80
|
+
setAttributes(gradient, {
|
|
81
|
+
id: `civic-shimmer-gradient-${Date.now()}`,
|
|
82
|
+
x2: "320",
|
|
83
|
+
y1: "15",
|
|
84
|
+
y2: "15",
|
|
85
|
+
gradientUnits: "userSpaceOnUse",
|
|
86
|
+
});
|
|
87
|
+
// Create gradient stops
|
|
88
|
+
const stop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
89
|
+
setAttributes(stop1, {
|
|
90
|
+
offset: "0",
|
|
91
|
+
"stop-color": backgroundColor,
|
|
92
|
+
});
|
|
93
|
+
const stop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
94
|
+
setAttributes(stop2, {
|
|
95
|
+
offset: ".511",
|
|
96
|
+
"stop-color": "#9A9DA6",
|
|
97
|
+
});
|
|
98
|
+
const stop3 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
99
|
+
setAttributes(stop3, {
|
|
100
|
+
offset: "1",
|
|
101
|
+
"stop-color": backgroundColor,
|
|
102
|
+
});
|
|
103
|
+
gradient.appendChild(stop1);
|
|
104
|
+
gradient.appendChild(stop2);
|
|
105
|
+
gradient.appendChild(stop3);
|
|
106
|
+
defs.appendChild(gradient);
|
|
107
|
+
// Create background rectangle
|
|
108
|
+
const rect = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
109
|
+
setAttributes(rect, {
|
|
110
|
+
id: "civic-shimmer-rect",
|
|
111
|
+
fill: backgroundColor,
|
|
112
|
+
d: "M0 0h328v28H0z",
|
|
113
|
+
});
|
|
114
|
+
// Create shimmer path
|
|
115
|
+
const shimmer = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
116
|
+
setAttributes(shimmer, {
|
|
117
|
+
id: "civic-shimmer-path",
|
|
118
|
+
fill: `url(#${gradient.getAttribute("id")})`,
|
|
119
|
+
d: "M0 -2h328v34H0z",
|
|
120
|
+
transform: "translate(-328)",
|
|
121
|
+
});
|
|
122
|
+
setStyles(shimmer, {
|
|
123
|
+
animation: "1s linear infinite both civic-shimmer",
|
|
124
|
+
});
|
|
125
|
+
// Assemble SVG
|
|
126
|
+
svg.appendChild(defs);
|
|
127
|
+
svg.appendChild(rect);
|
|
128
|
+
svg.appendChild(shimmer);
|
|
129
|
+
// Add SVG to container
|
|
130
|
+
container.appendChild(svg);
|
|
131
|
+
return container;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Creates a shimmer loader for iframe loading states
|
|
135
|
+
* Positioned to center within an iframe container
|
|
136
|
+
*/
|
|
137
|
+
export function createIframeShimmerLoader(backgroundColor = "#ffffff", maxWidth) {
|
|
138
|
+
const wrapper = document.createElement("div");
|
|
139
|
+
const wrapperStyles = {
|
|
140
|
+
width: "100%",
|
|
141
|
+
height: "26px",
|
|
142
|
+
display: "flex",
|
|
143
|
+
alignItems: "center",
|
|
144
|
+
justifyContent: "center",
|
|
145
|
+
position: "absolute",
|
|
146
|
+
top: "50%",
|
|
147
|
+
left: "50%",
|
|
148
|
+
transform: "translate(-50%, -50%)",
|
|
149
|
+
borderRadius: "13px",
|
|
150
|
+
overflow: "hidden",
|
|
151
|
+
};
|
|
152
|
+
// Add max-width if specified
|
|
153
|
+
if (maxWidth) {
|
|
154
|
+
wrapperStyles.maxWidth = maxWidth;
|
|
155
|
+
}
|
|
156
|
+
setStyles(wrapper, wrapperStyles);
|
|
157
|
+
setAttributes(wrapper, {
|
|
158
|
+
"data-testid": "iframe-shimmer-loader",
|
|
159
|
+
class: "civic-auth-iframe-shimmer-wrapper",
|
|
160
|
+
});
|
|
161
|
+
const shimmerLoader = createShimmerLoader({
|
|
162
|
+
backgroundColor,
|
|
163
|
+
width: "100%",
|
|
164
|
+
height: "26px",
|
|
165
|
+
borderRadius: "13px",
|
|
166
|
+
});
|
|
167
|
+
wrapper.appendChild(shimmerLoader);
|
|
168
|
+
return wrapper;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Creates a simple horizontal skeleton loader (CSS-based alternative)
|
|
172
|
+
* Lighter weight alternative to SVG shimmer
|
|
173
|
+
*/
|
|
174
|
+
export function createSkeletonLoader(options = {}) {
|
|
175
|
+
const { backgroundColor = "#f0f0f0", width = "100%", height = "20px", borderRadius = "4px", } = options;
|
|
176
|
+
const skeleton = document.createElement("div");
|
|
177
|
+
setStyles(skeleton, {
|
|
178
|
+
width,
|
|
179
|
+
height,
|
|
180
|
+
background: `linear-gradient(90deg, ${backgroundColor} 25%, #e0e0e0 50%, ${backgroundColor} 75%)`,
|
|
181
|
+
backgroundSize: "200% 100%",
|
|
182
|
+
animation: "civic-skeleton-shimmer 1.5s infinite",
|
|
183
|
+
borderRadius,
|
|
184
|
+
});
|
|
185
|
+
setAttributes(skeleton, {
|
|
186
|
+
class: "civic-auth-skeleton-loader",
|
|
187
|
+
});
|
|
188
|
+
// Add CSS animation keyframes for skeleton
|
|
189
|
+
const style = document.createElement("style");
|
|
190
|
+
style.textContent = `
|
|
191
|
+
@keyframes civic-skeleton-shimmer {
|
|
192
|
+
0% { background-position: -200% 0; }
|
|
193
|
+
100% { background-position: 200% 0; }
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
// Only add the style if it doesn't already exist
|
|
197
|
+
if (!document.querySelector("style[data-civic-skeleton]")) {
|
|
198
|
+
style.setAttribute("data-civic-skeleton", "true");
|
|
199
|
+
document.head.appendChild(style);
|
|
200
|
+
}
|
|
201
|
+
return skeleton;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Creates a button content loader that hides content and shows a skeleton
|
|
205
|
+
* Equivalent to ButtonContentOrLoader from React implementation
|
|
206
|
+
*/
|
|
207
|
+
export function createButtonContentLoader(content) {
|
|
208
|
+
const container = document.createElement("div");
|
|
209
|
+
setStyles(container, {
|
|
210
|
+
position: "relative",
|
|
211
|
+
display: "flex",
|
|
212
|
+
alignItems: "center",
|
|
213
|
+
justifyContent: "center",
|
|
214
|
+
});
|
|
215
|
+
setAttributes(container, {
|
|
216
|
+
class: "civic-auth-button-content-loader",
|
|
217
|
+
});
|
|
218
|
+
// Content span
|
|
219
|
+
const contentSpan = document.createElement("span");
|
|
220
|
+
setStyles(contentSpan, {
|
|
221
|
+
visibility: "visible",
|
|
222
|
+
whiteSpace: "nowrap",
|
|
223
|
+
});
|
|
224
|
+
setAttributes(contentSpan, {
|
|
225
|
+
class: "civic-auth-button-content",
|
|
226
|
+
});
|
|
227
|
+
if (typeof content === "string") {
|
|
228
|
+
contentSpan.textContent = content;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
contentSpan.appendChild(content);
|
|
232
|
+
}
|
|
233
|
+
// Loader span (hidden by default)
|
|
234
|
+
const loaderSpan = document.createElement("span");
|
|
235
|
+
setStyles(loaderSpan, {
|
|
236
|
+
position: "absolute",
|
|
237
|
+
display: "none",
|
|
238
|
+
justifyContent: "center",
|
|
239
|
+
alignItems: "center",
|
|
240
|
+
top: "0",
|
|
241
|
+
left: "0",
|
|
242
|
+
right: "0",
|
|
243
|
+
bottom: "0",
|
|
244
|
+
});
|
|
245
|
+
setAttributes(loaderSpan, {
|
|
246
|
+
class: "civic-auth-button-loader",
|
|
247
|
+
});
|
|
248
|
+
// Create skeleton loader for button
|
|
249
|
+
const skeletonLoader = createSkeletonLoader({
|
|
250
|
+
width: "70%",
|
|
251
|
+
height: "14px",
|
|
252
|
+
borderRadius: "7px",
|
|
253
|
+
});
|
|
254
|
+
loaderSpan.appendChild(skeletonLoader);
|
|
255
|
+
container.appendChild(contentSpan);
|
|
256
|
+
container.appendChild(loaderSpan);
|
|
257
|
+
return {
|
|
258
|
+
container,
|
|
259
|
+
showLoader: () => {
|
|
260
|
+
contentSpan.style.visibility = "hidden";
|
|
261
|
+
loaderSpan.style.display = "flex";
|
|
262
|
+
},
|
|
263
|
+
hideLoader: () => {
|
|
264
|
+
contentSpan.style.visibility = "visible";
|
|
265
|
+
loaderSpan.style.display = "none";
|
|
266
|
+
},
|
|
267
|
+
setContent: (newContent) => {
|
|
268
|
+
contentSpan.innerHTML = "";
|
|
269
|
+
if (typeof newContent === "string") {
|
|
270
|
+
contentSpan.textContent = newContent;
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
contentSpan.appendChild(newContent);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Creates a close icon (X) SVG element
|
|
280
|
+
* Equivalent to the CloseIcon component from React implementation
|
|
281
|
+
*/
|
|
282
|
+
export function createCloseIcon() {
|
|
283
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
284
|
+
setAttributes(svg, {
|
|
285
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
286
|
+
width: "24",
|
|
287
|
+
height: "24",
|
|
288
|
+
viewBox: "0 0 24 24",
|
|
289
|
+
fill: "none",
|
|
290
|
+
stroke: "currentColor",
|
|
291
|
+
"stroke-width": "2",
|
|
292
|
+
"stroke-linecap": "round",
|
|
293
|
+
"stroke-linejoin": "round",
|
|
294
|
+
class: "lucide lucide-x",
|
|
295
|
+
});
|
|
296
|
+
// Create the X paths
|
|
297
|
+
const path1 = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
298
|
+
setAttributes(path1, {
|
|
299
|
+
d: "M18 6 6 18",
|
|
300
|
+
});
|
|
301
|
+
const path2 = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
302
|
+
setAttributes(path2, {
|
|
303
|
+
d: "m6 6 12 12",
|
|
304
|
+
});
|
|
305
|
+
svg.appendChild(path1);
|
|
306
|
+
svg.appendChild(path2);
|
|
307
|
+
return svg;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Creates a close button for modal iframes
|
|
311
|
+
* Positioned absolutely in the top-right corner
|
|
312
|
+
*/
|
|
313
|
+
export function createCloseButton(onClose) {
|
|
314
|
+
const button = document.createElement("button");
|
|
315
|
+
setStyles(button, {
|
|
316
|
+
position: "absolute",
|
|
317
|
+
right: "0.6rem",
|
|
318
|
+
top: "0.6rem",
|
|
319
|
+
cursor: "pointer",
|
|
320
|
+
display: "flex",
|
|
321
|
+
alignItems: "center",
|
|
322
|
+
justifyContent: "center",
|
|
323
|
+
border: "none",
|
|
324
|
+
backgroundColor: "transparent",
|
|
325
|
+
padding: "0.25rem",
|
|
326
|
+
color: "#9ca3af",
|
|
327
|
+
zIndex: "100",
|
|
328
|
+
opacity: "0",
|
|
329
|
+
transition: "opacity 50ms ease",
|
|
330
|
+
});
|
|
331
|
+
setAttributes(button, {
|
|
332
|
+
type: "button",
|
|
333
|
+
"aria-label": "Close",
|
|
334
|
+
});
|
|
335
|
+
// Add hover effect
|
|
336
|
+
button.addEventListener("mouseenter", () => {
|
|
337
|
+
button.style.opacity = "0.8";
|
|
338
|
+
});
|
|
339
|
+
button.addEventListener("mouseleave", () => {
|
|
340
|
+
button.style.opacity = "1";
|
|
341
|
+
});
|
|
342
|
+
// Add the close icon
|
|
343
|
+
const closeIcon = createCloseIcon();
|
|
344
|
+
button.appendChild(closeIcon);
|
|
345
|
+
// Add click handler
|
|
346
|
+
button.addEventListener("click", onClose);
|
|
347
|
+
return button;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Utility function to remove all civic auth loading styles from the document
|
|
351
|
+
* Useful for cleanup
|
|
352
|
+
*/
|
|
353
|
+
export function cleanupLoadingStyles() {
|
|
354
|
+
const shimmerStyle = document.querySelector("style[data-civic-shimmer]");
|
|
355
|
+
const skeletonStyle = document.querySelector("style[data-civic-skeleton]");
|
|
356
|
+
if (shimmerStyle) {
|
|
357
|
+
shimmerStyle.remove();
|
|
358
|
+
}
|
|
359
|
+
if (skeletonStyle) {
|
|
360
|
+
skeletonStyle.remove();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
//# sourceMappingURL=LoadingComponents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingComponents.js","sourceRoot":"","sources":["../../../src/vanillajs/ui/LoadingComponents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,SAAS,SAAS,CAChB,OAAiC,EACjC,MAA8B;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CA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AE,CAAC;IACxB,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,aAAa,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["/**\n * UI Components for Civic Auth Vanilla JS implementation\n * Converted from React components to vanilla DOM elements\n */\n\n/**\n * Utility function to set multiple styles on an element using a key-value object\n */\nfunction setStyles(\n element: HTMLElement | SVGElement,\n styles: Record<string, string>,\n): void {\n Object.entries(styles).forEach(([property, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- CSSStyleDeclaration has read-only properties that prevent proper typing\n (element.style as any)[property] = value;\n });\n}\n\n/**\n * Utility function to set multiple attributes on an element using a key-value object\n */\nfunction setAttributes(\n element: Element,\n attributes: Record<string, string>,\n): void {\n Object.entries(attributes).forEach(([name, value]) => {\n element.setAttribute(name, value);\n });\n}\n\nexport interface ShimmerLoaderOptions {\n backgroundColor?: string;\n width?: string;\n height?: string;\n borderRadius?: string;\n}\n\n/**\n * Creates a horizontal shimmer loader element (SVG-based)\n * Equivalent to the SVGLoading component from React implementation\n */\nexport function createShimmerLoader(\n options: ShimmerLoaderOptions = {},\n): HTMLElement {\n const {\n backgroundColor = \"#ffffff\",\n width = \"100%\",\n height = \"40px\",\n borderRadius = \"0.5rem\",\n } = options;\n\n // Create container div\n const container = document.createElement(\"div\");\n setStyles(container, {\n position: \"absolute\",\n top: \"-6px\",\n left: \"0\",\n borderRadius,\n backgroundColor,\n width,\n height,\n opacity: \"1\",\n });\n setAttributes(container, {\n class: \"civic-auth-shimmer-loader\",\n });\n\n // Add CSS animation keyframes\n const style = document.createElement(\"style\");\n style.textContent = `\n @keyframes civic-shimmer {\n 0% {\n transform: translate(-328px, 0);\n }\n 100% {\n transform: translate(328px, 0);\n }\n }\n `;\n\n // Only add the style if it doesn't already exist\n if (!document.querySelector(\"style[data-civic-shimmer]\")) {\n style.setAttribute(\"data-civic-shimmer\", \"true\");\n document.head.appendChild(style);\n }\n\n // Create SVG element\n const svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n setAttributes(svg, {\n \"shape-rendering\": \"geometricPrecision\",\n \"text-rendering\": \"geometricPrecision\",\n viewBox: \"0 0 324 28\",\n height: \"40\",\n width: \"100%\",\n class: \"civic-auth-svg-loading\",\n });\n setStyles(svg, {\n position: \"absolute\",\n top: \"-6px\",\n left: \"0\",\n borderRadius,\n backgroundColor,\n });\n\n // Create gradient definition\n const defs = document.createElementNS(\"http://www.w3.org/2000/svg\", \"defs\");\n const gradient = document.createElementNS(\n \"http://www.w3.org/2000/svg\",\n \"linearGradient\",\n );\n setAttributes(gradient, {\n id: `civic-shimmer-gradient-${Date.now()}`,\n x2: \"320\",\n y1: \"15\",\n y2: \"15\",\n gradientUnits: \"userSpaceOnUse\",\n });\n\n // Create gradient stops\n const stop1 = document.createElementNS(\"http://www.w3.org/2000/svg\", \"stop\");\n setAttributes(stop1, {\n offset: \"0\",\n \"stop-color\": backgroundColor,\n });\n\n const stop2 = document.createElementNS(\"http://www.w3.org/2000/svg\", \"stop\");\n setAttributes(stop2, {\n offset: \".511\",\n \"stop-color\": \"#9A9DA6\",\n });\n\n const stop3 = document.createElementNS(\"http://www.w3.org/2000/svg\", \"stop\");\n setAttributes(stop3, {\n offset: \"1\",\n \"stop-color\": backgroundColor,\n });\n\n gradient.appendChild(stop1);\n gradient.appendChild(stop2);\n gradient.appendChild(stop3);\n defs.appendChild(gradient);\n\n // Create background rectangle\n const rect = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n setAttributes(rect, {\n id: \"civic-shimmer-rect\",\n fill: backgroundColor,\n d: \"M0 0h328v28H0z\",\n });\n\n // Create shimmer path\n const shimmer = document.createElementNS(\n \"http://www.w3.org/2000/svg\",\n \"path\",\n );\n setAttributes(shimmer, {\n id: \"civic-shimmer-path\",\n fill: `url(#${gradient.getAttribute(\"id\")})`,\n d: \"M0 -2h328v34H0z\",\n transform: \"translate(-328)\",\n });\n setStyles(shimmer, {\n animation: \"1s linear infinite both civic-shimmer\",\n });\n\n // Assemble SVG\n svg.appendChild(defs);\n svg.appendChild(rect);\n svg.appendChild(shimmer);\n\n // Add SVG to container\n container.appendChild(svg);\n\n return container;\n}\n\n/**\n * Creates a shimmer loader for iframe loading states\n * Positioned to center within an iframe container\n */\nexport function createIframeShimmerLoader(\n backgroundColor = \"#ffffff\",\n maxWidth?: string,\n): HTMLElement {\n const wrapper = document.createElement(\"div\");\n const wrapperStyles: Record<string, string> = {\n width: \"100%\",\n height: \"26px\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n position: \"absolute\",\n top: \"50%\",\n left: \"50%\",\n transform: \"translate(-50%, -50%)\",\n borderRadius: \"13px\",\n overflow: \"hidden\",\n };\n\n // Add max-width if specified\n if (maxWidth) {\n wrapperStyles.maxWidth = maxWidth;\n }\n\n setStyles(wrapper, wrapperStyles);\n setAttributes(wrapper, {\n \"data-testid\": \"iframe-shimmer-loader\",\n class: \"civic-auth-iframe-shimmer-wrapper\",\n });\n\n const shimmerLoader = createShimmerLoader({\n backgroundColor,\n width: \"100%\",\n height: \"26px\",\n borderRadius: \"13px\",\n });\n\n wrapper.appendChild(shimmerLoader);\n return wrapper;\n}\n\n/**\n * Creates a simple horizontal skeleton loader (CSS-based alternative)\n * Lighter weight alternative to SVG shimmer\n */\nexport function createSkeletonLoader(\n options: ShimmerLoaderOptions = {},\n): HTMLElement {\n const {\n backgroundColor = \"#f0f0f0\",\n width = \"100%\",\n height = \"20px\",\n borderRadius = \"4px\",\n } = options;\n\n const skeleton = document.createElement(\"div\");\n setStyles(skeleton, {\n width,\n height,\n background: `linear-gradient(90deg, ${backgroundColor} 25%, #e0e0e0 50%, ${backgroundColor} 75%)`,\n backgroundSize: \"200% 100%\",\n animation: \"civic-skeleton-shimmer 1.5s infinite\",\n borderRadius,\n });\n setAttributes(skeleton, {\n class: \"civic-auth-skeleton-loader\",\n });\n\n // Add CSS animation keyframes for skeleton\n const style = document.createElement(\"style\");\n style.textContent = `\n @keyframes civic-skeleton-shimmer {\n 0% { background-position: -200% 0; }\n 100% { background-position: 200% 0; }\n }\n `;\n\n // Only add the style if it doesn't already exist\n if (!document.querySelector(\"style[data-civic-skeleton]\")) {\n style.setAttribute(\"data-civic-skeleton\", \"true\");\n document.head.appendChild(style);\n }\n\n return skeleton;\n}\n\n/**\n * Creates a button content loader that hides content and shows a skeleton\n * Equivalent to ButtonContentOrLoader from React implementation\n */\nexport function createButtonContentLoader(content: string | HTMLElement): {\n container: HTMLElement;\n showLoader: () => void;\n hideLoader: () => void;\n setContent: (newContent: string | HTMLElement) => void;\n} {\n const container = document.createElement(\"div\");\n setStyles(container, {\n position: \"relative\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n });\n setAttributes(container, {\n class: \"civic-auth-button-content-loader\",\n });\n\n // Content span\n const contentSpan = document.createElement(\"span\");\n setStyles(contentSpan, {\n visibility: \"visible\",\n whiteSpace: \"nowrap\",\n });\n setAttributes(contentSpan, {\n class: \"civic-auth-button-content\",\n });\n\n if (typeof content === \"string\") {\n contentSpan.textContent = content;\n } else {\n contentSpan.appendChild(content);\n }\n\n // Loader span (hidden by default)\n const loaderSpan = document.createElement(\"span\");\n setStyles(loaderSpan, {\n position: \"absolute\",\n display: \"none\",\n justifyContent: \"center\",\n alignItems: \"center\",\n top: \"0\",\n left: \"0\",\n right: \"0\",\n bottom: \"0\",\n });\n setAttributes(loaderSpan, {\n class: \"civic-auth-button-loader\",\n });\n\n // Create skeleton loader for button\n const skeletonLoader = createSkeletonLoader({\n width: \"70%\",\n height: \"14px\",\n borderRadius: \"7px\",\n });\n loaderSpan.appendChild(skeletonLoader);\n\n container.appendChild(contentSpan);\n container.appendChild(loaderSpan);\n\n return {\n container,\n showLoader: () => {\n contentSpan.style.visibility = \"hidden\";\n loaderSpan.style.display = \"flex\";\n },\n hideLoader: () => {\n contentSpan.style.visibility = \"visible\";\n loaderSpan.style.display = \"none\";\n },\n setContent: (newContent: string | HTMLElement) => {\n contentSpan.innerHTML = \"\";\n if (typeof newContent === \"string\") {\n contentSpan.textContent = newContent;\n } else {\n contentSpan.appendChild(newContent);\n }\n },\n };\n}\n\n/**\n * Creates a close icon (X) SVG element\n * Equivalent to the CloseIcon component from React implementation\n */\nexport function createCloseIcon(): SVGElement {\n const svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n setAttributes(svg, {\n xmlns: \"http://www.w3.org/2000/svg\",\n width: \"24\",\n height: \"24\",\n viewBox: \"0 0 24 24\",\n fill: \"none\",\n stroke: \"currentColor\",\n \"stroke-width\": \"2\",\n \"stroke-linecap\": \"round\",\n \"stroke-linejoin\": \"round\",\n class: \"lucide lucide-x\",\n });\n\n // Create the X paths\n const path1 = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n setAttributes(path1, {\n d: \"M18 6 6 18\",\n });\n\n const path2 = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n setAttributes(path2, {\n d: \"m6 6 12 12\",\n });\n\n svg.appendChild(path1);\n svg.appendChild(path2);\n\n return svg;\n}\n\n/**\n * Creates a close button for modal iframes\n * Positioned absolutely in the top-right corner\n */\nexport function createCloseButton(onClose: () => void): HTMLButtonElement {\n const button = document.createElement(\"button\");\n setStyles(button, {\n position: \"absolute\",\n right: \"0.6rem\",\n top: \"0.6rem\",\n cursor: \"pointer\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n border: \"none\",\n backgroundColor: \"transparent\",\n padding: \"0.25rem\",\n color: \"#9ca3af\",\n zIndex: \"100\",\n opacity: \"0\",\n transition: \"opacity 50ms ease\",\n });\n setAttributes(button, {\n type: \"button\",\n \"aria-label\": \"Close\",\n });\n\n // Add hover effect\n button.addEventListener(\"mouseenter\", () => {\n button.style.opacity = \"0.8\";\n });\n\n button.addEventListener(\"mouseleave\", () => {\n button.style.opacity = \"1\";\n });\n\n // Add the close icon\n const closeIcon = createCloseIcon();\n button.appendChild(closeIcon);\n\n // Add click handler\n button.addEventListener(\"click\", onClose);\n\n return button;\n}\n\n/**\n * Utility function to remove all civic auth loading styles from the document\n * Useful for cleanup\n */\nexport function cleanupLoadingStyles(): void {\n const shimmerStyle = document.querySelector(\"style[data-civic-shimmer]\");\n const skeletonStyle = document.querySelector(\"style[data-civic-skeleton]\");\n\n if (shimmerStyle) {\n shimmerStyle.remove();\n }\n\n if (skeletonStyle) {\n skeletonStyle.remove();\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Endpoints } from "../../types.js";
|
|
2
|
+
interface BuildAuthUrlParams {
|
|
3
|
+
endpoints: Endpoints;
|
|
4
|
+
clientId: string;
|
|
5
|
+
redirectUrl: string;
|
|
6
|
+
scopes: string[];
|
|
7
|
+
codeChallenge: string;
|
|
8
|
+
state: string;
|
|
9
|
+
prompt?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildAuthUrl({ endpoints, clientId, redirectUrl, scopes, codeChallenge, state, prompt, }: BuildAuthUrlParams): string;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/utils/auth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,UAAU,kBAAkB;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,QAAQ,EACR,WAAW,EACX,MAAM,EACN,aAAa,EACb,KAAK,EACL,MAAM,GACP,EAAE,kBAAkB,GAAG,MAAM,CAe7B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function buildAuthUrl({ endpoints, clientId, redirectUrl, scopes, codeChallenge, state, prompt, }) {
|
|
2
|
+
const authUrl = new URL(endpoints.auth);
|
|
3
|
+
authUrl.searchParams.append("client_id", clientId);
|
|
4
|
+
authUrl.searchParams.append("redirect_uri", redirectUrl);
|
|
5
|
+
authUrl.searchParams.append("response_type", "code");
|
|
6
|
+
authUrl.searchParams.append("scope", scopes.join(" "));
|
|
7
|
+
authUrl.searchParams.append("state", state);
|
|
8
|
+
authUrl.searchParams.append("code_challenge", codeChallenge);
|
|
9
|
+
authUrl.searchParams.append("code_challenge_method", "S256");
|
|
10
|
+
if (prompt) {
|
|
11
|
+
authUrl.searchParams.append("prompt", prompt);
|
|
12
|
+
}
|
|
13
|
+
return authUrl.toString();
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=auth-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.js","sourceRoot":"","sources":["../../../src/vanillajs/utils/auth-utils.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,QAAQ,EACR,WAAW,EACX,MAAM,EACN,aAAa,EACb,KAAK,EACL,MAAM,GACa;IACnB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACnD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACzD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC;IAC7D,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;IAE7D,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import type { Endpoints } from \"../../types.js\";\n\ninterface BuildAuthUrlParams {\n endpoints: Endpoints;\n clientId: string;\n redirectUrl: string;\n scopes: string[];\n codeChallenge: string;\n state: string;\n prompt?: string;\n}\n\nexport function buildAuthUrl({\n endpoints,\n clientId,\n redirectUrl,\n scopes,\n codeChallenge,\n state,\n prompt,\n}: BuildAuthUrlParams): string {\n const authUrl = new URL(endpoints.auth);\n authUrl.searchParams.append(\"client_id\", clientId);\n authUrl.searchParams.append(\"redirect_uri\", redirectUrl);\n authUrl.searchParams.append(\"response_type\", \"code\");\n authUrl.searchParams.append(\"scope\", scopes.join(\" \"));\n authUrl.searchParams.append(\"state\", state);\n authUrl.searchParams.append(\"code_challenge\", codeChallenge);\n authUrl.searchParams.append(\"code_challenge_method\", \"S256\");\n\n if (prompt) {\n authUrl.searchParams.append(\"prompt\", prompt);\n }\n\n return authUrl.toString();\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
export declare const loggers: {
|
|
3
|
+
auth: debug.Debugger;
|
|
4
|
+
api: debug.Debugger;
|
|
5
|
+
storage: debug.Debugger;
|
|
6
|
+
session: debug.Debugger;
|
|
7
|
+
events: debug.Debugger;
|
|
8
|
+
utils: debug.Debugger;
|
|
9
|
+
iframe: debug.Debugger;
|
|
10
|
+
};
|
|
11
|
+
export declare const createLogger: (namespace: string) => {
|
|
12
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
13
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
14
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
15
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
16
|
+
};
|
|
17
|
+
export declare const configureLogging: (config: {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
namespace?: string;
|
|
20
|
+
level?: "debug" | "info" | "warn" | "error";
|
|
21
|
+
}) => void;
|
|
22
|
+
export declare const setCurrentLogger: (logger: ReturnType<typeof createLogger>) => void;
|
|
23
|
+
export declare const getCurrentLogger: () => {
|
|
24
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
25
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
26
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
27
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,eAAO,MAAM,OAAO;;;;;;;;CAQnB,CAAC;AAGF,eAAO,MAAM,YAAY,cAAe,MAAM;qBAGzB,MAAM,WAAW,OAAO,EAAE;oBAC3B,MAAM,WAAW,OAAO,EAAE;oBAC1B,MAAM,WAAW,OAAO,EAAE;qBACzB,MAAM,WAAW,OAAO,EAAE;CAE9C,CAAC;AAGF,eAAO,MAAM,gBAAgB,WAAY;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAC7C,SAwBA,CAAC;AAMF,eAAO,MAAM,gBAAgB,WAAY,UAAU,CAAC,OAAO,YAAY,CAAC,SAEvE,CAAC;AAGF,eAAO,MAAM,gBAAgB;qBA/CR,MAAM,WAAW,OAAO,EAAE;oBAC3B,MAAM,WAAW,OAAO,EAAE;oBAC1B,MAAM,WAAW,OAAO,EAAE;qBACzB,MAAM,WAAW,OAAO,EAAE;CAkD9C,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
// Create namespaced loggers for different components
|
|
3
|
+
export const loggers = {
|
|
4
|
+
auth: debug("civic:auth"),
|
|
5
|
+
api: debug("civic:auth:api"),
|
|
6
|
+
storage: debug("civic:auth:storage"),
|
|
7
|
+
session: debug("civic:auth:session"),
|
|
8
|
+
events: debug("civic:auth:events"),
|
|
9
|
+
utils: debug("civic:auth:utils"),
|
|
10
|
+
iframe: debug("civic:auth:iframe"),
|
|
11
|
+
};
|
|
12
|
+
// Helper function to create a logger with a specific namespace
|
|
13
|
+
export const createLogger = (namespace) => {
|
|
14
|
+
const logger = debug(`civic:auth:${namespace}`);
|
|
15
|
+
return {
|
|
16
|
+
debug: (message, ...args) => logger(message, ...args),
|
|
17
|
+
info: (message, ...args) => logger(message, ...args),
|
|
18
|
+
warn: (message, ...args) => logger(message, ...args),
|
|
19
|
+
error: (message, ...args) => logger(message, ...args),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
// Function to configure logging based on config
|
|
23
|
+
export const configureLogging = (config) => {
|
|
24
|
+
if (typeof window === "undefined")
|
|
25
|
+
return;
|
|
26
|
+
if (config.enabled) {
|
|
27
|
+
// Enable specific namespace if provided, otherwise enable all civic:auth namespaces
|
|
28
|
+
const namespace = config.namespace
|
|
29
|
+
? `civic:auth:${config.namespace}`
|
|
30
|
+
: "civic:auth:*";
|
|
31
|
+
debug.enable(namespace);
|
|
32
|
+
// Override debug's default log function to ensure it works in the browser
|
|
33
|
+
const originalLog = debug.log;
|
|
34
|
+
debug.log = (...args) => {
|
|
35
|
+
if (typeof console !== "undefined") {
|
|
36
|
+
console.log(...args);
|
|
37
|
+
}
|
|
38
|
+
if (originalLog) {
|
|
39
|
+
originalLog.apply(debug, args);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Disable all debug logs
|
|
45
|
+
debug.disable();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// Global variable to store the current logger instance
|
|
49
|
+
let currentLogger = null;
|
|
50
|
+
// Function to set the current logger instance
|
|
51
|
+
export const setCurrentLogger = (logger) => {
|
|
52
|
+
currentLogger = logger;
|
|
53
|
+
};
|
|
54
|
+
// Function to get the current logger instance
|
|
55
|
+
export const getCurrentLogger = () => {
|
|
56
|
+
if (!currentLogger) {
|
|
57
|
+
// Create a default logger if none is set
|
|
58
|
+
currentLogger = createLogger("default");
|
|
59
|
+
}
|
|
60
|
+
return currentLogger;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/vanillajs/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,qDAAqD;AACrD,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,KAAK,CAAC,YAAY,CAAC;IACzB,GAAG,EAAE,KAAK,CAAC,gBAAgB,CAAC;IAC5B,OAAO,EAAE,KAAK,CAAC,oBAAoB,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,oBAAoB,CAAC;IACpC,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC;IAClC,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC;IAChC,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC;CACnC,CAAC;AAEF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAAiB,EAAE,EAAE;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,cAAc,SAAS,EAAE,CAAC,CAAC;IAChD,OAAO;Q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,EAAE,CAAC;IAClB,CAAC;AACH,CAAC,CAAC;AAEF,uDAAuD;AACvD,IAAI,aAAa,GAA2C,IAAI,CAAC;AAEjE,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAuC,EAAE,EAAE;IAC1E,aAAa,GAAG,MAAM,CAAC;AACzB,CAAC,CAAC;AAEF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,yCAAyC;QACzC,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import debug from \"debug\";\n\n// Create namespaced loggers for different components\nexport const loggers = {\n auth: debug(\"civic:auth\"),\n api: debug(\"civic:auth:api\"),\n storage: debug(\"civic:auth:storage\"),\n session: debug(\"civic:auth:session\"),\n events: debug(\"civic:auth:events\"),\n utils: debug(\"civic:auth:utils\"),\n iframe: debug(\"civic:auth:iframe\"),\n};\n\n// Helper function to create a logger with a specific namespace\nexport const createLogger = (namespace: string) => {\n const logger = debug(`civic:auth:${namespace}`);\n return {\n debug: (message: string, ...args: unknown[]) => logger(message, ...args),\n info: (message: string, ...args: unknown[]) => logger(message, ...args),\n warn: (message: string, ...args: unknown[]) => logger(message, ...args),\n error: (message: string, ...args: unknown[]) => logger(message, ...args),\n };\n};\n\n// Function to configure logging based on config\nexport const configureLogging = (config: {\n enabled: boolean;\n namespace?: string;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\";\n}) => {\n if (typeof window === \"undefined\") return;\n\n if (config.enabled) {\n // Enable specific namespace if provided, otherwise enable all civic:auth namespaces\n const namespace = config.namespace\n ? `civic:auth:${config.namespace}`\n : \"civic:auth:*\";\n debug.enable(namespace);\n\n // Override debug's default log function to ensure it works in the browser\n const originalLog = debug.log;\n debug.log = (...args) => {\n if (typeof console !== \"undefined\") {\n console.log(...args);\n }\n if (originalLog) {\n originalLog.apply(debug, args);\n }\n };\n } else {\n // Disable all debug logs\n debug.disable();\n }\n};\n\n// Global variable to store the current logger instance\nlet currentLogger: ReturnType<typeof createLogger> | null = null;\n\n// Function to set the current logger instance\nexport const setCurrentLogger = (logger: ReturnType<typeof createLogger>) => {\n currentLogger = logger;\n};\n\n// Function to get the current logger instance\nexport const getCurrentLogger = () => {\n if (!currentLogger) {\n // Create a default logger if none is set\n currentLogger = createLogger(\"default\");\n }\n return currentLogger;\n};\n"]}
|