@wix/himalaya-cli 0.1387.0 → 0.1389.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-contract.d.ts +24 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-core.d.ts +3 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/index.d.ts +1 -1
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/video/src/display.d.ts +66 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/video/src/index.d.ts +185 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +57 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +57 -0
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-video.mjs +324 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/package.json +4 -0
  10. package/dist/cli.mjs +10 -5
  11. package/guides/iap-screen-adoption.md +53 -1
  12. package/guides/importable-sdks.md +1 -0
  13. package/guides/sdk-reference.json +261 -2
  14. package/package.json +2 -2
  15. package/templates/beauty-salon/dev/index.ts +193 -1
  16. package/templates/beauty-salon/tier5-src/_shared/collection-contract.ts +1 -1
  17. package/templates/beauty-salon/tier5-src/_shared/iap-worker.ts +84 -3
  18. package/templates/beauty-salon/tier5-src/_shared/video-caption.ts +21 -0
  19. package/templates/beauty-salon/tier5-src/himi-branded-lite-home/index.ts +31 -1
  20. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +36 -1
  21. package/templates/beauty-salon-owner/config.ts +11 -0
  22. package/templates/beauty-salon-owner/dev/index.ts +540 -0
  23. package/templates/beauty-salon-owner/himalaya.content.json +6 -0
  24. package/templates/beauty-salon-owner/platforms.json +2 -1
  25. package/templates/beauty-salon-owner/tier5-src/_shared/collection-contract.ts +1 -1
  26. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  27. package/templates/branded-lite/dev/index.ts +1212 -54
  28. package/templates/branded-lite/tier5-src/_shared/collection-contract.ts +1 -1
  29. package/templates/branded-lite/tier5-src/_shared/iap-worker.ts +84 -3
  30. package/templates/branded-lite/tier5-src/_shared/video-caption.ts +21 -0
  31. package/templates/branded-lite/tier5-src/himi-branded-lite-home/index.ts +31 -1
  32. package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +23 -32
  33. package/templates/branded-lite/tier5-src/himi-branded-lite-videos/index.ts +44 -38
  34. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +36 -1
  35. package/templates/community-club/dev/index.ts +193 -1
  36. package/templates/community-club/tier5-src/_shared/collection-contract.ts +1 -1
  37. package/templates/community-club/tier5-src/_shared/iap-worker.ts +84 -3
  38. package/templates/community-club/tier5-src/_shared/video-caption.ts +21 -0
  39. package/templates/community-club/tier5-src/himi-branded-lite-home/index.ts +31 -1
  40. package/templates/community-club/tier5-src/himi-store-account/index.ts +36 -1
  41. package/templates/community-club-owner/config.ts +11 -0
  42. package/templates/community-club-owner/dev/index.ts +540 -0
  43. package/templates/community-club-owner/himalaya.content.json +6 -0
  44. package/templates/community-club-owner/platforms.json +2 -1
  45. package/templates/community-club-owner/tier5-src/_shared/collection-contract.ts +1 -1
  46. package/templates/community-club-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  47. package/templates/events-meetups/dev/index.ts +193 -1
  48. package/templates/events-meetups/tier5-src/_shared/collection-contract.ts +1 -1
  49. package/templates/events-meetups/tier5-src/_shared/iap-worker.ts +84 -3
  50. package/templates/events-meetups/tier5-src/_shared/video-caption.ts +21 -0
  51. package/templates/events-meetups/tier5-src/himi-branded-lite-home/index.ts +31 -1
  52. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +36 -1
  53. package/templates/events-meetups-owner/config.ts +11 -0
  54. package/templates/events-meetups-owner/dev/index.ts +540 -0
  55. package/templates/events-meetups-owner/himalaya.content.json +6 -0
  56. package/templates/events-meetups-owner/platforms.json +2 -1
  57. package/templates/events-meetups-owner/tier5-src/_shared/collection-contract.ts +1 -1
  58. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  59. package/templates/gym-fitness/dev/index.ts +193 -1
  60. package/templates/gym-fitness/tier5-src/_shared/collection-contract.ts +1 -1
  61. package/templates/gym-fitness/tier5-src/_shared/iap-worker.ts +84 -3
  62. package/templates/gym-fitness/tier5-src/_shared/video-caption.ts +21 -0
  63. package/templates/gym-fitness/tier5-src/himi-branded-lite-home/index.ts +31 -1
  64. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +36 -1
  65. package/templates/gym-fitness-owner/config.ts +11 -0
  66. package/templates/gym-fitness-owner/dev/index.ts +540 -0
  67. package/templates/gym-fitness-owner/himalaya.content.json +6 -0
  68. package/templates/gym-fitness-owner/platforms.json +2 -1
  69. package/templates/gym-fitness-owner/tier5-src/_shared/collection-contract.ts +1 -1
  70. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  71. package/templates/nonprofit-cause/dev/index.ts +193 -1
  72. package/templates/nonprofit-cause/tier5-src/_shared/collection-contract.ts +1 -1
  73. package/templates/nonprofit-cause/tier5-src/_shared/iap-worker.ts +84 -3
  74. package/templates/nonprofit-cause/tier5-src/_shared/video-caption.ts +21 -0
  75. package/templates/nonprofit-cause/tier5-src/himi-branded-lite-home/index.ts +31 -1
  76. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +36 -1
  77. package/templates/nonprofit-cause-owner/config.ts +11 -0
  78. package/templates/nonprofit-cause-owner/dev/index.ts +540 -0
  79. package/templates/nonprofit-cause-owner/himalaya.content.json +6 -0
  80. package/templates/nonprofit-cause-owner/platforms.json +2 -1
  81. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-contract.ts +1 -1
  82. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  83. package/templates/owner-lite/config.ts +11 -0
  84. package/templates/owner-lite/dev/index.ts +540 -0
  85. package/templates/owner-lite/himalaya.content.json +6 -0
  86. package/templates/owner-lite/platforms.json +2 -1
  87. package/templates/owner-lite/tier5-src/_shared/collection-contract.ts +1 -1
  88. package/templates/owner-lite/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  89. package/templates/podcast-creator/dev/index.ts +193 -1
  90. package/templates/podcast-creator/tier5-src/_shared/collection-contract.ts +1 -1
  91. package/templates/podcast-creator/tier5-src/_shared/iap-worker.ts +84 -3
  92. package/templates/podcast-creator/tier5-src/_shared/video-caption.ts +21 -0
  93. package/templates/podcast-creator/tier5-src/himi-branded-lite-home/index.ts +31 -1
  94. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +36 -1
  95. package/templates/podcast-creator-owner/config.ts +11 -0
  96. package/templates/podcast-creator-owner/dev/index.ts +540 -0
  97. package/templates/podcast-creator-owner/himalaya.content.json +6 -0
  98. package/templates/podcast-creator-owner/platforms.json +2 -1
  99. package/templates/podcast-creator-owner/tier5-src/_shared/collection-contract.ts +1 -1
  100. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  101. package/templates/portfolio-creative/dev/index.ts +193 -1
  102. package/templates/portfolio-creative/tier5-src/_shared/collection-contract.ts +1 -1
  103. package/templates/portfolio-creative/tier5-src/_shared/iap-worker.ts +84 -3
  104. package/templates/portfolio-creative/tier5-src/_shared/video-caption.ts +21 -0
  105. package/templates/portfolio-creative/tier5-src/himi-branded-lite-home/index.ts +31 -1
  106. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +36 -1
  107. package/templates/portfolio-creative-owner/config.ts +11 -0
  108. package/templates/portfolio-creative-owner/dev/index.ts +540 -0
  109. package/templates/portfolio-creative-owner/himalaya.content.json +6 -0
  110. package/templates/portfolio-creative-owner/platforms.json +2 -1
  111. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-contract.ts +1 -1
  112. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  113. package/templates/restaurant/dev/index.ts +193 -1
  114. package/templates/restaurant/tier5-src/_shared/collection-contract.ts +1 -1
  115. package/templates/restaurant/tier5-src/_shared/iap-worker.ts +84 -3
  116. package/templates/restaurant/tier5-src/_shared/video-caption.ts +21 -0
  117. package/templates/restaurant/tier5-src/himi-branded-lite-home/index.ts +31 -1
  118. package/templates/restaurant/tier5-src/himi-store-account/index.ts +36 -1
  119. package/templates/restaurant-owner/config.ts +11 -0
  120. package/templates/restaurant-owner/dev/index.ts +540 -0
  121. package/templates/restaurant-owner/himalaya.content.json +6 -0
  122. package/templates/restaurant-owner/platforms.json +2 -1
  123. package/templates/restaurant-owner/tier5-src/_shared/collection-contract.ts +1 -1
  124. package/templates/restaurant-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  125. package/templates/retail-store/dev/index.ts +193 -1
  126. package/templates/retail-store/tier5-src/_shared/collection-contract.ts +1 -1
  127. package/templates/retail-store/tier5-src/_shared/iap-worker.ts +84 -3
  128. package/templates/retail-store/tier5-src/_shared/video-caption.ts +21 -0
  129. package/templates/retail-store/tier5-src/himi-branded-lite-home/index.ts +31 -1
  130. package/templates/retail-store/tier5-src/himi-store-account/index.ts +36 -1
  131. package/templates/retail-store-owner/config.ts +11 -0
  132. package/templates/retail-store-owner/dev/index.ts +540 -0
  133. package/templates/retail-store-owner/himalaya.content.json +6 -0
  134. package/templates/retail-store-owner/platforms.json +2 -1
  135. package/templates/retail-store-owner/tier5-src/_shared/collection-contract.ts +1 -1
  136. package/templates/retail-store-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  137. package/templates/yoga-studio/dev/index.ts +193 -1
  138. package/templates/yoga-studio/tier5-src/_shared/collection-contract.ts +1 -1
  139. package/templates/yoga-studio/tier5-src/_shared/iap-worker.ts +84 -3
  140. package/templates/yoga-studio/tier5-src/_shared/video-caption.ts +21 -0
  141. package/templates/yoga-studio/tier5-src/himi-branded-lite-home/index.ts +31 -1
  142. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +36 -1
  143. package/templates/yoga-studio-owner/config.ts +11 -0
  144. package/templates/yoga-studio-owner/dev/index.ts +540 -0
  145. package/templates/yoga-studio-owner/himalaya.content.json +6 -0
  146. package/templates/yoga-studio-owner/platforms.json +2 -1
  147. package/templates/yoga-studio-owner/tier5-src/_shared/collection-contract.ts +1 -1
  148. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-wrist/index.ts +350 -0
  149. package/templates/branded-lite/tier5-src/_shared/vod.ts +0 -71
