@tamtamchik/app-store-receipt-parser 2.0.0 → 2.1.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/README.md +6 -3
- package/dist/index.js +3 -1
- package/dist/index.mjs +3 -1
- package/package.json +9 -9
- package/src/mappings.ts +3 -0
- package/src/parser.ts +5 -1
- package/src/verifications.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# Apple Receipt Parser
|
|
2
2
|
|
|
3
|
-
[![Buy Me A Coffee][ico-coffee]][link-coffee]
|
|
4
3
|
[![Latest Version on NPM][ico-version]][link-npm]
|
|
5
4
|
[![Scrutinizer build][ico-scrutinizer-build]][link-scrutinizer]
|
|
6
5
|
[![Scrutinizer quality][ico-scrutinizer-quality]][link-scrutinizer]
|
|
@@ -11,8 +10,8 @@
|
|
|
11
10
|
A lightweight TypeScript library for extracting transaction IDs from Apple's ASN.1 encoded Unified Receipts.
|
|
12
11
|
|
|
13
12
|
> **Warning!** This library is not a full-fledged receipt parser.
|
|
14
|
-
> It only extracts some information from
|
|
15
|
-
> It does not work with the old
|
|
13
|
+
> It only extracts some information from Apple's ASN.1 encoded Unified Receipts.
|
|
14
|
+
> It does not work with the old-style transactions receipts.
|
|
16
15
|
|
|
17
16
|
> **Documentation for the version 1.x of the library can be found [here](https://github.com/tamtamchik/app-store-receipt-parser/tree/1.x/README.md).**
|
|
18
17
|
|
|
@@ -41,6 +40,7 @@ const data = parseReceipt(receiptString);
|
|
|
41
40
|
|
|
42
41
|
console.log(data);
|
|
43
42
|
// {
|
|
43
|
+
// ENVIRONMENT: 'ProductionSandbox',
|
|
44
44
|
// APP_VERSION: '1',
|
|
45
45
|
// ORIGINAL_APP_VERSION: '1.0',
|
|
46
46
|
// OPAQUE_VALUE: 'c4dd4054b0b61a07beb585f6a842e048',
|
|
@@ -89,6 +89,9 @@ Apple Receipt Parser is [MIT licensed](./LICENSE).
|
|
|
89
89
|
|
|
90
90
|
This project uses `ASN1.js`, which is licensed under the BSD-3-Clause License. The license text can be found in [LICENSE](./LICENSE).
|
|
91
91
|
|
|
92
|
+
---
|
|
93
|
+
[![Buy Me A Coffee][ico-coffee]][link-coffee]
|
|
94
|
+
|
|
92
95
|
[ico-coffee]: https://img.shields.io/badge/Buy%20Me%20A-Coffee-%236F4E37.svg?style=flat-square
|
|
93
96
|
[ico-version]: https://img.shields.io/npm/v/@tamtamchik/app-store-receipt-parser.svg?style=flat-square
|
|
94
97
|
[ico-license]: https://img.shields.io/npm/l/@tamtamchik/app-store-receipt-parser.svg?style=flat-square
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var import_asn1js2 = require("asn1js");
|
|
|
29
29
|
|
|
30
30
|
// src/mappings.ts
|
|
31
31
|
var RECEIPT_FIELDS_MAP = /* @__PURE__ */ new Map([
|
|
32
|
+
[0, "ENVIRONMENT"],
|
|
32
33
|
[2, "BUNDLE_ID"],
|
|
33
34
|
[3, "APP_VERSION"],
|
|
34
35
|
[4, "OPAQUE_VALUE"],
|
|
@@ -113,7 +114,7 @@ var uniqueArrayValues = (array) => Array.from(new Set(array));
|
|
|
113
114
|
|
|
114
115
|
// src/parser.ts
|
|
115
116
|
function isReceiptFieldKey(value) {
|
|
116
|
-
return Boolean(
|
|
117
|
+
return Boolean(typeof value === "number" && RECEIPT_FIELDS_MAP.has(value));
|
|
117
118
|
}
|
|
118
119
|
function isParsedReceiptContentComplete(data) {
|
|
119
120
|
for (const fieldKey of RECEIPT_FIELDS_MAP.values()) {
|
|
@@ -170,6 +171,7 @@ function parseReceipt(receipt) {
|
|
|
170
171
|
const rootSchemaVerification = verifyReceiptSchema(receipt);
|
|
171
172
|
const content = rootSchemaVerification.result[CONTENT_ID];
|
|
172
173
|
const parsed = {
|
|
174
|
+
ENVIRONMENT: "Production",
|
|
173
175
|
IN_APP_ORIGINAL_TRANSACTION_IDS: [],
|
|
174
176
|
IN_APP_TRANSACTION_IDS: []
|
|
175
177
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { IA5String, Sequence as Sequence2, Utf8String } from "asn1js";
|
|
|
3
3
|
|
|
4
4
|
// src/mappings.ts
|
|
5
5
|
var RECEIPT_FIELDS_MAP = /* @__PURE__ */ new Map([
|
|
6
|
+
[0, "ENVIRONMENT"],
|
|
6
7
|
[2, "BUNDLE_ID"],
|
|
7
8
|
[3, "APP_VERSION"],
|
|
8
9
|
[4, "OPAQUE_VALUE"],
|
|
@@ -87,7 +88,7 @@ var uniqueArrayValues = (array) => Array.from(new Set(array));
|
|
|
87
88
|
|
|
88
89
|
// src/parser.ts
|
|
89
90
|
function isReceiptFieldKey(value) {
|
|
90
|
-
return Boolean(
|
|
91
|
+
return Boolean(typeof value === "number" && RECEIPT_FIELDS_MAP.has(value));
|
|
91
92
|
}
|
|
92
93
|
function isParsedReceiptContentComplete(data) {
|
|
93
94
|
for (const fieldKey of RECEIPT_FIELDS_MAP.values()) {
|
|
@@ -144,6 +145,7 @@ function parseReceipt(receipt) {
|
|
|
144
145
|
const rootSchemaVerification = verifyReceiptSchema(receipt);
|
|
145
146
|
const content = rootSchemaVerification.result[CONTENT_ID];
|
|
146
147
|
const parsed = {
|
|
148
|
+
ENVIRONMENT: "Production",
|
|
147
149
|
IN_APP_ORIGINAL_TRANSACTION_IDS: [],
|
|
148
150
|
IN_APP_TRANSACTION_IDS: []
|
|
149
151
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamtamchik/app-store-receipt-parser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
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,15 +34,15 @@
|
|
|
34
34
|
"asn1js": "3.0.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/jest": "29.5.
|
|
38
|
-
"@types/node": "20.
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
40
|
-
"@typescript-eslint/parser": "6.
|
|
41
|
-
"eslint": "8.
|
|
37
|
+
"@types/jest": "29.5.12",
|
|
38
|
+
"@types/node": "20.12.7",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "7.6.0",
|
|
40
|
+
"@typescript-eslint/parser": "7.6.0",
|
|
41
|
+
"eslint": "8.57.0",
|
|
42
42
|
"jest": "29.7.0",
|
|
43
|
-
"ts-jest": "29.1.
|
|
44
|
-
"tsup": "8.0.
|
|
45
|
-
"typescript": "5.
|
|
43
|
+
"ts-jest": "29.1.2",
|
|
44
|
+
"tsup": "8.0.2",
|
|
45
|
+
"typescript": "5.4.5"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup src/index.ts --format cjs,esm --clean",
|
package/src/mappings.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type ReceiptFieldsKeyValues =
|
|
2
|
+
| 0
|
|
2
3
|
| 2
|
|
3
4
|
| 3
|
|
4
5
|
| 4
|
|
@@ -17,6 +18,7 @@ export type ReceiptFieldsKeyValues =
|
|
|
17
18
|
| 1712
|
|
18
19
|
|
|
19
20
|
export type ReceiptFieldsKeyNames =
|
|
21
|
+
| 'ENVIRONMENT'
|
|
20
22
|
| 'BUNDLE_ID'
|
|
21
23
|
| 'APP_VERSION'
|
|
22
24
|
| 'OPAQUE_VALUE'
|
|
@@ -39,6 +41,7 @@ export type ReceiptFieldsKeyNames =
|
|
|
39
41
|
* @see https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html
|
|
40
42
|
*/
|
|
41
43
|
export const RECEIPT_FIELDS_MAP: ReadonlyMap<ReceiptFieldsKeyValues, ReceiptFieldsKeyNames> = new Map([
|
|
44
|
+
[0, 'ENVIRONMENT'],
|
|
42
45
|
[2, 'BUNDLE_ID'],
|
|
43
46
|
[3, 'APP_VERSION'],
|
|
44
47
|
[4, 'OPAQUE_VALUE'],
|
package/src/parser.ts
CHANGED
|
@@ -5,13 +5,16 @@ import { CONTENT_ID, FIELD_TYPE_ID, FIELD_VALUE_ID, IN_APP } from './constants'
|
|
|
5
5
|
import { verifyFieldSchema, verifyReceiptSchema } from './verifications'
|
|
6
6
|
import { uniqueArrayValues } from './utils'
|
|
7
7
|
|
|
8
|
+
export type Environment = 'Production' | 'ProductionSandbox' | string
|
|
9
|
+
|
|
8
10
|
export type ParsedReceipt = Partial<Record<ReceiptFieldsKeyNames, string>> & {
|
|
11
|
+
ENVIRONMENT: Environment
|
|
9
12
|
IN_APP_ORIGINAL_TRANSACTION_IDS: string[]
|
|
10
13
|
IN_APP_TRANSACTION_IDS: string[]
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
function isReceiptFieldKey (value: unknown): value is ReceiptFieldsKeyValues {
|
|
14
|
-
return Boolean(
|
|
17
|
+
return Boolean(typeof value === 'number' && RECEIPT_FIELDS_MAP.has(value as ReceiptFieldsKeyValues))
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
function isParsedReceiptContentComplete (data: ParsedReceipt): data is ParsedReceipt {
|
|
@@ -86,6 +89,7 @@ export function parseReceipt (receipt: string): ParsedReceipt {
|
|
|
86
89
|
|
|
87
90
|
const content = rootSchemaVerification.result[CONTENT_ID] as OctetString
|
|
88
91
|
const parsed: ParsedReceipt = {
|
|
92
|
+
ENVIRONMENT: 'Production',
|
|
89
93
|
IN_APP_ORIGINAL_TRANSACTION_IDS: [],
|
|
90
94
|
IN_APP_TRANSACTION_IDS: [],
|
|
91
95
|
}
|