@b10cks/nuxt 0.9.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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/module.d.mts +13 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +31 -0
- package/dist/runtime/composables/useB10cksApi.d.ts +86 -0
- package/dist/runtime/composables/useB10cksApi.js +201 -0
- package/dist/runtime/plugin.d.ts +7 -0
- package/dist/runtime/plugin.js +23 -0
- package/dist/types.d.mts +3 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present – Coder's Cantina e.U.
|
|
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
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
|
|
3
|
+
interface ModuleOptions {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
componentsDir: string;
|
|
6
|
+
ilumUrl: string;
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
11
|
+
|
|
12
|
+
export { _default as default };
|
|
13
|
+
export type { ModuleOptions };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponentsDir, addPlugin, addImports } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "@b10cks/nuxt",
|
|
6
|
+
configKey: "b10cks"
|
|
7
|
+
},
|
|
8
|
+
defaults: {
|
|
9
|
+
accessToken: "",
|
|
10
|
+
apiUrl: "https://api.b10cks.com/api",
|
|
11
|
+
componentsDir: "~/b10cks"
|
|
12
|
+
},
|
|
13
|
+
setup(options, nuxt) {
|
|
14
|
+
const resolver = createResolver(import.meta.url);
|
|
15
|
+
if (options.componentsDir) {
|
|
16
|
+
addComponentsDir({ path: options.componentsDir, global: true, pathPrefix: false });
|
|
17
|
+
}
|
|
18
|
+
nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
|
|
19
|
+
nuxt.options.build.transpile.push(resolver.resolve("@b10cks/nuxt"));
|
|
20
|
+
nuxt.options.build.transpile.push(resolver.resolve("@b10cks/vue"));
|
|
21
|
+
nuxt.options.runtimeConfig.public.b10cks = {
|
|
22
|
+
accessToken: options.accessToken,
|
|
23
|
+
apiUrl: options.apiUrl
|
|
24
|
+
};
|
|
25
|
+
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
26
|
+
addImports({ name: "useB10cksApi", as: "useB10cksApi", from: resolver.resolve("./runtime/composables/useB10cksApi") });
|
|
27
|
+
nuxt.options.typescript.hoist.push("@b10cks/vue");
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export { module as default };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { IBBaseQueryParams, IBBlock, IBContent, IBContentQueryParams, IBDataEntry, IBDataSource, IBSpace, IBResponse } from '@b10cks/client';
|
|
2
|
+
import type { Endpoint } from '@b10cks/client';
|
|
3
|
+
export interface UseB10cksApiOptions<T> {
|
|
4
|
+
immediate?: boolean;
|
|
5
|
+
params?: Omit<IBBaseQueryParams, 'token'>;
|
|
6
|
+
transform?: (data: IBResponse<T>) => T;
|
|
7
|
+
}
|
|
8
|
+
interface UseB10cksApiReturn {
|
|
9
|
+
useContent: <T = never>(full_slug: string, params?: Omit<IBContentQueryParams, 'token' | 'full_slug'>, options?: Omit<UseB10cksApiOptions<IBContent<T>>, 'params'>) => {
|
|
10
|
+
data: import('vue').Ref<IBContent<T> | null>;
|
|
11
|
+
pending: import('vue').Ref<boolean>;
|
|
12
|
+
error: import('vue').Ref<Error | null>;
|
|
13
|
+
execute: () => Promise<any>;
|
|
14
|
+
refresh: () => Promise<any>;
|
|
15
|
+
};
|
|
16
|
+
useContents: <T = never>(params?: Omit<IBContentQueryParams, 'token'>, options?: Omit<UseB10cksApiOptions<IBContent<T>[]>, 'params'>) => {
|
|
17
|
+
data: import('vue').Ref<IBContent<T>[]>;
|
|
18
|
+
pending: import('vue').Ref<boolean>;
|
|
19
|
+
error: import('vue').Ref<Error | null>;
|
|
20
|
+
execute: () => Promise<any>;
|
|
21
|
+
refresh: () => Promise<any>;
|
|
22
|
+
};
|
|
23
|
+
useBlocks: (params?: Omit<IBBaseQueryParams, 'token'>, options?: Omit<UseB10cksApiOptions<IBBlock[]>, 'params'>) => {
|
|
24
|
+
data: import('vue').Ref<IBBlock[]>;
|
|
25
|
+
pending: import('vue').Ref<boolean>;
|
|
26
|
+
error: import('vue').Ref<Error | null>;
|
|
27
|
+
execute: () => Promise<any>;
|
|
28
|
+
refresh: () => Promise<any>;
|
|
29
|
+
};
|
|
30
|
+
useDataEntries: (source: string, params?: Omit<IBBaseQueryParams, 'token'>, options?: Omit<UseB10cksApiOptions<IBDataEntry[]>, 'params'>) => {
|
|
31
|
+
data: import('vue').Ref<IBDataEntry[]>;
|
|
32
|
+
pending: import('vue').Ref<boolean>;
|
|
33
|
+
error: import('vue').Ref<Error | null>;
|
|
34
|
+
execute: () => Promise<any>;
|
|
35
|
+
refresh: () => Promise<any>;
|
|
36
|
+
};
|
|
37
|
+
useDataSources: (options?: UseB10cksApiOptions<IBDataSource[]>) => {
|
|
38
|
+
data: import('vue').Ref<IBDataSource[]>;
|
|
39
|
+
pending: import('vue').Ref<boolean>;
|
|
40
|
+
error: import('vue').Ref<Error | null>;
|
|
41
|
+
execute: () => Promise<any>;
|
|
42
|
+
refresh: () => Promise<any>;
|
|
43
|
+
};
|
|
44
|
+
useSpace: (options?: UseB10cksApiOptions<IBSpace>) => {
|
|
45
|
+
data: import('vue').Ref<IBSpace>;
|
|
46
|
+
pending: import('vue').Ref<boolean>;
|
|
47
|
+
error: import('vue').Ref<Error | null>;
|
|
48
|
+
execute: () => Promise<any>;
|
|
49
|
+
refresh: () => Promise<any>;
|
|
50
|
+
};
|
|
51
|
+
useRedirects: (options?: UseB10cksApiOptions<Record<string, {
|
|
52
|
+
target: string;
|
|
53
|
+
status_code: number;
|
|
54
|
+
}>>) => {
|
|
55
|
+
data: import('vue').Ref<Record<string, {
|
|
56
|
+
target: string;
|
|
57
|
+
status_code: number;
|
|
58
|
+
}> | null>;
|
|
59
|
+
pending: import('vue').Ref<boolean>;
|
|
60
|
+
error: import('vue').Ref<Error | null>;
|
|
61
|
+
execute: () => Promise<any>;
|
|
62
|
+
refresh: () => Promise<any>;
|
|
63
|
+
};
|
|
64
|
+
useApiResource: <T = never>(endpoint: Endpoint, options?: UseB10cksApiOptions<T>) => {
|
|
65
|
+
data: import('vue').Ref<any>;
|
|
66
|
+
pending: import('vue').Ref<boolean>;
|
|
67
|
+
error: import('vue').Ref<Error | null>;
|
|
68
|
+
execute: () => Promise<any>;
|
|
69
|
+
refresh: () => Promise<any>;
|
|
70
|
+
};
|
|
71
|
+
useApiCollection: <T = never>(endpoint: Endpoint, options?: UseB10cksApiOptions<T[]>) => {
|
|
72
|
+
data: import('vue').Ref<any>;
|
|
73
|
+
pending: import('vue').Ref<boolean>;
|
|
74
|
+
error: import('vue').Ref<Error | null>;
|
|
75
|
+
execute: () => Promise<any>;
|
|
76
|
+
refresh: () => Promise<any>;
|
|
77
|
+
};
|
|
78
|
+
useB10cksConfig: <T>(params?: {
|
|
79
|
+
slug?: string;
|
|
80
|
+
} & IBContentQueryParams) => Promise<{
|
|
81
|
+
config: import('vue').ComputedRef<T>;
|
|
82
|
+
}>;
|
|
83
|
+
client: any;
|
|
84
|
+
}
|
|
85
|
+
export declare const useB10cksApi: () => UseB10cksApiReturn;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useNuxtApp, useState } from "#app";
|
|
3
|
+
export const useB10cksApi = () => {
|
|
4
|
+
const { $b10cksClient } = useNuxtApp();
|
|
5
|
+
function useApiResource(endpoint, options = {}) {
|
|
6
|
+
const { immediate = true, params = {}, transform } = options;
|
|
7
|
+
const pending = ref(false);
|
|
8
|
+
const data = ref(null);
|
|
9
|
+
const error = ref(null);
|
|
10
|
+
const execute = async () => {
|
|
11
|
+
pending.value = true;
|
|
12
|
+
error.value = null;
|
|
13
|
+
try {
|
|
14
|
+
const result = await $b10cksClient.get(endpoint, params);
|
|
15
|
+
data.value = transform ? transform(result) : result;
|
|
16
|
+
return data.value;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
19
|
+
throw error.value;
|
|
20
|
+
} finally {
|
|
21
|
+
pending.value = false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
if (immediate) {
|
|
25
|
+
execute().catch((err) => console.error(`Error fetching ${endpoint}:`, err));
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
data,
|
|
29
|
+
pending,
|
|
30
|
+
error,
|
|
31
|
+
execute,
|
|
32
|
+
refresh: execute
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useApiCollection(endpoint, options = {}) {
|
|
36
|
+
const { immediate = false, params = {}, transform } = options;
|
|
37
|
+
const pending = ref(false);
|
|
38
|
+
const data = ref(null);
|
|
39
|
+
const error = ref(null);
|
|
40
|
+
const execute = async () => {
|
|
41
|
+
pending.value = true;
|
|
42
|
+
error.value = null;
|
|
43
|
+
try {
|
|
44
|
+
const results = await $b10cksClient.getAll(endpoint, params);
|
|
45
|
+
data.value = transform ? transform(results) : results;
|
|
46
|
+
return data.value;
|
|
47
|
+
} catch (err) {
|
|
48
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
49
|
+
throw error.value;
|
|
50
|
+
} finally {
|
|
51
|
+
pending.value = false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (immediate) {
|
|
55
|
+
execute().catch((err) => console.error(`Error fetching ${endpoint}:`, err));
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
data,
|
|
59
|
+
pending,
|
|
60
|
+
error,
|
|
61
|
+
execute,
|
|
62
|
+
refresh: execute
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const useContent = (full_slug, params = {}, options = {}) => {
|
|
66
|
+
return useApiResource(
|
|
67
|
+
`contents/${full_slug}`,
|
|
68
|
+
{
|
|
69
|
+
...options,
|
|
70
|
+
params,
|
|
71
|
+
transform: (result) => {
|
|
72
|
+
if ("data" in result) {
|
|
73
|
+
return result.data;
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
const useContents = (params = {}, options = {}) => {
|
|
81
|
+
return useApiCollection(
|
|
82
|
+
"contents",
|
|
83
|
+
{
|
|
84
|
+
...options,
|
|
85
|
+
params
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
const useBlocks = (params = {}, options = {}) => {
|
|
90
|
+
return useApiCollection(
|
|
91
|
+
"blocks",
|
|
92
|
+
{
|
|
93
|
+
...options,
|
|
94
|
+
params
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
const useDataEntries = (source, params = {}, options = {}) => {
|
|
99
|
+
return useApiCollection(
|
|
100
|
+
`datasources/${source}/entries`,
|
|
101
|
+
{
|
|
102
|
+
...options,
|
|
103
|
+
params
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
const useDataSources = (options = {}) => {
|
|
108
|
+
return useApiCollection(
|
|
109
|
+
"datasources",
|
|
110
|
+
options
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
const useSpace = (options = {}) => {
|
|
114
|
+
return useApiResource(
|
|
115
|
+
"spaces/me",
|
|
116
|
+
{
|
|
117
|
+
...options,
|
|
118
|
+
transform: (result) => {
|
|
119
|
+
if ("data" in result) {
|
|
120
|
+
return result.data;
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
const cache = useState("redirects");
|
|
128
|
+
const useRedirects = (options = {}) => {
|
|
129
|
+
const { immediate = true, params = {}, transform } = options;
|
|
130
|
+
const pending = ref(false);
|
|
131
|
+
const data = ref(cache.value || null);
|
|
132
|
+
const error = ref(null);
|
|
133
|
+
const execute = async () => {
|
|
134
|
+
if (cache.value) {
|
|
135
|
+
return cache.value;
|
|
136
|
+
}
|
|
137
|
+
pending.value = true;
|
|
138
|
+
error.value = null;
|
|
139
|
+
try {
|
|
140
|
+
const results = await $b10cksClient.getAll("redirects", params);
|
|
141
|
+
const transformed = Object.fromEntries(
|
|
142
|
+
results.map(({ source, target, status_code }) => [
|
|
143
|
+
source,
|
|
144
|
+
{ target, status_code }
|
|
145
|
+
])
|
|
146
|
+
);
|
|
147
|
+
data.value = transformed;
|
|
148
|
+
cache.value = transformed;
|
|
149
|
+
return transformed;
|
|
150
|
+
} catch (err) {
|
|
151
|
+
error.value = err instanceof Error ? err : new Error(String(err));
|
|
152
|
+
throw error.value;
|
|
153
|
+
} finally {
|
|
154
|
+
pending.value = false;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
if (immediate && !cache.value) {
|
|
158
|
+
execute().catch((err) => console.error("Error fetching redirects:", err));
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
data,
|
|
162
|
+
pending,
|
|
163
|
+
error,
|
|
164
|
+
execute,
|
|
165
|
+
refresh: execute
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const configCache = useState("config");
|
|
169
|
+
const useB10cksConfig = async ({ slug = "_config", version, language, ...params } = {}) => {
|
|
170
|
+
const options = {
|
|
171
|
+
params: {
|
|
172
|
+
...params,
|
|
173
|
+
version,
|
|
174
|
+
vid: null,
|
|
175
|
+
language,
|
|
176
|
+
token: $b10cksClient.token
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const { data: config, execute } = useContent(slug, options.params, { immediate: false });
|
|
180
|
+
if (!configCache.value) {
|
|
181
|
+
await execute();
|
|
182
|
+
configCache.value = config.value?.content || {};
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
config: computed(() => configCache.value)
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
useContent,
|
|
190
|
+
useContents,
|
|
191
|
+
useBlocks,
|
|
192
|
+
useDataEntries,
|
|
193
|
+
useDataSources,
|
|
194
|
+
useSpace,
|
|
195
|
+
useRedirects,
|
|
196
|
+
useApiResource,
|
|
197
|
+
useApiCollection,
|
|
198
|
+
useB10cksConfig,
|
|
199
|
+
client: $b10cksClient
|
|
200
|
+
};
|
|
201
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ApiClient } from "@b10cks/client";
|
|
2
|
+
import { previewBridge, B10cksVue } from "@b10cks/vue";
|
|
3
|
+
import { defineNuxtPlugin, useRequestURL, useRuntimeConfig } from "nuxt/app";
|
|
4
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
5
|
+
const config = useRuntimeConfig();
|
|
6
|
+
const url = useRequestURL();
|
|
7
|
+
nuxtApp.vueApp.use(B10cksVue);
|
|
8
|
+
if (previewBridge.isInPreviewMode()) {
|
|
9
|
+
if (import.meta.client) {
|
|
10
|
+
previewBridge.init();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const b10cksClient = new ApiClient({
|
|
14
|
+
baseUrl: config.public.b10cks.apiUrl || "https://api.b10cks.com/api",
|
|
15
|
+
token: config.public.b10cks.accessToken,
|
|
16
|
+
fetchClient: $fetch
|
|
17
|
+
}, url);
|
|
18
|
+
return {
|
|
19
|
+
provide: {
|
|
20
|
+
b10cksClient
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
});
|
package/dist/types.d.mts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@b10cks/nuxt",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "0.9.6",
|
|
5
|
+
"author": "Michael Wallner @ Coder's Cantina",
|
|
6
|
+
"description": "b10cks Nuxt module",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/b10cks/sdk.git",
|
|
11
|
+
"directory": "packages/nuxt"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/types.d.mts",
|
|
16
|
+
"import": "./dist/module.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.mjs",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@nuxt/eslint": "^1.9.0",
|
|
25
|
+
"@nuxt/eslint-config": "^1.9.0",
|
|
26
|
+
"@nuxt/kit": "^4.0.3",
|
|
27
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
28
|
+
"@nuxt/schema": "^4.0.3",
|
|
29
|
+
"nuxt": "^4.0.3"
|
|
30
|
+
},
|
|
31
|
+
"release": {
|
|
32
|
+
"branches": [
|
|
33
|
+
"main"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@b10cks/client": "^0.9.6",
|
|
41
|
+
"@b10cks/vue": "^0.9.6"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "nuxt-module-build prepare && nuxt-module-build build",
|
|
45
|
+
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts --fix",
|
|
46
|
+
"lint:fix": "eslint . --fix",
|
|
47
|
+
"test": "vitest",
|
|
48
|
+
"clean": "rm -rf dist"
|
|
49
|
+
}
|
|
50
|
+
}
|