@@ -0,0 +1,324 @@
1
+ // ../../stdlib/wix-sdk/media/src/index.ts
2
+ var WIX_LIST_IMAGE = { width: 1e3, height: 1e3, quality: 85 };
3
+ var WIX_MEDIA = /^https?:\/\/static\.wixstatic\.com\/media\/[^/]/;
4
+ var WIX_IMAGE = /^wix:image:\/\/v1\/([^/]+)/i;
5
+ var WIX_TRANSFORM = /^(https?:\/\/static\.wixstatic\.com\/media\/[^/]+\/v1\/)([^/]+)\/([^/?#]+)(?:\/([^/?#]+))?([?#].*)?$/i;
6
+ var SIZING_PARAM = /^(w|h|q)_\d+$/i;
7
+ var WEB_URL = /^https?:\/\//i;
8
+ var RESIZABLE_MODES = /* @__PURE__ */ new Set(["fit", "fill"]);
9
+ var OWNED_PARAM = /^(w|h|q)_/i;
10
+ var DROPPED_PARAM = /^enc_/i;
11
+ function wixMediaId(reference) {
12
+ return WIX_IMAGE.exec(reference)?.[1] ?? (reference.includes("/") || reference.includes(":") ? "" : reference);
13
+ }
14
+ function resolveWixMediaReference(reference) {
15
+ const mediaId = wixMediaId(reference);
16
+ return mediaId ? `https://static.wixstatic.com/media/${mediaId}` : reference;
17
+ }
18
+ function requestedParams(size) {
19
+ return [`w_${size.width}`, `h_${size.height}`, `q_${size.quality ?? 85}`];
20
+ }
21
+ function fittedParams(size, source, mode) {
22
+ const quality = `q_${size.quality ?? 85}`;
23
+ const { width: sourceWidth, height: sourceHeight } = source;
24
+ if (sourceWidth && sourceHeight) {
25
+ if (mode.toLowerCase() === "fill") {
26
+ const scale = Math.min(size.width / sourceWidth, size.height / sourceHeight, 1);
27
+ return [
28
+ `w_${Math.max(1, Math.round(sourceWidth * scale))}`,
29
+ `h_${Math.max(1, Math.round(sourceHeight * scale))}`,
30
+ quality
31
+ ];
32
+ }
33
+ return [
34
+ `w_${Math.min(sourceWidth, size.width)}`,
35
+ `h_${Math.min(sourceHeight, size.height)}`,
36
+ quality
37
+ ];
38
+ }
39
+ if (sourceWidth) return [`w_${Math.min(sourceWidth, size.width)}`, quality];
40
+ if (sourceHeight) return [`h_${Math.min(sourceHeight, size.height)}`, quality];
41
+ return requestedParams(size);
42
+ }
43
+ function resizeWixTransform(url, size) {
44
+ const transform = WIX_TRANSFORM.exec(url);
45
+ if (!transform || !RESIZABLE_MODES.has(transform[2].toLowerCase())) return url;
46
+ const [, base, mode, rawParams, filename, suffix] = transform;
47
+ const source = rawParams.split(",").filter(Boolean);
48
+ if (!filename && !source.some((param) => SIZING_PARAM.test(param))) return url;
49
+ const dimensions = dimensionsOf(source);
50
+ if (mode.toLowerCase() === "fill" && !dimensions.width && !dimensions.height) return url;
51
+ const stated = [dimensions.width, dimensions.height].filter((d) => d !== void 0);
52
+ if (stated.length > 0 && (dimensions.width ?? 0) <= size.width && (dimensions.height ?? 0) <= size.height) return url;
53
+ const carried = source.filter((p) => !OWNED_PARAM.test(p) && !DROPPED_PARAM.test(p));
54
+ const params = [...fittedParams(size, dimensions, mode), ...carried];
55
+ return `${base}${mode}/${params.join(",")}/image.jpg${suffix ?? ""}`;
56
+ }
57
+ function wixTransformDimension(params, name) {
58
+ const match = params.find((param) => new RegExp(`^${name}_\\d+$`, "i").test(param));
59
+ return match ? Number(match.slice(2)) : void 0;
60
+ }
61
+ function dimensionsOf(params) {
62
+ return {
63
+ width: wixTransformDimension(params, "w"),
64
+ height: wixTransformDimension(params, "h")
65
+ };
66
+ }
67
+ function wixMediaUrl(value, size = WIX_LIST_IMAGE) {
68
+ const reference = typeof value === "string" ? value.trim() : "";
69
+ if (!reference) return "";
70
+ const resolvedUrl = resolveWixMediaReference(reference);
71
+ if (!WEB_URL.test(resolvedUrl)) return "";
72
+ if (size === null) return resolvedUrl;
73
+ if (!WIX_MEDIA.test(resolvedUrl)) return resolvedUrl;
74
+ const base = resolvedUrl.split(/[?#]/)[0];
75
+ if (base.includes("/v1/")) return resizeWixTransform(resolvedUrl, size);
76
+ const suffix = resolvedUrl.slice(base.length);
77
+ return `${base}/v1/fit/${requestedParams(size).join(",")}/image.jpg${suffix}`;
78
+ }
79
+
80
+ // ../../stdlib/wix-sdk/video/src/display.ts
81
+ var HOSTED_SOURCES = /* @__PURE__ */ new Set(["COMPUTER", "GOOGLE_DRIVE", "DROPBOX"]);
82
+ var PROCESSING = /PROCESS|PROGRESS|PENDING|QUEUE|INITIALIZED|TRANSCOD|UPLOAD|CONVERT|PREVIEW_READY/;
83
+ function isHostedVideo(video) {
84
+ return HOSTED_SOURCES.has(video.source ?? "");
85
+ }
86
+ function isVideoReady(video) {
87
+ return (video.status ?? "VISIBLE") === "VISIBLE" && video.content?.status === "READY";
88
+ }
89
+ function isVideoProcessing(video) {
90
+ return PROCESSING.test(video.content?.status ?? "");
91
+ }
92
+ function youtubeVideoId(video) {
93
+ const match = /^https:\/\/(?:(?:www\.|m\.)?youtube\.com|www\.youtube-nocookie\.com)\/embed\/([A-Za-z0-9_-]{11})(?:[?/#]|$)/.exec(video.content?.externalUrl ?? "");
94
+ if (match) return match[1];
95
+ const id = video.content?.externalId ?? "";
96
+ return /^[A-Za-z0-9_-]{11}$/.test(id) ? id : "";
97
+ }
98
+ function videoCoverUrl(video, size = WIX_LIST_IMAGE) {
99
+ for (const candidate of [video.cover?.selected, video.poster?.selected, video.content?.thumbnailUrl]) {
100
+ const url = wixMediaUrl(candidate, size);
101
+ if (url) return url;
102
+ }
103
+ const youtube = video.source === "YOUTUBE" ? youtubeVideoId(video) : "";
104
+ return youtube ? `https://i.ytimg.com/vi/${youtube}/hqdefault.jpg` : "";
105
+ }
106
+ function channelCoverUrl(channel, size = WIX_LIST_IMAGE) {
107
+ return wixMediaUrl(channel.cover?.selected, size);
108
+ }
109
+ function videoDurationSec(video) {
110
+ const ms = video.content?.duration;
111
+ return typeof ms === "number" && Number.isFinite(ms) && ms > 0 ? Math.round(ms / 1e3) : void 0;
112
+ }
113
+ function formatVideoDuration(seconds) {
114
+ if (seconds === void 0 || !Number.isFinite(seconds) || seconds <= 0) return "";
115
+ const total = Math.round(seconds);
116
+ const h = Math.floor(total / 3600);
117
+ const m = Math.floor(total % 3600 / 60);
118
+ const s = String(total % 60).padStart(2, "0");
119
+ return h ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
120
+ }
121
+ function isPaidVideo(video) {
122
+ return Array.isArray(video.pricing) && video.pricing.some((p) => p.enabled);
123
+ }
124
+ function canWatchVideo(channel, video, now = Date.now()) {
125
+ if (!Array.isArray(channel.pricing) || !Array.isArray(video.pricing)) return false;
126
+ const subscription = channel.purchase;
127
+ const expires = subscription?.expiresAt ? Date.parse(subscription.expiresAt) : void 0;
128
+ const subscribed = subscription?.status === "ACTIVE" && (expires === void 0 || expires > now) || subscription?.status === "CANCELED" && expires !== void 0 && expires > now;
129
+ const channelOptions = channel.pricing.filter((p) => p.enabled);
130
+ if (channelOptions.some((p) => p.required || p.type === "PRICING_PLAN") && !subscribed) return false;
131
+ return !isPaidVideo(video) || subscribed || video.purchase?.status === "ACTIVE" || video.rent_purchase?.status === "ACTIVE";
132
+ }
133
+ function latestVideos(channels, limit = 8) {
134
+ const queues = channels.map((channel) => ({
135
+ channel,
136
+ videos: (channel.videos?.entities ?? []).filter((video) => video?.id && isVideoReady(video))
137
+ }));
138
+ const out = [];
139
+ const seen = /* @__PURE__ */ new Set();
140
+ for (let round = 0; out.length < limit && queues.some((q) => q.videos.length > round); round++) {
141
+ for (const { channel, videos } of queues) {
142
+ const video = videos[round];
143
+ if (!video || seen.has(video.id)) continue;
144
+ seen.add(video.id);
145
+ out.push({ channel, video });
146
+ if (out.length >= limit) break;
147
+ }
148
+ }
149
+ return out;
150
+ }
151
+ function videoCard(entry, untitled = "Video", size = WIX_LIST_IMAGE) {
152
+ const { channel, video } = entry;
153
+ const title = video.title?.trim() || untitled;
154
+ const duration = formatVideoDuration(videoDurationSec(video));
155
+ const channelTitle = channel.title?.trim() ?? "";
156
+ const coverUrl = videoCoverUrl(video, size);
157
+ const isPaid = isPaidVideo(video);
158
+ return {
159
+ id: video.id,
160
+ channelId: channel.id,
161
+ title,
162
+ meta: [duration, channelTitle].filter(Boolean).join(" \xB7 "),
163
+ duration,
164
+ channelTitle,
165
+ coverUrl,
166
+ hasCover: !!coverUrl,
167
+ noCover: !coverUrl,
168
+ isPaid,
169
+ notPaid: !isPaid,
170
+ accessibilityLabel: [title, duration, channelTitle].filter(Boolean).join(", ")
171
+ };
172
+ }
173
+
174
+ // ../../stdlib/wix-sdk/video/src/index.ts
175
+ var WIX_VIDEO_GRAPHQL_URL = "https://manage.wix.com/_api/vod/public/graphql";
176
+ function wixVideoError(message, flags = {}) {
177
+ return Object.assign(new Error(message), {
178
+ denied: flags.denied ?? false,
179
+ signInRequired: flags.signInRequired ?? false,
180
+ notFound: flags.notFound ?? false
181
+ });
182
+ }
183
+ function isWixVideoWebRefusal(error) {
184
+ return /webwix_owner_only|absolute_urls_not_allowed/.test(String(error?.message ?? error));
185
+ }
186
+ function transportError(error) {
187
+ const message = String(error?.message ?? error);
188
+ const status = Number(/^HTTP\s+(\d{3})\b/.exec(message)?.[1]);
189
+ return Object.assign(wixVideoError(message, { signInRequired: status === 401, denied: status === 401 || status === 403 }), { cause: error });
190
+ }
191
+ function callHeaders(opts) {
192
+ const site = opts?.site?.trim();
193
+ return site ? { "wix-site-id": site } : void 0;
194
+ }
195
+ async function wixVideoQuery(query, variables = {}, opts) {
196
+ const wixApi = globalThis.himalaya?.wixApi;
197
+ if (!wixApi) throw wixVideoError("@himalaya/wix-video: host did not install the wixApi bridge");
198
+ const headers = callHeaders(opts);
199
+ let response;
200
+ try {
201
+ response = await (headers ? wixApi.call("POST", WIX_VIDEO_GRAPHQL_URL, { query, variables }, headers) : wixApi.call("POST", WIX_VIDEO_GRAPHQL_URL, { query, variables }));
202
+ } catch (error) {
203
+ throw transportError(error);
204
+ }
205
+ if (response?.errors?.length) {
206
+ const codes = response.errors.map((e) => e.extensions?.code ?? "");
207
+ const signInRequired = codes.some((code) => /^(UNAUTHENTICATED|UNAUTHORIZED)$/i.test(code));
208
+ const denied = codes.some((code) => /FORBIDDEN|UNAUTH|ACCESS_DENIED|PERMISSION_DENIED/i.test(code));
209
+ throw wixVideoError(signInRequired ? "Video unauthenticated" : denied ? "Video access denied" : "Wix Video query failed", { denied, signInRequired });
210
+ }
211
+ const data = response && Object.prototype.hasOwnProperty.call(response, "data") ? response.data : response;
212
+ if (!data || typeof data !== "object") throw wixVideoError("Invalid Wix Video response");
213
+ return data;
214
+ }
215
+ async function wixVideoPages(fetchPage) {
216
+ const rows = /* @__PURE__ */ new Map();
217
+ const cursors = /* @__PURE__ */ new Set();
218
+ let cursor = null;
219
+ for (let page = 0; page < 200; page++) {
220
+ const result = await fetchPage(cursor);
221
+ if (!result || !Array.isArray(result.entities)) throw wixVideoError("Invalid Wix Video page");
222
+ for (const row of result.entities) if (row?.id) rows.set(row.id, row);
223
+ if (!result.cursor) return [...rows.values()];
224
+ if (typeof result.cursor !== "string" || cursors.has(result.cursor)) throw wixVideoError("Invalid Wix Video cursor");
225
+ cursor = result.cursor;
226
+ cursors.add(cursor);
227
+ }
228
+ throw wixVideoError("Wix Video pagination limit exceeded");
229
+ }
230
+ var CHANNEL_FIELDS = "id title description source featuredVideoId hasPaidVideos cover { selected } videos { total }";
231
+ var CHANNEL_ACCESS_FIELDS = "id title pricing { type enabled required } purchase(filter: {type: SUBSCRIPTION}) { status expiresAt }";
232
+ var VIDEO_CARD_FIELDS = "id title source status cover { selected } poster { selected } content { status duration thumbnailUrl externalUrl externalId } pricing { type enabled }";
233
+ var VIDEO_FIELDS = "id title description source status cover { selected } poster { selected } content { status duration thumbnailUrl externalUrl externalId } pricing { type enabled } purchase(filter: {type: SALE}) { status } rent_purchase: purchase(filter: {type: RENT}) { status }";
234
+ function channelsQuery(videosPerChannel) {
235
+ const preview = videosPerChannel > 0 ? ` preview: videos(sort: CUSTOM_DESC, limit: ${Math.floor(videosPerChannel)}) { entities { ${VIDEO_CARD_FIELDS} } }` : "";
236
+ return `query WixVideoChannels($cursor: String) {
237
+ channels(sort: CUSTOM_ASC, cursor: $cursor) { total cursor entities { ${CHANNEL_FIELDS}${preview} } }
238
+ }`;
239
+ }
240
+ function withPreview(channel) {
241
+ const { preview, ...rest } = channel;
242
+ if (!preview) return rest;
243
+ return { ...rest, videos: { ...rest.videos, entities: Array.isArray(preview.entities) ? preview.entities : [] } };
244
+ }
245
+ async function listChannels(opts = {}) {
246
+ const query = channelsQuery(Math.max(0, opts.videosPerChannel ?? 0));
247
+ const channels = await wixVideoPages(async (cursor) => {
248
+ const data = await wixVideoQuery(query, { cursor }, opts);
249
+ return data.channels;
250
+ });
251
+ return channels.map(withPreview);
252
+ }
253
+ async function listChannelVideos(channelId, opts) {
254
+ if (!channelId) throw wixVideoError("listChannelVideos: channelId is required", { notFound: true });
255
+ const query = `query WixVideoChannelVideos($channelId: ID!, $cursor: String) {
256
+ channel(filter: {id: $channelId}) { ${CHANNEL_ACCESS_FIELDS} cover { selected } videos(sort: CUSTOM_DESC, cursor: $cursor) { cursor entities { ${VIDEO_FIELDS} } } }
257
+ }`;
258
+ let channel;
259
+ const videos = await wixVideoPages(async (cursor) => {
260
+ const data = await wixVideoQuery(query, { channelId, cursor }, opts);
261
+ if (!data.channel) throw wixVideoError("Channel unavailable", { notFound: true });
262
+ channel = data.channel;
263
+ return data.channel.videos;
264
+ });
265
+ const { videos: _page, ...rest } = channel;
266
+ return { channel: rest, videos };
267
+ }
268
+ async function getVideo(channelId, videoId, opts) {
269
+ const query = `query WixVideo($channelId: ID!, $videoId: ID!) {
270
+ channel(filter: {id: $channelId}) { ${CHANNEL_ACCESS_FIELDS} video(filter: {id: $videoId}) { ${VIDEO_FIELDS} } }
271
+ }`;
272
+ const data = await wixVideoQuery(query, { channelId, videoId }, opts);
273
+ if (!data.channel) return null;
274
+ const { video, ...channel } = data.channel;
275
+ return { channel, video: video ?? null };
276
+ }
277
+ async function getVideoStreamUrl(channelId, videoId, opts) {
278
+ const query = `query WixVideoPlay($channelId: ID!, $videoId: ID!) {
279
+ channel(filter: {id: $channelId}) { video(filter: {id: $videoId}) { play(type: CONTENT) { entity { url hls } } } }
280
+ }`;
281
+ const data = await wixVideoQuery(query, { channelId, videoId }, opts);
282
+ const entity = data.channel?.video?.play?.entity;
283
+ const url = entity?.hls || entity?.url || "";
284
+ return /^https:\/\//.test(url) ? url : "";
285
+ }
286
+ async function listLatestVideos(opts = {}) {
287
+ const channels = Math.max(1, Math.floor(opts.channels ?? 10));
288
+ const perChannel = Math.max(1, Math.floor(opts.perChannel ?? 4));
289
+ const query = `query WixVideoLatest {
290
+ channels(sort: CUSTOM_ASC, limit: ${channels}) { entities { ${CHANNEL_FIELDS} preview: videos(sort: CUSTOM_DESC, limit: ${perChannel}) { entities { ${VIDEO_CARD_FIELDS} } } } }
291
+ }`;
292
+ const data = await wixVideoQuery(query, {}, opts);
293
+ if (!data.channels || !Array.isArray(data.channels.entities)) throw wixVideoError("Invalid Wix Video page");
294
+ return latestVideos(data.channels.entities.filter((c) => c?.id).map(withPreview), opts.limit ?? 8);
295
+ }
296
+ export {
297
+ CHANNEL_ACCESS_FIELDS,
298
+ CHANNEL_FIELDS,
299
+ VIDEO_CARD_FIELDS,
300
+ VIDEO_FIELDS,
301
+ WIX_VIDEO_GRAPHQL_URL,
302
+ canWatchVideo,
303
+ channelCoverUrl,
304
+ formatVideoDuration,
305
+ getVideo,
306
+ getVideoStreamUrl,
307
+ isHostedVideo,
308
+ isPaidVideo,
309
+ isVideoProcessing,
310
+ isVideoReady,
311
+ isWixVideoWebRefusal,
312
+ latestVideos,
313
+ listChannelVideos,
314
+ listChannels,
315
+ listLatestVideos,
316
+ videoCard,
317
+ videoCoverUrl,
318
+ videoDurationSec,
319
+ wixVideoError,
320
+ wixVideoPages,
321
+ wixVideoQuery,
322
+ youtubeVideoId
323
+ };
324
+ //# sourceMappingURL=wix-video.mjs.map
@@ -506,6 +506,10 @@
506
506
  "types": "./dist/_types/stdlib/wix-sdk/users/src/index.d.ts",
507
507
  "import": "./dist/wix-users.mjs"
508
508
  },
509
+ "./wix-video": {
510
+ "types": "./dist/_types/stdlib/wix-sdk/video/src/index.d.ts",
511
+ "import": "./dist/wix-video.mjs"
512
+ },
509
513
  "./wix-workflows": {
510
514
  "types": "./dist/_types/stdlib/wix-sdk/workflows-v1/src/index.d.ts",
511
515
  "import": "./dist/wix-workflows.mjs"