@oino-ts/blob-azure 1.0.4 → 1.0.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.
@@ -42,7 +42,7 @@ class OINOBlobAzure extends blob_1.OINOBlob {
42
42
  _containerClient = null;
43
43
  constructor(params) {
44
44
  super(params);
45
- if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) { // && this.blobParams.credentials?.clientId)) {
45
+ if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) {
46
46
  throw new Error("OINOBlobAzure: missing or invalid credentials (provide either connectionStr or url and clientId)");
47
47
  }
48
48
  }
@@ -58,7 +58,7 @@ class OINOBlobAzure extends blob_1.OINOBlob {
58
58
  }
59
59
  else if (this.blobParams.credentials?.url) { // && this.blobParams.credentials?.clientId) {
60
60
  // Use ContainerClient directly to avoid double-container path when combining service URL + container
61
- serviceClient = new storage_blob_1.BlobServiceClient(this.blobParams.credentials.url, new identity_1.DefaultAzureCredential());
61
+ serviceClient = new storage_blob_1.BlobServiceClient(this.blobParams.credentials.url, new identity_1.DefaultAzureCredential({ managedIdentityClientId: this.blobParams.credentials.clientId }));
62
62
  this.isConnected = true;
63
63
  }
64
64
  this._containerClient = serviceClient.getContainerClient(this.blobParams.container);
@@ -174,8 +174,7 @@ class OINOBlobAzure extends blob_1.OINOBlob {
174
174
  throw new Error("OINOBlobAzure: not connected");
175
175
  }
176
176
  const blockBlobClient = this._containerClient.getBlockBlobClient(name);
177
- const headers = { blobDataType: contentType };
178
- await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: headers });
177
+ await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: { blobContentType: contentType } });
179
178
  }
180
179
  /**
181
180
  * Delete a named blob.
@@ -39,7 +39,7 @@ export class OINOBlobAzure extends OINOBlob {
39
39
  _containerClient = null;
40
40
  constructor(params) {
41
41
  super(params);
42
- if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) { // && this.blobParams.credentials?.clientId)) {
42
+ if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) {
43
43
  throw new Error("OINOBlobAzure: missing or invalid credentials (provide either connectionStr or url and clientId)");
44
44
  }
45
45
  }
@@ -55,7 +55,7 @@ export class OINOBlobAzure extends OINOBlob {
55
55
  }
56
56
  else if (this.blobParams.credentials?.url) { // && this.blobParams.credentials?.clientId) {
57
57
  // Use ContainerClient directly to avoid double-container path when combining service URL + container
58
- serviceClient = new BlobServiceClient(this.blobParams.credentials.url, new DefaultAzureCredential());
58
+ serviceClient = new BlobServiceClient(this.blobParams.credentials.url, new DefaultAzureCredential({ managedIdentityClientId: this.blobParams.credentials.clientId }));
59
59
  this.isConnected = true;
60
60
  }
61
61
  this._containerClient = serviceClient.getContainerClient(this.blobParams.container);
@@ -171,8 +171,7 @@ export class OINOBlobAzure extends OINOBlob {
171
171
  throw new Error("OINOBlobAzure: not connected");
172
172
  }
173
173
  const blockBlobClient = this._containerClient.getBlockBlobClient(name);
174
- const headers = { blobDataType: contentType };
175
- await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: headers });
174
+ await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: { blobContentType: contentType } });
176
175
  }
177
176
  /**
178
177
  * Delete a named blob.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oino-ts/blob-azure",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "OINO TS package for using Azure Blob Storage as a REST API.",
5
5
  "author": "Matias Kiviniemi (pragmatta)",
6
6
  "license": "MPL-2.0",
@@ -22,11 +22,11 @@
22
22
  "dependencies": {
23
23
  "@azure/storage-blob": "^12.0.0",
24
24
  "@azure/identity": "^3.0.0",
25
- "@oino-ts/blob": "1.0.4",
26
- "@oino-ts/common": "1.0.4"
25
+ "@oino-ts/blob": "1.0.6",
26
+ "@oino-ts/common": "1.0.6"
27
27
  },
28
28
  "devDependencies": {
29
- "@oino-ts/types": "1.0.4",
29
+ "@oino-ts/types": "1.0.6",
30
30
  "@types/bun": "^1.1.14",
31
31
  "@types/node": "^22.0.00",
32
32
  "typescript": "~5.9.0"
@@ -42,16 +42,26 @@ import { OINOBlob, OINOBlobParams, OINOBlobDataModel, OINOBlobApi, type OINOBlob
42
42
  * })
43
43
  * ```
44
44
  */
45
+ const BLOB_AZURE_ILLEGAL_CHARS_REGEX = /[\x00-\x1f\x7f\\]/g
46
+
45
47
  export class OINOBlobAzure extends OINOBlob {
46
48
  private _containerClient: ContainerClient | null = null
47
49
 
48
50
  constructor(params: OINOBlobParams) {
49
51
  super(params)
50
- if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) { // && this.blobParams.credentials?.clientId)) {
52
+ if ((!this.blobParams.credentials?.connectionStr) && !(this.blobParams.credentials?.url)) {
51
53
  throw new Error("OINOBlobAzure: missing or invalid credentials (provide either connectionStr or url and clientId)")
52
54
  }
53
55
  }
54
56
 
57
+ /**
58
+ * Replace characters that Azure Blob Storage does not permit in blob names
59
+ * (`\` and ASCII control characters) with `_`.
60
+ */
61
+ override sanitizeName(name: string): string {
62
+ return name.replace(BLOB_AZURE_ILLEGAL_CHARS_REGEX, "_")
63
+ }
64
+
55
65
  /**
56
66
  * Initialise the Azure SDK client. Does not perform any network call.
57
67
  */
@@ -66,7 +76,7 @@ export class OINOBlobAzure extends OINOBlob {
66
76
  // Use ContainerClient directly to avoid double-container path when combining service URL + container
67
77
  serviceClient = new BlobServiceClient(
68
78
  this.blobParams.credentials.url,
69
- new DefaultAzureCredential()
79
+ new DefaultAzureCredential({ managedIdentityClientId: this.blobParams.credentials.clientId })
70
80
  )
71
81
  this.isConnected = true
72
82
  }
@@ -193,8 +203,7 @@ export class OINOBlobAzure extends OINOBlob {
193
203
  throw new Error("OINOBlobAzure: not connected")
194
204
  }
195
205
  const blockBlobClient = this._containerClient.getBlockBlobClient(name)
196
- const headers:any = { blobDataType: contentType }
197
- await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: headers })
206
+ await blockBlobClient.upload(content, content.length, { blobHTTPHeaders: { blobContentType: contentType } })
198
207
  }
199
208
 
200
209
  /**