@internetarchive/fetch-handler 1.0.1

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 (62) hide show
  1. package/.editorconfig +29 -0
  2. package/.github/workflows/ci.yml +27 -0
  3. package/.github/workflows/gh-pages-main.yml +40 -0
  4. package/.github/workflows/pr-preview.yml +63 -0
  5. package/.husky/pre-commit +4 -0
  6. package/.prettierignore +1 -0
  7. package/.vscode/extensions.json +12 -0
  8. package/.vscode/tasks.json +12 -0
  9. package/LICENSE +661 -0
  10. package/README.md +82 -0
  11. package/coverage/.gitignore +3 -0
  12. package/coverage/.placeholder +0 -0
  13. package/demo/app-root.ts +84 -0
  14. package/demo/index.html +27 -0
  15. package/dist/demo/app-root.d.ts +12 -0
  16. package/dist/demo/app-root.js +90 -0
  17. package/dist/demo/app-root.js.map +1 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/src/fetch-handler-interface.d.ts +33 -0
  22. package/dist/src/fetch-handler-interface.js +2 -0
  23. package/dist/src/fetch-handler-interface.js.map +1 -0
  24. package/dist/src/ia-fetch-handler.d.ts +36 -0
  25. package/dist/src/ia-fetch-handler.js +70 -0
  26. package/dist/src/ia-fetch-handler.js.map +1 -0
  27. package/dist/src/utils/fetch-retrier.d.ts +36 -0
  28. package/dist/src/utils/fetch-retrier.js +94 -0
  29. package/dist/src/utils/fetch-retrier.js.map +1 -0
  30. package/dist/src/utils/promised-sleep.d.ts +13 -0
  31. package/dist/src/utils/promised-sleep.js +16 -0
  32. package/dist/src/utils/promised-sleep.js.map +1 -0
  33. package/dist/test/fetch-retrier.test.d.ts +1 -0
  34. package/dist/test/fetch-retrier.test.js +139 -0
  35. package/dist/test/fetch-retrier.test.js.map +1 -0
  36. package/dist/test/ia-fetch-handler.test.d.ts +1 -0
  37. package/dist/test/ia-fetch-handler.test.js +50 -0
  38. package/dist/test/ia-fetch-handler.test.js.map +1 -0
  39. package/dist/test/mocks/mock-analytics-handler.d.ts +20 -0
  40. package/dist/test/mocks/mock-analytics-handler.js +28 -0
  41. package/dist/test/mocks/mock-analytics-handler.js.map +1 -0
  42. package/dist/vite.config.d.ts +2 -0
  43. package/dist/vite.config.js +25 -0
  44. package/dist/vite.config.js.map +1 -0
  45. package/eslint.config.mjs +53 -0
  46. package/index.ts +2 -0
  47. package/package.json +74 -0
  48. package/renovate.json +6 -0
  49. package/screenshot/gh-pages-settings.png +0 -0
  50. package/src/fetch-handler-interface.ts +39 -0
  51. package/src/ia-fetch-handler.ts +94 -0
  52. package/src/utils/fetch-retrier.ts +141 -0
  53. package/src/utils/promised-sleep.ts +15 -0
  54. package/ssl/server.crt +22 -0
  55. package/ssl/server.key +28 -0
  56. package/test/fetch-retrier.test.ts +173 -0
  57. package/test/ia-fetch-handler.test.ts +66 -0
  58. package/test/mocks/mock-analytics-handler.ts +43 -0
  59. package/tsconfig.json +31 -0
  60. package/vite.config.ts +25 -0
  61. package/web-dev-server.config.mjs +32 -0
  62. package/web-test-runner.config.mjs +41 -0
