shred-api-client 2.4.15 → 2.5.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.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"
70
- };
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
132
+ "Content-Type": "application/json"
80
133
  };
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,86 @@ var NoteAPI = class {
5754
5795
  };
5755
5796
  var Note_api_default = NoteAPI;
5756
5797
 
5798
+ // src/model/special-offer/SpecialOffer.schema.ts
5799
+ var SpecialOfferSchema = external_exports.object({
5800
+ id: external_exports.string(),
5801
+ freeProjectsAllowed: external_exports.number(),
5802
+ windowHours: external_exports.number(),
5803
+ planId: external_exports.string(),
5804
+ couponId: external_exports.string(),
5805
+ title: external_exports.string(),
5806
+ description: external_exports.string(),
5807
+ ctaLabel: external_exports.string(),
5808
+ enabled: external_exports.boolean()
5809
+ });
5810
+ var UserOfferDetailsSchema = external_exports.object({
5811
+ offerId: external_exports.string(),
5812
+ expiresAt: external_exports.number(),
5813
+ title: external_exports.string(),
5814
+ description: external_exports.string(),
5815
+ ctaLabel: external_exports.string()
5816
+ });
5817
+ var CreateSpecialOfferSchema = external_exports.object({
5818
+ freeProjectsAllowed: external_exports.number().int().positive().optional(),
5819
+ windowHours: external_exports.number().int().positive(),
5820
+ planId: external_exports.string().min(1),
5821
+ couponId: external_exports.string().min(1),
5822
+ title: external_exports.string().min(1),
5823
+ description: external_exports.string().min(1),
5824
+ ctaLabel: external_exports.string().min(1)
5825
+ });
5826
+ var UpdateSpecialOfferSchema = external_exports.object({
5827
+ freeProjectsAllowed: external_exports.number().int().positive().optional(),
5828
+ windowHours: external_exports.number().int().positive().optional(),
5829
+ planId: external_exports.string().min(1).optional(),
5830
+ couponId: external_exports.string().min(1).optional(),
5831
+ title: external_exports.string().min(1).optional(),
5832
+ description: external_exports.string().min(1).optional(),
5833
+ ctaLabel: external_exports.string().min(1).optional()
5834
+ });
5835
+
5836
+ // src/api/SpecialOffer.api.ts
5837
+ var SpecialOfferAPI = class {
5838
+ constructor(env) {
5839
+ this.env = env;
5840
+ this.clientHTTP = new HTTPClient();
5841
+ }
5842
+ async list(ctx) {
5843
+ const { uri, method } = special_offer_exports.Endpoints.List;
5844
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, external_exports.array(SpecialOfferSchema));
5845
+ }
5846
+ async getActive(ctx) {
5847
+ const { uri, method } = special_offer_exports.Endpoints.GetActive;
5848
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, SpecialOfferSchema.nullable());
5849
+ }
5850
+ async create(ctx, data) {
5851
+ const { uri, method } = special_offer_exports.Endpoints.Create;
5852
+ return this.clientHTTP.makeRequest(this.env, uri, method, data, ctx, SpecialOfferSchema);
5853
+ }
5854
+ async update(ctx, id, data) {
5855
+ const { uri, method } = special_offer_exports.Endpoints.Update;
5856
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, data, ctx);
5857
+ }
5858
+ async enable(ctx, id) {
5859
+ const { uri, method } = special_offer_exports.Endpoints.Enable;
5860
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, null, ctx);
5861
+ }
5862
+ async disable(ctx, id) {
5863
+ const { uri, method } = special_offer_exports.Endpoints.Disable;
5864
+ await this.clientHTTP.makeRequest(this.env, uri.replace(":id", id), method, null, ctx);
5865
+ }
5866
+ async getMyOffer(ctx) {
5867
+ const { uri, method } = special_offer_exports.Endpoints.GetMyOffer;
5868
+ return this.clientHTTP.makeRequest(this.env, uri, method, null, ctx, UserOfferDetailsSchema.nullable());
5869
+ }
5870
+ async claim(ctx, callbackUrl) {
5871
+ const { uri, method } = special_offer_exports.Endpoints.Claim;
5872
+ const data = await this.clientHTTP.makeRequest(this.env, uri, method, { callbackUrl }, ctx);
5873
+ return data.url;
5874
+ }
5875
+ };
5876
+ var SpecialOffer_api_default = SpecialOfferAPI;
5877
+
5757
5878
  // src/model/Api.ts
