@turnkey/sdk-react 3.0.2 → 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 +25 -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 +29 -45
  12. package/dist/components/auth/Auth.js.map +1 -1
  13. package/dist/components/auth/Auth.mjs +123 -175
  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 +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/components/auth/Auth.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAcnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAoC1D,UAAU,SAAS;IACjB,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,UAAU,EAAE;QACV,YAAY,EAAE,OAAO,CAAC;QACtB,cAAc,EAAE,OAAO,CAAC;QACxB,YAAY,EAAE,OAAO,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;QACtB,eAAe,EAAE,OAAO,CAAC;QACzB,aAAa,EAAE,OAAO,CAAC;QACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,QAAA,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA2lB7B,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../../src/components/auth/Auth.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAcnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAqC1D,UAAU,SAAS;IACjB,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,UAAU,EAAE;QACV,YAAY,EAAE,OAAO,CAAC;QACtB,cAAc,EAAE,OAAO,CAAC;QACxB,YAAY,EAAE,OAAO,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;QACtB,eAAe,EAAE,OAAO,CAAC;QACzB,aAAa,EAAE,OAAO,CAAC;QACvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,QAAA,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA2jB7B,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -18,6 +18,7 @@ var OtpVerification = require('./OtpVerification.js');
18
18
  var useTurnkey = require('../../hooks/use-turnkey.js');
19
19
  var constants = require('./constants.js');
20
20
  var sdkServer = require('@turnkey/sdk-server');
21
+ var parsePhoneNumberFromString = require('libphonenumber-js');
21
22
 
22
23
  const passkeyIcon = jsxRuntime.jsxs("svg", {
23
24
  xmlns: "http://www.w3.org/2000/svg",
@@ -100,45 +101,9 @@ const Auth = ({
100
101
  });
101
102
  }
102
103
  const isValidEmail = email => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
103
- const isValidPhone = phone => /^\+1\d{10}$/.test(phone);
104
- const handleGetOrCreateSuborg = async (filterType, filterValue, additionalData = {}) => {
105
- let suborgId;
106
- if (filterType == constants.FilterType.Email || filterType == constants.FilterType.PhoneNumber) {
107
- const getVerifiedSuborgsResponse = await sdkServer.server.getVerifiedSuborgs({
108
- filterType,
109
- filterValue
110
- });
111
- if (!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds) {
112
- onError(constants.authErrors.suborg.fetchFailed);
113
- return null;
114
- }
115
- suborgId = getVerifiedSuborgsResponse?.organizationIds[0];
116
- } else {
117
- const getSuborgsResponse = await sdkServer.server.getSuborgs({
118
- filterType,
119
- filterValue
120
- });
121
- if (!getSuborgsResponse || !getSuborgsResponse.organizationIds) {
122
- onError(constants.authErrors.suborg.fetchFailed);
123
- return null;
124
- }
125
- suborgId = getSuborgsResponse?.organizationIds[0];
126
- }
127
- if (!suborgId) {
128
- const createSuborgData = {
129
- ...additionalData
130
- };
131
- if (filterType === constants.FilterType.Email) createSuborgData.email = filterValue;else if (filterType === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = filterValue;
132
- if (customAccounts) {
133
- createSuborgData.customAccounts = customAccounts;
134
- }
135
- const createSuborgResponse = await sdkServer.server.createSuborg(createSuborgData);
136
- if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
137
- onError(constants.authErrors.suborg.createFailed);
138
- }
139
- suborgId = createSuborgResponse?.subOrganizationId;
140
- }
141
- return suborgId;
104
+ const isValidPhone = phone => {
105
+ const phoneNumber = parsePhoneNumberFromString(phone);
106
+ return phoneNumber?.isValid() ?? false;
142
107
  };
143
108
  const handleAuthSuccess = async (credentialBundle, expirationSeconds) => {
144
109
  if (credentialBundle) {
@@ -228,7 +193,16 @@ const Auth = ({
228
193
  }
229
194
  };
230
195
  const handleOtpLogin = async (type, value, otpType) => {
231
- const suborgId = await handleGetOrCreateSuborg(type, value);
196
+ const resp = await sdkServer.server.getOrCreateSuborg({
197
+ filterType: type,
198
+ filterValue: value
199
+ });
200
+ const suborgIds = resp?.subOrganizationIds;
201
+ if (!suborgIds || suborgIds.length === 0) {
202
+ onError(constants.authErrors.oauth.loginFailed);
203
+ return;
204
+ }
205
+ const suborgId = suborgIds[0];
232
206
  const initAuthResponse = await sdkServer.server.sendOtp({
233
207
  suborgID: suborgId,
234
208
  otpType,
@@ -248,12 +222,22 @@ const Auth = ({
248
222
  };
249
223
  const handleOAuthLogin = async (credential, providerName) => {
250
224
  setOauthLoading(providerName);
251
- const suborgId = await handleGetOrCreateSuborg(constants.FilterType.OidcToken, credential, {
252
- oauthProviders: [{
253
- providerName,
254
- oidcToken: credential
255
- }]
225
+ const resp = await sdkServer.server.getOrCreateSuborg({
226
+ filterType: constants.FilterType.OidcToken,
227
+ filterValue: credential,
228
+ additionalData: {
229
+ oauthProviders: [{
230
+ providerName,
231
+ oidcToken: credential
232
+ }]
233
+ }
256
234
  });
235
+ const suborgIds = resp?.subOrganizationIds;
236
+ if (!suborgIds || suborgIds.length === 0) {
237
+ onError(constants.authErrors.oauth.loginFailed);
238
+ return;
239
+ }
240
+ const suborgId = suborgIds[0];
257
241
  const oauthResponse = await sdkServer.server.oauth({
258
242
  suborgID: suborgId,
259
243
  oidcToken: credential,