appstore-connect-sdk 0.0.9 → 1.0.0-beta.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/README.md CHANGED
@@ -41,7 +41,7 @@ import AppStoreConnectAPI from "appstore-connect-sdk";
41
41
 
42
42
  #### 2. Create your API Configuration
43
43
 
44
- 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`.
44
+ 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
45
 
46
46
  After downloading your private key, open the `.p8` file containing the private key in a text editor. It should look like this:
47
47
 
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,60 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
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
- // Generate the token using the provided options
11
- const token = jsonwebtoken_1.default.sign({}, privateKey, {
12
- algorithm: "ES256",
13
- expiresIn: expirationTime,
14
- issuer: issuerId,
15
- audience: "appstoreconnect-v1",
16
- header: {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const alg = "ES256";
41
+ const privateKey1 = yield jose.importPKCS8(privateKey, alg);
42
+ var nowSeconds = new Date().getTime() / 1000;
43
+ const token = yield new jose.SignJWT({})
44
+ .setProtectedHeader({
17
45
  // The algorithm used to sign the token (ECDSA with SHA-256)
18
- alg: "ES256",
46
+ alg,
19
47
  // The ID of the private key used to sign the token
20
48
  kid: apiKeyId,
21
49
  // The type of the token (JWT)
22
50
  typ: "JWT",
23
- },
51
+ })
52
+ .setIssuer(issuerId)
53
+ .setAudience("appstoreconnect-v1")
54
+ .setExpirationTime(nowSeconds)
55
+ .sign(privateKey1);
56
+ // Return the generated token
57
+ return token;
24
58
  });
25
- // Return the generated token
26
- return token;
27
59
  }
28
60
  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
- * Calls the specified API class using the current Configuration object.
68
- * @param apiClass - The API class to instantiate.
69
- * @returns An instance of the specified API class.
70
- */
71
- call<T extends BaseAPI>(apiClass: new (configuration?: Configuration) => T): T;
67
+ * Calls the specified API class using the current Configuration object.
68
+ * @param apiClass - The API class to instantiate.
69
+ * @returns An instance of the specified API class.
70
+ */
71
+ call<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");
@@ -29,50 +38,58 @@ class AppStoreConnectAPI {
29
38
  * Generates a new bearer token.
30
39
  */
31
40
  genToken() {
32
- if (this.options.bearerToken) {
33
- return this.options.bearerToken;
34
- }
35
- else if (this.options.privateKeyId && this.options.issuerId && this.options.privateKey) {
36
- return (0, auth_1.generateAuthToken)({
37
- apiKeyId: this.options.privateKeyId,
38
- issuerId: this.options.issuerId,
39
- privateKey: this.options.privateKey,
40
- expirationTime: this.options.expirationTime,
41
- });
42
- }
43
- else {
44
- throw 'No bearerToken!!!';
45
- }
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (this.options.bearerToken) {
43
+ return this.options.bearerToken;
44
+ }
45
+ else if (this.options.privateKeyId && this.options.issuerId && this.options.privateKey) {
46
+ return yield (0, auth_1.generateAuthToken)({
47
+ apiKeyId: this.options.privateKeyId,
48
+ issuerId: this.options.issuerId,
49
+ privateKey: this.options.privateKey,
50
+ expirationTime: this.options.expirationTime,
51
+ });
52
+ }
53
+ else {
54
+ throw "No bearerToken!!!";
55
+ }
56
+ });
46
57
  }
47
58
  /**
48
59
  * Create a Configuration object with the authentication token and any provided FetchAPI implementation.
49
60
  */
50
61
  genConfiguration() {
51
- this.configuration = new openapi_1.Configuration({
52
- headers: {
53
- Authorization: `Bearer ${this.genToken()}`,
54
- },
55
- fetchApi: this.options.fetchApi,
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ this.configuration = new openapi_1.Configuration({
64
+ headers: {
65
+ Authorization: `Bearer ${yield this.genToken()}`,
66
+ },
67
+ fetchApi: this.options.fetchApi,
68
+ });
69
+ this.bearerTokenGeneratedAt = Date.now();
56
70
  });
57
- this.bearerTokenGeneratedAt = Date.now();
58
71
  }
59
72
  /**
60
73
  * Returns the current bearer token, generating a new one if necessary.
61
74
  */
62
75
  getConfiguration() {
63
- const hasExpired = this.bearerTokenGeneratedAt && (Date.now() - this.bearerTokenGeneratedAt) > (1000 * this.options.expirationTime);
64
- if (!this.configuration || hasExpired) {
65
- this.genConfiguration();
66
- }
67
- return this.configuration;
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const hasExpired = this.bearerTokenGeneratedAt && Date.now() - this.bearerTokenGeneratedAt > 1000 * this.options.expirationTime;
78
+ if (!this.configuration || hasExpired) {
79
+ yield this.genConfiguration();
80
+ }
81
+ return this.configuration;
82
+ });
68
83
  }
69
84
  /**
70
- * Calls the specified API class using the current Configuration object.
71
- * @param apiClass - The API class to instantiate.
72
- * @returns An instance of the specified API class.
73
- */
85
+ * Calls the specified API class using the current Configuration object.
86
+ * @param apiClass - The API class to instantiate.
87
+ * @returns An instance of the specified API class.
88
+ */
74
89
  call(apiClass) {
75
- return new apiClass(this.getConfiguration());
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ return new apiClass(yield this.getConfiguration());
92
+ });
76
93
  }
77
94
  }
78
95
  exports.default = AppStoreConnectAPI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appstore-connect-sdk",
3
- "version": "0.0.9",
3
+ "version": "1.0.0-beta.0",
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
  }