@henrylabs-interview/payment-processor 0.2.12 → 0.2.14

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.
@@ -80,11 +80,11 @@ export class Checkout {
80
80
  status: 'failure',
81
81
  substatus: '501-not-supported',
82
82
  code: 501,
83
- message: 'This currency is currently not supported, please convert first.',
83
+ message: 'This currency is currently not supported, please convert to another supported currency first.',
84
84
  };
85
85
  }
86
- // Simulated random internal failure
87
- if (Math.random() > 0.85) {
86
+ // Simulated stupid internal failures
87
+ if ((params.customerId ?? '').length === crypto.randomUUID().length || (params.customerId ?? '').includes('-') || params.customerId === '') {
88
88
  return {
89
89
  _reqId: genReqId(),
90
90
  status: 'failure',
@@ -1,12 +1,16 @@
1
1
  const path = new URL('../db-store/history.json', import.meta.url);
2
+ async function ensureFileExists() {
3
+ const file = Bun.file(path);
4
+ if (!(await file.exists())) {
5
+ await Bun.write(path, '[]');
6
+ }
7
+ }
2
8
  /**
3
9
  * Reads all history records from the JSON store.
4
10
  */
5
11
  export async function readHistory() {
12
+ await ensureFileExists();
6
13
  const file = Bun.file(path);
7
- if (!(await file.exists())) {
8
- return [];
9
- }
10
14
  const text = await file.text();
11
15
  if (!text)
12
16
  return [];
@@ -14,6 +18,8 @@ export async function readHistory() {
14
18
  return JSON.parse(text);
15
19
  }
16
20
  catch {
21
+ // If file somehow becomes corrupted, reset it
22
+ await Bun.write(path, '[]');
17
23
  return [];
18
24
  }
19
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henrylabs-interview/payment-processor",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",