package/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,27 @@
1
+ name: App CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-node@v4
16
+ with:
17
+ node-version: latest
18
+
19
+ - name: Install dependencies
20
+ run: npm install
21
+
22
+ - name: Run tests
23
+ run: npm run test
24
+
25
+ - uses: codecov/codecov-action@v5
26
+ with:
27
+ token: ${{ secrets.CODECOV_TOKEN }}
@@ -0,0 +1,40 @@
1
+ # This workflow will generate the static page under `main` subdirectory inside the `gh-pages` branch
2
+
3
+ # This workflow will run every time new changes were pushed to the `main` branch
4
+
5
+ name: App build CI/CD to main branch
6
+ permissions:
7
+ contents: write
8
+
9
+ on:
10
+ push:
11
+ branches: [ main ]
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ with:
20
+ persist-credentials: false
21
+ - uses: actions/setup-node@v4
22
+ with:
23
+ node-version: latest
24
+
25
+
26
+ - name: Install dependencies
27
+ run: npm install
28
+
29
+ - name: Create build files for gh-pages deploy
30
+ run: npm run ghpages:build
31
+
32
+ # Reference: https://github.com/JamesIves/github-pages-deploy-action
33
+ - name: Deploy 🚀
34
+ uses: JamesIves/github-pages-deploy-action@v4.7.3
35
+ with:
36
+ branch: gh-pages
37
+ folder: ghpages
38
+ clean-exclude: pr/
39
+ force: false
40
+ target-folder: main
@@ -0,0 +1,63 @@
1
+ # This workflow will generate the static page under `pr` subdirectory inside the `gh-pages` branch
2
+
3
+ # This workflow will run every time there's a PR opened, reopened, synchronize, or closed
4
+
5
+ name: Deploy PR previews
6
+
7
+ on:
8
+ pull_request:
9
+ types:
10
+ - opened
11
+ - reopened
12
+ - synchronize
13
+ - closed
14
+
15
+ concurrency: preview-${{ github.ref }}
16
+
17
+ env:
18
+ PREVIEW_BRANCH: gh-pages
19
+ jobs:
20
+ deploy-preview:
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - name: Checkout
24
+ uses: actions/checkout@v4
25
+ - uses: actions/setup-node@v4
26
+ with:
27
+ node-version: latest
28
+
29
+
30
+ - name: Install and Build
31
+ run: |
32
+ npm install
33
+ npm run ghpages:build
34
+
35
+ # Reference: https://github.com/rossjrw/pr-preview-action
36
+ - name: Deploy preview
37
+ uses: rossjrw/pr-preview-action@v1
38
+ id: preview-step
39
+ with:
40
+ source-dir: ./ghpages/
41
+ umbrella-dir: pr
42
+ preview-branch: ${{ env.PREVIEW_BRANCH }}
43
+ comment: false
44
+
45
+ - uses: marocchino/sticky-pull-request-comment@v2
46
+ if: steps.preview-step.outputs.deployment-action == 'deploy'
47
+ with:
48
+ header: pr-preview
49
+ message: |
50
+ [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
51
+ :---:
52
+ | <p></p> :rocket: View preview at <br> ${{ steps.preview-step.outputs.preview-url }}demo/ <br><br>
53
+ | <h6>Built to branch [`${{ env.PREVIEW_BRANCH }}`](${{ github.server_url }}/${{ github.repository }}/tree/${{ env.PREVIEW_BRANCH }}) at ${{ steps.preview-step.outputs.action-start-time }}. <br> Preview will be ready when the [GitHub Pages deployment](${{ github.server_url }}/${{ github.repository }}/deployments) is complete. <br><br> </h6>
54
+
55
+ - uses: marocchino/sticky-pull-request-comment@v2
56
+ if: steps.preview-step.outputs.deployment-action == 'remove'
57
+ with:
58
+ header: pr-preview
59
+ message: |
60
+ [PR Preview Action](https://github.com/rossjrw/pr-preview-action) ${{ steps.preview-step.outputs.action-version }}
61
+ :---:
62
+ Preview removed because the pull request was closed.
63
+ ${{ steps.preview-step.outputs.action-start-time }}
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -0,0 +1 @@
1
+ coverage
@@ -0,0 +1,12 @@
1
+ {
2
+ "recommendations": [
3
+ "dbaeumer.vscode-eslint",
4
+ "esbenp.prettier-vscode",
5
+ "bierner.lit-html",
6
+ "bashmish.es6-string-css",
7
+ "streetsidesoftware.code-spell-checker",
8
+ "runem.lit-plugin",
9
+ "ryanluker.vscode-coverage-gutters"
10
+ ]
11
+ }
12
+
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Watch coverage on open",
6
+ "command": "${command:coverage-gutters.watchCoverageAndVisibleEditors}",
7
+ "runOptions": {
8
+ "runOn": "folderOpen"
9
+ }
10
+ }
11
+ ]
12
+ }