@playcademy/sdk 0.2.12 → 0.2.14
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/index.d.ts +65 -65
- package/dist/index.js +1 -1
- package/dist/internal.d.ts +77 -190
- package/dist/internal.js +1 -1
- package/dist/server.d.ts +16 -1
- package/dist/types.d.ts +78 -65
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -817,71 +817,6 @@ type InventoryItemWithItem = InventoryItemRow & {
|
|
|
817
817
|
item: ItemRow;
|
|
818
818
|
};
|
|
819
819
|
|
|
820
|
-
/**
|
|
821
|
-
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
822
|
-
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
823
|
-
*
|
|
824
|
-
* This is the recommended way to initialize the SDK as it automatically:
|
|
825
|
-
* - Detects the runtime environment (iframe vs standalone)
|
|
826
|
-
* - Configures the client with the appropriate context
|
|
827
|
-
* - Sets up event listeners for token refresh
|
|
828
|
-
* - Exposes the client for debugging in development mode
|
|
829
|
-
*
|
|
830
|
-
* @param options - Optional configuration overrides
|
|
831
|
-
* @param options.baseUrl - Override the base URL for API requests
|
|
832
|
-
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
833
|
-
* @throws Error if not running in a browser context
|
|
834
|
-
*
|
|
835
|
-
* @example
|
|
836
|
-
* ```typescript
|
|
837
|
-
* // Default initialization
|
|
838
|
-
* const client = await PlaycademyClient.init()
|
|
839
|
-
*
|
|
840
|
-
* // With custom base URL
|
|
841
|
-
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
842
|
-
* ```
|
|
843
|
-
*/
|
|
844
|
-
declare function init<T extends PlaycademyClient = PlaycademyClient>(this: new (...args: ConstructorParameters<typeof PlaycademyClient>) => T, options?: {
|
|
845
|
-
baseUrl?: string;
|
|
846
|
-
allowedParentOrigins?: string[];
|
|
847
|
-
onDisconnect?: DisconnectHandler;
|
|
848
|
-
enableConnectionMonitoring?: boolean;
|
|
849
|
-
}): Promise<T>;
|
|
850
|
-
|
|
851
|
-
/**
|
|
852
|
-
* Authenticates a user with email and password.
|
|
853
|
-
*
|
|
854
|
-
* This is a standalone authentication method that doesn't require an initialized client.
|
|
855
|
-
* Use this for login flows before creating a client instance.
|
|
856
|
-
*
|
|
857
|
-
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
858
|
-
*
|
|
859
|
-
* @param baseUrl - The base URL of the Playcademy API
|
|
860
|
-
* @param email - User's email address
|
|
861
|
-
* @param password - User's password
|
|
862
|
-
* @returns Promise resolving to authentication response with token
|
|
863
|
-
* @throws PlaycademyError if authentication fails or network error occurs
|
|
864
|
-
*
|
|
865
|
-
* @example
|
|
866
|
-
* ```typescript
|
|
867
|
-
* // Preferred approach:
|
|
868
|
-
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
869
|
-
* const result = await client.auth.login({
|
|
870
|
-
* email: 'user@example.com',
|
|
871
|
-
* password: 'password'
|
|
872
|
-
* })
|
|
873
|
-
*
|
|
874
|
-
* // Legacy approach (still works):
|
|
875
|
-
* try {
|
|
876
|
-
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
877
|
-
* const client = new PlaycademyClient({ token: response.token })
|
|
878
|
-
* } catch (error) {
|
|
879
|
-
* console.error('Login failed:', error.message)
|
|
880
|
-
* }
|
|
881
|
-
* ```
|
|
882
|
-
*/
|
|
883
|
-
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
884
|
-
|
|
885
820
|
/**
|
|
886
821
|
* @fileoverview Authentication Strategy Pattern
|
|
887
822
|
*
|
|
@@ -1038,6 +973,71 @@ declare abstract class PlaycademyBaseClient {
|
|
|
1038
973
|
};
|
|
1039
974
|
}
|
|
1040
975
|
|
|
976
|
+
/**
|
|
977
|
+
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
978
|
+
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
979
|
+
*
|
|
980
|
+
* This is the recommended way to initialize the SDK as it automatically:
|
|
981
|
+
* - Detects the runtime environment (iframe vs standalone)
|
|
982
|
+
* - Configures the client with the appropriate context
|
|
983
|
+
* - Sets up event listeners for token refresh
|
|
984
|
+
* - Exposes the client for debugging in development mode
|
|
985
|
+
*
|
|
986
|
+
* @param options - Optional configuration overrides
|
|
987
|
+
* @param options.baseUrl - Override the base URL for API requests
|
|
988
|
+
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
989
|
+
* @throws Error if not running in a browser context
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```typescript
|
|
993
|
+
* // Default initialization
|
|
994
|
+
* const client = await PlaycademyClient.init()
|
|
995
|
+
*
|
|
996
|
+
* // With custom base URL
|
|
997
|
+
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
998
|
+
* ```
|
|
999
|
+
*/
|
|
1000
|
+
declare function init<T extends PlaycademyBaseClient = PlaycademyBaseClient>(this: new (config?: Partial<ClientConfig>) => T, options?: {
|
|
1001
|
+
baseUrl?: string;
|
|
1002
|
+
allowedParentOrigins?: string[];
|
|
1003
|
+
onDisconnect?: DisconnectHandler;
|
|
1004
|
+
enableConnectionMonitoring?: boolean;
|
|
1005
|
+
}): Promise<T>;
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* Authenticates a user with email and password.
|
|
1009
|
+
*
|
|
1010
|
+
* This is a standalone authentication method that doesn't require an initialized client.
|
|
1011
|
+
* Use this for login flows before creating a client instance.
|
|
1012
|
+
*
|
|
1013
|
+
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
1014
|
+
*
|
|
1015
|
+
* @param baseUrl - The base URL of the Playcademy API
|
|
1016
|
+
* @param email - User's email address
|
|
1017
|
+
* @param password - User's password
|
|
1018
|
+
* @returns Promise resolving to authentication response with token
|
|
1019
|
+
* @throws PlaycademyError if authentication fails or network error occurs
|
|
1020
|
+
*
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```typescript
|
|
1023
|
+
* // Preferred approach:
|
|
1024
|
+
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
1025
|
+
* const result = await client.auth.login({
|
|
1026
|
+
* email: 'user@example.com',
|
|
1027
|
+
* password: 'password'
|
|
1028
|
+
* })
|
|
1029
|
+
*
|
|
1030
|
+
* // Legacy approach (still works):
|
|
1031
|
+
* try {
|
|
1032
|
+
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
1033
|
+
* const client = new PlaycademyClient({ token: response.token })
|
|
1034
|
+
* } catch (error) {
|
|
1035
|
+
* console.error('Login failed:', error.message)
|
|
1036
|
+
* }
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
1040
|
+
|
|
1041
1041
|
/**
|
|
1042
1042
|
* Playcademy SDK client for game developers.
|
|
1043
1043
|
* Provides namespaced access to platform features for games running inside Cademy.
|
package/dist/index.js
CHANGED
|
@@ -1477,7 +1477,7 @@ function createTimebackNamespace(client) {
|
|
|
1477
1477
|
const cacheKey = [
|
|
1478
1478
|
options?.grade ?? "",
|
|
1479
1479
|
options?.subject ?? "",
|
|
1480
|
-
options?.include?.
|
|
1480
|
+
options?.include?.toSorted().join(",") ?? ""
|
|
1481
1481
|
].join(":");
|
|
1482
1482
|
return xpCache.get(cacheKey, async () => {
|
|
1483
1483
|
const params = new URLSearchParams;
|
package/dist/internal.d.ts
CHANGED
|
@@ -5619,71 +5619,6 @@ declare class PlaycademyMessaging {
|
|
|
5619
5619
|
*/
|
|
5620
5620
|
declare const messaging: PlaycademyMessaging;
|
|
5621
5621
|
|
|
5622
|
-
/**
|
|
5623
|
-
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
5624
|
-
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
5625
|
-
*
|
|
5626
|
-
* This is the recommended way to initialize the SDK as it automatically:
|
|
5627
|
-
* - Detects the runtime environment (iframe vs standalone)
|
|
5628
|
-
* - Configures the client with the appropriate context
|
|
5629
|
-
* - Sets up event listeners for token refresh
|
|
5630
|
-
* - Exposes the client for debugging in development mode
|
|
5631
|
-
*
|
|
5632
|
-
* @param options - Optional configuration overrides
|
|
5633
|
-
* @param options.baseUrl - Override the base URL for API requests
|
|
5634
|
-
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
5635
|
-
* @throws Error if not running in a browser context
|
|
5636
|
-
*
|
|
5637
|
-
* @example
|
|
5638
|
-
* ```typescript
|
|
5639
|
-
* // Default initialization
|
|
5640
|
-
* const client = await PlaycademyClient.init()
|
|
5641
|
-
*
|
|
5642
|
-
* // With custom base URL
|
|
5643
|
-
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
5644
|
-
* ```
|
|
5645
|
-
*/
|
|
5646
|
-
declare function init<T extends PlaycademyClient = PlaycademyClient>(this: new (...args: ConstructorParameters<typeof PlaycademyClient>) => T, options?: {
|
|
5647
|
-
baseUrl?: string;
|
|
5648
|
-
allowedParentOrigins?: string[];
|
|
5649
|
-
onDisconnect?: DisconnectHandler;
|
|
5650
|
-
enableConnectionMonitoring?: boolean;
|
|
5651
|
-
}): Promise<T>;
|
|
5652
|
-
|
|
5653
|
-
/**
|
|
5654
|
-
* Authenticates a user with email and password.
|
|
5655
|
-
*
|
|
5656
|
-
* This is a standalone authentication method that doesn't require an initialized client.
|
|
5657
|
-
* Use this for login flows before creating a client instance.
|
|
5658
|
-
*
|
|
5659
|
-
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
5660
|
-
*
|
|
5661
|
-
* @param baseUrl - The base URL of the Playcademy API
|
|
5662
|
-
* @param email - User's email address
|
|
5663
|
-
* @param password - User's password
|
|
5664
|
-
* @returns Promise resolving to authentication response with token
|
|
5665
|
-
* @throws PlaycademyError if authentication fails or network error occurs
|
|
5666
|
-
*
|
|
5667
|
-
* @example
|
|
5668
|
-
* ```typescript
|
|
5669
|
-
* // Preferred approach:
|
|
5670
|
-
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
5671
|
-
* const result = await client.auth.login({
|
|
5672
|
-
* email: 'user@example.com',
|
|
5673
|
-
* password: 'password'
|
|
5674
|
-
* })
|
|
5675
|
-
*
|
|
5676
|
-
* // Legacy approach (still works):
|
|
5677
|
-
* try {
|
|
5678
|
-
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
5679
|
-
* const client = new PlaycademyClient({ token: response.token })
|
|
5680
|
-
* } catch (error) {
|
|
5681
|
-
* console.error('Login failed:', error.message)
|
|
5682
|
-
* }
|
|
5683
|
-
* ```
|
|
5684
|
-
*/
|
|
5685
|
-
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
5686
|
-
|
|
5687
5622
|
/**
|
|
5688
5623
|
* @fileoverview Authentication Strategy Pattern
|
|
5689
5624
|
*
|
|
@@ -5841,132 +5776,69 @@ declare abstract class PlaycademyBaseClient {
|
|
|
5841
5776
|
}
|
|
5842
5777
|
|
|
5843
5778
|
/**
|
|
5844
|
-
*
|
|
5845
|
-
*
|
|
5779
|
+
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
5780
|
+
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
5781
|
+
*
|
|
5782
|
+
* This is the recommended way to initialize the SDK as it automatically:
|
|
5783
|
+
* - Detects the runtime environment (iframe vs standalone)
|
|
5784
|
+
* - Configures the client with the appropriate context
|
|
5785
|
+
* - Sets up event listeners for token refresh
|
|
5786
|
+
* - Exposes the client for debugging in development mode
|
|
5787
|
+
*
|
|
5788
|
+
* @param options - Optional configuration overrides
|
|
5789
|
+
* @param options.baseUrl - Override the base URL for API requests
|
|
5790
|
+
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
5791
|
+
* @throws Error if not running in a browser context
|
|
5792
|
+
*
|
|
5793
|
+
* @example
|
|
5794
|
+
* ```typescript
|
|
5795
|
+
* // Default initialization
|
|
5796
|
+
* const client = await PlaycademyClient.init()
|
|
5797
|
+
*
|
|
5798
|
+
* // With custom base URL
|
|
5799
|
+
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
5800
|
+
* ```
|
|
5846
5801
|
*/
|
|
5847
|
-
declare
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
}) => void) | (() => void) | ((isVisible: boolean) => void)) => void;
|
|
5888
|
-
removeAllListeners: () => void;
|
|
5889
|
-
getListenerCounts: () => Record<string, number>;
|
|
5890
|
-
assets: {
|
|
5891
|
-
url(pathOrStrings: string | TemplateStringsArray, ...values: unknown[]): string;
|
|
5892
|
-
fetch: (path: string, options?: RequestInit) => Promise<Response>;
|
|
5893
|
-
json: <T = unknown>(path: string) => Promise<T>;
|
|
5894
|
-
blob: (path: string) => Promise<Blob>;
|
|
5895
|
-
text: (path: string) => Promise<string>;
|
|
5896
|
-
arrayBuffer: (path: string) => Promise<ArrayBuffer>;
|
|
5897
|
-
};
|
|
5898
|
-
};
|
|
5899
|
-
/**
|
|
5900
|
-
* TimeBack integration for activity tracking and user context.
|
|
5901
|
-
*
|
|
5902
|
-
* User context (cached from init, refreshable):
|
|
5903
|
-
* - `user.role` - User's role (student, parent, teacher, etc.)
|
|
5904
|
-
* - `user.enrollments` - Courses the player is enrolled in for this game
|
|
5905
|
-
* - `user.organizations` - Schools/districts the player belongs to
|
|
5906
|
-
* - `user.fetch()` - Refresh user context from server
|
|
5907
|
-
*
|
|
5908
|
-
* Activity tracking:
|
|
5909
|
-
* - `startActivity(metadata)` - Begin tracking an activity
|
|
5910
|
-
* - `pauseActivity()` / `resumeActivity()` - Pause/resume timer
|
|
5911
|
-
* - `endActivity(scoreData)` - Submit activity results to TimeBack
|
|
5912
|
-
*/
|
|
5913
|
-
timeback: {
|
|
5914
|
-
readonly user: TimebackUser;
|
|
5915
|
-
startActivity: (metadata: ActivityData) => void;
|
|
5916
|
-
pauseActivity: () => void;
|
|
5917
|
-
resumeActivity: () => void;
|
|
5918
|
-
endActivity: (data: EndActivityScoreData) => Promise<EndActivityResponse>;
|
|
5919
|
-
};
|
|
5920
|
-
/**
|
|
5921
|
-
* Playcademy Credits (platform currency) management.
|
|
5922
|
-
* - `get()` - Get user's credit balance
|
|
5923
|
-
* - `add(amount)` - Award credits to user
|
|
5924
|
-
*/
|
|
5925
|
-
credits: {
|
|
5926
|
-
balance: () => Promise<number>;
|
|
5927
|
-
add: (amount: number) => Promise<number>;
|
|
5928
|
-
spend: (amount: number) => Promise<number>;
|
|
5929
|
-
};
|
|
5930
|
-
/**
|
|
5931
|
-
* Game score submission and leaderboards.
|
|
5932
|
-
* - `submit(gameId, score, metadata?)` - Record a game score
|
|
5933
|
-
*/
|
|
5934
|
-
scores: {
|
|
5935
|
-
submit: (gameId: string, score: number, metadata?: Record<string, unknown>) => Promise<ScoreSubmission>;
|
|
5936
|
-
};
|
|
5937
|
-
/**
|
|
5938
|
-
* Realtime multiplayer authentication.
|
|
5939
|
-
* - `getToken()` - Get token for WebSocket/realtime connections
|
|
5940
|
-
*/
|
|
5941
|
-
realtime: {
|
|
5942
|
-
token: {
|
|
5943
|
-
get: () => Promise<RealtimeTokenResponse>;
|
|
5944
|
-
};
|
|
5945
|
-
};
|
|
5946
|
-
/**
|
|
5947
|
-
* Make requests to your game's custom backend API routes.
|
|
5948
|
-
* - `get(path)`, `post(path, body)`, `put()`, `delete()` - HTTP methods
|
|
5949
|
-
* - Routes are relative to your game's deployment (e.g., '/hello' → your-game.playcademy.gg/api/hello)
|
|
5950
|
-
*/
|
|
5951
|
-
backend: {
|
|
5952
|
-
get<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
|
|
5953
|
-
post<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
5954
|
-
put<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
5955
|
-
patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
5956
|
-
delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
|
|
5957
|
-
request<T = unknown>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
|
|
5958
|
-
download(path: string, method?: Method, body?: unknown, headers?: Record<string, string>): Promise<Response>;
|
|
5959
|
-
url(pathOrStrings: string | TemplateStringsArray, ...values: unknown[]): string;
|
|
5960
|
-
};
|
|
5961
|
-
/** Auto-initializes a PlaycademyClient with context from the environment */
|
|
5962
|
-
static init: typeof init;
|
|
5963
|
-
/** Authenticates a user with email and password */
|
|
5964
|
-
static login: typeof login;
|
|
5965
|
-
/** Static identity utilities for OAuth operations */
|
|
5966
|
-
static identity: {
|
|
5967
|
-
parseOAuthState: typeof parseOAuthState;
|
|
5968
|
-
};
|
|
5969
|
-
}
|
|
5802
|
+
declare function init<T extends PlaycademyBaseClient = PlaycademyBaseClient>(this: new (config?: Partial<ClientConfig>) => T, options?: {
|
|
5803
|
+
baseUrl?: string;
|
|
5804
|
+
allowedParentOrigins?: string[];
|
|
5805
|
+
onDisconnect?: DisconnectHandler;
|
|
5806
|
+
enableConnectionMonitoring?: boolean;
|
|
5807
|
+
}): Promise<T>;
|
|
5808
|
+
|
|
5809
|
+
/**
|
|
5810
|
+
* Authenticates a user with email and password.
|
|
5811
|
+
*
|
|
5812
|
+
* This is a standalone authentication method that doesn't require an initialized client.
|
|
5813
|
+
* Use this for login flows before creating a client instance.
|
|
5814
|
+
*
|
|
5815
|
+
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
5816
|
+
*
|
|
5817
|
+
* @param baseUrl - The base URL of the Playcademy API
|
|
5818
|
+
* @param email - User's email address
|
|
5819
|
+
* @param password - User's password
|
|
5820
|
+
* @returns Promise resolving to authentication response with token
|
|
5821
|
+
* @throws PlaycademyError if authentication fails or network error occurs
|
|
5822
|
+
*
|
|
5823
|
+
* @example
|
|
5824
|
+
* ```typescript
|
|
5825
|
+
* // Preferred approach:
|
|
5826
|
+
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
5827
|
+
* const result = await client.auth.login({
|
|
5828
|
+
* email: 'user@example.com',
|
|
5829
|
+
* password: 'password'
|
|
5830
|
+
* })
|
|
5831
|
+
*
|
|
5832
|
+
* // Legacy approach (still works):
|
|
5833
|
+
* try {
|
|
5834
|
+
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
5835
|
+
* const client = new PlaycademyClient({ token: response.token })
|
|
5836
|
+
* } catch (error) {
|
|
5837
|
+
* console.error('Login failed:', error.message)
|
|
5838
|
+
* }
|
|
5839
|
+
* ```
|
|
5840
|
+
*/
|
|
5841
|
+
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
5970
5842
|
|
|
5971
5843
|
/**
|
|
5972
5844
|
* Type definitions for the game timeback namespace.
|
|
@@ -6625,6 +6497,17 @@ interface CustomRoutesIntegration {
|
|
|
6625
6497
|
interface DatabaseIntegration {
|
|
6626
6498
|
/** Database directory (defaults to 'db') */
|
|
6627
6499
|
directory?: string;
|
|
6500
|
+
/** Schema strategy: 'push' uses drizzle-kit push-style diffing, 'migrate' uses migration files.
|
|
6501
|
+
* When omitted, auto-detects based on presence of a migrations directory with _journal.json. */
|
|
6502
|
+
strategy?: 'push' | 'migrate';
|
|
6503
|
+
}
|
|
6504
|
+
interface QueueConfig {
|
|
6505
|
+
maxBatchSize?: number;
|
|
6506
|
+
maxRetries?: number;
|
|
6507
|
+
maxBatchTimeout?: number;
|
|
6508
|
+
maxConcurrency?: number;
|
|
6509
|
+
retryDelay?: number;
|
|
6510
|
+
deadLetterQueue?: string;
|
|
6628
6511
|
}
|
|
6629
6512
|
/**
|
|
6630
6513
|
* Integrations configuration
|
|
@@ -6643,6 +6526,8 @@ interface IntegrationsConfig {
|
|
|
6643
6526
|
bucket?: boolean;
|
|
6644
6527
|
/** Authentication (optional) */
|
|
6645
6528
|
auth?: boolean;
|
|
6529
|
+
/** Queues (optional) */
|
|
6530
|
+
queues?: Record<string, QueueConfig | boolean>;
|
|
6646
6531
|
}
|
|
6647
6532
|
/**
|
|
6648
6533
|
* Unified Playcademy configuration
|
|
@@ -6749,6 +6634,8 @@ interface BackendResourceBindings {
|
|
|
6749
6634
|
keyValue?: string[];
|
|
6750
6635
|
/** Object storage buckets to bind (maps to R2 on Cloudflare) */
|
|
6751
6636
|
bucket?: string[];
|
|
6637
|
+
/** Queue bindings to create and bind */
|
|
6638
|
+
queues?: Record<string, QueueConfig | boolean>;
|
|
6752
6639
|
}
|
|
6753
6640
|
/**
|
|
6754
6641
|
* Backend deployment bundle for uploading to Playcademy platform
|
package/dist/internal.js
CHANGED
|
@@ -1477,7 +1477,7 @@ function createTimebackNamespace(client) {
|
|
|
1477
1477
|
const cacheKey = [
|
|
1478
1478
|
options?.grade ?? "",
|
|
1479
1479
|
options?.subject ?? "",
|
|
1480
|
-
options?.include?.
|
|
1480
|
+
options?.include?.toSorted().join(",") ?? ""
|
|
1481
1481
|
].join(":");
|
|
1482
1482
|
return xpCache.get(cacheKey, async () => {
|
|
1483
1483
|
const params = new URLSearchParams;
|
package/dist/server.d.ts
CHANGED
|
@@ -382,6 +382,17 @@ interface CustomRoutesIntegration {
|
|
|
382
382
|
interface DatabaseIntegration {
|
|
383
383
|
/** Database directory (defaults to 'db') */
|
|
384
384
|
directory?: string;
|
|
385
|
+
/** Schema strategy: 'push' uses drizzle-kit push-style diffing, 'migrate' uses migration files.
|
|
386
|
+
* When omitted, auto-detects based on presence of a migrations directory with _journal.json. */
|
|
387
|
+
strategy?: 'push' | 'migrate';
|
|
388
|
+
}
|
|
389
|
+
interface QueueConfig {
|
|
390
|
+
maxBatchSize?: number;
|
|
391
|
+
maxRetries?: number;
|
|
392
|
+
maxBatchTimeout?: number;
|
|
393
|
+
maxConcurrency?: number;
|
|
394
|
+
retryDelay?: number;
|
|
395
|
+
deadLetterQueue?: string;
|
|
385
396
|
}
|
|
386
397
|
/**
|
|
387
398
|
* Integrations configuration
|
|
@@ -400,6 +411,8 @@ interface IntegrationsConfig {
|
|
|
400
411
|
bucket?: boolean;
|
|
401
412
|
/** Authentication (optional) */
|
|
402
413
|
auth?: boolean;
|
|
414
|
+
/** Queues (optional) */
|
|
415
|
+
queues?: Record<string, QueueConfig | boolean>;
|
|
403
416
|
}
|
|
404
417
|
/**
|
|
405
418
|
* Unified Playcademy configuration
|
|
@@ -506,6 +519,8 @@ interface BackendResourceBindings {
|
|
|
506
519
|
keyValue?: string[];
|
|
507
520
|
/** Object storage buckets to bind (maps to R2 on Cloudflare) */
|
|
508
521
|
bucket?: string[];
|
|
522
|
+
/** Queue bindings to create and bind */
|
|
523
|
+
queues?: Record<string, QueueConfig | boolean>;
|
|
509
524
|
}
|
|
510
525
|
/**
|
|
511
526
|
* Backend deployment bundle for uploading to Playcademy platform
|
|
@@ -712,4 +727,4 @@ declare function verifyGameToken(gameToken: string, options?: {
|
|
|
712
727
|
}): Promise<VerifyGameTokenResponse>;
|
|
713
728
|
|
|
714
729
|
export { PlaycademyClient, verifyGameToken };
|
|
715
|
-
export type { ActivityData, BackendDeploymentBundle, BackendResourceBindings, ComponentConfig, ComponentResourceConfig, EndActivityPayload, IntegrationsConfig, OrganizationConfig, PlaycademyConfig, PlaycademyServerClientConfig, PlaycademyServerClientState, ResourceConfig, TimebackBaseConfig, TimebackCourseConfigWithOverrides, TimebackGrade, TimebackIntegrationConfig, TimebackSubject, UserInfo };
|
|
730
|
+
export type { ActivityData, BackendDeploymentBundle, BackendResourceBindings, ComponentConfig, ComponentResourceConfig, EndActivityPayload, IntegrationsConfig, OrganizationConfig, PlaycademyConfig, PlaycademyServerClientConfig, PlaycademyServerClientState, QueueConfig, ResourceConfig, TimebackBaseConfig, TimebackCourseConfigWithOverrides, TimebackGrade, TimebackIntegrationConfig, TimebackSubject, UserInfo };
|
package/dist/types.d.ts
CHANGED
|
@@ -4674,71 +4674,6 @@ declare enum MessageEvents {
|
|
|
4674
4674
|
AUTH_CALLBACK = "PLAYCADEMY_AUTH_CALLBACK"
|
|
4675
4675
|
}
|
|
4676
4676
|
|
|
4677
|
-
/**
|
|
4678
|
-
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
4679
|
-
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
4680
|
-
*
|
|
4681
|
-
* This is the recommended way to initialize the SDK as it automatically:
|
|
4682
|
-
* - Detects the runtime environment (iframe vs standalone)
|
|
4683
|
-
* - Configures the client with the appropriate context
|
|
4684
|
-
* - Sets up event listeners for token refresh
|
|
4685
|
-
* - Exposes the client for debugging in development mode
|
|
4686
|
-
*
|
|
4687
|
-
* @param options - Optional configuration overrides
|
|
4688
|
-
* @param options.baseUrl - Override the base URL for API requests
|
|
4689
|
-
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
4690
|
-
* @throws Error if not running in a browser context
|
|
4691
|
-
*
|
|
4692
|
-
* @example
|
|
4693
|
-
* ```typescript
|
|
4694
|
-
* // Default initialization
|
|
4695
|
-
* const client = await PlaycademyClient.init()
|
|
4696
|
-
*
|
|
4697
|
-
* // With custom base URL
|
|
4698
|
-
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
4699
|
-
* ```
|
|
4700
|
-
*/
|
|
4701
|
-
declare function init<T extends PlaycademyClient = PlaycademyClient>(this: new (...args: ConstructorParameters<typeof PlaycademyClient>) => T, options?: {
|
|
4702
|
-
baseUrl?: string;
|
|
4703
|
-
allowedParentOrigins?: string[];
|
|
4704
|
-
onDisconnect?: DisconnectHandler;
|
|
4705
|
-
enableConnectionMonitoring?: boolean;
|
|
4706
|
-
}): Promise<T>;
|
|
4707
|
-
|
|
4708
|
-
/**
|
|
4709
|
-
* Authenticates a user with email and password.
|
|
4710
|
-
*
|
|
4711
|
-
* This is a standalone authentication method that doesn't require an initialized client.
|
|
4712
|
-
* Use this for login flows before creating a client instance.
|
|
4713
|
-
*
|
|
4714
|
-
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
4715
|
-
*
|
|
4716
|
-
* @param baseUrl - The base URL of the Playcademy API
|
|
4717
|
-
* @param email - User's email address
|
|
4718
|
-
* @param password - User's password
|
|
4719
|
-
* @returns Promise resolving to authentication response with token
|
|
4720
|
-
* @throws PlaycademyError if authentication fails or network error occurs
|
|
4721
|
-
*
|
|
4722
|
-
* @example
|
|
4723
|
-
* ```typescript
|
|
4724
|
-
* // Preferred approach:
|
|
4725
|
-
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
4726
|
-
* const result = await client.auth.login({
|
|
4727
|
-
* email: 'user@example.com',
|
|
4728
|
-
* password: 'password'
|
|
4729
|
-
* })
|
|
4730
|
-
*
|
|
4731
|
-
* // Legacy approach (still works):
|
|
4732
|
-
* try {
|
|
4733
|
-
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
4734
|
-
* const client = new PlaycademyClient({ token: response.token })
|
|
4735
|
-
* } catch (error) {
|
|
4736
|
-
* console.error('Login failed:', error.message)
|
|
4737
|
-
* }
|
|
4738
|
-
* ```
|
|
4739
|
-
*/
|
|
4740
|
-
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
4741
|
-
|
|
4742
4677
|
/**
|
|
4743
4678
|
* @fileoverview Authentication Strategy Pattern
|
|
4744
4679
|
*
|
|
@@ -4895,6 +4830,71 @@ declare abstract class PlaycademyBaseClient {
|
|
|
4895
4830
|
};
|
|
4896
4831
|
}
|
|
4897
4832
|
|
|
4833
|
+
/**
|
|
4834
|
+
* Auto-initializes a PlaycademyClient with context from the environment.
|
|
4835
|
+
* Works in both iframe mode (production/development) and standalone mode (local dev).
|
|
4836
|
+
*
|
|
4837
|
+
* This is the recommended way to initialize the SDK as it automatically:
|
|
4838
|
+
* - Detects the runtime environment (iframe vs standalone)
|
|
4839
|
+
* - Configures the client with the appropriate context
|
|
4840
|
+
* - Sets up event listeners for token refresh
|
|
4841
|
+
* - Exposes the client for debugging in development mode
|
|
4842
|
+
*
|
|
4843
|
+
* @param options - Optional configuration overrides
|
|
4844
|
+
* @param options.baseUrl - Override the base URL for API requests
|
|
4845
|
+
* @returns Promise resolving to a fully initialized PlaycademyClient
|
|
4846
|
+
* @throws Error if not running in a browser context
|
|
4847
|
+
*
|
|
4848
|
+
* @example
|
|
4849
|
+
* ```typescript
|
|
4850
|
+
* // Default initialization
|
|
4851
|
+
* const client = await PlaycademyClient.init()
|
|
4852
|
+
*
|
|
4853
|
+
* // With custom base URL
|
|
4854
|
+
* const client = await PlaycademyClient.init({ baseUrl: 'https://custom.api.com' })
|
|
4855
|
+
* ```
|
|
4856
|
+
*/
|
|
4857
|
+
declare function init<T extends PlaycademyBaseClient = PlaycademyBaseClient>(this: new (config?: Partial<ClientConfig>) => T, options?: {
|
|
4858
|
+
baseUrl?: string;
|
|
4859
|
+
allowedParentOrigins?: string[];
|
|
4860
|
+
onDisconnect?: DisconnectHandler;
|
|
4861
|
+
enableConnectionMonitoring?: boolean;
|
|
4862
|
+
}): Promise<T>;
|
|
4863
|
+
|
|
4864
|
+
/**
|
|
4865
|
+
* Authenticates a user with email and password.
|
|
4866
|
+
*
|
|
4867
|
+
* This is a standalone authentication method that doesn't require an initialized client.
|
|
4868
|
+
* Use this for login flows before creating a client instance.
|
|
4869
|
+
*
|
|
4870
|
+
* @deprecated Use client.auth.login() instead for better error handling and automatic token management
|
|
4871
|
+
*
|
|
4872
|
+
* @param baseUrl - The base URL of the Playcademy API
|
|
4873
|
+
* @param email - User's email address
|
|
4874
|
+
* @param password - User's password
|
|
4875
|
+
* @returns Promise resolving to authentication response with token
|
|
4876
|
+
* @throws PlaycademyError if authentication fails or network error occurs
|
|
4877
|
+
*
|
|
4878
|
+
* @example
|
|
4879
|
+
* ```typescript
|
|
4880
|
+
* // Preferred approach:
|
|
4881
|
+
* const client = new PlaycademyClient({ baseUrl: '/api' })
|
|
4882
|
+
* const result = await client.auth.login({
|
|
4883
|
+
* email: 'user@example.com',
|
|
4884
|
+
* password: 'password'
|
|
4885
|
+
* })
|
|
4886
|
+
*
|
|
4887
|
+
* // Legacy approach (still works):
|
|
4888
|
+
* try {
|
|
4889
|
+
* const response = await PlaycademyClient.login('/api', 'user@example.com', 'password')
|
|
4890
|
+
* const client = new PlaycademyClient({ token: response.token })
|
|
4891
|
+
* } catch (error) {
|
|
4892
|
+
* console.error('Login failed:', error.message)
|
|
4893
|
+
* }
|
|
4894
|
+
* ```
|
|
4895
|
+
*/
|
|
4896
|
+
declare function login(baseUrl: string, email: string, password: string): Promise<LoginResponse>;
|
|
4897
|
+
|
|
4898
4898
|
/**
|
|
4899
4899
|
* Playcademy SDK client for game developers.
|
|
4900
4900
|
* Provides namespaced access to platform features for games running inside Cademy.
|
|
@@ -5680,6 +5680,17 @@ interface CustomRoutesIntegration {
|
|
|
5680
5680
|
interface DatabaseIntegration {
|
|
5681
5681
|
/** Database directory (defaults to 'db') */
|
|
5682
5682
|
directory?: string;
|
|
5683
|
+
/** Schema strategy: 'push' uses drizzle-kit push-style diffing, 'migrate' uses migration files.
|
|
5684
|
+
* When omitted, auto-detects based on presence of a migrations directory with _journal.json. */
|
|
5685
|
+
strategy?: 'push' | 'migrate';
|
|
5686
|
+
}
|
|
5687
|
+
interface QueueConfig {
|
|
5688
|
+
maxBatchSize?: number;
|
|
5689
|
+
maxRetries?: number;
|
|
5690
|
+
maxBatchTimeout?: number;
|
|
5691
|
+
maxConcurrency?: number;
|
|
5692
|
+
retryDelay?: number;
|
|
5693
|
+
deadLetterQueue?: string;
|
|
5683
5694
|
}
|
|
5684
5695
|
/**
|
|
5685
5696
|
* Integrations configuration
|
|
@@ -5698,6 +5709,8 @@ interface IntegrationsConfig {
|
|
|
5698
5709
|
bucket?: boolean;
|
|
5699
5710
|
/** Authentication (optional) */
|
|
5700
5711
|
auth?: boolean;
|
|
5712
|
+
/** Queues (optional) */
|
|
5713
|
+
queues?: Record<string, QueueConfig | boolean>;
|
|
5701
5714
|
}
|
|
5702
5715
|
/**
|
|
5703
5716
|
* Unified Playcademy configuration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcademy/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"@playcademy/data": "0.0.1",
|
|
45
45
|
"@playcademy/logger": "0.0.1",
|
|
46
46
|
"@playcademy/types": "0.0.1",
|
|
47
|
-
"@playcademy/sandbox": "0.3.
|
|
47
|
+
"@playcademy/sandbox": "0.3.14",
|
|
48
48
|
"@playcademy/test": "0.0.1",
|
|
49
49
|
"@playcademy/timeback": "0.0.1",
|
|
50
50
|
"@playcademy/utils": "0.0.1",
|
|
51
51
|
"@types/bun": "latest",
|
|
52
|
-
"playcademy": "0.16.
|
|
52
|
+
"playcademy": "0.16.11",
|
|
53
53
|
"rollup": "^4.50.2",
|
|
54
54
|
"rollup-plugin-dts": "^6.2.3",
|
|
55
55
|
"typescript": "^5.7.2"
|