Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gunzipSync } from 'node:zlib';
import { SignJWT, importPKCS8 } from 'jose';

// issuerId and apiKey from https://appstoreconnect.apple.com/access/api
Expand Down Expand Up @@ -99,9 +100,12 @@ export const api = async function AppStoreConnectApiFetcher({ issuerId, apiKey,
url = parsed.toString();
}
const response = await authFetch(url, options);
const text = await response.text();
const contentType = response.headers.get('content-type');
const isJson = (contentType === 'application/json' || contentType === 'application/vnd.api+json');
const isTsvGzip = contentType === 'application/a-gzip';
const text = isTsvGzip ?
gunzipSync(new Buffer.from(await response.arrayBuffer())).toString()
: await response.text();
const crawlAllPages = options?.crawlAllPages ?? true;
if (response.ok) {
if (isJson) {
Expand Down Expand Up @@ -133,6 +137,9 @@ export const api = async function AppStoreConnectApiFetcher({ issuerId, apiKey,
} else {
return result.data;
}
} else if (isTsvGzip) {
const [headers, ...rows] = text.split('\n').map(line => line.split('\t'));
return { data: rows.map(row => Object.fromEntries(headers.map((header, i) => [header, row[i]]))) };
} else {
return text;
}
Expand Down