Skip to content

Commit

Permalink
Make all
Browse files Browse the repository at this point in the history
  • Loading branch information
j3k0 committed Jun 1, 2023
1 parent a97b626 commit 9c71bc7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
9 changes: 9 additions & 0 deletions api/interfaces/CdvPurchase.Utils.Ajax.Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Option for an external HTTP request
- [error](CdvPurchase.Utils.Ajax.Options.md#error)
- [method](CdvPurchase.Utils.Ajax.Options.md#method)
- [success](CdvPurchase.Utils.Ajax.Options.md#success)
- [timeout](CdvPurchase.Utils.Ajax.Options.md#timeout)
- [url](CdvPurchase.Utils.Ajax.Options.md#url)

## Properties
Expand Down Expand Up @@ -67,6 +68,14 @@ A success callback taking the body as an argument

___

### timeout

`Optional` **timeout**: `number`

Request timeout in milliseconds

___

### url

**url**: `string`
Expand Down
2 changes: 2 additions & 0 deletions api/interfaces/CdvPurchase.Validator.Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

**Function**(`receipt`, `callback`): `void`

Receipt validator as a function.

#### Parameters

| Name | Type |
Expand Down
15 changes: 15 additions & 0 deletions api/interfaces/CdvPurchase.Validator.Target.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

[CdvPurchase](../modules/CdvPurchase.md).[Validator](../modules/CdvPurchase.Validator.md).Target

Custom definition of the validation request target.

## Table of contents

### Properties

- [headers](CdvPurchase.Validator.Target.md#headers)
- [timeout](CdvPurchase.Validator.Target.md#timeout)
- [url](CdvPurchase.Validator.Target.md#url)

## Properties
Expand All @@ -15,12 +18,24 @@

`Optional` **headers**: `Object`

Custom headers

#### Index signature

[token: `string`]: `string`

___

### timeout

`Optional` **timeout**: `number`

Request timeout in millseconds

___

### url

**url**: `string`

URL of the receipt validator
12 changes: 12 additions & 0 deletions api/modules/CdvPurchase.Utils.Ajax.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
- [ErrorCallback](CdvPurchase.Utils.Ajax.md#errorcallback)
- [SuccessCallback](CdvPurchase.Utils.Ajax.md#successcallback)

### Variables

- [HTTP\_REQUEST\_TIMEOUT](CdvPurchase.Utils.Ajax.md#http_request_timeout)

## Type Aliases

### ErrorCallback
Expand Down Expand Up @@ -64,3 +68,11 @@ Success callback for an ajax call
##### Returns

`void`

## Variables

### HTTP\_REQUEST\_TIMEOUT

`Const` **HTTP\_REQUEST\_TIMEOUT**: ``408``

HTTP status returned when a request times out
2 changes: 1 addition & 1 deletion api/modules/CdvPurchase.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ___

### PLUGIN\_VERSION

`Const` **PLUGIN\_VERSION**: ``"13.4.3"``
`Const` **PLUGIN\_VERSION**: ``"13.5.0"``

Current release number of the plugin.

Expand Down
16 changes: 15 additions & 1 deletion www/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ declare namespace CdvPurchase {
/**
* Current release number of the plugin.
*/
const PLUGIN_VERSION = "13.4.3";
const PLUGIN_VERSION = "13.5.0";
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -4980,6 +4980,8 @@ declare var msCrypto: any;
declare namespace CdvPurchase {
namespace Utils {
namespace Ajax {
/** HTTP status returned when a request times out */
const HTTP_REQUEST_TIMEOUT = 408;
/** Success callback for an ajax call */
type SuccessCallback<T> = (body: T) => void;
/** Error callback for an ajax call */
Expand All @@ -5000,6 +5002,8 @@ declare namespace CdvPurchase {
customHeaders?: {
[key: string]: string;
};
/** Request timeout in milliseconds */
timeout?: number;
}
}
/**
Expand Down Expand Up @@ -5425,14 +5429,24 @@ declare namespace CdvPurchase {
* Dates stored as a ISO formatted string
*/
type ISODate = string;
/**
* Receipt validator as a function.
*/
interface Function {
(receipt: Validator.Request.Body, callback: Callback<Validator.Response.Payload>): void;
}
/**
* Custom definition of the validation request target.
*/
interface Target {
/** URL of the receipt validator */
url: string;
/** Custom headers */
headers?: {
[token: string]: string;
};
/** Request timeout in millseconds */
timeout?: number;
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions www/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,10 @@ var CdvPurchase;
if (typeof this.controller.validator === 'function')
return this.runValidatorFunction(this.controller.validator, receipt, body, callback);
const target = typeof this.controller.validator === 'string'
? { url: this.controller.validator }
? {
url: this.controller.validator,
timeout: 20000, // validation request will timeout after 20 seconds by default
}
: this.controller.validator;
return this.runValidatorRequest(target, receipt, body, callback);
}
Expand Down Expand Up @@ -587,6 +590,7 @@ var CdvPurchase;
url: target.url,
method: 'POST',
customHeaders: target.headers,
timeout: target.timeout,
data: body,
success: (response) => {
var _a;
Expand Down Expand Up @@ -828,7 +832,7 @@ var CdvPurchase;
/**
* Current release number of the plugin.
*/
CdvPurchase.PLUGIN_VERSION = '13.4.3';
CdvPurchase.PLUGIN_VERSION = '13.5.0';
/**
* Entry class of the plugin.
*/
Expand Down Expand Up @@ -5526,6 +5530,11 @@ var CdvPurchase;
(function (CdvPurchase) {
let Utils;
(function (Utils) {
let Ajax;
(function (Ajax) {
/** HTTP status returned when a request times out */
Ajax.HTTP_REQUEST_TIMEOUT = 408;
})(Ajax = Utils.Ajax || (Utils.Ajax = {}));
/**
* Simplified version of jQuery's ajax method based on XMLHttpRequest.
*
Expand All @@ -5539,6 +5548,13 @@ var CdvPurchase;
}
var doneCb = function () { };
var xhr = new XMLHttpRequest();
if (options.timeout) {
xhr.timeout = options.timeout;
xhr.ontimeout = function ( /*event*/) {
log.warn("ajax -> request to " + options.url + " timeout");
Utils.callExternal(log, 'ajax.error', options.error, Ajax.HTTP_REQUEST_TIMEOUT, "Timeout");
};
}
xhr.open(options.method || 'POST', options.url, true);
xhr.onreadystatechange = function ( /*event*/) {
try {
Expand Down

0 comments on commit 9c71bc7

Please sign in to comment.