@paybyrd/devagent-test-js 2.1.0-alpha.4 → 2.1.0-alpha.6

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/README.md CHANGED
@@ -10,3 +10,7 @@ branches and PRs publish prereleases), and the version in `package.json` stays `
10
10
  Used by `devagent-test-service` (Azure DevOps): `web/` (npm) and `widget/` (Yarn).
11
11
 
12
12
  Build and test: `npm ci && npm test`.
13
+
14
+ Demo page: `demo/index.html` validates a payment with the built SDK, so run `npm run build` first (`dist/` is not
15
+ committed). Then serve the repository root, e.g. `python3 -m http.server 8000`, and open
16
+ `http://localhost:8000/demo/`.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export interface PaymentRequest {
2
2
  amount: number;
3
3
  reference: string;
4
+ currency?: string;
4
5
  }
5
6
  export interface ValidationResult {
6
7
  valid: boolean;
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePayment = validatePayment;
4
+ const SUPPORTED_CURRENCIES = ["EUR", "USD", "GBP"];
4
5
  function validatePayment(request) {
5
6
  const errors = [];
6
7
  if (!(request.amount > 0)) {
@@ -12,5 +13,9 @@ function validatePayment(request) {
12
13
  else if (request.reference.length > 50) {
13
14
  errors.push("reference must be at most 50 characters");
14
15
  }
16
+ // null (e.g. from JSON) also means no currency, like a missing field.
17
+ if (request.currency != null && !SUPPORTED_CURRENCIES.includes(request.currency)) {
18
+ errors.push(`currency must be one of ${SUPPORTED_CURRENCIES.join(", ")}`);
19
+ }
15
20
  return { valid: errors.length === 0, errors };
16
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paybyrd/devagent-test-js",
3
- "version": "2.1.0-alpha.4",
3
+ "version": "2.1.0-alpha.6",
4
4
  "description": "Test package for the Paybyrd dev agent sandbox. Not for use: it has no real functionality.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",