├── .eslintrc.js ├── .github ├── FUNDING.yml └── workflows │ └── release.yml ├── .gitignore ├── .gitmodules ├── .npmrc ├── .prettierignore ├── .prettierrc.js ├── .yarnrc.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── config.json ├── demo-snippets ├── assets │ ├── httpbin.org.cer │ └── httpbin.org.expired.cer ├── package.json └── vue │ ├── Basic.vue │ └── install.ts ├── docs ├── .nojekyll ├── assets │ ├── hierarchy.js │ ├── highlight.css │ ├── icons.js │ ├── icons.svg │ ├── main.js │ ├── navigation.js │ ├── search.js │ └── style.css ├── functions │ ├── addInterceptor.html │ ├── addNetworkInterceptor.html │ ├── cancelAllRequests.html │ ├── cancelRequest.html │ ├── clearCache.html │ ├── clearCookies.html │ ├── createRequest.html │ ├── disableSSLPinning.html │ ├── enableSSLPinning.html │ ├── getBinary.html │ ├── getClient.html │ ├── getFile.html │ ├── getFilenameFromUrl.html │ ├── getImage.html │ ├── getJSON.html │ ├── getString.html │ ├── parseJSON.html │ ├── removeCachedResponse.html │ ├── request.html │ └── setCache.html ├── index.html ├── interfaces │ ├── CacheOptions.html │ ├── Headers.html │ ├── HttpsFormDataParam.html │ ├── HttpsRequest.html │ ├── HttpsRequestObject.html │ ├── HttpsRequestOptions.html │ ├── HttpsResponse.html │ ├── HttpsResponseLegacy.html │ └── HttpsSSLPinningOptions.html ├── media │ └── Basic.vue ├── modules.html ├── types │ └── CachePolicy.html └── variables │ ├── interceptors.html │ └── networkInterceptors.html ├── lerna.json ├── package.json ├── packages └── https │ ├── .npmignore │ ├── CHANGELOG.md │ ├── README.md │ ├── angular │ └── package.json │ ├── blueprint.md │ ├── package.json │ ├── platforms │ ├── android │ │ ├── include.gradle │ │ ├── java │ │ │ └── com │ │ │ │ └── nativescript │ │ │ │ └── https │ │ │ │ ├── CacheInterceptor.java │ │ │ │ ├── CacheUtils.java │ │ │ │ ├── OkHttpResponse.java │ │ │ │ ├── OkhttpCallback.java │ │ │ │ ├── ProgressRequestWrapper.java │ │ │ │ └── QuotePreservingCookieJar.java │ │ └── native-api-usage.json │ └── ios │ │ └── Podfile │ └── tsconfig.json ├── pnpm-workspace.yaml ├── references.d.ts ├── src └── https │ ├── angular │ ├── excluded.service.ts │ ├── index.ts │ ├── ng-package.json │ ├── ns-http-xhr-backend.ts │ ├── ns-https.module.ts │ ├── package.json │ └── tsconfig.json │ ├── index.ts │ ├── references.d.ts │ ├── request.android.ts │ ├── request.common.ts │ ├── request.d.ts │ ├── request.ios.ts │ └── typings │ ├── android.d.ts │ ├── objc!AFNetworking.d.ts │ └── okhttp3.d.ts ├── svelte.config.js ├── tsconfig.json ├── tsconfig.vue3.json └── yarn.lock /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: './tools/.eslintrc.js' 3 | }; 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [farfromrefug] 2 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: 'release' 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | release_type: 7 | type: choice 8 | default: auto 9 | description: What kind of version upgrade 10 | options: 11 | - auto 12 | - patch 13 | - minor 14 | - major 15 | 16 | jobs: 17 | release: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v4 22 | with: 23 | fetch-depth: "0" 24 | submodules: true 25 | 26 | - name: setup node 27 | uses: actions/setup-node@v4 28 | with: 29 | node-version: lts/* 30 | registry-url: 'https://registry.npmjs.org' 31 | 32 | 33 | - uses: oNaiPs/secrets-to-env-action@v1 34 | with: 35 | secrets: ${{ toJSON(secrets) }} 36 | 37 | 38 | - uses: oleksiyrudenko/gha-git-credentials@v2-latest 39 | with: 40 | token: '${{ secrets.GITHUB_TOKEN }}' 41 | name: Martin Guillon 42 | email: dev@akylas.fr 43 | 44 | - name: install jq 45 | run: sudo apt install jq 46 | 47 | - name: Enable CorePack 48 | run: | 49 | corepack enable 50 | yarn config get globalFolder # the yarn command will ensure the correct yarn version is downloaded and installed 51 | 52 | - name: Get yarn cache directory path 53 | id: yarn-cache-dir-path 54 | run: echo "::set-output name=dir::$(yarn config get globalFolder)" 55 | 56 | - name: Remove package.json resolutions 57 | run: echo "`jq 'delpaths([["resolutions"]])' package.json`" > package.json 58 | 59 | - uses: actions/cache@v4 60 | name: Handle node_modules Cache 61 | id: yarn-node_modules # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) 62 | with: 63 | path: node_modules 64 | key: ${{ runner.os }}-yarn-node_modules-${{ hashFiles('**/yarn.lock') }} 65 | restore-keys: | 66 | ${{ runner.os }}-node_modules- 67 | 68 | - uses: actions/cache@v4 69 | if: steps.yarn-node_modules.outputs.cache-hit != 'true' 70 | name: Handle Yarn cache 71 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) 72 | with: 73 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 74 | key: ${{ runner.os }}-yarn-cache-${{ hashFiles('**/yarn.lock') }} 75 | restore-keys: | 76 | ${{ runner.os }}-yarn- 77 | 78 | - name: Install deps 79 | if: steps.yarn-node_modules.outputs.cache-hit != 'true' 80 | uses: bahmutov/npm-install@v1 81 | with: 82 | install-command: yarn install --silent 83 | env: 84 | YARN_ENABLE_IMMUTABLE_INSTALLS: false 85 | 86 | - name: run setup 87 | run: | 88 | npm run setup 89 | 90 | - name: "NPM Identity" 91 | env: 92 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 93 | run: | 94 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc 95 | 96 | - name: publish auto 97 | if: github.event.inputs.release_type == 'auto' 98 | run: | 99 | npm run publish -- --force-publish --no-verify-access --no-private --no-commit-hooks --yes 100 | env: 101 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 102 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 103 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 104 | 105 | - name: publish 106 | if: github.event.inputs.release_type != 'auto' 107 | run: | 108 | npm run publish -- --force-publish --no-verify-access --no-private --no-commit-hooks --yes --bump ${{ github.event.inputs.release_type }} 109 | env: 110 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 111 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 112 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # NativeScript 2 | hooks/ 3 | node_modules/ 4 | platforms 5 | 6 | # NativeScript Template 7 | *.js.map 8 | !ngcc.config.js 9 | !webpack.config.js 10 | 11 | # Logs 12 | logs 13 | *.log 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | 18 | # General 19 | .DS_Store 20 | .AppleDouble 21 | .LSOverride 22 | .idea 23 | .cloud 24 | .gradle 25 | .project 26 | .yarn 27 | .cxx 28 | tmp/ 29 | 30 | !.eslintrc.js 31 | !.prettierrc.js 32 | 33 | !e2e/*.js 34 | !detox.config.js 35 | devices.js 36 | 37 | *.framework 38 | *.xcframework 39 | **/*.js.map 40 | src/**/*.js 41 | packages/**/*.js 42 | packages/**/*.d.ts 43 | bin 44 | build 45 | Pods 46 | !packages/*/platforms 47 | /packages/**/*.aar 48 | /packages/**/*.framework 49 | /packages/**/*.xcframework 50 | /demo-snippets/**/*.aar 51 | *.xcuserdatad 52 | /packages/README.md 53 | packages/**/*js.map 54 | packages/**/*js 55 | packages/angular 56 | packages/typings 57 | packages/**/angular/*.json 58 | packages/**/*.ngsummary.json 59 | packages/**/*.metadata.json 60 | 61 | .vscode/settings.json 62 | 63 | /blueprint.md -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "demo-vue"] 2 | path = demo-vue 3 | url = https://github.com/nativescript-community/plugin-seed-demo-vue.git 4 | [submodule "tools"] 5 | path = tools 6 | url = https://github.com/nativescript-community/plugin-seed-tools.git 7 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | public-hoist-pattern[]=*eslint* 3 | public-hoist-pattern[]=source-map-support 4 | public-hoist-pattern[]=ts-patch 5 | public-hoist-pattern[]=typescript 6 | public-hoist-pattern[]=cpy-cli 7 | strict-peer-dependencies=false 8 | shell-emulator=true 9 | auto-install-peers=false 10 | loglevel=error 11 | engine-strict=true 12 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | node_modules/ 3 | plugin/ 4 | docs/ 5 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 200, 3 | semi: true, 4 | tabWidth: 4, 5 | trailingComma: 'none', 6 | singleQuote: true 7 | }; 8 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | compressionLevel: mixed 2 | 3 | nmHoistingLimits: workspaces 4 | 5 | nodeLinker: node-modules 6 | 7 | yarnPath: tools/.yarn/releases/yarn-4.0.1.cjs 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | ### clean up typings 3 | 4 | * regexp: ```/export class .*?JNI {(.|[\r\n])*?}//``` 5 | * regexp: ```/export module .*? {([\t\r\n])*?}//``` twice 6 | * regexp: ```/declare module com {([\t\r\n])*?}/``` 7 | 8 | ## ios typings 9 | 10 | run in the demo app 11 | ``` 12 | TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios --bundle 13 | ``` 14 | 15 | ### clean up typings 16 | 17 | * regexp: ```/description\(\): string;//``` 18 | * regexp: ```/hash\(\): number;//``` 19 | * regexp: ```/var:/variant:/``` -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | nativescript-https 4 | Copyright (c) 2016, GetHuman 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | // Use maven repository 4 | repositories { 5 | mavenCentral() 6 | google() 7 | } 8 | dependencies { 9 | implementation 'com.squareup.okhttp3:okhttp:3.14.7' 10 | implementation files('/Volumes/dev/androidSDK/platforms/android-28/android.jar') 11 | } 12 | sourceSets { 13 | main { 14 | java { 15 | srcDirs = ["src/platforms/android/java"] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "readme": true, 3 | "angular": true, 4 | "demos": [ 5 | "vue" 6 | ] 7 | } -------------------------------------------------------------------------------- /demo-snippets/assets/httpbin.org.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nativescript-community/https/341d142a8b7d3527bb5ae02b13ac7708a1c349d2/demo-snippets/assets/httpbin.org.cer -------------------------------------------------------------------------------- /demo-snippets/assets/httpbin.org.expired.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nativescript-community/https/341d142a8b7d3527bb5ae02b13ac7708a1c349d2/demo-snippets/assets/httpbin.org.expired.cer -------------------------------------------------------------------------------- /demo-snippets/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/template-snippet", 3 | "private": true, 4 | "version": "0.0.1", 5 | "dependencies": { 6 | "@nativescript-community/https": "4.0.11" 7 | }, 8 | "nativescript": { 9 | "platforms": { 10 | "android": "2.3.0", 11 | "ios": "2.3.0" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /demo-snippets/vue/Basic.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 206 | 207 | 217 | -------------------------------------------------------------------------------- /demo-snippets/vue/install.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'nativescript-vue'; 2 | import Basic from './Basic.vue'; 3 | import * as Https from '@nativescript-community/https'; 4 | import * as fs from '@nativescript/core/file-system'; 5 | 6 | const folder = fs.knownFolders.temp().getFolder('cache'); 7 | const diskLocation = folder.path; 8 | const cacheSize = 10 * 1024 * 1024; 9 | Https.setCache({ 10 | // forceCache: true, 11 | diskLocation, 12 | diskSize: cacheSize, 13 | memorySize: cacheSize 14 | }); 15 | 16 | export function installPlugin() {} 17 | 18 | export const demos = [{ name: 'Basic', path: 'basic', component: Basic }]; 19 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. -------------------------------------------------------------------------------- /docs/assets/hierarchy.js: -------------------------------------------------------------------------------- 1 | window.hierarchyData = "data:application/octet-stream;base64,H4sIAAAAAAAAA6tWKsrPLylWsoqO1VEqSk3LSU0uyczPK1ayqq6tBQAWeT+5HQAAAA==" -------------------------------------------------------------------------------- /docs/assets/highlight.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --light-hl-0: #795E26; 3 | --dark-hl-0: #DCDCAA; 4 | --light-hl-1: #000000; 5 | --dark-hl-1: #D4D4D4; 6 | --light-hl-2: #A31515; 7 | --dark-hl-2: #CE9178; 8 | --light-hl-3: #AF00DB; 9 | --dark-hl-3: #C586C0; 10 | --light-hl-4: #0000FF; 11 | --dark-hl-4: #569CD6; 12 | --light-hl-5: #001080; 13 | --dark-hl-5: #9CDCFE; 14 | --light-hl-6: #098658; 15 | --dark-hl-6: #B5CEA8; 16 | --light-hl-7: #008000; 17 | --dark-hl-7: #6A9955; 18 | --light-hl-8: #000000; 19 | --dark-hl-8: #C8C8C8; 20 | --light-hl-9: #267F99; 21 | --dark-hl-9: #4EC9B0; 22 | --light-code-background: #FFFFFF; 23 | --dark-code-background: #1E1E1E; 24 | } 25 | 26 | @media (prefers-color-scheme: light) { :root { 27 | --hl-0: var(--light-hl-0); 28 | --hl-1: var(--light-hl-1); 29 | --hl-2: var(--light-hl-2); 30 | --hl-3: var(--light-hl-3); 31 | --hl-4: var(--light-hl-4); 32 | --hl-5: var(--light-hl-5); 33 | --hl-6: var(--light-hl-6); 34 | --hl-7: var(--light-hl-7); 35 | --hl-8: var(--light-hl-8); 36 | --hl-9: var(--light-hl-9); 37 | --code-background: var(--light-code-background); 38 | } } 39 | 40 | @media (prefers-color-scheme: dark) { :root { 41 | --hl-0: var(--dark-hl-0); 42 | --hl-1: var(--dark-hl-1); 43 | --hl-2: var(--dark-hl-2); 44 | --hl-3: var(--dark-hl-3); 45 | --hl-4: var(--dark-hl-4); 46 | --hl-5: var(--dark-hl-5); 47 | --hl-6: var(--dark-hl-6); 48 | --hl-7: var(--dark-hl-7); 49 | --hl-8: var(--dark-hl-8); 50 | --hl-9: var(--dark-hl-9); 51 | --code-background: var(--dark-code-background); 52 | } } 53 | 54 | :root[data-theme='light'] { 55 | --hl-0: var(--light-hl-0); 56 | --hl-1: var(--light-hl-1); 57 | --hl-2: var(--light-hl-2); 58 | --hl-3: var(--light-hl-3); 59 | --hl-4: var(--light-hl-4); 60 | --hl-5: var(--light-hl-5); 61 | --hl-6: var(--light-hl-6); 62 | --hl-7: var(--light-hl-7); 63 | --hl-8: var(--light-hl-8); 64 | --hl-9: var(--light-hl-9); 65 | --code-background: var(--light-code-background); 66 | } 67 | 68 | :root[data-theme='dark'] { 69 | --hl-0: var(--dark-hl-0); 70 | --hl-1: var(--dark-hl-1); 71 | --hl-2: var(--dark-hl-2); 72 | --hl-3: var(--dark-hl-3); 73 | --hl-4: var(--dark-hl-4); 74 | --hl-5: var(--dark-hl-5); 75 | --hl-6: var(--dark-hl-6); 76 | --hl-7: var(--dark-hl-7); 77 | --hl-8: var(--dark-hl-8); 78 | --hl-9: var(--dark-hl-9); 79 | --code-background: var(--dark-code-background); 80 | } 81 | 82 | .hl-0 { color: var(--hl-0); } 83 | .hl-1 { color: var(--hl-1); } 84 | .hl-2 { color: var(--hl-2); } 85 | .hl-3 { color: var(--hl-3); } 86 | .hl-4 { color: var(--hl-4); } 87 | .hl-5 { color: var(--hl-5); } 88 | .hl-6 { color: var(--hl-6); } 89 | .hl-7 { color: var(--hl-7); } 90 | .hl-8 { color: var(--hl-8); } 91 | .hl-9 { color: var(--hl-9); } 92 | pre, code { background: var(--code-background); } 93 | -------------------------------------------------------------------------------- /docs/assets/navigation.js: -------------------------------------------------------------------------------- 1 | window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAA43VXU/CMBQG4P/SayJ+G7nzI0SNESLxynhx2I5Q6drZHlFi/O+GAaOj3SnX79tn3XoKr7+C8IdET9xANsVBSdJoJzqiBJqKnpCa0L5Dhq7rFw6mVCjRETOpc9E7Pjv/69TQHUKONm6sM3Y5Uen6xha3QDAEC0VcCmpJ9Bk/v9BRO7cu7AsNxh+YpblVbW+UOYFIbw/WlUY75MBVY2/qESeQLdLgqpdkR6PHodRa6kny3YMqh1fzOjRK+nulRbkZ5VW0IxxeXhydHXtKtYUMSzL+SM/BShgrdF0/b1onPqORvo2d3Se0SI1BIc+95tZ7/9JZ9Xm6zUaTOj9tUk/Bs1vEsMjAGegM1ZVS67l1MTQoJcHgLu9i0bvchBSCrSYhqtRpkjBmJjH+Xl7OMRaBkHslv8BAuXTLOdpekxgWlBgQddrb7TDcBOlaarCLmFOHPHCjJOroV6pDHuhLFT3xdZRerKHAvjXFi1WM47V48r6ASduGqoxf/jAaPLWsXkb84hHZllOtQwYowTpse34dMoDFwsyxumV5+Ee1tWI9lm29STZ5hxxS64/CJguWv/0D8NmaQ0gJAAA=" -------------------------------------------------------------------------------- /docs/assets/search.js: -------------------------------------------------------------------------------- 1 | window.searchData = "data:application/octet-stream;base64,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"; -------------------------------------------------------------------------------- /docs/functions/addInterceptor.html: -------------------------------------------------------------------------------- 1 | addInterceptor | Nativescript plugin for https requests
  • Parameters

    • interceptor: any

    Returns void

