appstore-connect-sdk 0.0.3 → 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,6 +1,8 @@
1
- # appstoreconnect-api [![@latest](https://img.shields.io/npm/v/appstore-connect-sdk.svg)](https://www.npmjs.com/package/appstore-connect-sdk)
1
+ # Appstore Connect SDK [![@latest](https://img.shields.io/npm/v/appstore-connect-sdk.svg)](https://www.npmjs.com/package/appstore-connect-sdk)
2
2
 
3
- App Store Connect SDK for Nodejs, written in Typescript, supports all APIs based on OpenAPI Generator.
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)
4
6
 
5
7
  ## Kickstart information on the API
6
8
 
@@ -10,15 +12,14 @@ App Store Connect SDK for Nodejs, written in Typescript, supports all APIs based
10
12
 
11
13
  ## Included in this SDK
12
14
 
13
- - [x] Configuration with API Key
14
- - [x] JWT Logic to sign requests
15
- - [x] Support custom network libraries for making requests, such as fetch/node-fetch/axios...
16
- - [x] Supports _all_ requests due to OpenAPI generated requests and entities
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
17
18
 
18
19
  ## Installation
19
20
 
20
21
  ```bash
21
- npm install appstoreconnect-api
22
+ npm install appstore-connect-sdk
22
23
  ```
23
24
 
24
25
  ## Usage
@@ -26,14 +27,14 @@ npm install appstoreconnect-api
26
27
  #### 1. Import `appstore-connect-sdk`
27
28
 
28
29
  ```typescript
29
- import AppStoreConnectAPI from 'appstore-connect-sdk';
30
+ import AppStoreConnectAPI from "appstore-connect-sdk";
30
31
  ```
31
32
 
32
33
  #### 2. Create your API Configuration
33
34
 
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`.
35
36
 
36
- After downloading your private key, you can open the `.p8` file containing the private key in a text editor which will show like the following content:
37
+ After downloading your private key, open the `.p8` file containing the private key in a text editor. It should look like this:
37
38
 
38
39
  ```
39
40
  -----BEGIN PRIVATE KEY-----
@@ -54,21 +55,29 @@ const appStoreConnect = new AppStoreConnectAPI({
54
55
  });
55
56
  ```
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
+
57
64
  #### 3. Create an API and perform a request
58
65
 
59
- 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 missing or any problem, please open an [issue](https://github.com/isaced/appstore-connect-sdk/issues).
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).
60
67
 
61
68
  ```typescript
62
- const api = new AppsApi(appStoreConnect.configuration);
63
- const res = await api.appsAppEventsGetToManyRelated({ id: APP_ID });
69
+ const res = await client.call(AppsApi).appsGetCollection();
64
70
  console.log(res);
65
71
  ```
66
72
 
67
- #### The complete code example above
73
+ Here's the complete code example:
68
74
 
69
75
  ```typescript
70
- import AppStoreConnectAPI from 'appstore-connect-sdk';
71
- import { AppsApi, AppEventLocalizationsApi } from 'appstore-connect-sdk/dist/openapi/apis';
76
+ import AppStoreConnectAPI from "appstore-connect-sdk";
77
+ import {
78
+ AppsApi,
79
+ AppEventLocalizationsApi,
80
+ } from "appstore-connect-sdk/dist/openapi/apis";
72
81
 
73
82
  const appStoreConnect = new AppStoreConnectAPI({
74
83
  issuerId: "<YOUR ISSUER ID>",
@@ -76,29 +85,29 @@ const appStoreConnect = new AppStoreConnectAPI({
76
85
  privateKey: "<YOUR PRIVATE KEY>",
77
86
  });
78
87
 
79
- const api = new AppsApi(appStoreConnect.configuration);
80
- const res = await api.appsAppEventsGetToManyRelated({ id: APP_ID });
88
+ const res = await client.call(AppsApi).appsGetCollection();
81
89
  console.log(res);
82
90
  ```
83
91
 
84
92
  ### Custom network libraries
85
93
 
86
- In order to adapt to different projects, it is supported to configure any network library to take over HTTP requests, just follow the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/fetch) standard specification and set `fetchApi` in the `AppStoreConnectAPI` option.
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.
87
97
 
88
98
  ```typescript
89
- import AppStoreConnectAPI from 'appstore-connect-sdk';
90
- import { FetchAPI } from "./../src/openapi/runtime";
91
- import fetch from 'node-fetch';
99
+ import AppStoreConnectAPI from "appstore-connect-sdk";
100
+ import fetch from "node-fetch";
92
101
 
93
102
  new AppStoreConnectAPI({
94
- // ...
95
- fetchApi: fetch as FetchAPI, // All network requests are made via node-fetch
103
+ // ...
104
+ fetchApi: fetch as unknown as FetchAPI, // All network requests are made via node-fetch
96
105
  });
97
106
  ```
98
107
 
99
- ## Update OpenAPI generated code
108
+ ## Updating OpenAPI generated code
100
109
 
101
- Run the following:
110
+ To update the OpenAPI-generated code, run the following command:
102
111
 
103
112
  ```bash
104
113
  $ sh gen-openapi.sh
@@ -108,8 +117,8 @@ This will generate Typescript code through [OpenAPI Generator](https://openapi-g
108
117
 
109
118
  ## License
110
119
 
111
- **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 info.
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.
112
121
 
113
122
  ## Author
114
123
 
115
- This project is originally created by [isaced](https://github.com/isaced) but has a lot of [great contributors](https://github.com/isaced/appstore-connect-sdk/graphs/contributors). We're open for contributions of any kind to make this project even better.
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 {
7
+ /**
8
+ * The issuer ID associated with the private key.
9
+ */
4
10
  issuerId: string;
11
+ /**
12
+ * The ID of the private key.
13
+ */
5
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
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.3",
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",