@turnkey/sdk-react 3.0.3 → 3.0.4

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 (33) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.mjs +84 -102
  3. package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -1
  4. package/dist/components/auth/Apple.d.ts +4 -2
  5. package/dist/components/auth/Apple.d.ts.map +1 -1
  6. package/dist/components/auth/Apple.js +66 -41
  7. package/dist/components/auth/Apple.js.map +1 -1
  8. package/dist/components/auth/Apple.mjs +66 -41
  9. package/dist/components/auth/Apple.mjs.map +1 -1
  10. package/dist/components/auth/Auth.d.ts.map +1 -1
  11. package/dist/components/auth/Auth.js +25 -45
  12. package/dist/components/auth/Auth.js.map +1 -1
  13. package/dist/components/auth/Auth.mjs +119 -174
  14. package/dist/components/auth/Auth.mjs.map +1 -1
  15. package/dist/components/auth/Facebook.js.map +1 -1
  16. package/dist/components/auth/Facebook.mjs +3 -3
  17. package/dist/components/auth/Facebook.mjs.map +1 -1
  18. package/dist/components/auth/Google.js.map +1 -1
  19. package/dist/components/auth/Google.mjs +1 -1
  20. package/dist/components/auth/Google.mjs.map +1 -1
  21. package/dist/components/auth/OtpVerification.mjs +2 -2
  22. package/dist/components/auth/OtpVerification.mjs.map +1 -1
  23. package/dist/components/auth/PhoneInput.js.map +1 -1
  24. package/dist/components/auth/facebookUtils.mjs +2 -2
  25. package/dist/components/auth/facebookUtils.mjs.map +1 -1
  26. package/dist/components/auth/otp.js.map +1 -1
  27. package/dist/components/export/Export.mjs +4 -4
  28. package/dist/components/export/Export.mjs.map +1 -1
  29. package/dist/components/import/Import.mjs +3 -3
  30. package/dist/components/import/Import.mjs.map +1 -1
  31. package/dist/contexts/TurnkeyContext.mjs +3 -3
  32. package/dist/contexts/TurnkeyContext.mjs.map +1 -1
  33. package/package.json +4 -4
