@zapier/zapier-sdk 0.18.0 → 0.18.2

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -5
  3. package/dist/api/router.d.ts.map +1 -1
  4. package/dist/api/router.js +1 -7
  5. package/dist/api/router.test.js +1 -7
  6. package/dist/api/types.d.ts +2 -1
  7. package/dist/api/types.d.ts.map +1 -1
  8. package/dist/api/types.js +0 -10
  9. package/dist/index.cjs +59 -247
  10. package/dist/index.d.mts +100 -191
  11. package/dist/index.mjs +59 -247
  12. package/dist/plugins/eventEmission/transport.d.ts +8 -18
  13. package/dist/plugins/eventEmission/transport.d.ts.map +1 -1
  14. package/dist/plugins/eventEmission/transport.js +47 -44
  15. package/dist/plugins/eventEmission/transport.test.js +36 -25
  16. package/dist/plugins/getAuthentication/index.d.ts +3 -3
  17. package/dist/plugins/getAuthentication/index.d.ts.map +1 -1
  18. package/dist/plugins/getAuthentication/index.js +3 -5
  19. package/dist/plugins/getAuthentication/index.test.js +4 -16
  20. package/dist/plugins/getAuthentication/schemas.d.ts +2 -4
  21. package/dist/plugins/getAuthentication/schemas.d.ts.map +1 -1
  22. package/dist/plugins/getAuthentication/schemas.js +1 -1
  23. package/dist/plugins/listAuthentications/index.d.ts.map +1 -1
  24. package/dist/schemas/Auth.d.ts +11 -11
  25. package/dist/schemas/Auth.d.ts.map +1 -1
  26. package/dist/schemas/Auth.js +2 -12
  27. package/dist/sdk.d.ts +3 -1
  28. package/dist/sdk.d.ts.map +1 -1
  29. package/dist/temporary-internal-core/index.d.ts +0 -2
  30. package/dist/temporary-internal-core/index.d.ts.map +1 -1
  31. package/dist/temporary-internal-core/index.js +0 -2
  32. package/dist/temporary-internal-core/utils/transformations.d.ts +1 -1
  33. package/dist/temporary-internal-core/utils/transformations.d.ts.map +1 -1
  34. package/package.json +2 -1
  35. package/dist/temporary-internal-core/handlers/getAuthentication.d.ts +0 -94
  36. package/dist/temporary-internal-core/handlers/getAuthentication.d.ts.map +0 -1
  37. package/dist/temporary-internal-core/handlers/getAuthentication.js +0 -68
  38. package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts +0 -2
  39. package/dist/temporary-internal-core/handlers/getAuthentication.test.d.ts.map +0 -1
  40. package/dist/temporary-internal-core/handlers/getAuthentication.test.js +0 -248
  41. package/dist/temporary-internal-core/schemas/authentications/index.d.ts +0 -150
  42. package/dist/temporary-internal-core/schemas/authentications/index.d.ts.map +0 -1
  43. package/dist/temporary-internal-core/schemas/authentications/index.js +0 -97
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { AuthenticationItemSchema as AuthenticationItemSchema$1, GetAuthenticationParamSchema } from '@zapier/zapier-sdk-core/v0/schemas/authentications';
2
3
  import { setTimeout as setTimeout$1 } from 'timers/promises';
3
4
  import * as os from 'os';
4
5
 
@@ -2241,26 +2242,7 @@ var ListAuthenticationsSchema = z.object({
2241
2242
  cursor: z.string().optional().describe("Cursor to start from")
2242
2243
  }).merge(TelemetryMarkerSchema).describe("List available authentications with optional filtering");
