optropic 1.0.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/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/index.cjs +662 -0
- package/dist/index.d.cts +478 -0
- package/dist/index.d.ts +478 -0
- package/dist/index.js +618 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Optropic GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# optropic
|
|
2
|
+
|
|
3
|
+
Official Optropic SDK for TypeScript and JavaScript. Protect products. Verify authenticity.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/optropic)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install optropic
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { OptropicClient } from 'optropic';
|
|
19
|
+
|
|
20
|
+
const client = new OptropicClient({
|
|
21
|
+
apiKey: process.env.OPTROPIC_API_KEY!,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Verify an asset
|
|
25
|
+
const result = await client.assets.verify('asset-id');
|
|
26
|
+
console.log(result.signature_valid); // true
|
|
27
|
+
console.log(result.revocation_status); // 'active'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Resources
|
|
31
|
+
|
|
32
|
+
### Assets
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// Create an asset
|
|
36
|
+
const asset = await client.assets.create({
|
|
37
|
+
gtin: '01234567890128',
|
|
38
|
+
serial: 'SN-2026-001',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// List assets
|
|
42
|
+
const assets = await client.assets.list({ limit: 10 });
|
|
43
|
+
|
|
44
|
+
// Get a single asset
|
|
45
|
+
const asset = await client.assets.get('asset-id');
|
|
46
|
+
|
|
47
|
+
// Verify an asset
|
|
48
|
+
const verification = await client.assets.verify('asset-id');
|
|
49
|
+
|
|
50
|
+
// Revoke an asset
|
|
51
|
+
await client.assets.revoke('asset-id', 'recalled');
|
|
52
|
+
|
|
53
|
+
// Batch create assets
|
|
54
|
+
const batch = await client.assets.batchCreate({
|
|
55
|
+
assets: [
|
|
56
|
+
{ gtin: '01234567890128', serial: 'SN-001' },
|
|
57
|
+
{ gtin: '01234567890128', serial: 'SN-002' },
|
|
58
|
+
{ gtin: '01234567890128', serial: 'SN-003' },
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Keys
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Create a key
|
|
67
|
+
const key = await client.keys.create({ name: 'Production Key' });
|
|
68
|
+
|
|
69
|
+
// List keys
|
|
70
|
+
const keys = await client.keys.list();
|
|
71
|
+
|
|
72
|
+
// Revoke a key
|
|
73
|
+
await client.keys.revoke('key-id');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Error Handling
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { OptropicError, AuthenticationError } from 'optropic';
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await client.assets.verify(id);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof AuthenticationError) {
|
|
85
|
+
// Handle invalid API key
|
|
86
|
+
} else if (error instanceof OptropicError) {
|
|
87
|
+
console.error(error.code, error.message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
| Option | Type | Default | Description |
|
|
95
|
+
|--------|------|---------|-------------|
|
|
96
|
+
| apiKey | string | required | API key (`optr_live_*` or `optr_test_*`) |
|
|
97
|
+
| baseUrl | string | `https://api.optropic.com` | API base URL |
|
|
98
|
+
| timeout | number | `30000` | Request timeout (ms) |
|
|
99
|
+
| retry | RetryConfig | `{ maxRetries: 3 }` | Retry configuration |
|
|
100
|
+
| headers | Record<string, string> | `{}` | Custom headers |
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT © [Optropic GmbH](https://optropic.com)
|