@privy-io/api-base 0.2.0-beta-20230925233038 → 0.2.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/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{z as D}from"zod";var E=(t=>(t.APPLICATION_JSON="application/json",t))(E||{});var u=(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))(u||{});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}]`:""}`}},y=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,y as InvalidInputError,x as LegacyInvalidInputError,E as MimeType,d as NotFoundError,c as PrivyErrorCode,S as Protocols,i as Route,u as StatusCode,R as TooManyRequestsError,m as UnauthorizedError,P as UnsupportedMediaType,D as z};
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};
package/dist/index.d.ts CHANGED
@@ -2,6 +2,103 @@ import * as zod from 'zod';
2
2
  import { ZodType, ZodCatch, z } from 'zod';
3
3
  export { z } from 'zod';
4
4
 
5
+ declare enum PrivyErrorCode {
6
+ /** The Privy app id is either not provided or not valid. Check the developer console to verify you are setting the correct value. */
7
+ MISSING_OR_INVALID_PRIVY_APP_ID = "missing_or_invalid_privy_app_id",
8
+ /** The Privy account id is either not provided or not valid. Check the developer console to verify you are setting the correct value. */
9
+ MISSING_OR_INVALID_PRIVY_ACCOUNT_ID = "missing_or_invalid_privy_account_id",
10
+ /** The refresh or access token is either not provided or not valid. */
11
+ MISSING_OR_INVALID_TOKEN = "missing_or_invalid_token",
12
+ /** The body of the request contains input that is invalid. Check the response body for detailed information. */
13
+ INVALID_DATA = "invalid_data",
14
+ /** A form of INVALID_DATA specifically when the user is trying to authenticate and did not match the provided challenge. */
15
+ INVALID_CREDENTIALS = "invalid_credentials",
16
+ /** You attempted to link an account that belongs to another user. */
17
+ LINKED_TO_ANOTHER_USER = "linked_to_another_user",
18
+ /** This app has an allowlist and the login account was not included. Either disable the allowlist or have the user try again with a different account. */
19
+ ALLOWLIST_REJECTED = "allowlist_rejected",
20
+ /** Embedded wallets cannot be unlinked */
21
+ CANNOT_UNLINK_EMBEDDED_WALLET = "cannot_unlink_embedded_wallet",
22
+ /** You are unable to unlink an account when there is only one account present. */
23
+ CANNOT_UNLINK_SOLE_ACCOUNT = "cannot_unlink_sole_account",
24
+ /** Cannot link another account of this type */
25
+ CANNOT_LINK_MORE_OF_TYPE = "cannot_link_more_of_type",
26
+ /** Linked account cannot be found. The account was either invalid or has already been unlinked. */
27
+ LINKED_ACCOUNT_NOT_FOUND = "linked_account_not_found",
28
+ /** Too many requests. Please wait to try again. */
29
+ TOO_MANY_REQUESTS = "too_many_requests",
30
+ /** Origin was expected and is invalid. */
31
+ INVALID_ORIGIN = "invalid_origin",
32
+ /** Origin was expected and is not set. */
33
+ MISSING_ORIGIN = "missing_origin",
34
+ /** Refresh token re-use detected. */
35
+ TOKEN_ALREADY_USED = "token_already_used",
36
+ /** Attempting to log out of a session that does not exist. */
37
+ ALREADY_LOGGED_OUT = "already_logged_out",
38
+ /** The value (phone number, email) that was submitted is not supported. */
39
+ NOT_SUPPORTED = "not_supported",
40
+ /** You have previously unsubscribed from the sending email/phone number. */
41
+ USER_UNSUBSCRIBED = "user_unsubscribed",
42
+ /** You have reached the maximum number of apps allowed per account. */
43
+ MAX_APPS_REACHED = "max_apps_reached",
44
+ /** You are trying to reconstruct an embedded wallet on a device that has been marked as revoked */
45
+ DEVICE_REVOKED = "device_revoked",
46
+ /** You attempted to set a password on a wallet with an existing password */
47
+ WALLET_PASSWORD_EXISTS = "wallet_password_exists"
48
+ }
49
+
50
+ type ApiError = {
51
+ error: string;
52
+ cause?: string;
53
+ code?: PrivyErrorCode;
54
+ };
55
+ declare class HttpError extends Error {
56
+ status: number;
57
+ /** Unique Privy error code. The SDK/customers should be able to use this code to programmatically */
58
+ code?: PrivyErrorCode;
59
+ constructor(status: number, message: string, code?: PrivyErrorCode);
60
+ toString(): string;
61
+ }
62
+ declare class InvalidInputError extends HttpError {
63
+ constructor(message: string, errorCode: PrivyErrorCode);
64
+ }
65
+ declare class UnauthorizedError extends HttpError {
66
+ constructor(message: string, errorCode?: PrivyErrorCode);
67
+ }
68
+ declare class AllowlistRejectedError extends UnauthorizedError {
69
+ /**
70
+ * TODO: Changing the default message will cause existing allowlist SDK checks to fail and
71
+ * should not be done until we're sure all users are off the version of the SDK that checks for
72
+ * that string.
73
+ */
74
+ constructor(message?: string);
75
+ }
76
+ declare class ForbiddenError extends HttpError {
77
+ constructor(message: string, errorCode?: PrivyErrorCode);
78
+ }
79
+ declare class NotFoundError extends HttpError {
80
+ constructor(message: string);
81
+ }
82
+ declare class UnsupportedMediaType extends HttpError {
83
+ constructor(message: string);
84
+ }
85
+ /**
86
+ * @deprecated
87
+ *
88
+ * Use InvalidInputError moving forward.
89
+ *
90
+ * In the past, we would occasionally return 422 for invalid input.
91
+ */
92
+ declare class LegacyInvalidInputError extends HttpError {
93
+ constructor(message: string, errorCode: PrivyErrorCode);
94
+ }
95
+ declare class TooManyRequestsError extends HttpError {
96
+ constructor(message?: string);
97
+ }
98
+ declare class InternalServerError extends HttpError {
99
+ constructor(message?: string);
100
+ }
101
+
5
102
  declare enum HttpMethod {
6
103
  GET = "get",
7
104
  POST = "post",
@@ -224,15 +321,15 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
224
321
  readonly schema: zod.ZodObject<{
225
322
  error: zod.ZodString;
226
323
  cause: zod.ZodOptional<zod.ZodString>;
227
- code: zod.ZodOptional<zod.ZodNativeEnum<typeof undefined>>;
324
+ code: zod.ZodOptional<zod.ZodNativeEnum<typeof PrivyErrorCode>>;
228
325
  }, "strip", zod.ZodTypeAny, {
229
326
  error: string;
230
327
  cause?: string | undefined;
231
- code?: undefined | undefined;
328
+ code?: PrivyErrorCode | undefined;
232
329
  }, {
233
330
  error: string;
234
331
  cause?: string | undefined;
235
- code?: undefined | undefined;
332
+ code?: PrivyErrorCode | undefined;
236
333
  }>;
237
334
  };
