@eyepop.ai/react-native-eyepop 1.15.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 (61) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +33 -0
  3. package/lib/commonjs/index.js +52 -0
  4. package/lib/commonjs/index.js.map +1 -0
  5. package/lib/commonjs/package.json +1 -0
  6. package/lib/commonjs/rn_http_client.js +113 -0
  7. package/lib/commonjs/rn_http_client.js.map +1 -0
  8. package/lib/commonjs/rn_http_header_parser.js +135 -0
  9. package/lib/commonjs/rn_http_header_parser.js.map +1 -0
  10. package/lib/commonjs/rn_http_response_parser.js +199 -0
  11. package/lib/commonjs/rn_http_response_parser.js.map +1 -0
  12. package/lib/commonjs/rn_local_file.js +38 -0
  13. package/lib/commonjs/rn_local_file.js.map +1 -0
  14. package/lib/commonjs/rn_streaming_fetch.js +111 -0
  15. package/lib/commonjs/rn_streaming_fetch.js.map +1 -0
  16. package/lib/module/index.js +48 -0
  17. package/lib/module/index.js.map +1 -0
  18. package/lib/module/package.json +1 -0
  19. package/lib/module/rn_http_client.js +109 -0
  20. package/lib/module/rn_http_client.js.map +1 -0
  21. package/lib/module/rn_http_header_parser.js +131 -0
  22. package/lib/module/rn_http_header_parser.js.map +1 -0
  23. package/lib/module/rn_http_response_parser.js +194 -0
  24. package/lib/module/rn_http_response_parser.js.map +1 -0
  25. package/lib/module/rn_local_file.js +34 -0
  26. package/lib/module/rn_local_file.js.map +1 -0
  27. package/lib/module/rn_streaming_fetch.js +107 -0
  28. package/lib/module/rn_streaming_fetch.js.map +1 -0
  29. package/lib/typescript/commonjs/package.json +1 -0
  30. package/lib/typescript/commonjs/src/index.d.ts +8 -0
  31. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  32. package/lib/typescript/commonjs/src/rn_http_client.d.ts +19 -0
  33. package/lib/typescript/commonjs/src/rn_http_client.d.ts.map +1 -0
  34. package/lib/typescript/commonjs/src/rn_http_header_parser.d.ts +2 -0
  35. package/lib/typescript/commonjs/src/rn_http_header_parser.d.ts.map +1 -0
  36. package/lib/typescript/commonjs/src/rn_http_response_parser.d.ts +21 -0
  37. package/lib/typescript/commonjs/src/rn_http_response_parser.d.ts.map +1 -0
  38. package/lib/typescript/commonjs/src/rn_local_file.d.ts +5 -0
  39. package/lib/typescript/commonjs/src/rn_local_file.d.ts.map +1 -0
  40. package/lib/typescript/commonjs/src/rn_streaming_fetch.d.ts +7 -0
  41. package/lib/typescript/commonjs/src/rn_streaming_fetch.d.ts.map +1 -0
  42. package/lib/typescript/module/package.json +1 -0
  43. package/lib/typescript/module/src/index.d.ts +8 -0
  44. package/lib/typescript/module/src/index.d.ts.map +1 -0
  45. package/lib/typescript/module/src/rn_http_client.d.ts +19 -0
  46. package/lib/typescript/module/src/rn_http_client.d.ts.map +1 -0
  47. package/lib/typescript/module/src/rn_http_header_parser.d.ts +2 -0
  48. package/lib/typescript/module/src/rn_http_header_parser.d.ts.map +1 -0
  49. package/lib/typescript/module/src/rn_http_response_parser.d.ts +21 -0
  50. package/lib/typescript/module/src/rn_http_response_parser.d.ts.map +1 -0
  51. package/lib/typescript/module/src/rn_local_file.d.ts +5 -0
  52. package/lib/typescript/module/src/rn_local_file.d.ts.map +1 -0
  53. package/lib/typescript/module/src/rn_streaming_fetch.d.ts +7 -0
  54. package/lib/typescript/module/src/rn_streaming_fetch.d.ts.map +1 -0
  55. package/package.json +202 -0
  56. package/src/index.ts +48 -0
  57. package/src/rn_http_client.ts +134 -0
  58. package/src/rn_http_header_parser.ts +138 -0
  59. package/src/rn_http_response_parser.ts +248 -0
  60. package/src/rn_local_file.ts +43 -0
  61. package/src/rn_streaming_fetch.ts +131 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 EyePop.ai
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # react-native-eyepop
2
+
3
+ The official Typescript library for EyePop.ai's inference API for React Native
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-eyepop
9
+ ```
10
+
11
+ ## Usage
12
+
13
+
14
+ ```js
15
+ import { multiply } from 'react-native-eyepop';
16
+
17
+ // ...
18
+
19
+ const result = await multiply(3, 7);
20
+ ```
21
+
22
+
23
+ ## Contributing
24
+
25
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
26
+
27
+ ## License
28
+
29
+ MIT
30
+
31
+ ---
32
+
33
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EyePop = void 0;
7
+ require("react-native-polyfill-globals/auto");
8
+ require("@azure/core-asynciterator-polyfill");
9
+ var _reactNativeWebrtc = require("react-native-webrtc");
10
+ var _pino = require("pino");
11
+ var _eyepop = require("@eyepop.ai/eyepop");
12
+ var _rn_local_file = require("./rn_local_file.js");
13
+ var _rn_http_client = require("./rn_http_client.js");
14
+ globalThis.Buffer = require('buffer').Buffer;
15
+ // @ts-ignore
16
+ globalThis.RTCPeerConnection = _reactNativeWebrtc.RTCPeerConnection;
17
+ // @ts-ignore
18
+ globalThis.RTCSessionDescription = _reactNativeWebrtc.RTCSessionDescription;
19
+ let EyePop = exports.EyePop = void 0;
20
+ (function (_EyePop2) {
21
+ function workerEndpoint(opts) {
22
+ opts = opts || {};
23
+ if (opts.logger === undefined) {
24
+ opts.logger = (0, _pino.pino)({
25
+ level: 'debug',
26
+ name: 'eyepop'
27
+ });
28
+ }
29
+ opts.platformSupport = {
30
+ resolvePath: _rn_local_file.resolvePathRN,
31
+ createHttpClient: _rn_http_client.createHttpClientRN
32
+ };
33
+ return _eyepop.EyePop.workerEndpoint(opts);
34
+ }
35
+ _EyePop2.workerEndpoint = workerEndpoint;
36
+ function dataEndpoint(opts) {
37
+ opts = opts || {};
38
+ if (opts.logger === undefined) {
39
+ opts.logger = (0, _pino.pino)({
40
+ level: 'debug',
41
+ name: 'eyepop'
42
+ });
43
+ }
44
+ opts.platformSupport = {
45
+ resolvePath: _rn_local_file.resolvePathRN,
46
+ createHttpClient: _rn_http_client.createHttpClientRN
47
+ };
48
+ return _eyepop.EyePop.dataEndpoint(opts);
49
+ }
50
+ _EyePop2.dataEndpoint = dataEndpoint;
51
+ })(EyePop || (exports.EyePop = EyePop = {}));
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_reactNativeWebrtc","_pino","_eyepop","_rn_local_file","_rn_http_client","globalThis","Buffer","RTCPeerConnection","RTCSessionDescription","EyePop","exports","_EyePop2","workerEndpoint","opts","logger","undefined","pino","level","name","platformSupport","resolvePath","resolvePathRN","createHttpClient","createHttpClientRN","_EyePop","dataEndpoint"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAAA,OAAA;AAGAA,OAA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AI,CAAC;EACnC;EAACF,QAAA,CAAAc,YAAA,GAAAA,YAAA;AAAA,GAvBchB,MAAM,KAAAC,OAAA,CAAAD,MAAA,GAANA,MAAM","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHttpClientRN = createHttpClientRN;
7
+ require("react-native-polyfill-globals/auto");
8
+ var _rn_streaming_fetch = require("./rn_streaming_fetch.js");
9
+ var _reactNativeTcpSocket = _interopRequireDefault(require("react-native-tcp-socket"));
10
+ var _es = require("web-streams-polyfill/ponyfill/es6");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /** HTTP client that will work around the RN fetch implementation and truly stream request and response bodies.
13
+ *
14
+ * While '{ textStreaming: true }' helps somewhat for the response body, it does not truly stream the response
15
+ * body, instead it keeps a large buffer and does not stream bytes to the consumer as they come in.
16
+ * Additionally, it does not support streaming request bodies which forces the consumer to load large files
17
+ * into memory w/o any possibility to avoid OOMs.
18
+ *
19
+ * This implementation implements selected HTTP interactions by using TCP sockets directly. The implementation
20
+ * is minimal and far from complete, e.g. no redirect support. For that reason, EyePop wil prefer to use the
21
+ * built-in fetch() except for cases when (a) the request requires a ReadableStream request body, or
22
+ * (b) the response is supposed to truly stream as indicated by the proprietary init parameter
23
+ * '{ eyepop: { responseStreaming: true} }'.
24
+ *
25
+ * */
26
+ async function createHttpClientRN(logger) {
27
+ class ReactNativeHttpClient {
28
+ constructor(logger_) {
29
+ this.logger = logger_;
30
+ }
31
+ async fetch(input, init) {
32
+ init ||= {};
33
+ let streamBody;
34
+ if (input instanceof Request && input.body instanceof _es.ReadableStream) {
35
+ // Request body streaming not supported by RN fetch
36
+ streamBody = input.body;
37
+ } else if (init?.body instanceof _es.ReadableStream) {
38
+ streamBody = init.body;
39
+ // @ts-ignore
40
+ } else if (init?.eyepop?.responseStreaming) {
41
+ const requestBody = input instanceof Request ? input.body : init?.body;
42
+ if (requestBody !== undefined) {
43
+ // The limited HTTP post requires a ReadableStream request body
44
+ if (typeof requestBody === 'string') {
45
+ streamBody = new _es.ReadableStream({
46
+ start: controller => {
47
+ controller.enqueue(Buffer.from(requestBody, 'utf8'));
48
+ controller.close();
49
+ }
50
+ });
51
+ } else if (requestBody instanceof Uint8Array) {
52
+ streamBody = new _es.ReadableStream({
53
+ start: controller => {
54
+ controller.enqueue(requestBody);
55
+ controller.close();
56
+ }
57
+ });
58
+ } else {
59
+ this.logger.warn(`EyePop responseStreaming requires a request body of type ReadableStream | string | Uint8Array but is ${typeof requestBody}`);
60
+ }
61
+ }
62
+ }
63
+ if (streamBody) {
64
+ let url;
65
+ let method;
66
+ let headers;
67
+ if (input instanceof Request) {
68
+ url = new URL(input.url);
69
+ method = input.method;
70
+ headers = input.headers;
71
+ } else {
72
+ if (input instanceof URL) {
73
+ url = input;
74
+ } else {
75
+ url = new URL(input);
76
+ }
77
+ method = init?.method || 'POST';
78
+ headers = new Headers(init?.headers);
79
+ }
80
+ let contentLength;
81
+ if (headers.has('content-length')) {
82
+ contentLength = parseInt(headers.get('content-length') || '', 10);
83
+ } else {
84
+ headers.append('Transfer-Encoding', 'chunked');
85
+ }
86
+ this.logger.debug(`reactNativeStreamingFetch() BEFORE ${method} ${url}`);
87
+ const response = await (0, _rn_streaming_fetch.reactNativeStreamingFetch)(url, method, headers, streamBody, contentLength, _reactNativeTcpSocket.default, this.logger);
88
+ this.logger.debug(`AFTER ${method} ${url} -> ${response.status}`);
89
+ return response;
90
+ }
91
+ // @ts-ignore
92
+ init.reactNative = {
93
+ textStreaming: true
94
+ };
95
+ const logLine = logLineFromRequest(input, init);
96
+ this.logger.debug(`ReactNative fetch() BEFORE ${logLine}`);
97
+ const response = await fetch(input, init);
98
+ this.logger.debug(`AFTER ${logLine} -> ${response.status}`);
99
+ return response;
100
+ }
101
+ async close() {}
102
+ isFullDuplex() {
103
+ return true;
104
+ }
105
+ }
106
+ return new ReactNativeHttpClient(logger);
107
+ }
108
+ function logLineFromRequest(input, init) {
109
+ const url = input instanceof Request ? input.url : input;
110
+ const method = input instanceof Request ? input.method : init?.method || (init?.body !== undefined ? 'POST' : 'GET');
111
+ return `${method} ${url}`;
112
+ }
113
+ //# sourceMappingURL=rn_http_client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_rn_streaming_fetch","_reactNativeTcpSocket","_interopRequireDefault","_es","e","__esModule","default","createHttpClientRN","logger","ReactNativeHttpClient","constructor","logger_","fetch","input","init","streamBody","Request","body","ReadableStream","eyepop","responseStreaming","requestBody","undefined","start","controller","enqueue","Buffer","from","close","Uint8Array","warn","url","method","headers","URL","Headers","contentLength","has","parseInt","get","append","debug","response","reactNativeStreamingFetch","TcpSockets","status","reactNative","textStreaming","logLine","logLineFromRequest","isFullDuplex"],"sourceRoot":"../../src","sources":["rn_http_client.ts"],"mappings":";;;;;;AAAAA,OAAA;AAEA,IAAAC,mBAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,GAAA,GAAAJ,OAAA;AAAmE,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeG,kBAAkBA,CAACC,MAAc,EAAuB;EAC5E,MAAMC,qBAAqB,CAAC;IAG1BC,WAAWA,CAACC,OAAe,EAAE;MAC3B,IAAI,CAACH,MAAM,GAAGG,OAAO;IACvB;IAEA,MAAaC,KAAKA,CAChBC,KAAwB,EACxBC,IAAkB,EACC;MACnBA,IAAI,KAAK,CAAC,CAAC;MACX,IAAIC,UAAkD;MACtD,IAAIF,KAAK,YAAYG,OAAO,IAAIH,KAAK,CAACI,IAAI,YAAYC,kBAAc,EAAE;QAC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M,CAACiC,KAAK,CAAC,SAASO,OAAO,OAAON,QAAQ,CAACG,MAAM,EAAE,CAAC;MAC3D,OAAOH,QAAQ;IACjB;IAEA,MAAad,KAAKA,CAAA,EAAkB,CAAC;IAE9BsB,YAAYA,CAAA,EAAG;MACpB,OAAO,IAAI;IACb;EACF;EAEA,OAAO,IAAIzC,qBAAqB,CAACD,MAAM,CAAC;AAC1C;AAEA,SAASyC,kBAAkBA,CACzBpC,KAAwB,EACxBC,IAAkB,EACV;EACR,MAAMiB,GAAG,GAAGlB,KAAK,YAAYG,OAAO,GAAGH,KAAK,CAACkB,GAAG,GAAGlB,KAAK;EACxD,MAAMmB,MAAM,GACVnB,KAAK,YAAYG,OAAO,GACpBH,KAAK,CAACmB,MAAM,GACZlB,IAAI,EAAEkB,MAAM,KAAKlB,IAAI,EAAEG,IAAI,KAAKK,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC;EACjE,OAAO,GAAGU,MAAM,IAAID,GAAG,EAAE;AAC3B","ignoreList":[]}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseHttpHeader = parseHttpHeader;
7
+ // RFC-2068 Start-Line definitions:
8
+ // Request-Line: Method SP Request-URI SP HTTP-Version CRLF
9
+ // Status-Line: HTTP-Version SP Status-Code SP Reason-Phrase CRLF
10
+ var startLine = /^[A-Z_]+(\/\d\.\d)? /;
11
+ var requestLine = /^([A-Z_]+) (.+) [A-Z]+\/(\d)\.(\d)$/;
12
+ var statusLine = /^[A-Z]+\/(\d)\.(\d) (\d{3}) (.*)$/;
13
+ function parseHttpHeader(lines, onlyHeaders) {
14
+ let line = lines[0] || '';
15
+ let match;
16
+ if (onlyHeaders && startLine.test(line)) {
17
+ return parseHeaders(lines);
18
+ } else if ((match = line.match(requestLine)) !== null) {
19
+ return {
20
+ method: match[1],
21
+ url: match[2],
22
+ version: {
23
+ major: parseInt(match[3] || '', 10),
24
+ minor: parseInt(match[4] || '', 10)
25
+ },
26
+ headers: parseHeaders(lines)
27
+ };
28
+ } else if ((match = line.match(statusLine)) !== null) {
29
+ return {
30
+ version: {
31
+ major: parseInt(match[1] || '', 10),
32
+ minor: parseInt(match[2] || '', 10)
33
+ },
34
+ statusCode: parseInt(match[3] || '', 10),
35
+ statusMessage: match[4],
36
+ headers: parseHeaders(lines)
37
+ };
38
+ } else {
39
+ return parseHeaders(lines);
40
+ }
41
+ }
42
+ function parseHeaders(lines) {
43
+ var headers = {};
44
+ var i = 0;
45
+ var line = lines[i] || '';
46
+ var index, name, value;
47
+ if (startLine.test(line)) {
48
+ line = line[++i] || '';
49
+ }
50
+ while (line) {
51
+ // subsequent lines in multi-line headers start with whitespace
52
+ if (line[0] === ' ' || line[0] === '\t') {
53
+ value += ' ' + line.trim();
54
+ i++;
55
+ if (i < lines.length) {
56
+ line = lines[i] || '';
57
+ } else {
58
+ line = '';
59
+ }
60
+ continue;
61
+ }
62
+ if (name && value) {
63
+ addHeaderLine(name, value, headers);
64
+ }
65
+ index = line.indexOf(':');
66
+ name = line.substr(0, index);
67
+ value = line.substr(index + 1).trim();
68
+ i++;
69
+ if (i < lines.length) {
70
+ line = lines[i] || '';
71
+ } else {
72
+ line = '';
73
+ }
74
+ }
75
+ if (name && value) {
76
+ addHeaderLine(name, value, headers);
77
+ }
78
+ return headers;
79
+ }
80
+
81
+ // The following function is lifted from:
82
+ // https://github.com/nodejs/node/blob/f1294f5bfd7f02bce8029818be9c92de59749137/lib/_http_incoming.js#L116-L170
83
+ //
84
+ // Add the given (field, value) pair to the message
85
+ //
86
+ // Per RFC2616, section 4.2 it is acceptable to join multiple instances of the
87
+ // same header with a ', ' if the header in question supports specification of
88
+ // multiple values this way. If not, we declare the first instance the winner
89
+ // and drop the second. Extended header fields (those beginning with 'x-') are
90
+ // always joined.
91
+ function addHeaderLine(field, value, dest) {
92
+ field = field.toLowerCase();
93
+ switch (field) {
94
+ // Array headers:
95
+ case 'set-cookie':
96
+ if (dest[field] !== undefined) {
97
+ dest[field].push(value);
98
+ } else {
99
+ dest[field] = [value];
100
+ }
101
+ break;
102
+
103
+ // list is taken from:
104
+ // https://mxr.mozilla.org/mozilla/source/netwerk/protocol/http/src/nsHttpHeaderArray.cpp
105
+ case 'content-type':
106
+ case 'content-length':
107
+ case 'user-agent':
108
+ case 'referer':
109
+ case 'host':
110
+ case 'authorization':
111
+ case 'proxy-authorization':
112
+ case 'if-modified-since':
113
+ case 'if-unmodified-since':
114
+ case 'from':
115
+ case 'location':
116
+ case 'max-forwards':
117
+ case 'retry-after':
118
+ case 'etag':
119
+ case 'last-modified':
120
+ case 'server':
121
+ case 'age':
122
+ case 'expires':
123
+ // drop duplicates
124
+ if (dest[field] === undefined) dest[field] = value;
125
+ break;
126
+ default:
127
+ // make comma-separated list
128
+ if (typeof dest[field] === 'string') {
129
+ dest[field] += ', ' + value;
130
+ } else {
131
+ dest[field] = value;
132
+ }
133
+ }
134
+ }
135
+ //# sourceMappingURL=rn_http_header_parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["startLine","requestLine","statusLine","parseHttpHeader","lines","onlyHeaders","line","match","test","parseHeaders","method","url","version","major","parseInt","minor","headers","statusCode","statusMessage","i","index","name","value","trim","length","addHeaderLine","indexOf","substr","field","dest","toLowerCase","undefined","push"],"sourceRoot":"../../src","sources":["rn_http_header_parser.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA,IAAIA,SAAS,GAAG,sBAAsB;AACtC,IAAIC,WAAW,GAAG,qCAAqC;AACvD,IAAIC,UAAU,GAAG,mCAAmC;AAE7C,SAASC,eAAeA,CAACC,KAAe,EAAEC,WAAoB,EAAE;EACrE,IAAIC,IAAI,GAAGF,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE;EACzB,IAAIG,KAAK;EAET,IAAIF,WAAW,IAAIL,SAAS,CAACQ,IAAI,CAACF,IAAI,CAAC,EAAE;IACvC,OAAOG,YAAY,CAACL,KAAK,CAAC;EAC5B,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AE;EAC9DD,KAAK,GAAGA,KAAK,CAACE,WAAW,CAAC,CAAC;EAC3B,QAAQF,KAAK;IACX;IACA,KAAK,YAAY;MACf,IAAIC,IAAI,CAACD,KAAK,CAAC,KAAKG,SAAS,EAAE;QAC7BF,IAAI,CAACD,KAAK,CAAC,CAACI,IAAI,CAACV,KAAK,CAAC;MACzB,CAAC,MAAM;QACLO,IAAI,CAACD,KAAK,CAAC,GAAG,CAACN,KAAK,CAAC;MACvB;MACA;;IAEF;IACA;IACA,KAAK,cAAc;IACnB,KAAK,gBAAgB;IACrB,KAAK,YAAY;IACjB,KAAK,SAAS;IACd,KAAK,MAAM;IACX,KAAK,eAAe;IACpB,KAAK,qBAAqB;IAC1B,KAAK,mBAAmB;IACxB,KAAK,qBAAqB;IAC1B,KAAK,MAAM;IACX,KAAK,UAAU;IACf,KAAK,cAAc;IACnB,KAAK,aAAa;IAClB,KAAK,MAAM;IACX,KAAK,eAAe;IACpB,KAAK,QAAQ;IACb,KAAK,KAAK;IACV,KAAK,SAAS;MACZ;MACA,IAAIO,IAAI,CAACD,KAAK,CAAC,KAAKG,SAAS,EAAEF,IAAI,CAACD,KAAK,CAAC,GAAGN,KAAK;MAClD;IAEF;MACE;MACA,IAAI,OAAOO,IAAI,CAACD,KAAK,CAAC,KAAK,QAAQ,EAAE;QACnCC,IAAI,CAACD,KAAK,CAAC,IAAI,IAAI,GAAGN,KAAK;MAC7B,CAAC,MAAM;QACLO,IAAI,CAACD,KAAK,CAAC,GAAGN,KAAK;MACrB;EACJ;AACF","ignoreList":[]}
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ResponseParser = void 0;
7
+ require("react-native-polyfill-globals/auto");
8
+ var _eyepop = require("@eyepop.ai/eyepop");
9
+ var _rn_http_header_parser = require("./rn_http_header_parser.js");
10
+ var _es = require("web-streams-polyfill/ponyfill/es6");
11
+ var ResponseState = /*#__PURE__*/function (ResponseState) {
12
+ ResponseState[ResponseState["RECEIVING_HEADER"] = 0] = "RECEIVING_HEADER";
13
+ ResponseState[ResponseState["RECEIVING_BODY"] = 1] = "RECEIVING_BODY";
14
+ ResponseState[ResponseState["RECEIVING_BODY_CHUNKED"] = 2] = "RECEIVING_BODY_CHUNKED";
15
+ ResponseState[ResponseState["RECEIVING_COMPLETED"] = 3] = "RECEIVING_COMPLETED";
16
+ return ResponseState;
17
+ }(ResponseState || {});
18
+ class ResponseParser {
19
+ responseChunkRemainder = 0;
20
+ constructor(logger, resolve, reject) {
21
+ this.logger = logger;
22
+ this.resolve = resolve;
23
+ this.reject = reject;
24
+ this.error = null;
25
+ this.responseReadBuffer = undefined;
26
+ this.responseState = ResponseState.RECEIVING_HEADER;
27
+ this.pullController = undefined;
28
+ this.pullResolve = undefined;
29
+ this.pullReject = undefined;
30
+ }
31
+ processResponseReadBuffer(data) {
32
+ if (this.error) {
33
+ this.logger.info(`RN http streamed response, received ${data.length} bytes in error mode`);
34
+ return false;
35
+ }
36
+ if (this.responseReadBuffer) {
37
+ this.responseReadBuffer = Buffer.concat([this.responseReadBuffer, data]);
38
+ } else {
39
+ this.responseReadBuffer = Buffer.from(data.subarray());
40
+ }
41
+ if (this.responseState === ResponseState.RECEIVING_COMPLETED) {
42
+ if (this.pullController) {
43
+ this.pullController.close();
44
+ if (this.pullResolve) {
45
+ this.pullResolve();
46
+ }
47
+ }
48
+ return false;
49
+ } else if (this.responseState === ResponseState.RECEIVING_HEADER) {
50
+ const headerEnd = this.responseReadBuffer.indexOf('\r\n\r\n');
51
+ if (headerEnd >= 0) {
52
+ let headerChunk = this.responseReadBuffer.subarray(0, headerEnd + 4);
53
+ this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(headerEnd + 4));
54
+ const maxHeaderLines = 128;
55
+ let responseHeaderLines = [];
56
+ const lineDecoder = new _eyepop.EyepopLineDecoder();
57
+ for (const line of lineDecoder.decode(headerChunk)) {
58
+ if (line.length > 0) {
59
+ responseHeaderLines.push(line);
60
+ if (responseHeaderLines.length > maxHeaderLines) {
61
+ this.error = `Response header exceeds ${maxHeaderLines} lines`;
62
+ this.reject(this.error);
63
+ return false;
64
+ }
65
+ }
66
+ }
67
+ let responseHeader = (0, _rn_http_header_parser.parseHttpHeader)(responseHeaderLines, false);
68
+ if (responseHeader.statusCode === undefined) {
69
+ this.logger.warn(`Could not find status header in HTTP response ${JSON.stringify(responseHeader)}`);
70
+ this.reject('missing status header in HTTP response');
71
+ return false;
72
+ }
73
+ const headers = new Headers(responseHeader.headers);
74
+ if (headers.has('transfer-encoding')) {
75
+ if (headers.get('transfer-encoding')?.toLowerCase() === 'chunked') {
76
+ this.responseState = ResponseState.RECEIVING_BODY_CHUNKED;
77
+ this.responseChunkRemainder = 0;
78
+ } else {
79
+ this.error = `Response with unsupported transfer-encoding '${headers.get('transfer-encoding')}'`;
80
+ this.reject(this.error);
81
+ return false;
82
+ }
83
+ } else if (headers.has('content-length')) {
84
+ this.responseState = ResponseState.RECEIVING_BODY;
85
+ this.responseChunkRemainder = parseInt(headers.get('content-length') || '-1', 10);
86
+ } else {
87
+ this.responseState = ResponseState.RECEIVING_BODY_CHUNKED;
88
+ this.responseChunkRemainder = 0;
89
+ }
90
+ const responseBody = new _es.ReadableStream({
91
+ pull: controller => {
92
+ if (this.error || this.responseState === ResponseState.RECEIVING_COMPLETED) {
93
+ // done with the whole request
94
+ return;
95
+ }
96
+ if (this.pull(controller)) {
97
+ // one chunk enqueued, fulfilled the pull() protocol
98
+ return;
99
+ }
100
+ // nothing to enqueue yet, need to defer top a promise
101
+ return new Promise((resolve, reject) => {
102
+ if (this.pullController) {
103
+ if (this.pullReject) {
104
+ this.pullReject('pull, we got a pending controller already');
105
+ }
106
+ }
107
+ this.pullController = controller;
108
+ this.pullResolve = resolve;
109
+ this.pullReject = reject;
110
+ });
111
+ },
112
+ cancel: reason => {
113
+ if (!this.error) {
114
+ this.error = `cancelled: ${reason}`;
115
+ this.reject(this.error);
116
+ }
117
+ }
118
+ });
119
+ this.resolve(
120
+ // @ts-ignore
121
+ new Response(responseBody, {
122
+ status: responseHeader.statusCode,
123
+ statusText: responseHeader.statusText,
124
+ headers: headers
125
+ }));
126
+ }
127
+ } else if (this.pullController) {
128
+ if (this.pull(this.pullController)) {
129
+ this.pullController = undefined;
130
+ if (this.pullResolve) {
131
+ this.pullResolve();
132
+ }
133
+ this.pullResolve = undefined;
134
+ this.pullReject = undefined;
135
+ }
136
+ }
137
+ return true;
138
+ }
139
+ pull(controller) {
140
+ if (this.responseState === ResponseState.RECEIVING_COMPLETED) {
141
+ controller.close();
142
+ return false;
143
+ }
144
+ if (this.responseReadBuffer === undefined) {
145
+ return false;
146
+ }
147
+ if (this.responseState === ResponseState.RECEIVING_BODY) {
148
+ controller.enqueue(this.responseReadBuffer);
149
+ this.responseChunkRemainder -= this.responseReadBuffer.length;
150
+ this.responseReadBuffer = undefined;
151
+ if (this.responseChunkRemainder <= 0) {
152
+ this.responseState = ResponseState.RECEIVING_COMPLETED;
153
+ controller.close();
154
+ }
155
+ return true;
156
+ } else if (this.responseState === ResponseState.RECEIVING_BODY_CHUNKED) {
157
+ while (this.responseReadBuffer.length > 1) {
158
+ if (this.responseChunkRemainder === 0) {
159
+ // need to find the new chunk length
160
+ let chunkHeaderEnd = 0;
161
+ while (this.responseReadBuffer.length >= 2 && chunkHeaderEnd === 0) {
162
+ chunkHeaderEnd = this.responseReadBuffer.indexOf('\r\n');
163
+ if (chunkHeaderEnd === 0) {
164
+ // skip closing \r\n line of a previous chunk
165
+ this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(2));
166
+ }
167
+ }
168
+ if (chunkHeaderEnd > 0) {
169
+ this.responseChunkRemainder = parseInt(Buffer.from(this.responseReadBuffer, 0, chunkHeaderEnd).toString('utf8'), 16);
170
+ this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(chunkHeaderEnd + 2));
171
+ if (this.responseChunkRemainder <= 0) {
172
+ this.responseState = ResponseState.RECEIVING_COMPLETED;
173
+ controller.close();
174
+ return true;
175
+ }
176
+ } else if (this.responseReadBuffer.length > 64) {
177
+ this.error = 'Cannot find chunked encoding header within 64 bytes, given up';
178
+ controller.error(this.error);
179
+ }
180
+ }
181
+ if (this.responseChunkRemainder > 0 && this.responseReadBuffer.length > 0) {
182
+ const chunk = Buffer.from(this.responseReadBuffer.subarray(0, this.responseChunkRemainder));
183
+ this.responseReadBuffer = Buffer.from(this.responseReadBuffer.subarray(this.responseChunkRemainder));
184
+ controller.enqueue(chunk);
185
+ this.responseChunkRemainder -= chunk.length;
186
+ return true;
187
+ } else {
188
+ break;
189
+ }
190
+ }
191
+ } else {
192
+ this.error = `Received more data in wrong state ${this.responseState}`;
193
+ controller.error(this.error);
194
+ }
195
+ return false;
196
+ }
197
+ }
198
+ exports.ResponseParser = ResponseParser;
199
+ //# sourceMappingURL=rn_http_response_parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_eyepop","_rn_http_header_parser","_es","ResponseState","ResponseParser","responseChunkRemainder","constructor","logger","resolve","reject","error","responseReadBuffer","undefined","responseState","RECEIVING_HEADER","pullController","pullResolve","pullReject","processResponseReadBuffer","data","info","length","Buffer","concat","from","subarray","RECEIVING_COMPLETED","close","headerEnd","indexOf","headerChunk","maxHeaderLines","responseHeaderLines","lineDecoder","EyepopLineDecoder","line","decode","push","responseHeader","parseHttpHeader","statusCode","warn","JSON","stringify","headers","Headers","has","get","toLowerCase","RECEIVING_BODY_CHUNKED","RECEIVING_BODY","parseInt","responseBody","ReadableStream","pull","controller","Promise","cancel","reason","Response","status","statusText","enqueue","chunkHeaderEnd","toString","chunk","exports"],"sourceRoot":"../../src","sources":["rn_http_response_parser.ts"],"mappings":";;;;;;AAAAA,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AAEA,IAAAG,GAAA,GAAAH,OAAA;AAG2C,IAEtCI,aAAa,0BAAbA,aAAa;EAAbA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use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolvePathRN = resolvePathRN;
7
+ require("react-native-polyfill-globals/auto");
8
+ var _es = require("web-streams-polyfill/ponyfill/es6");
9
+ var _reactNativeFileAccess = require("react-native-file-access");
10
+ async function resolvePathRN(source, _) {
11
+ const bufferSize = 1024 * 1024;
12
+ let pos = 0;
13
+ const size = (await _reactNativeFileAccess.FileSystem.stat(source.path)).size;
14
+ let eof = false;
15
+ const stream = new _es.ReadableStream({
16
+ async pull(controller) {
17
+ if (eof) {
18
+ return;
19
+ }
20
+ const chunkSize = Math.min(bufferSize, size - pos);
21
+ const chunkAsB64 = await _reactNativeFileAccess.FileSystem.readFileChunk(source.path, pos, chunkSize, 'base64');
22
+ if (chunkAsB64.length > 0) {
23
+ const chunk = Buffer.from(chunkAsB64, 'base64').subarray(0, chunkSize);
24
+ controller.enqueue(chunk);
25
+ pos += chunk.length;
26
+ } else {
27
+ eof = true;
28
+ controller.close();
29
+ }
30
+ }
31
+ });
32
+ return {
33
+ stream: stream,
34
+ size: size,
35
+ mimeType: source.mimeType || 'image/*'
36
+ };
37
+ }
38
+ //# sourceMappingURL=rn_local_file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["require","_es","_reactNativeFileAccess","resolvePathRN","source","_","bufferSize","pos","size","FileSystem","stat","path","eof","stream","ReadableStream","pull","controller","chunkSize","Math","min","chunkAsB64","readFileChunk","length","chunk","Buffer","from","subarray","enqueue","close","mimeType"],"sourceRoot":"../../src","sources":["rn_local_file.ts"],"mappings":";;;;;;AAAAA,OAAA;AAGA,IAAAC,GAAA,GAAAD,OAAA;AAEA,IAAAE,sBAAA,GAAAF,OAAA;AAEO,eAAeG,aAAaA,CACjCC,MAAkB,EAClBC,CAAS,EACc;EACvB,MAAMC,UAAU,GAAG,IAAI,GAAG,IAAI;EAC9B,IAAIC,GAAG,GAAG,CAAC;EACX,MAAMC,IAAI,GAAG,CAAC,MAAMC,iCAAU,CAACC,IAAI,CAACN,MAAM,CAACO,IAAI,CAAC,EAAEH,IAAI;EACtD,IAAII,GAAG,GAAG,KAAK;EACf,MAAMC,MAAM,GAAG,IAAIC,kBAAc,CAAC;IAChC,MAAMC,IAAIA,CAACC,UAAe,EAAE;MAC1B,IAAIJ,GAAG,EAAE;QACP;MACF;MACA,MAAMK,SAAS,GAAGC,IAAI,CAACC,GAAG,CAACb,UAAU,EAAEE,IAAI,GAAGD,GAAG,CAAC;MAClD,MAAMa,UAAU,GAAG,MAAMX,iCAAU,CAACY,aAAa,CAC/CjB,MAAM,CAACO,IAAI,EACXJ,GAAG,EACHU,SAAS,EACT,QACF,CAAC;MACD,IAAIG,UAAU,CAACE,MAAM,GAAG,CAAC,EAAE;QACzB,MAAMC,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACL,UAAU,EAAE,QAAQ,CAAC,CAACM,QAAQ,CAAC,CAAC,EAAET,SAAS,CAAC;QACtED,UAAU,CAACW,OAAO,CAACJ,KAAK,CAAC;QACzBhB,GAAG,IAAIgB,KAAK,CAACD,MAAM;MACrB,CAAC,MAAM;QACLV,GAAG,GAAG,IAAI;QACVI,UAAU,CAACY,KAAK,CAAC,CAAC;MACpB;IACF;EACF,CAAC,CAAC;EACF,OAAO;IACLf,MAAM,EAAEA,MAAM;IACdL,IAAI,EAAEA,IAAI;IACVqB,QAAQ,EAAEzB,MAAM,CAACyB,QAAQ,IAAI;EAC/B,CAAC;AACH","ignoreList":[]}