The App Store Server Library
npm install app-store-server-libraryThis software is currently in Beta testing. Therefore, it should only be used for testing purposes, like for the Sandbox environment. API signatures may change between releases and signature verification may receive security updates.
#### Requirements
- Node 16+
bash
With NPM
npm install @apple/app-store-server-library --save
With Yarn
yarn add @apple/app-store-server-library
`Documentation
Usage
$3
`typescript
import { AppStoreServerAPIClient, Environment, SendTestNotificationResponse } from "@apple/app-store-server-library"const issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"
const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const environment = Environment.SANDBOX
const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
try {
const response: SendTestNotificationResponse = await client.requestTestNotification()
console.log(response)
} catch (e) {
console.error(e)
}
`$3
`typescript
import { SignedDataVerifier } from "@apple/app-store-server-library/dist/jwt_verification"const bundleId = "com.example"
const appleRootCAs: Buffer[] = loadRootCAs() // Specific implementation may vary
const enableOnlineChecks = true
const environment = Environment.SANDBOX
const verifier = new SignedDataVerifier(appleRootCAs, enableOnlineChecks, environment, bundleId)
const notificationPayload = "ey..."
const verifiedNotification = await verifier.verifyAndDecodeNotification()
console.log(verifiedNotification)
`$3
`typescript
import { AppStoreServerAPIClient, Environment, ReceiptUtility, Order, ProductType, HistoryResponse, TransactionHistoryRequest } from "@apple/app-store-server-library"const issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"
const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const environment = Environment.SANDBOX
const client =
new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
const appReceipt = "MI..."
const receiptUtil = new ReceiptUtility()
const transactionId = receiptUtil.extractTransactionIdFromAppReceipt(appReceipt)
if (transactionId != null) {
const transactionHistoryRequest: TransactionHistoryRequest = {
sort: Order.ASCENDING,
revoked: false,
productTypes: [ProductType.AUTO_RENEWABLE]
}
let response: HistoryResponse | null = null
let transactions: string[] = []
do {
const revisionToken = response !== null && response.revision !== null ? response.revision : null
response = await client.getTransactionHistory(transactionId, revisionToken, transactionHistoryRequest)
if (response.signedTransactions) {
transactions = transactions.concat(response.signedTransactions)
}
} while (response.hasMore)
console.log(transactions)
}
`$3
`typescript
import { PromotionalOfferSignatureCreator } from "@apple/app-store-server-library"const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const productId = ""
const subscriptionOfferId = ""
const applicationUsername = ""
const signatureCreator = new PromotionalOfferSignatureCreator(encodedKey, keyId, bundleId)
const signature = signatureCreator.createSignature(productId, subscriptionOfferId, signatureCreator)
console.log(signature)
``Only the latest major version of the library will receive updates, including security updates. Therefore, it is recommended to update to new major versions.