@opentdf/sdk 0.4.0-beta.13 → 0.4.0-beta.14
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/cjs/src/access.js +16 -1
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +15 -1
- package/dist/cjs/src/index.js +4 -2
- package/dist/cjs/src/opentdf.js +64 -12
- package/dist/cjs/src/platform.js +14 -3
- package/dist/cjs/src/seekable.js +32 -1
- package/dist/cjs/src/utils.js +57 -3
- package/dist/types/src/access.d.ts +15 -0
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +14 -0
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +126 -6
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +16 -0
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/seekable.d.ts +31 -0
- package/dist/types/src/seekable.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +56 -2
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/web/src/access.js +16 -1
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +15 -1
- package/dist/web/src/index.js +2 -1
- package/dist/web/src/opentdf.js +64 -12
- package/dist/web/src/platform.js +14 -3
- package/dist/web/src/seekable.js +32 -1
- package/dist/web/src/utils.js +57 -3
- package/package.json +5 -3
- package/src/access.ts +15 -0
- package/src/auth/oidc-refreshtoken-provider.ts +14 -0
- package/src/index.ts +1 -0
- package/src/opentdf.ts +147 -71
- package/src/platform.ts +17 -5
- package/src/seekable.ts +31 -0
- package/src/utils.ts +56 -2
package/src/utils.ts
CHANGED
|
@@ -35,6 +35,12 @@ export function validateSecureUrl(url: string): boolean {
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Pads a URL with a trailing slash if it does not already have one.
|
|
40
|
+
* This is useful for ensuring that URLs are in a consistent format.
|
|
41
|
+
* @param u The URL to pad.
|
|
42
|
+
* @returns The padded URL.
|
|
43
|
+
*/
|
|
38
44
|
export function padSlashToUrl(u: string): string {
|
|
39
45
|
if (u.endsWith('/')) {
|
|
40
46
|
return u;
|
|
@@ -42,10 +48,21 @@ export function padSlashToUrl(u: string): string {
|
|
|
42
48
|
return `${u}/`;
|
|
43
49
|
}
|
|
44
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Checks if the current environment is a browser.
|
|
53
|
+
* This is useful for determining if certain APIs or features are available.
|
|
54
|
+
* @returns true if running in a browser, false otherwise.
|
|
55
|
+
*/
|
|
45
56
|
export function isBrowser() {
|
|
46
57
|
return typeof window !== 'undefined'; // eslint-disable-line
|
|
47
58
|
}
|
|
48
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Removes trailing characters from a string.
|
|
62
|
+
* @param str The string to trim.
|
|
63
|
+
* @param suffix The suffix to remove (default is a single space).
|
|
64
|
+
* @returns The trimmed string.
|
|
65
|
+
*/
|
|
49
66
|
export const rstrip = (str: string, suffix = ' '): string => {
|
|
50
67
|
while (str && suffix && str.endsWith(suffix)) {
|
|
51
68
|
str = str.slice(0, -suffix.length);
|
|
@@ -92,6 +109,15 @@ export const estimateSkewFromHeaders = (headers: AnyHeaders, dateNowBefore?: num
|
|
|
92
109
|
return Math.round((deltaBefore + deltaAfter) / 2);
|
|
93
110
|
};
|
|
94
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Adds new lines to a string every 64 characters.
|
|
114
|
+
* @param str A string to add new lines to.
|
|
115
|
+
* This function takes a string and adds new lines every 64 characters.
|
|
116
|
+
* If the string is empty or undefined, it returns the original string.
|
|
117
|
+
* This is useful for formatting long strings, such as public keys or certificates,
|
|
118
|
+
* to ensure they are properly formatted for PEM encoding.
|
|
119
|
+
* @returns The formatted string with new lines added.
|
|
120
|
+
*/
|
|
95
121
|
export function addNewLines(str: string): string {
|
|
96
122
|
if (!str) {
|
|
97
123
|
return str;
|
|
@@ -105,6 +131,11 @@ export function addNewLines(str: string): string {
|
|
|
105
131
|
return finalString;
|
|
106
132
|
}
|
|
107
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Creates a PEM-encoded string from a public key.
|
|
136
|
+
* @param publicKey The public key to convert.
|
|
137
|
+
* @returns A promise that resolves to a PEM-encoded string.
|
|
138
|
+
*/
|
|
108
139
|
export async function cryptoPublicToPem(publicKey: CryptoKey): Promise<string> {
|
|
109
140
|
if (publicKey.type !== 'public') {
|
|
110
141
|
throw new ConfigurationError('incorrect key type');
|
|
@@ -116,6 +147,11 @@ export async function cryptoPublicToPem(publicKey: CryptoKey): Promise<string> {
|
|
|
116
147
|
return `-----BEGIN PUBLIC KEY-----\r\n${pem}-----END PUBLIC KEY-----`;
|
|
117
148
|
}
|
|
118
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Converts a PEM-encoded public key to a CryptoKey.
|
|
152
|
+
* @param pem The PEM-encoded public key.
|
|
153
|
+
* @returns A promise that resolves to a CryptoKey.
|
|
154
|
+
*/
|
|
119
155
|
export async function pemToCryptoPublicKey(pem: string): Promise<CryptoKey> {
|
|
120
156
|
if (/-----BEGIN PUBLIC KEY-----/.test(pem)) {
|
|
121
157
|
return pemPublicToCrypto(pem);
|
|
@@ -128,6 +164,15 @@ export async function pemToCryptoPublicKey(pem: string): Promise<CryptoKey> {
|
|
|
128
164
|
throw new TypeError(`unsupported pem type [${pem}]`);
|
|
129
165
|
}
|
|
130
166
|
|
|
167
|
+
/**
|
|
168
|
+
* Extracts the PEM-encoded public key from a key string.
|
|
169
|
+
* @param keyString A string containing a public key or certificate.
|
|
170
|
+
* This function extracts the PEM-encoded public key from a given key string.
|
|
171
|
+
* If the key string contains a certificate, it imports the certificate and exports
|
|
172
|
+
* the public key in PEM format. If the key string is already in PEM format, it returns
|
|
173
|
+
* the key string as is.
|
|
174
|
+
* @returns A promise that resolves to a PEM-encoded public key.
|
|
175
|
+
*/
|
|
131
176
|
export async function extractPemFromKeyString(keyString: string): Promise<string> {
|
|
132
177
|
let pem: string = keyString;
|
|
133
178
|
|
|
@@ -143,6 +188,12 @@ export async function extractPemFromKeyString(keyString: string): Promise<string
|
|
|
143
188
|
|
|
144
189
|
/**
|
|
145
190
|
* Extracts the error message from an RPC catch error.
|
|
191
|
+
* @param error An error object, typically from a network request.
|
|
192
|
+
* This function extracts the error message from a ConnectError or a generic Error.
|
|
193
|
+
* If the error is a ConnectError or a standard Error, it returns the message.
|
|
194
|
+
* If the error is of an unknown type, it returns a default message indicating
|
|
195
|
+
* that an unknown network error occurred.
|
|
196
|
+
* @returns The extracted error message.
|
|
146
197
|
*/
|
|
147
198
|
export function extractRpcErrorMessage(error: unknown): string {
|
|
148
199
|
if (error instanceof ConnectError || error instanceof Error) {
|
|
@@ -153,8 +204,11 @@ export function extractRpcErrorMessage(error: unknown): string {
|
|
|
153
204
|
|
|
154
205
|
/**
|
|
155
206
|
* Converts a KAS endpoint URL to a platform URL.
|
|
156
|
-
*
|
|
157
|
-
*
|
|
207
|
+
* @param endpoint The KAS endpoint URL to extract the platform URL from.
|
|
208
|
+
* This function extracts the base URL from a KAS endpoint URL.
|
|
209
|
+
* It removes any trailing slashes and specific path segments related to rewrap or kas.
|
|
210
|
+
* This is useful for obtaining the base URL for further API requests.
|
|
211
|
+
* @returns The base URL of the platform.
|
|
158
212
|
*/
|
|
159
213
|
export function getPlatformUrlFromKasEndpoint(endpoint: string): string {
|
|
160
214
|
let result = endpoint || '';
|