@sanity/sdk 2.11.0 → 2.12.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.
Files changed (57) hide show
  1. package/dist/_chunks-dts/utils.d.ts +171 -19
  2. package/dist/_chunks-es/_internal.js +41 -26
  3. package/dist/_chunks-es/_internal.js.map +1 -1
  4. package/dist/_chunks-es/createGroqSearchFilter.js +25 -9
  5. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
  6. package/dist/_chunks-es/telemetryManager.js +25 -19
  7. package/dist/_chunks-es/telemetryManager.js.map +1 -1
  8. package/dist/_chunks-es/version.js +1 -1
  9. package/dist/_exports/_internal.d.ts +27 -11
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +723 -418
  12. package/dist/index.js.map +1 -1
  13. package/package.json +16 -16
  14. package/src/_exports/index.ts +23 -2
  15. package/src/auth/refreshStampedToken.test.ts +2 -2
  16. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +116 -0
  17. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +27 -9
  18. package/src/config/sanityConfig.ts +12 -0
  19. package/src/document/actions.test.ts +112 -1
  20. package/src/document/actions.ts +148 -1
  21. package/src/document/applyDocumentActions.ts +4 -3
  22. package/src/document/documentStore.ts +7 -6
  23. package/src/document/events.test.ts +57 -2
  24. package/src/document/events.ts +43 -24
  25. package/src/document/permissions.ts +1 -1
  26. package/src/document/processActions/create.ts +135 -0
  27. package/src/document/processActions/delete.ts +100 -0
  28. package/src/document/processActions/discard.ts +63 -0
  29. package/src/document/processActions/edit.ts +141 -0
  30. package/src/document/processActions/processActions.ts +209 -0
  31. package/src/document/processActions/publish.ts +120 -0
  32. package/src/document/processActions/releaseArchive.ts +77 -0
  33. package/src/document/processActions/releaseCreate.ts +59 -0
  34. package/src/document/processActions/releaseDelete.ts +65 -0
  35. package/src/document/processActions/releaseEdit.ts +36 -0
  36. package/src/document/processActions/releasePublish.ts +45 -0
  37. package/src/document/processActions/releaseSchedule.ts +87 -0
  38. package/src/document/processActions/releaseUtil.ts +31 -0
  39. package/src/document/processActions/shared.ts +139 -0
  40. package/src/document/processActions/unpublish.ts +85 -0
  41. package/src/document/processActions.test.ts +424 -2
  42. package/src/document/reducers.ts +41 -6
  43. package/src/releases/getPerspectiveState.test.ts +1 -1
  44. package/src/releases/releasesStore.test.ts +50 -1
  45. package/src/releases/releasesStore.ts +41 -18
  46. package/src/releases/utils/sortReleases.test.ts +2 -2
  47. package/src/releases/utils/sortReleases.ts +1 -1
  48. package/src/telemetry/environment.test.ts +119 -0
  49. package/src/telemetry/environment.ts +92 -0
  50. package/src/telemetry/{__telemetry__/sdk.telemetry.ts → events.ts} +9 -9
  51. package/src/telemetry/initTelemetry.test.ts +240 -16
  52. package/src/telemetry/initTelemetry.ts +39 -16
  53. package/src/telemetry/telemetryManager.test.ts +129 -65
  54. package/src/telemetry/telemetryManager.ts +41 -29
  55. package/src/document/processActions.ts +0 -735
  56. package/src/telemetry/devMode.test.ts +0 -60
  57. package/src/telemetry/devMode.ts +0 -41
@@ -1,60 +0,0 @@
1
- import {afterEach, describe, expect, it, vi} from 'vitest'
2
-
3
- import {isDevMode} from './devMode'
4
-
5
- describe('isDevMode', () => {
6
- afterEach(() => {
7
- vi.unstubAllEnvs()
8
- vi.unstubAllGlobals()
9
- })
10
-
11
- it('returns false when NODE_ENV is production', () => {
12
- vi.stubEnv('NODE_ENV', 'production')
13
- vi.stubGlobal('window', undefined)
14
- expect(isDevMode()).toBe(false)
15
- })
16
-
17
- it('returns true when running on localhost', () => {
18
- vi.stubEnv('NODE_ENV', 'development')
19
- vi.stubGlobal('window', {
20
- location: {href: 'http://localhost:3000/'},
21
- })
22
- expect(isDevMode()).toBe(true)
23
- })
24
-
25
- it('returns true when running on 127.0.0.1', () => {
26
- vi.stubEnv('NODE_ENV', 'development')
27
- vi.stubGlobal('window', {
28
- location: {href: 'http://127.0.0.1:3000/'},
29
- })
30
- expect(isDevMode()).toBe(true)
31
- })
32
-
33
- it('returns true on localhost even when NODE_ENV is production', () => {
34
- vi.stubEnv('NODE_ENV', 'production')
35
- vi.stubGlobal('window', {
36
- location: {href: 'http://localhost:3000/'},
37
- })
38
- expect(isDevMode()).toBe(true)
39
- })
40
-
41
- it('returns false for a non-local URL', () => {
42
- vi.stubEnv('NODE_ENV', 'test')
43
- vi.stubGlobal('window', {
44
- location: {href: 'https://myapp.sanity.studio/'},
45
- })
46
- expect(isDevMode()).toBe(false)
47
- })
48
-
49
- it('returns true when NODE_ENV is development and no window', () => {
50
- vi.stubEnv('NODE_ENV', 'development')
51
- vi.stubGlobal('window', undefined)
52
- expect(isDevMode()).toBe(true)
53
- })
54
-
55
- it('returns false when NODE_ENV is test and no window', () => {
56
- vi.stubEnv('NODE_ENV', 'test')
57
- vi.stubGlobal('window', undefined)
58
- expect(isDevMode()).toBe(false)
59
- })
60
- })
@@ -1,41 +0,0 @@
1
- /**
2
- * Checks whether the current URL points to a local development server.
3
- *
4
- * @param win - The window object to check
5
- * @returns True if running on localhost or 127.0.0.1
6
- * @internal
7
- */
8
- function isLocalUrl(win: Window): boolean {
9
- const url = win.location?.href
10
- if (!url) return false
11
- return (
12
- url.startsWith('http://localhost') ||
13
- url.startsWith('https://localhost') ||
14
- url.startsWith('http://127.0.0.1') ||
15
- url.startsWith('https://127.0.0.1')
16
- )
17
- }
18
-
19
- /**
20
- * Determines whether the SDK should enable dev-mode telemetry for the
21
- * SDK consumer (i.e. a developer building an app with `@sanity/sdk`).
22
- *
23
- * Browser: returns true only when the URL is `localhost` or `127.0.0.1`.
24
- * The URL check is the primary signal because consumer bundlers may or
25
- * may not forward `NODE_ENV` to the browser reliably.
26
- *
27
- * Node (scripts / non-browser): falls back to `NODE_ENV === 'development'`.
28
- *
29
- * Bracket-notation `process.env['NODE_ENV']` is used to avoid bundler
30
- * dead-code replacement.
31
- *
32
- * @returns True if the SDK is running in a development environment
33
- * @internal
34
- */
35
- export function isDevMode(): boolean {
36
- if (typeof window !== 'undefined') {
37
- return isLocalUrl(window)
38
- }
39
-
40
- return typeof process !== 'undefined' && process.env?.['NODE_ENV'] === 'development'
41
- }