@btps/sdk 0.0.0-stage → 1.1.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/CHANGELOG.md +149 -0
- package/LICENSE +190 -0
- package/NOTICE +25 -0
- package/README.md +261 -2
- package/dist/client/btpsAgent.d.ts +20 -0
- package/dist/client/btpsAgent.js +172 -0
- package/dist/client/btpsClient.d.ts +202 -0
- package/dist/client/btpsClient.js +602 -0
- package/dist/client/btpsTransporter.d.ts +52 -0
- package/dist/client/btpsTransporter.js +249 -0
- package/dist/client/constants.ts/index.d.ts +11 -0
- package/dist/client/constants.ts/index.js +20 -0
- package/dist/client/index.d.ts +12 -0
- package/dist/client/index.js +27 -0
- package/dist/client/libs/schema.d.ts +27604 -0
- package/dist/client/libs/schema.js +56 -0
- package/dist/client/libs/timeouts.d.ts +22 -0
- package/dist/client/libs/timeouts.js +19 -0
- package/dist/client/types/index.d.ts +155 -0
- package/dist/client/types/index.js +7 -0
- package/dist/core/authentication/BtpsAuthentication.d.ts +128 -0
- package/dist/core/authentication/BtpsAuthentication.js +293 -0
- package/dist/core/authentication/index.d.ts +11 -0
- package/dist/core/authentication/index.js +12 -0
- package/dist/core/authentication/keyProof.d.ts +18 -0
- package/dist/core/authentication/keyProof.js +16 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.d.ts +55 -0
- package/dist/core/authentication/storage/InMemoryAuthSessionStore.js +62 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.d.ts +63 -0
- package/dist/core/authentication/storage/InMemoryTokenStore.js +63 -0
- package/dist/core/authentication/types.d.ts +135 -0
- package/dist/core/authentication/types.js +7 -0
- package/dist/core/crypto/decryptVerify.d.ts +9 -0
- package/dist/core/crypto/decryptVerify.js +45 -0
- package/dist/core/crypto/decrypter-interface.d.ts +25 -0
- package/dist/core/crypto/decrypter-interface.js +7 -0
- package/dist/core/crypto/index.d.ts +77 -0
- package/dist/core/crypto/index.js +210 -0
- package/dist/core/crypto/jcs.d.ts +28 -0
- package/dist/core/crypto/jcs.js +60 -0
- package/dist/core/crypto/keygen.d.ts +9 -0
- package/dist/core/crypto/keygen.js +35 -0
- package/dist/core/crypto/pem-decrypter.d.ts +26 -0
- package/dist/core/crypto/pem-decrypter.js +52 -0
- package/dist/core/crypto/pem-signer.d.ts +21 -0
- package/dist/core/crypto/pem-signer.js +34 -0
- package/dist/core/crypto/signEncrypt.d.ts +34 -0
- package/dist/core/crypto/signEncrypt.js +75 -0
- package/dist/core/crypto/signer-interface.d.ts +22 -0
- package/dist/core/crypto/signer-interface.js +7 -0
- package/dist/core/crypto/types.d.ts +79 -0
- package/dist/core/crypto/types.js +7 -0
- package/dist/core/delegation/BtpsDelegator.d.ts +102 -0
- package/dist/core/delegation/BtpsDelegator.js +118 -0
- package/dist/core/delegation/index.d.ts +7 -0
- package/dist/core/delegation/index.js +8 -0
- package/dist/core/error/constant.d.ts +66 -0
- package/dist/core/error/constant.js +194 -0
- package/dist/core/error/index.d.ts +35 -0
- package/dist/core/error/index.js +52 -0
- package/dist/core/error/types.d.ts +16 -0
- package/dist/core/error/types.js +7 -0
- package/dist/core/server/constants/btps-protocol.d.ts +17 -0
- package/dist/core/server/constants/btps-protocol.js +25 -0
- package/dist/core/server/constants/control.d.ts +7 -0
- package/dist/core/server/constants/control.js +11 -0
- package/dist/core/server/constants/currency.d.ts +7 -0
- package/dist/core/server/constants/currency.js +332 -0
- package/dist/core/server/constants/index.d.ts +26 -0
- package/dist/core/server/constants/index.js +61 -0
- package/dist/core/server/constants/limits.d.ts +50 -0
- package/dist/core/server/constants/limits.js +50 -0
- package/dist/core/server/helpers/BtpsMessageQueue.d.ts +13 -0
- package/dist/core/server/helpers/BtpsMessageQueue.js +12 -0
- package/dist/core/server/helpers/InMemoryQueue.d.ts +16 -0
- package/dist/core/server/helpers/InMemoryQueue.js +35 -0
- package/dist/core/server/helpers/index.d.ts +8 -0
- package/dist/core/server/helpers/index.js +9 -0
- package/dist/core/server/schemas/artifacts/agentSchema.d.ts +4565 -0
- package/dist/core/server/schemas/artifacts/agentSchema.js +51 -0
- package/dist/core/server/schemas/artifacts/artifacts.d.ts +4920 -0
- package/dist/core/server/schemas/artifacts/artifacts.js +21 -0
- package/dist/core/server/schemas/artifacts/controlSchema.d.ts +23 -0
- package/dist/core/server/schemas/artifacts/controlSchema.js +18 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.d.ts +32 -0
- package/dist/core/server/schemas/artifacts/identityLookupSchema.js +21 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.d.ts +553 -0
- package/dist/core/server/schemas/artifacts/transporterSchema.js +60 -0
- package/dist/core/server/schemas/btpsDocsSchema.d.ts +4519 -0
- package/dist/core/server/schemas/btpsDocsSchema.js +272 -0
- package/dist/core/server/schemas/helpers.d.ts +1612 -0
- package/dist/core/server/schemas/helpers.js +87 -0
- package/dist/core/server/schemas/responseSchema.d.ts +6918 -0
- package/dist/core/server/schemas/responseSchema.js +86 -0
- package/dist/core/server/schemas/schema.d.ts +4916 -0
- package/dist/core/server/schemas/schema.js +70 -0
- package/dist/core/server/schemas/shared.d.ts +21 -0
- package/dist/core/server/schemas/shared.js +18 -0
- package/dist/core/server/types.d.ts +172 -0
- package/dist/core/server/types.js +7 -0
- package/dist/core/storage/AbstractIdentityStore.d.ts +17 -0
- package/dist/core/storage/AbstractIdentityStore.js +13 -0
- package/dist/core/storage/AbstractStorageStore.d.ts +16 -0
- package/dist/core/storage/AbstractStorageStore.js +17 -0
- package/dist/core/storage/JsonIdentityStore.d.ts +29 -0
- package/dist/core/storage/JsonIdentityStore.js +39 -0
- package/dist/core/storage/JsonStorageStore.d.ts +59 -0
- package/dist/core/storage/JsonStorageStore.js +110 -0
- package/dist/core/storage/index.d.ts +11 -0
- package/dist/core/storage/index.js +18 -0
- package/dist/core/storage/types.d.ts +28 -0
- package/dist/core/storage/types.js +7 -0
- package/dist/core/trust/index.d.ts +10 -0
- package/dist/core/trust/index.js +15 -0
- package/dist/core/trust/storage/AbstractTrustStore.d.ts +23 -0
- package/dist/core/trust/storage/AbstractTrustStore.js +13 -0
- package/dist/core/trust/storage/JsonTrustStore.d.ts +33 -0
- package/dist/core/trust/storage/JsonTrustStore.js +42 -0
- package/dist/core/trust/trustUtils.d.ts +78 -0
- package/dist/core/trust/trustUtils.js +41 -0
- package/dist/core/trust/types.d.ts +53 -0
- package/dist/core/trust/types.js +7 -0
- package/dist/core/utils/identity.d.ts +20 -0
- package/dist/core/utils/identity.js +22 -0
- package/dist/core/utils/index.d.ts +70 -0
- package/dist/core/utils/index.js +124 -0
- package/dist/core/utils/types.d.ts +10 -0
- package/dist/core/utils/types.js +7 -0
- package/dist/core/utils/validation.d.ts +14 -0
- package/dist/core/utils/validation.js +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/server/btpsServer.d.ts +292 -0
- package/dist/server/btpsServer.js +827 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +15 -0
- package/dist/server/libs/abstractRateLimiter.d.ts +10 -0
- package/dist/server/libs/abstractRateLimiter.js +15 -0
- package/dist/server/libs/artifactSizeGuard.d.ts +27 -0
- package/dist/server/libs/artifactSizeGuard.js +44 -0
- package/dist/server/libs/artifactTimeWindow.d.ts +24 -0
- package/dist/server/libs/artifactTimeWindow.js +30 -0
- package/dist/server/libs/btpsFactory.d.ts +29 -0
- package/dist/server/libs/btpsFactory.js +49 -0
- package/dist/server/libs/btpsLightweightFactory.d.ts +35 -0
- package/dist/server/libs/btpsLightweightFactory.js +37 -0
- package/dist/server/libs/btpsRegistry.d.ts +14 -0
- package/dist/server/libs/btpsRegistry.js +16 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.d.ts +13 -0
- package/dist/server/libs/btpsSimpleMetricsTracker.js +21 -0
- package/dist/server/libs/btpsSimpleRateLimiter.d.ts +28 -0
- package/dist/server/libs/btpsSimpleRateLimiter.js +46 -0
- package/dist/server/libs/connectionTimeout.d.ts +16 -0
- package/dist/server/libs/connectionTimeout.js +14 -0
- package/dist/server/libs/defaultMiddleware.d.ts +8 -0
- package/dist/server/libs/defaultMiddleware.js +128 -0
- package/dist/server/libs/inFlightLimit.d.ts +18 -0
- package/dist/server/libs/inFlightLimit.js +17 -0
- package/dist/server/libs/index.d.ts +18 -0
- package/dist/server/libs/index.js +34 -0
- package/dist/server/libs/middlewareManager.d.ts +59 -0
- package/dist/server/libs/middlewareManager.js +126 -0
- package/dist/server/libs/type.d.ts +22 -0
- package/dist/server/libs/type.js +7 -0
- package/dist/server/types.d.ts +236 -0
- package/dist/server/types.js +7 -0
- package/package.json +126 -4
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2025 Bhupendra Tamang
|
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
|
5
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { BtpSignatureSchema, BtpEncryptionSchema } from "./schema.js";
|
|
10
|
+
import { identitySchema } from "./shared.js";
|
|
11
|
+
import { BtpAuthResDocSchema, BtpIdentityResDocSchema } from "./btpsDocsSchema.js";
|
|
12
|
+
import { BtpTransporterArtifactSchema } from "./artifacts/transporterSchema.js";
|
|
13
|
+
const BtpStatusSchema = z.object({
|
|
14
|
+
ok: z.boolean(),
|
|
15
|
+
code: z.number(),
|
|
16
|
+
message: z.string().optional(),
|
|
17
|
+
error: z.string().optional()
|
|
18
|
+
}), BtpDeliveryFailureDocSchema = z.object({
|
|
19
|
+
id: z.string(),
|
|
20
|
+
reason: z.string(),
|
|
21
|
+
failedAt: z.string().datetime(),
|
|
22
|
+
retryCount: z.number().optional(),
|
|
23
|
+
document: BtpTransporterArtifactSchema.optional(),
|
|
24
|
+
errorLog: z.any().optional(),
|
|
25
|
+
|
|
26
|
+
recipient: identitySchema,
|
|
27
|
+
transportArtifactId: z.string(),
|
|
28
|
+
agentArtifactId: z.string().optional()
|
|
29
|
+
}), BtpDeliveryFailureArtifactSchema = z.object({
|
|
30
|
+
id: z.string(),
|
|
31
|
+
issuedAt: z.string().datetime(),
|
|
32
|
+
document: BtpDeliveryFailureDocSchema,
|
|
33
|
+
type: z.literal("BTP_DELIVERY_FAILURE"),
|
|
34
|
+
from: identitySchema,
|
|
35
|
+
to: identitySchema
|
|
36
|
+
}), BtpQueryResultEntrySchema = z.object({
|
|
37
|
+
artifact: z.union([BtpTransporterArtifactSchema, BtpDeliveryFailureArtifactSchema]),
|
|
38
|
+
meta: z.object({
|
|
39
|
+
seen: z.boolean().optional(),
|
|
40
|
+
seenAt: z.string().datetime().optional()
|
|
41
|
+
}).catchall(z.unknown()).optional()
|
|
42
|
+
}), BtpQueryResultSchema = z.object({
|
|
43
|
+
results: z.array(BtpQueryResultEntrySchema),
|
|
44
|
+
cursor: z.string().optional(),
|
|
45
|
+
total: z.number().optional(),
|
|
46
|
+
hasNext: z.boolean().optional()
|
|
47
|
+
}), BtpServerResDocsSchema = z.union([
|
|
48
|
+
BtpAuthResDocSchema,
|
|
49
|
+
BtpQueryResultSchema,
|
|
50
|
+
BtpIdentityResDocSchema
|
|
51
|
+
]), BtpServerResponseSchema = z.object({
|
|
52
|
+
version: z.string().regex(/^\d+\.\d+\.\d+$/, "Version must be in semantic versioning format (e.g., 1.0.0)"),
|
|
53
|
+
status: BtpStatusSchema,
|
|
54
|
+
id: z.string(),
|
|
55
|
+
issuedAt: z.string().datetime(),
|
|
56
|
+
type: z.enum(["btps_error", "btps_response"]),
|
|
57
|
+
reqId: z.string().optional(),
|
|
58
|
+
document: z.union([BtpServerResDocsSchema, z.string()]).optional(),
|
|
59
|
+
signature: BtpSignatureSchema.optional(),
|
|
60
|
+
encryption: BtpEncryptionSchema.optional(),
|
|
61
|
+
signedBy: identitySchema.optional(),
|
|
62
|
+
selector: z.string().optional()
|
|
63
|
+
}).superRefine((data, ctx) => {
|
|
64
|
+
data.signature && (data.signedBy || ctx.addIssue({
|
|
65
|
+
path: ["signedBy"],
|
|
66
|
+
code: z.ZodIssueCode.custom,
|
|
67
|
+
message: "signedBy is required when signature is present"
|
|
68
|
+
}), data.selector || ctx.addIssue({
|
|
69
|
+
path: ["selector"],
|
|
70
|
+
code: z.ZodIssueCode.custom,
|
|
71
|
+
message: "selector is required when signature is present"
|
|
72
|
+
})), data.encryption && typeof data.document != "string" && ctx.addIssue({
|
|
73
|
+
path: ["document"],
|
|
74
|
+
code: z.ZodIssueCode.custom,
|
|
75
|
+
message: "When encrypted, document must be a string"
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
export {
|
|
79
|
+
BtpDeliveryFailureArtifactSchema,
|
|
80
|
+
BtpDeliveryFailureDocSchema,
|
|
81
|
+
BtpQueryResultEntrySchema,
|
|
82
|
+
BtpQueryResultSchema,
|
|
83
|
+
BtpServerResDocsSchema,
|
|
84
|
+
BtpServerResponseSchema,
|
|
85
|
+
BtpStatusSchema
|
|
86
|
+
};
|