@adlad/plugin-viverse 0.6.0 → 0.7.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/deno.lock CHANGED
@@ -33,8 +33,8 @@
33
33
  "@jridgewell/sourcemap-codec"
34
34
  ]
35
35
  },
36
- "acorn@8.15.0": {
37
- "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
36
+ "acorn@8.16.0": {
37
+ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
38
38
  "bin": true
39
39
  },
40
40
  "buffer-from@1.1.2": {
@@ -1,3 +1,18 @@
1
+ /**
2
+ * @typedef ViverseProfile
3
+ * @property {string} name
4
+ * @property {ViverseAvatar | null} activeAvatar
5
+ */
6
+ /**
7
+ * @typedef ViverseAvatar
8
+ * @property {string | number} id
9
+ * @property {boolean} isPrivate
10
+ * @property {string} vrmUrl
11
+ * @property {string} headIconUrl
12
+ * @property {string} snapshot
13
+ * @property {number} createTime
14
+ * @property {number} updateTime
15
+ */
1
16
  /**
2
17
  * @param {Object} options
3
18
  * @param {string} options.appId
@@ -20,6 +35,23 @@ export function viversePlugin({ appId, }: {
20
35
  readonly getStorageItem: (key: string) => Promise<unknown>;
21
36
  readonly showAuthPrompt: () => void;
22
37
  readonly getIsSignedIn: () => boolean;
23
- readonly getProfile: () => Promise<any>;
38
+ /**
39
+ * @returns {Promise<ViverseProfile?>}
40
+ */
41
+ readonly getProfile: () => Promise<ViverseProfile | null>;
24
42
  };
25
43
  };
44
+ export default viversePlugin;
45
+ export type ViverseProfile = {
46
+ name: string;
47
+ activeAvatar: ViverseAvatar | null;
48
+ };
49
+ export type ViverseAvatar = {
50
+ id: string | number;
51
+ isPrivate: boolean;
52
+ vrmUrl: string;
53
+ headIconUrl: string;
54
+ snapshot: string;
55
+ createTime: number;
56
+ updateTime: number;
57
+ };
@@ -1 +1 @@
1
- function viversePlugin({appId:e}){let t=!1;if(!e)throw new Error("No app id was provided");const a={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData",avatar:"avatar",baseURL:"baseURL",token:"token"};let i,o;a>0&&console.log(a);let n=null,s=null;const l=new Map,r="adlad_viverse_";return{name:"viverse",async initialize(s){if(t)throw new Error("Viverse plugin is being initialized more than once");if(t=!0,await s.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),i=new globalThis[a.viverse][a.client]({[a.clientId]:e,[a.domain]:"account.htcvive.com",[a.cookieDomain]:window.location.hostname}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on viverse.com.");const l=await i[a.checkAuth]();n=l?.access_token||null;const r=new globalThis[a.viverse][a.storage];o=await r[a.newCloudSaveClient](e)},customRequests:{async setStorageItem(e,t){const i=JSON.stringify(t);if(n)await o[a.setPlayerData](e,{s:i},n);else{await new Promise((e=>setTimeout(e,1e3)));try{localStorage.setItem(r+e,i)}catch{l.set(e,i)}}},async getStorageItem(e){let t;if(n){const i=await o[a.getPlayerData](e,n);t="object"==typeof i&&null!=i?i.s:null}else{await new Promise((e=>setTimeout(e,1e3)));try{t=localStorage.getItem(r+e)}catch{t=l.get(e)}}return t&&"string"==typeof t?JSON.parse(t):null},showAuthPrompt(){i[a.loginWithWorlds]()},getIsSignedIn:()=>Boolean(n),async getProfile(){const e=n?(s||(s=new viverse[a.avatar]({[a.baseURL]:"https://sdk-api.viverse.com/",[a.token]:n})),s):null;return e?await e.getProfile():null}}}}export{viversePlugin};
1
+ function viversePlugin({appId:e}){let t=!1;if(!e)throw new Error("No app id was provided");const a={viverse:"viverse",client:"client",clientId:"clientId",domain:"domain",cookieDomain:"cookieDomain",checkAuth:"checkAuth",loginWithWorlds:"loginWithWorlds",storage:"storage",newCloudSaveClient:"newCloudSaveClient",setPlayerData:"setPlayerData",getPlayerData:"getPlayerData",avatar:"avatar",baseURL:"baseURL",token:"token"};let i,o;a>0&&console.log(a);let n=null,s=null;const l=new Map,r="adlad_viverse_";return{name:"viverse",async initialize(s){if(t)throw new Error("Viverse plugin is being initialized more than once");if(t=!0,await s.loadScriptTag("https://www.viverse.com/static-assets/viverse-sdk/index.umd.cjs"),i=new globalThis[a.viverse][a.client]({[a.clientId]:e,[a.domain]:"account.htcvive.com",[a.cookieDomain]:window.location.hostname}),window.parent==window)throw new Error("The Viverse SDK is not supported unless the game is embedded on viverse.com.");const l=await i[a.checkAuth]();n=l?.access_token||null;const r=new globalThis[a.viverse][a.storage];o=await r[a.newCloudSaveClient](e)},customRequests:{async setStorageItem(e,t){const i=JSON.stringify(t);if(n)await o[a.setPlayerData](e,{s:i},n);else{await new Promise((e=>setTimeout(e,1e3)));try{localStorage.setItem(r+e,i)}catch{l.set(e,i)}}},async getStorageItem(e){let t;if(n){const i=await o[a.getPlayerData](e,n);t="object"==typeof i&&null!=i?i.s:null}else{await new Promise((e=>setTimeout(e,1e3)));try{t=localStorage.getItem(r+e)}catch{t=l.get(e)}}return t&&"string"==typeof t?JSON.parse(t):null},showAuthPrompt(){i[a.loginWithWorlds]()},getIsSignedIn:()=>Boolean(n),async getProfile(){const e=n?(s||(s=new viverse[a.avatar]({[a.baseURL]:"https://sdk-api.viverse.com/",[a.token]:n})),s):null;return e?await e.getProfile():null}}}}export{viversePlugin as default,viversePlugin};
package/mod.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./src/mod.js";
2
+ export { default } from "./src/mod.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adlad/plugin-viverse",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "AdLad plugin for the Viverse sdk.",
5
5
  "main": "mod.js",
