@turnkey/sdk-react 3.0.3 → 3.0.5

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 +19 -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 +31 -41
  12. package/dist/components/auth/Auth.js.map +1 -1
  13. package/dist/components/auth/Auth.mjs +127 -172
  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
@@ -105,45 +105,6 @@ const Auth = ({
105
105
  const phoneNumber = parsePhoneNumberFromString(phone);
106
106
  return phoneNumber?.isValid() ?? false;
107
107
  };
108
- const handleGetOrCreateSuborg = async (filterType, filterValue, additionalData = {}) => {
109
- let suborgId;
110
- if (filterType == constants.FilterType.Email || filterType == constants.FilterType.PhoneNumber) {
111
- const getVerifiedSuborgsResponse = await sdkServer.server.getVerifiedSuborgs({
112
- filterType,
113
- filterValue
114
- });
115
- if (!getVerifiedSuborgsResponse || !getVerifiedSuborgsResponse.organizationIds) {
116
- onError(constants.authErrors.suborg.fetchFailed);
117
- return null;
118
- }
119
- suborgId = getVerifiedSuborgsResponse?.organizationIds[0];
120
- } else {
121
- const getSuborgsResponse = await sdkServer.server.getSuborgs({
122
- filterType,
123
- filterValue
124
- });
125
- if (!getSuborgsResponse || !getSuborgsResponse.organizationIds) {
126
- onError(constants.authErrors.suborg.fetchFailed);
127
- return null;
128
- }
129
- suborgId = getSuborgsResponse?.organizationIds[0];
130
- }
131
- if (!suborgId) {
132
- const createSuborgData = {
133
- ...additionalData
134
- };
135
- if (filterType === constants.FilterType.Email) createSuborgData.email = filterValue;else if (filterType === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = filterValue;
136
- if (customAccounts) {
137
- createSuborgData.customAccounts = customAccounts;
138
- }
139
- const createSuborgResponse = await sdkServer.server.createSuborg(createSuborgData);
140
- if (!createSuborgResponse || !createSuborgResponse.subOrganizationId) {
141
- onError(constants.authErrors.suborg.createFailed);
142
- }
143
- suborgId = createSuborgResponse?.subOrganizationId;
144
- }
145
- return suborgId;
146
- };
147
108
  const handleAuthSuccess = async (credentialBundle, expirationSeconds) => {
148
109
  if (credentialBundle) {
149
110
  await authIframeClient.injectCredentialBundle(credentialBundle);
@@ -232,7 +193,22 @@ const Auth = ({
232
193
  }
233
194
  };
234
195
  const handleOtpLogin = async (type, value, otpType) => {
235
- const suborgId = await handleGetOrCreateSuborg(type, value);
196
+ const createSuborgData = {};
197
+ if (type === constants.FilterType.Email) createSuborgData.email = value;else if (type === constants.FilterType.PhoneNumber) createSuborgData.phoneNumber = value;
198
+ if (customAccounts) {
199
+ createSuborgData.customAccounts = customAccounts;
200
+ }
201
+ const resp = await sdkServer.server.getOrCreateSuborg({
202
+ filterType: type,
203
+ filterValue: value,
204
+ additionalData: createSuborgData
205
+ });
206
+ const suborgIds = resp?.subOrganizationIds;
207
+ if (!suborgIds || suborgIds.length === 0) {
208
+ onError(constants.authErrors.otp.sendFailed);
209
+ return;
210
+ }
211
+ const suborgId = suborgIds[0];
236
212
  const initAuthResponse = await sdkServer.server.sendOtp({
237
213
  suborgID: suborgId,
238
214
  otpType,
@@ -252,12 +228,26 @@ const Auth = ({
252
228
  };
253
229
  const handleOAuthLogin = async (credential, providerName) => {
254
230
  setOauthLoading(providerName);
255
- const suborgId = await handleGetOrCreateSuborg(constants.FilterType.OidcToken, credential, {
231
+ const createSuborgData = {
256
232
  oauthProviders: [{
257
233
  providerName,
258
234
  oidcToken: credential
259
235
  }]
236
+ };
237
+ if (customAccounts) {
238
+ createSuborgData.customAccounts = customAccounts;
239
+ }
240
+ const resp = await sdkServer.server.getOrCreateSuborg({
241
+ filterType: constants.FilterType.OidcToken,
242
+ filterValue: credential,
243
+ additionalData: createSuborgData
260
244
  });
245
+ const suborgIds = resp?.subOrganizationIds;
246
+ if (!suborgIds || suborgIds.length === 0) {
247
+ onError(constants.authErrors.oauth.loginFailed);
248
+ return;
249
+ }
250
+ const suborgId = suborgIds[0];
261
251
  const oauthResponse = await sdkServer.server.oauth({
262
252
  suborgID: suborgId,
263
253
  oidcToken: credential,