@wix/sdk 1.2.8 → 1.3.0

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.
@@ -40,19 +40,23 @@ function objectToKeyValue(input) {
40
40
  function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
41
41
  return origFunc({
42
42
  request: async (factory) => {
43
- var _a;
43
+ var _a, _b;
44
44
  const requestOptions = factory({ host: API_URL });
45
- const domain = requestOptions.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => requestOptions.url === url2) ? READ_ONLY_API_URL : API_URL;
46
- let url = `https://${domain}${requestOptions.url}`;
47
- if (requestOptions.params && requestOptions.params.toString()) {
48
- url += `?${requestOptions.params.toString()}`;
45
+ let request = requestOptions;
46
+ if (request.method === "GET" && ((_a = request.fallback) == null ? void 0 : _a.length) && request.params.toString().length > 4e3) {
47
+ request = requestOptions.fallback[0];
48
+ }
49
+ const domain = request.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => request.url === url2) ? READ_ONLY_API_URL : API_URL;
50
+ let url = `https://${domain}${request.url}`;
51
+ if (request.params && request.params.toString()) {
52
+ url += `?${request.params.toString()}`;
49
53
  }
50
54
  try {
51
55
  const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
52
56
  const res = await boundFetch(url, {
53
- method: requestOptions.method,
54
- ...requestOptions.data && {
55
- body: JSON.stringify(requestOptions.data)
57
+ method: request.method,
58
+ ...request.data && {
59
+ body: JSON.stringify(request.data)
56
60
  },
57
61
  headers: {
58
62
  ...biHeader
@@ -82,7 +86,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
82
86
  statusText: res.statusText
83
87
  };
84
88
  } catch (e) {
85
- if ((_a = e.message) == null ? void 0 : _a.includes("fetch is not defined")) {
89
+ if ((_b = e.message) == null ? void 0 : _b.includes("fetch is not defined")) {
86
90
  console.error("Node.js v18+ is required");
87
91
  }
88
92
  throw e;
@@ -362,7 +366,6 @@ function OAuthStrategy(config) {
362
366
  _tokens.refreshToken = tokens.refreshToken;
363
367
  };
364
368
  let _state = {
365
- stateKind: "initial",
366
369
  loginState: "INITIAL" /* INITIAL */
367
370
  };
368
371
  const getAuthHeaders = async () => {
@@ -525,24 +528,20 @@ function OAuthStrategy(config) {
525
528
  if (response.state === authentication.StateType.SUCCESS) {
526
529
  return {
527
530
  loginState: "SUCCESS" /* SUCCESS */,
528
- stateKind: "success",
529
531
  data: { sessionToken: response.sessionToken }
530
532
  };
531
533
  } else if (response.state === authentication.StateType.REQUIRE_OWNER_APPROVAL) {
532
534
  return {
533
- loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */,
534
- stateKind: "ownerApprovalRequired"
535
+ loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
535
536
  };
536
537
  } else if (response.state === authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
537
538
  _state = {
538
539
  loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
539
- stateKind: "emailVerificationRequired",
540
540
  data: { stateToken: response.stateToken }
541
541
  };
542
542
  return _state;
543
543
  }
544
544
  return {
545
- stateKind: "failure",
546
545
  loginState: "FAILURE" /* FAILURE */,
547
546
  error: "Unknown _state"
548
547
  };
@@ -574,7 +573,6 @@ function OAuthStrategy(config) {
574
573
  );
575
574
  if (emailValidation) {
576
575
  return {
577
- stateKind: "failure",
578
576
  loginState: "FAILURE" /* FAILURE */,
579
577
  error: emailValidation.description,
580
578
  errorCode: "invalidEmail"
@@ -582,7 +580,6 @@ function OAuthStrategy(config) {
582
580
  }
583
581
  if (((_e = e.details.applicationError) == null ? void 0 : _e.code) === MISSING_CAPTCHA) {
584
582
  return {
585
- stateKind: "failure",
586
583
  loginState: "FAILURE" /* FAILURE */,
587
584
  error: e.message,
588
585
  errorCode: "missingCaptchaToken"
@@ -590,7 +587,6 @@ function OAuthStrategy(config) {
590
587
  }
591
588
  if (((_f = e.details.applicationError) == null ? void 0 : _f.code) === EMAIL_EXISTS) {
592
589
  return {
593
- stateKind: "failure",
594
590
  loginState: "FAILURE" /* FAILURE */,
595
591
  error: e.message,
596
592
  errorCode: "emailAlreadyExists"
@@ -598,14 +594,12 @@ function OAuthStrategy(config) {
598
594
  }
599
595
  if (((_g = e.details.applicationError) == null ? void 0 : _g.code) === INVALID_CAPTCHA) {
600
596
  return {
601
- stateKind: "failure",
602
597
  loginState: "FAILURE" /* FAILURE */,
603
598
  error: e.message,
604
599
  errorCode: "invalidCaptchaToken"
605
600
  };
606
601
  }
607
602
  return {
608
- stateKind: "failure",
609
603
  loginState: "FAILURE" /* FAILURE */,
610
604
  error: e.message
611
605
  };
@@ -633,25 +627,24 @@ function OAuthStrategy(config) {
633
627
  return handleState(res);
634
628
  } catch (e) {
635
629
  return {
636
- stateKind: "failure",
637
630
  loginState: "FAILURE" /* FAILURE */,
638
631
  error: e.message,
639
632
  errorCode: ((_c = e.details.applicationError) == null ? void 0 : _c.code) === MISSING_CAPTCHA ? "missingCaptchaToken" : ((_d = e.details.applicationError) == null ? void 0 : _d.code) === INVALID_CAPTCHA ? "invalidCaptchaToken" : e.details.applicationError.code === INVALID_PASSWORD ? "invalidPassword" : e.details.applicationError.code === RESET_PASSWORD ? "resetPassword" : "invalidEmail"
640
633
  };
641
634
  }
642
635
  };
643
- const processVerification = async (nextInputs) => {
636
+ const processVerification = async (nextInputs, state) => {
644
637
  var _a;
645
- if (_state.stateKind === "emailVerificationRequired") {
638
+ const stateToUse = state != null ? state : _state;
639
+ if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
646
640
  const code = (_a = nextInputs.verificationCode) != null ? _a : nextInputs.code;
647
641
  const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
648
642
  code,
649
- { stateToken: _state.data.stateToken }
643
+ { stateToken: stateToUse.data.stateToken }
650
644
  );
651
645
  return handleState(res);
652
646
  }
653
647
  return {
654
- stateKind: "failure",
655
648
  loginState: "FAILURE" /* FAILURE */,
656
649
  error: "Unknown _state"
657
650
  };
@@ -696,18 +689,9 @@ function OAuthStrategy(config) {
696
689
  loggedIn,
697
690
  logout,
698
691
  register,
699
- proceed: (nextInputs) => {
700
- const { code, ...restProps } = nextInputs;
701
- return processVerification({
702
- verificationCode: code,
703
- ...restProps
704
- });
705
- },
706
692
  processVerification,
707
693
  login,
708
- complete: getMemberTokensForDirectLogin,
709
694
  getMemberTokensForDirectLogin,
710
- sendResetPasswordMail: sendPasswordResetEmail,
711
695
  sendPasswordResetEmail,
712
696
  captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
713
697
  captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
package/build/index.d.mts CHANGED
@@ -136,20 +136,8 @@ interface IOAuthStrategy extends AuthenticationStrategy {
136
136
  };
137
137
  register: (params: RegisterParams) => Promise<StateMachine>;
138
138
  login: (params: LoginParams) => Promise<StateMachine>;
139
- processVerification<T extends ProcessableState>(nextInputs: CalculateNextState<T>): Promise<StateMachine>;
140
- /**
141
- * @deprecated use processVerification instead
142
- */
143
- proceed<T extends ProcessableState>(nextInputs: DeprecatedCalculateNextState<T>): Promise<StateMachine>;
144
- /**
145
- * @deprecated use getMemberTokensForDirectLogin instead
146
- */
147
- complete: (sessionToken: string) => Promise<Tokens>;
139
+ processVerification<T extends ProcessableState>(nextInputs: CalculateNextState<T>, state?: StateMachine): Promise<StateMachine>;
148
140
  getMemberTokensForDirectLogin: (sessionToken: string) => Promise<Tokens>;
149
- /**
150
- * @deprecated use sendPasswordResetEmail instead
151
- */
152
- sendResetPasswordMail: (email: string, redirectUri: string) => Promise<void>;
153
141
  sendPasswordResetEmail: (email: string, redirectUri: string) => Promise<void>;
154
142
  captchaInvisibleSiteKey: string;
155
143
  captchaVisibleSiteKey: string;
@@ -164,37 +152,33 @@ declare enum LoginState {
164
152
  USER_CAPTCHA_REQUIRED = "USER_CAPTCHA_REQUIRED",
165
153
  SILENT_CAPTCHA_REQUIRED = "SILENT_CAPTCHA_REQUIRED"
166
154
  }
167
- interface LoginResults<SK extends string, LK extends LoginState> {
168
- /**
169
- * @deprecated use loginState instead
170
- */
171
- stateKind: SK;
155
+ interface LoginResults<LK extends LoginState> {
172
156
  loginState: LK;
173
157
  }
174
- interface SuccessState extends LoginResults<'success', LoginState.SUCCESS> {
158
+ interface SuccessState extends LoginResults<LoginState.SUCCESS> {
175
159
  data: {
176
160
  sessionToken: string;
177
161
  };
178
162
  }
179
- interface InitialState extends LoginResults<'initial', LoginState.INITIAL> {
163
+ interface InitialState extends LoginResults<LoginState.INITIAL> {
180
164
  }
181
- interface ErrorState extends LoginResults<'failure', LoginState.FAILURE> {
165
+ interface ErrorState extends LoginResults<LoginState.FAILURE> {
182
166
  errorCode?: 'invalidEmail' | 'invalidPassword' | 'resetPassword' | 'missingCaptchaToken' | 'emailAlreadyExists' | 'invalidCaptchaToken';
183
167
  error: string;
184
168
  }
185
- interface EmailVerificationRequiredState extends LoginResults<'emailVerificationRequired', LoginState.EMAIL_VERIFICATION_REQUIRED> {
169
+ interface EmailVerificationRequiredState extends LoginResults<LoginState.EMAIL_VERIFICATION_REQUIRED> {
186
170
  data: {
187
171
  stateToken: string;
188
172
  };
189
173
  }
190
- interface OwnerApprovalRequiredState extends LoginResults<'ownerApprovalRequired', LoginState.OWNER_APPROVAL_REQUIRED> {
174
+ interface OwnerApprovalRequiredState extends LoginResults<LoginState.OWNER_APPROVAL_REQUIRED> {
191
175
  }
192
- interface SilentCaptchaRequiredState extends LoginResults<'silentCaptchaRequired', LoginState.SILENT_CAPTCHA_REQUIRED> {
176
+ interface SilentCaptchaRequiredState extends LoginResults<LoginState.SILENT_CAPTCHA_REQUIRED> {
193
177
  data: {
194
178
  stateToken: string;
195
179
  };
196
180
  }
197
- interface UserCaptchaRequiredState extends LoginResults<'userCaptchaRequired', LoginState.USER_CAPTCHA_REQUIRED> {
181
+ interface UserCaptchaRequiredState extends LoginResults<LoginState.USER_CAPTCHA_REQUIRED> {
198
182
  data: {
199
183
  stateToken: string;
200
184
  };
@@ -205,16 +189,9 @@ declare enum TokenRole {
205
189
  MEMBER = "member"
206
190
  }
207
191
  type StateMachine = InitialState | SuccessState | ErrorState | EmailVerificationRequiredState | OwnerApprovalRequiredState | SilentCaptchaRequiredState | UserCaptchaRequiredState;
208
- type DeprecatedCode = {
209
- /**
210
- * @deprecated use verificationCode instead
211
- */
212
- code: string;
213
- };
214
192
  type VerificationCode = {
215
193
  verificationCode: string;
216
194
  };
217
- type DeprecatedCalculateNextState<T> = T extends EmailVerificationRequiredState ? DeprecatedCode : never;
218
195
  type CalculateNextState<T> = T extends EmailVerificationRequiredState ? VerificationCode : never;
219
196
  type ProcessableState = EmailVerificationRequiredState;
220
197
 
@@ -245,4 +222,4 @@ declare function ApiKeyStrategy({ siteId, accountId, apiKey, }: {
245
222
  apiKey: string;
246
223
  } & Context): IApiKeyStrategy;
247
224
 
248
- export { AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, DeprecatedCalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixClient, createClient, decodeText, media };
225
+ export { AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixClient, createClient, decodeText, media };
package/build/index.d.ts CHANGED
@@ -136,20 +136,8 @@ interface IOAuthStrategy extends AuthenticationStrategy {
136
136
  };
137
137
  register: (params: RegisterParams) => Promise<StateMachine>;
138
138
  login: (params: LoginParams) => Promise<StateMachine>;
139
- processVerification<T extends ProcessableState>(nextInputs: CalculateNextState<T>): Promise<StateMachine>;
140
- /**
141
- * @deprecated use processVerification instead
142
- */
143
- proceed<T extends ProcessableState>(nextInputs: DeprecatedCalculateNextState<T>): Promise<StateMachine>;
144
- /**
145
- * @deprecated use getMemberTokensForDirectLogin instead
146
- */
147
- complete: (sessionToken: string) => Promise<Tokens>;
139
+ processVerification<T extends ProcessableState>(nextInputs: CalculateNextState<T>, state?: StateMachine): Promise<StateMachine>;
148
140
  getMemberTokensForDirectLogin: (sessionToken: string) => Promise<Tokens>;
149
- /**
150
- * @deprecated use sendPasswordResetEmail instead
151
- */
152
- sendResetPasswordMail: (email: string, redirectUri: string) => Promise<void>;
153
141
  sendPasswordResetEmail: (email: string, redirectUri: string) => Promise<void>;
154
142
  captchaInvisibleSiteKey: string;
155
143
  captchaVisibleSiteKey: string;
@@ -164,37 +152,33 @@ declare enum LoginState {
164
152
  USER_CAPTCHA_REQUIRED = "USER_CAPTCHA_REQUIRED",
165
153
  SILENT_CAPTCHA_REQUIRED = "SILENT_CAPTCHA_REQUIRED"
166
154
  }
167
- interface LoginResults<SK extends string, LK extends LoginState> {
168
- /**
169
- * @deprecated use loginState instead
170
- */
171
- stateKind: SK;
155
+ interface LoginResults<LK extends LoginState> {
172
156
  loginState: LK;
173
157
  }
174
- interface SuccessState extends LoginResults<'success', LoginState.SUCCESS> {
158
+ interface SuccessState extends LoginResults<LoginState.SUCCESS> {
175
159
  data: {
176
160
  sessionToken: string;
177
161
  };
178
162
  }
179
- interface InitialState extends LoginResults<'initial', LoginState.INITIAL> {
163
+ interface InitialState extends LoginResults<LoginState.INITIAL> {
180
164
  }
181
- interface ErrorState extends LoginResults<'failure', LoginState.FAILURE> {
165
+ interface ErrorState extends LoginResults<LoginState.FAILURE> {
182
166
  errorCode?: 'invalidEmail' | 'invalidPassword' | 'resetPassword' | 'missingCaptchaToken' | 'emailAlreadyExists' | 'invalidCaptchaToken';
183
167
  error: string;
184
168
  }
185
- interface EmailVerificationRequiredState extends LoginResults<'emailVerificationRequired', LoginState.EMAIL_VERIFICATION_REQUIRED> {
169
+ interface EmailVerificationRequiredState extends LoginResults<LoginState.EMAIL_VERIFICATION_REQUIRED> {
186
170
  data: {
187
171
  stateToken: string;
188
172
  };
189
173
  }
190
- interface OwnerApprovalRequiredState extends LoginResults<'ownerApprovalRequired', LoginState.OWNER_APPROVAL_REQUIRED> {
174
+ interface OwnerApprovalRequiredState extends LoginResults<LoginState.OWNER_APPROVAL_REQUIRED> {
191
175
  }
192
- interface SilentCaptchaRequiredState extends LoginResults<'silentCaptchaRequired', LoginState.SILENT_CAPTCHA_REQUIRED> {
176
+ interface SilentCaptchaRequiredState extends LoginResults<LoginState.SILENT_CAPTCHA_REQUIRED> {
193
177
  data: {
194
178
  stateToken: string;
195
179
  };
196
180
  }
197
- interface UserCaptchaRequiredState extends LoginResults<'userCaptchaRequired', LoginState.USER_CAPTCHA_REQUIRED> {
181
+ interface UserCaptchaRequiredState extends LoginResults<LoginState.USER_CAPTCHA_REQUIRED> {
198
182
  data: {
199
183
  stateToken: string;
200
184
  };
@@ -205,16 +189,9 @@ declare enum TokenRole {
205
189
  MEMBER = "member"
206
190
  }
207
191
  type StateMachine = InitialState | SuccessState | ErrorState | EmailVerificationRequiredState | OwnerApprovalRequiredState | SilentCaptchaRequiredState | UserCaptchaRequiredState;
208
- type DeprecatedCode = {
209
- /**
210
- * @deprecated use verificationCode instead
211
- */
212
- code: string;
213
- };
214
192
  type VerificationCode = {
215
193
  verificationCode: string;
216
194
  };
217
- type DeprecatedCalculateNextState<T> = T extends EmailVerificationRequiredState ? DeprecatedCode : never;
218
195
  type CalculateNextState<T> = T extends EmailVerificationRequiredState ? VerificationCode : never;
219
196
  type ProcessableState = EmailVerificationRequiredState;
220
197
 
@@ -245,4 +222,4 @@ declare function ApiKeyStrategy({ siteId, accountId, apiKey, }: {
245
222
  apiKey: string;
246
223
  } & Context): IApiKeyStrategy;
247
224
 
248
- export { AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, DeprecatedCalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixClient, createClient, decodeText, media };
225
+ export { AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixClient, createClient, decodeText, media };
package/build/index.js CHANGED
@@ -83,17 +83,21 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
83
83
  return origFunc({
84
84
  request: async (factory) => {
85
85
  const requestOptions = factory({ host: API_URL });
86
- const domain = requestOptions.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => requestOptions.url === url2) ? READ_ONLY_API_URL : API_URL;
87
- let url = `https://${domain}${requestOptions.url}`;
88
- if (requestOptions.params && requestOptions.params.toString()) {
89
- url += `?${requestOptions.params.toString()}`;
86
+ let request = requestOptions;
87
+ if (request.method === "GET" && request.fallback?.length && request.params.toString().length > 4e3) {
88
+ request = requestOptions.fallback[0];
89
+ }
90
+ const domain = request.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => request.url === url2) ? READ_ONLY_API_URL : API_URL;
91
+ let url = `https://${domain}${request.url}`;
92
+ if (request.params && request.params.toString()) {
93
+ url += `?${request.params.toString()}`;
90
94
  }
91
95
  try {
92
96
  const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
93
97
  const res = await boundFetch(url, {
94
- method: requestOptions.method,
95
- ...requestOptions.data && {
96
- body: JSON.stringify(requestOptions.data)
98
+ method: request.method,
99
+ ...request.data && {
100
+ body: JSON.stringify(request.data)
97
101
  },
98
102
  headers: {
99
103
  ...biHeader
@@ -403,7 +407,6 @@ function OAuthStrategy(config) {
403
407
  _tokens.refreshToken = tokens.refreshToken;
404
408
  };
405
409
  let _state = {
406
- stateKind: "initial",
407
410
  loginState: "INITIAL" /* INITIAL */
408
411
  };
409
412
  const getAuthHeaders = async () => {
@@ -563,24 +566,20 @@ function OAuthStrategy(config) {
563
566
  if (response.state === import_identity.authentication.StateType.SUCCESS) {
564
567
  return {
565
568
  loginState: "SUCCESS" /* SUCCESS */,
566
- stateKind: "success",
567
569
  data: { sessionToken: response.sessionToken }
568
570
  };
569
571
  } else if (response.state === import_identity.authentication.StateType.REQUIRE_OWNER_APPROVAL) {
570
572
  return {
571
- loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */,
572
- stateKind: "ownerApprovalRequired"
573
+ loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
573
574
  };
574
575
  } else if (response.state === import_identity.authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
575
576
  _state = {
576
577
  loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
577
- stateKind: "emailVerificationRequired",
578
578
  data: { stateToken: response.stateToken }
579
579
  };
580
580
  return _state;
581
581
  }
582
582
  return {
583
- stateKind: "failure",
584
583
  loginState: "FAILURE" /* FAILURE */,
585
584
  error: "Unknown _state"
586
585
  };
@@ -611,7 +610,6 @@ function OAuthStrategy(config) {
611
610
  );
612
611
  if (emailValidation) {
613
612
  return {
614
- stateKind: "failure",
615
613
  loginState: "FAILURE" /* FAILURE */,
616
614
  error: emailValidation.description,
617
615
  errorCode: "invalidEmail"
@@ -619,7 +617,6 @@ function OAuthStrategy(config) {
619
617
  }
620
618
  if (e.details.applicationError?.code === MISSING_CAPTCHA) {
621
619
  return {
622
- stateKind: "failure",
623
620
  loginState: "FAILURE" /* FAILURE */,
624
621
  error: e.message,
625
622
  errorCode: "missingCaptchaToken"
@@ -627,7 +624,6 @@ function OAuthStrategy(config) {
627
624
  }
628
625
  if (e.details.applicationError?.code === EMAIL_EXISTS) {
629
626
  return {
630
- stateKind: "failure",
631
627
  loginState: "FAILURE" /* FAILURE */,
632
628
  error: e.message,
633
629
  errorCode: "emailAlreadyExists"
@@ -635,14 +631,12 @@ function OAuthStrategy(config) {
635
631
  }
636
632
  if (e.details.applicationError?.code === INVALID_CAPTCHA) {
637
633
  return {
638
- stateKind: "failure",
639
634
  loginState: "FAILURE" /* FAILURE */,
640
635
  error: e.message,
641
636
  errorCode: "invalidCaptchaToken"
642
637
  };
643
638
  }
644
639
  return {
645
- stateKind: "failure",
646
640
  loginState: "FAILURE" /* FAILURE */,
647
641
  error: e.message
648
642
  };
@@ -669,24 +663,23 @@ function OAuthStrategy(config) {
669
663
  return handleState(res);
670
664
  } catch (e) {
671
665
  return {
672
- stateKind: "failure",
673
666
  loginState: "FAILURE" /* FAILURE */,
674
667
  error: e.message,
675
668
  errorCode: e.details.applicationError?.code === MISSING_CAPTCHA ? "missingCaptchaToken" : e.details.applicationError?.code === INVALID_CAPTCHA ? "invalidCaptchaToken" : e.details.applicationError.code === INVALID_PASSWORD ? "invalidPassword" : e.details.applicationError.code === RESET_PASSWORD ? "resetPassword" : "invalidEmail"
676
669
  };
677
670
  }
678
671
  };
679
- const processVerification = async (nextInputs) => {
680
- if (_state.stateKind === "emailVerificationRequired") {
672
+ const processVerification = async (nextInputs, state) => {
673
+ const stateToUse = state ?? _state;
674
+ if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
681
675
  const code = nextInputs.verificationCode ?? nextInputs.code;
682
676
  const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
683
677
  code,
684
- { stateToken: _state.data.stateToken }
678
+ { stateToken: stateToUse.data.stateToken }
685
679
  );
686
680
  return handleState(res);
687
681
  }
688
682
  return {
689
- stateKind: "failure",
690
683
  loginState: "FAILURE" /* FAILURE */,
691
684
  error: "Unknown _state"
692
685
  };
@@ -730,18 +723,9 @@ function OAuthStrategy(config) {
730
723
  loggedIn,
731
724
  logout,
732
725
  register,
733
- proceed: (nextInputs) => {
734
- const { code, ...restProps } = nextInputs;
735
- return processVerification({
736
- verificationCode: code,
737
- ...restProps
738
- });
739
- },
740
726
  processVerification,
741
727
  login,
742
- complete: getMemberTokensForDirectLogin,
743
728
  getMemberTokensForDirectLogin,
744
- sendResetPasswordMail: sendPasswordResetEmail,
745
729
  sendPasswordResetEmail,
746
730
  captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
747
731
  captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
package/build/index.mjs CHANGED
@@ -40,17 +40,21 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
40
40
  return origFunc({
41
41
  request: async (factory) => {
42
42
  const requestOptions = factory({ host: API_URL });
43
- const domain = requestOptions.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => requestOptions.url === url2) ? READ_ONLY_API_URL : API_URL;
44
- let url = `https://${domain}${requestOptions.url}`;
45
- if (requestOptions.params && requestOptions.params.toString()) {
46
- url += `?${requestOptions.params.toString()}`;
43
+ let request = requestOptions;
44
+ if (request.method === "GET" && request.fallback?.length && request.params.toString().length > 4e3) {
45
+ request = requestOptions.fallback[0];
46
+ }
47
+ const domain = request.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => request.url === url2) ? READ_ONLY_API_URL : API_URL;
48
+ let url = `https://${domain}${request.url}`;
49
+ if (request.params && request.params.toString()) {
50
+ url += `?${request.params.toString()}`;
47
51
  }
48
52
  try {
49
53
  const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
50
54
  const res = await boundFetch(url, {
51
- method: requestOptions.method,
52
- ...requestOptions.data && {
53
- body: JSON.stringify(requestOptions.data)
55
+ method: request.method,
56
+ ...request.data && {
57
+ body: JSON.stringify(request.data)
54
58
  },
55
59
  headers: {
56
60
  ...biHeader
@@ -360,7 +364,6 @@ function OAuthStrategy(config) {
360
364
  _tokens.refreshToken = tokens.refreshToken;
361
365
  };
362
366
  let _state = {
363
- stateKind: "initial",
364
367
  loginState: "INITIAL" /* INITIAL */
365
368
  };
366
369
  const getAuthHeaders = async () => {
@@ -520,24 +523,20 @@ function OAuthStrategy(config) {
520
523
  if (response.state === authentication.StateType.SUCCESS) {
521
524
  return {
522
525
  loginState: "SUCCESS" /* SUCCESS */,
523
- stateKind: "success",
524
526
  data: { sessionToken: response.sessionToken }
525
527
  };
526
528
  } else if (response.state === authentication.StateType.REQUIRE_OWNER_APPROVAL) {
527
529
  return {
528
- loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */,
529
- stateKind: "ownerApprovalRequired"
530
+ loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
530
531
  };
531
532
  } else if (response.state === authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
532
533
  _state = {
533
534
  loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
534
- stateKind: "emailVerificationRequired",
535
535
  data: { stateToken: response.stateToken }
536
536
  };
537
537
  return _state;
538
538
  }
539
539
  return {
540
- stateKind: "failure",
541
540
  loginState: "FAILURE" /* FAILURE */,
542
541
  error: "Unknown _state"
543
542
  };
@@ -568,7 +567,6 @@ function OAuthStrategy(config) {
568
567
  );
569
568
  if (emailValidation) {
570
569
  return {
571
- stateKind: "failure",
572
570
  loginState: "FAILURE" /* FAILURE */,
573
571
  error: emailValidation.description,
574
572
  errorCode: "invalidEmail"
@@ -576,7 +574,6 @@ function OAuthStrategy(config) {
576
574
  }
577
575
  if (e.details.applicationError?.code === MISSING_CAPTCHA) {
578
576
  return {
579
- stateKind: "failure",
580
577
  loginState: "FAILURE" /* FAILURE */,
581
578
  error: e.message,
582
579
  errorCode: "missingCaptchaToken"
@@ -584,7 +581,6 @@ function OAuthStrategy(config) {
584
581
  }
585
582
  if (e.details.applicationError?.code === EMAIL_EXISTS) {
586
583
  return {
587
- stateKind: "failure",
588
584
  loginState: "FAILURE" /* FAILURE */,
589
585
  error: e.message,
590
586
  errorCode: "emailAlreadyExists"
@@ -592,14 +588,12 @@ function OAuthStrategy(config) {
592
588
  }
593
589
  if (e.details.applicationError?.code === INVALID_CAPTCHA) {
594
590
  return {
595
- stateKind: "failure",
596
591
  loginState: "FAILURE" /* FAILURE */,
597
592
  error: e.message,
598
593
  errorCode: "invalidCaptchaToken"
599
594
  };
600
595
  }
601
596
  return {
602
- stateKind: "failure",
603
597
  loginState: "FAILURE" /* FAILURE */,
604
598
  error: e.message
605
599
  };
@@ -626,24 +620,23 @@ function OAuthStrategy(config) {
626
620
  return handleState(res);
627
621
  } catch (e) {
628
622
  return {
629
- stateKind: "failure",
630
623
  loginState: "FAILURE" /* FAILURE */,
631
624
  error: e.message,
632
625
  errorCode: e.details.applicationError?.code === MISSING_CAPTCHA ? "missingCaptchaToken" : e.details.applicationError?.code === INVALID_CAPTCHA ? "invalidCaptchaToken" : e.details.applicationError.code === INVALID_PASSWORD ? "invalidPassword" : e.details.applicationError.code === RESET_PASSWORD ? "resetPassword" : "invalidEmail"
633
626
  };
634
627
  }
635
628
  };
636
- const processVerification = async (nextInputs) => {
637
- if (_state.stateKind === "emailVerificationRequired") {
629
+ const processVerification = async (nextInputs, state) => {
630
+ const stateToUse = state ?? _state;
631
+ if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
638
632
  const code = nextInputs.verificationCode ?? nextInputs.code;
639
633
  const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
640
634
  code,
641
- { stateToken: _state.data.stateToken }
635
+ { stateToken: stateToUse.data.stateToken }
642
636
  );
643
637
  return handleState(res);
644
638
  }
645
639
  return {
646
- stateKind: "failure",
647
640
  loginState: "FAILURE" /* FAILURE */,
648
641
  error: "Unknown _state"
649
642
  };
@@ -687,18 +680,9 @@ function OAuthStrategy(config) {
687
680
  loggedIn,
688
681
  logout,
689
682
  register,
690
- proceed: (nextInputs) => {
691
- const { code, ...restProps } = nextInputs;
692
- return processVerification({
693
- verificationCode: code,
694
- ...restProps
695
- });
696
- },
697
683
  processVerification,
698
684
  login,
699
- complete: getMemberTokensForDirectLogin,
700
685
  getMemberTokensForDirectLogin,
701
- sendResetPasswordMail: sendPasswordResetEmail,
702
686
  sendPasswordResetEmail,
703
687
  captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
704
688
  captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -30,30 +30,30 @@
30
30
  "*.{js,ts}": "yarn lint"
31
31
  },
32
32
  "dependencies": {
33
- "@babel/runtime": "^7.22.6",
34
- "@wix/identity": "^1.0.47",
35
- "@wix/image-kit": "^1.35.0",
36
- "@wix/redirects": "^1.0.22",
37
- "@wix/sdk-types": "1.2.8",
33
+ "@babel/runtime": "^7.22.11",
34
+ "@wix/identity": "^1.0.54",
35
+ "@wix/image-kit": "^1.36.0",
36
+ "@wix/redirects": "^1.0.23",
37
+ "@wix/sdk-types": "1.3.0",
38
38
  "pkce-challenge": "^3.1.0",
39
39
  "querystring": "^0.2.1",
40
40
  "type-fest": "^3.13.1"
41
41
  },
42
42
  "devDependencies": {
43
- "@swc/core": "^1.3.72",
44
- "@swc/jest": "^0.2.27",
43
+ "@swc/core": "^1.3.80",
44
+ "@swc/jest": "^0.2.29",
45
45
  "@types/jest": "^27.5.2",
46
- "@types/node": "^16.18.39",
47
- "@wix/ecom": "^1.0.302",
48
- "@wix/events": "^1.0.110",
49
- "@wix/motion": "^1.0.27",
46
+ "@types/node": "^16.18.46",
47
+ "@wix/ecom": "^1.0.342",
48
+ "@wix/events": "^1.0.115",
49
+ "@wix/metro": "^1.0.65",
50
50
  "eslint": "^7.32.0",
51
51
  "eslint-config-sdk": "0.0.0",
52
52
  "is-ci": "^3.0.1",
53
53
  "jest": "^27.5.1",
54
54
  "jest-teamcity": "^1.11.0",
55
55
  "ts-jest": "^27.1.5",
56
- "tsup": "^7.1.0",
56
+ "tsup": "^7.2.0",
57
57
  "typescript": "~4.9.5"
58
58
  },
59
59
  "yoshiFlowLibrary": {
@@ -79,5 +79,5 @@
79
79
  "wallaby": {
80
80
  "autoDetect": true
81
81
  },
82
- "falconPackageHash": "07eb178e34d03b5584413811900bdedde21e79d9438809689ff22469"
82
+ "falconPackageHash": "2a6a54a97f2776cdbc13af01a1ac8a5a0b6c6522b2a4bbff0a80f8b6"
83
83
  }