glitch-javascript-sdk 3.9.0 → 3.9.1
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/browser/hosting-runtime.js +5851 -0
- package/dist/browser/hosting-runtime.js.map +1 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/Hosting.d.ts +5 -0
- package/dist/esm/hosting-runtime.d.ts +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
- package/src/api/Hosting.ts +11 -0
- package/src/hosting-runtime.ts +44 -0
- package/src/routes/HostingRoute.ts +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -11525,6 +11525,7 @@ declare class GameAdvertising {
|
|
|
11525
11525
|
static adminUpsertProviderApp<T>(data: GameAdProviderApp): AxiosPromise<Response<T>>;
|
|
11526
11526
|
}
|
|
11527
11527
|
|
|
11528
|
+
type HostingPlanKey = 'free' | 'launch' | 'growth' | 'scale' | 'studio';
|
|
11528
11529
|
type HostingMode = 'static' | 'server';
|
|
11529
11530
|
type HostingDatabaseEngine = 'postgresql' | 'mysql' | 'azure_sql' | 'cosmos_nosql';
|
|
11530
11531
|
type HostingDatabasePlan = 'sandbox' | 'launch' | 'growth' | 'scale' | 'dedicated';
|
|
@@ -11557,6 +11558,10 @@ declare class Hosting {
|
|
|
11557
11558
|
static catalog<T>(): AxiosPromise<Response<T>>;
|
|
11558
11559
|
static dashboard<T>(title_id: string): AxiosPromise<Response<T>>;
|
|
11559
11560
|
static channelAnalytics<T>(title_id: string, params?: Record<string, any>): AxiosPromise<Response<T>>;
|
|
11561
|
+
/** Start or apply a bandwidth-based Hosting plan, separate from Store distribution. */
|
|
11562
|
+
static billingCheckout<T>(title_id: string, plan: HostingPlanKey): AxiosPromise<Response<T>>;
|
|
11563
|
+
/** Confirm a paid Stripe Checkout session before provisioning its Azure resource. */
|
|
11564
|
+
static confirmBillingCheckout<T>(title_id: string, checkout_session_id: string): AxiosPromise<Response<T>>;
|
|
11560
11565
|
static createSite<T>(title_id: string, data: CreateHostingSiteRequest): AxiosPromise<Response<T>>;
|
|
11561
11566
|
static updateSite<T>(title_id: string, site_id: string, data: Partial<CreateHostingSiteRequest> & Record<string, any>): AxiosPromise<Response<T>>;
|
|
11562
11567
|
static createUploadUrl<T>(title_id: string, site_id: string): AxiosPromise<Response<T>>;
|
package/package.json
CHANGED
package/src/api/Hosting.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface HostingAccount {
|
|
|
14
14
|
id: string;
|
|
15
15
|
community_id: string;
|
|
16
16
|
plan: HostingPlanKey;
|
|
17
|
+
pending_plan?: HostingPlanKey | null;
|
|
17
18
|
status: string;
|
|
18
19
|
included_bandwidth_bytes: number;
|
|
19
20
|
used_bandwidth_bytes: number;
|
|
@@ -129,6 +130,16 @@ class Hosting {
|
|
|
129
130
|
return Requests.processRoute(HostingRoute.routes.channelAnalytics, undefined, { title_id }, params);
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
/** Start or apply a bandwidth-based Hosting plan, separate from Store distribution. */
|
|
134
|
+
public static billingCheckout<T>(title_id: string, plan: HostingPlanKey): AxiosPromise<Response<T>> {
|
|
135
|
+
return Requests.processRoute(HostingRoute.routes.billingCheckout, { plan }, { title_id });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Confirm a paid Stripe Checkout session before provisioning its Azure resource. */
|
|
139
|
+
public static confirmBillingCheckout<T>(title_id: string, checkout_session_id: string): AxiosPromise<Response<T>> {
|
|
140
|
+
return Requests.processRoute(HostingRoute.routes.confirmBillingCheckout, { checkout_session_id }, { title_id });
|
|
141
|
+
}
|
|
142
|
+
|
|
132
143
|
public static createSite<T>(title_id: string, data: CreateHostingSiteRequest): AxiosPromise<Response<T>> {
|
|
133
144
|
return Requests.processRoute(HostingRoute.routes.createSite, data, { title_id });
|
|
134
145
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Hosting from './api/Hosting';
|
|
2
|
+
import Config from './config/Config';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
GlitchHosting?: {
|
|
7
|
+
ready: Promise<Record<string, any>>;
|
|
8
|
+
session?: Record<string, any>;
|
|
9
|
+
getContext: () => Record<string, any> | null;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const script = document.currentScript as HTMLScriptElement | null;
|
|
15
|
+
const siteId = script?.dataset.glitchHostingSite || '';
|
|
16
|
+
const releaseId = script?.dataset.glitchHostingRelease || '';
|
|
17
|
+
const apiBase = script?.dataset.glitchApiBase || 'https://api.glitch.fun/api';
|
|
18
|
+
Config.setConfig(apiBase, '');
|
|
19
|
+
|
|
20
|
+
const ready = Hosting.startPlaySession<Record<string, any>>({
|
|
21
|
+
hostname: window.location.hostname,
|
|
22
|
+
hosting_site_id: siteId || undefined,
|
|
23
|
+
hosting_release_id: releaseId || undefined,
|
|
24
|
+
surface: 'gameplay',
|
|
25
|
+
}).then((response) => {
|
|
26
|
+
const session = (response as any)?.data?.data || (response as any)?.data || response;
|
|
27
|
+
if (window.GlitchHosting) window.GlitchHosting.session = session;
|
|
28
|
+
window.dispatchEvent(new CustomEvent('glitch:hosting-ready', { detail: session }));
|
|
29
|
+
const heartbeat = () => Hosting.heartbeatPlaySession(session.session_id, session.session_token).catch(() => undefined);
|
|
30
|
+
const interval = window.setInterval(heartbeat, 60_000);
|
|
31
|
+
window.addEventListener('pagehide', () => window.clearInterval(interval), { once: true });
|
|
32
|
+
|
|
33
|
+
return session;
|
|
34
|
+
}).catch((error) => {
|
|
35
|
+
window.dispatchEvent(new CustomEvent('glitch:hosting-error', { detail: { message: error?.message || 'Hosting analytics could not start.' } }));
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
window.GlitchHosting = {
|
|
40
|
+
ready,
|
|
41
|
+
getContext: () => window.GlitchHosting?.session || null,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export {};
|
|
@@ -7,6 +7,8 @@ class HostingRoute {
|
|
|
7
7
|
catalog: { url: '/hosting/catalog', method: HTTP_METHODS.GET },
|
|
8
8
|
dashboard: { url: '/titles/{title_id}/hosting', method: HTTP_METHODS.GET },
|
|
9
9
|
channelAnalytics: { url: '/titles/{title_id}/hosting/analytics/channels', method: HTTP_METHODS.GET },
|
|
10
|
+
billingCheckout: { url: '/titles/{title_id}/hosting/billing/checkout', method: HTTP_METHODS.POST },
|
|
11
|
+
confirmBillingCheckout: { url: '/titles/{title_id}/hosting/billing/confirm', method: HTTP_METHODS.POST },
|
|
10
12
|
createSite: { url: '/titles/{title_id}/hosting/sites', method: HTTP_METHODS.POST },
|
|
11
13
|
updateSite: { url: '/titles/{title_id}/hosting/sites/{site_id}', method: HTTP_METHODS.PUT },
|
|
12
14
|
uploadUrl: { url: '/titles/{title_id}/hosting/sites/{site_id}/upload-url', method: HTTP_METHODS.POST },
|