@orangelogic/orange-dam-content-browser-sdk 2.3.0 → 2.3.1

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.
@@ -14,7 +14,7 @@ export type ContentItem = {
14
14
  recordID: string;
15
15
  };
16
16
  export type GetAssetLinkRequest = {
17
- ExtraFields?: string;
17
+ ExtraFields?: string[];
18
18
  GenerateAssetUrl?: boolean;
19
19
  Parameters?: TrackingParameter[];
20
20
  Proxy?: string;
@@ -12757,6 +12757,24 @@ __decorateClass$1([
12757
12757
  CxContentBrowserHeader = __decorateClass$1([
12758
12758
  customElement("cx-content-browser-header")
12759
12759
  ], CxContentBrowserHeader);
12760
+ const appendPathAndQuery = (baseUrl, pathSuffix, extraQueryParams = []) => {
12761
+ const questionMarkIndex = baseUrl.indexOf("?");
12762
+ const hashIndex = baseUrl.indexOf("#");
12763
+ const separatorIndex = [questionMarkIndex, hashIndex].filter((index) => index !== -1).reduce((lowest, index) => lowest === -1 ? index : Math.min(lowest, index), -1);
12764
+ const path = separatorIndex === -1 ? baseUrl : baseUrl.slice(0, separatorIndex);
12765
+ const tail = separatorIndex === -1 ? "" : baseUrl.slice(separatorIndex);
12766
+ const tailHashIndex = tail.indexOf("#");
12767
+ const fragment = tailHashIndex === -1 ? "" : tail.slice(tailHashIndex);
12768
+ const existingQuery = (tailHashIndex === -1 ? tail : tail.slice(0, tailHashIndex)).replace(/^\?/, "");
12769
+ const parameterName = (parameter) => parameter.split("=")[0].toLowerCase();
12770
+ const overriddenNames = new Set(extraQueryParams.map(parameterName));
12771
+ const mergedParams = [
12772
+ ...existingQuery.split("&").filter((parameter) => parameter && !overriddenNames.has(parameterName(parameter))),
12773
+ ...extraQueryParams
12774
+ ];
12775
+ const query = mergedParams.length > 0 ? `?${mergedParams.join("&")}` : "";
12776
+ return `${path}${pathSuffix}${query}${fragment}`;
12777
+ };
12760
12778
  const DEFAULT_VIEW_SIZE = "CoreField.LargeSizePreview";
12761
12779
  const FIELD_ALLOW_ATS_LINK = "AllowATSLink";
12762
12780
  const FIELD_DOC_CAPTION_LONG = "Document.CaptionLong";
@@ -12802,6 +12820,8 @@ function resolveAssetExtraFilters(selectedFacets) {
12802
12820
  function isCortexErrorResponse(response) {
12803
12821
  return response && typeof response === "object" && "ErrorCode" in response;
12804
12822
  }
12823
+ const POST_UNSUPPORTED_STATUSES = /* @__PURE__ */ new Set([405, 501]);
12824
+ const postUnsupportedOrigins = /* @__PURE__ */ new Set();
12805
12825
  function createId() {
12806
12826
  const cryptoApi = globalThis.crypto;
12807
12827
  if (cryptoApi == null ? void 0 : cryptoApi.randomUUID) {
@@ -12822,6 +12842,128 @@ function createId() {
12822
12842
  }
12823
12843
  return `${Date.now()}-${Math.random().toString(36).slice(2)}`;
12824
12844
  }
12845
+ function buildAssetLinkImageUrl({
12846
+ asset,
12847
+ extension,
12848
+ parameters,
12849
+ permanentLink,
12850
+ rawResponse,
12851
+ transformations,
12852
+ useSession
12853
+ }) {
12854
+ let baseImageUrl = permanentLink || rawResponse.imageUrl;
12855
+ let transformationPath = "";
12856
+ if (transformations && transformations.length > 0) {
12857
+ transformationPath += "/t/";
12858
+ }
12859
+ transformations == null ? void 0 : transformations.forEach(({ key, value }) => {
12860
+ if (key === TransformationAction.Resize) {
12861
+ const validTransformations = [
12862
+ ...[
12863
+ {
12864
+ key: "re_w_",
12865
+ value: value.width
12866
+ },
12867
+ {
12868
+ key: "re_h_",
12869
+ value: value.height
12870
+ }
12871
+ ].filter((item) => item.value !== void 0).map((item) => ({
12872
+ key: item.key,
12873
+ value: Math.round(Number(item.value))
12874
+ })),
12875
+ {
12876
+ key: "re_rm_",
12877
+ value: "stretch"
12878
+ }
12879
+ ];
12880
+ validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12881
+ transformationPath += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12882
+ });
12883
+ transformationPath += "/";
12884
+ }
12885
+ if (key === TransformationAction.Crop) {
12886
+ const validTransformations = [
12887
+ ...[
12888
+ {
12889
+ key: "c_w_",
12890
+ value: value.width
12891
+ },
12892
+ {
12893
+ key: "c_h_",
12894
+ value: value.height
12895
+ },
12896
+ {
12897
+ key: "c_x_",
12898
+ value: value.x
12899
+ },
12900
+ {
12901
+ key: "c_y_",
12902
+ value: value.y
12903
+ }
12904
+ ].filter((item) => item.value !== void 0).map((item) => ({
12905
+ key: item.key,
12906
+ value: Math.round(Number(item.value))
12907
+ })),
12908
+ {
12909
+ key: "c_whu_",
12910
+ value: "pixel"
12911
+ }
12912
+ ];
12913
+ validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12914
+ transformationPath += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12915
+ });
12916
+ transformationPath += "/";
12917
+ }
12918
+ if (key === TransformationAction.Rotate) {
12919
+ const validTransformations = [{
12920
+ key: "r_a_",
12921
+ value: value.rotation
12922
+ }].filter((item) => item.value !== void 0).map((item) => ({ key: item.key, value: Math.round(Number(item.value)) }));
12923
+ validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12924
+ transformationPath += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12925
+ });
12926
+ transformationPath += "/";
12927
+ }
12928
+ if (key === TransformationAction.Quality) {
12929
+ const validTransformations = [{
12930
+ key: "q_level_",
12931
+ value: value.quality
12932
+ }].filter((item) => item.value !== void 0).map((item) => ({ key: item.key, value: Math.round(Number(item.value)) }));
12933
+ validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12934
+ transformationPath += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12935
+ });
12936
+ transformationPath += "/";
12937
+ }
12938
+ if (key === TransformationAction.Metadata) {
12939
+ if (value.keepMetadata === true) {
12940
+ transformationPath += "fl_keep_metadata/";
12941
+ }
12942
+ }
12943
+ });
12944
+ const hasTransformations = Boolean(transformations && transformations.length > 0);
12945
+ if (hasTransformations) {
12946
+ transformationPath += `${asset.identifier}`;
12947
+ }
12948
+ if (!permanentLink) {
12949
+ const assetExtension = extension != null ? extension : asset.extension;
12950
+ const normalizedExtension = assetExtension.startsWith(".") ? assetExtension : `.${assetExtension}`;
12951
+ if (hasTransformations) {
12952
+ transformationPath += normalizedExtension;
12953
+ } else {
12954
+ const [basePath, baseTail] = baseImageUrl.split(/([?#].*)$/, 2);
12955
+ baseImageUrl = basePath.replace(/\.[^./]+$/, "") + normalizedExtension + (baseTail != null ? baseTail : "");
12956
+ }
12957
+ }
12958
+ const queryParams = [];
12959
+ parameters == null ? void 0 : parameters.forEach(({ key, value }) => {
12960
+ queryParams.push(`${encodeURIComponent(key.trim())}=${encodeURIComponent(value.trim())}`);
12961
+ });
12962
+ if (useSession) {
12963
+ queryParams.push(`UseSession=${encodeURIComponent(useSession)}`);
12964
+ }
12965
+ return appendPathAndQuery(baseImageUrl, transformationPath, queryParams);
12966
+ }
12825
12967
  function apiGetAssetLinks(_0) {
12826
12968
  return __async(this, arguments, function* ({
12827
12969
  assets,
@@ -12833,161 +12975,83 @@ function apiGetAssetLinks(_0) {
12833
12975
  transformations,
12834
12976
  useSession
12835
12977
  }) {
12978
+ var _a2;
12836
12979
  const getAssetLinkErrors = {};
12837
12980
  const isOnlyOneAssetSelected = assets.length === 1;
12838
12981
  let hasError = false;
12982
+ const origin2 = (_a2 = http.defaults.baseURL) != null ? _a2 : window.location.origin;
12839
12983
  try {
12840
- const settled = yield Promise.allSettled(assets.map((asset) => {
12841
- return http.request({
12842
- method: "GET",
12843
- params: {
12844
- ExtraFields: extraFields,
12845
- GenerateAssetUrl: !permanentLink,
12846
- Parameters: parameters,
12847
- Proxy: proxyPreference,
12848
- RecordId: asset.recordId,
12849
- UseSession: useSession || void 0
12850
- },
12851
- paramsSerializer: {
12852
- indexes: null
12853
- },
12854
- transformResponse: [
12855
- ...Array.isArray(http.defaults.transformResponse) ? http.defaults.transformResponse : [],
12856
- (rawResponse) => {
12857
- if (isCortexErrorResponse(rawResponse)) {
12858
- hasError = true;
12859
- if (isOnlyOneAssetSelected) {
12860
- if (getAssetLinkErrors[rawResponse.ErrorCode]) {
12861
- getAssetLinkErrors[rawResponse.ErrorCode].push(asset);
12862
- } else {
12863
- getAssetLinkErrors[rawResponse.ErrorCode] = [asset];
12864
- }
12865
- }
12866
- return {
12867
- imageUrl: asset.imageUrl
12868
- };
12869
- }
12870
- const sourceUrl = permanentLink || rawResponse.imageUrl;
12871
- const [sourcePath, sourceQuery] = sourceUrl.split("?", 2);
12872
- const mergedParams = new URLSearchParams(sourceQuery != null ? sourceQuery : "");
12873
- let imageUrl = sourcePath;
12874
- if (transformations && transformations.length > 0) {
12875
- imageUrl += "/t/";
12876
- }
12877
- transformations == null ? void 0 : transformations.forEach(({ key, value }) => {
12878
- if (key === TransformationAction.Resize) {
12879
- const validTransformations = [
12880
- ...[
12881
- {
12882
- key: "re_w_",
12883
- value: value.width
12884
- },
12885
- {
12886
- key: "re_h_",
12887
- value: value.height
12888
- }
12889
- ].filter((item) => item.value !== void 0).map((item) => ({
12890
- key: item.key,
12891
- value: Math.round(Number(item.value))
12892
- })),
12893
- {
12894
- key: "re_rm_",
12895
- value: "stretch"
12896
- }
12897
- ];
12898
- validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12899
- imageUrl += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12900
- });
12901
- imageUrl += "/";
12902
- }
12903
- if (key === TransformationAction.Crop) {
12904
- const validTransformations = [
12905
- ...[
12906
- {
12907
- key: "c_w_",
12908
- value: value.width
12909
- },
12910
- {
12911
- key: "c_h_",
12912
- value: value.height
12913
- },
12914
- {
12915
- key: "c_x_",
12916
- value: value.x
12917
- },
12918
- {
12919
- key: "c_y_",
12920
- value: value.y
12921
- }
12922
- ].filter((item) => item.value !== void 0).map((item) => ({
12923
- key: item.key,
12924
- value: Math.round(Number(item.value))
12925
- })),
12926
- {
12927
- key: "c_whu_",
12928
- value: "pixel"
12929
- }
12930
- ];
12931
- validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12932
- imageUrl += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12933
- });
12934
- imageUrl += "/";
12935
- }
12936
- if (key === TransformationAction.Rotate) {
12937
- const validTransformations = [{
12938
- key: "r_a_",
12939
- value: value.rotation
12940
- }].filter((item) => item.value !== void 0).map((item) => ({ key: item.key, value: Math.round(Number(item.value)) }));
12941
- validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12942
- imageUrl += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12943
- });
12944
- imageUrl += "/";
12945
- }
12946
- if (key === TransformationAction.Quality) {
12947
- const validTransformations = [{
12948
- key: "q_level_",
12949
- value: value.quality
12950
- }].filter((item) => item.value !== void 0).map((item) => ({ key: item.key, value: Math.round(Number(item.value)) }));
12951
- validTransformations.forEach(({ key: vKey, value: vValue }, index) => {
12952
- imageUrl += `${vKey}${vValue}${index < validTransformations.length - 1 ? "," : ""}`;
12953
- });
12954
- imageUrl += "/";
12955
- }
12956
- if (key === TransformationAction.Metadata) {
12957
- if (value.keepMetadata === true) {
12958
- imageUrl += "fl_keep_metadata/";
12959
- }
12960
- }
12961
- });
12962
- if (transformations && transformations.length > 0) {
12963
- imageUrl += `${asset.identifier}`;
12964
- }
12965
- if (!permanentLink) {
12966
- const assetExtension = extension != null ? extension : asset.extension;
12967
- const normalizedExtension = assetExtension.startsWith(".") ? assetExtension : `.${assetExtension}`;
12968
- imageUrl = imageUrl.replace(/\.[^./]+$/, "") + normalizedExtension;
12969
- }
12970
- parameters == null ? void 0 : parameters.forEach(({ key, value }) => {
12971
- mergedParams.set(key.trim(), value.trim());
12972
- });
12973
- if (useSession && !mergedParams.has("UseSession")) {
12974
- mergedParams.set("UseSession", useSession);
12975
- }
12976
- const finalQuery = mergedParams.toString();
12977
- if (finalQuery) {
12978
- imageUrl += `?${finalQuery}`;
12979
- }
12980
- return __spreadProps(__spreadValues({}, rawResponse), {
12981
- imageUrl
12982
- });
12984
+ const settled = yield Promise.allSettled(assets.map((asset) => __async(null, null, function* () {
12985
+ const requestBody = {
12986
+ GenerateAssetUrl: !permanentLink,
12987
+ Parameters: parameters,
12988
+ Proxy: proxyPreference,
12989
+ RecordId: asset.recordId
12990
+ };
12991
+ if (extraFields == null ? void 0 : extraFields.length) {
12992
+ requestBody.ExtraFields = extraFields;
12993
+ }
12994
+ const useSessionQuery = useSession ? `?${new URLSearchParams({ UseSession: useSession }).toString()}` : "";
12995
+ const attemptPost = !postUnsupportedOrigins.has(origin2);
12996
+ let rawResponse;
12997
+ if (attemptPost) {
12998
+ try {
12999
+ const postResult = yield http.request({
13000
+ data: requestBody,
13001
+ method: "POST",
13002
+ url: `${AssetApiEndpoint.GET_ASSET_LINK}${useSessionQuery}`,
13003
+ validateStatus: () => true
13004
+ });
13005
+ if (POST_UNSUPPORTED_STATUSES.has(postResult.status)) {
13006
+ postUnsupportedOrigins.add(origin2);
13007
+ } else {
13008
+ rawResponse = postResult.data;
12983
13009
  }
12984
- ],
12985
- url: AssetApiEndpoint.GET_ASSET_LINK
13010
+ } catch (e2) {
13011
+ }
13012
+ }
13013
+ if (rawResponse === void 0) {
13014
+ const getResult = yield http.request({
13015
+ method: "GET",
13016
+ params: __spreadProps(__spreadValues({}, requestBody), {
13017
+ UseSession: useSession || void 0
13018
+ }),
13019
+ paramsSerializer: {
13020
+ indexes: null
13021
+ },
13022
+ url: AssetApiEndpoint.GET_ASSET_LINK
13023
+ });
13024
+ rawResponse = getResult.data;
13025
+ }
13026
+ if (isCortexErrorResponse(rawResponse)) {
13027
+ hasError = true;
13028
+ if (isOnlyOneAssetSelected) {
13029
+ if (getAssetLinkErrors[rawResponse.ErrorCode]) {
13030
+ getAssetLinkErrors[rawResponse.ErrorCode].push(asset);
13031
+ } else {
13032
+ getAssetLinkErrors[rawResponse.ErrorCode] = [asset];
13033
+ }
13034
+ }
13035
+ return {
13036
+ imageUrl: asset.imageUrl
13037
+ };
13038
+ }
13039
+ const imageUrl = buildAssetLinkImageUrl({
13040
+ asset,
13041
+ extension,
13042
+ parameters,
13043
+ permanentLink,
13044
+ rawResponse,
13045
+ transformations,
13046
+ useSession
12986
13047
  });
12987
- }));
13048
+ return __spreadProps(__spreadValues({}, rawResponse), {
13049
+ imageUrl
13050
+ });
13051
+ })));
12988
13052
  const data = settled.flatMap((result) => {
12989
13053
  if (result.status === "fulfilled") {
12990
- return [result.value.data];
13054
+ return [result.value];
12991
13055
  }
12992
13056
  hasError = true;
12993
13057
  return [];