shred-api-client 2.4.15 → 2.5.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/dist/index.js CHANGED
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  Project: () => project_exports,
41
41
  Prompt: () => prompt_exports,
42
42
  ShredAPI: () => ShredAPI,
43
+ SpecialOffer: () => special_offer_exports,
43
44
  Subscription: () => subscription_exports,
44
45
  Tenant: () => tenant_exports,
45
46
  Track: () => track_exports,
@@ -50,64 +51,115 @@ module.exports = __toCommonJS(index_exports);
50
51
 
51
52
  // src/util/HTTPClient.ts
52
53
  var import_cross_fetch = __toESM(require("cross-fetch"));
54
+
55
+ // src/model/exceptions/ShredException.ts
56
+ var ShredException = class extends Error {
57
+ constructor(message, status) {
58
+ super(message);
59
+ this.name = "ShredException";
60
+ this.status = status;
61
+ }
62
+ };
63
+
64
+ // src/model/exceptions/UnauthorizedException.ts
65
+ var UnauthorizedException = class extends ShredException {
66
+ constructor(message) {
67
+ super(message, 401);
68
+ this.name = "UnauthorizedException";
69
+ }
70
+ };
71
+
72
+ // src/model/exceptions/ForbiddenException.ts
73
+ var ForbiddenException = class extends ShredException {
74
+ constructor(message) {
75
+ super(message, 403);
76
+ this.name = "ForbiddenException";
77
+ }
78
+ };
79
+
80
+ // src/model/exceptions/ResourceNotFoundException.ts
81
+ var ResourceNotFoundException = class extends ShredException {
82
+ constructor(message) {
83
+ super(message, 404);
84
+ this.name = "ResourceNotFoundException";
85
+ }
86
+ };
87
+
88
+ // src/model/exceptions/ConflictException.ts
89
+ var ConflictException = class extends ShredException {
90
+ constructor(message) {
91
+ super(message, 409);
92
+ this.name = "ConflictException";
93
+ }
94
+ };
95
+
96
+ // src/model/exceptions/InvalidArgumentException.ts
97
+ var InvalidArgumentException = class extends ShredException {
98
+ constructor(message) {
99
+ super(message, 400);
100
+ this.name = "InvalidArgumentException";
101
+ }
102
+ };
103
+
104
+ // src/util/HTTPClient.ts
53
105
  var HOSTS = {
54
106
  prod: "https://api.shreditapp.com",
55
107
  staging: "https://api.staging.shreditapp.com",
56
108
  local: "https://api.staging.shreditapp.com"
57
109
  };
