@wix/sdk 1.5.7 → 1.5.9

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.
@@ -23,7 +23,7 @@ var parseMethod = (method) => {
23
23
  case "OPTIONS":
24
24
  return "OPTIONS";
25
25
  default:
26
- throw new Error(`Unknown method: ${method}`);
26
+ throw new Error("Unknown method: ".concat(method));
27
27
  }
28
28
  };
29
29
  var toHTTPModule = (factory) => (httpClient) => async (payload) => {
@@ -69,6 +69,13 @@ var toHTTPModule = (factory) => (httpClient) => async (payload) => {
69
69
  var ambassadorModuleOptions = () => ({
70
70
  HTTPHost: self.location.host
71
71
  });
72
+ var isAmbassadorModule = (module) => {
73
+ if (module.__isAmbassador) {
74
+ return true;
75
+ }
76
+ const fn = module();
77
+ return Boolean(fn.__isAmbassador);
78
+ };
72
79
 
73
80
  // src/common.ts
74
81
  var PUBLIC_METADATA_KEY = "__metadata";
@@ -105,7 +112,7 @@ function biHeaderGenerator(apiMetadata, publicMetadata) {
105
112
  };
106
113
  }
107
114
  function objectToKeyValue(input) {
108
- return Object.entries(input).filter(([_, value]) => Boolean(value)).map(([key, value]) => `${key}=${value}`).join(",");
115
+ return Object.entries(input).filter(([_, value]) => Boolean(value)).map(([key, value]) => "".concat(key, "=").concat(value)).join(",");
109
116
  }
110
117
 
111
118
  // src/rest-modules.ts
@@ -120,9 +127,9 @@ function buildRESTDescriptor(origFunc, publicMetadata, boundFetch, options) {
120
127
  request = requestOptions.fallback[0];
121
128
  }
122
129
  const domain = (_b = options == null ? void 0 : options.HTTPHost) != null ? _b : getDefaultDomain(request.method, request.url);
123
- let url = `https://${domain}${request.url}`;
130
+ let url = "https://".concat(domain).concat(request.url);
124
131
  if (request.params && request.params.toString()) {
125
- url += `?${request.params.toString()}`;
132
+ url += "?".concat(request.params.toString());
126
133
  }
127
134
  try {
128
135
  const biHeader = biHeaderGenerator(requestOptions, publicMetadata);
@@ -252,7 +259,7 @@ function createClient(config) {
252
259
  if (isHostModule(modules) && config.host) {
253
260
  return buildHostModule(modules, config.host);
254
261
  } else if (typeof modules === "function") {
255
- const { module, options } = modules.__isAmbassador ? {
262
+ const { module, options } = isAmbassadorModule(modules) ? {
256
263
  module: toHTTPModule(modules),
257
264
  options: ambassadorModuleOptions()
258
265
  } : { module: modules, options: void 0 };
@@ -286,7 +293,7 @@ function createClient(config) {
286
293
  setHeaders,
287
294
  use,
288
295
  fetch: (relativeUrl, options) => {
289
- const finalUrl = new URL(relativeUrl, `https://${API_URL}`);
296
+ const finalUrl = new URL(relativeUrl, "https://".concat(API_URL));
290
297
  finalUrl.host = API_URL;
291
298
  finalUrl.protocol = "https";
292
299
  return boundFetch(finalUrl.toString(), options);
@@ -295,7 +302,7 @@ function createClient(config) {
295
302
  apiVersion: "alpha"
296
303
  }) {
297
304
  const res = await boundFetch(
298
- `https://${API_URL}/graphql/${opts.apiVersion}`,
305
+ "https://".concat(API_URL, "/graphql/").concat(opts.apiVersion),
299
306
  {
300
307
  method: "POST",
301
308
  headers: {
@@ -306,7 +313,7 @@ function createClient(config) {
306
313
  );
307
314
  if (res.status !== 200) {
308
315
  throw new FetchErrorResponse(
309
- `GraphQL request failed with status ${res.status}`,
316
+ "GraphQL request failed with status ".concat(res.status),
310
317
  res
311
318
  );
312
319
  }
@@ -322,7 +329,13 @@ import { parse } from "querystring";
322
329
  var URL_HASH_PREFIX = "#";
323
330
  var WIX_PROTOCOL = "wix:";
324
331
  var WIX_IMAGE = "image";
332
+ var WIX_VIDEO = "video";
333
+ var WIX_AUDIO = "audio";
334
+ var WIX_DOCUMENT = "document";
325
335
  var WIX_IMAGE_URL = "https://static.wixstatic.com/media/";
336
+ var WIX_VIDEO_URL = "https://video.wixstatic.com/video/";
337
+ var WIX_AUDIO_URL = "https://static.wixstatic.com/mp3/";
338
+ var WIX_DOCUMENT_URL = "https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/";
326
339
  function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
327
340
  const img = getImageUrl(wixMediaIdentifier);
328
341
  return sdk.getScaleToFillImageURL(
@@ -373,12 +386,12 @@ function getImageUrl(val) {
373
386
  ({ originHeight: height, originWidth: width } = parse(
374
387
  hash.replace(URL_HASH_PREFIX, "")
375
388
  ));
376
- [id, filenameOrAltText] = pathname.replace(`${WIX_IMAGE}://v1/`, "").split("/");
389
+ [id, filenameOrAltText] = pathname.replace("".concat(WIX_IMAGE, "://v1/"), "").split("/");
377
390
  }
378
391
  const decodedFilenameOrAltText = decodeText(filenameOrAltText);
379
392
  const res = {
380
393
  id,
381
- url: `${WIX_IMAGE_URL}${id}`,
394
+ url: "".concat(WIX_IMAGE_URL).concat(id),
382
395
  height: Number(height),
383
396
  width: Number(width)
384
397
  };
@@ -391,6 +404,74 @@ function getImageUrl(val) {
391
404
  filename: decodedFilenameOrAltText
392
405
  };
393
406
  }
407
+ function getVideoUrl(val, resolution) {
408
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = "";
409
+ if (val.startsWith(WIX_VIDEO_URL)) {
410
+ id = val.split(WIX_VIDEO_URL).pop().split("/")[0];
411
+ thumbnailId = "".concat(id, ".jpg");
412
+ thumbnailWidth = "50";
413
+ thumbnailHeight = "50";
414
+ } else {
415
+ const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
416
+ const { pathname, hash } = new URL(alignedVideo);
417
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
418
+ const [_id, fileName] = pathname.replace("".concat(WIX_VIDEO, "://v1/"), "").split("/");
419
+ id = _id;
420
+ thumbnailId = hashParams.get("posterUri") || "".concat(id, ".jpg");
421
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
422
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
423
+ decodedFilename = decodeText(fileName);
424
+ }
425
+ const res = {
426
+ id,
427
+ url: "".concat(WIX_VIDEO_URL).concat(id, "/").concat(resolution ? "".concat(resolution, "/mp4/file.mp4") : "file"),
428
+ thumbnail: "".concat(WIX_PROTOCOL).concat(WIX_IMAGE, "://v1/").concat(thumbnailId, "#originWidth=").concat(thumbnailWidth, "&originHeight=").concat(thumbnailHeight)
429
+ };
430
+ if (!decodedFilename) {
431
+ return res;
432
+ }
433
+ return {
434
+ ...res,
435
+ filename: decodedFilename
436
+ };
437
+ }
438
+ function getAudioUrl(val) {
439
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
440
+ const { pathname, hash } = new URL(alignedAudio);
441
+ const [id, filename] = pathname.replace("".concat(WIX_AUDIO, "://v1/"), "").split("/");
442
+ const decodedFilename = decodeText(filename);
443
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
444
+ const res = {
445
+ id,
446
+ duration: Number(hashParams.get("duration") || ""),
447
+ url: "".concat(WIX_AUDIO_URL).concat(id)
448
+ };
449
+ if (!decodedFilename) {
450
+ return res;
451
+ }
452
+ return {
453
+ ...res,
454
+ filename: decodedFilename
455
+ };
456
+ }
457
+ function getDocumentUrl(val) {
458
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
459
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
460
+ const { pathname } = new URL(alignedDocument);
461
+ const [id, filename] = pathname.replace("".concat(WIX_DOCUMENT, "://v1/"), "").split("/");
462
+ const decodedFilename = decodeText(filename);
463
+ const res = {
464
+ id,
465
+ url: "".concat(WIX_DOCUMENT_URL).concat(id)
466
+ };
467
+ if (!decodedFilename) {
468
+ return res;
469
+ }
470
+ return {
471
+ ...res,
472
+ filename: decodedFilename
473
+ };
474
+ }
394
475
  function decodeText(s) {
395
476
  if (!s) {
396
477
  return s;
@@ -399,13 +480,23 @@ function decodeText(s) {
399
480
  }
400
481
  function alignIfLegacy(url, type) {
401
482
  const { protocol } = new URL(url);
402
- return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
483
+ return protocol === "".concat(type, ":") ? "".concat(WIX_PROTOCOL).concat(url) : url;
403
484
  }
485
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
486
+ VideoResolution2["MOBILE"] = "360p";
487
+ VideoResolution2["LOW"] = "480p";
488
+ VideoResolution2["MID"] = "720p";
489
+ VideoResolution2["HIGH"] = "1080p";
490
+ return VideoResolution2;
491
+ })(VideoResolution || {});
404
492
  var media = {
405
493
  getCroppedImageUrl,
406
494
  getScaledToFillImageUrl,
407
495
  getScaledToFitImageUrl,
408
- getImageUrl
496
+ getImageUrl,
497
+ getVideoUrl,
498
+ getAudioUrl,
499
+ getDocumentUrl
409
500
  };
410
501
 
411
502
  // src/auth/oauth2/OAuthStrategy.ts
@@ -839,7 +930,7 @@ function OAuthStrategy(config) {
839
930
  };
840
931
  }
841
932
  var fetchTokens = async (payload) => {
842
- const res = await fetch(`https://${API_URL}/oauth2/token`, {
933
+ const res = await fetch("https://".concat(API_URL, "/oauth2/token"), {
843
934
  method: "POST",
844
935
  body: JSON.stringify(payload),
845
936
  headers: {
@@ -891,14 +982,14 @@ function WixAppOAuthStrategy(opts) {
891
982
  let refreshToken = opts.refreshToken;
892
983
  return {
893
984
  getInstallUrl({ redirectUrl }) {
894
- return `https://www.wix.com/installer/install?appId=${opts.appId}&redirectUrl=${redirectUrl}`;
985
+ return "https://www.wix.com/installer/install?appId=".concat(opts.appId, "&redirectUrl=").concat(redirectUrl);
895
986
  },
896
987
  async handleOAuthCallback(url, oauthOpts) {
897
988
  const params = new URLSearchParams(new URL(url).search);
898
989
  const state = params.get("state");
899
990
  if (state && (oauthOpts == null ? void 0 : oauthOpts.state) && state !== oauthOpts.state) {
900
991
  throw new Error(
901
- `Invalid OAuth callback URL. Expected state to be "${oauthOpts.state}" but got "${state}"`
992
+ 'Invalid OAuth callback URL. Expected state to be "'.concat(oauthOpts.state, '" but got "').concat(state, '"')
902
993
  );
903
994
  }
904
995
  const code = params.get("code");
@@ -922,7 +1013,7 @@ function WixAppOAuthStrategy(opts) {
922
1013
  });
923
1014
  if (tokensRes.status !== 200) {
924
1015
  throw new Error(
925
- `Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
1016
+ "Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ".concat(tokensRes.status)
926
1017
  );
927
1018
  }
928
1019
  const tokens = await tokensRes.json();
@@ -953,7 +1044,7 @@ function WixAppOAuthStrategy(opts) {
953
1044
  });
954
1045
  if (tokensRes.status !== 200) {
955
1046
  throw new Error(
956
- `Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
1047
+ "Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ".concat(tokensRes.status)
957
1048
  );
958
1049
  }
959
1050
  const tokens = await tokensRes.json();
@@ -975,6 +1066,7 @@ export {
975
1066
  LoginState,
976
1067
  OAuthStrategy,
977
1068
  TokenRole,
1069
+ VideoResolution,
978
1070
  WixAppOAuthStrategy,
979
1071
  createClient,
980
1072
  decodeText,
package/build/index.d.mts CHANGED
@@ -31,8 +31,7 @@ type AmbassadorRequestOptions<T = any> = {
31
31
  data?: any;
32
32
  transformResponse?: ResponseTransformer | ResponseTransformer[];
33
33
  };
34
- type AmbassadorFactory<Request, Response> = {
35
- (payload: Request): (context: RequestContext) => AmbassadorRequestOptions<Response>;
34
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
36
35
  __isAmbassador: boolean;
37
36
  };
38
37
  type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
@@ -150,20 +149,41 @@ declare function getImageUrl(val: string): {
150
149
  url: string;
151
150
  height: number;
152
151
  width: number;
153
- } | {
154
- altText: string;
155
- filename: string;
152
+ altText?: string;
153
+ filename?: string;
154
+ };
155
+ declare function getVideoUrl(val: string, resolution?: VideoResolution): {
156
156
  id: string;
157
157
  url: string;
158
- height: number;
159
- width: number;
158
+ thumbnail: string;
159
+ filename?: string;
160
+ };
161
+ declare function getAudioUrl(val: string): {
162
+ id: string;
163
+ url: string;
164
+ duration: number;
165
+ filename?: string;
166
+ };
167
+ declare function getDocumentUrl(val: string): {
168
+ id: string;
169
+ url: string;
170
+ filename?: string;
160
171
  };
161
172
  declare function decodeText(s: string): string;
173
+ declare enum VideoResolution {
174
+ MOBILE = "360p",
175
+ LOW = "480p",
176
+ MID = "720p",
177
+ HIGH = "1080p"
178
+ }
162
179
  declare const media: {
163
180
  getCroppedImageUrl: typeof getCroppedImageUrl;
164
181
  getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
165
182
  getScaledToFitImageUrl: typeof getScaledToFitImageUrl;
166
183
  getImageUrl: typeof getImageUrl;
184
+ getVideoUrl: typeof getVideoUrl;
185
+ getAudioUrl: typeof getAudioUrl;
186
+ getDocumentUrl: typeof getDocumentUrl;
167
187
  };
168
188
 
169
189
  interface Tokens {
@@ -366,4 +386,4 @@ declare function WixAppOAuthStrategy(opts: {
366
386
  refreshToken?: string;
367
387
  }): WixAppOAuthStrategy;
368
388
 
369
- 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, getDefaultDomain, media };
389
+ export { API_URL, type AccessToken, ApiKeyStrategy, type AssertHostMatches, type BuildDescriptors, type CalculateNextState, type Descriptors, type IApiKeyStrategy, type IOAuthStrategy, type LoginParams, LoginState, OAuthStrategy, type OauthData, type OauthPKCE, type ProcessableState, type RefreshToken, type RegisterParams, type StateMachine, type Token, type TokenResponse, TokenRole, type Tokens, VideoResolution, WixAppOAuthStrategy, type WixClient, createClient, decodeText, getDefaultDomain, media };
package/build/index.d.ts CHANGED
@@ -31,8 +31,7 @@ type AmbassadorRequestOptions<T = any> = {
31
31
  data?: any;
32
32
  transformResponse?: ResponseTransformer | ResponseTransformer[];
33
33
  };
34
- type AmbassadorFactory<Request, Response> = {
35
- (payload: Request): (context: RequestContext) => AmbassadorRequestOptions<Response>;
34
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
36
35
  __isAmbassador: boolean;
37
36
  };
38
37
  type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
@@ -150,20 +149,41 @@ declare function getImageUrl(val: string): {
150
149
  url: string;
151
150
  height: number;
152
151
  width: number;
153
- } | {
154
- altText: string;
155
- filename: string;
152
+ altText?: string;
153
+ filename?: string;
154
+ };
155
+ declare function getVideoUrl(val: string, resolution?: VideoResolution): {
156
156
  id: string;
157
157
  url: string;
158
- height: number;
159
- width: number;
158
+ thumbnail: string;
159
+ filename?: string;
160
+ };
161
+ declare function getAudioUrl(val: string): {
162
+ id: string;
163
+ url: string;
164
+ duration: number;
165
+ filename?: string;
166
+ };
167
+ declare function getDocumentUrl(val: string): {
168
+ id: string;
169
+ url: string;
170
+ filename?: string;
160
171
  };
161
172
  declare function decodeText(s: string): string;
173
+ declare enum VideoResolution {
174
+ MOBILE = "360p",
175
+ LOW = "480p",
176
+ MID = "720p",
177
+ HIGH = "1080p"
178
+ }
162
179
  declare const media: {
163
180
  getCroppedImageUrl: typeof getCroppedImageUrl;
164
181
  getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
165
182
  getScaledToFitImageUrl: typeof getScaledToFitImageUrl;
166
183
  getImageUrl: typeof getImageUrl;
184
+ getVideoUrl: typeof getVideoUrl;
185
+ getAudioUrl: typeof getAudioUrl;
186
+ getDocumentUrl: typeof getDocumentUrl;
167
187
  };
168
188
 
169
189
  interface Tokens {
@@ -366,4 +386,4 @@ declare function WixAppOAuthStrategy(opts: {
366
386
  refreshToken?: string;
367
387
  }): WixAppOAuthStrategy;
368
388
 
369
- 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, getDefaultDomain, media };
389
+ export { API_URL, type AccessToken, ApiKeyStrategy, type AssertHostMatches, type BuildDescriptors, type CalculateNextState, type Descriptors, type IApiKeyStrategy, type IOAuthStrategy, type LoginParams, LoginState, OAuthStrategy, type OauthData, type OauthPKCE, type ProcessableState, type RefreshToken, type RegisterParams, type StateMachine, type Token, type TokenResponse, TokenRole, type Tokens, VideoResolution, WixAppOAuthStrategy, type WixClient, createClient, decodeText, getDefaultDomain, media };
package/build/index.js CHANGED
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  LoginState: () => LoginState,
37
37
  OAuthStrategy: () => OAuthStrategy,
38
38
  TokenRole: () => TokenRole,
39
+ VideoResolution: () => VideoResolution,
39
40
  WixAppOAuthStrategy: () => WixAppOAuthStrategy,
40
41
  createClient: () => createClient,
41
42
  decodeText: () => decodeText,
@@ -115,6 +116,13 @@ var toHTTPModule = (factory) => (httpClient) => async (payload) => {
115
116
  var ambassadorModuleOptions = () => ({
116
117
  HTTPHost: self.location.host
117
118
  });
119
+ var isAmbassadorModule = (module2) => {
120
+ if (module2.__isAmbassador) {
121
+ return true;
122
+ }
123
+ const fn = module2();
124
+ return Boolean(fn.__isAmbassador);
125
+ };
118
126
 
119
127
  // src/common.ts
120
128
  var PUBLIC_METADATA_KEY = "__metadata";
@@ -296,7 +304,7 @@ function createClient(config) {
296
304
  if (isHostModule(modules) && config.host) {
297
305
  return buildHostModule(modules, config.host);
298
306
  } else if (typeof modules === "function") {
299
- const { module: module2, options } = modules.__isAmbassador ? {
307
+ const { module: module2, options } = isAmbassadorModule(modules) ? {
300
308
  module: toHTTPModule(modules),
301
309
  options: ambassadorModuleOptions()
302
310
  } : { module: modules, options: void 0 };
@@ -366,7 +374,13 @@ var import_querystring = require("querystring");
366
374
  var URL_HASH_PREFIX = "#";
367
375
  var WIX_PROTOCOL = "wix:";
368
376
  var WIX_IMAGE = "image";
377
+ var WIX_VIDEO = "video";
378
+ var WIX_AUDIO = "audio";
379
+ var WIX_DOCUMENT = "document";
369
380
  var WIX_IMAGE_URL = "https://static.wixstatic.com/media/";
381
+ var WIX_VIDEO_URL = "https://video.wixstatic.com/video/";
382
+ var WIX_AUDIO_URL = "https://static.wixstatic.com/mp3/";
383
+ var WIX_DOCUMENT_URL = "https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/";
370
384
  function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
371
385
  const img = getImageUrl(wixMediaIdentifier);
372
386
  return import_image_kit.sdk.getScaleToFillImageURL(
@@ -435,6 +449,74 @@ function getImageUrl(val) {
435
449
  filename: decodedFilenameOrAltText
436
450
  };
437
451
  }
452
+ function getVideoUrl(val, resolution) {
453
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = "";
454
+ if (val.startsWith(WIX_VIDEO_URL)) {
455
+ id = val.split(WIX_VIDEO_URL).pop().split("/")[0];
456
+ thumbnailId = `${id}.jpg`;
457
+ thumbnailWidth = "50";
458
+ thumbnailHeight = "50";
459
+ } else {
460
+ const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
461
+ const { pathname, hash } = new URL(alignedVideo);
462
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
463
+ const [_id, fileName] = pathname.replace(`${WIX_VIDEO}://v1/`, "").split("/");
464
+ id = _id;
465
+ thumbnailId = hashParams.get("posterUri") || `${id}.jpg`;
466
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
467
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
468
+ decodedFilename = decodeText(fileName);
469
+ }
470
+ const res = {
471
+ id,
472
+ url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : "file"}`,
473
+ thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`
474
+ };
475
+ if (!decodedFilename) {
476
+ return res;
477
+ }
478
+ return {
479
+ ...res,
480
+ filename: decodedFilename
481
+ };
482
+ }
483
+ function getAudioUrl(val) {
484
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
485
+ const { pathname, hash } = new URL(alignedAudio);
486
+ const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, "").split("/");
487
+ const decodedFilename = decodeText(filename);
488
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
489
+ const res = {
490
+ id,
491
+ duration: Number(hashParams.get("duration") || ""),
492
+ url: `${WIX_AUDIO_URL}${id}`
493
+ };
494
+ if (!decodedFilename) {
495
+ return res;
496
+ }
497
+ return {
498
+ ...res,
499
+ filename: decodedFilename
500
+ };
501
+ }
502
+ function getDocumentUrl(val) {
503
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
504
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
505
+ const { pathname } = new URL(alignedDocument);
506
+ const [id, filename] = pathname.replace(`${WIX_DOCUMENT}://v1/`, "").split("/");
507
+ const decodedFilename = decodeText(filename);
508
+ const res = {
509
+ id,
510
+ url: `${WIX_DOCUMENT_URL}${id}`
511
+ };
512
+ if (!decodedFilename) {
513
+ return res;
514
+ }
515
+ return {
516
+ ...res,
517
+ filename: decodedFilename
518
+ };
519
+ }
438
520
  function decodeText(s) {
439
521
  if (!s) {
440
522
  return s;
@@ -445,11 +527,21 @@ function alignIfLegacy(url, type) {
445
527
  const { protocol } = new URL(url);
446
528
  return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
447
529
  }
530
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
531
+ VideoResolution2["MOBILE"] = "360p";
532
+ VideoResolution2["LOW"] = "480p";
533
+ VideoResolution2["MID"] = "720p";
534
+ VideoResolution2["HIGH"] = "1080p";
535
+ return VideoResolution2;
536
+ })(VideoResolution || {});
448
537
  var media = {
449
538
  getCroppedImageUrl,
450
539
  getScaledToFillImageUrl,
451
540
  getScaledToFitImageUrl,
452
- getImageUrl
541
+ getImageUrl,
542
+ getVideoUrl,
543
+ getAudioUrl,
544
+ getDocumentUrl
453
545
  };
454
546
 
455
547
  // src/auth/oauth2/OAuthStrategy.ts
@@ -1013,6 +1105,7 @@ __reExport(src_exports, require("@wix/sdk-types"), module.exports);
1013
1105
  LoginState,
1014
1106
  OAuthStrategy,
1015
1107
  TokenRole,
1108
+ VideoResolution,
1016
1109
  WixAppOAuthStrategy,
1017
1110
  createClient,
1018
1111
  decodeText,
package/build/index.mjs CHANGED
@@ -69,6 +69,13 @@ var toHTTPModule = (factory) => (httpClient) => async (payload) => {
69
69
  var ambassadorModuleOptions = () => ({
70
70
  HTTPHost: self.location.host
71
71
  });
72
+ var isAmbassadorModule = (module) => {
73
+ if (module.__isAmbassador) {
74
+ return true;
75
+ }
76
+ const fn = module();
77
+ return Boolean(fn.__isAmbassador);
78
+ };
72
79
 
73
80
  // src/common.ts
74
81
  var PUBLIC_METADATA_KEY = "__metadata";
@@ -250,7 +257,7 @@ function createClient(config) {
250
257
  if (isHostModule(modules) && config.host) {
251
258
  return buildHostModule(modules, config.host);
252
259
  } else if (typeof modules === "function") {
253
- const { module, options } = modules.__isAmbassador ? {
260
+ const { module, options } = isAmbassadorModule(modules) ? {
254
261
  module: toHTTPModule(modules),
255
262
  options: ambassadorModuleOptions()
256
263
  } : { module: modules, options: void 0 };
@@ -320,7 +327,13 @@ import { parse } from "querystring";
320
327
  var URL_HASH_PREFIX = "#";
321
328
  var WIX_PROTOCOL = "wix:";
322
329
  var WIX_IMAGE = "image";
330
+ var WIX_VIDEO = "video";
331
+ var WIX_AUDIO = "audio";
332
+ var WIX_DOCUMENT = "document";
323
333
  var WIX_IMAGE_URL = "https://static.wixstatic.com/media/";
334
+ var WIX_VIDEO_URL = "https://video.wixstatic.com/video/";
335
+ var WIX_AUDIO_URL = "https://static.wixstatic.com/mp3/";
336
+ var WIX_DOCUMENT_URL = "https://d945e594-8657-47e2-9cd9-e9033c3d8da0.usrfiles.com/ugd/";
324
337
  function getScaledToFillImageUrl(wixMediaIdentifier, targetWidth, targetHeight, options) {
325
338
  const img = getImageUrl(wixMediaIdentifier);
326
339
  return sdk.getScaleToFillImageURL(
@@ -389,6 +402,74 @@ function getImageUrl(val) {
389
402
  filename: decodedFilenameOrAltText
390
403
  };
391
404
  }
405
+ function getVideoUrl(val, resolution) {
406
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight, decodedFilename = "";
407
+ if (val.startsWith(WIX_VIDEO_URL)) {
408
+ id = val.split(WIX_VIDEO_URL).pop().split("/")[0];
409
+ thumbnailId = `${id}.jpg`;
410
+ thumbnailWidth = "50";
411
+ thumbnailHeight = "50";
412
+ } else {
413
+ const alignedVideo = alignIfLegacy(val, WIX_VIDEO);
414
+ const { pathname, hash } = new URL(alignedVideo);
415
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
416
+ const [_id, fileName] = pathname.replace(`${WIX_VIDEO}://v1/`, "").split("/");
417
+ id = _id;
418
+ thumbnailId = hashParams.get("posterUri") || `${id}.jpg`;
419
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
420
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
421
+ decodedFilename = decodeText(fileName);
422
+ }
423
+ const res = {
424
+ id,
425
+ url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : "file"}`,
426
+ thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`
427
+ };
428
+ if (!decodedFilename) {
429
+ return res;
430
+ }
431
+ return {
432
+ ...res,
433
+ filename: decodedFilename
434
+ };
435
+ }
436
+ function getAudioUrl(val) {
437
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
438
+ const { pathname, hash } = new URL(alignedAudio);
439
+ const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, "").split("/");
440
+ const decodedFilename = decodeText(filename);
441
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
442
+ const res = {
443
+ id,
444
+ duration: Number(hashParams.get("duration") || ""),
445
+ url: `${WIX_AUDIO_URL}${id}`
446
+ };
447
+ if (!decodedFilename) {
448
+ return res;
449
+ }
450
+ return {
451
+ ...res,
452
+ filename: decodedFilename
453
+ };
454
+ }
455
+ function getDocumentUrl(val) {
456
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
457
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
458
+ const { pathname } = new URL(alignedDocument);
459
+ const [id, filename] = pathname.replace(`${WIX_DOCUMENT}://v1/`, "").split("/");
460
+ const decodedFilename = decodeText(filename);
461
+ const res = {
462
+ id,
463
+ url: `${WIX_DOCUMENT_URL}${id}`
464
+ };
465
+ if (!decodedFilename) {
466
+ return res;
467
+ }
468
+ return {
469
+ ...res,
470
+ filename: decodedFilename
471
+ };
472
+ }
392
473
  function decodeText(s) {
393
474
  if (!s) {
394
475
  return s;
@@ -399,11 +480,21 @@ function alignIfLegacy(url, type) {
399
480
  const { protocol } = new URL(url);
400
481
  return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
401
482
  }
483
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
484
+ VideoResolution2["MOBILE"] = "360p";
485
+ VideoResolution2["LOW"] = "480p";
486
+ VideoResolution2["MID"] = "720p";
487
+ VideoResolution2["HIGH"] = "1080p";
488
+ return VideoResolution2;
489
+ })(VideoResolution || {});
402
490
  var media = {
403
491
  getCroppedImageUrl,
404
492
  getScaledToFillImageUrl,
405
493
  getScaledToFitImageUrl,
406
- getImageUrl
494
+ getImageUrl,
495
+ getVideoUrl,
496
+ getAudioUrl,
497
+ getDocumentUrl
407
498
  };
408
499
 
409
500
  // src/auth/oauth2/OAuthStrategy.ts
@@ -966,6 +1057,7 @@ export {
966
1057
  LoginState,
967
1058
  OAuthStrategy,
968
1059
  TokenRole,
1060
+ VideoResolution,
969
1061
  WixAppOAuthStrategy,
970
1062
  createClient,
971
1063
  decodeText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -29,35 +29,35 @@
29
29
  "*.{js,ts}": "yarn lint"
30
30
  },
31
31
  "dependencies": {
32
- "@babel/runtime": "^7.23.2",
33
- "@wix/identity": "^1.0.62",
34
- "@wix/image-kit": "^1.40.0",
32
+ "@babel/runtime": "^7.23.5",
33
+ "@wix/identity": "^1.0.63",
34
+ "@wix/image-kit": "^1.42.0",
35
35
  "@wix/redirects": "^1.0.28",
36
- "@wix/sdk-types": "1.5.1",
36
+ "@wix/sdk-types": "^1.5.3",
37
37
  "pkce-challenge": "^3.1.0",
38
38
  "querystring": "^0.2.1",
39
- "type-fest": "^3.13.1"
39
+ "type-fest": "^4.8.3"
40
40
  },
41
41
  "optionalDependencies": {
42
42
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/is-ci": "^3.0.4",
46
- "@types/node": "^20.9.0",
47
- "@wix/ecom": "^1.0.379",
46
+ "@types/node": "^20.10.4",
47
+ "@wix/ecom": "^1.0.385",
48
48
  "@wix/events": "^1.0.127",
49
49
  "@wix/metro": "^1.0.67",
50
- "@wix/metro-runtime": "^1.1547.0",
50
+ "@wix/metro-runtime": "^1.1556.0",
51
51
  "eslint": "^7.32.0",
52
52
  "eslint-config-sdk": "0.0.0",
53
- "graphql": "16.8.0",
53
+ "graphql": "^16.8.0",
54
54
  "is-ci": "^3.0.1",
55
55
  "jsdom": "^22.1.0",
56
- "msw": "^2.0.5",
57
- "tsup": "^7.2.0",
58
- "typescript": "~4.9.5",
56
+ "msw": "^2.0.10",
57
+ "tsup": "^7.3.0",
58
+ "typescript": "^5.3.3",
59
59
  "vitest": "^0.34.6",
60
- "vitest-teamcity-reporter": "^0.2.0"
60
+ "vitest-teamcity-reporter": "^0.2.1"
61
61
  },
62
62
  "yoshiFlowLibrary": {
63
63
  "buildEsmWithBabel": true
@@ -82,5 +82,5 @@
82
82
  "wallaby": {
83
83
  "autoDetect": true
84
84
  },
85
- "falconPackageHash": "ef89c90113560669ac1e3eaddcf8cb682516f3c71c91e15d3dbf4821"
85
+ "falconPackageHash": "5ba41ba27346699ec85cbabd2fc593dd3e33823247aab3de2e26addf"
86
86
  }