@@ -109,7 +109,7 @@ var Auth = function Auth(_ref) {
109
109
  passkeyCreated = _useState22[0],
110
110
  setPasskeyCreated = _useState22[1];
111
111
  var handleResendCode = /*#__PURE__*/function () {
112
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
112
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
113
113
  return _regeneratorRuntime().wrap(function _callee$(_context) {
114
114
  while (1) switch (_context.prev = _context.next) {
115
115
  case 0:
@@ -162,118 +162,38 @@ var Auth = function Auth(_ref) {
162
162
  var phoneNumber = parsePhoneNumberFromString(phone);
163
163
  return (_phoneNumber$isValid = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.isValid()) !== null && _phoneNumber$isValid !== void 0 ? _phoneNumber$isValid : false;
164
164
  };
165
- var handleGetOrCreateSuborg = /*#__PURE__*/function () {
166
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(filterType, filterValue) {
167
- var additionalData,
168
- suborgId,
169
- getVerifiedSuborgsResponse,
170
- getSuborgsResponse,
171
- createSuborgData,
172
- createSuborgResponse,
173
- _args2 = arguments;
165
+ var handleAuthSuccess = /*#__PURE__*/function () {
166
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(credentialBundle, expirationSeconds) {
174
167
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
175
168
  while (1) switch (_context2.prev = _context2.next) {
176
- case 0:
177
- additionalData = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
178
- if (!(filterType == FilterType.Email || filterType == FilterType.PhoneNumber)) {
179
- _context2.next = 11;
180
- break;
181
- }
182
- _context2.next = 4;
183
- return server.getVerifiedSuborgs({
184
- filterType: filterType,
185
- filterValue: filterValue
186
- });
187
- case 4:
188
- getVerifiedSuborgsResponse = _context2.sent;
189
- if (!(!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds)) {
190
- _context2.next = 8;
191
- break;
192
- }
193
- onError(authErrors.suborg.fetchFailed);
194
- return _context2.abrupt("return", null);
195
- case 8:
196
- suborgId = getVerifiedSuborgsResponse === null || getVerifiedSuborgsResponse === void 0 ? void 0 : getVerifiedSuborgsResponse.organizationIds[0];
197
- _context2.next = 18;
198
- break;
199
- case 11:
200
- _context2.next = 13;
201
- return server.getSuborgs({
202
- filterType: filterType,
203
- filterValue: filterValue
204
- });
205
- case 13:
206
- getSuborgsResponse = _context2.sent;
207
- if (!(!getSuborgsResponse || !getSuborgsResponse.organizationIds)) {
208
- _context2.next = 17;
209
- break;
210
- }
211
- onError(authErrors.suborg.fetchFailed);
212
- return _context2.abrupt("return", null);
213
- case 17:
214
- suborgId = getSuborgsResponse === null || getSuborgsResponse === void 0 ? void 0 : getSuborgsResponse.organizationIds[0];
215
- case 18:
216
- if (suborgId) {
217
- _context2.next = 27;
218
- break;
219
- }
220
- createSuborgData = _objectSpread2({}, additionalData);
221
- if (filterType === FilterType.Email) createSuborgData.email = filterValue;else if (filterType === FilterType.PhoneNumber) createSuborgData.phoneNumber = filterValue;
222
- if (customAccounts) {
223
- createSuborgData.customAccounts = customAccounts;
224
- }
225
- _context2.next = 24;
226
- return server.createSuborg(createSuborgData);
227
- case 24:
228
- createSuborgResponse = _context2.sent;
229
- if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
230
- onError(authErrors.suborg.createFailed);
231
- }
232
- suborgId = createSuborgResponse === null || createSuborgResponse === void 0 ? void 0 : createSuborgResponse.subOrganizationId;
233
- case 27:
234
- return _context2.abrupt("return", suborgId);
235
- case 28:
236
- case "end":
237
- return _context2.stop();
238
- }
239
- }, _callee2);
240
- }));
241
- return function handleGetOrCreateSuborg(_x, _x2) {
242
- return _ref3.apply(this, arguments);
243
- };
244
- }();
245
- var handleAuthSuccess = /*#__PURE__*/function () {
246
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(credentialBundle, expirationSeconds) {
247
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
248
- while (1) switch (_context3.prev = _context3.next) {
249
169
  case 0:
250
170
  if (!credentialBundle) {
251
- _context3.next = 7;
171
+ _context2.next = 7;
252
172
  break;
253
173
  }
254
- _context3.next = 3;
174
+ _context2.next = 3;
255
175
  return authIframeClient.injectCredentialBundle(credentialBundle);
256
176
  case 3:
257
- _context3.next = 5;
177
+ _context2.next = 5;
258
178
  return authIframeClient.loginWithAuthBundle(credentialBundle, expirationSeconds);
259
179
  case 5:
260
- _context3.next = 7;
180
+ _context2.next = 7;
261
181
  return onAuthSuccess();
262
182
  case 7:
263
183
  case "end":
264
- return _context3.stop();
184
+ return _context2.stop();
265
185
  }
266
- }, _callee3);
186
+ }, _callee2);
267
187
  }));
268
- return function handleAuthSuccess(_x3, _x4) {
269
- return _ref4.apply(this, arguments);
188
+ return function handleAuthSuccess(_x, _x2) {
189
+ return _ref3.apply(this, arguments);
270
190
  };
271
191
  }();
