@turnkey/sdk-react 3.0.1 → 3.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.
@@ -17,6 +17,7 @@ import OtpVerification from './OtpVerification.mjs';
17
17
  import { useTurnkey } from '../../hooks/use-turnkey.mjs';
18
18
  import { OtpType, FilterType, authErrors } from './constants.mjs';
19
19
  import { server } from '@turnkey/sdk-server';
20
+ import parsePhoneNumberFromString from 'libphonenumber-js';
20
21
 
21
22
  var passkeyIcon = jsxs("svg", {
22
23
  xmlns: "http://www.w3.org/2000/svg",
@@ -157,7 +158,9 @@ var Auth = function Auth(_ref) {
157
158
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
158
159
  };
159
160
  var isValidPhone = function isValidPhone(phone) {
160
- return /^\+1\d{10}$/.test(phone);
161
+ var _phoneNumber$isValid;
162
+ var phoneNumber = parsePhoneNumberFromString(phone);
163
+ return (_phoneNumber$isValid = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.isValid()) !== null && _phoneNumber$isValid !== void 0 ? _phoneNumber$isValid : false;
161
164
  };
162
165
  var handleGetOrCreateSuborg = /*#__PURE__*/function () {
163
166
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(filterType, filterValue) {
@@ -173,7 +176,7 @@ var Auth = function Auth(_ref) {
173
176
  case 0:
174
177
  additionalData = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
175
178
  if (!(filterType == FilterType.Email || filterType == FilterType.PhoneNumber)) {
176
- _context2.next = 9;
179
+ _context2.next = 11;
177
180
  break;
178
181
  }
179
182
  _context2.next = 4;
@@ -183,27 +186,35 @@ var Auth = function Auth(_ref) {
183
186
  });
184
187
  case 4:
185
188
  getVerifiedSuborgsResponse = _context2.sent;
186
- if (!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds) {
187
- onError(authErrors.suborg.fetchFailed);
189
+ if (!(!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds)) {
190
+ _context2.next = 8;
191
+ break;
188
192
  }
193
+ onError(authErrors.suborg.fetchFailed);
194
+ return _context2.abrupt("return", null);
195
+ case 8:
189
196
  suborgId = getVerifiedSuborgsResponse === null || getVerifiedSuborgsResponse === void 0 ? void 0 : getVerifiedSuborgsResponse.organizationIds[0];
190
- _context2.next = 14;
197
+ _context2.next = 18;
191
198
  break;
192
- case 9:
193
- _context2.next = 11;
199
+ case 11:
200
+ _context2.next = 13;
194
201
  return server.getSuborgs({
195
202
  filterType: filterType,
196
203
  filterValue: filterValue
197
204
  });
198
- case 11:
205
+ case 13:
199
206
  getSuborgsResponse = _context2.sent;
200
- if (!getSuborgsResponse || !getSuborgsResponse.organizationIds) {
201
- onError(authErrors.suborg.fetchFailed);
207
+ if (!(!getSuborgsResponse || !getSuborgsResponse.organizationIds)) {
208
+ _context2.next = 17;
209
+ break;
202
210
  }
211
+ onError(authErrors.suborg.fetchFailed);
212
+ return _context2.abrupt("return", null);
213
+ case 17:
203
214
  suborgId = getSuborgsResponse === null || getSuborgsResponse === void 0 ? void 0 : getSuborgsResponse.organizationIds[0];
204
- case 14:
215
+ case 18:
205
216
  if (suborgId) {
206
- _context2.next = 23;
217
+ _context2.next = 27;
207
218
  break;
208
219
  }
209
220
  createSuborgData = _objectSpread2({}, additionalData);
@@ -211,17 +222,17 @@ var Auth = function Auth(_ref) {
211
222
  if (customAccounts) {
212
223
  createSuborgData.customAccounts = customAccounts;
213
224
  }
214
- _context2.next = 20;
225
+ _context2.next = 24;
215
226
  return server.createSuborg(createSuborgData);
216
- case 20:
227
+ case 24:
217
228
  createSuborgResponse = _context2.sent;
218
229
  if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
219
230
  onError(authErrors.suborg.createFailed);
220
231
  }
221
232
  suborgId = createSuborgResponse === null || createSuborgResponse === void 0 ? void 0 : createSuborgResponse.subOrganizationId;
222
- case 23:
233
+ case 27:
223
234
  return _context2.abrupt("return", suborgId);
224
- case 24:
235
+ case 28:
225
236
  case "end":
226
237
  return _context2.stop();
227
238
  }
@@ -232,7 +243,7 @@ var Auth = function Auth(_ref) {
232
243
  };
233
244
  }();
234
245
  var handleAuthSuccess = /*#__PURE__*/function () {
235
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(credentialBundle) {
246
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(credentialBundle, expirationSeconds) {
236
247
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
237
248
  while (1) switch (_context3.prev = _context3.next) {
238
249
  case 0:
@@ -244,7 +255,7 @@ var Auth = function Auth(_ref) {
244
255
  return authIframeClient.injectCredentialBundle(credentialBundle);
245
256
  case 3:
246
257
  _context3.next = 5;
247
- return authIframeClient.loginWithAuthBundle(credentialBundle);
258
+ return authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
248
259
  case 5:
249
260
  _context3.next = 7;
250
261
  return onAuthSuccess();
@@ -254,13 +265,13 @@ var Auth = function Auth(_ref) {
254
265
  }
255
266
  }, _callee3);
256
267
  }));
257
- return function handleAuthSuccess(_x3) {
268
+ return function handleAuthSuccess(_x3, _x4) {
258
269
  return _ref4.apply(this, arguments);
259
270
  };
260
271
  }();
261
272
  var handleSignupWithPasskey = /*#__PURE__*/function () {
262
273
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
263
- var siteInfo, _turnkey$config$defau, _ref6, encodedChallenge, attestation, response, sessionResponse;
274
+ var siteInfo, _turnkey$config$defau, _ref6, encodedChallenge, attestation, response, sessionResponse, _authConfig$sessionLe;
264
275
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
265
276
  while (1) switch (_context4.prev = _context4.next) {
266
277
  case 0:
@@ -325,10 +336,13 @@ var Auth = function Auth(_ref) {
325
336
  case 21:
326
337
  case 22:
327
338
  _context4.next = 24;
328
- return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession({
329
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
339
+ return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
340
+ targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
341
+ }, authConfig.sessionLengthSeconds !== undefined && {
342
+ expirationSeconds: authConfig.sessionLengthSeconds.toString()
343
+ }), {}, {
330
344
  organizationId: (_turnkey$config$defau = turnkey === null || turnkey === void 0 ? void 0 : turnkey.config.defaultOrganizationId) !== null && _turnkey$config$defau !== void 0 ? _turnkey$config$defau : process.env.NEXT_PUBLIC_ORGANIZATION_ID
331
- });
345
+ }));
332
346
  case 24:
333
347
  sessionResponse = _context4.sent;
334
348
  if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
@@ -336,7 +350,7 @@ var Auth = function Auth(_ref) {
336
350
  break;
337
351
  }
338
352
  _context4.next = 28;
339
- return handleAuthSuccess(sessionResponse.credentialBundle);
353
+ return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString());
340
354
  case 28:
341
355
  _context4.next = 31;
342
356
  break;
@@ -361,16 +375,19 @@ var Auth = function Auth(_ref) {
361
375
  }();
362
376
  var handleLoginWithPasskey = /*#__PURE__*/function () {
363
377
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
364
- var _turnkey$config$defau2, sessionResponse;
378
+ var _turnkey$config$defau2, sessionResponse, _authConfig$sessionLe2;
365
379
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
366
380
  while (1) switch (_context5.prev = _context5.next) {
367
381
  case 0:
368
382
  _context5.prev = 0;
369
383
  _context5.next = 3;
370
- return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession({
371
- targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
384
+ return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
385
+ targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
386
+ }, authConfig.sessionLengthSeconds !== undefined && {
387
+ expirationSeconds: authConfig.sessionLengthSeconds.toString()
388
+ }), {}, {
372
389
  organizationId: (_turnkey$config$defau2 = turnkey === null || turnkey === void 0 ? void 0 : turnkey.config.defaultOrganizationId) !== null && _turnkey$config$defau2 !== void 0 ? _turnkey$config$defau2 : process.env.NEXT_PUBLIC_ORGANIZATION_ID
373
- });
390
+ }));
374
391
  case 3:
