@requiply/nuxt 0.1.0 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ - `useRequiplyServer()` runs on every server runtime: Nuxt picks a `nuxt/server` version on Nitro v3 (Nuxt 5, or Nuxt 4.7+ with `nitro` installed) and other server builders, and the Nitro 2 version on `nitropack`, as the Nuxt module server compatibility guide describes. Its `event` parameter now also accepts a `nuxt/server` request event.
6
+ - Runtime config types augment `nuxt/schema`, so `requiply` keys are typed in server code on either Nitro.
7
+ - `@nuxt/kit` ^4.7.1. Tests run on Nitro 2 and Nitro v3.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  First release.
package/README.md CHANGED
@@ -381,6 +381,8 @@ export default defineEventHandler(async (event) => {
381
381
  })
382
382
  ```
383
383
 
384
+ It works on every Nuxt server runtime: Nitro 2 (Nuxt 3 and 4), and Nitro v3 (Nuxt 5, or Nuxt 4.7+ with `nitro` installed) through `nuxt/server`.
385
+
384
386
  Errors are `RequiplyError` (auto-imported in `server/`) with `status`, `reason` and `data`. Types come from `#requiply`:
385
387
 
386
388
  ```ts
package/dist/module.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
1
+ import * as nuxt_schema from 'nuxt/schema';
2
2
  import { RequiplyPublicRuntimeConfig, RequiplyPrivateRuntimeConfig, ModuleOptions } from '../dist/runtime/types.js';
3
3
  export * from '../dist/runtime/types.js';
4
4
 
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
5
+ declare const _default: nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
 
7
- declare module '@nuxt/schema' {
7
+ declare module 'nuxt/schema' {
8
8
  interface PublicRuntimeConfig {
9
9
  requiply: RequiplyPublicRuntimeConfig;
10
10
  }
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.13.0"
6
6
  },
7
- "version": "0.1.0",
7
+ "version": "0.1.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.4",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -68,7 +68,13 @@ const module$1 = defineNuxtModule({
68
68
  { name: "useRequiplyProduct", from: resolver.resolve("./runtime/app/composables/useRequiplyProduct") }
69
69
  ]);
70
70
  addServerImports([
71
- { name: "useRequiplyServer", from: resolver.resolve("./runtime/server/utils/requiply") },
71
+ {
72
+ name: "useRequiplyServer",
73
+ from: {
74
+ nuxt: resolver.resolve("./runtime/server/utils/requiply"),
75
+ nitro2: resolver.resolve("./runtime/server/utils/requiply.legacy")
76
+ }
77
+ },
72
78
  { name: "RequiplyError", from: "@requiply/api-sdk" }
73
79
  ]);
74
80
  if (options.components !== false) {
@@ -0,0 +1,22 @@
1
+ import { RequiplyClient } from '@requiply/api-sdk';
2
+ /**
3
+ * The slice of runtime config the server client reads, the same under every server runtime.
4
+ * The index signature lets each runtime's own config type (Nitro 2, Nitro 3, `nuxt/server`)
5
+ * be passed as it is.
6
+ */
7
+ export interface RequiplyServerConfig {
8
+ [key: string]: unknown;
9
+ requiply?: {
10
+ secretKey?: string;
11
+ };
12
+ public?: {
13
+ requiply?: {
14
+ apiUrl?: string;
15
+ };
16
+ };
17
+ }
18
+ /**
19
+ * The secret-key client for a runtime config, reused per API address and key. Shared by the
20
+ * `nuxt/server` and Nitro 2 variants of `useRequiplyServer()`, so it imports no server API.
21
+ */
22
+ export declare function requiplyServerClient(config: RequiplyServerConfig): RequiplyClient;
@@ -0,0 +1,20 @@
1
+ import { RequiplyClient } from "@requiply/api-sdk";
2
+ const clients = /* @__PURE__ */ new Map();
3
+ export function requiplyServerClient(config) {
4
+ const secretKey = config.requiply?.secretKey;
5
+ if (!secretKey) {
6
+ throw new Error("[requiply] useRequiplyServer() needs a secret key: set NUXT_REQUIPLY_SECRET_KEY (or `requiply.secretKey` in nuxt.config). Create one in Requiply under Settings > API keys.");
7
+ }
8
+ if (!secretKey.startsWith("rq_sk_")) {
9
+ throw new Error("[requiply] NUXT_REQUIPLY_SECRET_KEY does not hold a secret key (rq_sk_...).");
10
+ }
11
+ const baseUrl = config.public?.requiply?.apiUrl;
12
+ const cacheKey = `${baseUrl}
13
+ ${secretKey}`;
14
+ let client = clients.get(cacheKey);
15
+ if (!client) {
16
+ client = new RequiplyClient({ apiKey: secretKey, baseUrl });
17
+ clients.set(cacheKey, client);
18
+ }
19
+ return client;
20
+ }
@@ -1,16 +1,20 @@
1
- import { RequiplyClient } from '@requiply/api-sdk';
2
- import type { H3Event } from 'h3';
1
+ import type { RequiplyClient } from '@requiply/api-sdk';
2
+ import { type RequestEvent } from 'nuxt/server';
3
3
  /**
4
- * The Requiply API client with the secret key, for server routes, server middleware and
5
- * Nitro tasks. A secret key reaches everything the organization's API allows: bookings,
6
- * clients, sales, reports and inventory edits. Never return its raw results to the browser
7
- * without picking the fields the page needs.
4
+ * The Requiply API client with the secret key, for server routes and server middleware. A
5
+ * secret key reaches everything the organization's API allows: bookings, clients, sales,
6
+ * reports and inventory edits. Never return its raw results to the browser without picking
7
+ * the fields the page needs.
8
8
  *
9
- * @param event The request, so runtime config overrides per environment apply. Optional in tasks.
9
+ * This variant runs on any server runtime through `nuxt/server` (Nuxt 4.6+, Nuxt 5, Nitro v3
10
+ * and other builders); Nitro 2 hosts get `requiply.legacy.ts`.
11
+ *
12
+ * @param _event The request. Accepted for symmetry with the Nitro 2 variant; runtime config is
13
+ * read for the current request either way.
10
14
  * @example
11
15
  * export default defineEventHandler(async (event) => {
12
16
  * const requiply = useRequiplyServer(event)
13
17
  * return requiply.reports.revenue({ groupBy: 'month' })
14
18
  * })
15
19
  */
16
- export declare function useRequiplyServer(event?: H3Event): RequiplyClient;
20
+ export declare function useRequiplyServer(_event?: Pick<RequestEvent, 'context'>): RequiplyClient;
@@ -1,22 +1,5 @@
1
- import { RequiplyClient } from "@requiply/api-sdk";
2
- import { useRuntimeConfig } from "nitropack/runtime";
3
- const clients = /* @__PURE__ */ new Map();
4
- export function useRequiplyServer(event) {
5
- const { requiply: privateConfig, public: { requiply: publicConfig } } = useRuntimeConfig(event);
6
- const secretKey = privateConfig?.secretKey;
7
- if (!secretKey) {
8
- throw new Error("[requiply] useRequiplyServer() needs a secret key: set NUXT_REQUIPLY_SECRET_KEY (or `requiply.secretKey` in nuxt.config). Create one in Requiply under Settings > API keys.");
9
- }
10
- if (!secretKey.startsWith("rq_sk_")) {
11
- throw new Error("[requiply] NUXT_REQUIPLY_SECRET_KEY does not hold a secret key (rq_sk_...).");
12
- }
13
- const baseUrl = publicConfig?.apiUrl;
14
- const cacheKey = `${baseUrl}
15
- ${secretKey}`;
16
- let client = clients.get(cacheKey);
17
- if (!client) {
18
- client = new RequiplyClient({ apiKey: secretKey, baseUrl });
19
- clients.set(cacheKey, client);
20
- }
21
- return client;
1
+ import { useRuntimeConfig } from "nuxt/server";
2
+ import { requiplyServerClient } from "../client.js";
3
+ export function useRequiplyServer(_event) {
4
+ return requiplyServerClient(useRuntimeConfig());
22
5
  }
@@ -0,0 +1,10 @@
1
+ import type { RequiplyClient } from '@requiply/api-sdk';
2
+ import type { H3Event } from 'h3';
3
+ /**
4
+ * The Requiply API client with the secret key, for server routes, server middleware and
5
+ * Nitro tasks, on hosts running Nitro 2 (`nitropack`). Other hosts get `requiply.ts`, which
6
+ * builds on `nuxt/server`.
7
+ *
8
+ * @param event The request, so runtime config overrides per environment apply. Optional in tasks.
9
+ */
10
+ export declare function useRequiplyServer(event?: H3Event): RequiplyClient;
@@ -0,0 +1,5 @@
1
+ import { useRuntimeConfig } from "nitropack/runtime";
2
+ import { requiplyServerClient } from "../client.js";
3
+ export function useRequiplyServer(event) {
4
+ return requiplyServerClient(useRuntimeConfig(event));
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requiply/nuxt",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Requiply for Nuxt: rental booking components, a cart that checks out in the Requiply booking portal, and the Requiply API on the client and the server",
5
5
  "author": "Andrian Zafiiovskiy <andrian.zafiiovskiy@gmail.com>",
6
6
  "license": "MIT",
@@ -60,18 +60,19 @@
60
60
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
61
61
  },
62
62
  "dependencies": {
63
- "@nuxt/kit": "^4.7.0",
63
+ "@nuxt/kit": "^4.7.1",
64
64
  "@requiply/api-sdk": "^0.4.0",
65
65
  "defu": "^6.1.4"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@nuxt/eslint-config": "^1.17.0",
69
69
  "@nuxt/module-builder": "^1.0.4",
70
- "@nuxt/schema": "^4.7.0",
70
+ "@nuxt/schema": "^4.7.1",
71
71
  "@nuxt/test-utils": "^4.4.0",
72
72
  "@types/node": "^24.0.0",
73
73
  "eslint": "^10.12.0",
74
- "nuxt": "^4.7.0",
74
+ "nitro": "^3.0.261103-rc",
75
+ "nuxt": "^4.7.1",
75
76
  "typescript": "^5.9.3",
76
77
  "vite": "^8.4.0",
77
78
  "vitest": "^5.1.2",