@c15t/node-sdk 3.0.0-alpha.2 → 3.0.0-alpha.4
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 +53 -45
- package/dist/160.js +68 -0
- package/dist/index.js +1016 -349
- package/dist/testing.js +42 -87
- package/dist-types/client.d.ts +112 -705
- package/dist-types/configuration-error.d.ts +17 -0
- package/dist-types/contract.d.ts +930 -0
- package/dist-types/errors.d.ts +143 -0
- package/dist-types/index.d.ts +13 -40
- package/dist-types/options.d.ts +152 -0
- package/dist-types/path.d.ts +24 -0
- package/dist-types/result.d.ts +77 -0
- package/dist-types/testing.d.ts +81 -90
- package/dist-types/transport.d.ts +19 -0
- package/dist-types/version.d.ts +1 -1
- package/package.json +6 -12
- package/dist-types/endpoints/consent.d.ts +0 -16
- package/dist-types/endpoints/index.d.ts +0 -4
- package/dist-types/endpoints/init.d.ts +0 -15
- package/dist-types/endpoints/status.d.ts +0 -15
- package/dist-types/endpoints/subjects.d.ts +0 -45
- package/dist-types/error.d.ts +0 -85
- package/dist-types/fetcher.d.ts +0 -37
- package/dist-types/headers.d.ts +0 -3
- package/dist-types/types.d.ts +0 -234
package/dist/testing.js
CHANGED
|
@@ -1,95 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const isSuccess = options.ok ?? true;
|
|
4
|
-
const error = options.error ?? null;
|
|
5
|
-
const response = options.response ?? null;
|
|
1
|
+
import { C15tError } from "./160.js";
|
|
2
|
+
const testing_ok = function(data, init = {}) {
|
|
6
3
|
return {
|
|
7
|
-
data
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
},
|
|
20
|
-
ok: isSuccess,
|
|
21
|
-
response,
|
|
22
|
-
unwrap () {
|
|
23
|
-
if (!isSuccess || null === data) throw new Error(error?.message || 'Request failed');
|
|
24
|
-
return data;
|
|
25
|
-
},
|
|
26
|
-
unwrapOr (defaultValue) {
|
|
27
|
-
if (!isSuccess || null === data) return defaultValue;
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
4
|
+
data,
|
|
5
|
+
headers: new Headers(init.headers),
|
|
6
|
+
ok: true,
|
|
7
|
+
requestId: init.requestId ?? 'mock-request-id',
|
|
8
|
+
status: init.status ?? 200
|
|
30
9
|
};
|
|
31
10
|
};
|
|
32
|
-
const
|
|
33
|
-
return
|
|
34
|
-
error
|
|
11
|
+
const testing_err = function(code, init = {}) {
|
|
12
|
+
return {
|
|
13
|
+
error: new C15tError({
|
|
14
|
+
code,
|
|
15
|
+
issues: init.issues,
|
|
16
|
+
message: init.message ?? `Mock ${code} error.`,
|
|
17
|
+
reason: init.reason,
|
|
18
|
+
requestId: init.requestId ?? 'mock-request-id',
|
|
19
|
+
retryable: init.retryable,
|
|
20
|
+
serverCode: init.serverCode,
|
|
21
|
+
status: init.status
|
|
22
|
+
}),
|
|
35
23
|
ok: false
|
|
36
|
-
}
|
|
24
|
+
};
|
|
37
25
|
};
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
}, {
|
|
72
|
-
consent: {
|
|
73
|
-
check: (query)=>Promise.resolve(checkConsent(query))
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
26
|
+
const missing = (name)=>()=>Promise.reject(new Error(`createMockC15tClient: ${name} was called but has no handler. Pass one in the handlers object.`));
|
|
27
|
+
const bind = (name, handler)=>void 0 === handler ? missing(name) : async (...args)=>await handler(...args);
|
|
28
|
+
const testing_createMockC15tClient = function(handlers = {}) {
|
|
29
|
+
return {
|
|
30
|
+
consents: {
|
|
31
|
+
check: bind('consents.check', handlers.consents?.check)
|
|
32
|
+
},
|
|
33
|
+
experiments: {
|
|
34
|
+
summary: bind('experiments.summary', handlers.experiments?.summary)
|
|
35
|
+
},
|
|
36
|
+
init: bind('init', handlers.init),
|
|
37
|
+
legalDocuments: {
|
|
38
|
+
publish: bind('legalDocuments.publish', handlers.legalDocuments?.publish)
|
|
39
|
+
},
|
|
40
|
+
manifest: bind('manifest', handlers.manifest),
|
|
41
|
+
status: bind('status', handlers.status),
|
|
76
42
|
subjects: {
|
|
77
|
-
create: (
|
|
78
|
-
get: (
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
}, {
|
|
89
|
-
meta: {
|
|
90
|
-
init: ()=>Promise.resolve(init()),
|
|
91
|
-
status: ()=>Promise.resolve(status())
|
|
43
|
+
create: bind('subjects.create', handlers.subjects?.create),
|
|
44
|
+
get: bind('subjects.get', handlers.subjects?.get),
|
|
45
|
+
identify: bind('subjects.identify', handlers.subjects?.identify),
|
|
46
|
+
list: bind('subjects.list', handlers.subjects?.list)
|
|
92
47
|
}
|
|
93
|
-
}
|
|
48
|
+
};
|
|
94
49
|
};
|
|
95
|
-
export {
|
|
50
|
+
export { testing_createMockC15tClient as createMockC15tClient, testing_err as err, testing_ok as ok };
|