@genoacms/adapter-gcp 0.7.8 → 0.8.2-1

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.
@@ -1,13 +1,11 @@
1
- import config from '../../config.js';
1
+ import { getProvider } from '@genoacms/cloudabstraction';
2
2
  import { ProjectsClient } from '@google-cloud/resource-manager';
3
- const PROVIDER_NAME = '@genoacms/adapter-gcp/authorization';
4
- const authorizationConfig = config.authorization.providers.find((provider) => provider.name === PROVIDER_NAME);
5
- if (!authorizationConfig)
6
- throw new Error('authorization-provider-not-found');
7
- const projectId = authorizationConfig.projectId;
3
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/authorization';
4
+ const provider = getProvider('authorization', ADAPTER_PATH);
5
+ const projectId = provider.projectId;
8
6
  const resourceManager = new ProjectsClient({
9
7
  projectId,
10
- credentials: authorizationConfig.credentials
8
+ credentials: provider.credentials
11
9
  });
12
10
  const isEmailAdmins = async (email) => {
13
11
  const resource = `projects/${projectId}`;
@@ -1,13 +1,11 @@
1
- import config from '../../config.js';
2
1
  import { Firestore } from '@google-cloud/firestore';
3
- const PROVIDER_NAME = '@genoacms/adapter-gcp/database';
4
- const firestoreConfig = config.database.providers.find((provider) => provider.name === PROVIDER_NAME);
5
- if (!firestoreConfig)
6
- throw new Error('firestore-provider-not-found');
2
+ import { getProvider } from '@genoacms/cloudabstraction';
3
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/database';
4
+ const provider = getProvider('database', ADAPTER_PATH);
7
5
  const firestore = new Firestore({
8
- credentials: firestoreConfig.credentials,
9
- databaseId: firestoreConfig.databaseId,
10
- projectId: firestoreConfig.projectId
6
+ credentials: provider.credentials,
7
+ databaseId: provider.databaseId,
8
+ projectId: provider.projectId
11
9
  });
12
10
  const createDocument = async (reference, data) => {
13
11
  const document = await firestore.collection(reference.name).add(data);
@@ -1,15 +1,16 @@
1
- import config from '../../config.js';
2
1
  import { createReadStream, createWriteStream } from 'node:fs';
3
2
  import { resolve, dirname, basename } from 'node:path';
4
3
  import { fileURLToPath } from 'node:url';
5
4
  import { v2 } from '@google-cloud/functions';
6
5
  import archiver from 'archiver';
6
+ import { getProvider } from '@genoacms/cloudabstraction';
7
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/deployment';
7
8
  const { FunctionServiceClient } = v2;
9
+ const provider = getProvider('deployment', ADAPTER_PATH);
8
10
  const functionsClient = new FunctionServiceClient({
9
- credentials: config.deployment.credentials
11
+ credentials: provider.credentials
10
12
  });
11
- const projectId = config.deployment.projectId;
12
- const region = config.deployment.region;
13
+ const { projectId, region, functionName } = provider;
13
14
  const currentDir = dirname(fileURLToPath(import.meta.url));
14
15
  async function createZip(source, injectPaths, ignorePaths, out) {
15
16
  await new Promise((resolve, reject) => {
@@ -109,6 +110,6 @@ async function deploy() {
109
110
  ];
110
111
  await createZip(buildDirectoryPath, injectArchivePaths, ignoreArchivePaths, buildArchivePath);
111
112
  const functionStorageSource = await uploadSource(buildArchivePath);
112
- await deployFunction('genoacms', functionStorageSource);
113
+ await deployFunction(functionName ?? 'genoacms', functionStorageSource);
113
114
  }
114
115
  export default deploy;
@@ -1,4 +1,4 @@
1
1
  import type { Adapter } from '@genoacms/cloudabstraction/deployment';
2
- declare const svelteKitAdapter: Adapter.svelteKitAdapter;
3
- declare const deployProcedure: Adapter.deployProcedure;
2
+ declare const svelteKitAdapter: Adapter['svelteKitAdapter'];
3
+ declare const deployProcedure: Adapter['deployProcedure'];
4
4
  export { svelteKitAdapter, deployProcedure };
@@ -55,7 +55,13 @@ const listDirectory = async ({ bucket, name }, listingParams = {}) => {
55
55
  lastModified: new Date(file.metadata.updated)
56
56
  };
57
57
  }),
58
- directories: (apiResponse?.prefixes ?? []).filter((item) => item !== name).map(i => i.replace(name, ''))
58
+ directories: (apiResponse?.prefixes ?? []).filter((item) => item !== name).map(i => {
59
+ const object = {
60
+ bucket,
61
+ name: i
62
+ };
63
+ return object;
64
+ })
59
65
  };
60
66
  };
