@iflow-mcp/apple-rag-mcp 4.6.2
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/.github/workflows/release.yml +62 -0
- package/.releaserc.json +38 -0
- package/CHANGELOG.md +161 -0
- package/README.md +114 -0
- package/README.zh-CN.md +119 -0
- package/apple-rag-mcp_process.log +8 -0
- package/biome.json +59 -0
- package/dist/src/auth/auth-middleware.d.ts +26 -0
- package/dist/src/auth/auth-middleware.d.ts.map +1 -0
- package/dist/src/auth/auth-middleware.js +77 -0
- package/dist/src/auth/auth-middleware.js.map +1 -0
- package/dist/src/auth/token-validator.d.ts +22 -0
- package/dist/src/auth/token-validator.d.ts.map +1 -0
- package/dist/src/auth/token-validator.js +64 -0
- package/dist/src/auth/token-validator.js.map +1 -0
- package/dist/src/mcp/formatters/response-formatter.d.ts +26 -0
- package/dist/src/mcp/formatters/response-formatter.d.ts.map +1 -0
- package/dist/src/mcp/formatters/response-formatter.js +119 -0
- package/dist/src/mcp/formatters/response-formatter.js.map +1 -0
- package/dist/src/mcp/manifest.d.ts +48 -0
- package/dist/src/mcp/manifest.d.ts.map +1 -0
- package/dist/src/mcp/manifest.js +46 -0
- package/dist/src/mcp/manifest.js.map +1 -0
- package/dist/src/mcp/middleware/request-validator.d.ts +48 -0
- package/dist/src/mcp/middleware/request-validator.d.ts.map +1 -0
- package/dist/src/mcp/middleware/request-validator.js +102 -0
- package/dist/src/mcp/middleware/request-validator.js.map +1 -0
- package/dist/src/mcp/protocol-handler.d.ts +70 -0
- package/dist/src/mcp/protocol-handler.d.ts.map +1 -0
- package/dist/src/mcp/protocol-handler.js +285 -0
- package/dist/src/mcp/protocol-handler.js.map +1 -0
- package/dist/src/mcp/tools/fetch-tool.d.ts +18 -0
- package/dist/src/mcp/tools/fetch-tool.d.ts.map +1 -0
- package/dist/src/mcp/tools/fetch-tool.js +76 -0
- package/dist/src/mcp/tools/fetch-tool.js.map +1 -0
- package/dist/src/mcp/tools/search-tool.d.ts +20 -0
- package/dist/src/mcp/tools/search-tool.d.ts.map +1 -0
- package/dist/src/mcp/tools/search-tool.js +86 -0
- package/dist/src/mcp/tools/search-tool.js.map +1 -0
- package/dist/src/services/database.d.ts +37 -0
- package/dist/src/services/database.d.ts.map +1 -0
- package/dist/src/services/database.js +166 -0
- package/dist/src/services/database.js.map +1 -0
- package/dist/src/services/deepinfra-base.d.ts +22 -0
- package/dist/src/services/deepinfra-base.d.ts.map +1 -0
- package/dist/src/services/deepinfra-base.js +55 -0
- package/dist/src/services/deepinfra-base.js.map +1 -0
- package/dist/src/services/embedding.d.ts +44 -0
- package/dist/src/services/embedding.d.ts.map +1 -0
- package/dist/src/services/embedding.js +61 -0
- package/dist/src/services/embedding.js.map +1 -0
- package/dist/src/services/index.d.ts +10 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +52 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/ip-authentication.d.ts +12 -0
- package/dist/src/services/ip-authentication.d.ts.map +1 -0
- package/dist/src/services/ip-authentication.js +39 -0
- package/dist/src/services/ip-authentication.js.map +1 -0
- package/dist/src/services/rag.d.ts +35 -0
- package/dist/src/services/rag.d.ts.map +1 -0
- package/dist/src/services/rag.js +106 -0
- package/dist/src/services/rag.js.map +1 -0
- package/dist/src/services/rate-limit.d.ts +27 -0
- package/dist/src/services/rate-limit.d.ts.map +1 -0
- package/dist/src/services/rate-limit.js +91 -0
- package/dist/src/services/rate-limit.js.map +1 -0
- package/dist/src/services/reranker.d.ts +40 -0
- package/dist/src/services/reranker.d.ts.map +1 -0
- package/dist/src/services/reranker.js +97 -0
- package/dist/src/services/reranker.js.map +1 -0
- package/dist/src/services/search-engine.d.ts +89 -0
- package/dist/src/services/search-engine.d.ts.map +1 -0
- package/dist/src/services/search-engine.js +225 -0
- package/dist/src/services/search-engine.js.map +1 -0
- package/dist/src/services/tool-call-logger.d.ts +36 -0
- package/dist/src/services/tool-call-logger.d.ts.map +1 -0
- package/dist/src/services/tool-call-logger.js +34 -0
- package/dist/src/services/tool-call-logger.js.map +1 -0
- package/dist/src/types/env.d.ts +18 -0
- package/dist/src/types/env.d.ts.map +1 -0
- package/dist/src/types/env.js +2 -0
- package/dist/src/types/env.js.map +1 -0
- package/dist/src/types/index.d.ts +145 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +6 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/d1-utils.d.ts +6 -0
- package/dist/src/utils/d1-utils.d.ts.map +1 -0
- package/dist/src/utils/d1-utils.js +29 -0
- package/dist/src/utils/d1-utils.js.map +1 -0
- package/dist/src/utils/logger.d.ts +11 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +26 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/query-cleaner.d.ts +20 -0
- package/dist/src/utils/query-cleaner.d.ts.map +1 -0
- package/dist/src/utils/query-cleaner.js +117 -0
- package/dist/src/utils/query-cleaner.js.map +1 -0
- package/dist/src/utils/request-info.d.ts +18 -0
- package/dist/src/utils/request-info.d.ts.map +1 -0
- package/dist/src/utils/request-info.js +32 -0
- package/dist/src/utils/request-info.js.map +1 -0
- package/dist/src/utils/telegram-notifier.d.ts +4 -0
- package/dist/src/utils/telegram-notifier.d.ts.map +1 -0
- package/dist/src/utils/telegram-notifier.js +33 -0
- package/dist/src/utils/telegram-notifier.js.map +1 -0
- package/dist/src/utils/url-processor.d.ts +15 -0
- package/dist/src/utils/url-processor.d.ts.map +1 -0
- package/dist/src/utils/url-processor.js +54 -0
- package/dist/src/utils/url-processor.js.map +1 -0
- package/dist/src/worker.d.ts +15 -0
- package/dist/src/worker.d.ts.map +1 -0
- package/dist/src/worker.js +136 -0
- package/dist/src/worker.js.map +1 -0
- package/migrations/schema.sql +155 -0
- package/package.json +49 -0
- package/scripts/semantic-release-server-json.js +34 -0
- package/server.json +25 -0
- package/src/auth/auth-middleware.ts +104 -0
- package/src/auth/token-validator.ts +96 -0
- package/src/mcp/formatters/response-formatter.ts +157 -0
- package/src/mcp/manifest.ts +48 -0
- package/src/mcp/middleware/request-validator.ts +135 -0
- package/src/mcp/protocol-handler.ts +412 -0
- package/src/mcp/tools/fetch-tool.ts +146 -0
- package/src/mcp/tools/search-tool.ts +165 -0
- package/src/services/database.ts +202 -0
- package/src/services/deepinfra-base.ts +81 -0
- package/src/services/embedding.ts +96 -0
- package/src/services/index.ts +59 -0
- package/src/services/ip-authentication.ts +62 -0
- package/src/services/rag.ts +158 -0
- package/src/services/rate-limit.ts +141 -0
- package/src/services/reranker.ts +171 -0
- package/src/services/search-engine.ts +333 -0
- package/src/services/tool-call-logger.ts +98 -0
- package/src/types/env.ts +22 -0
- package/src/types/index.ts +189 -0
- package/src/utils/d1-utils.ts +45 -0
- package/src/utils/logger.ts +33 -0
- package/src/utils/query-cleaner.ts +151 -0
- package/src/utils/request-info.ts +47 -0
- package/src/utils/telegram-notifier.ts +47 -0
- package/src/utils/url-processor.ts +65 -0
- package/src/worker.ts +176 -0
- package/tsconfig.json +32 -0
- package/wrangler.toml.example +39 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
issues: write
|
|
12
|
+
pull-requests: write
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
release:
|
|
16
|
+
name: Release
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
24
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
25
|
+
|
|
26
|
+
- name: Install pnpm
|
|
27
|
+
uses: pnpm/action-setup@v3
|
|
28
|
+
with:
|
|
29
|
+
version: 8
|
|
30
|
+
|
|
31
|
+
- name: Setup Node.js
|
|
32
|
+
uses: actions/setup-node@v4
|
|
33
|
+
with:
|
|
34
|
+
node-version: '20'
|
|
35
|
+
cache: 'pnpm'
|
|
36
|
+
|
|
37
|
+
- name: Install dependencies
|
|
38
|
+
run: pnpm install --no-frozen-lockfile
|
|
39
|
+
|
|
40
|
+
- name: Run semantic-release
|
|
41
|
+
env:
|
|
42
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
43
|
+
run: pnpm exec semantic-release
|
|
44
|
+
|
|
45
|
+
- name: Build project
|
|
46
|
+
run: pnpm run build
|
|
47
|
+
|
|
48
|
+
- name: Deploy to Development
|
|
49
|
+
if: success()
|
|
50
|
+
env:
|
|
51
|
+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
52
|
+
run: |
|
|
53
|
+
pnpm install -g wrangler
|
|
54
|
+
pnpm run deploy:dev
|
|
55
|
+
|
|
56
|
+
- name: Deploy to Production
|
|
57
|
+
if: success()
|
|
58
|
+
env:
|
|
59
|
+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
60
|
+
run: pnpm run deploy:prod
|
|
61
|
+
|
|
62
|
+
|
package/.releaserc.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["main"],
|
|
3
|
+
"plugins": [
|
|
4
|
+
[
|
|
5
|
+
"@semantic-release/commit-analyzer",
|
|
6
|
+
{
|
|
7
|
+
"releaseRules": [
|
|
8
|
+
{ "type": "docs", "release": "patch" },
|
|
9
|
+
{ "type": "style", "release": "patch" },
|
|
10
|
+
{ "type": "refactor", "release": "patch" },
|
|
11
|
+
{ "type": "perf", "release": "patch" }
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"@semantic-release/release-notes-generator",
|
|
16
|
+
"@semantic-release/changelog",
|
|
17
|
+
[
|
|
18
|
+
"@semantic-release/npm",
|
|
19
|
+
{
|
|
20
|
+
"npmPublish": false
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"./scripts/semantic-release-server-json.js",
|
|
24
|
+
[
|
|
25
|
+
"@semantic-release/git",
|
|
26
|
+
{
|
|
27
|
+
"assets": ["package.json", "server.json", "CHANGELOG.md"],
|
|
28
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
"@semantic-release/github",
|
|
33
|
+
{
|
|
34
|
+
"assets": []
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
]
|
|
38
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
## [4.6.2](https://github.com/BingoWon/apple-rag-mcp/compare/v4.6.1...v4.6.2) (2025-12-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* preserve capitalized meta-descriptive words in query cleaner ([e378a89](https://github.com/BingoWon/apple-rag-mcp/commit/e378a89affaa9aab626b7498919ccf19750b2d1c))
|
|
7
|
+
|
|
8
|
+
## [4.6.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.6.0...v4.6.1) (2025-12-03)
|
|
9
|
+
|
|
10
|
+
# [4.6.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.5.1...v4.6.0) (2025-12-01)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* more generous rate limits and clearer usage guidance ([7daf6bc](https://github.com/BingoWon/apple-rag-mcp/commit/7daf6bc79a564d88d246e0cfbabfe48efd533abe))
|
|
16
|
+
|
|
17
|
+
# [4.6.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.5.1...v4.6.0) (2025-12-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* more generous rate limits and clearer usage guidance ([7daf6bc](https://github.com/BingoWon/apple-rag-mcp/commit/7daf6bc79a564d88d246e0cfbabfe48efd533abe))
|
|
23
|
+
|
|
24
|
+
## [4.5.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.5.0...v4.5.1) (2025-11-30)
|
|
25
|
+
|
|
26
|
+
# [4.5.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.4.2...v4.5.0) (2025-11-27)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* **d1:** add timeout protection and background writes for D1 operations ([3b87b63](https://github.com/BingoWon/apple-rag-mcp/commit/3b87b6355b14ad6a459516bd7ce73b27e7a41ca6))
|
|
32
|
+
|
|
33
|
+
## [4.4.2](https://github.com/BingoWon/apple-rag-mcp/compare/v4.4.1...v4.4.2) (2025-11-27)
|
|
34
|
+
|
|
35
|
+
## [4.4.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.4.0...v4.4.1) (2025-11-27)
|
|
36
|
+
|
|
37
|
+
# [4.4.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.3.3...v4.4.0) (2025-11-27)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* **reranker:** implement dual-model fallback with 8B→4B degradation ([3daf9cf](https://github.com/BingoWon/apple-rag-mcp/commit/3daf9cfea01656c8034bad7940aeb0ba282b664c))
|
|
43
|
+
|
|
44
|
+
## [4.3.3](https://github.com/BingoWon/apple-rag-mcp/compare/v4.3.2...v4.3.3) (2025-11-27)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* use ctx.waitUntil() for Telegram notifications ([c53bc8f](https://github.com/BingoWon/apple-rag-mcp/commit/c53bc8f06177c3d76be7e43b6d18fac5bdfe0ba3))
|
|
50
|
+
|
|
51
|
+
## [4.3.2](https://github.com/BingoWon/apple-rag-mcp/compare/v4.3.1...v4.3.2) (2025-11-27)
|
|
52
|
+
|
|
53
|
+
## [4.3.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.3.0...v4.3.1) (2025-11-26)
|
|
54
|
+
|
|
55
|
+
# [4.3.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.2.1...v4.3.0) (2025-11-26)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Features
|
|
59
|
+
|
|
60
|
+
* add requested_query and actual_query fields for search logs ([470bae8](https://github.com/BingoWon/apple-rag-mcp/commit/470bae81f3d082b3dfa0272fea5141da564b0c41))
|
|
61
|
+
|
|
62
|
+
## [4.2.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.2.0...v4.2.1) (2025-11-26)
|
|
63
|
+
|
|
64
|
+
# [4.2.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.7...v4.2.0) (2025-11-26)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Features
|
|
68
|
+
|
|
69
|
+
* add country_code tracking from Cloudflare ([d1777bb](https://github.com/BingoWon/apple-rag-mcp/commit/d1777bba8c93553878d32b79c067cf46d952de1f))
|
|
70
|
+
|
|
71
|
+
## [4.1.7](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.6...v4.1.7) (2025-11-26)
|
|
72
|
+
|
|
73
|
+
## [4.1.6](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.5...v4.1.6) (2025-11-23)
|
|
74
|
+
|
|
75
|
+
## [4.1.5](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.4...v4.1.5) (2025-11-06)
|
|
76
|
+
|
|
77
|
+
## [4.1.4](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.3...v4.1.4) (2025-11-06)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### Bug Fixes
|
|
81
|
+
|
|
82
|
+
* remove legacy SSE support ([82224c0](https://github.com/BingoWon/apple-rag-mcp/commit/82224c06beefb200171bb9efa411987fcc0723e8))
|
|
83
|
+
|
|
84
|
+
## [4.1.3](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.2...v4.1.3) (2025-10-08)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Bug Fixes
|
|
88
|
+
|
|
89
|
+
* enhance token extraction to handle multiple Bearer prefixes and improve error logging ([c8f0c73](https://github.com/BingoWon/apple-rag-mcp/commit/c8f0c735c7f5319b9bb7f9f99b2ca188c2657864))
|
|
90
|
+
|
|
91
|
+
## [4.1.2](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.1...v4.1.2) (2025-10-07)
|
|
92
|
+
|
|
93
|
+
## [4.1.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.1.0...v4.1.1) (2025-10-04)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Bug Fixes
|
|
97
|
+
|
|
98
|
+
* add keep_vars to preserve Cloudflare Secrets on deploy ([d840d06](https://github.com/BingoWon/apple-rag-mcp/commit/d840d06108118ca881252a80fb2000f6a71e1f94))
|
|
99
|
+
|
|
100
|
+
# [4.1.0](https://github.com/BingoWon/apple-rag-mcp/compare/v4.0.2...v4.1.0) (2025-10-04)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Features
|
|
104
|
+
|
|
105
|
+
* configure semantic-release to trigger patch releases for docs and style commits ([0f1c4ae](https://github.com/BingoWon/apple-rag-mcp/commit/0f1c4ae9bcd15651d89ac86e1ce67ca3c107de30))
|
|
106
|
+
|
|
107
|
+
## [4.0.2](https://github.com/BingoWon/apple-rag-mcp/compare/v4.0.1...v4.0.2) (2025-09-30)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Bug Fixes
|
|
111
|
+
|
|
112
|
+
* remove duplicate v4.0.1 entry in CHANGELOG.md ([45a7748](https://github.com/BingoWon/apple-rag-mcp/commit/45a7748716b6e7e07436056bd035b258226553da))
|
|
113
|
+
|
|
114
|
+
## [4.0.1](https://github.com/BingoWon/apple-rag-mcp/compare/v4.0.0...v4.0.1) (2025-09-30)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
### Bug Fixes
|
|
118
|
+
|
|
119
|
+
* simplify deployment workflow ([1ebb758](https://github.com/BingoWon/apple-rag-mcp/commit/1ebb75821b1116cb8ca1ca0725978d1434403039))
|
|
120
|
+
* test patch release workflow ([15d1126](https://github.com/BingoWon/apple-rag-mcp/commit/15d1126b92fba30c72fd67aa9613848f42540610))
|
|
121
|
+
|
|
122
|
+
# [4.0.0](https://github.com/BingoWon/apple-rag-mcp/compare/v3.0.1...v4.0.0) (2025-09-30)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Features
|
|
126
|
+
|
|
127
|
+
* migrate to Cloudflare Workers Secrets for secure configuration ([98b8bba](https://github.com/BingoWon/apple-rag-mcp/commit/98b8bbac930bcbfb0efe40e5adb4da854ccb6c0b))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### BREAKING CHANGES
|
|
131
|
+
|
|
132
|
+
* Environment variables moved from wrangler.toml to Cloudflare Secrets
|
|
133
|
+
|
|
134
|
+
## [3.0.1](https://github.com/BingoWon/apple-rag-mcp/compare/v3.0.0...v3.0.1) (2025-09-26)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### Bug Fixes
|
|
138
|
+
|
|
139
|
+
* add build step before deployment in CI workflow ([e474a22](https://github.com/BingoWon/apple-rag-mcp/commit/e474a227ced60839f2cf0a84eccc681bac5982b4))
|
|
140
|
+
|
|
141
|
+
# [3.0.0](https://github.com/BingoWon/apple-rag-mcp/compare/v2.9.1...v3.0.0) (2025-09-25)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### Bug Fixes
|
|
145
|
+
|
|
146
|
+
* add workflow_dispatch trigger for manual release testing ([610e345](https://github.com/BingoWon/apple-rag-mcp/commit/610e34585d6afa14c1288fcbe76c187c9aefdc01))
|
|
147
|
+
* convert semantic-release plugin to ES modules ([c96767a](https://github.com/BingoWon/apple-rag-mcp/commit/c96767a884f09de93670b6c577dce7287857e91f))
|
|
148
|
+
* correct GitHub Actions workflow configuration ([bcb06d0](https://github.com/BingoWon/apple-rag-mcp/commit/bcb06d0dc07790774579fca171f34c4fc6a6f209))
|
|
149
|
+
* resolve pnpm lockfile compatibility issue in CI ([e5012be](https://github.com/BingoWon/apple-rag-mcp/commit/e5012be43766609ffb4328dc5bf7b9db48e8a9a4))
|
|
150
|
+
* restore complete pnpm-only workflow with proper action setup ([d1f27bf](https://github.com/BingoWon/apple-rag-mcp/commit/d1f27bf8c0479f1c7146100e68d6b8aa668ec74c))
|
|
151
|
+
* simplify GitHub Actions workflow for semantic-release testing ([0857757](https://github.com/BingoWon/apple-rag-mcp/commit/08577575cca72db89421375f046d1fa3ea7ae265))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### Features
|
|
155
|
+
|
|
156
|
+
* migrate to semantic-release for modern automated releases ([9f90ed7](https://github.com/BingoWon/apple-rag-mcp/commit/9f90ed772aefcf7dc59b6fa3cf78a04373785345))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
### BREAKING CHANGES
|
|
160
|
+
|
|
161
|
+
* Release process now fully automated via GitHub Actions
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://apple-rag.com/logo-with-text.svg" alt="Apple RAG MCP" width="400">
|
|
4
|
+
|
|
5
|
+
### The Apple docs MCP your AI actually deserves.
|
|
6
|
+
|
|
7
|
+
*370,000+ docs. 1,300+ WWDC transcripts. Semantic + keyword + hybrid search. One clean tool.*
|
|
8
|
+
|
|
9
|
+
[](https://cursor.com/en/install-mcp?name=apple-rag-mcp&config=eyJ1cmwiOiJodHRwczovL21jcC5hcHBsZS1yYWcuY29tIn0%3D)
|
|
10
|
+
|
|
11
|
+
[](vscode:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D) [](vscode-insiders:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D)
|
|
12
|
+
|
|
13
|
+
[🌐 Website](https://apple-rag.com) • [📊 Dashboard](https://apple-rag.com/overview)
|
|
14
|
+
|
|
15
|
+
**English** | [中文](./README.zh-CN.md)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Not Just Another Docs Tool
|
|
22
|
+
|
|
23
|
+
Others give you keyword search. We give you that, plus semantic understanding, plus AI-powered hybrid search that combines both intelligently. Every search mode you need, working together.
|
|
24
|
+
|
|
25
|
+
**Minimal footprint. Maximum signal.** Our MCP tools are designed to be lean—no bloated responses, no wasted tokens, no noise cluttering your agent's context. Just the information that matters.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Start in Seconds
|
|
30
|
+
|
|
31
|
+
**One click:**
|
|
32
|
+
|
|
33
|
+
[](https://cursor.com/en/install-mcp?name=apple-rag-mcp&config=eyJ1cmwiOiJodHRwczovL21jcC5hcHBsZS1yYWcuY29tIn0%3D)
|
|
34
|
+
|
|
35
|
+
[](vscode:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D) [](vscode-insiders:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D)
|
|
36
|
+
|
|
37
|
+
Click the button above and your editor will automatically configure everything for you in seconds.
|
|
38
|
+
|
|
39
|
+
### Option 2: Manual Setup for Other MCP Clients
|
|
40
|
+
|
|
41
|
+
**JSON Configuration (Copy & Paste):**
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"apple-rag-mcp": {
|
|
46
|
+
"url": "https://mcp.apple-rag.com"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Manual Configuration Parameters:**
|
|
53
|
+
- **MCP Type:** `Streamable HTTP`
|
|
54
|
+
- **URL:** `https://mcp.apple-rag.com`
|
|
55
|
+
- **Authentication:** `Optional` (MCP Token for higher limits)
|
|
56
|
+
- **MCP Token:** Get yours at [apple-rag.com](https://apple-rag.com) for increased quota
|
|
57
|
+
|
|
58
|
+
**Supported Clients:** Cursor, Claude Desktop, Cline, and all MCP-compatible tools.
|
|
59
|
+
|
|
60
|
+
> **Note:** No MCP Token required to start! You get free queries without any authentication. Add an MCP Token later for higher usage limits.
|
|
61
|
+
|
|
62
|
+
## 🌟 Why Developers Love Apple RAG MCP
|
|
63
|
+
|
|
64
|
+
<table>
|
|
65
|
+
<tr>
|
|
66
|
+
<td width="50%">
|
|
67
|
+
|
|
68
|
+
### ⚡ **Fast & Reliable**
|
|
69
|
+
Get quick responses with our optimized search infrastructure. No more hunting through docs.
|
|
70
|
+
|
|
71
|
+
### 🎯 **AI-Powered Hybrid Search**
|
|
72
|
+
Advanced search technology combining Semantic Search for RAG, Keyword Search, and Hybrid Search with vector similarity and technical term matching provides accurate, contextual answers from Apple's documentation.
|
|
73
|
+
|
|
74
|
+
### 🔒 **Always Secure**
|
|
75
|
+
MCP authentication ensures trusted access for your AI agents with enterprise-grade security.
|
|
76
|
+
|
|
77
|
+
</td>
|
|
78
|
+
<td width="50%">
|
|
79
|
+
|
|
80
|
+
### 📝 **Code Examples**
|
|
81
|
+
Get practical code examples in Swift, Objective-C, and SwiftUI alongside documentation references.
|
|
82
|
+
|
|
83
|
+
### 🔄 **Real-time Updates**
|
|
84
|
+
Our documentation index is continuously updated to reflect the latest Apple developer resources.
|
|
85
|
+
|
|
86
|
+
### 🆓 **Completely Free**
|
|
87
|
+
Start immediately with no MCP Token required. Get an MCP Token for higher usage limits - all managed at [apple-rag.com](https://apple-rag.com).
|
|
88
|
+
|
|
89
|
+
</td>
|
|
90
|
+
</tr>
|
|
91
|
+
</table>
|
|
92
|
+
|
|
93
|
+
## 🎯 Features
|
|
94
|
+
|
|
95
|
+
- **🔍 Semantic Search for RAG** - Vector similarity with semantic understanding for intelligent retrieval
|
|
96
|
+
- **🔎 Keyword Search** - Precise technical term matching for API names and specific terminology
|
|
97
|
+
- **🎯 Hybrid Search** - Combined semantic and keyword search with AI reranking for optimal results
|
|
98
|
+
- **📚 Complete Coverage** - iOS, macOS, watchOS, tvOS, visionOS documentation
|
|
99
|
+
- **🎬 WWDC Videos** - Full transcripts from Apple Developer videos and WWDC sessions
|
|
100
|
+
- **⚡ Fast Response** - Optimized for speed across all content types
|
|
101
|
+
- **🚀 High Performance** - Multi-instance cluster deployment for maximum throughput
|
|
102
|
+
- **🔄 Always Current** - Synced with Apple's latest docs and video content
|
|
103
|
+
- **🛡️ Secure & Private** - Your queries stay private
|
|
104
|
+
- **🌐 Universal MCP** - Works with any MCP-compatible client
|
|
105
|
+
|
|
106
|
+
<div align="center">
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
**Better docs. Better context. Better code.**
|
|
111
|
+
|
|
112
|
+
[Get Started →](https://apple-rag.com)
|
|
113
|
+
|
|
114
|
+
</div>
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://apple-rag.com/logo-with-text.svg" alt="Apple RAG MCP" width="400">
|
|
4
|
+
|
|
5
|
+
### 为 AI 智能体打造的 Apple 文档 MCP
|
|
6
|
+
|
|
7
|
+
*覆盖 37 万+ 文档、1,300+ 条 WWDC 视频字幕。支持语义 / 关键词 / 混合搜索,一站式把答案递到你的智能体手中。*
|
|
8
|
+
|
|
9
|
+
[](https://cursor.com/en/install-mcp?name=apple-rag-mcp&config=eyJ1cmwiOiJodHRwczovL21jcC5hcHBsZS1yYWcuY29tIn0%3D)
|
|
10
|
+
|
|
11
|
+
[](vscode:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D) [](vscode-insiders:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D)
|
|
12
|
+
|
|
13
|
+
[🌐 官网](https://apple-rag.com) • [📊 控制台](https://apple-rag.com/overview)
|
|
14
|
+
|
|
15
|
+
[English](./README.md) | **中文**
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 不只是查文档
|
|
22
|
+
|
|
23
|
+
多数工具只能做关键词匹配。Apple RAG MCP 在关键词搜索之外加入语义理解,并用 AI 混合搜索把两者结合,把真正有用的上下文精准送到你的智能体。
|
|
24
|
+
|
|
25
|
+
**精简高效。** 响应克制、不啰嗦,尽量少占用 token,不打乱智能体的上下文,只保留最有价值的信号。
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 方式一:秒速开始
|
|
30
|
+
|
|
31
|
+
**免费对话体验:**
|
|
32
|
+
- [阿里云百宝箱网页应用 - 苹果应用开发专家](https://tbox.alipay.com/inc/share/202511APsocn07628729?platform=WebService)
|
|
33
|
+
- [阿里云百宝箱 MCP 插件(需先登录) - 苹果开发文档检索 / Apple RAG MCP](https://tbox.alipay.com/inc/plugin-market/plugin-detail/20251130R4pz05084592)
|
|
34
|
+
|
|
35
|
+
**一键安装:**
|
|
36
|
+
|
|
37
|
+
[](https://cursor.com/en/install-mcp?name=apple-rag-mcp&config=eyJ1cmwiOiJodHRwczovL21jcC5hcHBsZS1yYWcuY29tIn0%3D)
|
|
38
|
+
|
|
39
|
+
[](vscode:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D) [](vscode-insiders:mcp/install?%7B%22name%22%3A%22apple-rag-mcp%22%2C%22type%22%3A%22http%22%2C%22url%22%3A%22https%3A%2F%2Fmcp.apple-rag.com%22%7D)
|
|
40
|
+
|
|
41
|
+
点击上面的按钮,在 IDE 中自动填充 MCP 配置,几秒钟即可使用。
|
|
42
|
+
|
|
43
|
+
### 方式二:为其他 MCP 客户端手动配置
|
|
44
|
+
|
|
45
|
+
**JSON 配置(直接粘贴):**
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"mcpServers": {
|
|
49
|
+
"apple-rag-mcp": {
|
|
50
|
+
"url": "https://mcp.apple-rag.com"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**手动配置参数:**
|
|
57
|
+
- **MCP 类型:** `Streamable HTTP`
|
|
58
|
+
- **URL:** `https://mcp.apple-rag.com`
|
|
59
|
+
- **认证:** `可选`(添加 MCP Token 可提升配额)
|
|
60
|
+
- **MCP Token:** 在 [apple-rag.com](https://apple-rag.com) 获取
|
|
61
|
+
|
|
62
|
+
**支持的客户端:** 通义灵码、Cursor、Claude Desktop、Cline,以及任何兼容 MCP 的工具。
|
|
63
|
+
|
|
64
|
+
> **提示:** 开箱即可免费使用,无需 Token。需要更高额度时,再添加 MCP Token。
|
|
65
|
+
|
|
66
|
+
## 🌟 开发者为什么选 Apple RAG MCP
|
|
67
|
+
|
|
68
|
+
<table>
|
|
69
|
+
<tr>
|
|
70
|
+
<td width="50%">
|
|
71
|
+
|
|
72
|
+
### ⚡ **响应迅捷**
|
|
73
|
+
优化的搜索基础设施,结果反馈更快,省去翻找文档的时间。
|
|
74
|
+
|
|
75
|
+
### 🎯 **AI 混合搜索**
|
|
76
|
+
语义 + 关键词 + 向量重排序,精准锁定 Apple 文档里的上下文答案。
|
|
77
|
+
|
|
78
|
+
### 🔒 **安全可信**
|
|
79
|
+
MCP 认证链路,确保你的智能体获得安全、可控的访问。
|
|
80
|
+
|
|
81
|
+
</td>
|
|
82
|
+
<td width="50%">
|
|
83
|
+
|
|
84
|
+
### 📝 **示例随取随用**
|
|
85
|
+
提供 Swift、Objective-C、SwiftUI 的实用代码示例和文档。
|
|
86
|
+
|
|
87
|
+
### 🔄 **持续更新**
|
|
88
|
+
文档索引与 Apple 开发者资源持续同步,保持最新。
|
|
89
|
+
|
|
90
|
+
### 🆓 **免费上手**
|
|
91
|
+
无需 Token 即可使用;可在 [apple-rag.com](https://apple-rag.com) 获取更多配额。
|
|
92
|
+
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
</table>
|
|
96
|
+
|
|
97
|
+
## 🎯 核心能力
|
|
98
|
+
|
|
99
|
+
- **🔍 RAG 语义搜索** - 基于语义理解的向量相似度检索
|
|
100
|
+
- **🔎 关键词搜索** - 精准匹配 API 名称和技术术语
|
|
101
|
+
- **🎯 混合搜索** - 语义 + 关键词 + AI 重排序,挑出最佳结果
|
|
102
|
+
- **📚 全面覆盖** - 覆盖 iOS、macOS、watchOS、tvOS、visionOS 文档
|
|
103
|
+
- **🎬 WWDC 视频** - 收录 Apple 开发者视频与 WWDC session 字幕
|
|
104
|
+
- **⚡ 快速响应** - 针对所有内容类型优化查询速度
|
|
105
|
+
- **🚀 高性能** - 多实例集群带来高吞吐
|
|
106
|
+
- **🔄 始终最新** - 持续同步最新文档与视频
|
|
107
|
+
- **🛡️ 安全私密** - 查询保持私密与安全
|
|
108
|
+
- **🌐 通用 MCP** - 兼容所有支持 MCP 的客户端
|
|
109
|
+
|
|
110
|
+
<div align="center">
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
**更优质的文档,更清晰的上下文,更踏实的代码。**
|
|
115
|
+
|
|
116
|
+
[立即开始 →](https://apple-rag.com)
|
|
117
|
+
|
|
118
|
+
</div>
|
|
119
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[2025-12-29] [✅] 获取项目信息: https://github.com/BingoWon/apple-rag-mcp
|
|
2
|
+
[2025-12-29] [✅] Fork和克隆: 成功克隆到 /Users/jiashuowang/MCPs/提示词项目/iflow_auto_import/data/apple-rag-mcp
|
|
3
|
+
[2025-12-29] [✅] 阅读代码: Node.js/TypeScript项目,使用Cloudflare Workers,streamable-http协议
|
|
4
|
+
[2025-12-29] [✅] 修改配置文件: package.json已修改,name改为@iflow-mcp/BingoWon_apple-rag-mcp
|
|
5
|
+
[2025-12-29] [✅] 修复代码问题: 无需修复,Cloudflare Workers项目
|
|
6
|
+
[2025-12-29] [✅] 构建项目: TypeScript构建成功
|
|
7
|
+
[2025-12-29] [⚠️] 本地测试: 项目使用streamable-http协议,需要Cloudflare Workers和D1数据库环境,无法进行stdio本地测试。项目已部署在https://mcp.apple-rag.com
|
|
8
|
+
[2025-12-29] [✅] 创建并推送iflow分支: 已成功创建并推送到远程
|
package/biome.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false
|
|
10
|
+
},
|
|
11
|
+
"formatter": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"indentStyle": "space",
|
|
14
|
+
"indentWidth": 2,
|
|
15
|
+
"lineWidth": 80
|
|
16
|
+
},
|
|
17
|
+
"linter": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"rules": {
|
|
20
|
+
"recommended": true,
|
|
21
|
+
"suspicious": {
|
|
22
|
+
"noExplicitAny": "warn",
|
|
23
|
+
"noArrayIndexKey": "off"
|
|
24
|
+
},
|
|
25
|
+
"style": {
|
|
26
|
+
"noNonNullAssertion": "off"
|
|
27
|
+
},
|
|
28
|
+
"complexity": {
|
|
29
|
+
"noForEach": "off"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"javascript": {
|
|
34
|
+
"formatter": {
|
|
35
|
+
"quoteStyle": "double",
|
|
36
|
+
"jsxQuoteStyle": "double",
|
|
37
|
+
"trailingCommas": "es5",
|
|
38
|
+
"semicolons": "always",
|
|
39
|
+
"arrowParentheses": "always",
|
|
40
|
+
"bracketSpacing": true,
|
|
41
|
+
"bracketSameLine": false
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"assist": {
|
|
45
|
+
"enabled": true,
|
|
46
|
+
"actions": {
|
|
47
|
+
"source": {
|
|
48
|
+
"organizeImports": "on"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"json": {
|
|
53
|
+
"formatter": {
|
|
54
|
+
"enabled": true,
|
|
55
|
+
"indentStyle": "space",
|
|
56
|
+
"indentWidth": 2
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple MCP Authentication Middleware
|
|
3
|
+
*/
|
|
4
|
+
import type { AuthContext } from "../types/index.js";
|
|
5
|
+
import { type UserTokenData } from "./token-validator.js";
|
|
6
|
+
export declare class AuthMiddleware {
|
|
7
|
+
private readonly tokenValidator;
|
|
8
|
+
private readonly ipAuthService;
|
|
9
|
+
constructor(d1: D1Database);
|
|
10
|
+
/**
|
|
11
|
+
* Extract Bearer token from Authorization header
|
|
12
|
+
* Handles multiple "Bearer" prefixes and validates token format
|
|
13
|
+
*/
|
|
14
|
+
private extractBearerToken;
|
|
15
|
+
/**
|
|
16
|
+
* Optional authentication middleware
|
|
17
|
+
* Validates token if present, or checks IP-based authentication, allows access without either
|
|
18
|
+
*/
|
|
19
|
+
optionalAuth(request: Request): Promise<AuthContext>;
|
|
20
|
+
getUserData(userId: string): Promise<UserTokenData>;
|
|
21
|
+
/**
|
|
22
|
+
* Get client IP address from request (Worker optimized)
|
|
23
|
+
*/
|
|
24
|
+
private getClientIP;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/auth/auth-middleware.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1E,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0B;gBAE5C,EAAE,EAAE,UAAU;IAK1B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAmDpD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIzD;;OAEG;IACH,OAAO,CAAC,WAAW;CASpB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple MCP Authentication Middleware
|
|
3
|
+
*/
|
|
4
|
+
import { IPAuthenticationService } from "../services/ip-authentication.js";
|
|
5
|
+
import { logger } from "../utils/logger.js";
|
|
6
|
+
import { TokenValidator } from "./token-validator.js";
|
|
7
|
+
export class AuthMiddleware {
|
|
8
|
+
tokenValidator;
|
|
9
|
+
ipAuthService;
|
|
10
|
+
constructor(d1) {
|
|
11
|
+
this.tokenValidator = new TokenValidator(d1);
|
|
12
|
+
this.ipAuthService = new IPAuthenticationService(d1);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Extract Bearer token from Authorization header
|
|
16
|
+
* Handles multiple "Bearer" prefixes and validates token format
|
|
17
|
+
*/
|
|
18
|
+
extractBearerToken(authHeader) {
|
|
19
|
+
if (!authHeader)
|
|
20
|
+
return null;
|
|
21
|
+
// Remove all "Bearer " prefixes (case-insensitive, supports multiple)
|
|
22
|
+
const token = authHeader.replace(/^(Bearer\s+)+/gi, "").trim();
|
|
23
|
+
// Only return if it matches valid token format
|
|
24
|
+
return /^at_[a-f0-9]{32}$/.test(token) ? token : null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Optional authentication middleware
|
|
28
|
+
* Validates token if present, or checks IP-based authentication, allows access without either
|
|
29
|
+
*/
|
|
30
|
+
async optionalAuth(request) {
|
|
31
|
+
const authHeader = request.headers.get("authorization");
|
|
32
|
+
const token = this.extractBearerToken(authHeader || undefined);
|
|
33
|
+
const clientIP = this.getClientIP(request);
|
|
34
|
+
// Try token authentication first
|
|
35
|
+
if (token) {
|
|
36
|
+
const validation = await this.tokenValidator.validateToken(token);
|
|
37
|
+
if (validation.valid) {
|
|
38
|
+
logger.info(`Token authentication successful for userId: ${validation.userData?.userId}`);
|
|
39
|
+
return {
|
|
40
|
+
isAuthenticated: true,
|
|
41
|
+
userId: validation.userData?.userId,
|
|
42
|
+
email: validation.userData?.email,
|
|
43
|
+
token: token,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
logger.error(`Token validation failed. Raw header: "${authHeader}", Extracted token: "${token}", IP: ${clientIP}, Error: ${validation.error}`);
|
|
47
|
+
}
|
|
48
|
+
// Try IP-based authentication
|
|
49
|
+
const ipAuthResult = await this.ipAuthService.checkIPAuthentication(clientIP);
|
|
50
|
+
if (ipAuthResult) {
|
|
51
|
+
logger.info(`IP-based authentication successful for userId: ${ipAuthResult.userId} from IP: ${clientIP}`);
|
|
52
|
+
return {
|
|
53
|
+
isAuthenticated: true,
|
|
54
|
+
userId: ipAuthResult.userId,
|
|
55
|
+
email: ipAuthResult.email,
|
|
56
|
+
token: "ip-based",
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// No authentication method succeeded
|
|
60
|
+
logger.info(`No authentication provided - allowing unauthenticated access from IP: ${clientIP} (hasToken: ${!!token})`);
|
|
61
|
+
return { isAuthenticated: false };
|
|
62
|
+
}
|
|
63
|
+
async getUserData(userId) {
|
|
64
|
+
return this.tokenValidator.getUserDataById(userId);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get client IP address from request (Worker optimized)
|
|
68
|
+
*/
|
|
69
|
+
getClientIP(request) {
|
|
70
|
+
// Cloudflare provides client IP in CF-Connecting-IP header
|
|
71
|
+
return (request.headers.get("CF-Connecting-IP") ||
|
|
72
|
+
request.headers.get("X-Forwarded-For") ||
|
|
73
|
+
request.headers.get("X-Real-IP") ||
|
|
74
|
+
"unknown");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=auth-middleware.js.map
|