@arkadiuminc/sdk 0.0.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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2017 mark.bober <mark.bober@arkadium.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Arkadium SDK
2
+
3
+ This library lets you integrate your game with [Arkadium SDK](https://arkadiumsdk.z19.web.core.windows.net/).
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ npm install @arkadiuminc/sdk
9
+ ```
10
+
11
+
12
+ ## Usage
13
+
14
+ ```typescript
15
+ import { getInstance, Env } from '@arkadiuminc/sdk';
16
+
17
+ const Game = {
18
+ pause: () => console.log('Game paused!'),
19
+ resume: () => console.log('Game resumed!'),
20
+ };
21
+
22
+ async function main() {
23
+ Game.pause();
24
+ const { ads } = await getInstance(Env.DEV);
25
+ await ads.interstitial.show();
26
+ Game.resume();
27
+ }
28
+
29
+ main();
30
+ ```
31
+
@@ -0,0 +1,29 @@
1
+ interface RpcRequest {
2
+ module: string;
3
+ func: string;
4
+ payload: any[];
5
+ }
6
+ declare class RpcPublisher {
7
+ private rpcCallbacks;
8
+ private target;
9
+ init(target: any): void;
10
+ sendMessage(message: RpcRequest): Promise<any>;
11
+ private genId;
12
+ private processMessages;
13
+ private registerCb;
14
+ private unregisterCB;
15
+ }
16
+ declare class RpcSubscriber {
17
+ constructor();
18
+ private registry;
19
+ private target;
20
+ init(target: any): void;
21
+ addToRegistry(module: string, name: string, bindTo: any, fn: any): void;
22
+ private getId;
23
+ private processMessages;
24
+ private sendResponse;
25
+ }
26
+ export declare function shouldSubscribe(name: string, value: any): boolean;
27
+ export declare const rpcPublisher: RpcPublisher;
28
+ export declare const rpcSubscriber: RpcSubscriber;
29
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare class VideoAd {
2
+ static getInstance(): VideoAd;
3
+ constructor();
4
+ interstitial(): Promise<unknown>;
5
+ rewarded(): Promise<unknown>;
6
+ }
@@ -0,0 +1,18 @@
1
+ declare class InterstitialAd {
2
+ constructor();
3
+ show(): Promise<void>;
4
+ }
5
+ declare class RewardedAd {
6
+ constructor();
7
+ show(): Promise<{
8
+ value: number;
9
+ }>;
10
+ }
11
+ export declare class AdsApi {
12
+ interstitial: InterstitialAd;
13
+ rewarded: RewardedAd;
14
+ constructor(interstitial: InterstitialAd, rewarded: RewardedAd);
15
+ static getArenaApi(): AdsApi;
16
+ static getGameApi(): AdsApi;
17
+ }
18
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare class VideoAd {
2
+ static getInstance(): VideoAd;
3
+ protected _scriptLoaded: Promise<void>;
4
+ constructor();
5
+ interstitial(): Promise<void>;
6
+ rewarded(): Promise<void>;
7
+ protected triggerRender(): Promise<void>;
8
+ }
@@ -0,0 +1,17 @@
1
+ import { ApiGateway as UserApiGateway } from '@arkadium/eagle-user-client';
2
+ import { ApiGateway as PaymentsApiGateway } from '@arkadium/eagle-payments-api-client';
3
+ import { ApiGateway as VirtualItemApiGateway } from '@arkadium/eagle-virtual-items-api-client';
4
+ import { UserGameDataApi } from '@arkadium/eagle-user-client/dist/types/api/v1/user-game-data.api';
5
+ export declare enum ApiEnv {
6
+ DEV = "DEV",
7
+ PROD = "PROD"
8
+ }
9
+ export declare class BackendApi {
10
+ userApiGateway: Awaited<ReturnType<typeof UserApiGateway.prototype.getAuthApi>> | null;
11
+ paymentsApiGateway: Awaited<ReturnType<typeof PaymentsApiGateway.prototype.getApi>> | null;
12
+ virtualItemApiGateway: Awaited<ReturnType<typeof VirtualItemApiGateway.prototype.getApi>> | null;
13
+ private userGateway;
14
+ userGameData: UserGameDataApi | null;
15
+ init(e: ApiEnv, isGameSide: boolean): Promise<void>;
16
+ isUserAuthorized(): boolean;
17
+ }
@@ -0,0 +1,27 @@
1
+ export interface LocalStorageContract {
2
+ getItem(key: string): Promise<string | null>;
3
+ setItem(key: string, value: string): Promise<void>;
4
+ removeItem(key: string): Promise<void>;
5
+ }
6
+ export declare class DefaultLocalStorage implements LocalStorageContract {
7
+ private ls;
8
+ constructor();
9
+ getItem(key: string): Promise<string | null>;
10
+ setItem(key: string, value: string): Promise<void>;
11
+ removeItem(key: string): Promise<void>;
12
+ }
13
+ interface CookieStorageContract {
14
+ GetKey(key: string): Promise<string>;
15
+ }
16
+ interface UrlParamsReaderContract {
17
+ GetParam(key: string): Promise<string | null>;
18
+ }
19
+ export declare class EnvironmentApi {
20
+ localStorage: LocalStorageContract;
21
+ cookieStorage: CookieStorageContract;
22
+ urlParamsReader: UrlParamsReaderContract;
23
+ constructor(localStorage: LocalStorageContract, cookieStorage: CookieStorageContract, urlParamsReader: UrlParamsReaderContract);
24
+ static getArenaApi(): EnvironmentApi;
25
+ static getGameApi(): EnvironmentApi;
26
+ }
27
+ export {};
@@ -0,0 +1,35 @@
1
+ declare enum LifecycleEvent {
2
+ TEST_READY = 1,
3
+ GAME_START = 2,
4
+ INTERACT = 3,
5
+ SCORE_CHANGED = 4,
6
+ GAME_END = 5
7
+ }
8
+ declare type LifecycleFn = (event: LifecycleEvent, payload?: any) => void;
9
+ export interface GameLifecycleContract {
10
+ OnTestReady(): Promise<void>;
11
+ OnGameStart(): Promise<void>;
12
+ OnInteract(): Promise<void>;
13
+ OnChangeScore(score: number): Promise<void>;
14
+ OnGameEnd(): Promise<void>;
15
+ subscribe(fn: LifecycleFn): void;
16
+ }
17
+ export declare class GameLifecycle implements GameLifecycleContract {
18
+ private cb;
19
+ constructor();
20
+ OnTestReady(): Promise<void>;
21
+ OnGameStart(): Promise<void>;
22
+ OnInteract(): Promise<void>;
23
+ OnChangeScore(score: number): Promise<void>;
24
+ OnGameEnd(): Promise<void>;
25
+ subscribe(cb: LifecycleFn): void;
26
+ }
27
+ export declare class GameLifecycleProxy implements GameLifecycleContract {
28
+ OnTestReady(): Promise<void>;
29
+ OnGameStart(): Promise<void>;
30
+ OnInteract(): Promise<void>;
31
+ OnChangeScore(score: number): Promise<void>;
32
+ OnGameEnd(): Promise<void>;
33
+ subscribe(fn: LifecycleFn): void;
34
+ }
35
+ export {};
@@ -0,0 +1,21 @@
1
+ import { LocalStorageContract } from '../environment/environment.api';
2
+ import { BackendApi } from '../backend/backend.api';
3
+ export interface GameStateContract {
4
+ loadGameState(key: string): Promise<any>;
5
+ saveGameState(key: string, state: any): Promise<void>;
6
+ }
7
+ export declare class GameStateApi {
8
+ ls: LocalStorageContract;
9
+ backendApi: BackendApi;
10
+ constructor(backendApi: BackendApi);
11
+ private packData;
12
+ private unpackData;
13
+ private isUserAuthorized;
14
+ loadGameState(key: string): Promise<any>;
15
+ private loadData;
16
+ saveGameState(key: string, state: any): Promise<void>;
17
+ }
18
+ export declare class GameStateApiProxy {
19
+ loadGameState(): Promise<any>;
20
+ saveGameState(state: any): Promise<any>;
21
+ }
@@ -0,0 +1,16 @@
1
+ export declare type ObserverFn<T> = (data: T) => void;
2
+ export interface ReadonlyObservable<T> {
3
+ subscribe: (observer: ObserverFn<T>) => any;
4
+ }
5
+ export declare class Observable<T> {
6
+ private lastValue;
7
+ private observers;
8
+ subscribe(observer: ObserverFn<T>): () => void;
9
+ next(data: T): void;
10
+ }
11
+ export declare function createStore<T>(initialValue: T): {
12
+ observers: ObserverFn<T>[];
13
+ value: T;
14
+ subscribe: (observer: ObserverFn<T>) => void;
15
+ update(newValue: T): void;
16
+ };
@@ -0,0 +1,26 @@
1
+ import { ApiEnv, BackendApi } from './api/features/backend/backend.api';
2
+ import { GameStateContract } from './api/features/game-state/game-state.api';
3
+ import { GameLifecycleContract } from './api/features/game-lifecycle/game-lifecycle.api';
4
+ import { EnvironmentApi } from './api/features/environment/environment.api';
5
+ import { AdsApi } from './api/features/ads/';
6
+ export declare class ArkadiumGameSdk {
7
+ backendApi: BackendApi;
8
+ environment: EnvironmentApi;
9
+ gameState: GameStateContract;
10
+ lifecycle: GameLifecycleContract;
11
+ ads: AdsApi;
12
+ constructor(backendApi: BackendApi, environment: EnvironmentApi, gameState: GameStateContract, lifecycle: GameLifecycleContract, ads: AdsApi);
13
+ initialize(env: ApiEnv, isGameSide: boolean): Promise<void>;
14
+ updateWinReference(target: any): void;
15
+ }
16
+ export { ApiEnv };
17
+ export declare class GameApi {
18
+ version: string;
19
+ private static sdk;
20
+ static getInstance(env: ApiEnv): Promise<ArkadiumGameSdk>;
21
+ }
22
+ export declare class ArenaApi {
23
+ version: string;
24
+ private static sdk;
25
+ static getInstance(env: ApiEnv): Promise<ArkadiumGameSdk>;
26
+ }
@@ -0,0 +1,26 @@
1
+ import { ApiEnv, BackendApi } from './api/features/backend/backend.api';
2
+ import { GameStateContract } from './api/features/game-state/game-state.api';
3
+ import { GameLifecycleContract } from './api/features/game-lifecycle/game-lifecycle.api';
4
+ import { EnvironmentApi } from './api/features/environment/environment.api';
5
+ import { AdsApi } from './api/features/ads/';
6
+ export declare class ArkadiumGameSdk {
7
+ backendApi: BackendApi;
8
+ environment: EnvironmentApi;
9
+ gameState: GameStateContract;
10
+ lifecycle: GameLifecycleContract;
11
+ ads: AdsApi;
12
+ constructor(backendApi: BackendApi, environment: EnvironmentApi, gameState: GameStateContract, lifecycle: GameLifecycleContract, ads: AdsApi);
13
+ initialize(env: ApiEnv, isGameSide: boolean): Promise<void>;
14
+ updateWinReference(target: any): void;
15
+ }
16
+ export { ApiEnv };
17
+ export declare class GameApi {
18
+ version: string;
19
+ private static sdk;
20
+ static getInstance(env: ApiEnv): Promise<ArkadiumGameSdk>;
21
+ }
22
+ export declare class ArenaApi {
23
+ version: string;
24
+ private static sdk;
25
+ static getInstance(env: ApiEnv): Promise<ArkadiumGameSdk>;
26
+ }
@@ -0,0 +1,17 @@
1
+ const i = "https://arkadiumsdk.z19.web.core.windows.net/sdk.js";
2
+ var c = /* @__PURE__ */ ((e) => (e.DEV = "DEV", e.PROD = "PROD", e))(c || {});
3
+ let n, t;
4
+ function a(e) {
5
+ return t ? Promise.resolve(t) : (n || (n = new Promise((s) => {
6
+ const r = document.createElement("script");
7
+ r.src = i, r.onload = () => {
8
+ globalThis.__GameApi__.getInstance(e).then((o) => {
9
+ t = o, s(t);
10
+ });
11
+ };
12
+ })), n);
13
+ }
14
+ export {
15
+ c as Env,
16
+ a as getInstance
17
+ };
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e.ArkadiumSdk={}))})(this,function(e){"use strict";const t="https://arkadiumsdk.z19.web.core.windows.net/sdk.js";var o=(n=>(n.DEV="DEV",n.PROD="PROD",n))(o||{});let s,i;function d(n){return i?Promise.resolve(i):(s||(s=new Promise(c=>{const r=document.createElement("script");r.src=t,r.onload=()=>{globalThis.__GameApi__.getInstance(n).then(u=>{i=u,c(i)})}})),s)}e.Env=o,e.getInstance=d,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title></title>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link href="css/style.css" rel="stylesheet">
8
+
9
+ <script src=""
10
+ </head>
11
+ <body>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,8 @@
1
+ import { ArkadiumGameSdk } from './arkadium-game-sdk';
2
+ declare type API = ArkadiumGameSdk;
3
+ export declare enum Env {
4
+ DEV = "DEV",
5
+ PROD = "PROD"
6
+ }
7
+ export declare function getInstance(env: Env): Promise<API>;
8
+ export {};
package/package.json ADDED
@@ -0,0 +1,129 @@
1
+ {
2
+ "name": "@arkadiuminc/sdk",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "keywords": [],
6
+ "main": "dist/pkg/arkadium-sdk.umd.js",
7
+ "module": "dist/pkg/arkadium-sdk.mjs",
8
+ "typings": "dist/pkg/loader.d.ts",
9
+ "files": [
10
+ "dist/pkg"
11
+ ],
12
+ "author": "pavel.orlov <pavel.orlov@arkadium.com>",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git@ssh.dev.azure.com:v3/ArkadiumArena/Arena-Arkadium%20Modularization/arkadium-sdk"
16
+ },
17
+ "license": "MIT",
18
+ "engines": {
19
+ "node": ">=6.0.0"
20
+ },
21
+ "scripts": {
22
+ "preview:tsc": "tsc --project example/game/simple-game/tsconfig.json",
23
+ "preview:build": "tsc --project example/game/simple-game/tsconfig.json && vite build --config src/example/game/simple-game/vite.config.js",
24
+ "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
25
+ "prebuild": "rimraf dist",
26
+ "build:pkg": "vite build",
27
+ "build:game": "vite build --config vite.game.config.js",
28
+ "build:arena": "vite build --config vite.arena.config.js",
29
+ "build:docs": "typedoc --out docs --theme default src/arkadium-game-sdk.ts",
30
+ "build": "npm run build:pkg && npm run build:game && npm run build:arena && npm run build:docs",
31
+ "start": "rollup -c rollup.config.ts -w",
32
+ "test": "jest --coverage",
33
+ "test:watch": "jest --coverage --watch",
34
+ "test:prod": "npm run lint && npm run test -- --no-cache",
35
+ "deploy-docs": "ts-node tools/gh-pages-publish",
36
+ "report-coverage": "cat ./coverage/lcov.info | coveralls",
37
+ "commit": "git-cz",
38
+ "semantic-release": "semantic-release",
39
+ "semantic-release-prepare": "ts-node tools/semantic-release-prepare",
40
+ "precommit": "lint-staged"
41
+ },
42
+ "lint-staged": {
43
+ "{src,test}/**/*.ts": [
44
+ "prettier --write",
45
+ "git add"
46
+ ]
47
+ },
48
+ "config": {
49
+ "commitizen": {
50
+ "path": "node_modules/cz-conventional-changelog"
51
+ }
52
+ },
53
+ "jest": {
54
+ "transform": {
55
+ ".(ts|tsx)": "ts-jest"
56
+ },
57
+ "testEnvironment": "node",
58
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
59
+ "moduleFileExtensions": [
60
+ "ts",
61
+ "tsx",
62
+ "js"
63
+ ],
64
+ "coveragePathIgnorePatterns": [
65
+ "/node_modules/",
66
+ "/test/"
67
+ ],
68
+ "coverageThreshold": {
69
+ "global": {
70
+ "branches": 90,
71
+ "functions": 95,
72
+ "lines": 95,
73
+ "statements": 95
74
+ }
75
+ },
76
+ "collectCoverageFrom": [
77
+ "src/*.{js,ts}"
78
+ ]
79
+ },
80
+ "prettier": {
81
+ "singleQuote": true
82
+ },
83
+ "commitlint": {
84
+ "extends": [
85
+ "@commitlint/config-conventional"
86
+ ]
87
+ },
88
+ "devDependencies": {
89
+ "@arkadium/eagle-payments-api-client": "^0.0.35",
90
+ "@arkadium/eagle-user-client": "^0.0.84",
91
+ "@arkadium/eagle-virtual-items-api-client": "^0.0.27",
92
+ "@commitlint/cli": "^17.0.3",
93
+ "@commitlint/config-conventional": "^17.0.3",
94
+ "@rollup/plugin-commonjs": "~22.0.1",
95
+ "@rollup/plugin-json": "~4.1.0",
96
+ "@rollup/plugin-node-resolve": "~13.3.0",
97
+ "@types/jest": "^28.1.6",
98
+ "@types/node": "^18.0.6",
99
+ "colors": "^1.4.0",
100
+ "coveralls": "^3.1.1",
101
+ "cross-env": "^7.0.3",
102
+ "cz-conventional-changelog": "^3.3.0",
103
+ "husky": "^8.0.1",
104
+ "jest": "^28.1.3",
105
+ "jest-config": "^28.1.3",
106
+ "jest-environment-jsdom": "^29.7.0",
107
+ "lint-staged": "^13.0.3",
108
+ "lodash.camelcase": "^4.3.0",
109
+ "prettier": "^2.7.1",
110
+ "prompt": "^1.3.0",
111
+ "replace-in-file": "^6.3.5",
112
+ "rimraf": "^3.0.2",
113
+ "rollup": "~2.77.0",
114
+ "rollup-plugin-sourcemaps": "~0.6.3",
115
+ "rollup-plugin-typescript2": "~0.32.1",
116
+ "semantic-release": "^19.0.3",
117
+ "semantic-release-ado": "^1.4.0",
118
+ "shelljs": "^0.8.5",
119
+ "ts-jest": "^28.0.7",
120
+ "ts-node": "^10.9.1",
121
+ "tslint": "^5.20.1",
122
+ "tslint-config-prettier": "^1.18.0",
123
+ "tslint-config-standard": "^8.0.1",
124
+ "typedoc": "~0.23.8",
125
+ "typescript": "~4.7.4",
126
+ "vite": "^4.4.11",
127
+ "vite-plugin-dts": "^3.6.3"
128
+ }
129
+ }