2 | -------------------------------------------------------------------------------- /docs/functions/addNetworkInterceptor.html: -------------------------------------------------------------------------------- 1 | addNetworkInterceptor | Nativescript plugin for https requests
  • Parameters

    • interceptor: any

    Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/cancelAllRequests.html: -------------------------------------------------------------------------------- 1 | cancelAllRequests | Nativescript plugin for https requests
  • Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/cancelRequest.html: -------------------------------------------------------------------------------- 1 | cancelRequest | Nativescript plugin for https requests
  • Parameters

    • tag: string

    Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/clearCache.html: -------------------------------------------------------------------------------- 1 | clearCache | Nativescript plugin for https requests
  • Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/clearCookies.html: -------------------------------------------------------------------------------- 1 | clearCookies | Nativescript plugin for https requests
  • Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/createRequest.html: -------------------------------------------------------------------------------- 1 | createRequest | Nativescript plugin for https requests
2 | -------------------------------------------------------------------------------- /docs/functions/disableSSLPinning.html: -------------------------------------------------------------------------------- 1 | disableSSLPinning | Nativescript plugin for https requests
  • Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/enableSSLPinning.html: -------------------------------------------------------------------------------- 1 | enableSSLPinning | Nativescript plugin for https requests
2 | -------------------------------------------------------------------------------- /docs/functions/getBinary.html: -------------------------------------------------------------------------------- 1 | getBinary | Nativescript plugin for https requests
  • Downloads the content from the specified URL as binary and returns an ArrayBuffer.

    2 |

    Parameters

    • arg: string | HttpsRequestOptions

      either The URL to request from or HttpsRequestOptions options.

      3 |

    Returns Promise<ArrayBuffer>

