proxymail-qa 0.5.1 → 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;
@@ -217,6 +231,16 @@ export declare class ProxyMailQA {
217
231
  createAddress(input?: CreateAddressInput): Promise<CreatedAddress>;
218
232
  listAddresses(options?: ListAddressesOptions): Promise<Address[]>;
219
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>;
220
244
  updateAddress(address: string, patch: AddressPatch): Promise<Address>;
221
245
  deleteAddress(address: string): Promise<void>;
222
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "proxymail-qa",
3
- "version": "0.5.1",
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)",