@rage-against-the-pixel/app-store-connect-api 3.6.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.
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // This file is auto-generated by @hey-api/openapi-ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,45 @@
1
+ import * as services from './app_store_connect_api/services.gen';
2
+ /**
3
+ * Options for configuring the App Store Connect client.
4
+ * @see https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api
5
+ */
6
+ interface AppStoreConnectOptions {
7
+ /**
8
+ * The issuer ID associated with the private key.
9
+ */
10
+ issuerId?: string;
11
+ /**
12
+ * The ID of the private key.
13
+ */
14
+ privateKeyId?: string;
15
+ /**
16
+ * The private key in PEM format.
17
+ */
18
+ privateKey?: string;
19
+ /**
20
+ * The path to the private key file.
21
+ */
22
+ privateKeyFile?: string;
23
+ /**
24
+ * A bearer token can be provided directly, which will be used instead of generating a new token
25
+ */
26
+ bearerToken?: string;
27
+ /**
28
+ * The time (in seconds) until the token expires (default 10 minutes)
29
+ */
30
+ expirationTime?: number;
31
+ }
32
+ declare class AppStoreConnectClient {
33
+ private appStoreConnectOptions;
34
+ private bearerToken;
35
+ private bearerTokenGeneratedAt;
36
+ api: typeof services;
37
+ constructor(appStoreConnectOptions: AppStoreConnectOptions);
38
+ private getToken;
39
+ /**
40
+ * Generates a JWT token for authenticating with the App Store Connect API.
41
+ * @see https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
42
+ */
43
+ private generateAuthToken;
44
+ }
45
+ export { AppStoreConnectOptions, AppStoreConnectClient };
package/dist/client.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.AppStoreConnectClient = void 0;
30
+ const services = __importStar(require("./app_store_connect_api/services.gen"));
31
+ const jose = __importStar(require("jose"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ class AppStoreConnectClient {
34
+ appStoreConnectOptions;
35
+ bearerToken = null;
36
+ bearerTokenGeneratedAt = 0;
37
+ api = services;
38
+ constructor(appStoreConnectOptions) {
39
+ if (!appStoreConnectOptions) {
40
+ throw new Error('AppStoreConnectOptions is required');
41
+ }
42
+ this.appStoreConnectOptions = appStoreConnectOptions;
43
+ services.client.setConfig({ baseUrl: 'https://api.appstoreconnect.apple.com' });
44
+ services.client.interceptors.request.use(async (request, _options) => {
45
+ request.headers.set('Authorization', `Bearer ${await this.getToken()}`);
46
+ return request;
47
+ });
48
+ }
49
+ async getToken() {
50
+ if (this.appStoreConnectOptions.bearerToken) {
51
+ this.bearerToken = this.appStoreConnectOptions.bearerToken;
52
+ }
53
+ else {
54
+ if (this.appStoreConnectOptions.privateKeyId &&
55
+ this.appStoreConnectOptions.issuerId &&
56
+ (this.appStoreConnectOptions.privateKey || this.appStoreConnectOptions.privateKeyFile)) {
57
+ const defaultExpirationTime = 600; // 10 minutes
58
+ const expirationTime = this.appStoreConnectOptions.expirationTime ?? defaultExpirationTime;
59
+ if (!this.bearerToken || this.bearerTokenGeneratedAt + expirationTime * 1000 < Date.now()) {
60
+ if (this.appStoreConnectOptions.privateKeyFile) {
61
+ const fileHandle = await fs_1.default.promises.open(this.appStoreConnectOptions.privateKeyFile, 'r');
62
+ try {
63
+ this.appStoreConnectOptions.privateKey = await fileHandle.readFile('utf8');
64
+ }
65
+ finally {
66
+ await fileHandle.close();
67
+ }
68
+ }
69
+ this.bearerToken = await this.generateAuthToken(this.appStoreConnectOptions.issuerId, this.appStoreConnectOptions.privateKeyId, this.appStoreConnectOptions.privateKey, expirationTime);
70
+ }
71
+ }
72
+ else {
73
+ throw new Error('Bearer token or private key information is required to generate a token');
74
+ }
75
+ }
76
+ return this.bearerToken;
77
+ }
78
+ /**
79
+ * Generates a JWT token for authenticating with the App Store Connect API.
80
+ * @see https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
81
+ */
82
+ async generateAuthToken(issuerId, privateKeyId, privateKey, expirationTime) {
83
+ const alg = "ES256";
84
+ const key = await jose.importPKCS8(privateKey, alg);
85
+ const token = await new jose.SignJWT({})
86
+ .setProtectedHeader({ alg, kid: privateKeyId, typ: "JWT" })
87
+ .setIssuer(issuerId)
88
+ .setAudience("appstoreconnect-v1")
89
+ .setExpirationTime(new Date(Date.now() + expirationTime * 1000))
90
+ .sign(key);
91
+ return token;
92
+ }
93
+ }
94
+ exports.AppStoreConnectClient = AppStoreConnectClient;
@@ -0,0 +1 @@
1
+ export * from './client';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client"), exports);
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@rage-against-the-pixel/app-store-connect-api",
3
+ "version": "3.6.0",
4
+ "description": "A TypeScript package for communicating with Apple App Store Connect API",
5
+ "author": "RageAgainstThePixel",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/RageAgainstThePixel/app-store-connect-api"
10
+ },
11
+ "keywords": [
12
+ "apple",
13
+ "app store",
14
+ "connect",
15
+ "api",
16
+ "api client",
17
+ "app store api",
18
+ "app store connect",
19
+ "app store connect api",
20
+ "app-store-connect",
21
+ "app-store-connect-api",
22
+ "typescript"
23
+ ],
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "files": [
27
+ "dist/**/*"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "watch": "tsc -w",
32
+ "openapi-ts": "openapi-ts",
33
+ "test": "jest",
34
+ "generate": "npx @hey-api/openapi-ts -f ./openapi-ts.config.ts && tsc"
35
+ },
36
+ "devDependencies": {
37
+ "@hey-api/openapi-ts": "^0.53.10",
38
+ "@types/jest": "^29.5.13",
39
+ "@types/node": "^22.7.5",
40
+ "jest": "^29.7.0",
41
+ "ts-jest": "^29.2.5",
42
+ "ts-node": "^10.9.2",
43
+ "typescript": "^5.6.3"
44
+ },
45
+ "dependencies": {
46
+ "@hey-api/client-fetch": "^0.4.1",
47
+ "jose": "^5.9.4"
48
+ }
49
+ }