@opentdf/sdk 0.4.0-beta.19 → 0.4.0-beta.6
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 +1 -16
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +1 -15
- package/dist/cjs/src/index.js +2 -4
- package/dist/cjs/src/opentdf.js +12 -64
- package/dist/cjs/src/platform.js +3 -14
- package/dist/cjs/src/seekable.js +1 -32
- package/dist/cjs/src/utils.js +3 -57
- package/dist/types/src/access.d.ts +0 -15
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +0 -14
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +6 -126
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/platform.d.ts +0 -16
- package/dist/types/src/platform.d.ts.map +1 -1
- package/dist/types/src/seekable.d.ts +0 -31
- package/dist/types/src/seekable.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +2 -56
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/web/src/access.js +1 -16
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +1 -15
- package/dist/web/src/index.js +1 -2
- package/dist/web/src/opentdf.js +12 -64
- package/dist/web/src/platform.js +3 -14
- package/dist/web/src/seekable.js +1 -32
- package/dist/web/src/utils.js +3 -57
- package/package.json +3 -5
- package/src/access.ts +0 -15
- package/src/auth/oidc-refreshtoken-provider.ts +0 -14
- package/src/index.ts +0 -1
- package/src/opentdf.ts +71 -147
- package/src/platform.ts +5 -17
- package/src/seekable.ts +0 -31
- package/src/utils.ts +2 -56
package/src/utils.ts
CHANGED
|
@@ -35,12 +35,6 @@ 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
|
-
*/
|
|
44
38
|
export function padSlashToUrl(u: string): string {
|
|
45
39
|
if (u.endsWith('/')) {
|
|
46
40
|
return u;
|
|
@@ -48,21 +42,10 @@ export function padSlashToUrl(u: string): string {
|
|
|
48
42
|
return `${u}/`;
|
|
49
43
|
}
|
|
50
44
|
|
|
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
|
-
*/
|
|
56
45
|
export function isBrowser() {
|
|
57
46
|
return typeof window !== 'undefined'; // eslint-disable-line
|
|
58
47
|
}
|
|
59
48
|
|
|
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
|
-
*/
|
|
66
49
|
export const rstrip = (str: string, suffix = ' '): string => {
|
|
67
50
|
while (str && suffix && str.endsWith(suffix)) {
|
|
68
51
|
str = str.slice(0, -suffix.length);
|
|
@@ -109,15 +92,6 @@ export const estimateSkewFromHeaders = (headers: AnyHeaders, dateNowBefore?: num
|
|
|
109
92
|
return Math.round((deltaBefore + deltaAfter) / 2);
|
|
110
93
|
};
|
|
111
94
|
|
|
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
|
-
*/
|
|
121
95
|
export function addNewLines(str: string): string {
|
|
122
96
|
if (!str) {
|
|
123
97
|
return str;
|
|
@@ -131,11 +105,6 @@ export function addNewLines(str: string): string {
|
|
|
131
105
|
return finalString;
|
|
132
106
|
}
|
|
133
107
|
|
|
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
|
-
*/
|
|
139
108
|
export async function cryptoPublicToPem(publicKey: CryptoKey): Promise<string> {
|
|
140
109
|
if (publicKey.type !== 'public') {
|
|
141
110
|
throw new ConfigurationError('incorrect key type');
|
|
@@ -147,11 +116,6 @@ export async function cryptoPublicToPem(publicKey: CryptoKey): Promise<string> {
|
|
|
147
116
|
return `-----BEGIN PUBLIC KEY-----\r\n${pem}-----END PUBLIC KEY-----`;
|
|
148
117
|
}
|
|
149
118
|
|
|
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
|
-
*/
|
|
155
119
|
export async function pemToCryptoPublicKey(pem: string): Promise<CryptoKey> {
|
|
156
120
|
if (/-----BEGIN PUBLIC KEY-----/.test(pem)) {
|
|
157
121
|
return pemPublicToCrypto(pem);
|
|
@@ -164,15 +128,6 @@ export async function pemToCryptoPublicKey(pem: string): Promise<CryptoKey> {
|
|
|
164
128
|
throw new TypeError(`unsupported pem type [${pem}]`);
|
|
165
129
|
}
|
|
166
130
|
|
|
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
|
-
*/
|
|
176
131
|
export async function extractPemFromKeyString(keyString: string): Promise<string> {
|
|
177
132
|
let pem: string = keyString;
|
|
178
133
|
|
|
@@ -188,12 +143,6 @@ export async function extractPemFromKeyString(keyString: string): Promise<string
|
|
|
188
143
|
|
|
189
144
|
/**
|
|
190
145
|
* 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.
|
|
197
146
|
*/
|
|
198
147
|
export function extractRpcErrorMessage(error: unknown): string {
|
|
199
148
|
if (error instanceof ConnectError || error instanceof Error) {
|
|
@@ -204,11 +153,8 @@ export function extractRpcErrorMessage(error: unknown): string {
|
|
|
204
153
|
|
|
205
154
|
/**
|
|
206
155
|
* Converts a KAS endpoint URL to a platform URL.
|
|
207
|
-
*
|
|
208
|
-
*
|
|
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.
|
|
156
|
+
* If the KAS endpoint ends with '/kas', it returns the host url
|
|
157
|
+
* Otherwise, it returns the original KAS endpoint.
|
|
212
158
|
*/
|
|
213
159
|
export function getPlatformUrlFromKasEndpoint(endpoint: string): string {
|
|
214
160
|
let result = endpoint || '';
|