61
67
  const createDirectory = async ({ bucket, name }) => {
@@ -1,14 +1,14 @@
1
- import config from '../../config.js';
2
1
  import { Storage } from '@google-cloud/storage';
3
- const PROVIDER_NAME = '@genoacms/adapter-gcp/storage';
4
- const storageConfig = config.storage.providers.find((provider) => provider.name === PROVIDER_NAME);
5
- if (!storageConfig)
6
- throw new Error('storage-provider-not-found');
2
+ import { getProvider } from '@genoacms/cloudabstraction';
3
+ import config from '../../config.js';
4
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/storage';
5
+ const provider = getProvider('storage', ADAPTER_PATH);
7
6
  const storage = new Storage({
8
- credentials: storageConfig.credentials
7
+ credentials: provider.credentials
9
8
  });
10
9
  const hasBucket = (name) => {
11
- const has = config.storage.buckets.find((bucket) => bucket.name === name && bucket.providerName === PROVIDER_NAME);
10
+ const has = config.storage.buckets.find((bucket) => bucket.name === name &&
11
+ bucket.providerName === provider.name);
12
12
  return !!has;
13
13
  };
14
14
  const getBucket = (name) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genoacms/adapter-gcp",
3
- "version": "0.7.8",
3
+ "version": "0.8.2-1",
4
4
  "type": "module",
5
5
  "description": "Implementation of abstraction layer of GenoaCMS for GCP",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "provenance": true
21
21
  },
