@shware/http 2.11.4 → 2.12.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.
Files changed (236) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +13 -0
  2. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  3. package/dist/cache/index.cjs +5 -30
  4. package/dist/cache/index.cjs.map +1 -1
  5. package/dist/cache/index.d.cts +7 -5
  6. package/dist/cache/index.d.cts.map +1 -0
  7. package/dist/cache/index.d.mts +11 -0
  8. package/dist/cache/index.d.mts.map +1 -0
  9. package/dist/cache/index.mjs +5 -6
  10. package/dist/cache/index.mjs.map +1 -1
  11. package/dist/error/detail.cjs +100 -90
  12. package/dist/error/detail.cjs.map +1 -1
  13. package/dist/error/detail.d.cts +77 -78
  14. package/dist/error/detail.d.cts.map +1 -0
  15. package/dist/error/detail.d.mts +108 -0
  16. package/dist/error/detail.d.mts.map +1 -0
  17. package/dist/error/detail.mjs +99 -65
  18. package/dist/error/detail.mjs.map +1 -1
  19. package/dist/error/i18n/en-us.cjs +5 -29
  20. package/dist/error/i18n/en-us.cjs.map +1 -1
  21. package/dist/error/i18n/en-us.d.cts +3 -1
  22. package/dist/error/i18n/en-us.d.cts.map +1 -0
  23. package/dist/error/i18n/en-us.d.mts +5 -0
  24. package/dist/error/i18n/en-us.d.mts.map +1 -0
  25. package/dist/error/i18n/en-us.mjs +5 -5
  26. package/dist/error/i18n/en-us.mjs.map +1 -1
  27. package/dist/error/index.cjs +29 -56
  28. package/dist/error/index.cjs.map +1 -1
  29. package/dist/error/index.d.cts +12 -10
  30. package/dist/error/index.d.cts.map +1 -0
  31. package/dist/error/index.d.mts +21 -0
  32. package/dist/error/index.d.mts.map +1 -0
  33. package/dist/error/index.mjs +25 -28
  34. package/dist/error/index.mjs.map +1 -1
  35. package/dist/error/parse.cjs +63 -61
  36. package/dist/error/parse.cjs.map +1 -1
  37. package/dist/error/parse.d.cts +8 -7
  38. package/dist/error/parse.d.cts.map +1 -0
  39. package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
  40. package/dist/error/parse.d.mts.map +1 -0
  41. package/dist/error/parse.mjs +59 -33
  42. package/dist/error/parse.mjs.map +1 -1
  43. package/dist/error/reason.cjs +0 -19
  44. package/dist/error/reason.d.cts +5 -4
  45. package/dist/error/reason.d.cts.map +1 -0
  46. package/dist/error/reason.d.mts +6 -0
  47. package/dist/error/reason.d.mts.map +1 -0
  48. package/dist/error/reason.mjs +1 -1
  49. package/dist/error/status.cjs +103 -256
  50. package/dist/error/status.cjs.map +1 -1
  51. package/dist/error/status.d.cts +58 -58
  52. package/dist/error/status.d.cts.map +1 -0
  53. package/dist/error/status.d.mts +69 -0
  54. package/dist/error/status.d.mts.map +1 -0
  55. package/dist/error/status.mjs +98 -227
  56. package/dist/error/status.mjs.map +1 -1
  57. package/dist/google-one-tap/index.cjs +135 -138
  58. package/dist/google-one-tap/index.cjs.map +1 -1
  59. package/dist/google-one-tap/index.d.cts +49 -48
  60. package/dist/google-one-tap/index.d.cts.map +1 -0
  61. package/dist/google-one-tap/index.d.mts +82 -0
  62. package/dist/google-one-tap/index.d.mts.map +1 -0
  63. package/dist/google-one-tap/index.mjs +133 -112
  64. package/dist/google-one-tap/index.mjs.map +1 -1
  65. package/dist/google-one-tap/types.cjs +0 -19
  66. package/dist/google-one-tap/types.d.cts +124 -122
  67. package/dist/google-one-tap/types.d.cts.map +1 -0
  68. package/dist/google-one-tap/types.d.mts +157 -0
  69. package/dist/google-one-tap/types.d.mts.map +1 -0
  70. package/dist/google-one-tap/types.mjs +1 -1
  71. package/dist/hono/authorizer.cjs +28 -65
  72. package/dist/hono/authorizer.cjs.map +1 -1
  73. package/dist/hono/authorizer.d.cts +12 -11
  74. package/dist/hono/authorizer.d.cts.map +1 -0
  75. package/dist/hono/authorizer.d.mts +19 -0
  76. package/dist/hono/authorizer.d.mts.map +1 -0
  77. package/dist/hono/authorizer.mjs +23 -36
  78. package/dist/hono/authorizer.mjs.map +1 -1
  79. package/dist/hono/csrf.cjs +81 -92
  80. package/dist/hono/csrf.cjs.map +1 -1
  81. package/dist/hono/csrf.d.cts +46 -45
  82. package/dist/hono/csrf.d.cts.map +1 -0
  83. package/dist/hono/csrf.d.mts +76 -0
  84. package/dist/hono/csrf.d.mts.map +1 -0
  85. package/dist/hono/csrf.mjs +76 -63
  86. package/dist/hono/csrf.mjs.map +1 -1
  87. package/dist/hono/geolocation.cjs +10 -34
  88. package/dist/hono/geolocation.cjs.map +1 -1
  89. package/dist/hono/geolocation.d.cts +5 -4
  90. package/dist/hono/geolocation.d.cts.map +1 -0
  91. package/dist/hono/geolocation.d.mts +7 -0
  92. package/dist/hono/geolocation.d.mts.map +1 -0
  93. package/dist/hono/geolocation.mjs +8 -12
  94. package/dist/hono/geolocation.mjs.map +1 -1
  95. package/dist/hono/handler.cjs +37 -61
  96. package/dist/hono/handler.cjs.map +1 -1
  97. package/dist/hono/handler.d.cts +26 -25
  98. package/dist/hono/handler.d.cts.map +1 -0
  99. package/dist/hono/handler.d.mts +32 -0
  100. package/dist/hono/handler.d.mts.map +1 -0
  101. package/dist/hono/handler.mjs +34 -34
  102. package/dist/hono/handler.mjs.map +1 -1
  103. package/dist/hono/index.cjs +14 -48
  104. package/dist/hono/index.d.cts +7 -15
  105. package/dist/hono/index.d.mts +7 -0
  106. package/dist/hono/index.mjs +4 -14
  107. package/dist/hono/rate-limit.cjs +65 -110
  108. package/dist/hono/rate-limit.cjs.map +1 -1
  109. package/dist/hono/rate-limit.d.cts +27 -26
  110. package/dist/hono/rate-limit.d.cts.map +1 -0
  111. package/dist/hono/rate-limit.d.mts +36 -0
  112. package/dist/hono/rate-limit.d.mts.map +1 -0
  113. package/dist/hono/rate-limit.mjs +60 -81
  114. package/dist/hono/rate-limit.mjs.map +1 -1
  115. package/dist/hono/validator.cjs +47 -66
  116. package/dist/hono/validator.cjs.map +1 -1
  117. package/dist/hono/validator.d.cts +25 -30
  118. package/dist/hono/validator.d.cts.map +1 -0
  119. package/dist/hono/validator.d.mts +26 -0
  120. package/dist/hono/validator.d.mts.map +1 -0
  121. package/dist/hono/validator.mjs +43 -43
  122. package/dist/hono/validator.mjs.map +1 -1
  123. package/dist/index.cjs +39 -95
  124. package/dist/index.d.cts +12 -14
  125. package/dist/index.d.mts +12 -0
  126. package/dist/index.mjs +5 -48
  127. package/dist/iso/iso_3601_1.cjs +1512 -290
  128. package/dist/iso/iso_3601_1.cjs.map +1 -1
  129. package/dist/iso/iso_3601_1.d.cts +8 -6
  130. package/dist/iso/iso_3601_1.d.cts.map +1 -0
  131. package/dist/iso/iso_3601_1.d.mts +11 -0
  132. package/dist/iso/iso_3601_1.d.mts.map +1 -0
  133. package/dist/iso/iso_3601_1.mjs +1511 -265
  134. package/dist/iso/iso_3601_1.mjs.map +1 -1
  135. package/dist/max-length/index.cjs +158 -91
  136. package/dist/max-length/index.cjs.map +1 -1
  137. package/dist/max-length/index.d.cts +110 -1
  138. package/dist/max-length/index.d.cts.map +1 -0
  139. package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
  140. package/dist/max-length/index.d.mts.map +1 -0
  141. package/dist/max-length/index.mjs +133 -47
  142. package/dist/max-length/index.mjs.map +1 -1
  143. package/dist/message.cjs +5 -30
  144. package/dist/message.cjs.map +1 -1
  145. package/dist/message.d.cts +3 -1
  146. package/dist/message.d.cts.map +1 -0
  147. package/dist/{message.d.ts → message.d.mts} +3 -1
  148. package/dist/message.d.mts.map +1 -0
  149. package/dist/message.mjs +5 -6
  150. package/dist/message.mjs.map +1 -1
  151. package/dist/polyfills/index.cjs +4 -4
  152. package/dist/polyfills/index.cjs.map +1 -1
  153. package/dist/polyfills/index.d.cts +1 -2
  154. package/dist/polyfills/index.d.mts +1 -0
  155. package/dist/polyfills/index.mjs +5 -2
  156. package/dist/polyfills/index.mjs.map +1 -1
  157. package/dist/response.cjs +191 -208
  158. package/dist/response.cjs.map +1 -1
  159. package/dist/response.d.cts +53 -54
  160. package/dist/response.d.cts.map +1 -0
  161. package/dist/response.d.mts +82 -0
  162. package/dist/response.d.mts.map +1 -0
  163. package/dist/response.mjs +182 -175
  164. package/dist/response.mjs.map +1 -1
  165. package/dist/snowflake.cjs +48 -70
  166. package/dist/snowflake.cjs.map +1 -1
  167. package/dist/snowflake.d.cts +16 -14
  168. package/dist/snowflake.d.cts.map +1 -0
  169. package/dist/snowflake.d.mts +31 -0
  170. package/dist/snowflake.d.mts.map +1 -0
  171. package/dist/snowflake.mjs +46 -44
  172. package/dist/snowflake.mjs.map +1 -1
  173. package/dist/utils/geolocation.cjs +51 -75
  174. package/dist/utils/geolocation.cjs.map +1 -1
  175. package/dist/utils/geolocation.d.cts +14 -12
  176. package/dist/utils/geolocation.d.cts.map +1 -0
  177. package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
  178. package/dist/utils/geolocation.d.mts.map +1 -0
  179. package/dist/utils/geolocation.mjs +47 -47
  180. package/dist/utils/geolocation.mjs.map +1 -1
  181. package/dist/utils/google-tag-gateway.cjs +35 -56
  182. package/dist/utils/google-tag-gateway.cjs.map +1 -1
  183. package/dist/utils/google-tag-gateway.d.cts +3 -1
  184. package/dist/utils/google-tag-gateway.d.cts.map +1 -0
  185. package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
  186. package/dist/utils/google-tag-gateway.d.mts.map +1 -0
  187. package/dist/utils/google-tag-gateway.mjs +33 -30
  188. package/dist/utils/google-tag-gateway.mjs.map +1 -1
  189. package/dist/utils/timing.cjs +50 -71
  190. package/dist/utils/timing.cjs.map +1 -1
  191. package/dist/utils/timing.d.cts +11 -9
  192. package/dist/utils/timing.d.cts.map +1 -0
  193. package/dist/utils/timing.d.mts +15 -0
  194. package/dist/utils/timing.d.mts.map +1 -0
  195. package/dist/utils/timing.mjs +49 -46
  196. package/dist/utils/timing.mjs.map +1 -1
  197. package/dist/webhook/index.cjs +43 -72
  198. package/dist/webhook/index.cjs.map +1 -1
  199. package/dist/webhook/index.d.cts +3 -1
  200. package/dist/webhook/index.d.cts.map +1 -0
  201. package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
  202. package/dist/webhook/index.d.mts.map +1 -0
  203. package/dist/webhook/index.mjs +41 -46
  204. package/dist/webhook/index.mjs.map +1 -1
  205. package/package.json +49 -24
  206. package/dist/cache/index.d.ts +0 -9
  207. package/dist/error/detail.d.ts +0 -109
  208. package/dist/error/i18n/en-us.d.ts +0 -3
  209. package/dist/error/index.d.ts +0 -19
  210. package/dist/error/reason.cjs.map +0 -1
  211. package/dist/error/reason.d.ts +0 -5
  212. package/dist/error/reason.mjs.map +0 -1
  213. package/dist/error/status.d.ts +0 -69
  214. package/dist/google-one-tap/index.d.ts +0 -81
  215. package/dist/google-one-tap/types.cjs.map +0 -1
  216. package/dist/google-one-tap/types.d.ts +0 -155
  217. package/dist/google-one-tap/types.mjs.map +0 -1
  218. package/dist/hono/authorizer.d.ts +0 -18
  219. package/dist/hono/csrf.d.ts +0 -75
  220. package/dist/hono/geolocation.d.ts +0 -6
  221. package/dist/hono/handler.d.ts +0 -31
  222. package/dist/hono/index.cjs.map +0 -1
  223. package/dist/hono/index.d.ts +0 -15
  224. package/dist/hono/index.mjs.map +0 -1
  225. package/dist/hono/rate-limit.d.ts +0 -35
  226. package/dist/hono/validator.d.ts +0 -31
  227. package/dist/index-BhgdyigB.d.cts +0 -129
  228. package/dist/index.cjs.map +0 -1
  229. package/dist/index.d.ts +0 -14
  230. package/dist/index.mjs.map +0 -1
  231. package/dist/iso/iso_3601_1.d.ts +0 -9
  232. package/dist/max-length/index.d.ts +0 -1
  233. package/dist/polyfills/index.d.ts +0 -2
  234. package/dist/response.d.ts +0 -83
  235. package/dist/snowflake.d.ts +0 -29
  236. package/dist/utils/timing.d.ts +0 -13
