@opengovsg/confetti 0.9.3 → 0.9.5

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.
@@ -1 +0,0 @@
1
- import{z as e}from"zod";const t=e.object({type:e.literal(`next`)}),n=e.object({type:e.literal(`end`)}),r=e.object({type:e.literal(`jump`),target:e.number({error:`Target question is required`})}),i=e.discriminatedUnion(`type`,[t,r,n]),a=e.object({type:e.literal(`value`),value:e.union([e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(2048)),e.number({error:`Value is required`})])}),o=e.object({type:e.literal(`binary-operator`),operator:e.union([e.literal(`equal`),e.literal(`not-equal`),e.literal(`greater`),e.literal(`greater-or-equal`),e.literal(`less`),e.literal(`less-or-equal`),e.literal(`contains`),e.literal(`not-contains`)]),value:a,target:i}),s=e.object({type:e.literal(`switch`),cases:e.array(o),default:i}),c=e.object({type:e.literal(`always`),target:i}),ee=e.discriminatedUnion(`type`,[c,s]),l=e.string().check(e.trim(),e.maxLength(2048),e.url({protocol:/^(https|mailto)/,error:`Link must start with https:// or mailto:`})),u=e.optional(e.string().check(e.trim(),e.maxLength(50))),te=e.object({value:e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(200)),label:e.optional(e.string().max(200)),description:e.optional(e.string().check(e.trim(),e.maxLength(200))),translationId:e.optional(e.cuid2().max(200))}),d=e.array(te).max(100).check(e.superRefine((e,t)=>{let n=new Set;for(let r of e)if(r.translationId!==void 0){if(n.has(r.translationId)){t.addIssue({code:`custom`,message:`Option translation ids must be unique within a question`});return}n.add(r.translationId)}})),f=e.nullable(e.object({label:e.string().check(e.trim(),e.minLength(1,{error:`Value is required`}),e.maxLength(200)),max:e.number().max(2e3),description:e.optional(e.string().check(e.trim(),e.maxLength(200)))})),p=e.optional(e.boolean()),ne=e.object({type:e.literal(`rating`),buttonLabel:u,shouldAutoProgress:p,scale:e.number().check(e.gte(2),e.lte(10)),labels:e.optional(e.object({lower:e.optional(e.pipe(e.string().check(e.trim(),e.maxLength(100)),e.transform(e=>e===``?void 0:e))),upper:e.optional(e.pipe(e.string().check(e.trim(),e.maxLength(100)),e.transform(e=>e===``?void 0:e)))})),display:e.optional(e.literal([`star`,`emoji`,`number`]))}),re=e.object({type:e.literal(`open-ended`),placeholder:e.optional(e.string().max(200)),buttonLabel:u,max:e.number().max(2e3)}),ie=e.object({type:e.literal(`single-select`),shouldAutoProgress:p,options:d,buttonLabel:u,editable:f}),ae=e.object({type:e.literal(`multi-select`),buttonLabel:u,options:d,editable:f,max:e.optional(e.number()),display:e.optional(e.literal([`checkbox`,`tag`]))}),m=e.object({type:e.literal(`statement`),buttonLabel:u,buttonUrl:e.optional(l)}),h=e.object({type:e.literal(`bug-report`),placeholder:e.optional(e.string().max(200)),buttonLabel:u,enableScreenshot:e.boolean(),enableRecording:e.boolean(),detailsLabel:e.string().check(e.trim(),e.minLength(1,{error:`Label is required`}),e.maxLength(128)),detailsPlaceholder:e.optional(e.string().max(200)),redactClasses:e.optional(e.array(e.string().max(128)).max(100))}),g=e.discriminatedUnion(`type`,[ne,ie,re,ae,m,h]),oe=e=>e.trim()===``?void 0:e,_=t=>e.string().max(t).transform(oe),v=_(50).optional(),se=_(128).optional(),y=e.object({label:_(200).optional(),description:_(200).optional()}),b=e.optional(e.object({label:_(200).optional(),description:_(200).optional()})),ce=e.object({type:e.literal(`rating`),buttonLabel:v,labels:e.optional(e.object({lower:_(100).optional(),upper:_(100).optional()}))}),le=e.object({type:e.literal(`open-ended`),placeholder:_(200).optional(),buttonLabel:v}),ue=e.object({type:e.literal(`single-select`),buttonLabel:v,options:e.optional(e.record(e.string(),y)),editable:b}),de=e.object({type:e.literal(`multi-select`),buttonLabel:v,options:e.optional(e.record(e.string(),y)),editable:b}),fe=e.object({type:e.literal(`statement`),buttonLabel:v}),pe=e.object({type:e.literal(`bug-report`),placeholder:_(200).optional(),buttonLabel:v,detailsLabel:se,detailsPlaceholder:_(200).optional()}),me=e.discriminatedUnion(`type`,[ce,le,ue,de,fe,pe]),x=`__CONFETTI_CHECKBOX_Others`,S=`__CONFETTI_RADIO_Others`,he=e.url({protocol:/^https$/,hostname:/^(?:app\.datadoghq\.(?:com|eu)|(?:app\.)?(?:us3|us5|ap1|ap2|uk1)\.datadoghq\.com|app\.ddog-gov\.com|(?:app\.)?us2\.ddog-gov\.com)$/}).max(2048),ge=e.optional(e.looseObject({userAgent:e.string().check(e.trim(),e.maxLength(1e3)),screenResolution:e.string().check(e.trim(),e.maxLength(100)),viewportSize:e.string().check(e.trim(),e.maxLength(100)),pageUrl:e.string().max(2048),pageTitle:e.string().check(e.trim(),e.maxLength(1e3)),referrer:e.string().max(2048),datadogTraceId:e.optional(e.string().max(128)),datadogSessionId:e.optional(e.string().max(128)),datadogSessionReplayLink:e.catch(e.optional(he),void 0)}).partial().catchall(e.optional(e.string().max(1e3))));e.cuid2().max(200);const C=e.looseObject({type:e.literal([0,1,2,3,4,5,6]),data:e.unknown(),timestamp:e.number(),delay:e.optional(e.number())});e.array(C);const w=e.array(C),T=e.string().max(10485760,{abort:!0}).check(e.refine(e=>{try{return w.safeParse(JSON.parse(e)).success}catch{return!1}},{error:`Invalid recording events`})),E=e.string().max(10485760,{abort:!0}).check(e.regex(/^data:image\/(png|jpeg|jpg|webp|gif);base64,[A-Za-z0-9+/]+=*$/,{error:`Invalid image data URL`})),D=t=>e.object({title:e.string().check(e.trim(),...t?[e.minLength(1,{error:`Title is required`})]:[],e.maxLength(256)),description:e.optional(e.string().check(e.trim(),e.maxLength(4096))),screenshotDataUrl:e.optional(E),recordingEventsJson:e.optional(T),metadata:ge});D(!0);const O=D(!1),k=(e,{required:t})=>D(t),A=e=>{if(!e)return!1;try{let t=JSON.parse(e);return Array.isArray(t)&&t.length>0}catch{return!1}},j=e=>!e.title.trim()&&!e.description?.trim()&&!e.screenshotDataUrl&&!A(e.recordingEventsJson),M=t=>e.preprocess(e=>typeof e==`string`&&/^(10|[1-9])$/.test(e)?Number(e):e,e.number({error:`Please select a rating`}).check(e.int(),e.gte(1),e.lte(t))),N=({scale:t},{required:n})=>{let r=M(t);return n?r:e.optional(r)},P=({maxLength:t},{required:n})=>e.string().check(e.trim(),...n?[e.minLength(1,{error:`This field is required`})]:[],e.maxLength(t??2e3,{error:({maximum:e})=>`Please enter less than ${e} characters`})),F=({options:t,editable:n},r)=>{let i=new Set(t.map(e=>e.value));return e.string({error:`Please select an option`}).check(e.trim(),e.superRefine((e,t)=>{if(i.has(e))return;let a=n?!e||e===r?`Please fill out the free text field`:e.length>n.max?`Please enter less than ${n.max} characters`:void 0:`Please select an option`;a&&t.addIssue({code:`custom`,message:a})}))},I=(t,{required:n})=>{let r=F(t,S);return n?r:e.optional(r)},L=(t,{required:n})=>{let{options:r,editable:i,max:a}=t,o=new Set(r.map(e=>e.value));return e.array(F(t,x)).check(...n?[e.minLength(1,{error:`Please select at least one option`})]:[],e.maxLength(a??r.length+ +!!i,{error:({maximum:e})=>`Please select less than ${e} options`}),e.refine(e=>e.filter(e=>!o.has(e)).length<=1,{error:`Please select an option`}))},_e=()=>e.optional(e.string().max(2048)),ve=(t,n)=>{switch(t.type){case`rating`:return N({scale:t.scale},n);case`open-ended`:return P({maxLength:t.max},n);case`single-select`:return I(t,n);case`multi-select`:return L(t,n);case`statement`:return _e();case`bug-report`:return k({},n);default:return e.never()}},R=[`en`,`zh`,`ms`,`ta`],z=e.enum(R),B=e.cuid2().max(200),ye=e.object({title:e.string().check(e.trim(),e.maxLength(500)),description:e.string().check(e.trim(),e.maxLength(1e3)),buttonText:e.string().check(e.trim(),e.maxLength(100))}),V=e.object({id:e.string(),title:e.string(),description:e.nullable(e.string()),position:e.number(),required:e.boolean(),properties:g,routingLogic:ee}),be=e.object({title:_(200).optional(),description:_(1e3).optional(),backButtonLabel:v,confirmation:e.optional(e.object({title:_(500).optional(),description:_(1e3).optional(),buttonText:_(100).optional()}))});e.partialRecord(z,be);const xe=e.object({title:_(500).optional(),description:_(1e3).optional(),properties:e.optional(me)});e.partialRecord(z,xe);const Se=e.object({title:e.string(),description:e.nullable(e.string()),questions:e.array(V),confirmation:ye,isBackNavigationAllowed:e.boolean(),backButtonLabel:e.nullable(e.string().check(e.trim(),e.maxLength(50)))});e.object({locale:e.optional(z)}),e.object({cursor:e.optional(e.string().check(e.minLength(1),e.maxLength(100))),limit:e.optional(e.number().check(e.int(),e.gte(1),e.lte(100)))});const H=e.object({id:e.string(),title:e.string(),description:e.nullable(e.string()),status:e.enum([`active`,`inactive`]),createdAt:e.date(),updatedAt:e.date()});e.object({data:e.array(H),nextCursor:e.nullable(e.string()),limit:e.number(),links:e.object({self:e.string(),next:e.nullable(e.string())})}),e.object({surveyId:B});const Ce=V;e.object({data:e.object({...H.shape,questions:e.array(Ce)})}),e.object({surveyId:B,responseId:e.union([e.cuid2().max(200),e.uuid()])});const we=e.catch(e.object({type:e.enum([`embedded`,`popover`,`modal`]),version:e.string().check(e.trim(),e.minLength(1),e.maxLength(50)),build:e.string().check(e.trim(),e.minLength(1),e.maxLength(50))}).partial(),{}),U=e.record(e.string().trim().min(1).max(200),e.union([e.string().check(e.trim(),e.maxLength(2e3)),e.number(),e.array(e.string().check(e.trim(),e.maxLength(2e3))).check(e.maxLength(1024)),O])),W=1e3,G=e.string().check(e.trim(),e.maxLength(W)),Te=e.record(G,G),K=e.string().trim().min(1).max(W),q=e.discriminatedUnion(`code`,[e.object({code:e.literal(`metadata_value_truncated`),key:K}).strict(),e.object({code:e.literal(`metadata_value_invalid`),key:K}).strict(),e.object({code:e.literal(`metadata_key_invalid`),position:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_key_duplicate`),key:K}).strict(),e.object({code:e.literal(`metadata_entry_limit`),droppedCount:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_container_invalid`)}).strict(),e.object({code:e.literal(`metadata_warning_details_omitted`),count:e.number().int().positive().max(2**53-1)}).strict(),e.object({code:e.literal(`metadata_warning_report_invalid`)}).strict()]),Ee=e.object({metadata:e.array(q).min(1).max(20)}).strict(),De=e.object({metadata:e.array(q).min(1)}).strict(),J=(e,t)=>Math.min(2**53-1,e+t),Y=e=>{let t=[],n=0;for(let r of e)r.code===`metadata_warning_details_omitted`?n=J(n,r.count):t.push(r);let r=n>0||t.length>20?19:20,i=t.slice(0,r);return n=J(n,t.length-i.length),n>0?[...i,{code:`metadata_warning_details_omitted`,count:n}]:i},Oe=e=>{let t=Y(e);return t.length>0?{metadata:t}:void 0},ke=e=>{if(e===void 0)return[];let t=De.safeParse(e);return t.success?Y(t.data.metadata):[{code:`metadata_warning_report_invalid`}]},Ae=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Reflect.getPrototypeOf(e);return t===Object.prototype||t===null},je=e=>{if(e===void 0)return{metadata:{},warnings:[]};if(!Ae(e))return{metadata:{},warnings:[{code:`metadata_container_invalid`}]};let t=new Map,n=[],r=0;for(let[i,[a,o]]of Object.entries(e).entries()){let e=a.trim();if(e.length===0||e.length>1e3){n.push({code:`metadata_key_invalid`,position:i+1});continue}if(typeof o!=`string`){n.push({code:`metadata_value_invalid`,key:e});continue}if(t.has(e)){n.push({code:`metadata_key_duplicate`,key:e});continue}if(t.size>=20){r+=1;continue}let s=o.trim(),c=s.length>1e3?`${s.slice(0,W-11)}[truncated]`:s;c!==s&&n.push({code:`metadata_value_truncated`,key:e}),t.set(e,c)}return r>0&&n.push({code:`metadata_entry_limit`,droppedCount:r}),{metadata:Object.fromEntries(t),warnings:Y(n)}},X=({metadata:e,warnings:t})=>{let n=je(e);return{metadata:n.metadata,warnings:Oe([...n.warnings,...ke(t)])}};Te.check(e.refine(e=>Object.keys(e).length<=20,`At most 20 metadata entries are allowed.`)),e.object({respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200)),data:U,metadata:e.unknown().optional(),warnings:e.unknown().optional(),telemetry:e.optional(we)}).transform(e=>{let{metadata:t,warnings:n,...r}=e,{metadata:i,warnings:a}=X({metadata:t,warnings:n});return{...r,metadata:i,...a&&{warnings:a}}});const Me=e.object({id:e.string(),createdAt:e.date(),warnings:e.optional(Ee)});e.object({surveyId:B,respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200))}),e.object({surveyId:B,respondent:e.string().check(e.trim(),e.minLength(1),e.maxLength(200))}),e.object({surveyId:B});const Z=e.object({lastRespondedAt:e.nullable(e.union([e.iso.datetime(),e.date()])),lastViewedAt:e.nullable(e.union([e.iso.datetime(),e.date()])),lastDismissedAt:e.nullable(e.union([e.iso.datetime(),e.date()]))});e.object({type:e.enum([`view`,`dismiss`])}),e.object({}),e.object({surveyId:B}),e.object({respondent:e.optional(e.string().check(e.trim(),e.minLength(1),e.maxLength(200))),after:e.optional(e.iso.datetime({offset:!0,local:!0})),before:e.optional(e.iso.datetime({offset:!0,local:!0})),cursor:e.optional(e.string().check(e.minLength(1),e.maxLength(100))),limit:e.optional(e.number().check(e.int(),e.gte(1),e.lte(100)))});const Ne=e.object({id:e.string(),respondent:e.string(),data:U,clientMetadata:e.record(e.string(),e.string()),createdAt:e.date()});e.object({data:e.array(Ne),nextCursor:e.nullable(e.string()),limit:e.number(),links:e.object({self:e.string(),next:e.nullable(e.string())})});const Q=e.number().check(e.int(),e.gte(0));e.object({data:e.object({totalViews:Q,uniqueViewers:Q,totalDismissals:Q,uniqueDismissers:Q,totalResponses:Q,uniqueResponders:Q})}),e.object({questionIds:e.array(e.string().max(200)).check(e.minLength(1)),timeRange:e.union([e.enum([`last-7-days`,`last-30-days`]),e.string().check(e.regex(/^q[1-4]-\d{4}$/)),e.string().check(e.regex(/^custom_\d{4}-\d{2}-\d{2}_\d{4}-\d{2}-\d{2}$/))])});const $=e.record(e.string(),e.record(e.string(),e.number()));e.object({data:e.object({current:$,previousQuarter:e.nullable($)})});export{R as a,x as c,Se as i,S as l,Me as n,ve as o,X as r,j as s,Z as t,l as u};