@rankwrangler/http-client 0.1.2

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/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @rankwrangler/http-client
2
+
3
+ Typed tRPC client for the RankWrangler public API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @rankwrangler/http-client
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createRankWranglerClient } from '@rankwrangler/http-client';
15
+
16
+ const client = createRankWranglerClient({
17
+ baseUrl: 'https://rankwrangler.merchbase.co',
18
+ apiKey: 'rrk_...'
19
+ });
20
+
21
+ const product = await client.getProductInfo.mutate({
22
+ marketplaceId: 'ATVPDKIKX0DER',
23
+ asin: 'B0DV53VS61'
24
+ });
25
+ ```
26
+
27
+ The client is scoped to the public surface (`api.public.*`) so it stays aligned with CLI usage.
28
+
29
+ ## Types
30
+
31
+ ```ts
32
+ import type { PublicRouterInputs, PublicRouterOutputs } from '@rankwrangler/http-client';
33
+
34
+ type GetProductInput = PublicRouterInputs['getProductInfo'];
35
+ type GetProductOutput = PublicRouterOutputs['getProductInfo'];
36
+ ```
37
+
38
+ ## Maintenance
39
+
40
+ When the public router changes, regenerate the bundled router types:
41
+
42
+ ```bash
43
+ bun run http-client:types
44
+ ```
45
+
46
+ Build the package before publishing:
47
+
48
+ ```bash
49
+ bun run http-client:build
50
+ ```
51
+
52
+ ## Publish
53
+
54
+ From `packages/http-client`:
55
+
56
+ ```bash
57
+ set -a
58
+ source ../../.env
59
+ set +a
60
+ npm whoami --userconfig ../../.npmrc
61
+ npm publish --access public --userconfig ../../.npmrc
62
+ ```
63
+
64
+ Before publishing:
65
+
66
+ 1. Bump `version` in `packages/http-client/package.json`.
67
+ 2. Run `bun run http-client:build` from repo root.
68
+ 3. Run `npm pack --dry-run` from `packages/http-client`.
69
+
70
+ ## Versioning
71
+
72
+ - App releases are tracked in root `CHANGELOG.md` as `vX.Y.Z` entries.
73
+ - npm client releases are tracked in `packages/http-client/package.json` with SemVer.
74
+ - These two version tracks are related but independent.
@@ -0,0 +1,205 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export interface LicenseUsageData {
4
+ id: string;
5
+ email: string;
6
+ usage: number;
7
+ usageLimit: number;
8
+ }
9
+ export interface ClerkUser {
10
+ sub: string;
11
+ email?: string;
12
+ }
13
+ export type ProductInfo = {
14
+ asin: string;
15
+ marketplaceId: string;
16
+ dateFirstAvailable: string | null;
17
+ title: string | null;
18
+ brand: string | null;
19
+ rootCategoryId: number | null;
20
+ rootCategoryBsr: number | null;
21
+ rootCategoryDisplayName: string | null;
22
+ thumbnailUrl?: string;
23
+ metadata: {
24
+ lastFetched: string;
25
+ cached: boolean;
26
+ };
27
+ };
28
+ export declare const publicAppRouter: import("@trpc/server").TRPCBuiltRouter<{
29
+ ctx: {
30
+ user: ClerkUser;
31
+ isAdmin: boolean;
32
+ authType: "license" | "clerk" | "none";
33
+ license: {
34
+ key: string;
35
+ data: LicenseUsageData | undefined;
36
+ };
37
+ licenseError: undefined;
38
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
39
+ } | {
40
+ user: null;
41
+ isAdmin: boolean;
42
+ authType: "license" | "clerk" | "none";
43
+ license: null;
44
+ licenseError: string | undefined;
45
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
46
+ } | {
47
+ user: ClerkUser;
48
+ isAdmin: boolean;
49
+ authType: "license" | "clerk" | "none";
50
+ license: null;
51
+ licenseError: undefined;
52
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
53
+ };
54
+ meta: object;
55
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
56
+ transformer: false;
57
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
58
+ api: import("@trpc/server").TRPCBuiltRouter<{
59
+ ctx: {
60
+ user: ClerkUser;
61
+ isAdmin: boolean;
62
+ authType: "license" | "clerk" | "none";
63
+ license: {
64
+ key: string;
65
+ data: LicenseUsageData | undefined;
66
+ };
67
+ licenseError: undefined;
68
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
69
+ } | {
70
+ user: null;
71
+ isAdmin: boolean;
72
+ authType: "license" | "clerk" | "none";
73
+ license: null;
74
+ licenseError: string | undefined;
75
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
76
+ } | {
77
+ user: ClerkUser;
78
+ isAdmin: boolean;
79
+ authType: "license" | "clerk" | "none";
80
+ license: null;
81
+ licenseError: undefined;
82
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
83
+ };
84
+ meta: object;
85
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
86
+ transformer: false;
87
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
88
+ public: import("@trpc/server").TRPCBuiltRouter<{
89
+ ctx: {
90
+ user: ClerkUser;
91
+ isAdmin: boolean;
92
+ authType: "license" | "clerk" | "none";
93
+ license: {
94
+ key: string;
95
+ data: LicenseUsageData | undefined;
96
+ };
97
+ licenseError: undefined;
98
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
99
+ } | {
100
+ user: null;
101
+ isAdmin: boolean;
102
+ authType: "license" | "clerk" | "none";
103
+ license: null;
104
+ licenseError: string | undefined;
105
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
106
+ } | {
107
+ user: ClerkUser;
108
+ isAdmin: boolean;
109
+ authType: "license" | "clerk" | "none";
110
+ license: null;
111
+ licenseError: undefined;
112
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
113
+ };
114
+ meta: object;
115
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
116
+ transformer: false;
117
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
118
+ getProductInfoBatch: import("@trpc/server").TRPCMutationProcedure<{
119
+ input: {
120
+ marketplaceId: string;
121
+ asins: string[];
122
+ };
123
+ output: {
124
+ marketplaceId: string;
125
+ items: ({
126
+ asin: string;
127
+ success: true;
128
+ data: ProductInfo;
129
+ } | {
130
+ asin: string;
131
+ success: false;
132
+ error: string;
133
+ code: "UNAUTHORIZED" | "PARSE_ERROR" | "BAD_REQUEST" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
134
+ })[];
135
+ meta: {
136
+ requestedCount: number;
137
+ successCount: number;
138
+ errorCount: number;
139
+ };
140
+ };
141
+ meta: object;
142
+ }>;
143
+ getProductInfo: import("@trpc/server").TRPCMutationProcedure<{
144
+ input: {
145
+ marketplaceId: string;
146
+ asin: string;
147
+ };
148
+ output: ProductInfo;
149
+ meta: object;
150
+ }>;
151
+ license: import("@trpc/server").TRPCBuiltRouter<{
152
+ ctx: {
153
+ user: ClerkUser;
154
+ isAdmin: boolean;
155
+ authType: "license" | "clerk" | "none";
156
+ license: {
157
+ key: string;
158
+ data: LicenseUsageData | undefined;
159
+ };
160
+ licenseError: undefined;
161
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
162
+ } | {
163
+ user: null;
164
+ isAdmin: boolean;
165
+ authType: "license" | "clerk" | "none";
166
+ license: null;
167
+ licenseError: string | undefined;
168
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
169
+ } | {
170
+ user: ClerkUser;
171
+ isAdmin: boolean;
172
+ authType: "license" | "clerk" | "none";
173
+ license: null;
174
+ licenseError: undefined;
175
+ request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider.js").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>;
176
+ };
177
+ meta: object;
178
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
179
+ transformer: false;
180
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
181
+ validate: import("@trpc/server").TRPCMutationProcedure<{
182
+ input: void;
183
+ output: {
184
+ email: string;
185
+ usage: number;
186
+ usageLimit: number;
187
+ };
188
+ meta: object;
189
+ }>;
190
+ status: import("@trpc/server").TRPCMutationProcedure<{
191
+ input: void;
192
+ output: {
193
+ email: string;
194
+ usage: number;
195
+ usageLimit: number;
196
+ };
197
+ meta: object;
198
+ }>;
199
+ }>>;
200
+ }>>;
201
+ }>>;
202
+ }>>;
203
+ export type PublicAppRouter = typeof publicAppRouter;
204
+
205
+ export {};
@@ -0,0 +1,19 @@
1
+ import { createTRPCProxyClient } from '@trpc/client';
2
+ import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
3
+ import type { PublicAppRouter } from './app-router';
4
+ export declare const DEFAULT_API_BASE_URL = "https://rankwrangler.merchbase.co";
5
+ export type AppRouter = PublicAppRouter;
6
+ export type RouterInputs = inferRouterInputs<PublicAppRouter>;
7
+ export type RouterOutputs = inferRouterOutputs<PublicAppRouter>;
8
+ export type PublicRouterInputs = RouterInputs['api']['public'];
9
+ export type PublicRouterOutputs = RouterOutputs['api']['public'];
10
+ export type RankWranglerClientOptions = {
11
+ baseUrl: string;
12
+ apiKey?: string;
13
+ headers?: Record<string, string>;
14
+ batch?: boolean;
15
+ };
16
+ type PublicProxyClient = ReturnType<typeof createTRPCProxyClient<PublicAppRouter>>;
17
+ export type RankWranglerClient = PublicProxyClient['api']['public'];
18
+ export declare const createRankWranglerClient: ({ baseUrl, apiKey, headers, batch, }: RankWranglerClientOptions) => RankWranglerClient;
19
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { createTRPCProxyClient, httpBatchLink, httpLink } from '@trpc/client';
2
+ const TRAILING_SLASHES_REGEX = /\/+$/;
3
+ export const DEFAULT_API_BASE_URL = 'https://rankwrangler.merchbase.co';
4
+ export const createRankWranglerClient = ({ baseUrl, apiKey, headers, batch = true, }) => {
5
+ const url = `${normalizeBaseUrl(baseUrl)}/api`;
6
+ const resolveHeaders = () => ({
7
+ ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
8
+ ...(headers ?? {}),
9
+ });
10
+ if (batch) {
11
+ const client = createTRPCProxyClient({
12
+ links: [
13
+ httpBatchLink({
14
+ url,
15
+ headers: resolveHeaders,
16
+ }),
17
+ ],
18
+ });
19
+ return client.api.public;
20
+ }
21
+ const client = createTRPCProxyClient({
22
+ links: [
23
+ httpLink({
24
+ url,
25
+ headers: resolveHeaders,
26
+ }),
27
+ ],
28
+ });
29
+ return client.api.public;
30
+ };
31
+ const normalizeBaseUrl = (baseUrl) => baseUrl.replace(TRAILING_SLASHES_REGEX, '');
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@rankwrangler/http-client",
3
+ "version": "0.1.2",
4
+ "description": "Typed tRPC client for RankWrangler",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": ["dist", "README.md"],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "sideEffects": false,
19
+ "dependencies": {
20
+ "@trpc/client": "^11.0.0",
21
+ "@trpc/server": "^11.0.0"
22
+ },
23
+ "packageManager": "bun@1.1.27"
24
+ }