@wix/sdk 1.5.7 → 1.5.8

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,65 @@ function getImageUrl(val) {
391
404
  filename: decodedFilenameOrAltText
392
405
  };
393
406
  }
407
+ function getVideoUrl(val, resolution) {
408
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight;
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
+ [id] = pathname.replace("".concat(WIX_VIDEO, "://v1/"), "").split("/");
419
+ thumbnailId = hashParams.get("posterUri") || "".concat(id, ".jpg");
420
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
421
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
422
+ }
423
+ return {
424
+ id,
425
+ url: "".concat(WIX_VIDEO_URL).concat(id, "/").concat(resolution ? "".concat(resolution, "/mp4/file.mp4") : "file"),
426
+ thumbnail: "".concat(WIX_PROTOCOL).concat(WIX_IMAGE, "://v1/").concat(thumbnailId, "#originWidth=").concat(thumbnailWidth, "&originHeight=").concat(thumbnailHeight)
427
+ };
428
+ }
429
+ function getAudioUrl(val) {
430
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
431
+ const { pathname, hash } = new URL(alignedAudio);
432
+ const [id, filename] = pathname.replace("".concat(WIX_AUDIO, "://v1/"), "").split("/");
433
+ const decodedFilename = decodeText(filename);
434
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
435
+ const res = {
436
+ id,
437
+ duration: Number(hashParams.get("duration") || ""),
438
+ url: "".concat(WIX_AUDIO_URL).concat(id)
439
+ };
440
+ if (!decodedFilename) {
441
+ return res;
442
+ }
443
+ return {
444
+ ...res,
445
+ name: decodedFilename
446
+ };
447
+ }
448
+ function getDocumentUrl(val) {
449
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
450
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
451
+ const { pathname } = new URL(alignedDocument);
452
+ const [id, filename] = pathname.replace("".concat(WIX_DOCUMENT, "://v1/"), "").split("/");
453
+ const decodedFilename = decodeText(filename);
454
+ const res = {
455
+ id,
456
+ url: "".concat(WIX_DOCUMENT_URL).concat(id)
457
+ };
458
+ if (!decodedFilename) {
459
+ return res;
460
+ }
461
+ return {
462
+ ...res,
463
+ name: decodedFilename
464
+ };
465
+ }
394
466
  function decodeText(s) {
395
467
  if (!s) {
396
468
  return s;
@@ -399,13 +471,23 @@ function decodeText(s) {
399
471
  }
400
472
  function alignIfLegacy(url, type) {
401
473
  const { protocol } = new URL(url);
402
- return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
474
+ return protocol === "".concat(type, ":") ? "".concat(WIX_PROTOCOL).concat(url) : url;
403
475
  }
476
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
477
+ VideoResolution2["MOBILE"] = "360p";
478
+ VideoResolution2["LOW"] = "480p";
479
+ VideoResolution2["MID"] = "720p";
480
+ VideoResolution2["HIGH"] = "1080p";
481
+ return VideoResolution2;
482
+ })(VideoResolution || {});
404
483
  var media = {
405
484
  getCroppedImageUrl,
406
485
  getScaledToFillImageUrl,
407
486
  getScaledToFitImageUrl,
408
- getImageUrl
487
+ getImageUrl,
488
+ getVideoUrl,
489
+ getAudioUrl,
490
+ getDocumentUrl
409
491
  };
410
492
 
411
493
  // src/auth/oauth2/OAuthStrategy.ts
@@ -839,7 +921,7 @@ function OAuthStrategy(config) {
839
921
  };
840
922
  }
