wealthica-sdk-js 0.0.17 → 0.0.18

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/README.md CHANGED
@@ -165,7 +165,7 @@ token = await user.getToken(); // fetches and returns a new token
165
165
  token = await user.getToken({ minimumLifeTime: 600 }); // fetches and returns another new token
166
166
  ```
167
167
 
168
- #### user.getConnectData({ provider, redirectURI, state, lang, theme, providersPerLine })
168
+ #### user.getConnectData({ provider, redirectURI, state, lang, theme, providersPerLine, webhookURI })
169
169
 
170
170
  This method returns a Wealthica Connect URL and authentication token for user to connect an institution.
171
171
 
@@ -192,6 +192,7 @@ const { url, token } = await user.getConnectData({
192
192
  theme: 'light', // optional (light | dark), 'light' by default
193
193
  providersPerLine: 1, // optional (1 | 2), 2 by default
194
194
  features: 'feature1,feature2', // optional, a comma-separated list of features. undefined by default
195
+ webhookURI: 'YOUR_WEBHOOK_URI', // optional, URL to receive webhook notifications (must be HTTPS)
195
196
  });
196
197
  // {
197
198
  // url: "https://connect.wealthica.com/connect/coinbase?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&origin=YOUR_SITE_ORIGIN&state=YOUR_APP_STATE&lang=en&theme=light&providersPerLine=2",
@@ -227,7 +228,7 @@ const user2 = wealthica.login('USER_ID_2');
227
228
  const { url: url2, token } = await user2.getConnectData();
228
229
  ```
229
230
 
230
- #### user.connect({ provider, providers, institutionId, lang, theme, providersPerLine, features, origin })
231
+ #### user.connect({ provider, providers, institutionId, lang, theme, providersPerLine, features, origin, webhookURI })
231
232
 
232
233
  This method starts the Wealthica Connect process inside your webpage/app for user to connect their institution.
233
234
 
@@ -238,6 +239,7 @@ This method accepts the same parameters as `user.getConnectData()` except for `r
238
239
  ```javascript
