-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05aaa0f
commit 7b93ff7
Showing
17 changed files
with
562 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# @greenlight/storeapi | ||
|
||
This package is the storeapi. It will communicate with the gamepass catalog and fetch all products and keep the information in a in-memory sql lite database | ||
|
||
## Class: StoreApi | ||
|
||
### constructor(config:{ market: '<US/NL>' }):void | ||
|
||
### loadProductIds(titles:string[]):boolean | ||
|
||
Returns true if the supplied product id's have been loaded. | ||
|
||
### findTitle():Promise<ItemResponse[]> | ||
|
||
Returns a promise with ItemResponse object. This contains an id, title_name and title_data. | ||
|
||
## Class: xCloudApi | ||
|
||
### constructor(host:string, token:string):void | ||
|
||
### getTitles():Promise<any> | ||
|
||
Returns data with the titleID included. This is mostly used to test the functionality with a bigger chunk of data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@greenlight/webapi", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"main": "dist/index", | ||
"scripts": { | ||
"start": "yarn build:deps && yarn build && DEBUG='*' node dist/bin/example.js", | ||
"build": "tsc --build", | ||
"build:deps": "yarn workspace @greenlight/authentication build && yarn workspace @greenlight/logger build", | ||
"clean": "rm -rf dist/ && rm -rf *.tsbuildinfo", | ||
"test": "yarn build && mocha -r ../../node_modules/ts-node/register tests/**.ts tests/**/*.ts" | ||
}, | ||
"dependencies": { | ||
"@greenlight/authentication": "workspace:^", | ||
"@greenlight/logger": "workspace:^" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4", | ||
"@types/debug": "^4.1.7", | ||
"@types/mocha": "^10", | ||
"@types/node": "^20.9.0", | ||
"chai": "^4.3.6", | ||
"mocha": "^10.1.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
import Authentication from '@greenlight/authentication' | ||
import Logger from '@greenlight/logger' | ||
import WebApi from '../index' | ||
|
||
class Cli { | ||
private _auth = new Authentication() | ||
public logger = new Logger('WebApi:Cli') | ||
|
||
constructor(){ | ||
this.logger.log('Greenlight WebApi Cli') | ||
this.logger.log('User:', this._auth.user.getGamertag()) | ||
|
||
this._auth.user.getWebToken().then((token) => { | ||
console.log('Userhash:', this._auth.user.getUserhash()) | ||
console.log('Token:', token.data.Token) | ||
console.log('Token NotAfter:', token.data.NotAfter) | ||
|
||
// Only used for loading all productId's | ||
const webapi = new WebApi({ | ||
uhs: this._auth.user.getUserhash(), | ||
token: { | ||
Token: token.data.Token, | ||
NotAfter: token.data.NotAfter | ||
} | ||
}) | ||
|
||
console.log('Token valid:', webapi.isTokenValid()) | ||
// webapi.provider.smartglass.getConsolesList().then((response) => { | ||
// console.log('Console ID:', response[0].id) | ||
|
||
|
||
// webapi.provider.smartglass.getInstalledApps(response[0].id).then((response) => { | ||
// console.log('Response:', response) | ||
|
||
// response.forEach((app) => { | ||
// console.log(app.contentType, ':', app.name) | ||
// }) | ||
// }) | ||
// }) | ||
|
||
webapi.provider.people.getFriends().then((response) => { | ||
console.log('Response:', response) | ||
}) | ||
|
||
}).catch((error) => { | ||
this.logger.error('Error:', error) | ||
}) | ||
} | ||
} | ||
|
||
new Cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Logger from '@greenlight/logger' | ||
|
||
const logger = new Logger('WebApi:HTTP') | ||
|
||
export default { | ||
|
||
get(url:string, headers:any) { | ||
logger.log('GET:', url, headers) | ||
|
||
return fetch(url, { | ||
method: 'GET', | ||
headers: headers | ||
}).then(async (response) => { | ||
logger.log(response.status,'-', url) | ||
try { | ||
return { | ||
response: response, | ||
data: await response.json() | ||
} | ||
} catch (error) { | ||
return { | ||
response: response, | ||
data: response.body | ||
} | ||
} | ||
}) | ||
}, | ||
|
||
post(url:string, headers:any, body:any) { | ||
logger.log('POST:', url, headers, JSON.stringify(body)) | ||
return fetch(url, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(body) | ||
}).then(async (response) => { | ||
logger.log(response.status,'-', url) | ||
try { | ||
return { | ||
response: response, | ||
data: await response.json() | ||
} | ||
} catch (error) { | ||
return { | ||
response: response, | ||
data: response.body | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Logger from '@greenlight/logger' | ||
|
||
import SmartglassProvider from './providers/smartglass' | ||
import SocialProvider from './providers/social' | ||
import PeopleProvider from './providers/people' | ||
|
||
export interface xCloudApiConfig { | ||
uhs:string | ||
token:XstsToken | ||
language?:string | ||
} | ||
|
||
export interface XstsToken { | ||
Token:string | ||
NotAfter:string | ||
} | ||
|
||
export default class WebApi { | ||
|
||
public logger:Logger = new Logger('WebApi') | ||
private _uhs:string | ||
private _token:XstsToken | ||
private _language:string | ||
|
||
public provider = { | ||
smartglass: new SmartglassProvider(this), | ||
social: new SocialProvider(this), | ||
people: new PeopleProvider(this), | ||
} | ||
|
||
constructor(config:xCloudApiConfig) { | ||
this.logger.log('constructor() Creating new WebApi instance') | ||
|
||
this._uhs = config.uhs | ||
this._token = config.token | ||
this._language = config.language || 'en-US' | ||
} | ||
|
||
isTokenValid() { | ||
return new Date(this._token.NotAfter) > new Date() | ||
} | ||
|
||
getAuthorizationHeader() { | ||
return 'XBL3.0 x='+this._uhs+';'+this._token.Token | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import WebApi from '..' | ||
import Logger from '@greenlight/logger' | ||
import Http from '../http' | ||
|
||
export interface HttpHeaders { | ||
[name:string]: string | ||
} | ||
|
||
export default class BaseProvider { | ||
|
||
private _api:WebApi | ||
public logger:Logger | ||
|
||
public _endpoint = 'https://undefined.xboxlive.com' | ||
public _headers:HttpHeaders = {} | ||
|
||
constructor(api:WebApi){ | ||
this._api = api | ||
this.logger = this._api.logger.extend(this.constructor.name) | ||
} | ||
|
||
async get(path:string, headers:HttpHeaders = {}) { | ||
const reqHeaders = Object.assign({}, { | ||
'Authorization': this._api.getAuthorizationHeader() | ||
}, headers) | ||
|
||
return await Http.get(this._endpoint+path, reqHeaders) | ||
} | ||
|
||
} |
Oops, something went wrong.