@nu-art/google-services-backend 0.401.9 → 0.500.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.
@@ -6,9 +6,19 @@ import { google } from 'googleapis';
6
6
  import { GoogleAuth, JWTInput } from 'google-auth-library';
7
7
  type AuthClient_ = typeof google.auth.getClient;
8
8
  type ClientOptions = NonNullable<Parameters<AuthClient_>[0]>['clientOptions'];
9
+ export type AuthEntryConfig = {
10
+ credentials: JWT_Input | string;
11
+ mongo?: {
12
+ mongoUrl?: string;
13
+ firestoreMongo?: {
14
+ firestoreUid: string;
15
+ firestoreLocation: string;
16
+ };
17
+ };
18
+ };
9
19
  type AuthModuleConfig = {
10
20
  auth: {
11
- [k: string]: JWT_Input | string;
21
+ [k: string]: JWT_Input | string | AuthEntryConfig;
12
22
  };
13
23
  };
14
24
  export type JWT_Input = JWTInput;
@@ -17,7 +27,8 @@ export declare class ModuleBE_Auth_Class extends Module<AuthModuleConfig> {
17
27
  getAuth(authKey: string, scopes: string[], clientOptions?: ClientOptions): ({
18
28
  auth: GoogleAuth;
19
29
  });
20
- getAuthConfig(authKey: string): string | JWTInput;
30
+ getAuthConfig(authKey: string): JWT_Input | string | AuthEntryConfig;
31
+ getCredentials(authKey: string): JWT_Input | string;
21
32
  getJWT(authKey: string, scopes: string[]): Promise<import("google-auth-library").Credentials>;
22
33
  }
23
34
  export declare const ModuleBE_Auth: ModuleBE_Auth_Class;
@@ -9,10 +9,10 @@ export class ModuleBE_Auth_Class extends Module {
9
9
  this.setDefaultConfig({ auth: {} });
10
10
  }
11
11
  getAuth(authKey, scopes, clientOptions) {
12
- const conf = this.getAuthConfig(authKey);
12
+ const conf = this.getCredentials(authKey);
13
13
  const base = typeof conf === 'string'
14
14
  ? { keyFile: conf }
15
- : { credentials: conf }; // JWTInput
15
+ : { credentials: conf };
16
16
  const auth = new GoogleAuth({ ...base, scopes, clientOptions });
17
17
  return { auth };
18
18
  }
@@ -22,11 +22,18 @@ export class ModuleBE_Auth_Class extends Module {
22
22
  throw new ImplementationMissingException(`Config of authKey: ${authKey} was not found`);
23
23
  return projectAuth;
24
24
  }
25
+ getCredentials(authKey) {
26
+ const config = this.getAuthConfig(authKey);
27
+ if (typeof config === 'string')
28
+ return config;
29
+ if ('credentials' in config)
30
+ return config.credentials;
31
+ return config;
32
+ }
25
33
  async getJWT(authKey, scopes) {
26
- const authConfig = this.getAuthConfig(authKey);
27
- if (typeof authConfig === 'string') {
28
- return new JWT({ keyFile: authConfig, scopes }).authorize();
29
- }
34
+ const credentials = this.getCredentials(authKey);
35
+ if (typeof credentials === 'string')
36
+ return new JWT({ keyFile: credentials, scopes }).authorize();
30
37
  throw new NotImplementedYetException('cannot create a JWT from a raw credentials.. need path to file');
31
38
  }
32
39
  }
@@ -1,4 +1,4 @@
1
- import { Module } from "@nu-art/ts-common";
1
+ import { Module } from '@nu-art/ts-common';
2
2
  import { PublishOptions } from '@google-cloud/pubsub';
