@aglyn/shared-util-http 1.0.0-beta.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +3 -0
- package/jest.config.d.ts +30 -0
- package/package.json +38 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +18 -0
- package/src/index.js.map +1 -0
- package/src/lib/authorized-token.d.ts +109 -0
- package/src/lib/authorized-token.js +189 -0
- package/src/lib/authorized-token.js.map +1 -0
- package/src/lib/cookie-get-user-id-token.d.ts +19 -0
- package/src/lib/cookie-get-user-id-token.js +23 -0
- package/src/lib/cookie-get-user-id-token.js.map +1 -0
- package/src/lib/cookie-set-user-id-token.d.ts +20 -0
- package/src/lib/cookie-set-user-id-token.js +25 -0
- package/src/lib/cookie-set-user-id-token.js.map +1 -0
- package/src/lib/cors-build-response-handler.d.ts +7 -0
- package/src/lib/cors-build-response-handler.js +25 -0
- package/src/lib/cors-build-response-handler.js.map +1 -0
- package/src/lib/cors-handle-response.d.ts +22 -0
- package/src/lib/cors-handle-response.js +94 -0
- package/src/lib/cors-handle-response.js.map +1 -0
- package/src/lib/get-absolute-url.d.ts +34 -0
- package/src/lib/get-absolute-url.js +48 -0
- package/src/lib/get-absolute-url.js.map +1 -0
- package/src/lib/get-allowed-headers.d.ts +26 -0
- package/src/lib/get-allowed-headers.js +39 -0
- package/src/lib/get-allowed-headers.js.map +1 -0
- package/src/lib/get-origin-headers-from-request.d.ts +20 -0
- package/src/lib/get-origin-headers-from-request.js +26 -0
- package/src/lib/get-origin-headers-from-request.js.map +1 -0
- package/src/lib/get-origin-headers.d.ts +3 -0
- package/src/lib/get-origin-headers.js +37 -0
- package/src/lib/get-origin-headers.js.map +1 -0
- package/src/lib/get-request-header.d.ts +20 -0
- package/src/lib/get-request-header.js +21 -0
- package/src/lib/get-request-header.js.map +1 -0
- package/src/lib/http.d.ts +27 -0
- package/src/lib/http.js +28 -0
- package/src/lib/http.js.map +1 -0
- package/src/lib/is-origin-allowed.d.ts +19 -0
- package/src/lib/is-origin-allowed.js +21 -0
- package/src/lib/is-origin-allowed.js.map +1 -0
- package/src/lib/safe-redirect.d.ts +41 -0
- package/src/lib/safe-redirect.js +101 -0
- package/src/lib/safe-redirect.js.map +1 -0
- package/src/lib/safe-url-scheme.d.ts +42 -0
- package/src/lib/safe-url-scheme.js +124 -0
- package/src/lib/safe-url-scheme.js.map +1 -0
- package/src/lib/types.d.ts +30 -0
- package/src/lib/types.js +18 -0
- package/src/lib/types.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
package/jest.config.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
declare const _default: {
|
|
18
|
+
displayName: string;
|
|
19
|
+
preset: string;
|
|
20
|
+
globals: {};
|
|
21
|
+
testEnvironment: string;
|
|
22
|
+
transform: {
|
|
23
|
+
'^.+\\.[tj]sx?$': (string | {
|
|
24
|
+
tsconfig: string;
|
|
25
|
+
})[];
|
|
26
|
+
};
|
|
27
|
+
moduleFileExtensions: string[];
|
|
28
|
+
coverageDirectory: string;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aglyn/shared-util-http",
|
|
3
|
+
"version": "1.0.0-beta.143",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"homepage": "https://aglyn.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/aglyn/aglyn.git",
|
|
9
|
+
"directory": "libs/shared/util/http"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"default": "./src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"types": "./src/lib/*.d.ts",
|
|
23
|
+
"default": "./src/lib/*.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.143",
|
|
29
|
+
"@swc/helpers": "0.5.23"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"next": "16.3.3"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"types": "./src/index.d.ts",
|
|
36
|
+
"module": "./src/index.js",
|
|
37
|
+
"main": "./src/index.js"
|
|
38
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export * from './lib/http';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ export * from "./lib/http.js";
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/shared/util/http/src/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from './lib/http'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,cAAc,gBAAY"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* How long a call waits for the caller's ID token before it gives up.
|
|
19
|
+
*
|
|
20
|
+
* `getIdToken()` mints from a cached token when one is live and otherwise
|
|
21
|
+
* refreshes against Google's token endpoint, and that refresh carries no
|
|
22
|
+
* deadline of its own: a request that is never answered leaves a promise
|
|
23
|
+
* pending for the life of the page. Every surface here awaits that promise
|
|
24
|
+
* BEFORE it issues its own request, so an unbounded wait is not a slow
|
|
25
|
+
* request — it is a surface that issues nothing, forever, having reported
|
|
26
|
+
* nothing.
|
|
27
|
+
*
|
|
28
|
+
* Long enough to cover a cold refresh over a slow connection, and short
|
|
29
|
+
* enough that a button which reads "Working…" goes back to being a button.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ID_TOKEN_TIMEOUT_MS = 10000;
|
|
32
|
+
/**
|
|
33
|
+
* The caller could not be authorized, so no request was made.
|
|
34
|
+
*
|
|
35
|
+
* A distinct type because it is the one failure that has NOT reached the
|
|
36
|
+
* server: nothing was sent, nothing was charged, nothing was mailed. A
|
|
37
|
+
* surface catching it can say so plainly instead of reporting the generic
|
|
38
|
+
* failure of an action that never left the browser.
|
|
39
|
+
*/
|
|
40
|
+
export declare class AuthorizationUnavailableError extends Error {
|
|
41
|
+
/** Which of the three ways the token could not be had. */
|
|
42
|
+
readonly reason: 'signed-out' | 'timeout' | 'rejected';
|
|
43
|
+
constructor(reason: 'signed-out' | 'timeout' | 'rejected', message: string);
|
|
44
|
+
}
|
|
45
|
+
/** The account shape this needs: something that can mint an ID token. */
|
|
46
|
+
export interface TokenSource {
|
|
47
|
+
getIdToken?: (forceRefresh?: boolean) => Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
/** What a caller may hand in where an account is expected. */
|
|
50
|
+
export type MaybeTokenSource = TokenSource | null | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* THE CALLER'S ID TOKEN, OR AN ERROR THAT SAYS WHY THERE ISN'T ONE.
|
|
53
|
+
*
|
|
54
|
+
* Three refusals rather than a value that may be missing, because the
|
|
55
|
+
* alternative is what a missing token silently buys: a request that goes out
|
|
56
|
+
* with no `Authorization` header, is refused by the route on its own terms,
|
|
57
|
+
* and reports "Send failed" to somebody whose actual problem is that they are
|
|
58
|
+
* signed out. A token is either obtained or the call does not happen.
|
|
59
|
+
*
|
|
60
|
+
* The timeout is the load-bearing one. Awaiting an unbounded refresh in front
|
|
61
|
+
* of a request means a stalled token endpoint takes the whole surface with
|
|
62
|
+
* it — no data, no action, and a button latched on a promise that never
|
|
63
|
+
* settles.
|
|
64
|
+
*
|
|
65
|
+
* @param user - The signed-in account, or nothing.
|
|
66
|
+
* @param options - `timeoutMs` overrides the deadline; `forceRefresh` asks
|
|
67
|
+
* Firebase to skip its cached token, which is what a surface reading a
|
|
68
|
+
* claim that has just changed needs.
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveIdToken(user: MaybeTokenSource, options?: {
|
|
71
|
+
timeoutMs?: number;
|
|
72
|
+
forceRefresh?: boolean;
|
|
73
|
+
}): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* What to put in front of somebody when a call failed.
|
|
76
|
+
*
|
|
77
|
+
* An authorization failure names itself; anything else is the caller's own
|
|
78
|
+
* fallback, because a network error mid-send and a send that never left are
|
|
79
|
+
* not the same news.
|
|
80
|
+
*/
|
|
81
|
+
export declare const describeCallFailure: (error: unknown, fallback: string) => string;
|
|
82
|
+
/**
|
|
83
|
+
* A `fetch` THAT CANNOT GO OUT UNAUTHENTICATED AND CANNOT HANG ON THE TOKEN.
|
|
84
|
+
*
|
|
85
|
+
* The header is unconditional, which is the whole point: building it as
|
|
86
|
+
* `...(idToken ? { Authorization } : {})` means a caller who could not be
|
|
87
|
+
* authorized sends the request ANYWAY, without credentials. That is a request
|
|
88
|
+
* which should never have left the browser — it reaches the route, is refused
|
|
89
|
+
* on the route's own terms, and comes back as whatever generic failure the
|
|
90
|
+
* surface prints for a bad response, so the one fact worth telling the person
|
|
91
|
+
* (they are signed out) is the one fact nobody says.
|
|
92
|
+
*
|
|
93
|
+
* When the token cannot be had the request is not made at all and the caller
|
|
94
|
+
* is answered with a `401` carrying the reason. Callers already branch on
|
|
95
|
+
* `response.ok` and already render `payload.error`, so the refusal arrives
|
|
96
|
+
* through the path they have rather than through one they would have to grow
|
|
97
|
+
* — and, unlike a thrown error, it cannot turn a surface that used to hang
|
|
98
|
+
* into a surface that silently rejects.
|
|
99
|
+
*
|
|
100
|
+
* Callers that must distinguish "the route refused me" from "this never left
|
|
101
|
+
* the browser" should use {@link resolveIdToken} directly and catch
|
|
102
|
+
* {@link AuthorizationUnavailableError}.
|
|
103
|
+
*/
|
|
104
|
+
export declare function authorizedFetch(user: MaybeTokenSource, input: string | URL, init?: RequestInit, options?: {
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
forceRefresh?: boolean;
|
|
107
|
+
/** Test seam. The real one is `fetch`. */
|
|
108
|
+
fetchImpl?: typeof fetch;
|
|
109
|
+
}): Promise<Response>;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /**
|
|
18
|
+
* How long a call waits for the caller's ID token before it gives up.
|
|
19
|
+
*
|
|
20
|
+
* `getIdToken()` mints from a cached token when one is live and otherwise
|
|
21
|
+
* refreshes against Google's token endpoint, and that refresh carries no
|
|
22
|
+
* deadline of its own: a request that is never answered leaves a promise
|
|
23
|
+
* pending for the life of the page. Every surface here awaits that promise
|
|
24
|
+
* BEFORE it issues its own request, so an unbounded wait is not a slow
|
|
25
|
+
* request — it is a surface that issues nothing, forever, having reported
|
|
26
|
+
* nothing.
|
|
27
|
+
*
|
|
28
|
+
* Long enough to cover a cold refresh over a slow connection, and short
|
|
29
|
+
* enough that a button which reads "Working…" goes back to being a button.
|
|
30
|
+
*/ export const ID_TOKEN_TIMEOUT_MS = 10000;
|
|
31
|
+
/**
|
|
32
|
+
* The caller could not be authorized, so no request was made.
|
|
33
|
+
*
|
|
34
|
+
* A distinct type because it is the one failure that has NOT reached the
|
|
35
|
+
* server: nothing was sent, nothing was charged, nothing was mailed. A
|
|
36
|
+
* surface catching it can say so plainly instead of reporting the generic
|
|
37
|
+
* failure of an action that never left the browser.
|
|
38
|
+
*/ export class AuthorizationUnavailableError extends Error {
|
|
39
|
+
constructor(reason, message){
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = 'AuthorizationUnavailableError';
|
|
42
|
+
this.reason = reason;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Whatever a thrown value has to say for itself, in one line. */ const errorText = (cause)=>{
|
|
46
|
+
var _ref, _ref1;
|
|
47
|
+
return cause instanceof Error ? cause.message : String((_ref = (_ref1 = cause == null ? void 0 : cause.message) != null ? _ref1 : cause) != null ? _ref : 'no detail');
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* THE CALLER'S ID TOKEN, OR AN ERROR THAT SAYS WHY THERE ISN'T ONE.
|
|
51
|
+
*
|
|
52
|
+
* Three refusals rather than a value that may be missing, because the
|
|
53
|
+
* alternative is what a missing token silently buys: a request that goes out
|
|
54
|
+
* with no `Authorization` header, is refused by the route on its own terms,
|
|
55
|
+
* and reports "Send failed" to somebody whose actual problem is that they are
|
|
56
|
+
* signed out. A token is either obtained or the call does not happen.
|
|
57
|
+
*
|
|
58
|
+
* The timeout is the load-bearing one. Awaiting an unbounded refresh in front
|
|
59
|
+
* of a request means a stalled token endpoint takes the whole surface with
|
|
60
|
+
* it — no data, no action, and a button latched on a promise that never
|
|
61
|
+
* settles.
|
|
62
|
+
*
|
|
63
|
+
* @param user - The signed-in account, or nothing.
|
|
64
|
+
* @param options - `timeoutMs` overrides the deadline; `forceRefresh` asks
|
|
65
|
+
* Firebase to skip its cached token, which is what a surface reading a
|
|
66
|
+
* claim that has just changed needs.
|
|
67
|
+
*/ export async function resolveIdToken(user, options = {}) {
|
|
68
|
+
const { timeoutMs = ID_TOKEN_TIMEOUT_MS, forceRefresh = false } = options;
|
|
69
|
+
if (!(user == null ? void 0 : user.getIdToken)) {
|
|
70
|
+
throw new AuthorizationUnavailableError('signed-out', 'You are signed out, so nothing was sent. Sign in again and retry.');
|
|
71
|
+
}
|
|
72
|
+
let timer;
|
|
73
|
+
try {
|
|
74
|
+
const token = await Promise.race([
|
|
75
|
+
Promise.resolve(user.getIdToken(forceRefresh)).catch((cause)=>{
|
|
76
|
+
throw new AuthorizationUnavailableError('rejected', 'Your sign-in could not be confirmed, so nothing was sent. ' + `Check your connection and retry. (${errorText(cause)})`);
|
|
77
|
+
}),
|
|
78
|
+
new Promise((_resolve, reject)=>{
|
|
79
|
+
timer = setTimeout(()=>{
|
|
80
|
+
reject(new AuthorizationUnavailableError('timeout', 'Your sign-in could not be confirmed in time, so nothing was ' + 'sent. Check your connection and retry.'));
|
|
81
|
+
}, timeoutMs);
|
|
82
|
+
})
|
|
83
|
+
]);
|
|
84
|
+
if (!token) {
|
|
85
|
+
throw new AuthorizationUnavailableError('signed-out', 'You are signed out, so nothing was sent. Sign in again and retry.');
|
|
86
|
+
}
|
|
87
|
+
return token;
|
|
88
|
+
} finally{
|
|
89
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What to put in front of somebody when a call failed.
|
|
94
|
+
*
|
|
95
|
+
* An authorization failure names itself; anything else is the caller's own
|
|
96
|
+
* fallback, because a network error mid-send and a send that never left are
|
|
97
|
+
* not the same news.
|
|
98
|
+
*/ export const describeCallFailure = (error, fallback)=>error instanceof AuthorizationUnavailableError ? error.message : fallback;
|
|
99
|
+
/**
|
|
100
|
+
* The answer a caller gets when the token could not be had.
|
|
101
|
+
*
|
|
102
|
+
* `401` because that is what the request would have been answered with had it
|
|
103
|
+
* gone out, and the reason travels in `error`, which is the field every
|
|
104
|
+
* caller already reads off a refused response. Duck-typed rather than a real
|
|
105
|
+
* `Response`: the constructor is absent from some of the environments these
|
|
106
|
+
* surfaces are tested in, and every field a caller touches is here.
|
|
107
|
+
*/ const refusedResponse = (message)=>{
|
|
108
|
+
const body = JSON.stringify({
|
|
109
|
+
error: message
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
status: 401,
|
|
114
|
+
statusText: 'Unauthorized',
|
|
115
|
+
redirected: false,
|
|
116
|
+
type: 'basic',
|
|
117
|
+
url: '',
|
|
118
|
+
headers: {
|
|
119
|
+
get: (name)=>name.toLowerCase() === 'content-type' ? 'application/json' : null
|
|
120
|
+
},
|
|
121
|
+
json: async ()=>({
|
|
122
|
+
error: message
|
|
123
|
+
}),
|
|
124
|
+
text: async ()=>body,
|
|
125
|
+
clone () {
|
|
126
|
+
return refusedResponse(message);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* A `fetch` THAT CANNOT GO OUT UNAUTHENTICATED AND CANNOT HANG ON THE TOKEN.
|
|
132
|
+
*
|
|
133
|
+
* The header is unconditional, which is the whole point: building it as
|
|
134
|
+
* `...(idToken ? { Authorization } : {})` means a caller who could not be
|
|
135
|
+
* authorized sends the request ANYWAY, without credentials. That is a request
|
|
136
|
+
* which should never have left the browser — it reaches the route, is refused
|
|
137
|
+
* on the route's own terms, and comes back as whatever generic failure the
|
|
138
|
+
* surface prints for a bad response, so the one fact worth telling the person
|
|
139
|
+
* (they are signed out) is the one fact nobody says.
|
|
140
|
+
*
|
|
141
|
+
* When the token cannot be had the request is not made at all and the caller
|
|
142
|
+
* is answered with a `401` carrying the reason. Callers already branch on
|
|
143
|
+
* `response.ok` and already render `payload.error`, so the refusal arrives
|
|
144
|
+
* through the path they have rather than through one they would have to grow
|
|
145
|
+
* — and, unlike a thrown error, it cannot turn a surface that used to hang
|
|
146
|
+
* into a surface that silently rejects.
|
|
147
|
+
*
|
|
148
|
+
* Callers that must distinguish "the route refused me" from "this never left
|
|
149
|
+
* the browser" should use {@link resolveIdToken} directly and catch
|
|
150
|
+
* {@link AuthorizationUnavailableError}.
|
|
151
|
+
*/ export async function authorizedFetch(user, input, init = {}, options = {}) {
|
|
152
|
+
var _options_fetchImpl;
|
|
153
|
+
let idToken;
|
|
154
|
+
try {
|
|
155
|
+
idToken = await resolveIdToken(user, options);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return refusedResponse(describeCallFailure(error, 'Your sign-in could not be confirmed.'));
|
|
158
|
+
}
|
|
159
|
+
return ((_options_fetchImpl = options.fetchImpl) != null ? _options_fetchImpl : fetch)(input, _extends({}, init, {
|
|
160
|
+
headers: _extends({}, plainHeaders(init.headers), {
|
|
161
|
+
Authorization: `Bearer ${idToken}`
|
|
162
|
+
})
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Whatever `headers` form the caller used, as a plain record.
|
|
167
|
+
*
|
|
168
|
+
* The outgoing headers stay a plain object rather than becoming a `Headers`
|
|
169
|
+
* instance, because that is the shape callers hand in and the shape their
|
|
170
|
+
* tests read back off the recorded request. Promoting it would change what
|
|
171
|
+
* every one of those assertions sees without changing what the server gets.
|
|
172
|
+
*/ const plainHeaders = (headers)=>{
|
|
173
|
+
if (!headers) return {};
|
|
174
|
+
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
175
|
+
if (typeof headers.forEach === 'function' && !isPlainRecord(headers)) {
|
|
176
|
+
const flat = {};
|
|
177
|
+
headers.forEach((value, key)=>{
|
|
178
|
+
flat[key] = value;
|
|
179
|
+
});
|
|
180
|
+
return flat;
|
|
181
|
+
}
|
|
182
|
+
return _extends({}, headers);
|
|
183
|
+
};
|
|
184
|
+
/** True for an object literal, which `Headers` is not. */ const isPlainRecord = (value)=>{
|
|
185
|
+
const proto = Object.getPrototypeOf(value);
|
|
186
|
+
return proto === Object.prototype || proto === null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
//# sourceMappingURL=authorized-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/shared/util/http/src/lib/authorized-token.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * How long a call waits for the caller's ID token before it gives up.\n *\n * `getIdToken()` mints from a cached token when one is live and otherwise\n * refreshes against Google's token endpoint, and that refresh carries no\n * deadline of its own: a request that is never answered leaves a promise\n * pending for the life of the page. Every surface here awaits that promise\n * BEFORE it issues its own request, so an unbounded wait is not a slow\n * request — it is a surface that issues nothing, forever, having reported\n * nothing.\n *\n * Long enough to cover a cold refresh over a slow connection, and short\n * enough that a button which reads \"Working…\" goes back to being a button.\n */\nexport const ID_TOKEN_TIMEOUT_MS = 10_000\n\n/**\n * The caller could not be authorized, so no request was made.\n *\n * A distinct type because it is the one failure that has NOT reached the\n * server: nothing was sent, nothing was charged, nothing was mailed. A\n * surface catching it can say so plainly instead of reporting the generic\n * failure of an action that never left the browser.\n */\nexport class AuthorizationUnavailableError extends Error {\n /** Which of the three ways the token could not be had. */\n readonly reason: 'signed-out' | 'timeout' | 'rejected'\n\n constructor(reason: 'signed-out' | 'timeout' | 'rejected', message: string) {\n super(message)\n this.name = 'AuthorizationUnavailableError'\n this.reason = reason\n }\n}\n\n/** The account shape this needs: something that can mint an ID token. */\nexport interface TokenSource {\n getIdToken?: (forceRefresh?: boolean) => Promise<string>\n}\n\n/** What a caller may hand in where an account is expected. */\nexport type MaybeTokenSource = TokenSource | null | undefined\n\n/** Whatever a thrown value has to say for itself, in one line. */\nconst errorText = (cause: unknown): string =>\n cause instanceof Error\n ? cause.message\n : String((cause as { message?: unknown })?.message ?? cause ?? 'no detail')\n\n/**\n * THE CALLER'S ID TOKEN, OR AN ERROR THAT SAYS WHY THERE ISN'T ONE.\n *\n * Three refusals rather than a value that may be missing, because the\n * alternative is what a missing token silently buys: a request that goes out\n * with no `Authorization` header, is refused by the route on its own terms,\n * and reports \"Send failed\" to somebody whose actual problem is that they are\n * signed out. A token is either obtained or the call does not happen.\n *\n * The timeout is the load-bearing one. Awaiting an unbounded refresh in front\n * of a request means a stalled token endpoint takes the whole surface with\n * it — no data, no action, and a button latched on a promise that never\n * settles.\n *\n * @param user - The signed-in account, or nothing.\n * @param options - `timeoutMs` overrides the deadline; `forceRefresh` asks\n * Firebase to skip its cached token, which is what a surface reading a\n * claim that has just changed needs.\n */\nexport async function resolveIdToken(\n user: MaybeTokenSource,\n options: { timeoutMs?: number; forceRefresh?: boolean } = {},\n): Promise<string> {\n const { timeoutMs = ID_TOKEN_TIMEOUT_MS, forceRefresh = false } = options\n if (!user?.getIdToken) {\n throw new AuthorizationUnavailableError(\n 'signed-out',\n 'You are signed out, so nothing was sent. Sign in again and retry.',\n )\n }\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n const token = await Promise.race([\n Promise.resolve(user.getIdToken(forceRefresh)).catch((cause: unknown) => {\n throw new AuthorizationUnavailableError(\n 'rejected',\n 'Your sign-in could not be confirmed, so nothing was sent. ' +\n `Check your connection and retry. (${errorText(cause)})`,\n )\n }),\n new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n reject(\n new AuthorizationUnavailableError(\n 'timeout',\n 'Your sign-in could not be confirmed in time, so nothing was ' +\n 'sent. Check your connection and retry.',\n ),\n )\n }, timeoutMs)\n }),\n ])\n if (!token) {\n throw new AuthorizationUnavailableError(\n 'signed-out',\n 'You are signed out, so nothing was sent. Sign in again and retry.',\n )\n }\n return token\n } finally {\n if (timer !== undefined) clearTimeout(timer)\n }\n}\n\n/**\n * What to put in front of somebody when a call failed.\n *\n * An authorization failure names itself; anything else is the caller's own\n * fallback, because a network error mid-send and a send that never left are\n * not the same news.\n */\nexport const describeCallFailure = (\n error: unknown,\n fallback: string,\n): string =>\n error instanceof AuthorizationUnavailableError ? error.message : fallback\n\n/**\n * The answer a caller gets when the token could not be had.\n *\n * `401` because that is what the request would have been answered with had it\n * gone out, and the reason travels in `error`, which is the field every\n * caller already reads off a refused response. Duck-typed rather than a real\n * `Response`: the constructor is absent from some of the environments these\n * surfaces are tested in, and every field a caller touches is here.\n */\nconst refusedResponse = (message: string): Response => {\n const body = JSON.stringify({ error: message })\n return {\n ok: false,\n status: 401,\n statusText: 'Unauthorized',\n redirected: false,\n type: 'basic' as ResponseType,\n url: '',\n headers: { get: (name: string) =>\n name.toLowerCase() === 'content-type' ? 'application/json' : null },\n json: async () => ({ error: message }),\n text: async () => body,\n clone() {\n return refusedResponse(message)\n },\n } as unknown as Response\n}\n\n/**\n * A `fetch` THAT CANNOT GO OUT UNAUTHENTICATED AND CANNOT HANG ON THE TOKEN.\n *\n * The header is unconditional, which is the whole point: building it as\n * `...(idToken ? { Authorization } : {})` means a caller who could not be\n * authorized sends the request ANYWAY, without credentials. That is a request\n * which should never have left the browser — it reaches the route, is refused\n * on the route's own terms, and comes back as whatever generic failure the\n * surface prints for a bad response, so the one fact worth telling the person\n * (they are signed out) is the one fact nobody says.\n *\n * When the token cannot be had the request is not made at all and the caller\n * is answered with a `401` carrying the reason. Callers already branch on\n * `response.ok` and already render `payload.error`, so the refusal arrives\n * through the path they have rather than through one they would have to grow\n * — and, unlike a thrown error, it cannot turn a surface that used to hang\n * into a surface that silently rejects.\n *\n * Callers that must distinguish \"the route refused me\" from \"this never left\n * the browser\" should use {@link resolveIdToken} directly and catch\n * {@link AuthorizationUnavailableError}.\n */\nexport async function authorizedFetch(\n user: MaybeTokenSource,\n input: string | URL,\n init: RequestInit = {},\n options: {\n timeoutMs?: number\n forceRefresh?: boolean\n /** Test seam. The real one is `fetch`. */\n fetchImpl?: typeof fetch\n } = {},\n): Promise<Response> {\n let idToken: string\n try {\n idToken = await resolveIdToken(user, options)\n } catch (error) {\n return refusedResponse(\n describeCallFailure(error, 'Your sign-in could not be confirmed.'),\n )\n }\n return (options.fetchImpl ?? fetch)(input, {\n ...init,\n headers: { ...plainHeaders(init.headers), Authorization: `Bearer ${idToken}` },\n })\n}\n\n/**\n * Whatever `headers` form the caller used, as a plain record.\n *\n * The outgoing headers stay a plain object rather than becoming a `Headers`\n * instance, because that is the shape callers hand in and the shape their\n * tests read back off the recorded request. Promoting it would change what\n * every one of those assertions sees without changing what the server gets.\n */\nconst plainHeaders = (headers: RequestInit['headers']): Record<string, string> => {\n if (!headers) return {}\n if (Array.isArray(headers)) return Object.fromEntries(headers)\n if (typeof (headers as Headers).forEach === 'function' && !isPlainRecord(headers)) {\n const flat: Record<string, string> = {}\n ;(headers as Headers).forEach((value, key) => {\n flat[key] = value\n })\n return flat\n }\n return { ...(headers as Record<string, string>) }\n}\n\n/** True for an object literal, which `Headers` is not. */\nconst isPlainRecord = (value: unknown): boolean => {\n const proto = Object.getPrototypeOf(value)\n return proto === Object.prototype || proto === null\n}\n"],"names":["ID_TOKEN_TIMEOUT_MS","AuthorizationUnavailableError","Error","reason","message","name","errorText","cause","String","resolveIdToken","user","options","timeoutMs","forceRefresh","getIdToken","timer","token","Promise","race","resolve","catch","_resolve","reject","setTimeout","undefined","clearTimeout","describeCallFailure","error","fallback","refusedResponse","body","JSON","stringify","ok","status","statusText","redirected","type","url","headers","get","toLowerCase","json","text","clone","authorizedFetch","input","init","idToken","fetchImpl","fetch","plainHeaders","Authorization","Array","isArray","Object","fromEntries","forEach","isPlainRecord","flat","value","key","proto","getPrototypeOf","prototype"],"mappings":"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"}
|