@webority-technologies/mobile-core 0.0.1 → 0.0.3

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 (146) hide show
  1. package/README.md +22 -1
  2. package/lib/commonjs/api/baseUrl.js +34 -0
  3. package/lib/commonjs/api/curl.js +109 -0
  4. package/lib/commonjs/api/publicClient.js +11 -20
  5. package/lib/commonjs/api/retry.js +75 -0
  6. package/lib/commonjs/api/userClient.js +46 -22
  7. package/lib/commonjs/auth/authStore.js +101 -33
  8. package/lib/commonjs/auth/jwt.js +32 -8
  9. package/lib/commonjs/config/index.js +2 -1
  10. package/lib/commonjs/deepLink/index.js +286 -0
  11. package/lib/commonjs/download/adapters/expoFs.js +100 -0
  12. package/lib/commonjs/download/adapters/shared.js +13 -0
  13. package/lib/commonjs/download/index.js +272 -0
  14. package/lib/commonjs/formatters/date.js +1 -1
  15. package/lib/commonjs/formatters/index.js +24 -0
  16. package/lib/commonjs/formatters/phone.js +132 -15
  17. package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
  18. package/lib/commonjs/geolocation/index.js +339 -0
  19. package/lib/commonjs/index.js +151 -48
  20. package/lib/commonjs/initSDK.js +23 -2
  21. package/lib/commonjs/initUserAuth.js +2 -1
  22. package/lib/commonjs/logger/index.js +159 -5
  23. package/lib/commonjs/network/index.js +6 -0
  24. package/lib/commonjs/network/networkStatus.js +50 -15
  25. package/lib/commonjs/permissions/index.js +24 -1
  26. package/lib/commonjs/sqlite/adapters/expo.js +53 -0
  27. package/lib/commonjs/sqlite/adapters/op.js +43 -0
  28. package/lib/commonjs/sqlite/adapters/rows.js +33 -0
  29. package/lib/commonjs/sqlite/adapters/storage.js +50 -0
  30. package/lib/commonjs/sqlite/adapters/sync.js +45 -0
  31. package/lib/commonjs/sqlite/index.js +610 -0
  32. package/lib/commonjs/sqlite/nitro.js +17 -0
  33. package/lib/commonjs/sqlite/op.js +18 -0
  34. package/lib/commonjs/sqlite/quick.js +14 -0
  35. package/lib/commonjs/sqlite/storage.js +14 -0
  36. package/lib/commonjs/storage/index.js +41 -20
  37. package/lib/commonjs/types/globals.d.js +6 -0
  38. package/lib/commonjs/utils/imageCompression.js +51 -14
  39. package/lib/commonjs/utils/index.js +6 -0
  40. package/lib/commonjs/versionCheck/index.js +28 -4
  41. package/lib/module/api/baseUrl.js +30 -0
  42. package/lib/module/api/curl.js +104 -0
  43. package/lib/module/api/publicClient.js +11 -20
  44. package/lib/module/api/retry.js +69 -0
  45. package/lib/module/api/userClient.js +45 -21
  46. package/lib/module/auth/authStore.js +99 -32
  47. package/lib/module/auth/jwt.js +32 -8
  48. package/lib/module/config/index.js +2 -1
  49. package/lib/module/deepLink/index.js +280 -0
  50. package/lib/module/download/adapters/expoFs.js +95 -0
  51. package/lib/module/download/adapters/shared.js +8 -0
  52. package/lib/module/download/index.js +264 -0
  53. package/lib/module/formatters/date.js +1 -1
  54. package/lib/module/formatters/index.js +1 -1
  55. package/lib/module/formatters/phone.js +110 -13
  56. package/lib/module/geolocation/adapters/expoLocation.js +121 -0
  57. package/lib/module/geolocation/index.js +332 -0
  58. package/lib/module/index.js +28 -11
  59. package/lib/module/initSDK.js +23 -2
  60. package/lib/module/initUserAuth.js +2 -1
  61. package/lib/module/logger/index.js +156 -4
  62. package/lib/module/network/index.js +1 -1
  63. package/lib/module/network/networkStatus.js +47 -14
  64. package/lib/module/permissions/index.js +22 -0
  65. package/lib/module/sqlite/adapters/expo.js +48 -0
  66. package/lib/module/sqlite/adapters/op.js +38 -0
  67. package/lib/module/sqlite/adapters/rows.js +28 -0
  68. package/lib/module/sqlite/adapters/storage.js +46 -0
  69. package/lib/module/sqlite/adapters/sync.js +41 -0
  70. package/lib/module/sqlite/index.js +600 -0
  71. package/lib/module/sqlite/nitro.js +12 -0
  72. package/lib/module/sqlite/op.js +13 -0
  73. package/lib/module/sqlite/quick.js +9 -0
  74. package/lib/module/sqlite/storage.js +9 -0
  75. package/lib/module/storage/index.js +38 -19
  76. package/lib/module/types/globals.d.js +10 -0
  77. package/lib/module/utils/imageCompression.js +49 -13
  78. package/lib/module/utils/index.js +1 -1
  79. package/lib/module/versionCheck/index.js +27 -4
  80. package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
  81. package/lib/typescript/commonjs/api/curl.d.ts +18 -0
  82. package/lib/typescript/commonjs/api/retry.d.ts +27 -0
  83. package/lib/typescript/commonjs/api/userClient.d.ts +11 -0
  84. package/lib/typescript/commonjs/auth/authStore.d.ts +29 -6
  85. package/lib/typescript/commonjs/config/index.d.ts +6 -0
  86. package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
  87. package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +45 -0
  88. package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
  89. package/lib/typescript/commonjs/download/index.d.ts +76 -0
  90. package/lib/typescript/commonjs/formatters/index.d.ts +2 -1
  91. package/lib/typescript/commonjs/formatters/phone.d.ts +27 -1
  92. package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
  93. package/lib/typescript/commonjs/geolocation/index.d.ts +89 -0
  94. package/lib/typescript/commonjs/index.d.ts +30 -13
  95. package/lib/typescript/commonjs/initSDK.d.ts +32 -0
  96. package/lib/typescript/commonjs/logger/index.d.ts +39 -0
  97. package/lib/typescript/commonjs/network/index.d.ts +2 -2
  98. package/lib/typescript/commonjs/network/networkStatus.d.ts +16 -0
  99. package/lib/typescript/commonjs/permissions/index.d.ts +35 -0
  100. package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
  101. package/lib/typescript/commonjs/sqlite/adapters/op.d.ts +27 -0
  102. package/lib/typescript/commonjs/sqlite/adapters/rows.d.ts +7 -0
  103. package/lib/typescript/commonjs/sqlite/adapters/storage.d.ts +30 -0
  104. package/lib/typescript/commonjs/sqlite/adapters/sync.d.ts +31 -0
  105. package/lib/typescript/commonjs/sqlite/index.d.ts +121 -0
  106. package/lib/typescript/commonjs/sqlite/nitro.d.ts +7 -0
  107. package/lib/typescript/commonjs/sqlite/op.d.ts +8 -0
  108. package/lib/typescript/commonjs/sqlite/quick.d.ts +4 -0
  109. package/lib/typescript/commonjs/sqlite/storage.d.ts +4 -0
  110. package/lib/typescript/commonjs/storage/index.d.ts +25 -3
  111. package/lib/typescript/commonjs/utils/imageCompression.d.ts +17 -0
  112. package/lib/typescript/commonjs/utils/index.d.ts +2 -2
  113. package/lib/typescript/module/api/baseUrl.d.ts +20 -0
  114. package/lib/typescript/module/api/curl.d.ts +18 -0
  115. package/lib/typescript/module/api/retry.d.ts +27 -0
  116. package/lib/typescript/module/api/userClient.d.ts +11 -0
  117. package/lib/typescript/module/auth/authStore.d.ts +29 -6
  118. package/lib/typescript/module/config/index.d.ts +6 -0
  119. package/lib/typescript/module/deepLink/index.d.ts +54 -0
  120. package/lib/typescript/module/download/adapters/expoFs.d.ts +45 -0
  121. package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
  122. package/lib/typescript/module/download/index.d.ts +76 -0
  123. package/lib/typescript/module/formatters/index.d.ts +2 -1
  124. package/lib/typescript/module/formatters/phone.d.ts +27 -1
  125. package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
  126. package/lib/typescript/module/geolocation/index.d.ts +89 -0
  127. package/lib/typescript/module/index.d.ts +30 -13
  128. package/lib/typescript/module/initSDK.d.ts +32 -0
  129. package/lib/typescript/module/logger/index.d.ts +39 -0
  130. package/lib/typescript/module/network/index.d.ts +2 -2
  131. package/lib/typescript/module/network/networkStatus.d.ts +16 -0
  132. package/lib/typescript/module/permissions/index.d.ts +35 -0
  133. package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
  134. package/lib/typescript/module/sqlite/adapters/op.d.ts +27 -0
  135. package/lib/typescript/module/sqlite/adapters/rows.d.ts +7 -0
  136. package/lib/typescript/module/sqlite/adapters/storage.d.ts +30 -0
  137. package/lib/typescript/module/sqlite/adapters/sync.d.ts +31 -0
  138. package/lib/typescript/module/sqlite/index.d.ts +121 -0
  139. package/lib/typescript/module/sqlite/nitro.d.ts +7 -0
  140. package/lib/typescript/module/sqlite/op.d.ts +8 -0
  141. package/lib/typescript/module/sqlite/quick.d.ts +4 -0
  142. package/lib/typescript/module/sqlite/storage.d.ts +4 -0
  143. package/lib/typescript/module/storage/index.d.ts +25 -3
  144. package/lib/typescript/module/utils/imageCompression.d.ts +17 -0
  145. package/lib/typescript/module/utils/index.d.ts +2 -2
  146. package/package.json +102 -13
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import * as ExpoNetwork from 'expo-network';
3
4
  import { useEffect, useState } from 'react';
