@vishalsharma7nov/react-native-proto 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/android/src/main/java/com/vishalsharma7nov/reactnativeproto/ReactNativeProtoNativeGrpcModule.java +142 -0
  2. package/app.plugin.js +63 -0
  3. package/bin/react-native-proto.js +956 -0
  4. package/ios/ReactNativeProtoNativeGrpc.m +129 -0
  5. package/lib/commonjs/auth.js +72 -0
  6. package/lib/commonjs/auth.js.map +1 -0
  7. package/lib/commonjs/client-factory.js +81 -0
  8. package/lib/commonjs/client-factory.js.map +1 -0
  9. package/lib/commonjs/codecs.js +41 -0
  10. package/lib/commonjs/codecs.js.map +1 -0
  11. package/lib/commonjs/connect/envelope.js +100 -0
  12. package/lib/commonjs/connect/envelope.js.map +1 -0
  13. package/lib/commonjs/connect/errors.js +71 -0
  14. package/lib/commonjs/connect/errors.js.map +1 -0
  15. package/lib/commonjs/errors.js +54 -0
  16. package/lib/commonjs/errors.js.map +1 -0
  17. package/lib/commonjs/generated/create-api.js +29 -0
  18. package/lib/commonjs/generated/create-api.js.map +1 -0
  19. package/lib/commonjs/generated/message-types.js +2 -0
  20. package/lib/commonjs/generated/message-types.js.map +1 -0
  21. package/lib/commonjs/generated/messages.js +47 -0
  22. package/lib/commonjs/generated/messages.js.map +1 -0
  23. package/lib/commonjs/generated/messages.pb.js +2787 -0
  24. package/lib/commonjs/generated/messages.pb.js.map +1 -0
  25. package/lib/commonjs/generated/method-map.js +68 -0
  26. package/lib/commonjs/generated/method-map.js.map +1 -0
  27. package/lib/commonjs/index.js +283 -0
  28. package/lib/commonjs/index.js.map +1 -0
  29. package/lib/commonjs/interceptors.js +19 -0
  30. package/lib/commonjs/interceptors.js.map +1 -0
  31. package/lib/commonjs/logging.js +54 -0
  32. package/lib/commonjs/logging.js.map +1 -0
  33. package/lib/commonjs/metro/index.js +35 -0
  34. package/lib/commonjs/metro/index.js.map +1 -0
  35. package/lib/commonjs/metro/transformer.js +33 -0
  36. package/lib/commonjs/metro/transformer.js.map +1 -0
  37. package/lib/commonjs/mock-server/index.js +125 -0
  38. package/lib/commonjs/mock-server/index.js.map +1 -0
  39. package/lib/commonjs/native-grpc/index.js +242 -0
  40. package/lib/commonjs/native-grpc/index.js.map +1 -0
  41. package/lib/commonjs/offline-queue.js +137 -0
  42. package/lib/commonjs/offline-queue.js.map +1 -0
  43. package/lib/commonjs/package.json +1 -0
  44. package/lib/commonjs/path-templates.js +44 -0
  45. package/lib/commonjs/path-templates.js.map +1 -0
  46. package/lib/commonjs/react-query/index.js +30 -0
  47. package/lib/commonjs/react-query/index.js.map +1 -0
  48. package/lib/commonjs/streaming.js +251 -0
  49. package/lib/commonjs/streaming.js.map +1 -0
  50. package/lib/commonjs/transport.js +323 -0
  51. package/lib/commonjs/transport.js.map +1 -0
  52. package/lib/commonjs/types.js +6 -0
  53. package/lib/commonjs/types.js.map +1 -0
  54. package/lib/commonjs/validation/zod.js +48 -0
  55. package/lib/commonjs/validation/zod.js.map +1 -0
  56. package/lib/commonjs/version-check.js +102 -0
  57. package/lib/commonjs/version-check.js.map +1 -0
  58. package/lib/module/auth.js +67 -0
  59. package/lib/module/auth.js.map +1 -0
  60. package/lib/module/client-factory.js +77 -0
  61. package/lib/module/client-factory.js.map +1 -0
  62. package/lib/module/codecs.js +36 -0
  63. package/lib/module/codecs.js.map +1 -0
  64. package/lib/module/connect/envelope.js +93 -0
  65. package/lib/module/connect/envelope.js.map +1 -0
  66. package/lib/module/connect/errors.js +65 -0
  67. package/lib/module/connect/errors.js.map +1 -0
  68. package/lib/module/errors.js +46 -0
  69. package/lib/module/errors.js.map +1 -0
  70. package/lib/module/generated/create-api.js +13 -0
  71. package/lib/module/generated/create-api.js.map +1 -0
  72. package/lib/module/generated/message-types.js +2 -0
  73. package/lib/module/generated/message-types.js.map +1 -0
  74. package/lib/module/generated/messages.js +43 -0
  75. package/lib/module/generated/messages.js.map +1 -0
  76. package/lib/module/generated/messages.pb.js +2787 -0
  77. package/lib/module/generated/messages.pb.js.map +1 -0
  78. package/lib/module/generated/method-map.js +64 -0
  79. package/lib/module/generated/method-map.js.map +1 -0
  80. package/lib/module/index.js +53 -0
  81. package/lib/module/index.js.map +1 -0
  82. package/lib/module/interceptors.js +15 -0
  83. package/lib/module/interceptors.js.map +1 -0
  84. package/lib/module/logging.js +50 -0
  85. package/lib/module/logging.js.map +1 -0
  86. package/lib/module/metro/index.js +25 -0
  87. package/lib/module/metro/index.js.map +1 -0
  88. package/lib/module/metro/transformer.js +29 -0
  89. package/lib/module/metro/transformer.js.map +1 -0
  90. package/lib/module/mock-server/index.js +120 -0
  91. package/lib/module/mock-server/index.js.map +1 -0
  92. package/lib/module/native-grpc/index.js +233 -0
  93. package/lib/module/native-grpc/index.js.map +1 -0
  94. package/lib/module/offline-queue.js +132 -0
  95. package/lib/module/offline-queue.js.map +1 -0
  96. package/lib/module/package.json +1 -0
  97. package/lib/module/path-templates.js +39 -0
  98. package/lib/module/path-templates.js.map +1 -0
  99. package/lib/module/react-query/index.js +25 -0
  100. package/lib/module/react-query/index.js.map +1 -0
  101. package/lib/module/streaming.js +246 -0
  102. package/lib/module/streaming.js.map +1 -0
  103. package/lib/module/transport.js +316 -0
  104. package/lib/module/transport.js.map +1 -0
  105. package/lib/module/types.js +4 -0
  106. package/lib/module/types.js.map +1 -0
  107. package/lib/module/validation/zod.js +43 -0
  108. package/lib/module/validation/zod.js.map +1 -0
  109. package/lib/module/version-check.js +93 -0
  110. package/lib/module/version-check.js.map +1 -0
  111. package/lib/typescript/src/auth.d.ts +26 -0
  112. package/lib/typescript/src/auth.d.ts.map +1 -0
  113. package/lib/typescript/src/client-factory.d.ts +7 -0
  114. package/lib/typescript/src/client-factory.d.ts.map +1 -0
  115. package/lib/typescript/src/codecs.d.ts +5 -0
  116. package/lib/typescript/src/codecs.d.ts.map +1 -0
  117. package/lib/typescript/src/connect/envelope.d.ts +18 -0
  118. package/lib/typescript/src/connect/envelope.d.ts.map +1 -0
  119. package/lib/typescript/src/connect/errors.d.ts +11 -0
  120. package/lib/typescript/src/connect/errors.d.ts.map +1 -0
  121. package/lib/typescript/src/errors.d.ts +21 -0
  122. package/lib/typescript/src/errors.d.ts.map +1 -0
  123. package/lib/typescript/src/generated/create-api.d.ts +34 -0
  124. package/lib/typescript/src/generated/create-api.d.ts.map +1 -0
  125. package/lib/typescript/src/generated/message-types.d.ts +54 -0
  126. package/lib/typescript/src/generated/message-types.d.ts.map +1 -0
  127. package/lib/typescript/src/generated/messages.d.ts +17 -0
  128. package/lib/typescript/src/generated/messages.d.ts.map +1 -0
  129. package/lib/typescript/src/generated/method-map.d.ts +7 -0
  130. package/lib/typescript/src/generated/method-map.d.ts.map +1 -0
  131. package/lib/typescript/src/index.d.ts +53 -0
  132. package/lib/typescript/src/index.d.ts.map +1 -0
  133. package/lib/typescript/src/interceptors.d.ts +17 -0
  134. package/lib/typescript/src/interceptors.d.ts.map +1 -0
  135. package/lib/typescript/src/logging.d.ts +16 -0
  136. package/lib/typescript/src/logging.d.ts.map +1 -0
  137. package/lib/typescript/src/metro/index.d.ts +15 -0
  138. package/lib/typescript/src/metro/index.d.ts.map +1 -0
  139. package/lib/typescript/src/metro/transformer.d.ts +16 -0
  140. package/lib/typescript/src/metro/transformer.d.ts.map +1 -0
  141. package/lib/typescript/src/mock-server/index.d.ts +27 -0
  142. package/lib/typescript/src/mock-server/index.d.ts.map +1 -0
  143. package/lib/typescript/src/native-grpc/index.d.ts +36 -0
  144. package/lib/typescript/src/native-grpc/index.d.ts.map +1 -0
  145. package/lib/typescript/src/offline-queue.d.ts +47 -0
  146. package/lib/typescript/src/offline-queue.d.ts.map +1 -0
  147. package/lib/typescript/src/path-templates.d.ts +17 -0
  148. package/lib/typescript/src/path-templates.d.ts.map +1 -0
  149. package/lib/typescript/src/react-query/index.d.ts +14 -0
  150. package/lib/typescript/src/react-query/index.d.ts.map +1 -0
  151. package/lib/typescript/src/streaming.d.ts +10 -0
  152. package/lib/typescript/src/streaming.d.ts.map +1 -0
  153. package/lib/typescript/src/transport.d.ts +19 -0
  154. package/lib/typescript/src/transport.d.ts.map +1 -0
  155. package/lib/typescript/src/types.d.ts +78 -0
  156. package/lib/typescript/src/types.d.ts.map +1 -0
  157. package/lib/typescript/src/validation/zod.d.ts +33 -0
  158. package/lib/typescript/src/validation/zod.d.ts.map +1 -0
  159. package/lib/typescript/src/version-check.d.ts +40 -0
  160. package/lib/typescript/src/version-check.d.ts.map +1 -0
  161. package/metro/index.js +23 -0
  162. package/metro/transformer.js +21 -0
  163. package/package.json +144 -0
  164. package/react-native-proto.podspec +15 -0
  165. package/src/auth.ts +97 -0
  166. package/src/client-factory.ts +109 -0
  167. package/src/codecs.ts +42 -0
  168. package/src/connect/envelope.ts +112 -0
  169. package/src/connect/errors.ts +86 -0
  170. package/src/errors.ts +81 -0
  171. package/src/generated/create-api.ts +40 -0
  172. package/src/generated/message-types.ts +63 -0
  173. package/src/generated/messages.pb.js +3207 -0
  174. package/src/generated/messages.ts +45 -0
  175. package/src/generated/method-map.ts +71 -0
  176. package/src/index.ts +113 -0
  177. package/src/interceptors.ts +32 -0
  178. package/src/logging.ts +67 -0
  179. package/src/metro/index.ts +27 -0
  180. package/src/metro/transformer.ts +38 -0
  181. package/src/mock-server/index.ts +164 -0
  182. package/src/native-grpc/index.ts +302 -0
  183. package/src/offline-queue.ts +160 -0
  184. package/src/path-templates.ts +65 -0
  185. package/src/react-query/index.ts +40 -0
  186. package/src/streaming.ts +326 -0
  187. package/src/transport.ts +427 -0
  188. package/src/types.ts +94 -0
  189. package/src/validation/zod.ts +75 -0
  190. package/src/version-check.ts +121 -0