2243
2244
  var AuthenticationItemSchema = withFormatter(
2244
- AuthenticationSchema.omit({ selected_api: true, customuser_id: true }).extend(
2245
- {
2246
- id: z.string(),
2247
- // Converted from number
2248
- account_id: z.string(),
2249
- // Converted from number
2250
- implementation_id: z.string().optional(),
2251
- // Renamed from selected_api
2252
- is_expired: z.string().optional(),
2253
- // Mapped from is_stale
2254
- expired_at: z.string().nullable().optional(),
2255
- // Mapped from marked_stale_at
2256
- app_key: z.string().optional(),
2257
- // App key from implementations endpoint
2258
- app_version: z.string().optional(),
2259
- // Version extracted from implementation_id
2260
- profile_id: z.string().optional()
2261
- // Mapped from customuser_id, converted from number
2262
- }
2263
- ),
2245
+ AuthenticationItemSchema$1,
2264
2246
  {
2265
2247
  format: (item) => {
2266
2248
  const details = [];
@@ -2347,7 +2329,9 @@ var listAuthenticationsPlugin = ({ context }) => {
2347
2329
  (auth) => normalizeAuthenticationItem(auth)
2348
2330
  );
2349
2331
  if (options.title) {
2350
- auths = auths.filter((auth) => auth.title === options.title);
2332
+ auths = auths.filter(
2333
+ (auth) => auth.title === options.title
2334
+ );
2351
2335
  }
2352
2336
  return {
2353
2337
  data: auths,
@@ -2475,64 +2459,6 @@ var getActionPlugin = ({ sdk, context }) => {
2475
2459
  }
2476
2460
  };
2477
2461
  };
2478
- var AuthenticationSchema2 = z.object({
2479
- id: z.number(),
2480
- date: z.string(),
2481
- lastchanged: z.string().optional(),
2482
- account_id: z.number(),
2483
- customuser_id: z.number().optional(),
2484
- selected_api: z.string(),
2485
- destination_selected_api: z.string().nullable().optional(),
2486
- is_invite_only: z.boolean(),
2487
- is_private: z.boolean(),
2488
- shared_with_all: z.boolean(),
2489
- is_stale: z.string().optional(),
2490
- is_shared: z.string().optional(),
2491
- marked_stale_at: z.string().nullable().optional(),
2492
- label: z.string().nullable().optional(),
2493
- identifier: z.string().nullable().optional(),
2494
- title: z.string().nullable().optional(),
2495
- url: z.string().optional(),
2496
- groups: z.string().optional(),
2497
- members: z.string().optional(),
2498
- permissions: z.record(z.string(), z.boolean()).optional()
2499
- });
2500
- z.object({
2501
- count: z.number(),
2502
- next: z.string().nullable().optional(),
2503
- previous: z.string().nullable().optional(),
2504
- results: z.array(AuthenticationSchema2)
2505
- });
2506
- var AuthenticationItemSchema2 = AuthenticationSchema2.omit({
2507
- selected_api: true,
2508
- customuser_id: true
2509
- }).extend({
2510
- // Override numeric IDs with string versions (converted by normalizeAuthenticationItem)
2511
- id: z.string(),
2512
- account_id: z.string(),
2513
- // Renamed fields
2514
- implementation_id: z.string().optional(),
2515
- profile_id: z.string().optional(),
2516
- // Mapped fields (originals preserved in ...restOfAuth)
2517
- is_expired: z.string().optional(),
2518
- expired_at: z.string().nullable().optional(),
2519
- // Computed fields
2520
- app_key: z.string().optional(),
2521
- app_version: z.string().optional()
2522
- });
2523
- var GetAuthenticationOptionsSchema = z.object({
2524
- authenticationId: z.union([z.string(), z.number().int().positive()]).describe("Authentication ID to retrieve")
2525
- }).describe("Get a specific authentication by ID");
2526
- var GetAuthenticationHandlerRequestSchema = z.object({
2527
- authenticationId: z.union([z.string(), z.number()]).describe("Authentication ID - string from searchParams or number")
2528
- }).transform((data) => ({
2529
- authenticationId: typeof data.authenticationId === "string" ? parseInt(data.authenticationId, 10) : data.authenticationId
2530
- }));
2531
- z.object({
2532
- data: z.lazy(() => AuthenticationItemSchema2)
2533
- });
2534
-
2535
- // src/plugins/getAuthentication/index.ts
2536
2462
  var getAuthenticationPlugin = ({ context }) => {
2537
2463
  async function getAuthentication(options) {
2538
2464
  const { api } = context;
@@ -2542,7 +2468,7 @@ var getAuthenticationPlugin = ({ context }) => {
2542
2468
  }
2543
2469
  const getAuthenticationDefinition = createFunction(
2544
2470
  getAuthentication,
2545
- GetAuthenticationOptionsSchema,
2471
+ GetAuthenticationParamSchema,
2546
2472
  createTelemetryCallback(
2547
2473
  context.eventEmission.emitMethodCalled,
2548
2474
  getAuthentication.name
@@ -2556,7 +2482,7 @@ var getAuthenticationPlugin = ({ context }) => {
2556
2482
  categories: ["authentication"],
2557
2483
  type: "item",
2558
2484
  itemType: "Authentication",
2559
- inputSchema: GetAuthenticationOptionsSchema,
2485
+ inputSchema: GetAuthenticationParamSchema,
2560
2486
  outputSchema: AuthenticationItemSchema,
2561
2487
  resolvers: {
2562
2488
  authenticationId: authenticationIdGenericResolver
@@ -3854,50 +3780,6 @@ function extractPaginationCursor(response) {
3854
3780
  return void 0;
3855
3781
  }
3856
3782
  }
3857
- function normalizeAuthenticationItem2(auth, options = {}) {
3858
- let appKey = options.app_key;
3859
- let appVersion = options.app_version;
3860
- if (auth.selected_api) {
3861
- const [extractedAppKey, extractedVersion] = splitVersionedKey2(
3862
- auth.selected_api
3863
- );
3864
- if (!appKey) {
3865
- appKey = extractedAppKey;
3866
- }
3867
- if (!appVersion) {
3868
- appVersion = extractedVersion;
3869
- }
3870
- }
3871
- const {
3872
- selected_api: selectedApi,
3873
- customuser_id: profileId,
3874
- id,
3875
- account_id: accountId,
3876
- ...restOfAuth
3877
- } = auth;
3878
- return {
3879
- ...restOfAuth,
3880
- // Pass through all other API response fields except selected_api
3881
- id: String(id),
3882
- // Convert to string
3883
- account_id: String(accountId),
3884
- // Convert to string
3885
- implementation_id: selectedApi,
3886
- // Rename selected_api to implementation_id
3887
- title: auth.title || auth.label || void 0,
3888
- // Coerce title from label if missing
3889
- is_expired: auth.is_stale,
3890
- // Map is_stale to is_expired
3891
- expired_at: auth.marked_stale_at,
3892
- // Map marked_stale_at to expired_at
3893
- app_key: appKey,
3894
- // App key from implementations endpoint or parsed from selected_api
3895
- app_version: appVersion,
3896
- // Version from selected_api or provided
3897
- profile_id: profileId != null ? String(profileId) : void 0
3898
- // Map customuser_id to profile_id, convert to string
3899
- };
3900
- }
3901
3783
 
3902
3784
  // src/temporary-internal-core/handlers/listApps.ts
3903
3785
  var DEFAULT_PAGE_SIZE = 20;
@@ -4001,73 +3883,6 @@ var handleListApps = async ({ request, deps }) => {
4001
3883
  };
4002
3884
  };
4003
3885
 
4004
- // src/temporary-internal-core/schemas/errors/index.ts
4005
- var ZapierError2 = class extends Error {
4006
- constructor(message, options = {}) {
4007
- super(message);
4008
- this.statusCode = options.statusCode;
4009
- this.errors = options.errors;
4010
- this.cause = options.cause;
4011
- this.response = options.response;
4012
- Object.setPrototypeOf(this, new.target.prototype);
4013
- }
4014
- };
4015
- var ZapierAuthenticationError2 = class extends ZapierError2 {
4016
- constructor(message, options = {}) {
4017
- super(message, options);
4018
- this.name = "ZapierAuthenticationError";
4019
- }
4020
- };
4021
- var ZapierResourceNotFoundError2 = class extends ZapierError2 {
4022
- constructor(message, options = {}) {
4023
- super(message, options);
4024
- this.name = "ZapierResourceNotFoundError";
4025
- this.resourceType = options.resourceType;
4026
- this.resourceId = options.resourceId;
4027
- }
4028
- };
4029
-
4030
- // src/temporary-internal-core/handlers/getAuthentication.ts
4031
- var handleGetAuthentication = async ({ request, deps }) => {
4032
- const validatedRequest = GetAuthenticationHandlerRequestSchema.parse(request);
4033
- const { httpClient } = deps;
4034
- const { authenticationId } = validatedRequest;
4035
- const authentication = await httpClient.get(
4036
- `/zapier/api/v4/authentications/${authenticationId}/`,
4037
- {
4038
- authRequired: true,
4039
- customErrorHandler: ({ status }) => {
4040
- if (status === 401) {
4041
- return new ZapierAuthenticationError2(
4042
- `Authentication failed. Your token may not have permission to access authentications or may be expired. (HTTP ${status})`,
4043
- { statusCode: status }
4044
- );
4045
- }
4046
- if (status === 403) {
4047
- return new ZapierAuthenticationError2(
4048
- `Access forbidden. Your token may not have the required scopes to get authentication ${authenticationId}. (HTTP ${status})`,
4049
- { statusCode: status }
4050
- );
4051
- }
4052
- if (status === 404) {
4053
- return new ZapierResourceNotFoundError2(
4054
- `Authentication ${authenticationId} not found. It may not exist or you may not have access to it. (HTTP ${status})`,
4055
- {
4056
- resourceType: "Authentication",
4057
- resourceId: String(authenticationId)
4058
- }
4059
- );
4060
- }
4061
- return void 0;
4062
- }
4063
- }
4064
- );
4065
- const normalizedAuthentication = normalizeAuthenticationItem2(authentication);
4066
- return {
4067
- data: normalizedAuthentication
4068
- };
4069
- };
4070
-
4071
3886
  // src/api/router.ts
4072
3887
  var routes = [
4073
3888
  {
@@ -4075,12 +3890,6 @@ var routes = [
4075
3890
  pattern: /^\/api\/v0\/apps$/,
4076
3891
  handler: handleListApps,
4077
3892
  paramMap: []
4078
- },
4079
- {
4080
- method: "GET",
4081
- pattern: /^\/api\/v0\/authentications\/([^\/]+)$/,
4082
- handler: handleGetAuthentication,
4083
- paramMap: ["authenticationId"]
4084
3893
  }
4085
3894
  ];
4086
3895
  function findMatchingRoute(routeList, method, path) {
@@ -4894,70 +4703,73 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
4894
4703
  // src/plugins/eventEmission/transport.ts
4895
4704
  var DEFAULT_RETRY_ATTEMPTS = 2;
4896
4705
  var DEFAULT_RETRY_DELAY_MS = 300;
4897
- var HttpTransport = class {
4898
- constructor(config) {
4899
- this.config = config;
4900
- }
4901
- async emit(subject, event) {
4902
- try {
4903
- await this.emitWithRetry(
4904
- subject,
4905
- event,
4906
- this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
4907
- );
4908
- } catch {
4909
- }
4910
- }
4911
- async emitWithRetry(subject, event, attemptsLeft) {
4706
+ function createHttpTransport(config) {
4707
+ const delay = async (ms) => {
4708
+ return new Promise((resolve2) => {
4709
+ const timer = setTimeout(resolve2, ms);
4710
+ if (typeof timer.unref === "function") {
4711
+ timer.unref();
4712
+ }
4713
+ });
4714
+ };
4715
+ const emitWithRetry = async (subject, event, attemptsLeft) => {
4912
4716
  try {
4913
4717
  const payload = {
4914
4718
  subject,
4915
4719
  properties: event
4916
4720
  };
4917
- const response = await fetch(this.config.endpoint, {
4721
+ const response = await fetch(config.endpoint, {
4918
4722
  method: "POST",
4919
4723
  headers: {
4920
4724
  "Content-Type": "application/json",
4921
- ...this.config.headers
4725
+ ...config.headers
4922
4726
  },
4923
4727
  body: JSON.stringify(payload)
4924
4728
  });
4925
4729
  if (!response.ok && attemptsLeft > 1) {
4926
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
4927
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
4730
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
4731
+ return emitWithRetry(subject, event, attemptsLeft - 1);
4928
4732
  }
4929
4733
  } catch (error) {
4930
4734
  if (attemptsLeft > 1) {
4931
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
4932
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
4735
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
4736
+ return emitWithRetry(subject, event, attemptsLeft - 1);
4933
4737
  }
4934
4738
  throw error;
4935
4739
  }
4936
- }
4937
- async delay(ms) {
4938
- return new Promise((resolve2) => {
4939
- const timer = setTimeout(resolve2, ms);
4940
- if (typeof timer.unref === "function") {
4941
- timer.unref();
4740
+ };
4741
+ return {
4742
+ async emit(subject, event) {
4743
+ try {
4744
+ await emitWithRetry(
4745
+ subject,
4746
+ event,
4747
+ config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
4748
+ );
4749
+ } catch {
4942
4750
  }
4943
- });
4944
- }
4945
- };
4946
- var ConsoleTransport = class {
4947
- async emit(subject, event) {
4948
- try {
4949
- console.log(
4950
- "[SDK Telemetry]",
4951
- JSON.stringify({ subject, properties: event }, null, 2)
4952
- );
4953
- } catch {
4954
4751
  }
4955
- }
4956
- };
4957
- var NoopTransport = class {
4958
- async emit(_subject, _event) {
4959
- }
4960
- };
4752
+ };
4753
+ }
4754
+ function createConsoleTransport() {
4755
+ return {
4756
+ async emit(subject, event) {
4757
+ try {
4758
+ console.log(
4759
+ "[SDK Telemetry]",
4760
+ JSON.stringify({ subject, properties: event }, null, 2)
4761
+ );
4762
+ } catch {
4763
+ }
4764
+ }
4765
+ };
4766
+ }
4767
+ function createNoopTransport() {
4768
+ return {
4769
+ async emit(_subject, _event) {
4770
+ }
4771
+ };
4772
+ }
4961
4773
  function createTransport(config) {
4962
4774
  try {
4963
4775
  switch (config.type) {
@@ -4965,20 +4777,20 @@ function createTransport(config) {
4965
4777
  if (!config.endpoint) {
4966
4778
  throw new Error("HTTP transport requires endpoint");
4967
4779
  }
4968
- return new HttpTransport({
4780
+ return createHttpTransport({
4969
4781
  endpoint: config.endpoint,
4970
4782
  headers: config.headers,
4971
4783
  retryAttempts: config.retryAttempts,
4972
4784
  retryDelayMs: config.retryDelayMs
4973
4785
  });
4974
4786
  case "console":
4975
- return new ConsoleTransport();
4787
+ return createConsoleTransport();
4976
4788
  case "noop":
4977
4789
  default:
4978
- return new NoopTransport();
4790
+ return createNoopTransport();
4979
4791
  }
4980
4792
  } catch {
4981
- return new NoopTransport();
4793
+ return createNoopTransport();
4982
4794
  }
4983
4795
  }
4984
4796
  function generateEventId() {
@@ -5047,7 +4859,7 @@ function getCpuTime() {
5047
4859
 
5048
4860
  // package.json
5049
4861
  var package_default = {
5050
- version: "0.18.0"};
4862
+ version: "0.18.2"};
5051
4863
 
5052
4864
  // src/plugins/eventEmission/builders.ts
5053
4865
  function createBaseEvent(context = {}) {
@@ -15,23 +15,13 @@ export interface TransportConfig {
15
15
  retryAttempts?: number;
16
16
  retryDelayMs?: number;
17
17
  }
18
- export declare class HttpTransport implements EventTransport {
19
- private config;
20
- constructor(config: {
21
- endpoint: string;
22
- headers?: Record<string, string>;
23
- retryAttempts?: number;
24
- retryDelayMs?: number;
25
- });
26
- emit<T extends any>(subject: string, event: T): Promise<void>;
27
- private emitWithRetry;
28
- private delay;
29
- }
30
- export declare class ConsoleTransport implements EventTransport {
31
- emit<T extends any>(subject: string, event: T): Promise<void>;
32
- }
33
- export declare class NoopTransport implements EventTransport {
34
- emit<T extends any>(_subject: string, _event: T): Promise<void>;
35
- }
18
+ export declare function createHttpTransport(config: {
19
+ endpoint: string;
20
+ headers?: Record<string, string>;
21
+ retryAttempts?: number;
22
+ retryDelayMs?: number;
23
+ }): EventTransport;
24
+ export declare function createConsoleTransport(): EventTransport;
25
+ export declare function createNoopTransport(): EventTransport;
36
26
  export declare function createTransport(config: TransportConfig): EventTransport;
37
27
  //# sourceMappingURL=transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,qBAAa,aAAc,YAAW,cAAc;IAEhD,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB;IAGG,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAYrD,aAAa;YAiCb,KAAK;CAQpB;AAGD,qBAAa,gBAAiB,YAAW,cAAc;IAC/C,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAUpE;AAGD,qBAAa,aAAc,YAAW,cAAc;IAC5C,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAGtE;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAyBvE"}
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,cAAc,CAwDjB;AAGD,wBAAgB,sBAAsB,IAAI,cAAc,CAavD;AAGD,wBAAgB,mBAAmB,IAAI,cAAc,CAMpD;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAyBvE"}
@@ -8,70 +8,73 @@
8
8
  const DEFAULT_RETRY_ATTEMPTS = 2;
9
9
  const DEFAULT_RETRY_DELAY_MS = 300;
10
10
  // HTTP Transport - sends events to remote endpoint
11
- export class HttpTransport {
12
- constructor(config) {
13
- this.config = config;
14
- }
15
- async emit(subject, event) {
16
- try {
17
- await this.emitWithRetry(subject, event, this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS);
18
- }
19
- catch {
20
- // Silent failure - never throw
21
- }
22
- }
23
- async emitWithRetry(subject, event, attemptsLeft) {
11
+ export function createHttpTransport(config) {
12
+ const delay = async (ms) => {
13
+ return new Promise((resolve) => {
14
+ const timer = setTimeout(resolve, ms);
15
+ if (typeof timer.unref === "function") {
16
+ timer.unref();
17
+ }
18
+ });
19
+ };
20
+ const emitWithRetry = async (subject, event, attemptsLeft) => {
24
21
  try {
25
22
  const payload = {
26
23
  subject,
27
24
  properties: event,
28
25
  };
29
- const response = await fetch(this.config.endpoint, {
26
+ const response = await fetch(config.endpoint, {
30
27
  method: "POST",
31
28
  headers: {
32
29
  "Content-Type": "application/json",
33
- ...this.config.headers,
30
+ ...config.headers,
34
31
  },
35
32
  body: JSON.stringify(payload),
36
33
  });
37
34
  if (!response.ok && attemptsLeft > 1) {
38
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
39
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
35
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
36
+ return emitWithRetry(subject, event, attemptsLeft - 1);
40
37
  }
41
38
  }
42
39
  catch (error) {
43
40
  if (attemptsLeft > 1) {
44
- await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
45
- return this.emitWithRetry(subject, event, attemptsLeft - 1);
41
+ await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
42
+ return emitWithRetry(subject, event, attemptsLeft - 1);
46
43
  }
47
44
  throw error;
48
45
  }
49
- }
50
- async delay(ms) {
51
- return new Promise((resolve) => {
52
- const timer = setTimeout(resolve, ms);
53
- if (typeof timer.unref === "function") {
54
- timer.unref();
46
+ };
47
+ return {
48
+ async emit(subject, event) {
49
+ try {
50
+ await emitWithRetry(subject, event, config.retryAttempts || DEFAULT_RETRY_ATTEMPTS);
55
51
  }
56
- });
57
- }
52
+ catch {
53
+ // Silent failure - never throw
54
+ }
55
+ },
56
+ };
58
57
  }
59
58
  // Console Transport - logs events to console (for development)
60
- export class ConsoleTransport {
61
- async emit(subject, event) {
62
- try {
63
- console.log("[SDK Telemetry]", JSON.stringify({ subject, properties: event }, null, 2));
64
- }
65
- catch {
66
- // Silent failure - never throw
67
- }
68
- }
59
+ export function createConsoleTransport() {
60
+ return {
61
+ async emit(subject, event) {
62
+ try {
63
+ console.log("[SDK Telemetry]", JSON.stringify({ subject, properties: event }, null, 2));
64
+ }
65
+ catch {
66
+ // Silent failure - never throw
67
+ }
68
+ },
69
+ };
69
70
  }
70
71
  // No-op Transport - discards all events (for testing/disabled state)
71
- export class NoopTransport {
72
- async emit(_subject, _event) {
73
- // Intentionally do nothing
74
- }
72
+ export function createNoopTransport() {
73
+ return {
74
+ async emit(_subject, _event) {
75
+ // Intentionally do nothing
76
+ },
77
+ };
75
78
  }
76
79
  // Transport factory
77
80
  export function createTransport(config) {
@@ -81,21 +84,21 @@ export function createTransport(config) {
81
84
  if (!config.endpoint) {
82
85
  throw new Error("HTTP transport requires endpoint");
83
86
  }
84
- return new HttpTransport({
87
+ return createHttpTransport({
85
88
  endpoint: config.endpoint,
86
89
  headers: config.headers,
87
90
  retryAttempts: config.retryAttempts,
88
91
  retryDelayMs: config.retryDelayMs,
89
92
  });
90
93
  case "console":
91
- return new ConsoleTransport();
94
+ return createConsoleTransport();
92
95
  case "noop":
93
96
  default:
94
- return new NoopTransport();
97
+ return createNoopTransport();
95
98
  }
96
99
  }
97
100
  catch {
98
101
  // If transport creation fails, return noop to maintain silent operation
99
- return new NoopTransport();
102
+ return createNoopTransport();
100
103
  }
101
104
  }