@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 @@
1
+ {"version":3,"file":"offline-queue.d.ts","sourceRoot":"","sources":["../../../src/offline-queue.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,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AC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IA8BtD,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,IAAI;YAME,OAAO;CAItB"}
@@ -0,0 +1,17 @@
1
+ import type { MethodMapEntry } from './types';
2
+ export type PathTemplatePreset = 'connect' | 'grpc-web' | 'envoy' | 'grpc-gateway' | 'restish';
3
+ /**
4
+ * Built-in path builders for common gateways and proxies.
5
+ *
6
+ * - connect / grpc-web / envoy: `/{package}.{Service}/{Method}`
7
+ * - grpc-gateway: `/{package}.{Service}/{Method}` (HTTP body RPC style)
8
+ * - restish: `/v1/{service}/{method}` (lowercase camel segments)
9
+ */
10
+ export declare function createPathForMethod(preset?: PathTemplatePreset): (entry: MethodMapEntry) => string;
11
+ /**
12
+ * Custom template. Placeholders:
13
+ * `{package}` `{service}` `{method}` `{rpcPath}`
14
+ * `{serviceCamel}` `{methodCamel}`
15
+ */
16
+ export declare function pathFromTemplate(template: string): (entry: MethodMapEntry) => string;
17
+ //# sourceMappingURL=path-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-templates.d.ts","sourceRoot":"","sources":["../../../src/path-templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAC1B,SAAS,GACT,UAAU,GACV,OAAO,GACP,cAAc,GACd,SAAS,CAAC;AAWd;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,kBAA8B,GACrC,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAanC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,GACf,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAenC"}
@@ -0,0 +1,14 @@
1
+ import type { QueryKey, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
2
+ type UnaryFn<TReq, TRes> = (request: TReq) => Promise<TRes>;
3
+ /**
4
+ * Thin React Query wrapper around a generated unary client method.
5
+ */
6
+ export declare function useProtoQuery<TReq extends object, TRes>(method: UnaryFn<TReq, TRes>, request: TReq, options?: Omit<UseQueryOptions<TRes, Error, TRes, QueryKey>, 'queryKey' | 'queryFn'> & {
7
+ queryKey?: QueryKey;
8
+ }): import("@tanstack/react-query").UseQueryResult<TRes, Error>;
9
+ /**
10
+ * Thin React Query mutation wrapper around a generated unary client method.
11
+ */
12
+ export declare function useProtoMutation<TReq extends object, TRes>(method: UnaryFn<TReq, TRes>, options?: UseMutationOptions<TRes, Error, TReq>): import("@tanstack/react-query").UseMutationResult<TRes, Error, TReq, unknown>;
13
+ export {};
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/react-query/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAG/B,KAAK,OAAO,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5D;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EACrD,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAC3B,OAAO,EAAE,IAAI,EACb,OAAO,CAAC,EAAE,IAAI,CACZ,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,EAC5C,UAAU,GAAG,SAAS,CACvB,GAAG;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,+DAQ5B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EACxD,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAC3B,OAAO,CAAC,EAAE,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,iFAMhD"}
@@ -0,0 +1,10 @@
1
+ import { type ResolvedTransportConfig } from './transport';
2
+ import type { CodecRegistry, StreamCallInput } from './types';
3
+ /**
4
+ * Streaming helpers.
5
+ * - HTTP+protobuf: unary only
6
+ * - Connect: server-streaming via envelope frames; client/bidi send enveloped requests
7
+ * - native-grpc: bridge streaming when available
8
+ */
9
+ export declare function streamCall(config: ResolvedTransportConfig, codecs: CodecRegistry, input: StreamCallInput): AsyncGenerator<Record<string, unknown>, void, undefined>;
10
+ //# sourceMappingURL=streaming.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../src/streaming.ts"],"names":[],"mappings":"AAYA,OAAO,EAA2B,KAAK,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAgB,eAAe,EAAE,MAAM,SAAS,CAAC;AAmR5E;;;;;GAKG;AACH,wBAAuB,UAAU,CAC/B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,eAAe,GACrB,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CA2B1D"}
@@ -0,0 +1,19 @@
1
+ import { type Interceptor } from "./interceptors";
2
+ import type { HeaderMap, MethodMapEntry, ProtoClientConfig, UnaryCallInput } from "./types";
3
+ import type { CodecRegistry } from "./types";
4
+ export type ResolvedTransportConfig = {
5
+ baseUrl: string;
6
+ timeoutMs: number;
7
+ maxResponseBytes: number;
8
+ transport: NonNullable<ProtoClientConfig["transport"]>;
9
+ getHeaders?: ProtoClientConfig["getHeaders"];
10
+ fetchImpl: typeof fetch;
11
+ onError?: ProtoClientConfig["onError"];
12
+ pathForMethod: (entry: MethodMapEntry) => string;
13
+ interceptors: Interceptor[];
14
+ retryOnUnauthorized: boolean;
15
+ };
16
+ export declare function resolveConfig(config: ProtoClientConfig): ResolvedTransportConfig;
17
+ export declare function buildHeaders(config: ResolvedTransportConfig, contentType: string, rpcPath: string, extra?: HeaderMap): Promise<Record<string, string>>;
18
+ export declare function unaryCall(config: ResolvedTransportConfig, codecs: CodecRegistry, input: UnaryCallInput): Promise<Record<string, unknown>>;
19
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/transport.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAM7C,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,WAAW,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;IACvD,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,SAAS,EAAE,OAAO,KAAK,CAAC;IACxB,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACvC,aAAa,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAAC;IACjD,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,iBAAiB,GACxB,uBAAuB,CA0EzB;AAED,wBAAsB,YAAY,CAChC,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,SAAS,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA2CjC;AAyND,wBAAsB,SAAS,CAC7B,MAAM,EAAE,uBAAuB,EAC/B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA8ClC"}
@@ -0,0 +1,78 @@
1
+ import type { Type } from 'protobufjs';
2
+ import type { Interceptor } from './interceptors';
3
+ import type { PathTemplatePreset } from './path-templates';
4
+ export type TransportKind = 'http' | 'connect' | 'native-grpc';
5
+ export type HeaderMap = Record<string, string>;
6
+ export type ProtoClientConfig = {
7
+ /** API origin, for example https://api.example.com */
8
+ baseUrl: string;
9
+ /** Optional per-request headers (auth tokens, app version, etc.) */
10
+ getHeaders?: () => HeaderMap | Promise<HeaderMap>;
11
+ /** Request timeout in milliseconds (default 30000) */
12
+ timeoutMs?: number;
13
+ /** Maximum accepted response body size in bytes (default 2 MiB) */
14
+ maxResponseBytes?: number;
15
+ /** How calls are sent to the server */
16
+ transport?: TransportKind;
17
+ /** Custom fetch implementation (tests / polyfills) */
18
+ fetch?: typeof fetch;
19
+ /** Optional logging hook — errors are still thrown */
20
+ onError?: (error: import('./errors').ProtoClientError) => void;
21
+ /**
22
+ * Builds the HTTP path for a service method.
23
+ * Default: /{package}.{Service}/{Method}
24
+ */
25
+ pathForMethod?: (entry: MethodMapEntry) => string;
26
+ /** Shortcut for built-in path presets (ignored if pathForMethod is set) */
27
+ pathPreset?: PathTemplatePreset;
28
+ /** Unary interceptor pipeline (auth, logging, etc.) */
29
+ interceptors?: Interceptor[];
30
+ /**
31
+ * When true (default), retry a unary call once after auth interceptor refresh
32
+ * is handled inside createAuthInterceptor — this flag reserved for transport-level 401.
33
+ */
34
+ retryOnUnauthorized?: boolean;
35
+ };
36
+ export type MethodKind = 'unary' | 'serverStreaming' | 'clientStreaming' | 'bidi';
37
+ export type MethodMapEntry = {
38
+ serviceName: string;
39
+ methodName: string;
40
+ packageName: string;
41
+ rpcPath: string;
42
+ requestType: string;
43
+ responseType: string;
44
+ kind: MethodKind;
45
+ };
46
+ export type MethodMap = ReadonlyArray<MethodMapEntry>;
47
+ export type MessageCodec = {
48
+ encode: (message: Record<string, unknown>) => Uint8Array;
49
+ decode: (bytes: Uint8Array) => Record<string, unknown>;
50
+ };
51
+ export type CodecRegistry = {
52
+ get(typeName: string): MessageCodec | undefined;
53
+ has(typeName: string): boolean;
54
+ };
55
+ export type UnaryCallInput = {
56
+ entry: MethodMapEntry;
57
+ request: Record<string, unknown>;
58
+ signal?: AbortSignal;
59
+ /** Extra headers merged for this call (from interceptors) */
60
+ headers?: HeaderMap;
61
+ };
62
+ export type StreamCallInput = UnaryCallInput & {
63
+ onMessage?: (message: Record<string, unknown>) => void;
64
+ /** Client-streaming / bidi: async iterable of request messages */
65
+ requests?: AsyncIterable<Record<string, unknown>> | Iterable<Record<string, unknown>>;
66
+ };
67
+ export type ClientServices = {
68
+ [serviceName: string]: {
69
+ [methodName: string]: (request?: Record<string, unknown>, options?: {
70
+ signal?: AbortSignal;
71
+ }) => Promise<Record<string, unknown>> | AsyncIterable<Record<string, unknown>>;
72
+ };
73
+ };
74
+ export type ProtoClient = ClientServices & {
75
+ readonly config: Readonly<Required<Pick<ProtoClientConfig, 'baseUrl' | 'timeoutMs' | 'maxResponseBytes' | 'transport'>>> & ProtoClientConfig;
76
+ };
77
+ export type ProtobufTypeLike = Pick<Type, 'encode' | 'decode' | 'create' | 'fromObject'>;
78
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS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M,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KAChF,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG;IACzC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAChC,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,WAAW,GAAG,kBAAkB,GAAG,WAAW,CAAC,CACpF,CAAC,GACA,iBAAiB,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { MessageCodec } from "../types";
2
+ export type ZodLikeSchema<T = unknown> = {
3
+ parse: (data: unknown) => T;
4
+ safeParse?: (data: unknown) => {
5
+ success: true;
6
+ data: T;
7
+ } | {
8
+ success: false;
9
+ error: unknown;
10
+ };
11
+ };
12
+ /**
13
+ * Wrap a protobuf codec with optional Zod (or Zod-compatible) request/response
14
+ * validation. Peer dependency: install `zod` in your app.
15
+ */
16
+ export declare function withZodValidation(codec: MessageCodec, options: {
17
+ request?: ZodLikeSchema<Record<string, unknown>>;
18
+ response?: ZodLikeSchema<Record<string, unknown>>;
19
+ }): MessageCodec;
20
+ /**
21
+ * Apply Zod schemas to selected type names in a codec registry.
22
+ */
23
+ export declare function wrapCodecRegistryWithZod(registry: {
24
+ get(typeName: string): MessageCodec | undefined;
25
+ has(typeName: string): boolean;
26
+ }, schemas: Record<string, {
27
+ request?: ZodLikeSchema;
28
+ response?: ZodLikeSchema;
29
+ } | ZodLikeSchema>): {
30
+ get(typeName: string): MessageCodec | undefined;
31
+ has(typeName: string): boolean;
32
+ };
33
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../../src/validation/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACvC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,CACV,IAAI,EAAE,OAAO,KACV;QAAE,OAAO,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,CAAC,CAAA;KAAE,GAAG;QAAE,OAAO,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;CACtE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD,GACA,YAAY,CAad;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE;IACR,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAChD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC,EACD,OAAO,EAAE,MAAM,CACb,MAAM,EACN;IAAE,OAAO,CAAC,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,GAAG,aAAa,CACtE,GACA;IACD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IAChD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC,CAyBA"}
@@ -0,0 +1,40 @@
1
+ import type { HeaderMap } from './types';
2
+ import type { Interceptor } from './interceptors';
3
+ export declare const CLIENT_VERSION_HEADER = "X-React-Native-Proto-Client-Version";
4
+ export declare const SERVER_MIN_CLIENT_HEADER = "X-React-Native-Proto-Min-Client-Version";
5
+ export declare const METHOD_MAP_HASH_HEADER = "X-React-Native-Proto-Method-Map-Hash";
6
+ export type VersionCheckOptions = {
7
+ /** Semver or opaque version string sent on every request */
8
+ clientVersion: string;
9
+ /** Optional hash/fingerprint of the generated method map */
10
+ methodMapHash?: string;
11
+ /**
12
+ * If the response includes SERVER_MIN_CLIENT_HEADER and client is older,
13
+ * throw (default) or only warn via onMismatch.
14
+ */
15
+ mode?: 'throw' | 'warn';
16
+ onMismatch?: (info: {
17
+ clientVersion: string;
18
+ serverMinClientVersion: string;
19
+ }) => void;
20
+ compareVersions?: (client: string, serverMin: string) => number;
21
+ };
22
+ /** Simple dotted numeric compare: 1.2.0 vs 1.10.0. Non-numeric falls back to string cmp. */
23
+ export declare function compareDottedVersions(a: string, b: string): number;
24
+ export declare function versionHeaders(options: {
25
+ clientVersion: string;
26
+ methodMapHash?: string;
27
+ }): HeaderMap;
28
+ /**
29
+ * Attaches client version headers. Pair with `assertServerMinClient` after responses
30
+ * if you read response headers in a custom transport; for the default HTTP path,
31
+ * use `createVersionInterceptor` which only sends headers (response check needs
32
+ * fetch wrapper — see createVersionAwareFetch).
33
+ */
34
+ export declare function createVersionInterceptor(options: VersionCheckOptions): Interceptor;
35
+ export declare function assertServerMinClient(serverMinClientVersion: string | null | undefined, options: VersionCheckOptions): void;
36
+ /**
37
+ * Wraps fetch to validate SERVER_MIN_CLIENT_HEADER on each response.
38
+ */
39
+ export declare function createVersionAwareFetch(baseFetch: typeof fetch, options: VersionCheckOptions): typeof fetch;
40
+ //# sourceMappingURL=version-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-check.d.ts","sourceRoot":"","sources":["../../../src/version-check.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,eAAO,MAAM,qBAAqB,wCAAwC,CAAC;AAC3E,eAAO,MAAM,wBAAwB,4CAA4C,CAAC;AAClF,eAAO,MAAM,sBAAsB,yCAAyC,CAAC;AAE7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAClB,aAAa,EAAE,MAAM,CAAC;QACtB,sBAAsB,EAAE,MAAM,CAAC;KAChC,KAAK,IAAI,CAAC;IACX,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CACjE,CAAC;AAEF,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAclE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GAAG,SAAS,CAQZ;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,mBAAmB,GAC3B,WAAW,CAWb;AAED,wBAAgB,qBAAqB,CACnC,sBAAsB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjD,OAAO,EAAE,mBAAmB,GAC3B,IAAI,CAmBN;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,OAAO,KAAK,EACvB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,KAAK,CAcd"}
package/metro/index.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Metro config helper (CommonJS entry for metro.config.js).
3
+ */
4
+ function createProtoMetroConfig(baseConfig) {
5
+ const resolver = baseConfig.resolver || {};
6
+ const sourceExts = new Set([...(resolver.sourceExts || []), 'proto']);
7
+ const assetExts = (resolver.assetExts || []).filter((ext) => ext !== 'proto');
8
+
9
+ return {
10
+ ...baseConfig,
11
+ resolver: {
12
+ ...resolver,
13
+ sourceExts: Array.from(sourceExts),
14
+ assetExts,
15
+ },
16
+ transformer: {
17
+ ...(baseConfig.transformer || {}),
18
+ babelTransformerPath: require.resolve('./transformer'),
19
+ },
20
+ };
21
+ }
22
+
23
+ module.exports = { createProtoMetroConfig };
@@ -0,0 +1,21 @@
1
+ async function transform(args) {
2
+ const { filename, src } = args;
3
+
4
+ if (!filename.endsWith('.proto')) {
5
+ try {
6
+ const upstream = require('@react-native/metro-babel-transformer');
7
+ if (upstream && typeof upstream.transform === 'function') {
8
+ return upstream.transform(args);
9
+ }
10
+ } catch (_err) {
11
+ // fall through
12
+ }
13
+ }
14
+
15
+ return {
16
+ code: `module.exports = ${JSON.stringify(src)};`,
17
+ map: null,
18
+ };
19
+ }
20
+
21
+ module.exports = { transform };
package/package.json ADDED
@@ -0,0 +1,144 @@
1
+ {
2
+ "name": "@vishalsharma7nov/react-native-proto",
3
+ "version": "0.2.2",
4
+ "description": "Dynamic React Native protobuf client with generate CLI, HTTP/Connect transports, interceptors, and typed errors",
5
+ "main": "lib/commonjs/index.js",
6
+ "module": "lib/module/index.js",
7
+ "types": "lib/typescript/src/index.d.ts",
8
+ "react-native": "src/index.ts",
9
+ "source": "src/index.ts",
10
+ "bin": {
11
+ "react-native-proto": "./bin/react-native-proto.js"
12
+ },
13
+ "files": [
14
+ "src",
15
+ "lib",
16
+ "bin",
17
+ "metro",
18
+ "android",
19
+ "ios",
20
+ "app.plugin.js",
21
+ "react-native-proto.podspec",
22
+ "!**/__tests__",
23
+ "!**/__fixtures__",
24
+ "!**/__mocks__"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./lib/typescript/src/index.d.ts",
29
+ "react-native": "./src/index.ts",
30
+ "import": "./lib/module/index.js",
31
+ "require": "./lib/commonjs/index.js"
32
+ },
33
+ "./react-query": {
34
+ "types": "./lib/typescript/src/react-query/index.d.ts",
35
+ "react-native": "./src/react-query/index.ts",
36
+ "import": "./lib/module/react-query/index.js",
37
+ "require": "./lib/commonjs/react-query/index.js"
38
+ },
39
+ "./metro": {
40
+ "types": "./lib/typescript/src/metro/index.d.ts",
41
+ "import": "./lib/module/metro/index.js",
42
+ "require": "./lib/commonjs/metro/index.js",
43
+ "default": "./src/metro/index.ts"
44
+ },
45
+ "./mock-server": {
46
+ "types": "./lib/typescript/src/mock-server/index.d.ts",
47
+ "import": "./lib/module/mock-server/index.js",
48
+ "require": "./lib/commonjs/mock-server/index.js"
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
52
+ "scripts": {
53
+ "build": "bob build",
54
+ "prepare": "node -e \"process.exit(0)\"",
55
+ "prepublishOnly": "bob build",
56
+ "typecheck": "tsc --noEmit",
57
+ "lint": "eslint src __tests__ --ext .ts,.tsx,.js",
58
+ "test": "jest",
59
+ "clean": "rm -rf lib"
60
+ },
61
+ "keywords": [
62
+ "react-native",
63
+ "protobuf",
64
+ "proto",
65
+ "grpc",
66
+ "connect",
67
+ "client"
68
+ ],
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "https://github.com/vishalsharma7nov/react-native-proto.git"
72
+ },
73
+ "author": "vishalsharma7nov",
74
+ "license": "MIT",
75
+ "publishConfig": {
76
+ "registry": "https://npm.pkg.github.com",
77
+ "access": "public"
78
+ },
79
+ "peerDependencies": {
80
+ "@tanstack/react-query": ">=4.0.0",
81
+ "react": "*",
82
+ "react-native": "*",
83
+ "zod": ">=3.0.0"
84
+ },
85
+ "peerDependenciesMeta": {
86
+ "@tanstack/react-query": {
87
+ "optional": true
88
+ },
89
+ "react": {
90
+ "optional": true
91
+ },
92
+ "react-native": {
93
+ "optional": true
94
+ },
95
+ "zod": {
96
+ "optional": true
97
+ }
98
+ },
99
+ "dependencies": {
100
+ "protobufjs": "^7.4.0"
101
+ },
102
+ "devDependencies": {
103
+ "@tanstack/react-query": "^5.62.0",
104
+ "@types/jest": "^29.5.14",
105
+ "@types/node": "^22.10.0",
106
+ "@types/react": "^18.3.12 || ^19.1.0",
107
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
108
+ "@typescript-eslint/parser": "^8.15.0",
109
+ "eslint": "^8.57.1",
110
+ "jest": "^29.7.0",
111
+ "protobufjs-cli": "^1.1.3",
112
+ "react-native-builder-bob": "^0.35.2",
113
+ "ts-jest": "^29.2.5",
114
+ "typescript": "^5.6.3",
115
+ "zod": "^3.24.1"
116
+ },
117
+ "react-native-builder-bob": {
118
+ "source": "src",
119
+ "output": "lib",
120
+ "targets": [
121
+ "commonjs",
122
+ "module",
123
+ [
124
+ "typescript",
125
+ {
126
+ "project": "tsconfig.build.json"
127
+ }
128
+ ]
129
+ ]
130
+ },
131
+ "jest": {
132
+ "preset": "ts-jest",
133
+ "testEnvironment": "node",
134
+ "testMatch": [
135
+ "**/__tests__/**/*.test.ts"
136
+ ],
137
+ "modulePathIgnorePatterns": [
138
+ "<rootDir>/lib/"
139
+ ]
140
+ },
141
+ "expo": {
142
+ "plugin": "./app.plugin.js"
143
+ }
144
+ }
@@ -0,0 +1,15 @@
1
+ require('../metro/podspec.rb') if false
2
+
3
+ Pod::Spec.new do |s|
4
+ s.name = "react-native-proto"
5
+ s.version = "0.1.0"
6
+ s.summary = "Native HTTP+protobuf gRPC bridge for react-native-proto"
7
+ s.homepage = "https://github.com/vishalsharma7nov/react-native-proto"
8
+ s.license = "MIT"
9
+ s.authors = "vishalsharma7nov"
10
+ s.platforms = { :ios => "13.0" }
11
+ s.source = { :git => "https://github.com/vishalsharma7nov/react-native-proto.git", :tag => "v#{s.version}" }
12
+ # Includes ios/ReactNativeProtoNativeGrpc.m (NSURLSession unary)
13
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
14
+ s.dependency "React-Core"
15
+ end
package/src/auth.ts ADDED
@@ -0,0 +1,97 @@
1
+ import { isProtoClientError } from "./errors";
2
+ import type { Interceptor } from "./interceptors";
3
+ import type { HeaderMap } from "./types";
4
+
5
+ export type AuthInterceptorOptions = {
6
+ /** Return the current access token (without "Bearer " prefix unless you prefer that). */
7
+ getAccessToken: () => string | null | Promise<string | null>;
8
+ /** Header name (default Authorization) */
9
+ headerName?: string;
10
+ /** Prefix before token (default "Bearer ") */
11
+ scheme?: string;
12
+ /**
13
+ * Called once when the server returns unauthorized; should refresh and return
14
+ * a new token. The failed call is retried once with the new token.
15
+ */
16
+ refreshAccessToken?: () => Promise<string | null>;
17
+ /** Decide whether an error should trigger refresh (default: HTTP 401 or UNAUTHENTICATED). */
18
+ isUnauthorized?: (error: unknown) => boolean;
19
+ };
20
+
21
+ function defaultIsUnauthorized(error: unknown): boolean {
22
+ if (!isProtoClientError(error)) {
23
+ return false;
24
+ }
25
+ if (error.status === 401) {
26
+ return true;
27
+ }
28
+ const msg = error.message.toLowerCase();
29
+ return (
30
+ error.code === "RPC" &&
31
+ (msg.includes("unauthenticated") || msg.includes("unauthorized"))
32
+ );
33
+ }
34
+
35
+ /**
36
+ * Adds Authorization (or custom) headers and optionally retries once after refresh.
37
+ */
38
+ export function createAuthInterceptor(
39
+ options: AuthInterceptorOptions,
40
+ ): Interceptor {
41
+ const headerName = options.headerName ?? "Authorization";
42
+ const scheme = options.scheme ?? "Bearer ";
43
+ const isUnauthorized = options.isUnauthorized ?? defaultIsUnauthorized;
44
+
45
+ return async (ctx, next) => {
46
+ const applyToken = (
47
+ headers: HeaderMap,
48
+ token: string | null,
49
+ ): HeaderMap => {
50
+ if (!token) {
51
+ return headers;
52
+ }
53
+ return {
54
+ ...headers,
55
+ [headerName]: token.startsWith(scheme) ? token : `${scheme}${token}`,
56
+ };
57
+ };
58
+
59
+ const token = await options.getAccessToken();
60
+ const firstCtx = {
61
+ ...ctx,
62
+ headers: applyToken(ctx.headers, token),
63
+ };
64
+
65
+ try {
66
+ return await next(firstCtx);
67
+ } catch (error) {
68
+ if (!options.refreshAccessToken || !isUnauthorized(error)) {
69
+ throw error;
70
+ }
71
+
72
+ const refreshed = await options.refreshAccessToken();
73
+ const retryCtx = {
74
+ ...ctx,
75
+ headers: applyToken(ctx.headers, refreshed),
76
+ };
77
+ return next(retryCtx);
78
+ }
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Simple helper that only injects a static or async token (no refresh).
84
+ */
85
+ export function createBearerTokenHeaders(
86
+ getToken: () => string | null | Promise<string | null>,
87
+ ): () => Promise<HeaderMap> {
88
+ return async (): Promise<HeaderMap> => {
89
+ const token = await getToken();
90
+ if (!token) {
91
+ return {};
92
+ }
93
+ return {
94
+ Authorization: token.startsWith('Bearer ') ? token : `Bearer ${token}`,
95
+ };
96
+ };
97
+ }