@@ -1,145 +1,142 @@
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
-
20
- // src/google-one-tap/index.ts
21
- var google_one_tap_exports = {};
22
- __export(google_one_tap_exports, {
23
- prompt: () => prompt,
24
- requestCode: () => requestCode
25
- });
26
- module.exports = __toCommonJS(google_one_tap_exports);
27
- var script = null;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/google-one-tap/index.ts
3
+ let script = null;
28
4
  function loadScript() {
29
- return new Promise((resolve, reject) => {
30
- if (script) {
31
- if (window.google?.accounts?.id) {
32
- resolve();
33
- } else {
34
- script.addEventListener("load", () => resolve());
35
- script.addEventListener("error", () => {
36
- script = null;
37
- reject(new Error("Failed to load Google One Tap script"));
38
- });
39
- }
40
- return;
41
- }
42
- script = document.createElement("script");
43
- script.id = "google-one-tap";
44
- script.async = true;
45
- script.defer = true;
46
- script.src = "https://accounts.google.com/gsi/client";
47
- script.onload = () => resolve();
48
- script.onerror = () => {
49
- script = null;
50
- reject(new Error("Failed to load Google One Tap script"));
51
- };
52
- document.head.appendChild(script);
53
- });
5
+ return new Promise((resolve, reject) => {
6
+ if (script) {
7
+ if (window.google?.accounts?.id) resolve();
8
+ else {
9
+ script.addEventListener("load", () => resolve());
10
+ script.addEventListener("error", () => {
11
+ script = null;
12
+ reject(/* @__PURE__ */ new Error("Failed to load Google One Tap script"));
13
+ });
14
+ }
15
+ return;
16
+ }
17
+ script = document.createElement("script");
18
+ script.id = "google-one-tap";
19
+ script.async = true;
20
+ script.defer = true;
21
+ script.src = "https://accounts.google.com/gsi/client";
22
+ script.onload = () => resolve();
23
+ script.onerror = () => {
24
+ script = null;
25
+ reject(/* @__PURE__ */ new Error("Failed to load Google One Tap script"));
26
+ };
27
+ document.head.appendChild(script);
28
+ });
54
29
  }
