@rage-against-the-pixel/app-store-connect-api 3.7.0 → 3.8.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/dist/client.d.ts CHANGED
@@ -41,5 +41,10 @@ declare class AppStoreConnectClient {
41
41
  * @see https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
42
42
  */
43
43
  private generateAuthToken;
44
+ /**
45
+ * Generates a user auth token for authenticating with the App Store Connect API.
46
+ * @see https://developer.apple.com/documentation/appstoreconnectapi/generating-tokens-for-api-requests#Create-the-JWT-Payload-for-Individual-Keys
47
+ */
48
+ private generateUserAuthToken;
44
49
  }
45
50
  export { AppStoreConnectOptions, AppStoreConnectClient };
package/dist/client.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
@@ -51,14 +61,13 @@ class AppStoreConnectClient {
51
61
  this.bearerToken = this.appStoreConnectOptions.bearerToken;
52
62
  }
53
63
  else {
54
- if (this.appStoreConnectOptions.privateKeyId &&
55
- this.appStoreConnectOptions.issuerId &&
56
- (this.appStoreConnectOptions.privateKey || this.appStoreConnectOptions.privateKeyFile)) {
64
+ const { privateKeyId, issuerId, privateKey, privateKeyFile, expirationTime } = this.appStoreConnectOptions;
65
+ if (privateKeyId && (privateKey || privateKeyFile)) {
57
66
  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');
67
+ const tokenExpirationTime = expirationTime ?? defaultExpirationTime;
68
+ if (!this.bearerToken || this.bearerTokenGeneratedAt + tokenExpirationTime * 1000 < Date.now()) {
69
+ if (privateKeyFile) {
70
+ const fileHandle = await fs_1.default.promises.open(privateKeyFile, fs_1.default.constants.O_RDONLY);
62
71
  try {
63
72
  this.appStoreConnectOptions.privateKey = await fileHandle.readFile('utf8');
64
73
  }
@@ -66,7 +75,13 @@ class AppStoreConnectClient {
66
75
  await fileHandle.close();
67
76
  }
68
77
  }
69
- this.bearerToken = await this.generateAuthToken(this.appStoreConnectOptions.issuerId, this.appStoreConnectOptions.privateKeyId, this.appStoreConnectOptions.privateKey, expirationTime);
78
+ if (issuerId) {
79
+ this.bearerToken = await this.generateAuthToken(issuerId, privateKeyId, this.appStoreConnectOptions.privateKey, tokenExpirationTime);
80
+ }
81
+ else {
82
+ this.bearerToken = await this.generateUserAuthToken(privateKeyId, this.appStoreConnectOptions.privateKey, tokenExpirationTime);
83
+ }
84
+ this.bearerTokenGeneratedAt = Date.now();
70
85
  }
71
86
  }
72
87
  else {
@@ -80,12 +95,27 @@ class AppStoreConnectClient {
80
95
  * @see https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
81
96
  */
82
97
  async generateAuthToken(issuerId, privateKeyId, privateKey, expirationTime) {
83
- const alg = "ES256";
98
+ const alg = 'ES256';
84
99
  const key = await jose.importPKCS8(privateKey, alg);
85
100
  const token = await new jose.SignJWT({})
86
- .setProtectedHeader({ alg, kid: privateKeyId, typ: "JWT" })
101
+ .setProtectedHeader({ alg, kid: privateKeyId, typ: 'JWT' })
87
102
  .setIssuer(issuerId)
88
- .setAudience("appstoreconnect-v1")
103
+ .setAudience('appstoreconnect-v1')
104
+ .setExpirationTime(new Date(Date.now() + expirationTime * 1000))
105
+ .sign(key);
106
+ return token;
107
+ }
108
+ /**
109
+ * Generates a user auth token for authenticating with the App Store Connect API.
110
+ * @see https://developer.apple.com/documentation/appstoreconnectapi/generating-tokens-for-api-requests#Create-the-JWT-Payload-for-Individual-Keys
111
+ */
112
+ async generateUserAuthToken(privateKeyId, privateKey, expirationTime) {
113
+ const alg = 'ES256';
114
+ const key = await jose.importPKCS8(privateKey, alg);
115
+ const token = await new jose.SignJWT({})
116
+ .setProtectedHeader({ alg, kid: privateKeyId, typ: 'JWT' })
117
+ .setSubject('user')
118
+ .setAudience('appstoreconnect-v1')
89
119
  .setExpirationTime(new Date(Date.now() + expirationTime * 1000))
90
120
  .sign(key);
91
121
  return token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rage-against-the-pixel/app-store-connect-api",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "A TypeScript package for communicating with Apple App Store Connect API",
5
5
  "author": "RageAgainstThePixel",
6
6
  "license": "MIT",
@@ -34,16 +34,16 @@
34
34
  "generate": "npx @hey-api/openapi-ts -f ./openapi-ts.config.ts && tsc"
35
35
  },
36
36
  "devDependencies": {
37
- "@hey-api/openapi-ts": "^0.53.10",
38
- "@types/jest": "^29.5.13",
39
- "@types/node": "^22.7.5",
37
+ "@hey-api/openapi-ts": "^0.53.12",
38
+ "@types/jest": "^29.5.14",
39
+ "@types/node": "^22.13.4",
40
40
  "jest": "^29.7.0",
41
41
  "ts-jest": "^29.2.5",
42
42
  "ts-node": "^10.9.2",
43
- "typescript": "^5.6.3"
43
+ "typescript": "^5.7.3"
44
44
  },
45
45
  "dependencies": {
46
- "@hey-api/client-fetch": "^0.4.1",
47
- "jose": "^5.9.4"
46
+ "@hey-api/client-fetch": "^0.4.4",
47
+ "jose": "^5.9.6"
48
48
  }
49
49
  }