shred-api-client 2.4.14 → 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"
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;
@@ -4720,6 +4761,19 @@ var TenantAPI = class {
4720
4761
  );
4721
4762
  return data;
4722
4763
  }
4764
+ async updateReportViewers(tenantId, reportViewerUpdate, context) {
4765
+ const endpointInfo = tenant_exports.Endpoints.UpdateReportViewers;
4766
+ const endpointData = tenant_exports.Endpoints.UpdateReportViewers;
4767
+ const endpoint = endpointData.uri.replace(":tenantId", tenantId);
4768
+ const data = await this.clientHTTP.makeRequest(
4769
+ this.env,
4770
+ `${endpoint}`,
4771
+ endpointInfo.method,
4772
+ { data: reportViewerUpdate, context },
4773
+ context
4774
+ );
4775
+ return data;
4776
+ }
4723
4777
  };
4724
4778
  var Tenant_api_default = TenantAPI;
4725
4779
 
@@ -5741,6 +5795,86 @@ var NoteAPI = class {
5741
5795
  };
5742
5796
  var Note_api_default = NoteAPI;
5743
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
+
5744
5878
  // src/model/Api.ts
5745
5879
  var ShredAPI = class {
5746
5880
  constructor(env) {
@@ -5755,75 +5889,21 @@ var ShredAPI = class {
5755
5889
  this.app = new AppConfig_api_default(env);
5756
5890
  this.track = new Track_api_default(env);
5757
5891
  this.note = new Note_api_default(env);
5892
+ this.specialOffer = new SpecialOffer_api_default(env);
5758
5893
  }
5759
5894
  };
5760
5895
 
5761
5896
  // src/model/exceptions/index.ts
5762
5897
  var exceptions_exports = {};
5763
5898
  __export(exceptions_exports, {
5764
- default: () => exceptions_default
5899
+ ConflictException: () => ConflictException,
5900
+ ForbiddenException: () => ForbiddenException,
5901
+ InvalidArgumentException: () => InvalidArgumentException,
5902
+ ResourceNotFoundException: () => ResourceNotFoundException,
5903
+ ShredException: () => ShredException,
5904
+ UnauthorizedException: () => UnauthorizedException
5765
5905
  });
5766
5906
 
5767
- // src/model/exceptions/ShredException.ts
5768
- var ShredException = class extends Error {
5769
- constructor(message, status) {
5770
- super(message);
5771
- this.name = "ShredException";
5772
- this.status = status;
5773
- }
5774
- };
5775
-
5776
- // src/model/exceptions/ConflictException.ts
5777
- var ConflictException = class extends ShredException {
5778
- constructor(message) {
5779
- super(message, 409);
5780
- this.name = "ConflictException";
5781
- }
5782
- };
5783
-
5784
- // src/model/exceptions/InvalidArgumentException.ts
5785
- var InvalidArgumentException = class extends ShredException {
5786
- constructor(message) {
5787
- super(message, 400);
5788
- this.name = "InvalidArgumentException";
5789
- }
5790
- };
5791
-
5792
- // src/model/exceptions/ResourceNotFoundException.ts
5793
- var ResourceNotFoundException = class extends ShredException {
5794
- constructor(message) {
5795
- super(message, 404);
5796
- this.name = "ResourceNotFoundException";
5797
- }
5798
- };
5799
-
5800
- // src/model/exceptions/UnauthorizedException.ts
5801
- var UnauthorizedException = class extends ShredException {
5802
- constructor(message) {
5803
- super(message, 401);
5804
- this.name = "UnauthorizedException";
5805
- }
5806
- };
5807
-
5808
- // src/model/exceptions/ForbiddenException.ts
5809
- var ForbiddenException = class extends ShredException {
5810
- constructor(message) {
5811
- super(message, 403);
5812
- this.name = "ForbiddenException";
5813
- }
5814
- };
5815
-
5816
- // src/model/exceptions/index.ts
5817
- var Exceptions = {
5818
- ConflictException,
5819
- InvalidArgumentException,
5820
- ResourceNotFoundException,
5821
- ShredException,
5822
- UnauthorizedException,
5823
- ForbiddenException
5824
- };
5825
- var exceptions_default = Exceptions;
5826
-
5827
5907
  // src/model/prompt/index.ts
5828
5908
  var prompt_exports = {};
5829
5909
  __export(prompt_exports, {
@@ -5894,9 +5974,11 @@ var Endpoints7 = {
5894
5974
  // src/model/tenant/index.ts
5895
5975
  var tenant_exports = {};
5896
5976
  __export(tenant_exports, {
5977
+ Action: () => Action,
5897
5978
  Endpoints: () => Endpoints8,
5898
5979
  MemberSchema: () => MemberSchema,
5899
5980
  PreferencesSchema: () => PreferencesSchema,
5981
+ ReportViewerUpdateSchema: () => ReportViewerUpdateSchema,
5900
5982
  TenantSchema: () => TenantSchema
5901
5983
  });
5902
5984
 
@@ -5915,16 +5997,6 @@ var PlanSchema = external_exports.object({
5915
5997
  metadata: external_exports.record(external_exports.string(), external_exports.string()),
5916
5998
  subscriptionItemId: external_exports.string()
5917
5999
  });
5918
- var SpecialOfferSchema = external_exports.object({
5919
- id: external_exports.string(),
5920
- freeProjectsAllowed: external_exports.number().default(15),
5921
- windowHours: external_exports.number(),
5922
- couponId: external_exports.string(),
5923
- title: external_exports.string(),
5924
- description: external_exports.string(),
5925
- ctaLabel: external_exports.string(),
5926
- enabled: external_exports.boolean().default(true)
5927
- });
5928
6000
  var DescriptionSchema = external_exports.object({
5929
6001
  description: external_exports.string(),
5930
6002
  subtitle: external_exports.string()
@@ -5996,7 +6068,9 @@ var TenantSchema = external_exports.object({
5996
6068
  useOwnScripts: external_exports.boolean().optional(),
5997
6069
  subscription: external_exports.optional(external_exports.lazy(() => SubscriptionSchema)),
5998
6070
  totalSubscriptions: external_exports.number().optional(),
5999
- totalUsers: external_exports.number().optional()
6071
+ totalUsers: external_exports.number().optional(),
6072
+ reportUrl: external_exports.string().optional(),
6073
+ reportViewers: external_exports.array(external_exports.string()).optional()
6000
6074
  });
6001
6075
  var MemberSchema = external_exports.object({
6002
6076
  name: external_exports.string(),
@@ -6004,6 +6078,15 @@ var MemberSchema = external_exports.object({
6004
6078
  pictureUrl: external_exports.string(),
6005
6079
  isActive: external_exports.boolean()
6006
6080
  });
6081
+ var Action = /* @__PURE__ */ ((Action2) => {
6082
+ Action2["ADD"] = "add";
6083
+ Action2["REMOVE"] = "remove";
6084
+ return Action2;
6085
+ })(Action || {});
6086
+ var ReportViewerUpdateSchema = external_exports.object({
6087
+ userId: external_exports.string(),
6088
+ action: external_exports.nativeEnum(Action)
6089
+ });
6007
6090
 
6008
6091
  // src/model/tenant/Tenant.api.ts
6009
6092
  var Endpoints8 = {
@@ -6034,6 +6117,10 @@ var Endpoints8 = {
6034
6117
  Members: {
6035
6118
  uri: "/tenants/:tenantId/members",
6036
6119
  method: "GET"
6120
+ },
6121
+ UpdateReportViewers: {
6122
+ uri: "/tenants/:tenantId/report-viewers",
6123
+ method: "PUT"
6037
6124
  }
6038
6125
  };
6039
6126
 
@@ -6140,10 +6227,6 @@ var Endpoints10 = {
6140
6227
  uri: "/subscriptions/active/",
6141
6228
  method: "GET"
6142
6229
  },
6143
- GetSpecialOffer: {
6144
- uri: "/subscriptions/specialOffer/",
6145
- method: "GET"
6146
- },
6147
6230
  GetCharges: {
6148
6231
  uri: "/subscriptions/payment/charge/list/",
6149
6232
  method: "GET"
@@ -6217,6 +6300,52 @@ var Endpoints11 = {
6217
6300
  // src/model/core/index.ts
6218
6301
  var core_exports = {};
6219
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
+
6220
6349
  // src/index.ts
6221
6350
  var index_default = ShredAPI;
6222
6351
  //# sourceMappingURL=index.js.map