58
- var OLD_HOSTS = {
59
- prod: "https://api.shredmedia.co",
60
- staging: "https://api-staging.shredmedia.co",
61
- local: "https://api-staging.shredmedia.co"
62
- };
110
+ function toException(status, message) {
111
+ switch (status) {
112
+ case 400:
113
+ return new InvalidArgumentException(message);
114
+ case 401:
115
+ return new UnauthorizedException(message);
116
+ case 403:
117
+ return new ForbiddenException(message);
118
+ case 404:
119
+ return new ResourceNotFoundException(message);
120
+ case 409:
121
+ return new ConflictException(message);
122
+ default:
123
+ return new ShredException(message, status);
124
+ }
125
+ }
63
126
  var HTTPClient = class {
64
- async makeRequest(env, uri, method, data, context, useLegacyApi) {
65
- const hostDict = useLegacyApi ? OLD_HOSTS : HOSTS;
66
- const host = hostDict[env] || hostDict.staging;
127
+ async makeRequest(env, uri, method, data, context, schema) {
128
+ var _a, _b, _c;
129
+ const host = (_a = HOSTS[env]) != null ? _a : HOSTS.staging;
67
130
  const url = host + uri;
68
131
  const headers = {
69
- "Content-Type": useLegacyApi ? "application/x-www-form-urlencoded" : "application/json"
132
+ "Content-Type": "application/json"
70
133
  };
71
- if (context == null ? void 0 : context.token) {
72
- headers["Authorization"] = `Bearer ${context.token}`;
73
- }
74
- if (context == null ? void 0 : context.requestId) {
75
- headers["X-Request-ID"] = context.requestId;
76
- }
77
- const fetchOptions = {
78
- method,
79
- headers
80
- };
81
- if (method !== "GET" && data) {
82
- fetchOptions.body = useLegacyApi ? new URLSearchParams(data).toString() : JSON.stringify(data);
134
+ if (context == null ? void 0 : context.token) headers["Authorization"] = `Bearer ${context.token}`;
135
+ if (context == null ? void 0 : context.requestId) headers["X-Request-ID"] = context.requestId;
136
+ const fetchOptions = { method, headers };
137
+ if (method !== "GET" && data != null) {
138
+ fetchOptions.body = JSON.stringify(data);
83
139
  }
140
+ let response;
84
141
  try {
85
- const response = await (0, import_cross_fetch.default)(url, fetchOptions);
86
- if (!response.ok) {
87
- const errorText = await response.text();
88
- throw {
89
- status: response.status,
90
- statusText: response.statusText,
91
- body: errorText
92
- };
93
- }
94
- try {
95
- return await response.json();
96
- } catch {
97
- return await response.text();
98
- }
99
- } catch (error) {
100
- let parsedBody = {};
142
+ response = await (0, import_cross_fetch.default)(url, fetchOptions);
143
+ } catch (err) {
144
+ throw new ShredException((_b = err == null ? void 0 : err.message) != null ? _b : "Network error", 0);
145
+ }
146
+ if (!response.ok) {
147
+ let message = response.statusText;
101
148
  try {
102
- parsedBody = error.body ? JSON.parse(error.body) : {};
149
+ const body = await response.json();
150
+ message = (_c = body == null ? void 0 : body.message) != null ? _c : message;
103
151
  } catch {
104
- parsedBody = { message: error.body || "Unknown error" };
105
152
  }
106
- throw {
107
- message: parsedBody.message || "Unexpected error occurred",
108
- original: error
109
- };
153
+ throw toException(response.status, message);
110
154
  }
155
+ let result;
156
+ try {
157
+ result = await response.json();
158
+ } catch {
159
+ result = await response.text();
160
+ }
161
+ if (schema) return schema.parse(result);
162
+ return result;
111
163
  }
112
164
  };
113
165
 
@@ -4540,17 +4592,6 @@ var SubscriptionAPI = class {
4540
4592
  );
4541
4593
  return data;
4542
4594
  }
4543
- async getSpecialOffer(ctx) {
4544
- const endpointInfo = subscription_exports.Endpoints.GetSpecialOffer;
4545
- const data = await this.clientHTTP.makeRequest(
4546
- this.env,
4547
- endpointInfo.uri,
4548
- endpointInfo.method,
4549
- null,
4550
- ctx
4551
- );
4552
- return data;
4553
- }
4554
4595
  async getSubscription(context, userId) {
4555
4596
  const endpointInfo = subscription_exports.Endpoints.GetActiveSubscription;
4556
4597
  let uri = endpointInfo.uri;
@@ -5754,6 +5795,122 @@ var NoteAPI = class {
5754
5795
  };
5755
5796
  var Note_api_default = NoteAPI;
5756
5797
 
5798
+ // src/model/special-offer/SpecialOffer.api.ts
5799
+ var Endpoints7 = {
5800
+ List: {
5801
+ uri: "/special-offers/",
5802
+ method: "GET"
5803
+ },
5804
+ GetActive: {
5805
+ uri: "/special-offers/active",
5806
+ method: "GET"
5807
+ },
5808
+ Create: {
5809
+ uri: "/special-offers/",
5810
+ method: "POST"
5811
+ },
5812
+ Update: {
5813
+ uri: "/special-offers/:id",
5814
+ method: "PUT"
5815
+ },
5816
+ Enable: {
5817
+ uri: "/special-offers/:id/enable",
5818
+ method: "PUT"
5819
+ },
5820
+ Disable: {
5821
+ uri: "/special-offers/:id/disable",
5822
+ method: "PUT"
5823
+ },
5824
+ GetMyOffer: {
5825
+ uri: "/special-offers/my-offer",
5826
+ method: "GET"
5827
+ },
5828
+ Claim: {
5829
+ uri: "/special-offers/claim",
5830
+ method: "POST"
5831
+ }
5832
+ };
5833
+
5834
+ // src/model/special-offer/SpecialOffer.schema.ts
5835
+ var SpecialOfferSchema = external_exports.object({
5836
+ id: external_exports.string(),
5837
+ freeProjectsAllowed: external_exports.number(),
5838
+ windowHours: external_exports.number(),
5839
+ planId: external_exports.string(),
5840
+ couponId: external_exports.string(),
5841
+ title: external_exports.string(),
5842
+ description: external_exports.string(),
5843
+ ctaLabel: external_exports.string(),
5844
+ enabled: external_exports.boolean()
5845
+ });
5846
+ var UserOfferDetailsSchema = external_exports.object({
5847
+ offerId: external_exports.string(),
5848
+ expiresAt: external_exports.number(),
5849
+ title: external_exports.string(),
5850
+ description: external_exports.string(),
5851
+ ctaLabel: external_exports.string()
5852
+ });
5853
+ var CreateSpecialOfferSchema = external_exports.object({
5854
+ freeProjectsAllowed: external_exports.number().int().positive().optional(),
5855
+ windowHours: external_exports.number().int().positive(),
5856
+ planId: external_exports.string().min(1),
5857
+ couponId: external_exports.string().min(1),
5858
+ title: external_exports.string().min(1),
5859
+ description: external_exports.string().min(1),
5860
+ ctaLabel: external_exports.string().min(1)
5861
+ });
5862
+ var UpdateSpecialOfferSchema = external_exports.object({
5863
+ freeProjectsAllowed: external_exports.number().int().positive().optional(),
5864
+ windowHours: external_exports.number().int().positive().optional(),
5865
+ planId: external_exports.string().min(1).optional(),
5866
+ couponId: external_exports.string().min(1).optional(),
5867
+ title: external_exports.string().min(1).optional(),
5868
+ description: external_exports.string().min(1).optional(),
5869
+ ctaLabel: external_exports.string().min(1).optional()
5870
+ });
5871
+
5872
+ // src/api/SpecialOffer.api.ts
5873
+ var SpecialOfferAPI = class {
5874
+ constructor(env) {
5875
+ this.env = env;
5876
+ this.clientHTTP = new HTTPClient();
5877
+ }
5878
+ async list(ctx) {
5879
+ const { uri, method } = Endpoints7.List;
5880
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, external_exports.array(SpecialOfferSchema));
5881
+ }
5882
+ async getActive(ctx) {
5883
+ const { uri, method } = Endpoints7.GetActive;
5884
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, SpecialOfferSchema.nullable());
5885
+ }
5886
+ async create(ctx, data) {
5887
+ const { uri, method } = Endpoints7.Create;
5888
+ return this.clientHTTP.makeRequest(this.env, uri, method, data, ctx, SpecialOfferSchema);
5889
+ }
5890
+ async update(ctx, id, data) {
5891
+ const { uri, method } = Endpoints7.Update;
5892
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, data, ctx);
5893
+ }
5894
+ async enable(ctx, id) {
5895
+ const { uri, method } = Endpoints7.Enable;
5896
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, null, ctx);
5897
+ }
5898
+ async disable(ctx, id) {
5899
+ const { uri, method } = Endpoints7.Disable;
5900
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, null, ctx);
5901
+ }
5902
+ async getMyOffer(ctx) {
5903
+ const { uri, method } = Endpoints7.GetMyOffer;
5904
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, UserOfferDetailsSchema.nullable());
5905
+ }
5906
+ async claim(ctx, callbackUrl) {
5907
+ const { uri, method } = Endpoints7.Claim;
5908
+ const data = await this.clientHTTP.makeRequest(this.env, uri, method, { callbackUrl }, ctx);
5909
+ return data.url;
5910
+ }
5911
+ };
5912
+ var SpecialOffer_api_default = SpecialOfferAPI;
5913
+
5757
5914
  // src/model/Api.ts
