optropic 2.3.0 → 2.4.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/dist/index.cjs +65 -2
- package/dist/index.d.cts +79 -2
- package/dist/index.d.ts +79 -2
- package/dist/index.js +64 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(index_exports, {
|
|
|
45
45
|
NetworkError: () => NetworkError,
|
|
46
46
|
OptropicClient: () => OptropicClient,
|
|
47
47
|
OptropicError: () => OptropicError,
|
|
48
|
+
Permission: () => Permission,
|
|
48
49
|
ProvenanceResource: () => ProvenanceResource,
|
|
49
50
|
QuotaExceededError: () => QuotaExceededError,
|
|
50
51
|
RateLimitedError: () => RateLimitedError,
|
|
@@ -512,6 +513,20 @@ var AssetsResource = class {
|
|
|
512
513
|
async batchCreate(params) {
|
|
513
514
|
return this.request({ method: "POST", path: "/v1/assets/batch", body: params });
|
|
514
515
|
}
|
|
516
|
+
async batchVerify(assetIds) {
|
|
517
|
+
return this.request({
|
|
518
|
+
method: "POST",
|
|
519
|
+
path: "/v1/assets/batch-verify",
|
|
520
|
+
body: { asset_ids: assetIds }
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
async batchRevoke(assetIds, reason) {
|
|
524
|
+
return this.request({
|
|
525
|
+
method: "POST",
|
|
526
|
+
path: "/v1/assets/batch-revoke",
|
|
527
|
+
body: { asset_ids: assetIds, reason }
|
|
528
|
+
});
|
|
529
|
+
}
|
|
515
530
|
buildQuery(params) {
|
|
516
531
|
const entries = Object.entries(params).filter(([, v]) => v !== void 0);
|
|
517
532
|
if (entries.length === 0) return "";
|
|
@@ -973,7 +988,7 @@ var SchemasResource = class {
|
|
|
973
988
|
// src/client.ts
|
|
974
989
|
var DEFAULT_BASE_URL = "https://api.optropic.com";
|
|
975
990
|
var DEFAULT_TIMEOUT = 3e4;
|
|
976
|
-
var SDK_VERSION = "2.
|
|
991
|
+
var SDK_VERSION = "2.4.0";
|
|
977
992
|
var SANDBOX_PREFIXES = ["optr_test_"];
|
|
978
993
|
var DEFAULT_RETRY_CONFIG = {
|
|
979
994
|
maxRetries: 3,
|
|
@@ -987,6 +1002,7 @@ var OptropicClient = class {
|
|
|
987
1002
|
retryConfig;
|
|
988
1003
|
_sandbox;
|
|
989
1004
|
_debug;
|
|
1005
|
+
_rateLimit = null;
|
|
990
1006
|
assets;
|
|
991
1007
|
audit;
|
|
992
1008
|
compliance;
|
|
@@ -1045,6 +1061,10 @@ var OptropicClient = class {
|
|
|
1045
1061
|
get environment() {
|
|
1046
1062
|
return this._sandbox ? "sandbox" : "live";
|
|
1047
1063
|
}
|
|
1064
|
+
/** Last known rate limit status, updated after every API call. Returns null until the first request. */
|
|
1065
|
+
get rateLimit() {
|
|
1066
|
+
return this._rateLimit;
|
|
1067
|
+
}
|
|
1048
1068
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1049
1069
|
// DEBUG LOGGING
|
|
1050
1070
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -1157,6 +1177,15 @@ var OptropicClient = class {
|
|
|
1157
1177
|
const durationMs = performance.now() - t0;
|
|
1158
1178
|
const serverRequestId = response.headers.get("x-request-id") ?? "";
|
|
1159
1179
|
this.logResponse(method, path, response.status, durationMs, requestId, serverRequestId, attempt);
|
|
1180
|
+
const rlLimit = response.headers.get("x-ratelimit-limit");
|
|
1181
|
+
const rlRemaining = response.headers.get("x-ratelimit-remaining");
|
|
1182
|
+
if (rlLimit !== null || rlRemaining !== null) {
|
|
1183
|
+
this._rateLimit = {
|
|
1184
|
+
limit: rlLimit ? parseInt(rlLimit, 10) : 0,
|
|
1185
|
+
remaining: rlRemaining ? parseInt(rlRemaining, 10) : 0,
|
|
1186
|
+
reset: response.headers.get("x-ratelimit-reset") ?? void 0
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1160
1189
|
if (!response.ok) {
|
|
1161
1190
|
let errorBody;
|
|
1162
1191
|
try {
|
|
@@ -1226,6 +1255,39 @@ function createClient(config) {
|
|
|
1226
1255
|
return new OptropicClient(config);
|
|
1227
1256
|
}
|
|
1228
1257
|
|
|
1258
|
+
// src/types.ts
|
|
1259
|
+
var Permission = {
|
|
1260
|
+
ASSETS_READ: "assets:read",
|
|
1261
|
+
ASSETS_WRITE: "assets:write",
|
|
1262
|
+
ASSETS_VERIFY: "assets:verify",
|
|
1263
|
+
AUDIT_READ: "audit:read",
|
|
1264
|
+
COMPLIANCE_READ: "compliance:read",
|
|
1265
|
+
KEYS_MANAGE: "keys:manage",
|
|
1266
|
+
SCHEMAS_MANAGE: "schemas:manage",
|
|
1267
|
+
DOCUMENTS_ENROLL: "documents:enroll",
|
|
1268
|
+
DOCUMENTS_VERIFY: "documents:verify",
|
|
1269
|
+
PROVENANCE_READ: "provenance:read",
|
|
1270
|
+
PROVENANCE_WRITE: "provenance:write",
|
|
1271
|
+
WEBHOOKS_MANAGE: "webhooks:manage",
|
|
1272
|
+
/** All read permissions. */
|
|
1273
|
+
ALL_READ: ["assets:read", "audit:read", "compliance:read", "provenance:read"],
|
|
1274
|
+
/** All write permissions. */
|
|
1275
|
+
ALL_WRITE: [
|
|
1276
|
+
"assets:write",
|
|
1277
|
+
"assets:verify",
|
|
1278
|
+
"documents:enroll",
|
|
1279
|
+
"documents:verify",
|
|
1280
|
+
"provenance:write",
|
|
1281
|
+
"webhooks:manage",
|
|
1282
|
+
"keys:manage",
|
|
1283
|
+
"schemas:manage"
|
|
1284
|
+
],
|
|
1285
|
+
/** All permissions combined. */
|
|
1286
|
+
all() {
|
|
1287
|
+
return [...this.ALL_READ, ...this.ALL_WRITE];
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1229
1291
|
// src/filter-verify.ts
|
|
1230
1292
|
var HEADER_SIZE = 19;
|
|
1231
1293
|
var SIGNATURE_SIZE = 64;
|
|
@@ -1469,7 +1531,7 @@ async function verifyWebhookSignature(options) {
|
|
|
1469
1531
|
}
|
|
1470
1532
|
|
|
1471
1533
|
// src/index.ts
|
|
1472
|
-
var SDK_VERSION2 = "2.
|
|
1534
|
+
var SDK_VERSION2 = "2.4.0";
|
|
1473
1535
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1474
1536
|
0 && (module.exports = {
|
|
1475
1537
|
AssetsResource,
|
|
@@ -1487,6 +1549,7 @@ var SDK_VERSION2 = "2.3.0";
|
|
|
1487
1549
|
NetworkError,
|
|
1488
1550
|
OptropicClient,
|
|
1489
1551
|
OptropicError,
|
|
1552
|
+
Permission,
|
|
1490
1553
|
ProvenanceResource,
|
|
1491
1554
|
QuotaExceededError,
|
|
1492
1555
|
RateLimitedError,
|
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,53 @@ interface RetryConfig {
|
|
|
77
77
|
* Use these for programmatic error handling.
|
|
78
78
|
*/
|
|
79
79
|
type ErrorCode = 'INVALID_API_KEY' | 'EXPIRED_API_KEY' | 'INSUFFICIENT_PERMISSIONS' | 'INVALID_GTIN' | 'INVALID_SERIAL' | 'INVALID_CODE_FORMAT' | 'INVALID_BATCH_CONFIG' | 'CODE_NOT_FOUND' | 'BATCH_NOT_FOUND' | 'PRODUCT_NOT_FOUND' | 'CODE_REVOKED' | 'CODE_EXPIRED' | 'BATCH_ALREADY_EXISTS' | 'RATE_LIMITED' | 'QUOTA_EXCEEDED' | 'NETWORK_ERROR' | 'TIMEOUT' | 'SERVICE_UNAVAILABLE' | 'INTERNAL_ERROR' | 'UNKNOWN_ERROR';
|
|
80
|
+
/**
|
|
81
|
+
* Type-safe permission constants for API key creation.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* import { Permission } from 'optropic';
|
|
86
|
+
*
|
|
87
|
+
* const key = await client.keys.create({
|
|
88
|
+
* environment: 'live',
|
|
89
|
+
* label: 'Read-only integration',
|
|
90
|
+
* permissions: [Permission.ASSETS_READ, Permission.ASSETS_VERIFY],
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare const Permission: {
|
|
95
|
+
readonly ASSETS_READ: "assets:read";
|
|
96
|
+
readonly ASSETS_WRITE: "assets:write";
|
|
97
|
+
readonly ASSETS_VERIFY: "assets:verify";
|
|
98
|
+
readonly AUDIT_READ: "audit:read";
|
|
99
|
+
readonly COMPLIANCE_READ: "compliance:read";
|
|
100
|
+
readonly KEYS_MANAGE: "keys:manage";
|
|
101
|
+
readonly SCHEMAS_MANAGE: "schemas:manage";
|
|
102
|
+
readonly DOCUMENTS_ENROLL: "documents:enroll";
|
|
103
|
+
readonly DOCUMENTS_VERIFY: "documents:verify";
|
|
104
|
+
readonly PROVENANCE_READ: "provenance:read";
|
|
105
|
+
readonly PROVENANCE_WRITE: "provenance:write";
|
|
106
|
+
readonly WEBHOOKS_MANAGE: "webhooks:manage";
|
|
107
|
+
/** All read permissions. */
|
|
108
|
+
readonly ALL_READ: readonly ["assets:read", "audit:read", "compliance:read", "provenance:read"];
|
|
109
|
+
/** All write permissions. */
|
|
110
|
+
readonly ALL_WRITE: readonly ["assets:write", "assets:verify", "documents:enroll", "documents:verify", "provenance:write", "webhooks:manage", "keys:manage", "schemas:manage"];
|
|
111
|
+
/** All permissions combined. */
|
|
112
|
+
readonly all: () => string[];
|
|
113
|
+
};
|
|
114
|
+
type PermissionValue = typeof Permission[keyof Omit<typeof Permission, 'ALL_READ' | 'ALL_WRITE' | 'all'>];
|
|
115
|
+
/**
|
|
116
|
+
* Rate limit status parsed from response headers.
|
|
117
|
+
* Updated automatically after every API call.
|
|
118
|
+
*/
|
|
119
|
+
interface RateLimitInfo {
|
|
120
|
+
/** Maximum requests allowed per period. */
|
|
121
|
+
readonly limit: number;
|
|
122
|
+
/** Remaining requests in current period. */
|
|
123
|
+
readonly remaining: number;
|
|
124
|
+
/** ISO 8601 timestamp when the limit resets. */
|
|
125
|
+
readonly reset?: string;
|
|
126
|
+
}
|
|
80
127
|
|
|
81
128
|
/**
|
|
82
129
|
* Assets Resource
|
|
@@ -152,6 +199,31 @@ interface BatchCreateResult {
|
|
|
152
199
|
readonly requested: number;
|
|
153
200
|
readonly assets: Asset[];
|
|
154
201
|
}
|
|
202
|
+
interface BatchVerifyResult {
|
|
203
|
+
readonly verified: number;
|
|
204
|
+
readonly requested: number;
|
|
205
|
+
readonly results: Array<{
|
|
206
|
+
readonly assetId: string;
|
|
207
|
+
readonly signatureValid: boolean;
|
|
208
|
+
readonly revocationStatus: string;
|
|
209
|
+
}>;
|
|
210
|
+
readonly errors?: Array<{
|
|
211
|
+
readonly assetId: string;
|
|
212
|
+
readonly error: string;
|
|
213
|
+
}>;
|
|
214
|
+
}
|
|
215
|
+
interface BatchRevokeResult {
|
|
216
|
+
readonly revoked: number;
|
|
217
|
+
readonly requested: number;
|
|
218
|
+
readonly results: Array<{
|
|
219
|
+
readonly assetId: string;
|
|
220
|
+
readonly status: string;
|
|
221
|
+
}>;
|
|
222
|
+
readonly errors?: Array<{
|
|
223
|
+
readonly assetId: string;
|
|
224
|
+
readonly error: string;
|
|
225
|
+
}>;
|
|
226
|
+
}
|
|
155
227
|
declare class AssetsResource {
|
|
156
228
|
private readonly request;
|
|
157
229
|
private readonly client;
|
|
@@ -181,6 +253,8 @@ declare class AssetsResource {
|
|
|
181
253
|
verify(assetId: string): Promise<VerifyResult>;
|
|
182
254
|
revoke(assetId: string, reason?: string): Promise<Asset>;
|
|
183
255
|
batchCreate(params: BatchCreateParams): Promise<BatchCreateResult>;
|
|
256
|
+
batchVerify(assetIds: string[]): Promise<BatchVerifyResult>;
|
|
257
|
+
batchRevoke(assetIds: string[], reason: string): Promise<BatchRevokeResult>;
|
|
184
258
|
private buildQuery;
|
|
185
259
|
}
|
|
186
260
|
|
|
@@ -758,6 +832,7 @@ declare class OptropicClient {
|
|
|
758
832
|
private readonly retryConfig;
|
|
759
833
|
private readonly _sandbox;
|
|
760
834
|
private readonly _debug;
|
|
835
|
+
private _rateLimit;
|
|
761
836
|
readonly assets: AssetsResource;
|
|
762
837
|
readonly audit: AuditResource;
|
|
763
838
|
readonly compliance: ComplianceResource;
|
|
@@ -773,6 +848,8 @@ declare class OptropicClient {
|
|
|
773
848
|
get isLive(): boolean;
|
|
774
849
|
/** Returns 'sandbox' or 'live'. */
|
|
775
850
|
get environment(): 'sandbox' | 'live';
|
|
851
|
+
/** Last known rate limit status, updated after every API call. Returns null until the first request. */
|
|
852
|
+
get rateLimit(): RateLimitInfo | null;
|
|
776
853
|
private redact;
|
|
777
854
|
private logRequest;
|
|
778
855
|
private logResponse;
|
|
@@ -1324,6 +1401,6 @@ declare function createErrorFromResponse(statusCode: number, body: {
|
|
|
1324
1401
|
requestId?: string;
|
|
1325
1402
|
}): OptropicError;
|
|
1326
1403
|
|
|
1327
|
-
declare const SDK_VERSION = "2.
|
|
1404
|
+
declare const SDK_VERSION = "2.4.0";
|
|
1328
1405
|
|
|
1329
|
-
export { type ApiKey, type Asset, AssetsResource, type AuditEvent, AuditResource, AuthenticationError, type BatchCreateParams, type BatchCreateResult, BatchNotFoundError, type BatteryPassportData, type ChainVerifyResult, CodeNotFoundError, type ComplianceConfig, ComplianceResource, type ConformityDeclaration, type CreateAssetParams, type CreateAuditEventParams, type CreateKeyParams, type CreateKeyResult, type CreateKeysetParams, type CreateSchemaParams, type DPPCategory, type DPPMetadata, type Document, type DocumentVerifyResult, DocumentsResource, type EnrollDocumentParams, type ErrorCode, type ExportParams, type ExportResult, type FiberEntry, type FilterHeader, type FilterSyncResult, InvalidCodeError, InvalidGTINError, InvalidSerialError, KeysResource, type Keyset, KeysetsResource, type ListAssetsParams, type ListAssetsResponse, type ListAuditParams, type ListAuditResponse, type ListDocumentsParams, type ListDocumentsResponse, type ListKeysetsParams, type ListKeysetsResponse, type ListProvenanceParams, type ListProvenanceResponse, type ListSchemasParams, type ListSchemasResponse, type MerkleProof, type MerkleRoot, NetworkError, type OfflineVerifyOptions, type OfflineVerifyResult, OptropicClient, type OptropicConfig, OptropicError, type ProvenanceChain, type ProvenanceEvent, type ProvenanceEventType, type ProvenanceLocation, ProvenanceResource, QuotaExceededError, RateLimitedError, type RecordProvenanceParams, type RequestFn, type RetryConfig, RevokedCodeError, SDK_VERSION, type SchemaValidationResult, SchemasResource, ServiceUnavailableError, StaleFilterError, type SubstanceEntry, type TextilePassportData, TimeoutError, type UpdateSchemaParams, type VerifyDocumentParams, type VerifyProvenanceResult, type VerifyResult, type VerticalSchema, type WebhookVerifyOptions, type WebhookVerifyResult, buildDPPConfig, createClient, createErrorFromResponse, parseFilterHeader, parseSaltsHeader, validateDPPMetadata, verifyOffline, verifyWebhookSignature };
|
|
1406
|
+
export { type ApiKey, type Asset, AssetsResource, type AuditEvent, AuditResource, AuthenticationError, type BatchCreateParams, type BatchCreateResult, BatchNotFoundError, type BatchRevokeResult, type BatchVerifyResult, type BatteryPassportData, type ChainVerifyResult, CodeNotFoundError, type ComplianceConfig, ComplianceResource, type ConformityDeclaration, type CreateAssetParams, type CreateAuditEventParams, type CreateKeyParams, type CreateKeyResult, type CreateKeysetParams, type CreateSchemaParams, type DPPCategory, type DPPMetadata, type Document, type DocumentVerifyResult, DocumentsResource, type EnrollDocumentParams, type ErrorCode, type ExportParams, type ExportResult, type FiberEntry, type FilterHeader, type FilterSyncResult, InvalidCodeError, InvalidGTINError, InvalidSerialError, KeysResource, type Keyset, KeysetsResource, type ListAssetsParams, type ListAssetsResponse, type ListAuditParams, type ListAuditResponse, type ListDocumentsParams, type ListDocumentsResponse, type ListKeysetsParams, type ListKeysetsResponse, type ListProvenanceParams, type ListProvenanceResponse, type ListSchemasParams, type ListSchemasResponse, type MerkleProof, type MerkleRoot, NetworkError, type OfflineVerifyOptions, type OfflineVerifyResult, OptropicClient, type OptropicConfig, OptropicError, Permission, type PermissionValue, type ProvenanceChain, type ProvenanceEvent, type ProvenanceEventType, type ProvenanceLocation, ProvenanceResource, QuotaExceededError, type RateLimitInfo, RateLimitedError, type RecordProvenanceParams, type RequestFn, type RetryConfig, RevokedCodeError, SDK_VERSION, type SchemaValidationResult, SchemasResource, ServiceUnavailableError, StaleFilterError, type SubstanceEntry, type TextilePassportData, TimeoutError, type UpdateSchemaParams, type VerifyDocumentParams, type VerifyProvenanceResult, type VerifyResult, type VerticalSchema, type WebhookVerifyOptions, type WebhookVerifyResult, buildDPPConfig, createClient, createErrorFromResponse, parseFilterHeader, parseSaltsHeader, validateDPPMetadata, verifyOffline, verifyWebhookSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,53 @@ interface RetryConfig {
|
|
|
77
77
|
* Use these for programmatic error handling.
|
|
78
78
|
*/
|
|
79
79
|
type ErrorCode = 'INVALID_API_KEY' | 'EXPIRED_API_KEY' | 'INSUFFICIENT_PERMISSIONS' | 'INVALID_GTIN' | 'INVALID_SERIAL' | 'INVALID_CODE_FORMAT' | 'INVALID_BATCH_CONFIG' | 'CODE_NOT_FOUND' | 'BATCH_NOT_FOUND' | 'PRODUCT_NOT_FOUND' | 'CODE_REVOKED' | 'CODE_EXPIRED' | 'BATCH_ALREADY_EXISTS' | 'RATE_LIMITED' | 'QUOTA_EXCEEDED' | 'NETWORK_ERROR' | 'TIMEOUT' | 'SERVICE_UNAVAILABLE' | 'INTERNAL_ERROR' | 'UNKNOWN_ERROR';
|
|
80
|
+
/**
|
|
81
|
+
* Type-safe permission constants for API key creation.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* import { Permission } from 'optropic';
|
|
86
|
+
*
|
|
87
|
+
* const key = await client.keys.create({
|
|
88
|
+
* environment: 'live',
|
|
89
|
+
* label: 'Read-only integration',
|
|
90
|
+
* permissions: [Permission.ASSETS_READ, Permission.ASSETS_VERIFY],
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare const Permission: {
|
|
95
|
+
readonly ASSETS_READ: "assets:read";
|
|
96
|
+
readonly ASSETS_WRITE: "assets:write";
|
|
97
|
+
readonly ASSETS_VERIFY: "assets:verify";
|
|
98
|
+
readonly AUDIT_READ: "audit:read";
|
|
99
|
+
readonly COMPLIANCE_READ: "compliance:read";
|
|
100
|
+
readonly KEYS_MANAGE: "keys:manage";
|
|
101
|
+
readonly SCHEMAS_MANAGE: "schemas:manage";
|
|
102
|
+
readonly DOCUMENTS_ENROLL: "documents:enroll";
|
|
103
|
+
readonly DOCUMENTS_VERIFY: "documents:verify";
|
|
104
|
+
readonly PROVENANCE_READ: "provenance:read";
|
|
105
|
+
readonly PROVENANCE_WRITE: "provenance:write";
|
|
106
|
+
readonly WEBHOOKS_MANAGE: "webhooks:manage";
|
|
107
|
+
/** All read permissions. */
|
|
108
|
+
readonly ALL_READ: readonly ["assets:read", "audit:read", "compliance:read", "provenance:read"];
|
|
109
|
+
/** All write permissions. */
|
|
110
|
+
readonly ALL_WRITE: readonly ["assets:write", "assets:verify", "documents:enroll", "documents:verify", "provenance:write", "webhooks:manage", "keys:manage", "schemas:manage"];
|
|
111
|
+
/** All permissions combined. */
|
|
112
|
+
readonly all: () => string[];
|
|
113
|
+
};
|
|
114
|
+
type PermissionValue = typeof Permission[keyof Omit<typeof Permission, 'ALL_READ' | 'ALL_WRITE' | 'all'>];
|
|
115
|
+
/**
|
|
116
|
+
* Rate limit status parsed from response headers.
|
|
117
|
+
* Updated automatically after every API call.
|
|
118
|
+
*/
|
|
119
|
+
interface RateLimitInfo {
|
|
120
|
+
/** Maximum requests allowed per period. */
|
|
121
|
+
readonly limit: number;
|
|
122
|
+
/** Remaining requests in current period. */
|
|
123
|
+
readonly remaining: number;
|
|
124
|
+
/** ISO 8601 timestamp when the limit resets. */
|
|
125
|
+
readonly reset?: string;
|
|
126
|
+
}
|
|
80
127
|
|
|
81
128
|
/**
|
|
82
129
|
* Assets Resource
|
|
@@ -152,6 +199,31 @@ interface BatchCreateResult {
|
|
|
152
199
|
readonly requested: number;
|
|
153
200
|
readonly assets: Asset[];
|
|
154
201
|
}
|
|
202
|
+
interface BatchVerifyResult {
|
|
203
|
+
readonly verified: number;
|
|
204
|
+
readonly requested: number;
|
|
205
|
+
readonly results: Array<{
|
|
206
|
+
readonly assetId: string;
|
|
207
|
+
readonly signatureValid: boolean;
|
|
208
|
+
readonly revocationStatus: string;
|
|
209
|
+
}>;
|
|
210
|
+
readonly errors?: Array<{
|
|
211
|
+
readonly assetId: string;
|
|
212
|
+
readonly error: string;
|
|
213
|
+
}>;
|
|
214
|
+
}
|
|
215
|
+
interface BatchRevokeResult {
|
|
216
|
+
readonly revoked: number;
|
|
217
|
+
readonly requested: number;
|
|
218
|
+
readonly results: Array<{
|
|
219
|
+
readonly assetId: string;
|
|
220
|
+
readonly status: string;
|
|
221
|
+
}>;
|
|
222
|
+
readonly errors?: Array<{
|
|
223
|
+
readonly assetId: string;
|
|
224
|
+
readonly error: string;
|
|
225
|
+
}>;
|
|
226
|
+
}
|
|
155
227
|
declare class AssetsResource {
|
|
156
228
|
private readonly request;
|
|
157
229
|
private readonly client;
|
|
@@ -181,6 +253,8 @@ declare class AssetsResource {
|
|
|
181
253
|
verify(assetId: string): Promise<VerifyResult>;
|
|
182
254
|
revoke(assetId: string, reason?: string): Promise<Asset>;
|
|
183
255
|
batchCreate(params: BatchCreateParams): Promise<BatchCreateResult>;
|
|
256
|
+
batchVerify(assetIds: string[]): Promise<BatchVerifyResult>;
|
|
257
|
+
batchRevoke(assetIds: string[], reason: string): Promise<BatchRevokeResult>;
|
|
184
258
|
private buildQuery;
|
|
185
259
|
}
|
|
186
260
|
|
|
@@ -758,6 +832,7 @@ declare class OptropicClient {
|
|
|
758
832
|
private readonly retryConfig;
|
|
759
833
|
private readonly _sandbox;
|
|
760
834
|
private readonly _debug;
|
|
835
|
+
private _rateLimit;
|
|
761
836
|
readonly assets: AssetsResource;
|
|
762
837
|
readonly audit: AuditResource;
|
|
763
838
|
readonly compliance: ComplianceResource;
|
|
@@ -773,6 +848,8 @@ declare class OptropicClient {
|
|
|
773
848
|
get isLive(): boolean;
|
|
774
849
|
/** Returns 'sandbox' or 'live'. */
|
|
775
850
|
get environment(): 'sandbox' | 'live';
|
|
851
|
+
/** Last known rate limit status, updated after every API call. Returns null until the first request. */
|
|
852
|
+
get rateLimit(): RateLimitInfo | null;
|
|
776
853
|
private redact;
|
|
777
854
|
private logRequest;
|
|
778
855
|
private logResponse;
|
|
@@ -1324,6 +1401,6 @@ declare function createErrorFromResponse(statusCode: number, body: {
|
|
|
1324
1401
|
requestId?: string;
|
|
1325
1402
|
}): OptropicError;
|
|
1326
1403
|
|
|
1327
|
-
declare const SDK_VERSION = "2.
|
|
1404
|
+
declare const SDK_VERSION = "2.4.0";
|
|
1328
1405
|
|
|
1329
|
-
export { type ApiKey, type Asset, AssetsResource, type AuditEvent, AuditResource, AuthenticationError, type BatchCreateParams, type BatchCreateResult, BatchNotFoundError, type BatteryPassportData, type ChainVerifyResult, CodeNotFoundError, type ComplianceConfig, ComplianceResource, type ConformityDeclaration, type CreateAssetParams, type CreateAuditEventParams, type CreateKeyParams, type CreateKeyResult, type CreateKeysetParams, type CreateSchemaParams, type DPPCategory, type DPPMetadata, type Document, type DocumentVerifyResult, DocumentsResource, type EnrollDocumentParams, type ErrorCode, type ExportParams, type ExportResult, type FiberEntry, type FilterHeader, type FilterSyncResult, InvalidCodeError, InvalidGTINError, InvalidSerialError, KeysResource, type Keyset, KeysetsResource, type ListAssetsParams, type ListAssetsResponse, type ListAuditParams, type ListAuditResponse, type ListDocumentsParams, type ListDocumentsResponse, type ListKeysetsParams, type ListKeysetsResponse, type ListProvenanceParams, type ListProvenanceResponse, type ListSchemasParams, type ListSchemasResponse, type MerkleProof, type MerkleRoot, NetworkError, type OfflineVerifyOptions, type OfflineVerifyResult, OptropicClient, type OptropicConfig, OptropicError, type ProvenanceChain, type ProvenanceEvent, type ProvenanceEventType, type ProvenanceLocation, ProvenanceResource, QuotaExceededError, RateLimitedError, type RecordProvenanceParams, type RequestFn, type RetryConfig, RevokedCodeError, SDK_VERSION, type SchemaValidationResult, SchemasResource, ServiceUnavailableError, StaleFilterError, type SubstanceEntry, type TextilePassportData, TimeoutError, type UpdateSchemaParams, type VerifyDocumentParams, type VerifyProvenanceResult, type VerifyResult, type VerticalSchema, type WebhookVerifyOptions, type WebhookVerifyResult, buildDPPConfig, createClient, createErrorFromResponse, parseFilterHeader, parseSaltsHeader, validateDPPMetadata, verifyOffline, verifyWebhookSignature };
|
|
1406
|
+
export { type ApiKey, type Asset, AssetsResource, type AuditEvent, AuditResource, AuthenticationError, type BatchCreateParams, type BatchCreateResult, BatchNotFoundError, type BatchRevokeResult, type BatchVerifyResult, type BatteryPassportData, type ChainVerifyResult, CodeNotFoundError, type ComplianceConfig, ComplianceResource, type ConformityDeclaration, type CreateAssetParams, type CreateAuditEventParams, type CreateKeyParams, type CreateKeyResult, type CreateKeysetParams, type CreateSchemaParams, type DPPCategory, type DPPMetadata, type Document, type DocumentVerifyResult, DocumentsResource, type EnrollDocumentParams, type ErrorCode, type ExportParams, type ExportResult, type FiberEntry, type FilterHeader, type FilterSyncResult, InvalidCodeError, InvalidGTINError, InvalidSerialError, KeysResource, type Keyset, KeysetsResource, type ListAssetsParams, type ListAssetsResponse, type ListAuditParams, type ListAuditResponse, type ListDocumentsParams, type ListDocumentsResponse, type ListKeysetsParams, type ListKeysetsResponse, type ListProvenanceParams, type ListProvenanceResponse, type ListSchemasParams, type ListSchemasResponse, type MerkleProof, type MerkleRoot, NetworkError, type OfflineVerifyOptions, type OfflineVerifyResult, OptropicClient, type OptropicConfig, OptropicError, Permission, type PermissionValue, type ProvenanceChain, type ProvenanceEvent, type ProvenanceEventType, type ProvenanceLocation, ProvenanceResource, QuotaExceededError, type RateLimitInfo, RateLimitedError, type RecordProvenanceParams, type RequestFn, type RetryConfig, RevokedCodeError, SDK_VERSION, type SchemaValidationResult, SchemasResource, ServiceUnavailableError, StaleFilterError, type SubstanceEntry, type TextilePassportData, TimeoutError, type UpdateSchemaParams, type VerifyDocumentParams, type VerifyProvenanceResult, type VerifyResult, type VerticalSchema, type WebhookVerifyOptions, type WebhookVerifyResult, buildDPPConfig, createClient, createErrorFromResponse, parseFilterHeader, parseSaltsHeader, validateDPPMetadata, verifyOffline, verifyWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -445,6 +445,20 @@ var AssetsResource = class {
|
|
|
445
445
|
async batchCreate(params) {
|
|
446
446
|
return this.request({ method: "POST", path: "/v1/assets/batch", body: params });
|
|
447
447
|
}
|
|
448
|
+
async batchVerify(assetIds) {
|
|
449
|
+
return this.request({
|
|
450
|
+
method: "POST",
|
|
451
|
+
path: "/v1/assets/batch-verify",
|
|
452
|
+
body: { asset_ids: assetIds }
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
async batchRevoke(assetIds, reason) {
|
|
456
|
+
return this.request({
|
|
457
|
+
method: "POST",
|
|
458
|
+
path: "/v1/assets/batch-revoke",
|
|
459
|
+
body: { asset_ids: assetIds, reason }
|
|
460
|
+
});
|
|
461
|
+
}
|
|
448
462
|
buildQuery(params) {
|
|
449
463
|
const entries = Object.entries(params).filter(([, v]) => v !== void 0);
|
|
450
464
|
if (entries.length === 0) return "";
|
|
@@ -906,7 +920,7 @@ var SchemasResource = class {
|
|
|
906
920
|
// src/client.ts
|
|
907
921
|
var DEFAULT_BASE_URL = "https://api.optropic.com";
|
|
908
922
|
var DEFAULT_TIMEOUT = 3e4;
|
|
909
|
-
var SDK_VERSION = "2.
|
|
923
|
+
var SDK_VERSION = "2.4.0";
|
|
910
924
|
var SANDBOX_PREFIXES = ["optr_test_"];
|
|
911
925
|
var DEFAULT_RETRY_CONFIG = {
|
|
912
926
|
maxRetries: 3,
|
|
@@ -920,6 +934,7 @@ var OptropicClient = class {
|
|
|
920
934
|
retryConfig;
|
|
921
935
|
_sandbox;
|
|
922
936
|
_debug;
|
|
937
|
+
_rateLimit = null;
|
|
923
938
|
assets;
|
|
924
939
|
audit;
|
|
925
940
|
compliance;
|
|
@@ -978,6 +993,10 @@ var OptropicClient = class {
|
|
|
978
993
|
get environment() {
|
|
979
994
|
return this._sandbox ? "sandbox" : "live";
|
|
980
995
|
}
|
|
996
|
+
/** Last known rate limit status, updated after every API call. Returns null until the first request. */
|
|
997
|
+
get rateLimit() {
|
|
998
|
+
return this._rateLimit;
|
|
999
|
+
}
|
|
981
1000
|
// ─────────────────────────────────────────────────────────────────────────
|
|
982
1001
|
// DEBUG LOGGING
|
|
983
1002
|
// ─────────────────────────────────────────────────────────────────────────
|
|
@@ -1090,6 +1109,15 @@ var OptropicClient = class {
|
|
|
1090
1109
|
const durationMs = performance.now() - t0;
|
|
1091
1110
|
const serverRequestId = response.headers.get("x-request-id") ?? "";
|
|
1092
1111
|
this.logResponse(method, path, response.status, durationMs, requestId, serverRequestId, attempt);
|
|
1112
|
+
const rlLimit = response.headers.get("x-ratelimit-limit");
|
|
1113
|
+
const rlRemaining = response.headers.get("x-ratelimit-remaining");
|
|
1114
|
+
if (rlLimit !== null || rlRemaining !== null) {
|
|
1115
|
+
this._rateLimit = {
|
|
1116
|
+
limit: rlLimit ? parseInt(rlLimit, 10) : 0,
|
|
1117
|
+
remaining: rlRemaining ? parseInt(rlRemaining, 10) : 0,
|
|
1118
|
+
reset: response.headers.get("x-ratelimit-reset") ?? void 0
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1093
1121
|
if (!response.ok) {
|
|
1094
1122
|
let errorBody;
|
|
1095
1123
|
try {
|
|
@@ -1159,6 +1187,39 @@ function createClient(config) {
|
|
|
1159
1187
|
return new OptropicClient(config);
|
|
1160
1188
|
}
|
|
1161
1189
|
|
|
1190
|
+
// src/types.ts
|
|
1191
|
+
var Permission = {
|
|
1192
|
+
ASSETS_READ: "assets:read",
|
|
1193
|
+
ASSETS_WRITE: "assets:write",
|
|
1194
|
+
ASSETS_VERIFY: "assets:verify",
|
|
1195
|
+
AUDIT_READ: "audit:read",
|
|
1196
|
+
COMPLIANCE_READ: "compliance:read",
|
|
1197
|
+
KEYS_MANAGE: "keys:manage",
|
|
1198
|
+
SCHEMAS_MANAGE: "schemas:manage",
|
|
1199
|
+
DOCUMENTS_ENROLL: "documents:enroll",
|
|
1200
|
+
DOCUMENTS_VERIFY: "documents:verify",
|
|
1201
|
+
PROVENANCE_READ: "provenance:read",
|
|
1202
|
+
PROVENANCE_WRITE: "provenance:write",
|
|
1203
|
+
WEBHOOKS_MANAGE: "webhooks:manage",
|
|
1204
|
+
/** All read permissions. */
|
|
1205
|
+
ALL_READ: ["assets:read", "audit:read", "compliance:read", "provenance:read"],
|
|
1206
|
+
/** All write permissions. */
|
|
1207
|
+
ALL_WRITE: [
|
|
1208
|
+
"assets:write",
|
|
1209
|
+
"assets:verify",
|
|
1210
|
+
"documents:enroll",
|
|
1211
|
+
"documents:verify",
|
|
1212
|
+
"provenance:write",
|
|
1213
|
+
"webhooks:manage",
|
|
1214
|
+
"keys:manage",
|
|
1215
|
+
"schemas:manage"
|
|
1216
|
+
],
|
|
1217
|
+
/** All permissions combined. */
|
|
1218
|
+
all() {
|
|
1219
|
+
return [...this.ALL_READ, ...this.ALL_WRITE];
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1162
1223
|
// src/filter-verify.ts
|
|
1163
1224
|
var HEADER_SIZE = 19;
|
|
1164
1225
|
var SIGNATURE_SIZE = 64;
|
|
@@ -1402,7 +1463,7 @@ async function verifyWebhookSignature(options) {
|
|
|
1402
1463
|
}
|
|
1403
1464
|
|
|
1404
1465
|
// src/index.ts
|
|
1405
|
-
var SDK_VERSION2 = "2.
|
|
1466
|
+
var SDK_VERSION2 = "2.4.0";
|
|
1406
1467
|
export {
|
|
1407
1468
|
AssetsResource,
|
|
1408
1469
|
AuditResource,
|
|
@@ -1419,6 +1480,7 @@ export {
|
|
|
1419
1480
|
NetworkError,
|
|
1420
1481
|
OptropicClient,
|
|
1421
1482
|
OptropicError,
|
|
1483
|
+
Permission,
|
|
1422
1484
|
ProvenanceResource,
|
|
1423
1485
|
QuotaExceededError,
|
|
1424
1486
|
RateLimitedError,
|