@veryfront/ext-auth-jwt 0.1.985
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 +202 -0
- package/NOTICE +2 -0
- package/README.md +48 -0
- package/esm/_dnt.polyfills.d.ts +124 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +249 -0
- package/esm/_dnt.shims.d.ts +12 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +68 -0
- package/esm/extensions/ext-auth-jwt/src/index.d.ts +48 -0
- package/esm/extensions/ext-auth-jwt/src/index.d.ts.map +1 -0
- package/esm/extensions/ext-auth-jwt/src/index.js +124 -0
- package/esm/package.json +3 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @veryfront/ext-auth-jwt
|
|
2
|
+
|
|
3
|
+
> **Category:** Auth | **Contract:** `AuthProvider` | **Optional**
|
|
4
|
+
|
|
5
|
+
Provides JWT authentication for Veryfront applications: HMAC-based sign/verify (HS256 by default), remote JWKS verification, PEM public-key verification, and protected-header decoding, backed by [`jose`](https://github.com/panva/jose).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add the extension to your project's `veryfront.config.ts`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import extJwt from "@veryfront/ext-auth-jwt";
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
extensions: [extJwt()],
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Environment Variables
|
|
20
|
+
|
|
21
|
+
| Variable | Required | Description |
|
|
22
|
+
| ------------ | ----------------------- | -------------------------------------------------------------------------------- |
|
|
23
|
+
| `JWT_SECRET` | Yes (for sign / verify) | HMAC secret for symmetric JWT operations. Without it, `sign` and `verify` throw. |
|
|
24
|
+
|
|
25
|
+
## Factory configuration
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
extJwt({
|
|
29
|
+
secret: "...", // overrides JWT_SECRET when set
|
|
30
|
+
jwksResolverFactory: (url) => /* custom JWKS resolver for tests */,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Both fields are optional. `jwksResolverFactory` is primarily a test seam. Production callers should leave it unset so `createRemoteJWKSet` resolves the real JWKS URL.
|
|
35
|
+
|
|
36
|
+
## Provided contract
|
|
37
|
+
|
|
38
|
+
`AuthProvider` supports:
|
|
39
|
+
|
|
40
|
+
- `sign(payload, options)`: HS256 JWT signing using the configured or env secret.
|
|
41
|
+
- `verify(token, options)`: symmetric verification using the same secret.
|
|
42
|
+
- `verifyWithJwks(token, jwksUrl, options)`: remote JWKS verification, with the JWKS document cached per URL by `createRemoteJWKSet`.
|
|
43
|
+
- `verifyWithPublicKey(token, publicKeyPem, options)`: PEM public-key verification for configured issuer keys.
|
|
44
|
+
- `decode(token)`: read `kid`, `alg`, etc. without verifying the signature.
|
|
45
|
+
|
|
46
|
+
## Capabilities
|
|
47
|
+
|
|
48
|
+
- **net `*`:** `createRemoteJWKSet` fetches JWKS documents from arbitrary issuers at verify time.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Error {
|
|
3
|
+
cause?: unknown;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export {};
|
|
7
|
+
/**
|
|
8
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
9
|
+
* but instead of using npm to install additional dependencies,
|
|
10
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
11
|
+
*
|
|
12
|
+
* Note that this code might be imported multiple times
|
|
13
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
14
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
15
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
16
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
17
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
18
|
+
*/
|
|
19
|
+
import { createRequire } from "node:module";
|
|
20
|
+
import { type URL } from "node:url";
|
|
21
|
+
declare global {
|
|
22
|
+
interface ImportMeta {
|
|
23
|
+
/** A string representation of the fully qualified module URL. When the
|
|
24
|
+
* module is loaded locally, the value will be a file URL (e.g.
|
|
25
|
+
* `file:///path/module.ts`).
|
|
26
|
+
*
|
|
27
|
+
* You can also parse the string as a URL to determine more information about
|
|
28
|
+
* how the current module was loaded. For example to determine if a module was
|
|
29
|
+
* local or not:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const url = new URL(import.meta.url);
|
|
33
|
+
* if (url.protocol === "file:") {
|
|
34
|
+
* console.log("this module was loaded locally");
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
url: string;
|
|
39
|
+
/**
|
|
40
|
+
* A function that returns resolved specifier as if it would be imported
|
|
41
|
+
* using `import(specifier)`.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* console.log(import.meta.resolve("./foo.js"));
|
|
45
|
+
* // file:///dev/foo.js
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param specifier The module specifier to resolve relative to `parent`.
|
|
49
|
+
* @param parent The absolute parent module URL to resolve from.
|
|
50
|
+
* @returns The absolute (`file:`) URL string for the resolved module.
|
|
51
|
+
*/
|
|
52
|
+
resolve(specifier: string, parent?: string | URL | undefined): string;
|
|
53
|
+
/** A flag that indicates if the current module is the main module that was
|
|
54
|
+
* called when starting the program under Deno.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* if (import.meta.main) {
|
|
58
|
+
* // this was loaded as the main module, maybe do some bootstrapping
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
main: boolean;
|
|
63
|
+
/** The absolute path of the current module.
|
|
64
|
+
*
|
|
65
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
66
|
+
*
|
|
67
|
+
* Example:
|
|
68
|
+
* ```
|
|
69
|
+
* // Unix
|
|
70
|
+
* console.log(import.meta.filename); // /home/alice/my_module.ts
|
|
71
|
+
*
|
|
72
|
+
* // Windows
|
|
73
|
+
* console.log(import.meta.filename); // C:\alice\my_module.ts
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
filename: string;
|
|
77
|
+
/** The absolute path of the directory containing the current module.
|
|
78
|
+
*
|
|
79
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
80
|
+
*
|
|
81
|
+
* * Example:
|
|
82
|
+
* ```
|
|
83
|
+
* // Unix
|
|
84
|
+
* console.log(import.meta.dirname); // /home/alice
|
|
85
|
+
*
|
|
86
|
+
* // Windows
|
|
87
|
+
* console.log(import.meta.dirname); // C:\alice
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
dirname: string;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
type NodeRequest = ReturnType<typeof createRequire>;
|
|
94
|
+
type NodeModule = NonNullable<NodeRequest["main"]>;
|
|
95
|
+
interface ImportMetaPonyfillCommonjs {
|
|
96
|
+
(require: NodeRequest, module: NodeModule): ImportMeta;
|
|
97
|
+
}
|
|
98
|
+
interface ImportMetaPonyfillEsmodule {
|
|
99
|
+
(importMeta: ImportMeta): ImportMeta;
|
|
100
|
+
}
|
|
101
|
+
interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
|
|
102
|
+
}
|
|
103
|
+
export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
|
|
104
|
+
export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
|
|
105
|
+
export declare let import_meta_ponyfill: ImportMetaPonyfill;
|
|
106
|
+
declare global {
|
|
107
|
+
interface ArrayConstructor {
|
|
108
|
+
fromAsync<T>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T | Promise<T>> | ArrayLike<T | Promise<T>>): Promise<T[]>;
|
|
109
|
+
fromAsync<T, U>(iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>, mapFn: (value: Awaited<T>) => U, thisArg?: any): Promise<Awaited<U>[]>;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
113
|
+
declare global {
|
|
114
|
+
interface Object {
|
|
115
|
+
/**
|
|
116
|
+
* Determines whether an object has a property with the specified name.
|
|
117
|
+
* @param o An object.
|
|
118
|
+
* @param v A property name.
|
|
119
|
+
*/
|
|
120
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export {};
|
|
124
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AACV;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC;AAExB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,gBAAgB;QACxB,SAAS,CAAC,CAAC,EACP,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAC7F,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;QAEhB,SAAS,CAAC,CAAC,EAAE,CAAC,EACV,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAClE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAC/B,OAAO,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KAC1B;CACF;AAoID,OAAO,EAAE,CAAC;AAeV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
import { dirname } from "node:path";
|
|
19
|
+
const defineGlobalPonyfill = (symbolFor, fn) => {
|
|
20
|
+
if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
|
|
21
|
+
Object.defineProperty(globalThis, Symbol.for(symbolFor), {
|
|
22
|
+
configurable: true,
|
|
23
|
+
get() {
|
|
24
|
+
return fn;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
|
|
30
|
+
(() => {
|
|
31
|
+
const moduleImportMetaWM = new WeakMap();
|
|
32
|
+
return (require, module) => {
|
|
33
|
+
let importMetaCache = moduleImportMetaWM.get(module);
|
|
34
|
+
if (importMetaCache == null) {
|
|
35
|
+
const importMeta = Object.assign(Object.create(null), {
|
|
36
|
+
url: pathToFileURL(module.filename).href,
|
|
37
|
+
main: require.main == module,
|
|
38
|
+
resolve: (specifier, parentURL = importMeta.url) => {
|
|
39
|
+
return pathToFileURL((importMeta.url === parentURL
|
|
40
|
+
? require
|
|
41
|
+
: createRequire(parentURL))
|
|
42
|
+
.resolve(specifier)).href;
|
|
43
|
+
},
|
|
44
|
+
filename: module.filename,
|
|
45
|
+
dirname: module.path,
|
|
46
|
+
});
|
|
47
|
+
moduleImportMetaWM.set(module, importMeta);
|
|
48
|
+
importMetaCache = importMeta;
|
|
49
|
+
}
|
|
50
|
+
return importMetaCache;
|
|
51
|
+
};
|
|
52
|
+
})());
|
|
53
|
+
defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
|
|
54
|
+
export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
|
|
55
|
+
((importMeta) => {
|
|
56
|
+
const resolveFunStr = String(importMeta.resolve);
|
|
57
|
+
const shimWs = new WeakSet();
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
|
|
60
|
+
.replace(/\/{3,}/, "///");
|
|
61
|
+
const commonShim = (importMeta) => {
|
|
62
|
+
if (typeof importMeta.main !== "boolean") {
|
|
63
|
+
importMeta.main = importMeta.url === mainUrl;
|
|
64
|
+
}
|
|
65
|
+
if (typeof importMeta.filename !== "string") {
|
|
66
|
+
importMeta.filename = fileURLToPath(importMeta.url);
|
|
67
|
+
importMeta.dirname = dirname(importMeta.filename);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (
|
|
71
|
+
// v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
|
|
72
|
+
resolveFunStr === "undefined" ||
|
|
73
|
+
// v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
|
|
74
|
+
resolveFunStr.startsWith("async")
|
|
75
|
+
// enable by --experimental-import-meta-resolve flag
|
|
76
|
+
) {
|
|
77
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
78
|
+
if (!shimWs.has(importMeta)) {
|
|
79
|
+
shimWs.add(importMeta);
|
|
80
|
+
const importMetaUrlRequire = {
|
|
81
|
+
url: importMeta.url,
|
|
82
|
+
require: createRequire(importMeta.url),
|
|
83
|
+
};
|
|
84
|
+
importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
|
|
85
|
+
return pathToFileURL((importMetaUrlRequire.url === parentURL
|
|
86
|
+
? importMetaUrlRequire.require
|
|
87
|
+
: createRequire(parentURL)).resolve(specifier)).href;
|
|
88
|
+
};
|
|
89
|
+
commonShim(importMeta);
|
|
90
|
+
}
|
|
91
|
+
return importMeta;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
/// native support
|
|
96
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
97
|
+
if (!shimWs.has(importMeta)) {
|
|
98
|
+
shimWs.add(importMeta);
|
|
99
|
+
commonShim(importMeta);
|
|
100
|
+
}
|
|
101
|
+
return importMeta;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return import_meta_ponyfill_esmodule(importMeta);
|
|
105
|
+
}));
|
|
106
|
+
defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
|
|
107
|
+
export let import_meta_ponyfill = ((...args) => {
|
|
108
|
+
const _MODULE = (() => {
|
|
109
|
+
if (typeof require === "function" && typeof module === "object") {
|
|
110
|
+
return "commonjs";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// eval("typeof import.meta");
|
|
114
|
+
return "esmodule";
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
if (_MODULE === "commonjs") {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
|
|
124
|
+
}
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
return import_meta_ponyfill(...args);
|
|
127
|
+
});
|
|
128
|
+
// From https://github.com/es-shims/array-from-async/blob/4a5ff83947b861f35b380d5d4f20da2f07698638/index.mjs
|
|
129
|
+
// Tried to have dnt depend on the package instead, but it distributes as an
|
|
130
|
+
// ES module, so doesn't work with CommonJS.
|
|
131
|
+
//
|
|
132
|
+
// Code below:
|
|
133
|
+
//
|
|
134
|
+
// Copyright 2021 J. S. Choi
|
|
135
|
+
//
|
|
136
|
+
// Redistribution and use in source and binary forms, with or without
|
|
137
|
+
// modification, are permitted provided that the following conditions
|
|
138
|
+
// are met:
|
|
139
|
+
//
|
|
140
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
141
|
+
// notice, this list of conditions and the following disclaimer.
|
|
142
|
+
//
|
|
143
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
144
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
145
|
+
// documentation and/or other materials provided with the distribution.
|
|
146
|
+
//
|
|
147
|
+
// 3. Neither the name of the copyright holder nor the names of its
|
|
148
|
+
// contributors may be used to endorse or promote products derived from
|
|
149
|
+
// this software without specific prior written permission.
|
|
150
|
+
//
|
|
151
|
+
// **This software is provided by the copyright holders and contributors
|
|
152
|
+
// "as is" and any express or implied warranties, including, but not
|
|
153
|
+
// limited to, the implied warranties of merchantability and fitness for a
|
|
154
|
+
// particular purpose are disclaimed. In no event shall the copyright
|
|
155
|
+
// holder or contributors be liable for any direct, indirect, incidental,
|
|
156
|
+
// special, exemplary, or consequential damages (including, but not limited
|
|
157
|
+
// to, procurement of substitute goods or services; loss of use, data, or
|
|
158
|
+
// profits; or business interruption) however caused and on any theory of
|
|
159
|
+
// liability, whether in contract, strict liability, or tort (including
|
|
160
|
+
// negligence or otherwise) arising in any way out of the use of this
|
|
161
|
+
// software, even if advised of the possibility of such damage.**
|
|
162
|
+
const { MAX_SAFE_INTEGER } = Number;
|
|
163
|
+
const iteratorSymbol = Symbol.iterator;
|
|
164
|
+
const asyncIteratorSymbol = Symbol.asyncIterator;
|
|
165
|
+
const IntrinsicArray = Array;
|
|
166
|
+
const tooLongErrorMessage = 'Input is too long and exceeded Number.MAX_SAFE_INTEGER times.';
|
|
167
|
+
function isConstructor(obj) {
|
|
168
|
+
if (obj != null) {
|
|
169
|
+
const prox = new Proxy(obj, {
|
|
170
|
+
construct() {
|
|
171
|
+
return prox;
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
try {
|
|
175
|
+
new prox;
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async function fromAsync(items, mapfn, thisArg) {
|
|
187
|
+
const itemsAreIterable = (asyncIteratorSymbol in items ||
|
|
188
|
+
iteratorSymbol in items);
|
|
189
|
+
if (itemsAreIterable) {
|
|
190
|
+
const result = isConstructor(this)
|
|
191
|
+
? new this
|
|
192
|
+
: IntrinsicArray(0);
|
|
193
|
+
let i = 0;
|
|
194
|
+
for await (const v of items) {
|
|
195
|
+
if (i > MAX_SAFE_INTEGER) {
|
|
196
|
+
throw TypeError(tooLongErrorMessage);
|
|
197
|
+
}
|
|
198
|
+
else if (mapfn) {
|
|
199
|
+
result[i] = await mapfn.call(thisArg, v, i);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
result[i] = v;
|
|
203
|
+
}
|
|
204
|
+
i++;
|
|
205
|
+
}
|
|
206
|
+
result.length = i;
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// In this case, the items are assumed to be an arraylike object with
|
|
211
|
+
// a length property and integer properties for each element.
|
|
212
|
+
const { length } = items;
|
|
213
|
+
const result = isConstructor(this)
|
|
214
|
+
? new this(length)
|
|
215
|
+
: IntrinsicArray(length);
|
|
216
|
+
let i = 0;
|
|
217
|
+
while (i < length) {
|
|
218
|
+
if (i > MAX_SAFE_INTEGER) {
|
|
219
|
+
throw TypeError(tooLongErrorMessage);
|
|
220
|
+
}
|
|
221
|
+
const v = await items[i];
|
|
222
|
+
if (mapfn) {
|
|
223
|
+
result[i] = await mapfn.call(thisArg, v, i);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
result[i] = v;
|
|
227
|
+
}
|
|
228
|
+
i++;
|
|
229
|
+
}
|
|
230
|
+
result.length = i;
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!Array.fromAsync) {
|
|
235
|
+
Array.fromAsync = fromAsync;
|
|
236
|
+
}
|
|
237
|
+
if (!Object.hasOwn) {
|
|
238
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
239
|
+
value: function (object, property) {
|
|
240
|
+
if (object == null) {
|
|
241
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
242
|
+
}
|
|
243
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
244
|
+
},
|
|
245
|
+
configurable: true,
|
|
246
|
+
enumerable: false,
|
|
247
|
+
writable: true,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { setInterval, setTimeout } from "@deno/shim-timers";
|
|
5
|
+
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
6
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "setInterval" | "setTimeout" | "crypto" | "Deno"> & {
|
|
7
|
+
Deno: typeof Deno;
|
|
8
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
9
|
+
setInterval: typeof setInterval;
|
|
10
|
+
setTimeout: typeof setTimeout;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=_dnt.shims.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,KAAK,uBAAuB,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ5D,eAAO,MAAM,aAAa;;;;;CAA2C,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
import { crypto } from "@deno/shim-crypto";
|
|
4
|
+
export { crypto } from "@deno/shim-crypto";
|
|
5
|
+
import { setInterval, setTimeout } from "@deno/shim-timers";
|
|
6
|
+
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
7
|
+
const dntGlobals = {
|
|
8
|
+
Deno,
|
|
9
|
+
crypto,
|
|
10
|
+
setInterval,
|
|
11
|
+
setTimeout,
|
|
12
|
+
};
|
|
13
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
14
|
+
function createMergeProxy(baseObj, extObj) {
|
|
15
|
+
return new Proxy(baseObj, {
|
|
16
|
+
get(_target, prop, _receiver) {
|
|
17
|
+
if (prop in extObj) {
|
|
18
|
+
return extObj[prop];
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return baseObj[prop];
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
set(_target, prop, value) {
|
|
25
|
+
if (prop in extObj) {
|
|
26
|
+
delete extObj[prop];
|
|
27
|
+
}
|
|
28
|
+
baseObj[prop] = value;
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
deleteProperty(_target, prop) {
|
|
32
|
+
let success = false;
|
|
33
|
+
if (prop in extObj) {
|
|
34
|
+
delete extObj[prop];
|
|
35
|
+
success = true;
|
|
36
|
+
}
|
|
37
|
+
if (prop in baseObj) {
|
|
38
|
+
delete baseObj[prop];
|
|
39
|
+
success = true;
|
|
40
|
+
}
|
|
41
|
+
return success;
|
|
42
|
+
},
|
|
43
|
+
ownKeys(_target) {
|
|
44
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
45
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
46
|
+
const extKeysSet = new Set(extKeys);
|
|
47
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
48
|
+
},
|
|
49
|
+
defineProperty(_target, prop, desc) {
|
|
50
|
+
if (prop in extObj) {
|
|
51
|
+
delete extObj[prop];
|
|
52
|
+
}
|
|
53
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
54
|
+
return true;
|
|
55
|
+
},
|
|
56
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
57
|
+
if (prop in extObj) {
|
|
58
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
has(_target, prop) {
|
|
65
|
+
return prop in extObj || prop in baseObj;
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ext-auth-jwt: AuthProvider implementation backed by `jose`.
|
|
3
|
+
*
|
|
4
|
+
* Provides the `AuthProvider` contract: sign / verify (HS256 by default),
|
|
5
|
+
* remote-JWKS verification, public-key verification, and header decoding.
|
|
6
|
+
*
|
|
7
|
+
* @module extensions/ext-auth-jwt
|
|
8
|
+
*/
|
|
9
|
+
import "../../../_dnt.polyfills.js";
|
|
10
|
+
import { jwtVerify } from "jose";
|
|
11
|
+
import type { ExtensionFactory } from "veryfront/extensions";
|
|
12
|
+
import type { AuthProvider } from "veryfront/extensions/auth";
|
|
13
|
+
/**
|
|
14
|
+
* Signature used by jose's verify step to resolve a key for a given header.
|
|
15
|
+
*
|
|
16
|
+
* Matches the shape returned by `createRemoteJWKSet` / `createLocalJWKSet`
|
|
17
|
+
* and lets tests inject an in-memory key set without reaching the network.
|
|
18
|
+
*/
|
|
19
|
+
export type JwksResolver = Parameters<typeof jwtVerify>[1] & object;
|
|
20
|
+
/**
|
|
21
|
+
* Factory for building a JWKS resolver from a URL.
|
|
22
|
+
*
|
|
23
|
+
* The default uses `createRemoteJWKSet`; tests can inject a stub that returns
|
|
24
|
+
* a local resolver bound to an in-memory key set.
|
|
25
|
+
*/
|
|
26
|
+
export type JwksResolverFactory = (jwksUrl: string) => JwksResolver;
|
|
27
|
+
/**
|
|
28
|
+
* Optional configuration for the ext-auth-jwt factory.
|
|
29
|
+
*
|
|
30
|
+
* - `secret`: HMAC secret for `sign`/`verify`. Falls back to the `JWT_SECRET`
|
|
31
|
+
* environment variable. Without one, `sign`/`verify` throw.
|
|
32
|
+
* - `jwksResolverFactory`: test seam that overrides JWKS resolution.
|
|
33
|
+
*/
|
|
34
|
+
export interface ExtJwtConfig {
|
|
35
|
+
secret?: string | Uint8Array;
|
|
36
|
+
jwksResolverFactory?: JwksResolverFactory;
|
|
37
|
+
}
|
|
38
|
+
declare function createAuthProvider(config: ExtJwtConfig): AuthProvider;
|
|
39
|
+
/**
|
|
40
|
+
* Default export — the ext-auth-jwt extension factory.
|
|
41
|
+
*
|
|
42
|
+
* Produces an extension that registers an `AuthProvider` contract
|
|
43
|
+
* implementation backed by `jose`.
|
|
44
|
+
*/
|
|
45
|
+
declare const extJwt: ExtensionFactory;
|
|
46
|
+
export default extJwt;
|
|
47
|
+
export { createAuthProvider };
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-auth-jwt/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,4BAA4B,CAAC;AAKpC,OAAO,EAKL,SAAS,EAGV,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EACV,YAAY,EAKb,MAAM,2BAA2B,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AAEpE;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,YAAY,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAsBD,iBAAS,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAgG9D;AAED;;;;;GAKG;AACH,QAAA,MAAM,MAAM,EAAE,gBAcb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ext-auth-jwt: AuthProvider implementation backed by `jose`.
|
|
3
|
+
*
|
|
4
|
+
* Provides the `AuthProvider` contract: sign / verify (HS256 by default),
|
|
5
|
+
* remote-JWKS verification, public-key verification, and header decoding.
|
|
6
|
+
*
|
|
7
|
+
* @module extensions/ext-auth-jwt
|
|
8
|
+
*/
|
|
9
|
+
import "../../../_dnt.polyfills.js";
|
|
10
|
+
import * as dntShim from "../../../_dnt.shims.js";
|
|
11
|
+
import { createRemoteJWKSet, decodeProtectedHeader, importSPKI, jwtVerify, SignJWT, } from "jose";
|
|
12
|
+
function defaultJwksResolverFactory(jwksUrl) {
|
|
13
|
+
return createRemoteJWKSet(new URL(jwksUrl));
|
|
14
|
+
}
|
|
15
|
+
function toUint8Array(secret) {
|
|
16
|
+
return typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
|
|
17
|
+
}
|
|
18
|
+
function getSecret(configSecret) {
|
|
19
|
+
if (configSecret !== undefined)
|
|
20
|
+
return toUint8Array(configSecret);
|
|
21
|
+
const env = typeof dntShim.Deno !== "undefined" ? dntShim.Deno.env.get("JWT_SECRET") : undefined;
|
|
22
|
+
if (!env) {
|
|
23
|
+
throw new Error("ext-auth-jwt: no HMAC secret configured. Pass `secret` to the extension " +
|
|
24
|
+
"factory or set the JWT_SECRET environment variable.");
|
|
25
|
+
}
|
|
26
|
+
return new TextEncoder().encode(env);
|
|
27
|
+
}
|
|
28
|
+
function createAuthProvider(config) {
|
|
29
|
+
const jwksResolverFactory = config.jwksResolverFactory ??
|
|
30
|
+
defaultJwksResolverFactory;
|
|
31
|
+
// Cache one resolver per JWKS URL; `createRemoteJWKSet` maintains its own
|
|
32
|
+
// internal key cache with cooldown/rotation semantics, so reusing the
|
|
33
|
+
// same resolver is required for the cache to be effective.
|
|
34
|
+
const jwksResolvers = new Map();
|
|
35
|
+
const publicKeys = new Map();
|
|
36
|
+
function getJwksResolver(jwksUrl) {
|
|
37
|
+
const existing = jwksResolvers.get(jwksUrl);
|
|
38
|
+
if (existing)
|
|
39
|
+
return existing;
|
|
40
|
+
const created = jwksResolverFactory(jwksUrl);
|
|
41
|
+
jwksResolvers.set(jwksUrl, created);
|
|
42
|
+
return created;
|
|
43
|
+
}
|
|
44
|
+
function getPublicKey(publicKeyPem, algorithm) {
|
|
45
|
+
const cacheKey = `${algorithm}:${publicKeyPem}`;
|
|
46
|
+
const existing = publicKeys.get(cacheKey);
|
|
47
|
+
if (existing)
|
|
48
|
+
return existing;
|
|
49
|
+
const created = importSPKI(publicKeyPem, algorithm);
|
|
50
|
+
publicKeys.set(cacheKey, created);
|
|
51
|
+
return created;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
async sign(payload, options) {
|
|
55
|
+
const secret = getSecret(config.secret);
|
|
56
|
+
const algorithm = options?.algorithm ?? "HS256";
|
|
57
|
+
const { sub, ...rest } = payload;
|
|
58
|
+
const builder = new SignJWT(rest)
|
|
59
|
+
.setProtectedHeader({ alg: algorithm })
|
|
60
|
+
.setSubject(sub);
|
|
61
|
+
if (options?.expiresIn !== undefined) {
|
|
62
|
+
// jose's setExpirationTime accepts `string | number | Date`.
|
|
63
|
+
builder.setExpirationTime(options.expiresIn);
|
|
64
|
+
}
|
|
65
|
+
return await builder.sign(secret);
|
|
66
|
+
},
|
|
67
|
+
async verify(token, options) {
|
|
68
|
+
const secret = getSecret(config.secret);
|
|
69
|
+
const algorithms = options?.algorithms ?? ["HS256"];
|
|
70
|
+
const { payload } = await jwtVerify(token, secret, { algorithms });
|
|
71
|
+
return payload;
|
|
72
|
+
},
|
|
73
|
+
async verifyWithJwks(token, jwksUrl, options) {
|
|
74
|
+
const resolver = getJwksResolver(jwksUrl);
|
|
75
|
+
const { algorithms, ...rest } = options ?? {};
|
|
76
|
+
const verifyOpts = { ...rest };
|
|
77
|
+
if (algorithms)
|
|
78
|
+
verifyOpts.algorithms = algorithms;
|
|
79
|
+
const { payload } = await jwtVerify(token, resolver, verifyOpts);
|
|
80
|
+
return payload;
|
|
81
|
+
},
|
|
82
|
+
async verifyWithPublicKey(token, publicKeyPem, options) {
|
|
83
|
+
const algorithms = options?.algorithms ?? ["RS256"];
|
|
84
|
+
const algorithm = algorithms[0] ?? "RS256";
|
|
85
|
+
const publicKey = await getPublicKey(publicKeyPem, algorithm);
|
|
86
|
+
const { algorithms: _algorithms, ...rest } = options ?? {};
|
|
87
|
+
const { payload } = await jwtVerify(token, publicKey, {
|
|
88
|
+
...rest,
|
|
89
|
+
algorithms,
|
|
90
|
+
});
|
|
91
|
+
return payload;
|
|
92
|
+
},
|
|
93
|
+
decode(token) {
|
|
94
|
+
try {
|
|
95
|
+
return decodeProtectedHeader(token);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Default export — the ext-auth-jwt extension factory.
|
|
105
|
+
*
|
|
106
|
+
* Produces an extension that registers an `AuthProvider` contract
|
|
107
|
+
* implementation backed by `jose`.
|
|
108
|
+
*/
|
|
109
|
+
const extJwt = (config) => {
|
|
110
|
+
const cfg = (config ?? {});
|
|
111
|
+
const provider = createAuthProvider(cfg);
|
|
112
|
+
return {
|
|
113
|
+
name: "ext-auth-jwt",
|
|
114
|
+
version: "0.1.0",
|
|
115
|
+
capabilities: [
|
|
116
|
+
{ type: "net:outbound", hosts: ["*"] },
|
|
117
|
+
],
|
|
118
|
+
provides: {
|
|
119
|
+
AuthProvider: provider,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export default extJwt;
|
|
124
|
+
export { createAuthProvider };
|
package/esm/package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@veryfront/ext-auth-jwt",
|
|
3
|
+
"version": "0.1.985",
|
|
4
|
+
"description": "Veryfront first-party extension package for ext-auth-jwt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"veryfront",
|
|
7
|
+
"extension",
|
|
8
|
+
"ext-auth-jwt"
|
|
9
|
+
],
|
|
10
|
+
"author": "Veryfront",
|
|
11
|
+
"homepage": "https://github.com/veryfront/veryfront-code/tree/main/extensions/ext-auth-jwt",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/veryfront/veryfront-code.git",
|
|
15
|
+
"directory": "extensions/ext-auth-jwt"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/veryfront/veryfront-code/issues"
|
|
20
|
+
},
|
|
21
|
+
"module": "./esm/extensions/ext-auth-jwt/src/index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./esm/extensions/ext-auth-jwt/src/index.js",
|
|
25
|
+
"types": "./esm/extensions/ext-auth-jwt/src/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"veryfront": {
|
|
36
|
+
"extension": true,
|
|
37
|
+
"contracts": {
|
|
38
|
+
"provides": [
|
|
39
|
+
"AuthProvider"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"capabilities": [
|
|
43
|
+
{
|
|
44
|
+
"type": "net:outbound",
|
|
45
|
+
"hosts": [
|
|
46
|
+
"*"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@deno/shim-deno": "~0.18.0",
|
|
53
|
+
"@deno/shim-crypto": "~0.3.1",
|
|
54
|
+
"@deno/shim-timers": "~0.1.0",
|
|
55
|
+
"jose": "5.9.6"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"veryfront": "^0.1.985"
|
|
59
|
+
},
|
|
60
|
+
"type": "module",
|
|
61
|
+
"types": "./esm/extensions/ext-auth-jwt/src/index.d.ts",
|
|
62
|
+
"files": [
|
|
63
|
+
"esm",
|
|
64
|
+
"LICENSE",
|
|
65
|
+
"NOTICE",
|
|
66
|
+
"README.md"
|
|
67
|
+
]
|
|
68
|
+
}
|