theta-client-react-native 1.14.0 → 1.15.0

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 (46) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/ricoh360/thetaclientreactnative/ThetaClientSdkModule.kt +68 -48
  3. package/ios/ThetaClientReactNative.swift +101 -65
  4. package/lib/commonjs/NativeThetaClientReactNative.js +31 -2
  5. package/lib/commonjs/NativeThetaClientReactNative.js.map +1 -1
  6. package/lib/commonjs/theta-repository/libs/convert-utils.js +19 -0
  7. package/lib/commonjs/theta-repository/libs/convert-utils.js.map +1 -1
  8. package/lib/commonjs/theta-repository/libs/index.js +11 -0
  9. package/lib/commonjs/theta-repository/libs/index.js.map +1 -1
  10. package/lib/commonjs/theta-repository/libs/type-guards.js +13 -0
  11. package/lib/commonjs/theta-repository/libs/type-guards.js.map +1 -0
  12. package/lib/commonjs/theta-repository/theta-repository.js +7 -0
  13. package/lib/commonjs/theta-repository/theta-repository.js.map +1 -1
  14. package/lib/commonjs/theta-repository/theta-web-api-error.js +62 -0
  15. package/lib/commonjs/theta-repository/theta-web-api-error.js.map +1 -0
  16. package/lib/module/NativeThetaClientReactNative.js +31 -2
  17. package/lib/module/NativeThetaClientReactNative.js.map +1 -1
  18. package/lib/module/theta-repository/libs/convert-utils.js +17 -0
  19. package/lib/module/theta-repository/libs/convert-utils.js.map +1 -1
  20. package/lib/module/theta-repository/libs/index.js +1 -0
  21. package/lib/module/theta-repository/libs/index.js.map +1 -1
  22. package/lib/module/theta-repository/libs/type-guards.js +7 -0
  23. package/lib/module/theta-repository/libs/type-guards.js.map +1 -0
  24. package/lib/module/theta-repository/theta-repository.js +1 -0
  25. package/lib/module/theta-repository/theta-repository.js.map +1 -1
  26. package/lib/module/theta-repository/theta-web-api-error.js +54 -0
  27. package/lib/module/theta-repository/theta-web-api-error.js.map +1 -0
  28. package/lib/typescript/NativeThetaClientReactNative.d.ts.map +1 -1
  29. package/lib/typescript/theta-repository/libs/convert-utils.d.ts +2 -0
  30. package/lib/typescript/theta-repository/libs/convert-utils.d.ts.map +1 -1
  31. package/lib/typescript/theta-repository/libs/index.d.ts +1 -0
  32. package/lib/typescript/theta-repository/libs/index.d.ts.map +1 -1
  33. package/lib/typescript/theta-repository/libs/type-guards.d.ts +5 -0
  34. package/lib/typescript/theta-repository/libs/type-guards.d.ts.map +1 -0
  35. package/lib/typescript/theta-repository/theta-repository.d.ts +1 -0
  36. package/lib/typescript/theta-repository/theta-repository.d.ts.map +1 -1
  37. package/lib/typescript/theta-repository/theta-web-api-error.d.ts +15 -0
  38. package/lib/typescript/theta-repository/theta-web-api-error.d.ts.map +1 -0
  39. package/package.json +1 -1
  40. package/src/NativeThetaClientReactNative.ts +50 -2
  41. package/src/theta-repository/libs/convert-utils.ts +19 -0
  42. package/src/theta-repository/libs/index.ts +1 -0
  43. package/src/theta-repository/libs/type-guards.ts +10 -0
  44. package/src/theta-repository/theta-repository.ts +1 -0
  45. package/src/theta-repository/theta-web-api-error.ts +81 -0
  46. package/theta-client-react-native.podspec +1 -1
@@ -1,5 +1,7 @@
1
1
  import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
+ import { normalizeNativeError } from './theta-repository/theta-web-api-error';
4
+ import { isPromiseLike } from './theta-repository/libs';
3
5
 