239
240
  user.connect({
240
241
  // additional options
242
+ webhookURI: 'YOUR_WEBHOOK_URI', // optional, URL to receive webhook notifications (must be HTTPS)
241
243
  }).onConnection((institution, data) => {
242
244
  console.log('provider', data.provider);
243
245
  // Send the institution to your server
@@ -249,7 +251,7 @@ user.connect({
249
251
  });
250
252
  ```
251
253
 
252
- #### user.reconnect(institutionId)
254
+ #### user.reconnect(institutionId, { lang, theme, features, origin, webhookURI })
253
255
 
254
256
  This method starts the Wealthica Connect process to re-connect an existing institution that has expired/revoked credentials.
255
257
 
@@ -258,6 +260,7 @@ Connection response are provided via callbacks.
258
260
  ```javascript
259
261
  user.reconnect('INSTITUTION_ID', {
260
262
  // additional options
263
+ webhookURI: 'YOUR_WEBHOOK_URI', // optional, URL to receive webhook notifications (must be HTTPS)
261
264
  }).onConnection(((institution, data) => {
262
265
  console.log('provider', data.provider);
263
266
  // Send the institution to your server
@@ -6208,9 +6208,11 @@ var API = /*#__PURE__*/function () {
6208
6208
  theme,
6209
6209
  providersPerLine,
6210
6210
  features,
6211
+ webhookURI,
6211
6212
  _this$config5,
6212
6213
  clientId,
6213
6214
  connectURL,
6215
+ _url,
6214
6216
  token,
6215
6217
  query,
6216
6218
  queryString,
@@ -6221,13 +6223,32 @@ var API = /*#__PURE__*/function () {
6221
6223
  switch (_context4.prev = _context4.next) {
6222
6224
  case 0:
6223
6225
  options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
6224
- provider = options.provider, institutionId = options.institutionId, state = options.state, _options$origin = options.origin, origin = _options$origin === void 0 ? this.isBrowser ? window.location.origin : undefined : _options$origin, lang = options.lang, _options$redirectURI = options.redirectURI, redirectURI = _options$redirectURI === void 0 ? this.config.redirectURI : _options$redirectURI, providers = options.providers, _options$providerGrou = options.providerGroups, providerGroups = _options$providerGrou === void 0 ? ['core'] : _options$providerGrou, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features;
6225
- _this$config5 = this.config, clientId = _this$config5.clientId, connectURL = _this$config5.connectURL; // Get a token with at least 10 minutes left
6226
- _context4.next = 5;
6226
+ provider = options.provider, institutionId = options.institutionId, state = options.state, _options$origin = options.origin, origin = _options$origin === void 0 ? this.isBrowser ? window.location.origin : undefined : _options$origin, lang = options.lang, _options$redirectURI = options.redirectURI, redirectURI = _options$redirectURI === void 0 ? this.config.redirectURI : _options$redirectURI, providers = options.providers, _options$providerGrou = options.providerGroups, providerGroups = _options$providerGrou === void 0 ? ['core'] : _options$providerGrou, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, webhookURI = options.webhookURI;
6227
+ _this$config5 = this.config, clientId = _this$config5.clientId, connectURL = _this$config5.connectURL; // Validate webhookURI if provided
6228
+ if (!webhookURI) {
6229
+ _context4.next = 13;
6230
+ break;
6231
+ }
6232
+ _context4.prev = 4;
6233
+ _url = new URL(webhookURI);
6234
+ if (!(_url.protocol !== 'https:')) {
6235
+ _context4.next = 8;
6236
+ break;
6237
+ }
6238
+ throw new Error('Webhook URI must use HTTPS protocol');
6239
+ case 8:
6240
+ _context4.next = 13;
6241
+ break;
6242
+ case 10:
6243
+ _context4.prev = 10;
6244
+ _context4.t0 = _context4["catch"](4);
6245
+ throw new Error("Invalid webhook URI: ".concat(_context4.t0.message));
6246
+ case 13:
6247
+ _context4.next = 15;
6227
6248
  return this.getToken({
6228
6249
  minimumLifetime: 600
6229
6250
  });
6230
- case 5:
6251
+ case 15:
6231
6252
  token = _context4.sent;
6232
6253
  query = {
6233
6254
  client_id: clientId,
@@ -6240,7 +6261,8 @@ var API = /*#__PURE__*/function () {
6240
6261
  provider_groups: providerGroups.join(','),
6241
6262
  theme: ['light', 'dark'].includes(theme) ? theme : 'light',
6242
6263
  providers_per_line: providersPerLine && ['1', '2'].includes(providersPerLine.toString()) ? providersPerLine.toString() : '2',
6243
- features: features
6264
+ features: features,
6265
+ webhook_uri: webhookURI
6244
6266
  }; // Cleanup blank params
6245
6267
  Object.keys(query).forEach(function (key) {
6246
6268
  return [undefined, null, ''].includes(query[key]) && delete query[key];
@@ -6254,12 +6276,12 @@ var API = /*#__PURE__*/function () {
6254
6276
  url: "".concat(url, "?").concat(queryString),
6255
6277
  token: token
6256
6278
  });
6257
- case 12:
6279
+ case 22:
6258
6280
  case "end":
6259
6281
  return _context4.stop();
6260
6282
  }
6261
6283
  }
6262
- }, _callee4, this);
6284
+ }, _callee4, this, [[4, 10]]);
6263
6285
  }));
6264
6286
  function getConnectData() {
6265
6287
  return _getConnectData.apply(this, arguments);
@@ -6313,14 +6335,14 @@ var API = /*#__PURE__*/function () {
6313
6335
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6314
6336
  if (!this.isBrowser) throw new Error('Only supported in Browser.');
6315
6337
  _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
6316
- var provider, providers, providerGroups, institutionId, lang, theme, providersPerLine, features, connectionType, origin, _yield$_this$getConne, url, token;
6338
+ var provider, providers, providerGroups, institutionId, lang, theme, providersPerLine, features, connectionType, origin, webhookURI, _yield$_this$getConne, url, token;
6317
6339
  return regeneratorRuntime.wrap(function _callee5$(_context5) {
6318
6340
  while (1) {
6319
6341
  switch (_context5.prev = _context5.next) {
6320
6342
  case 0:
6321
6343
  _context5.prev = 0;
6322
6344
  _this._widgetOpened = true;
6323
- provider = options.provider, providers = options.providers, providerGroups = options.providerGroups, institutionId = options.institutionId, lang = options.lang, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, connectionType = options.connectionType, origin = options.origin;
6345
+ provider = options.provider, providers = options.providers, providerGroups = options.providerGroups, institutionId = options.institutionId, lang = options.lang, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, connectionType = options.connectionType, origin = options.origin, webhookURI = options.webhookURI;
6324
6346
  _context5.next = 5;
6325
6347
  return _this.getConnectData({
6326
6348
  provider: provider,
@@ -6331,7 +6353,8 @@ var API = /*#__PURE__*/function () {
6331
6353
  theme: theme,
6332
6354
  providersPerLine: providersPerLine,
6333
6355
  features: features,
6334
- origin: origin
6356
+ origin: origin,
6357
+ webhookURI: webhookURI
6335
6358
  });
6336
6359
  case 5:
6337
6360
  _yield$_this$getConne = _context5.sent;
@@ -6360,7 +6383,7 @@ var API = /*#__PURE__*/function () {
6360
6383
  case 16:
6361
6384
  _context5.prev = 16;
6362
6385
  _context5.t0 = _context5["catch"](0);
6363
- _this._closeWidgetWithError(500, 'Connection refused');
6386
+ _this._closeWidgetWithError(500, _context5.t0.message || 'Connection refused');
6364
6387
  case 19:
6365
6388
  case "end":
6366
6389
  return _context5.stop();
package/dist/wealthica.js CHANGED
@@ -6198,9 +6198,11 @@ var API = /*#__PURE__*/function () {
6198
6198
  theme,
6199
6199
  providersPerLine,
6200
6200
  features,
6201
+ webhookURI,
6201
6202
  _this$config5,
6202
6203
  clientId,
6203
6204
  connectURL,
6205
+ _url,
6204
6206
  token,
6205
6207
  query,
6206
6208
  queryString,
@@ -6211,13 +6213,32 @@ var API = /*#__PURE__*/function () {
6211
6213
  switch (_context4.prev = _context4.next) {
6212
6214
  case 0:
6213
6215
  options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
6214
- provider = options.provider, institutionId = options.institutionId, state = options.state, _options$origin = options.origin, origin = _options$origin === void 0 ? this.isBrowser ? window.location.origin : undefined : _options$origin, lang = options.lang, _options$redirectURI = options.redirectURI, redirectURI = _options$redirectURI === void 0 ? this.config.redirectURI : _options$redirectURI, providers = options.providers, _options$providerGrou = options.providerGroups, providerGroups = _options$providerGrou === void 0 ? ['core'] : _options$providerGrou, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features;
6215
- _this$config5 = this.config, clientId = _this$config5.clientId, connectURL = _this$config5.connectURL; // Get a token with at least 10 minutes left
6216
- _context4.next = 5;
6216
+ provider = options.provider, institutionId = options.institutionId, state = options.state, _options$origin = options.origin, origin = _options$origin === void 0 ? this.isBrowser ? window.location.origin : undefined : _options$origin, lang = options.lang, _options$redirectURI = options.redirectURI, redirectURI = _options$redirectURI === void 0 ? this.config.redirectURI : _options$redirectURI, providers = options.providers, _options$providerGrou = options.providerGroups, providerGroups = _options$providerGrou === void 0 ? ['core'] : _options$providerGrou, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, webhookURI = options.webhookURI;
6217
+ _this$config5 = this.config, clientId = _this$config5.clientId, connectURL = _this$config5.connectURL; // Validate webhookURI if provided
6218
+ if (!webhookURI) {
6219
+ _context4.next = 13;
6220
+ break;
6221
+ }
6222
+ _context4.prev = 4;
6223
+ _url = new URL(webhookURI);
6224
+ if (!(_url.protocol !== 'https:')) {
6225
+ _context4.next = 8;
6226
+ break;
6227
+ }
6228
+ throw new Error('Webhook URI must use HTTPS protocol');
6229
+ case 8:
6230
+ _context4.next = 13;
6231
+ break;
6232
+ case 10:
6233
+ _context4.prev = 10;
6234
+ _context4.t0 = _context4["catch"](4);
6235
+ throw new Error("Invalid webhook URI: ".concat(_context4.t0.message));
6236
+ case 13:
6237
+ _context4.next = 15;
6217
6238
  return this.getToken({
6218
6239
  minimumLifetime: 600
6219
6240
  });
6220
- case 5:
6241
+ case 15:
6221
6242
  token = _context4.sent;
6222
6243
  query = {
6223
6244
  client_id: clientId,
@@ -6230,7 +6251,8 @@ var API = /*#__PURE__*/function () {
6230
6251
  provider_groups: providerGroups.join(','),
6231
6252
  theme: ['light', 'dark'].includes(theme) ? theme : 'light',
6232
6253
  providers_per_line: providersPerLine && ['1', '2'].includes(providersPerLine.toString()) ? providersPerLine.toString() : '2',
6233
- features: features
6254
+ features: features,
6255
+ webhook_uri: webhookURI
6234
6256
  }; // Cleanup blank params
6235
6257
  Object.keys(query).forEach(function (key) {
6236
6258
  return [undefined, null, ''].includes(query[key]) && delete query[key];
@@ -6244,12 +6266,12 @@ var API = /*#__PURE__*/function () {
6244
6266
  url: "".concat(url, "?").concat(queryString),
6245
6267
  token: token
6246
6268
  });
6247
- case 12:
6269
+ case 22:
6248
6270
  case "end":
6249
6271
  return _context4.stop();
6250
6272
  }
6251
6273
  }
6252
- }, _callee4, this);
6274
+ }, _callee4, this, [[4, 10]]);
6253
6275
  }));
6254
6276
  function getConnectData() {
6255
6277
  return _getConnectData.apply(this, arguments);
@@ -6303,14 +6325,14 @@ var API = /*#__PURE__*/function () {
6303
6325
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6304
6326
  if (!this.isBrowser) throw new Error('Only supported in Browser.');
6305
6327
  _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
6306
- var provider, providers, providerGroups, institutionId, lang, theme, providersPerLine, features, connectionType, origin, _yield$_this$getConne, url, token;
6328
+ var provider, providers, providerGroups, institutionId, lang, theme, providersPerLine, features, connectionType, origin, webhookURI, _yield$_this$getConne, url, token;
6307
6329
  return regeneratorRuntime.wrap(function _callee5$(_context5) {
6308
6330
  while (1) {
6309
6331
  switch (_context5.prev = _context5.next) {
6310
6332
  case 0:
6311
6333
  _context5.prev = 0;
6312
6334
  _this._widgetOpened = true;
6313
- provider = options.provider, providers = options.providers, providerGroups = options.providerGroups, institutionId = options.institutionId, lang = options.lang, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, connectionType = options.connectionType, origin = options.origin;
6335
+ provider = options.provider, providers = options.providers, providerGroups = options.providerGroups, institutionId = options.institutionId, lang = options.lang, theme = options.theme, providersPerLine = options.providersPerLine, features = options.features, connectionType = options.connectionType, origin = options.origin, webhookURI = options.webhookURI;
6314
6336
  _context5.next = 5;
6315
6337
  return _this.getConnectData({
6316
6338
  provider: provider,
@@ -6321,7 +6343,8 @@ var API = /*#__PURE__*/function () {
6321
6343
  theme: theme,
6322
6344
  providersPerLine: providersPerLine,
6323
6345
  features: features,
6324
- origin: origin
6346
+ origin: origin,
6347
+ webhookURI: webhookURI
6325
6348
  });
6326
6349
  case 5:
6327
6350
  _yield$_this$getConne = _context5.sent;
@@ -6350,7 +6373,7 @@ var API = /*#__PURE__*/function () {
6350
6373
  case 16:
6351
6374
  _context5.prev = 16;
6352
6375
  _context5.t0 = _context5["catch"](0);
6353
- _this._closeWidgetWithError(500, 'Connection refused');
6376
+ _this._closeWidgetWithError(500, _context5.t0.message || 'Connection refused');
6354
6377
  case 19:
6355
6378
  case "end":
6356
6379
  return _context5.stop();