-
Notifications
You must be signed in to change notification settings - Fork 29
/
JWSTransactionDecodedPayload.ts
293 lines (263 loc) · 12.7 KB
/
JWSTransactionDecodedPayload.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// Copyright (c) 2023 Apple Inc. Licensed under MIT License.
import { DecodedSignedData } from "./DecodedSignedData"
import { Environment, EnvironmentValidator } from "./Environment"
import { InAppOwnershipType, InAppOwnershipTypeValidator } from "./InAppOwnershipType"
import { OfferDiscountType, OfferDiscountTypeValidator } from "./OfferDiscountType"
import { OfferType, OfferTypeValidator } from "./OfferType"
import { RevocationReason, RevocationReasonValidator } from "./RevocationReason"
import { TransactionReason, TransactionReasonValidator } from "./TransactionReason"
import { Type, TypeValidator } from "./Type"
import { Validator } from "./Validator"
/**
* A decoded payload containing transaction information.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/jwstransactiondecodedpayload JWSTransactionDecodedPayload}
*/
export interface JWSTransactionDecodedPayload extends DecodedSignedData {
/**
* The original transaction identifier of a purchase.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/originaltransactionid originalTransactionId}
**/
originalTransactionId?: string
/**
* The unique identifier for a transaction such as an in-app purchase, restored in-app purchase, or subscription renewal.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/transactionid transactionId}
**/
transactionId?: string
/**
* The unique identifier of subscription-purchase events across devices, including renewals.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/weborderlineitemid webOrderLineItemId}
**/
webOrderLineItemId?: string
/**
* The bundle identifier of an app.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/bundleid bundleId}
**/
bundleId?: string
/**
* The unique identifier for the product, that you create in App Store Connect.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/productid productId}
**/
productId?: string
/**
* The identifier of the subscription group that the subscription belongs to.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/subscriptiongroupidentifier subscriptionGroupIdentifier}
**/
subscriptionGroupIdentifier?: string
/**
* The time that the App Store charged the user’s account for an in-app purchase, a restored in-app purchase, a subscription, or a subscription renewal after a lapse.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/purchasedate purchaseDate}
**/
purchaseDate?: number
/**
* The purchase date of the transaction associated with the original transaction identifier.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/originalpurchasedate originalPurchaseDate}
**/
originalPurchaseDate?: number
/**
* The UNIX time, in milliseconds, an auto-renewable subscription expires or renews.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/expiresdate expiresDate}
**/
expiresDate?: number
/**
* The number of consumable products purchased.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/quantity quantity}
**/
quantity?: number
/**
* The type of the in-app purchase.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/type type}
**/
type?: Type | string
/**
* The UUID that an app optionally generates to map a customer’s in-app purchase with its resulting App Store transaction.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/appaccounttoken appAccountToken}
**/
appAccountToken?: string
/**
* A string that describes whether the transaction was purchased by the user, or is available to them through Family Sharing.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/inappownershiptype inAppOwnershipType}
**/
inAppOwnershipType?: InAppOwnershipType | string
/**
* The UNIX time, in milliseconds, that the App Store signed the JSON Web Signature data.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/signeddate signedDate}
**/
signedDate?: number
/**
* The reason that the App Store refunded the transaction or revoked it from family sharing.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/revocationreason revocationReason}
**/
revocationReason?: RevocationReason | number
/**
* The UNIX time, in milliseconds, that Apple Support refunded a transaction.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/revocationdate revocationDate}
**/
revocationDate?: number
/**
* The Boolean value that indicates whether the user upgraded to another subscription.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/isupgraded isUpgraded}
**/
isUpgraded?: boolean
/**
* A value that represents the promotional offer type.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/offertype offerType}
**/
offerType?: OfferType | number
/**
* The identifier that contains the promo code or the promotional offer identifier.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/offeridentifier offerIdentifier}
**/
offerIdentifier?: string
/**
* The server environment, either sandbox or production.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/environment environment}
**/
environment?: Environment | string
/**
* The three-letter code that represents the country or region associated with the App Store storefront for the purchase.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/storefront storefront}
**/
storefront?: string
/**
* An Apple-defined value that uniquely identifies the App Store storefront associated with the purchase.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/storefrontid storefrontId}
**/
storefrontId?: string
/**
* The reason for the purchase transaction, which indicates whether it’s a customer’s purchase or a renewal for an auto-renewable subscription that the system initates.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/transactionreason transactionReason}
**/
transactionReason?: TransactionReason | string
/**
* The three-letter ISO 4217 currency code for the price of the product.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/currency currency}
**/
currency?: string
/**
* The price of the in-app purchase or subscription offer that you configured in App Store Connect, as an integer.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/price price}
**/
price?: number
/**
* The payment mode you configure for an introductory offer, promotional offer, or offer code on an auto-renewable subscription.
*
* {@link https://developer.apple.com/documentation/appstoreserverapi/offerdiscounttype offerDiscountType}
**/
offerDiscountType?: OfferDiscountType | string
}
export class JWSTransactionDecodedPayloadValidator implements Validator<JWSTransactionDecodedPayload> {
static readonly environmentValidator = new EnvironmentValidator()
static readonly offerTypeValidator = new OfferTypeValidator()
static readonly revocationReasonValidator = new RevocationReasonValidator()
static readonly inAppOwnershipTypeValidator = new InAppOwnershipTypeValidator()
static readonly typeValidator = new TypeValidator()
static readonly transactionReasonValidator = new TransactionReasonValidator()
static readonly offerDiscountTypeValidator = new OfferDiscountTypeValidator()
validate(obj: any): obj is JWSTransactionDecodedPayload {
if ((typeof obj['originalTransactionId'] !== 'undefined') && !(typeof obj['originalTransactionId'] === "string" || obj['originalTransactionId'] instanceof String)) {
return false
}
if ((typeof obj['transactionId'] !== 'undefined') && !(typeof obj['transactionId'] === "string" || obj['transactionId'] instanceof String)) {
return false
}
if ((typeof obj['webOrderLineItemId'] !== 'undefined') && !(typeof obj['webOrderLineItemId'] === "string" || obj['webOrderLineItemId'] instanceof String)) {
return false
}
if ((typeof obj['bundleId'] !== 'undefined') && !(typeof obj['bundleId'] === "string" || obj['bundleId'] instanceof String)) {
return false
}
if ((typeof obj['productId'] !== 'undefined') && !(typeof obj['productId'] === "string" || obj['productId'] instanceof String)) {
return false
}
if ((typeof obj['subscriptionGroupIdentifier'] !== 'undefined') && !(typeof obj['subscriptionGroupIdentifier'] === "string" || obj['subscriptionGroupIdentifier'] instanceof String)) {
return false
}
if ((typeof obj['purchaseDate'] !== 'undefined') && !(typeof obj['purchaseDate'] === "number")) {
return false
}
if ((typeof obj['originalPurchaseDate'] !== 'undefined') && !(typeof obj['originalPurchaseDate'] === "number")) {
return false
}
if ((typeof obj['expiresDate'] !== 'undefined') && !(typeof obj['expiresDate'] === "number")) {
return false
}
if ((typeof obj['quantity'] !== 'undefined') && !(typeof obj['quantity'] === 'number')) {
return false
}
if ((typeof obj['type'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.typeValidator.validate(obj['type']))) {
return false
}
if ((typeof obj['appAccountToken'] !== 'undefined') && !(typeof obj['appAccountToken'] === "string" || obj['appAccountToken'] instanceof String)) {
return false
}
if ((typeof obj['inAppOwnershipType'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.inAppOwnershipTypeValidator.validate(obj['inAppOwnershipType']))) {
return false
}
if ((typeof obj['signedDate'] !== 'undefined') && !(typeof obj['signedDate'] === "number")) {
return false
}
if ((typeof obj['revocationReason'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.revocationReasonValidator.validate(obj['revocationReason']))) {
return false
}
if ((typeof obj['revocationDate'] !== 'undefined') && !(typeof obj['revocationDate'] === "number")) {
return false
}
if ((typeof obj['isUpgraded'] !== 'undefined') && !(typeof obj['isUpgraded'] === "boolean" || obj['isUpgraded'] instanceof Boolean)) {
return false
}
if ((typeof obj['offerType'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.offerTypeValidator.validate(obj['offerType']))) {
return false
}
if ((typeof obj['offerIdentifier'] !== 'undefined') && !(typeof obj['offerIdentifier'] === "string" || obj['offerIdentifier'] instanceof String)) {
return false
}
if ((typeof obj['environment'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.environmentValidator.validate(obj['environment']))) {
return false
}
if ((typeof obj['storefront'] !== 'undefined') && !(typeof obj['storefront'] === "string" || obj['storefront'] instanceof String)) {
return false
}
if ((typeof obj['storefrontId'] !== 'undefined') && !(typeof obj['storefrontId'] === "string" || obj['storefrontId'] instanceof String)) {
return false
}
if ((typeof obj['transactionReason'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.transactionReasonValidator.validate(obj['transactionReason']))) {
return false
}
if ((typeof obj['currency'] !== 'undefined') && !(typeof obj['currency'] === "string" || obj['currency'] instanceof String)) {
return false
}
if ((typeof obj['price'] !== 'undefined') && !(typeof obj['price'] === "number")) {
return false
}
if ((typeof obj['offerDiscountType'] !== 'undefined') && !(JWSTransactionDecodedPayloadValidator.offerDiscountTypeValidator.validate(obj['offerDiscountType']))) {
return false
}
return true
}
}