@wix/sdk 1.1.21 → 1.2.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.
- package/build/browser/index.mjs +783 -0
- package/build/index.d.mts +244 -0
- package/build/index.d.ts +244 -0
- package/build/index.js +818 -0
- package/build/index.mjs +774 -0
- package/package.json +38 -24
- package/dist/cjs/__tests__/fixtures/constants.js +0 -9
- package/dist/cjs/__tests__/fixtures/constants.js.map +0 -1
- package/dist/cjs/auth/OAuthStrategy.js +0 -90
- package/dist/cjs/auth/OAuthStrategy.js.map +0 -1
- package/dist/cjs/auth/strategy.js +0 -2
- package/dist/cjs/auth/strategy.js.map +0 -1
- package/dist/cjs/external-types.d.js +0 -2
- package/dist/cjs/external-types.d.js.map +0 -1
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/test-types.d.js +0 -2
- package/dist/cjs/test-types.d.js.map +0 -1
- package/dist/cjs/wixClient.js +0 -111
- package/dist/cjs/wixClient.js.map +0 -1
- package/dist/cjs/wixMedia.js +0 -69
- package/dist/cjs/wixMedia.js.map +0 -1
- package/dist/esm/__tests__/fixtures/constants.js +0 -3
- package/dist/esm/__tests__/fixtures/constants.js.map +0 -1
- package/dist/esm/auth/OAuthStrategy.js +0 -86
- package/dist/esm/auth/OAuthStrategy.js.map +0 -1
- package/dist/esm/auth/strategy.js +0 -2
- package/dist/esm/auth/strategy.js.map +0 -1
- package/dist/esm/external-types.d.js +0 -2
- package/dist/esm/external-types.d.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/test-types.d.js +0 -2
- package/dist/esm/test-types.d.js.map +0 -1
- package/dist/esm/wixClient.js +0 -108
- package/dist/esm/wixClient.js.map +0 -1
- package/dist/esm/wixMedia.js +0 -63
- package/dist/esm/wixMedia.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/__tests__/fixtures/constants.d.ts +0 -3
- package/dist/types/__tests__/fixtures/constants.d.ts.map +0 -1
- package/dist/types/auth/OAuthStrategy.d.ts +0 -18
- package/dist/types/auth/OAuthStrategy.d.ts.map +0 -1
- package/dist/types/auth/strategy.d.ts +0 -6
- package/dist/types/auth/strategy.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/wixClient.d.ts +0 -18
- package/dist/types/wixClient.d.ts.map +0 -1
- package/dist/types/wixMedia.d.ts +0 -26
- package/dist/types/wixMedia.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,56 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Ronny Ringel",
|
|
7
7
|
"email": "ronnyr@wix.com"
|
|
8
8
|
},
|
|
9
|
-
"main": "
|
|
10
|
-
"module": "
|
|
9
|
+
"main": "build/index.js",
|
|
10
|
+
"module": "build/index.mjs",
|
|
11
|
+
"browser": "build/browser/index.mjs",
|
|
11
12
|
"sideEffects": false,
|
|
12
|
-
"types": "
|
|
13
|
+
"types": "build/index.d.ts",
|
|
13
14
|
"files": [
|
|
14
|
-
"
|
|
15
|
+
"build"
|
|
15
16
|
],
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"registry": "https://registry.npmjs.org/",
|
|
18
19
|
"access": "public"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
|
-
"build": "
|
|
22
|
-
"
|
|
23
|
-
"test": "
|
|
24
|
-
"lint": "
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"test:watch": "jest --watch",
|
|
25
|
+
"lint": "eslint --max-warnings=0 .",
|
|
26
|
+
"lint:fix": "eslint --max-warnings=0 . --fix",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
25
28
|
},
|
|
26
29
|
"lint-staged": {
|
|
27
30
|
"*.{js,ts}": "yarn lint"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.
|
|
31
|
-
"@
|
|
32
|
-
"@wix/
|
|
33
|
-
"@wix/
|
|
33
|
+
"@babel/runtime": "^7.22.6",
|
|
34
|
+
"@types/grecaptcha": "^3.0.4",
|
|
35
|
+
"@wix/identity": "^1.0.44",
|
|
36
|
+
"@wix/image-kit": "^1.34.0",
|
|
37
|
+
"@wix/redirects": "^1.0.21",
|
|
38
|
+
"@wix/sdk-types": "1.2.5",
|
|
39
|
+
"pkce-challenge": "^3.1.0",
|
|
34
40
|
"querystring": "^0.2.1",
|
|
35
|
-
"type-fest": "^
|
|
41
|
+
"type-fest": "^3.13.1"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
44
|
+
"@swc/core": "^1.3.70",
|
|
45
|
+
"@swc/jest": "^0.2.27",
|
|
38
46
|
"@types/jest": "^27.5.2",
|
|
39
|
-
"@types/node": "^16.18.
|
|
40
|
-
"@wix/ecom": "^1.0.
|
|
41
|
-
"@wix/
|
|
42
|
-
"@wix/
|
|
47
|
+
"@types/node": "^16.18.39",
|
|
48
|
+
"@wix/ecom": "^1.0.274",
|
|
49
|
+
"@wix/events": "^1.0.107",
|
|
50
|
+
"@wix/motion": "^1.0.26",
|
|
51
|
+
"eslint": "^7.32.0",
|
|
52
|
+
"eslint-config-sdk": "0.0.0",
|
|
53
|
+
"is-ci": "^3.0.1",
|
|
54
|
+
"jest": "^27.5.1",
|
|
55
|
+
"jest-teamcity": "^1.11.0",
|
|
43
56
|
"ts-jest": "^27.1.5",
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
"jest": {
|
|
47
|
-
"preset": "@wix/jest-yoshi-preset"
|
|
57
|
+
"tsup": "^7.1.0",
|
|
58
|
+
"typescript": "~4.9.5"
|
|
48
59
|
},
|
|
49
60
|
"yoshiFlowLibrary": {
|
|
50
61
|
"buildEsmWithBabel": true
|
|
51
62
|
},
|
|
52
63
|
"eslintConfig": {
|
|
53
|
-
"extends": "
|
|
64
|
+
"extends": "sdk"
|
|
54
65
|
},
|
|
55
66
|
"wix": {
|
|
56
67
|
"artifact": {
|
|
@@ -60,11 +71,14 @@
|
|
|
60
71
|
"validations": {
|
|
61
72
|
"source": [
|
|
62
73
|
"lint"
|
|
74
|
+
],
|
|
75
|
+
"postDependenciesBuild": [
|
|
76
|
+
"typecheck"
|
|
63
77
|
]
|
|
64
78
|
}
|
|
65
79
|
},
|
|
66
80
|
"wallaby": {
|
|
67
81
|
"autoDetect": true
|
|
68
82
|
},
|
|
69
|
-
"falconPackageHash": "
|
|
83
|
+
"falconPackageHash": "877aac46cdf9d0aa57c0b0a7739d777f1fda89bf48cacd716766956a"
|
|
70
84
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.VALID_TOKEN = exports.EXPIRED_TOKEN = void 0;
|
|
5
|
-
const VALID_TOKEN = 'OauthNG.JWS.eyJraWQiOiJWUWswU3lxbyIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1widG9rZW5JZFwiOlwiMzU5NGU1ZTUtZTk1Yy00MTk0LWFmYzItNmY2ZGFkNWM2NWIxXCIsXCJjbGllbnRJZFwiOlwiNjczMDc3M2QtZTU0Ny00YmViLWFiODktNmM0ODAxNjZjMjlkXCIsXCJzY29wZXNcIjpudWxsLFwic3ViamVjdFwiOntcIkBjbGFzc1wiOlwiY29tLndpeHByZXNzLmlkZW50aXR5Lm9hdXRoMi52MS5kb21haW4uT2F1dGhEb21haW4kVmlzaXRvclwiLFwiaWRcIjpcImVlMWMyMmQ0LTRlYzYtNDNjMS05ZjQ4LTVhNDM2ODM5NDdkZVwiLFwibXNpZFwiOlwiNzNjYTBiYmItOGZiYi00N2Y5LTg3MjQtODIyNjczZWM4MjE2XCJ9fSIsImlhdCI6MTY3NDAyNTc0MywiZXhwIjoyNjc0MDI2MTAzfQ.GxviE1J4jd9p-WYK__w9DqH8zFAyAKv5OwB6Ccy9vcE';
|
|
6
|
-
exports.VALID_TOKEN = VALID_TOKEN;
|
|
7
|
-
const EXPIRED_TOKEN = 'OauthNG.JWS.eyJraWQiOiJWUWswU3lxbyIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1widG9rZW5JZFwiOlwiMzU5NGU1ZTUtZTk1Yy00MTk0LWFmYzItNmY2ZGFkNWM2NWIxXCIsXCJjbGllbnRJZFwiOlwiNjczMDc3M2QtZTU0Ny00YmViLWFiODktNmM0ODAxNjZjMjlkXCIsXCJzY29wZXNcIjpudWxsLFwic3ViamVjdFwiOntcIkBjbGFzc1wiOlwiY29tLndpeHByZXNzLmlkZW50aXR5Lm9hdXRoMi52MS5kb21haW4uT2F1dGhEb21haW4kVmlzaXRvclwiLFwiaWRcIjpcImVlMWMyMmQ0LTRlYzYtNDNjMS05ZjQ4LTVhNDM2ODM5NDdkZVwiLFwibXNpZFwiOlwiNzNjYTBiYmItOGZiYi00N2Y5LTg3MjQtODIyNjczZWM4MjE2XCJ9fSIsImlhdCI6MTY3NDAyNTc0MywiZXhwIjoxNjc0MDI2MTAzfQ.cmmc2eZLpPM40KAXYKR49DkTq9nwvKH_ghbSBHfiD4M';
|
|
8
|
-
exports.EXPIRED_TOKEN = EXPIRED_TOKEN;
|
|
9
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["VALID_TOKEN","EXPIRED_TOKEN"],"sources":["../../../../src/__tests__/fixtures/constants.ts"],"sourcesContent":["export const VALID_TOKEN =\n 'OauthNG.JWS.eyJraWQiOiJWUWswU3lxbyIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1widG9rZW5JZFwiOlwiMzU5NGU1ZTUtZTk1Yy00MTk0LWFmYzItNmY2ZGFkNWM2NWIxXCIsXCJjbGllbnRJ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AAMC,aAAa,GACxB,gkBAAgkB;AAAC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.OAuthStrategy = OAuthStrategy;
|
|
5
|
-
var _wixClient = require("../wixClient");
|
|
6
|
-
var _identity = require("@wix/identity");
|
|
7
|
-
function OAuthStrategy(config) {
|
|
8
|
-
const wixClient = (0, _wixClient.createClient)({
|
|
9
|
-
modules: {
|
|
10
|
-
oauth: _identity.oauth
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
const _tokens = {
|
|
14
|
-
accessToken: '',
|
|
15
|
-
refreshToken: ''
|
|
16
|
-
};
|
|
17
|
-
const generateVisitorTokens = async tokens => {
|
|
18
|
-
if (tokens != null && tokens.accessToken && tokens != null && tokens.refreshToken && !isTokenExpired(tokens.accessToken)) {
|
|
19
|
-
return Promise.resolve(tokens);
|
|
20
|
-
}
|
|
21
|
-
if (tokens != null && tokens.refreshToken) {
|
|
22
|
-
return renewToken(tokens.refreshToken);
|
|
23
|
-
}
|
|
24
|
-
const tokensResponse = await wixClient.oauth.token({
|
|
25
|
-
preAuthenticated: {
|
|
26
|
-
clientId: config.clientId
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return {
|
|
30
|
-
accessToken: tokensResponse.accessToken.token,
|
|
31
|
-
refreshToken: tokensResponse.refreshToken.token
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const renewToken = async refreshToken => {
|
|
35
|
-
const tokensResponse = await wixClient.oauth.token({
|
|
36
|
-
refreshToken: {
|
|
37
|
-
token: refreshToken
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
accessToken: tokensResponse.accessToken.token,
|
|
42
|
-
refreshToken
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
generateVisitorTokens,
|
|
47
|
-
renewToken,
|
|
48
|
-
isTokenExpired,
|
|
49
|
-
getAuthHeaders: async () => {
|
|
50
|
-
if (!_tokens.accessToken || isTokenExpired(_tokens.accessToken)) {
|
|
51
|
-
const tokens = await generateVisitorTokens(_tokens);
|
|
52
|
-
_tokens.accessToken = tokens.accessToken;
|
|
53
|
-
_tokens.refreshToken = tokens.refreshToken;
|
|
54
|
-
}
|
|
55
|
-
return Promise.resolve({
|
|
56
|
-
headers: {
|
|
57
|
-
Authorization: _tokens.accessToken
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
setTokens: tokens => {
|
|
62
|
-
_tokens.accessToken = tokens.accessToken;
|
|
63
|
-
_tokens.refreshToken = tokens.refreshToken;
|
|
64
|
-
},
|
|
65
|
-
getTokens: () => _tokens
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function parseJWT(token) {
|
|
69
|
-
const base64Url = token.split('.')[3];
|
|
70
|
-
if (typeof window !== 'undefined') {
|
|
71
|
-
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
72
|
-
const jsonPayload = decodeURIComponent(window.atob(base64).split('').map(c => {
|
|
73
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
74
|
-
}).join(''));
|
|
75
|
-
return JSON.parse(jsonPayload);
|
|
76
|
-
} else {
|
|
77
|
-
return JSON.parse(Buffer.from(base64Url, 'base64').toString());
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function isTokenExpired(token) {
|
|
81
|
-
const {
|
|
82
|
-
exp
|
|
83
|
-
} = parseJWT(token);
|
|
84
|
-
if (exp) {
|
|
85
|
-
const currentDate = Math.floor(Date.now() / 1000);
|
|
86
|
-
return exp < currentDate;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=OAuthStrategy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["OAuthStrategy","config","wixClient","createClient","modules","oauth","_tokens","accessToken","refreshToken","generateVisitorTokens","tokens","isTokenExpired","Promise","resolve","renewToken","tokensResponse","token","preAuthenticated","clientId","getAuthHeaders","headers","Authorization","setTokens","getTokens","parseJWT","base64Url","split","window","base64","replace","jsonPayload","decodeURIComponent","atob","map","c","charCodeAt","toString","slice","join","JSON","parse","Buffer","from","exp","currentDate","Math","floor","Date","now"],"sources":["../../../src/auth/OAuthStrategy.ts"],"sourcesContent":["import { createClient } from '../wixClient';\nimport { oauth } from '@wix/identity';\n\nexport interface Tokens {\n accessToken: string;\n refreshToken: string;\n}\n\nexport interface IOAuthStrategy extends AuthenticationStrategy {\n generateVisitorTokens(tokens?: {\n refreshToken?: string;\n accessToken?: string;\n }): Promise<Tokens>;\n renewToken: (refreshToken: string) => Promise<Tokens>;\n isTokenExpired: (accessToken: string) => boolean;\n setTokens: (tokens: Tokens) => void;\n getTokens: () => Tokens;\n}\n\nexport function OAuthStrategy(config: { clientId: string }): IOAuthStrategy {\n const wixClient = createClient({ modules: { oauth } });\n const _tokens: Tokens = { accessToken: '', refreshToken: '' };\n\n const generateVisitorTokens = async (\n tokens?: Partial<Tokens>,\n ): Promise<Tokens> => {\n if (\n tokens?.accessToken &&\n tokens?.refreshToken &&\n !isTokenExpired(tokens.accessToken)\n ) {\n return Promise.resolve(tokens) as Promise<Tokens>;\n }\n\n if (tokens?.refreshToken) {\n return renewToken(tokens.refreshToken);\n }\n\n const tokensResponse = await wixClient.oauth.token({\n preAuthenticated: {\n clientId: config.clientId,\n },\n });\n\n return {\n accessToken: tokensResponse.accessToken!.token!,\n refreshToken: tokensResponse.refreshToken!.token!,\n };\n };\n\n const renewToken = async (refreshToken: string): Promise<Tokens> => {\n const tokensResponse = await wixClient.oauth.token({\n refreshToken: { token: refreshToken },\n });\n return {\n accessToken: tokensResponse.accessToken!.token!,\n refreshToken,\n };\n };\n\n return {\n generateVisitorTokens,\n renewToken,\n isTokenExpired,\n getAuthHeaders: async () => {\n if (!_tokens.accessToken || isTokenExpired(_tokens.accessToken)) {\n const tokens = await generateVisitorTokens(_tokens);\n _tokens.accessToken = tokens.accessToken;\n _tokens.refreshToken = tokens.refreshToken;\n }\n return Promise.resolve({\n headers: { Authorization: _tokens.accessToken },\n });\n },\n setTokens: (tokens: Tokens): void => {\n _tokens.accessToken = tokens.accessToken;\n _tokens.refreshToken = tokens.refreshToken;\n },\n getTokens: () => _tokens,\n };\n}\n\nfunction parseJWT(token: string) {\n const base64Url = token.split('.')[3];\n if (typeof window !== 'undefined') {\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n window\n .atob(base64)\n .split('')\n .map((c) => {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(''),\n );\n\n return JSON.parse(jsonPayload);\n } else {\n return JSON.parse(Buffer.from(base64Url, 'base64').toString());\n }\n}\n\nfunction isTokenExpired(token: string): boolean {\n const { exp } = parseJWT(token);\n if (exp) {\n const currentDate = Math.floor(Date.now() / 1000);\n return exp < currentDate;\n }\n return true;\n}\n"],"mappings":";;;;AAAA;AACA;AAkBO,SAASA,aAAa,CAACC,MAA4B,EAAkB;EAC1E,MAAMC,SAAS,GAAG,IAAAC,uBAAY,EAAC;IAAEC,OAAO,EAAE;MAAEC,KAAK,EAALA;IAAM;EAAE,CAAC,CAAC;EACtD,MAAMC,OAAe,GAAG;IAAEC,WAAW,EAAE,EAAE;IAAEC,YAAY,EAAE;EAAG,CAAC;EAE7D,MAAMC,qBAAqB,GAAG,MAC5BC,MAAwB,IACJ;IACpB,IACEA,MAAM,YAANA,MAAM,CAAEH,WAAW,IACnBG,MAAM,YAANA,MAAM,CAAEF,YAAY,IACpB,CAACG,cAAc,CAACD,MAAM,CAACH,WAAW,CAAC,EACnC;MACA,OAAOK,OAAO,CAACC,OAAO,CAACH,MAAM,CAAC;IAChC;IAEA,IAAIA,MAAM,YAANA,MAAM,CAAEF,YAAY,EAAE;MACxB,OAAOM,UAAU,CAACJ,MAAM,CAACF,YAAY,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ACR,KAAa,EAAE;EAC/B,MAAMS,SAAS,GAAGT,KAAK,CAACU,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACrC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,MAAMC,MAAM,GAAGH,SAAS,CAACI,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;IAC9D,MAAMC,WAAW,GAAGC,kBAAkB,CACpCJ,MAAM,CACHK,IAAI,CAACJ,MAAM,CAAC,CACZF,KAAK,CAAC,EAAE,CAAC,CACTO,GAAG,CAAEC,CAAC,IAAK;MACV,OAAO,GAAG,GAAG,CAAC,IAAI,GAAGA,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,EAAEC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CACDC,IAAI,CAAC,EAAE,CAAC,CACZ;IAED,OAAOC,IAAI,CAACC,KAAK,CAACV,WAAW,CAAC;EAChC,CAAC,MAAM;IACL,OAAOS,IAAI,CAACC,KAAK,CAACC,MAAM,CAACC,IAAI,CAACjB,SAAS,EAAE,QAAQ,CAAC,CAACW,QAAQ,EAAE,CAAC;EAChE;AACF;AAEA,SAASzB,cAAc,CAACK,KAAa,EAAW;EAC9C,MAAM;IAAE2B;EAAI,CAAC,GAAGnB,QAAQ,CAACR,KAAK,CAAC;EAC/B,IAAI2B,GAAG,EAAE;IACP,MAAMC,WAAW,GAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,GAAG,EAAE,GAAG,IAAI,CAAC;IACjD,OAAOL,GAAG,GAAGC,WAAW;EAC1B;EACA,OAAO,IAAI;AACb"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/auth/strategy.ts"],"sourcesContent":["type AuthenticationStrategy = {\n getAuthHeaders: () => Promise<{ headers: Record<string, string> }>;\n};\n"],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/external-types.d.ts"],"sourcesContent":["/// <reference types=\"@wix/yoshi-flow-library/types\" />\n"],"mappings":"AAAA"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
var _wixClient = require("./wixClient");
|
|
5
|
-
Object.keys(_wixClient).forEach(function (key) {
|
|
6
|
-
if (key === "default" || key === "__esModule") return;
|
|
7
|
-
if (key in exports && exports[key] === _wixClient[key]) return;
|
|
8
|
-
exports[key] = _wixClient[key];
|
|
9
|
-
});
|
|
10
|
-
var _wixMedia = require("./wixMedia");
|
|
11
|
-
Object.keys(_wixMedia).forEach(function (key) {
|
|
12
|
-
if (key === "default" || key === "__esModule") return;
|
|
13
|
-
if (key in exports && exports[key] === _wixMedia[key]) return;
|
|
14
|
-
exports[key] = _wixMedia[key];
|
|
15
|
-
});
|
|
16
|
-
var _OAuthStrategy = require("./auth/OAuthStrategy");
|
|
17
|
-
Object.keys(_OAuthStrategy).forEach(function (key) {
|
|
18
|
-
if (key === "default" || key === "__esModule") return;
|
|
19
|
-
if (key in exports && exports[key] === _OAuthStrategy[key]) return;
|
|
20
|
-
exports[key] = _OAuthStrategy[key];
|
|
21
|
-
});
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './wixClient';\nexport * from './wixMedia';\nexport * from './auth/OAuthStrategy';\n"],"mappings":";;;AAAA;AAAA;EAAA;EAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;AAAA"}
|
package/dist/cjs/test-types.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/test-types.d.ts"],"sourcesContent":["/// <reference types=\"@wix/jest-yoshi-preset/types\" />\n"],"mappings":"AAAA"}
|
package/dist/cjs/wixClient.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.createClient = createClient;
|
|
5
|
-
const API_URL = 'www.wixapis.com';
|
|
6
|
-
const wrapperBuilder = (origFunc, authStrategy, headers
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
) => {
|
|
9
|
-
return origFunc({
|
|
10
|
-
request: async factory => {
|
|
11
|
-
const requestOptions = factory({
|
|
12
|
-
host: API_URL
|
|
13
|
-
});
|
|
14
|
-
let url = `https://${API_URL}${requestOptions.url}`;
|
|
15
|
-
if (requestOptions.params && Object.keys(requestOptions.params).length) {
|
|
16
|
-
url += `?${new URLSearchParams(requestOptions.params)}`;
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const authHeaders = await authStrategy.getAuthHeaders();
|
|
20
|
-
const res = await fetch(url, {
|
|
21
|
-
method: requestOptions.method,
|
|
22
|
-
...(requestOptions.data && {
|
|
23
|
-
body: JSON.stringify(requestOptions.data)
|
|
24
|
-
}),
|
|
25
|
-
headers: {
|
|
26
|
-
'Content-Type': 'application/json',
|
|
27
|
-
...headers,
|
|
28
|
-
...(authHeaders == null ? void 0 : authHeaders.headers)
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
if (res.status !== 200) {
|
|
32
|
-
var _dataError, _dataError2;
|
|
33
|
-
let dataError = null;
|
|
34
|
-
try {
|
|
35
|
-
dataError = await res.json();
|
|
36
|
-
} catch (e) {
|
|
37
|
-
//
|
|
38
|
-
}
|
|
39
|
-
throw errorBuilder(res.status, (_dataError = dataError) == null ? void 0 : _dataError.message, (_dataError2 = dataError) == null ? void 0 : _dataError2.details);
|
|
40
|
-
}
|
|
41
|
-
const data = await res.json();
|
|
42
|
-
return {
|
|
43
|
-
data
|
|
44
|
-
};
|
|
45
|
-
} catch (e) {
|
|
46
|
-
var _e$message;
|
|
47
|
-
if ((_e$message = e.message) != null && _e$message.includes('fetch is not defined')) {
|
|
48
|
-
console.error('Node.js v18+ is required');
|
|
49
|
-
}
|
|
50
|
-
throw e;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
const errorBuilder = (code, description, details) => {
|
|
56
|
-
return {
|
|
57
|
-
response: {
|
|
58
|
-
data: {
|
|
59
|
-
details: {
|
|
60
|
-
...details,
|
|
61
|
-
...(!(details != null && details.validationError) && {
|
|
62
|
-
applicationError: {
|
|
63
|
-
description,
|
|
64
|
-
code
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
},
|
|
68
|
-
message: description
|
|
69
|
-
},
|
|
70
|
-
status: code
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
function createClient(config) {
|
|
75
|
-
if (!config.modules || Object.entries(config.modules).length < 1) {
|
|
76
|
-
throw new Error('Missing modules');
|
|
77
|
-
}
|
|
78
|
-
const _headers = config.headers || {
|
|
79
|
-
Authorization: ''
|
|
80
|
-
};
|
|
81
|
-
const authStrategy = config.auth || {
|
|
82
|
-
getAuthHeaders: () => Promise.resolve({
|
|
83
|
-
headers: {}
|
|
84
|
-
})
|
|
85
|
-
};
|
|
86
|
-
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
87
|
-
const traverse = obj => {
|
|
88
|
-
return Object.entries(obj).reduce((prev, [key, value]) => {
|
|
89
|
-
if (isObject(value)) {
|
|
90
|
-
prev[key] = traverse(value);
|
|
91
|
-
} else if (typeof obj[key] === 'function') {
|
|
92
|
-
prev[key] = wrapperBuilder(value, authStrategy, _headers);
|
|
93
|
-
} else {
|
|
94
|
-
prev[key] = value;
|
|
95
|
-
}
|
|
96
|
-
return prev;
|
|
97
|
-
}, {});
|
|
98
|
-
};
|
|
99
|
-
const setHeaders = headers => {
|
|
100
|
-
for (const k in headers) {
|
|
101
|
-
_headers[k] = headers[k];
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const wrappedModules = traverse(config.modules);
|
|
105
|
-
return {
|
|
106
|
-
...wrappedModules,
|
|
107
|
-
auth: authStrategy,
|
|
108
|
-
setHeaders
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=wixClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["API_URL","wrapperBuilder","origFunc","authStrategy","headers","request","factory","requestOptions","host","url","params","Object","keys","length","URLSearchParams","authHeaders","getAuthHeaders","res","fetch","method","data","body","JSON","stringify","status","dataError","json","e","errorBuilder","message","details","includes","console","error","code","description","response","validationError","applicationError","createClient","config","modules","entries","Error","_headers","Authorization","auth","Promise","resolve","isObject","val","Array","isArray","traverse","obj","reduce","prev","key","value","setHeaders","k","wrappedModules"],"sources":["../../src/wixClient.ts"],"sourcesContent":["import { Simplify } from 'type-fest';\n\ntype Headers = { Authorization: string } & Record<string, string>;\n\ntype WithoutFunctionWrapper<T> = {\n [Key in keyof T]: T[Key] extends (...args: any) => any\n ? ReturnType<T[Key]>\n : Simplify<WithoutFunctionWrapper<T[Key]>>;\n};\n\nexport interface IWrapper<Z extends AuthenticationStrategy> {\n setHeaders(headers: Headers): void;\n auth: Z;\n}\n\nconst API_URL = 'www.wixapis.com';\n\nconst wrapperBuilder = <T extends Function, Z extends AuthenticationStrategy>(\n origFunc: T,\n authStrategy: Z,\n headers: Headers,\n // @ts-expect-error\n): ReturnType<T> => {\n return origFunc({\n request: async (factory: any) => {\n const requestOptions = factory({ host: API_URL });\n let url = `https://${API_URL}${requestOptions.url}`;\n if (requestOptions.params && Object.keys(requestOptions.params).length) {\n url += `?${new URLSearchParams(requestOptions.params)}`;\n }\n try {\n const authHeaders = await authStrategy.getAuthHeaders();\n const res = await fetch(url, {\n method: requestOptions.method,\n ...(requestOptions.data && {\n body: JSON.stringify(requestOptions.data),\n }),\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n ...authHeaders?.headers,\n },\n });\n if (res.status !== 200) {\n let dataError: any = null;\n try {\n dataError = await res.json();\n } catch (e) {\n //\n }\n throw errorBuilder(\n res.status,\n dataError?.message,\n dataError?.details,\n );\n }\n const data = await res.json();\n return { data };\n } catch (e: any) {\n if (e.message?.includes('fetch is not defined')) {\n console.error('Node.js v18+ is required');\n }\n throw e;\n }\n },\n });\n};\n\nconst errorBuilder = (code: number, description: string, details?: any) => {\n return {\n response: {\n data: {\n details: {\n ...details,\n ...(!details?.validationError && {\n applicationError: {\n description,\n code,\n },\n }),\n },\n message: description,\n },\n status: code,\n },\n };\n};\n\nexport function createClient<\n T = any,\n Z extends AuthenticationStrategy = any,\n>(config: {\n modules: T;\n auth?: Z;\n headers?: Headers;\n}): WithoutFunctionWrapper<T> & IWrapper<Z> {\n if (!config.modules || Object.entries(config.modules).length < 1) {\n throw new Error('Missing modules');\n }\n\n const _headers: Headers = config.headers || { Authorization: '' };\n const authStrategy = config.auth || {\n getAuthHeaders: () => Promise.resolve({ headers: {} }),\n };\n\n const isObject = (val: any) =>\n val && typeof val === 'object' && !Array.isArray(val);\n\n const traverse = (obj: any) => {\n return Object.entries(obj).reduce((prev: any, [key, value]) => {\n if (isObject(value)) {\n prev[key] = traverse(value);\n } else if (typeof obj[key] === 'function') {\n prev[key] = wrapperBuilder(value as Function, authStrategy, _headers);\n } else {\n prev[key] = value;\n }\n return prev;\n }, {});\n };\n\n const setHeaders = (headers: Headers) => {\n for (const k in headers) {\n _headers[k] = headers[k];\n }\n };\n\n const wrappedModules = traverse(config.modules);\n return {\n ...wrappedModules,\n auth: authStrategy,\n setHeaders,\n };\n}\n"],"mappings":";;;;AAeA,MAAMA,OAAO,GAAG,iBAAiB;AAEjC,MAAMC,cAAc,GAAG,CACrBC,QAAW,EACXC,YAAe,EACfC;AACA;AAAA,KACkB;EAClB,OAAOF,QAAQ,CAAC;IACdG,OAAO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AC,CAACC,MAAM,CAAC,CAACC,IAAS,EAAE,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;MAC7D,IAAIT,QAAQ,CAACS,KAAK,CAAC,EAAE;QACnBF,IAAI,CAACC,GAAG,CAAC,GAAGJ,QAAQ,CAACK,KAAK,CAAC;MAC7B,CAAC,MAAM,IAAI,OAAOJ,GAAG,CAACG,GAAG,CAAC,KAAK,UAAU,EAAE;QACzCD,IAAI,CAACC,GAAG,CAAC,GAAGxD,cAAc,CAACyD,KAAK,EAAcvD,YAAY,EAAEyC,QAAQ,CAAC;MACvE,CAAC,MAAM;QACLY,IAAI,CAACC,GAAG,CAAC,GAAGC,KAAK;MACnB;MACA,OAAOF,IAAI;IACb,CAAC,EAAE,CAAC,CAAC,CAAC;EACR,CAAC;EAED,MAAMG,UAAU,GAAIvD,OAAgB,IAAK;IACvC,KAAK,MAAMwD,CAAC,IAAIxD,OAAO,EAAE;MACvBwC,QAAQ,CAACgB,CAAC,CAAC,GAAGxD,OAAO,CAACwD,CAAC,CAAC;IAC1B;EACF,CAAC;EAED,MAAMC,cAAc,GAAGR,QAAQ,CAACb,MAAM,CAACC,OAAO,CAAC;EAC/C,OAAO;IACL,GAAGoB,cAAc;IACjBf,IAAI,EAAE3C,YAAY;IAClBwD;EACF,CAAC;AACH"}
|
package/dist/cjs/wixMedia.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.decodeText = decodeText;
|
|
5
|
-
exports.media = void 0;
|
|
6
|
-
var _imageKit = require("@wix/image-kit");
|
|
7
|
-
var _querystring = require("querystring");
|
|
8
|
-
const URL_HASH_PREFIX = '#';
|
|
9
|
-
const WIX_PROTOCOL = 'wix:';
|
|
10
|
-
const WIX_IMAGE = 'image';
|
|
11
|
-
function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
12
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
13
|
-
return _imageKit.sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
14
|
-
}
|
|
15
|
-
function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
16
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
17
|
-
return _imageKit.sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
18
|
-
}
|
|
19
|
-
function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
20
|
-
const img = getImageUrl(wixMediaIdentifier);
|
|
21
|
-
return _imageKit.sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
22
|
-
}
|
|
23
|
-
function getImageUrl(val) {
|
|
24
|
-
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
25
|
-
const {
|
|
26
|
-
hash,
|
|
27
|
-
pathname
|
|
28
|
-
} = new URL(alignedImage);
|
|
29
|
-
const {
|
|
30
|
-
originHeight: height,
|
|
31
|
-
originWidth: width
|
|
32
|
-
} = (0, _querystring.parse)(hash.replace(URL_HASH_PREFIX, ''));
|
|
33
|
-
const [id, filenameOrAltText] = pathname.replace(`${WIX_IMAGE}://v1/`, '').split('/');
|
|
34
|
-
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
35
|
-
const res = {
|
|
36
|
-
id,
|
|
37
|
-
url: `https://static.wixstatic.com/media/${id}`,
|
|
38
|
-
height: Number(height),
|
|
39
|
-
width: Number(width)
|
|
40
|
-
};
|
|
41
|
-
if (!decodedFilenameOrAltText) {
|
|
42
|
-
return res;
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
...res,
|
|
46
|
-
altText: decodedFilenameOrAltText,
|
|
47
|
-
filename: decodedFilenameOrAltText
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function decodeText(s) {
|
|
51
|
-
if (!s) {
|
|
52
|
-
return s;
|
|
53
|
-
}
|
|
54
|
-
return decodeURIComponent(s);
|
|
55
|
-
}
|
|
56
|
-
function alignIfLegacy(url, type) {
|
|
57
|
-
const {
|
|
58
|
-
protocol
|
|
59
|
-
} = new URL(url);
|
|
60
|
-
return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
|
|
61
|
-
}
|
|
62
|
-
const media = {
|
|
63
|
-
getCroppedImageUrl,
|
|
64
|
-
getScaledToFillImageUrl,
|
|
65
|
-
getScaledToFitImageUrl,
|
|
66
|
-
getImageUrl
|
|
67
|
-
};
|
|
68
|
-
exports.media = media;
|
|
69
|
-
//# sourceMappingURL=wixMedia.js.map
|
package/dist/cjs/wixMedia.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["URL_HASH_PREFIX","WIX_PROTOCOL","WIX_IMAGE","getScaledToFillImageUrl","wixMediaIdentifier","targetWidth","targetHeight","options","img","getImageUrl","sdk","getScaleToFillImageURL","id","height","width","getScaledToFitImageUrl","getScaleToFitImageURL","getCroppedImageUrl","cropX","cropY","cropWidth","cropHeight","getCropImageURL","val","alignedImage","alignIfLegacy","hash","pathname","URL","originHeight","originWidth","parse","replace","filenameOrAltText","split","decodedFilenameOrAltText","decodeText","res","url","Number","altText","filename","s","decodeURIComponent","type","protocol","media"],"sources":["../../src/wixMedia.ts"],"sourcesContent":["import { sdk, ImageTransformOptions } from '@wix/image-kit';\nimport { parse } from 'querystring';\n\nconst URL_HASH_PREFIX = '#';\nconst WIX_PROTOCOL = 'wix:';\nconst WIX_IMAGE = 'image';\n\nfunction getScaledToFillImageUrl(\n wixMediaIdentifier: string,\n targetWidth: number,\n targetHeight: number,\n options: ImageTransformOptions,\n) {\n const img = getImageUrl(wixMediaIdentifier);\n\n return sdk.getScaleToFillImageURL(\n img.id,\n img.height,\n img.width,\n targetWidth,\n targetHeight,\n options,\n );\n}\n\nfunction getScaledToFitImageUrl(\n wixMediaIdentifier: string,\n targetWidth: number,\n targetHeight: number,\n options: ImageTransformOptions,\n) {\n const img = getImageUrl(wixMediaIdentifier);\n\n return sdk.getScaleToFitImageURL(\n img.id,\n img.height,\n img.width,\n targetWidth,\n targetHeight,\n options,\n );\n}\n\nfunction getCroppedImageUrl(\n wixMediaIdentifier: string,\n cropX: number,\n cropY: number,\n cropWidth: number,\n cropHeight: number,\n targetWidth: number,\n targetHeight: number,\n options?: ImageTransformOptions,\n) {\n const img = getImageUrl(wixMediaIdentifier);\n\n return sdk.getCropImageURL(\n img.id,\n img.height,\n img.width,\n cropX,\n cropY,\n cropWidth,\n cropHeight,\n targetWidth,\n targetHeight,\n options,\n );\n}\n\nfunction getImageUrl(val: string) {\n const alignedImage = alignIfLegacy(val, WIX_IMAGE);\n\n const { hash, pathname } = new URL(alignedImage);\n\n const { originHeight: height, originWidth: width } = parse(\n hash.replace(URL_HASH_PREFIX, ''),\n );\n const [id, filenameOrAltText] = pathname\n .replace(`${WIX_IMAGE}://v1/`, '')\n .split('/');\n\n const decodedFilenameOrAltText = decodeText(filenameOrAltText);\n\n const res = {\n id,\n url: `https://static.wixstatic.com/media/${id}`,\n height: Number(height),\n width: Number(width),\n };\n\n if (!decodedFilenameOrAltText) {\n return res;\n }\n\n return {\n ...res,\n altText: decodedFilenameOrAltText,\n filename: decodedFilenameOrAltText,\n };\n}\n\nexport function decodeText(s: string) {\n if (!s) {\n return s;\n }\n\n return decodeURIComponent(s);\n}\n\nfunction alignIfLegacy(url: string, type: string): string {\n const { protocol } = new URL(url);\n\n return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;\n}\n\nexport const media = {\n getCroppedImageUrl,\n getScaledToFillImageUrl,\n getScaledToFitImageUrl,\n getImageUrl,\n};\n"],"mappings":";;;;;AAAA;AACA;AAEA,MAAMA,eAAe,GAAG,GAAG;AAC3B,MAAMC,YAAY,GAAG,MAAM;AAC3B,MAAMC,SAAS,GAAG,OAAO;AAEzB,SAASC,uBAAuB,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Tq9nwvKH_ghbSBHfiD4M';
|
|
3
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["VALID_TOKEN","EXPIRED_TOKEN"],"sources":["../../../../src/__tests__/fixtures/constants.ts"],"sourcesContent":["export const VALID_TOKEN =\n 'OauthNG.JWS.eyJraWQiOiJWUWswU3lxbyIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1widG9rZW5JZFwiOlwiMzU5NGU1ZTUtZTk1Yy00MTk0LWFmYzItNmY2ZGFkNWM2NWIxXCIsXCJjbGllbnRJZFwiOlwiNjczMDc3M2QtZTU0Ny00YmViLWFiODktNmM0ODAxNjZjMjlkXCIsXCJzY29wZXNcIjpudWxsLFwic3ViamVjdFwiOntcIkBjbGFzc1wiOlwiY29tLndpeHByZXNzLmlkZW50aXR5Lm9hdXRoMi52MS5kb21haW4uT2F1dGhEb21haW4kVmlzaXRvclwiLFwiaWRcIjpcImVlMWMyMmQ0LTRlYzYtNDNjMS05ZjQ4LTVhNDM2ODM5NDdkZVwiLFwibXNpZFwiOlwiNzNjYTBiYmItOGZiYi00N2Y5LTg3MjQtODIyNjczZWM4MjE2XCJ9fSIsImlhdCI6MTY3NDAyNTc0MywiZXhwIjoyNjc0MDI2MTAzfQ.GxviE1J4jd9p-WYK__w9DqH8zFAyAKv5OwB6Ccy9vcE';\n\nexport const EXPIRED_TOKEN =\n 'OauthNG.JWS.eyJraWQiOiJWUWswU3lxbyIsImFsZyI6IkhTMjU2In0.eyJkYXRhIjoie1widG9rZW5JZFwiOlwiMzU5NGU1ZTUtZTk1Yy00MTk0LWFmYzItNmY2ZGFkNWM2NWIxXCIsXCJjbGllbnRJZFwiOlwiNjczMDc3M2QtZTU0Ny00YmViLWFiODktNmM0ODAxNjZjMjlkXCIsXCJzY29wZXNcIjpudWxsLFwic3ViamVjdFwiOntcIkBjbGFzc1wiOlwiY29tLndpeHByZXNzLmlkZW50aXR5Lm9hdXRoMi52MS5kb21haW4uT2F1dGhEb21haW4kVmlzaXRvclwiLFwiaWRcIjpcImVlMWMyMmQ0LTRlYzYtNDNjMS05ZjQ4LTVhNDM2ODM5NDdkZVwiLFwibXNpZFwiOlwiNzNjYTBiYmItOGZiYi00N2Y5LTg3MjQtODIyNjczZWM4MjE2XCJ9fSIsImlhdCI6MTY3NDAyNTc0MywiZXhwIjoxNjc0MDI2MTAzfQ.cmmc2eZLpPM40KAXYKR49DkTq9nwvKH_ghbSBHfiD4M';\n"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GACtB,gkBAAgkB;AAElkB,OAAO,MAAMC,aAAa,GACxB,gkBAAgkB"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { createClient } from '../wixClient';
|
|
2
|
-
import { oauth } from '@wix/identity';
|
|
3
|
-
export function OAuthStrategy(config) {
|
|
4
|
-
const wixClient = createClient({
|
|
5
|
-
modules: {
|
|
6
|
-
oauth
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
const _tokens = {
|
|
10
|
-
accessToken: '',
|
|
11
|
-
refreshToken: ''
|
|
12
|
-
};
|
|
13
|
-
const generateVisitorTokens = async tokens => {
|
|
14
|
-
if (tokens != null && tokens.accessToken && tokens != null && tokens.refreshToken && !isTokenExpired(tokens.accessToken)) {
|
|
15
|
-
return Promise.resolve(tokens);
|
|
16
|
-
}
|
|
17
|
-
if (tokens != null && tokens.refreshToken) {
|
|
18
|
-
return renewToken(tokens.refreshToken);
|
|
19
|
-
}
|
|
20
|
-
const tokensResponse = await wixClient.oauth.token({
|
|
21
|
-
preAuthenticated: {
|
|
22
|
-
clientId: config.clientId
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
accessToken: tokensResponse.accessToken.token,
|
|
27
|
-
refreshToken: tokensResponse.refreshToken.token
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const renewToken = async refreshToken => {
|
|
31
|
-
const tokensResponse = await wixClient.oauth.token({
|
|
32
|
-
refreshToken: {
|
|
33
|
-
token: refreshToken
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
accessToken: tokensResponse.accessToken.token,
|
|
38
|
-
refreshToken
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
generateVisitorTokens,
|
|
43
|
-
renewToken,
|
|
44
|
-
isTokenExpired,
|
|
45
|
-
getAuthHeaders: async () => {
|
|
46
|
-
if (!_tokens.accessToken || isTokenExpired(_tokens.accessToken)) {
|
|
47
|
-
const tokens = await generateVisitorTokens(_tokens);
|
|
48
|
-
_tokens.accessToken = tokens.accessToken;
|
|
49
|
-
_tokens.refreshToken = tokens.refreshToken;
|
|
50
|
-
}
|
|
51
|
-
return Promise.resolve({
|
|
52
|
-
headers: {
|
|
53
|
-
Authorization: _tokens.accessToken
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
setTokens: tokens => {
|
|
58
|
-
_tokens.accessToken = tokens.accessToken;
|
|
59
|
-
_tokens.refreshToken = tokens.refreshToken;
|
|
60
|
-
},
|
|
61
|
-
getTokens: () => _tokens
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function parseJWT(token) {
|
|
65
|
-
const base64Url = token.split('.')[3];
|
|
66
|
-
if (typeof window !== 'undefined') {
|
|
67
|
-
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
68
|
-
const jsonPayload = decodeURIComponent(window.atob(base64).split('').map(c => {
|
|
69
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
70
|
-
}).join(''));
|
|
71
|
-
return JSON.parse(jsonPayload);
|
|
72
|
-
} else {
|
|
73
|
-
return JSON.parse(Buffer.from(base64Url, 'base64').toString());
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function isTokenExpired(token) {
|
|
77
|
-
const {
|
|
78
|
-
exp
|
|
79
|
-
} = parseJWT(token);
|
|
80
|
-
if (exp) {
|
|
81
|
-
const currentDate = Math.floor(Date.now() / 1000);
|
|
82
|
-
return exp < currentDate;
|
|
83
|
-
}
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=OAuthStrategy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createClient","oauth","OAuthStrategy","config","wixClient","modules","_tokens","accessToken","refreshToken","generateVisitorTokens","tokens","isTokenExpired","Promise","resolve","renewToken","tokensResponse","token","preAuthenticated","clientId","getAuthHeaders","headers","Authorization","setTokens","getTokens","parseJWT","base64Url","split","window","base64","replace","jsonPayload","decodeURIComponent","atob","map","c","charCodeAt","toString","slice","join","JSON","parse","Buffer","from","exp","currentDate","Math","floor","Date","now"],"sources":["../../../src/auth/OAuthStrategy.ts"],"sourcesContent":["import { createClient } from '../wixClient';\nimport { oauth } from '@wix/identity';\n\nexport interface Tokens {\n accessToken: string;\n refreshToken: string;\n}\n\nexport interface IOAuthStrategy extends AuthenticationStrategy {\n generateVisitorTokens(tokens?: {\n refreshToken?: string;\n accessToken?: string;\n }): Promise<Tokens>;\n renewToken: (refreshToken: string) => Promise<Tokens>;\n isTokenExpired: (accessToken: string) => boolean;\n setTokens: (tokens: Tokens) => void;\n getTokens: () => Tokens;\n}\n\nexport function OAuthStrategy(config: { clientId: string }): IOAuthStrategy {\n const wixClient = createClient({ modules: { oauth } });\n const _tokens: Tokens = { accessToken: '', refreshToken: '' };\n\n const generateVisitorTokens = async (\n tokens?: Partial<Tokens>,\n ): Promise<Tokens> => {\n if (\n tokens?.accessToken &&\n tokens?.refreshToken &&\n !isTokenExpired(tokens.accessToken)\n ) {\n return Promise.resolve(tokens) as Promise<Tokens>;\n }\n\n if (tokens?.refreshToken) {\n return renewToken(tokens.refreshToken);\n }\n\n const tokensResponse = await wixClient.oauth.token({\n preAuthenticated: {\n clientId: config.clientId,\n },\n });\n\n return {\n accessToken: tokensResponse.accessToken!.token!,\n refreshToken: tokensResponse.refreshToken!.token!,\n };\n };\n\n const renewToken = async (refreshToken: string): Promise<Tokens> => {\n const tokensResponse = await wixClient.oauth.token({\n refreshToken: { token: refreshToken },\n });\n return {\n accessToken: tokensResponse.accessToken!.token!,\n refreshToken,\n };\n };\n\n return {\n generateVisitorTokens,\n renewToken,\n isTokenExpired,\n getAuthHeaders: async () => {\n if (!_tokens.accessToken || isTokenExpired(_tokens.accessToken)) {\n const tokens = await generateVisitorTokens(_tokens);\n _tokens.accessToken = tokens.accessToken;\n _tokens.refreshToken = tokens.refreshToken;\n }\n return Promise.resolve({\n headers: { Authorization: _tokens.accessToken },\n });\n },\n setTokens: (tokens: Tokens): void => {\n _tokens.accessToken = tokens.accessToken;\n _tokens.refreshToken = tokens.refreshToken;\n },\n getTokens: () => _tokens,\n };\n}\n\nfunction parseJWT(token: string) {\n const base64Url = token.split('.')[3];\n if (typeof window !== 'undefined') {\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n window\n .atob(base64)\n .split('')\n .map((c) => {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join(''),\n );\n\n return JSON.parse(jsonPayload);\n } else {\n return JSON.parse(Buffer.from(base64Url, 'base64').toString());\n }\n}\n\nfunction isTokenExpired(token: string): boolean {\n const { exp } = parseJWT(token);\n if (exp) {\n const currentDate = Math.floor(Date.now() / 1000);\n return exp < currentDate;\n }\n return true;\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,cAAc;AAC3C,SAASC,KAAK,QAAQ,eAAe;AAkBrC,OAAO,SAASC,aAAa,CAACC,MAA4B,EAAkB;EAC1E,MAAMC,SAAS,GAAGJ,YAAY,CAAC;IAAEK,OAAO,EAAE;MAAEJ;IAAM;EAAE,CAAC,CAAC;EACtD,MAAMK,OAAe,GAAG;IAAEC,WAAW,EAAE,EAAE;IAAEC,YAAY,EAAE;EAAG,CAAC;EAE7D,MAAMC,qBAAqB,GAAG,MAC5BC,MAAwB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GAAGC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,GAAG,EAAE,GAAG,IAAI,CAAC;IACjD,OAAOL,GAAG,GAAGC,WAAW;EAC1B;EACA,OAAO,IAAI;AACb"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/auth/strategy.ts"],"sourcesContent":["type AuthenticationStrategy = {\n getAuthHeaders: () => Promise<{ headers: Record<string, string> }>;\n};\n"],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/external-types.d.ts"],"sourcesContent":["/// <reference types=\"@wix/yoshi-flow-library/types\" />\n"],"mappings":"AAAA"}
|
package/dist/esm/index.js
DELETED
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["export * from './wixClient';\nexport * from './wixMedia';\nexport * from './auth/OAuthStrategy';\n"],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,YAAY;AAC1B,cAAc,sBAAsB"}
|
package/dist/esm/test-types.d.js
DELETED