@stacksjs/browser 0.70.45 → 0.70.53

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2023 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -919,14 +919,14 @@ var isAuthenticated = ref(false);
919
919
  function useAuth() {
920
920
  async function fetchAuthUser() {
921
921
  try {
922
- if (!token) {
922
+ if (!token.value) {
923
923
  isAuthenticated.value = false;
924
924
  user.value = null;
925
925
  return null;
926
926
  }
927
927
  const response = await fetch(`${baseUrl}/me`, {
928
928
  headers: {
929
- Authorization: `Bearer ${token}`,
929
+ Authorization: `Bearer ${token.value}`,
930
930
  Accept: "application/json"
931
931
  }
932
932
  });
@@ -937,9 +937,9 @@ function useAuth() {
937
937
  return null;
938
938
  }
939
939
  const data = await response.json();
940
- user.value = data.user;
940
+ user.value = data;
941
941
  isAuthenticated.value = true;
942
- return data.user;
942
+ return data;
943
943
  } catch (error) {
944
944
  console.error("Error fetching user:", error);
945
945
  token.value = "";
@@ -971,7 +971,7 @@ function useAuth() {
971
971
  return data;
972
972
  }
973
973
  if (isRegisterResponse(data)) {
974
- token.value = data.data.token;
974
+ token.value = data.token;
975
975
  return data;
976
976
  }
977
977
  return data;
@@ -980,7 +980,7 @@ function useAuth() {
980
980
  return "errors" in data;
981
981
  }
982
982
  function isRegisterResponse(data) {
983
- return "data" in data && "token" in data.data;
983
+ return "token" in data && "user" in data;
984
984
  }
985
985
  async function login(user2) {
986
986
  try {
@@ -997,7 +997,7 @@ function useAuth() {
997
997
  throw new Error(errorData.message || `HTTP error! status: ${response.status}`);
998
998
  }
999
999
  const data = await response.json();
1000
- token.value = data.data.token;
1000
+ token.value = data.token;
1001
1001
  await fetchAuthUser();
1002
1002
  return data;
1003
1003
  } catch (error) {
@@ -1271,7 +1271,7 @@ function loadBrowserModels() {
1271
1271
  useSoftDeletes: definition.traits?.useSoftDeletes ?? false,
1272
1272
  useApi: definition.traits?.useApi
1273
1273
  },
1274
- attributes: extractBrowserAttributes(definition.attributes || {})
1274
+ attributes: extractBrowserAttributes(definition.attributes ?? {})
1275
1275
  });
1276
1276
  window.StacksBrowser[definition.name] = browserModel;
1277
1277
  } catch (error) {
@@ -1304,7 +1304,7 @@ function getBrowserModelNames() {
1304
1304
  return [];
1305
1305
  return Object.keys(stacksBrowser).filter((key) => {
1306
1306
  const value = stacksBrowser[key];
1307
- return value && typeof value.all === "function" && typeof value.find === "function";
1307
+ return value != null && typeof value.all === "function" && typeof value.find === "function";
1308
1308
  });
1309
1309
  }
1310
1310
 
@@ -1362,7 +1362,7 @@ import { toString } from "@stacksjs/strings";
1362
1362
  async function loop(times, callback) {
1363
1363
  Array.from({ length: times }).forEach(async (_, i) => await callback(i));
1364
1364
  }
1365
- // ../../../../node_modules/@stripe/stripe-js/dist/index.mjs
1365
+ // ../../../../pantry/@stripe/stripe-js/dist/index.mjs
1366
1366
  function _typeof(obj) {
1367
1367
  "@babel/helpers - typeof";
1368
1368
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
@@ -1376,7 +1376,7 @@ function _typeof(obj) {
1376
1376
  }
1377
1377
  return _typeof(obj);
1378
1378
  }
1379
- var RELEASE_TRAIN = "dahlia";
1379
+ var RELEASE_TRAIN = "clover";
1380
1380
  var runtimeVersionToUrlVersion = function runtimeVersionToUrlVersion2(version) {
1381
1381
  return version === 3 ? "v3" : version;
1382
1382
  };
@@ -1416,7 +1416,7 @@ var registerWrapper = function registerWrapper2(stripe, startTime) {
1416
1416
  }
1417
1417
  stripe._registerWrapper({
1418
1418
  name: "stripe-js",
1419
- version: "9.4.0",
1419
+ version: "8.11.0",
1420
1420
  startTime
1421
1421
  });
1422
1422
  };
@@ -1494,7 +1494,7 @@ var initStripe = function initStripe2(maybeStripe, args, startTime) {
1494
1494
  var version = runtimeVersionToUrlVersion(maybeStripe.version);
1495
1495
  var expectedVersion = RELEASE_TRAIN;
1496
1496
  if (isTestKey && version !== expectedVersion) {
1497
- console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("9.4.0", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
1497
+ console.warn("Stripe.js@".concat(version, " was loaded on the page, but @stripe/stripe-js@").concat("8.11.0", " expected Stripe.js@").concat(expectedVersion, ". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));
1498
1498
  }
1499
1499
  var stripe = maybeStripe.apply(undefined, args);
1500
1500
  registerWrapper(stripe, startTime);
@@ -2070,7 +2070,7 @@ function random(size = 21) {
2070
2070
  }
2071
2071
  return id;
2072
2072
  }
2073
- // ../../../../node_modules/magic-regexp/dist/flags-BP1_fHjc.mjs
2073
+ // ../../../../pantry/magic-regexp/dist/flags-BP1_fHjc.mjs
2074
2074
  var NO_WRAP_RE = /^(?:\(.*\)|\\?.)$/;
2075
2075
  function wrap(s) {
2076
2076
  const v = s.toString();
@@ -5,8 +5,80 @@ export declare function loadBrowserModels(): void;
5
5
  /**
6
6
  * Get a loaded model by name
7
7
  */
8
- export declare function getBrowserModel(name: string): any;
8
+ export declare function getBrowserModel(name: string): BrowserModel | null;
9
9
  /**
10
10
  * Get all loaded model names
11
11
  */
12
12
  export declare function getBrowserModelNames(): string[];
13
+ /**
14
+ * Minimal shape of a model attribute as far as the browser model
15
+ * loader is concerned. The full server-side attribute has
16
+ * `factory`, validation rules, casters, etc. — none of which are
17
+ * meaningful client-side, so we strip them off in
18
+ * {@link extractBrowserAttributes}.
19
+ */
20
+ export declare interface BrowserAttributeDefinition {
21
+ fillable?: boolean
22
+ hidden?: boolean
23
+ guarded?: boolean
24
+ nullable?: boolean
25
+ }
26
+ /**
27
+ * `useApi` trait shape — declares the REST URI the browser model
28
+ * should call into. When omitted, the loader skips the model
29
+ * (browser code can't reach a model that has no API surface).
30
+ */
31
+ export declare interface BrowserUseApiTrait {
32
+ uri: string
33
+ [extra: string]: unknown
34
+ }
35
+ /**
36
+ * Subset of model-traits the browser loader inspects. Server-side
37
+ * traits like `useAudit`, `observe`, etc. aren't meaningful client-
38
+ * side — only the four below influence browser-side behaviour.
39
+ */
40
+ export declare interface BrowserModelTraits {
41
+ useApi?: BrowserUseApiTrait
42
+ useUuid?: boolean
43
+ useTimestamps?: boolean
44
+ useSoftDeletes?: boolean
45
+ [extra: string]: unknown
46
+ }
47
+ /**
48
+ * Shape of a `defineModel(...)`-returned module's default export
49
+ * that the browser loader cares about. Mirrors a tight subset of
50
+ * `StacksModelDefinition` from `@stacksjs/orm` — typed locally so
51
+ * the browser package doesn't pull the full ORM types in.
52
+ */
53
+ export declare interface BrowserModelDefinition {
54
+ name: string
55
+ table?: string
56
+ primaryKey?: string
57
+ traits?: BrowserModelTraits
58
+ attributes?: Record<string, BrowserAttributeDefinition & { [extra: string]: unknown }>
59
+ [extra: string]: unknown
60
+ }
61
+ /**
62
+ * Shape of a model returned by `createBrowserModel`. Methods are
63
+ * declared loosely (the underlying bun-query-builder API surface
64
+ * is broader and changes) — we only check `.all` / `.find` exist
65
+ * in {@link getBrowserModelNames} for discovery.
66
+ */
67
+ export declare interface BrowserModel {
68
+ all: (...args: unknown[]) => unknown
69
+ find: (id: string | number, ...args: unknown[]) => unknown
70
+ [extra: string]: unknown
71
+ }
72
+ /**
73
+ * Window augmentation for the framework's `StacksBrowser` global
74
+ * (stacksjs/stacks#1894 T-9). Pre-fix every access went through
75
+ * `(window as any)` — typos in model names silently returned
76
+ * `undefined`. The augmented index signature still permits any
77
+ * model name at runtime; what it adds is the existence + shape of
78
+ * the StacksBrowser bag itself.
79
+ */
80
+ declare global {
81
+ interface Window {
82
+ StacksBrowser?: Record<string, BrowserModel | undefined>
83
+ }
84
+ }
@@ -8,14 +8,31 @@ export declare interface ValidationError {
8
8
  export declare interface RegisterError {
9
9
  errors: ResponseError
10
10
  }
11
+ // LoginAction/RegisterAction/AuthUserAction respond via `response.json(...)`,
12
+ // which serializes flat (see @stacksjs/bun-router's ResponseFactory.json) —
13
+ // there is no `{ data: ... }` envelope, unlike endpoints built on
14
+ // `response.success()` or a JsonResource. These types mirror the actual
15
+ // flat wire shape.
11
16
  export declare interface RegisterResponse {
12
- data: {
13
- token: string
14
- user: {
15
- id: number
16
- email: string
17
- name: string
18
- }
17
+ token: string
18
+ user: {
19
+ id: number
20
+ email: string
21
+ name: string
22
+ }
23
+ }
24
+ // LoginAction additionally mints an OAuth2-compatible token pack; `token`
25
+ // is kept alongside `access_token` for backward compatibility.
26
+ export declare interface LoginResponse {
27
+ access_token: string
28
+ refresh_token: string
29
+ token_type: string
30
+ expires_in: number
31
+ token: string
32
+ user: {
33
+ id: number
34
+ email: string
35
+ name: string
19
36
  }
20
37
  }
21
38
  export declare interface Response<T> {
@@ -34,9 +51,6 @@ export declare interface UserData {
34
51
  email: string
35
52
  name: string
36
53
  }
37
- export declare interface MeResponse {
38
- user: UserData
39
- }
40
54
  export declare interface AuthComposable {
41
55
  isAuthenticated: Ref<boolean>
42
56
  user: Ref<UserData | null>
@@ -52,4 +66,4 @@ export type ResponseError = {
52
66
  error: string
53
67
  } | ValidationError;
54
68
  export type LoginError = RegisterError;
55
- export type LoginResponse = RegisterResponse;
69
+ export type MeResponse = UserData;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/browser",
3
3
  "type": "module",
4
- "version": "0.70.45",
4
+ "version": "0.70.53",
5
5
  "description": "Stacks core frontend/browser functionalities.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -47,14 +47,14 @@
47
47
  "prepublishOnly": "bun run build"
48
48
  },
49
49
  "dependencies": {
50
- "@stacksjs/composables": "^0.70.45",
51
- "@stacksjs/stx": "^0.2.40",
50
+ "@stacksjs/composables": "0.70.53",
51
+ "@stacksjs/stx": "^0.2.82",
52
52
  "@stripe/stripe-js": "^9.0.0",
53
- "bun-query-builder": "^0.1.21",
53
+ "bun-query-builder": "^0.1.38",
54
54
  "magic-regexp": "^0.11.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "better-dx": "^0.2.12",
58
- "@stacksjs/utils": "^0.70.45"
58
+ "@stacksjs/utils": "0.70.53"
59
59
  }
60
60
  }