375
392
  sessionResponse = _context5.sent;
376
393
  if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
@@ -378,7 +395,7 @@ var Auth = function Auth(_ref) {
378
395
  break;
379
396
  }
380
397
  _context5.next = 7;
381
- return handleAuthSuccess(sessionResponse.credentialBundle);
398
+ return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString());
382
399
  case 7:
383
400
  _context5.next = 10;
384
401
  break;
@@ -435,13 +452,13 @@ var Auth = function Auth(_ref) {
435
452
  }
436
453
  }, _callee6);
437
454
  }));
438
- return function handleOtpLogin(_x4, _x5, _x6) {
455
+ return function handleOtpLogin(_x5, _x6, _x7) {
439
456
  return _ref8.apply(this, arguments);
440
457
  };
441
458
  }();
442
459
  var handleOAuthLogin = /*#__PURE__*/function () {
443
460
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(credential, providerName) {
444
- var suborgId, oauthResponse;
461
+ var suborgId, oauthResponse, _authConfig$sessionLe3;
445
462
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
446
463
  while (1) switch (_context7.prev = _context7.next) {
447
464
  case 0:
@@ -469,7 +486,7 @@ var Auth = function Auth(_ref) {
469
486
  break;
470
487
  }
471
488
  _context7.next = 10;
472
- return handleAuthSuccess(oauthResponse.token);
489
+ return handleAuthSuccess(oauthResponse.token, (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString());
473
490
  case 10:
474
491
  _context7.next = 13;
475
492
  break;
@@ -481,7 +498,7 @@ var Auth = function Auth(_ref) {
481
498
  }
482
499
  }, _callee7);
483
500
  }));
484
- return function handleOAuthLogin(_x7, _x8) {
501
+ return function handleOAuthLogin(_x8, _x9) {
485
502
  return _ref9.apply(this, arguments);
486
503
  };
487
504
  }();