272
192
  var handleSignupWithPasskey = /*#__PURE__*/function () {
273
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
274
- var siteInfo, _turnkey$config$defau, _ref6, encodedChallenge, attestation, response, sessionResponse, _authConfig$sessionLe;
275
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
276
- while (1) switch (_context4.prev = _context4.next) {
193
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
194
+ var siteInfo, _turnkey$config$defau, _ref5, encodedChallenge, attestation, response, sessionResponse, _authConfig$sessionLe;
195
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
196
+ while (1) switch (_context3.prev = _context3.next) {
277
197
  case 0:
278
198
  setPasskeySignupError("");
279
199
  siteInfo = "".concat(new URL(window.location.href).hostname, " - ").concat(new Date().toLocaleString(undefined, {
@@ -286,12 +206,12 @@ var Auth = function Auth(_ref) {
286
206
  }));
287
207
  setPasskeySignupScreen(false);
288
208
  setPasskeyCreationScreen(true);
289
- _context4.prev = 4;
209
+ _context3.prev = 4;
290
210
  if (passkeyCreated) {
291
- _context4.next = 22;
211
+ _context3.next = 22;
292
212
  break;
293
213
  }
294
- _context4.next = 8;
214
+ _context3.next = 8;
295
215
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createUserPasskey({
296
216
  publicKey: {
297
217
  user: {
@@ -301,21 +221,21 @@ var Auth = function Auth(_ref) {
301
221
  }
302
222
  });
303
223
  case 8:
304
- _context4.t0 = _context4.sent;
305
- if (_context4.t0) {
306
- _context4.next = 11;
224
+ _context3.t0 = _context3.sent;
225
+ if (_context3.t0) {
226
+ _context3.next = 11;
307
227
  break;
308
228
  }
309
- _context4.t0 = {};
229
+ _context3.t0 = {};
310
230
  case 11:
311
- _ref6 = _context4.t0;
312
- encodedChallenge = _ref6.encodedChallenge;
313
- attestation = _ref6.attestation;
231
+ _ref5 = _context3.t0;
232
+ encodedChallenge = _ref5.encodedChallenge;
233
+ attestation = _ref5.attestation;
314
234
  if (!(encodedChallenge && attestation)) {
315
- _context4.next = 21;
235
+ _context3.next = 21;
316
236
  break;
317
237
  }
318
- _context4.next = 17;
238
+ _context3.next = 17;
319
239
  return server.createSuborg(_objectSpread2({
320
240
  email: email,
321
241
  passkey: {
@@ -327,15 +247,15 @@ var Auth = function Auth(_ref) {
327
247
  customAccounts: customAccounts
328
248
  }));
329
249
  case 17:
330
- response = _context4.sent;
250
+ response = _context3.sent;
331
251
  if (response !== null && response !== void 0 && response.subOrganizationId) {
332
252
  setPasskeyCreated(true);
333
253
  }
334
- _context4.next = 22;
254
+ _context3.next = 22;
335
255
  break;
336
256
  case 21:
337
257
  case 22:
338
- _context4.next = 24;
258
+ _context3.next = 24;
339
259
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
340
260
  targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
341
261
  }, authConfig.sessionLengthSeconds !== undefined && {
@@ -344,43 +264,43 @@ var Auth = function Auth(_ref) {
344
264
  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
345
265
  }));
346
266
  case 24:
347
- sessionResponse = _context4.sent;
267
+ sessionResponse = _context3.sent;
348
268
  if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
349
- _context4.next = 30;
269
+ _context3.next = 30;
350
270
  break;
351
271
  }
352
- _context4.next = 28;
272
+ _context3.next = 28;
353
273
  return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe === void 0 ? void 0 : _authConfig$sessionLe.toString());
354
274
  case 28:
355
- _context4.next = 31;
275
+ _context3.next = 31;
356
276
  break;
357
277
  case 30:
358
278
  setPasskeySignupError(authErrors.passkey.loginFailed);
359
279
  case 31:
360
- _context4.next = 36;
280
+ _context3.next = 36;
361
281
  break;
362
282
  case 33:
363
- _context4.prev = 33;
364
- _context4.t1 = _context4["catch"](4);
283
+ _context3.prev = 33;
284
+ _context3.t1 = _context3["catch"](4);
365
285
  setPasskeySignupError(authErrors.passkey.timeoutOrNotAllowed);
366
286
  case 36:
367
287
  case "end":
368
- return _context4.stop();
288
+ return _context3.stop();
369
289
  }
370
- }, _callee4, null, [[4, 33]]);
290
+ }, _callee3, null, [[4, 33]]);
371
291
  }));
372
292
  return function handleSignupWithPasskey() {
373
- return _ref5.apply(this, arguments);
293
+ return _ref4.apply(this, arguments);
374
294
  };
375
295
  }();
