nativescript-community / https

Secure HTTP client with SSL pinning for Nativescript - iOS/Android
https://nativescript-community.github.io/https/
Other
50 stars 42 forks source link

errors on latest nativescript #16

Closed EbrahimTahernejad closed 7 years ago

EbrahimTahernejad commented 7 years ago

I tried to compile the latest NS with this plugin and here is what it told me

Found peer TypeScript 2.2.2
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(45,18): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(500,19): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(502,28): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(503,24): error TS2314: Generic type 'Map<K, V>' requires 2 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(530,33): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(597,37): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(605,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(757,32): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(764,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(931,34): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,33): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(938,67): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1042,36): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1123,25): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1346,52): error TS2314: Generic type 'WeakReference<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1425,56): error TS2314: Generic type 'Set<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1621,35): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,35): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1632,69): error TS2314: Generic type 'Enum<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(1994,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,134): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2042,159): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,32): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2061,86): error TS2314: Generic type 'Class<T>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,39): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2759,80): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,41): error TS2694: Namespace 'java.nio' has no exported member 'file'.

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2762,82): error TS2694: Namespace 'java.nio' has no exported member 'file'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2767,31): error TS2314: Generic type 'AbstractList<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2768,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2770,25): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2776,22): error TS2314: Generic type 'Iterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2777,30): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2778,35): error TS2694: Namespace 'java.util' has no exported member 'Spliterator'.

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2785,40): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2787,41): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2788,23): error TS2314: Generic type 'Comparator<T>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2789,28): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2793,26): error TS2314: Generic type 'ListIterator<E>' requires 1 type argument(s).

node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2794,38): error TS2694: Namespace 'java.util' has no exported member 'stream'.
node_modules/nativescript-https/com.squareup.okhttp3.d.ts(2796,30): error TS2314: Generic type 'Collection<E>' requires 1 type argument(s).

my refrences.d.ts

/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />

my tsconfig

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true,
        "lib": [
            "es6",
            "dom",
            "es2015.iterable"
        ],
        "baseUrl": ".",
        "paths": {
            "*": [
                "./node_modules/tns-core-modules/*",
                "./node_modules/*"
            ]
        }
    },
    "skipLibCheck": true,
    "exclude": [
        "node_modules",
        "platforms",
        "**/*.aot.ts"
    ]
}
rowdyrabouw commented 7 years ago

You can bypass these TypeScript errors by setting "noEmitOnError": false

EbrahimTahernejad commented 7 years ago

thanks

now

    https.request({
      url: 'http://site.com/api/?action=latest_chapters&format=json',
      method: 'GET',
      headers: {
          //'Authorization': 'Basic ZWx1c3VhcmlvOnlsYWNsYXZl',
      },
    }).then(response => {
      console.log(response.content.toString())
    }).catch(error => {
      console.log(error);
    });

results:

JS: Error: android.os.NetworkOnMainThreadException
JS:     android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
JS:     libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249)
JS:     libcore.io.IoBridge.recvfrom(IoBridge.java:553)
JS:     java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)
JS:     java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
JS:     java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
JS:     okio.Okio$2.read(Okio.java:138)
JS:     okio.AsyncTimeout$2.read(AsyncTimeout.java:236)
JS:     okio.RealBufferedSource.indexOf(RealBufferedSource.java:325)
JS:     okio.RealBufferedSource.indexOf(RealBufferedSource.java:314)
JS:     okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:210)
JS:     okhttp3.internal.http1.Http1Codec$ChunkedSource.readChunkSize(Http1Codec.java:442)
JS:     okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:426)
JS:     okhttp3.internal.Util.skipAll(Util.java:165)
JS:     okhttp3.internal.Util.discard(Util.java:147)
JS:     okhttp3.internal.http1.Http1Codec$ChunkedSource.close(Http1Codec.java:463)
JS:     okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS:     okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS:     okio.InflaterSource.close(InflaterSource.java:126)
JS:     okio.GzipSource.close(GzipSource.java:182)
JS:     okio.RealBufferedSource.close(RealBufferedSource.java:434)
JS:     okhttp3.internal.Util.closeQuietly(Util.java:100)
JS:     okhttp3.ResponseBody.string(ResponseBody.java:176)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.access$2400(Runtime.java:33)
JS:     com.tns.Runtime$3.run(Runtime.java:1054)
JS:     android.os.Handler.handleCallback(Handler.java:739)
JS:     android.os.Handler.dispatchMessage(Handler.java:95)
JS:     android.os.Looper.loop(Looper.java:145)
JS:     android.app.ActivityThread.main(ActivityThread.java:5832)
JS:     java.lang.reflect.Method.invoke(Native Method)
JS:     java.lang.reflect.Method.invoke(Method.java:372)
JS:     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
JS:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
roblav96 commented 7 years ago

@AOTOA You'll want to add this somewhere:

application.android.on(application.AndroidApplication.activityCreatedEvent, function(args: application.AndroidActivityBundleEventData) {
    let policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll().build()
    android.os.StrictMode.setThreadPolicy(policy)
})
EbrahimTahernejad commented 7 years ago

thanks It did the work 💃

tremho commented 5 years ago

The snippet also solved my problem. However (for the benefit of others who stumble here as I did and might get tripped up), the non-Typescript Javascript version is more like this:

if(application.android) {
  application.android.on(application.AndroidApplication.activityCreatedEvent, function () {
    let policy = new android.os.StrictMode.ThreadPolicy.Builder().permitAll().build()
    android.os.StrictMode.setThreadPolicy(policy)
  })
}

@roblav96 : Don't you think this bit of preamble should be resident in the plugin or alternately update the plugin to wrap the business within AsyncTask, rather than putting this burden on the {N} developer?