@situm/cordova 3.15.62 → 3.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@situm/cordova",
3
- "version": "3.15.62",
3
+ "version": "3.16.0",
4
4
  "description": "Situm Wayfinding for Capacitor and Cordova. Integrate plug&play indoor navigation experience with floorplans, POIs, routes and turn-by-turn directions in no time. With the power of Situm.",
5
5
  "private": false,
6
6
  "repository": "https://github.com/situmtech/cordova",
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  id="@situm/cordova"
5
- version="3.15.62">
5
+ version="3.16.0">
6
6
  <name>Situm Cordova plugin Official</name>
7
7
  <description>This is the stable branch.</description>
8
8
  <license>MIT</license>
@@ -86,6 +86,14 @@ public class SitumPlugin extends CordovaPlugin {
86
86
  String email = args.getString(0);
87
87
  String password = args.getString(1);
88
88
  es.situm.sdk.SitumSdk.configuration().setUserPass(email, password);
89
+ } else if (action.equalsIgnoreCase("setToken")) {
90
+ try {
91
+ String token = args.getString(0);
92
+ es.situm.sdk.SitumSdk.configuration().setToken(token);
93
+ } catch(IllegalArgumentException e) {
94
+ Log.d(TAG,"Error setting authentication token: " + e);
95
+ return false;
96
+ }
89
97
  } else if (action.equalsIgnoreCase("setCacheMaxAge")) {
90
98
  Integer cacheAge = args.getInt(0);
91
99
  Log.d(TAG,"Setting cache max age to " + cacheAge + " seconds");
@@ -17,6 +17,7 @@
17
17
  // The hooks for our plugin commands
18
18
  - (void)setApiKey:(CDVInvokedUrlCommand *)command;
19
19
  - (void)setUserPass:(CDVInvokedUrlCommand *)command;
20
+ - (void)setToken:(CDVInvokedUrlCommand *)command;
20
21
  - (void)getDeviceId:(CDVInvokedUrlCommand *)command;
21
22
  - (void)startPositioning:(CDVInvokedUrlCommand *)command;
22
23
  - (void)setUseRemoteConfig:(CDVInvokedUrlCommand *)command;
@@ -29,7 +29,22 @@ static NSString *DEFAULT_SITUM_LOG = @"SitumSDK >>: ";
29
29
  - (void)setApiKey:(CDVInvokedUrlCommand *)command {
30
30
  NSString* email = [command.arguments objectAtIndex:0];
31
31
  NSString* apiKey = [command.arguments objectAtIndex:1];
32
- [SITServices provideAPIKey:apiKey forEmail:email];
32
+ [SITServices setApiKey:apiKey];
33
+
34
+ if (IS_LOG_ENABLED) {
35
+ NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
36
+ NSString *documentsDirectory = [allPaths objectAtIndex:0];
37
+ NSString *pathForLog = [documentsDirectory stringByAppendingPathComponent:@"logging.txt"];
38
+ freopen([pathForLog cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
39
+
40
+ NSLog(@"%@", [NSString stringWithFormat: @"%@ Logging ios calls", DEFAULT_SITUM_LOG]);
41
+ }
42
+
43
+ }
44
+
45
+ - (void)setToken:(CDVInvokedUrlCommand *)command {
46
+ NSString* token = [command.arguments objectAtIndex:0];
47
+ [SITServices setToken:token];
33
48
 
34
49
  if (IS_LOG_ENABLED) {
35
50
  NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
@@ -50,7 +65,7 @@ static NSString *DEFAULT_SITUM_LOG = @"SitumSDK >>: ";
50
65
  - (void)setUserPass:(CDVInvokedUrlCommand *)command {
51
66
  NSString* email = [command.arguments objectAtIndex:0];
52
67
  NSString* password = [command.arguments objectAtIndex:1];
53
- [SITServices provideUser:email password:password];
68
+ [SITServices setUser:email pass:password];
54
69
  }
55
70
 
56
71
  - (void)setCacheMaxAge:(CDVInvokedUrlCommand *)command {
@@ -53,9 +53,11 @@ class MapViewControllerImpl {
53
53
  _mapView = undefined;
54
54
  _isNavigating = false;
55
55
  _navigationType = "";
56
+ _isWaitingForAuth = false;
56
57
 
57
58
  constructor() {
58
59
  Situm.internalSetEventDelegate(this._handleSdkNativeEvents.bind(this));
60
+ Situm.internalSetTokenCallback(this._handleTokenSet.bind(this));
59
61
  }
60
62
 
61
63
  _prepare(mapView) {
@@ -153,6 +155,9 @@ class MapViewControllerImpl {
153
155
  case 'app.map_is_ready':
154
156
  this._handleMapIsReady();
155
157
  break;
158
+ case 'app.ready_for_auth':
159
+ this._handleReadyForAuth();
160
+ break;
156
161
  case 'cartography.poi_selected':
157
162
  console.debug(`poi (${m.payload.identifier}) was selected`);
158
163
  const poiSelectedResult = {
@@ -215,6 +220,26 @@ class MapViewControllerImpl {
215
220
  ]);
216
221
  }
217
222
 
223
+ _handleReadyForAuth() {
224
+ this._isWaitingForAuth = true;
225
+ this._sendTokenToViewer(Situm.internalGetToken());
226
+ }
227
+
228
+ _handleTokenSet(token) {
229
+ if (this._isWaitingForAuth) {
230
+ this._sendTokenToViewer(token);
231
+ }
232
+ }
233
+
234
+ _sendTokenToViewer(token) {
235
+ if (!token) {
236
+ return;
237
+ }
238
+ this._sendMessageToViewer('app.set_auth',
239
+ {jwt: token}
240
+ );
241
+ }
242
+
218
243
  // Fetch the given building and return it or undefined if not found.
219
244
  _ensureBuilding(buildingId, callback) {
220
245
  if (this._buildings) {
package/www/map-view.js CHANGED
@@ -99,13 +99,13 @@ class MapView extends HTMLElement {
99
99
  ? this.getAttribute('language')
100
100
  : '';
101
101
 
102
- let situmApiKeyQP = situmApiKey.length > 0 ? `apikey=${situmApiKey}` : '';
102
+ let authQP = situmApiKey.length > 0 ? `apikey=${situmApiKey}` : 'wait_for_auth=true';
103
103
  let buildingIdentifierQP =
104
104
  buildingIdentifier.length > 0 ? `&buildingid=${buildingIdentifier}` : '';
105
105
  let languageQP = language.length > 0 ? `&lng=${language}` : '';
106
106
  let deviceIdQP = deviceId ? `&deviceId=${deviceId}` : '';
107
107
 
108
- let query = `${situmApiKeyQP}${buildingIdentifierQP}${languageQP}${deviceIdQP}&mode=embed`;
108
+ let query = `${authQP}${buildingIdentifierQP}${languageQP}${deviceIdQP}&mode=embed`;
109
109
 
110
110
  let remoteIdentifier = this.getAttribute('remote-identifier');
111
111
  if (remoteIdentifier && remoteIdentifier.length > 0) {
package/www/situm.js CHANGED
@@ -3,6 +3,8 @@ const common = require('@situm/cordova.common-utils');
3
3
 
4
4
  var PLUGIN_NAME = 'SitumPlugin';
5
5
  let _internalEventDelegate = undefined;
6
+ let _internalTokenCallback = undefined;
7
+ let _token = String;
6
8
 
7
9
  let _clientLocationUpdateCallback;
8
10
  let _clientLocationStatusCallback;
@@ -48,6 +50,12 @@ var Situm = {
48
50
  internalHandleMapViewMessage: function(message, payload) {
49
51
  exec(() => {}, () => {}, PLUGIN_NAME, 'internalHandleMapViewMessage', [message, payload]);
50
52
  },
53
+ internalGetToken: function() {
54
+ return _token;
55
+ },
56
+ internalSetTokenCallback: function(callback) {
57
+ _internalTokenCallback = callback;
58
+ },
51
59
  /**
52
60
  * Provides your API key to the Situm SDK.
53
61
  * @description Provides your API key to the Situm SDK. This key is generated for your application in the Dashboard. Old credentials will be removed.
@@ -63,6 +71,36 @@ var Situm = {
63
71
  setUseRemoteConfig: function (useRemoteConfig, cb, error) {
64
72
  exec(cb, error, PLUGIN_NAME, 'setUseRemoteConfig', [useRemoteConfig]);
65
73
  },
74
+ /**
75
+ * Provides your token to the Situm SDK. Any previously configured credentials will be replaced.
76
+ * <p>The SDK does not cryptographically validate the token signature, nor does it verify the
77
+ * token against Situm servers when this method is called. The token is parsed locally only to
78
+ * obtain the account information needed by the SDK, and it will be sent as a Bearer token in
79
+ * subsequent authenticated network requests.</p>
80
+ *
81
+ * <p>If the provided token is expired, has an invalid signature, or is otherwise rejected by
82
+ * Situm servers, network operations that require server authentication will fail. However,
83
+ * features that can operate with already cached local data may continue to work, such as
84
+ * visualizing cached resources or positioning with previously downloaded positioning data.</p>
85
+ *
86
+ * <p>User-provided tokens cannot be renewed automatically by the SDK. To recover from an
87
+ * expired or rejected token, provide a new token by calling this method again.</p>
88
+ *
89
+ * @description Provides your token to the Situm SDK. Any previously configured credentials will be replaced.
90
+ * @param {string} base64Token String representing the token used for authentication; must not be {@code null} or empty.
91
+ * The expected format is a base64-encoded JWT with header, payload and signature sections.
92
+ * This token can be retrieved from <a href="https://developers.situm.com/pages/rest/openapi/#tag/jwt/POST/api/v1/auth/access_tokens">a REST endpoint</a>.
93
+ * @param {function} cb Cordova native callback to recive data.
94
+ * @param {function} error Cordova native callback to recive errors.
95
+ * @return {boolean} success True if operation finished successfully, otherwise false
96
+ */
97
+ setToken: function (base64Token, cb, error) {
98
+ _token = base64Token;
99
+ if (_internalTokenCallback) {
100
+ _internalTokenCallback(base64Token);
101
+ }
102
+ exec(cb, error, PLUGIN_NAME, 'setToken', [base64Token]);
103
+ },
66
104
  /**
67
105
  * Provides user's email and password.
68
106
  * @description Provides user's email and password. This credentials will be used to obtain a valid user token to authenticate the server request, when necessary. Token obtaining is not necessary done when this method is executed. Old credentials will be removed.