5758
5879
  var ShredAPI = class {
5759
5880
  constructor(env) {
@@ -5768,75 +5889,21 @@ var ShredAPI = class {
5768
5889
  this.app = new AppConfig_api_default(env);
5769
5890
  this.track = new Track_api_default(env);
5770
5891
  this.note = new Note_api_default(env);
5892
+ this.specialOffer = new SpecialOffer_api_default(env);
5771
5893
  }
5772
5894
  };
5773
5895
 
5774
5896
  // src/model/exceptions/index.ts
5775
5897
  var exceptions_exports = {};
5776
5898
  __export(exceptions_exports, {
5777
- default: () => exceptions_default
5899
+ ConflictException: () => ConflictException,
5900
+ ForbiddenException: () => ForbiddenException,
5901
+ InvalidArgumentException: () => InvalidArgumentException,
5902
+ ResourceNotFoundException: () => ResourceNotFoundException,
5903
+ ShredException: () => ShredException,
5904
+ UnauthorizedException: () => UnauthorizedException
5778
5905
  });
5779
5906
 
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
5907
  // src/model/prompt/index.ts
5841
5908
  var prompt_exports = {};
5842
5909
  __export(prompt_exports, {
@@ -5930,16 +5997,6 @@ var PlanSchema = external_exports.object({
5930
5997
  metadata: external_exports.record(external_exports.string(), external_exports.string()),
5931
5998
  subscriptionItemId: external_exports.string()
5932
5999
  });
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
6000
  var DescriptionSchema = external_exports.object({
5944
6001
  description: external_exports.string(),
5945
6002
  subtitle: external_exports.string()
@@ -6170,10 +6227,6 @@ var Endpoints10 = {
6170
6227
  uri: "/subscriptions/active/",
6171
6228
  method: "GET"
6172
6229
  },
6173
- GetSpecialOffer: {
6174
- uri: "/subscriptions/specialOffer/",
6175
- method: "GET"
6176
- },
6177
6230
  GetCharges: {
6178
6231
  uri: "/subscriptions/payment/charge/list/",
6179
6232
  method: "GET"
@@ -6247,6 +6300,52 @@ var Endpoints11 = {
6247
6300
  // src/model/core/index.ts
6248
6301
  var core_exports = {};
6249
6302
 
6303
+ // src/model/special-offer/index.ts
6304
+ var special_offer_exports = {};
6305
+ __export(special_offer_exports, {
6306
+ CreateSpecialOfferSchema: () => CreateSpecialOfferSchema,
6307
+ Endpoints: () => Endpoints12,
6308
+ SpecialOfferSchema: () => SpecialOfferSchema,
6309
+ UpdateSpecialOfferSchema: () => UpdateSpecialOfferSchema,
6310
+ UserOfferDetailsSchema: () => UserOfferDetailsSchema
6311
+ });
6312
+
6313
+ // src/model/special-offer/SpecialOffer.api.ts
6314
+ var Endpoints12 = {
6315
+ List: {
6316
+ uri: "/special-offers/",
6317
+ method: "GET"
6318
+ },
6319
+ GetActive: {
6320
+ uri: "/special-offers/active",
6321
+ method: "GET"
6322
+ },
6323
+ Create: {
6324
+ uri: "/special-offers/",
6325
+ method: "POST"
6326
+ },
6327
+ Update: {
6328
+ uri: "/special-offers/:id",
6329
+ method: "PUT"
6330
+ },
6331
+ Enable: {
6332
+ uri: "/special-offers/:id/enable",
6333
+ method: "PUT"
6334
+ },
6335
+ Disable: {
6336
+ uri: "/special-offers/:id/disable",
6337
+ method: "PUT"
6338
+ },
6339
+ GetMyOffer: {
6340
+ uri: "/special-offers/my-offer",
6341
+ method: "GET"
6342
+ },
6343
+ Claim: {
6344
+ uri: "/special-offers/claim",
6345
+ method: "POST"
6346
+ }
6347
+ };
6348
+
6250
6349
  // src/index.ts
6251
6350
  var index_default = ShredAPI;
6252
6351
  //# sourceMappingURL=index.js.map