@clubays/clubgate-sdk 0.2.0 → 0.3.0
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/bin/emulator.js +0 -0
- package/bin/pack.js +0 -0
- package/dist/index.cjs +33 -5
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +33 -5
- package/package.json +6 -6
package/bin/emulator.js
CHANGED
|
File without changes
|
package/bin/pack.js
CHANGED
|
File without changes
|
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ var timeoutMs = 1e4;
|
|
|
41
41
|
var seq = 0;
|
|
42
42
|
var listening = false;
|
|
43
43
|
var pending = /* @__PURE__ */ new Map();
|
|
44
|
+
var navListeners = /* @__PURE__ */ new Set();
|
|
44
45
|
function init(options = {}) {
|
|
45
46
|
if (options.hostOrigin !== void 0) {
|
|
46
47
|
let normalized;
|
|
@@ -58,7 +59,14 @@ function init(options = {}) {
|
|
|
58
59
|
}
|
|
59
60
|
function onMessage(e) {
|
|
60
61
|
if (e.origin !== hostOrigin || e.source !== window.parent) return;
|
|
61
|
-
const
|
|
62
|
+
const data = e.data || {};
|
|
63
|
+
if (data.type === "nav.go") {
|
|
64
|
+
if (typeof data.path === "string") {
|
|
65
|
+
navListeners.forEach((cb) => cb(data.path));
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const { id, result, error } = data;
|
|
62
70
|
if (typeof id !== "number") return;
|
|
63
71
|
const p = pending.get(id);
|
|
64
72
|
if (!p) return;
|
|
@@ -66,14 +74,16 @@ function onMessage(e) {
|
|
|
66
74
|
clearTimeout(p.timer);
|
|
67
75
|
error ? p.reject(new ClubgateError(error)) : p.resolve(result);
|
|
68
76
|
}
|
|
77
|
+
function ensureListening() {
|
|
78
|
+
if (typeof window === "undefined" || listening) return;
|
|
79
|
+
window.addEventListener("message", onMessage);
|
|
80
|
+
listening = true;
|
|
81
|
+
}
|
|
69
82
|
function request(method, params, opts = {}) {
|
|
70
83
|
if (typeof window === "undefined" || window.parent === window) {
|
|
71
84
|
return Promise.reject(new ClubgateError("not_embedded"));
|
|
72
85
|
}
|
|
73
|
-
|
|
74
|
-
window.addEventListener("message", onMessage);
|
|
75
|
-
listening = true;
|
|
76
|
-
}
|
|
86
|
+
ensureListening();
|
|
77
87
|
return new Promise((resolve, reject) => {
|
|
78
88
|
const id = ++seq;
|
|
79
89
|
const timer = setTimeout(() => {
|
|
@@ -104,6 +114,24 @@ var clubgate = {
|
|
|
104
114
|
},
|
|
105
115
|
profile: {
|
|
106
116
|
get: () => request("profile.get")
|
|
117
|
+
},
|
|
118
|
+
nav: {
|
|
119
|
+
/**
|
|
120
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
121
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
122
|
+
*/
|
|
123
|
+
set: (path) => request("nav.set", { path }),
|
|
124
|
+
/**
|
|
125
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
126
|
+
* pasted link). Returns an unsubscribe function.
|
|
127
|
+
*/
|
|
128
|
+
onChange: (cb) => {
|
|
129
|
+
ensureListening();
|
|
130
|
+
navListeners.add(cb);
|
|
131
|
+
return () => {
|
|
132
|
+
navListeners.delete(cb);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
107
135
|
}
|
|
108
136
|
};
|
|
109
137
|
var clubays = clubgate;
|
package/dist/index.d.cts
CHANGED
|
@@ -50,6 +50,18 @@ declare const clubgate: {
|
|
|
50
50
|
profile: {
|
|
51
51
|
get: () => Promise<ClubgateProfile>;
|
|
52
52
|
};
|
|
53
|
+
nav: {
|
|
54
|
+
/**
|
|
55
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
56
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
57
|
+
*/
|
|
58
|
+
set: (path: string) => Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
61
|
+
* pasted link). Returns an unsubscribe function.
|
|
62
|
+
*/
|
|
63
|
+
onChange: (cb: (path: string) => void) => () => void;
|
|
64
|
+
};
|
|
53
65
|
};
|
|
54
66
|
/** @deprecated use `clubgate` */
|
|
55
67
|
declare const clubays: {
|
|
@@ -71,6 +83,18 @@ declare const clubays: {
|
|
|
71
83
|
profile: {
|
|
72
84
|
get: () => Promise<ClubgateProfile>;
|
|
73
85
|
};
|
|
86
|
+
nav: {
|
|
87
|
+
/**
|
|
88
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
89
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
90
|
+
*/
|
|
91
|
+
set: (path: string) => Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
94
|
+
* pasted link). Returns an unsubscribe function.
|
|
95
|
+
*/
|
|
96
|
+
onChange: (cb: (path: string) => void) => () => void;
|
|
97
|
+
};
|
|
74
98
|
};
|
|
75
99
|
/** @deprecated use `ClubgateError` */
|
|
76
100
|
declare const ClubaysError: typeof ClubgateError;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,18 @@ declare const clubgate: {
|
|
|
50
50
|
profile: {
|
|
51
51
|
get: () => Promise<ClubgateProfile>;
|
|
52
52
|
};
|
|
53
|
+
nav: {
|
|
54
|
+
/**
|
|
55
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
56
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
57
|
+
*/
|
|
58
|
+
set: (path: string) => Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
61
|
+
* pasted link). Returns an unsubscribe function.
|
|
62
|
+
*/
|
|
63
|
+
onChange: (cb: (path: string) => void) => () => void;
|
|
64
|
+
};
|
|
53
65
|
};
|
|
54
66
|
/** @deprecated use `clubgate` */
|
|
55
67
|
declare const clubays: {
|
|
@@ -71,6 +83,18 @@ declare const clubays: {
|
|
|
71
83
|
profile: {
|
|
72
84
|
get: () => Promise<ClubgateProfile>;
|
|
73
85
|
};
|
|
86
|
+
nav: {
|
|
87
|
+
/**
|
|
88
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
89
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
90
|
+
*/
|
|
91
|
+
set: (path: string) => Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
94
|
+
* pasted link). Returns an unsubscribe function.
|
|
95
|
+
*/
|
|
96
|
+
onChange: (cb: (path: string) => void) => () => void;
|
|
97
|
+
};
|
|
74
98
|
};
|
|
75
99
|
/** @deprecated use `ClubgateError` */
|
|
76
100
|
declare const ClubaysError: typeof ClubgateError;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var timeoutMs = 1e4;
|
|
|
13
13
|
var seq = 0;
|
|
14
14
|
var listening = false;
|
|
15
15
|
var pending = /* @__PURE__ */ new Map();
|
|
16
|
+
var navListeners = /* @__PURE__ */ new Set();
|
|
16
17
|
function init(options = {}) {
|
|
17
18
|
if (options.hostOrigin !== void 0) {
|
|
18
19
|
let normalized;
|
|
@@ -30,7 +31,14 @@ function init(options = {}) {
|
|
|
30
31
|
}
|
|
31
32
|
function onMessage(e) {
|
|
32
33
|
if (e.origin !== hostOrigin || e.source !== window.parent) return;
|
|
33
|
-
const
|
|
34
|
+
const data = e.data || {};
|
|
35
|
+
if (data.type === "nav.go") {
|
|
36
|
+
if (typeof data.path === "string") {
|
|
37
|
+
navListeners.forEach((cb) => cb(data.path));
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const { id, result, error } = data;
|
|
34
42
|
if (typeof id !== "number") return;
|
|
35
43
|
const p = pending.get(id);
|
|
36
44
|
if (!p) return;
|
|
@@ -38,14 +46,16 @@ function onMessage(e) {
|
|
|
38
46
|
clearTimeout(p.timer);
|
|
39
47
|
error ? p.reject(new ClubgateError(error)) : p.resolve(result);
|
|
40
48
|
}
|
|
49
|
+
function ensureListening() {
|
|
50
|
+
if (typeof window === "undefined" || listening) return;
|
|
51
|
+
window.addEventListener("message", onMessage);
|
|
52
|
+
listening = true;
|
|
53
|
+
}
|
|
41
54
|
function request(method, params, opts = {}) {
|
|
42
55
|
if (typeof window === "undefined" || window.parent === window) {
|
|
43
56
|
return Promise.reject(new ClubgateError("not_embedded"));
|
|
44
57
|
}
|
|
45
|
-
|
|
46
|
-
window.addEventListener("message", onMessage);
|
|
47
|
-
listening = true;
|
|
48
|
-
}
|
|
58
|
+
ensureListening();
|
|
49
59
|
return new Promise((resolve, reject) => {
|
|
50
60
|
const id = ++seq;
|
|
51
61
|
const timer = setTimeout(() => {
|
|
@@ -76,6 +86,24 @@ var clubgate = {
|
|
|
76
86
|
},
|
|
77
87
|
profile: {
|
|
78
88
|
get: () => request("profile.get")
|
|
89
|
+
},
|
|
90
|
+
nav: {
|
|
91
|
+
/**
|
|
92
|
+
* Tell the host the app's current route (e.g. "/profile?tab=a") so it can
|
|
93
|
+
* mirror it into the browser URL. Must start with a single "/".
|
|
94
|
+
*/
|
|
95
|
+
set: (path) => request("nav.set", { path }),
|
|
96
|
+
/**
|
|
97
|
+
* Called when the host URL changes from outside the app (back/forward,
|
|
98
|
+
* pasted link). Returns an unsubscribe function.
|
|
99
|
+
*/
|
|
100
|
+
onChange: (cb) => {
|
|
101
|
+
ensureListening();
|
|
102
|
+
navListeners.add(cb);
|
|
103
|
+
return () => {
|
|
104
|
+
navListeners.delete(cb);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
79
107
|
}
|
|
80
108
|
};
|
|
81
109
|
var clubays = clubgate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clubays/clubgate-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "SDK for building Clubays miniapps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"bin"
|
|
38
38
|
],
|
|
39
39
|
"sideEffects": false,
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"tsup": "^8.0.0",
|
|
42
46
|
"typescript": "^5.6.0"
|
|
@@ -46,9 +50,5 @@
|
|
|
46
50
|
},
|
|
47
51
|
"dependencies": {
|
|
48
52
|
"archiver": "^7.0.1"
|
|
49
|
-
},
|
|
50
|
-
"scripts": {
|
|
51
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
53
53
|
}
|
|
54
|
-
}
|
|
54
|
+
}
|