30
+ /** FedCM feature detection — `IdentityCredential` is absent on Safari, Firefox and pre-117 Chrome. */
55
31
  function isFedcmSupported() {
56
- return typeof window !== "undefined" && "IdentityCredential" in window;
32
+ return typeof window !== "undefined" && "IdentityCredential" in window;
57
33
  }
58
- async function prompt({
59
- nonce,
60
- client_id,
61
- auto_select = false,
62
- use_fedcm_for_prompt = true,
63
- cancel_on_tap_outside = false
64
- }) {
65
- if (use_fedcm_for_prompt !== false && !isFedcmSupported()) {
66
- return { authorized: false, unsupported: true, reason: "fedcm_unsupported" };
67
- }
68
- try {
69
- await loadScript();
70
- } catch {
71
- return { authorized: false, unsupported: true, reason: "script_load_failed" };
72
- }
73
- return new Promise((resolve) => {
74
- let settled = false;
75
- const settle = (result) => {
76
- if (settled) return;
77
- settled = true;
78
- resolve(result);
79
- };
80
- try {
81
- window.google.accounts.id.initialize({
82
- ux_mode: "popup",
83
- context: "signin",
84
- auto_select,
85
- nonce,
86
- client_id,
87
- use_fedcm_for_prompt,
88
- cancel_on_tap_outside,
89
- callback: (credential) => settle({ authorized: true, credential }),
90
- native_callback: (credential) => settle({ authorized: true, credential })
91
- });
92
- window.google.accounts.id.prompt((notification) => {
93
- if (settled) return;
94
- const skipped = notification.isSkippedMoment();
95
- const dismissed = notification.isDismissedMoment();
96
- const dismissedReason = notification.getDismissedReason();
97
- if (skipped || dismissed && dismissedReason !== "credential_returned") {
98
- settle({
99
- authorized: false,
100
- moment: { skipped, dismissed, dismissedReason }
101
- });
102
- }
103
- });
104
- } catch {
105
- settle({ authorized: false, unsupported: true, reason: "prompt_error" });
106
- }
107
- });
34
+ /** debug: chrome://settings/content/federatedIdentityApi */
35
+ async function prompt({ nonce, client_id, auto_select = false, use_fedcm_for_prompt = true, cancel_on_tap_outside = false }) {
36
+ if (use_fedcm_for_prompt !== false && !isFedcmSupported()) return {
37
+ authorized: false,
38
+ unsupported: true,
39
+ reason: "fedcm_unsupported"
40
+ };
41
+ try {
42
+ await loadScript();
43
+ } catch {
44
+ return {
45
+ authorized: false,
46
+ unsupported: true,
47
+ reason: "script_load_failed"
48
+ };
49
+ }
50
+ return new Promise((resolve) => {
51
+ let settled = false;
52
+ const settle = (result) => {
53
+ if (settled) return;
54
+ settled = true;
55
+ resolve(result);
56
+ };
57
+ try {
58
+ window.google.accounts.id.initialize({
59
+ ux_mode: "popup",
60
+ context: "signin",
61
+ auto_select,
62
+ nonce,
63
+ client_id,
64
+ use_fedcm_for_prompt,
65
+ cancel_on_tap_outside,
66
+ callback: (credential) => settle({
67
+ authorized: true,
68
+ credential
69
+ }),
70
+ native_callback: (credential) => settle({
71
+ authorized: true,
72
+ credential
73
+ })
74
+ });
75
+ window.google.accounts.id.prompt((notification) => {
76
+ if (settled) return;
77
+ const skipped = notification.isSkippedMoment();
78
+ const dismissed = notification.isDismissedMoment();
79
+ const dismissedReason = notification.getDismissedReason();
80
+ if (skipped || dismissed && dismissedReason !== "credential_returned") settle({
81
+ authorized: false,
82
+ moment: {
83
+ skipped,
84
+ dismissed,
85
+ dismissedReason
86
+ }
87
+ });
88
+ });
89
+ } catch {
90
+ settle({
91
+ authorized: false,
92
+ unsupported: true,
93
+ reason: "prompt_error"
94
+ });
95
+ }
96
+ });
108
97
  }
109
- async function requestCode({
110
- client_id,
111
- scope = "openid email profile",
112
- ux_mode = "popup",
113
- redirect_uri,
114
- state,
115
- login_hint,
116
- hd
117
- }) {
118
- await loadScript();
119
- return new Promise((resolve) => {
120
- let settled = false;
121
- const settle = (result) => {
122
- if (settled) return;
123
- settled = true;
124
- resolve(result);
125
- };
126
- const client = window.google.accounts.oauth2.initCodeClient({
127
- client_id,
128
- scope,
129
- ux_mode,
130
- redirect_uri,
131
- state,
132
- login_hint,
133
- hd,
134
- callback: (response) => settle(response.code ? { ok: true, response } : { ok: false, error: response }),
135
- error_callback: (error) => settle({ ok: false, error })
136
- });
137
- client.requestCode();
138
- });
98
+ /**
99
+ * OAuth 2.0 authorization-code fallback for environments where One Tap / FedCM
100
+ * is unavailable (i.e. prompt() resolved with `unsupported: true`). It reuses
101
+ * the same GSI script, so there is no extra dependency.
102
+ *
103
+ * Unlike One Tap it returns an authorization `code` for the backend to
104
+ * exchange, not an ID token, and it must be triggered by a user gesture or the
105
+ * popup may be blocked.
106
+ */
107
+ async function requestCode({ client_id, scope = "openid email profile", ux_mode = "popup", redirect_uri, state, login_hint, hd }) {
108
+ await loadScript();
109
+ return new Promise((resolve) => {
110
+ let settled = false;
111
+ const settle = (result) => {
112
+ if (settled) return;
113
+ settled = true;
114
+ resolve(result);
115
+ };
116
+ window.google.accounts.oauth2.initCodeClient({
117
+ client_id,
118
+ scope,
119
+ ux_mode,
120
+ redirect_uri,
121
+ state,
122
+ login_hint,
123
+ hd,
124
+ callback: (response) => settle(response.code ? {
125
+ ok: true,
126
+ response
127
+ } : {
128
+ ok: false,
129
+ error: response
130
+ }),
131
+ error_callback: (error) => settle({
132
+ ok: false,
133
+ error
134
+ })
135
+ }).requestCode();
136
+ });
139
137
  }
140
- // Annotate the CommonJS export names for ESM import in node:
141
- 0 && (module.exports = {
142
- prompt,
143
- requestCode
144
- });
138
+ //#endregion
139
+ exports.prompt = prompt;
140
+ exports.requestCode = requestCode;
141
+
145
142
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/google-one-tap/index.ts"],"sourcesContent":["import type {\n ClientConfigError,\n CodeResponse,\n CredentialResponse,\n GoogleAccounts,\n PromptMomentNotification,\n} from './types';\n\ndeclare global {\n interface Window {\n google: {\n accounts: GoogleAccounts;\n };\n }\n}\n\nexport type Props = {\n /**\n * Opaque nonce string forwarded as-is to Google. Google echoes it back in\n * the ID Token's `nonce` claim per the OIDC spec; the caller is responsible\n * for any hashing/encoding required by its verifier.\n */\n nonce?: string;\n client_id: string;\n auto_select?: boolean;\n cancel_on_tap_outside?: boolean;\n use_fedcm_for_prompt?: boolean;\n};\n\nexport type PromptMoment = {\n skipped: boolean;\n dismissed: boolean;\n dismissedReason: ReturnType<PromptMomentNotification['getDismissedReason']>;\n};\n\n/**\n * Why prompt() could not run One Tap, so the caller can decide to fall back\n * to requestCode().\n * - `fedcm_unsupported`: browser has no FedCM (Safari/Firefox/pre-117 Chrome).\n * - `script_load_failed`: the GSI script failed to load (network/CSP).\n * - `prompt_error`: GIS threw synchronously while initializing/prompting.\n */\nexport type UnsupportedReason = 'fedcm_unsupported' | 'script_load_failed' | 'prompt_error';\n\nexport type PromptResult =\n | { authorized: true; credential: CredentialResponse }\n | { authorized: false; moment: PromptMoment }\n | { authorized: false; unsupported: true; reason: UnsupportedReason };\n\nlet script: HTMLScriptElement | null = null;\n\nfunction loadScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (script) {\n if (window.google?.accounts?.id) {\n resolve();\n } else {\n script.addEventListener('load', () => resolve());\n script.addEventListener('error', () => {\n script = null; // allow a later call to recreate the element instead of hanging\n reject(new Error('Failed to load Google One Tap script'));\n });\n }\n return;\n }\n\n script = document.createElement('script');\n script.id = 'google-one-tap';\n script.async = true;\n script.defer = true;\n script.src = 'https://accounts.google.com/gsi/client';\n script.onload = () => resolve();\n script.onerror = () => {\n script = null; // allow a later call to recreate the element instead of hanging\n reject(new Error('Failed to load Google One Tap script'));\n };\n\n document.head.appendChild(script);\n });\n}\n\n/** FedCM feature detection — `IdentityCredential` is absent on Safari, Firefox and pre-117 Chrome. */\nfunction isFedcmSupported(): boolean {\n return typeof window !== 'undefined' && 'IdentityCredential' in window;\n}\n\n/** debug: chrome://settings/content/federatedIdentityApi */\nexport async function prompt({\n nonce,\n client_id,\n auto_select = false,\n use_fedcm_for_prompt = true,\n cancel_on_tap_outside = false,\n}: Props): Promise<PromptResult> {\n // FedCM is mandatory for One Tap on capable browsers (GIS completed the\n // migration in early 2025) and there is no viable legacy fallback anymore.\n // When the caller wants FedCM but the browser lacks it, bail early instead\n // of letting GIS throw an async `NotSupportedError: Missing request type`\n // from navigator.credentials.get. Callers should fall back to requestCode().\n if (use_fedcm_for_prompt !== false && !isFedcmSupported()) {\n return { authorized: false, unsupported: true, reason: 'fedcm_unsupported' };\n }\n\n try {\n await loadScript();\n } catch {\n return { authorized: false, unsupported: true, reason: 'script_load_failed' };\n }\n\n return new Promise<PromptResult>((resolve) => {\n let settled = false;\n const settle = (result: PromptResult) => {\n if (settled) return;\n settled = true;\n resolve(result);\n };\n\n try {\n window.google.accounts.id.initialize({\n ux_mode: 'popup',\n context: 'signin',\n auto_select,\n nonce,\n client_id,\n use_fedcm_for_prompt,\n cancel_on_tap_outside,\n callback: (credential) => settle({ authorized: true, credential }),\n native_callback: (credential) => settle({ authorized: true, credential }),\n });\n\n window.google.accounts.id.prompt((notification) => {\n if (settled) return;\n\n const skipped = notification.isSkippedMoment();\n const dismissed = notification.isDismissedMoment();\n const dismissedReason = notification.getDismissedReason();\n\n if (skipped || (dismissed && dismissedReason !== 'credential_returned')) {\n settle({\n authorized: false,\n moment: { skipped, dismissed, dismissedReason },\n });\n }\n });\n } catch {\n settle({ authorized: false, unsupported: true, reason: 'prompt_error' });\n }\n });\n}\n\nexport type CodeProps = {\n client_id: string;\n /**\n * Space-delimited OAuth scopes. Defaults to OpenID Connect scopes so the\n * backend can exchange the code for an ID token, mirroring One Tap's intent.\n */\n scope?: string;\n /** 'popup' resolves the returned promise; 'redirect' navigates away and never resolves. */\n ux_mode?: 'popup' | 'redirect';\n /** Required when ux_mode is 'redirect'; for 'popup' Google uses postMessage. */\n redirect_uri?: string;\n state?: string;\n login_hint?: string;\n hd?: string;\n};\n\nexport type CodeResult =\n | { ok: true; response: CodeResponse }\n | { ok: false; error: ClientConfigError | CodeResponse };\n\n/**\n * OAuth 2.0 authorization-code fallback for environments where One Tap / FedCM\n * is unavailable (i.e. prompt() resolved with `unsupported: true`). It reuses\n * the same GSI script, so there is no extra dependency.\n *\n * Unlike One Tap it returns an authorization `code` for the backend to\n * exchange, not an ID token, and it must be triggered by a user gesture or the\n * popup may be blocked.\n */\nexport async function requestCode({\n client_id,\n scope = 'openid email profile',\n ux_mode = 'popup',\n redirect_uri,\n state,\n login_hint,\n hd,\n}: CodeProps): Promise<CodeResult> {\n await loadScript();\n\n return new Promise<CodeResult>((resolve) => {\n let settled = false;\n const settle = (result: CodeResult) => {\n if (settled) return;\n settled = true;\n resolve(result);\n };\n\n const client = window.google.accounts.oauth2.initCodeClient({\n client_id,\n scope,\n ux_mode,\n redirect_uri,\n state,\n login_hint,\n hd,\n callback: (response) =>\n settle(response.code ? { ok: true, response } : { ok: false, error: response }),\n error_callback: (error) => settle({ ok: false, error }),\n });\n\n client.requestCode();\n });\n}\n"],"mappings":"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","names":[]}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/google-one-tap/index.ts"],"sourcesContent":["import type {\n ClientConfigError,\n CodeResponse,\n CredentialResponse,\n GoogleAccounts,\n PromptMomentNotification,\n} from './types';\n\ndeclare global {\n interface Window {\n google: {\n accounts: GoogleAccounts;\n };\n }\n}\n\nexport type Props = {\n /**\n * Opaque nonce string forwarded as-is to Google. Google echoes it back in\n * the ID Token's `nonce` claim per the OIDC spec; the caller is responsible\n * for any hashing/encoding required by its verifier.\n */\n nonce?: string;\n client_id: string;\n auto_select?: boolean;\n cancel_on_tap_outside?: boolean;\n use_fedcm_for_prompt?: boolean;\n};\n\nexport type PromptMoment = {\n skipped: boolean;\n dismissed: boolean;\n dismissedReason: ReturnType<PromptMomentNotification['getDismissedReason']>;\n};\n\n/**\n * Why prompt() could not run One Tap, so the caller can decide to fall back\n * to requestCode().\n * - `fedcm_unsupported`: browser has no FedCM (Safari/Firefox/pre-117 Chrome).\n * - `script_load_failed`: the GSI script failed to load (network/CSP).\n * - `prompt_error`: GIS threw synchronously while initializing/prompting.\n */\nexport type UnsupportedReason = 'fedcm_unsupported' | 'script_load_failed' | 'prompt_error';\n\nexport type PromptResult =\n | { authorized: true; credential: CredentialResponse }\n | { authorized: false; moment: PromptMoment }\n | { authorized: false; unsupported: true; reason: UnsupportedReason };\n\nlet script: HTMLScriptElement | null = null;\n\nfunction loadScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (script) {\n if (window.google?.accounts?.id) {\n resolve();\n } else {\n script.addEventListener('load', () => resolve());\n script.addEventListener('error', () => {\n script = null; // allow a later call to recreate the element instead of hanging\n reject(new Error('Failed to load Google One Tap script'));\n });\n }\n return;\n }\n\n script = document.createElement('script');\n script.id = 'google-one-tap';\n script.async = true;\n script.defer = true;\n script.src = 'https://accounts.google.com/gsi/client';\n script.onload = () => resolve();\n script.onerror = () => {\n script = null; // allow a later call to recreate the element instead of hanging\n reject(new Error('Failed to load Google One Tap script'));\n };\n\n document.head.appendChild(script);\n });\n}\n\n/** FedCM feature detection — `IdentityCredential` is absent on Safari, Firefox and pre-117 Chrome. */\nfunction isFedcmSupported(): boolean {\n return typeof window !== 'undefined' && 'IdentityCredential' in window;\n}\n\n/** debug: chrome://settings/content/federatedIdentityApi */\nexport async function prompt({\n nonce,\n client_id,\n auto_select = false,\n use_fedcm_for_prompt = true,\n cancel_on_tap_outside = false,\n}: Props): Promise<PromptResult> {\n // FedCM is mandatory for One Tap on capable browsers (GIS completed the\n // migration in early 2025) and there is no viable legacy fallback anymore.\n // When the caller wants FedCM but the browser lacks it, bail early instead\n // of letting GIS throw an async `NotSupportedError: Missing request type`\n // from navigator.credentials.get. Callers should fall back to requestCode().\n if (use_fedcm_for_prompt !== false && !isFedcmSupported()) {\n return { authorized: false, unsupported: true, reason: 'fedcm_unsupported' };\n }\n\n try {\n await loadScript();\n } catch {\n return { authorized: false, unsupported: true, reason: 'script_load_failed' };\n }\n\n return new Promise<PromptResult>((resolve) => {\n let settled = false;\n const settle = (result: PromptResult) => {\n if (settled) return;\n settled = true;\n resolve(result);\n };\n\n try {\n window.google.accounts.id.initialize({\n ux_mode: 'popup',\n context: 'signin',\n auto_select,\n nonce,\n client_id,\n use_fedcm_for_prompt,\n cancel_on_tap_outside,\n callback: (credential) => settle({ authorized: true, credential }),\n native_callback: (credential) => settle({ authorized: true, credential }),\n });\n\n window.google.accounts.id.prompt((notification) => {\n if (settled) return;\n\n const skipped = notification.isSkippedMoment();\n const dismissed = notification.isDismissedMoment();\n const dismissedReason = notification.getDismissedReason();\n\n if (skipped || (dismissed && dismissedReason !== 'credential_returned')) {\n settle({\n authorized: false,\n moment: { skipped, dismissed, dismissedReason },\n });\n }\n });\n } catch {\n settle({ authorized: false, unsupported: true, reason: 'prompt_error' });\n }\n });\n}\n\nexport type CodeProps = {\n client_id: string;\n /**\n * Space-delimited OAuth scopes. Defaults to OpenID Connect scopes so the\n * backend can exchange the code for an ID token, mirroring One Tap's intent.\n */\n scope?: string;\n /** 'popup' resolves the returned promise; 'redirect' navigates away and never resolves. */\n ux_mode?: 'popup' | 'redirect';\n /** Required when ux_mode is 'redirect'; for 'popup' Google uses postMessage. */\n redirect_uri?: string;\n state?: string;\n login_hint?: string;\n hd?: string;\n};\n\nexport type CodeResult =\n | { ok: true; response: CodeResponse }\n | { ok: false; error: ClientConfigError | CodeResponse };\n\n/**\n * OAuth 2.0 authorization-code fallback for environments where One Tap / FedCM\n * is unavailable (i.e. prompt() resolved with `unsupported: true`). It reuses\n * the same GSI script, so there is no extra dependency.\n *\n * Unlike One Tap it returns an authorization `code` for the backend to\n * exchange, not an ID token, and it must be triggered by a user gesture or the\n * popup may be blocked.\n */\nexport async function requestCode({\n client_id,\n scope = 'openid email profile',\n ux_mode = 'popup',\n redirect_uri,\n state,\n login_hint,\n hd,\n}: CodeProps): Promise<CodeResult> {\n await loadScript();\n\n return new Promise<CodeResult>((resolve) => {\n let settled = false;\n const settle = (result: CodeResult) => {\n if (settled) return;\n settled = true;\n resolve(result);\n };\n\n const client = window.google.accounts.oauth2.initCodeClient({\n client_id,\n scope,\n ux_mode,\n redirect_uri,\n state,\n login_hint,\n hd,\n callback: (response) =>\n settle(response.code ? { ok: true, response } : { ok: false, error: response }),\n error_callback: (error) => settle({ ok: false, error }),\n });\n\n client.requestCode();\n });\n}\n"],"mappings":";;AAiDA,IAAI,SAAmC;AAEvC,SAAS,aAA4B;CACnC,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,QAAQ;GACV,IAAI,OAAO,QAAQ,UAAU,IAC3B,QAAQ;QACH;IACL,OAAO,iBAAiB,cAAc,QAAQ,CAAC;IAC/C,OAAO,iBAAiB,eAAe;KACrC,SAAS;KACT,uBAAO,IAAI,MAAM,sCAAsC,CAAC;IAC1D,CAAC;GACH;GACA;EACF;EAEA,SAAS,SAAS,cAAc,QAAQ;EACxC,OAAO,KAAK;EACZ,OAAO,QAAQ;EACf,OAAO,QAAQ;EACf,OAAO,MAAM;EACb,OAAO,eAAe,QAAQ;EAC9B,OAAO,gBAAgB;GACrB,SAAS;GACT,uBAAO,IAAI,MAAM,sCAAsC,CAAC;EAC1D;EAEA,SAAS,KAAK,YAAY,MAAM;CAClC,CAAC;AACH;;AAGA,SAAS,mBAA4B;CACnC,OAAO,OAAO,WAAW,eAAe,wBAAwB;AAClE;;AAGA,eAAsB,OAAO,EAC3B,OACA,WACA,cAAc,OACd,uBAAuB,MACvB,wBAAwB,SACO;CAM/B,IAAI,yBAAyB,SAAS,CAAC,iBAAiB,GACtD,OAAO;EAAE,YAAY;EAAO,aAAa;EAAM,QAAQ;CAAoB;CAG7E,IAAI;EACF,MAAM,WAAW;CACnB,QAAQ;EACN,OAAO;GAAE,YAAY;GAAO,aAAa;GAAM,QAAQ;EAAqB;CAC9E;CAEA,OAAO,IAAI,SAAuB,YAAY;EAC5C,IAAI,UAAU;EACd,MAAM,UAAU,WAAyB;GACvC,IAAI,SAAS;GACb,UAAU;GACV,QAAQ,MAAM;EAChB;EAEA,IAAI;GACF,OAAO,OAAO,SAAS,GAAG,WAAW;IACnC,SAAS;IACT,SAAS;IACT;IACA;IACA;IACA;IACA;IACA,WAAW,eAAe,OAAO;KAAE,YAAY;KAAM;IAAW,CAAC;IACjE,kBAAkB,eAAe,OAAO;KAAE,YAAY;KAAM;IAAW,CAAC;GAC1E,CAAC;GAED,OAAO,OAAO,SAAS,GAAG,QAAQ,iBAAiB;IACjD,IAAI,SAAS;IAEb,MAAM,UAAU,aAAa,gBAAgB;IAC7C,MAAM,YAAY,aAAa,kBAAkB;IACjD,MAAM,kBAAkB,aAAa,mBAAmB;IAExD,IAAI,WAAY,aAAa,oBAAoB,uBAC/C,OAAO;KACL,YAAY;KACZ,QAAQ;MAAE;MAAS;MAAW;KAAgB;IAChD,CAAC;GAEL,CAAC;EACH,QAAQ;GACN,OAAO;IAAE,YAAY;IAAO,aAAa;IAAM,QAAQ;GAAe,CAAC;EACzE;CACF,CAAC;AACH;;;;;;;;;;AA+BA,eAAsB,YAAY,EAChC,WACA,QAAQ,wBACR,UAAU,SACV,cACA,OACA,YACA,MACiC;CACjC,MAAM,WAAW;CAEjB,OAAO,IAAI,SAAqB,YAAY;EAC1C,IAAI,UAAU;EACd,MAAM,UAAU,WAAuB;GACrC,IAAI,SAAS;GACb,UAAU;GACV,QAAQ,MAAM;EAChB;EAeA,OAbsB,OAAO,SAAS,OAAO,eAAe;GAC1D;GACA;GACA;GACA;GACA;GACA;GACA;GACA,WAAW,aACT,OAAO,SAAS,OAAO;IAAE,IAAI;IAAM;GAAS,IAAI;IAAE,IAAI;IAAO,OAAO;GAAS,CAAC;GAChF,iBAAiB,UAAU,OAAO;IAAE,IAAI;IAAO;GAAM,CAAC;EACxD,CAEK,CAAC,CAAC,YAAY;CACrB,CAAC;AACH"}
@@ -1,28 +1,28 @@
1
- import { GoogleAccounts, CodeResponse, ClientConfigError, PromptMomentNotification, CredentialResponse } from './types.cjs';
2
-
1
+ import { ClientConfigError, CodeResponse, CredentialResponse, GoogleAccounts, PromptMomentNotification } from "./types.cjs";
2
+ //#region src/google-one-tap/index.d.ts
3
3
  declare global {
4
- interface Window {
5
- google: {
6
- accounts: GoogleAccounts;
7
- };
8
- }
4
+ interface Window {
5
+ google: {
6
+ accounts: GoogleAccounts;
7
+ };
8
+ }
9
9
  }
10
10
  type Props = {
11
- /**
12
- * Opaque nonce string forwarded as-is to Google. Google echoes it back in
13
- * the ID Token's `nonce` claim per the OIDC spec; the caller is responsible
14
- * for any hashing/encoding required by its verifier.
15
- */
16
- nonce?: string;
17
- client_id: string;
18
- auto_select?: boolean;
19
- cancel_on_tap_outside?: boolean;
20
- use_fedcm_for_prompt?: boolean;
11
+ /**
12
+ * Opaque nonce string forwarded as-is to Google. Google echoes it back in
13
+ * the ID Token's `nonce` claim per the OIDC spec; the caller is responsible
14
+ * for any hashing/encoding required by its verifier.
15
+ */
16
+ nonce?: string;
17
+ client_id: string;
18
+ auto_select?: boolean;
19
+ cancel_on_tap_outside?: boolean;
20
+ use_fedcm_for_prompt?: boolean;
21
21
  };
22
22
  type PromptMoment = {
23
- skipped: boolean;
24
- dismissed: boolean;
25
- dismissedReason: ReturnType<PromptMomentNotification['getDismissedReason']>;
23
+ skipped: boolean;
24
+ dismissed: boolean;
25
+ dismissedReason: ReturnType<PromptMomentNotification['getDismissedReason']>;
26
26
  };
27
27
  /**
28
28
  * Why prompt() could not run One Tap, so the caller can decide to fall back
@@ -33,39 +33,39 @@ type PromptMoment = {
33
33
  */
34
34
  type UnsupportedReason = 'fedcm_unsupported' | 'script_load_failed' | 'prompt_error';
35
35
  type PromptResult = {
36
- authorized: true;
37
- credential: CredentialResponse;
36
+ authorized: true;
37
+ credential: CredentialResponse;
38
38
  } | {
39
- authorized: false;
40
- moment: PromptMoment;
39
+ authorized: false;
40
+ moment: PromptMoment;
41
41
  } | {
42
- authorized: false;
43
- unsupported: true;
44
- reason: UnsupportedReason;
42
+ authorized: false;
43
+ unsupported: true;
44
+ reason: UnsupportedReason;
45
45
  };
46
46
  /** debug: chrome://settings/content/federatedIdentityApi */
47
- declare function prompt({ nonce, client_id, auto_select, use_fedcm_for_prompt, cancel_on_tap_outside, }: Props): Promise<PromptResult>;
47
+ declare function prompt({ nonce, client_id, auto_select, use_fedcm_for_prompt, cancel_on_tap_outside }: Props): Promise<PromptResult>;
48
48
  type CodeProps = {
49
- client_id: string;
50
- /**
51
- * Space-delimited OAuth scopes. Defaults to OpenID Connect scopes so the
52
- * backend can exchange the code for an ID token, mirroring One Tap's intent.
53
- */
54
- scope?: string;
55
- /** 'popup' resolves the returned promise; 'redirect' navigates away and never resolves. */
56
- ux_mode?: 'popup' | 'redirect';
57
- /** Required when ux_mode is 'redirect'; for 'popup' Google uses postMessage. */
58
- redirect_uri?: string;
59
- state?: string;
60
- login_hint?: string;
61
- hd?: string;
49
+ client_id: string;
50
+ /**
51
+ * Space-delimited OAuth scopes. Defaults to OpenID Connect scopes so the
52
+ * backend can exchange the code for an ID token, mirroring One Tap's intent.
53
+ */
54
+ scope?: string;
55
+ /** 'popup' resolves the returned promise; 'redirect' navigates away and never resolves. */
56
+ ux_mode?: 'popup' | 'redirect';
57
+ /** Required when ux_mode is 'redirect'; for 'popup' Google uses postMessage. */
58
+ redirect_uri?: string;
59
+ state?: string;
60
+ login_hint?: string;
61
+ hd?: string;
62
62
  };
63
63
  type CodeResult = {
64
- ok: true;
65
- response: CodeResponse;
64
+ ok: true;
65
+ response: CodeResponse;
66
66
  } | {
67
- ok: false;
68
- error: ClientConfigError | CodeResponse;
67
+ ok: false;
68
+ error: ClientConfigError | CodeResponse;
69
69
  };
70
70
  /**
71
71
  * OAuth 2.0 authorization-code fallback for environments where One Tap / FedCM
@@ -76,6 +76,7 @@ type CodeResult = {
76
76
  * exchange, not an ID token, and it must be triggered by a user gesture or the
77
77
  * popup may be blocked.
78
78
  */
79
- declare function requestCode({ client_id, scope, ux_mode, redirect_uri, state, login_hint, hd, }: CodeProps): Promise<CodeResult>;
80
-
81
- export { type CodeProps, type CodeResult, type PromptMoment, type PromptResult, type Props, type UnsupportedReason, prompt, requestCode };
79
+ declare function requestCode({ client_id, scope, ux_mode, redirect_uri, state, login_hint, hd }: CodeProps): Promise<CodeResult>;
80
+ //#endregion
81
+ export { CodeProps, CodeResult, PromptMoment, PromptResult, Props, UnsupportedReason, prompt, requestCode };
82
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/google-one-tap/index.ts"],"mappings":";;QAQQ;YACI;IACR;MACE,UAAU;;;;KAKJ;;;;;;EAMV;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA;EACA,iBAAiB,WAAW;;;;;;;;;KAUlB;KAEA;EACN;EAAkB,YAAY;;EAC9B;EAAmB,QAAQ;;EAC3B;EAAmB;EAAmB,QAAQ;;;iBAwC9B,SACpB,OACA,WACA,aACA,sBACA,yBACC,QAAQ,QAAQ;KAyDP;EACV;;;;;EAKA;;EAEA;;EAEA;EACA;EACA;EACA;;KAGU;EACN;EAAU,UAAU;;EACpB;EAAW,OAAO,oBAAoB;;;;;;;;;;;iBAWtB,cACpB,WACA,OACA,SACA,cACA,OACA,YACA,MACC,YAAY,QAAQ"}
@@ -0,0 +1,82 @@
1
+ import { ClientConfigError, CodeResponse, CredentialResponse, GoogleAccounts, PromptMomentNotification } from "./types.mjs";
2
+ //#region src/google-one-tap/index.d.ts
3
+ declare global {
4
+ interface Window {
5
+ google: {
6
+ accounts: GoogleAccounts;
7
+ };
8
+ }
9
+ }
10
+ type Props = {
11
+ /**
12
+ * Opaque nonce string forwarded as-is to Google. Google echoes it back in
13
+ * the ID Token's `nonce` claim per the OIDC spec; the caller is responsible
14
+ * for any hashing/encoding required by its verifier.
15
+ */
16
+ nonce?: string;
17
+ client_id: string;
18
+ auto_select?: boolean;
19
+ cancel_on_tap_outside?: boolean;
20
+ use_fedcm_for_prompt?: boolean;
21
+ };
22
+ type PromptMoment = {
23
+ skipped: boolean;
24
+ dismissed: boolean;
25
+ dismissedReason: ReturnType<PromptMomentNotification['getDismissedReason']>;
26
+ };
27
+ /**
28
+ * Why prompt() could not run One Tap, so the caller can decide to fall back
29
+ * to requestCode().
30
+ * - `fedcm_unsupported`: browser has no FedCM (Safari/Firefox/pre-117 Chrome).
31
+ * - `script_load_failed`: the GSI script failed to load (network/CSP).
32
+ * - `prompt_error`: GIS threw synchronously while initializing/prompting.
33
+ */
34
+ type UnsupportedReason = 'fedcm_unsupported' | 'script_load_failed' | 'prompt_error';
35
+ type PromptResult = {
36
+ authorized: true;
37
+ credential: CredentialResponse;
38
+ } | {
39
+ authorized: false;
40
+ moment: PromptMoment;
41
+ } | {
42
+ authorized: false;
43
+ unsupported: true;
44
+ reason: UnsupportedReason;
45
+ };
46
+ /** debug: chrome://settings/content/federatedIdentityApi */
47
+ declare function prompt({ nonce, client_id, auto_select, use_fedcm_for_prompt, cancel_on_tap_outside }: Props): Promise<PromptResult>;
48
+ type CodeProps = {
49
+ client_id: string;
50
+ /**
51
+ * Space-delimited OAuth scopes. Defaults to OpenID Connect scopes so the
52
+ * backend can exchange the code for an ID token, mirroring One Tap's intent.
53
+ */
54
+ scope?: string;
55
+ /** 'popup' resolves the returned promise; 'redirect' navigates away and never resolves. */
56
+ ux_mode?: 'popup' | 'redirect';
57
+ /** Required when ux_mode is 'redirect'; for 'popup' Google uses postMessage. */
58
+ redirect_uri?: string;
59
+ state?: string;
60
+ login_hint?: string;
61
+ hd?: string;
62
+ };
63
+ type CodeResult = {
64
+ ok: true;
65
+ response: CodeResponse;
66
+ } | {
67
+ ok: false;
68
+ error: ClientConfigError | CodeResponse;
69
+ };
70
+ /**
71
+ * OAuth 2.0 authorization-code fallback for environments where One Tap / FedCM
72
+ * is unavailable (i.e. prompt() resolved with `unsupported: true`). It reuses
73
+ * the same GSI script, so there is no extra dependency.
74
+ *
75
+ * Unlike One Tap it returns an authorization `code` for the backend to
76
+ * exchange, not an ID token, and it must be triggered by a user gesture or the
77
+ * popup may be blocked.
78
+ */
79
+ declare function requestCode({ client_id, scope, ux_mode, redirect_uri, state, login_hint, hd }: CodeProps): Promise<CodeResult>;
80
+ //#endregion
81
+ export { CodeProps, CodeResult, PromptMoment, PromptResult, Props, UnsupportedReason, prompt, requestCode };
82
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/google-one-tap/index.ts"],"mappings":";;QAQQ;YACI;IACR;MACE,UAAU;;;;KAKJ;;;;;;EAMV;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA;EACA,iBAAiB,WAAW;;;;;;;;;KAUlB;KAEA;EACN;EAAkB,YAAY;;EAC9B;EAAmB,QAAQ;;EAC3B;EAAmB;EAAmB,QAAQ;;;iBAwC9B,SACpB,OACA,WACA,aACA,sBACA,yBACC,QAAQ,QAAQ;KAyDP;EACV;;;;;EAKA;;EAEA;;EAEA;EACA;EACA;EACA;;KAGU;EACN;EAAU,UAAU;;EACpB;EAAW,OAAO,oBAAoB;;;;;;;;;;;iBAWtB,cACpB,WACA,OACA,SACA,cACA,OACA,YACA,MACC,YAAY,QAAQ"}