@gpt-core/client 0.7.21 → 0.7.23

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
@@ -45,6 +45,9 @@ __export(index_exports, {
45
45
  ThreadCreateSchema: () => ThreadCreateSchema,
46
46
  TimeoutError: () => TimeoutError,
47
47
  ValidationError: () => ValidationError,
48
+ WebhookConfigCreateSchema: () => WebhookConfigCreateSchema,
49
+ WebhookConfigUpdateSchema: () => WebhookConfigUpdateSchema,
50
+ WebhookError: () => WebhookError,
48
51
  WorkspaceCreateSchema: () => WorkspaceCreateSchema,
49
52
  calculateBackoff: () => calculateBackoff,
50
53
  client: () => client,
@@ -315,6 +318,7 @@ __export(index_exports, {
315
318
  sleep: () => sleep,
316
319
  streamMessage: () => streamMessage,
317
320
  streamSSE: () => streamSSE,
321
+ webhooks: () => webhooks,
318
322
  withRetry: () => withRetry
319
323
  });
320
324
  module.exports = __toCommonJS(index_exports);
@@ -3909,6 +3913,28 @@ var PresignedUploadSchema = import_zod.z.object({
3909
3913
  var PresignedDownloadSchema = import_zod.z.object({
3910
3914
  file_id: import_zod.z.string().uuid()
3911
3915
  });
3916
+ var WebhookConfigCreateSchema = import_zod.z.object({
3917
+ name: import_zod.z.string().min(1).max(255),
3918
+ url: import_zod.z.string().url(),
3919
+ events: import_zod.z.array(import_zod.z.string()).optional(),
3920
+ enabled: import_zod.z.boolean().optional().default(true),
3921
+ secret: import_zod.z.string().optional(),
3922
+ // Tenant-level webhook: set tenant_id to scope to a specific tenant
3923
+ tenant_id: import_zod.z.string().uuid().optional(),
3924
+ // ISV filter: specific tenant UUIDs to receive events from (null = all)
3925
+ tenant_ids: import_zod.z.array(import_zod.z.string().uuid()).optional(),
3926
+ // Tenant filter: specific workspace UUIDs to receive events from (null = all)
3927
+ workspace_ids: import_zod.z.array(import_zod.z.string().uuid()).optional()
3928
+ });
3929
+ var WebhookConfigUpdateSchema = import_zod.z.object({
3930
+ name: import_zod.z.string().min(1).max(255).optional(),
3931
+ url: import_zod.z.string().url().optional(),
3932
+ events: import_zod.z.array(import_zod.z.string()).optional(),
3933
+ enabled: import_zod.z.boolean().optional(),
3934
+ secret: import_zod.z.string().optional(),
3935
+ tenant_ids: import_zod.z.array(import_zod.z.string().uuid()).optional(),
3936
+ workspace_ids: import_zod.z.array(import_zod.z.string().uuid()).optional()
3937
+ });
3912
3938
 
3913
3939
  // src/utils/retry.ts
3914
3940
  var DEFAULT_RETRY_CONFIG = {
@@ -4060,10 +4086,207 @@ async function collectStreamedMessage(stream) {
4060
4086
  return fullMessage;
4061
4087
  }
4062
4088
 
4089
+ // src/webhooks.ts
4090
+ var WebhookError = class extends Error {
4091
+ constructor(message, status, errors) {
4092
+ super(message);
4093
+ this.status = status;
4094
+ this.errors = errors;
4095
+ this.name = "WebhookError";
4096
+ }
4097
+ };
4098
+ function unwrap(data) {
4099
+ if (data && typeof data === "object" && "attributes" in data) {
4100
+ const obj = data;
4101
+ return { id: obj.id, ...obj.attributes };
4102
+ }
4103
+ return data;
4104
+ }
4105
+ function handleError(error) {
4106
+ if (error && typeof error === "object") {
4107
+ const err = error;
4108
+ throw new WebhookError(
4109
+ err.detail || "Webhook operation failed",
4110
+ err.status,
4111
+ err.errors
4112
+ );
4113
+ }
4114
+ throw new WebhookError("Unknown error");
4115
+ }
4116
+ function processResult(result) {
4117
+ const r = result;
4118
+ if (r.error) handleError(r.error);
4119
+ return r.data?.data;
4120
+ }
4121
+ function processArrayResult(result) {
4122
+ const r = result;
4123
+ if (r.error) handleError(r.error);
4124
+ return (r.data?.data || []).map((d) => unwrap(d));
4125
+ }
4126
+ var webhooks = {
4127
+ /**
4128
+ * List all webhook configurations accessible to the current user.
4129
+ *
4130
+ * For tenant users, this returns webhooks scoped to their tenant.
4131
+ * For ISV/app owners, this returns application-level webhooks.
4132
+ */
4133
+ async list(options) {
4134
+ const result = await getWebhookConfigs({
4135
+ headers: { "x-application-key": "" },
4136
+ query: options?.filter
4137
+ });
4138
+ return processArrayResult(result);
4139
+ },
4140
+ /**
4141
+ * Get a single webhook configuration by ID.
4142
+ */
4143
+ async get(id) {
4144
+ const result = await getWebhookConfigsById({
4145
+ headers: { "x-application-key": "" },
4146
+ path: { id }
4147
+ });
4148
+ return unwrap(processResult(result));
4149
+ },
4150
+ /**
4151
+ * Create a new webhook configuration.
4152
+ *
4153
+ * For tenant-level webhooks, include `tenant_id` in the attributes.
4154
+ * The tenant_id is typically obtained from the user's profile.
4155
+ *
4156
+ * @example
4157
+ * ```typescript
4158
+ * // Tenant-level webhook (receives only this tenant's events)
4159
+ * const webhook = await webhooks.create({
4160
+ * name: 'My Webhook',
4161
+ * url: 'https://example.com/webhook',
4162
+ * events: ['extraction.completed', 'document.processed'],
4163
+ * tenant_id: userProfile.tenant_id,
4164
+ * });
4165
+ *
4166
+ * // With workspace filtering (only events from specific workspaces)
4167
+ * const webhook = await webhooks.create({
4168
+ * name: 'Workspace Webhook',
4169
+ * url: 'https://example.com/webhook',
4170
+ * tenant_id: userProfile.tenant_id,
4171
+ * workspace_ids: ['workspace-uuid-1', 'workspace-uuid-2'],
4172
+ * });
4173
+ * ```
4174
+ */
4175
+ async create(attributes) {
4176
+ const validated = WebhookConfigCreateSchema.parse(attributes);
4177
+ const result = await postWebhookConfigs({
4178
+ headers: { "x-application-key": "" },
4179
+ body: {
4180
+ data: {
4181
+ type: "webhook_config",
4182
+ attributes: validated
4183
+ }
4184
+ }
4185
+ });
4186
+ return unwrap(processResult(result));
4187
+ },
4188
+ /**
4189
+ * Update an existing webhook configuration.
4190
+ */
4191
+ async update(id, attributes) {
4192
+ const validated = WebhookConfigUpdateSchema.parse(attributes);
4193
+ const result = await patchWebhookConfigsById({
4194
+ headers: { "x-application-key": "" },
4195
+ path: { id },
4196
+ body: {
4197
+ data: {
4198
+ type: "webhook_config",
4199
+ id,
4200
+ attributes: validated
4201
+ }
4202
+ }
4203
+ });
4204
+ return unwrap(processResult(result));
4205
+ },
4206
+ /**
4207
+ * Delete a webhook configuration.
4208
+ */
4209
+ async delete(id) {
4210
+ const result = await deleteWebhookConfigsById({
4211
+ headers: { "x-application-key": "" },
4212
+ path: { id }
4213
+ });
4214
+ const r = result;
4215
+ if (r.error) handleError(r.error);
4216
+ },
4217
+ /**
4218
+ * Send a test webhook to verify the endpoint is reachable.
4219
+ *
4220
+ * This enqueues a test webhook delivery with a sample payload.
4221
+ * Check the deliveries list to see the result.
4222
+ */
4223
+ async test(id) {
4224
+ const result = await postWebhookConfigsByIdTest({
4225
+ headers: { "x-application-key": "" },
4226
+ path: { id }
4227
+ });
4228
+ return unwrap(processResult(result));
4229
+ },
4230
+ /**
4231
+ * Rotate the webhook secret.
4232
+ *
4233
+ * This generates a new secret for the webhook. The old secret
4234
+ * becomes invalid immediately. Make sure to update your endpoint
4235
+ * with the new secret.
4236
+ */
4237
+ async rotateSecret(id) {
4238
+ const result = await patchWebhookConfigsByIdRotateSecret({
4239
+ headers: { "x-application-key": "" },
4240
+ path: { id }
4241
+ });
4242
+ return unwrap(processResult(result));
4243
+ },
4244
+ /**
4245
+ * Webhook delivery management
4246
+ */
4247
+ deliveries: {
4248
+ /**
4249
+ * List webhook deliveries.
4250
+ *
4251
+ * Deliveries are sorted by newest first by default.
4252
+ */
4253
+ async list(options) {
4254
+ const result = await getWebhookDeliveries({
4255
+ headers: { "x-application-key": "" },
4256
+ query: options?.filter
4257
+ });
4258
+ return processArrayResult(result);
4259
+ },
4260
+ /**
4261
+ * Get a single webhook delivery by ID.
4262
+ */
4263
+ async get(id) {
4264
+ const result = await getWebhookDeliveriesById({
4265
+ headers: { "x-application-key": "" },
4266
+ path: { id }
4267
+ });
4268
+ return unwrap(processResult(result));
4269
+ },
4270
+ /**
4271
+ * Retry a failed webhook delivery.
4272
+ *
4273
+ * This re-enqueues the delivery for another attempt.
4274
+ */
4275
+ async retry(id) {
4276
+ const result = await postWebhookDeliveriesByIdRetry({
4277
+ headers: { "x-application-key": "" },
4278
+ path: { id }
4279
+ });
4280
+ return unwrap(processResult(result));
4281
+ }
4282
+ }
4283
+ };
4284
+
4063
4285
  // src/index.ts
4064
4286
  var gptCore = {
4065
4287
  ...sdk_gen_exports,
4066
- client
4288
+ client,
4289
+ webhooks
4067
4290
  };
4068
4291
  var index_default = gptCore;
4069
4292
  // Annotate the CommonJS export names for ESM import in node:
@@ -4093,6 +4316,9 @@ var index_default = gptCore;
4093
4316
  ThreadCreateSchema,
4094
4317
  TimeoutError,
4095
4318
  ValidationError,
4319
+ WebhookConfigCreateSchema,
4320
+ WebhookConfigUpdateSchema,
4321
+ WebhookError,
4096
4322
  WorkspaceCreateSchema,
4097
4323
  calculateBackoff,
4098
4324
  client,
@@ -4362,5 +4588,6 @@ var index_default = gptCore;
4362
4588
  sleep,
4363
4589
  streamMessage,
4364
4590
  streamSSE,
4591
+ webhooks,
4365
4592
  withRetry
4366
4593
  });
package/dist/index.mjs CHANGED
@@ -3594,6 +3594,28 @@ var PresignedUploadSchema = z.object({
3594
3594
  var PresignedDownloadSchema = z.object({
3595
3595
  file_id: z.string().uuid()
3596
3596
  });
3597
+ var WebhookConfigCreateSchema = z.object({
3598
+ name: z.string().min(1).max(255),
3599
+ url: z.string().url(),
3600
+ events: z.array(z.string()).optional(),
3601
+ enabled: z.boolean().optional().default(true),
3602
+ secret: z.string().optional(),
3603
+ // Tenant-level webhook: set tenant_id to scope to a specific tenant
3604
+ tenant_id: z.string().uuid().optional(),
3605
+ // ISV filter: specific tenant UUIDs to receive events from (null = all)
3606
+ tenant_ids: z.array(z.string().uuid()).optional(),
3607
+ // Tenant filter: specific workspace UUIDs to receive events from (null = all)
3608
+ workspace_ids: z.array(z.string().uuid()).optional()
3609
+ });
3610
+ var WebhookConfigUpdateSchema = z.object({
3611
+ name: z.string().min(1).max(255).optional(),
3612
+ url: z.string().url().optional(),
3613
+ events: z.array(z.string()).optional(),
3614
+ enabled: z.boolean().optional(),
3615
+ secret: z.string().optional(),
3616
+ tenant_ids: z.array(z.string().uuid()).optional(),
3617
+ workspace_ids: z.array(z.string().uuid()).optional()
3618
+ });
3597
3619
 
3598
3620
  // src/utils/retry.ts
3599
3621
  var DEFAULT_RETRY_CONFIG = {
@@ -3745,10 +3767,207 @@ async function collectStreamedMessage(stream) {
3745
3767
  return fullMessage;
3746
3768
  }
3747
3769
 
3770
+ // src/webhooks.ts
3771
+ var WebhookError = class extends Error {
3772
+ constructor(message, status, errors) {
3773
+ super(message);
3774
+ this.status = status;
3775
+ this.errors = errors;
3776
+ this.name = "WebhookError";
3777
+ }
3778
+ };
3779
+ function unwrap(data) {
3780
+ if (data && typeof data === "object" && "attributes" in data) {
3781
+ const obj = data;
3782
+ return { id: obj.id, ...obj.attributes };
3783
+ }
3784
+ return data;
3785
+ }
3786
+ function handleError(error) {
3787
+ if (error && typeof error === "object") {
3788
+ const err = error;
3789
+ throw new WebhookError(
3790
+ err.detail || "Webhook operation failed",
3791
+ err.status,
3792
+ err.errors
3793
+ );
3794
+ }
3795
+ throw new WebhookError("Unknown error");
3796
+ }
3797
+ function processResult(result) {
3798
+ const r = result;
3799
+ if (r.error) handleError(r.error);
3800
+ return r.data?.data;
3801
+ }
3802
+ function processArrayResult(result) {
3803
+ const r = result;
3804
+ if (r.error) handleError(r.error);
3805
+ return (r.data?.data || []).map((d) => unwrap(d));
3806
+ }
3807
+ var webhooks = {
3808
+ /**
3809
+ * List all webhook configurations accessible to the current user.
3810
+ *
3811
+ * For tenant users, this returns webhooks scoped to their tenant.
3812
+ * For ISV/app owners, this returns application-level webhooks.
3813
+ */
3814
+ async list(options) {
3815
+ const result = await getWebhookConfigs({
3816
+ headers: { "x-application-key": "" },
3817
+ query: options?.filter
3818
+ });
3819
+ return processArrayResult(result);
3820
+ },
3821
+ /**
3822
+ * Get a single webhook configuration by ID.
3823
+ */
3824
+ async get(id) {
3825
+ const result = await getWebhookConfigsById({
3826
+ headers: { "x-application-key": "" },
3827
+ path: { id }
3828
+ });
3829
+ return unwrap(processResult(result));
3830
+ },
3831
+ /**
3832
+ * Create a new webhook configuration.
3833
+ *
3834
+ * For tenant-level webhooks, include `tenant_id` in the attributes.
3835
+ * The tenant_id is typically obtained from the user's profile.
3836
+ *
3837
+ * @example
3838
+ * ```typescript
3839
+ * // Tenant-level webhook (receives only this tenant's events)
3840
+ * const webhook = await webhooks.create({
3841
+ * name: 'My Webhook',
3842
+ * url: 'https://example.com/webhook',
3843
+ * events: ['extraction.completed', 'document.processed'],
3844
+ * tenant_id: userProfile.tenant_id,
3845
+ * });
3846
+ *
3847
+ * // With workspace filtering (only events from specific workspaces)
3848
+ * const webhook = await webhooks.create({
3849
+ * name: 'Workspace Webhook',
3850
+ * url: 'https://example.com/webhook',
3851
+ * tenant_id: userProfile.tenant_id,
3852
+ * workspace_ids: ['workspace-uuid-1', 'workspace-uuid-2'],
3853
+ * });
3854
+ * ```
3855
+ */
3856
+ async create(attributes) {
3857
+ const validated = WebhookConfigCreateSchema.parse(attributes);
3858
+ const result = await postWebhookConfigs({
3859
+ headers: { "x-application-key": "" },
3860
+ body: {
3861
+ data: {
3862
+ type: "webhook_config",
3863
+ attributes: validated
3864
+ }
3865
+ }
3866
+ });
3867
+ return unwrap(processResult(result));
3868
+ },
3869
+ /**
3870
+ * Update an existing webhook configuration.
3871
+ */
3872
+ async update(id, attributes) {
3873
+ const validated = WebhookConfigUpdateSchema.parse(attributes);
3874
+ const result = await patchWebhookConfigsById({
3875
+ headers: { "x-application-key": "" },
3876
+ path: { id },
3877
+ body: {
3878
+ data: {
3879
+ type: "webhook_config",
3880
+ id,
3881
+ attributes: validated
3882
+ }
3883
+ }
3884
+ });
3885
+ return unwrap(processResult(result));
3886
+ },
3887
+ /**
3888
+ * Delete a webhook configuration.
3889
+ */
3890
+ async delete(id) {
3891
+ const result = await deleteWebhookConfigsById({
3892
+ headers: { "x-application-key": "" },
3893
+ path: { id }
3894
+ });
3895
+ const r = result;
3896
+ if (r.error) handleError(r.error);
3897
+ },
3898
+ /**
3899
+ * Send a test webhook to verify the endpoint is reachable.
3900
+ *
3901
+ * This enqueues a test webhook delivery with a sample payload.
3902
+ * Check the deliveries list to see the result.
3903
+ */
3904
+ async test(id) {
3905
+ const result = await postWebhookConfigsByIdTest({
3906
+ headers: { "x-application-key": "" },
3907
+ path: { id }
3908
+ });
3909
+ return unwrap(processResult(result));
3910
+ },
3911
+ /**
3912
+ * Rotate the webhook secret.
3913
+ *
3914
+ * This generates a new secret for the webhook. The old secret
3915
+ * becomes invalid immediately. Make sure to update your endpoint
3916
+ * with the new secret.
3917
+ */
3918
+ async rotateSecret(id) {
3919
+ const result = await patchWebhookConfigsByIdRotateSecret({
3920
+ headers: { "x-application-key": "" },
3921
+ path: { id }
3922
+ });
3923
+ return unwrap(processResult(result));
3924
+ },
3925
+ /**
3926
+ * Webhook delivery management
3927
+ */
3928
+ deliveries: {
3929
+ /**
3930
+ * List webhook deliveries.
3931
+ *
3932
+ * Deliveries are sorted by newest first by default.
3933
+ */
3934
+ async list(options) {
3935
+ const result = await getWebhookDeliveries({
3936
+ headers: { "x-application-key": "" },
3937
+ query: options?.filter
3938
+ });
3939
+ return processArrayResult(result);
3940
+ },
3941
+ /**
3942
+ * Get a single webhook delivery by ID.
3943
+ */
3944
+ async get(id) {
3945
+ const result = await getWebhookDeliveriesById({
3946
+ headers: { "x-application-key": "" },
3947
+ path: { id }
3948
+ });
3949
+ return unwrap(processResult(result));
3950
+ },
3951
+ /**
3952
+ * Retry a failed webhook delivery.
3953
+ *
3954
+ * This re-enqueues the delivery for another attempt.
3955
+ */
3956
+ async retry(id) {
3957
+ const result = await postWebhookDeliveriesByIdRetry({
3958
+ headers: { "x-application-key": "" },
3959
+ path: { id }
3960
+ });
3961
+ return unwrap(processResult(result));
3962
+ }
3963
+ }
3964
+ };
3965
+
3748
3966
  // src/index.ts
3749
3967
  var gptCore = {
3750
3968
  ...sdk_gen_exports,
3751
- client
3969
+ client,
3970
+ webhooks
3752
3971
  };
3753
3972
  var index_default = gptCore;
3754
3973
  export {
@@ -3777,6 +3996,9 @@ export {
3777
3996
  ThreadCreateSchema,
3778
3997
  TimeoutError,
3779
3998
  ValidationError,
3999
+ WebhookConfigCreateSchema,
4000
+ WebhookConfigUpdateSchema,
4001
+ WebhookError,
3780
4002
  WorkspaceCreateSchema,
3781
4003
  calculateBackoff,
3782
4004
  client,
@@ -4047,5 +4269,6 @@ export {
4047
4269
  sleep,
4048
4270
  streamMessage,
4049
4271
  streamSSE,
4272
+ webhooks,
4050
4273
  withRetry
4051
4274
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpt-core/client",
3
- "version": "0.7.21",
3
+ "version": "0.7.23",
4
4
  "description": "TypeScript SDK for GPT Core Client API - Document extraction, AI agents, and workspace management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -43,6 +43,14 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
+ "scripts": {
47
+ "generate": "openapi-ts",
48
+ "build": "tsup src/index.ts --format cjs,esm --dts",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest",
51
+ "test:ui": "vitest --ui",
52
+ "test:coverage": "vitest run --coverage"
53
+ },
46
54
  "dependencies": {
47
55
  "eventsource-parser": "^3.0.6",
48
56
  "zod": "^3.25.76"
@@ -54,13 +62,5 @@
54
62
  "tsup": "^8.5.1",
55
63
  "typescript": "^5.9.3",
56
64
  "vitest": "^4.0.15"
57
- },
58
- "scripts": {
59
- "generate": "openapi-ts",
60
- "build": "tsup src/index.ts --format cjs,esm --dts",
61
- "test": "vitest run",
62
- "test:watch": "vitest",
63
- "test:ui": "vitest --ui",
64
- "test:coverage": "vitest run --coverage"
65
65
  }
66
- }
66
+ }