3
3
  declare class ModuleBE_GooglePubSub_Class extends Module {
4
4
  project(projectId: string, authKey?: string): {
@@ -1,6 +1,6 @@
1
- import { Module } from "@nu-art/ts-common";
1
+ import { Module } from '@nu-art/ts-common';
2
2
  import { PubSub } from '@google-cloud/pubsub';
3
- import { ModuleBE_Auth } from "./ModuleBE_Auth.js";
3
+ import { ModuleBE_Auth } from './ModuleBE_Auth.js';
4
4
  class ModuleBE_GooglePubSub_Class extends Module {
5
5
  project(projectId, authKey = projectId) {
6
6
  const authObject = ModuleBE_Auth.getAuth(authKey, []);
@@ -13,6 +13,7 @@ export declare class SecretKey<T extends AnyPrimitive> {
13
13
  get(fallbackValue: T): Promise<T>;
14
14
  set(secret: T): Promise<string>;
15
15
  previous(reverseIndex?: number): Promise<T | undefined>;
16
+ delete(): Promise<void>;
16
17
  modifiedTimestamp(): Promise<number>;
17
18
  }
18
19
  export declare class ModuleBE_SecretManager_Class extends Module {
@@ -24,6 +25,7 @@ export declare class ModuleBE_SecretManager_Class extends Module {
24
25
  updateSecretImpl: (secret: ISecret, data: string) => Promise<void>;
25
26
  listEnabledVersions: (secret: Secret) => Promise<google.cloud.secretmanager.v1.ISecretVersion[]>;
26
27
  getSecretVersionMetadata: (versionName: string) => Promise<google.cloud.secretmanager.v1.ISecretVersion>;
28
+ deleteSecret: (_secret: Secret) => Promise<void>;
27
29
  getOrCreateSecret: (_secret: Secret) => Promise<ISecret>;
28
30
  }
29
31
  export declare const ModuleBE_SecretManager: ModuleBE_SecretManager_Class;
@@ -32,6 +32,9 @@ export class SecretKey {
32
32
  const rawSecret = await ModuleBE_SecretManager.getSecretValueImpl(version.name);
33
33
  return rawSecret ? JSON.parse(rawSecret) : undefined;
34
34
  }
35
+ async delete() {
36
+ await ModuleBE_SecretManager.deleteSecret(this.secret);
37
+ }
35
38
  async modifiedTimestamp() {
36
39
  const versions = await ModuleBE_SecretManager.listEnabledVersions(this.secret);
37
40
  if (!versions.length)
@@ -92,6 +95,17 @@ export class ModuleBE_SecretManager_Class extends Module {
92
95
  const [version] = await this.client.getSecretVersion({ name: versionName });
93
96
  return version;
94
97
  };
98
+ deleteSecret = async (_secret) => {
99
+ const name = composeSecretKey(_secret);
100
+ try {
101
+ await this.client.deleteSecret({ name });
102
+ }
103
+ catch (err) {
104
+ if (err.code === 5)
105
+ return;
106
+ throw new ThisShouldNotHappenException(`Failed to delete secret (${JSON.stringify(_secret)})`, err);
107
+ }
108
+ };
95
109
  getOrCreateSecret = async (_secret) => {
96
110
  const name = composeSecretKey(_secret);
97
111
  try {
@@ -1,5 +1,10 @@
1
1
  import { Module } from '@nu-art/ts-common';
2
- export declare class ModuleBE_WhoAmI_GCP_Class extends Module {
2
+ type Config = {
3
+ printEnvVars: boolean;
4
+ printIdentity: boolean;
5
+ };
6
+ export declare class ModuleBE_WhoAmI_GCP_Class extends Module<Config> {
7
+ constructor();
3
8
  init(): void;
4
9
  printCallerIdentity: () => Promise<{
5
10
  projectId: string;
@@ -7,3 +12,4 @@ export declare class ModuleBE_WhoAmI_GCP_Class extends Module {
7
12
  }>;
8
13
  }
9
14
  export declare const ModuleBE_WhoAmI_GCP: ModuleBE_WhoAmI_GCP_Class;
15
+ export {};
@@ -1,12 +1,25 @@
1
- import { Module } from '@nu-art/ts-common';
1
+ import { Module, tsValidateMandatoryBoolean } from '@nu-art/ts-common';
2
2
  import { GoogleAuth } from 'google-auth-library';
3
+ const defaultConfig = { printEnvVars: false, printIdentity: true };
4
+ const configValidator = {
5
+ printEnvVars: tsValidateMandatoryBoolean,
6
+ printIdentity: tsValidateMandatoryBoolean
7
+ };
3
8
  export class ModuleBE_WhoAmI_GCP_Class extends Module {
9
+ constructor() {
10
+ super();
11
+ this.setDefaultConfig(defaultConfig);
12
+ this.setConfigValidator(configValidator);
13
+ }
4
14
  init() {
5
15
  this.printCallerIdentity().then(({ projectId, info }) => {
6
- this.logInfo('env: ', process.env);
7
- this.logInfo('GOOGLE_APPLICATION_CREDENTIALS: ', process.env.GOOGLE_APPLICATION_CREDENTIALS ?? 'not set');
8
- this.logInfo(`🔐 GCP Caller Identity: ${info.email || info.sub}`);
9
- this.logInfo(`🏗️ GCP Project ID: ${projectId}`);
16
+ if (this.config.printEnvVars)
17
+ this.logInfo('env: ', process.env);
18
+ if (this.config.printIdentity) {
19
+ this.logInfo('GOOGLE_APPLICATION_CREDENTIALS: ', process.env.GOOGLE_APPLICATION_CREDENTIALS ?? 'not set');
20
+ this.logInfo(`🔐 GCP Caller Identity: ${info.email || info.sub}`);
21
+ this.logInfo(`🏗️ GCP Project ID: ${projectId}`);
22
+ }
10
23
  }).catch(err => {
11
24
  this.logError('error: ', err);
12
25
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/google-services-backend",
3
- "version": "0.401.9",
3
+ "version": "0.500.6",
4
4
  "description": "google-services Backend",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -33,7 +33,7 @@
33
33
  "build": "tsc"
34
34
  },
35
35
  "dependencies": {
36
- "@nu-art/ts-common": "0.401.9",
36
+ "@nu-art/ts-common": "0.500.6",
37
37
  "@google-cloud/pubsub": "^4.0.0",
38
38
  "@google-cloud/secret-manager": "^6.1.0",
39
39
  "google-auth-library": "^10.0.0",