238
335
  };
@@ -244,15 +341,15 @@ declare class Route<Name extends string, Method extends HttpMethod, Path extends
244
341
  readonly schema: zod.ZodObject<{
245
342
  error: zod.ZodString;
246
343
  cause: zod.ZodOptional<zod.ZodString>;
247
- code: zod.ZodOptional<zod.ZodNativeEnum<typeof undefined>>;
344
+ code: zod.ZodOptional<zod.ZodNativeEnum<typeof PrivyErrorCode>>;
248
345
  }, "strip", zod.ZodTypeAny, {
249
346
  error: string;
250
347
  cause?: string | undefined;
251
- code?: undefined | undefined;
348
+ code?: PrivyErrorCode | undefined;
252
349
  }, {
253
350
  error: string;
254
351
  cause?: string | undefined;
255
- code?: undefined | undefined;
352
+ code?: PrivyErrorCode | undefined;
256
353
  }>;
257
354
  };
258
355
  };
@@ -293,103 +390,6 @@ type InferRouteTypes<T> = T extends Route<infer Name, infer Method, infer Path,
293
390
  expectedResponse: ResponseType[ExpectedStatusCode];
294
391
  } : never;
295
392
 
296
- declare enum PrivyErrorCode {
297
- /** The Privy app id is either not provided or not valid. Check the developer console to verify you are setting the correct value. */
298
- MISSING_OR_INVALID_PRIVY_APP_ID = "missing_or_invalid_privy_app_id",
299
- /** The Privy account id is either not provided or not valid. Check the developer console to verify you are setting the correct value. */
300
- MISSING_OR_INVALID_PRIVY_ACCOUNT_ID = "missing_or_invalid_privy_account_id",
301
- /** The refresh or access token is either not provided or not valid. */
302
- MISSING_OR_INVALID_TOKEN = "missing_or_invalid_token",
303
- /** The body of the request contains input that is invalid. Check the response body for detailed information. */
304
- INVALID_DATA = "invalid_data",
305
- /** A form of INVALID_DATA specifically when the user is trying to authenticate and did not match the provided challenge. */
306
- INVALID_CREDENTIALS = "invalid_credentials",
307
- /** You attempted to link an account that belongs to another user. */
308
- LINKED_TO_ANOTHER_USER = "linked_to_another_user",
309
- /** This app has an allowlist and the login account was not included. Either disable the allowlist or have the user try again with a different account. */
310
- ALLOWLIST_REJECTED = "allowlist_rejected",
311
- /** Embedded wallets cannot be unlinked */
312
- CANNOT_UNLINK_EMBEDDED_WALLET = "cannot_unlink_embedded_wallet",
313
- /** You are unable to unlink an account when there is only one account present. */
314
- CANNOT_UNLINK_SOLE_ACCOUNT = "cannot_unlink_sole_account",
315
- /** Cannot link another account of this type */
316
- CANNOT_LINK_MORE_OF_TYPE = "cannot_link_more_of_type",
317
- /** Linked account cannot be found. The account was either invalid or has already been unlinked. */
318
- LINKED_ACCOUNT_NOT_FOUND = "linked_account_not_found",
319
- /** Too many requests. Please wait to try again. */
320
- TOO_MANY_REQUESTS = "too_many_requests",
321
- /** Origin was expected and is invalid. */
322
- INVALID_ORIGIN = "invalid_origin",
323
- /** Origin was expected and is not set. */
324
- MISSING_ORIGIN = "missing_origin",
325
- /** Refresh token re-use detected. */
326
- TOKEN_ALREADY_USED = "token_already_used",
327
- /** Attempting to log out of a session that does not exist. */
328
- ALREADY_LOGGED_OUT = "already_logged_out",
329
- /** The value (phone number, email) that was submitted is not supported. */
330
- NOT_SUPPORTED = "not_supported",
331
- /** You have previously unsubscribed from the sending email/phone number. */
332
- USER_UNSUBSCRIBED = "user_unsubscribed",
333
- /** You have reached the maximum number of apps allowed per account. */
334
- MAX_APPS_REACHED = "max_apps_reached",
335
- /** You are trying to reconstruct an embedded wallet on a device that has been marked as revoked */
336
- DEVICE_REVOKED = "device_revoked",
337
- /** You attempted to set a password on a wallet with an existing password */
338
- WALLET_PASSWORD_EXISTS = "wallet_password_exists"
339
- }
340
-
341
- type ApiError = {
342
- error: string;
343
- cause?: string;
344
- code?: PrivyErrorCode;
345
- };
346
- declare class HttpError extends Error {
347
- status: number;
348
- /** Unique Privy error code. The SDK/customers should be able to use this code to programmatically */
349
- code?: PrivyErrorCode;
350
- constructor(status: number, message: string, code?: PrivyErrorCode);
351
- toString(): string;
352
- }
353
- declare class InvalidInputError extends HttpError {
354
- constructor(message: string, errorCode: PrivyErrorCode);
355
- }
356
- declare class UnauthorizedError extends HttpError {
357
- constructor(message: string, errorCode?: PrivyErrorCode);
358
- }
359
- declare class AllowlistRejectedError extends UnauthorizedError {
360
- /**
361
- * TODO: Changing the default message will cause existing allowlist SDK checks to fail and
362
- * should not be done until we're sure all users are off the version of the SDK that checks for
363
- * that string.
364
- */
365
- constructor(message?: string);
366
- }
367
- declare class ForbiddenError extends HttpError {
368
- constructor(message: string, errorCode?: PrivyErrorCode);
369
- }
370
- declare class NotFoundError extends HttpError {
371
- constructor(message: string);
372
- }
373
- declare class UnsupportedMediaType extends HttpError {
374
- constructor(message: string);
375
- }
376
- /**
377
- * @deprecated
378
- *
379
- * Use InvalidInputError moving forward.
380
- *
381
- * In the past, we would occasionally return 422 for invalid input.
382
- */
383
- declare class LegacyInvalidInputError extends HttpError {
384
- constructor(message: string, errorCode: PrivyErrorCode);
385
- }
386
- declare class TooManyRequestsError extends HttpError {
387
- constructor(message?: string);
388
- }
389
- declare class InternalServerError extends HttpError {
390
- constructor(message?: string);
391
- }
392
-
393
393
  declare enum Protocols {
394
394
  HTTP = "http:",
395
395
  HTTPS = "https:"
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var M=(r,e)=>{for(var s in e)E(r,s,{get:e[s],enumerable:!0})},k=(r,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of B(e))!U.call(r,o)&&o!==s&&E(r,o,{get:()=>e[o],enumerable:!(a=b(e,o))||a.enumerable});return r};var w=r=>k(E({},"__esModule",{value:!0}),r);var K={};M(K,{APIError:()=>h,AllowlistRejectedError:()=>d,ForbiddenError:()=>P,HttpError:()=>p,HttpMethod:()=>f,InternalServerError:()=>l,InvalidInputError:()=>N,LegacyInvalidInputError:()=>A,MimeType:()=>y,NotFoundError:()=>x,PrivyErrorCode:()=>c,Protocols:()=>D,Route:()=>T,StatusCode:()=>O,TooManyRequestsError:()=>I,UnauthorizedError:()=>m,UnsupportedMediaType:()=>R,z:()=>u.z});module.exports=w(K);var u=require("zod");var y=(e=>(e.APPLICATION_JSON="application/json",e))(y||{});var O=(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))(O||{});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 h=_.z.object({error:_.z.string(),cause:_.z.string().optional(),code:_.z.nativeEnum(c).optional()});var T=class{#n;#r;#e;#a;#p;#o;#t;#s;constructor({name:e,method:s,path:a,expectedStatusCode:o=200,pathParamsSchema:i,pathQuerySchema:g,bodySchema:S,responseSchema:L}){this.#n=e,this.#r=s,this.#e=a,this.#a=o,this.#p=i,this.#o=g,this.#t=S,this.#s=L}get name(){return this.#n}get method(){return this.#r}get path(){return this.#e}get expectedStatusCode(){return this.#a}parsePathParamsOrThrow(e){return this.#p?.parse(e)}parsePathQueryOrThrow(e){return this.#o?.parse(e)}parseBodyOrThrow(e){return this.#t.parse(e)}parseResponseOrThrow(e,s){let a=this.#s[s];if(!a)throw new Error(`No schema found for status code ${s}`);return a.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:{[400]:T.toJSONResponseSchema(h,"Invalid Input"),[500]:T.toJSONResponseSchema(h,"Server Error"),...this.#s}}}}constructPath({params:e}){let s=this.path;return e!==void 0?(Object.keys(e).forEach(a=>{let o=e[a];s=s.replace(`:${a}`,`${o}`)}),`${s}`):s}};var p=class extends Error{status;code;constructor(e,s,a){super(s),this.code=a,this.status=e}toString(){return`${this.constructor.name}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},N=class extends p{constructor(e,s){super(400,e,s)}},m=class extends p{constructor(e,s){super(401,e,s)}},d=class extends m{constructor(e){super(e||"User is not allowed to login to this app.","allowlist_rejected")}},P=class extends p{constructor(e,s){super(403,e,s)}},x=class extends p{constructor(e){super(404,e)}},R=class extends p{constructor(e){super(415,e)}},A=class extends p{constructor(e,s){super(422,e,s)}},I=class extends p{constructor(e){super(429,e||"Too many requests. Please wait to try again.","too_many_requests")}},l=class extends p{constructor(e){super(500,e||"Service unavailable.")}};var f=(i=>(i.GET="get",i.POST="post",i.PATCH="patch",i.DELETE="delete",i.PUT="put",i))(f||{});var D=(s=>(s.HTTP="http:",s.HTTPS="https:",s))(D||{});0&&(module.exports={APIError,AllowlistRejectedError,ForbiddenError,HttpError,HttpMethod,InternalServerError,InvalidInputError,LegacyInvalidInputError,MimeType,NotFoundError,PrivyErrorCode,Protocols,Route,StatusCode,TooManyRequestsError,UnauthorizedError,UnsupportedMediaType,z});
1
+ "use strict";var E=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var M=(r,e)=>{for(var s in e)E(r,s,{get:e[s],enumerable:!0})},k=(r,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of B(e))!U.call(r,o)&&o!==s&&E(r,o,{get:()=>e[o],enumerable:!(a=b(e,o))||a.enumerable});return r};var w=r=>k(E({},"__esModule",{value:!0}),r);var K={};M(K,{APIError:()=>h,AllowlistRejectedError:()=>d,ForbiddenError:()=>P,HttpError:()=>p,HttpMethod:()=>f,InternalServerError:()=>l,InvalidInputError:()=>N,LegacyInvalidInputError:()=>A,MimeType:()=>u,NotFoundError:()=>x,PrivyErrorCode:()=>c,Protocols:()=>D,Route:()=>T,StatusCode:()=>O,TooManyRequestsError:()=>I,UnauthorizedError:()=>m,UnsupportedMediaType:()=>R,z:()=>y.z});module.exports=w(K);var y=require("zod");var u=(e=>(e.APPLICATION_JSON="application/json",e))(u||{});var O=(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))(O||{});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 h=_.z.object({error:_.z.string(),cause:_.z.string().optional(),code:_.z.nativeEnum(c).optional()});var T=class{#n;#r;#e;#a;#p;#o;#t;#s;constructor({name:e,method:s,path:a,expectedStatusCode:o=200,pathParamsSchema:i,pathQuerySchema:g,bodySchema:S,responseSchema:L}){this.#n=e,this.#r=s,this.#e=a,this.#a=o,this.#p=i,this.#o=g,this.#t=S,this.#s=L}get name(){return this.#n}get method(){return this.#r}get path(){return this.#e}get expectedStatusCode(){return this.#a}parsePathParamsOrThrow(e){return this.#p?.parse(e)}parsePathQueryOrThrow(e){return this.#o?.parse(e)}parseBodyOrThrow(e){return this.#t.parse(e)}parseResponseOrThrow(e,s){let a=this.#s[s];if(!a)throw new Error(`No schema found for status code ${s}`);return a.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:{[400]:T.toJSONResponseSchema(h,"Invalid Input"),[500]:T.toJSONResponseSchema(h,"Server Error"),...this.#s}}}}constructPath({params:e}){let s=this.path;return e!==void 0?(Object.keys(e).forEach(a=>{let o=e[a];s=s.replace(`:${a}`,`${o}`)}),`${s}`):s}};var p=class extends Error{status;code;constructor(e,s,a){super(s),this.code=a,this.status=e}toString(){return`${this.constructor.name}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},N=class extends p{constructor(e,s){super(400,e,s)}},m=class extends p{constructor(e,s){super(401,e,s)}},d=class extends m{constructor(e){super(e||"User is not allowed to login to this app.","allowlist_rejected")}},P=class extends p{constructor(e,s){super(403,e,s)}},x=class extends p{constructor(e){super(404,e)}},R=class extends p{constructor(e){super(415,e)}},A=class extends p{constructor(e,s){super(422,e,s)}},I=class extends p{constructor(e){super(429,e||"Too many requests. Please wait to try again.","too_many_requests")}},l=class extends p{constructor(e){super(500,e||"Service unavailable.")}};var f=(i=>(i.GET="get",i.POST="post",i.PATCH="patch",i.DELETE="delete",i.PUT="put",i))(f||{});var D=(s=>(s.HTTP="http:",s.HTTPS="https:",s))(D||{});0&&(module.exports={APIError,AllowlistRejectedError,ForbiddenError,HttpError,HttpMethod,InternalServerError,InvalidInputError,LegacyInvalidInputError,MimeType,NotFoundError,PrivyErrorCode,Protocols,Route,StatusCode,TooManyRequestsError,UnauthorizedError,UnsupportedMediaType,z});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privy-io/api-base",
3
- "version": "0.2.0-beta-20230925233038",
3
+ "version": "0.2.0",
4
4
  "engines": {
5
5
  "npm": ">=8.0.0 <10.0.0",
6
6
  "node": ">=18.0.0 <19"