376
296
  var handleLoginWithPasskey = /*#__PURE__*/function () {
377
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
297
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
378
298
  var _turnkey$config$defau2, sessionResponse, _authConfig$sessionLe2;
379
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
380
- while (1) switch (_context5.prev = _context5.next) {
299
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
300
+ while (1) switch (_context4.prev = _context4.next) {
381
301
  case 0:
382
- _context5.prev = 0;
383
- _context5.next = 3;
302
+ _context4.prev = 0;
303
+ _context4.next = 3;
384
304
  return passkeyClient === null || passkeyClient === void 0 ? void 0 : passkeyClient.createReadWriteSession(_objectSpread2(_objectSpread2({
385
305
  targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
386
306
  }, authConfig.sessionLengthSeconds !== undefined && {
@@ -389,45 +309,57 @@ var Auth = function Auth(_ref) {
389
309
  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
390
310
  }));
391
311
  case 3:
392
- sessionResponse = _context5.sent;
312
+ sessionResponse = _context4.sent;
393
313
  if (!(sessionResponse !== null && sessionResponse !== void 0 && sessionResponse.credentialBundle)) {
394
- _context5.next = 9;
314
+ _context4.next = 9;
395
315
  break;
396
316
  }
397
- _context5.next = 7;
317
+ _context4.next = 7;
398
318
  return handleAuthSuccess(sessionResponse.credentialBundle, (_authConfig$sessionLe2 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe2 === void 0 ? void 0 : _authConfig$sessionLe2.toString());
399
319
  case 7:
400
- _context5.next = 10;
320
+ _context4.next = 10;
401
321
  break;
402
322
  case 9:
403
323
  case 10:
404
- _context5.next = 15;
324
+ _context4.next = 15;
405
325
  break;
406
326
  case 12:
407
- _context5.prev = 12;
408
- _context5.t0 = _context5["catch"](0);
327
+ _context4.prev = 12;
328
+ _context4.t0 = _context4["catch"](0);
409
329
  onError(authErrors.passkey.loginFailed);
410
330
  case 15:
411
331
  case "end":
412
- return _context5.stop();
332
+ return _context4.stop();
413
333
  }
414
- }, _callee5, null, [[0, 12]]);
334
+ }, _callee4, null, [[0, 12]]);
415
335
  }));
416
336
  return function handleLoginWithPasskey() {
417
- return _ref7.apply(this, arguments);
337
+ return _ref6.apply(this, arguments);
418
338
  };
419
339
  }();
420
340
  var handleOtpLogin = /*#__PURE__*/function () {
421
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(type, value, otpType) {
422
- var suborgId, initAuthResponse;
423
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
424
- while (1) switch (_context6.prev = _context6.next) {
341
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(type, value, otpType) {
342
+ var resp, suborgIds, suborgId, initAuthResponse;
343
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
344
+ while (1) switch (_context5.prev = _context5.next) {
425
345
  case 0:
426
- _context6.next = 2;
427
- return handleGetOrCreateSuborg(type, value);
346
+ _context5.next = 2;
347
+ return server.getOrCreateSuborg({
348
+ filterType: type,
349
+ filterValue: value
350
+ });
428
351
  case 2:
429
- suborgId = _context6.sent;
430
- _context6.next = 5;
352
+ resp = _context5.sent;
353
+ suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
354
+ if (!(!suborgIds || suborgIds.length === 0)) {
355
+ _context5.next = 7;
356
+ break;
357
+ }
358
+ onError(authErrors.oauth.loginFailed);
359
+ return _context5.abrupt("return");
360
+ case 7:
361
+ suborgId = suborgIds[0];
362
+ _context5.next = 10;
431
363
  return server.sendOtp(_objectSpread2(_objectSpread2({
432
364
  suborgID: suborgId,
433
365
  otpType: otpType,
@@ -437,8 +369,8 @@ var Auth = function Auth(_ref) {
437
369
  }), {}, {
438
370
  userIdentifier: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey
439
371
  }));
440
- case 5:
441
- initAuthResponse = _context6.sent;
372
+ case 10:
373
+ initAuthResponse = _context5.sent;
442
374
  if (initAuthResponse && initAuthResponse.otpId) {
443
375
  setSuborgId(suborgId);
444
376
  setOtpId(initAuthResponse === null || initAuthResponse === void 0 ? void 0 : initAuthResponse.otpId);
@@ -446,60 +378,73 @@ var Auth = function Auth(_ref) {
446
378
  } else {
447
379
  onError(authErrors.otp.sendFailed);
448
380
  }
449
- case 7:
381
+ case 12:
450
382
  case "end":
451
- return _context6.stop();
383
+ return _context5.stop();
452
384
  }
453
- }, _callee6);
385
+ }, _callee5);
454
386
  }));
