appstore-connect-sdk 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -1,2 +1,124 @@
1
- # appstoreconnect-api
2
- An App Store Connect API client for Node.js
1
+ # Appstore Connect SDK [![@latest](https://img.shields.io/npm/v/appstore-connect-sdk.svg)](https://www.npmjs.com/package/appstore-connect-sdk)
2
+
3
+ The App Store Connect SDK for Node.js is written in TypeScript and supports all APIs based on OpenAPI Generator.
4
+
5
+ English | [简体中文](https://github.com/isaced/appstore-connect-sdk/blob/main/README_zh.md)
6
+
7
+ ## Kickstart information on the API
8
+
9
+ - [Automate your workflow with the App Store Connect API](https://developer.apple.com/app-store-connect/api/)
10
+ - [App Store Connect API Official Documentation](https://developer.apple.com/documentation/appstoreconnectapi)
11
+ - [WWDC 2018 303 - Automating App Store Connect](https://developer.apple.com/videos/play/wwdc2018/303/) (Video)
12
+
13
+ ## Included in this SDK
14
+
15
+ - [x] Configuration with API Key and JWT Logic to sign requests
16
+ - [x] Support for custom network libraries for making requests, such as fetch/node-fetch/axios...
17
+ - [x] Support for _all_ requests due to OpenAPI generated requests and entities
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install appstore-connect-sdk
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ #### 1. Import `appstore-connect-sdk`
28
+
29
+ ```typescript
30
+ import AppStoreConnectAPI from "appstore-connect-sdk";
31
+ ```
32
+
33
+ #### 2. Create your API Configuration
34
+
35
+ Go to [App Sotre Connect -> Users and Access -> Keys](https://appstoreconnect.apple.com/access/api) and create your own key. This is also the page to find your `private key ID` and the `issuer ID`.
36
+
37
+ After downloading your private key, open the `.p8` file containing the private key in a text editor. It should look like this:
38
+
39
+ ```
40
+ -----BEGIN PRIVATE KEY-----
41
+ AIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgKEn1VBakCdHIEcdS
42
+ aBWr/9laASzaAbF2LP7wTYjHK52gCgYIKoZIzj0DAQehRANCAAQ/jf2sxRvXEhjn
43
+ srw8kJcHvO0dQ1KmUlxZvATsFsjJbdQ1yAENAWItUoeTV0rhdajcdOQxKl1OPse0
44
+ nNdXXbA4
45
+ -----END PRIVATE KEY-----
46
+ ```
47
+
48
+ Now use this `Private Key` together with the `isuer ID` and the `private key ID` to create your configuration:
49
+
50
+ ```typescript
51
+ const appStoreConnect = new AppStoreConnectAPI({
52
+ issuerId: "<YOUR ISSUER ID>",
53
+ privateKeyId: "<YOUR PRIVATE KEY ID>",
54
+ privateKey: "<YOUR PRIVATE KEY>",
55
+ });
56
+ ```
57
+
58
+ For more information on how JWT works with the App Store Connect API, check out Apple's authentication guides:
59
+
60
+ - [Creating API Keys for App Store Connect API](https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api)
61
+ - [Generating Tokens for API Requests](https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests)
62
+ - [Revoking API Keys](https://developer.apple.com/documentation/appstoreconnectapi/revoking_api_keys)
63
+
64
+ #### 3. Create an API and perform a request
65
+
66
+ You can find all available APIs in [src/openapi/apis](https://github.com/isaced/appstore-connect-sdk/tree/main/src/openapi/apis), these classes are generated according to [App Store Connect API - OpenAPI specification](https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip), If you encounter any problems, please open an [issue](https://github.com/isaced/appstore-connect-sdk/issues).
67
+
68
+ ```typescript
69
+ const res = await client.call(AppsApi).appsGetCollection();
70
+ console.log(res);
71
+ ```
72
+
73
+ Here's the complete code example:
74
+
75
+ ```typescript
76
+ import AppStoreConnectAPI from "appstore-connect-sdk";
77
+ import {
78
+ AppsApi,
79
+ AppEventLocalizationsApi,
80
+ } from "appstore-connect-sdk/dist/openapi/apis";
81
+
82
+ const appStoreConnect = new AppStoreConnectAPI({
83
+ issuerId: "<YOUR ISSUER ID>",
84
+ privateKeyId: "<YOUR PRIVATE KEY ID>",
85
+ privateKey: "<YOUR PRIVATE KEY>",
86
+ });
87
+
88
+ const res = await client.call(AppsApi).appsGetCollection();
89
+ console.log(res);
90
+ ```
91
+
92
+ ### Custom network libraries
93
+
94
+ By default, AppStoreConnectAPI uses its built-in `fetch` function for HTTP requests. Note that this function requires Node.js version **18.0.0** or higher.
95
+
96
+ However, you can also configure any network library that adheres to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/fetch) standard specification by setting the `fetchApi` option in the AppStoreConnectAPI constructor.
97
+
98
+ ```typescript
99
+ import AppStoreConnectAPI from "appstore-connect-sdk";
100
+ import fetch from "node-fetch";
101
+
102
+ new AppStoreConnectAPI({
103
+ // ...
104
+ fetchApi: fetch as unknown as FetchAPI, // All network requests are made via node-fetch
105
+ });
106
+ ```
107
+
108
+ ## Updating OpenAPI generated code
109
+
110
+ To update the OpenAPI-generated code, run the following command:
111
+
112
+ ```bash
113
+ $ sh gen-openapi.sh
114
+ ```
115
+
116
+ This will generate Typescript code through [OpenAPI Generator](https://openapi-generator.tech/) based on the [OpenAPI specification](https://github.com/isaced/appstore-connect-sdk/blob/fdabb5bb414e9e3c02341ac1fa3238a5bfa15c30/app_store_connect_api_2.2_openapi.json) file officially released by Apple.
117
+
118
+ ## License
119
+
120
+ **appstore-connect-sdk** is available under the MIT license, and uses source code from open source projects. See the [LICENSE](https://github.com/isaced/appstore-connect-sdk/blob/main/LICENSE) file for more information.
121
+
122
+ ## Author
123
+
124
+ This project was originally created by [isaced](https://github.com/isaced) but has had many [great contributors](https://github.com/isaced/appstore-connect-sdk/graphs/contributors). We're open to contributions of any kind to make this project even better.
package/dist/auth.js CHANGED
@@ -5,20 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.generateAuthToken = void 0;
7
7
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ // Generates a JWT token for use with the App Store Connect API
8
9
  function generateAuthToken({ apiKeyId, issuerId, privateKey, expirationTime }) {
10
+ // Default expiration time is 10 minutes (600 seconds)
9
11
  const EXPIRATION_TIME = expirationTime || 10 * 60;
12
+ // Generate the token using the provided options
10
13
  const token = jsonwebtoken_1.default.sign({}, privateKey, {
11
14
  algorithm: "ES256",
12
15
  expiresIn: EXPIRATION_TIME,
13
16
  issuer: issuerId,
14
17
  audience: "appstoreconnect-v1",
15
18
  header: {
19
+ // The algorithm used to sign the token (ECDSA with SHA-256)
16
20
  alg: "ES256",
21
+ // The ID of the private key used to sign the token
17
22
  kid: apiKeyId,
23
+ // The type of the token (JWT)
18
24
  typ: "JWT",
19
25
  },
20
26
  });
21
- console.log("Gen JWT Token: ", token);
27
+ // Log the generated token to the console for debugging purposes
28
+ console.log("Generated JWT Token: ", token);
29
+ // Return the generated token
22
30
  return token;
23
31
  }
24
32
  exports.generateAuthToken = generateAuthToken;
package/dist/main.d.ts CHANGED
@@ -1,14 +1,49 @@
1
- import { FetchAPI } from "./openapi/runtime";
1
+ import { FetchAPI, BaseAPI } from "./openapi/runtime";
2
2
  import { Configuration } from "./openapi";
3
+ /**
4
+ * Options for configuring the AppStoreConnectAPI instance.
5
+ */
3
6
  interface AppStoreConnectAPIOptions {
4
- apiKey: string;
7
+ /**
8
+ * The issuer ID associated with the private key.
9
+ */
5
10
  issuerId: string;
11
+ /**
12
+ * The ID of the private key.
13
+ */
14
+ privateKeyId: string;
15
+ /**
16
+ * The private key in PEM format.
17
+ */
6
18
  privateKey: string;
19
+ /**
20
+ * An optional FetchAPI instance to use for making HTTP requests.
21
+ */
7
22
  fetchApi?: FetchAPI;
8
23
  }
24
+ /**
25
+ * The App Store Connect SDK for Node.js is written in TypeScript and supports all APIs
26
+ * based on OpenAPI Generator.
27
+ *
28
+ * https://github.com/isaced/appstore-connect-sdk
29
+ */
9
30
  export default class AppStoreConnectAPI {
10
31
  private bearerToken?;
11
32
  configuration?: Configuration;
33
+ /**
34
+ * Creates an instance of the AppStoreConnectAPI.
35
+ * @param options - The configuration options for the API.
36
+ * @param options.issuerId - The issuer ID for generating JWT token.
37
+ * @param options.privateKeyId - The ID of the private key used for generating JWT token.
38
+ * @param options.privateKey - The content of the private key used for generating JWT token.
39
+ * @param options.fetchApi - (Optional) The FetchAPI implementation to use for API requests.
40
+ */
12
41
  constructor(options: AppStoreConnectAPIOptions);
42
+ /**
43
+ * Calls the specified API class using the current Configuration object.
44
+ * @param apiClass - The API class to instantiate.
45
+ * @returns An instance of the specified API class.
46
+ */
47
+ call<T extends BaseAPI>(apiClass: new (configuration?: Configuration) => T): T;
13
48
  }
14
49
  export {};
package/dist/main.js CHANGED
@@ -2,13 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const openapi_1 = require("./openapi");
4
4
  const auth_1 = require("./auth");
5
+ /**
6
+ * The App Store Connect SDK for Node.js is written in TypeScript and supports all APIs
7
+ * based on OpenAPI Generator.
8
+ *
9
+ * https://github.com/isaced/appstore-connect-sdk
10
+ */
5
11
  class AppStoreConnectAPI {
12
+ /**
13
+ * Creates an instance of the AppStoreConnectAPI.
14
+ * @param options - The configuration options for the API.
15
+ * @param options.issuerId - The issuer ID for generating JWT token.
16
+ * @param options.privateKeyId - The ID of the private key used for generating JWT token.
17
+ * @param options.privateKey - The content of the private key used for generating JWT token.
18
+ * @param options.fetchApi - (Optional) The FetchAPI implementation to use for API requests.
19
+ */
6
20
  constructor(options) {
21
+ // Generate an authentication token using the provided options.
7
22
  this.bearerToken = (0, auth_1.generateAuthToken)({
8
- apiKeyId: options.apiKey,
23
+ apiKeyId: options.privateKeyId,
9
24
  issuerId: options.issuerId,
10
25
  privateKey: options.privateKey,
11
26
  });
27
+ // Create a Configuration object with the authentication token and any provided FetchAPI implementation.
12
28
  this.configuration = new openapi_1.Configuration({
13
29
  headers: {
14
30
  Authorization: `Bearer ${this.bearerToken}`,
@@ -16,5 +32,13 @@ class AppStoreConnectAPI {
16
32
  fetchApi: options.fetchApi,
17
33
  });
18
34
  }
35
+ /**
36
+ * Calls the specified API class using the current Configuration object.
37
+ * @param apiClass - The API class to instantiate.
38
+ * @returns An instance of the specified API class.
39
+ */
40
+ call(apiClass) {
41
+ return new apiClass(this.configuration);
42
+ }
19
43
  }
20
44
  exports.default = AppStoreConnectAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appstore-connect-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "An App Store Connect API client for Node.js",
5
5
  "keywords": [
6
6
  "appstore connect",
@@ -20,6 +20,7 @@
20
20
  "@openapitools/openapi-generator-cli": "^2.5.2",
21
21
  "@types/jest": "^29.4.0",
22
22
  "@types/jsonwebtoken": "^9.0.1",
23
+ "@types/node-fetch": "^2.0.0",
23
24
  "dotenv": "^16.0.3",
24
25
  "jest": "^29.4.2",
25
26
  "node-fetch": "^2.0.0",
@@ -40,4 +41,4 @@
40
41
  "email": "isaced@163.com"
41
42
  },
42
43
  "homepage": "https://github.com/isaced/appstore-connect-sdk"
43
- }
44
+ }