diff --git a/libs/blocks/caas-config/caas-config.js b/libs/blocks/caas-config/caas-config.js index d7b61448ea..d59fece7b7 100644 --- a/libs/blocks/caas-config/caas-config.js +++ b/libs/blocks/caas-config/caas-config.js @@ -1,3 +1,4 @@ +/* eslint-disable compat/compat */ /* eslint-disable react-hooks/exhaustive-deps */ /* global ClipboardItem */ import { @@ -13,10 +14,16 @@ import { getConfig, parseEncodedConfig, loadStyle, - utf8ToB64, } from '../../utils/utils.js'; import Accordion from '../../ui/controls/Accordion.js'; -import { defaultState, initCaas, loadCaasFiles, loadCaasTags, loadStrings } from '../caas/utils.js'; +import { + decodeCompressedString, + defaultState, + initCaas, + loadCaasFiles, + loadCaasTags, + loadStrings, +} from '../caas/utils.js'; import { Input as FormInput, Select as FormSelect } from '../../ui/controls/formControls.js'; import TagSelect from '../../ui/controls/TagSelector.js'; import MultiField from '../../ui/controls/MultiField.js'; @@ -36,13 +43,16 @@ const updateObj = (obj, defaultObj) => { const isValidUuid = (id) => /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(id); -const getHashConfig = () => { +const getHashConfig = async () => { const { hash } = window.location; if (!hash) return null; window.location.hash = ''; const encodedConfig = hash.startsWith('#') ? hash.substring(1) : hash; - return parseEncodedConfig(encodedConfig); + const config = encodedConfig.startsWith('~~') + ? await decodeCompressedString(encodedConfig.substring(2)) + : parseEncodedConfig(encodedConfig); + return config; }; const caasFilesLoaded = loadCaasFiles(); @@ -700,14 +710,16 @@ const reducer = (state, action) => { return { ...state, [action.prop]: action.value }; case 'RESET_STATE': return cloneObj(defaultState); + case 'SET_STATE': + return cloneObj(action.value); /* c8 ignore next 2 */ default: return state; } }; -const getInitialState = () => { - let state = getHashConfig(); +const getInitialState = async () => { + let state = await getHashConfig(); // /* c8 ignore next 2 */ if (!state) { const lsState = localStorage.getItem(LS_KEY); @@ -741,6 +753,34 @@ const saveStateToLocalStorage = (state) => { */ const fgKeyReplacer = (key, value) => (key === 'fetchCardsFromFloodgateTree' ? undefined : value); +const getEncodedObject = async (obj, replacer = null) => { + if (!window.CompressionStream) { + await import('../../deps/compression-streams-pollyfill.js'); + } + + const objToStream = (data) => new Blob( + [JSON.stringify(data, replacer)], + { type: 'text/plain' }, + ).stream(); + + const compressStream = async (stream) => new Response( + // eslint-disable-next-line no-undef + stream.pipeThrough(new CompressionStream('gzip')), + ); + + const responseToBuffer = async (res) => { + const blob = await res.blob(); + return blob.arrayBuffer(); + }; + + const b64encode = (buf) => btoa(String.fromCharCode(...new Uint8Array(buf))); + + const stream = objToStream(obj); + const compressedResponse = await compressStream(stream); + const buffer = await responseToBuffer(compressedResponse); + return b64encode(buffer); +}; + /* c8 ignore start */ const CopyBtn = () => { const { state } = useContext(ConfiguratorContext); @@ -756,22 +796,25 @@ const CopyBtn = () => { }, 2000); }; - const getUrl = () => { + const getUrl = async () => { const url = new URL(window.location.href); url.search = ''; - url.hash = utf8ToB64(JSON.stringify(state, fgKeyReplacer)); + const hashStr = await getEncodedObject(state, fgKeyReplacer); + // starts with ~~ to differentiate from old hash format + url.hash = `~~${hashStr}`; return url.href; }; - const copyConfig = () => { - setConfigUrl(getUrl()); + const copyConfig = async () => { + const url = await getUrl(); + setConfigUrl(url); if (!navigator?.clipboard) { setTempStatus(setIsError); return; } const link = document.createElement('a'); - link.href = getUrl(); + link.href = url; const dateStr = new Date().toLocaleString('us-EN', { weekday: 'long', year: 'numeric', @@ -782,7 +825,7 @@ const CopyBtn = () => { hour12: false, }); const collectionName = state.collectionName ? `- ${state.collectionName} ` : ''; - link.textContent = `Content as a Service ${collectionName}- ${dateStr}${state.doNotLazyLoad ? ' (no-lazy)' : ''}`; + link.textContent = `Content as a Service v2 ${collectionName}- ${dateStr}${state.doNotLazyLoad ? ' (no-lazy)' : ''}`; const blob = new Blob([link.outerHTML], { type: 'text/html' }); const data = [new ClipboardItem({ [blob.type]: blob })]; @@ -899,7 +942,7 @@ const idOverlayMO = () => { }; const Configurator = ({ rootEl }) => { - const [state, dispatch] = useReducer(reducer, getInitialState() || cloneObj(defaultState)); + const [state, dispatch] = useReducer(reducer, {}); const [isCaasLoaded, setIsCaasLoaded] = useState(false); const [strings, setStrings] = useState(); const [panels, setPanels] = useState([]); @@ -919,6 +962,15 @@ const Configurator = ({ rootEl }) => { }); }, []); + useEffect(() => { + const setInitialState = async () => { + const initialState = await getInitialState(); + dispatch({ type: 'SET_STATE', value: initialState }); + }; + + setInitialState(); + }, []); + useEffect(() => { if (state.showIds && !cardMutationObsv) { /* c8 ignore next */ diff --git a/libs/blocks/caas/caas.js b/libs/blocks/caas/caas.js index 2014e3f153..46832bc2e1 100644 --- a/libs/blocks/caas/caas.js +++ b/libs/blocks/caas/caas.js @@ -1,5 +1,17 @@ -import { initCaas, loadCaasFiles, loadStrings, fgHeaderValue } from './utils.js'; -import { parseEncodedConfig, createIntersectionObserver, getMetadata, getConfig, b64ToUtf8 } from '../../utils/utils.js'; +import { + decodeCompressedString, + fgHeaderValue, + initCaas, + loadCaasFiles, + loadStrings, +} from './utils.js'; +import { + b64ToUtf8, + createIntersectionObserver, + getConfig, + getMetadata, + parseEncodedConfig, +} from '../../utils/utils.js'; const ROOT_MARGIN = 1000; const P_CAAS_AIO = b64ToUtf8('MTQyNTctY2hpbWVyYS5hZG9iZWlvcnVudGltZS5uZXQvYXBpL3YxL3dlYi9jaGltZXJhLTAuMC4xL2NvbGxlY3Rpb24='); @@ -15,7 +27,10 @@ const getCaasStrings = (placeholderUrl) => new Promise((resolve) => { const loadCaas = async (a) => { const encodedConfig = a.href.split('#')[1]; - const state = parseEncodedConfig(encodedConfig); + // ~~ indicates the new compressed string format + const state = encodedConfig.startsWith('~~') + ? await decodeCompressedString(encodedConfig.substring(2)) + : parseEncodedConfig(encodedConfig); const [caasStrs] = await Promise.all([ getCaasStrings(state.placeholderUrl), diff --git a/libs/blocks/caas/utils.js b/libs/blocks/caas/utils.js index b7681899bf..3be4be0a26 100644 --- a/libs/blocks/caas/utils.js +++ b/libs/blocks/caas/utils.js @@ -1,3 +1,4 @@ +/* eslint-disable compat/compat */ /* eslint-disable no-underscore-dangle */ import { loadScript, loadStyle, getConfig as pageConfigHelper } from '../../utils/utils.js'; import { fetchWithTimeout } from '../utils/utils.js'; @@ -56,6 +57,35 @@ export const loadStrings = async ( } }; +export const decodeCompressedString = async (txt) => { + if (!window.DecompressionStream) { + await import('../../deps/compression-streams-pollyfill.js'); + } + const b64decode = (str) => { + const binaryStr = window.atob(str); + const bytes = new Uint8Array(new ArrayBuffer(binaryStr.length)); + binaryStr?.split('') + .forEach((c, i) => (bytes[i] = c.charCodeAt(0))); + return bytes; + }; + + const b64toStream = (b64) => new Blob([b64decode(b64)], { type: 'text/plain' }).stream(); + + const decompressStream = async (stream) => new Response( + // eslint-disable-next-line no-undef + stream.pipeThrough(new DecompressionStream('gzip')), + ); + + const responseToJSON = async (response) => { + const blob = await response.blob(); + return JSON.parse(await blob.text()); + }; + + const stream = b64toStream(txt); + const resp = await decompressStream(stream); + return responseToJSON(resp); +}; + export const loadCaasFiles = async () => { const version = new URL(document.location.href)?.searchParams?.get('caasver') || 'stable'; diff --git a/libs/deps/compression-streams-pollyfill.js b/libs/deps/compression-streams-pollyfill.js new file mode 100644 index 0000000000..1762131b8f --- /dev/null +++ b/libs/deps/compression-streams-pollyfill.js @@ -0,0 +1 @@ +!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){var t={},n=Uint8Array,r=Uint16Array,e=Int32Array,i=new n([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),a=new n([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),o=new n([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),s=function(t,n){for(var i=new r(31),a=0;a<31;++a)i[a]=n+=1<>1|(21845&d)<<1;p[d]=((65280&(g=(61680&(g=(52428&g)>>2|(13107&g)<<2))>>4|(3855&g)<<4))>>8|(255&g)<<8)>>1}var y=function(t,n,e){for(var i=t.length,a=0,o=new r(n);a>h]=u}else for(s=new r(i),a=0;a>15-t[a]);return s},w=new n(288);for(d=0;d<144;++d)w[d]=8;for(d=144;d<256;++d)w[d]=9;for(d=256;d<280;++d)w[d]=7;for(d=280;d<288;++d)w[d]=8;var b=new n(32);for(d=0;d<32;++d)b[d]=5;var m=/*#__PURE__*/y(w,9,0),M=/*#__PURE__*/y(w,9,1),z=/*#__PURE__*/y(b,5,0),k=/*#__PURE__*/y(b,5,1),x=function(t){for(var n=t[0],r=1;rn&&(n=t[r]);return n},A=function(t,n,r){var e=n/8|0;return(t[e]|t[e+1]<<8)>>(7&n)&r},S=function(t,n){var r=n/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(7&n)},T=function(t){return(t+7)/8|0},E=function(t,r,e){(null==r||r<0)&&(r=0),(null==e||e>t.length)&&(e=t.length);var i=new n(e-r);return i.set(t.subarray(r,e)),i},U=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],O=function(t,n,r){var e=new Error(n||U[t]);if(e.code=t,Error.captureStackTrace&&Error.captureStackTrace(e,O),!r)throw e;return e},D=function(t,r,e,s){var f=t.length,u=s?s.length:0;if(!f||r.f&&!r.l)return e||new n(0);var l=!e||2!=r.i,v=r.i;e||(e=new n(3*f));var p=function(t){var r=e.length;if(t>r){var i=new n(Math.max(2*r,t));i.set(e),e=i}},d=r.f||0,g=r.p||0,w=r.b||0,b=r.l,m=r.d,z=r.m,U=r.n,D=8*f;do{if(!b){d=A(t,g,1);var $=A(t,g+1,3);if(g+=3,!$){var B=t[(G=T(g)+4)-4]|t[G-3]<<8,L=G+B;if(L>f){v&&O(0);break}l&&p(w+B),e.set(t.subarray(G,L),w),r.b=w+=B,r.p=g=8*L,r.f=d;continue}if(1==$)b=M,m=k,z=9,U=5;else if(2==$){var C=A(t,g,31)+257,F=A(t,g+10,15)+4,I=C+A(t,g+5,31)+1;g+=14;for(var j=new n(I),q=new n(19),R=0;R>4)<16)j[R++]=G;else{var J=0,K=0;for(16==G?(K=3+A(t,g,3),g+=2,J=j[R-1]):17==G?(K=3+A(t,g,7),g+=3):18==G&&(K=11+A(t,g,127),g+=7);K--;)j[R++]=J}}var N=j.subarray(0,C),Q=j.subarray(C);z=x(N),U=x(Q),b=y(N,z,1),m=y(Q,U,1)}else O(1);if(g>D){v&&O(0);break}}l&&p(w+131072);for(var X=(1<>4;if((g+=15&J)>D){v&&O(0);break}if(J||O(2),_<256)e[w++]=_;else{if(256==_){Z=g,b=null;break}var tt=_-254;_>264&&(tt=A(t,g,(1<<(et=i[R=_-257]))-1)+h[R],g+=et);var nt=m[S(t,g)&Y],rt=nt>>4;if(nt||O(3),g+=15&nt,Q=c[rt],rt>3){var et=a[rt];Q+=S(t,g)&(1<D){v&&O(0);break}l&&p(w+131072);var it=w+tt;if(w>8},B=function(t,n,r){var e=n/8|0;t[e]|=r<<=7&n,t[e+1]|=r>>8,t[e+2]|=r>>16},L=function(t,e){for(var i=[],a=0;ap&&(p=s[a].s);var d=new r(p+1),g=C(i[c-1],d,0);if(g>e){a=0;var y=0,w=g-e,b=1<e))break;y+=b-(1<>=w;y>0;){var M=s[a].s;d[M]=0&&y;--a){var z=s[a].s;d[z]==e&&(--d[z],++y)}g=e}return{t:new n(d),l:g}},C=function(t,n,r){return-1==t.s?Math.max(C(t.l,n,r+1),C(t.r,n,r+1)):n[t.s]=r},F=function(t){for(var n=t.length;n&&!t[--n];);for(var e=new r(++n),i=0,a=t[0],o=1,s=function(t){e[i++]=t},f=1;f<=n;++f)if(t[f]==a&&f!=n)++o;else{if(!a&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(a),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(a);o=1,a=t[f]}return{c:e.subarray(0,i),n:n}},I=function(t,n){for(var r=0,e=0;e>8,t[i+2]=255^t[i],t[i+3]=255^t[i+1];for(var a=0;a4&&!V[o[P-1]];--P);var G,H,J,K,N=v+5<<3,Q=I(f,w)+I(h,b)+u,X=I(f,g)+I(h,x)+u+14+3*P+I(C,V)+2*C[16]+3*C[17]+7*C[18];if(c>=0&&N<=Q&&N<=X)return j(n,p,t.subarray(c,c+v));if($(n,p,1+(X15&&($(n,p,tt[q]>>5&127),p+=tt[q]>>12)}}else G=m,H=w,J=z,K=b;for(q=0;q255){var rt;B(n,p,G[257+(rt=nt>>18&31)]),p+=H[rt+257],rt>7&&($(n,p,nt>>23&31),p+=i[rt]);var et=31&nt;B(n,p,J[et]),p+=K[et],et>3&&(B(n,p,nt>>5&8191),p+=a[et])}else B(n,p,G[nt]),p+=H[nt]}return B(n,p,G[256]),p+H[256]},R=/*#__PURE__*/new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),V=/*#__PURE__*/new n(0),W=function(t,o,s,f,h,l){var c=l.z||t.length,p=new n(f+c+5*(1+Math.ceil(c/7e3))+h),d=p.subarray(f,p.length-h),g=l.l,y=7&(l.r||0);if(o){y&&(d[0]=l.r>>3);for(var w=R[o-1],b=w>>13,m=8191&w,M=(1<7e3||C>24576)&&(G>423||!g)){y=q(t,d,0,U,O,D,B,C,I,L-I,y),C=$=B=0,I=L;for(var H=0;H<286;++H)O[H]=0;for(H=0;H<30;++H)D[H]=0}var J=2,K=0,N=m,Q=W-P&32767;if(G>2&&V==S(L-Q))for(var X=Math.min(b,G)-1,Y=Math.min(32767,L),Z=Math.min(258,G);Q<=Y&&--N&&W!=P;){if(t[L+J]==t[L+J-Q]){for(var _=0;_J){if(J=_,K=Q,_>X)break;var tt=Math.min(Q,_-2),nt=0;for(H=0;Hnt&&(nt=et,P=rt)}}}Q+=(W=P)-(P=z[W])&32767}if(K){U[C++]=268435456|u[J]<<18|v[K];var it=31&u[J],at=31&v[K];B+=i[it]+a[at],++O[257+it],++D[at],F=L+J,++$}else U[C++]=t[L],++O[t[L]]}}for(L=Math.max(L,F);L=c&&(d[y/8|0]=g,ot=c),y=j(d,y+1,t.subarray(L,ot))}l.i=c}return E(p,0,f+T(y)+h)},P=/*#__PURE__*/function(){for(var t=new Int32Array(256),n=0;n<256;++n){for(var r=n,e=9;--e;)r=(1&r&&-306674912)^r>>>1;t[n]=r}return t}(),G=function(){var t=-1;return{p:function(n){for(var r=t,e=0;e>>8;t=r},d:function(){return~t}}},H=function(){var t=1,n=0;return{p:function(r){for(var e=t,i=n,a=0|r.length,o=0;o!=a;){for(var s=Math.min(o+2655,a);o>16),i=(65535&i)+15*(i>>16)}t=e,n=i},d:function(){return(255&(t%=65521))<<24|(65280&t)<<8|(255&(n%=65521))<<8|n>>8}}},J=function(t,r,e,i,a){if(!a&&(a={l:1},r.dictionary)){var o=r.dictionary.subarray(-32768),s=new n(o.length+t.length);s.set(o),s.set(t,o.length),t=s,a.w=o.length}return W(t,null==r.level?6:r.level,null==r.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(t.length)))):12+r.mem,e,i,a)},K=function(t,n,r){for(var e=t(),i=t.toString(),a=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),o=0;o>>=8},ot=function(t,n){var r=n.filename;if(t[0]=31,t[1]=139,t[2]=8,t[8]=n.level<2?4:9==n.level?2:0,t[9]=3,0!=n.mtime&&at(t,4,Math.floor(new Date(n.mtime||Date.now())/1e3)),r){t[3]=8;for(var e=0;e<=r.length;++e)t[e+10]=r.charCodeAt(e)}},st=function(t){31==t[0]&&139==t[1]&&8==t[2]||O(6,"invalid gzip data");var n=t[3],r=10;4&n&&(r+=2+(t[10]|t[11]<<8));for(var e=(n>>3&1)+(n>>4&1);e>0;e-=!t[r++]);return r+(2&n)},ft=function(t){var n=t.length;return(t[n-4]|t[n-3]<<8|t[n-2]<<16|t[n-1]<<24)>>>0},ht=function(t){return 10+(t.filename?t.filename.length+1:0)},ut=function(t,n){var r=n.level,e=0==r?0:r<6?1:9==r?3:2;if(t[0]=120,t[1]=e<<6|(n.dictionary&&32),t[1]|=31-(t[0]<<8|t[1])%31,n.dictionary){var i=H();i.p(n.dictionary),at(t,2,i.d())}},lt=function(t,n){return(8!=(15&t[0])||t[0]>>4>7||(t[0]<<8|t[1])%31)&&O(6,"invalid zlib data"),(t[1]>>5&1)==+!n&&O(6,"invalid zlib data: "+(32&t[1]?"need":"unexpected")+" dictionary"),2+(t[1]>>3&4)};function ct(t,n){return"function"==typeof t&&(n=t,t={}),this.ondata=n,t}var vt=/*#__PURE__*/function(){function t(t,r){if("function"==typeof t&&(r=t,t={}),this.ondata=r,this.o=t||{},this.s={l:0,i:32768,w:32768,z:32768},this.b=new n(98304),this.o.dictionary){var e=this.o.dictionary.subarray(-32768);this.b.set(e,32768-e.length),this.s.i=32768-e.length}}return t.prototype.p=function(t,n){this.ondata(J(t,this.o,0,0,this.s),n)},t.prototype.push=function(t,r){this.ondata||O(5),this.s.l&&O(4);var e=t.length+this.s.z;if(e>this.b.length){if(e>2*this.b.length-32768){var i=new n(-32768&e);i.set(this.b.subarray(0,this.s.z)),this.b=i}var a=this.b.length-this.s.z;a&&(this.b.set(t.subarray(0,a),this.s.z),this.s.z=this.b.length,this.p(this.b,!1)),this.b.set(this.b.subarray(-32768)),this.b.set(t.subarray(a),32768),this.s.z=t.length-a+32768,this.s.i=32766,this.s.w=32768}else this.b.set(t,this.s.z),this.s.z+=t.length;this.s.l=1&r,(this.s.z>this.s.w+8191||r)&&(this.p(this.b,r||!1),this.s.w=this.s.i,this.s.i-=2)},t}(),pt=/*#__PURE__*/function(){return function(t,n){it([X,function(){return[et,vt]}],this,ct.call(this,t,n),function(t){var n=new vt(t.data);onmessage=et(n)},6)}}();function dt(t,n){return J(t,n||{},0,0)}var gt=/*#__PURE__*/function(){function t(t,r){"function"==typeof t&&(r=t,t={}),this.ondata=r;var e=t&&t.dictionary&&t.dictionary.subarray(-32768);this.s={i:0,b:e?e.length:0},this.o=new n(32768),this.p=new n(0),e&&this.o.set(e)}return t.prototype.e=function(t){if(this.ondata||O(5),this.d&&O(4),this.p.length){if(t.length){var r=new n(this.p.length+t.length);r.set(this.p),r.set(t,this.p.length),this.p=r}}else this.p=t},t.prototype.c=function(t){this.s.i=+(this.d=t||!1);var n=this.s.b,r=D(this.p,this.s,this.o);this.ondata(E(r,n,this.s.b),this.d),this.o=E(r,this.s.b-32768),this.s.b=this.o.length,this.p=E(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(t,n){this.e(t),this.c(n)},t}(),yt=/*#__PURE__*/function(){return function(t,n){it([Q,function(){return[et,gt]}],this,ct.call(this,t,n),function(t){var n=new gt(t.data);onmessage=et(n)},7)}}();function wt(t,n){return D(t,{i:2},n&&n.out,n&&n.dictionary)}var bt=/*#__PURE__*/function(){function t(t,n){this.c=G(),this.l=0,this.v=1,vt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),this.l+=t.length,vt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=J(t,this.o,this.v&&ht(this.o),n&&8,this.s);this.v&&(ot(r,this.o),this.v=0),n&&(at(r,r.length-8,this.c.d()),at(r,r.length-4,this.l)),this.ondata(r,n)},t}(),mt=/*#__PURE__*/function(){return function(t,n){it([X,Y,function(){return[et,vt,bt]}],this,ct.call(this,t,n),function(t){var n=new bt(t.data);onmessage=et(n)},8)}}(),Mt=/*#__PURE__*/function(){function t(t,n){this.v=1,this.r=0,gt.call(this,t,n)}return t.prototype.push=function(t,r){if(gt.prototype.e.call(this,t),this.r+=t.length,this.v){var e=this.p.subarray(this.v-1),i=e.length>3?st(e):4;if(i>e.length){if(!r)return}else this.v>1&&this.onmember&&this.onmember(this.r-e.length);this.p=e.subarray(i),this.v=0}gt.prototype.c.call(this,r),this.s.f&&!this.s.l&&(this.v=T(this.s.p)+9,this.s={i:0},this.o=new n(0),this.p.length&&this.push(new n(0),r))},t}(),zt=/*#__PURE__*/function(){return function(t,n){var r=this;it([Q,Z,function(){return[et,gt,Mt]}],this,ct.call(this,t,n),function(t){var n=new Mt(t.data);n.onmember=function(t){return postMessage(t)},onmessage=et(n)},9,function(t){return r.onmember&&r.onmember(t)})}}(),kt=/*#__PURE__*/function(){function t(t,n){this.c=H(),this.v=1,vt.call(this,t,n)}return t.prototype.push=function(t,n){this.c.p(t),vt.prototype.push.call(this,t,n)},t.prototype.p=function(t,n){var r=J(t,this.o,this.v&&(this.o.dictionary?6:2),n&&4,this.s);this.v&&(ut(r,this.o),this.v=0),n&&at(r,r.length-4,this.c.d()),this.ondata(r,n)},t}(),xt=/*#__PURE__*/function(){return function(t,n){it([X,_,function(){return[et,vt,kt]}],this,ct.call(this,t,n),function(t){var n=new kt(t.data);onmessage=et(n)},10)}}(),At=/*#__PURE__*/function(){function t(t,n){gt.call(this,t,n),this.v=t&&t.dictionary?2:1}return t.prototype.push=function(t,n){if(gt.prototype.e.call(this,t),this.v){if(this.p.length<6&&!n)return;this.p=this.p.subarray(lt(this.p,this.v-1)),this.v=0}n&&(this.p.length<4&&O(6,"invalid zlib data"),this.p=this.p.subarray(0,-4)),gt.prototype.c.call(this,n)},t}(),St=/*#__PURE__*/function(){return function(t,n){it([Q,tt,function(){return[et,gt,At]}],this,ct.call(this,t,n),function(t){var n=new At(t.data);onmessage=et(n)},11)}}(),Tt="undefined"!=typeof TextDecoder&&/*#__PURE__*/new TextDecoder;try{Tt.decode(V,{stream:!0})}catch(t){}const Et=t=>class{constructor(){this.ondata=void 0,this.i=void 0,this.i=new t,this.i.ondata=(t,n)=>{this.ondata(null,t,n)}}push(t,n){try{this.i.push(t,n)}catch(t){this.ondata(t,null,n||!1)}}};let Ut=1;try{(new pt).terminate()}catch(O){Ut=0}const Ot=Ut?{gzip:mt,deflate:xt,"deflate-raw":pt}:{gzip:Et(bt),deflate:Et(kt),"deflate-raw":Et(vt)},Dt=Ut?{gzip:zt,deflate:St,"deflate-raw":yt}:{gzip:Et(Mt),deflate:Et(At),"deflate-raw":Et(gt)},$t=(t,n,r)=>class extends t{constructor(t){if(!arguments.length)throw new TypeError(`Failed to construct '${r}': 1 argument required, but only 0 present.`);const e=n[t];if(!e)throw new TypeError(`Failed to construct '${r}': Unsupported compression format: '${t}'`);let i,a=new e;super({start:t=>{a.ondata=(n,r,e)=>{n?t.error(n):r&&(t.enqueue(r),e&&(i?i():t.terminate()))}},transform:t=>{if(t instanceof ArrayBuffer)t=new Uint8Array(t);else{if(!ArrayBuffer.isView(t))throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'");t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}a.push(t)},flush:()=>new Promise(t=>{i=t,a.push(new Uint8Array(0),!0)})},{size:t=>0|t.byteLength,highWaterMark:65536})}},Bt="undefined"==typeof globalThis?"undefined"==typeof self?"undefined"==typeof global?{}:global:self:globalThis;var Lt;void 0===Bt.CompressionStream&&(Bt.CompressionStream=(Lt=TransformStream,$t(Lt,Ot,"CompressionStream"))),void 0===Bt.DecompressionStream&&(Bt.DecompressionStream=function(t){return $t(t,Dt,"DecompressionStream")}(TransformStream))}); diff --git a/test/blocks/caas-config/caas-config.test.html b/test/blocks/caas-config/caas-config.test.html index 2c9784beae..587e618f90 100644 --- a/test/blocks/caas-config/caas-config.test.html +++ b/test/blocks/caas-config/caas-config.test.html @@ -209,10 +209,16 @@ const tagUrlInput = findByLabel('Tags Url', configPanelEl); tagUrlInput.value = 'https://not.the.right.url/tags'; tagUrlInput.dispatchEvent(new Event('change')); - const errorEl = await waitForElement('.tool-error'); - expect(errorEl).to.not.be.null; - expect(errorEl.textContent).to.be.equal('Unable to fetch tags, loading backup tags. Please check tags url in the Advanced Panel'); - + const toolErrorEl = await waitForElement('.tool-error'); + expect(toolErrorEl).to.not.be.null; + + // Due to a race condition, the error message may be one of two things + let correctErrorMsg = false; + if (toolErrorEl.textContent === 'Tags url is not defined in the Advanced Panel' + || toolErrorEl.textContent === 'Unable to fetch tags, loading backup tags. Please check tags url in the Advanced Panel') { + correctErrorMsg = true; + } + expect(correctErrorMsg).to.be.true; const expectedConfig = cloneObj(defaultConfig); expect(config).to.eql(expectedConfig); }); @@ -285,7 +291,24 @@ copyBtn.click(); await delay(50); const copyTextArea = document.querySelector('.copy-text'); - expect(copyTextArea.value.split('#')[1]).to.equal('eyJhZGRpdGlvbmFsUmVxdWVzdFBhcmFtcyI6W10sImFuYWx5dGljc0NvbGxlY3Rpb25OYW1lIjoiIiwiYW5hbHl0aWNzVHJhY2tJbXByZXNzaW9uIjpmYWxzZSwiYW5kTG9naWNUYWdzIjpbXSwiYXV0b0NvdW50cnlMYW5nIjpmYWxzZSwiYm9va21hcmtJY29uU2VsZWN0IjoiIiwiYm9va21hcmtJY29uVW5zZWxlY3QiOiIiLCJjYXJkU3R5bGUiOiJoYWxmLWhlaWdodCIsImNhcmRUaXRsZUFjY2Vzc2liaWxpdHlMZXZlbCI6NiwiY29sbGVjdGlvbkJ0blN0eWxlIjoicHJpbWFyeSIsImNvbGxlY3Rpb25OYW1lIjoiIiwiY29sbGVjdGlvblRpdGxlIjoiIiwiY29sbGVjdGlvblNpemUiOiIiLCJjb250YWluZXIiOiIxMjAwTWF4V2lkdGgiLCJjb250ZW50VHlwZVRhZ3MiOltdLCJjb3VudHJ5IjoiY2Fhczpjb3VudHJ5L3VzIiwiY3VzdG9tQ2FyZCI6IiIsImN0YUFjdGlvbiI6Il9zZWxmIiwiZG9Ob3RMYXp5TG9hZCI6ZmFsc2UsImRpc2FibGVCYW5uZXJzIjpmYWxzZSwiZHJhZnREYiI6ZmFsc2UsImVuZHBvaW50Ijoid3d3LmFkb2JlLmNvbS9jaGltZXJhLWFwaS9jb2xsZWN0aW9uIiwiZW52aXJvbm1lbnQiOiIiLCJleGNsdWRlZENhcmRzIjpbXSwiZXhjbHVkZVRhZ3MiOltdLCJmYWxsYmFja0VuZHBvaW50IjoiI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HNlLCJzb3J0RGVmYXVsdCI6ImRhdGVEZXNjIiwic29ydEVuYWJsZVBvcHVwIjpmYWxzZSwic29ydEVuYWJsZVJhbmRvbVNhbXBsaW5nIjpmYWxzZSwic29ydEV2ZW50U29ydCI6ZmFsc2UsInNvcnRGZWF0dXJlZCI6ZmFsc2UsInNvcnRNb2RpZmllZEFzYyI6ZmFsc2UsInNvcnRNb2RpZmllZERlc2MiOmZhbHNlLCJzb3J0UmFuZG9tIjpmYWxzZSwic29ydFJlc2Vydm9pclBvb2wiOjEwMDAsInNvcnRSZXNlcnZvaXJTYW1wbGUiOjMsInNvcnRUaXRsZUFzYyI6ZmFsc2UsInNvcnRUaXRsZURlc2MiOmZhbHNlLCJzb3VyY2UiOlsiaGF3a3MiXSwidGFnc1VybCI6Ind3dy5hZG9iZS5jb20vY2hpbWVyYS1hcGkvdGFncyIsInRhcmdldEFjdGl2aXR5IjoiIiwidGFyZ2V0RW5hYmxlZCI6ZmFsc2UsInRoZW1lIjoibGlnaHRlc3QiLCJkZXRhaWxzVGV4dE9wdGlvbiI6ImRlZmF1bHQiLCJ0aXRsZUhlYWRpbmdMZXZlbCI6ImgzIiwidG90YWxDYXJkc1RvU2hvdyI6MTAsInVzZUxpZ2h0VGV4dCI6ZmFsc2UsInVzZU92ZXJsYXlMaW5rcyI6ZmFsc2UsImNvbGxlY3Rpb25CdXR0b25TdHlsZSI6InByaW1hcnkiLCJ1c2VySW5mbyI6W119') + + // Windows/Linux encodes the hash very slightly differently than OSX + // This is due to different header values in the zip output + // Note the start of each hash: + // Win: ~~H4sIAAAAAAAAA3 + // Osx: ~~H4sIAAAAAAAAE3 + + // This does not affect the decoded hash value, + // so either of these are valid hashes for the same content + + const windowsHash = '~~H4sIAAAAAAAAA3VVTXPbNhD9Lzw7sVK3PehmyfbEM3KsRvL0kOl0VsBSxAjEsgAomen0v3cXpPihKDfiLfbr7cPy3wy0NtGQA/sV/6kxxDV4KEM2//bXTQYMN9GosCRrUcm9L1BiNs+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gBwAA'; + let isCorrectHash = false; + const hash = copyTextArea.value.split('#')[1]; + if (hash === windowsHash || hash === osxHash) { + isCorrectHash = true; + } + expect(isCorrectHash).to.be.true; }); it('Clones an object', () => { @@ -305,13 +328,21 @@ expect(updateObj({ a: 'blah', d: 1234 }, allKeys)).to.eql({ a: 'blah', b: 2, c: [6, 7, 8], d: 1234 }); }); - it('Converts Base 64 to UTF-8', () => { + it('Converts Verson1 Hash Base 64 to UTF-8', async () => { const hash = 'eyJhZGRpdGlvbmFsUmVxdWVzdFBhcmFtcyI6W10sImFuYWx5dGljc0NvbGxlY3Rpb25OYW1lIjoiIiwiYW5hbHl0aWNzVHJhY2tJbXByZXNzaW9uIjpmYWxzZSwiYW5kTG9naWNUYWdzIjpbXSwiYXV0b0NvdW50cnlMYW5nIjpmYWxzZSwiYm9va21hcmtJY29uU2VsZWN0IjoiIiwiYm9va21hcmtJY29uVW5zZWxlY3QiOiIiLCJjYXJkU3R5bGUiOiJoYWxmLWhlaWdodCIsImNhcmRUaXRsZUFjY2Vzc2liaWxpdHlMZXZlbCI6NiwiY29sbGVjdGlvbkJ0blN0eWxlIjoicHJpbWFyeSIsImNvbGxlY3Rpb25OYW1lIjoiIiwiY29sbGVjdGlvblRpdGxlIjoiIiwiY29sbGVjdGlvblNpemUiOiIiLCJjb250YWluZXIiOiIxMjAwTWF4V2lkdGgiLCJjb250ZW50VHlwZVRhZ3MiOltdLCJjb3VudHJ5IjoiY2Fhczpjb3VudHJ5L3VzIiwiY3VzdG9tQ2FyZCI6IiIsImN0YUFjdGlvbiI6Il9ibGFuayIsImRvTm90TGF6eUxvYWQiOmZhbHNlLCJkaXNhYmxlQmFubmVycyI6ZmFsc2UsImRyYWZ0RGIiOmZhbHNlLCJlbmRwb2ludCI6Ind3dy5hZG9iZS5jb20vY2hpbWVyYS1hcGkvY29sbGVjdGlvbiIsImVudmlyb25tZW50IjoiIiwiZXhjbHVkZWRDYXJkcyI6W10sImV4Y2x1ZGVUYWdzIjpbXS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mZhbHNlLCJzb3J0RGVmYXVsdCI6ImRhdGVEZXNjIiwic29ydEVuYWJsZVBvcHVwIjpmYWxzZSwic29ydEVuYWJsZVJhbmRvbVNhbXBsaW5nIjpmYWxzZSwic29ydEV2ZW50U29ydCI6ZmFsc2UsInNvcnRGZWF0dXJlZCI6ZmFsc2UsInNvcnRNb2RpZmllZEFzYyI6ZmFsc2UsInNvcnRNb2RpZmllZERlc2MiOmZhbHNlLCJzb3J0UmFuZG9tIjpmYWxzZSwic29ydFJlc2Vydm9pclBvb2wiOjEwMDAsInNvcnRSZXNlcnZvaXJTYW1wbGUiOjMsInNvcnRUaXRsZUFzYyI6ZmFsc2UsInNvcnRUaXRsZURlc2MiOmZhbHNlLCJzb3VyY2UiOlsiaGF3a3MiXSwidGFnc1VybCI6Ind3dy5hZG9iZS5jb20vY2hpbWVyYS1hcGkvdGFncyIsInRhcmdldEFjdGl2aXR5IjoiIiwidGFyZ2V0RW5hYmxlZCI6ZmFsc2UsInRoZW1lIjoibGlnaHRlc3QiLCJkZXRhaWxzVGV4dE9wdGlvbiI6ImRlZmF1bHQiLCJ0aXRsZUhlYWRpbmdMZXZlbCI6ImgzIiwidG90YWxDYXJkc1RvU2hvdyI6MTAsInVzZUxpZ2h0VGV4dCI6ZmFsc2UsInVzZU92ZXJsYXlMaW5rcyI6ZmFsc2UsImNvbGxlY3Rpb25CdXR0b25TdHlsZSI6InByaW1hcnkiLCJ1c2VySW5mbyI6W119'; window.location.hash = hash; - const hashConfig = getHashConfig(); + const hashConfig = await getHashConfig(); expect(hashConfig.cardStyle).to.equal('half-height'); }); + it('Converts Verson2 Gzipped Hash Base 64 to UTF-8', async () => { + const hash = '~~H4sIAAAAAAAAE3VVTXPbNhD9Lzw7sVK3PehmyfbEM3KsRvL0kOl0VsBSxAjEsgAomen0v3cX/JSi3Ii32K+3D8t/M9DaREMO7Ff8p8YQ1+ChDNn82183GTDcRKPCkqxFJfe+QInZPMsmxq0HdXguK48h8I1snoMNKBf0ivZGbWHfx6sjLal20TcrcPvh5o7oUII/PCtyG5RMbYop/ubCxKLA601srNSS19Z+EKDDtyZavFdKytkZa2KzwiPabP4724dGFtH1ASpvOEuTTc1jnyOWAl+CG/N9wFwE49Dz8dMvs9kLvP9pdCw6E7q4bSoc2VAtE3xbAYR5d7ytgzjUIVK5lKba2BHuUzo+/s1E5Ixp+kJxBd+bFYEeuNQmwM7iAhxXEkbYQx4fdsMZna7IOKHzdDp9BE07/KiovFWFKdHDB6jM7dhlJh5H48mV6LoZ4LuytUYtVXYtddDYI2ezO5bH45iOPXOEWPszz9zYiP7xOERvgUVtrF6Dk/El+ZTAkhvMK1LQsWIxjxOcdccg+QE6yxOWid8zaFPQ6bGsYjNwtK9jTNP89Z3DFAh6CFMYjcsIz/r8PDZu3AUTlgVfwx77cffnWxRyLTRUJ31IuroSiKf6Qh6vCpWcbaTgRfdCBi670slfPL0K9sYlru6dKdPHEJWrkLczXnl0IqFRU6Pljxpc5Bclud0Ve9dBByT6R+NbwG2BJd6NjhYUFmSZ2Ddv28HzGqltDGv060TXbzdZQPCqeDJoe74DRml4QV5PVR4mlISnNNfrtld3zpcYn3qdTLBNynwGbSnKskxFjgby8QEi3gf1A/aAV8AX0iY3E46TAXPgsMyD7v1aQzuQNVWsjKlDi3/lTUvlBsrKmslWTRfkQW344wx96t7fGdhXdNlCj//QRpv2HMKA/kjGr4l4nJ9ms9mFIVXJU71r8XZXXwRO4EW62iv2+pYVcDqEjBUQWdqtZn6+v+ROJlf9HqPsz6OR550N2KXQo8hTlonZF5F/hrJlkZe6DVt8j69Vt2t0Nyd2kFI/82Zg4ru/TFbciUFUkjS2JXksQsZNVgdcSWiJNiRl8PWInlfAyrjDqKnJv4oXEV3ZAuzpn11O7Ztw/DeYPvr//gcuiyqz3gcAAA=='; + window.location.hash = hash; + // v2 getHashConfig is async + const hashConfig = await getHashConfig(); + expect(hashConfig.cardStyle).to.equal('full-card'); + }); + }); diff --git a/test/blocks/caas/caas.test.html b/test/blocks/caas/caas.test.html index 95d4122f64..6ba0810ec1 100644 --- a/test/blocks/caas/caas.test.html +++ b/test/blocks/caas/caas.test.html @@ -21,6 +21,13 @@ >My CaaS Collection

+

+ My CaaS Collection +

@@ -49,6 +56,11 @@ const ogFetch = window.fetch; beforeEach(() => { + document.getElementById('caas')?.remove(); + caasEl = null; + loadScript.reset(); + loadStyle.reset(); + window.fetch = stub().returns( new Promise((resolve) => { resolve({ @@ -87,6 +99,16 @@ expect(loadStyle.callCount).to.equal(1); expect(caasEl).to.equal(document.getElementById('caas')); }); + + it('it can use the v2 hash format', async () => { + const a = document.getElementById('v2-caaslink'); + await init(a); + await waitForElement('#caas'); + await delay(5); + expect(loadScript.callCount).to.equal(3); + expect(loadStyle.callCount).to.equal(1); + expect(caasEl).to.equal(document.getElementById('caas')); + }); }); }); diff --git a/tools/caas-import/parseCaasConfig.js b/tools/caas-import/parseCaasConfig.js index d9ac97cdf4..170d91c4cf 100644 --- a/tools/caas-import/parseCaasConfig.js +++ b/tools/caas-import/parseCaasConfig.js @@ -1,3 +1,4 @@ +/* eslint-disable compat/compat */ const defaultState = { analyticsCollectionName: '', analyticsTrackImpression: false, @@ -335,7 +336,6 @@ const convertToCsv = (obj) => { arr.unshift('"key","val"'); return arr.join('\n'); }; - const { getCaasConfigHash, getStringCsv } = (() => { let data; const getData = (configStr) => { @@ -349,9 +349,9 @@ const { getCaasConfigHash, getStringCsv } = (() => { getCaasConfigHash: (conf) => { const state = getData(conf); const configStr = JSON.stringify(state.configState); - const link = 'https://milo.adobe.com/tools/caas#'; - if (typeof window !== 'undefined' && window.btoa) { - return `${link}${utf8ToB64(configStr)}`; + const link = 'https://milo.adobe.com/tools/caas'; + if (window?.btoa) { + return `${link}#~~${utf8ToB64(configStr)}`; } // for node return `${link}${Buffer.from(configStr).toString('base64')}`;