@wix/sdk 1.1.15 → 1.1.17
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/dist/cjs/auth/OAuthStrategy.js +78 -0
- package/dist/cjs/auth/OAuthStrategy.js.map +1 -0
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/wixClient.js +20 -31
- package/dist/cjs/wixClient.js.map +1 -1
- package/dist/cjs/wixMedia.js +25 -41
- package/dist/cjs/wixMedia.js.map +1 -1
- package/dist/esm/auth/OAuthStrategy.js +74 -0
- package/dist/esm/auth/OAuthStrategy.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/wixClient.js +38 -49
- package/dist/esm/wixClient.js.map +1 -1
- package/dist/esm/wixMedia.js +26 -40
- package/dist/esm/wixMedia.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/auth/OAuthStrategy.d.ts +18 -0
- package/dist/types/auth/OAuthStrategy.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/wixClient.d.ts +7 -5
- package/dist/types/wixClient.d.ts.map +1 -1
- package/dist/types/wixMedia.d.ts +8 -8
- package/dist/types/wixMedia.d.ts.map +1 -1
- package/package.json +11 -10
package/dist/esm/wixClient.js
CHANGED
|
@@ -1,93 +1,81 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
const API_URL = 'www.wixapis.com';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const wrapperBuilder = (origFunc, headers
|
|
3
|
+
// @ts-expect-error
|
|
5
4
|
) => {
|
|
6
5
|
return origFunc({
|
|
7
6
|
request: async factory => {
|
|
8
|
-
if (!headers.Authorization) {
|
|
9
|
-
// eslint-disable-next-line no-throw-literal
|
|
10
|
-
throw errorBuilder(500, 'You must set Authorization header before triggering a call');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
const requestOptions = factory({
|
|
14
8
|
host: API_URL
|
|
15
9
|
});
|
|
16
|
-
|
|
10
|
+
let url = "https://" + API_URL + requestOptions.url;
|
|
11
|
+
if (requestOptions.params) {
|
|
12
|
+
url += "?" + new URLSearchParams(requestOptions.params);
|
|
13
|
+
}
|
|
17
14
|
try {
|
|
18
|
-
const res = await fetch(
|
|
19
|
-
method: requestOptions.method
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
headers:
|
|
24
|
-
'Content-Type': 'application/json'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
const res = await fetch(url, {
|
|
16
|
+
method: requestOptions.method,
|
|
17
|
+
...(requestOptions.data && {
|
|
18
|
+
body: JSON.stringify(requestOptions.data)
|
|
19
|
+
}),
|
|
20
|
+
headers: {
|
|
21
|
+
'Content-Type': 'application/json',
|
|
22
|
+
...headers
|
|
23
|
+
}
|
|
24
|
+
});
|
|
28
25
|
if (res.status !== 200) {
|
|
29
26
|
var _dataError, _dataError2;
|
|
30
|
-
|
|
31
27
|
let dataError = null;
|
|
32
|
-
|
|
33
28
|
try {
|
|
34
29
|
dataError = await res.json();
|
|
35
|
-
} catch (e) {
|
|
30
|
+
} catch (e) {
|
|
31
|
+
//
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
throw errorBuilder(res.status, (_dataError = dataError) == null ? void 0 : _dataError.message, (_dataError2 = dataError) == null ? void 0 : _dataError2.details);
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
const data = await res.json();
|
|
42
36
|
return {
|
|
43
37
|
data
|
|
44
38
|
};
|
|
45
39
|
} catch (e) {
|
|
46
40
|
var _e$message;
|
|
47
|
-
|
|
48
41
|
if ((_e$message = e.message) != null && _e$message.includes('fetch is not defined')) {
|
|
49
42
|
console.error('Node.js v18+ is required');
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
throw e;
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
47
|
});
|
|
56
48
|
};
|
|
57
|
-
|
|
58
49
|
const errorBuilder = (code, description, details) => {
|
|
59
50
|
return {
|
|
60
51
|
response: {
|
|
61
52
|
data: {
|
|
62
|
-
details:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
details: {
|
|
54
|
+
...details,
|
|
55
|
+
...(!(details != null && details.validationError) && {
|
|
56
|
+
applicationError: {
|
|
57
|
+
description,
|
|
58
|
+
code
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
},
|
|
68
62
|
message: description
|
|
69
63
|
},
|
|
70
64
|
status: code
|
|
71
65
|
}
|
|
72
66
|
};
|
|
73
67
|
};
|
|
74
|
-
|
|
75
68
|
export function createClient(config) {
|
|
76
69
|
if (!config.modules || Object.entries(config.modules).length < 1) {
|
|
77
70
|
throw new Error('Missing modules');
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
const _headers = config.headers || {
|
|
81
73
|
Authorization: ''
|
|
82
74
|
};
|
|
83
|
-
|
|
84
75
|
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
|
85
|
-
|
|
86
76
|
const traverse = obj => {
|
|
87
77
|
return Object.entries(obj).reduce((prev, _ref) => {
|
|
88
|
-
let key = _ref
|
|
89
|
-
value = _ref[1];
|
|
90
|
-
|
|
78
|
+
let [key, value] = _ref;
|
|
91
79
|
if (isObject(value)) {
|
|
92
80
|
prev[key] = traverse(value);
|
|
93
81
|
} else if (typeof obj[key] === 'function') {
|
|
@@ -95,18 +83,19 @@ export function createClient(config) {
|
|
|
95
83
|
} else {
|
|
96
84
|
prev[key] = value;
|
|
97
85
|
}
|
|
98
|
-
|
|
99
86
|
return prev;
|
|
100
87
|
}, {});
|
|
101
88
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
setHeaders: headers => {
|
|
106
|
-
for (const k in headers) {
|
|
107
|
-
_headers[k] = headers[k];
|
|
108
|
-
}
|
|
89
|
+
const setHeaders = headers => {
|
|
90
|
+
for (const k in headers) {
|
|
91
|
+
_headers[k] = headers[k];
|
|
109
92
|
}
|
|
110
|
-
}
|
|
93
|
+
};
|
|
94
|
+
const wrappedModules = traverse(config.modules);
|
|
95
|
+
return {
|
|
96
|
+
...wrappedModules,
|
|
97
|
+
auth: config.auth == null ? void 0 : config.auth(setHeaders),
|
|
98
|
+
setHeaders
|
|
99
|
+
};
|
|
111
100
|
}
|
|
112
101
|
//# sourceMappingURL=wixClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["API_URL","wrapperBuilder","origFunc","headers","request","factory","
|
|
1
|
+
{"version":3,"names":["API_URL","wrapperBuilder","origFunc","headers","request","factory","requestOptions","host","url","params","URLSearchParams","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","Object","entries","length","Error","_headers","Authorization","isObject","val","Array","isArray","traverse","obj","reduce","prev","key","value","setHeaders","k","wrappedModules","auth"],"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 (...args: any) => any> {\n setHeaders(headers: Headers): void;\n auth: ReturnType<Z>;\n}\n\nconst API_URL = 'www.wixapis.com';\n\nconst wrapperBuilder = <T extends Function>(\n origFunc: T,\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) {\n url += `?${new URLSearchParams(requestOptions.params)}`;\n }\n try {\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 },\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 (...args: any) => any = 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 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, _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: config.auth?.(setHeaders),\n setHeaders,\n };\n}\n"],"mappings":"AAeA,MAAMA,OAAO,GAAG,iBAAiB;AAEjC,MAAMC,cAAc,GAAG,CACrBC,QAAW,EACXC;AACA;AAAA,KACkB;EAClB,OAAOD,QAAQ,CAAC;IACdE,OAAO,EAAE,MAAOC,OAAY,IAAK;MAC/B,MAAMC,cAAc,GAAGD,OAAO,CAAC;QAAEE,IAAI,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AAC,EAAE,CAAC,CAAC,CAAC;EACR,CAAC;EAED,MAAMG,UAAU,GAAIjD,OAAgB,IAAK;IACvC,KAAK,MAAMkD,CAAC,IAAIlD,OAAO,EAAE;MACvBqC,QAAQ,CAACa,CAAC,CAAC,GAAGlD,OAAO,CAACkD,CAAC,CAAC;IAC1B;EACF,CAAC;EAED,MAAMC,cAAc,GAAGR,QAAQ,CAACZ,MAAM,CAACC,OAAO,CAAC;EAC/C,OAAO;IACL,GAAGmB,cAAc;IACjBC,IAAI,EAAErB,MAAM,CAACqB,IAAI,oBAAXrB,MAAM,CAACqB,IAAI,CAAGH,UAAU,CAAC;IAC/BA;EACF,CAAC;AACH"}
|
package/dist/esm/wixMedia.js
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
1
|
import { sdk } from '@wix/image-kit';
|
|
3
2
|
import { parse } from 'querystring';
|
|
4
3
|
const URL_HASH_PREFIX = '#';
|
|
5
4
|
const WIX_PROTOCOL = 'wix:';
|
|
6
5
|
const WIX_IMAGE = 'image';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const img = getRawImageUrl(wixMediaIdentifier);
|
|
6
|
+
function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
7
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
10
8
|
return sdk.getScaleToFillImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const img = getRawImageUrl(wixMediaIdentifier);
|
|
10
|
+
function getScaledToFitImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
|
|
11
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
15
12
|
return sdk.getScaleToFitImageURL(img.id, img.height, img.width, targetWidth, targetHeight, options);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const img = getRawImageUrl(wixMediaIdentifier);
|
|
14
|
+
function getCroppedImageUrl(wixMediaIdentifier, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options) {
|
|
15
|
+
const img = getImageUrl(wixMediaIdentifier);
|
|
20
16
|
return sdk.getCropImageURL(img.id, img.height, img.width, cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight, options);
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
function getRawImageUrl(val) {
|
|
18
|
+
function getImageUrl(val) {
|
|
24
19
|
const alignedImage = alignIfLegacy(val, WIX_IMAGE);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const _pathname$replace$spl = pathname.replace(WIX_IMAGE + "://v1/", '').split('/'),
|
|
35
|
-
id = _pathname$replace$spl[0],
|
|
36
|
-
filenameOrAltText = _pathname$replace$spl[1];
|
|
37
|
-
|
|
20
|
+
const {
|
|
21
|
+
hash,
|
|
22
|
+
pathname
|
|
23
|
+
} = new URL(alignedImage);
|
|
24
|
+
const {
|
|
25
|
+
originHeight: height,
|
|
26
|
+
originWidth: width
|
|
27
|
+
} = parse(hash.replace(URL_HASH_PREFIX, ''));
|
|
28
|
+
const [id, filenameOrAltText] = pathname.replace(WIX_IMAGE + "://v1/", '').split('/');
|
|
38
29
|
const decodedFilenameOrAltText = decodeText(filenameOrAltText);
|
|
39
30
|
const res = {
|
|
40
31
|
id,
|
|
@@ -42,36 +33,31 @@ function getRawImageUrl(val) {
|
|
|
42
33
|
height: Number(height),
|
|
43
34
|
width: Number(width)
|
|
44
35
|
};
|
|
45
|
-
|
|
46
36
|
if (!decodedFilenameOrAltText) {
|
|
47
37
|
return res;
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
return {
|
|
40
|
+
...res,
|
|
51
41
|
altText: decodedFilenameOrAltText,
|
|
52
42
|
filename: decodedFilenameOrAltText
|
|
53
|
-
}
|
|
43
|
+
};
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
export function decodeText(s) {
|
|
57
46
|
if (!s) {
|
|
58
47
|
return s;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
return decodeURIComponent(s);
|
|
62
50
|
}
|
|
63
|
-
|
|
64
51
|
function alignIfLegacy(url, type) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
const {
|
|
53
|
+
protocol
|
|
54
|
+
} = new URL(url);
|
|
68
55
|
return protocol === type + ":" ? "" + WIX_PROTOCOL + url : url;
|
|
69
56
|
}
|
|
70
|
-
|
|
71
57
|
export const media = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
getCroppedImageUrl,
|
|
59
|
+
getScaledToFillImageUrl,
|
|
60
|
+
getScaledToFitImageUrl,
|
|
61
|
+
getImageUrl
|
|
76
62
|
};
|
|
77
63
|
//# sourceMappingURL=wixMedia.js.map
|
package/dist/esm/wixMedia.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sdk","parse","URL_HASH_PREFIX","WIX_PROTOCOL","WIX_IMAGE","
|
|
1
|
+
{"version":3,"names":["sdk","parse","URL_HASH_PREFIX","WIX_PROTOCOL","WIX_IMAGE","getScaledToFillImageUrl","wixMediaIdentifier","targetWidth","targetHeight","options","img","getImageUrl","getScaleToFillImageURL","id","height","width","getScaledToFitImageUrl","getScaleToFitImageURL","getCroppedImageUrl","cropX","cropY","cropWidth","cropHeight","getCropImageURL","val","alignedImage","alignIfLegacy","hash","pathname","URL","originHeight","originWidth","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,SAASA,GAAG,QAA+B,gBAAgB;AAC3D,SAASC,KAAK,QAAQ,aAAa;AAEnC,MAAMC,eAAe,GAAG,GAAG;AAC3B,MAAMC,YAAY,GAAG,MAAM;AAC3B,MAAMC,SAAS,GAAG,OAAO;AAEzB,SAASC,uBAAuB,CAC9BC,kBAA0B,EAC1BC,WAAmB,EACnBC,YAAoB,EACpBC,OAA8B,EAC9B;EACA,MAAMC,GAAG,GAAGC,WAAW,CAACL,kBAAkB,CAAC;EAE3C,OAAON,GAAG,CAACY,sBAAsB,CAC/BF,GAAG,CAACG,EAAE,EACNH,GAAG,CAACI,MAAM,EACVJ,GAAG,CAACK,KAAK,EACTR,WAAW,EACXC,YAAY,EACZC,OAAO,CACR;AACH;AAEA,SAASO,sBAAsB,CAC7BV,kBAA0B,EAC1BC,WAAmB,EACnBC,YAAoB,EACpBC,OAA8B,EAC9B;EACA,MAAMC,GAAG,GAAGC,WAAW,CAACL,kBAAkB,CAAC;EAE3C,OAAON,GAAG,CAACiB,qBAAqB,CAC9BP,GAAG,CAACG,EAAE,EACNH,GAAG,CAACI,MAAM,EACVJ,GAAG,CAACK,KAAK,EACTR,WAAW,EACXC,YAAY,EACZC,OAAO,CACR;AACH;AAEA,SAASS,kBAAkB,CACzBZ,kBAA0B,EAC1Ba,KAAa,EACbC,KAAa,EACbC,SAAiB,EACjBC,UAAkB,EAClBf,WAAmB,EACnBC,YAAoB,EACpBC,OAA+B,EAC/B;EACA,MAAMC,GAAG,GAAGC,WAAW,CAACL,kBAAkB,CAAC;EAE3C,OAAON,GAAG,CAACuB,eAAe,CACxBb,GAAG,CAACG,EAAE,EACNH,GAAG,CAACI,MAAM,EACVJ,GAAG,CAACK,KAAK,EACTI,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,UAAU,EACVf,WAAW,EACXC,YAAY,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