@tamtamchik/app-store-receipt-parser 1.0.0-pre.0 → 1.0.0-pre.2

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 ADDED
@@ -0,0 +1,72 @@
1
+ # Apple Receipt Parser
2
+
3
+ [![Buy Me A Coffee][ico-coffee]][link-coffee]
4
+ [![Latest Version on NPM][ico-version]][link-npm]
5
+ [![CircleCI][ico-circleci]][link-circleci]
6
+ [![Software License][ico-license]](./LICENSE)
7
+ [![Total Downloads][ico-downloads]][link-downloads]
8
+
9
+ A lightweight TypeScript library for extracting transaction IDs from Apple's ASN.1 encoded Unified Receipts.
10
+
11
+ > **Warning!** This library is not a full-fledged receipt parser.
12
+ > It only extracts transaction IDs from the Apple's ASN.1 encoded Unified Receipts.
13
+ > It does not work with the old style transactions receipts.
14
+
15
+ ## Installation
16
+
17
+ Using npm:
18
+
19
+ ```shell
20
+ npm install @tamtamchik/apple-receipt-parser
21
+ ```
22
+
23
+ Using yarn:
24
+
25
+ ```shell
26
+ yarn add @tamtamchik/apple-receipt-parser
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```typescript
32
+ import { ReceiptParser } from '@tamtamchik/apple-receipt-parser';
33
+
34
+ // Unified Receipt string
35
+ const receiptString = "MII...";
36
+
37
+ // As an instance ...
38
+ const parser = new ReceiptParser(receiptString);
39
+ const ids = parser.getTransactionIds();
40
+ console.log(ids);
41
+ // {
42
+ // transactionIds: ['1000000000000000'],
43
+ // originalTransactionIds: ['1000000000000000'],
44
+ // }
45
+
46
+ // ... or as a static method
47
+ const ids = ReceiptParser.getTransactionIds(receiptString);
48
+ console.log(ids);
49
+ // {
50
+ // transactionIds: ['1000000000000000'],
51
+ // originalTransactionIds: ['1000000000000000'],
52
+ // }
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ Pull requests are always welcome. If you have bigger changes in mind, please open an issue first to discuss your ideas.
58
+
59
+ ## License
60
+
61
+ Apple Receipt Parser is [MIT licensed](./LICENSE).
62
+
63
+ [ico-coffee]: https://img.shields.io/badge/Buy%20Me%20A-Coffee-%236F4E37.svg?style=flat-square
64
+ [ico-version]: https://img.shields.io/npm/v/@tamtamchik/apple-receipt-parser.svg?style=flat-square
65
+ [ico-license]: https://img.shields.io/npm/l/@tamtamchik/apple-receipt-parser.svg?style=flat-square
66
+ [ico-downloads]: https://img.shields.io/npm/dt/@tamtamchik/apple-receipt-parser.svg?style=flat-square
67
+ [ico-circleci]: https://img.shields.io/circleci/build/github/tamtamchik/apple-receipt-parser.svg?style=flat-square
68
+
69
+ [link-coffee]: https://www.buymeacoffee.com/tamtamchik
70
+ [link-npm]: https://www.npmjs.com/package/@tamtamchik/apple-receipt-parser
71
+ [link-downloads]: https://www.npmjs.com/package/@tamtamchik/apple-receipt-parser
72
+ [link-circleci]: https://app.circleci.com/pipelines/github/tamtamchik/apple-receipt-parser?branch=main
package/dist/index.js CHANGED
@@ -54,6 +54,9 @@ var ReceiptParser = class _ReceiptParser {
54
54
  }
55
55
  static getTransactionIdsFromReceiptString(receiptString) {
56
56
  const { result } = (0, import_asn1js.fromBER)(Buffer.from(receiptString, "base64"));
57
+ if (result.error) {
58
+ throw new Error(`Error parsing receipt: ${result.error}`);
59
+ }
57
60
  return this.getTransactionIdsFromBlock(result.toJSON());
58
61
  }
