appstore-connect-sdk 0.0.9 → 1.0.0-beta.1
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 +9 -14
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +45 -14
- package/dist/main.d.ts +8 -8
- package/dist/main.js +50 -32
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -17,8 +17,7 @@ The `appstore-connect-sdk` module includes the following features:
|
|
|
17
17
|
- [x] Configuration with API Key and JWT Logic to sign requests
|
|
18
18
|
- [x] Support for custom network libraries for making requests, such as fetch/node-fetch/axios...
|
|
19
19
|
- [x] Support for _all_ requests due to OpenAPI generated requests and entities
|
|
20
|
-
- [x] Compatibility with both Node.js and **Deno** environments
|
|
21
|
-
- [] ESM Support
|
|
20
|
+
- [x] Compatibility with both Node.js and **Deno** environments
|
|
22
21
|
|
|
23
22
|
## Examples
|
|
24
23
|
|
|
@@ -41,7 +40,7 @@ import AppStoreConnectAPI from "appstore-connect-sdk";
|
|
|
41
40
|
|
|
42
41
|
#### 2. Create your API Configuration
|
|
43
42
|
|
|
44
|
-
Go to [App
|
|
43
|
+
Go to [App Store 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`.
|
|
45
44
|
|
|
46
45
|
After downloading your private key, open the `.p8` file containing the private key in a text editor. It should look like this:
|
|
47
46
|
|
|
@@ -57,7 +56,7 @@ nNdXXbA4
|
|
|
57
56
|
Now use this `Private Key` together with the `isuer ID` and the `private key ID` to create your configuration:
|
|
58
57
|
|
|
59
58
|
```typescript
|
|
60
|
-
const
|
|
59
|
+
const client = new AppStoreConnectAPI({
|
|
61
60
|
issuerId: "<YOUR ISSUER ID>",
|
|
62
61
|
privateKeyId: "<YOUR PRIVATE KEY ID>",
|
|
63
62
|
privateKey: "<YOUR PRIVATE KEY>",
|
|
@@ -75,7 +74,8 @@ For more information on how JWT works with the App Store Connect API, check out
|
|
|
75
74
|
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).
|
|
76
75
|
|
|
77
76
|
```typescript
|
|
78
|
-
const
|
|
77
|
+
const api = await client.create(AppsApi);
|
|
78
|
+
const res = await api.appsGetCollection();
|
|
79
79
|
console.log(res);
|
|
80
80
|
```
|
|
81
81
|
|
|
@@ -88,13 +88,14 @@ import {
|
|
|
88
88
|
AppEventLocalizationsApi,
|
|
89
89
|
} from "appstore-connect-sdk/dist/openapi/apis";
|
|
90
90
|
|
|
91
|
-
const
|
|
91
|
+
const client = new AppStoreConnectAPI({
|
|
92
92
|
issuerId: "<YOUR ISSUER ID>",
|
|
93
93
|
privateKeyId: "<YOUR PRIVATE KEY ID>",
|
|
94
94
|
privateKey: "<YOUR PRIVATE KEY>",
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
const
|
|
97
|
+
const api = await client.create(AppsApi);
|
|
98
|
+
const res = await api.appsGetCollection();
|
|
98
99
|
console.log(res);
|
|
99
100
|
```
|
|
100
101
|
|
|
@@ -126,13 +127,7 @@ This will generate Typescript code through [OpenAPI Generator](https://openapi-g
|
|
|
126
127
|
|
|
127
128
|
## Deno Compatibility
|
|
128
129
|
|
|
129
|
-
The appstore-connect-sdk module is
|
|
130
|
-
|
|
131
|
-
One specific limitation is that the `jsonwebtoken` package, which is used by the appstore-connect-sdk module to generate JSON Web Tokens (JWTs), is not fully compatible with Deno. As a result, it is not possible to use `jsonwebtoken` in a Deno environment to generate JWTs for use with the App Store Connect API.
|
|
132
|
-
|
|
133
|
-
To work around this limitation, you can manually generate JWTs using a library that is fully compatible with Deno, such as `djwt`. You can then pass the manually generated JWT to the `appstore-connect-sdk` module to authenticate with the App Store Connect API.
|
|
134
|
-
|
|
135
|
-
An example of using the `appstore-connect-sdk` module in a Deno environment can be found in the [deno_example](https://github.com/isaced/appstore-connect-sdk/tree/deno_example).
|
|
130
|
+
The `appstore-connect-sdk` module is fully compatible with Deno, An example of using the `appstore-connect-sdk` module in a Deno environment can be found in the [deno_example](https://github.com/isaced/appstore-connect-sdk/tree/deno_example).
|
|
136
131
|
|
|
137
132
|
We are committed to ensuring that the `appstore-connect-sdk` module remains fully compatible with both Node.js and Deno, and we will continue to work on improving its compatibility with Deno as the Deno runtime evolves.
|
|
138
133
|
|
package/dist/auth.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ interface GenerateAuthTokenOptions {
|
|
|
4
4
|
privateKey: string;
|
|
5
5
|
expirationTime?: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function generateAuthToken({ apiKeyId, issuerId, privateKey, expirationTime }: GenerateAuthTokenOptions): string
|
|
7
|
+
export declare function generateAuthToken({ apiKeyId, issuerId, privateKey, expirationTime }: GenerateAuthTokenOptions): Promise<string>;
|
|
8
8
|
export {};
|
package/dist/auth.js
CHANGED
|
@@ -1,28 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
4
33
|
};
|
|
5
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
35
|
exports.generateAuthToken = void 0;
|
|
7
|
-
const
|
|
36
|
+
const jose = __importStar(require("jose"));
|
|
8
37
|
// Generates a JWT token for use with the App Store Connect API
|
|
9
38
|
function generateAuthToken({ apiKeyId, issuerId, privateKey, expirationTime }) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
audience: "appstoreconnect-v1",
|
|
16
|
-
header: {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const alg = "ES256";
|
|
41
|
+
const key = yield jose.importPKCS8(privateKey, alg);
|
|
42
|
+
const token = yield new jose.SignJWT({})
|
|
43
|
+
.setProtectedHeader({
|
|
17
44
|
// The algorithm used to sign the token (ECDSA with SHA-256)
|
|
18
|
-
alg
|
|
45
|
+
alg,
|
|
19
46
|
// The ID of the private key used to sign the token
|
|
20
47
|
kid: apiKeyId,
|
|
21
48
|
// The type of the token (JWT)
|
|
22
49
|
typ: "JWT",
|
|
23
|
-
}
|
|
50
|
+
})
|
|
51
|
+
.setIssuer(issuerId)
|
|
52
|
+
.setAudience("appstoreconnect-v1")
|
|
53
|
+
.setExpirationTime(expirationTime !== null && expirationTime !== void 0 ? expirationTime : new Date().getTime() / 1000)
|
|
54
|
+
.sign(key);
|
|
55
|
+
// Return the generated token
|
|
56
|
+
return token;
|
|
24
57
|
});
|
|
25
|
-
// Return the generated token
|
|
26
|
-
return token;
|
|
27
58
|
}
|
|
28
59
|
exports.generateAuthToken = generateAuthToken;
|
package/dist/main.d.ts
CHANGED
|
@@ -54,20 +54,20 @@ export default class AppStoreConnectAPI {
|
|
|
54
54
|
/**
|
|
55
55
|
* Generates a new bearer token.
|
|
56
56
|
*/
|
|
57
|
-
genToken(): string
|
|
57
|
+
genToken(): Promise<string>;
|
|
58
58
|
/**
|
|
59
59
|
* Create a Configuration object with the authentication token and any provided FetchAPI implementation.
|
|
60
60
|
*/
|
|
61
|
-
genConfiguration(): void
|
|
61
|
+
genConfiguration(): Promise<void>;
|
|
62
62
|
/**
|
|
63
63
|
* Returns the current bearer token, generating a new one if necessary.
|
|
64
64
|
*/
|
|
65
|
-
getConfiguration(): Configuration | undefined
|
|
65
|
+
getConfiguration(): Promise<Configuration | undefined>;
|
|
66
66
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
* Creates an instance of the specified API class.
|
|
68
|
+
* @param apiClass - The API class to instantiate.
|
|
69
|
+
* @returns An instance of the specified API class.
|
|
70
|
+
*/
|
|
71
|
+
create<T extends BaseAPI>(apiClass: new (configuration?: Configuration) => T): Promise<T>;
|
|
72
72
|
}
|
|
73
73
|
export {};
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
const openapi_1 = require("./openapi");
|
|
4
13
|
const auth_1 = require("./auth");
|
|
@@ -22,57 +31,66 @@ class AppStoreConnectAPI {
|
|
|
22
31
|
*/
|
|
23
32
|
constructor(options) {
|
|
24
33
|
this.bearerTokenGeneratedAt = 0;
|
|
25
|
-
|
|
34
|
+
if (options.expirationTime)
|
|
35
|
+
options.expirationTime = options.expirationTime;
|
|
26
36
|
this.options = options;
|
|
27
37
|
}
|
|
28
38
|
/**
|
|
29
39
|
* Generates a new bearer token.
|
|
30
40
|
*/
|
|
31
41
|
genToken() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (this.options.bearerToken) {
|
|
44
|
+
return this.options.bearerToken;
|
|
45
|
+
}
|
|
46
|
+
else if (this.options.privateKeyId && this.options.issuerId && this.options.privateKey) {
|
|
47
|
+
return yield (0, auth_1.generateAuthToken)({
|
|
48
|
+
apiKeyId: this.options.privateKeyId,
|
|
49
|
+
issuerId: this.options.issuerId,
|
|
50
|
+
privateKey: this.options.privateKey,
|
|
51
|
+
expirationTime: this.options.expirationTime,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw "No bearerToken!!!";
|
|
56
|
+
}
|
|
57
|
+
});
|
|
46
58
|
}
|
|
47
59
|
/**
|
|
48
60
|
* Create a Configuration object with the authentication token and any provided FetchAPI implementation.
|
|
49
61
|
*/
|
|
50
62
|
genConfiguration() {
|
|
51
|
-
this
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
this.configuration = new openapi_1.Configuration({
|
|
65
|
+
headers: {
|
|
66
|
+
Authorization: `Bearer ${yield this.genToken()}`,
|
|
67
|
+
},
|
|
68
|
+
fetchApi: this.options.fetchApi,
|
|
69
|
+
});
|
|
70
|
+
this.bearerTokenGeneratedAt = Date.now();
|
|
56
71
|
});
|
|
57
|
-
this.bearerTokenGeneratedAt = Date.now();
|
|
58
72
|
}
|
|
59
73
|
/**
|
|
60
74
|
* Returns the current bearer token, generating a new one if necessary.
|
|
61
75
|
*/
|
|
62
76
|
getConfiguration() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const hasExpired = this.bearerTokenGeneratedAt && Date.now() - this.bearerTokenGeneratedAt > 1000 * this.options.expirationTime;
|
|
79
|
+
if (!this.configuration || hasExpired) {
|
|
80
|
+
yield this.genConfiguration();
|
|
81
|
+
}
|
|
82
|
+
return this.configuration;
|
|
83
|
+
});
|
|
68
84
|
}
|
|
69
85
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return
|
|
86
|
+
* Creates an instance of the specified API class.
|
|
87
|
+
* @param apiClass - The API class to instantiate.
|
|
88
|
+
* @returns An instance of the specified API class.
|
|
89
|
+
*/
|
|
90
|
+
create(apiClass) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
return new apiClass(yield this.getConfiguration());
|
|
93
|
+
});
|
|
76
94
|
}
|
|
77
95
|
}
|
|
78
96
|
exports.default = AppStoreConnectAPI;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appstore-connect-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "An App Store Connect API client for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"appstore connect",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@openapitools/openapi-generator-cli": "^2.5.2",
|
|
21
21
|
"@types/jest": "^29.4.0",
|
|
22
|
-
"@types/jsonwebtoken": "^9.0.1",
|
|
23
22
|
"@types/node-fetch": "^2.0.0",
|
|
24
23
|
"dotenv": "^16.0.3",
|
|
25
24
|
"jest": "^29.4.2",
|
|
@@ -27,9 +26,6 @@
|
|
|
27
26
|
"ts-jest": "^29.0.5",
|
|
28
27
|
"typescript": "^4.9.5"
|
|
29
28
|
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"jsonwebtoken": "^9.0.0"
|
|
32
|
-
},
|
|
33
29
|
"author": "isaced",
|
|
34
30
|
"license": "MIT",
|
|
35
31
|
"repository": {
|
|
@@ -40,5 +36,8 @@
|
|
|
40
36
|
"url": "https://github.com/isaced/appstore-connect-sdk/issues",
|
|
41
37
|
"email": "isaced@163.com"
|
|
42
38
|
},
|
|
43
|
-
"homepage": "https://github.com/isaced/appstore-connect-sdk"
|
|
39
|
+
"homepage": "https://github.com/isaced/appstore-connect-sdk",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"jose": "^4.14.4"
|
|
42
|
+
}
|
|
44
43
|
}
|