@playcademy/better-auth 0.0.16-beta.4 → 0.0.16

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.
Files changed (2) hide show
  1. package/dist/server.js +36 -6
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -16287,11 +16287,20 @@ function statusCodeToErrorCode(status) {
16287
16287
  }
16288
16288
  }
16289
16289
  }
16290
- async function makeApiRequest(baseUrl, apiToken, endpoint, method = "GET", body) {
16290
+ var SDK_VERSION = "0.12.0";
16291
+ async function makeApiRequest(opts) {
16292
+ const { baseUrl, apiToken, endpoint, method = "GET", body, gameOrigin, launchId } = opts;
16291
16293
  const url = `${baseUrl}${endpoint}`;
16292
16294
  const headers = new Headers;
16293
16295
  headers.set("Content-Type", "application/json");
16294
16296
  headers.set("x-api-key", apiToken);
16297
+ headers.set("x-playcademy-sdk-version", SDK_VERSION);
16298
+ if (gameOrigin) {
16299
+ headers.set("x-playcademy-game-origin", gameOrigin);
16300
+ }
16301
+ if (launchId) {
16302
+ headers.set("x-playcademy-launch-id", launchId);
16303
+ }
16295
16304
  const options = {
16296
16305
  method,
16297
16306
  headers
@@ -16316,8 +16325,10 @@ async function makeApiRequest(baseUrl, apiToken, endpoint, method = "GET", body)
16316
16325
 
16317
16326
  class PlaycademyClient {
16318
16327
  state;
16319
- constructor(state) {
16328
+ requestCtx = {};
16329
+ constructor(state, requestCtx) {
16320
16330
  this.state = state;
16331
+ this.requestCtx = requestCtx ?? {};
16321
16332
  }
16322
16333
  static async init(config2) {
16323
16334
  const { apiKey, baseUrl, gameId } = config2;
@@ -16341,11 +16352,22 @@ class PlaycademyClient {
16341
16352
  }
16342
16353
  return client;
16343
16354
  }
16355
+ forRequest(ctx) {
16356
+ return new PlaycademyClient(this.state, ctx);
16357
+ }
16344
16358
  async fetchGameId() {
16345
16359
  throw new Error("[Playcademy SDK] gameId is required. Please provide it in the config or implement gameId fetching.");
16346
16360
  }
16347
16361
  async request(path, method = "GET", body) {
16348
- return makeApiRequest(this.state.baseUrl, this.state.apiKey, path, method, body);
16362
+ return makeApiRequest({
16363
+ baseUrl: this.state.baseUrl,
16364
+ apiToken: this.state.apiKey,
16365
+ endpoint: path,
16366
+ method,
16367
+ body,
16368
+ gameOrigin: this.requestCtx.gameOrigin,
16369
+ launchId: this.requestCtx.launchId
16370
+ });
16349
16371
  }
16350
16372
  get gameId() {
16351
16373
  return this.state.gameId;
@@ -16365,11 +16387,19 @@ async function verifyGameToken(gameToken, options) {
16365
16387
  Please set the PLAYCADEMY_BASE_URL environment variable`);
16366
16388
  }
16367
16389
  try {
16390
+ const headers = {
16391
+ "Content-Type": "application/json",
16392
+ "x-playcademy-sdk-version": SDK_VERSION
16393
+ };
16394
+ if (options?.gameOrigin) {
16395
+ headers["x-playcademy-game-origin"] = options.gameOrigin;
16396
+ }
16397
+ if (options?.launchId) {
16398
+ headers["x-playcademy-launch-id"] = options.launchId;
16399
+ }
16368
16400
  const response = await fetch(`${baseUrl}/api/games/verify`, {
16369
16401
  method: "POST",
16370
- headers: {
16371
- "Content-Type": "application/json"
16372
- },
16402
+ headers,
16373
16403
  body: JSON.stringify({ token: gameToken })
16374
16404
  });
16375
16405
  if (!response.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/better-auth",
3
- "version": "0.0.16-beta.4",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": {
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@better-auth/utils": "^0.3.0",
27
27
  "@better-fetch/fetch": "^1.1.18",
28
- "@playcademy/sdk": "0.11.0",
28
+ "@playcademy/sdk": "0.12.0",
29
29
  "better-auth": "1.3.33",
30
30
  "better-call": "^1.0.19"
31
31
  },