6
6
  "types": "dist/adlad-plugin-viverse.d.ts",
package/src/mod.js CHANGED
@@ -1,3 +1,20 @@
1
+ /**
2
+ * @typedef ViverseProfile
3
+ * @property {string} name
4
+ * @property {ViverseAvatar | null} activeAvatar
5
+ */
6
+
7
+ /**
8
+ * @typedef ViverseAvatar
9
+ * @property {string | number} id
10
+ * @property {boolean} isPrivate
11
+ * @property {string} vrmUrl
12
+ * @property {string} headIconUrl
13
+ * @property {string} snapshot
14
+ * @property {number} createTime
15
+ * @property {number} updateTime
16
+ */
17
+
1
18
  /**
2
19
  * @param {Object} options
3
20
  * @param {string} options.appId
@@ -155,6 +172,9 @@ export function viversePlugin({
155
172
  getIsSignedIn() {
156
173
  return Boolean(accessToken);
157
174
  },
175
+ /**
176
+ * @returns {Promise<ViverseProfile?>}
177
+ */
158
178
  async getProfile() {
159
179
  const client = getAvatarClient();
160
180
  if (!client) return null;
@@ -165,3 +185,5 @@ export function viversePlugin({
165
185
 
166
186
  return plugin;
167
187
  }
188
+
189
+ export default viversePlugin;
package/src/types.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ViverseProfile } from "./mod.js";
2
+
1
3
  declare global {
2
4
  var viverse: {
3
5
  client: typeof ViverseClient;
@@ -42,22 +44,7 @@ interface ViverseAvatarClientOptions {
42
44
 
43
45
  export class ViverseAvatarClient {
44
46
  constructor(options: ViverseAvatarClientOptions);
45
- getProfile(): Promise<ViverseAvatar>;
46
- }
47
-
48
- type ViverseProfile = {
49
- name: string;
50
- activeAvatar: ViverseAvatar | null;
51
- };
52
-
53
- type ViverseAvatar = {
54
- id: string | number;
55
- isPrivate: boolean;
56
- vrmUrl: string;
57
- headIconUrl: string;
58
- snapshot: string;
59
- createTime: number;
60
- updateTime: number;
61
- };
47
+ getProfile(): Promise<ViverseProfile>;
48
+ }
62
49
 
63
50
  export {};