diff --git a/sdks/npm/src/cf/on-ua-applicator.ts b/sdks/npm/src/cf/on-ua-applicator.ts index 785059f..a1ac740 100644 --- a/sdks/npm/src/cf/on-ua-applicator.ts +++ b/sdks/npm/src/cf/on-ua-applicator.ts @@ -8,8 +8,12 @@ export default class UATransformApplicator implements HTMLRewriterElementConten } static serializeOperation(operation: Experimentation.Operations, args: any[]) { - if (operation === Experimentation.Operations.CustomJs) { - return [operation, `$=>{${args[0]}}`]; + switch (operation) { + case Experimentation.Operations.CustomJs: + return [operation, `$=>{${args[0]}}`]; + case Experimentation.Operations.Redirect: + // In case of a redirect, we use a CustomJs operation to rewrite location. + return [Experimentation.Operations.CustomJs, `$=>{window.location.href="${JSON.stringify(args[0])}"}`]; } return [operation, ...args.map(arg => JSON.stringify(arg))]; } diff --git a/sdks/npm/src/cf/pre-ua-applicator.ts b/sdks/npm/src/cf/pre-ua-applicator.ts index 693c6c9..82f0330 100644 --- a/sdks/npm/src/cf/pre-ua-applicator.ts +++ b/sdks/npm/src/cf/pre-ua-applicator.ts @@ -37,5 +37,11 @@ export default class PreUATransformApplicator implements HTMLRewriterElementCont } // Handle any complex operations that involves multiple CF operations. + switch (this.op) { + case Experimentation.Operations.Redirect: + const [url, code] = this.args; + Response.redirect(url, code); + break; + } } } \ No newline at end of file diff --git a/specs/EXPLAINER.md b/specs/EXPLAINER.md index 210deb5..40f6211 100644 --- a/specs/EXPLAINER.md +++ b/specs/EXPLAINER.md @@ -109,25 +109,22 @@ where each field can be defined as follows
- -Arguments: - -`code`: Javascript code serialized as a string. The applicator code will call this code as a function ($) => code, $ referring to the element selected. +
- -Arguments: +
+
`content`: HTML markup
- -Arguments: - -
-`content`: HTML markup +
- -Arguments: +
`content`: HTML markup
+
`content`: HTML markup
- -Arguments: - -
+
- -Arguments: - -
-none. -
- -Arguments: - -
+
+ `value`: Value to be set on the attribute.
- -Arguments: - -
+