@transistorsoft/background-geolocation-types 5.0.0-beta.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +137 -0
  3. package/dist/core/api/BackgroundGeolocation.d.ts +6 -0
  4. package/dist/core/api/BackgroundGeolocation.js +2 -0
  5. package/dist/core/api/CurrentPositionRequest.d.ts +44 -0
  6. package/dist/core/api/CurrentPositionRequest.js +2 -0
  7. package/dist/core/api/DeviceSettings.d.ts +77 -0
  8. package/dist/core/api/DeviceSettings.js +2 -0
  9. package/dist/core/api/Logger.d.ts +421 -0
  10. package/dist/core/api/Logger.js +2 -0
  11. package/dist/core/api/State.d.ts +75 -0
  12. package/dist/core/api/State.js +2 -0
  13. package/dist/core/config/ActivityConfig.d.ts +271 -0
  14. package/dist/core/config/ActivityConfig.js +2 -0
  15. package/dist/core/config/AppConfig.d.ts +599 -0
  16. package/dist/core/config/AppConfig.js +2 -0
  17. package/dist/core/config/AuthorizationConfig.d.ts +200 -0
  18. package/dist/core/config/AuthorizationConfig.js +2 -0
  19. package/dist/core/config/CompoundConfig.d.ts +19 -0
  20. package/dist/core/config/CompoundConfig.js +2 -0
  21. package/dist/core/config/Config.d.ts +149 -0
  22. package/dist/core/config/Config.js +2 -0
  23. package/dist/core/config/GeoConfig.d.ts +905 -0
  24. package/dist/core/config/GeoConfig.js +2 -0
  25. package/dist/core/config/HttpConfig.d.ts +579 -0
  26. package/dist/core/config/HttpConfig.js +2 -0
  27. package/dist/core/config/LocationFilter.d.ts +272 -0
  28. package/dist/core/config/LocationFilter.js +2 -0
  29. package/dist/core/config/LoggerConfig.d.ts +319 -0
  30. package/dist/core/config/LoggerConfig.js +2 -0
  31. package/dist/core/config/NotificationConfig.d.ts +519 -0
  32. package/dist/core/config/NotificationConfig.js +2 -0
  33. package/dist/core/config/PersistenceConfig.d.ts +552 -0
  34. package/dist/core/config/PersistenceConfig.js +2 -0
  35. package/dist/core/data/DeviceInfo.d.ts +61 -0
  36. package/dist/core/data/DeviceInfo.js +2 -0
  37. package/dist/core/data/Geofence.d.ts +16 -0
  38. package/dist/core/data/Geofence.js +2 -0
  39. package/dist/core/data/Location.d.ts +253 -0
  40. package/dist/core/data/Location.js +2 -0
  41. package/dist/core/data/Sensors.d.ts +30 -0
  42. package/dist/core/data/Sensors.js +2 -0
  43. package/dist/core/events/AuthorizationEvent.d.ts +15 -0
  44. package/dist/core/events/AuthorizationEvent.js +2 -0
  45. package/dist/core/events/ConnectivityChangeEvent.d.ts +9 -0
  46. package/dist/core/events/ConnectivityChangeEvent.js +2 -0
  47. package/dist/core/events/GeofenceEvent.d.ts +19 -0
  48. package/dist/core/events/GeofenceEvent.js +2 -0
  49. package/dist/core/events/GeofencesChangeEvent.d.ts +12 -0
  50. package/dist/core/events/GeofencesChangeEvent.js +2 -0
  51. package/dist/core/events/HeadlessEvent.d.ts +12 -0
  52. package/dist/core/events/HeadlessEvent.js +2 -0
  53. package/dist/core/events/HeartbeatEvent.d.ts +14 -0
  54. package/dist/core/events/HeartbeatEvent.js +2 -0
  55. package/dist/core/events/HttpEvent.d.ts +13 -0
  56. package/dist/core/events/HttpEvent.js +2 -0
  57. package/dist/core/events/MotionActivityEvent.d.ts +12 -0
  58. package/dist/core/events/MotionActivityEvent.js +2 -0
  59. package/dist/core/events/MotionChangeEvent.d.ts +12 -0
  60. package/dist/core/events/MotionChangeEvent.js +2 -0
  61. package/dist/core/events/ProviderChangeEvent.d.ts +17 -0
  62. package/dist/core/events/ProviderChangeEvent.js +2 -0
  63. package/dist/core/events/Subscription.d.ts +86 -0
  64. package/dist/core/events/Subscription.js +2 -0
  65. package/dist/docs-entry.d.ts +3 -0
  66. package/dist/docs-entry.js +20 -0
  67. package/dist/enums/AccuracyAuthorization.d.ts +16 -0
  68. package/dist/enums/AccuracyAuthorization.js +19 -0
  69. package/dist/enums/ActivityType.d.ts +28 -0
  70. package/dist/enums/ActivityType.js +31 -0
  71. package/dist/enums/AuthorizationStatus.d.ts +20 -0
  72. package/dist/enums/AuthorizationStatus.js +23 -0
  73. package/dist/enums/AuthorizationStrategy.d.ts +10 -0
  74. package/dist/enums/AuthorizationStrategy.js +13 -0
  75. package/dist/enums/DesiredAccuracy.d.ts +13 -0
  76. package/dist/enums/DesiredAccuracy.js +16 -0
  77. package/dist/enums/Event.d.ts +21 -0
  78. package/dist/enums/Event.js +24 -0
  79. package/dist/enums/GeofenceAction.d.ts +18 -0
  80. package/dist/enums/GeofenceAction.js +21 -0
  81. package/dist/enums/HttpMethod.d.ts +11 -0
  82. package/dist/enums/HttpMethod.js +14 -0
  83. package/dist/enums/KalmanProfile.d.ts +30 -0
  84. package/dist/enums/KalmanProfile.js +33 -0
  85. package/dist/enums/LocationError.d.ts +23 -0
  86. package/dist/enums/LocationError.js +26 -0
  87. package/dist/enums/LocationFilterPolicy.d.ts +108 -0
  88. package/dist/enums/LocationFilterPolicy.js +111 -0
  89. package/dist/enums/LogLevel.d.ts +13 -0
  90. package/dist/enums/LogLevel.js +16 -0
  91. package/dist/enums/LogLevelName.d.ts +1 -0
  92. package/dist/enums/LogLevelName.js +15 -0
  93. package/dist/enums/MotionActivityType.d.ts +14 -0
  94. package/dist/enums/MotionActivityType.js +17 -0
  95. package/dist/enums/NotificationPriority.d.ts +22 -0
  96. package/dist/enums/NotificationPriority.js +25 -0
  97. package/dist/enums/PersistMode.d.ts +12 -0
  98. package/dist/enums/PersistMode.js +15 -0
  99. package/dist/enums/SQLQueryOrder.d.ts +16 -0
  100. package/dist/enums/SQLQueryOrder.js +17 -0
  101. package/dist/enums/TrackingMode.d.ts +14 -0
  102. package/dist/enums/TrackingMode.js +17 -0
  103. package/dist/enums/TriggerActivity.d.ts +13 -0
  104. package/dist/enums/TriggerActivity.js +16 -0
  105. package/dist/index.d.ts +49 -0
  106. package/dist/index.js +69 -0
  107. package/dist/legacy/LegacyConfig.d.ts +24 -0
  108. package/dist/legacy/LegacyConfig.js +2 -0
  109. package/package.json +50 -0
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Configure the SDK to authenticate with your server using an
3
+ * {@link AuthorizationConfig.accessToken | access token} (e.g., a
4
+ * [JSON Web Token](https://jwt.io/)), and automatically request new tokens when
5
+ * the server returns **`401 Unauthorized`**.
6
+ *
7
+ * **Note:** Only [JSON Web Token](https://jwt.io/) (JWT) is currently supported.
8
+ *
9
+ * The SDK automatically attaches your token to each HTTP request:
10
+ *
11
+ * ```txt
12
+ * Authorization: Bearer XXX.YYY.ZZZ
13
+ * ```
14
+ *
15
+ * When using {@link Config.authorization}, **do not** manually define
16
+ * `Authorization` inside {@link HttpConfig.headers}. The SDK manages all JWT
17
+ * headers automatically.
18
+ *
19
+ * If you supply {@link AuthorizationConfig.refreshUrl},
20
+ * {@link AuthorizationConfig.refreshToken}, and
21
+ * {@link AuthorizationConfig.refreshPayload}, the SDK can automatically refresh
22
+ * expired tokens when a `401 Unauthorized` response is received.
23
+ *
24
+ * **Configuration**
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const token = getMyToken(); // Your own JWT fetch method
29
+ *
30
+ * // Listen for authorization refresh results
31
+ * BackgroundGeolocation.onAuthorization((event) => {
32
+ * if (event.success) {
33
+ * console.log("[authorization] SUCCESS:", event.response);
34
+ * } else {
35
+ * console.log("[authorization] ERROR:", event.error);
36
+ * }
37
+ * });
38
+ *
39
+ * // Initialize with JWT authorization
40
+ * BackgroundGeolocation.ready({
41
+ * http: {
42
+ * url: "https://app.your.server.com/users/locations",
43
+ * autoSync: true,
44
+ * },
45
+ * authorization: {
46
+ * strategy: "JWT",
47
+ * accessToken: token.accessToken,
48
+ * refreshToken: token.refreshToken,
49
+ * refreshUrl: "https://auth.your.server.com/tokens",
50
+ * refreshPayload: {
51
+ * the_refresh_token_field_name: "{refreshToken}"
52
+ * },
53
+ * expires: token.expiresAt,
54
+ * }
55
+ * });
56
+ * ```
57
+ *
58
+ * **Receiving responses from** {@link AuthorizationConfig.refreshUrl}
59
+ *
60
+ * Whenever the SDK receives a response from your
61
+ * {@link refreshUrl}, it fires
62
+ * {@link BackgroundGeolocation.onAuthorization}. Your callback will receive an
63
+ * {@link AuthorizationEvent}.
64
+ *
65
+ * - On **success**, {@link AuthorizationEvent.response} contains the parsed JSON.
66
+ * - On **error**, {@link AuthorizationEvent.error} contains the error message.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * BackgroundGeolocation.onAuthorization((event) => {
71
+ * if (event.success) {
72
+ * console.log("[authorization] SUCCESS:", event.response);
73
+ * } else {
74
+ * console.log("[authorization] ERROR:", event.error);
75
+ * }
76
+ * });
77
+ * ```
78
+ * @category Config
79
+ */
80
+ export interface AuthorizationConfig {
81
+ /**
82
+ * Authorization strategy. Only [JWT](https://jwt.io/) is supported.
83
+ */
84
+ strategy: string;
85
+ /**
86
+ * Authorization token (eg: [JWT](https://jwt.io/)) required for authorization by your server at {@link HttpConfig.url}.
87
+ *
88
+ * The SDK will automatically apply the configured `accessToken` to each HTTP request's `Authorization` header, eg:
89
+ *
90
+ * `"Authorization": "Bearer XXX.YYY.ZZZ"`
91
+ *
92
+ * You do **not** need to manually configure {@link HttpConfig.headers} with the `Authorization` parameter. It is all **automatic**.
93
+ */
94
+ accessToken: string;
95
+ /**
96
+ * The token to be POSTed to {@link refreshUrl}, encoded into the {@link refreshPayload}, when a new {@link accessToken} is required after {@link expires} or when HTTP `401 Unauthorized` is received.
97
+ */
98
+ refreshToken?: string;
99
+ /**
100
+ * The url to your authorization server that provides new {@link accessToken} when expired.
101
+ *
102
+ * When the SDK receives a response the server, it will decode the JSON and recursively iterate through the keys, performing regular expressions and other String-analysis *to "taste"* the data in search of the following 3 items:
103
+ *
104
+ * 1. "access token"
105
+ * 2. "refresh token"
106
+ * 3. "expiry time"
107
+ *
108
+ * The SDK is designed to operate with *any* response data-structure. For example, one authorization server might return a complex response such as:
109
+ *
110
+ * ```json
111
+ * {
112
+ * "token": {
113
+ * "access_token": "XXX.YYY.ZZZ",
114
+ * "expires_at": 3900
115
+ * },
116
+ * "refresh_token": "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb"
117
+ * }
118
+ * ```
119
+ *
120
+ * While another server might return a flat response, such as:
121
+ *
122
+ * ```json
123
+ * {
124
+ * "accessToken": "XXX.YYY.ZZZ",
125
+ * "refreshToken": "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
126
+ * "expiry": 3900
127
+ * }
128
+ * ```
129
+ *
130
+ * When the response from the server is received, the event {@link BackgroundGeolocation.onAuthorization} will be fired, provided with the {@link AuthorizationEvent}.
131
+ */
132
+ refreshUrl?: string;
133
+ /**
134
+ * Refresh payload will be encoded into the FORM POST to the {@link refreshUrl} when requesting a new {@link accessToken} after expiration.
135
+ *
136
+ * You *must* provide one field-template which will represent your "refresh token" using the value: __`{refreshToken}`__. The SDK will
137
+ * _automatically_ replace this simple template with the configured {@link refreshToken}.
138
+ *
139
+ * @example
140
+ *
141
+ * ```typescript
142
+ * BackgroundGeolocation.ready({
143
+ * authorization: {
144
+ * strategy: "JWT",
145
+ * accessToken: "XXX.YYY.ZZZ",
146
+ * refreshUrl: "https://auth.your.server.com/tokens",
147
+ * refreshToken: "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
148
+ * refreshPayload: {
149
+ * my_refresh_token: "{refreshToken}",
150
+ * grant_type: "refresh_token",
151
+ * foo: "another arbitrary field"
152
+ * }
153
+ * }
154
+ * });
155
+ * ```
156
+ *
157
+ * with the configuration above, a **`curl`** representation of the SDK's FORM POST, might look like this:
158
+ * ```bash
159
+ * $ curl -X POST \
160
+ * -F 'my_refresh_token=smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb' \
161
+ * -F 'grant_type=refresh_token' \
162
+ * -F 'foo=another arbitrary field' \
163
+ * https://auth.your.server.com/tokens
164
+ * ```
165
+ *
166
+ */
167
+ refreshPayload?: Record<string, string>;
168
+ /**
169
+ * Optional headers applied on requests to {@link refreshUrl}
170
+ * Defaults to: `{"Authorization": "Bearer {accessToken}"}`
171
+ *
172
+ * The template variable `{accessToken}` will automatically be replaced with your app's current auth token.
173
+ *
174
+ * If you do not want *any* headers applied on requests to {refreshUrl}, provide an empty `{}`.
175
+ *
176
+ * ## Example
177
+ *
178
+ * ```typescript
179
+ * BackgroundGeolocation.ready({
180
+ * authorization: {
181
+ * accessToken: "XXX.YYY.ZZZ",
182
+ * refreshUrl: "https://auth.domain.com/tokens",
183
+ * refreshToken: "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
184
+ * refreshPayload: {
185
+ * "my_refresh_token": "{refreshToken}", // <-- replaced with configured refreshToken above.
186
+ * "grant_type": "refresh_token", // <-- arbitrary fields required by your auth server
187
+ * "foo": "another arbitrary field"
188
+ * },
189
+ * refreshHeaders: {} // <-- Empty {} to provide no refreshHeaders.
190
+ * )
191
+ * ));
192
+ * ```
193
+ *
194
+ */
195
+ refreshHeaders?: Record<string, string>;
196
+ /**
197
+ * Token expiry time in seconds.
198
+ */
199
+ expires?: number;
200
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { LoggerConfig } from './LoggerConfig';
2
+ import { HttpConfig } from './HttpConfig';
3
+ import { GeoConfig } from './GeoConfig';
4
+ import { AppConfig } from './AppConfig';
5
+ import { PersistenceConfig } from './PersistenceConfig';
6
+ import { ActivityConfig } from './ActivityConfig';
7
+ import { AuthorizationConfig } from './AuthorizationConfig';
8
+ /**
9
+ * Root compound configuration object for the BackgroundGeolocation SDK.
10
+ */
11
+ export interface CompoundConfig {
12
+ logger?: LoggerConfig;
13
+ geolocation?: GeoConfig;
14
+ http?: HttpConfig;
15
+ app?: AppConfig;
16
+ persistence?: PersistenceConfig;
17
+ activity?: ActivityConfig;
18
+ authorization?: AuthorizationConfig;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,149 @@
1
+ import { LoggerConfig } from './LoggerConfig';
2
+ import { HttpConfig } from './HttpConfig';
3
+ import { GeoConfig } from './GeoConfig';
4
+ import { AppConfig } from './AppConfig';
5
+ import { PersistenceConfig } from './PersistenceConfig';
6
+ import { ActivityConfig } from './ActivityConfig';
7
+ import { AuthorizationConfig } from './AuthorizationConfig';
8
+ /**
9
+ * Configuration API.
10
+ *
11
+ * The `Config` class defines all SDK options, grouped into compound
12
+ * configuration objects:
13
+ *
14
+ * - {@link GeoConfig} — Geolocation and filtering options
15
+ * - {@link AppConfig} — Application lifecycle options
16
+ * - {@link HttpConfig} — Networking and HTTP sync options
17
+ * - {@link PersistenceConfig} — Data persistence and database options
18
+ * - {@link LoggerConfig} — Logging and debugging options
19
+ * - {@link ActivityConfig} — Motion and activity-recognition options
20
+ *
21
+ * Instances of `Config` are consumed by {@link BackgroundGeolocation.ready}
22
+ * and {@link BackgroundGeolocation.setConfig}.
23
+ *
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import BackgroundGeolocation, {
28
+ * Config,
29
+ * GeoConfig,
30
+ * ActivityConfig,
31
+ * HttpConfig,
32
+ * PersistenceConfig,
33
+ * DesiredAccuracy,
34
+ * PersistMode,
35
+ * LogLevel,
36
+ * AppConfig,
37
+ * LoggerConfig,
38
+ * State
39
+ * } from '{{pluginName}}';
40
+ *
41
+ * async function main() {
42
+ * // Configure the SDK with compound configuration objects.
43
+ * const config: Config = {
44
+ * geolocation: {
45
+ * desiredAccuracy: DesiredAccuracy.High,
46
+ * distanceFilter: 20,
47
+ * stopTimeout: 5,
48
+ * stationaryRadius: 150,
49
+ * },
50
+ * activity: {
51
+ * disableStopDetection: false,
52
+ * motionTriggerDelay: 30000,
53
+ * },
54
+ * http: {
55
+ * url: 'https://my.server.com/api/locations',
56
+ * method: 'POST',
57
+ * autoSync: true,
58
+ * headers: {
59
+ * Authorization: 'Bearer secret-token',
60
+ * },
61
+ * params: {
62
+ * user_id: 123,
63
+ * },
64
+ * },
65
+ * persistence: {
66
+ * persistMode: PersistMode.All,
67
+ * maxDaysToPersist: 14,
68
+ * extras: { appVersion: '1.0.0' },
69
+ * },
70
+ * app: {
71
+ * stopOnTerminate: false,
72
+ * startOnBoot: true,
73
+ * enableHeadless: true
74
+ * },
75
+ * logger: {
76
+ * debug: true,
77
+ * logLevel: LogLevel.Verbose,
78
+ * logMaxDays: 3,
79
+ * },
80
+ * };
81
+ *
82
+ * // Apply the configuration.
83
+ * const state: State = await BackgroundGeolocation.ready(config);
84
+ * console.log('[ready] BackgroundGeolocation is configured and ready to use');
85
+ *
86
+ * if (!state.enabled) {
87
+ * await BackgroundGeolocation.start();
88
+ * }
89
+ *
90
+ * // To modify configuration after initialization, use setConfig.
91
+ * const updated: State = await BackgroundGeolocation.setConfig({
92
+ * http: {
93
+ * headers: {
94
+ * Authorization: 'Bearer new-token',
95
+ * },
96
+ * },
97
+ * logger: {
98
+ * logLevel: LogLevel.Info
99
+ * },
100
+ * });
101
+ *
102
+ * await BackgroundGeolocation.sync();
103
+ * }
104
+ *
105
+ * ```
106
+ * @category Primary API
107
+ * @category Config
108
+ */
109
+ export interface Config {
110
+ /**
111
+ * Reset the plugin to its initial state before applying this configuration. This is probably what you want.
112
+ *
113
+ * Defaults to `true`
114
+ *
115
+ * If you set this to `false`, the SDK will consume your `Config` only at the first install of your app. Thereafter, the only way
116
+ * to change your configuration will be to call {@link BackgroundGeolocation.setConfig},
117
+ *
118
+ * You will certainly **NOT** want to use `reset: false` during development, as it will prevent your configuration changes from taking effect on subsequent app launches.
119
+ */
120
+ reset?: boolean;
121
+ /**
122
+ * Logger configuration.
123
+ */
124
+ logger?: LoggerConfig;
125
+ /**
126
+ * Geolocation configuration.
127
+ */
128
+ geolocation?: GeoConfig;
129
+ /**
130
+ * HTTP configuration.
131
+ */
132
+ http?: HttpConfig;
133
+ /**
134
+ * App configuration.
135
+ */
136
+ app?: AppConfig;
137
+ /**
138
+ * Persistence configuration.
139
+ */
140
+ persistence?: PersistenceConfig;
141
+ /**
142
+ * Motion Activity configuration.
143
+ */
144
+ activity?: ActivityConfig;
145
+ /**
146
+ * Authorization configuration.
147
+ */
148
+ authorization?: AuthorizationConfig;
149
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });