@veilgroup/sdk-woro 0.1.1

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 ADDED
@@ -0,0 +1,78 @@
1
+ # WORO JavaScript SDK
2
+
3
+ Use WORO from JavaScript or TypeScript applications to send a piece of data and let its intended user retrieve it once.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @veilgroup/sdk-woro
9
+ # or
10
+ pnpm add @veilgroup/sdk-woro
11
+ ```
12
+
13
+ ## Send and retrieve data
14
+
15
+ ```ts
16
+ import { WoroClient } from '@veilgroup/sdk-woro';
17
+
18
+ const woro = new WoroClient({ writeToken: process.env.WORO_WRITE_TOKEN });
19
+ const { readToken } = await woro.writeSecret('one-time value');
20
+
21
+ // Share the read token with the person or application that needs the data.
22
+ const received = await woro.readSecret(readToken);
23
+ console.log(new TextDecoder().decode(received.data));
24
+ ```
25
+
26
+ Reading consumes the data. WORO deletes its stored copy as it is retrieved. A read token can be redeemed only once. Data that is not redeemed expires after 14 days.
27
+
28
+ The SDK also accepts binary data as a `Uint8Array`, `ArrayBuffer`, or `Blob`. A string is encoded as UTF-8. To create a read token before data is ready, call `createEmptySlot()` and later fill it once with `fillSecret(readToken, data)`.
29
+
30
+ ## Compression and encryption
31
+
32
+ The SDK compresses data locally when compression makes the request smaller. The receiving application using this SDK restores the original data.
33
+
34
+ Encryption is optional. Provide the same 32-byte key when writing and reading:
35
+
36
+ ```ts
37
+ const key = crypto.getRandomValues(new Uint8Array(32));
38
+ const { readToken } = await woro.writeSecret(file, {
39
+ encryptionKey: key,
40
+ contentType: 'application/octet-stream',
41
+ });
42
+
43
+ // Share the read token and encryption key through separate channels.
44
+ const received = await woro.readSecret(readToken, { encryptionKey: key });
45
+ ```
46
+
47
+ The SDK uses the key in your application and sends encrypted data to WORO. Share the key separately from the read token. Anyone who has both can decrypt the data. Keep keys out of URLs and logs. If retrieval succeeds but decryption fails, the SDK error includes the original encrypted bytes so they can be recovered with the correct key; the read token has still been consumed.
48
+
49
+ The SDK's original and transformed request bodies must each fit WORO's 1 MiB request limit. The SDK also limits decompression to 1 MiB.
50
+
51
+ ## Account features
52
+
53
+ Account features let you check your balance, manage write tokens, and inspect the status of a read token you created. Sign in with your WORO account username and password:
54
+
55
+ ```ts
56
+ await woro.signIn(username, password);
57
+
58
+ const balance = await woro.getAccountBalance();
59
+ const writeTokens = await woro.listWriteTokens();
60
+ const status = await woro.getSecretStatus(readToken);
61
+
62
+ await woro.signOut();
63
+ ```
64
+
65
+ Account features require the WORO account sign-in settings to be configured for your application. The SDK keeps the sign-in session in memory; `signOut()` clears it. The current sign-in flow does not support multi-factor authentication or forced password-reset challenges.
66
+
67
+ ## Credits and limits
68
+
69
+ - Each call to `writeSecret()` or `createEmptySlot()` consumes one credit and starts the 14-day expiry period.
70
+ - Filling an empty slot does not consume another credit.
71
+ - Reading or deleting data does not refund the credit.
72
+ - A request body can be up to 1 MiB after compression and optional encryption.
73
+
74
+ API errors are reported as `WoroApiError`; sign-in errors as `WoroAuthError`; and payload processing errors as `WoroPayloadError`.
75
+
76
+ ## Licence
77
+
78
+ This package is published as `UNLICENSED`. Downloading it does not grant general permission to use, modify, or redistribute it. Contact [support@veilgroup.au](mailto:support@veilgroup.au) to discuss permission.
@@ -0,0 +1,95 @@
1
+ import { type PayloadOptions, type WoroInput } from './payload.js';
2
+ export declare const WORO_PRODUCTION_URL = "https://woro.veilgroup.au";
3
+ export interface CognitoConfig {
4
+ region: string;
5
+ userPoolId: string;
6
+ appClientId: string;
7
+ }
8
+ export interface WoroClientOptions {
9
+ baseUrl?: string;
10
+ writeToken?: string;
11
+ idToken?: string;
12
+ cognito?: CognitoConfig;
13
+ fetch?: typeof fetch;
14
+ }
15
+ export interface WriteOptions extends PayloadOptions {
16
+ writeToken?: string;
17
+ }
18
+ export interface ReadOptions {
19
+ encryptionKey?: Uint8Array;
20
+ }
21
+ export interface CreatedSecret {
22
+ readToken: string;
23
+ expiresAt: string;
24
+ }
25
+ export interface ReadSecret {
26
+ data: Uint8Array;
27
+ contentType: string;
28
+ }
29
+ export interface SecretStatus {
30
+ state: string | null;
31
+ createdAt: string | null;
32
+ expiresAt: string | null;
33
+ uploadedAt: string | null;
34
+ redeemedAt: string | null;
35
+ deletedAt: string | null;
36
+ }
37
+ export interface AccountOverview {
38
+ id: string;
39
+ email?: string;
40
+ status?: string;
41
+ createdAt?: string;
42
+ credits: number;
43
+ [key: string]: unknown;
44
+ }
45
+ export interface AccountBalance {
46
+ credits: number;
47
+ [key: string]: unknown;
48
+ }
49
+ export interface WriteTokenRecord {
50
+ id: string;
51
+ label?: string;
52
+ createdAt?: string;
53
+ active?: boolean;
54
+ [key: string]: unknown;
55
+ }
56
+ export interface CreatedWriteToken {
57
+ id: string;
58
+ token: string;
59
+ label?: string;
60
+ createdAt?: string;
61
+ [key: string]: unknown;
62
+ }
63
+ export declare class WoroClient {
64
+ readonly baseUrl: string;
65
+ private readonly fetcher;
66
+ private readonly cognito;
67
+ private writeToken;
68
+ private idToken;
69
+ private idTokenExpiresAt;
70
+ constructor(options?: WoroClientOptions);
71
+ setWriteToken(token: string | undefined): void;
72
+ setIdToken(token: string | undefined, expiresInSeconds?: number): void;
73
+ signOut(): void;
74
+ signIn(username: string, password: string): Promise<{
75
+ idToken: string;
76
+ expiresIn: number;
77
+ }>;
78
+ writeSecret(input: WoroInput, options?: WriteOptions): Promise<CreatedSecret>;
79
+ createEmptySlot(writeToken?: string): Promise<CreatedSecret>;
80
+ fillSecret(readToken: string, input: WoroInput, options?: PayloadOptions): Promise<void>;
81
+ readSecret(readToken: string, options?: ReadOptions): Promise<ReadSecret>;
82
+ deleteSecret(readToken: string): Promise<void>;
83
+ getSecretStatus(readToken: string): Promise<SecretStatus>;
84
+ getAccount(): Promise<AccountOverview>;
85
+ getAccountBalance(): Promise<AccountBalance>;
86
+ listWriteTokens(): Promise<WriteTokenRecord[]>;
87
+ createWriteToken(label: string): Promise<CreatedWriteToken>;
88
+ revokeWriteToken(tokenId: string): Promise<void>;
89
+ checkWriteToken(writeToken?: string): Promise<string | null>;
90
+ private getWriteToken;
91
+ private authorizationHeaders;
92
+ private assertPayloadSize;
93
+ private request;
94
+ }
95
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,YAAa,SAAQ,cAAc;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE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iError extends Error {
2
+ readonly status: number;
3
+ readonly code?: string | undefined;
4
+ constructor(status: number, message: string, code?: string | undefined);
5
+ }
6
+ export declare class WoroAuthError extends Error {
7
+ readonly code?: string | undefined;
8
+ constructor(message: string, code?: string | undefined);
9
+ }
10
+ export declare class WoroPayloadError extends Error {
11
+ readonly rawPayload?: Uint8Array | undefined;
12
+ constructor(message: string, rawPayload?: Uint8Array | undefined);
13
+ }
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;aAEnB,MAAM,EAAE,MAAM;aAEd,IAAI,CAAC,EAAE,MAAM;gBAFb,MAAM,EAAE,MAAM,EAC9B,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,MAAM,YAAA;CAKhC;AAED,qBAAa,aAAc,SAAQ,KAAK;aACO,IAAI,CAAC,EAAE,MAAM;gBAA9C,OAAO,EAAE,MAAM,EAAkB,IAAI,CAAC,EAAE,MAAM,YAAA;CAI3D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;aACI,UAAU,CAAC,EAAE,UAAU;gBAAxD,OAAO,EAAE,MAAM,EAAkB,UAAU,CAAC,EAAE,UAAU,YAAA;CAIrE"}