5758
5915
  var ShredAPI = class {
5759
5916
  constructor(env) {
@@ -5768,80 +5925,26 @@ var ShredAPI = class {
5768
5925
  this.app = new AppConfig_api_default(env);
5769
5926
  this.track = new Track_api_default(env);
5770
5927
  this.note = new Note_api_default(env);
5928
+ this.specialOffer = new SpecialOffer_api_default(env);
5771
5929
  }
5772
5930
  };
5773
5931
 
5774
5932
  // src/model/exceptions/index.ts
5775
5933
  var exceptions_exports = {};
5776
5934
  __export(exceptions_exports, {
5777
- default: () => exceptions_default
5935
+ ConflictException: () => ConflictException,
5936
+ ForbiddenException: () => ForbiddenException,
5937
+ InvalidArgumentException: () => InvalidArgumentException,
5938
+ ResourceNotFoundException: () => ResourceNotFoundException,
5939
+ ShredException: () => ShredException,
5940
+ UnauthorizedException: () => UnauthorizedException
5778
5941
  });
5779
5942
 
5780
- // src/model/exceptions/ShredException.ts
5781
- var ShredException = class extends Error {
5782
- constructor(message, status) {
5783
- super(message);
5784
- this.name = "ShredException";
5785
- this.status = status;
5786
- }
5787
- };
5788
-
5789
- // src/model/exceptions/ConflictException.ts
5790
- var ConflictException = class extends ShredException {
5791
- constructor(message) {
5792
- super(message, 409);
5793
- this.name = "ConflictException";
5794
- }
5795
- };
5796
-
5797
- // src/model/exceptions/InvalidArgumentException.ts
5798
- var InvalidArgumentException = class extends ShredException {
5799
- constructor(message) {
5800
- super(message, 400);
5801
- this.name = "InvalidArgumentException";
5802
- }
5803
- };
5804
-
5805
- // src/model/exceptions/ResourceNotFoundException.ts
5806
- var ResourceNotFoundException = class extends ShredException {
5807
- constructor(message) {
5808
- super(message, 404);
5809
- this.name = "ResourceNotFoundException";
5810
- }
5811
- };
5812
-
5813
- // src/model/exceptions/UnauthorizedException.ts
5814
- var UnauthorizedException = class extends ShredException {
5815
- constructor(message) {
5816
- super(message, 401);
5817
- this.name = "UnauthorizedException";
5818
- }
5819
- };
5820
-
5821
- // src/model/exceptions/ForbiddenException.ts
5822
- var ForbiddenException = class extends ShredException {
5823
- constructor(message) {
5824
- super(message, 403);
5825
- this.name = "ForbiddenException";
5826
- }
5827
- };
5828
-
5829
- // src/model/exceptions/index.ts
5830
- var Exceptions = {
5831
- ConflictException,
5832
- InvalidArgumentException,
5833
- ResourceNotFoundException,
5834
- ShredException,
5835
- UnauthorizedException,
5836
- ForbiddenException
5837
- };
5838
- var exceptions_default = Exceptions;
5839
-
5840
5943
  // src/model/prompt/index.ts
5841
5944
  var prompt_exports = {};
5842
5945
  __export(prompt_exports, {
5843
5946
  CategorySchema: () => CategorySchema,
5844
- Endpoints: () => Endpoints7,
5947
+ Endpoints: () => Endpoints8,
5845
5948
  PromptSchema: () => PromptSchema,
5846
5949
  ScriptIARequestSchema: () => ScriptIARequestSchema,
5847
5950
  ScriptSchema: () => ScriptSchema
@@ -5877,7 +5980,7 @@ var PromptSchema = external_exports.object({
5877
5980
  });
5878
5981
 
5879
5982
  // src/model/prompt/Prompt.api.ts
5880
- var Endpoints7 = {
5983
+ var Endpoints8 = {
5881
5984
  GetPrompt: {
5882
5985
  uri: "/prompts/getPrompt",
5883
5986
  method: "GET"
@@ -5908,7 +6011,7 @@ var Endpoints7 = {
5908
6011
  var tenant_exports = {};
5909
6012
  __export(tenant_exports, {
5910
6013
  Action: () => Action,
5911
- Endpoints: () => Endpoints8,
6014
+ Endpoints: () => Endpoints9,
5912
6015
  MemberSchema: () => MemberSchema,
5913
6016
  PreferencesSchema: () => PreferencesSchema,
5914
6017
  ReportViewerUpdateSchema: () => ReportViewerUpdateSchema,
@@ -5930,16 +6033,6 @@ var PlanSchema = external_exports.object({
5930
6033
  metadata: external_exports.record(external_exports.string(), external_exports.string()),
5931
6034
  subscriptionItemId: external_exports.string()
5932
6035
  });
5933
- var SpecialOfferSchema = external_exports.object({
5934
- id: external_exports.string(),
5935
- freeProjectsAllowed: external_exports.number().default(15),
5936
- windowHours: external_exports.number(),
5937
- couponId: external_exports.string(),
5938
- title: external_exports.string(),
5939
- description: external_exports.string(),
5940
- ctaLabel: external_exports.string(),
5941
- enabled: external_exports.boolean().default(true)
5942
- });
5943
6036
  var DescriptionSchema = external_exports.object({
5944
6037
  description: external_exports.string(),
5945
6038
  subtitle: external_exports.string()
@@ -6032,7 +6125,7 @@ var ReportViewerUpdateSchema = external_exports.object({
6032
6125
  });
6033
6126
 
6034
6127
  // src/model/tenant/Tenant.api.ts
6035
- var Endpoints8 = {
6128
+ var Endpoints9 = {
6036
6129
  GetByInviteCode: {
6037
6130
  uri: "/tenants/public/invitation/",
6038
6131
  method: "GET"
@@ -6070,7 +6163,7 @@ var Endpoints8 = {
6070
6163
  // src/model/user/index.ts
6071
6164
  var user_exports = {};
6072
6165
  __export(user_exports, {
6073
- Endpoints: () => Endpoints9,
6166
+ Endpoints: () => Endpoints10,
6074
6167
  PreferencesSchema: () => PreferencesSchema2,
6075
6168
  Role: () => Role,
6076
6169
  System: () => System,
@@ -6125,7 +6218,7 @@ var UserSchema = external_exports.object({
6125
6218
  });
6126
6219
 
6127
6220
  // src/model/user/User.api.ts
6128
- var Endpoints9 = {
6221
+ var Endpoints10 = {
6129
6222
  ChangeEmail: { uri: "/accounts/user/changeEmail", method: "PUT" },
6130
6223
  GetUserInfo: { uri: "/accounts/user/info", method: "GET" },
6131
6224
  GetBindedUsers: { uri: "/accounts/binded/list", method: "GET" },
@@ -6148,7 +6241,7 @@ var Endpoints9 = {
6148
6241
  var subscription_exports = {};
6149
6242
  __export(subscription_exports, {
6150
6243
  ChargeSchema: () => ChargeSchema,
6151
- Endpoints: () => Endpoints10,
6244
+ Endpoints: () => Endpoints11,
6152
6245
  PlanSchema: () => PlanSchema,
6153
6246
  ProductSchema: () => ProductSchema,
6154
6247
  SubscriptionSchema: () => SubscriptionSchema,
@@ -6157,7 +6250,7 @@ __export(subscription_exports, {
6157
6250
  });
6158
6251
 
6159
6252
  // src/model/subscription/Subscription.api.ts
6160
- var Endpoints10 = {
6253
+ var Endpoints11 = {
6161
6254
  GetPortal: {
6162
6255
  uri: "/subscriptions/portal/",
6163
6256
  method: "GET"
@@ -6170,10 +6263,6 @@ var Endpoints10 = {
6170
6263
  uri: "/subscriptions/active/",
6171
6264
  method: "GET"
6172
6265
  },
6173
- GetSpecialOffer: {
6174
- uri: "/subscriptions/specialOffer/",
6175
- method: "GET"
6176
- },
6177
6266
  GetCharges: {
6178
6267
  uri: "/subscriptions/payment/charge/list/",
6179
6268
  method: "GET"
@@ -6219,7 +6308,7 @@ var Endpoints10 = {
6219
6308
  // src/model/track/index.ts
6220
6309
  var track_exports = {};
6221
6310
  __export(track_exports, {
6222
- Endpoints: () => Endpoints11,
6311
+ Endpoints: () => Endpoints12,
6223
6312
  TrackParamSchema: () => TrackParamSchema,
6224
6313
  TrackSchema: () => TrackSchema
6225
6314
  });
@@ -6237,7 +6326,7 @@ var TrackSchema = external_exports.object({
6237
6326
  });
6238
6327
 
6239
6328
  // src/model/track/Track.api.ts
6240
- var Endpoints11 = {
6329
+ var Endpoints12 = {
6241
6330
  Track: {
6242
6331
  uri: "/track/public/send/",
6243
6332
  method: "POST"
@@ -6247,6 +6336,16 @@ var Endpoints11 = {
6247
6336
  // src/model/core/index.ts
6248
6337
  var core_exports = {};
6249
6338
 
6339
+ // src/model/special-offer/index.ts
6340
+ var special_offer_exports = {};
6341
+ __export(special_offer_exports, {
6342
+ CreateSpecialOfferSchema: () => CreateSpecialOfferSchema,
6343
+ Endpoints: () => Endpoints7,
6344
+ SpecialOfferSchema: () => SpecialOfferSchema,
6345
+ UpdateSpecialOfferSchema: () => UpdateSpecialOfferSchema,
6346
+ UserOfferDetailsSchema: () => UserOfferDetailsSchema
6347
+ });
6348
+
6250
6349
  // src/index.ts
6251
6350
  var index_default = ShredAPI;
6252
6351
  //# sourceMappingURL=index.js.map