@empiricalrun/playwright-utils 0.68.1 → 0.70.0
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.
- package/CHANGELOG.md +37 -0
- package/dist/api-worker-client.d.ts +12 -1
- package/dist/api-worker-client.d.ts.map +1 -1
- package/dist/api-worker-client.js +24 -0
- package/dist/email.d.ts +48 -0
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +56 -1
- package/dist/generated/api-worker-openapi.d.ts +2428 -1853
- package/dist/generated/api-worker-openapi.d.ts.map +1 -1
- package/dist/inbox-client.d.ts +2 -2
- package/dist/inbox-client.d.ts.map +1 -1
- package/dist/inbox-client.js +17 -29
- package/dist/reporter/ibr-utils.d.ts +1 -1
- package/dist/reporter/ibr-utils.d.ts.map +1 -1
- package/dist/reporter/ibr-utils.js +5 -11
- package/dist/reporter/incremental-blob-reporter.d.ts +1 -0
- package/dist/reporter/incremental-blob-reporter.d.ts.map +1 -1
- package/dist/reporter/incremental-blob-reporter.js +13 -3
- package/dist/reporter/lifecycle-events.d.ts +3 -3
- package/dist/reporter/lifecycle-events.d.ts.map +1 -1
- package/dist/reporter/lifecycle-events.js +11 -12
- package/dist/reporter/parity-utils.d.ts +1 -1
- package/dist/reporter/parity-utils.d.ts.map +1 -1
- package/dist/reporter/parity-utils.js +14 -3
- package/dist/reporter/util.d.ts +1 -1
- package/dist/reporter/util.d.ts.map +1 -1
- package/dist/reporter/util.js +7 -7
- package/dist/test/index.d.ts +7 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +11 -3
- package/dist/test/scoped-http-headers.d.ts +20 -0
- package/dist/test/scoped-http-headers.d.ts.map +1 -0
- package/dist/test/scoped-http-headers.js +177 -0
- package/dist/test/scoped-http-headers.spec.d.ts +2 -0
- package/dist/test/scoped-http-headers.spec.d.ts.map +1 -0
- package/dist/test/scoped-http-headers.spec.js +81 -0
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +20 -53
- package/docs/fixtures.md +25 -0
- package/package.json +6 -6
- package/playwright.config.ts +5 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/upstream-oracle/README.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @empiricalrun/playwright-utils
|
|
2
2
|
|
|
3
|
+
## 0.70.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0d3a87c: Add EmailClient.sendEmail to send email with attachments to allowed recipients, and messageId on received emails for threaded replies
|
|
8
|
+
- 5d0fb97: feat: scopedHTTPHeaders option on customContextPageProvider sends headers only to listed hosts, per request and redirect hop
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 4ddfc3b: Stop tagging the no-onBegin skip as a reporter failure when a shard is interrupted before tests start
|
|
13
|
+
- 7f076ff: move html-report-utils from reporter into r2-uploader
|
|
14
|
+
- Updated dependencies [7f076ff]
|
|
15
|
+
- Updated dependencies [4a5d72f]
|
|
16
|
+
- @empiricalrun/r2-uploader@0.11.6
|
|
17
|
+
- @empiricalrun/reporter@0.30.5
|
|
18
|
+
- @empiricalrun/cua@0.6.0
|
|
19
|
+
|
|
20
|
+
## 0.69.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies [a0d9b35]
|
|
25
|
+
- @empiricalrun/reporter@0.30.4
|
|
26
|
+
|
|
27
|
+
## 0.69.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- 395958b: EmailClient defaults to the inbox provider, including for a bare emailId; only a full \*.mailosaur.net emailId without a provider still uses Mailosaur
|
|
32
|
+
- 2cc6f8d: EmailClient and inbox webhook captures use the typed inbox APIs instead of the inbox proxy, and waitForEmail names the address when another project has claimed it
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- 983ef2c: IncrementalBlobReporter embeds path attachments in its zip when no uploader is configured, so merged reports keep their bytes
|
|
37
|
+
- @empiricalrun/cua@0.6.0
|
|
38
|
+
- @empiricalrun/reporter@0.30.3
|
|
39
|
+
|
|
3
40
|
## 0.68.1
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { type Client } from "openapi-fetch";
|
|
2
2
|
import type { components, paths } from "./generated/api-worker-openapi";
|
|
3
3
|
type OpenApiWorkerClient = Client<paths>;
|
|
4
|
-
type ProviderProxyPath = "/api/
|
|
4
|
+
type ProviderProxyPath = "/api/mailosaur/proxy" | "/api/webhook-site/proxy";
|
|
5
5
|
export type ProviderProxyRequest = components["schemas"]["PlaywrightUtilsProxyRequest"];
|
|
6
6
|
export type ProviderProxyResponse = components["schemas"]["PlaywrightUtilsProxyResponse"];
|
|
7
7
|
export type TwoCaptchaProxyRequest = components["schemas"]["TwoCaptchaProxyRequest"];
|
|
8
8
|
export type TwoCaptchaProxyResponse = components["schemas"]["TwoCaptchaProxyResponse"];
|
|
9
9
|
export type KvEntryRecord = components["schemas"]["KvEntry"];
|
|
10
|
+
export type InboxMessageRecord = components["schemas"]["InboxMessage"];
|
|
11
|
+
export type AddressMessagesQuery = paths["/api/inboxes/messages"]["get"]["parameters"]["query"];
|
|
12
|
+
export type SendInboxMessageBody = components["schemas"]["SendInboxMessageRequest"];
|
|
13
|
+
export type SentInboxMessage = components["schemas"]["SendInboxMessageResponse"]["data"];
|
|
14
|
+
export type WebhookCaptureRecord = components["schemas"]["WebhookCapture"];
|
|
15
|
+
export type WebhookCaptureEndpoint = components["schemas"]["WebhookCaptureEndpointResponse"]["data"];
|
|
16
|
+
export type WebhookCaptureQuery = NonNullable<paths["/api/webhook-captures/{token}"]["get"]["parameters"]["query"]>;
|
|
10
17
|
export type KvListQuery = NonNullable<paths["/api/kv"]["get"]["parameters"]["query"]>;
|
|
11
18
|
export type KvListPageRecord = components["schemas"]["KvListResponse"]["data"];
|
|
12
19
|
export type KvPutBody = components["schemas"]["PutKvEntryRequest"];
|
|
@@ -57,6 +64,10 @@ export declare class ApiWorkerClient {
|
|
|
57
64
|
refreshKvEntry(key: string, ttl: number, ifVersion?: number): Promise<KvConditionalResult<KvEntryRecord> | null>;
|
|
58
65
|
deleteKvEntry(key: string, ifVersion?: number): Promise<KvConditionalResult<boolean>>;
|
|
59
66
|
private conditional;
|
|
67
|
+
listAddressMessages(query: AddressMessagesQuery): Promise<InboxMessageRecord[]>;
|
|
68
|
+
sendInboxMessage(body: SendInboxMessageBody): Promise<SentInboxMessage>;
|
|
69
|
+
createWebhookCapture(): Promise<WebhookCaptureEndpoint>;
|
|
70
|
+
listWebhookCaptures(token: string, query: WebhookCaptureQuery): Promise<WebhookCaptureRecord[]>;
|
|
60
71
|
postProviderProxy(path: ProviderProxyPath, body: ProviderProxyRequest): Promise<ProviderProxyResponse>;
|
|
61
72
|
putTestCaseRunEndEvent(body: TestCaseRunEndEventRequest): Promise<void>;
|
|
62
73
|
putTestCaseRunBeginEvent(body: TestCaseRunBeginEventRequest): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-worker-client.d.ts","sourceRoot":"","sources":["../src/api-worker-client.ts"],"names":[],"mappings":"AACA,OAAqB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAExE,KAAK,mBAAmB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAEzC,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"api-worker-client.d.ts","sourceRoot":"","sources":["../src/api-worker-client.ts"],"names":[],"mappings":"AACA,OAAqB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAExE,KAAK,mBAAmB,GAAG,MAAM,CAAC,KAAK,CA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etchWithRetry(input, undefined, { acceptStatuses: KV_EXPECTED_STATUSES });
|
|
95
|
+
const sendOnce = (input) => fetch(input);
|
|
95
96
|
function versionOf(ifVersion) {
|
|
96
97
|
return ifVersion === undefined ? undefined : { ifVersion };
|
|
97
98
|
}
|
|
@@ -187,6 +188,29 @@ class ApiWorkerClient {
|
|
|
187
188
|
const { data } = this.unwrap(result, label);
|
|
188
189
|
return { ok: true, value: data.entry };
|
|
189
190
|
}
|
|
191
|
+
async listAddressMessages(query) {
|
|
192
|
+
const result = await this.client.GET("/api/inboxes/messages", {
|
|
193
|
+
params: { query },
|
|
194
|
+
});
|
|
195
|
+
return this.unwrap(result, "GET /api/inboxes/messages").data.messages;
|
|
196
|
+
}
|
|
197
|
+
async sendInboxMessage(body) {
|
|
198
|
+
const result = await this.client.POST("/api/inboxes/send", {
|
|
199
|
+
body,
|
|
200
|
+
fetch: sendOnce,
|
|
201
|
+
});
|
|
202
|
+
return this.unwrap(result, "POST /api/inboxes/send").data;
|
|
203
|
+
}
|
|
204
|
+
async createWebhookCapture() {
|
|
205
|
+
const result = await this.client.POST("/api/webhook-captures");
|
|
206
|
+
return this.unwrap(result, "POST /api/webhook-captures").data;
|
|
207
|
+
}
|
|
208
|
+
async listWebhookCaptures(token, query) {
|
|
209
|
+
const result = await this.client.GET("/api/webhook-captures/{token}", {
|
|
210
|
+
params: { path: { token }, query },
|
|
211
|
+
});
|
|
212
|
+
return this.unwrap(result, "GET /api/webhook-captures/{token}").data.captures;
|
|
213
|
+
}
|
|
190
214
|
async postProviderProxy(path, body) {
|
|
191
215
|
const result = await this.client.POST(path, {
|
|
192
216
|
body,
|
package/dist/email.d.ts
CHANGED
|
@@ -11,19 +11,67 @@ export type WaitForEmailOptions = {
|
|
|
11
11
|
*/
|
|
12
12
|
receivedAfter?: Date;
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* The file extension sets the attachment's type and must be an allowed one:
|
|
16
|
+
* pdf, images, txt, csv, tsv, json, xml, ics, eml, md or office documents.
|
|
17
|
+
*/
|
|
18
|
+
export type EmailAttachment = {
|
|
19
|
+
filename: string;
|
|
20
|
+
content: Buffer | string;
|
|
21
|
+
} | {
|
|
22
|
+
path: string;
|
|
23
|
+
filename?: string;
|
|
24
|
+
};
|
|
25
|
+
export type SendEmailOptions = {
|
|
26
|
+
to: string | string[];
|
|
27
|
+
cc?: string[];
|
|
28
|
+
bcc?: string[];
|
|
29
|
+
subject: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
html?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Must be an `@empiricalrun.email` address. Defaults to this client's address.
|
|
34
|
+
*/
|
|
35
|
+
replyTo?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `messageId` of a received email. The sent email replies to it in the same thread.
|
|
38
|
+
*/
|
|
39
|
+
inReplyTo?: string;
|
|
40
|
+
references?: string[];
|
|
41
|
+
attachments?: EmailAttachment[];
|
|
42
|
+
};
|
|
43
|
+
export type SentEmail = {
|
|
44
|
+
messageId: string;
|
|
45
|
+
sentAt: Date;
|
|
46
|
+
};
|
|
14
47
|
type EmailProvider = "inbox" | "mailosaur";
|
|
15
48
|
type EmailClientOptions = {
|
|
16
49
|
timeout?: number;
|
|
17
50
|
emailId?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Defaults to `"inbox"`. Without a provider, an `emailId` that is a full
|
|
53
|
+
* `*.mailosaur.net` address uses Mailosaur.
|
|
54
|
+
*/
|
|
18
55
|
provider?: EmailProvider;
|
|
19
56
|
};
|
|
57
|
+
export declare function resolveEmailProvider(provider: EmailProvider | undefined, emailId: string | undefined): EmailProvider;
|
|
20
58
|
export declare class EmailClient {
|
|
21
59
|
address: string;
|
|
22
60
|
timeout: number;
|
|
23
61
|
private client;
|
|
62
|
+
private apiClient;
|
|
63
|
+
private provider;
|
|
24
64
|
constructor(opts?: EmailClientOptions);
|
|
25
65
|
getAddress(): string;
|
|
26
66
|
waitForEmail(options?: WaitForEmailOptions): Promise<Email>;
|
|
67
|
+
/**
|
|
68
|
+
* Sends an email from this client's address. Replies to it arrive at this
|
|
69
|
+
* address, so `waitForEmail` reads them. Each recipient must be an
|
|
70
|
+
* `@empiricalrun.email` address, someone who emailed this address, or an
|
|
71
|
+
* allowed recipient verified for the project (Inboxes → Allowed recipients).
|
|
72
|
+
* Never retried, so one call sends at most one email.
|
|
73
|
+
*/
|
|
74
|
+
sendEmail(options: SendEmailOptions): Promise<SentEmail>;
|
|
27
75
|
}
|
|
28
76
|
export {};
|
|
29
77
|
//# sourceMappingURL=email.d.ts.map
|
package/dist/email.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,MAAM,KAAK,GAAG,cAAc,GAAG,UAAU,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,IAAI,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,EAAE,CAAC,EAAE,MAAM,EA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1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.EmailClient = void 0;
|
|
7
|
+
exports.resolveEmailProvider = resolveEmailProvider;
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
10
|
const api_worker_client_1 = require("./api-worker-client");
|
|
5
11
|
const inbox_client_1 = require("./inbox-client");
|
|
6
12
|
const mailosaur_client_1 = require("./mailosaur-client");
|
|
13
|
+
function toAttachmentBody(attachment) {
|
|
14
|
+
if ("path" in attachment) {
|
|
15
|
+
return {
|
|
16
|
+
filename: attachment.filename ?? node_path_1.default.basename(attachment.path),
|
|
17
|
+
content: node_fs_1.default.readFileSync(attachment.path).toString("base64"),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
filename: attachment.filename,
|
|
22
|
+
content: Buffer.from(attachment.content).toString("base64"),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
7
25
|
const DEFAULT_TIMEOUT = 30_000;
|
|
8
26
|
const MAILOSAUR_SERVER_ID = "pnyrwq5o";
|
|
9
27
|
const INBOX_EMAIL_DOMAIN = "empiricalrun.email";
|
|
28
|
+
function resolveEmailProvider(provider, emailId) {
|
|
29
|
+
if (provider) {
|
|
30
|
+
return provider;
|
|
31
|
+
}
|
|
32
|
+
const domain = emailId?.split("@")[1]?.toLowerCase();
|
|
33
|
+
return domain?.endsWith("mailosaur.net") ? "mailosaur" : "inbox";
|
|
34
|
+
}
|
|
10
35
|
class EmailClient {
|
|
11
36
|
address;
|
|
12
37
|
timeout;
|
|
13
38
|
client;
|
|
39
|
+
apiClient;
|
|
40
|
+
provider;
|
|
14
41
|
constructor(opts = {}) {
|
|
15
42
|
const { timeout = DEFAULT_TIMEOUT, emailId: knownEmailId } = opts;
|
|
16
43
|
this.timeout = timeout;
|
|
17
|
-
const provider = opts.provider
|
|
44
|
+
const provider = resolveEmailProvider(opts.provider, knownEmailId);
|
|
18
45
|
const apiClient = new api_worker_client_1.ApiWorkerClient();
|
|
46
|
+
this.apiClient = apiClient;
|
|
47
|
+
this.provider = provider;
|
|
19
48
|
const emailId = knownEmailId ||
|
|
20
49
|
[...Array(7)].map(() => Math.random().toString(36)[2]).join("");
|
|
21
50
|
if (provider === "inbox") {
|
|
@@ -41,5 +70,31 @@ class EmailClient {
|
|
|
41
70
|
async waitForEmail(options) {
|
|
42
71
|
return this.client.waitForEmail(this.address, options);
|
|
43
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Sends an email from this client's address. Replies to it arrive at this
|
|
75
|
+
* address, so `waitForEmail` reads them. Each recipient must be an
|
|
76
|
+
* `@empiricalrun.email` address, someone who emailed this address, or an
|
|
77
|
+
* allowed recipient verified for the project (Inboxes → Allowed recipients).
|
|
78
|
+
* Never retried, so one call sends at most one email.
|
|
79
|
+
*/
|
|
80
|
+
async sendEmail(options) {
|
|
81
|
+
if (this.provider !== "inbox") {
|
|
82
|
+
throw new Error("sendEmail needs the inbox provider");
|
|
83
|
+
}
|
|
84
|
+
const sent = await this.apiClient.sendInboxMessage({
|
|
85
|
+
from: this.address,
|
|
86
|
+
to: Array.isArray(options.to) ? options.to : [options.to],
|
|
87
|
+
cc: options.cc,
|
|
88
|
+
bcc: options.bcc,
|
|
89
|
+
reply_to: options.replyTo,
|
|
90
|
+
subject: options.subject,
|
|
91
|
+
text: options.text,
|
|
92
|
+
html: options.html,
|
|
93
|
+
in_reply_to: options.inReplyTo,
|
|
94
|
+
references: options.references,
|
|
95
|
+
attachments: options.attachments?.map(toAttachmentBody),
|
|
96
|
+
});
|
|
97
|
+
return { messageId: sent.message_id, sentAt: new Date(sent.sent_at) };
|
|
98
|
+
}
|
|
44
99
|
}
|
|
45
100
|
exports.EmailClient = EmailClient;
|