@tanakayuto/intmax402-express 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/middleware.js +1 -17
  2. package/package.json +20 -3
@@ -4,22 +4,6 @@ exports.intmax402 = intmax402;
4
4
  const intmax402_core_1 = require("@tanakayuto/intmax402-core");
5
5
  const crypto_1 = require("./crypto");
6
6
  const verify_payment_1 = require("./verify-payment");
7
- function buildWWWAuthenticate(nonce, config) {
8
- let header = `INTMAX402 realm="intmax402", nonce="${nonce}", mode="${config.mode}"`;
9
- if (config.serverAddress) {
10
- header += `, serverAddress="${config.serverAddress}"`;
11
- }
12
- if (config.amount) {
13
- header += `, amount="${config.amount}"`;
14
- }
15
- if (config.tokenAddress) {
16
- header += `, tokenAddress="${config.tokenAddress}"`;
17
- }
18
- if (config.chainId) {
19
- header += `, chainId="${config.chainId}"`;
20
- }
21
- return header;
22
- }
23
7
  function intmax402(config) {
24
8
  return async (req, res, next) => {
25
9
  const authHeader = req.headers.authorization;
@@ -27,7 +11,7 @@ function intmax402(config) {
27
11
  const ip = req.ip || req.socket.remoteAddress || "unknown";
28
12
  const nonce = (0, intmax402_core_1.generateNonce)(config.secret, ip, req.path, config.bindIp ?? false);
29
13
  const statusCode = config.mode === "payment" ? 402 : 401;
30
- res.setHeader("WWW-Authenticate", buildWWWAuthenticate(nonce, config));
14
+ res.setHeader("WWW-Authenticate", (0, intmax402_core_1.buildWWWAuthenticate)(nonce, config));
31
15
  res.status(statusCode).json({
32
16
  error: config.mode === "payment" ? "Payment Required" : "Unauthorized",
33
17
  protocol: "INTMAX402",
package/package.json CHANGED
@@ -1,12 +1,29 @@
1
1
  {
2
2
  "name": "@tanakayuto/intmax402-express",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ },
12
+ "./crypto": {
13
+ "import": "./dist/crypto.js",
14
+ "require": "./dist/crypto.js",
15
+ "types": "./dist/crypto.d.ts"
16
+ },
17
+ "./verify-payment": {
18
+ "import": "./dist/verify-payment.js",
19
+ "require": "./dist/verify-payment.js",
20
+ "types": "./dist/verify-payment.d.ts"
21
+ }
22
+ },
6
23
  "dependencies": {
7
- "@tanakayuto/intmax402-core": "0.2.2",
8
24
  "ethers": "^6.16.0",
9
- "intmax2-server-sdk": "^1.5.2"
25
+ "intmax2-server-sdk": "^1.5.2",
26
+ "@tanakayuto/intmax402-core": "0.2.3"
10
27
  },
11
28
  "peerDependencies": {
12
29
  "express": "^4.18.0"