@wix/sdk 1.2.8 → 1.4.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 +181 -38
- package/build/index.d.mts +97 -35
- package/build/index.d.ts +97 -35
- package/build/index.js +181 -36
- package/build/index.mjs +179 -36
- package/package.json +18 -14
package/build/browser/index.mjs
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
+
// src/ambassador-modules.ts
|
|
2
|
+
import { transformError } from "@wix/metro-runtime/velo";
|
|
3
|
+
var parseMethod = (method) => {
|
|
4
|
+
switch (method) {
|
|
5
|
+
case "get":
|
|
6
|
+
case "GET":
|
|
7
|
+
return "GET";
|
|
8
|
+
case "post":
|
|
9
|
+
case "POST":
|
|
10
|
+
return "POST";
|
|
11
|
+
case "put":
|
|
12
|
+
case "PUT":
|
|
13
|
+
return "PUT";
|
|
14
|
+
case "delete":
|
|
15
|
+
case "DELETE":
|
|
16
|
+
return "DELETE";
|
|
17
|
+
case "patch":
|
|
18
|
+
case "PATCH":
|
|
19
|
+
return "PATCH";
|
|
20
|
+
case "head":
|
|
21
|
+
case "HEAD":
|
|
22
|
+
return "HEAD";
|
|
23
|
+
case "options":
|
|
24
|
+
case "OPTIONS":
|
|
25
|
+
return "OPTIONS";
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Unknown method: ${method}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var toHTTPModule = (factory) => (httpClient) => async (payload) => {
|
|
31
|
+
let requestOptions;
|
|
32
|
+
const HTTPFactory = (context) => {
|
|
33
|
+
requestOptions = factory(payload)(context);
|
|
34
|
+
if (requestOptions.url === void 0) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Url was not successfully created for this request, please reach out to support channels for assistance."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const { method, url, params } = requestOptions;
|
|
40
|
+
return {
|
|
41
|
+
...requestOptions,
|
|
42
|
+
method: parseMethod(method),
|
|
43
|
+
url,
|
|
44
|
+
data: requestOptions.data,
|
|
45
|
+
params
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
const response = await httpClient.request(HTTPFactory);
|
|
50
|
+
if (requestOptions === void 0) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Request options were not created for this request, please reach out to support channels for assistance."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const transformations = Array.isArray(requestOptions.transformResponse) ? requestOptions.transformResponse : [requestOptions.transformResponse];
|
|
56
|
+
let data = response.data;
|
|
57
|
+
transformations.forEach((transform) => {
|
|
58
|
+
if (transform) {
|
|
59
|
+
data = transform(response.data, response.headers);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return data;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
throw transformError(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var ambassadorModuleOptions = () => ({
|
|
68
|
+
HTTPHost: self.location.host
|
|
69
|
+
});
|
|
70
|
+
|
|
1
71
|
// src/common.ts
|
|
2
72
|
var PUBLIC_METADATA_KEY = "__metadata";
|
|
3
73
|
var API_URL = "www.wixapis.com";
|
|
@@ -37,22 +107,27 @@ function objectToKeyValue(input) {
|
|
|
37
107
|
}
|
|
38
108
|
|
|
39
109
|
// src/rest-modules.ts
|
|
40
|
-
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
110
|
+
function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
|
|
41
111
|
return origFunc({
|
|
42
112
|
request: async (factory) => {
|
|
43
|
-
var _a;
|
|
44
|
-
const requestOptions = factory({ host: API_URL });
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
113
|
+
var _a, _b, _c;
|
|
114
|
+
const requestOptions = factory({ host: (options == null ? void 0 : options.HTTPHost) || API_URL });
|
|
115
|
+
let request = requestOptions;
|
|
116
|
+
if (request.method === "GET" && ((_a = request.fallback) == null ? void 0 : _a.length) && request.params.toString().length > 4e3) {
|
|
117
|
+
request = requestOptions.fallback[0];
|
|
118
|
+
}
|
|
119
|
+
const getDefaultDomain = () => request.method === "GET" && !FORCE_WRITE_API_URLS.some((url2) => request.url === url2) ? READ_ONLY_API_URL : API_URL;
|
|
120
|
+
const domain = (_b = options == null ? void 0 : options.HTTPHost) != null ? _b : getDefaultDomain();
|
|
121
|
+
let url = `https://${domain}${request.url}`;
|
|
122
|
+
if (request.params && request.params.toString()) {
|
|
123
|
+
url += `?${request.params.toString()}`;
|
|
49
124
|
}
|
|
50
125
|
try {
|
|
51
126
|
const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
|
|
52
127
|
const res = await boundFetch(url, {
|
|
53
|
-
method:
|
|
54
|
-
...
|
|
55
|
-
body: JSON.stringify(
|
|
128
|
+
method: request.method,
|
|
129
|
+
...request.data && {
|
|
130
|
+
body: JSON.stringify(request.data)
|
|
56
131
|
},
|
|
57
132
|
headers: {
|
|
58
133
|
...biHeader
|
|
@@ -82,7 +157,7 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch) {
|
|
|
82
157
|
statusText: res.statusText
|
|
83
158
|
};
|
|
84
159
|
} catch (e) {
|
|
85
|
-
if ((
|
|
160
|
+
if ((_c = e.message) == null ? void 0 : _c.includes("fetch is not defined")) {
|
|
86
161
|
console.error("Node.js v18+ is required");
|
|
87
162
|
}
|
|
88
163
|
throw e;
|
|
@@ -134,10 +209,15 @@ function createClient(config) {
|
|
|
134
209
|
if (isHostModule(modules) && config.host) {
|
|
135
210
|
return buildHostModule(modules, config.host);
|
|
136
211
|
} else if (typeof modules === "function") {
|
|
212
|
+
const { module, options } = modules.__isAmbassador ? {
|
|
213
|
+
module: toHTTPModule(modules),
|
|
214
|
+
options: ambassadorModuleOptions()
|
|
215
|
+
} : { module: modules, options: void 0 };
|
|
137
216
|
return buildRESTDescriptor(
|
|
138
|
-
|
|
217
|
+
module,
|
|
139
218
|
metadata != null ? metadata : {},
|
|
140
|
-
boundFetch
|
|
219
|
+
boundFetch,
|
|
220
|
+
options
|
|
141
221
|
);
|
|
142
222
|
} else if (isObject(modules)) {
|
|
143
223
|
return Object.fromEntries(
|
|
@@ -362,7 +442,6 @@ function OAuthStrategy(config) {
|
|
|
362
442
|
_tokens.refreshToken = tokens.refreshToken;
|
|
363
443
|
};
|
|
364
444
|
let _state = {
|
|
365
|
-
stateKind: "initial",
|
|
366
445
|
loginState: "INITIAL" /* INITIAL */
|
|
367
446
|
};
|
|
368
447
|
const getAuthHeaders = async () => {
|
|
@@ -525,24 +604,20 @@ function OAuthStrategy(config) {
|
|
|
525
604
|
if (response.state === authentication.StateType.SUCCESS) {
|
|
526
605
|
return {
|
|
527
606
|
loginState: "SUCCESS" /* SUCCESS */,
|
|
528
|
-
stateKind: "success",
|
|
529
607
|
data: { sessionToken: response.sessionToken }
|
|
530
608
|
};
|
|
531
609
|
} else if (response.state === authentication.StateType.REQUIRE_OWNER_APPROVAL) {
|
|
532
610
|
return {
|
|
533
|
-
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED
|
|
534
|
-
stateKind: "ownerApprovalRequired"
|
|
611
|
+
loginState: "OWNER_APPROVAL_REQUIRED" /* OWNER_APPROVAL_REQUIRED */
|
|
535
612
|
};
|
|
536
613
|
} else if (response.state === authentication.StateType.REQUIRE_EMAIL_VERIFICATION) {
|
|
537
614
|
_state = {
|
|
538
615
|
loginState: "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */,
|
|
539
|
-
stateKind: "emailVerificationRequired",
|
|
540
616
|
data: { stateToken: response.stateToken }
|
|
541
617
|
};
|
|
542
618
|
return _state;
|
|
543
619
|
}
|
|
544
620
|
return {
|
|
545
|
-
stateKind: "failure",
|
|
546
621
|
loginState: "FAILURE" /* FAILURE */,
|
|
547
622
|
error: "Unknown _state"
|
|
548
623
|
};
|
|
@@ -574,7 +649,6 @@ function OAuthStrategy(config) {
|
|
|
574
649
|
);
|
|
575
650
|
if (emailValidation) {
|
|
576
651
|
return {
|
|
577
|
-
stateKind: "failure",
|
|
578
652
|
loginState: "FAILURE" /* FAILURE */,
|
|
579
653
|
error: emailValidation.description,
|
|
580
654
|
errorCode: "invalidEmail"
|
|
@@ -582,7 +656,6 @@ function OAuthStrategy(config) {
|
|
|
582
656
|
}
|
|
583
657
|
if (((_e = e.details.applicationError) == null ? void 0 : _e.code) === MISSING_CAPTCHA) {
|
|
584
658
|
return {
|
|
585
|
-
stateKind: "failure",
|
|
586
659
|
loginState: "FAILURE" /* FAILURE */,
|
|
587
660
|
error: e.message,
|
|
588
661
|
errorCode: "missingCaptchaToken"
|
|
@@ -590,7 +663,6 @@ function OAuthStrategy(config) {
|
|
|
590
663
|
}
|
|
591
664
|
if (((_f = e.details.applicationError) == null ? void 0 : _f.code) === EMAIL_EXISTS) {
|
|
592
665
|
return {
|
|
593
|
-
stateKind: "failure",
|
|
594
666
|
loginState: "FAILURE" /* FAILURE */,
|
|
595
667
|
error: e.message,
|
|
596
668
|
errorCode: "emailAlreadyExists"
|
|
@@ -598,14 +670,12 @@ function OAuthStrategy(config) {
|
|
|
598
670
|
}
|
|
599
671
|
if (((_g = e.details.applicationError) == null ? void 0 : _g.code) === INVALID_CAPTCHA) {
|
|
600
672
|
return {
|
|
601
|
-
stateKind: "failure",
|
|
602
673
|
loginState: "FAILURE" /* FAILURE */,
|
|
603
674
|
error: e.message,
|
|
604
675
|
errorCode: "invalidCaptchaToken"
|
|
605
676
|
};
|
|
606
677
|
}
|
|
607
678
|
return {
|
|
608
|
-
stateKind: "failure",
|
|
609
679
|
loginState: "FAILURE" /* FAILURE */,
|
|
610
680
|
error: e.message
|
|
611
681
|
};
|
|
@@ -633,25 +703,24 @@ function OAuthStrategy(config) {
|
|
|
633
703
|
return handleState(res);
|
|
634
704
|
} catch (e) {
|
|
635
705
|
return {
|
|
636
|
-
stateKind: "failure",
|
|
637
706
|
loginState: "FAILURE" /* FAILURE */,
|
|
638
707
|
error: e.message,
|
|
639
708
|
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
709
|
};
|
|
641
710
|
}
|
|
642
711
|
};
|
|
643
|
-
const processVerification = async (nextInputs) => {
|
|
712
|
+
const processVerification = async (nextInputs, state) => {
|
|
644
713
|
var _a;
|
|
645
|
-
|
|
714
|
+
const stateToUse = state != null ? state : _state;
|
|
715
|
+
if (stateToUse.loginState === "EMAIL_VERIFICATION_REQUIRED" /* EMAIL_VERIFICATION_REQUIRED */) {
|
|
646
716
|
const code = (_a = nextInputs.verificationCode) != null ? _a : nextInputs.code;
|
|
647
717
|
const res = await wixClientWithTokens.verification.verifyDuringAuthentication(
|
|
648
718
|
code,
|
|
649
|
-
{ stateToken:
|
|
719
|
+
{ stateToken: stateToUse.data.stateToken }
|
|
650
720
|
);
|
|
651
721
|
return handleState(res);
|
|
652
722
|
}
|
|
653
723
|
return {
|
|
654
|
-
stateKind: "failure",
|
|
655
724
|
loginState: "FAILURE" /* FAILURE */,
|
|
656
725
|
error: "Unknown _state"
|
|
657
726
|
};
|
|
@@ -696,18 +765,9 @@ function OAuthStrategy(config) {
|
|
|
696
765
|
loggedIn,
|
|
697
766
|
logout,
|
|
698
767
|
register,
|
|
699
|
-
proceed: (nextInputs) => {
|
|
700
|
-
const { code, ...restProps } = nextInputs;
|
|
701
|
-
return processVerification({
|
|
702
|
-
verificationCode: code,
|
|
703
|
-
...restProps
|
|
704
|
-
});
|
|
705
|
-
},
|
|
706
768
|
processVerification,
|
|
707
769
|
login,
|
|
708
|
-
complete: getMemberTokensForDirectLogin,
|
|
709
770
|
getMemberTokensForDirectLogin,
|
|
710
|
-
sendResetPasswordMail: sendPasswordResetEmail,
|
|
711
771
|
sendPasswordResetEmail,
|
|
712
772
|
captchaInvisibleSiteKey: "6LdoPaUfAAAAAJphvHoUoOob7mx0KDlXyXlgrx5v",
|
|
713
773
|
captchaVisibleSiteKey: "6Ld0J8IcAAAAANyrnxzrRlX1xrrdXsOmsepUYosy"
|
|
@@ -761,13 +821,96 @@ function ApiKeyStrategy({
|
|
|
761
821
|
};
|
|
762
822
|
}
|
|
763
823
|
|
|
824
|
+
// src/auth/WixAppOAuthStrategy.ts
|
|
825
|
+
function WixAppOAuthStrategy(opts) {
|
|
826
|
+
let refreshToken = opts.refreshToken;
|
|
827
|
+
return {
|
|
828
|
+
getInstallUrl({ redirectUrl }) {
|
|
829
|
+
return `https://www.wix.com/installer/install?appId=${opts.appId}&redirectUrl=${redirectUrl}`;
|
|
830
|
+
},
|
|
831
|
+
async handleOAuthCallback(url, oauthOpts) {
|
|
832
|
+
const params = new URLSearchParams(new URL(url).search);
|
|
833
|
+
const state = params.get("state");
|
|
834
|
+
if (state && (oauthOpts == null ? void 0 : oauthOpts.state) && state !== oauthOpts.state) {
|
|
835
|
+
throw new Error(
|
|
836
|
+
`Invalid OAuth callback URL. Expected state to be "${oauthOpts.state}" but got "${state}"`
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
const code = params.get("code");
|
|
840
|
+
const instanceId = params.get("instanceId");
|
|
841
|
+
if (!code || !instanceId) {
|
|
842
|
+
throw new Error(
|
|
843
|
+
"Invalid OAuth callback URL. Make sure you pass the url including the code and instanceId query params."
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
const tokensRes = await fetch("https://www.wixapis.com/oauth/access", {
|
|
847
|
+
method: "POST",
|
|
848
|
+
headers: {
|
|
849
|
+
"Content-Type": "application/json"
|
|
850
|
+
},
|
|
851
|
+
body: JSON.stringify({
|
|
852
|
+
code,
|
|
853
|
+
client_id: opts.appId,
|
|
854
|
+
client_secret: opts.appSecret,
|
|
855
|
+
grant_type: "authorization_code"
|
|
856
|
+
})
|
|
857
|
+
});
|
|
858
|
+
if (tokensRes.status !== 200) {
|
|
859
|
+
throw new Error(
|
|
860
|
+
`Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
const tokens = await tokensRes.json();
|
|
864
|
+
refreshToken = tokens.refresh_token;
|
|
865
|
+
return {
|
|
866
|
+
instanceId,
|
|
867
|
+
accessToken: tokens.access_token,
|
|
868
|
+
refreshToken: tokens.refresh_token
|
|
869
|
+
};
|
|
870
|
+
},
|
|
871
|
+
async getAuthHeaders() {
|
|
872
|
+
if (!refreshToken) {
|
|
873
|
+
throw new Error(
|
|
874
|
+
"Missing refresh token. Either pass it to the WixAppOAuthStrategy or use the handleOAuthCallback method to retrieve it."
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
const tokensRes = await fetch("https://www.wixapis.com/oauth/access", {
|
|
878
|
+
method: "POST",
|
|
879
|
+
headers: {
|
|
880
|
+
"Content-Type": "application/json"
|
|
881
|
+
},
|
|
882
|
+
body: JSON.stringify({
|
|
883
|
+
refresh_token: refreshToken,
|
|
884
|
+
client_id: opts.appId,
|
|
885
|
+
client_secret: opts.appSecret,
|
|
886
|
+
grant_type: "refresh_token"
|
|
887
|
+
})
|
|
888
|
+
});
|
|
889
|
+
if (tokensRes.status !== 200) {
|
|
890
|
+
throw new Error(
|
|
891
|
+
`Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
const tokens = await tokensRes.json();
|
|
895
|
+
refreshToken = tokens.refresh_token;
|
|
896
|
+
return {
|
|
897
|
+
headers: {
|
|
898
|
+
Authorization: tokens.access_token
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
764
905
|
// src/index.ts
|
|
765
906
|
export * from "@wix/sdk-types";
|
|
766
907
|
export {
|
|
908
|
+
API_URL,
|
|
767
909
|
ApiKeyStrategy,
|
|
768
910
|
LoginState,
|
|
769
911
|
OAuthStrategy,
|
|
770
912
|
TokenRole,
|
|
913
|
+
WixAppOAuthStrategy,
|
|
771
914
|
createClient,
|
|
772
915
|
decodeText,
|
|
773
916
|
media
|
package/build/index.d.mts
CHANGED
|
@@ -7,6 +7,34 @@ import { authentication } from '@wix/identity';
|
|
|
7
7
|
type PublicMetadata = {
|
|
8
8
|
PACKAGE_NAME?: string;
|
|
9
9
|
};
|
|
10
|
+
declare const API_URL = "www.wixapis.com";
|
|
11
|
+
|
|
12
|
+
type RequestContext = {
|
|
13
|
+
isSSR: boolean;
|
|
14
|
+
host: string;
|
|
15
|
+
protocol?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
19
|
+
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
20
|
+
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
21
|
+
*/
|
|
22
|
+
type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
23
|
+
type ResponseTransformer = (data: any, headers?: any) => any;
|
|
24
|
+
type AmbassadorRequestOptions<T = any> = {
|
|
25
|
+
_?: T;
|
|
26
|
+
url?: string;
|
|
27
|
+
method?: Method;
|
|
28
|
+
params?: any;
|
|
29
|
+
data?: any;
|
|
30
|
+
transformResponse?: ResponseTransformer | ResponseTransformer[];
|
|
31
|
+
};
|
|
32
|
+
type AmbassadorFactory<Request, Response> = {
|
|
33
|
+
(payload: Request): (context: RequestContext) => AmbassadorRequestOptions<Response>;
|
|
34
|
+
__isAmbassador: boolean;
|
|
35
|
+
};
|
|
36
|
+
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
37
|
+
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
10
38
|
|
|
11
39
|
type Headers = {
|
|
12
40
|
Authorization: string;
|
|
@@ -17,10 +45,13 @@ type Headers = {
|
|
|
17
45
|
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
18
46
|
* do not match the given host (as they will not work with the given host).
|
|
19
47
|
*/
|
|
20
|
-
type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
|
|
48
|
+
type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined> = BuildRESTDescriptors<T> & BuildAmbassadorDescriptors<T> & (H extends Host<any> ? BuildHostDescriptors<T> : {});
|
|
21
49
|
type BuildRESTDescriptors<T extends Descriptors> = T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : ConditionalExcept<{
|
|
22
50
|
[Key in keyof T]: T[Key] extends Descriptors ? BuildRESTDescriptors<T[Key]> : never;
|
|
23
51
|
}, EmptyObject>;
|
|
52
|
+
type BuildAmbassadorDescriptors<T extends Descriptors> = T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : ConditionalExcept<{
|
|
53
|
+
[Key in keyof T]: T[Key] extends Descriptors ? BuildAmbassadorDescriptors<T[Key]> : never;
|
|
54
|
+
}, EmptyObject>;
|
|
24
55
|
type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
25
56
|
[Key in keyof T]: T[Key] extends Descriptors ? BuildHostDescriptors<T[Key]> : never;
|
|
26
57
|
}, EmptyObject>;
|
|
@@ -29,7 +60,7 @@ type BuildHostDescriptors<T extends Descriptors> = T extends HostModule<any, any
|
|
|
29
60
|
* can either be a REST module or a host module.
|
|
30
61
|
* This type is recursive, so it can describe nested modules.
|
|
31
62
|
*/
|
|
32
|
-
type Descriptors = RESTFunctionDescriptor | HostModule<any, any> | {
|
|
63
|
+
type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | {
|
|
33
64
|
[key: string]: Descriptors | PublicMetadata | any;
|
|
34
65
|
};
|
|
35
66
|
/**
|
|
@@ -136,20 +167,8 @@ interface IOAuthStrategy extends AuthenticationStrategy {
|
|
|
136
167
|
};
|
|
137
168
|
register: (params: RegisterParams) => Promise<StateMachine>;
|
|
138
169
|
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>;
|
|
170
|
+
processVerification<T extends ProcessableState>(nextInputs: CalculateNextState<T>, state?: StateMachine): Promise<StateMachine>;
|
|
148
171
|
getMemberTokensForDirectLogin: (sessionToken: string) => Promise<Tokens>;
|
|
149
|
-
/**
|
|
150
|
-
* @deprecated use sendPasswordResetEmail instead
|
|
151
|
-
*/
|
|
152
|
-
sendResetPasswordMail: (email: string, redirectUri: string) => Promise<void>;
|
|
153
172
|
sendPasswordResetEmail: (email: string, redirectUri: string) => Promise<void>;
|
|
154
173
|
captchaInvisibleSiteKey: string;
|
|
155
174
|
captchaVisibleSiteKey: string;
|
|
@@ -164,37 +183,33 @@ declare enum LoginState {
|
|
|
164
183
|
USER_CAPTCHA_REQUIRED = "USER_CAPTCHA_REQUIRED",
|
|
165
184
|
SILENT_CAPTCHA_REQUIRED = "SILENT_CAPTCHA_REQUIRED"
|
|
166
185
|
}
|
|
167
|
-
interface LoginResults<
|
|
168
|
-
/**
|
|
169
|
-
* @deprecated use loginState instead
|
|
170
|
-
*/
|
|
171
|
-
stateKind: SK;
|
|
186
|
+
interface LoginResults<LK extends LoginState> {
|
|
172
187
|
loginState: LK;
|
|
173
188
|
}
|
|
174
|
-
interface SuccessState extends LoginResults<
|
|
189
|
+
interface SuccessState extends LoginResults<LoginState.SUCCESS> {
|
|
175
190
|
data: {
|
|
176
191
|
sessionToken: string;
|
|
177
192
|
};
|
|
178
193
|
}
|
|
179
|
-
interface InitialState extends LoginResults<
|
|
194
|
+
interface InitialState extends LoginResults<LoginState.INITIAL> {
|
|
180
195
|
}
|
|
181
|
-
interface ErrorState extends LoginResults<
|
|
196
|
+
interface ErrorState extends LoginResults<LoginState.FAILURE> {
|
|
182
197
|
errorCode?: 'invalidEmail' | 'invalidPassword' | 'resetPassword' | 'missingCaptchaToken' | 'emailAlreadyExists' | 'invalidCaptchaToken';
|
|
183
198
|
error: string;
|
|
184
199
|
}
|
|
185
|
-
interface EmailVerificationRequiredState extends LoginResults<
|
|
200
|
+
interface EmailVerificationRequiredState extends LoginResults<LoginState.EMAIL_VERIFICATION_REQUIRED> {
|
|
186
201
|
data: {
|
|
187
202
|
stateToken: string;
|
|
188
203
|
};
|
|
189
204
|
}
|
|
190
|
-
interface OwnerApprovalRequiredState extends LoginResults<
|
|
205
|
+
interface OwnerApprovalRequiredState extends LoginResults<LoginState.OWNER_APPROVAL_REQUIRED> {
|
|
191
206
|
}
|
|
192
|
-
interface SilentCaptchaRequiredState extends LoginResults<
|
|
207
|
+
interface SilentCaptchaRequiredState extends LoginResults<LoginState.SILENT_CAPTCHA_REQUIRED> {
|
|
193
208
|
data: {
|
|
194
209
|
stateToken: string;
|
|
195
210
|
};
|
|
196
211
|
}
|
|
197
|
-
interface UserCaptchaRequiredState extends LoginResults<
|
|
212
|
+
interface UserCaptchaRequiredState extends LoginResults<LoginState.USER_CAPTCHA_REQUIRED> {
|
|
198
213
|
data: {
|
|
199
214
|
stateToken: string;
|
|
200
215
|
};
|
|
@@ -205,16 +220,9 @@ declare enum TokenRole {
|
|
|
205
220
|
MEMBER = "member"
|
|
206
221
|
}
|
|
207
222
|
type StateMachine = InitialState | SuccessState | ErrorState | EmailVerificationRequiredState | OwnerApprovalRequiredState | SilentCaptchaRequiredState | UserCaptchaRequiredState;
|
|
208
|
-
type DeprecatedCode = {
|
|
209
|
-
/**
|
|
210
|
-
* @deprecated use verificationCode instead
|
|
211
|
-
*/
|
|
212
|
-
code: string;
|
|
213
|
-
};
|
|
214
223
|
type VerificationCode = {
|
|
215
224
|
verificationCode: string;
|
|
216
225
|
};
|
|
217
|
-
type DeprecatedCalculateNextState<T> = T extends EmailVerificationRequiredState ? DeprecatedCode : never;
|
|
218
226
|
type CalculateNextState<T> = T extends EmailVerificationRequiredState ? VerificationCode : never;
|
|
219
227
|
type ProcessableState = EmailVerificationRequiredState;
|
|
220
228
|
|
|
@@ -245,4 +253,58 @@ declare function ApiKeyStrategy({ siteId, accountId, apiKey, }: {
|
|
|
245
253
|
apiKey: string;
|
|
246
254
|
} & Context): IApiKeyStrategy;
|
|
247
255
|
|
|
248
|
-
|
|
256
|
+
type WixAppOAuthStrategy = AuthenticationStrategy & {
|
|
257
|
+
getInstallUrl({ redirectUrl }: {
|
|
258
|
+
redirectUrl: string;
|
|
259
|
+
}): string;
|
|
260
|
+
handleOAuthCallback(url: string, opts?: {
|
|
261
|
+
state: string;
|
|
262
|
+
}): Promise<{
|
|
263
|
+
instanceId: string;
|
|
264
|
+
accessToken: string;
|
|
265
|
+
refreshToken: string;
|
|
266
|
+
}>;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Creates an authentication strategy for Wix Apps OAuth installation process.
|
|
270
|
+
* Use this authentication strategy when making requests to Wix APIs from your Wix App backend.
|
|
271
|
+
* @param opts Options for initializing the authentication strategy
|
|
272
|
+
* @param opts.appId The Wix App ID
|
|
273
|
+
* @param opts.appSecret The Wix App Secret
|
|
274
|
+
* @param opts.refreshToken An optional refresh token previously retrieved from Wix OAuth API
|
|
275
|
+
* @returns An authentication strategy that can be used with WixClient
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* import { WixAppOAuthStrategy, createClient } from '@wix/sdk';
|
|
279
|
+
* import { products } from '@wix/stores';
|
|
280
|
+
*
|
|
281
|
+
* const client = createClient({
|
|
282
|
+
* auth: WixAppOAuthStrategy({
|
|
283
|
+
* appId: 'appId',
|
|
284
|
+
* appSecret: 'appSecret',
|
|
285
|
+
* }),
|
|
286
|
+
* modules: { products },
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* const installUrl = client.auth.getInstallUrl({ redirectUrl: 'https://example.com' });
|
|
290
|
+
* // Redirect the user to the installUrl
|
|
291
|
+
*
|
|
292
|
+
* ...
|
|
293
|
+
*
|
|
294
|
+
* // in the callback handler of your http server
|
|
295
|
+
* // req.url is the url of the callback request
|
|
296
|
+
* const { instanceId, refreshToken } = await client.auth.handleOAuthCallback(req.url);
|
|
297
|
+
*
|
|
298
|
+
* // store the instanceId and refreshToken in your database
|
|
299
|
+
* // use the authorized client
|
|
300
|
+
* const products = await client.products.queryProducts().find();
|
|
301
|
+
*
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
declare function WixAppOAuthStrategy(opts: {
|
|
305
|
+
appId: string;
|
|
306
|
+
appSecret: string;
|
|
307
|
+
refreshToken?: string;
|
|
308
|
+
}): WixAppOAuthStrategy;
|
|
309
|
+
|
|
310
|
+
export { API_URL, AccessToken, ApiKeyStrategy, AssertHostMatches, BuildDescriptors, CalculateNextState, Descriptors, IApiKeyStrategy, IOAuthStrategy, LoginParams, LoginState, OAuthStrategy, OauthData, OauthPKCE, ProcessableState, RefreshToken, RegisterParams, StateMachine, Token, TokenResponse, TokenRole, Tokens, WixAppOAuthStrategy, WixClient, createClient, decodeText, media };
|