4 | -------------------------------------------------------------------------------- /docs/functions/getClient.html: -------------------------------------------------------------------------------- 1 | getClient | Nativescript plugin for https requests
2 | -------------------------------------------------------------------------------- /docs/functions/getFile.html: -------------------------------------------------------------------------------- 1 | getFile | Nativescript plugin for https requests
  • Downloads the content from the specified URL and attempts to save it as file.

    2 |

    Parameters

    • arg: string | HttpsRequestOptions

      either The URL to request from or HttpsRequestOptions options.

      3 |
    • OptionaldestinationFilePath: string

      Optional. The downloaded file path.

      4 |

    Returns Promise<any>

5 | -------------------------------------------------------------------------------- /docs/functions/getFilenameFromUrl.html: -------------------------------------------------------------------------------- 1 | getFilenameFromUrl | Nativescript plugin for https requests
  • Parameters

    • url: string

    Returns string

2 | -------------------------------------------------------------------------------- /docs/functions/getImage.html: -------------------------------------------------------------------------------- 1 | getImage | Nativescript plugin for https requests
  • Downloads the content from the specified URL and attempts to decode it as an image.

    2 |

    Parameters

    • arg: string | HttpsRequestOptions

      either The URL to request from or HttpsRequestOptions options.

      3 |

    Returns Promise<ImageSource>

4 | -------------------------------------------------------------------------------- /docs/functions/getJSON.html: -------------------------------------------------------------------------------- 1 | getJSON | Nativescript plugin for https requests
  • Downloads the content from the specified URL as a string and returns its JSON.parse representation.

    2 |

    Type Parameters

    • T

    Parameters

    • arg: string | HttpsRequestOptions

      either The URL to request from or HttpsRequestOptions options.

      3 |

    Returns Promise<T>

4 | -------------------------------------------------------------------------------- /docs/functions/getString.html: -------------------------------------------------------------------------------- 1 | getString | Nativescript plugin for https requests
  • Downloads the content from the specified URL as a string.

    2 |

    Parameters

    • arg: string | HttpsRequestOptions

      either The URL to request from or HttpsRequestOptions options.

      3 |

    Returns Promise<string>

4 | -------------------------------------------------------------------------------- /docs/functions/parseJSON.html: -------------------------------------------------------------------------------- 1 | parseJSON | Nativescript plugin for https requests
  • Parameters

    • source: string

    Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/removeCachedResponse.html: -------------------------------------------------------------------------------- 1 | removeCachedResponse | Nativescript plugin for https requests
  • Parameters

    • url: string

    Returns any

2 | -------------------------------------------------------------------------------- /docs/functions/request.html: -------------------------------------------------------------------------------- 1 | request | Nativescript plugin for https requests
2 | -------------------------------------------------------------------------------- /docs/functions/setCache.html: -------------------------------------------------------------------------------- 1 | setCache | Nativescript plugin for https requests
  • Parameters

    Returns any

2 | -------------------------------------------------------------------------------- /docs/interfaces/Headers.html: -------------------------------------------------------------------------------- 1 | Headers | Nativescript plugin for https requests

Indexable

  • [k: string]: string
2 | -------------------------------------------------------------------------------- /docs/interfaces/HttpsRequestObject.html: -------------------------------------------------------------------------------- 1 | HttpsRequestObject | Nativescript plugin for https requests

Indexable

