@playcademy/better-auth 0.0.3 → 0.0.4-beta.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/client.d.ts CHANGED
@@ -18,7 +18,6 @@
18
18
  * })
19
19
  * ```
20
20
  */
21
- import { playcademy as playcademyServerPlugin } from './server';
22
21
  /**
23
22
  * Configuration options for the Playcademy Better Auth client plugin
24
23
  *
@@ -138,6 +137,54 @@ export interface PlaycademyClientOptions {
138
137
  */
139
138
  export declare function playcademy(options?: PlaycademyClientOptions): {
140
139
  id: "playcademy-client";
141
- $InferServerPlugin: ReturnType<typeof playcademyServerPlugin>;
140
+ $InferServerPlugin: {
141
+ id: string;
142
+ schema: {
143
+ user: {
144
+ fields: {
145
+ playcademyUserId: {
146
+ type: "string";
147
+ unique: boolean;
148
+ required: boolean;
149
+ };
150
+ };
151
+ };
152
+ };
153
+ endpoints: {
154
+ playcademyAuth: {
155
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({
156
+ body?: undefined;
157
+ } & {
158
+ method?: "POST" | undefined;
159
+ } & {
160
+ query?: Record<string, any> | undefined;
161
+ } & {
162
+ params?: Record<string, any> | undefined;
163
+ } & {
164
+ request?: Request | undefined;
165
+ } & {
166
+ headers?: HeadersInit | undefined;
167
+ } & {
168
+ asResponse?: boolean | undefined;
169
+ returnHeaders?: boolean | undefined;
170
+ use?: any[] | undefined;
171
+ path?: string | undefined;
172
+ } & {
173
+ asResponse?: AsResponse | undefined;
174
+ returnHeaders?: ReturnHeaders | undefined;
175
+ }) | undefined): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
176
+ headers: Headers;
177
+ response: Response;
178
+ } : Response>;
179
+ options: {
180
+ method: "POST";
181
+ requireHeaders: false;
182
+ } & {
183
+ use: any[];
184
+ };
185
+ path: "/playcademy";
186
+ };
187
+ };
188
+ };
142
189
  fetchPlugins: import("@better-fetch/fetch").BetterFetchPlugin[];
143
190
  };
package/dist/client.js CHANGED
@@ -11,23 +11,27 @@ var __export = (target, all) => {
11
11
 
12
12
  // src/utils.ts
13
13
  function isPlatformMode() {
14
- if (typeof window === "undefined")
14
+ if (typeof globalThis.window === "undefined") {
15
15
  return false;
16
- if (window.self === window.top)
16
+ }
17
+ if (globalThis.self === window.top) {
17
18
  return false;
19
+ }
18
20
  return true;
19
21
  }
20
22
  function isSafari() {
21
- if (typeof window === "undefined")
23
+ if (typeof globalThis.window === "undefined") {
22
24
  return false;
25
+ }
23
26
  const ua = navigator.userAgent;
24
27
  return ua.includes("Safari") && !ua.includes("Chrome") && !ua.includes("Chromium");
25
28
  }
26
29
  function getPlatformToken() {
27
- if (typeof window === "undefined")
30
+ if (typeof globalThis.window === "undefined") {
28
31
  return null;
32
+ }
29
33
  try {
30
- return window.PLAYCADEMY?.token || null;
34
+ return globalThis.PLAYCADEMY?.token || null;
31
35
  } catch {
32
36
  return null;
33
37
  }
@@ -36,12 +40,15 @@ function hasStorageAccessAPI() {
36
40
  return typeof document !== "undefined" && "hasStorageAccess" in document;
37
41
  }
38
42
  async function needsStorageAccess() {
39
- if (!isPlatformMode())
43
+ if (!isPlatformMode()) {
40
44
  return false;
41
- if (!isSafari())
45
+ }
46
+ if (!isSafari()) {
42
47
  return false;
43
- if (!hasStorageAccessAPI())
48
+ }
49
+ if (!hasStorageAccessAPI()) {
44
50
  return false;
51
+ }
45
52
  try {
46
53
  const hasAccess = await document.hasStorageAccess();
47
54
  return !hasAccess;
@@ -50,8 +57,9 @@ async function needsStorageAccess() {
50
57
  }
51
58
  }
52
59
  async function requestStorageAccess() {
53
- if (!hasStorageAccessAPI())
60
+ if (!hasStorageAccessAPI()) {
54
61
  return false;
62
+ }
55
63
  try {
56
64
  await document.requestStorageAccess();
57
65
  return true;
@@ -62,8 +70,9 @@ async function requestStorageAccess() {
62
70
 
63
71
  // src/fetch.ts
64
72
  async function ensureStorageAccess() {
65
- if (!isSafari())
73
+ if (!isSafari()) {
66
74
  return true;
75
+ }
67
76
  const needs = await needsStorageAccess();
68
77
  if (needs) {
69
78
  return false;
@@ -72,8 +81,8 @@ async function ensureStorageAccess() {
72
81
  await document.requestStorageAccess();
73
82
  await new Promise((resolve) => setTimeout(resolve, 50));
74
83
  return true;
75
- } catch (err) {
76
- console.error("[Playcademy Auth] Safari Storage Access activation failed:", err);
84
+ } catch (error) {
85
+ console.error("[Playcademy Auth] Safari Storage Access activation failed:", error);
77
86
  return false;
78
87
  }
79
88
  }
@@ -104,16 +113,18 @@ function playcademyExchangePlugin(_opts) {
104
113
  id: "playcademy-exchange",
105
114
  name: "Playcademy Exchange",
106
115
  async init(url, options) {
107
- if (exchangeComplete)
116
+ if (exchangeComplete) {
108
117
  return { url, options };
118
+ }
109
119
  if (exchangePromise) {
110
120
  await exchangePromise;
111
121
  return { url, options };
112
122
  }
113
123
  exchangePromise = (async () => {
114
124
  const token = await waitForToken();
115
- if (!token)
125
+ if (!token) {
116
126
  return;
127
+ }
117
128
  const canProceed = await ensureStorageAccess();
118
129
  if (!canProceed) {
119
130
  return;
@@ -152,8 +163,9 @@ function removeOverlay() {
152
163
  }
153
164
  }
154
165
  function injectStorageAccessOverlay() {
155
- if (document.getElementById(OVERLAY_ID))
166
+ if (document.getElementById(OVERLAY_ID)) {
156
167
  return;
168
+ }
157
169
  if (!document.body) {
158
170
  document.addEventListener("DOMContentLoaded", injectStorageAccessOverlay);
159
171
  return;
@@ -237,7 +249,7 @@ function injectStorageAccessOverlay() {
237
249
  const hasAccess = await document.hasStorageAccess();
238
250
  if (hasAccess) {
239
251
  removeOverlay();
240
- window.location.reload();
252
+ globalThis.location.reload();
241
253
  return;
242
254
  }
243
255
  } catch {}
@@ -245,7 +257,7 @@ function injectStorageAccessOverlay() {
245
257
  const granted = await requestStorageAccess();
246
258
  if (granted) {
247
259
  removeOverlay();
248
- window.location.reload();
260
+ globalThis.location.reload();
249
261
  } else {
250
262
  const message = overlay.querySelector(`#${OVERLAY_ID}-message`);
