@c15t/node-sdk 2.2.0 → 3.0.0-alpha.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.
- package/README.md +2 -2
- package/dist/index.js +205 -179
- package/dist/testing.js +61 -45
- package/dist-types/client.d.ts +433 -232
- package/dist-types/endpoints/consent.d.ts +1 -1
- package/dist-types/endpoints/init.d.ts +1 -1
- package/dist-types/endpoints/status.d.ts +1 -1
- package/dist-types/endpoints/subjects.d.ts +4 -4
- package/dist-types/error.d.ts +1 -1
- package/dist-types/fetcher.d.ts +4 -4
- package/dist-types/headers.d.ts +1 -1
- package/dist-types/index.d.ts +1 -1
- package/dist-types/testing.d.ts +5 -26
- package/dist-types/types.d.ts +4 -4
- package/dist-types/version.d.ts +1 -1
- package/package.json +24 -25
- package/readme.json +1 -1
- package/dist/index.cjs +0 -427
- package/dist/testing.cjs +0 -123
package/dist/testing.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
const assignInOrder = Object.assign;
|
|
2
|
+
const testing_createMockResponse = function createMockResponse(data, options = {}) {
|
|
2
3
|
const isSuccess = options.ok ?? true;
|
|
3
4
|
const error = options.error ?? null;
|
|
4
5
|
const response = options.response ?? null;
|
|
5
6
|
return {
|
|
6
7
|
data: isSuccess ? data : null,
|
|
7
8
|
error,
|
|
9
|
+
expect (message) {
|
|
10
|
+
if (!isSuccess || null === data) throw new Error(message);
|
|
11
|
+
return data;
|
|
12
|
+
},
|
|
13
|
+
map (fn) {
|
|
14
|
+
if (!isSuccess || null === data) return createMockResponse(null, {
|
|
15
|
+
error: error ?? void 0,
|
|
16
|
+
ok: false
|
|
17
|
+
});
|
|
18
|
+
return createMockResponse(fn(data));
|
|
19
|
+
},
|
|
8
20
|
ok: isSuccess,
|
|
9
21
|
response,
|
|
10
22
|
unwrap () {
|
|
@@ -14,31 +26,20 @@ function createMockResponse(data, options = {}) {
|
|
|
14
26
|
unwrapOr (defaultValue) {
|
|
15
27
|
if (!isSuccess || null === data) return defaultValue;
|
|
16
28
|
return data;
|
|
17
|
-
},
|
|
18
|
-
expect (message) {
|
|
19
|
-
if (!isSuccess || null === data) throw new Error(message);
|
|
20
|
-
return data;
|
|
21
|
-
},
|
|
22
|
-
map (fn) {
|
|
23
|
-
if (!isSuccess || null === data) return createMockResponse(null, {
|
|
24
|
-
ok: false,
|
|
25
|
-
error: error ?? void 0
|
|
26
|
-
});
|
|
27
|
-
return createMockResponse(fn(data));
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
|
-
}
|
|
31
|
-
function
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
};
|
|
32
|
+
const testing_createMockErrorResponse = function(error) {
|
|
33
|
+
return testing_createMockResponse(null, {
|
|
34
|
+
error,
|
|
35
|
+
ok: false
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
-
function
|
|
38
|
-
const defaultNotImplemented = ()=>
|
|
37
|
+
};
|
|
38
|
+
const testing_createMockClient = function(overrides = {}) {
|
|
39
|
+
const defaultNotImplemented = ()=>testing_createMockErrorResponse({
|
|
40
|
+
code: 'NOT_IMPLEMENTED',
|
|
39
41
|
message: 'Method not implemented in mock',
|
|
40
|
-
status: 501
|
|
41
|
-
code: 'NOT_IMPLEMENTED'
|
|
42
|
+
status: 501
|
|
42
43
|
});
|
|
43
44
|
const status = overrides.status ?? defaultNotImplemented;
|
|
44
45
|
const init = overrides.init ?? defaultNotImplemented;
|
|
@@ -47,33 +48,48 @@ function createMockClient(overrides = {}) {
|
|
|
47
48
|
const getSubject = overrides.getSubject ?? defaultNotImplemented;
|
|
48
49
|
const patchSubject = overrides.patchSubject ?? defaultNotImplemented;
|
|
49
50
|
const listSubjects = overrides.listSubjects ?? defaultNotImplemented;
|
|
50
|
-
return {
|
|
51
|
-
status: ()=>Promise.resolve(status())
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
return assignInOrder({}, {
|
|
52
|
+
status: ()=>Promise.resolve(status())
|
|
53
|
+
}, {
|
|
54
|
+
init: ()=>Promise.resolve(init())
|
|
55
|
+
}, {
|
|
56
|
+
checkConsent: (query)=>Promise.resolve(checkConsent(query))
|
|
57
|
+
}, {
|
|
58
|
+
createSubject: (input)=>Promise.resolve(createSubject(input))
|
|
59
|
+
}, {
|
|
60
|
+
getSubject: (id)=>Promise.resolve(getSubject(id))
|
|
61
|
+
}, {
|
|
62
|
+
patchSubject: (id, input)=>{
|
|
63
|
+
const patchInput = {
|
|
64
|
+
id
|
|
65
|
+
};
|
|
66
|
+
if ('object' == typeof input && null !== input) Object.assign(patchInput, input);
|
|
67
|
+
return Promise.resolve(patchSubject(patchInput));
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
listSubjects: (query)=>Promise.resolve(listSubjects(query))
|
|
71
|
+
}, {
|
|
61
72
|
consent: {
|
|
62
73
|
check: (query)=>Promise.resolve(checkConsent(query))
|
|
63
|
-
}
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
64
76
|
subjects: {
|
|
65
77
|
create: (input)=>Promise.resolve(createSubject(input)),
|
|
66
78
|
get: (id)=>Promise.resolve(getSubject(id)),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
list: (query)=>Promise.resolve(listSubjects(query)),
|
|
80
|
+
patch: (id, input)=>{
|
|
81
|
+
const patchInput = {
|
|
82
|
+
id
|
|
83
|
+
};
|
|
84
|
+
if ('object' == typeof input && null !== input) Object.assign(patchInput, input);
|
|
85
|
+
return Promise.resolve(patchSubject(patchInput));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
73
89
|
meta: {
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
init: ()=>Promise.resolve(init()),
|
|
91
|
+
status: ()=>Promise.resolve(status())
|
|
76
92
|
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
export { createMockClient, createMockErrorResponse, createMockResponse };
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
export { testing_createMockClient as createMockClient, testing_createMockErrorResponse as createMockErrorResponse, testing_createMockResponse as createMockResponse };
|