proxymail-qa 0.5.0 → 0.6.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/dist/index.d.ts CHANGED
@@ -23,6 +23,20 @@ export interface Address {
23
23
  has_password: boolean;
24
24
  email_count: number;
25
25
  latest: Omit<Match, 'address' | 'email_id' | 'service_domain'> | null;
26
+ checked_out_until?: string;
27
+ }
28
+ export interface CheckoutOptions extends Omit<ListAddressesOptions, 'limit' | 'before'> {
29
+ minutes?: number;
30
+ }
31
+ export interface CheckedOutAccount extends Address {
32
+ checkout: {
33
+ token: string;
34
+ until: string;
35
+ };
36
+ }
37
+ export interface ReturnState {
38
+ addTags?: string[];
39
+ removeTags?: string[];
26
40
  }
27
41
  export interface CreatedAddress extends Address {
28
42
  password?: string;
@@ -110,6 +124,7 @@ export interface WaitOptions {
110
124
  timeout?: number;
111
125
  service?: string;
112
126
  since?: Date | string;
127
+ unused?: boolean;
113
128
  }
114
129
  export type LinkType = 'verify' | 'magic_signin' | 'invite' | 'reset' | 'any';
115
130
  export interface EmailSummary {
@@ -216,6 +231,16 @@ export declare class ProxyMailQA {
216
231
  createAddress(input?: CreateAddressInput): Promise<CreatedAddress>;
217
232
  listAddresses(options?: ListAddressesOptions): Promise<Address[]>;
218
233
  getAddress(address: string): Promise<Address>;
234
+ checkOutAccount(options?: CheckoutOptions): Promise<CheckedOutAccount>;
235
+ extendCheckout(account: CheckedOutAccount, minutes?: number): Promise<{
236
+ address: string;
237
+ checkout: {
238
+ token: string;
239
+ until: string;
240
+ };
241
+ }>;
242
+ returnAccount(account: CheckedOutAccount, state?: ReturnState): Promise<Address>;
243
+ withAccount<T>(options: CheckoutOptions, fn: (account: CheckedOutAccount) => Promise<T>): Promise<T>;
219
244
  updateAddress(address: string, patch: AddressPatch): Promise<Address>;
220
245
  deleteAddress(address: string): Promise<void>;
221
246
  waitForCode(address: string, options?: WaitOptions): Promise<Match>;
package/dist/index.js CHANGED
@@ -115,6 +115,51 @@ export class ProxyMailQA {
115
115
  getAddress(address) {
116
116
  return this.request('GET', `/addresses/${encodeURIComponent(address)}`);
117
117
  }
118
+ // Checks out an account matching every filter that nobody else holds, the
119
+ // least recently used first, for `minutes` (default 10). Throws
120
+ // ProxyMailQAError 409 when every match is checked out, 404 when none
121
+ // match. Tag accounts with their state (verified, premium…) to make pools.
122
+ checkOutAccount(options = {}) {
123
+ return this.request('POST', '/addresses/checkout', {
124
+ tags: options.tags,
125
+ country: options.country,
126
+ min_age: options.minAge,
127
+ max_age: options.maxAge,
128
+ has_password: options.hasPassword,
129
+ search: options.search,
130
+ minutes: options.minutes,
131
+ });
132
+ }
133
+ // More time from now (default 10 minutes).
134
+ extendCheckout(account, minutes) {
135
+ return this.request('POST', `/addresses/${encodeURIComponent(account.address)}/extend`, {
136
+ token: account.checkout.token,
137
+ minutes,
138
+ });
139
+ }
140
+ // Frees it for the next test, recording any change to its state.
141
+ returnAccount(account, state = {}) {
142
+ return this.request('POST', `/addresses/${encodeURIComponent(account.address)}/return`, {
143
+ token: account.checkout.token,
144
+ add_tags: state.addTags,
145
+ remove_tags: state.removeTags,
146
+ });
147
+ }
148
+ // Checks out an account, runs fn with it, and always returns it. fn can
149
+ // say what state it left the account in by returning { addTags, removeTags }.
150
+ async withAccount(options, fn) {
151
+ const account = await this.checkOutAccount(options);
152
+ let state = {};
153
+ try {
154
+ const result = await fn(account);
155
+ if (result && typeof result === 'object' && ('addTags' in result || 'removeTags' in result))
156
+ state = result;
157
+ return result;
158
+ }
159
+ finally {
160
+ await this.returnAccount(account, state).catch(() => { });
161
+ }
162
+ }
118
163
  updateAddress(address, patch) {
119
164
  return this.request('PATCH', `/addresses/${encodeURIComponent(address)}`, patch);
120
165
  }
@@ -254,6 +299,8 @@ export class ProxyMailQA {
254
299
  query.set('type', type);
255
300
  if (app !== undefined)
256
301
  query.set('app', String(app));
302
+ if (options.unused)
303
+ query.set('unused', 'true');
257
304
  const more = Date.now() + left * 1000 < deadline - 500;
258
305
  try {
259
306
  return await this.request('GET', `/addresses/${encodeURIComponent(address)}/${kind}?${query}`, undefined, more);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxymail-qa",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Disposable test inboxes for Playwright, Cypress and scripts: create an address, then wait for its verification code or link.",
5
5
  "license": "MIT",
6
6
  "author": "Proxy Mail QA <hello@proxymail.qa> (https://proxymail.qa)",