@veramo/url-handler 7.0.1 → 7.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"message-handler.d.ts","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAOzE;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAAsB;IACrD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAkC7E"}
1
+ {"version":3,"file":"message-handler.d.ts","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAOzE;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAAsB;IACrD,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAiC3E;CACF"}
package/package.json CHANGED
@@ -1,22 +1,21 @@
1
1
  {
2
2
  "name": "@veramo/url-handler",
3
3
  "description": "Veramo message handler plugin to decode URL messages.",
4
- "version": "7.0.1",
4
+ "version": "7.0.2",
5
5
  "main": "build/index.js",
6
6
  "exports": "./build/index.js",
7
7
  "types": "build/index.d.ts",
8
8
  "dependencies": {
9
+ "@veramo/core-types": "^7.0.2",
10
+ "@veramo/message-handler": "^7.0.2",
9
11
  "cross-fetch": "^4.0.0",
10
12
  "debug": "^4.3.3",
11
- "url-parse": "^1.5.4",
12
- "@veramo/core-types": "^7.0.1",
13
- "@veramo/message-handler": "^7.0.1"
13
+ "url-parse": "^1.5.4"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/debug": "4.1.8",
17
17
  "@types/url-parse": "1.4.8",
18
- "jest-fetch-mock": "3.0.3",
19
- "typescript": "5.7.3"
18
+ "typescript": "7.0.2"
20
19
  },
21
20
  "files": [
22
21
  "build/**/*",
@@ -1,17 +1,30 @@
1
- import { Message } from '../../../message-handler/src'
1
+ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
2
+
3
+ import { Message } from '../../../message-handler/src/index.js'
2
4
  import { UrlMessageHandler } from '../message-handler.js'
3
- import fetchMock, { MockParams } from 'jest-fetch-mock'
5
+ import { IAgentContext } from "../../../core-types/src/index.js";
4
6
 
5
- fetchMock.enableMocks()
6
- import { jest } from '@jest/globals'
7
- import { IAgentContext } from "../../../core-types/src";
7
+ // jest-fetch-mock replacement: use a vitest-native fetch mock.
8
+ // The source (url-handler) calls the global `fetch(url)` and reads
9
+ // response.url (redirect) and response.text() (body), so each test stubs the
10
+ // global `fetch` with a minimal Response-like object. jest-fetch-mock's
11
+ // `counter: 1` meant "consume this response once"; we replicate that by setting
12
+ // the implementation per test and restoring the global in afterEach.
13
+ const fetchMock = vi.fn()
14
+ beforeEach(() => {
15
+ vi.stubGlobal('fetch', fetchMock)
16
+ })
17
+ afterEach(() => {
18
+ vi.unstubAllGlobals()
19
+ fetchMock.mockReset()
20
+ })
8
21
 
9
22
  const context = {
10
23
  agent: {
11
- execute: jest.fn(),
12
- availableMethods: jest.fn(),
13
- getSchema: jest.fn(),
14
- emit: jest.fn(),
24
+ execute: vi.fn(),
25
+ availableMethods: vi.fn(),
26
+ getSchema: vi.fn(),
27
+ emit: vi.fn(),
15
28
  },
16
29
  } as IAgentContext<{}>
17
30
 
@@ -40,7 +53,12 @@ describe('@veramo/url-handler', () => {
40
53
 
41
54
  it('should try to load data from URL if URL is not standard', async () => {
42
55
  const message = new Message({ raw: 'https://example.com/public-profile.jwt' })
43
- fetchMock.mockResponse('mockbody')
56
+ fetchMock.mockImplementation(() =>
57
+ Promise.resolve({
58
+ url: 'https://example.com/public-profile.jwt',
59
+ text: async () => 'mockbody',
60
+ } as any),
61
+ )
44
62
  expect.assertions(2)
45
63
 
46
64
  await expect(messageHandler.handle(message, context)).rejects.toThrow('Unsupported message type')
@@ -50,10 +68,12 @@ describe('@veramo/url-handler', () => {
50
68
 
51
69
  it('should try to load data from redirected URL query', async () => {
52
70
  const message = new Message({ raw: 'https://example.com/public-profile.jwt' })
53
- fetchMock.mockResponse('mockbody', {
54
- counter: 1,
55
- url: 'https://some.other.site.example.com?c_i=asdf',
56
- } as MockParams)
71
+ fetchMock.mockImplementation(() =>
72
+ Promise.resolve({
73
+ url: 'https://some.other.site.example.com?c_i=asdf',
74
+ text: async () => 'mockbody',
75
+ } as any),
76
+ )
57
77
  expect.assertions(2)
58
78
 
59
79
  await expect(messageHandler.handle(message, context)).rejects.toThrow('Unsupported message type')
@@ -63,10 +83,12 @@ describe('@veramo/url-handler', () => {
63
83
 
64
84
  it('should try to load data from redirected URL body', async () => {
65
85
  const message = new Message({ raw: 'https://example.com/public-profile.jwt' })
66
- fetchMock.mockResponse('otherbody', {
67
- counter: 1,
68
- url: 'https://some.other.example.com/cred.jwt',
69
- } as MockParams)
86
+ fetchMock.mockImplementation(() =>
87
+ Promise.resolve({
88
+ url: 'https://some.other.example.com/cred.jwt',
89
+ text: async () => 'otherbody',
90
+ } as any),
91
+ )
70
92
  expect.assertions(2)
71
93
 
72
94
  await expect(messageHandler.handle(message, context)).rejects.toThrow('Unsupported message type')