From cf1da606d4172542545eb3814ec2e5e64ecbe979 Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 11 Aug 2024 18:24:01 -0500 Subject: [PATCH 1/5] adding azure table client module --- .../modules/src/azTable/az-table.constants.ts | 1 + .../modules/src/azTable/az-table.interface.ts | 5 ++ libs/modules/src/azTable/az-table.module.ts | 21 ++++++ libs/modules/src/azTable/az-table.service.ts | 19 +++++ libs/modules/src/index.ts | 5 ++ package-lock.json | 70 ++++++++++++++++++- package.json | 1 + 7 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 libs/modules/src/azTable/az-table.constants.ts create mode 100644 libs/modules/src/azTable/az-table.interface.ts create mode 100644 libs/modules/src/azTable/az-table.module.ts create mode 100644 libs/modules/src/azTable/az-table.service.ts diff --git a/libs/modules/src/azTable/az-table.constants.ts b/libs/modules/src/azTable/az-table.constants.ts new file mode 100644 index 0000000..cde8d41 --- /dev/null +++ b/libs/modules/src/azTable/az-table.constants.ts @@ -0,0 +1 @@ +export const TABLE_OPTIONS = 'TABLE_OPTIONS'; \ No newline at end of file diff --git a/libs/modules/src/azTable/az-table.interface.ts b/libs/modules/src/azTable/az-table.interface.ts new file mode 100644 index 0000000..6b7387e --- /dev/null +++ b/libs/modules/src/azTable/az-table.interface.ts @@ -0,0 +1,5 @@ +export interface TableOptions { + accountName: string; + accountKey: string; + tableName: string; +} \ No newline at end of file diff --git a/libs/modules/src/azTable/az-table.module.ts b/libs/modules/src/azTable/az-table.module.ts new file mode 100644 index 0000000..7c3c662 --- /dev/null +++ b/libs/modules/src/azTable/az-table.module.ts @@ -0,0 +1,21 @@ +import { Module, DynamicModule } from '@nestjs/common'; +import { TableService } from './az-table.service'; +import { TableOptions } from './az-table.interface'; +import { TABLE_OPTIONS } from './az-table.constants'; + +@Module({}) +export class TablesModule { + static register(options: TableOptions): DynamicModule { + return { + module: TablesModule, + providers: [ + { + provide: TABLE_OPTIONS, + useValue: options + }, + TablesModule + ], + exports: [TableService] + } + } +} \ No newline at end of file diff --git a/libs/modules/src/azTable/az-table.service.ts b/libs/modules/src/azTable/az-table.service.ts new file mode 100644 index 0000000..b73fc40 --- /dev/null +++ b/libs/modules/src/azTable/az-table.service.ts @@ -0,0 +1,19 @@ +import { Inject, Injectable } from '@nestjs/common'; +import { TableOptions } from './az-table.interface'; +import { TABLE_OPTIONS } from './az-table.constants'; +import { TableClient, AzureNamedKeyCredential } from '@azure/data-tables'; + +@Injectable() +export class TableService { + constructor( + @Inject(TABLE_OPTIONS) + private tablesOptions: TableOptions + ) {} + + async getTableClient(): Promise { + const credential: AzureNamedKeyCredential = new AzureNamedKeyCredential(this.tablesOptions.accountName, this.tablesOptions.accountKey); + const tableClient: TableClient = new TableClient(`https://${this.tablesOptions.accountName}`, this.tablesOptions.tableName, credential); + + return tableClient; + } +} \ No newline at end of file diff --git a/libs/modules/src/index.ts b/libs/modules/src/index.ts index 57f094e..ec1bfd7 100644 --- a/libs/modules/src/index.ts +++ b/libs/modules/src/index.ts @@ -3,6 +3,11 @@ export * from './azAppConfig/az-app-config.module'; export * from './azAppConfig/az-app-config.service'; +// Azure Data Tables + +export * from './azTable/az-table.module'; +export * from './azTable/az-table.service'; + // Auth export * from './auth/auth.module'; diff --git a/package-lock.json b/package-lock.json index 006e21b..3b25966 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "@noahspan/noahspan-modules", - "version": "0.2.9", + "version": "0.3.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@noahspan/noahspan-modules", - "version": "0.2.9", + "version": "0.3.5", "license": "UNLICENSED", "dependencies": { "@azure/app-configuration": "^1.6.0", + "@azure/data-tables": "^13.2.2", "@azure/identity": "^4.2.0", "@azure/msal-node": "^2.9.2", "@microsoft/microsoft-graph-client": "^3.0.7", @@ -438,6 +439,45 @@ "node": ">=18.0.0" } }, + "node_modules/@azure/core-xml": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@azure/core-xml/-/core-xml-1.4.3.tgz", + "integrity": "sha512-D6G7FEmDiTctPKuWegX2WTrS1enKZwqYwdKTO6ZN6JMigcCehlT0/CYl+zWpI9vQ9frwwp7GQT3/owaEXgnOsA==", + "dependencies": { + "fast-xml-parser": "^4.3.2", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@azure/data-tables": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/@azure/data-tables/-/data-tables-13.2.2.tgz", + "integrity": "sha512-Dq2Aq0mMMF0BPzYQKdBY/OtO7VemP/foh6z+mJpUO1hRL+65C1rGQUJf20LJHotSyU8wHb4HJzOs+Z50GXSy1w==", + "dependencies": { + "@azure/core-auth": "^1.3.0", + "@azure/core-client": "^1.0.0", + "@azure/core-paging": "^1.1.1", + "@azure/core-rest-pipeline": "^1.1.0", + "@azure/core-tracing": "^1.0.0", + "@azure/core-xml": "^1.0.0", + "@azure/logger": "^1.0.0", + "tslib": "^2.2.0", + "uuid": "^8.3.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@azure/data-tables/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@azure/identity": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@azure/identity/-/identity-4.2.0.tgz", @@ -4772,6 +4812,27 @@ "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" }, + "node_modules/fast-xml-parser": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.4.1.tgz", + "integrity": "sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + }, + { + "type": "paypal", + "url": "https://paypal.me/naturalintelligence" + } + ], + "dependencies": { + "strnum": "^1.0.5" + }, + "bin": { + "fxparser": "src/cli/cli.js" + } + }, "node_modules/fastq": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", @@ -8644,6 +8705,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==" + }, "node_modules/superagent": { "version": "8.1.2", "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", diff --git a/package.json b/package.json index a83f5d7..4cc3b9f 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "dependencies": { "@azure/app-configuration": "^1.6.0", + "@azure/data-tables": "^13.2.2", "@azure/identity": "^4.2.0", "@azure/msal-node": "^2.9.2", "@microsoft/microsoft-graph-client": "^3.0.7", -- 2.49.1 From dbe79d5e1b04cf480481f86f6fbaeca7f2d437eb Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 11 Aug 2024 18:38:02 -0500 Subject: [PATCH 2/5] adding azure table client module --- libs/modules/src/azTable/az-table.module.ts | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/modules/src/azTable/az-table.module.ts b/libs/modules/src/azTable/az-table.module.ts index 7c3c662..a9e806a 100644 --- a/libs/modules/src/azTable/az-table.module.ts +++ b/libs/modules/src/azTable/az-table.module.ts @@ -4,16 +4,16 @@ import { TableOptions } from './az-table.interface'; import { TABLE_OPTIONS } from './az-table.constants'; @Module({}) -export class TablesModule { +export class TableModule { static register(options: TableOptions): DynamicModule { return { - module: TablesModule, + module: TableModule, providers: [ { provide: TABLE_OPTIONS, useValue: options }, - TablesModule + TableModule ], exports: [TableService] } diff --git a/package.json b/package.json index 4cc3b9f..7b2e799 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahspan/noahspan-modules", - "version": "0.3.5", + "version": "0.3.7", "description": "", "author": "", "license": "UNLICENSED", -- 2.49.1 From db969534432f43b850c02a6d21d2c49f23729c3f Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 11 Aug 2024 19:00:46 -0500 Subject: [PATCH 3/5] adding azure table client module --- libs/modules/src/azTable/az-table.interface.ts | 1 - libs/modules/src/azTable/az-table.service.ts | 4 ++-- package.json | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libs/modules/src/azTable/az-table.interface.ts b/libs/modules/src/azTable/az-table.interface.ts index 6b7387e..4a80ed2 100644 --- a/libs/modules/src/azTable/az-table.interface.ts +++ b/libs/modules/src/azTable/az-table.interface.ts @@ -1,5 +1,4 @@ export interface TableOptions { accountName: string; accountKey: string; - tableName: string; } \ No newline at end of file diff --git a/libs/modules/src/azTable/az-table.service.ts b/libs/modules/src/azTable/az-table.service.ts index b73fc40..242ea95 100644 --- a/libs/modules/src/azTable/az-table.service.ts +++ b/libs/modules/src/azTable/az-table.service.ts @@ -10,9 +10,9 @@ export class TableService { private tablesOptions: TableOptions ) {} - async getTableClient(): Promise { + async getTableClient(tableName: string): Promise { const credential: AzureNamedKeyCredential = new AzureNamedKeyCredential(this.tablesOptions.accountName, this.tablesOptions.accountKey); - const tableClient: TableClient = new TableClient(`https://${this.tablesOptions.accountName}`, this.tablesOptions.tableName, credential); + const tableClient: TableClient = new TableClient(`https://${this.tablesOptions.accountName}.table.core.windows.net`, tableName, credential); return tableClient; } diff --git a/package.json b/package.json index 7b2e799..191ed49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahspan/noahspan-modules", - "version": "0.3.7", + "version": "0.3.8", "description": "", "author": "", "license": "UNLICENSED", -- 2.49.1 From 0cfb2edd837eddef61c3c65a359e0fa7a1fc8d56 Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 11 Aug 2024 19:45:35 -0500 Subject: [PATCH 4/5] adding azure table client module --- libs/modules/src/azTable/az-table.module.ts | 2 +- libs/modules/src/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/modules/src/azTable/az-table.module.ts b/libs/modules/src/azTable/az-table.module.ts index a9e806a..774f227 100644 --- a/libs/modules/src/azTable/az-table.module.ts +++ b/libs/modules/src/azTable/az-table.module.ts @@ -13,7 +13,7 @@ export class TableModule { provide: TABLE_OPTIONS, useValue: options }, - TableModule + TableService ], exports: [TableService] } diff --git a/libs/modules/src/index.ts b/libs/modules/src/index.ts index ec1bfd7..3222471 100644 --- a/libs/modules/src/index.ts +++ b/libs/modules/src/index.ts @@ -7,6 +7,7 @@ export * from './azAppConfig/az-app-config.service'; export * from './azTable/az-table.module'; export * from './azTable/az-table.service'; +export { TableClient } from '@azure/data-tables'; // Auth -- 2.49.1 From f62c8a0c13440e5ee5b22b288d9b09dffc85288e Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 11 Aug 2024 19:45:47 -0500 Subject: [PATCH 5/5] adding azure table client module --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 191ed49..ed3cba0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahspan/noahspan-modules", - "version": "0.3.8", + "version": "0.3.9", "description": "", "author": "", "license": "UNLICENSED", -- 2.49.1