@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.
Files changed (36) hide show
  1. package/dist/cjs/src/access.js +1 -16
  2. package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +1 -15
  3. package/dist/cjs/src/index.js +2 -4
  4. package/dist/cjs/src/opentdf.js +12 -64
  5. package/dist/cjs/src/platform.js +3 -14
  6. package/dist/cjs/src/seekable.js +1 -32
  7. package/dist/cjs/src/utils.js +3 -57
  8. package/dist/types/src/access.d.ts +0 -15
  9. package/dist/types/src/access.d.ts.map +1 -1
  10. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +0 -14
  11. package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
  12. package/dist/types/src/index.d.ts +0 -1
  13. package/dist/types/src/index.d.ts.map +1 -1
  14. package/dist/types/src/opentdf.d.ts +6 -126
  15. package/dist/types/src/opentdf.d.ts.map +1 -1
  16. package/dist/types/src/platform.d.ts +0 -16
  17. package/dist/types/src/platform.d.ts.map +1 -1
  18. package/dist/types/src/seekable.d.ts +0 -31
  19. package/dist/types/src/seekable.d.ts.map +1 -1
  20. package/dist/types/src/utils.d.ts +2 -56
  21. package/dist/types/src/utils.d.ts.map +1 -1
  22. package/dist/web/src/access.js +1 -16
  23. package/dist/web/src/auth/oidc-refreshtoken-provider.js +1 -15
  24. package/dist/web/src/index.js +1 -2
  25. package/dist/web/src/opentdf.js +12 -64
  26. package/dist/web/src/platform.js +3 -14
  27. package/dist/web/src/seekable.js +1 -32
  28. package/dist/web/src/utils.js +3 -57
  29. package/package.json +3 -5
  30. package/src/access.ts +0 -15
  31. package/src/auth/oidc-refreshtoken-provider.ts +0 -14
  32. package/src/index.ts +0 -1
  33. package/src/opentdf.ts +71 -147
  34. package/src/platform.ts +5 -17
  35. package/src/seekable.ts +0 -31
  36. 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
- * @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.
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 || '';