Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions notNeededPackages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8743,6 +8743,10 @@
"libraryName": "zookeeper",
"asOfVersion": "4.6.0"
},
"zoomist": {
"libraryName": "zoomist",
"asOfVersion": "2.0.1"
},
"zrender": {
"libraryName": "zrender",
"asOfVersion": "5.0.0"
Expand Down
37 changes: 35 additions & 2 deletions types/akamai-edgeworkers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,15 @@ declare module "http-request" {
* - `headers` Request headers to specify.
* - `body` The request payload.
* - `timeout` The request timeout, in milliseconds.
* - `preserveEncoding` Whether to preserve the original encoding of the response body. Default is false and
* response bodies are decoded.
*/
function httpRequest(url: string, options?: {
method?: string | undefined;
headers?: { [others: string]: string | string[] } | undefined;
body?: RequestBody | undefined;
timeout?: number | undefined;
preserveEncoding?: boolean | undefined;
}): Promise<HttpResponse>;

/**
Expand All @@ -1003,12 +1006,14 @@ declare module "http-request" {
/**
* Returns a Promise that resolves to a string containing the
* response body. Note that the body is buffered in memory.
* Will automatically decode recognized content-encodings even if `preserveEncoding:true` was specified
*/
text(): Promise<string>;

/**
* Parses the body of the response as JSON. The response is buffered
* and `JSON.parse()` is run on the text.
* Will automatically decode recognized content-encodings even if `preserveEncoding:true` was specified
*/
json(): Promise<any>;
}
Expand All @@ -1020,7 +1025,7 @@ declare module "http-request" {
* [WHATWG Streams Standard]: https://streams.spec.whatwg.org
*/
declare module "streams" {
interface ReadableStream<R = any> extends EW.ReadableStreamEW {
interface ReadableStream<R = any> extends EW.ReadableStreamEW<R> {
}

const ReadableStream: {
Expand All @@ -1032,7 +1037,7 @@ declare module "streams" {
new<R = any>(underlyingSource?: EW.UnderlyingSource<R>, strategy?: EW.QueuingStrategy<R>): ReadableStream<R>;
};

interface WritableStream<R = any> extends EW.WritableStreamEW {
interface WritableStream<W = any> extends EW.WritableStreamEW<W> {
}

const WritableStream: {
Expand All @@ -1043,6 +1048,13 @@ declare module "streams" {
interface ReadableStreamDefaultController<R = any> extends EW.ReadableStreamDefaultControllerEW {
}

type BufferSource = ArrayBufferView | ArrayBuffer;

interface GenericTransformStream<R = any, W = any> {
readonly readable: ReadableStream<R>;
readonly writable: WritableStream<W>;
}

interface TransformStream<I = any, O = any> {
readonly readable: ReadableStream<O>;
readonly writable: WritableStream<I>;
Expand Down Expand Up @@ -1104,9 +1116,30 @@ declare module "streams" {
new(options: { highWaterMark: number }): ByteLengthQueuingStrategy;
};

type CompressionFormat = "brotli" | "deflate" | "deflate-raw" | "gzip";

interface CompressionStream extends GenericTransformStream<Uint8Array, BufferSource> {
}

const CompressionStream: {
prototype: CompressionStream;
new(format: CompressionFormat): CompressionStream;
};

interface DecompressionStream extends GenericTransformStream<Uint8Array, BufferSource> {
}

const DecompressionStream: {
prototype: DecompressionStream;
new(format: CompressionFormat): DecompressionStream;
};

export {
ByteLengthQueuingStrategy,
CompressionFormat,
CompressionStream,
CountQueuingStrategy,
DecompressionStream,
ReadableStream,
ReadableStreamDefaultController,
TransformStream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function onClientRequest(request: EW.IngressClientRequest) {
testHeaders(request.getHeaders());

// Exercise EW.ClientRequest.getVariable()
request.respondWith(505, [], "Missing get-variable-present");
request.getVariable("variableName");

request.respondWith(505, { no: "bad" }, "Expected var to be missing");

Expand Down
1 change: 1 addition & 0 deletions types/akamai-edgeworkers/test/http-request-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ httpRequest("url", {});
httpRequest("url", { headers: { "Accept-Encoding": "zz" } });
httpRequest("url", { method: "POST", body: "post payload" });
httpRequest("url", { timeout: 9 });
httpRequest("url", { preserveEncoding: true });
httpRequest("url", {
method: "POST",
body: new ReadableStream({
Expand Down
36 changes: 35 additions & 1 deletion types/akamai-edgeworkers/test/stream.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
import { createResponse } from "create-response";
import { HtmlRewritingStream } from "html-rewriter";
import { httpRequest } from "http-request";
import { CompressionStream, DecompressionStream } from "streams";
import { TextDecoderStream } from "text-encode-transform";

const TEMPLATE_URL = "http://techjam.edgekey-staging.net/templates/index1MB.html";

export function responseProviderBufferedResponse(request: EW.ResponseProviderRequest) {
return httpRequest("http://techjam.edgekey-staging.net/templates/index1MB.html").then(response => {
return httpRequest(TEMPLATE_URL).then(response => {
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
const body = "";
return reader.read().then(function accumulate({ done, value }) {
return createResponse(response.status, {}, body);
});
});
}

export function responseProviderCompressedResponse(request: EW.ResponseProviderRequest) {
return httpRequest(TEMPLATE_URL).then(response => {
let compressed = response.body.pipeThrough(new CompressionStream("gzip"));
return createResponse(response.status, { "content-encoding": "gzip" }, compressed);
});
}

export function responseProviderRewriteCompressed(request: EW.ResponseProviderRequest) {
const rewriter = new HtmlRewritingStream();
rewriter.onElement("head", el => {
el.append("<script src=\"/beaconTracker.js\"></script>");
});

return httpRequest(TEMPLATE_URL, { preserveEncoding: true }).then(response => {
let stream = response.body;
const contentEncoding = response.getHeader("content-encoding")?.[0];
const decompress = contentEncoding == "gzip";

const inject = request.getVariable("PMUSER_INJECT_BEACON");
if (inject === "true") {
stream = decompress ? stream.pipeThrough(new DecompressionStream("gzip")) : stream;
stream = stream.pipeThrough(rewriter);
stream = stream.pipeThrough(new CompressionStream("gzip"));
return createResponse(response.status, { "content-encoding": "gzip" }, stream);
} else {
return createResponse(response.status, {}, stream);
}
});
}
97 changes: 97 additions & 0 deletions types/googlepay/googlepay-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,103 @@ function getGooglePaymentDataConfiguration(): google.payments.api.PaymentDataReq
};
}

function getGoogleRecurringPaymentDataConfiguration(): google.payments.api.PaymentDataRequest {
const recurringTransactionInfo: google.payments.api.RecurringTransactionInfo = {
currencyCode: "USD",
countryCode: "US",
immediateTotalPrice: "0.00",
managementUrl: "https://example.com/account",
immediateDisplayItems: [{
label: "Due today",
type: "LINE_ITEM",
price: "0.00",
status: "FINAL",
}],
recurrenceItems: [{
label: "Monthly subscription",
priceStatus: "FINAL",
recurrencePeriod: "MONTH",
recurrencePeriodCount: 1,
price: "9.99",
}],
introductoryPeriodInfo: {
introductoryPeriodEndDateTime: "2026-09-30T23:59:59Z",
label: "Free trial",
totalPrice: "0.00",
},
};

return {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods,
merchantInfo: {
merchantId: "01234567890123456789",
merchantName: "Example Merchant",
},
recurringTransactionInfo,
};
}

function getGoogleDeferredPaymentDataConfiguration(): google.payments.api.PaymentDataRequest {
const deferredTransactionInfo: google.payments.api.DeferredTransactionInfo = {
currencyCode: "USD",
countryCode: "US",
immediateTotalPrice: "0.00",
managementUrl: "https://example.com/bookings",
immediateDisplayItems: [{
label: "Due today",
type: "LINE_ITEM",
price: "0.00",
status: "FINAL",
}],
billingDateTime: "2026-09-30T23:59:59Z",
priceStatus: "FINAL",
label: "Pay later",
price: "49.99",
};

return {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods,
merchantInfo: {
merchantId: "01234567890123456789",
merchantName: "Example Merchant",
},
deferredTransactionInfo,
};
}

function getGoogleAutomaticReloadPaymentDataConfiguration(): google.payments.api.PaymentDataRequest {
const automaticReloadTransactionInfo: google.payments.api.AutomaticReloadTransactionInfo = {
currencyCode: "USD",
countryCode: "US",
immediateTotalPrice: "10.00",
managementUrl: "https://example.com/balance",
immediateDisplayItems: [{
label: "Reload today",
type: "LINE_ITEM",
price: "10.00",
status: "FINAL",
}],
minimumBalanceAmount: "5.00",
reloadAmount: "25.00",
label: "Transit card reload",
};

return {
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods,
merchantInfo: {
merchantId: "01234567890123456789",
merchantName: "Example Merchant",
},
automaticReloadTransactionInfo,
};
}

function prefetchGooglePaymentData() {
const client = getGooglePaymentsClient();
client.prefetchPaymentData(getGooglePaymentDataConfiguration());
Expand Down
Loading