@playcademy/sdk 0.0.3 → 0.0.5

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.
@@ -12,7 +12,7 @@ export declare class PlaycademyClient {
12
12
  private listeners;
13
13
  private internalClientSessionId?;
14
14
  private authContext?;
15
- private userId?;
15
+ private initPayload?;
16
16
  /**
17
17
  * Creates a new PlaycademyClient instance.
18
18
  *
@@ -133,6 +133,7 @@ export declare class PlaycademyClient {
133
133
  };
134
134
  /** Identity provider connection methods (connect external accounts) */
135
135
  identity: {
136
+ readonly user: import("@playcademy/data/types").AuthenticatedUser | null;
136
137
  connect: (options: import("../types").AuthOptions) => Promise<import("../types").AuthResult>;
137
138
  _getContext: () => {
138
139
  isInIframe: boolean;
@@ -181,7 +182,7 @@ export declare class PlaycademyClient {
181
182
  leaderboard: {
182
183
  get: (gameId: string, options?: {
183
184
  limit?: number;
184
- offset?: number;
185
+ offset? /** Telemetry methods (pushMetrics) */: number;
185
186
  }) => Promise<import("@playcademy/data/types").LeaderboardEntry[]>;
186
187
  };
187
188
  };
@@ -197,7 +198,7 @@ export declare class PlaycademyClient {
197
198
  };
198
199
  scores: {
199
200
  get: (userIdOrOptions?: string | {
200
- limit? /** Telemetry methods (pushMetrics) */: number;
201
+ limit?: number;
201
202
  gameId?: string;
202
203
  }, options?: {
203
204
  limit?: number;
@@ -7,6 +7,13 @@ import type { AuthOptions, AuthResult, PlaycademyClient } from '../../types';
7
7
  * @returns Identity namespace with connection methods
8
8
  */
9
9
  export declare function createIdentityNamespace(client: PlaycademyClient): {
10
+ /**
11
+ * The authenticated user information provided by the Playcademy platform,
12
+ * if available in the current context (e.g., iframe runtime).
13
+ *
14
+ * Returns null when no user context is available (e.g., standalone dev).
15
+ */
16
+ readonly user: import("@playcademy/data/types").AuthenticatedUser | null;
10
17
  /**
11
18
  * Connects an external identity provider to the user's Playcademy account.
12
19
  *
package/dist/index.js CHANGED
@@ -1124,20 +1124,14 @@ async function login(client, options) {
1124
1124
  try {
1125
1125
  let stateData = options.stateData;
1126
1126
  if (!stateData) {
1127
- const storedUserId = client["userId"];
1128
- if (storedUserId) {
1129
- stateData = {
1130
- playcademy_user_id: storedUserId,
1131
- game_id: client["gameId"] || ""
1132
- };
1127
+ const currentUser = client["initPayload"]?.user;
1128
+ if (currentUser?.id) {
1129
+ stateData = { playcademy_user_id: currentUser.id };
1133
1130
  } else {
1134
1131
  try {
1135
- const currentUser = await client.users.me();
1136
- if (currentUser?.id) {
1137
- stateData = {
1138
- playcademy_user_id: currentUser.id,
1139
- game_id: client["gameId"] || ""
1140
- };
1132
+ const currentUser2 = await client.users.me();
1133
+ if (currentUser2?.id) {
1134
+ stateData = { playcademy_user_id: currentUser2.id };
1141
1135
  }
1142
1136
  } catch {
1143
1137
  log.debug("[Playcademy SDK] No current user available for state data");
@@ -1150,11 +1144,11 @@ async function login(client, options) {
1150
1144
  callbackUrl: options.callbackUrl,
1151
1145
  hasStateData: !!stateData
1152
1146
  });
1153
- const enrichedOptions = {
1147
+ const optionsWithState = {
1154
1148
  ...options,
1155
1149
  stateData
1156
1150
  };
1157
- const result = await initiateUnifiedFlow(enrichedOptions);
1151
+ const result = await initiateUnifiedFlow(optionsWithState);
1158
1152
  if (result.success && result.user) {
1159
1153
  log.debug("[Playcademy SDK] OAuth login successful", {
1160
1154
  userId: result.user.sub
@@ -1178,6 +1172,9 @@ var init_login = __esm(() => {
1178
1172
  // src/core/namespaces/identity.ts
1179
1173
  function createIdentityNamespace(client) {
1180
1174
  return {
1175
+ get user() {
1176
+ return client["initPayload"]?.user ?? null;
1177
+ },
1181
1178
  connect: (options) => login(client, options),
1182
1179
  _getContext: () => ({
1183
1180
  isInIframe: client["authContext"]?.isInIframe ?? false
@@ -2624,7 +2621,8 @@ function createStandaloneConfig() {
2624
2621
  baseUrl: "/api",
2625
2622
  token: "mock-game-token-for-local-dev",
2626
2623
  gameId: "mock-game-id-from-template",
2627
- realtimeUrl: undefined
2624
+ realtimeUrl: undefined,
2625
+ user: undefined
2628
2626
  };
2629
2627
  window.PLAYCADEMY = mockConfig;
2630
2628
  return mockConfig;
@@ -2640,9 +2638,7 @@ async function init() {
2640
2638
  token: config.token,
2641
2639
  gameId: config.gameId
2642
2640
  });
2643
- if (config.userId) {
2644
- client["userId"] = config.userId;
2645
- }
2641
+ client["initPayload"] = config;
2646
2642
  messaging.listen("PLAYCADEMY_TOKEN_REFRESH" /* TOKEN_REFRESH */, ({ token }) => client.setToken(token));
2647
2643
  messaging.send("PLAYCADEMY_READY" /* READY */, undefined);
2648
2644
  if (import.meta.env?.MODE === "development") {
@@ -2720,7 +2716,7 @@ var init_client = __esm(() => {
2720
2716
  listeners = {};
2721
2717
  internalClientSessionId;
2722
2718
  authContext;
2723
- userId;
2719
+ initPayload;
2724
2720
  constructor(config) {
2725
2721
  if (!config) {
2726
2722
  this.baseUrl = "/api";
package/dist/types.d.ts CHANGED
@@ -1,12 +1,20 @@
1
+ import type { AuthenticatedUser } from '@playcademy/data/types';
1
2
  export type * from '@playcademy/data/types';
2
3
  export { CURRENCIES, BADGES } from '@playcademy/data/constants';
3
- export type { AuthenticatedUser as PlaycademyUser } from '@playcademy/sdk/types';
4
+ export type { AuthenticatedUser } from '@playcademy/data/types';
4
5
  export type { PlaycademyClient } from './core/client';
5
6
  export interface ClientConfig {
6
7
  baseUrl: string;
7
8
  token?: string;
8
9
  gameId?: string;
9
10
  }
11
+ export interface InitPayload {
12
+ baseUrl: string;
13
+ token: string;
14
+ gameId: string;
15
+ realtimeUrl?: string;
16
+ user?: AuthenticatedUser;
17
+ }
10
18
  export declare const AuthProvider: {
11
19
  readonly TIMEBACK: "TIMEBACK";
12
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {