@looplay/sdk 0.8.9 → 0.8.10
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/dist/looplay-sdk.cjs.js +58 -54
- package/dist/looplay-sdk.cjs.js.map +1 -1
- package/dist/looplay-sdk.esm.js +58 -54
- package/dist/looplay-sdk.esm.js.map +1 -1
- package/dist/looplay-sdk.min.js +4 -4
- package/dist/looplay-sdk.min.js.map +1 -1
- package/dist/types/apps/api-client.d.ts +1 -1
- package/dist/types/apps/http.d.ts +2 -2
- package/dist/types/iframe/iframe-auth.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/looplay-sdk.cjs.js
CHANGED
|
@@ -140,8 +140,45 @@ var LooplayAuth = class {
|
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
// src/constants.ts
|
|
144
|
+
var DEFAULT_API_URL = "https://miniapp-api.looplay.gg";
|
|
145
|
+
function resolveEnvParentOrigin() {
|
|
146
|
+
try {
|
|
147
|
+
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('looplay-sdk.cjs.js', document.baseURI).href)) }) !== "undefined" && undefined?.VITE_PARENT_ORIGIN) {
|
|
148
|
+
const val = undefined.VITE_PARENT_ORIGIN;
|
|
149
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
if (typeof process !== "undefined" && process.env?.VITE_PARENT_ORIGIN) {
|
|
155
|
+
const val = process.env.VITE_PARENT_ORIGIN;
|
|
156
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
return void 0;
|
|
161
|
+
}
|
|
162
|
+
function resolveEnvApiUrl() {
|
|
163
|
+
try {
|
|
164
|
+
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('looplay-sdk.cjs.js', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
165
|
+
const val = undefined.VITE_API_URL ?? undefined.VITE_LOOPLAY_API_URL;
|
|
166
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
if (typeof process !== "undefined" && process.env) {
|
|
172
|
+
const val = process.env.VITE_API_URL ?? process.env.VITE_LOOPLAY_API_URL;
|
|
173
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
174
|
+
}
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
return void 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
143
180
|
// src/version.ts
|
|
144
|
-
var LOOPLAY_SDK_VERSION = "0.8.
|
|
181
|
+
var LOOPLAY_SDK_VERSION = "0.8.10";
|
|
145
182
|
|
|
146
183
|
// src/apps/http.ts
|
|
147
184
|
function getFetchFn(fetchOverride) {
|
|
@@ -167,8 +204,9 @@ var HttpClient = class {
|
|
|
167
204
|
baseUrl;
|
|
168
205
|
fetchFn;
|
|
169
206
|
defaultHeaders;
|
|
170
|
-
constructor(options) {
|
|
171
|
-
|
|
207
|
+
constructor(options = {}) {
|
|
208
|
+
const rawBaseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
209
|
+
this.baseUrl = rawBaseUrl.replace(/\/$/, "");
|
|
172
210
|
this.fetchFn = getFetchFn(options.fetch);
|
|
173
211
|
this.defaultHeaders = {
|
|
174
212
|
"x-looplay-sdk-version": LOOPLAY_SDK_VERSION,
|
|
@@ -464,10 +502,11 @@ var ApiClient = class {
|
|
|
464
502
|
playSession;
|
|
465
503
|
playSessionPromiseKey;
|
|
466
504
|
playSessionPromise;
|
|
467
|
-
constructor(options) {
|
|
468
|
-
|
|
505
|
+
constructor(options = {}) {
|
|
506
|
+
const baseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
507
|
+
if (!baseUrl) throw new MissingBaseUrlError();
|
|
469
508
|
this.raw = new ServiceClient({
|
|
470
|
-
baseUrl
|
|
509
|
+
baseUrl,
|
|
471
510
|
fetch: options.fetch,
|
|
472
511
|
defaultHeaders: options.defaultHeaders
|
|
473
512
|
});
|
|
@@ -685,43 +724,6 @@ var ApiClient = class {
|
|
|
685
724
|
}
|
|
686
725
|
};
|
|
687
726
|
|
|
688
|
-
// src/constants.ts
|
|
689
|
-
var DEFAULT_API_URL = "https://miniapp-api.looplay.gg";
|
|
690
|
-
function resolveEnvParentOrigin() {
|
|
691
|
-
try {
|
|
692
|
-
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('looplay-sdk.cjs.js', document.baseURI).href)) }) !== "undefined" && undefined?.VITE_PARENT_ORIGIN) {
|
|
693
|
-
const val = undefined.VITE_PARENT_ORIGIN;
|
|
694
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
695
|
-
}
|
|
696
|
-
} catch {
|
|
697
|
-
}
|
|
698
|
-
try {
|
|
699
|
-
if (typeof process !== "undefined" && process.env?.VITE_PARENT_ORIGIN) {
|
|
700
|
-
const val = process.env.VITE_PARENT_ORIGIN;
|
|
701
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
702
|
-
}
|
|
703
|
-
} catch {
|
|
704
|
-
}
|
|
705
|
-
return void 0;
|
|
706
|
-
}
|
|
707
|
-
function resolveEnvApiUrl() {
|
|
708
|
-
try {
|
|
709
|
-
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('looplay-sdk.cjs.js', document.baseURI).href)) }) !== "undefined" && undefined) {
|
|
710
|
-
const val = undefined.VITE_API_URL ?? undefined.VITE_LOOPLAY_API_URL;
|
|
711
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
712
|
-
}
|
|
713
|
-
} catch {
|
|
714
|
-
}
|
|
715
|
-
try {
|
|
716
|
-
if (typeof process !== "undefined" && process.env) {
|
|
717
|
-
const val = process.env.VITE_API_URL ?? process.env.VITE_LOOPLAY_API_URL;
|
|
718
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
719
|
-
}
|
|
720
|
-
} catch {
|
|
721
|
-
}
|
|
722
|
-
return void 0;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
727
|
// src/looplay-sdk.ts
|
|
726
728
|
var LooplaySDK = class {
|
|
727
729
|
auth;
|
|
@@ -731,21 +733,19 @@ var LooplaySDK = class {
|
|
|
731
733
|
constructor(options = {}) {
|
|
732
734
|
const {
|
|
733
735
|
auth,
|
|
734
|
-
baseUrl = resolveEnvApiUrl() ?? DEFAULT_API_URL,
|
|
735
736
|
fetch,
|
|
736
737
|
defaultHeaders
|
|
737
738
|
} = options;
|
|
739
|
+
const baseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
738
740
|
if (auth) {
|
|
739
741
|
this.auth = new LooplayAuth(auth);
|
|
740
742
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
});
|
|
748
|
-
}
|
|
743
|
+
this.api = new ApiClient({
|
|
744
|
+
baseUrl,
|
|
745
|
+
fetch,
|
|
746
|
+
defaultHeaders,
|
|
747
|
+
getAccessToken: async () => this.auth?.getAccessToken()
|
|
748
|
+
});
|
|
749
749
|
}
|
|
750
750
|
async init(params) {
|
|
751
751
|
this.gameId = params.gameId;
|
|
@@ -1007,7 +1007,8 @@ var LooplayIframeAuth = class {
|
|
|
1007
1007
|
return this.state.jwt;
|
|
1008
1008
|
}
|
|
1009
1009
|
getApiUrl() {
|
|
1010
|
-
|
|
1010
|
+
const raw = toOptionalString(this.state.apiUrl) ?? toOptionalString(this.options.apiUrl) ?? resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
1011
|
+
return raw.trim();
|
|
1011
1012
|
}
|
|
1012
1013
|
/** Resolves to the configured `appId`, falling back to whatever the parent pushed as `gameId`. */
|
|
1013
1014
|
getGameId() {
|
|
@@ -1382,7 +1383,10 @@ ${gameId}`;
|
|
|
1382
1383
|
}
|
|
1383
1384
|
}
|
|
1384
1385
|
resolveParentOrigin() {
|
|
1385
|
-
if (this.options.parentOrigin)
|
|
1386
|
+
if (this.options.parentOrigin) {
|
|
1387
|
+
const opt = toOptionalString(this.options.parentOrigin);
|
|
1388
|
+
if (opt) return opt;
|
|
1389
|
+
}
|
|
1386
1390
|
const envOrigin = resolveEnvParentOrigin();
|
|
1387
1391
|
if (envOrigin) return envOrigin;
|
|
1388
1392
|
if (typeof document === "undefined" || !document.referrer) return null;
|