2 | -------------------------------------------------------------------------------- /docs/media/Basic.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 206 | 207 | 217 | -------------------------------------------------------------------------------- /docs/types/CachePolicy.html: -------------------------------------------------------------------------------- 1 | CachePolicy | Nativescript plugin for https requests
CachePolicy: "noCache" | "onlyCache" | "ignoreCache"
2 | -------------------------------------------------------------------------------- /docs/variables/interceptors.html: -------------------------------------------------------------------------------- 1 | interceptors | Nativescript plugin for https requests
interceptors: any[]
2 | -------------------------------------------------------------------------------- /docs/variables/networkInterceptors.html: -------------------------------------------------------------------------------- 1 | networkInterceptors | Nativescript plugin for https requests
networkInterceptors: any[]
2 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "4.1.19", 3 | "$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json", 4 | "packages": [ 5 | "packages/*" 6 | ], 7 | "npmClient": "yarn", 8 | "useWorkspaces": true, 9 | "command": { 10 | "publish": { 11 | "cleanupTempFiles": true 12 | } 13 | }, 14 | "npmClientArgs": [ 15 | "--no-package-lock" 16 | ], 17 | "commitHooks": false, 18 | "createRelease": "github", 19 | "conventionalCommits": true, 20 | "private": false, 21 | "message": "chore(release): publish new version %v", 22 | "changelogPreset": "conventional-changelog-conventionalcommits", 23 | "ignoreChanges": [ 24 | "**/__fixtures__/**", 25 | "**/__tests__/**", 26 | "**/*.md" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0", 3 | "description": "Nativescript plugin for https requests", 4 | "scripts": { 5 | "tsc": "cp src/index.d.ts src/request.d.ts plugin && tsc -skipLibCheck -d", 6 | "clean": "rimraf 'packages/**/*.d.ts' 'packages/**/*.js' 'packages/**/*.js.map' 'packages/**/*.metada' 'packages/**/angular/ng-package.json'", 7 | "build.plugin": " cp README.md plugin/ && rm -f .tsbuildinfo && npm run tsc", 8 | "build.android": "bash src-native/android/build.sh", 9 | "build.ios": "bash src-native/ios/build.sh", 10 | "build.native": "npm run build.android && npm run build.ios", 11 | "build.angular": "lerna run build.angular", 12 | "build": "lerna run build", 13 | "demo.ios": "npm run build && cd ./demo && tns run ios", 14 | "demo.android": "npm run build && cd ./demo && tns run android", 15 | "plugin.watch.tsc": "npm run tsc -- -w", 16 | "plugin.watch.android": "npm i && npm-watch build.android", 17 | "plugin.watch.ios": "npm i && npm-watch build.ios", 18 | "plugin.watch": "npm run plugin.watch.tsc & npm run plugin.watch.android & npm run plugin.watch.ios", 19 | "publish": "npm run setup && npm run clean && npm run build.all && npm run readme && npm run doc && npm run commit_readme_doc_changes && lerna publish", 20 | "publish.major": "npm run build && lerna publish major --create-release=github --force-publish", 21 | "sync": "node ./tools/sync.js", 22 | "commitmsg": "commitlint -e $GIT_PARAMS", 23 | "build.all": "lerna run build.all", 24 | "fullclean": "npm run clean && rimraf 'packages/**/node_modules' 'demo-*/hooks' 'demo-*/node_modules' 'package-lock.json' 'pnpm-lock.yaml' 'node_modules'", 25 | "demo.vue.android": "cd ./demo-vue && ns run android --no-hmr --env.watchNodeModules", 26 | "demo.vue.clean": "cd ./demo-vue && ns clean", 27 | "demo.vue.ios": "cd ./demo-vue && ns run ios --no-hmr --env.watchNodeModules", 28 | "doc": "node tools/builddoc.mjs", 29 | "postinstall": "npm run setup", 30 | "readme": "lerna run readme && node ./tools/readme.js", 31 | "setup": "npm run submodules && ts-patch install", 32 | "start": "./node_modules/.bin/ntl -A -s 15 -o", 33 | "submodules": "git submodule update --init", 34 | "update": "node ./tools/update.js", 35 | "commit_readme_doc_changes": "git add docs/** *.md ; git commit -m \"readme/doc\" ; echo \"commit readme doc done\"" 36 | }, 37 | "keywords": [ 38 | "secure", 39 | "https", 40 | "http", 41 | "ssl", 42 | "tls", 43 | "pinning", 44 | "nativescript", 45 | "ecosystem:nativescript", 46 | "nativescript-android", 47 | "nativescript-ios", 48 | "JavaScript", 49 | "Android", 50 | "iOS" 51 | ], 52 | "contributors": [ 53 | { 54 | "name": "Eddy Verbruggen", 55 | "email": "eddyverbruggen@gmail.com", 56 | "url": "https://github.com/EddyVerbruggen" 57 | }, 58 | { 59 | "name": "Kefah BADER ALDIN", 60 | "email": "kefah.bader@gmail.com", 61 | "url": "https://github.com/kefahB" 62 | }, 63 | { 64 | "name": "Ruslan Lekhman", 65 | "email": "lekhman112@gmail.com", 66 | "url": "https://github.com/lekhmanrus" 67 | } 68 | ], 69 | "author": { 70 | "name": "Martin Guillon", 71 | "email": "dev@akylas.fr" 72 | }, 73 | "bugs": { 74 | "url": "https://github.com/nativescript-community/https/issues" 75 | }, 76 | "license": "MIT", 77 | "homepage": "https://github.com/nativescript-community/https", 78 | "readmeFilename": "README.md", 79 | "devDependencies": { 80 | "@nativescript-community/plugin-seed-tools": "file:tools", 81 | "@nativescript-community/template-snippet": "file:demo-snippets" 82 | }, 83 | "bootstrapper": "nativescript-plugin-seed", 84 | "commitlint": { 85 | "extends": [ 86 | "@commitlint/config-conventional" 87 | ] 88 | }, 89 | "ntl": { 90 | "descriptions": { 91 | "build": "Build the plugin", 92 | "build.angular": "Build the plugin for Angular", 93 | "build.all": "Build the plugin for all platforms", 94 | "clean": "Clean the local environment.", 95 | "demo.vue.android": "Runs the Vue demo on Android.", 96 | "demo.vue.ios": "Runs the Vue demo on iOS.", 97 | "watch": "Watch for changes in the plugin source and re-build." 98 | } 99 | }, 100 | "workspaces": [ 101 | "packages/*", 102 | "demo*" 103 | ], 104 | "engines": { 105 | "npm": "please use yarn or pnpm", 106 | "yarn": ">=1.19.1", 107 | "pnpm": ">=7.0.0", 108 | "node": "^14.20.0 || ^16.13.0 || >=18.10.0" 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /packages/https/.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | tsconfig.json 3 | node_modules/ 4 | pnpm-global/ 5 | CHANGELOG.md 6 | blueprint.md 7 | *.aar 8 | *.jar -------------------------------------------------------------------------------- /packages/https/angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/https-angular", 3 | "main": "index.js", 4 | "module": "fesm2022/nativescript-community-https-angular.mjs", 5 | "typings": "index.d.ts", 6 | "exports": { 7 | "./package.json": { 8 | "default": "./package.json" 9 | }, 10 | ".": { 11 | "types": "./index.d.ts", 12 | "esm2022": "./esm2022/nativescript-community-https-angular.mjs", 13 | "esm": "./esm2022/nativescript-community-https-angular.mjs", 14 | "default": "./fesm2022/nativescript-community-https-angular.mjs" 15 | } 16 | }, 17 | "sideEffects": false, 18 | "dependencies": { 19 | "tslib": "^2.3.0" 20 | }, 21 | "scripts": { 22 | "prepublishOnly": "node --eval \"console.error('ERROR: Trying to publish a package that has been compiled by Ivy in full compilation mode. This is not allowed.\\nPlease delete and rebuild the package with Ivy partial compilation mode, before attempting to publish.\\n')\" && exit 1" 23 | } 24 | } -------------------------------------------------------------------------------- /packages/https/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/https", 3 | "version": "4.1.19", 4 | "description": "Nativescript plugin for https requests", 5 | "main": "index", 6 | "funding": "https://github.com/sponsors/farfromrefug", 7 | "sideEffects": false, 8 | "typings": "index.d.ts", 9 | "nativescript": { 10 | "platforms": { 11 | "android": "6.2.1", 12 | "ios": "6.2.1" 13 | } 14 | }, 15 | "scripts": { 16 | "tsc": "cpy '**/*.d.ts' '../../packages/https' --parents --cwd=../../src/https && tsc -d", 17 | "readme": "readme generate -c ../../tools/readme/blueprint.json", 18 | "build": "npm run tsc", 19 | "build.watch": "npm run tsc -- -w", 20 | "build.win": "npm run tsc-win", 21 | "build.all": "npm run build && npm run build.angular", 22 | "build.angular": "ng-packagr -p ../../src/https/angular/ng-package.json -c ../../src/https/angular/tsconfig.json && rm angular/.npmignore", 23 | "build.all.win": "npm run build.win", 24 | "clean": "rimraf ./*.d.ts ./*.js ./*.js.map" 25 | }, 26 | "contributors": [ 27 | { 28 | "name": "Eddy Verbruggen", 29 | "email": "eddyverbruggen@gmail.com", 30 | "url": "https://github.com/EddyVerbruggen" 31 | }, 32 | { 33 | "name": "Kefah BADER ALDIN", 34 | "email": "kefah.bader@gmail.com", 35 | "url": "https://github.com/kefahB" 36 | }, 37 | { 38 | "name": "Ruslan Lekhman", 39 | "email": "lekhman112@gmail.com", 40 | "url": "https://github.com/lekhmanrus" 41 | } 42 | ], 43 | "author": { 44 | "name": "Martin Guillon", 45 | "email": "dev@akylas.fr" 46 | }, 47 | "bugs": { 48 | "url": "https://github.com/nativescript-community/https/issues" 49 | }, 50 | "license": "MIT", 51 | "homepage": "https://github.com/nativescript-community/https", 52 | "readmeFilename": "README.md", 53 | "bootstrapper": "nativescript-plugin-seed", 54 | "keywords": [ 55 | "secure", 56 | "https", 57 | "http", 58 | "ssl", 59 | "tls", 60 | "pinning", 61 | "nativescript", 62 | "ecosystem:nativescript", 63 | "nativescript-android", 64 | "nativescript-ios", 65 | "JavaScript", 66 | "Android", 67 | "iOS" 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /packages/https/platforms/android/include.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | def okHttpVersion = project.hasProperty("okHttpVersion") ? project.okHttpVersion : "4.12.0" 3 | implementation "com.squareup.okhttp3:okhttp:$okHttpVersion" 4 | // def conscryptVersion = project.hasProperty("conscryptVersion") ? project.conscryptVersion : "2.4.0" 5 | // implementation "org.conscrypt:conscrypt-android:$conscryptVersion" 6 | } 7 | -------------------------------------------------------------------------------- /packages/https/platforms/android/java/com/nativescript/https/CacheInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.nativescript.https; 2 | import okhttp3.Interceptor; 3 | import okhttp3.Request; 4 | import okhttp3.Response; 5 | import java.io.IOException; 6 | 7 | 8 | public class CacheInterceptor { 9 | public static final Interceptor INTERCEPTOR = chain -> { 10 | Request originalRequest = chain.request(); 11 | String cacheControlHeader = originalRequest.header("Cache-Control"); 12 | Response originalResponse = chain.proceed(originalRequest); 13 | if (cacheControlHeader != null) { 14 | return originalResponse.newBuilder().header("Cache-Control", cacheControlHeader).removeHeader("Pragma").build(); 15 | } else { 16 | return originalResponse; 17 | } 18 | }; 19 | } -------------------------------------------------------------------------------- /packages/https/platforms/android/java/com/nativescript/https/CacheUtils.java: -------------------------------------------------------------------------------- 1 | package com.nativescript.https; 2 | 3 | import java.util.Iterator; 4 | import okhttp3.Cache; 5 | 6 | public class CacheUtils { 7 | public static void removeCachedResponse(String url, Cache cache) { 8 | Iterator it; 9 | try { 10 | it = cache.urls(); 11 | } catch (Exception e) { 12 | it = null; 13 | } 14 | 15 | if (it != null) { 16 | while (it.hasNext()) { 17 | String cacheUrl = it.next(); 18 | 19 | if (cacheUrl.equals(url)) { 20 | it.remove(); 21 | break; 22 | } 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/https/platforms/android/java/com/nativescript/https/OkhttpCallback.java: -------------------------------------------------------------------------------- 1 | package com.nativescript.https; 2 | import okhttp3.Callback; 3 | 4 | public class OkhttpCallback implements Callback { 5 | final String TAG = "OkhttpCallback"; 6 | public void onStringResponse(String responseString, int statusCode, okhttp3.Headers headers) {} 7 | public void onResponse(okhttp3.Call call, okhttp3.Response response ) throws java.io.IOException { 8 | String responseString = null; 9 | okhttp3.ResponseBody responseBody = response.body(); 10 | responseString = responseBody.string(); 11 | responseBody.close(); 12 | onStringResponse(responseString, response.code(), response.headers()); 13 | } 14 | public void onFailure(okhttp3.Call call, java.io.IOException e) {} 15 | 16 | 17 | } -------------------------------------------------------------------------------- /packages/https/platforms/android/java/com/nativescript/https/ProgressRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.nativescript.https; 2 | 3 | import okhttp3.RequestBody; 4 | import okhttp3.MediaType; 5 | 6 | import java.io.IOException; 7 | 8 | import okio.Buffer; 9 | import okio.BufferedSink; 10 | import okio.ForwardingSink; 11 | import okio.Okio; 12 | import okio.Sink; 13 | 14 | public class ProgressRequestWrapper extends RequestBody { 15 | 16 | protected RequestBody delegate; 17 | protected ProgressListener listener; 18 | 19 | protected CountingSink countingSink; 20 | 21 | public ProgressRequestWrapper(RequestBody delegate, ProgressListener listener) { 22 | this.delegate = delegate; 23 | this.listener = listener; 24 | } 25 | 26 | @Override 27 | public MediaType contentType() { 28 | return delegate.contentType(); 29 | } 30 | 31 | @Override 32 | public long contentLength() throws IOException { 33 | return delegate.contentLength(); 34 | } 35 | 36 | @Override 37 | public void writeTo(BufferedSink sink) throws IOException { 38 | 39 | BufferedSink bufferedSink; 40 | 41 | countingSink = new CountingSink(sink); 42 | bufferedSink = Okio.buffer(countingSink); 43 | 44 | delegate.writeTo(bufferedSink); 45 | 46 | bufferedSink.flush(); 47 | } 48 | 49 | protected final class CountingSink extends ForwardingSink { 50 | 51 | private long bytesWritten = 0; 52 | 53 | public CountingSink(Sink delegate) { 54 | super(delegate); 55 | } 56 | 57 | @Override 58 | public void write(Buffer source, long byteCount) throws IOException { 59 | 60 | super.write(source, byteCount); 61 | 62 | bytesWritten += byteCount; 63 | listener.onRequestProgress(bytesWritten, contentLength()); 64 | } 65 | 66 | } 67 | 68 | public interface ProgressListener { 69 | 70 | void onRequestProgress(long bytesWritten, long contentLength); 71 | 72 | } 73 | } -------------------------------------------------------------------------------- /packages/https/platforms/android/java/com/nativescript/https/QuotePreservingCookieJar.java: -------------------------------------------------------------------------------- 1 | package com.nativescript.https; 2 | /* 3 | * Copyright (C) 2016 Square, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import java.io.IOException; 19 | import java.net.CookieHandler; 20 | import java.net.HttpCookie; 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.List; 24 | import java.util.Map; 25 | import okhttp3.Cookie; 26 | import okhttp3.CookieJar; 27 | import okhttp3.HttpUrl; 28 | import okhttp3.internal.platform.Platform; 29 | 30 | import static okhttp3.internal.platform.Platform.WARN; 31 | 32 | /** A cookie jar that delegates to a {@link java.net.CookieHandler}. */ 33 | public final class QuotePreservingCookieJar implements CookieJar { 34 | private final CookieHandler cookieHandler; 35 | 36 | public QuotePreservingCookieJar(CookieHandler cookieHandler) { 37 | this.cookieHandler = cookieHandler; 38 | } 39 | 40 | @Override public void saveFromResponse(HttpUrl url, List cookies) { 41 | if (cookieHandler != null) { 42 | List cookieStrings = new ArrayList<>(); 43 | for (Cookie cookie : cookies) { 44 | cookieStrings.add(cookie.toString().replaceAll("; domain=", "; domain=.")); 45 | } 46 | Map> multimap = Collections.singletonMap("Set-Cookie", cookieStrings); 47 | try { 48 | cookieHandler.put(url.uri(), multimap); 49 | } catch (IOException e) { 50 | // Platform.get().log(WARN, "Saving cookies failed for " + url.resolve("/..."), e); 51 | } 52 | } 53 | } 54 | 55 | @Override public List loadForRequest(HttpUrl url) { 56 | // The RI passes all headers. We don't have 'em, so we don't pass 'em! 57 | Map> headers = Collections.emptyMap(); 58 | Map> cookieHeaders; 59 | try { 60 | cookieHeaders = cookieHandler.get(url.uri(), headers); 61 | } catch (IOException e) { 62 | // Platform.get().log(WARN, "Loading cookies failed for " + url.resolve("/..."), e); 63 | return Collections.emptyList(); 64 | } 65 | 66 | List cookies = null; 67 | for (Map.Entry> entry : cookieHeaders.entrySet()) { 68 | String key = entry.getKey(); 69 | if (("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key)) 70 | && !entry.getValue().isEmpty()) { 71 | for (String header : entry.getValue()) { 72 | if (cookies == null) cookies = new ArrayList<>(); 73 | cookies.addAll(decodeHeaderAsJavaNetCookies(url, header)); 74 | } 75 | } 76 | } 77 | 78 | return cookies != null 79 | ? Collections.unmodifiableList(cookies) 80 | : Collections.emptyList(); 81 | } 82 | 83 | /** 84 | * Increments {@code pos} until {@code input[pos]} is not ASCII whitespace. Stops at {@code 85 | * limit}. 86 | */ 87 | public static int skipLeadingAsciiWhitespace(String input, int pos, int limit) { 88 | for (int i = pos; i < limit; i++) { 89 | switch (input.charAt(i)) { 90 | case '\t': 91 | case '\n': 92 | case '\f': 93 | case '\r': 94 | case ' ': 95 | continue; 96 | default: 97 | return i; 98 | } 99 | } 100 | return limit; 101 | } 102 | 103 | /** 104 | * Decrements {@code limit} until {@code input[limit - 1]} is not ASCII whitespace. Stops at 105 | * {@code pos}. 106 | */ 107 | public static int skipTrailingAsciiWhitespace(String input, int pos, int limit) { 108 | for (int i = limit - 1; i >= pos; i--) { 109 | switch (input.charAt(i)) { 110 | case '\t': 111 | case '\n': 112 | case '\f': 113 | case '\r': 114 | case ' ': 115 | continue; 116 | default: 117 | return i + 1; 118 | } 119 | } 120 | return pos; 121 | } 122 | 123 | /** Equivalent to {@code string.substring(pos, limit).trim()}. */ 124 | public static String trimSubstring(String string, int pos, int limit) { 125 | int start = skipLeadingAsciiWhitespace(string, pos, limit); 126 | int end = skipTrailingAsciiWhitespace(string, start, limit); 127 | return string.substring(start, end); 128 | } 129 | 130 | /** 131 | * Returns the index of the first character in {@code input} that contains a character in {@code 132 | * delimiters}. Returns limit if there is no such character. 133 | */ 134 | public static int delimiterOffset(String input, int pos, int limit, String delimiters) { 135 | for (int i = pos; i < limit; i++) { 136 | if (delimiters.indexOf(input.charAt(i)) != -1) return i; 137 | } 138 | return limit; 139 | } 140 | 141 | /** 142 | * Convert a request header to OkHttp's cookies via {@link HttpCookie}. That extra step handles 143 | * multiple cookies in a single request header, which {@link Cookie#parse} doesn't support. 144 | */ 145 | private List decodeHeaderAsJavaNetCookies(HttpUrl url, String header) { 146 | List result = new ArrayList<>(); 147 | for (int pos = 0, limit = header.length(), pairEnd; pos < limit; pos = pairEnd + 1) { 148 | pairEnd = delimiterOffset(header, pos, limit, ";,"); 149 | int equalsSign = delimiterOffset(header, pos, pairEnd, "="); 150 | String name = trimSubstring(header, pos, equalsSign); 151 | if (name.startsWith("$")) continue; 152 | 153 | // We have either name=value or just a name. 154 | String value = equalsSign < pairEnd 155 | ? trimSubstring(header, equalsSign + 1, pairEnd) 156 | : ""; 157 | 158 | result.add(new Cookie.Builder() 159 | .name(name) 160 | .value(value) 161 | .domain(url.host()) 162 | .build()); 163 | } 164 | return result; 165 | } 166 | } -------------------------------------------------------------------------------- /packages/https/platforms/android/native-api-usage.json: -------------------------------------------------------------------------------- 1 | { 2 | "uses": [ 3 | "android.os:StrictMode", 4 | "android.os:StrictMode.ThreadPolicy", 5 | "okhttp3:Call", 6 | "okhttp3:Dispatcher", 7 | "okhttp3:RequestBody", 8 | "okhttp3:MediaType", 9 | "okhttp3:MultipartBody", 10 | "okhttp3:Response", 11 | "okhttp3:ResponseBody", 12 | "okhttp3:Headers", 13 | "okhttp3:MultipartBody.Builder", 14 | "okhttp3:CacheControl", 15 | "okhttp3:CacheControl.Builder", 16 | "okhttp3:Request", 17 | "okhttp3:Request.Builder", 18 | "okhttp3:Interceptor", 19 | "okhttp3:OkHttpClient", 20 | "okhttp3:OkHttpClient.Builder", 21 | "okhttp3:CertificatePinner", 22 | "okhttp3:CertificatePinner.Builder", 23 | "okhttp3:ConnectionSpec", 24 | "okhttp3:Cache", 25 | "okhttp3:Callback", 26 | "okhttp3:FormBody", 27 | "okhttp3:FormBody.Builder", 28 | "okhttp3:CookieJar", 29 | "java.net:CookieManager", 30 | "java.net:CookiePolicy", 31 | "com.nativescript.https:QuotePreservingCookieJar", 32 | "com.nativescript.https:CacheInterceptor", 33 | "com.nativescript.https:CacheUtils", 34 | "com.nativescript.https:OkHttpResponse", 35 | "java.util:Collections", 36 | "java.security.cert:CertificateFactory", 37 | "java.security:KeyStore", 38 | "java.security:Security", 39 | "javax.net.ssl:TrustManagerFactory", 40 | "javax.net.ssl:SSLContext", 41 | "javax.net.ssl:HttpsURLConnection", 42 | "java.net:UnknownHostException", 43 | "java.util.concurrent:TimeUnit", 44 | "org.conscrypt:Conscrypt" 45 | ] 46 | } -------------------------------------------------------------------------------- /packages/https/platforms/ios/Podfile: -------------------------------------------------------------------------------- 1 | pod 'AFNetworking', :git => 'https://github.com/nativescript-community/AFNetworking' 2 | -------------------------------------------------------------------------------- /packages/https/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "../../src/https", 5 | "outDir": "./" 6 | }, 7 | "include": ["../../src/https/**/*", "../../references.d.ts", "../../tools/references.d.ts", "../../src/references.d.ts"], 8 | "exclude": ["../../src/https/angular/**"] 9 | } 10 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - packages/* 3 | - demo-* -------------------------------------------------------------------------------- /references.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nativescript-community/https/341d142a8b7d3527bb5ae02b13ac7708a1c349d2/references.d.ts -------------------------------------------------------------------------------- /src/https/angular/excluded.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpRequest } from '@angular/common/http'; 3 | 4 | @Injectable() 5 | export class ExcludedService { 6 | private readonly _urlList: string[] = []; 7 | 8 | public static isMultipartFormRequest(request: HttpRequest): boolean { 9 | const headers = request.headers.get('Content-Type'); 10 | return headers ? headers.includes('application/x-www-form-urlencoded') : false; 11 | } 12 | 13 | public addUrl(domain: string): void { 14 | this._urlList.push(domain); 15 | } 16 | 17 | public contains(needle: string): boolean { 18 | return Boolean(this._urlList.filter((url) => url === needle).length); 19 | } 20 | 21 | public skipSslPinning(request: HttpRequest): boolean { 22 | return this.contains(request.url); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/https/angular/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ns-https.module'; 2 | export * from './ns-http-xhr-backend'; 3 | -------------------------------------------------------------------------------- /src/https/angular/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dest": "../../../packages/https/angular", 3 | "lib": { 4 | "entryFile": "index.ts" 5 | }, 6 | "allowedNonPeerDependencies": [ 7 | "." 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /src/https/angular/ns-http-xhr-backend.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, InjectionToken, Optional } from '@angular/core'; 2 | import { XhrFactory } from '@angular/common'; 3 | import { HttpErrorResponse, HttpEvent, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http'; 4 | import { Observable, from, throwError } from 'rxjs'; 5 | import { catchError, map } from 'rxjs/operators'; 6 | import { NSFileSystem, NsHttpBackEnd } from '@nativescript/angular'; 7 | import { Headers, HttpsRequestObject, HttpsRequestOptions, HttpsResponse, request as httpsRequest } from '@nativescript-community/https'; 8 | import { ExcludedService } from './excluded.service'; 9 | 10 | /** Https request default options. */ 11 | export type HttpsRequestDefaultOptions = Pick & { useLegacy?: boolean }; 12 | 13 | /** Page size injection token. */ 14 | export const HTTPS_REQUEST_DEFAULT_OPTIONS = new InjectionToken('HTTPS_REQUEST_DEFAULT_OPTIONS'); 15 | 16 | @Injectable() 17 | export class NativeScriptHttpXhrBackend extends NsHttpBackEnd { 18 | constructor( 19 | xhrFactory: XhrFactory, 20 | nsFileSystem: NSFileSystem, 21 | private readonly _excludedService: ExcludedService, 22 | @Optional() 23 | @Inject(HTTPS_REQUEST_DEFAULT_OPTIONS) 24 | private readonly _defaults?: HttpsRequestDefaultOptions 25 | ) { 26 | super(xhrFactory, nsFileSystem); 27 | } 28 | 29 | public handle(req: HttpRequest): Observable> { 30 | let result: Observable>; 31 | if (this._isLocalRequest(req.url) || this._excludedService.skipSslPinning(req)) { 32 | result = super.handle(req); 33 | } else { 34 | result = this._request(req).pipe( 35 | map((response: HttpsResponse) => { 36 | if (response.statusCode < 200 || response.statusCode > 299) { 37 | throw this._mapHttpErrorResponse(response, req); 38 | } 39 | return new HttpResponse({ 40 | body: response.content, 41 | headers: new HttpHeaders(response.headers), 42 | status: response.statusCode, 43 | statusText: response.reason, 44 | url: req.url 45 | }); 46 | }), 47 | catchError((error) => throwError(() => error)) 48 | ); 49 | } 50 | 51 | return result; 52 | } 53 | 54 | private _isLocalRequest(url: string): boolean { 55 | return url.indexOf('~') === 0 || url.indexOf('/') === 0; 56 | } 57 | 58 | private _request(request: HttpRequest) { 59 | const method = request.method as 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD'; 60 | let url = request.url; 61 | if (request.params) { 62 | const params = request.params.toString(); 63 | if (params.length) { 64 | const qIdx = url.indexOf('?'); 65 | const sep = qIdx === -1 ? '?' : (qIdx < url.length - 1 ? '&' : ''); 66 | url += sep + params; 67 | } 68 | } 69 | return from( 70 | httpsRequest( 71 | { 72 | url, 73 | method, 74 | headers: this._mapHeaders(request), 75 | params: this._mapParams(request), 76 | body: request.body, 77 | timeout: this._defaults?.timeout ?? 3 * 60, 78 | allowLargeResponse: this._defaults?.allowLargeResponse ?? true, 79 | cachePolicy: this._defaults?.cachePolicy ?? 'noCache', 80 | cookiesEnabled: this._defaults?.cookiesEnabled ?? false 81 | }, 82 | this._defaults?.useLegacy ?? true 83 | ) 84 | ); 85 | } 86 | 87 | private _mapHeaders(request: HttpRequest): Headers { 88 | const headerKeys = request.headers.keys(); 89 | const headers = headerKeys.reduce((accumulator, key) => { 90 | const values = request.headers.getAll(key); 91 | if (values !== null && values !== undefined) { 92 | accumulator[key] = values.length > 1 ? values.join(' ') : values[0]; 93 | } 94 | return accumulator; 95 | }, {}); 96 | 97 | if (Object.keys(headers).length) { 98 | return headers; 99 | } 100 | 101 | return { 102 | 'Content-Type': 'application/json', 103 | Accept: 'application/json' 104 | }; 105 | } 106 | 107 | private _mapParams(request: HttpRequest): HttpsRequestObject { 108 | const paramKeys = request.params.keys(); 109 | const params = paramKeys.reduce((accumulator, key) => { 110 | const values = request.params.getAll(key); 111 | if (values !== null && values !== undefined) { 112 | accumulator[key] = values.length > 1 ? values : values[0]; 113 | } 114 | return accumulator; 115 | }, {}); 116 | return params; 117 | } 118 | 119 | private _mapHttpErrorResponse(error: HttpsResponse, request: HttpRequest): HttpErrorResponse { 120 | return new HttpErrorResponse({ 121 | error: error.content, 122 | status: error.statusCode, 123 | headers: new HttpHeaders(error.headers), 124 | statusText: error.reason || (typeof error.content === 'string' && error.content) || String(error.statusCode), 125 | url: request.url 126 | }); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/https/angular/ns-https.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders, Optional, Inject, InjectionToken } from '@angular/core'; 2 | import { HttpBackend } from '@angular/common/http'; 3 | import { NativeScriptHttpClientModule } from '@nativescript/angular'; 4 | import { HttpsSSLPinningOptions, enableSSLPinning } from '@nativescript-community/https'; 5 | import { HTTPS_REQUEST_DEFAULT_OPTIONS, NativeScriptHttpXhrBackend, HttpsRequestDefaultOptions } from './ns-http-xhr-backend'; 6 | import { ExcludedService } from './excluded.service'; 7 | 8 | /** Page size injection token. */ 9 | export const HTTPS_SSL_PINNING_OPTIONS = new InjectionToken('HTTPS_SSL_PINNING_OPTIONS'); 10 | 11 | @NgModule({ 12 | providers: [ 13 | ExcludedService, 14 | NativeScriptHttpXhrBackend, 15 | { provide: HttpBackend, useExisting: NativeScriptHttpXhrBackend }, 16 | { provide: HTTPS_REQUEST_DEFAULT_OPTIONS, useValue: {} }, 17 | { provide: HTTPS_SSL_PINNING_OPTIONS, useValue: { host: '', certificate: '' } } 18 | ], 19 | imports: [NativeScriptHttpClientModule], 20 | exports: [NativeScriptHttpClientModule] 21 | }) 22 | export class NativeScriptHttpsModule { 23 | constructor(@Optional()@Inject(HTTPS_SSL_PINNING_OPTIONS) defaults?: HttpsSSLPinningOptions) { 24 | enableSSLPinning(defaults ?? { host: '', certificate: '' }); 25 | } 26 | /** 27 | * Creates and configures a module. 28 | * @param defaults Https request default options. 29 | * @returns A wrapper around an NgModule that associates it with the providers. 30 | */ 31 | static forRoot(defaults: HttpsRequestDefaultOptions & HttpsSSLPinningOptions = { host: '', certificate: '' }): ModuleWithProviders { 32 | return { 33 | ngModule: NativeScriptHttpsModule, 34 | providers: [ 35 | { provide: HTTPS_REQUEST_DEFAULT_OPTIONS, useValue: defaults }, 36 | { provide: HTTPS_SSL_PINNING_OPTIONS, useValue: defaults } 37 | ] 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/https/angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/https-angular", 3 | "main": "index.js" 4 | } 5 | -------------------------------------------------------------------------------- /src/https/angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "./", 5 | "plugins": [], 6 | "paths": { 7 | "@nativescript-community/https": ["../../../packages/https"], 8 | "@nativescript-community/https/*": ["../../../packages/https/*"] 9 | } 10 | }, 11 | "include": ["./**/*.ts", "../../../references.d.ts", "../references.d.ts"], 12 | "exclude": ["../../../node_modules"], 13 | "angularCompilerOptions": { 14 | "enableIvy": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/https/index.ts: -------------------------------------------------------------------------------- 1 | import { ImageSource } from '@nativescript/core'; 2 | import type { HttpsRequestOptions } from './request'; 3 | // eslint-disable-next-line no-duplicate-imports 4 | import { request } from './request'; 5 | export * from './request'; 6 | 7 | /** 8 | * Downloads the content from the specified URL as a string. 9 | * @param arg either The URL to request from or HttpsRequestOptions options. 10 | */ 11 | export async function getString(arg: string | HttpsRequestOptions): Promise { 12 | const r = await request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg); 13 | return r.content.toStringAsync(); 14 | } 15 | 16 | /** 17 | * Downloads the content from the specified URL as a string and returns its JSON.parse representation. 18 | * @param arg either The URL to request from or HttpsRequestOptions options. 19 | */ 20 | export async function getJSON(arg: string | HttpsRequestOptions): Promise { 21 | const r = await request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg); 22 | return r.content.toJSONAsync(); 23 | } 24 | 25 | /** 26 | * Downloads the content from the specified URL and attempts to decode it as an image. 27 | * @param arg either The URL to request from or HttpsRequestOptions options. 28 | */ 29 | export async function getImage(arg: string | HttpsRequestOptions): Promise { 30 | const r = await request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg); 31 | return r.content.toImage(); 32 | } 33 | 34 | /** 35 | * Downloads the content from the specified URL and attempts to save it as file. 36 | * @param arg either The URL to request from or HttpsRequestOptions options. 37 | * @param destinationFilePath Optional. The downloaded file path. 38 | */ 39 | export async function getFile(arg: string | HttpsRequestOptions, destinationFilePath?: string): Promise { 40 | const r = await request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg); 41 | return r.content.toFile(destinationFilePath); 42 | } 43 | 44 | /** 45 | * Downloads the content from the specified URL as binary and returns an ArrayBuffer. 46 | * @param arg either The URL to request from or HttpsRequestOptions options. 47 | */ 48 | export async function getBinary(arg: string | HttpsRequestOptions): Promise { 49 | const r = await request(typeof arg === 'string' ? { url: arg, method: 'GET' } : arg); 50 | return r.content.toArrayBuffer(); 51 | } 52 | -------------------------------------------------------------------------------- /src/https/references.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | -------------------------------------------------------------------------------- /src/https/request.common.ts: -------------------------------------------------------------------------------- 1 | import { knownFolders, path } from '@nativescript/core'; 2 | 3 | export function getFilenameFromUrl(url: string) { 4 | const slashPos = url.lastIndexOf('/') + 1; 5 | const questionMarkPos = url.lastIndexOf('?'); 6 | 7 | let actualFileName: string; 8 | if (questionMarkPos !== -1) { 9 | actualFileName = url.substring(slashPos, questionMarkPos); 10 | } else { 11 | actualFileName = url.substring(slashPos); 12 | } 13 | 14 | const result = path.join(knownFolders.documents().path, actualFileName); 15 | 16 | return result; 17 | } 18 | 19 | export function parseJSON(source: string): any { 20 | const src = source.trim(); 21 | if (src.lastIndexOf(')') === src.length - 1) { 22 | return JSON.parse(src.substring(src.indexOf('(') + 1, src.lastIndexOf(')'))); 23 | } 24 | 25 | return JSON.parse(src); 26 | } 27 | 28 | export const interceptors = []; 29 | 30 | export function addInterceptor(interceptor) { 31 | interceptors.push(interceptor); 32 | } 33 | 34 | export const networkInterceptors = []; 35 | 36 | export function addNetworkInterceptor(interceptor) { 37 | networkInterceptors.push(interceptor); 38 | } 39 | -------------------------------------------------------------------------------- /src/https/request.d.ts: -------------------------------------------------------------------------------- 1 | import { File, HttpRequestOptions, ImageSource } from '@nativescript/core'; 2 | import * as Https from './request.common'; 3 | 4 | export interface HttpsSSLPinningOptions { 5 | host: string; 6 | certificate: string; 7 | allowInvalidCertificates?: boolean; 8 | validatesDomainName?: boolean; 9 | commonName?: string; 10 | } 11 | export interface CacheOptions { 12 | diskLocation: string; 13 | diskSize: number; 14 | memorySize?: number; 15 | forceCache?: boolean; 16 | } 17 | 18 | export interface HttpsFormDataParam { 19 | data: any; 20 | parameterName: string; 21 | fileName?: string; 22 | contentType?: string; 23 | } 24 | 25 | export interface HttpsRequestObject { 26 | [key: string]: string | number | boolean | HttpsRequestObject | any[] | HttpsFormDataParam; 27 | } 28 | 29 | export interface Headers { 30 | [k: string]: string; 31 | } 32 | 33 | export type CachePolicy = 'noCache' | 'onlyCache' | 'ignoreCache'; 34 | export interface HttpsRequestOptions extends HttpRequestOptions { 35 | url: string; 36 | tag?: string; // optional request tag to allow to cancel it 37 | method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; 38 | headers?: Headers; 39 | params?: HttpsRequestObject; 40 | body?: HttpsRequestObject | HttpsFormDataParam[] | File; 41 | /** 42 | * content can be used to pass native custom okhttp3.RequestBody 43 | */ 44 | content?: string | any; 45 | /** 46 | * Default 10 (seconds). 47 | */ 48 | timeout?: number; 49 | 50 | /** 51 | * On Android large responses may crash the app (fi. https://httpbin.org/bytes/10000). 52 | * By setting this to true and when not using useLegacy, we allow large responses on the main thread (which this plugin currently does). 53 | * Note that once set to true, this policy remains active until the app is killed. 54 | */ 55 | allowLargeResponse?: boolean; 56 | 57 | /** 58 | * iOS for now 59 | */ 60 | onProgress?: (current: number, total: number) => void; 61 | 62 | /** 63 | * default to true. Put to false to run response callback on current thread 64 | */ 65 | responseOnMainThread?: boolean; 66 | 67 | cachePolicy?: CachePolicy; 68 | 69 | /** 70 | * default to true. Android and iOS only store cookies in memory! it will be cleared after an app restart 71 | */ 72 | cookiesEnabled?: boolean; 73 | } 74 | 75 | export interface HttpsResponse { 76 | headers?: Headers; 77 | statusCode?: number; 78 | contentLength: number; 79 | content?: T; 80 | response?: string; 81 | reason?: string; 82 | description?: string; 83 | url?: string; 84 | failure?: any; 85 | } 86 | 87 | export interface HttpsRequest { 88 | nativeRequest; 89 | cancel(); 90 | run(success, failure); 91 | } 92 | 93 | export interface HttpsResponseLegacy { 94 | contentLength: number; 95 | toArrayBuffer(): ArrayBuffer; 96 | toArrayBufferAsync(): Promise; 97 | 98 | toString(): string; 99 | toStringAsync(): Promise; 100 | toJSON(): T; 101 | toJSONAsync(): Promise; 102 | toImage(): Promise; 103 | // toImageAsync(): Promise; 104 | toFile(destinationFilePath: string): Promise; 105 | // toFileAsync(destinationFilePath: string): Promise; 106 | } 107 | 108 | export function enableSSLPinning(options: HttpsSSLPinningOptions); 109 | 110 | export function disableSSLPinning(); 111 | 112 | // export declare function request(options: HttpsRequestOptions): Promise>>; 113 | export declare function request( 114 | options: HttpsRequestOptions, 115 | useLegacy?: U 116 | ): U extends true ? Promise>> : Promise>; 117 | export function setCache(options?: CacheOptions); 118 | export function clearCache(); 119 | export function removeCachedResponse(url: string); 120 | export function createRequest(opts: HttpsRequestOptions): HttpsRequest; 121 | export function cancelRequest(tag: string); 122 | export function cancelAllRequests(); 123 | export function clearCookies(); 124 | export function addNetworkInterceptor(interceptor); 125 | 126 | export function getClient(opts: Partial); 127 | export * from './request.common'; 128 | -------------------------------------------------------------------------------- /src/https/typings/android.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace com { 2 | export namespace nativescript { 3 | export namespace https { 4 | export class QuotePreservingCookieJar extends okhttp3.CookieJar { 5 | constructor(manager: java.net.CookieManager); 6 | } 7 | export class CacheInterceptor { 8 | public static INTERCEPTOR: okhttp3.Interceptor; 9 | } 10 | export class CacheUtils { 11 | static removeCachedResponse(url: string, cache: okhttp3.Cache): void; 12 | } 13 | export class OkHttpResponse { 14 | progressCallback: OkHttpResponse.OkHttpResponseProgressCallback; 15 | closeCallback: OkHttpResponse.OkHttpResponseCloseCallback; 16 | runOnMainThread: boolean; 17 | constructor(body: okhttp3.ResponseBody); 18 | contentLength(): number; 19 | cancel(); 20 | toByteArray(); 21 | toByteArrayAsync(callback: OkHttpResponse.OkHttpResponseAsyncCallback); 22 | asString(); 23 | asStringAsync(callback: OkHttpResponse.OkHttpResponseAsyncCallback); 24 | toImage(); 25 | toImageAsync(callback: OkHttpResponse.OkHttpResponseAsyncCallback); 26 | toFile(); 27 | toFileAsync(filePath: string, callback: OkHttpResponse.OkHttpResponseAsyncCallback); 28 | 29 | static getBody(response: okhttp3.Response): okhttp3.ResponseBody; 30 | static getStatusCode(response: okhttp3.Response): number; 31 | static getMessage(response: okhttp3.Response): string; 32 | static getHeaders(response: okhttp3.Response): string; 33 | } 34 | export class ProgressRequestWrapper extends okhttp3.RequestBody { 35 | constructor(body: okhttp3.RequestBody, listener: ProgressRequestWrapper.ProgressListener); 36 | } 37 | export namespace ProgressRequestWrapper { 38 | export class ProgressListener { 39 | constructor(impl: { onRequestProgress(current: number, total: number) }); 40 | onRequestProgress(current: number, total: number); 41 | } 42 | } 43 | export namespace OkHttpResponse { 44 | export class OkHttpResponseProgressCallback { 45 | constructor(impl: { onProgress(current: number, total: number) }); 46 | onProgress(current: number, total: number); 47 | } 48 | export class OkHttpResponseCloseCallback { 49 | constructor(impl: { onClose() }); 50 | onClose(); 51 | } 52 | export class OkHttpResponseAsyncCallback { 53 | constructor(impl: { onBitmap(res); onString(res); onByteArray(res); onFile(res); onException(err) }); 54 | onBitmap(res); 55 | onString(res); 56 | onByteArray(res); 57 | onFile(res); 58 | onException(err); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | const sveltePreprocess = require('svelte-preprocess'); 2 | // const svelteNativePreprocessor = require('svelte-native-preprocessor'); 3 | 4 | module.exports = { 5 | compilerOptions: { 6 | namespace: 'foreign' 7 | }, 8 | preprocess: [ 9 | sveltePreprocess({ 10 | typescript: { 11 | compilerOptions: { 12 | target: 'es2020' 13 | } 14 | } 15 | }) 16 | // svelteNativePreprocessor() 17 | ] 18 | }; 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tools/tsconfig", 3 | "compilerOptions": { 4 | "paths": { 5 | "@nativescript-community/ble": ["src/https/index"], 6 | "@nativescript-community/ble/*": ["src/https/*"], 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.vue3.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "composite": true, 5 | "paths": { 6 | "nativescript-vue": ["./node_modules/nativescript-vue3"] 7 | } 8 | }, 9 | "include": [ 10 | "./demo-snippets/vue3" 11 | ] 12 | } --------------------------------------------------------------------------------