@looplay/sdk 0.8.8 → 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/README.md +10 -9
- package/dist/looplay-sdk.cjs.js +69 -17
- package/dist/looplay-sdk.cjs.js.map +1 -1
- package/dist/looplay-sdk.esm.js +66 -18
- package/dist/looplay-sdk.esm.js.map +1 -1
- package/dist/looplay-sdk.min.js +5 -5
- 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/constants.d.ts +20 -0
- package/dist/types/iframe/iframe-auth.d.ts +1 -1
- package/dist/types/iframe/types.d.ts +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- 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
|
});
|
|
@@ -689,18 +728,21 @@ var LooplaySDK = class {
|
|
|
689
728
|
gameId;
|
|
690
729
|
initialized = false;
|
|
691
730
|
constructor(options = {}) {
|
|
692
|
-
const {
|
|
731
|
+
const {
|
|
732
|
+
auth,
|
|
733
|
+
fetch,
|
|
734
|
+
defaultHeaders
|
|
735
|
+
} = options;
|
|
736
|
+
const baseUrl = typeof options.baseUrl === "string" && options.baseUrl.trim().length > 0 ? options.baseUrl.trim() : resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
693
737
|
if (auth) {
|
|
694
738
|
this.auth = new LooplayAuth(auth);
|
|
695
739
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
});
|
|
703
|
-
}
|
|
740
|
+
this.api = new ApiClient({
|
|
741
|
+
baseUrl,
|
|
742
|
+
fetch,
|
|
743
|
+
defaultHeaders,
|
|
744
|
+
getAccessToken: async () => this.auth?.getAccessToken()
|
|
745
|
+
});
|
|
704
746
|
}
|
|
705
747
|
async init(params) {
|
|
706
748
|
this.gameId = params.gameId;
|
|
@@ -962,7 +1004,8 @@ var LooplayIframeAuth = class {
|
|
|
962
1004
|
return this.state.jwt;
|
|
963
1005
|
}
|
|
964
1006
|
getApiUrl() {
|
|
965
|
-
|
|
1007
|
+
const raw = toOptionalString(this.state.apiUrl) ?? toOptionalString(this.options.apiUrl) ?? resolveEnvApiUrl() ?? DEFAULT_API_URL;
|
|
1008
|
+
return raw.trim();
|
|
966
1009
|
}
|
|
967
1010
|
/** Resolves to the configured `appId`, falling back to whatever the parent pushed as `gameId`. */
|
|
968
1011
|
getGameId() {
|
|
@@ -1337,7 +1380,12 @@ ${gameId}`;
|
|
|
1337
1380
|
}
|
|
1338
1381
|
}
|
|
1339
1382
|
resolveParentOrigin() {
|
|
1340
|
-
if (this.options.parentOrigin)
|
|
1383
|
+
if (this.options.parentOrigin) {
|
|
1384
|
+
const opt = toOptionalString(this.options.parentOrigin);
|
|
1385
|
+
if (opt) return opt;
|
|
1386
|
+
}
|
|
1387
|
+
const envOrigin = resolveEnvParentOrigin();
|
|
1388
|
+
if (envOrigin) return envOrigin;
|
|
1341
1389
|
if (typeof document === "undefined" || !document.referrer) return null;
|
|
1342
1390
|
try {
|
|
1343
1391
|
return new URL(document.referrer).origin;
|
|
@@ -1379,6 +1427,6 @@ ${gameId}`;
|
|
|
1379
1427
|
}
|
|
1380
1428
|
};
|
|
1381
1429
|
|
|
1382
|
-
export { ApiClient, BrowserLocalStorageAuthStorage, HttpClient, HttpError, LOOPLAY_SDK_VERSION, LooplayAuth, LooplayIframeAuth, LooplaySDK, LooplaySDKError, MemoryAuthStorage, MissingAuthError, MissingBaseUrlError, NotAuthenticatedError, NotInitializedError, ServiceClient, TelegramAuthProvider };
|
|
1430
|
+
export { ApiClient, BrowserLocalStorageAuthStorage, DEFAULT_API_URL, HttpClient, HttpError, LOOPLAY_SDK_VERSION, LooplayAuth, LooplayIframeAuth, LooplaySDK, LooplaySDKError, MemoryAuthStorage, MissingAuthError, MissingBaseUrlError, NotAuthenticatedError, NotInitializedError, ServiceClient, TelegramAuthProvider, resolveEnvApiUrl, resolveEnvParentOrigin };
|
|
1383
1431
|
//# sourceMappingURL=looplay-sdk.esm.js.map
|
|
1384
1432
|
//# sourceMappingURL=looplay-sdk.esm.js.map
|