@c7-digital/ledger 0.0.6 → 0.0.8
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 +3 -3
- package/lib/src/api-surface.test.d.ts +1 -0
- package/lib/src/api-surface.test.js +183 -0
- package/lib/src/generated/asyncapi-schema.d.ts +1 -1
- package/lib/src/generated/asyncapi-schema.js +2 -2
- package/lib/src/generated/openapi-schema.d.ts +1 -1
- package/lib/src/generated/openapi-schema.js +2 -2
- package/lib/src/generated/sdk-version.d.ts +1 -1
- package/lib/src/generated/sdk-version.js +2 -2
- package/lib/src/validation.d.ts +5 -0
- package/lib/src/validation.js +76 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-lite/src/api-surface.test.d.ts +1 -0
- package/lib-lite/src/api-surface.test.js +183 -0
- package/lib-lite/src/generated/sdk-version.d.ts +1 -1
- package/lib-lite/src/generated/sdk-version.js +2 -2
- package/lib-lite/tsconfig.temp.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Surface Tests
|
|
3
|
+
*
|
|
4
|
+
* These tests verify the public API contract of the ledger package.
|
|
5
|
+
* They are designed to catch breaking changes during SDK version upgrades
|
|
6
|
+
* by asserting exports, method signatures, generated type shapes, and branded types.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import * as LedgerPackage from "./index.js";
|
|
12
|
+
import { Ledger } from "./ledger.js";
|
|
13
|
+
import { TypedHttpClient } from "./client.js";
|
|
14
|
+
import { WebSocketClient } from "./websocket.js";
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
16
|
+
const __dirname = path.dirname(__filename);
|
|
17
|
+
// Valid JWT token for testing with sub field
|
|
18
|
+
// Header: {"alg":"HS256","typ":"JWT"}
|
|
19
|
+
// Payload: {"sub":"test-user","iat":1516239022}
|
|
20
|
+
const TEST_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJpYXQiOjE1MTYyMzkwMjJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
|
|
21
|
+
describe("Public API surface", () => {
|
|
22
|
+
// Classes
|
|
23
|
+
it.each([
|
|
24
|
+
"Ledger",
|
|
25
|
+
"TypedHttpClient",
|
|
26
|
+
"WebSocketClient",
|
|
27
|
+
"ConsoleLogger",
|
|
28
|
+
"NoOpLogger",
|
|
29
|
+
])("exports class %s", (name) => {
|
|
30
|
+
expect(typeof LedgerPackage[name]).toBe("function");
|
|
31
|
+
});
|
|
32
|
+
// Functions
|
|
33
|
+
it.each([
|
|
34
|
+
"createCmd",
|
|
35
|
+
"createAndExerciseCmd",
|
|
36
|
+
"exerciseCmd",
|
|
37
|
+
"setLogger",
|
|
38
|
+
])("exports function %s", (name) => {
|
|
39
|
+
expect(typeof LedgerPackage[name]).toBe("function");
|
|
40
|
+
});
|
|
41
|
+
// Objects
|
|
42
|
+
it.each([
|
|
43
|
+
"logger",
|
|
44
|
+
"ValueStringValidators",
|
|
45
|
+
"ValueStringCreators",
|
|
46
|
+
])("exports object %s", (name) => {
|
|
47
|
+
expect(typeof LedgerPackage[name]).toBe("object");
|
|
48
|
+
});
|
|
49
|
+
// Constants
|
|
50
|
+
it("exports SDK_VERSION as a string", () => {
|
|
51
|
+
expect(typeof LedgerPackage.SDK_VERSION).toBe("string");
|
|
52
|
+
});
|
|
53
|
+
// Validator functions
|
|
54
|
+
it.each([
|
|
55
|
+
"isValidNameString",
|
|
56
|
+
"isValidPackageIdString",
|
|
57
|
+
"isValidPartyIdString",
|
|
58
|
+
"isValidLedgerString",
|
|
59
|
+
"isValidUserIdString",
|
|
60
|
+
])("exports validator function %s", (name) => {
|
|
61
|
+
expect(typeof LedgerPackage[name]).toBe("function");
|
|
62
|
+
});
|
|
63
|
+
// Creator functions
|
|
64
|
+
it.each([
|
|
65
|
+
"createNameString",
|
|
66
|
+
"createPackageIdString",
|
|
67
|
+
"createPartyIdString",
|
|
68
|
+
"createLedgerString",
|
|
69
|
+
"createUserIdString",
|
|
70
|
+
])("exports creator function %s", (name) => {
|
|
71
|
+
expect(typeof LedgerPackage[name]).toBe("function");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
describe("Generated type structure", () => {
|
|
75
|
+
// These tests use compile-time type assertions. If a schema property is
|
|
76
|
+
// removed or renamed, the TypeScript compiler (via ts-jest) will fail here.
|
|
77
|
+
it("CreatedEvent has expected properties", () => {
|
|
78
|
+
const keys = [
|
|
79
|
+
"offset",
|
|
80
|
+
"nodeId",
|
|
81
|
+
"contractId",
|
|
82
|
+
"templateId",
|
|
83
|
+
];
|
|
84
|
+
// Compile-time check passes if the above compiles; runtime sanity:
|
|
85
|
+
expect(keys).toEqual(["offset", "nodeId", "contractId", "templateId"]);
|
|
86
|
+
});
|
|
87
|
+
it("ArchivedEvent has expected properties", () => {
|
|
88
|
+
const keys = [
|
|
89
|
+
"offset",
|
|
90
|
+
"nodeId",
|
|
91
|
+
"contractId",
|
|
92
|
+
"templateId",
|
|
93
|
+
];
|
|
94
|
+
expect(keys).toEqual(["offset", "nodeId", "contractId", "templateId"]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe("Branded type verification", () => {
|
|
98
|
+
const apiFilePath = path.resolve(__dirname, "generated/api.ts");
|
|
99
|
+
const asyncApiFilePath = path.resolve(__dirname, "generated/async-api.ts");
|
|
100
|
+
let apiContent;
|
|
101
|
+
let asyncApiContent;
|
|
102
|
+
beforeAll(() => {
|
|
103
|
+
apiContent = fs.readFileSync(apiFilePath, "utf-8");
|
|
104
|
+
asyncApiContent = fs.readFileSync(asyncApiFilePath, "utf-8");
|
|
105
|
+
});
|
|
106
|
+
it("api.ts starts with branded type imports", () => {
|
|
107
|
+
expect(apiContent).toMatch(/^import \{ LedgerString, PartyIdString, UserIdString, NameString, PackageIdString \} from "/././valueTypes/.js"/);
|
|
108
|
+
});
|
|
109
|
+
it("async-api.ts starts with branded type imports", () => {
|
|
110
|
+
expect(asyncApiContent).toMatch(/^import \{ LedgerString, PartyIdString, UserIdString, NameString, PackageIdString \} from "/././valueTypes/.js"/);
|
|
111
|
+
});
|
|
112
|
+
it.each([
|
|
113
|
+
["contractId: LedgerString", /contractId:\s*LedgerString/],
|
|
114
|
+
["templateId: PackageIdString", /templateId:\s*PackageIdString/],
|
|
115
|
+
["userId: UserIdString", /userId:\s*UserIdString/],
|
|
116
|
+
["choice: NameString", /choice:\s*NameString/],
|
|
117
|
+
["partyIdHint: PartyIdString", /partyIdHint:\s*PartyIdString/],
|
|
118
|
+
])("api.ts uses branded type for %s", (_label, pattern) => {
|
|
119
|
+
expect(apiContent).toMatch(pattern);
|
|
120
|
+
});
|
|
121
|
+
it.each([
|
|
122
|
+
["contractId: LedgerString", /contractId:\s*LedgerString/],
|
|
123
|
+
["templateId: PackageIdString", /templateId:\s*PackageIdString/],
|
|
124
|
+
["userId: UserIdString", /userId:\s*UserIdString/],
|
|
125
|
+
["choice: NameString", /choice:\s*NameString/],
|
|
126
|
+
])("async-api.ts uses branded type for %s", (_label, pattern) => {
|
|
127
|
+
expect(asyncApiContent).toMatch(pattern);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe("Ledger method contract", () => {
|
|
131
|
+
const ledger = new Ledger({
|
|
132
|
+
token: TEST_TOKEN,
|
|
133
|
+
httpBaseUrl: "http://localhost:7575",
|
|
134
|
+
});
|
|
135
|
+
it.each([
|
|
136
|
+
"getTokenUserId",
|
|
137
|
+
"getTokenUserInfo",
|
|
138
|
+
"getTokenActAsParties",
|
|
139
|
+
"query",
|
|
140
|
+
"queryInterface",
|
|
141
|
+
"create",
|
|
142
|
+
"exercise",
|
|
143
|
+
"submit",
|
|
144
|
+
"streamQuery",
|
|
145
|
+
"streamQueryInterface",
|
|
146
|
+
"createMultiStream",
|
|
147
|
+
"createMultiInterfaceStream",
|
|
148
|
+
"getUserInfo",
|
|
149
|
+
"getParties",
|
|
150
|
+
"allocateParty",
|
|
151
|
+
])("Ledger.prototype has method %s", (method) => {
|
|
152
|
+
expect(typeof ledger[method]).toBe("function");
|
|
153
|
+
});
|
|
154
|
+
it.each([
|
|
155
|
+
"submitAndWait",
|
|
156
|
+
"submitAndWaitForTransaction",
|
|
157
|
+
"getParties",
|
|
158
|
+
"getUserInfo",
|
|
159
|
+
"getUserRights",
|
|
160
|
+
"queryActiveContracts",
|
|
161
|
+
"allocateParty",
|
|
162
|
+
"getLedgerEnd",
|
|
163
|
+
])("TypedHttpClient.prototype has method %s", (method) => {
|
|
164
|
+
expect(typeof TypedHttpClient.prototype[method]).toBe("function");
|
|
165
|
+
});
|
|
166
|
+
it.each([
|
|
167
|
+
"getToken",
|
|
168
|
+
"setToken",
|
|
169
|
+
"streamCompletions",
|
|
170
|
+
"streamActiveContracts",
|
|
171
|
+
"streamUpdates",
|
|
172
|
+
])("WebSocketClient.prototype has method %s", (method) => {
|
|
173
|
+
expect(typeof WebSocketClient.prototype[method]).toBe("function");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe("SDK version", () => {
|
|
177
|
+
it("SDK_VERSION equals 3.4.9", () => {
|
|
178
|
+
expect(LedgerPackage.SDK_VERSION).toBe("3.4.9");
|
|
179
|
+
});
|
|
180
|
+
it("SDK_VERSION matches semver pattern", () => {
|
|
181
|
+
expect(LedgerPackage.SDK_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "3.4.
|
|
1
|
+
export declare const SDK_VERSION = "3.4.9";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Auto-generated file - do not edit manually
|
|
2
|
-
// Generated from SDK version: 3.4.
|
|
3
|
-
export const SDK_VERSION = "3.4.
|
|
2
|
+
// Generated from SDK version: 3.4.9
|
|
3
|
+
export const SDK_VERSION = "3.4.9";
|