22
22
  "dependencies": {
23
- "@genoacms/cloudabstraction": "^0.7.8",
23
+ "@genoacms/cloudabstraction": "^0.8.2",
24
24
  "@google-cloud/firestore": "^7.1.0",
25
25
  "@google-cloud/functions": "^3.4.0",
26
26
  "@google-cloud/resource-manager": "^5.1.0",
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type Config from './genoa.config.js'
1
+ import type { Config } from './genoa.config.js'
2
2
  import { config } from '@genoacms/cloudabstraction'
3
3
 
4
4
  export default config satisfies Config
@@ -1,4 +1,8 @@
1
- import type Config from '@genoacms/cloudabstraction/src/genoa.config.js'
1
+ import type { Config as ConfigG } from '@genoacms/cloudabstraction/src/genoa.config.js'
2
+ import type { AuthorizationProvider as AuthorizationProviderG } from '@genoacms/cloudabstraction/authorization'
3
+ import type { DatabaseProvider as DatabaseProviderG } from '@genoacms/cloudabstraction/database'
4
+ import type { DeploymentProvider as DeploymentProviderG } from '@genoacms/cloudabstraction/deployment'
5
+ import type { StorageProvider as StorageProviderG } from '@genoacms/cloudabstraction/storage'
2
6
 
3
7
  interface Credentials {
4
8
  type: string
@@ -14,17 +18,34 @@ interface Credentials {
14
18
  'universe_domain': string
15
19
  }
16
20
 
17
- interface DatabaseConfig {
21
+ interface AuthorizationProvider extends AuthorizationProviderG {
22
+ projectId: string
23
+ credentials: Credentials
24
+ }
25
+
26
+ interface DatabaseProvider extends DatabaseProviderG {
27
+ projectId: string
18
28
  credentials: Credentials
19
29
  databaseId: string
20
30
  region: string
21
31
  }
32
+ interface DeploymentProvider extends DeploymentProviderG {
33
+ projectId: string
34
+ credentials: Credentials
35
+ region: string
36
+ functionName: string
37
+ }
22
38
 
23
- interface StorageConfig {
39
+ interface StorageProvider extends StorageProviderG {
24
40
  credentials: Credentials
25
- buckets: string[]
26
41
  }
27
42
 
28
- interface ConfigGCP extends Config<object, object, DatabaseConfig, StorageConfig> {}
43
+ interface Config extends ConfigG<object, AuthorizationProvider, DatabaseProvider, StorageProvider> {}
29
44
 
30
- export default ConfigGCP
45
+ export type {
46
+ Config,
47
+ AuthorizationProvider,
48
+ DatabaseProvider,
49
+ DeploymentProvider,
50
+ StorageProvider
51
+ }
@@ -1,14 +1,14 @@
1
- import type { Adapter, AuthorizationProvider } from '@genoacms/cloudabstraction/authorization'
2
- import config from '../../config.js'
1
+ import type { Adapter } from '@genoacms/cloudabstraction/authorization'
2
+ import type { AuthorizationProvider } from '../../genoa.config.js'
3
+ import { getProvider } from '@genoacms/cloudabstraction'
3
4
  import { ProjectsClient } from '@google-cloud/resource-manager'
4
5
 
5
- const PROVIDER_NAME = '@genoacms/adapter-gcp/authorization'
6
- const authorizationConfig = config.authorization.providers.find((provider: AuthorizationProvider) => provider.name === PROVIDER_NAME)
7
- if (!authorizationConfig) throw new Error('authorization-provider-not-found')
8
- const projectId = authorizationConfig.projectId
6
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/authorization'
7
+ const provider = getProvider('authorization', ADAPTER_PATH) as AuthorizationProvider
8
+ const projectId = provider.projectId
9
9
  const resourceManager = new ProjectsClient({
10
10
  projectId,
11
- credentials: authorizationConfig.credentials
11
+ credentials: provider.credentials
12
12
  })
13
13
 
14
14
  const isEmailAdmins: Adapter.isEmailAdmins = async (email: string) => {
@@ -1,22 +1,23 @@
1
1
  import type {
2
2
  Adapter,
3
- DatabaseProvider,
4
3
  CollectionSnapshot,
5
4
  Document,
6
5
  DocumentReference,
7
6
  DocumentSnapshot,
8
7
  UpdateSnapshot
9
8
  } from '@genoacms/cloudabstraction/database'
10
- import config from '../../config.js'
9
+ import type {
10
+ DatabaseProvider
11
+ } from '../../genoa.config.js'
11
12
  import { Firestore } from '@google-cloud/firestore'
13
+ import { getProvider } from '@genoacms/cloudabstraction'
12
14
 
13
- const PROVIDER_NAME = '@genoacms/adapter-gcp/database'
14
- const firestoreConfig = config.database.providers.find((provider: DatabaseProvider) => provider.name === PROVIDER_NAME)
15
- if (!firestoreConfig) throw new Error('firestore-provider-not-found')
15
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/database'
16
+ const provider = getProvider('database', ADAPTER_PATH) as DatabaseProvider
16
17
  const firestore = new Firestore({
17
- credentials: firestoreConfig.credentials,
18
- databaseId: firestoreConfig.databaseId,
19
- projectId: firestoreConfig.projectId
18
+ credentials: provider.credentials,
19
+ databaseId: provider.databaseId,
20
+ projectId: provider.projectId
20
21
  })
21
22
 
22
23
  const createDocument: Adapter['createDocument'] = async (reference, data) => {
@@ -1,18 +1,20 @@
1
- import config from '../../config.js'
1
+ import type { google } from '@google-cloud/functions/build/protos/protos.js'
2
+ import { type DeploymentProvider } from '../../genoa.config.js'
2
3
  import { createReadStream, createWriteStream } from 'node:fs'
3
4
  import { resolve, dirname, basename } from 'node:path'
4
5
  import { fileURLToPath } from 'node:url'
5
6
  import { v2 } from '@google-cloud/functions'
6
7
  import archiver from 'archiver'
7
- import type { google } from '@google-cloud/functions/build/protos/protos.js'
8
+ import { getProvider } from '@genoacms/cloudabstraction'
8
9
  type IStorageSource = google.cloud.functions.v2.IStorageSource
9
10
 
11
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/deployment'
10
12
  const { FunctionServiceClient } = v2
13
+ const provider = getProvider('deployment', ADAPTER_PATH) as DeploymentProvider
11
14
  const functionsClient = new FunctionServiceClient({
12
- credentials: config.deployment.credentials
15
+ credentials: provider.credentials
13
16
  })
14
- const projectId = config.deployment.projectId
15
- const region = config.deployment.region
17
+ const { projectId, region, functionName } = provider
16
18
 
17
19
  const currentDir = dirname(fileURLToPath(import.meta.url))
18
20
 
@@ -117,7 +119,7 @@ async function deploy (): Promise<void> {
117
119
  ]
118
120
  await createZip(buildDirectoryPath, injectArchivePaths, ignoreArchivePaths, buildArchivePath)
119
121
  const functionStorageSource = await uploadSource(buildArchivePath)
120
- await deployFunction('genoacms', functionStorageSource)
122
+ await deployFunction(functionName ?? 'genoacms', functionStorageSource)
121
123
  }
122
124
 
123
125
  export default deploy
@@ -1,8 +1,8 @@
1
1
  import type { Adapter } from '@genoacms/cloudabstraction/deployment'
2
2
 
3
- const svelteKitAdapter: Adapter.svelteKitAdapter = '@genoacms/sveltekit-adapter-cloud-run-functions'
3
+ const svelteKitAdapter: Adapter['svelteKitAdapter'] = '@genoacms/sveltekit-adapter-cloud-run-functions'
4
4
 
5
- const deployProcedure: Adapter.deployProcedure = async () => {
5
+ const deployProcedure: Adapter['deployProcedure'] = async () => {
6
6
  const deploy = (await import('./deploy.js')).default
7
7
  await deploy()
8
8
  }
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  Adapter,
3
+ ObjectReference,
3
4
  StorageObject
4
5
  } from '@genoacms/cloudabstraction/storage'
5
6
  import { type File } from '@google-cloud/storage'
@@ -71,7 +72,13 @@ const listDirectory: Adapter['listDirectory'] = async ({ bucket, name }, listing
71
72
  lastModified: new Date(file.metadata.updated as string)
72
73
  } satisfies StorageObject
73
74
  }),
74
- directories: (apiResponse?.prefixes ?? []).filter((item) => item !== name).map(i => i.replace(name, ''))
75
+ directories: (apiResponse?.prefixes ?? []).filter((item) => item !== name).map(i => {
76
+ const object: ObjectReference = {
77
+ bucket,
78
+ name: i
79
+ }
80
+ return object
81
+ })
75
82
  }
76
83
  }
77
84
 
@@ -1,16 +1,18 @@
1
- import config from '../../config.js'
1
+ import type { BucketInit } from '@genoacms/cloudabstraction/storage'
2
+ import type { StorageProvider } from '../../genoa.config.js'
2
3
  import { type Bucket, Storage } from '@google-cloud/storage'
3
- import type { StorageProvider, BucketInit } from '@genoacms/cloudabstraction/storage'
4
+ import { getProvider } from '@genoacms/cloudabstraction'
5
+ import config from '../../config.js'
4
6
 
5
- const PROVIDER_NAME = '@genoacms/adapter-gcp/storage'
6
- const storageConfig = config.storage.providers.find((provider: StorageProvider) => provider.name === PROVIDER_NAME)
7
- if (!storageConfig) throw new Error('storage-provider-not-found')
7
+ const ADAPTER_PATH = '@genoacms/adapter-gcp/storage'
8
+ const provider = getProvider('storage', ADAPTER_PATH) as StorageProvider
8
9
  const storage = new Storage({
9
- credentials: storageConfig.credentials
10
+ credentials: provider.credentials
10
11
  })
11
12
 
12
13
  const hasBucket = (name: string): boolean => {
13
- const has = config.storage.buckets.find((bucket: BucketInit) => bucket.name === name && bucket.providerName === PROVIDER_NAME)
14
+ const has = config.storage.buckets.find((bucket: BucketInit) => bucket.name === name &&
15
+ bucket.providerName === provider.name)
14
16
  return !!has
15
17
  }
16
18