@apigames/sdk-core 22.1.1 → 22.1.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,8 +1,8 @@
1
1
  # API Games SDK Core Package
2
2
 
3
3
  ![](https://img.shields.io/badge/build-passing-brightgreen)
4
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c5081d4fa5a84849b05e1a9b54d2b93f)](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
- [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/c5081d4fa5a84849b05e1a9b54d2b93f)](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)
4
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/8c3c5f94c0ac457ab23170cd9fca50f9)](https://www.codacy.com/gh/apigames-core/sdk-core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-core/sdk-core&utm_campaign=Badge_Grade)
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/8c3c5f94c0ac457ab23170cd9fca50f9)](https://www.codacy.com/gh/apigames-core/sdk-core/dashboard?utm_source=github.com&utm_medium=referral&utm_content=apigames-core/sdk-core&utm_campaign=Badge_Coverage)
6
6
  ![](https://img.shields.io/npm/v/@apigames/sdk-core)
7
7
  ![](https://img.shields.io/badge/license-MIT-blue)
8
8
 
@@ -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, utils_1.redactUndefinedValues)(queryOptions);
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, utils_1.redactUndefinedValues)(queryOptions);
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, utils_1.redactUndefinedValues)(queryOptions);
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, utils_1.redactUndefinedValues)(queryOptions);
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
  }
@@ -0,0 +1,3 @@
1
+ import { GeospatialPoint } from '../interfaces';
2
+ export declare function LoadDateTime(value: string): Date;
3
+ export declare function LoadGeospatialPoint(value: any): GeospatialPoint;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoadGeospatialPoint = exports.LoadDateTime = void 0;
4
+ const json_1 = require("@apigames/json");
5
+ const interfaces_1 = require("../interfaces");
6
+ function LoadDateTime(value) {
7
+ if ((0, json_1.isDefined)(value))
8
+ return new Date(value);
9
+ return undefined;
10
+ }
11
+ exports.LoadDateTime = LoadDateTime;
12
+ function LoadGeospatialPoint(value) {
13
+ if ((0, json_1.isDefined)(value) && (0, json_1.hasProperty)(value, 'longitude') && (0, json_1.isNumber)(value.longitude)
14
+ && (0, json_1.hasProperty)(value, 'latitude') && (0, json_1.isNumber)(value.latitude)) {
15
+ const geospatialPoint = new interfaces_1.GeospatialPoint();
16
+ geospatialPoint.LoadData(value);
17
+ return geospatialPoint;
18
+ }
19
+ return undefined;
20
+ }
21
+ exports.LoadGeospatialPoint = LoadGeospatialPoint;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './interfaces';
2
2
  export * from './exceptions';
3
3
  export * from './classes';
4
+ export * from './helpers';
package/lib/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./interfaces"), exports);
18
18
  __exportStar(require("./exceptions"), exports);
19
19
  __exportStar(require("./classes"), exports);
20
+ __exportStar(require("./helpers"), exports);
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceObjectRelationshipBase = exports.GeospatialPoint = exports.ResourceObjectAttributeBase = void 0;
4
4
  const json_1 = require("@apigames/json");
5
+ const helpers_1 = require("../helpers");
5
6
  class ResourceObjectAttributeBase {
6
7
  static LoadDateTime(value) {
7
- if ((0, json_1.isDefined)(value))
8
- return new Date(value);
9
- return undefined;
8
+ return (0, helpers_1.LoadDateTime)(value);
10
9
  }
11
10
  static LoadGeospatialPoint(value) {
11
+ return (0, helpers_1.LoadGeospatialPoint)(value);
12
12
  if ((0, json_1.isDefined)(value) && (0, json_1.hasProperty)(value, 'longitude') && (0, json_1.isNumber)(value.longitude)
13
13
  && (0, json_1.hasProperty)(value, 'latitude') && (0, json_1.isNumber)(value.latitude)) {
14
14
  const geospatialPoint = new GeospatialPoint();
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "description": "API Games SDK Core",
15
15
  "license": "MIT",
16
- "version": "22.1.1",
16
+ "version": "22.1.4",
17
17
  "main": "lib/index.js",
18
18
  "types": "lib/index.d.ts",
19
19
  "scripts": {
@@ -33,8 +33,8 @@
33
33
  "test:watch": "jest --watch"
34
34
  },
35
35
  "dependencies": {
36
- "@apigames/json": "22.1.1",
37
- "@apigames/rest-client": "22.1.1",
36
+ "@apigames/json": "22.1.2",
37
+ "@apigames/rest-client": "22.1.3",
38
38
  "object-hash": "2.2.0"
39
39
  },
40
40
  "devDependencies": {
@@ -42,25 +42,25 @@
42
42
  "@types/date-and-time": "^0.13.0",
43
43
  "@types/jest": "27.4.1",
44
44
  "@types/node": "14.18.12",
45
- "@typescript-eslint/eslint-plugin": "5.15.0",
46
- "@typescript-eslint/parser": "5.15.0",
47
- "eslint": "8.11.0",
45
+ "@typescript-eslint/eslint-plugin": "5.16.0",
46
+ "@typescript-eslint/parser": "5.16.0",
47
+ "eslint": "8.12.0",
48
48
  "eslint-config-airbnb": "19.0.4",
49
49
  "eslint-plugin-import": "2.25.4",
50
50
  "eslint-plugin-jsx-a11y": "6.5.1",
51
51
  "eslint-plugin-react": "7.29.4",
52
52
  "eslint-plugin-react-hooks": "4.3.0",
53
53
  "jest": "27.5.1",
54
- "ts-jest": "27.1.3",
55
- "typescript": "4.6.2"
54
+ "ts-jest": "27.1.4",
55
+ "typescript": "4.6.3"
56
56
  },
57
57
  "eslintConfig": {},
58
58
  "repository": {
59
59
  "type": "git",
60
- "url": "git+https://github.com/apigames-public/sdk-core.git"
60
+ "url": "git+https://github.com/apigames-core/sdk-core.git"
61
61
  },
62
62
  "bugs": {
63
- "url": "https://github.com/apigames-public/sdk-core/issues"
63
+ "url": "https://github.com/apigames-core/sdk-core/issues"
64
64
  },
65
- "homepage": "https://github.com/apigames-public/sdk-core#readme"
65
+ "homepage": "https://github.com/apigames-core/sdk-core#readme"
66
66
  }
@@ -1,7 +0,0 @@
1
- export CODACY_API_TOKEN=zLmkgxu0V5R3qEbGrbbm
2
- export CODACY_ORGANIZATION_PROVIDER=gh
3
- export CODACY_USERNAME=apigames-public
4
- export CODACY_PROJECT_NAME=sdk-core
5
-
6
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage/clover.xml
7
-