59
62
  /**
package/dist/index.mjs CHANGED
@@ -28,6 +28,9 @@ var ReceiptParser = class _ReceiptParser {
28
28
  }
29
29
  static getTransactionIdsFromReceiptString(receiptString) {
30
30
  const { result } = fromBER(Buffer.from(receiptString, "base64"));
31
+ if (result.error) {
32
+ throw new Error(`Error parsing receipt: ${result.error}`);
33
+ }
31
34
  return this.getTransactionIdsFromBlock(result.toJSON());
32
35
  }
33
36
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamtamchik/app-store-receipt-parser",
3
- "version": "1.0.0-pre.0",
3
+ "version": "1.0.0-pre.2",
4
4
  "description": "A lightweight TypeScript library for extracting transaction IDs from Apple's ASN.1 encoded receipts.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -34,10 +34,13 @@
34
34
  "asn1js": "3.0.5"
35
35
  },
36
36
  "devDependencies": {
37
+ "@types/jest": "29.5.3",
37
38
  "@types/node": "20.5.1",
38
39
  "@typescript-eslint/eslint-plugin": "6.4.0",
39
40
  "@typescript-eslint/parser": "6.4.0",
40
41
  "eslint": "8.47.0",
42
+ "jest": "29.6.2",
43
+ "ts-jest": "29.1.1",
41
44
  "tsup": "7.2.0",
42
45
  "typescript": "5.1.6"
43
46
  },
@@ -45,6 +48,8 @@
45
48
  "build": "tsup src/index.ts --format cjs,esm --clean",
46
49
  "dev": "npm run build -- --watch src",
47
50
  "lint": "eslint src --fix",
51
+ "test": "jest",
52
+ "coverage": "jest --coverage",
48
53
  "prepublishOnly": "npm run build"
49
54
  }
50
55
  }
@@ -51,6 +51,11 @@ export class ReceiptParser {
51
51
 
52
52
  static getTransactionIdsFromReceiptString (receiptString: string): TransactionIds | null {
53
53
  const { result } = fromBER(Buffer.from(receiptString, 'base64'))
54
+
55
+ if (result.error) {
56
+ throw new Error(`Error parsing receipt: ${result.error}`)
57
+ }
58
+
54
59
  return this.getTransactionIdsFromBlock(result.toJSON() as Block)
55
60
  }
56
61
 
@@ -72,10 +77,12 @@ export class ReceiptParser {
72
77
  if (!Array.isArray(block.valueBlock.value)) {
73
78
  return null
74
79
  }
80
+
75
81
  // The transaction ID is encoded as an OCTET STRING containing a UTF8String
76
82
  if (block.blockName === 'OCTET STRING' && block.valueBlock.value[0].blockName === 'UTF8String') {
77
83
  return block.valueBlock.value[0].valueBlock.value as string
78
84
  }
85
+
79
86
  return null
80
87
  }
81
88
 
package/.eslintrc DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "parser": "@typescript-eslint/parser",
3
- "extends": "plugin:@typescript-eslint/recommended",
4
- "parserOptions": {
5
- "ecmaVersion": 2021,
6
- "sourceType": "module"
7
- },
8
- "rules": {
9
- "indent": [ "error", 2, { "SwitchCase": 1 } ],
10
- "semi": "off",
11
- "quotes": "off",
12
- "object-curly-spacing": "off",
13
- "@typescript-eslint/array-type": [ "error", { "default": "array" } ],
14
- "@typescript-eslint/ban-ts-comment": 0,
15
- "@typescript-eslint/comma-dangle": [ "error", "always-multiline" ],
16
- "@typescript-eslint/quotes": [ "error", "single" ],
17
- "@typescript-eslint/semi": [ "error", "never" ],
18
- "@typescript-eslint/object-curly-spacing": [ "error", "always" ]
19
- },
20
- "env": {
21
- "node": true
22
- }
23
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "esnext",
5
- "strict": true,
6
- "esModuleInterop": true,
7
- "declaration": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "moduleResolution": "node"
11
- },
12
- "include": [
13
- "src/**/*.ts"
14
- ],
15
- "exclude": [
16
- "node_modules",
17
- "dist"
18
- ]
19
- }