4
5
  import { Logger } from "../logger/index.js";
5
6
  const DEFAULT_STATUS = {
@@ -7,21 +8,53 @@ const DEFAULT_STATUS = {
7
8
  isInternetReachable: null,
8
9
  type: 'unknown'
9
10
  };
10
- let netInfo = null;
11
- let resolved = false;
12
- const resolveNetInfo = () => {
13
- if (resolved) {
14
- return netInfo;
15
- }
16
- resolved = true;
17
- try {
18
- const mod = require('@react-native-community/netinfo');
19
- netInfo = mod.default ?? mod;
20
- } catch {
21
- Logger.warn('[network] @react-native-community/netinfo is not installed; ' + 'useNetworkStatus() will report a default "online" status.');
22
- netInfo = null;
11
+ /**
12
+ * expo-network is imported directly, not resolved through a seam.
13
+ *
14
+ * `expo` is a REQUIRED peer of this package, so every consumer has the Expo
15
+ * modules by construction and the static-require problem that forced the old
16
+ * injection design does not arise. An app wires nothing: connectivity works
17
+ * because the library uses Expo, which is the point of the Expo-first policy.
18
+ * One backend also means one behaviour, rather than each app choosing.
19
+ */
20
+ let override = null;
21
+
22
+ /**
23
+ * Replace the backend. Intended for TESTS and for the showcase, which uses it
24
+ * to reach error paths that a healthy device never takes; it is not the way an
25
+ * app is meant to configure the library. Pass `null` to restore expo-network.
26
+ */
27
+ export const setNetworkStatusImplementation = impl => {
28
+ override = impl;
29
+ };
30
+ const resolveNetInfo = () => override ?? expoNetworkBackend;
31
+
32
+ /**
33
+ * expo-network in the shape this module already speaks.
34
+ *
35
+ * The conversion is not cosmetic: expo reports its type as an UPPERCASE enum
36
+ * where this module's vocabulary is lowercase, marks every field optional, and
37
+ * returns an EventSubscription where an unsubscribe function is expected.
38
+ */
39
+ const expoNetworkBackend = {
40
+ fetch: async () => {
41
+ const state = await ExpoNetwork.getNetworkStateAsync();
42
+ return {
43
+ isConnected: state?.isConnected !== false,
44
+ isInternetReachable: state?.isInternetReachable ?? null,
45
+ type: state?.type ? String(state.type).toLowerCase() : undefined
46
+ };
47
+ },
48
+ addEventListener: cb => {
49
+ const subscription = ExpoNetwork.addNetworkStateListener(state => {
50
+ cb({
51
+ isConnected: state?.isConnected !== false,
52
+ isInternetReachable: state?.isInternetReachable ?? null,
53
+ type: state?.type ? String(state.type).toLowerCase() : undefined
54
+ });
55
+ });
56
+ return () => subscription.remove();
23
57
  }
24
- return netInfo;
25
58
  };
26
59
  const normalize = state => {
27
60
  if (!state) {
@@ -21,6 +21,28 @@ const resolveModule = () => {
21
21
  }
22
22
  return permsModule;
23
23
  };
24
+
25
+ /**
26
+ * Inject a custom permissions implementation at runtime.
27
+ * Pass `null` to reset to the default lazily-resolved native module.
28
+ *
29
+ * `resolved` goes FALSE on null, never true. Marking it resolved with a null
30
+ * backend would permanently disable permissions: the resolver short-circuits and the
31
+ * real module is never loaded again, which contradicts this function's own
32
+ * documented contract. That exact bug shipped once, in the storage seam.
33
+ *
34
+ * THIS MODULE IS THE EXPO-FIRST EXCEPTION, and deliberately keeps the old
35
+ * shape. Expo ships no permissions package: each module carries its own
36
+ * (expo-location's requestForegroundPermissionsAsync, expo-image-picker's, and
37
+ * so on), so there is no single object to adapt and the library must not guess
38
+ * which Expo modules an app installed. react-native-permissions stays, behind
39
+ * this module's own import path so an app that never asks for permissions
40
+ * never names the package to Metro.
41
+ */
42
+ export const setPermissionsImplementation = impl => {
43
+ permsModule = impl;
44
+ resolved = impl !== null;
45
+ };
24
46
  const mapToNative = kind => {
25
47
  const m = resolveModule();
26
48
  if (!m) {
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * expo-sqlite. Shape verified against 57.0.2 rather than assumed, and it is the
5
+ * one driver that cannot share an adapter with the others: expo splits reads
6
+ * from writes. `getAllAsync` yields rows but no change count, `runAsync` yields
7
+ * `{ changes, lastInsertRowId }` but no rows, and SqliteResultSet needs all
8
+ * three from one call. `prepareAsync` + `executeAsync` is the only call that
9
+ * returns both, so every statement goes through it rather than being routed by
10
+ * sniffing the SQL for a leading SELECT.
11
+ *
12
+ * The REQUIRE lives in the driver entry point beside this file, never here.
13
+ */
14
+
15
+ export const adaptExpoSqlite = mod => ({
16
+ // expo takes the directory as a third positional argument rather than an
17
+ // option, so `location` cannot be passed through the options object.
18
+ open: async (name, options) => {
19
+ const db = await mod.openDatabaseAsync(name, undefined, options?.location);
20
+ return {
21
+ execute: async (sql, params) => {
22
+ const statement = await db.prepareAsync(sql);
23
+ try {
24
+ const result = await statement.executeAsync(params ? [...params] : []);
25
+ // Safe on a write: expo returns [] when the statement produced no
26
+ // first row rather than stepping the statement a second time.
27
+ const rows = await result.getAllAsync();
28
+ return {
29
+ rows,
30
+ rowsAffected: result.changes,
31
+ // expo always reports lastInsertRowId, so unlike the other drivers
32
+ // this is never undefined. It is the connection's last insert rowid,
33
+ // which is only meaningful immediately after an INSERT.
34
+ insertId: result.lastInsertRowId
35
+ };
36
+ } finally {
37
+ // A statement left unfinalised holds a native handle for the life of
38
+ // the connection, and the core executes one per call.
39
+ await statement.finalizeAsync();
40
+ }
41
+ },
42
+ close: async () => {
43
+ await db.closeAsync();
44
+ }
45
+ };
46
+ }
47
+ });
48
+ //# sourceMappingURL=expo.js.map
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @op-engineering/op-sqlite. Shape verified against 18.1.4 rather than assumed:
5
+ * `open({ name, location })` is synchronous and returns a DB whose `execute` is
6
+ * ASYNC, and whose `rows` is already a plain array of objects rather than the
7
+ * `{ _array, item() }` shape the older drivers use. Both differences are why it
8
+ * cannot share the sync adapter.
9
+ *
10
+ * The REQUIRE lives in the driver entry point beside this file, never here.
11
+ */
12
+
13
+ export const adaptOpSqlite = mod => ({
14
+ open: async (name, options) => {
15
+ const db = mod.open({
16
+ name,
17
+ location: options?.location
18
+ });
19
+ return {
20
+ execute: async (sql, params) => {
21
+ const result = await db.execute(sql, params ? [...params] : undefined);
22
+ return {
23
+ rows: result.rows ?? [],
24
+ rowsAffected: result.rowsAffected ?? 0,
25
+ insertId: result.insertId
26
+ };
27
+ },
28
+ close: async () => {
29
+ if (db.closeAsync) {
30
+ await db.closeAsync();
31
+ return;
32
+ }
33
+ db.close();
34
+ }
35
+ };
36
+ }
37
+ });
38
+ //# sourceMappingURL=op.js.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Row shapes differ per driver: a plain array, `{ _array, length, item() }`, or
5
+ * `{ length, item() }` alone. Every adapter normalises to a plain array here so
6
+ * nothing driver-specific escapes into the Db layer.
7
+ */
8
+ export const rowsToArray = rows => {
9
+ if (Array.isArray(rows)) {
10
+ return rows;
11
+ }
12
+ const shaped = rows;
13
+ if (!shaped) {
14
+ return [];
15
+ }
16
+ if (Array.isArray(shaped._array)) {
17
+ return shaped._array;
18
+ }
19
+ if (typeof shaped.item === 'function' && typeof shaped.length === 'number') {
20
+ const out = [];
21
+ for (let i = 0; i < shaped.length; i += 1) {
22
+ out.push(shaped.item(i));
23
+ }
24
+ return out;
25
+ }
26
+ return [];
27
+ };
28
+ //# sourceMappingURL=rows.js.map
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ import { rowsToArray } from "./rows.js";
4
+
5
+ /** react-native-sqlite-storage: callback-based by default, promise-based once
6
+ * `enablePromise(true)` is called; `executeSql` resolves an array whose first
7
+ * element is the result set. */
8
+
9
+ /**
10
+ * Adapt an already-required `react-native-sqlite-storage` module. Exported for
11
+ * the same reason as the filesystem adapters: the library cannot name a package
12
+ * the app did not install without breaking the app's bundle.
13
+ */
14
+ export const adaptSqliteStorage = mod => ({
15
+ open: async (name, options) => {
16
+ // This is a GLOBAL side effect, not a per-connection setting: the vendor
17
+ // implements it by rewriting SQLitePlugin and SQLiteFactory prototype
18
+ // methods. An app that also uses react-native-sqlite-storage directly in
19
+ // callback mode will find its own callbacks converted to promises from the
20
+ // moment this adapter opens a database. Unavoidable, since the adapter
21
+ // cannot work otherwise, and worth knowing before mixing the two.
22
+ mod.enablePromise(true);
23
+ const db = await mod.openDatabase({
24
+ name,
25
+ location: options?.location ?? 'default'
26
+ });
27
+ return {
28
+ execute: async (sql, params) => {
29
+ const [result] = await db.executeSql(sql, params ? [...params] : undefined);
30
+ return {
31
+ rows: rowsToArray(result.rows),
32
+ rowsAffected: result.rowsAffected ?? 0,
33
+ insertId: result.insertId
34
+ };
35
+ },
36
+ // Not `() => db.close()`: in promise mode this driver resolves the
37
+ // success-callback ARGUMENTS array rather than void, so returning it
38
+ // directly would make SqliteDatabase.close() resolve an array while
39
+ // typed as void. Awaiting and discarding makes the type honest.
40
+ close: async () => {
41
+ await db.close();
42
+ }
43
+ };
44
+ }
45
+ });
46
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ import { rowsToArray } from "./rows.js";
4
+
5
+ /**
6
+ * nitro-sqlite and quick-sqlite share one synchronous shape, so one adapter
7
+ * serves both. The REQUIRE lives in the driver entry points beside this file,
8
+ * never here and never in the core: Metro resolves requires statically, so a
9
+ * package named anywhere reachable becomes mandatory for every consumer.
10
+ */
11
+
12
+ /** Shape shared by react-native-nitro-sqlite and react-native-quick-sqlite: a
13
+ * synchronous `open({ name, location })` whose `db.execute()` and `db.close()`
14
+ * are also synchronous. Both are wrapped in Promise.resolve to fit SqliteDriver. */
15
+
16
+ /**
17
+ * Adapt an already-required nitro-sqlite or quick-sqlite module. Both expose the
18
+ * same synchronous shape. Exported so an app on quick-sqlite can inject it.
19
+ */
20
+ export const adaptSyncSqlite = mod => ({
21
+ open: async (name, options) => {
22
+ const db = mod.open({
23
+ name,
24
+ location: options?.location
25
+ });
26
+ return {
27
+ execute: async (sql, params) => {
28
+ const result = db.execute(sql, params ? [...params] : undefined);
29
+ return {
30
+ rows: rowsToArray(result.rows),
31
+ rowsAffected: result.rowsAffected ?? 0,
32
+ insertId: result.insertId
33
+ };
34
+ },
35
+ close: async () => {
36
+ db.close();
37
+ }
38
+ };
39
+ }
40
+ });
41
+ //# sourceMappingURL=sync.js.map