455
- return function handleOtpLogin(_x5, _x6, _x7) {
456
- return _ref8.apply(this, arguments);
387
+ return function handleOtpLogin(_x3, _x4, _x5) {
388
+ return _ref7.apply(this, arguments);
457
389
  };
458
390
  }();
459
391
  var handleOAuthLogin = /*#__PURE__*/function () {
460
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(credential, providerName) {
461
- var suborgId, oauthResponse, _authConfig$sessionLe3;
462
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
463
- while (1) switch (_context7.prev = _context7.next) {
392
+ var _ref8 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(credential, providerName) {
393
+ var resp, suborgIds, suborgId, oauthResponse, _authConfig$sessionLe3;
394
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
395
+ while (1) switch (_context6.prev = _context6.next) {
464
396
  case 0:
465
397
  setOauthLoading(providerName);
466
- _context7.next = 3;
467
- return handleGetOrCreateSuborg(FilterType.OidcToken, credential, {
468
- oauthProviders: [{
469
- providerName: providerName,
470
- oidcToken: credential
471
- }]
398
+ _context6.next = 3;
399
+ return server.getOrCreateSuborg({
400
+ filterType: FilterType.OidcToken,
401
+ filterValue: credential,
402
+ additionalData: {
403
+ oauthProviders: [{
404
+ providerName: providerName,
405
+ oidcToken: credential
406
+ }]
407
+ }
472
408
  });
473
409
  case 3:
474
- suborgId = _context7.sent;
475
- _context7.next = 6;
410
+ resp = _context6.sent;
411
+ suborgIds = resp === null || resp === void 0 ? void 0 : resp.subOrganizationIds;
412
+ if (!(!suborgIds || suborgIds.length === 0)) {
413
+ _context6.next = 8;
414
+ break;
415
+ }
416
+ onError(authErrors.oauth.loginFailed);
417
+ return _context6.abrupt("return");
418
+ case 8:
419
+ suborgId = suborgIds[0];
420
+ _context6.next = 11;
476
421
  return server.oauth({
477
422
  suborgID: suborgId,
478
423
  oidcToken: credential,
479
424
  targetPublicKey: authIframeClient === null || authIframeClient === void 0 ? void 0 : authIframeClient.iframePublicKey,
480
425
  sessionLengthSeconds: authConfig.sessionLengthSeconds
481
426
  });
482
- case 6:
483
- oauthResponse = _context7.sent;
427
+ case 11:
428
+ oauthResponse = _context6.sent;
484
429
  if (!(oauthResponse && oauthResponse.token)) {
485
- _context7.next = 12;
430
+ _context6.next = 17;
486
431
  break;
487
432
  }
488
- _context7.next = 10;
433
+ _context6.next = 15;
489
434
  return handleAuthSuccess(oauthResponse.token, (_authConfig$sessionLe3 = authConfig.sessionLengthSeconds) === null || _authConfig$sessionLe3 === void 0 ? void 0 : _authConfig$sessionLe3.toString());
490
- case 10:
491
- _context7.next = 13;
435
+ case 15:
436
+ _context6.next = 18;
492
437
  break;
493
- case 12:
438
+ case 17:
494
439
  onError(authErrors.oauth.loginFailed);
495
- case 13:
440
+ case 18:
496
441
  case "end":
497
- return _context7.stop();
442
+ return _context6.stop();
498
443
  }
499
- }, _callee7);
444
+ }, _callee6);
500
445
  }));
501
- return function handleOAuthLogin(_x8, _x9) {
502
- return _ref9.apply(this, arguments);
446
+ return function handleOAuthLogin(_x6, _x7) {
447
+ return _ref8.apply(this, arguments);
503
448
  };
504
449
  }();
505
450
  var renderBackButton = function renderBackButton() {