4
6
  export interface Spec extends TurboModule {
5
7
  // Event listeners for Android old architecture only
@@ -193,7 +195,53 @@ export default new Proxy({} as Spec, {
193
195
  get(_, prop: string | symbol) {
194
196
  const module = getModule();
195
197
  const value = module[prop as keyof Spec];
196
- // Return the value directly - if it's a function, it will be callable
197
- return value;
198
+ if (typeof value !== 'function') {
199
+ return value;
200
+ }
201
+
202
+ // Wrap native async methods so rejected promises carry parsed THETA Web API details,
203
+ // without adding extra microtask ticks on the success path.
204
+ return (...args: unknown[]) => {
205
+ const result = (value as (...innerArgs: unknown[]) => unknown).apply(
206
+ module,
207
+ args
208
+ );
209
+ if (!isPromiseLike(result)) {
210
+ return result;
211
+ }
212
+ // Wrap the original promise in a Proxy that intercepts .then()/.catch() to
213
+ // normalize errors, while preserving the microtask timing of the original
214
+ // promise on the success path (no extra .then() hops added).
215
+ return new Proxy(result, {
216
+ get(target, p) {
217
+ if (p === 'then') {
218
+ return (
219
+ onFulfilled: ((value: unknown) => unknown) | null | undefined,
220
+ onRejected: ((reason: unknown) => unknown) | null | undefined
221
+ ) => {
222
+ const normalizedRejected = (err: unknown): unknown =>
223
+ onRejected != null
224
+ ? onRejected(normalizeNativeError(err))
225
+ : Promise.reject(normalizeNativeError(err));
226
+ return (target as PromiseLike<unknown>).then(
227
+ onFulfilled ?? undefined,
228
+ normalizedRejected
229
+ );
230
+ };
231
+ }
232
+ if (p === 'catch') {
233
+ return (
234
+ onRejected: ((reason: unknown) => unknown) | null | undefined
235
+ ) =>
236
+ (target as Promise<unknown>).catch((err: unknown) =>
237
+ onRejected != null
238
+ ? onRejected(normalizeNativeError(err))
239
+ : Promise.reject(normalizeNativeError(err))
240
+ );
241
+ }
242
+ return (target as unknown as Record<string | symbol, unknown>)[p];
243
+ },
244
+ });
245
+ };
198
246
  },
199
247
  });
@@ -1,5 +1,24 @@
1
1
  import type { Options } from '../options';
2
2
 
3
+ export function toNumber(value: unknown): number | undefined {
4
+ if (typeof value === 'number' && Number.isFinite(value)) {
5
+ return value;
6
+ }
7
+ if (typeof value === 'string') {
8
+ const parsed = Number(value);
9
+ return Number.isFinite(parsed) ? parsed : undefined;
10
+ }
11
+ if (value != null && typeof value === 'object' && 'valueOf' in value) {
12
+ const primitive = (value as { valueOf: () => unknown }).valueOf();
13
+ return toNumber(primitive);
14
+ }
15
+ return undefined;
16
+ }
17
+
18
+ export function toStringValue(value: unknown): string | undefined {
19
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
20
+ }
21
+
3
22
  export function convertOptions(
4
23
  options: Options,
5
24
  jsonOptions?: Record<string, string>
@@ -1,2 +1,3 @@
1
1
  export * from './convert-video-formats';
2
2
  export * from './convert-utils';
3
+ export * from './type-guards';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type guard to check if a value is promise-like (has a `then` method).
3
+ */
4
+ export function isPromiseLike<T>(value: unknown): value is Promise<T> {
5
+ return (
6
+ value != null &&
7
+ (typeof value === 'object' || typeof value === 'function') &&
8
+ typeof (value as { then?: unknown }).then === 'function'
9
+ );
10
+ }
@@ -35,6 +35,7 @@ import type { ThetaTimeout } from './theta-timeout';
35
35
  import { NotifyController } from './notify-controller';
36
36
  import { EventWebSocket } from './event-websocket';
37
37
  import { convertOptions, convertVideoFormatsImpl } from './libs';
38
+ export { ThetaWebApiError } from './theta-web-api-error';
38
39
 
39
40
  const NOTIFY_API_LOG = 'API-LOG';
40
41
  let apiLogListener: ((message: string) => void) | undefined;
@@ -0,0 +1,81 @@
1
+ import { toNumber, toStringValue } from './libs/convert-utils';
2
+
3
+ export class ThetaWebApiError extends Error {
4
+ statusCode?: number;
5
+ errorCode?: string;
6
+ moduleError?: Error;
7
+
8
+ constructor(
9
+ message: Error['message'],
10
+ statusCode?: number,
11
+ errorCode?: string,
12
+ e?: unknown
13
+ ) {
14
+ super(message);
15
+ this.name = 'ThetaWebApiError';
16
+ this.statusCode = statusCode;
17
+ this.errorCode = errorCode;
18
+ this.moduleError = e instanceof Error ? e : undefined;
19
+ }
20
+ }
21
+
22
+ type NativeErrorLike = {
23
+ message?: unknown;
24
+ userInfo?: Record<string, unknown>;
25
+ };
26
+
27
+ /**
28
+ * Extract THETA Web API error details from a native bridge error.
29
+ *
30
+ * Current bridge contract:
31
+ * - message: native error message (fallback to Error/String representation)
32
+ * - statusCode: nativeError.userInfo.statusCode
33
+ * - errorCode: nativeError.userInfo.errorCode
34
+ *
35
+ * Returns undefined when neither statusCode nor errorCode is available.
36
+ */
37
+ function _extractThetaWebApiError(
38
+ error: unknown
39
+ ): ThetaWebApiError | undefined {
40
+ if (error == null || typeof error !== 'object') {
41
+ return undefined;
42
+ }
43
+
44
+ const nativeError = error as NativeErrorLike;
45
+ const message =
46
+ toStringValue(nativeError.message) ??
47
+ (error instanceof Error ? error.message : String(error));
48
+
49
+ const statusCode = toNumber(nativeError.userInfo?.statusCode);
50
+ const errorCode = toStringValue(nativeError.userInfo?.errorCode);
51
+
52
+ if (statusCode == null && errorCode == null) {
53
+ return undefined;
54
+ }
55
+
56
+ return new ThetaWebApiError(message, statusCode, errorCode, error);
57
+ }
58
+
59
+ /**
60
+ * Normalize a native bridge error into Error with THETA Web API details.
61
+ *
62
+ * If THETA Web API details are not available, returns the original Error when
63
+ * possible, otherwise creates a generic Error.
64
+ * String errors are returned as-is.
65
+ */
66
+ export function normalizeNativeError(error: unknown): unknown {
67
+ if (typeof error === 'string') {
68
+ return error;
69
+ }
70
+
71
+ const details = _extractThetaWebApiError(error);
72
+ if (details == null) {
73
+ return error instanceof Error ? error : new Error(String(error));
74
+ }
75
+
76
+ console.log(
77
+ `[ThetaWebApiError] statusCode=${details.statusCode ?? '-'} errorCode=${details.errorCode ?? '-'} message=${details.message}`
78
+ );
79
+
80
+ return details;
81
+ }
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
15
15
 
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
17
 
18
- s.dependency "THETAClient", "1.14.0"
18
+ s.dependency "THETAClient", "1.15.0"
19
19
 
20
20
  install_modules_dependencies(s)
21
21
  end