@@ -0,0 +1,142 @@
1
+ package com.vishalsharma7nov.reactnativeproto;
2
+
3
+ import android.util.Base64;
4
+
5
+ import com.facebook.react.bridge.Promise;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
+ import com.facebook.react.bridge.ReactMethod;
9
+
10
+ import org.json.JSONObject;
11
+
12
+ import java.io.ByteArrayOutputStream;
13
+ import java.io.InputStream;
14
+ import java.io.OutputStream;
15
+ import java.net.HttpURLConnection;
16
+ import java.net.URL;
17
+ import java.util.Iterator;
18
+ import java.util.concurrent.ExecutorService;
19
+ import java.util.concurrent.Executors;
20
+
21
+ /**
22
+ * HTTP+protobuf unary bridge for transport "native-grpc".
23
+ * Uses HttpURLConnection (no extra Gradle deps).
24
+ */
25
+ public class ReactNativeProtoNativeGrpcModule extends ReactContextBaseJavaModule {
26
+ private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
27
+
28
+ public ReactNativeProtoNativeGrpcModule(ReactApplicationContext reactContext) {
29
+ super(reactContext);
30
+ }
31
+
32
+ @Override
33
+ public String getName() {
34
+ return "ReactNativeProtoNativeGrpc";
35
+ }
36
+
37
+ @ReactMethod
38
+ public void isAvailable(Promise promise) {
39
+ promise.resolve(true);
40
+ }
41
+
42
+ @ReactMethod
43
+ public void unary(
44
+ String baseUrl,
45
+ String rpcPath,
46
+ String requestBase64,
47
+ String headersJson,
48
+ double timeoutMs,
49
+ Promise promise
50
+ ) {
51
+ EXECUTOR.execute(() -> {
52
+ HttpURLConnection connection = null;
53
+ try {
54
+ if (baseUrl == null || baseUrl.isEmpty()) {
55
+ promise.reject("INVALID_ARGUMENT", "baseUrl is required");
56
+ return;
57
+ }
58
+ if (rpcPath == null || rpcPath.isEmpty()) {
59
+ promise.reject("INVALID_ARGUMENT", "rpcPath is required");
60
+ return;
61
+ }
62
+
63
+ byte[] body;
64
+ if (requestBase64 == null || requestBase64.isEmpty()) {
65
+ body = new byte[0];
66
+ } else {
67
+ body = Base64.decode(requestBase64, Base64.DEFAULT);
68
+ }
69
+
70
+ String path = rpcPath.startsWith("/") ? rpcPath : "/" + rpcPath;
71
+ String trimmedBase = baseUrl.endsWith("/")
72
+ ? baseUrl.substring(0, baseUrl.length() - 1)
73
+ : baseUrl;
74
+ URL url = new URL(trimmedBase + path);
75
+
76
+ connection = (HttpURLConnection) url.openConnection();
77
+ connection.setRequestMethod("POST");
78
+ connection.setDoOutput(true);
79
+ connection.setDoInput(true);
80
+ connection.setUseCaches(false);
81
+ connection.setRequestProperty("Content-Type", "application/x-protobuf");
82
+ connection.setRequestProperty("Accept", "application/x-protobuf");
83
+
84
+ int timeout = (int) Math.max(timeoutMs, 1);
85
+ connection.setConnectTimeout(timeout);
86
+ connection.setReadTimeout(timeout);
87
+
88
+ if (headersJson != null && headersJson.length() > 0) {
89
+ JSONObject headers = new JSONObject(headersJson);
90
+ Iterator<String> keys = headers.keys();
91
+ while (keys.hasNext()) {
92
+ String key = keys.next();
93
+ if (headers.isNull(key)) {
94
+ continue;
95
+ }
96
+ connection.setRequestProperty(key, headers.get(key).toString());
97
+ }
98
+ }
99
+
100
+ connection.setFixedLengthStreamingMode(body.length);
101
+ OutputStream out = connection.getOutputStream();
102
+ out.write(body);
103
+ out.flush();
104
+ out.close();
105
+
106
+ int status = connection.getResponseCode();
107
+ InputStream stream = status >= 200 && status < 300
108
+ ? connection.getInputStream()
109
+ : connection.getErrorStream();
110
+
111
+ byte[] responseBytes = readFully(stream);
112
+ if (status < 200 || status >= 300) {
113
+ promise.reject("HTTP_ERROR", "HTTP " + status);
114
+ return;
115
+ }
116
+
117
+ String responseBase64 = Base64.encodeToString(responseBytes, Base64.NO_WRAP);
118
+ promise.resolve(responseBase64);
119
+ } catch (Exception e) {
120
+ promise.reject("NETWORK", e.getMessage() != null ? e.getMessage() : "Network request failed", e);
121
+ } finally {
122
+ if (connection != null) {
123
+ connection.disconnect();
124
+ }
125
+ }
126
+ });
127
+ }
128
+
129
+ private static byte[] readFully(InputStream stream) throws Exception {
130
+ if (stream == null) {
131
+ return new byte[0];
132
+ }
133
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
134
+ byte[] chunk = new byte[4096];
135
+ int n;
136
+ while ((n = stream.read(chunk)) != -1) {
137
+ buffer.write(chunk, 0, n);
138
+ }
139
+ stream.close();
140
+ return buffer.toByteArray();
141
+ }
142
+ }
package/app.plugin.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Expo config plugin for @vishalsharma7nov/react-native-proto.
3
+ *
4
+ * Native iOS (react-native-proto.podspec) and Android
5
+ * (com.vishalsharma7nov.reactnativeproto) ship with the package and are
6
+ * normally picked up by React Native / Expo autolinking. This plugin is a
7
+ * lightweight hook for apps that list it under `plugins` in app.json / app.config.
8
+ *
9
+ * Usage in app.json:
10
+ * "plugins": ["@vishalsharma7nov/react-native-proto"]
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ function withReactNativeProto(config) {
16
+ let configPlugins;
17
+ try {
18
+ // Optional peer — Expo apps have this; plain RN apps may not.
19
+ configPlugins = require('@expo/config-plugins');
20
+ } catch (_err) {
21
+ console.warn(
22
+ '[react-native-proto] @expo/config-plugins not found; Expo plugin is a no-op. ' +
23
+ 'Native modules rely on autolinking (podspec + android package).'
24
+ );
25
+ return config;
26
+ }
27
+
28
+ const { createRunOncePlugin, withDangerousMod } = configPlugins;
29
+
30
+ const withNativeMods = (cfg) => {
31
+ cfg = withDangerousMod(cfg, [
32
+ 'ios',
33
+ async (config) => {
34
+ // Podspec at package root is autolinked; no Podfile edits required.
35
+ return config;
36
+ },
37
+ ]);
38
+
39
+ cfg = withDangerousMod(cfg, [
40
+ 'android',
41
+ async (config) => {
42
+ // Android package
43
+ // com.vishalsharma7nov.reactnativeproto.ReactNativeProtoNativeGrpcModule
44
+ // is autolinked when the library is installed.
45
+ return config;
46
+ },
47
+ ]);
48
+
49
+ return cfg;
50
+ };
51
+
52
+ if (typeof createRunOncePlugin === 'function') {
53
+ return createRunOncePlugin(
54
+ withNativeMods,
55
+ 'react-native-proto',
56
+ '0.1.0'
57
+ )(config);
58
+ }
59
+
60
+ return withNativeMods(config);
61
+ }
62
+
63
+ module.exports = withReactNativeProto;