@makefully/adaptfully 2.1.0 → 3.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.
@@ -1,89 +1,89 @@
1
- /* global window */
2
-
3
- (function registerPlatform(ns) {
4
- class Platform {
5
- /**
6
- * @param {object} authPlugin
7
- */
8
- constructor(authPlugin) {
9
- this.auth = authPlugin;
10
- this.online = true;
11
- this.#ready = false;
12
- this.#queue = [];
13
-
14
- authPlugin.whenReady((err) => {
15
- if (err) {
16
- this.online = false;
17
- }
18
- this.#ready = true;
19
- const queue = this.#queue;
20
- this.#queue = [];
21
- for (const callback of queue) {
22
- callback();
23
- }
24
- });
25
- }
26
-
27
- /** @type {boolean} */
28
- #ready;
29
-
30
- /** @type {Array<() => void>} */
31
- #queue;
32
-
33
- whenReady(callback) {
34
- if (this.#ready) {
35
- callback();
36
- return;
37
- }
38
- this.#queue.push(callback);
39
- }
40
-
41
- login(callback) {
42
- this.whenReady(() => {
43
- if (!this.online) {
44
- callback({ authenticated: false });
45
- return;
46
- }
47
- this.auth.login((result) => {
48
- callback(result || {
49
- authenticated: this.auth.isAuthenticated(),
50
- user: this.auth.getUser(),
51
- });
52
- });
53
- });
54
- }
55
-
56
- silentLogin(callback) {
57
- this.whenReady(() => {
58
- if (!this.online) {
59
- callback({ authenticated: false });
60
- return;
61
- }
62
- this.auth.silentLogin((result) => {
63
- callback(result || {
64
- authenticated: this.auth.isAuthenticated(),
65
- user: this.auth.getUser(),
66
- });
67
- });
68
- });
69
- }
70
-
71
- logout(callback) {
72
- this.whenReady(() => {
73
- this.auth.logout(() => {
74
- callback({ authenticated: false });
75
- });
76
- });
77
- }
78
-
79
- getUser() {
80
- return this.auth.getUser();
81
- }
82
-
83
- isAuthenticated() {
84
- return this.auth.isAuthenticated();
85
- }
86
- }
87
-
88
- ns.Platform = Platform;
89
- }(window.adaptfully));
1
+ /* global window */
2
+
3
+ (function registerPlatform(ns) {
4
+ class Platform {
5
+ /**
6
+ * @param {object} authPlugin
7
+ */
8
+ constructor(authPlugin) {
9
+ this.auth = authPlugin;
10
+ this.online = true;
11
+ this.#ready = false;
12
+ this.#queue = [];
13
+
14
+ authPlugin.whenReady((err) => {
15
+ if (err) {
16
+ this.online = false;
17
+ }
18
+ this.#ready = true;
19
+ const queue = this.#queue;
20
+ this.#queue = [];
21
+ for (const callback of queue) {
22
+ callback();
23
+ }
24
+ });
25
+ }
26
+
27
+ /** @type {boolean} */
28
+ #ready;
29
+
30
+ /** @type {Array<() => void>} */
31
+ #queue;
32
+
33
+ whenReady(callback) {
34
+ if (this.#ready) {
35
+ callback();
36
+ return;
37
+ }
38
+ this.#queue.push(callback);
39
+ }
40
+
41
+ login(callback) {
42
+ this.whenReady(() => {
43
+ if (!this.online) {
44
+ callback({ authenticated: false });
45
+ return;
46
+ }
47
+ this.auth.login((result) => {
48
+ callback(result || {
49
+ authenticated: this.auth.isAuthenticated(),
50
+ user: this.auth.getUser(),
51
+ });
52
+ });
53
+ });
54
+ }
55
+
56
+ silentLogin(callback) {
57
+ this.whenReady(() => {
58
+ if (!this.online) {
59
+ callback({ authenticated: false });
60
+ return;
61
+ }
62
+ this.auth.silentLogin((result) => {
63
+ callback(result || {
64
+ authenticated: this.auth.isAuthenticated(),
65
+ user: this.auth.getUser(),
66
+ });
67
+ });
68
+ });
69
+ }
70
+
71
+ logout(callback) {
72
+ this.whenReady(() => {
73
+ this.auth.logout(() => {
74
+ callback({ authenticated: false });
75
+ });
76
+ });
77
+ }
78
+
79
+ getUser() {
80
+ return this.auth.getUser();
81
+ }
82
+
83
+ isAuthenticated() {
84
+ return this.auth.isAuthenticated();
85
+ }
86
+ }
87
+
88
+ ns.Platform = Platform;
89
+ }(window.adaptfully));
package/package.json CHANGED
@@ -1,61 +1,62 @@
1
- {
2
- "name": "@makefully/adaptfully",
3
- "version": "2.1.0",
4
- "description": "Platform abstraction and Wrapfully deploy client for Makefully games",
5
- "type": "module",
6
- "main": "./lib/node/index.js",
7
- "exports": {
8
- ".": "./lib/node/index.js",
9
- "./runtime/*": "./lib/runtime/*",
10
- "./deploy": "./lib/node/deploy.js",
11
- "./package.json": "./package.json"
12
- },
13
- "bin": {
14
- "wrapfully-deploy": "bin/wrapfully-deploy.js"
15
- },
16
- "files": [
17
- "bin",
18
- "lib",
19
- "CHANGELOG.md",
20
- "LICENSE",
21
- "README.md"
22
- ],
23
- "scripts": {
24
- "deploy": "node bin/wrapfully-deploy.js",
25
- "test": "node --test test/*.test.js"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/Makefully-Studios/adaptfully.git"
30
- },
31
- "bugs": {
32
- "url": "https://github.com/Makefully-Studios/adaptfully/issues"
33
- },
34
- "homepage": "https://github.com/Makefully-Studios/adaptfully#readme",
35
- "keywords": [
36
- "adaptfully",
37
- "wrapfully",
38
- "auth",
39
- "platform",
40
- "deploy",
41
- "build",
42
- "cordova",
43
- "electron"
44
- ],
45
- "contributors": [
46
- "Derek Detweiler <derek@makefullystudios.com>"
47
- ],
48
- "license": "MIT",
49
- "publishConfig": {
50
- "access": "public",
51
- "provenance": true
52
- },
53
- "engines": {
54
- "node": ">=18"
55
- },
56
- "dependencies": {
57
- "archiver": "^7.0.1",
58
- "axios": "^1.7.9",
59
- "unzip-stream": "^0.3.4"
60
- }
61
- }
1
+ {
2
+ "name": "@makefully/adaptfully",
3
+ "version": "3.0.1",
4
+ "description": "Platform abstraction and Wrapfully deploy client for Makefully games",
5
+ "type": "module",
6
+ "main": "./lib/node/index.js",
7
+ "exports": {
8
+ ".": "./lib/node/index.js",
9
+ "./runtime/*": "./lib/runtime/*",
10
+ "./deploy": "./lib/node/deploy.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "bin": {
14
+ "adaptfully": "bin/adaptfully.js",
15
+ "wrapfully-deploy": "bin/wrapfully-deploy.js"
16
+ },
17
+ "files": [
18
+ "bin",
19
+ "lib",
20
+ "CHANGELOG.md",
21
+ "LICENSE",
22
+ "README.md"
23
+ ],
24
+ "scripts": {
25
+ "deploy": "node bin/wrapfully-deploy.js",
26
+ "test": "node --test test/*.test.js"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/Makefully-Studios/adaptfully.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/Makefully-Studios/adaptfully/issues"
34
+ },
35
+ "homepage": "https://github.com/Makefully-Studios/adaptfully#readme",
36
+ "keywords": [
37
+ "adaptfully",
38
+ "wrapfully",
39
+ "auth",
40
+ "platform",
41
+ "deploy",
42
+ "build",
43
+ "cordova",
44
+ "electron"
45
+ ],
46
+ "contributors": [
47
+ "Derek Detweiler <derek@makefullystudios.com>"
48
+ ],
49
+ "license": "MIT",
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "provenance": true
53
+ },
54
+ "engines": {
55
+ "node": ">=18"
56
+ },
57
+ "dependencies": {
58
+ "archiver": "^7.0.1",
59
+ "axios": "^1.7.9",
60
+ "unzip-stream": "^0.3.4"
61
+ }
62
+ }
@@ -1,138 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
- const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
7
- const RUNTIME_DIR = path.join(PACKAGE_ROOT, 'lib', 'runtime');
8
-
9
- /** @typedef {'web' | 'steam' | 'android' | 'ios'} BuildChannel */
10
-
11
- export const VALID_CHANNELS = new Set(['web', 'steam', 'android', 'ios']);
12
-
13
- /** @type {Record<BuildChannel, string[]>} */
14
- const CHANNEL_EXCLUDED_AUTH = {
15
- steam: ['auth/google-auth.js'],
16
- web: ['auth/steam-auth.js'],
17
- android: ['auth/steam-auth.js'],
18
- ios: ['auth/steam-auth.js'],
19
- };
20
-
21
- /** @type {Record<BuildChannel, string>} */
22
- const CHANNEL_EXT_SCRIPTS = {
23
- web: '<script src="https://accounts.google.com/gsi/client" async defer></script>\n',
24
- android: '<script src="https://accounts.google.com/gsi/client" async defer></script>\n',
25
- ios: '<script src="https://accounts.google.com/gsi/client" async defer></script>\n',
26
- };
27
-
28
- /** @type {Record<BuildChannel, string>} */
29
- const CHANNEL_AUTH_REGISTRATION = {
30
- web: "adaptfully.register('auth', adaptfully.auth.Google);",
31
- android: "adaptfully.register('auth', adaptfully.auth.Google);",
32
- ios: "adaptfully.register('auth', adaptfully.auth.Google);",
33
- steam: "adaptfully.register('auth', adaptfully.auth.Steam);",
34
- };
35
-
36
- const DEV_AUTH_REGISTRATION = "adaptfully.register('auth', adaptfully.auth.Dev);";
37
-
38
- const RUNTIME_BASE_SCRIPTS = [
39
- 'core.js',
40
- 'platform.js',
41
- ];
42
-
43
- export function getPackageRoot() {
44
- return PACKAGE_ROOT;
45
- }
46
-
47
- export function getRuntimeDir() {
48
- return RUNTIME_DIR;
49
- }
50
-
51
- export function resolveRuntimeScript(relativePath) {
52
- return path.join(RUNTIME_DIR, relativePath);
53
- }
54
-
55
- /**
56
- * @param {NodeJS.ProcessEnv} [env]
57
- * @returns {BuildChannel}
58
- */
59
- export function getBuildChannel(env = process.env) {
60
- const channel = env.ENTANGLEMENT_CHANNEL
61
- || env.VITE_ENTANGLEMENT_CHANNEL
62
- || env.ADAPTFULLY_CHANNEL
63
- || 'web';
64
-
65
- if (!VALID_CHANNELS.has(channel)) {
66
- throw new Error(
67
- `Invalid distribution channel "${channel}". Expected one of: ${[...VALID_CHANNELS].join(', ')}`,
68
- );
69
- }
70
-
71
- return /** @type {BuildChannel} */ (channel);
72
- }
73
-
74
- /** @param {BuildChannel} [channel] */
75
- export function authRegistrationForChannel(channel = getBuildChannel()) {
76
- const registration = CHANNEL_AUTH_REGISTRATION[channel];
77
- if (!registration) {
78
- throw new Error(`No auth registration for channel: ${channel}`);
79
- }
80
- return registration;
81
- }
82
-
83
- export function devAuthRegistration() {
84
- return DEV_AUTH_REGISTRATION;
85
- }
86
-
87
- /** @param {BuildChannel} [channel] */
88
- export function getAuthScriptsForChannel(channel = getBuildChannel()) {
89
- const excluded = new Set(CHANNEL_EXCLUDED_AUTH[channel] ?? []);
90
- const scripts = RUNTIME_BASE_SCRIPTS.map((rel) => resolveRuntimeScript(rel));
91
-
92
- const authDir = path.join(RUNTIME_DIR, 'auth');
93
- for (const file of fs.readdirSync(authDir).sort()) {
94
- const rel = path.join('auth', file).replace(/\\/g, '/');
95
- if (!excluded.has(rel)) {
96
- scripts.push(path.join(authDir, file));
97
- }
98
- }
99
-
100
- return scripts;
101
- }
102
-
103
- /** @param {BuildChannel} [channel] */
104
- export function authRegistrationScript(channel = getBuildChannel()) {
105
- return authRegistrationForChannel(channel);
106
- }
107
-
108
- /** @param {BuildChannel} [channel] */
109
- export function extScriptsForBuildChannel(channel = getBuildChannel()) {
110
- return CHANNEL_EXT_SCRIPTS[channel] ?? '';
111
- }
112
-
113
- /**
114
- * @param {Array<string | { src: string }>} includes
115
- * @param {BuildChannel} [channel]
116
- */
117
- export function filterIncludesForBuildChannel(includes, channel = getBuildChannel()) {
118
- if (channel !== 'steam') {
119
- return includes;
120
- }
121
-
122
- return includes.filter((include) => {
123
- const rel = typeof include === 'string' ? include : include.src;
124
- return rel !== 'script/banner-ads.js';
125
- });
126
- }
127
-
128
- /**
129
- * @param {BuildChannel} channel
130
- * @param {{ profiles: object, allExpansionsBitmask?: number }} distributionConfig
131
- */
132
- export function distributionSettingsForBuild(channel, distributionConfig) {
133
- return {
134
- channel,
135
- profiles: distributionConfig.profiles,
136
- allExpansionsBitmask: distributionConfig.allExpansionsBitmask ?? 15,
137
- };
138
- }