@netlify/identity 1.1.0 → 1.2.0

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.
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
30
+ // src/main.ts
31
+ var main_exports = {};
32
+ __export(main_exports, {
33
33
  AUTH_EVENTS: () => AUTH_EVENTS,
34
34
  AuthError: () => AuthError,
35
35
  MissingIdentityError: () => MissingIdentityError,
@@ -54,7 +54,7 @@ __export(index_exports, {
54
54
  verifyEmailChange: () => verifyEmailChange,
55
55
  verifyRequestOrigin: () => verifyRequestOrigin
56
56
  });
57
- module.exports = __toCommonJS(index_exports);
57
+ module.exports = __toCommonJS(main_exports);
58
58
 
59
59
  // src/types.ts
60
60
  var AUTH_PROVIDERS = ["google", "github", "gitlab", "bitbucket", "facebook", "email"];
@@ -150,7 +150,7 @@ var NF_JWT_COOKIE = "nf_jwt";
150
150
  var NF_REFRESH_COOKIE = "nf_refresh";
151
151
  var getCookie = (name) => {
152
152
  if (typeof document === "undefined") return null;
153
- const match = document.cookie.match(new RegExp(`(?:^|; )${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}=([^;]*)`));
153
+ const match = new RegExp(`(?:^|; )${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}=([^;]*)`).exec(document.cookie);
154
154
  if (!match) return null;
155
155
  try {
156
156
  return decodeURIComponent(match[1]);
@@ -232,13 +232,15 @@ var triggerNextjsDynamic = () => {
232
232
  var DEFAULT_TIMEOUT_MS = 5e3;
233
233
  var fetchWithTimeout = async (url, options = {}, timeoutMs = DEFAULT_TIMEOUT_MS) => {
234
234
  const controller = new AbortController();
235
- const timer = setTimeout(() => controller.abort(), timeoutMs);
235
+ const timer = setTimeout(() => {
236
+ controller.abort();
237
+ }, timeoutMs);
236
238
  try {
237
239
  return await fetch(url, { ...options, signal: controller.signal });
238
240
  } catch (error) {
239
241
  if (error instanceof Error && error.name === "AbortError") {
240
242
  const pathname = new URL(url).pathname;
241
- throw new AuthError(`Identity request to ${pathname} timed out after ${timeoutMs}ms`);
243
+ throw new AuthError(`Identity request to ${pathname} timed out after ${String(timeoutMs)}ms`);
242
244
  }
243
245
  throw error;
244
246
  } finally {
@@ -305,16 +307,18 @@ var startTokenRefresh = () => {
305
307
  const nowS = Math.floor(Date.now() / 1e3);
306
308
  const expiresAtS = typeof token.expires_at === "number" && token.expires_at > 1e12 ? Math.floor(token.expires_at / 1e3) : token.expires_at;
307
309
  const delayMs = Math.max(0, expiresAtS - nowS - REFRESH_MARGIN_S) * 1e3;
308
- refreshTimer = setTimeout(async () => {
309
- try {
310
- const freshJwt = await user.jwt(true);
311
- const freshDetails = user.tokenDetails();
312
- setBrowserAuthCookies(freshJwt, freshDetails?.refresh_token);
313
- emitAuthEvent(AUTH_EVENTS.TOKEN_REFRESH, toUser(user));
314
- startTokenRefresh();
315
- } catch {
316
- stopTokenRefresh();
317
- }
310
+ refreshTimer = setTimeout(() => {
311
+ void (async () => {
312
+ try {
313
+ const freshJwt = await user.jwt(true);
314
+ const freshDetails = user.tokenDetails();
315
+ setBrowserAuthCookies(freshJwt, freshDetails?.refresh_token);
316
+ emitAuthEvent(AUTH_EVENTS.TOKEN_REFRESH, toUser(user));
317
+ startTokenRefresh();
318
+ } catch {
319
+ stopTokenRefresh();
320
+ }
321
+ })();
318
322
  }, delayMs);
319
323
  };
320
324
  var stopTokenRefresh = () => {
@@ -380,7 +384,7 @@ var refreshSession = async () => {
380
384
  }
381
385
  return null;
382
386
  }
383
- throw new AuthError(errorBody.msg || `Token refresh failed (${res.status})`, res.status);
387
+ throw new AuthError(errorBody.msg ?? `Token refresh failed (${String(res.status)})`, res.status);
384
388
  }
385
389
  const data = await res.json();
386
390
  const cookies = globalThis.Netlify?.context?.cookies;
@@ -427,7 +431,10 @@ var login = async (email, password) => {
427
431
  }
428
432
  if (!res.ok) {
429
433
  const errorBody = await res.json().catch(() => ({}));
430
- throw new AuthError(errorBody.msg || errorBody.error_description || `Login failed (${res.status})`, res.status);
434
+ throw new AuthError(
435
+ errorBody.msg ?? errorBody.error_description ?? `Login failed (${String(res.status)})`,
436
+ res.status
437
+ );
431
438
  }
432
439
  const data = await res.json();
433
440
  const accessToken = data.access_token;
@@ -441,7 +448,7 @@ var login = async (email, password) => {
441
448
  }
442
449
  if (!userRes.ok) {
443
450
  const errorBody = await userRes.json().catch(() => ({}));
444
- throw new AuthError(errorBody.msg || `Failed to fetch user data (${userRes.status})`, userRes.status);
451
+ throw new AuthError(errorBody.msg ?? `Failed to fetch user data (${String(userRes.status)})`, userRes.status);
445
452
  }
446
453
  const userData = await userRes.json();
447
454
  const user = toUser(userData);
@@ -477,7 +484,7 @@ var signup = async (email, password, data) => {
477
484
  }
478
485
  if (!res.ok) {
479
486
  const errorBody = await res.json().catch(() => ({}));
480
- throw new AuthError(errorBody.msg || `Signup failed (${res.status})`, res.status);
487
+ throw new AuthError(errorBody.msg ?? `Signup failed (${String(res.status)})`, res.status);
481
488
  }
482
489
  const responseData = await res.json();
483
490
  const user = toUser(responseData);
@@ -631,7 +638,7 @@ var handleEmailChangeCallback = async (client, emailChangeToken) => {
631
638
  if (!emailChangeRes.ok) {
632
639
  const errorBody = await emailChangeRes.json().catch(() => ({}));
633
640
  throw new AuthError(
634
- errorBody.msg || `Email change verification failed (${emailChangeRes.status})`,
641
+ errorBody.msg ?? `Email change verification failed (${String(emailChangeRes.status)})`,
635
642
  emailChangeRes.status
636
643
  );
637
644
  }
@@ -693,7 +700,7 @@ var toRoles = (appMeta) => {
693
700
  var toUser = (userData) => {
694
701
  const userMeta = userData.user_metadata ?? {};
695
702
  const appMeta = userData.app_metadata ?? {};
696
- const name = userMeta.full_name || userMeta.name;
703
+ const name = userMeta.full_name ?? userMeta.name;
697
704
  const pictureUrl = userMeta.avatar_url;
698
705
  return {
699
706
  id: userData.id,
@@ -719,7 +726,7 @@ var toUser = (userData) => {
719
726
  var claimsToUser = (claims) => {
720
727
  const appMeta = claims.app_metadata ?? {};
721
728
  const userMeta = claims.user_metadata ?? {};
722
- const name = userMeta.full_name || userMeta.name;
729
+ const name = userMeta.full_name ?? userMeta.name;
723
730
  const pictureUrl = userMeta.avatar_url;
724
731
  return {
725
732
  id: claims.sub ?? "",
@@ -791,7 +798,7 @@ var getUser = async () => {
791
798
  }
792
799
  triggerNextjsDynamic();
793
800
  const identityContext = globalThis.netlifyIdentityContext;
794
- const serverJwt = identityContext?.token || getServerCookie(NF_JWT_COOKIE);
801
+ const serverJwt = identityContext?.token ?? getServerCookie(NF_JWT_COOKIE);
795
802
  if (serverJwt) {
796
803
  const identityUrl = resolveIdentityUrl();
797
804
  if (identityUrl) {
@@ -920,7 +927,7 @@ var verifyEmailChange = async (token) => {
920
927
  });
921
928
  if (!res.ok) {
922
929
  const errorBody = await res.json().catch(() => ({}));
923
- throw new AuthError(errorBody.msg || `Email change verification failed (${res.status})`, res.status);
930
+ throw new AuthError(errorBody.msg ?? `Email change verification failed (${String(res.status)})`, res.status);
924
931
  }
925
932
  const userData = await res.json();
926
933
  const user = toUser(userData);
@@ -984,7 +991,10 @@ var adminFetch = async (path, options = {}) => {
984
991
  }
985
992
  if (!res.ok) {
986
993
  const errorBody = await res.json().catch(() => ({}));
987
- throw new AuthError(errorBody.msg || `Admin request failed (${res.status})`, res.status);
994
+ throw new AuthError(
995
+ errorBody.msg ?? `Admin request failed (${String(res.status)})`,
996
+ res.status
997
+ );
988
998
  }
989
999
  return res;
990
1000
  };
@@ -1077,4 +1087,3 @@ var admin = { listUsers, getUser: getUser2, createUser, updateUser: updateUser2,
1077
1087
  verifyEmailChange,
1078
1088
  verifyRequestOrigin
1079
1089
  });
1080
- //# sourceMappingURL=index.cjs.map
@@ -99,7 +99,7 @@ var NF_JWT_COOKIE = "nf_jwt";
99
99
  var NF_REFRESH_COOKIE = "nf_refresh";
100
100
  var getCookie = (name) => {
101
101
  if (typeof document === "undefined") return null;
102
- const match = document.cookie.match(new RegExp(`(?:^|; )${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}=([^;]*)`));
102
+ const match = new RegExp(`(?:^|; )${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}=([^;]*)`).exec(document.cookie);
103
103
  if (!match) return null;
104
104
  try {
105
105
  return decodeURIComponent(match[1]);
@@ -181,13 +181,15 @@ var triggerNextjsDynamic = () => {
181
181
  var DEFAULT_TIMEOUT_MS = 5e3;
182
182
  var fetchWithTimeout = async (url, options = {}, timeoutMs = DEFAULT_TIMEOUT_MS) => {
183
183
  const controller = new AbortController();
184
- const timer = setTimeout(() => controller.abort(), timeoutMs);
184
+ const timer = setTimeout(() => {
185
+ controller.abort();
186
+ }, timeoutMs);
185
187
  try {
186
188
  return await fetch(url, { ...options, signal: controller.signal });
187
189
  } catch (error) {
188
190
  if (error instanceof Error && error.name === "AbortError") {
189
191
  const pathname = new URL(url).pathname;
190
- throw new AuthError(`Identity request to ${pathname} timed out after ${timeoutMs}ms`);
192
+ throw new AuthError(`Identity request to ${pathname} timed out after ${String(timeoutMs)}ms`);
191
193
  }
192
194
  throw error;
193
195
  } finally {
@@ -254,16 +256,18 @@ var startTokenRefresh = () => {
254
256
  const nowS = Math.floor(Date.now() / 1e3);
255
257
  const expiresAtS = typeof token.expires_at === "number" && token.expires_at > 1e12 ? Math.floor(token.expires_at / 1e3) : token.expires_at;
256
258
  const delayMs = Math.max(0, expiresAtS - nowS - REFRESH_MARGIN_S) * 1e3;
257
- refreshTimer = setTimeout(async () => {
258
- try {
259
- const freshJwt = await user.jwt(true);
260
- const freshDetails = user.tokenDetails();
261
- setBrowserAuthCookies(freshJwt, freshDetails?.refresh_token);
262
- emitAuthEvent(AUTH_EVENTS.TOKEN_REFRESH, toUser(user));
263
- startTokenRefresh();
264
- } catch {
265
- stopTokenRefresh();
266
- }
259
+ refreshTimer = setTimeout(() => {
260
+ void (async () => {
261
+ try {
262
+ const freshJwt = await user.jwt(true);
263
+ const freshDetails = user.tokenDetails();
264
+ setBrowserAuthCookies(freshJwt, freshDetails?.refresh_token);
265
+ emitAuthEvent(AUTH_EVENTS.TOKEN_REFRESH, toUser(user));
266
+ startTokenRefresh();
267
+ } catch {
268
+ stopTokenRefresh();
269
+ }
270
+ })();
267
271
  }, delayMs);
268
272
  };
269
273
  var stopTokenRefresh = () => {
@@ -329,7 +333,7 @@ var refreshSession = async () => {
329
333
  }
330
334
  return null;
331
335
  }
332
- throw new AuthError(errorBody.msg || `Token refresh failed (${res.status})`, res.status);
336
+ throw new AuthError(errorBody.msg ?? `Token refresh failed (${String(res.status)})`, res.status);
333
337
  }
334
338
  const data = await res.json();
335
339
  const cookies = globalThis.Netlify?.context?.cookies;
@@ -376,7 +380,10 @@ var login = async (email, password) => {
376
380
  }
377
381
  if (!res.ok) {
378
382
  const errorBody = await res.json().catch(() => ({}));
379
- throw new AuthError(errorBody.msg || errorBody.error_description || `Login failed (${res.status})`, res.status);
383
+ throw new AuthError(
384
+ errorBody.msg ?? errorBody.error_description ?? `Login failed (${String(res.status)})`,
385
+ res.status
386
+ );
380
387
  }
381
388
  const data = await res.json();
382
389
  const accessToken = data.access_token;
@@ -390,7 +397,7 @@ var login = async (email, password) => {
390
397
  }
391
398
  if (!userRes.ok) {
392
399
  const errorBody = await userRes.json().catch(() => ({}));
393
- throw new AuthError(errorBody.msg || `Failed to fetch user data (${userRes.status})`, userRes.status);
400
+ throw new AuthError(errorBody.msg ?? `Failed to fetch user data (${String(userRes.status)})`, userRes.status);
394
401
  }
395
402
  const userData = await userRes.json();
396
403
  const user = toUser(userData);
@@ -426,7 +433,7 @@ var signup = async (email, password, data) => {
426
433
  }
427
434
  if (!res.ok) {
428
435
  const errorBody = await res.json().catch(() => ({}));
429
- throw new AuthError(errorBody.msg || `Signup failed (${res.status})`, res.status);
436
+ throw new AuthError(errorBody.msg ?? `Signup failed (${String(res.status)})`, res.status);
430
437
  }
431
438
  const responseData = await res.json();
432
439
  const user = toUser(responseData);
@@ -580,7 +587,7 @@ var handleEmailChangeCallback = async (client, emailChangeToken) => {
580
587
  if (!emailChangeRes.ok) {
581
588
  const errorBody = await emailChangeRes.json().catch(() => ({}));
582
589
  throw new AuthError(
583
- errorBody.msg || `Email change verification failed (${emailChangeRes.status})`,
590
+ errorBody.msg ?? `Email change verification failed (${String(emailChangeRes.status)})`,
584
591
  emailChangeRes.status
585
592
  );
586
593
  }
@@ -642,7 +649,7 @@ var toRoles = (appMeta) => {
642
649
  var toUser = (userData) => {
643
650
  const userMeta = userData.user_metadata ?? {};
644
651
  const appMeta = userData.app_metadata ?? {};
645
- const name = userMeta.full_name || userMeta.name;
652
+ const name = userMeta.full_name ?? userMeta.name;
646
653
  const pictureUrl = userMeta.avatar_url;
647
654
  return {
648
655
  id: userData.id,
@@ -668,7 +675,7 @@ var toUser = (userData) => {
668
675
  var claimsToUser = (claims) => {
669
676
  const appMeta = claims.app_metadata ?? {};
670
677
  const userMeta = claims.user_metadata ?? {};
671
- const name = userMeta.full_name || userMeta.name;
678
+ const name = userMeta.full_name ?? userMeta.name;
672
679
  const pictureUrl = userMeta.avatar_url;
673
680
  return {
674
681
  id: claims.sub ?? "",
@@ -740,7 +747,7 @@ var getUser = async () => {
740
747
  }
741
748
  triggerNextjsDynamic();
742
749
  const identityContext = globalThis.netlifyIdentityContext;
743
- const serverJwt = identityContext?.token || getServerCookie(NF_JWT_COOKIE);
750
+ const serverJwt = identityContext?.token ?? getServerCookie(NF_JWT_COOKIE);
744
751
  if (serverJwt) {
745
752
  const identityUrl = resolveIdentityUrl();
746
753
  if (identityUrl) {
@@ -869,7 +876,7 @@ var verifyEmailChange = async (token) => {
869
876
  });
870
877
  if (!res.ok) {
871
878
  const errorBody = await res.json().catch(() => ({}));
872
- throw new AuthError(errorBody.msg || `Email change verification failed (${res.status})`, res.status);
879
+ throw new AuthError(errorBody.msg ?? `Email change verification failed (${String(res.status)})`, res.status);
873
880
  }
874
881
  const userData = await res.json();
875
882
  const user = toUser(userData);
@@ -933,7 +940,10 @@ var adminFetch = async (path, options = {}) => {
933
940
  }
934
941
  if (!res.ok) {
935
942
  const errorBody = await res.json().catch(() => ({}));
936
- throw new AuthError(errorBody.msg || `Admin request failed (${res.status})`, res.status);
943
+ throw new AuthError(
944
+ errorBody.msg ?? `Admin request failed (${String(res.status)})`,
945
+ res.status
946
+ );
937
947
  }
938
948
  return res;
939
949
  };
@@ -1025,4 +1035,3 @@ export {
1025
1035
  verifyEmailChange,
1026
1036
  verifyRequestOrigin
1027
1037
  };
1028
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,44 +1,41 @@
1
1
  {
2
2
  "name": "@netlify/identity",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
- "description": "Headless auth functions for Netlify Identity (not the widget). Import { login, getUser } and call them. No init, no class, no UI.",
6
- "main": "./dist/index.cjs",
7
- "types": "./dist/index.d.ts",
5
+ "engines": {
6
+ "node": ">=18.0.0"
7
+ },
8
+ "description": "Headless auth functions for Netlify Identity. Import { login, getUser } and call them. No init, no class, no UI.",
9
+ "main": "./dist/main.cjs",
10
+ "module": "./dist/main.js",
11
+ "types": "./dist/main.d.ts",
8
12
  "exports": {
9
13
  ".": {
14
+ "require": {
15
+ "types": "./dist/main.d.cts",
16
+ "default": "./dist/main.cjs"
17
+ },
10
18
  "import": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/index.js"
19
+ "types": "./dist/main.d.ts",
20
+ "default": "./dist/main.js"
13
21
  },
14
- "require": {
15
- "types": "./dist/index.d.cts",
16
- "default": "./dist/index.cjs"
22
+ "default": {
23
+ "types": "./dist/main.d.ts",
24
+ "default": "./dist/main.js"
17
25
  }
18
- }
26
+ },
27
+ "./package.json": "./package.json"
19
28
  },
20
29
  "files": [
21
- "dist/**/*.js",
22
- "dist/**/*.cjs",
23
- "dist/**/*.d.ts",
24
- "dist/**/*.d.cts",
25
- "dist/**/*.map"
30
+ "dist/**/*"
26
31
  ],
27
- "engines": {
28
- "node": ">=22"
29
- },
30
32
  "scripts": {
31
- "build": "tsup",
32
- "dev": "tsup --watch",
33
- "test": "vitest run",
34
- "test:watch": "vitest",
35
- "lint": "eslint src test",
36
- "typecheck": "tsc --noEmit",
37
- "format": "prettier --check .",
38
- "format:fix": "prettier --write .",
33
+ "build": "tsup-node",
34
+ "dev": "tsup-node --watch",
39
35
  "prepack": "npm run build",
40
- "prepublishOnly": "npm run test",
41
- "prepare": "husky"
36
+ "test": "vitest run",
37
+ "test:dev": "vitest",
38
+ "publint": "npx -y publint --strict"
42
39
  },
43
40
  "keywords": [
44
41
  "netlify",
@@ -56,26 +53,18 @@
56
53
  "license": "MIT",
57
54
  "repository": {
58
55
  "type": "git",
59
- "url": "https://github.com/netlify/identity.git"
56
+ "url": "https://github.com/netlify/primitives.git",
57
+ "directory": "packages/identity/prod"
60
58
  },
61
59
  "bugs": {
62
- "url": "https://github.com/netlify/identity/issues"
60
+ "url": "https://github.com/netlify/primitives/issues"
63
61
  },
64
62
  "author": "Netlify Inc.",
65
63
  "devDependencies": {
66
64
  "@types/node": "^22.0.0",
67
- "eslint": "^9.0.0",
68
- "husky": "^9.1.7",
69
65
  "jsdom": "^28.1.0",
70
- "lint-staged": "^16.2.7",
71
- "prettier": "^3.0.0",
72
- "tsup": "^8.5.0",
73
- "typescript": "^5.0.0",
74
- "typescript-eslint": "^8.0.0",
75
- "vitest": "^4.0.0"
76
- },
77
- "lint-staged": {
78
- "*.{ts,js,json,md}": "prettier --write"
66
+ "tsup": "^8.0.0",
67
+ "vitest": "^3.0.0"
79
68
  },
80
69
  "dependencies": {
81
70
  "gotrue-js": "^1.0.1"
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Netlify
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.