@wix/sdk 1.2.7 → 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.
- package/build/browser/index.mjs +20 -33
- package/build/index.d.mts +10 -33
- package/build/index.d.ts +10 -33
- package/build/index.js +18 -31
- package/build/index.mjs +18 -31
- package/package.json +14 -14
package/build/browser/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/common.ts
|
|
2
2
|
var PUBLIC_METADATA_KEY = "__metadata";
|
|
3
3
|
var API_URL = "www.wixapis.com";
|
|
4
|
+
var READ_ONLY_API_URL = "readonly.wixapis.com";
|
|
5
|
+
var FORCE_WRITE_API_URLS = ["/ecom/v1/carts/current"];
|
|
4
6
|
|
|
5
7
|
// src/helpers.ts
|
|
6
8
|
var getDefaultContentHeader = (options) => {
|
|
@@ -38,18 +40,23 @@ function objectToKeyValue(input) {
|
|
|
38
40
|
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
39
41
|
return origFunc({
|
|
40
42
|
request: async (factory) => {
|
|
41
|
-
var _a;
|
|
43
|
+
var _a, _b;
|
|
42
44
|
const requestOptions = factory({ host: API_URL });
|
|
43
|
-
let
|
|
44
|
-
if (
|
|
45
|
-
|
|
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()}`;
|
|
46
53
|
}
|
|
47
54
|
try {
|
|
48
55
|
const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
|
|
49
56
|
const res = await boundFetch(url, {
|
|
50
|
-
method:
|
|
51
|
-
...
|
|
52
|
-
body: JSON.stringify(
|
|
57
|
+
method: request.method,
|
|
58
|
+
...request.data && {
|
|
59
|
+
body: JSON.stringify(request.data)
|
|
53
60
|
},
|
|
54
61
|
headers: {
|
|
55
62
|
...biHeader
|
|
@@ -79,7 +86,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
|
79
86
|
statusText: res.statusText
|
|
80
87
|
};
|
|
81
88
|
} catch (e) {
|
|
82
|
-
if ((
|
|
89
|
+
if ((_b = e.message) == null ? void 0 : _b.includes("fetch is not defined")) {
|
|
83
90
|
console.error("Node.js v18+ is required");
|
|
84
91
|
}
|
|
85
92
|
throw e;
|
|
@@ -359,7 +366,6 @@ function OAuthStrategy(config) {
|
|
|
359
366
|
_tokens.refreshToken = tokens.refreshToken;
|
|
360
367
|
};
|
|
361
368
|
let _state = {
|
|
362
|
-
stateKind: "initial",
|
|
363
369
|
loginState: "INITIAL" /* INITIAL */
|
|
364
370
|
};
|
|
365
371
|
const getAuthHeaders = async () => {
|
|
@@ -522,24 +528,20 @@ function OAuthStrategy(config) {
|
|
|
522
528
|
if (response.state === authentication.StateType.SUCCESS) {
|
|
523
529
|
return {
|
|
524
530
|
loginState: "SUCCESS" /* SUCCESS */,
|
|
525
|
-
stateKind: "success",
|
|
526
531
|
data: { sessionToken: response.sessionToken }
|
|
527
532
|
};
|
|
528
533
|
} else if (response.state === authentication.StateType.REQUIRE_OWNER_APPROVAL) {
|
|
529
534
|
return {
|
|
530
|
-
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED
|
|
531
|
-
stateKind: "ownerApprovalRequired"
|
|
535
|
+
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
|
|
532
536
|
};
|
|
533
537
|
} else if (response.state === authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
|
|
534
538
|
_state = {
|
|
535
539
|
loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
536
|
-
stateKind: "emailVerificationRequired",
|
|
537
540
|
data: { stateToken: response.stateToken }
|
|
538
541
|
};
|
|
539
542
|
return _state;
|
|
540
543
|
}
|
|
541
544
|
return {
|
|
542
|
-
stateKind: "failure",
|
|
543
545
|
loginState: "FAILURE" /* FAILURE */,
|
|
544
546
|
error: "Unknown _state"
|
|
545
547
|
};
|
|
@@ -571,7 +573,6 @@ function OAuthStrategy(config) {
|
|
|
571
573
|
);
|
|
572
574
|
if (emailValidation) {
|
|
573
575
|
return {
|
|
574
|
-
stateKind: "failure",
|
|
575
576
|
loginState: "FAILURE" /* FAILURE */,
|
|
576
577
|
error: emailValidation.description,
|
|
577
578
|
errorCode: "invalidEmail"
|
|
@@ -579,7 +580,6 @@ function OAuthStrategy(config) {
|
|
|
579
580
|
}
|
|
580
581
|
if (((_e = e.details.applicationError) == null ? void 0 : _e.code) === MISSING_CAPTCHA) {
|
|
581
582
|
return {
|
|
582
|
-
stateKind: "failure",
|
|
583
583
|
loginState: "FAILURE" /* FAILURE */,
|
|
584
584
|
error: e.message,
|
|
585
585
|
errorCode: "missingCaptchaToken"
|
|
@@ -587,7 +587,6 @@ function OAuthStrategy(config) {
|
|
|
587
587
|
}
|
|
588
588
|
if (((_f = e.details.applicationError) == null ? void 0 : _f.code) === EMAIL_EXISTS) {
|
|
589
589
|
return {
|
|
590
|
-
stateKind: "failure",
|
|
591
590
|
loginState: "FAILURE" /* FAILURE */,
|
|
592
591
|
error: e.message,
|
|
593
592
|
errorCode: "emailAlreadyExists"
|
|
@@ -595,14 +594,12 @@ function OAuthStrategy(config) {
|
|
|
595
594
|
}
|
|
596
595
|
if (((_g = e.details.applicationError) == null ? void 0 : _g.code) === INVALID_CAPTCHA) {
|
|
597
596
|
return {
|
|
598
|
-
stateKind: "failure",
|
|
599
597
|
loginState: "FAILURE" /* FAILURE */,
|
|
600
598
|
error: e.message,
|
|
601
599
|
errorCode: "invalidCaptchaToken"
|
|
602
600
|
};
|
|
603
601
|
}
|
|
604
602
|
return {
|
|
605
|
-
stateKind: "failure",
|
|
606
603
|
loginState: "FAILURE" /* FAILURE */,
|
|
607
604
|
error: e.message
|
|
608
605
|
};
|
|
@@ -630,25 +627,24 @@ function OAuthStrategy(config) {
|
|
|
630
627
|
return handleState(res);
|
|
631
628
|
} catch (e) {
|
|
632
629
|
return {
|
|
633
|
-
stateKind: "failure",
|
|
634
630
|
loginState: "FAILURE" /* FAILURE */,
|
|
635
631
|
error: e.message,
|
|
636
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"
|
|
637
633
|
};
|
|
638
634
|
}
|
|
639
635
|
};
|
|
640
|
-
const processVerification = async (nextInputs) => {
|
|
636
|
+
const processVerification = async (nextInputs, state) => {
|
|
641
637
|
var _a;
|
|
642
|
-
|
|
638
|
+
const stateToUse = state != null ? state : _state;
|
|
639
|
+
if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
|
|
643
640
|
const code = (_a = nextInputs.verificationCode) != null ? _a : nextInputs.code;
|
|
644
641
|
const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
|
|
645
642
|
code,
|
|
646
|
-
{ stateToken:
|
|
643
|
+
{ stateToken: stateToUse.data.stateToken }
|
|
647
644
|
);
|
|
648
645
|
return handleState(res);
|
|
649
646
|
}
|
|
650
647
|
return {
|
|
651
|
-
stateKind: "failure",
|
|
652
648
|
loginState: "FAILURE" /* FAILURE */,
|
|
653
649
|
error: "Unknown _state"
|
|
654
650
|
};
|
|
@@ -693,18 +689,9 @@ function OAuthStrategy(config) {
|
|
|
693
689
|
loggedIn,
|
|
694
690
|
logout,
|
|
695
691
|
register,
|
|
696
|
-
proceed: (nextInputs) => {
|
|
697
|
-
const { code, ...restProps } = nextInputs;
|
|
698
|
-
return processVerification({
|
|
699
|
-
verificationCode: code,
|
|
700
|
-
...restProps
|
|
701
|
-
});
|
|
702
|
-
},
|
|
703
692
|
processVerification,
|
|
704
693
|
login,
|
|
705
|
-
complete: getMemberTokensForDirectLogin,
|
|
706
694
|
getMemberTokensForDirectLogin,
|
|
707
|
-
sendResetPasswordMail: sendPasswordResetEmail,
|
|
708
695
|
sendPasswordResetEmail,
|
|
709
696
|
captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
|
|
710
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
|
|
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<
|
|
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<
|
|
158
|
+
interface SuccessState extends LoginResults<LoginState.SUCCESS> {
|
|
175
159
|
data: {
|
|
176
160
|
sessionToken: string;
|
|
177
161
|
};
|
|
178
162
|
}
|
|
179
|
-
interface InitialState extends LoginResults<
|
|
163
|
+
interface InitialState extends LoginResults<LoginState.INITIAL> {
|
|
180
164
|
}
|
|
181
|
-
interface ErrorState extends LoginResults<
|
|
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<
|
|
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<
|
|
174
|
+
interface OwnerApprovalRequiredState extends LoginResults<LoginState.OWNER_APPROVAL_REQUIRED> {
|
|
191
175
|
}
|
|
192
|
-
interface SilentCaptchaRequiredState extends LoginResults<
|
|
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<
|
|
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,
|
|
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
|
|
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<
|
|
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<
|
|
158
|
+
interface SuccessState extends LoginResults<LoginState.SUCCESS> {
|
|
175
159
|
data: {
|
|
176
160
|
sessionToken: string;
|
|
177
161
|
};
|
|
178
162
|
}
|
|
179
|
-
interface InitialState extends LoginResults<
|
|
163
|
+
interface InitialState extends LoginResults<LoginState.INITIAL> {
|
|
180
164
|
}
|
|
181
|
-
interface ErrorState extends LoginResults<
|
|
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<
|
|
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<
|
|
174
|
+
interface OwnerApprovalRequiredState extends LoginResults<LoginState.OWNER_APPROVAL_REQUIRED> {
|
|
191
175
|
}
|
|
192
|
-
interface SilentCaptchaRequiredState extends LoginResults<
|
|
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<
|
|
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,
|
|
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
|
@@ -44,6 +44,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
44
44
|
// src/common.ts
|
|
45
45
|
var PUBLIC_METADATA_KEY = "__metadata";
|
|
46
46
|
var API_URL = "www.wixapis.com";
|
|
47
|
+
var READ_ONLY_API_URL = "readonly.wixapis.com";
|
|
48
|
+
var FORCE_WRITE_API_URLS = ["/ecom/v1/carts/current"];
|
|
47
49
|
|
|
48
50
|
// src/helpers.ts
|
|
49
51
|
var getDefaultContentHeader = (options) => {
|
|
@@ -81,16 +83,21 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
|
81
83
|
return origFunc({
|
|
82
84
|
request: async (factory) => {
|
|
83
85
|
const requestOptions = factory({ host: API_URL });
|
|
84
|
-
let
|
|
85
|
-
if (
|
|
86
|
-
|
|
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()}`;
|
|
87
94
|
}
|
|
88
95
|
try {
|
|
89
96
|
const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
|
|
90
97
|
const res = await boundFetch(url, {
|
|
91
|
-
method:
|
|
92
|
-
...
|
|
93
|
-
body: JSON.stringify(
|
|
98
|
+
method: request.method,
|
|
99
|
+
...request.data && {
|
|
100
|
+
body: JSON.stringify(request.data)
|
|
94
101
|
},
|
|
95
102
|
headers: {
|
|
96
103
|
...biHeader
|
|
@@ -400,7 +407,6 @@ function OAuthStrategy(config) {
|
|
|
400
407
|
_tokens.refreshToken = tokens.refreshToken;
|
|
401
408
|
};
|
|
402
409
|
let _state = {
|
|
403
|
-
stateKind: "initial",
|
|
404
410
|
loginState: "INITIAL" /* INITIAL */
|
|
405
411
|
};
|
|
406
412
|
const getAuthHeaders = async () => {
|
|
@@ -560,24 +566,20 @@ function OAuthStrategy(config) {
|
|
|
560
566
|
if (response.state === import_identity.authentication.StateType.SUCCESS) {
|
|
561
567
|
return {
|
|
562
568
|
loginState: "SUCCESS" /* SUCCESS */,
|
|
563
|
-
stateKind: "success",
|
|
564
569
|
data: { sessionToken: response.sessionToken }
|
|
565
570
|
};
|
|
566
571
|
} else if (response.state === import_identity.authentication.StateType.REQUIRE_OWNER_APPROVAL) {
|
|
567
572
|
return {
|
|
568
|
-
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED
|
|
569
|
-
stateKind: "ownerApprovalRequired"
|
|
573
|
+
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
|
|
570
574
|
};
|
|
571
575
|
} else if (response.state === import_identity.authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
|
|
572
576
|
_state = {
|
|
573
577
|
loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
574
|
-
stateKind: "emailVerificationRequired",
|
|
575
578
|
data: { stateToken: response.stateToken }
|
|
576
579
|
};
|
|
577
580
|
return _state;
|
|
578
581
|
}
|
|
579
582
|
return {
|
|
580
|
-
stateKind: "failure",
|
|
581
583
|
loginState: "FAILURE" /* FAILURE */,
|
|
582
584
|
error: "Unknown _state"
|
|
583
585
|
};
|
|
@@ -608,7 +610,6 @@ function OAuthStrategy(config) {
|
|
|
608
610
|
);
|
|
609
611
|
if (emailValidation) {
|
|
610
612
|
return {
|
|
611
|
-
stateKind: "failure",
|
|
612
613
|
loginState: "FAILURE" /* FAILURE */,
|
|
613
614
|
error: emailValidation.description,
|
|
614
615
|
errorCode: "invalidEmail"
|
|
@@ -616,7 +617,6 @@ function OAuthStrategy(config) {
|
|
|
616
617
|
}
|
|
617
618
|
if (e.details.applicationError?.code === MISSING_CAPTCHA) {
|
|
618
619
|
return {
|
|
619
|
-
stateKind: "failure",
|
|
620
620
|
loginState: "FAILURE" /* FAILURE */,
|
|
621
621
|
error: e.message,
|
|
622
622
|
errorCode: "missingCaptchaToken"
|
|
@@ -624,7 +624,6 @@ function OAuthStrategy(config) {
|
|
|
624
624
|
}
|
|
625
625
|
if (e.details.applicationError?.code === EMAIL_EXISTS) {
|
|
626
626
|
return {
|
|
627
|
-
stateKind: "failure",
|
|
628
627
|
loginState: "FAILURE" /* FAILURE */,
|
|
629
628
|
error: e.message,
|
|
630
629
|
errorCode: "emailAlreadyExists"
|
|
@@ -632,14 +631,12 @@ function OAuthStrategy(config) {
|
|
|
632
631
|
}
|
|
633
632
|
if (e.details.applicationError?.code === INVALID_CAPTCHA) {
|
|
634
633
|
return {
|
|
635
|
-
stateKind: "failure",
|
|
636
634
|
loginState: "FAILURE" /* FAILURE */,
|
|
637
635
|
error: e.message,
|
|
638
636
|
errorCode: "invalidCaptchaToken"
|
|
639
637
|
};
|
|
640
638
|
}
|
|
641
639
|
return {
|
|
642
|
-
stateKind: "failure",
|
|
643
640
|
loginState: "FAILURE" /* FAILURE */,
|
|
644
641
|
error: e.message
|
|
645
642
|
};
|
|
@@ -666,24 +663,23 @@ function OAuthStrategy(config) {
|
|
|
666
663
|
return handleState(res);
|
|
667
664
|
} catch (e) {
|
|
668
665
|
return {
|
|
669
|
-
stateKind: "failure",
|
|
670
666
|
loginState: "FAILURE" /* FAILURE */,
|
|
671
667
|
error: e.message,
|
|
672
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"
|
|
673
669
|
};
|
|
674
670
|
}
|
|
675
671
|
};
|
|
676
|
-
const processVerification = async (nextInputs) => {
|
|
677
|
-
|
|
672
|
+
const processVerification = async (nextInputs, state) => {
|
|
673
|
+
const stateToUse = state ?? _state;
|
|
674
|
+
if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
|
|
678
675
|
const code = nextInputs.verificationCode ?? nextInputs.code;
|
|
679
676
|
const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
|
|
680
677
|
code,
|
|
681
|
-
{ stateToken:
|
|
678
|
+
{ stateToken: stateToUse.data.stateToken }
|
|
682
679
|
);
|
|
683
680
|
return handleState(res);
|
|
684
681
|
}
|
|
685
682
|
return {
|
|
686
|
-
stateKind: "failure",
|
|
687
683
|
loginState: "FAILURE" /* FAILURE */,
|
|
688
684
|
error: "Unknown _state"
|
|
689
685
|
};
|
|
@@ -727,18 +723,9 @@ function OAuthStrategy(config) {
|
|
|
727
723
|
loggedIn,
|
|
728
724
|
logout,
|
|
729
725
|
register,
|
|
730
|
-
proceed: (nextInputs) => {
|
|
731
|
-
const { code, ...restProps } = nextInputs;
|
|
732
|
-
return processVerification({
|
|
733
|
-
verificationCode: code,
|
|
734
|
-
...restProps
|
|
735
|
-
});
|
|
736
|
-
},
|
|
737
726
|
processVerification,
|
|
738
727
|
login,
|
|
739
|
-
complete: getMemberTokensForDirectLogin,
|
|
740
728
|
getMemberTokensForDirectLogin,
|
|
741
|
-
sendResetPasswordMail: sendPasswordResetEmail,
|
|
742
729
|
sendPasswordResetEmail,
|
|
743
730
|
captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
|
|
744
731
|
captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
|
package/build/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/common.ts
|
|
2
2
|
var PUBLIC_METADATA_KEY = "__metadata";
|
|
3
3
|
var API_URL = "www.wixapis.com";
|
|
4
|
+
var READ_ONLY_API_URL = "readonly.wixapis.com";
|
|
5
|
+
var FORCE_WRITE_API_URLS = ["/ecom/v1/carts/current"];
|
|
4
6
|
|
|
5
7
|
// src/helpers.ts
|
|
6
8
|
var getDefaultContentHeader = (options) => {
|
|
@@ -38,16 +40,21 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
|
38
40
|
return origFunc({
|
|
39
41
|
request: async (factory) => {
|
|
40
42
|
const requestOptions = factory({ host: API_URL });
|
|
41
|
-
let
|
|
42
|
-
if (
|
|
43
|
-
|
|
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()}`;
|
|
44
51
|
}
|
|
45
52
|
try {
|
|
46
53
|
const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
|
|
47
54
|
const res = await boundFetch(url, {
|
|
48
|
-
method:
|
|
49
|
-
...
|
|
50
|
-
body: JSON.stringify(
|
|
55
|
+
method: request.method,
|
|
56
|
+
...request.data && {
|
|
57
|
+
body: JSON.stringify(request.data)
|
|
51
58
|
},
|
|
52
59
|
headers: {
|
|
53
60
|
...biHeader
|
|
@@ -357,7 +364,6 @@ function OAuthStrategy(config) {
|
|
|
357
364
|
_tokens.refreshToken = tokens.refreshToken;
|
|
358
365
|
};
|
|
359
366
|
let _state = {
|
|
360
|
-
stateKind: "initial",
|
|
361
367
|
loginState: "INITIAL" /* INITIAL */
|
|
362
368
|
};
|
|
363
369
|
const getAuthHeaders = async () => {
|
|
@@ -517,24 +523,20 @@ function OAuthStrategy(config) {
|
|
|
517
523
|
if (response.state === authentication.StateType.SUCCESS) {
|
|
518
524
|
return {
|
|
519
525
|
loginState: "SUCCESS" /* SUCCESS */,
|
|
520
|
-
stateKind: "success",
|
|
521
526
|
data: { sessionToken: response.sessionToken }
|
|
522
527
|
};
|
|
523
528
|
} else if (response.state === authentication.StateType.REQUIRE_OWNER_APPROVAL) {
|
|
524
529
|
return {
|
|
525
|
-
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED
|
|
526
|
-
stateKind: "ownerApprovalRequired"
|
|
530
|
+
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
|
|
527
531
|
};
|
|
528
532
|
} else if (response.state === authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
|
|
529
533
|
_state = {
|
|
530
534
|
loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
531
|
-
stateKind: "emailVerificationRequired",
|
|
532
535
|
data: { stateToken: response.stateToken }
|
|
533
536
|
};
|
|
534
537
|
return _state;
|
|
535
538
|
}
|
|
536
539
|
return {
|
|
537
|
-
stateKind: "failure",
|
|
538
540
|
loginState: "FAILURE" /* FAILURE */,
|
|
539
541
|
error: "Unknown _state"
|
|
540
542
|
};
|
|
@@ -565,7 +567,6 @@ function OAuthStrategy(config) {
|
|
|
565
567
|
);
|
|
566
568
|
if (emailValidation) {
|
|
567
569
|
return {
|
|
568
|
-
stateKind: "failure",
|
|
569
570
|
loginState: "FAILURE" /* FAILURE */,
|
|
570
571
|
error: emailValidation.description,
|
|
571
572
|
errorCode: "invalidEmail"
|
|
@@ -573,7 +574,6 @@ function OAuthStrategy(config) {
|
|
|
573
574
|
}
|
|
574
575
|
if (e.details.applicationError?.code === MISSING_CAPTCHA) {
|
|
575
576
|
return {
|
|
576
|
-
stateKind: "failure",
|
|
577
577
|
loginState: "FAILURE" /* FAILURE */,
|
|
578
578
|
error: e.message,
|
|
579
579
|
errorCode: "missingCaptchaToken"
|
|
@@ -581,7 +581,6 @@ function OAuthStrategy(config) {
|
|
|
581
581
|
}
|
|
582
582
|
if (e.details.applicationError?.code === EMAIL_EXISTS) {
|
|
583
583
|
return {
|
|
584
|
-
stateKind: "failure",
|
|
585
584
|
loginState: "FAILURE" /* FAILURE */,
|
|
586
585
|
error: e.message,
|
|
587
586
|
errorCode: "emailAlreadyExists"
|
|
@@ -589,14 +588,12 @@ function OAuthStrategy(config) {
|
|
|
589
588
|
}
|
|
590
589
|
if (e.details.applicationError?.code === INVALID_CAPTCHA) {
|
|
591
590
|
return {
|
|
592
|
-
stateKind: "failure",
|
|
593
591
|
loginState: "FAILURE" /* FAILURE */,
|
|
594
592
|
error: e.message,
|
|
595
593
|
errorCode: "invalidCaptchaToken"
|
|
596
594
|
};
|
|
597
595
|
}
|
|
598
596
|
return {
|
|
599
|
-
stateKind: "failure",
|
|
600
597
|
loginState: "FAILURE" /* FAILURE */,
|
|
601
598
|
error: e.message
|
|
602
599
|
};
|
|
@@ -623,24 +620,23 @@ function OAuthStrategy(config) {
|
|
|
623
620
|
return handleState(res);
|
|
624
621
|
} catch (e) {
|
|
625
622
|
return {
|
|
626
|
-
stateKind: "failure",
|
|
627
623
|
loginState: "FAILURE" /* FAILURE */,
|
|
628
624
|
error: e.message,
|
|
629
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"
|
|
630
626
|
};
|
|
631
627
|
}
|
|
632
628
|
};
|
|
633
|
-
const processVerification = async (nextInputs) => {
|
|
634
|
-
|
|
629
|
+
const processVerification = async (nextInputs, state) => {
|
|
630
|
+
const stateToUse = state ?? _state;
|
|
631
|
+
if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
|
|
635
632
|
const code = nextInputs.verificationCode ?? nextInputs.code;
|
|
636
633
|
const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
|
|
637
634
|
code,
|
|
638
|
-
{ stateToken:
|
|
635
|
+
{ stateToken: stateToUse.data.stateToken }
|
|
639
636
|
);
|
|
640
637
|
return handleState(res);
|
|
641
638
|
}
|
|
642
639
|
return {
|
|
643
|
-
stateKind: "failure",
|
|
644
640
|
loginState: "FAILURE" /* FAILURE */,
|
|
645
641
|
error: "Unknown _state"
|
|
646
642
|
};
|
|
@@ -684,18 +680,9 @@ function OAuthStrategy(config) {
|
|
|
684
680
|
loggedIn,
|
|
685
681
|
logout,
|
|
686
682
|
register,
|
|
687
|
-
proceed: (nextInputs) => {
|
|
688
|
-
const { code, ...restProps } = nextInputs;
|
|
689
|
-
return processVerification({
|
|
690
|
-
verificationCode: code,
|
|
691
|
-
...restProps
|
|
692
|
-
});
|
|
693
|
-
},
|
|
694
683
|
processVerification,
|
|
695
684
|
login,
|
|
696
|
-
complete: getMemberTokensForDirectLogin,
|
|
697
685
|
getMemberTokensForDirectLogin,
|
|
698
|
-
sendResetPasswordMail: sendPasswordResetEmail,
|
|
699
686
|
sendPasswordResetEmail,
|
|
700
687
|
captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
|
|
701
688
|
captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
34
|
-
"@wix/identity": "^1.0.
|
|
35
|
-
"@wix/image-kit": "^1.
|
|
36
|
-
"@wix/redirects": "^1.0.
|
|
37
|
-
"@wix/sdk-types": "1.
|
|
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.
|
|
44
|
-
"@swc/jest": "^0.2.
|
|
43
|
+
"@swc/core": "^1.3.80",
|
|
44
|
+
"@swc/jest": "^0.2.29",
|
|
45
45
|
"@types/jest": "^27.5.2",
|
|
46
|
-
"@types/node": "^16.18.
|
|
47
|
-
"@wix/ecom": "^1.0.
|
|
48
|
-
"@wix/events": "^1.0.
|
|
49
|
-
"@wix/
|
|
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.
|
|
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": "
|
|
82
|
+
"falconPackageHash": "2a6a54a97f2776cdbc13af01a1ac8a5a0b6c6522b2a4bbff0a80f8b6"
|
|
83
83
|
}
|