shred-api-client 2.3.3 → 2.3.5-rc.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/index.d.mts CHANGED
@@ -732,6 +732,13 @@ declare const UserSchema: z.ZodObject<{
732
732
  type User = z.infer<typeof UserSchema>;
733
733
  type Preferences$1 = z.infer<typeof PreferencesSchema$1>;
734
734
  type Update = Pick<User, "name" | "profession" | "preferences" | "photoUrl" | "fcmToken" | "timezone" | "experienceId">;
735
+ type Create = Pick<User, "name" | "email"> & {
736
+ password?: string;
737
+ passwordConfirmation?: string;
738
+ invitationCode?: string;
739
+ role?: Role;
740
+ industries?: string[];
741
+ };
735
742
 
736
743
  type QueryOrderBy<T> = {
737
744
  field: keyof T | "modified";
@@ -779,7 +786,7 @@ interface IAPI$8 {
779
786
  getIntegrationToken: (ctx: Context) => Promise<string | null>;
780
787
  createIntegrationToken: (ctx: Context) => Promise<string>;
781
788
  search: (ctx: Context, query: QueryOptions<User>) => Promise<APIResponse<User>>;
782
- createUser: (email: string, name: string, password: string, passwordConfirmation: string, profession: string | null, invitationCode: string | null) => Promise<User>;
789
+ createUser: (data: Create) => Promise<User>;
783
790
  }
784
791
  declare const Endpoints$7: {
785
792
  ChangeEmail: {
@@ -848,6 +855,7 @@ declare const Endpoints$7: {
848
855
  };
849
856
  };
850
857
 
858
+ type index$9_Create = Create;
851
859
  type index$9_Role = Role;
852
860
  declare const index$9_Role: typeof Role;
853
861
  type index$9_System = System;
@@ -855,7 +863,7 @@ declare const index$9_System: typeof System;
855
863
  type index$9_Update = Update;
856
864
  declare const index$9_UserSchema: typeof UserSchema;
857
865
  declare namespace index$9 {
858
- export { Endpoints$7 as Endpoints, type User as Entity, type IAPI$8 as IAPI, type Preferences$1 as Preferences, PreferencesSchema$1 as PreferencesSchema, index$9_Role as Role, index$9_System as System, type index$9_Update as Update, index$9_UserSchema as UserSchema };
866
+ export { type index$9_Create as Create, Endpoints$7 as Endpoints, type User as Entity, type IAPI$8 as IAPI, type Preferences$1 as Preferences, PreferencesSchema$1 as PreferencesSchema, index$9_Role as Role, index$9_System as System, type index$9_Update as Update, index$9_UserSchema as UserSchema };
859
867
  }
860
868
 
861
869
  declare const PreferencesSchema: z.ZodObject<{
package/dist/index.d.ts CHANGED
@@ -732,6 +732,13 @@ declare const UserSchema: z.ZodObject<{
732
732
  type User = z.infer<typeof UserSchema>;
733
733
  type Preferences$1 = z.infer<typeof PreferencesSchema$1>;
734
734
  type Update = Pick<User, "name" | "profession" | "preferences" | "photoUrl" | "fcmToken" | "timezone" | "experienceId">;
735
+ type Create = Pick<User, "name" | "email"> & {
736
+ password?: string;
737
+ passwordConfirmation?: string;
738
+ invitationCode?: string;
739
+ role?: Role;
740
+ industries?: string[];
741
+ };
735
742
 
736
743
  type QueryOrderBy<T> = {
737
744
  field: keyof T | "modified";
@@ -779,7 +786,7 @@ interface IAPI$8 {
779
786
  getIntegrationToken: (ctx: Context) => Promise<string | null>;
780
787
  createIntegrationToken: (ctx: Context) => Promise<string>;
781
788
  search: (ctx: Context, query: QueryOptions<User>) => Promise<APIResponse<User>>;
782
- createUser: (email: string, name: string, password: string, passwordConfirmation: string, profession: string | null, invitationCode: string | null) => Promise<User>;
789
+ createUser: (data: Create) => Promise<User>;
783
790
  }
784
791
  declare const Endpoints$7: {
785
792
  ChangeEmail: {
@@ -848,6 +855,7 @@ declare const Endpoints$7: {
848
855
  };
849
856
  };
850
857
 
858
+ type index$9_Create = Create;
851
859
  type index$9_Role = Role;
852
860
  declare const index$9_Role: typeof Role;
853
861
  type index$9_System = System;
@@ -855,7 +863,7 @@ declare const index$9_System: typeof System;
855
863
  type index$9_Update = Update;
856
864
  declare const index$9_UserSchema: typeof UserSchema;
857
865
  declare namespace index$9 {
858
- export { Endpoints$7 as Endpoints, type User as Entity, type IAPI$8 as IAPI, type Preferences$1 as Preferences, PreferencesSchema$1 as PreferencesSchema, index$9_Role as Role, index$9_System as System, type index$9_Update as Update, index$9_UserSchema as UserSchema };
866
+ export { type index$9_Create as Create, Endpoints$7 as Endpoints, type User as Entity, type IAPI$8 as IAPI, type Preferences$1 as Preferences, PreferencesSchema$1 as PreferencesSchema, index$9_Role as Role, index$9_System as System, type index$9_Update as Update, index$9_UserSchema as UserSchema };
859
867
  }
860
868
 
861
869
  declare const PreferencesSchema: z.ZodObject<{
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ __export(index_exports, {
48
48
  module.exports = __toCommonJS(index_exports);
49
49
 
50
50
  // src/util/HTTPClient.ts
51
- var import_cross_fetch = __toESM(require("cross-fetch"));
51
+ var import_axios = __toESM(require("axios"));
52
52
  var HOSTS = {
53
53
  prod: "https://api.shreditapp.com",
54
54
  staging: "https://api.staging.shreditapp.com",
@@ -73,37 +73,40 @@ var HTTPClient = class {
73
73
  if (context?.requestId) {
74
74
  headers["X-Request-ID"] = context.requestId;
75
75
  }
76
- const fetchOptions = {
77
- method,
78
- headers
79
- };
80
- if (method !== "GET" && data) {
81
- fetchOptions.body = useLegacyApi ? new URLSearchParams(data).toString() : JSON.stringify(data);
82
- }
83
76
  try {
84
- const response = await (0, import_cross_fetch.default)(url, fetchOptions);
85
- if (!response.ok) {
86
- const errorText = await response.text();
87
- throw {
88
- status: response.status,
89
- statusText: response.statusText,
90
- body: errorText
91
- };
92
- }
77
+ const response = await import_axios.default.request({
78
+ url,
79
+ method,
80
+ headers,
81
+ data: method !== "GET" && data ? useLegacyApi ? new URLSearchParams(data).toString() : data : void 0,
82
+ transformResponse: [(raw) => raw]
83
+ // evita parse automático para podermos tratar manual
84
+ });
93
85
  try {
94
- return await response.json();
86
+ return JSON.parse(response.data);
95
87
  } catch {
96
- return await response.text();
88
+ return response.data;
97
89
  }
98
- } catch (error) {
90
+ } catch (err) {
91
+ const error = err;
99
92
  let parsedBody = {};
100
- try {
101
- parsedBody = error.body ? JSON.parse(error.body) : {};
102
- } catch {
103
- parsedBody = { message: error.body || "Unknown error" };
93
+ if (error.response) {
94
+ try {
95
+ parsedBody = typeof error.response.data === "string" ? JSON.parse(error.response.data) : error.response.data;
96
+ } catch {
97
+ parsedBody = {
98
+ message: error.response.data?.message || error.response.statusText || "Unknown error"
99
+ };
100
+ }
101
+ throw {
102
+ message: parsedBody.message || "Unexpected error occurred",
103
+ status: error.response.status,
104
+ body: error.response.data,
105
+ original: error
106
+ };
104
107
  }
105
108
  throw {
106
- message: parsedBody.message || "Unexpected error occurred",
109
+ message: error.message || "Network error",
107
110
  original: error
108
111
  };
109
112
  }
@@ -782,20 +785,13 @@ var UserAPI = class {
782
785
  );
783
786
  return data.token;
784
787
  }
785
- async createUser(email, name, password, passwordConfirmation, profession, invitationCode) {
788
+ async createUser(create) {
786
789
  const endpointData = user_exports.Endpoints.CreateUser;
787
790
  const data = await this.clientHTTP.makeRequest(
788
791
  this.env,
789
792
  endpointData.uri,
790
793
  endpointData.method,
791
- {
792
- email,
793
- name,
794
- password,
795
- passwordConfirmation,
796
- profession,
797
- invitationCode
798
- },
794
+ create,
799
795
  null
800
796
  );
801
797
  return data;