@attributech/nuxt-drupal-utils 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @attributech/nuxt-drupal-utils
2
+
3
+ Shared utilities for Nuxt projects with Drupal backend.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @attributech/nuxt-drupal-utils
9
+ ```
10
+
11
+ ## Features
12
+
13
+ This package provides utility functions for handling URLs in Nuxt projects with Drupal backends, particularly for projects using Lagoon hosting:
14
+
15
+ - `getApiUrl`: Determines the API endpoint URL
16
+ - `getAppUrl`: Determines the application URL
17
+ - `getServerUrl`: Determines the server URL
18
+ - `getLagoonDevelopmentDomain`: Builds a Lagoon domain for development environments
19
+
20
+ ## Usage
21
+
22
+ ### Direct Import
23
+
24
+ You can import the utilities directly:
25
+
26
+ ```js
27
+ import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'
28
+
29
+ const serverUrl = getServerUrl('https://default-backend.com')
30
+ const apiUrl = getApiUrl('https://default-backend.com')
31
+ const appUrl = getAppUrl('https://www.example.com')
32
+ ```
33
+
34
+ This is particularly useful in `nuxt.config.js`:
35
+
36
+ ```js
37
+ // Nuxt 2
38
+ import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'
39
+
40
+ export default {
41
+ publicRuntimeConfig: {
42
+ serverUrl: getServerUrl('https://default-backend.com'),
43
+ apiUrl: getApiUrl('https://default-backend.com'),
44
+ appUrl: getAppUrl('https://www.example.com')
45
+ }
46
+ }
47
+
48
+ // Nuxt 3
49
+ import { getApiUrl, getServerUrl, getAppUrl } from '@attributech/nuxt-drupal-utils'
50
+
51
+ export default defineNuxtConfig({
52
+ runtimeConfig: {
53
+ public: {
54
+ serverUrl: getServerUrl('https://default-backend.com'),
55
+ apiUrl: getApiUrl('https://default-backend.com'),
56
+ appUrl: getAppUrl('https://www.example.com')
57
+ }
58
+ }
59
+ })
60
+ ```
61
+
62
+ ### As a Nuxt Module
63
+
64
+ You can also use it as a Nuxt module to auto-inject the utilities:
65
+
66
+ ```js
67
+ // Nuxt 2 with Bridge
68
+ export default {
69
+ buildModules: [
70
+ '@attributech/nuxt-drupal-utils/module'
71
+ ]
72
+ }
73
+
74
+ // Nuxt 3
75
+ export default defineNuxtConfig({
76
+ modules: [
77
+ '@attributech/nuxt-drupal-utils/module'
78
+ ]
79
+ })
80
+ ```
81
+
82
+ Then in your components:
83
+
84
+ ```vue
85
+ <!-- Nuxt 2 -->
86
+ <script>
87
+ export default {
88
+ mounted() {
89
+ const apiUrl = this.$getApiUrl('https://default-backend.com')
90
+ console.log(apiUrl)
91
+ }
92
+ }
93
+ </script>
94
+
95
+ <!-- Nuxt 3 -->
96
+ <script setup>
97
+ const { $getApiUrl } = useNuxtApp()
98
+ const apiUrl = $getApiUrl('https://default-backend.com')
99
+ </script>
100
+ ```
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1 @@
1
+ export default function (defaultServerUrl: string): string;
@@ -0,0 +1,6 @@
1
+ import getServerUrl from './getServerUrl';
2
+ // Provides a function to determin the API endpoint to use
3
+ export default function (defaultServerUrl) {
4
+ const serverUrl = getServerUrl(defaultServerUrl);
5
+ return `${serverUrl}/api`;
6
+ }
@@ -0,0 +1 @@
1
+ export default function (defaultUrl: string): string;
@@ -0,0 +1,17 @@
1
+ import getLagoonDevelopmentDomain from './getLagoonDevelopmentDomain';
2
+ // Provides a function to determin the app url
3
+ export default function (defaultUrl) {
4
+ // Override app url in case APP_URL env variable is set
5
+ if (process.env.APP_URL !== undefined && process.env.APP_URL !== '') {
6
+ return process.env.APP_URL;
7
+ }
8
+ // Build app url in case we are on a lagoon development environment
9
+ if (process.env.LAGOON_ENVIRONMENT_TYPE !== undefined &&
10
+ process.env.LAGOON_ENVIRONMENT_TYPE === 'development') {
11
+ const lagoonDevelopmentDomain = getLagoonDevelopmentDomain();
12
+ if (lagoonDevelopmentDomain !== null) {
13
+ return `https://frontend.${lagoonDevelopmentDomain}`;
14
+ }
15
+ }
16
+ return defaultUrl;
17
+ }
@@ -0,0 +1 @@
1
+ export default function (): string | null;
@@ -0,0 +1,9 @@
1
+ // Provides a function to build a lagoon domain for development enivronments
2
+ export default function () {
3
+ if (process.env.LAGOON_ENVIRONMENT !== undefined &&
4
+ process.env.LAGOON_PROJECT !== undefined &&
5
+ process.env.LAGOON_KUBERNETES !== undefined) {
6
+ return `${process.env.LAGOON_ENVIRONMENT}.${process.env.LAGOON_PROJECT}.${process.env.LAGOON_KUBERNETES}`;
7
+ }
8
+ return null;
9
+ }
@@ -0,0 +1 @@
1
+ export default function (defaultUrl: string): string;
@@ -0,0 +1,17 @@
1
+ import getLagoonDevelopmentDomain from './getLagoonDevelopmentDomain';
2
+ // Provides a function to determine the API endpoint to use
3
+ export default function (defaultUrl) {
4
+ // Override API endpoint in case API_SERVER env variable is set
5
+ if (process.env.API_SERVER !== undefined && process.env.API_SERVER !== '') {
6
+ return process.env.API_SERVER;
7
+ }
8
+ // Set API endpoint to nginx service in case we are on lagoon and not in production
9
+ if (process.env.LAGOON_ENVIRONMENT_TYPE !== undefined &&
10
+ process.env.LAGOON_ENVIRONMENT_TYPE === 'development') {
11
+ const lagoonDevelopmentDomain = getLagoonDevelopmentDomain();
12
+ if (lagoonDevelopmentDomain !== null) {
13
+ return `https://nginx.${lagoonDevelopmentDomain}`;
14
+ }
15
+ }
16
+ return defaultUrl;
17
+ }
@@ -0,0 +1,5 @@
1
+ import getApiUrl from './getApiUrl';
2
+ import getAppUrl from './getAppUrl';
3
+ import getServerUrl from './getServerUrl';
4
+ import getLagoonDevelopmentDomain from './getLagoonDevelopmentDomain';
5
+ export { getApiUrl, getAppUrl, getServerUrl, getLagoonDevelopmentDomain };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import getApiUrl from './getApiUrl';
2
+ import getAppUrl from './getAppUrl';
3
+ import getServerUrl from './getServerUrl';
4
+ import getLagoonDevelopmentDomain from './getLagoonDevelopmentDomain';
5
+ export { getApiUrl, getAppUrl, getServerUrl, getLagoonDevelopmentDomain };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@nuxt/schema").NuxtModule<any, any, false>;
2
+ export default _default;
package/dist/module.js ADDED
@@ -0,0 +1,17 @@
1
+ import { defineNuxtModule, addPlugin, createResolver } from '@nuxt/kit';
2
+ export default defineNuxtModule({
3
+ meta: {
4
+ name: '@attributech/nuxt-drupal-utils',
5
+ configKey: 'drupalUtils',
6
+ compatibility: {
7
+ // Compatible with Nuxt 2.16+ (with Bridge) and Nuxt 3
8
+ nuxt: '^2.16.0 || ^3.0.0'
9
+ }
10
+ },
11
+ defaults: {},
12
+ setup(options, nuxt) {
13
+ const resolver = createResolver(import.meta.url);
14
+ // Add plugin to make utilities available
15
+ addPlugin(resolver.resolve('./runtime/plugin'));
16
+ }
17
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: (context: any, inject: (name: string, value: any) => void) => void;
2
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import getApiUrl from '../getApiUrl';
2
+ import getAppUrl from '../getAppUrl';
3
+ import getServerUrl from '../getServerUrl';
4
+ import getLagoonDevelopmentDomain from '../getLagoonDevelopmentDomain';
5
+ // Plugin works with both Nuxt 2 + Bridge and Nuxt 3
6
+ export default (context, inject) => {
7
+ // Inject utilities into the context
8
+ inject('getApiUrl', getApiUrl);
9
+ inject('getAppUrl', getAppUrl);
10
+ inject('getServerUrl', getServerUrl);
11
+ inject('getLagoonDevelopmentDomain', getLagoonDevelopmentDomain);
12
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@attributech/nuxt-drupal-utils",
3
+ "version": "0.1.0",
4
+ "description": "Shared utilities for Nuxt 3 projects with Drupal backend",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./module": {
14
+ "import": "./dist/module.js",
15
+ "types": "./dist/module.d.ts"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "prepublishOnly": "npm run build",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "test:ui": "vitest --ui"
28
+ },
29
+ "keywords": [
30
+ "nuxt",
31
+ "drupal",
32
+ "utils",
33
+ "lagoon"
34
+ ],
35
+ "license": "MIT",
36
+ "peerDependencies": {
37
+ "nuxt": "^2.16.0 || ^3.0.0"
38
+ },
39
+ "dependencies": {
40
+ "@nuxt/kit": "^3.14.0"
41
+ },
42
+ "devDependencies": {
43
+ "@nuxt/types": "^2.16.0",
44
+ "@types/node": "^20.11.0",
45
+ "@vitest/coverage-v8": "^3.0.7",
46
+ "@vitest/ui": "^3.0.7",
47
+ "c8": "^10.1.3",
48
+ "happy-dom": "^17.2.2",
49
+ "typescript": "^5.6.3",
50
+ "vitest": "^3.0.7"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }