@apigames/sdk-core 22.1.0-dev.3 → 22.1.2
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/LICENSE +21 -1
- package/README.md +5 -4
- package/fixEOL.sh +8 -0
- package/lib/classes/resource.container.d.ts +2 -0
- package/lib/classes/resource.container.js +32 -21
- package/lib/classes/resource.object.d.ts +2 -0
- package/lib/classes/resource.object.js +18 -8
- package/lib/classes/sdk.config.d.ts +6 -0
- package/lib/classes/sdk.config.js +12 -0
- package/lib/index.js +5 -1
- package/package.json +27 -17
- package/publishCodeCoverage.sh +1 -1
package/LICENSE
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 API Games Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# API Games SDK Core Package
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-
[](https://www.codacy.com/gh/apigames-public/sdk-core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-public/sdk-core&utm_campaign=Badge_Grade)
|
|
5
|
+
[](https://www.codacy.com/gh/apigames-public/sdk-core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-public/sdk-core&utm_campaign=Badge_Coverage)
|
|
6
|
+

|
|
7
|
+

|
|
7
8
|
|
|
8
9
|
This package includes the core capabilites required by SDKs built to access the API Games Platform.
|
|
9
10
|
|
|
@@ -19,4 +20,4 @@ $ npm i @apigames/sdk-core
|
|
|
19
20
|
|
|
20
21
|
## License
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
This project is licensed under the MIT License
|
package/fixEOL.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
find src -name "*.js" -type f -exec dos2unix {} \;
|
|
2
|
+
find src -name "*.jsx" -type f -exec dos2unix {} \;
|
|
3
|
+
find src -name "*.ts" -type f -exec dos2unix {} \;
|
|
4
|
+
find src -name "*.tsx" -type f -exec dos2unix {} \;
|
|
5
|
+
find tests -name "*.js" -type f -exec dos2unix {} \;
|
|
6
|
+
find tests -name "*.jsx" -type f -exec dos2unix {} \;
|
|
7
|
+
find tests -name "*.ts" -type f -exec dos2unix {} \;
|
|
8
|
+
find tests -name "*.tsx" -type f -exec dos2unix {} \;
|
|
@@ -23,6 +23,7 @@ export default class ResourceContainer implements IResourceContainer {
|
|
|
23
23
|
get uri(): string;
|
|
24
24
|
isResourceObject(value: any): value is IResourceObject;
|
|
25
25
|
isResourceList(value: any): value is IResourceObject[];
|
|
26
|
+
protected EndpointContentType(): string;
|
|
26
27
|
protected EndpointPath(): string;
|
|
27
28
|
protected ClearData(): void;
|
|
28
29
|
protected AddResourceToMemoryStructure(obj: IResourceObject): void;
|
|
@@ -35,6 +36,7 @@ export default class ResourceContainer implements IResourceContainer {
|
|
|
35
36
|
Find(): Promise<void>;
|
|
36
37
|
Get(id: string): Promise<void>;
|
|
37
38
|
private InitParams;
|
|
39
|
+
private GetHeaders;
|
|
38
40
|
private GetQueryParams;
|
|
39
41
|
IncludedObject(type: string, id: string): IResourceObject;
|
|
40
42
|
Filter(filter: ResourceFilterName, selector: ResourceFilterType, value: ResourceFilterValue): IResourceContainer;
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.ResourceFilterType = void 0;
|
|
13
13
|
const json_1 = require("@apigames/json");
|
|
14
14
|
const rest_client_1 = require("@apigames/rest-client");
|
|
15
|
-
const utils_1 = require("@apigames/json/lib/utils");
|
|
16
15
|
const __1 = require("..");
|
|
17
16
|
const hash = require('object-hash');
|
|
18
17
|
var ResourceFilterType;
|
|
@@ -59,6 +58,9 @@ class ResourceContainer {
|
|
|
59
58
|
isResourceList(value) {
|
|
60
59
|
return (0, json_1.isArray)(value);
|
|
61
60
|
}
|
|
61
|
+
EndpointContentType() {
|
|
62
|
+
throw new Error('Method or Property not implemented.');
|
|
63
|
+
}
|
|
62
64
|
EndpointPath() {
|
|
63
65
|
throw new Error('Method or Property not implemented.');
|
|
64
66
|
}
|
|
@@ -121,15 +123,12 @@ class ResourceContainer {
|
|
|
121
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
124
|
if ((0, json_1.isDefined)(resource.id)) {
|
|
123
125
|
const queryUri = `${this.uri}/${resource.id}`;
|
|
124
|
-
const queryHeaders =
|
|
125
|
-
Accept: 'application/vnd.api+json',
|
|
126
|
-
'Content-Type': 'application/vnd.api+json',
|
|
127
|
-
};
|
|
126
|
+
const queryHeaders = this.GetHeaders('DELETE');
|
|
128
127
|
const queryOptions = {
|
|
129
128
|
queryParams: this.GetQueryParams(),
|
|
130
129
|
};
|
|
131
130
|
this.InitParams();
|
|
132
|
-
(0,
|
|
131
|
+
(0, json_1.redactUndefinedValues)(queryOptions);
|
|
133
132
|
yield this._restClient.Delete(queryUri, queryHeaders, queryOptions);
|
|
134
133
|
this.RemoveResourceFromMemoryStructure(resource);
|
|
135
134
|
}
|
|
@@ -141,10 +140,7 @@ class ResourceContainer {
|
|
|
141
140
|
Count() {
|
|
142
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
142
|
const queryUri = `${this.uri}`;
|
|
144
|
-
const queryHeaders =
|
|
145
|
-
Accept: 'application/vnd.api+json',
|
|
146
|
-
'Content-Type': 'application/vnd.api+json',
|
|
147
|
-
};
|
|
143
|
+
const queryHeaders = this.GetHeaders('COUNT');
|
|
148
144
|
const queryOptions = {
|
|
149
145
|
queryParams: this.GetQueryParams(),
|
|
150
146
|
};
|
|
@@ -155,7 +151,7 @@ class ResourceContainer {
|
|
|
155
151
|
(0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[size]');
|
|
156
152
|
(0, json_1.extractAndRedact)(queryOptions.queryParams, 'sort');
|
|
157
153
|
}
|
|
158
|
-
(0,
|
|
154
|
+
(0, json_1.redactUndefinedValues)(queryOptions);
|
|
159
155
|
const queryParams = {
|
|
160
156
|
uri: queryUri,
|
|
161
157
|
headers: queryHeaders,
|
|
@@ -183,15 +179,12 @@ class ResourceContainer {
|
|
|
183
179
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
180
|
this.ClearData();
|
|
185
181
|
const queryUri = `${this.uri}`;
|
|
186
|
-
const queryHeaders =
|
|
187
|
-
Accept: 'application/vnd.api+json',
|
|
188
|
-
'Content-Type': 'application/vnd.api+json',
|
|
189
|
-
};
|
|
182
|
+
const queryHeaders = this.GetHeaders('FIND');
|
|
190
183
|
const queryOptions = {
|
|
191
184
|
queryParams: this.GetQueryParams(),
|
|
192
185
|
};
|
|
193
186
|
this.InitParams();
|
|
194
|
-
(0,
|
|
187
|
+
(0, json_1.redactUndefinedValues)(queryOptions);
|
|
195
188
|
this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
|
|
196
189
|
});
|
|
197
190
|
}
|
|
@@ -199,15 +192,12 @@ class ResourceContainer {
|
|
|
199
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
193
|
this.ClearData();
|
|
201
194
|
const queryUri = `${this.uri}/${id}`;
|
|
202
|
-
const queryHeaders =
|
|
203
|
-
Accept: 'application/vnd.api+json',
|
|
204
|
-
'Content-Type': 'application/vnd.api+json',
|
|
205
|
-
};
|
|
195
|
+
const queryHeaders = this.GetHeaders('GET');
|
|
206
196
|
const queryOptions = {
|
|
207
197
|
queryParams: this.GetQueryParams(),
|
|
208
198
|
};
|
|
209
199
|
this.InitParams();
|
|
210
|
-
(0,
|
|
200
|
+
(0, json_1.redactUndefinedValues)(queryOptions);
|
|
211
201
|
this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
|
|
212
202
|
});
|
|
213
203
|
}
|
|
@@ -219,6 +209,27 @@ class ResourceContainer {
|
|
|
219
209
|
pagination: {},
|
|
220
210
|
};
|
|
221
211
|
}
|
|
212
|
+
GetHeaders(action) {
|
|
213
|
+
const headers = {};
|
|
214
|
+
switch (action) {
|
|
215
|
+
case 'GET':
|
|
216
|
+
case 'COUNT':
|
|
217
|
+
case 'FIND':
|
|
218
|
+
headers.Accept = this.EndpointContentType();
|
|
219
|
+
break;
|
|
220
|
+
default:
|
|
221
|
+
headers.Accept = this.EndpointContentType();
|
|
222
|
+
headers['Content-Type'] = this.EndpointContentType();
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
if ((0, json_1.isDefined)((0, __1.SDKConfig)().apiKey)) {
|
|
226
|
+
headers['x-api-key'] = (0, __1.SDKConfig)().apiKey;
|
|
227
|
+
}
|
|
228
|
+
if ((0, json_1.isDefined)((0, __1.SDKConfig)().accessToken)) {
|
|
229
|
+
headers.Authorization = `Bearer ${(0, __1.SDKConfig)().accessToken}`;
|
|
230
|
+
}
|
|
231
|
+
return headers;
|
|
232
|
+
}
|
|
222
233
|
GetQueryParams() {
|
|
223
234
|
const queryParams = {};
|
|
224
235
|
for (const filterName in this._queryParams.filters) {
|
|
@@ -9,6 +9,7 @@ export default class ResourceObject implements IResourceObject {
|
|
|
9
9
|
private _mode;
|
|
10
10
|
private _uri;
|
|
11
11
|
constructor(container: IResourceContainer);
|
|
12
|
+
protected EndpointContentType(): string;
|
|
12
13
|
protected LoadAttributes(value: any): void;
|
|
13
14
|
protected LoadRelationships(value: any): void;
|
|
14
15
|
protected UpdateAttributes(value: any): void;
|
|
@@ -18,6 +19,7 @@ export default class ResourceObject implements IResourceObject {
|
|
|
18
19
|
protected GetUpdatePayload(): any;
|
|
19
20
|
Delete(): Promise<void>;
|
|
20
21
|
private GetHeaderValue;
|
|
22
|
+
private GetHeaders;
|
|
21
23
|
private HasHeader;
|
|
22
24
|
private InsertResource;
|
|
23
25
|
private UpdateResource;
|
|
@@ -22,6 +22,9 @@ class ResourceObject {
|
|
|
22
22
|
this._mode = ResourceObjectMode.NewDocument;
|
|
23
23
|
this._container = container;
|
|
24
24
|
}
|
|
25
|
+
EndpointContentType() {
|
|
26
|
+
throw new Error('Method or Property not implemented.');
|
|
27
|
+
}
|
|
25
28
|
LoadAttributes(value) {
|
|
26
29
|
throw new Error('Method or Property not implemented.');
|
|
27
30
|
}
|
|
@@ -93,6 +96,19 @@ class ResourceObject {
|
|
|
93
96
|
}
|
|
94
97
|
return value;
|
|
95
98
|
}
|
|
99
|
+
GetHeaders() {
|
|
100
|
+
const headers = {
|
|
101
|
+
Accept: this.EndpointContentType(),
|
|
102
|
+
'Content-Type': this.EndpointContentType(),
|
|
103
|
+
};
|
|
104
|
+
if ((0, json_1.isDefined)((0, __1.SDKConfig)().apiKey)) {
|
|
105
|
+
headers['x-api-key'] = (0, __1.SDKConfig)().apiKey;
|
|
106
|
+
}
|
|
107
|
+
if ((0, json_1.isDefined)((0, __1.SDKConfig)().accessToken)) {
|
|
108
|
+
headers.Authorization = `Bearer ${(0, __1.SDKConfig)().accessToken}`;
|
|
109
|
+
}
|
|
110
|
+
return headers;
|
|
111
|
+
}
|
|
96
112
|
HasHeader(headers, targetHeader) {
|
|
97
113
|
let hasHeader = false;
|
|
98
114
|
for (const headerName in headers) {
|
|
@@ -105,10 +121,7 @@ class ResourceObject {
|
|
|
105
121
|
InsertResource() {
|
|
106
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
123
|
const queryUri = this._container.uri;
|
|
108
|
-
const queryHeaders =
|
|
109
|
-
Accept: 'application/vnd.api+json',
|
|
110
|
-
'Content-Type': 'application/vnd.api+json',
|
|
111
|
-
};
|
|
124
|
+
const queryHeaders = this.GetHeaders();
|
|
112
125
|
const queryOptions = {};
|
|
113
126
|
const payload = this.GetInsertPayload();
|
|
114
127
|
const response = yield this._container.restClient.Post(queryUri, payload, queryHeaders, queryOptions);
|
|
@@ -128,10 +141,7 @@ class ResourceObject {
|
|
|
128
141
|
UpdateResource() {
|
|
129
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
143
|
const queryUri = this.uri;
|
|
131
|
-
const queryHeaders =
|
|
132
|
-
Accept: 'application/vnd.api+json',
|
|
133
|
-
'Content-Type': 'application/vnd.api+json',
|
|
134
|
-
};
|
|
144
|
+
const queryHeaders = this.GetHeaders();
|
|
135
145
|
const queryOptions = {};
|
|
136
146
|
const payload = this.GetUpdatePayload();
|
|
137
147
|
yield this._container.restClient.Patch(queryUri, payload, queryHeaders, queryOptions);
|
|
@@ -3,12 +3,18 @@ export declare type SDKResourceMap = {
|
|
|
3
3
|
[index: string]: ResourceObjectClass;
|
|
4
4
|
};
|
|
5
5
|
export declare class SDKConfiguration {
|
|
6
|
+
private _accessToken;
|
|
7
|
+
private _apiKey;
|
|
6
8
|
private _hostName;
|
|
7
9
|
private _resourceMap;
|
|
8
10
|
constructor();
|
|
9
11
|
RegisterResourceClass(type: string, resourceClass: ResourceObjectClass): void;
|
|
10
12
|
ResourceClass(type: string): ResourceObjectClass;
|
|
11
13
|
FormatURL(path: string): string;
|
|
14
|
+
get accessToken(): string;
|
|
15
|
+
set accessToken(value: string);
|
|
16
|
+
get apiKey(): string;
|
|
17
|
+
set apiKey(value: string);
|
|
12
18
|
get hostName(): string;
|
|
13
19
|
set hostName(value: string);
|
|
14
20
|
}
|
|
@@ -17,6 +17,18 @@ class SDKConfiguration {
|
|
|
17
17
|
url = url.endsWith('/') ? url.slice(0, -1) : url;
|
|
18
18
|
return path.startsWith('/') ? `${url}${path}` : `${url}/${path}`;
|
|
19
19
|
}
|
|
20
|
+
get accessToken() {
|
|
21
|
+
return this._accessToken;
|
|
22
|
+
}
|
|
23
|
+
set accessToken(value) {
|
|
24
|
+
this._accessToken = value;
|
|
25
|
+
}
|
|
26
|
+
get apiKey() {
|
|
27
|
+
return this._apiKey;
|
|
28
|
+
}
|
|
29
|
+
set apiKey(value) {
|
|
30
|
+
this._apiKey = value;
|
|
31
|
+
}
|
|
20
32
|
get hostName() {
|
|
21
33
|
return this._hostName;
|
|
22
34
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apigames/sdk-core",
|
|
3
|
-
"author":
|
|
3
|
+
"author": {
|
|
4
|
+
"name" : "API Games Limited",
|
|
5
|
+
"email" : "hello@api.games",
|
|
6
|
+
"url" : "https://api.games"
|
|
7
|
+
},
|
|
8
|
+
"contributors": [
|
|
9
|
+
{
|
|
10
|
+
"name" : "Erich Kuba",
|
|
11
|
+
"email" : "erich.kuba@api.games"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
4
14
|
"description": "API Games SDK Core",
|
|
5
|
-
"license": "
|
|
6
|
-
"version": "22.1.
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"version": "22.1.2",
|
|
7
17
|
"main": "lib/index.js",
|
|
8
18
|
"types": "lib/index.d.ts",
|
|
9
19
|
"scripts": {
|
|
@@ -23,34 +33,34 @@
|
|
|
23
33
|
"test:watch": "jest --watch"
|
|
24
34
|
},
|
|
25
35
|
"dependencies": {
|
|
26
|
-
"@apigames/json": "22.1.
|
|
27
|
-
"@apigames/rest-client": "22.1.
|
|
36
|
+
"@apigames/json": "22.1.1",
|
|
37
|
+
"@apigames/rest-client": "22.1.2",
|
|
28
38
|
"object-hash": "2.2.0"
|
|
29
39
|
},
|
|
30
40
|
"devDependencies": {
|
|
31
|
-
"date-and-time": "^2.
|
|
41
|
+
"date-and-time": "^2.3.0",
|
|
32
42
|
"@types/date-and-time": "^0.13.0",
|
|
33
|
-
"@types/jest": "27.4.
|
|
34
|
-
"@types/node": "
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
36
|
-
"@typescript-eslint/parser": "5.
|
|
37
|
-
"eslint": "8.
|
|
43
|
+
"@types/jest": "27.4.1",
|
|
44
|
+
"@types/node": "14.18.12",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "5.16.0",
|
|
46
|
+
"@typescript-eslint/parser": "5.16.0",
|
|
47
|
+
"eslint": "8.11.0",
|
|
38
48
|
"eslint-config-airbnb": "19.0.4",
|
|
39
49
|
"eslint-plugin-import": "2.25.4",
|
|
40
50
|
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
41
|
-
"eslint-plugin-react": "7.
|
|
51
|
+
"eslint-plugin-react": "7.29.4",
|
|
42
52
|
"eslint-plugin-react-hooks": "4.3.0",
|
|
43
|
-
"jest": "27.
|
|
53
|
+
"jest": "27.5.1",
|
|
44
54
|
"ts-jest": "27.1.3",
|
|
45
|
-
"typescript": "4.
|
|
55
|
+
"typescript": "4.6.2"
|
|
46
56
|
},
|
|
47
57
|
"eslintConfig": {},
|
|
48
58
|
"repository": {
|
|
49
59
|
"type": "git",
|
|
50
|
-
"url": "git+https://github.com/apigames-
|
|
60
|
+
"url": "git+https://github.com/apigames-public/sdk-core.git"
|
|
51
61
|
},
|
|
52
62
|
"bugs": {
|
|
53
|
-
"url": "https://github.com/apigames-
|
|
63
|
+
"url": "https://github.com/apigames-public/sdk-core/issues"
|
|
54
64
|
},
|
|
55
|
-
"homepage": "https://github.com/apigames-
|
|
65
|
+
"homepage": "https://github.com/apigames-public/sdk-core#readme"
|
|
56
66
|
}
|
package/publishCodeCoverage.sh
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export CODACY_API_TOKEN=zLmkgxu0V5R3qEbGrbbm
|
|
2
2
|
export CODACY_ORGANIZATION_PROVIDER=gh
|
|
3
|
-
export CODACY_USERNAME=apigames-
|
|
3
|
+
export CODACY_USERNAME=apigames-public
|
|
4
4
|
export CODACY_PROJECT_NAME=sdk-core
|
|
5
5
|
|
|
6
6
|
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/clover.xml
|