841
923
  var fetchTokens = async (payload) => {
842
- const res = await fetch(`https://${API_URL}/oauth2/token`, {
924
+ const res = await fetch("https://".concat(API_URL, "/oauth2/token"), {
843
925
  method: "POST",
844
926
  body: JSON.stringify(payload),
845
927
  headers: {
@@ -891,14 +973,14 @@ function WixAppOAuthStrategy(opts) {
891
973
  let refreshToken = opts.refreshToken;
892
974
  return {
893
975
  getInstallUrl({ redirectUrl }) {
894
- return `https://www.wix.com/installer/install?appId=${opts.appId}&redirectUrl=${redirectUrl}`;
976
+ return "https://www.wix.com/installer/install?appId=".concat(opts.appId, "&redirectUrl=").concat(redirectUrl);
895
977
  },
896
978
  async handleOAuthCallback(url, oauthOpts) {
897
979
  const params = new URLSearchParams(new URL(url).search);
898
980
  const state = params.get("state");
899
981
  if (state && (oauthOpts == null ? void 0 : oauthOpts.state) && state !== oauthOpts.state) {
900
982
  throw new Error(
901
- `Invalid OAuth callback URL. Expected state to be "${oauthOpts.state}" but got "${state}"`
983
+ 'Invalid OAuth callback URL. Expected state to be "'.concat(oauthOpts.state, '" but got "').concat(state, '"')
902
984
  );
903
985
  }
904
986
  const code = params.get("code");
@@ -922,7 +1004,7 @@ function WixAppOAuthStrategy(opts) {
922
1004
  });
923
1005
  if (tokensRes.status !== 200) {
924
1006
  throw new Error(
925
- `Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
1007
+ "Failed to exchange authorization code for refresh token. Unexpected status code from Wix OAuth API: ".concat(tokensRes.status)
926
1008
  );
927
1009
  }
928
1010
  const tokens = await tokensRes.json();
@@ -953,7 +1035,7 @@ function WixAppOAuthStrategy(opts) {
953
1035
  });
954
1036
  if (tokensRes.status !== 200) {
955
1037
  throw new Error(
956
- `Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ${tokensRes.status}`
1038
+ "Failed to exchange refresh token for access token. Unexpected status code from Wix OAuth API: ".concat(tokensRes.status)
957
1039
  );
958
1040
  }
959
1041
  const tokens = await tokensRes.json();
@@ -975,6 +1057,7 @@ export {
975
1057
  LoginState,
976
1058
  OAuthStrategy,
977
1059
  TokenRole,
1060
+ VideoResolution,
978
1061
  WixAppOAuthStrategy,
979
1062
  createClient,
980
1063
  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,40 @@ 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
+ };
160
+ declare function getAudioUrl(val: string): {
161
+ id: string;
162
+ url: string;
163
+ duration: number;
164
+ name?: string;
165
+ };
166
+ declare function getDocumentUrl(val: string): {
167
+ id: string;
168
+ url: string;
169
+ name?: string;
160
170
  };
161
171
  declare function decodeText(s: string): string;
172
+ declare enum VideoResolution {
173
+ MOBILE = "360p",
174
+ LOW = "480p",
175
+ MID = "720p",
176
+ HIGH = "1080p"
177
+ }
162
178
  declare const media: {
163
179
  getCroppedImageUrl: typeof getCroppedImageUrl;
164
180
  getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
165
181
  getScaledToFitImageUrl: typeof getScaledToFitImageUrl;
166
182
  getImageUrl: typeof getImageUrl;
183
+ getVideoUrl: typeof getVideoUrl;
184
+ getAudioUrl: typeof getAudioUrl;
185
+ getDocumentUrl: typeof getDocumentUrl;
167
186
  };
168
187
 
169
188
  interface Tokens {
@@ -366,4 +385,4 @@ declare function WixAppOAuthStrategy(opts: {
366
385
  refreshToken?: string;
367
386
  }): WixAppOAuthStrategy;
368
387
 
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 };
388
+ 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,40 @@ 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
+ };
160
+ declare function getAudioUrl(val: string): {
161
+ id: string;
162
+ url: string;
163
+ duration: number;
164
+ name?: string;
165
+ };
166
+ declare function getDocumentUrl(val: string): {
167
+ id: string;
168
+ url: string;
169
+ name?: string;
160
170
  };
161
171
  declare function decodeText(s: string): string;
172
+ declare enum VideoResolution {
173
+ MOBILE = "360p",
174
+ LOW = "480p",
175
+ MID = "720p",
176
+ HIGH = "1080p"
177
+ }
162
178
  declare const media: {
163
179
  getCroppedImageUrl: typeof getCroppedImageUrl;
164
180
  getScaledToFillImageUrl: typeof getScaledToFillImageUrl;
165
181
  getScaledToFitImageUrl: typeof getScaledToFitImageUrl;
166
182
  getImageUrl: typeof getImageUrl;
183
+ getVideoUrl: typeof getVideoUrl;
184
+ getAudioUrl: typeof getAudioUrl;
185
+ getDocumentUrl: typeof getDocumentUrl;
167
186
  };
168
187
 
169
188
  interface Tokens {
@@ -366,4 +385,4 @@ declare function WixAppOAuthStrategy(opts: {
366
385
  refreshToken?: string;
367
386
  }): WixAppOAuthStrategy;
368
387
 
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 };
388
+ 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,65 @@ function getImageUrl(val) {
435
449
  filename: decodedFilenameOrAltText
436
450
  };
437
451
  }
452
+ function getVideoUrl(val, resolution) {
453
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight;
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
+ [id] = pathname.replace(`${WIX_VIDEO}://v1/`, "").split("/");
464
+ thumbnailId = hashParams.get("posterUri") || `${id}.jpg`;
465
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
466
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
467
+ }
468
+ return {
469
+ id,
470
+ url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : "file"}`,
471
+ thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`
472
+ };
473
+ }
474
+ function getAudioUrl(val) {
475
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
476
+ const { pathname, hash } = new URL(alignedAudio);
477
+ const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, "").split("/");
478
+ const decodedFilename = decodeText(filename);
479
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
480
+ const res = {
481
+ id,
482
+ duration: Number(hashParams.get("duration") || ""),
483
+ url: `${WIX_AUDIO_URL}${id}`
484
+ };
485
+ if (!decodedFilename) {
486
+ return res;
487
+ }
488
+ return {
489
+ ...res,
490
+ name: decodedFilename
491
+ };
492
+ }
493
+ function getDocumentUrl(val) {
494
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
495
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
496
+ const { pathname } = new URL(alignedDocument);
497
+ const [id, filename] = pathname.replace(`${WIX_DOCUMENT}://v1/`, "").split("/");
498
+ const decodedFilename = decodeText(filename);
499
+ const res = {
500
+ id,
501
+ url: `${WIX_DOCUMENT_URL}${id}`
502
+ };
503
+ if (!decodedFilename) {
504
+ return res;
505
+ }
506
+ return {
507
+ ...res,
508
+ name: decodedFilename
509
+ };
510
+ }
438
511
  function decodeText(s) {
439
512
  if (!s) {
440
513
  return s;
@@ -445,11 +518,21 @@ function alignIfLegacy(url, type) {
445
518
  const { protocol } = new URL(url);
446
519
  return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
447
520
  }
521
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
522
+ VideoResolution2["MOBILE"] = "360p";
523
+ VideoResolution2["LOW"] = "480p";
524
+ VideoResolution2["MID"] = "720p";
525
+ VideoResolution2["HIGH"] = "1080p";
526
+ return VideoResolution2;
527
+ })(VideoResolution || {});
448
528
  var media = {
449
529
  getCroppedImageUrl,
450
530
  getScaledToFillImageUrl,
451
531
  getScaledToFitImageUrl,
452
- getImageUrl
532
+ getImageUrl,
533
+ getVideoUrl,
534
+ getAudioUrl,
535
+ getDocumentUrl
453
536
  };
454
537
 
455
538
  // src/auth/oauth2/OAuthStrategy.ts
@@ -1013,6 +1096,7 @@ __reExport(src_exports, require("@wix/sdk-types"), module.exports);
1013
1096
  LoginState,
1014
1097
  OAuthStrategy,
1015
1098
  TokenRole,
1099
+ VideoResolution,
1016
1100
  WixAppOAuthStrategy,
1017
1101
  createClient,
1018
1102
  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,65 @@ function getImageUrl(val) {
389
402
  filename: decodedFilenameOrAltText
390
403
  };
391
404
  }
405
+ function getVideoUrl(val, resolution) {
406
+ let id, thumbnailId, thumbnailWidth, thumbnailHeight;
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
+ [id] = pathname.replace(`${WIX_VIDEO}://v1/`, "").split("/");
417
+ thumbnailId = hashParams.get("posterUri") || `${id}.jpg`;
418
+ thumbnailWidth = hashParams.get("posterWidth") || "50";
419
+ thumbnailHeight = hashParams.get("posterHeight") || "50";
420
+ }
421
+ return {
422
+ id,
423
+ url: `${WIX_VIDEO_URL}${id}/${resolution ? `${resolution}/mp4/file.mp4` : "file"}`,
424
+ thumbnail: `${WIX_PROTOCOL}${WIX_IMAGE}://v1/${thumbnailId}#originWidth=${thumbnailWidth}&originHeight=${thumbnailHeight}`
425
+ };
426
+ }
427
+ function getAudioUrl(val) {
428
+ const alignedAudio = alignIfLegacy(val, WIX_AUDIO);
429
+ const { pathname, hash } = new URL(alignedAudio);
430
+ const [id, filename] = pathname.replace(`${WIX_AUDIO}://v1/`, "").split("/");
431
+ const decodedFilename = decodeText(filename);
432
+ const hashParams = new URLSearchParams(hash.replace("#", ""));
433
+ const res = {
434
+ id,
435
+ duration: Number(hashParams.get("duration") || ""),
436
+ url: `${WIX_AUDIO_URL}${id}`
437
+ };
438
+ if (!decodedFilename) {
439
+ return res;
440
+ }
441
+ return {
442
+ ...res,
443
+ name: decodedFilename
444
+ };
445
+ }
446
+ function getDocumentUrl(val) {
447
+ const valWithoutUGD = val.replace("v1/ugd", "v1");
448
+ const alignedDocument = alignIfLegacy(valWithoutUGD, WIX_DOCUMENT);
449
+ const { pathname } = new URL(alignedDocument);
450
+ const [id, filename] = pathname.replace(`${WIX_DOCUMENT}://v1/`, "").split("/");
451
+ const decodedFilename = decodeText(filename);
452
+ const res = {
453
+ id,
454
+ url: `${WIX_DOCUMENT_URL}${id}`
455
+ };
456
+ if (!decodedFilename) {
457
+ return res;
458
+ }
459
+ return {
460
+ ...res,
461
+ name: decodedFilename
462
+ };
463
+ }
392
464
  function decodeText(s) {
393
465
  if (!s) {
394
466
  return s;
@@ -399,11 +471,21 @@ function alignIfLegacy(url, type) {
399
471
  const { protocol } = new URL(url);
400
472
  return protocol === `${type}:` ? `${WIX_PROTOCOL}${url}` : url;
401
473
  }
474
+ var VideoResolution = /* @__PURE__ */ ((VideoResolution2) => {
475
+ VideoResolution2["MOBILE"] = "360p";
476
+ VideoResolution2["LOW"] = "480p";
477
+ VideoResolution2["MID"] = "720p";
478
+ VideoResolution2["HIGH"] = "1080p";
479
+ return VideoResolution2;
480
+ })(VideoResolution || {});
402
481
  var media = {
403
482
  getCroppedImageUrl,
404
483
  getScaledToFillImageUrl,
405
484
  getScaledToFitImageUrl,
406
- getImageUrl
485
+ getImageUrl,
486
+ getVideoUrl,
487
+ getAudioUrl,
488
+ getDocumentUrl
407
489
  };
408
490
 
409
491
  // src/auth/oauth2/OAuthStrategy.ts
@@ -966,6 +1048,7 @@ export {
966
1048
  LoginState,
967
1049
  OAuthStrategy,
968
1050
  TokenRole,
1051
+ VideoResolution,
969
1052
  WixAppOAuthStrategy,
970
1053
  createClient,
971
1054
  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.8",
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.2",
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.2",
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
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.9",
57
+ "tsup": "^7.3.0",
58
+ "typescript": "^5.3.2",
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": "abc3cbf2dfe41ba544a61d2a46cac253a1b083d01586f66bd062aba8"
86
86
  }