@privy-io/api-base 0.2.0 → 0.3.0-beta-20230928004335
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/dist/index.d.ts +77 -48
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -0
- package/package.json +7 -7
- package/dist/esm/index.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ declare enum PrivyErrorCode {
|
|
|
47
47
|
WALLET_PASSWORD_EXISTS = "wallet_password_exists"
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
type
|
|
50
|
+
type ApiErrorType = {
|
|
51
51
|
error: string;
|
|
52
52
|
cause?: string;
|
|
53
53
|
code?: PrivyErrorCode;
|
|
@@ -143,7 +143,7 @@ type PathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${
|
|
|
143
143
|
[K in Param | keyof PathParams<Rest>]: PathParam;
|
|
144
144
|
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
145
145
|
[K in Param]: PathParam;
|
|
146
|
-
} : Record<string,
|
|
146
|
+
} : Record<string, string>;
|
|
147
147
|
type TBaseQuery = {
|
|
148
148
|
[name: string]: string | number | boolean | undefined;
|
|
149
149
|
};
|
|
@@ -163,6 +163,33 @@ type TBaseResponseStatusCodeMap = {
|
|
|
163
163
|
* @template T - The type that the ZodType or ZodCatch is expected to validate.
|
|
164
164
|
*/
|
|
165
165
|
type ZodTypeOrCatch<T> = ZodCatch<ZodType<T>> | ZodType<T>;
|
|
166
|
+
/**
|
|
167
|
+
* IRouteNamedTypes is an interface that defines the types for a route.
|
|
168
|
+
* It includes the expected response type, the name of the route, the HTTP method, the path,
|
|
169
|
+
* the type of path parameters, the type of query parameters, the type of the body,
|
|
170
|
+
* the type of the response, and the expected status code.
|
|
171
|
+
*
|
|
172
|
+
* @template Name - A string that uniquely identifies the route.
|
|
173
|
+
* @template Path - The URL path of the route. It can include path parameters, denoted by a colon prefix (e.g., '/user/:id').
|
|
174
|
+
* @template ExpectedResponseType - An object type representing the expected structure of the response. It should be a subtype of TBaseResponse.
|
|
175
|
+
* @template ExpectedStatusCode - The expected HTTP status code of the response. It should be a StatusCode. Default is StatusCode.OK.
|
|
176
|
+
*/
|
|
177
|
+
interface IRouteNamedTypes<Path extends string, ExpectedResponseType extends TBaseResponse, ExpectedStatusCode extends StatusCode = StatusCode.OK> {
|
|
178
|
+
Name: string;
|
|
179
|
+
Method: HttpMethod;
|
|
180
|
+
PathParamsType: PathParams<Path>;
|
|
181
|
+
PathQueryType: TBaseQuery;
|
|
182
|
+
BodyType: TBaseBody;
|
|
183
|
+
ResponseType: Partial<TBaseResponseStatusCodeMap> & Record<ExpectedStatusCode, ExpectedResponseType>;
|
|
184
|
+
ExpectedStatusCode: ExpectedStatusCode;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* BaseRouteType is a type alias for IRouteNamedTypes with default parameters.
|
|
188
|
+
* It represents a basic route type with a string name, string path, TBaseResponse as the expected response type,
|
|
189
|
+
* and StatusCode.OK as the expected status code.
|
|
190
|
+
* This type is used as a default in the `Route` class.
|
|
191
|
+
*/
|
|
192
|
+
type BaseRouteType = IRouteNamedTypes<string, TBaseResponse, StatusCode.OK>;
|
|
166
193
|
/**
|
|
167
194
|
* Sample Usage
|
|
168
195
|
*
|
|
@@ -193,16 +220,18 @@ type ZodTypeOrCatch<T> = ZodCatch<ZodType<T>> | ZodType<T>;
|
|
|
193
220
|
* It encapsulates all the necessary details about a route such as its name, HTTP method, path, and expected response.
|
|
194
221
|
* It also includes schemas for validating path parameters, query parameters, request body, and response.
|
|
195
222
|
*
|
|
196
|
-
* @
|
|
197
|
-
* @
|
|
198
|
-
* @template
|
|
199
|
-
* @
|
|
200
|
-
* @
|
|
201
|
-
* @
|
|
202
|
-
* @
|
|
203
|
-
* @
|
|
223
|
+
* @property {string} Path - The URL path of the route. It can include path parameters, denoted by a colon prefix (e.g., '/user/:id').
|
|
224
|
+
* @property {ExpectedResponseType} ExpectedResponseType - An object type representing the expected structure of the response. It should be a subtype of TBaseResponse.
|
|
225
|
+
* @template T - An object that includes the following properties:
|
|
226
|
+
* @property {string} T.Name - A string that uniquely identifies the route.
|
|
227
|
+
* @property {HttpMethod} T.Method - The HTTP method (GET, POST, PUT, DELETE, etc.) that the route responds to.
|
|
228
|
+
* @property {Object} T.PathParamsType - An object type derived from the path string, where each property is a path parameter and its value is a PathParam type.
|
|
229
|
+
* @property {Object} T.PathQueryType - An object type representing the expected structure of the query parameters in the route. It should be a subtype of TBaseQuery.
|
|
230
|
+
* @property {Object} T.BodyType - An object type representing the expected structure of the request body. It should be a subtype of TBaseBody.
|
|
231
|
+
* @property {Object} T.ResponseType - An object type representing the expected structure of the response. It should be a subtype of TBaseResponseStatusCodeMap and a record of ExpectedStatusCode to TBaseResponse.
|
|
232
|
+
* @property {StatusCode} T.ExpectedStatusCode - The expected HTTP status code of the response. Default is StatusCode.OK.
|
|
204
233
|
*/
|
|
205
|
-
declare class Route<
|
|
234
|
+
declare class Route<Path extends string, ExpectedResponseType extends TBaseResponse, T extends IRouteNamedTypes<Path, ExpectedResponseType>> {
|
|
206
235
|
#private;
|
|
207
236
|
/**
|
|
208
237
|
* Constructs a new instance of the Route class.
|
|
@@ -220,19 +249,19 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
220
249
|
* @param {ZodType<ResponseType[K]>} params.responseSchema[K].content[MimeType.APPLICATION_JSON].schema - The schema for the response content.
|
|
221
250
|
*/
|
|
222
251
|
constructor({ name, method, path, expectedStatusCode, pathParamsSchema, pathQuerySchema, bodySchema, responseSchema, }: {
|
|
223
|
-
name: Name;
|
|
224
|
-
expectedStatusCode?: ExpectedStatusCode;
|
|
225
|
-
method: Method;
|
|
252
|
+
name: T['Name'];
|
|
253
|
+
expectedStatusCode?: T['ExpectedStatusCode'];
|
|
254
|
+
method: T['Method'];
|
|
226
255
|
path: Path;
|
|
227
|
-
pathParamsSchema: ZodType<PathParamsType>;
|
|
228
|
-
pathQuerySchema: ZodType<PathQueryType>;
|
|
229
|
-
bodySchema: ZodTypeOrCatch<BodyType>;
|
|
256
|
+
pathParamsSchema: ZodType<T['PathParamsType']>;
|
|
257
|
+
pathQuerySchema: ZodType<T['PathQueryType']>;
|
|
258
|
+
bodySchema: ZodTypeOrCatch<T['BodyType']>;
|
|
230
259
|
responseSchema: {
|
|
231
|
-
[K in keyof ResponseType]: {
|
|
260
|
+
[K in keyof T['ResponseType']]: {
|
|
232
261
|
description: string;
|
|
233
262
|
content: {
|
|
234
263
|
[MimeType.APPLICATION_JSON]: {
|
|
235
|
-
schema: ZodType<ResponseType[K]>;
|
|
264
|
+
schema: ZodType<T['ResponseType'][K]>;
|
|
236
265
|
};
|
|
237
266
|
};
|
|
238
267
|
};
|
|
@@ -242,12 +271,12 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
242
271
|
* Getter for the name of the route.
|
|
243
272
|
* @returns {Name} The name of the route.
|
|
244
273
|
*/
|
|
245
|
-
get name(): Name;
|
|
274
|
+
get name(): T["Name"];
|
|
246
275
|
/**
|
|
247
276
|
* Getter for the HTTP method of the route.
|
|
248
277
|
* @returns {Method} The HTTP method of the route.
|
|
249
278
|
*/
|
|
250
|
-
get method(): Method;
|
|
279
|
+
get method(): T["Method"];
|
|
251
280
|
/**
|
|
252
281
|
* Getter for the path of the route.
|
|
253
282
|
* @returns {Path} The path of the route.
|
|
@@ -257,32 +286,32 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
257
286
|
* Getter for the expected status code of the route.
|
|
258
287
|
* @returns {ExpectedStatusCode} The expected status code of the route.
|
|
259
288
|
*/
|
|
260
|
-
get expectedStatusCode(): ExpectedStatusCode;
|
|
289
|
+
get expectedStatusCode(): T["ExpectedStatusCode"];
|
|
261
290
|
/**
|
|
262
291
|
* Parses the path parameters or throws an error if they are invalid.
|
|
263
292
|
* @param {unknown} maybePathParams - The path parameters to parse.
|
|
264
293
|
* @returns {PathParamsType} The parsed path parameters.
|
|
265
294
|
*/
|
|
266
|
-
parsePathParamsOrThrow(maybePathParams: unknown): PathParamsType;
|
|
295
|
+
parsePathParamsOrThrow(maybePathParams: unknown): T["PathParamsType"];
|
|
267
296
|
/**
|
|
268
297
|
* Parses the path query or throws an error if it is invalid.
|
|
269
298
|
* @param {unknown} maybePathQuery - The path query to parse.
|
|
270
299
|
* @returns {PathQueryType} The parsed path query.
|
|
271
300
|
*/
|
|
272
|
-
parsePathQueryOrThrow(maybePathQuery: unknown): PathQueryType;
|
|
301
|
+
parsePathQueryOrThrow(maybePathQuery: unknown): T["PathQueryType"];
|
|
273
302
|
/**
|
|
274
303
|
* Parses the body or throws an error if it is invalid.
|
|
275
304
|
* @param {unknown} maybeBody - The body to parse.
|
|
276
305
|
* @returns {BodyType} The parsed body.
|
|
277
306
|
*/
|
|
278
|
-
parseBodyOrThrow(maybeBody: unknown): BodyType;
|
|
307
|
+
parseBodyOrThrow(maybeBody: unknown): T["BodyType"];
|
|
279
308
|
/**
|
|
280
309
|
* Parses the response or throws an error if it is invalid.
|
|
281
310
|
* @param {unknown} maybeResponse - The response to parse.
|
|
282
311
|
* @param {StatusCode} statusCode - The status code of the response.
|
|
283
312
|
* @returns {ResponseType} The parsed response.
|
|
284
313
|
*/
|
|
285
|
-
parseResponseOrThrow(maybeResponse: unknown, statusCode: StatusCode): ResponseType[StatusCode.OK] | ResponseType[StatusCode.CREATED] | ResponseType[StatusCode.NO_CONTENT] | ResponseType[StatusCode.MOVED_PERMANENTLY] | ResponseType[StatusCode.MOVED_TEMPORARILY] | ResponseType[StatusCode.NOT_MODIFIED] | ResponseType[StatusCode.BAD_REQUEST] | ResponseType[StatusCode.NOT_AUTHENTICATED] | ResponseType[StatusCode.FORBIDDEN] | ResponseType[StatusCode.NOT_FOUND] | ResponseType[StatusCode.METHOD_NOT_ALLOWED] | ResponseType[StatusCode.UNSUPPORTED_MEDIA_TYPE] | ResponseType[StatusCode.UNPROCESSABLE_CONTENT] | ResponseType[StatusCode.TOO_MANY_REQUESTS] | ResponseType[StatusCode.INTERNAL_SERVER_ERROR] | ResponseType[StatusCode.NOT_IMPLEMENTED] | ResponseType[StatusCode.BAD_GATEWAY] | ResponseType[StatusCode.SERVICE_UNAVAILABLE] | ResponseType[StatusCode.GATEWAY_TIME_OUT] | ResponseType[StatusCode.HTTP_VERSION_NOT_SUPPORTED];
|
|
314
|
+
parseResponseOrThrow(maybeResponse: unknown, statusCode: StatusCode): T["ResponseType"][StatusCode.OK] | T["ResponseType"][StatusCode.CREATED] | T["ResponseType"][StatusCode.NO_CONTENT] | T["ResponseType"][StatusCode.MOVED_PERMANENTLY] | T["ResponseType"][StatusCode.MOVED_TEMPORARILY] | T["ResponseType"][StatusCode.NOT_MODIFIED] | T["ResponseType"][StatusCode.BAD_REQUEST] | T["ResponseType"][StatusCode.NOT_AUTHENTICATED] | T["ResponseType"][StatusCode.FORBIDDEN] | T["ResponseType"][StatusCode.NOT_FOUND] | T["ResponseType"][StatusCode.METHOD_NOT_ALLOWED] | T["ResponseType"][StatusCode.UNSUPPORTED_MEDIA_TYPE] | T["ResponseType"][StatusCode.UNPROCESSABLE_CONTENT] | T["ResponseType"][StatusCode.TOO_MANY_REQUESTS] | T["ResponseType"][StatusCode.INTERNAL_SERVER_ERROR] | T["ResponseType"][StatusCode.NOT_IMPLEMENTED] | T["ResponseType"][StatusCode.BAD_GATEWAY] | T["ResponseType"][StatusCode.SERVICE_UNAVAILABLE] | T["ResponseType"][StatusCode.GATEWAY_TIME_OUT] | T["ResponseType"][StatusCode.HTTP_VERSION_NOT_SUPPORTED];
|
|
286
315
|
/**
|
|
287
316
|
* Converts a Zod schema to a JSON response schema.
|
|
288
317
|
* @template T - The type that the Zod schema validates.
|
|
@@ -309,12 +338,19 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
309
338
|
body: {
|
|
310
339
|
content: {
|
|
311
340
|
'application/json': {
|
|
312
|
-
schema: ZodTypeOrCatch<BodyType>;
|
|
341
|
+
schema: ZodTypeOrCatch<T["BodyType"]>;
|
|
313
342
|
};
|
|
314
343
|
};
|
|
315
344
|
};
|
|
316
345
|
};
|
|
317
|
-
responses: {
|
|
346
|
+
responses: (T["ResponseType"] extends infer T_1 ? { [K in keyof T_1]: {
|
|
347
|
+
description: string;
|
|
348
|
+
content: {
|
|
349
|
+
"application/json": {
|
|
350
|
+
schema: ZodType<T["ResponseType"][K], zod.ZodTypeDef, T["ResponseType"][K]>;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
}; } : never) & {
|
|
318
354
|
400: {
|
|
319
355
|
readonly content: {
|
|
320
356
|
readonly 'application/json': {
|
|
@@ -355,14 +391,7 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
355
391
|
};
|
|
356
392
|
readonly description: string;
|
|
357
393
|
};
|
|
358
|
-
}
|
|
359
|
-
description: string;
|
|
360
|
-
content: {
|
|
361
|
-
"application/json": {
|
|
362
|
-
schema: ZodType<ResponseType[K], zod.ZodTypeDef, ResponseType[K]>;
|
|
363
|
-
};
|
|
364
|
-
};
|
|
365
|
-
}; };
|
|
394
|
+
};
|
|
366
395
|
};
|
|
367
396
|
};
|
|
368
397
|
/**
|
|
@@ -374,20 +403,20 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
|
|
|
374
403
|
* @returns {string} The constructed path.
|
|
375
404
|
*/
|
|
376
405
|
constructPath({ params }: {
|
|
377
|
-
params: PathParamsType;
|
|
406
|
+
params: T['PathParamsType'];
|
|
378
407
|
}): string;
|
|
379
408
|
}
|
|
380
|
-
type AnyRoute = Route<
|
|
381
|
-
type InferRouteTypes<T> = T extends Route<infer
|
|
382
|
-
name: Name;
|
|
383
|
-
method: Method;
|
|
409
|
+
type AnyRoute = Route<string, any, BaseRouteType>;
|
|
410
|
+
type InferRouteTypes<T> = T extends Route<infer Path, infer ExpectedResponseType, infer RouteType> ? {
|
|
411
|
+
name: RouteType['Name'];
|
|
412
|
+
method: RouteType['Method'];
|
|
384
413
|
path: Path;
|
|
385
|
-
pathParams: PathParamsType;
|
|
386
|
-
pathQuery: PathQueryType;
|
|
387
|
-
body: BodyType;
|
|
388
|
-
response: ResponseType;
|
|
389
|
-
expectedStatusCode: ExpectedStatusCode;
|
|
390
|
-
expectedResponse:
|
|
414
|
+
pathParams: RouteType['PathParamsType'];
|
|
415
|
+
pathQuery: RouteType['PathQueryType'];
|
|
416
|
+
body: RouteType['BodyType'];
|
|
417
|
+
response: RouteType['ResponseType'];
|
|
418
|
+
expectedStatusCode: RouteType['ExpectedStatusCode'];
|
|
419
|
+
expectedResponse: ExpectedResponseType;
|
|
391
420
|
} : never;
|
|
392
421
|
|
|
393
422
|
declare enum Protocols {
|
|
@@ -450,4 +479,4 @@ declare const APIError: z.ZodObject<{
|
|
|
450
479
|
code?: PrivyErrorCode | undefined;
|
|
451
480
|
}>;
|
|
452
481
|
|
|
453
|
-
export { APIError, AllowlistRejectedError, AnyRoute,
|
|
482
|
+
export { APIError, AllowlistRejectedError, AnyRoute, ApiErrorType, BaseRouteType, EndpointSpec, ForbiddenError, HttpError, HttpMethod, IRouteNamedTypes, InferRouteTypes, InternalServerError, InvalidInputError, LegacyInvalidInputError, MimeType, NotFoundError, OauthResponse, PrivyErrorCode, Protocols, Responses, Route, StatusCode, TooManyRequestsError, UnauthorizedError, UnsupportedMediaType };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var M=(p,e)=>{for(var s in e)u(p,s,{get:e[s],enumerable:!0})},k=(p,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of b(e))!U.call(p,a)&&a!==s&&u(p,a,{get:()=>e[a],enumerable:!(r=B(e,a))||r.enumerable});return p};var K=p=>k(u({},"__esModule",{value:!0}),p);var w={};M(w,{APIError:()=>m,AllowlistRejectedError:()=>N,ForbiddenError:()=>O,HttpError:()=>o,HttpMethod:()=>g,InternalServerError:()=>l,InvalidInputError:()=>d,LegacyInvalidInputError:()=>A,MimeType:()=>E,NotFoundError:()=>x,PrivyErrorCode:()=>c,Protocols:()=>f,Route:()=>i,StatusCode:()=>R,TooManyRequestsError:()=>I,UnauthorizedError:()=>h,UnsupportedMediaType:()=>P,z:()=>y.z});module.exports=K(w);var y=require("zod");var E=(e=>(e.APPLICATION_JSON="application/json",e))(E||{});var R=(t=>(t[t.OK=200]="OK",t[t.CREATED=201]="CREATED",t[t.NO_CONTENT=204]="NO_CONTENT",t[t.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",t[t.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",t[t.NOT_MODIFIED=304]="NOT_MODIFIED",t[t.BAD_REQUEST=400]="BAD_REQUEST",t[t.NOT_AUTHENTICATED=401]="NOT_AUTHENTICATED",t[t.FORBIDDEN=403]="FORBIDDEN",t[t.NOT_FOUND=404]="NOT_FOUND",t[t.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",t[t.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",t[t.UNPROCESSABLE_CONTENT=422]="UNPROCESSABLE_CONTENT",t[t.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",t[t.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",t[t.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",t[t.BAD_GATEWAY=502]="BAD_GATEWAY",t[t.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",t[t.GATEWAY_TIME_OUT=504]="GATEWAY_TIME_OUT",t[t.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",t))(R||{});var _=require("zod");var c=(n=>(n.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",n.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",n.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",n.INVALID_DATA="invalid_data",n.INVALID_CREDENTIALS="invalid_credentials",n.LINKED_TO_ANOTHER_USER="linked_to_another_user",n.ALLOWLIST_REJECTED="allowlist_rejected",n.CANNOT_UNLINK_EMBEDDED_WALLET="cannot_unlink_embedded_wallet",n.CANNOT_UNLINK_SOLE_ACCOUNT="cannot_unlink_sole_account",n.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",n.LINKED_ACCOUNT_NOT_FOUND="linked_account_not_found",n.TOO_MANY_REQUESTS="too_many_requests",n.INVALID_ORIGIN="invalid_origin",n.MISSING_ORIGIN="missing_origin",n.TOKEN_ALREADY_USED="token_already_used",n.ALREADY_LOGGED_OUT="already_logged_out",n.NOT_SUPPORTED="not_supported",n.USER_UNSUBSCRIBED="user_unsubscribed",n.MAX_APPS_REACHED="max_apps_reached",n.DEVICE_REVOKED="device_revoked",n.WALLET_PASSWORD_EXISTS="wallet_password_exists",n))(c||{});var m=_.z.object({error:_.z.string(),cause:_.z.string().optional(),code:_.z.nativeEnum(c).optional()});var i=class{#n;#p;#e;#r;#o;#a;#t;#s;constructor({name:e,method:s,path:r,expectedStatusCode:a=200,pathParamsSchema:T,pathQuerySchema:D,bodySchema:S,responseSchema:L}){this.#n=e,this.#p=s,this.#e=r,this.#r=a,this.#o=T,this.#a=D,this.#t=S,this.#s=L}get name(){return this.#n}get method(){return this.#p}get path(){return this.#e}get expectedStatusCode(){return this.#r}parsePathParamsOrThrow(e){return this.#o?.parse(e)}parsePathQueryOrThrow(e){return this.#a?.parse(e)}parseBodyOrThrow(e){return this.#t.parse(e)}parseResponseOrThrow(e,s){let r=this.#s[s];if(!r)throw new Error(`No schema found for status code ${s}`);return r.content["application/json"].schema.parse(e)}static toJSONResponseSchema(e,s){return{content:{"application/json":{schema:e}},description:s}}toSpec(){return{[this.method]:{path:this.#e,request:{body:{content:{"application/json":{schema:this.#t}}}},responses:{...this.#s,[400]:i.toJSONResponseSchema(m,"Invalid Input"),[500]:i.toJSONResponseSchema(m,"Server Error")}}}}constructPath({params:e}){let s=this.path;return e!==void 0?(Object.keys(e).forEach(r=>{let a=e[r];s=s.replace(`:${r}`,`${a}`)}),`${s}`):s}};var o=class extends Error{status;code;constructor(e,s,r){super(s),this.code=r,this.status=e}toString(){return`${this.constructor.name}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},d=class extends o{constructor(e,s){super(400,e,s)}},h=class extends o{constructor(e,s){super(401,e,s)}},N=class extends h{constructor(e){super(e||"User is not allowed to login to this app.","allowlist_rejected")}},O=class extends o{constructor(e,s){super(403,e,s)}},x=class extends o{constructor(e){super(404,e)}},P=class extends o{constructor(e){super(415,e)}},A=class extends o{constructor(e,s){super(422,e,s)}},I=class extends o{constructor(e){super(429,e||"Too many requests. Please wait to try again.","too_many_requests")}},l=class extends o{constructor(e){super(500,e||"Service unavailable.")}};var g=(T=>(T.GET="get",T.POST="post",T.PATCH="patch",T.DELETE="delete",T.PUT="put",T))(g||{});var f=(s=>(s.HTTP="http:",s.HTTPS="https:",s))(f||{});0&&(module.exports={APIError,AllowlistRejectedError,ForbiddenError,HttpError,HttpMethod,InternalServerError,InvalidInputError,LegacyInvalidInputError,MimeType,NotFoundError,PrivyErrorCode,Protocols,Route,StatusCode,TooManyRequestsError,UnauthorizedError,UnsupportedMediaType,z});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as f}from"zod";var u=(t=>(t.APPLICATION_JSON="application/json",t))(u||{});var y=(e=>(e[e.OK=200]="OK",e[e.CREATED=201]="CREATED",e[e.NO_CONTENT=204]="NO_CONTENT",e[e.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",e[e.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",e[e.NOT_MODIFIED=304]="NOT_MODIFIED",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_AUTHENTICATED=401]="NOT_AUTHENTICATED",e[e.FORBIDDEN=403]="FORBIDDEN",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",e[e.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",e[e.UNPROCESSABLE_CONTENT=422]="UNPROCESSABLE_CONTENT",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",e[e.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",e[e.BAD_GATEWAY=502]="BAD_GATEWAY",e[e.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",e[e.GATEWAY_TIME_OUT=504]="GATEWAY_TIME_OUT",e[e.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",e))(y||{});import{z as _}from"zod";var c=(n=>(n.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",n.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",n.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",n.INVALID_DATA="invalid_data",n.INVALID_CREDENTIALS="invalid_credentials",n.LINKED_TO_ANOTHER_USER="linked_to_another_user",n.ALLOWLIST_REJECTED="allowlist_rejected",n.CANNOT_UNLINK_EMBEDDED_WALLET="cannot_unlink_embedded_wallet",n.CANNOT_UNLINK_SOLE_ACCOUNT="cannot_unlink_sole_account",n.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",n.LINKED_ACCOUNT_NOT_FOUND="linked_account_not_found",n.TOO_MANY_REQUESTS="too_many_requests",n.INVALID_ORIGIN="invalid_origin",n.MISSING_ORIGIN="missing_origin",n.TOKEN_ALREADY_USED="token_already_used",n.ALREADY_LOGGED_OUT="already_logged_out",n.NOT_SUPPORTED="not_supported",n.USER_UNSUBSCRIBED="user_unsubscribed",n.MAX_APPS_REACHED="max_apps_reached",n.DEVICE_REVOKED="device_revoked",n.WALLET_PASSWORD_EXISTS="wallet_password_exists",n))(c||{});var m=_.object({error:_.string(),cause:_.string().optional(),code:_.nativeEnum(c).optional()});var T=class{#n;#p;#e;#r;#o;#a;#t;#s;constructor({name:t,method:s,path:o,expectedStatusCode:i=200,pathParamsSchema:a,pathQuerySchema:I,bodySchema:l,responseSchema:g}){this.#n=t,this.#p=s,this.#e=o,this.#r=i,this.#o=a,this.#a=I,this.#t=l,this.#s=g}get name(){return this.#n}get method(){return this.#p}get path(){return this.#e}get expectedStatusCode(){return this.#r}parsePathParamsOrThrow(t){return this.#o?.parse(t)}parsePathQueryOrThrow(t){return this.#a?.parse(t)}parseBodyOrThrow(t){return this.#t.parse(t)}parseResponseOrThrow(t,s){let o=this.#s[s];if(!o)throw new Error(`No schema found for status code ${s}`);return o.content["application/json"].schema.parse(t)}static toJSONResponseSchema(t,s){return{content:{"application/json":{schema:t}},description:s}}toSpec(){return{[this.method]:{path:this.#e,request:{body:{content:{"application/json":{schema:this.#t}}}},responses:{...this.#s,[400]:T.toJSONResponseSchema(m,"Invalid Input"),[500]:T.toJSONResponseSchema(m,"Server Error")}}}}constructPath({params:t}){let s=this.path;return t!==void 0?(Object.keys(t).forEach(o=>{let i=t[o];s=s.replace(`:${o}`,`${i}`)}),`${s}`):s}};var p=class extends Error{status;code;constructor(t,s,o){super(s),this.code=o,this.status=t}toString(){return`${this.constructor.name}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},E=class extends p{constructor(t,s){super(400,t,s)}},h=class extends p{constructor(t,s){super(401,t,s)}},R=class extends h{constructor(t){super(t||"User is not allowed to login to this app.","allowlist_rejected")}},d=class extends p{constructor(t,s){super(403,t,s)}},N=class extends p{constructor(t){super(404,t)}},O=class extends p{constructor(t){super(415,t)}},x=class extends p{constructor(t,s){super(422,t,s)}},P=class extends p{constructor(t){super(429,t||"Too many requests. Please wait to try again.","too_many_requests")}},A=class extends p{constructor(t){super(500,t||"Service unavailable.")}};var D=(a=>(a.GET="get",a.POST="post",a.PATCH="patch",a.DELETE="delete",a.PUT="put",a))(D||{});var S=(s=>(s.HTTP="http:",s.HTTPS="https:",s))(S||{});export{m as APIError,R as AllowlistRejectedError,d as ForbiddenError,p as HttpError,D as HttpMethod,A as InternalServerError,E as InvalidInputError,x as LegacyInvalidInputError,u as MimeType,N as NotFoundError,c as PrivyErrorCode,S as Protocols,T as Route,y as StatusCode,P as TooManyRequestsError,h as UnauthorizedError,O as UnsupportedMediaType,f as z};
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privy-io/api-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta-20230928004335",
|
|
4
4
|
"engines": {
|
|
5
5
|
"npm": ">=8.0.0 <10.0.0",
|
|
6
6
|
"node": ">=18.0.0 <19"
|
|
7
7
|
},
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
|
-
"module": "./dist/
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"typings": "./dist/index",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"require": "./dist/index.js",
|
|
15
|
-
"import": "./dist/
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
16
|
"types": "./dist/index.d.ts"
|
|
17
17
|
},
|
|
18
18
|
"./zod": {
|
|
19
19
|
"require": "./dist/index.js",
|
|
20
|
-
"import": "./dist/
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
21
|
"types": "./dist/index.d.ts"
|
|
22
22
|
},
|
|
23
23
|
"./constants": {
|
|
24
24
|
"require": "./dist/index.js",
|
|
25
|
-
"import": "./dist/
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
26
|
"types": "./dist/index.d.ts"
|
|
27
27
|
},
|
|
28
28
|
"./constants/*": {
|
|
29
29
|
"require": "./dist/index.js",
|
|
30
|
-
"import": "./dist/
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
31
|
"types": "./dist/index.d.ts"
|
|
32
32
|
},
|
|
33
33
|
"./classes": {
|
|
34
34
|
"require": "./dist/index.js",
|
|
35
|
-
"import": "./dist/
|
|
35
|
+
"import": "./dist/index.mjs",
|
|
36
36
|
"types": "./dist/index.d.ts"
|
|
37
37
|
}
|
|
38
38
|
},
|
package/dist/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{z as D}from"zod";var E=(t=>(t.APPLICATION_JSON="application/json",t))(E||{});var y=(e=>(e[e.OK=200]="OK",e[e.CREATED=201]="CREATED",e[e.NO_CONTENT=204]="NO_CONTENT",e[e.MOVED_PERMANENTLY=301]="MOVED_PERMANENTLY",e[e.MOVED_TEMPORARILY=302]="MOVED_TEMPORARILY",e[e.NOT_MODIFIED=304]="NOT_MODIFIED",e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.NOT_AUTHENTICATED=401]="NOT_AUTHENTICATED",e[e.FORBIDDEN=403]="FORBIDDEN",e[e.NOT_FOUND=404]="NOT_FOUND",e[e.METHOD_NOT_ALLOWED=405]="METHOD_NOT_ALLOWED",e[e.UNSUPPORTED_MEDIA_TYPE=415]="UNSUPPORTED_MEDIA_TYPE",e[e.UNPROCESSABLE_CONTENT=422]="UNPROCESSABLE_CONTENT",e[e.TOO_MANY_REQUESTS=429]="TOO_MANY_REQUESTS",e[e.INTERNAL_SERVER_ERROR=500]="INTERNAL_SERVER_ERROR",e[e.NOT_IMPLEMENTED=501]="NOT_IMPLEMENTED",e[e.BAD_GATEWAY=502]="BAD_GATEWAY",e[e.SERVICE_UNAVAILABLE=503]="SERVICE_UNAVAILABLE",e[e.GATEWAY_TIME_OUT=504]="GATEWAY_TIME_OUT",e[e.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP_VERSION_NOT_SUPPORTED",e))(y||{});import{z as _}from"zod";var c=(n=>(n.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",n.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",n.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",n.INVALID_DATA="invalid_data",n.INVALID_CREDENTIALS="invalid_credentials",n.LINKED_TO_ANOTHER_USER="linked_to_another_user",n.ALLOWLIST_REJECTED="allowlist_rejected",n.CANNOT_UNLINK_EMBEDDED_WALLET="cannot_unlink_embedded_wallet",n.CANNOT_UNLINK_SOLE_ACCOUNT="cannot_unlink_sole_account",n.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",n.LINKED_ACCOUNT_NOT_FOUND="linked_account_not_found",n.TOO_MANY_REQUESTS="too_many_requests",n.INVALID_ORIGIN="invalid_origin",n.MISSING_ORIGIN="missing_origin",n.TOKEN_ALREADY_USED="token_already_used",n.ALREADY_LOGGED_OUT="already_logged_out",n.NOT_SUPPORTED="not_supported",n.USER_UNSUBSCRIBED="user_unsubscribed",n.MAX_APPS_REACHED="max_apps_reached",n.DEVICE_REVOKED="device_revoked",n.WALLET_PASSWORD_EXISTS="wallet_password_exists",n))(c||{});var h=_.object({error:_.string(),cause:_.string().optional(),code:_.nativeEnum(c).optional()});var i=class{#n;#r;#e;#a;#p;#o;#t;#s;constructor({name:t,method:s,path:p,expectedStatusCode:T=200,pathParamsSchema:o,pathQuerySchema:I,bodySchema:l,responseSchema:f}){this.#n=t,this.#r=s,this.#e=p,this.#a=T,this.#p=o,this.#o=I,this.#t=l,this.#s=f}get name(){return this.#n}get method(){return this.#r}get path(){return this.#e}get expectedStatusCode(){return this.#a}parsePathParamsOrThrow(t){return this.#p?.parse(t)}parsePathQueryOrThrow(t){return this.#o?.parse(t)}parseBodyOrThrow(t){return this.#t.parse(t)}parseResponseOrThrow(t,s){let p=this.#s[s];if(!p)throw new Error(`No schema found for status code ${s}`);return p.content["application/json"].schema.parse(t)}static toJSONResponseSchema(t,s){return{content:{"application/json":{schema:t}},description:s}}toSpec(){return{[this.method]:{path:this.#e,request:{body:{content:{"application/json":{schema:this.#t}}}},responses:{[400]:i.toJSONResponseSchema(h,"Invalid Input"),[500]:i.toJSONResponseSchema(h,"Server Error"),...this.#s}}}}constructPath({params:t}){let s=this.path;return t!==void 0?(Object.keys(t).forEach(p=>{let T=t[p];s=s.replace(`:${p}`,`${T}`)}),`${s}`):s}};var r=class extends Error{status;code;constructor(t,s,p){super(s),this.code=p,this.status=t}toString(){return`${this.constructor.name}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},u=class extends r{constructor(t,s){super(400,t,s)}},m=class extends r{constructor(t,s){super(401,t,s)}},O=class extends m{constructor(t){super(t||"User is not allowed to login to this app.","allowlist_rejected")}},N=class extends r{constructor(t,s){super(403,t,s)}},d=class extends r{constructor(t){super(404,t)}},P=class extends r{constructor(t){super(415,t)}},x=class extends r{constructor(t,s){super(422,t,s)}},R=class extends r{constructor(t){super(429,t||"Too many requests. Please wait to try again.","too_many_requests")}},A=class extends r{constructor(t){super(500,t||"Service unavailable.")}};var g=(o=>(o.GET="get",o.POST="post",o.PATCH="patch",o.DELETE="delete",o.PUT="put",o))(g||{});var S=(s=>(s.HTTP="http:",s.HTTPS="https:",s))(S||{});export{h as APIError,O as AllowlistRejectedError,N as ForbiddenError,r as HttpError,g as HttpMethod,A as InternalServerError,u as InvalidInputError,x as LegacyInvalidInputError,E as MimeType,d as NotFoundError,c as PrivyErrorCode,S as Protocols,i as Route,y as StatusCode,R as TooManyRequestsError,m as UnauthorizedError,P as UnsupportedMediaType,D as z};
|