@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.esm.js
CHANGED
|
@@ -137,8 +137,45 @@ var LooplayAuth = class {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
// src/constants.ts
|
|
141
|
+
var DEFAULT_API_URL = "https://miniapp-api.looplay.gg";
|
|
142
|
+
function resolveEnvParentOrigin() {
|
|
143
|
+
try {
|
|
144
|
+
if (typeof import.meta !== "undefined" && import.meta.env?.VITE_PARENT_ORIGIN) {
|
|
145
|
+
const val = import.meta.env.VITE_PARENT_ORIGIN;
|
|
146
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
if (typeof process !== "undefined" && process.env?.VITE_PARENT_ORIGIN) {
|
|
152
|
+
const val = process.env.VITE_PARENT_ORIGIN;
|
|
153
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
function resolveEnvApiUrl() {
|
|
160
|
+
try {
|
|
161
|
+
if (typeof import.meta !== "undefined" && import.meta.env) {
|
|
162
|
+
const val = import.meta.env.VITE_API_URL ?? import.meta.env.VITE_LOOPLAY_API_URL;
|
|
163
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
164
|
+
}
|
|
165
|
+
} catch {
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
if (typeof process !== "undefined" && process.env) {
|
|
169
|
+
const val = process.env.VITE_API_URL ?? process.env.VITE_LOOPLAY_API_URL;
|
|
170
|
+
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
171
|
+
}
|
|
172
|
+
} catch {
|
|
173
|
+
}
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
140
177
|
// src/version.ts
|
|
141
|
-
var LOOPLAY_SDK_VERSION = "0.8.
|
|
178
|
+
var LOOPLAY_SDK_VERSION = "0.8.10";
|
|
142
179
|
|
|
143
180
|
// src/apps/http.ts
|
|
144
181
|
function getFetchFn(fetchOverride) {
|
|
@@ -164,8 +201,9 @@ var HttpClient = class {
|
|
|
164
201
|
baseUrl;
|
|
165
202
|
fetchFn;
|
|
166
203
|
defaultHeaders;
|
|
167
|
-
constructor(options) {
|
|
168
|
-
|
|
204
|
+
constructor(options = {}) {
|
|
205
|
+
const rawBaseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
206
|
+
this.baseUrl = rawBaseUrl.replace(/\/$/, "");
|
|
169
207
|
this.fetchFn = getFetchFn(options.fetch);
|
|
170
208
|
this.defaultHeaders = {
|
|
171
209
|
"x-looplay-sdk-version": LOOPLAY_SDK_VERSION,
|
|
@@ -461,10 +499,11 @@ var ApiClient = class {
|
|
|
461
499
|
playSession;
|
|
462
500
|
playSessionPromiseKey;
|
|
463
501
|
playSessionPromise;
|
|
464
|
-
constructor(options) {
|
|
465
|
-
|
|
502
|
+
constructor(options = {}) {
|
|
503
|
+
const baseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
504
|
+
if (!baseUrl) throw new MissingBaseUrlError();
|
|
466
505
|
this.raw = new ServiceClient({
|
|
467
|
-
baseUrl
|
|
506
|
+
baseUrl,
|
|
468
507
|
fetch: options.fetch,
|
|
469
508
|
defaultHeaders: options.defaultHeaders
|
|
470
509
|
});
|
|
@@ -682,43 +721,6 @@ var ApiClient = class {
|
|
|
682
721
|
}
|
|
683
722
|
};
|
|
684
723
|
|
|
685
|
-
// src/constants.ts
|
|
686
|
-
var DEFAULT_API_URL = "https://miniapp-api.looplay.gg";
|
|
687
|
-
function resolveEnvParentOrigin() {
|
|
688
|
-
try {
|
|
689
|
-
if (typeof import.meta !== "undefined" && import.meta.env?.VITE_PARENT_ORIGIN) {
|
|
690
|
-
const val = import.meta.env.VITE_PARENT_ORIGIN;
|
|
691
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
692
|
-
}
|
|
693
|
-
} catch {
|
|
694
|
-
}
|
|
695
|
-
try {
|
|
696
|
-
if (typeof process !== "undefined" && process.env?.VITE_PARENT_ORIGIN) {
|
|
697
|
-
const val = process.env.VITE_PARENT_ORIGIN;
|
|
698
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
699
|
-
}
|
|
700
|
-
} catch {
|
|
701
|
-
}
|
|
702
|
-
return void 0;
|
|
703
|
-
}
|
|
704
|
-
function resolveEnvApiUrl() {
|
|
705
|
-
try {
|
|
706
|
-
if (typeof import.meta !== "undefined" && import.meta.env) {
|
|
707
|
-
const val = import.meta.env.VITE_API_URL ?? import.meta.env.VITE_LOOPLAY_API_URL;
|
|
708
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
709
|
-
}
|
|
710
|
-
} catch {
|
|
711
|
-
}
|
|
712
|
-
try {
|
|
713
|
-
if (typeof process !== "undefined" && process.env) {
|
|
714
|
-
const val = process.env.VITE_API_URL ?? process.env.VITE_LOOPLAY_API_URL;
|
|
715
|
-
if (typeof val === "string" && val.trim().length > 0) return val.trim();
|
|
716
|
-
}
|
|
717
|
-
} catch {
|
|
718
|
-
}
|
|
719
|
-
return void 0;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
724
|
// src/looplay-sdk.ts
|
|
723
725
|
var LooplaySDK = class {
|
|
724
726
|
auth;
|
|
@@ -728,21 +730,19 @@ var LooplaySDK = class {
|
|
|
728
730
|
constructor(options = {}) {
|
|
729
731
|
const {
|
|
730
732
|
auth,
|
|
731
|
-
baseUrl = resolveEnvApiUrl() ?? DEFAULT_API_URL,
|
|
732
733
|
fetch,
|
|
733
734
|
defaultHeaders
|
|
734
735
|
} = options;
|
|
736
|
+
const baseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
735
737
|
if (auth) {
|
|
736
738
|
this.auth = new LooplayAuth(auth);
|
|
737
739
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
});
|
|
745
|
-
}
|
|
740
|
+
this.api = new ApiClient({
|
|
741
|
+
baseUrl,
|
|
742
|
+
fetch,
|
|
743
|
+
defaultHeaders,
|
|
744
|
+
getAccessToken: async () => this.auth?.getAccessToken()
|
|
745
|
+
});
|
|
746
746
|
}
|
|
747
747
|
async init(params) {
|
|
748
748
|
this.gameId = params.gameId;
|
|
@@ -1004,7 +1004,8 @@ var LooplayIframeAuth = class {
|
|
|
1004
1004
|
return this.state.jwt;
|
|
1005
1005
|
}
|
|
1006
1006
|
getApiUrl() {
|
|
1007
|
-
|
|
1007
|
+
const raw = toOptionalString(this.state.apiUrl) ?? toOptionalString(this.options.apiUrl) ?? resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
1008
|
+
return raw.trim();
|
|
1008
1009
|
}
|
|
1009
1010
|
/** Resolves to the configured `appId`, falling back to whatever the parent pushed as `gameId`. */
|
|
1010
1011
|
getGameId() {
|
|
@@ -1379,7 +1380,10 @@ ${gameId}`;
|
|
|
1379
1380
|
}
|
|
1380
1381
|
}
|
|
1381
1382
|
resolveParentOrigin() {
|
|
1382
|
-
if (this.options.parentOrigin)
|
|
1383
|
+
if (this.options.parentOrigin) {
|
|
1384
|
+
const opt = toOptionalString(this.options.parentOrigin);
|
|
1385
|
+
if (opt) return opt;
|
|
1386
|
+
}
|
|
1383
1387
|
const envOrigin = resolveEnvParentOrigin();
|
|
1384
1388
|
if (envOrigin) return envOrigin;
|
|
1385
1389
|
if (typeof document === "undefined" || !document.referrer) return null;
|