251
263
  if (message) {
@@ -257,10 +269,12 @@ function injectStorageAccessOverlay() {
257
269
  document.body.appendChild(overlay);
258
270
  }
259
271
  async function handleStorageAccess(options) {
260
- if (!options.autoPrompt)
272
+ if (!options.autoPrompt) {
261
273
  return;
262
- if (!isPlatformMode() || !isSafari())
274
+ }
275
+ if (!isPlatformMode() || !isSafari()) {
263
276
  return;
277
+ }
264
278
  const needs = await needsStorageAccess();
265
279
  if (needs) {
266
280
  injectStorageAccessOverlay();
@@ -272,7 +286,7 @@ function playcademy(options) {
272
286
  autoPrompt: options?.safari?.autoPrompt ?? true
273
287
  }
274
288
  };
275
- if (typeof window !== "undefined" && opts.safari.autoPrompt) {
289
+ if (typeof globalThis.window !== "undefined" && opts.safari.autoPrompt) {
276
290
  if (isPlatformMode() && isSafari()) {
277
291
  setTimeout(() => {
278
292
  handleStorageAccess(opts.safari);
package/dist/server.d.ts CHANGED
@@ -140,15 +140,15 @@
140
140
  * }
141
141
  * ```
142
142
  */
143
- export declare const playcademy: () => {
144
- id: "playcademy";
143
+ export declare function playcademy(): {
144
+ id: string;
145
145
  schema: {
146
146
  user: {
147
147
  fields: {
148
148
  playcademyUserId: {
149
149
  type: "string";
150
- unique: true;
151
- required: false;
150
+ unique: boolean;
151
+ required: boolean;
152
152
  };
153
153
  };
154
154
  };
@@ -177,16 +177,16 @@ export declare const playcademy: () => {
177
177
  } & {
178
178
  query?: Record<string, any> | undefined;
179
179
  } & {
180
- params?: Record<string, any>;
180
+ params?: Record<string, any> | undefined;
181
181
  } & {
182
- request?: Request;
182
+ request?: Request | undefined;
183
183
  } & {
184
- headers?: HeadersInit;
184
+ headers?: HeadersInit | undefined;
185
185
  } & {
186
- asResponse?: boolean;
187
- returnHeaders?: boolean;
188
- use?: import("better-call").Middleware[];
189
- path?: string;
186
+ asResponse?: boolean | undefined;
187
+ returnHeaders?: boolean | undefined;
188
+ use?: any[] | undefined;
189
+ path?: string | undefined;
190
190
  } & {
191
191
  asResponse?: AsResponse | undefined;
192
192
  returnHeaders?: ReturnHeaders | undefined;