@schematichq/schematic-typescript-node 1.4.1 → 1.4.3

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 (35) hide show
  1. package/README.md +91 -0
  2. package/dist/api/resources/billing/client/Client.d.ts +0 -1
  3. package/dist/api/resources/billing/client/requests/CreateBillingProductRequestBody.d.ts +1 -2
  4. package/dist/api/resources/plangroups/client/Client.d.ts +5 -2
  5. package/dist/api/resources/plangroups/client/requests/GetPlanGroupRequest.d.ts +9 -0
  6. package/dist/api/resources/plangroups/client/requests/index.d.ts +1 -0
  7. package/dist/api/resources/plangroups/types/GetPlanGroupParams.d.ts +6 -0
  8. package/dist/api/resources/plangroups/types/GetPlanGroupResponse.d.ts +1 -1
  9. package/dist/api/resources/plangroups/types/index.d.ts +1 -0
  10. package/dist/api/types/BillingCreditBundleResponseData.d.ts +0 -1
  11. package/dist/api/types/BillingCreditBundleView.d.ts +0 -1
  12. package/dist/api/types/CaptureRawEvent.d.ts +7 -0
  13. package/dist/api/types/CaptureRawEventBatch.d.ts +4 -0
  14. package/dist/api/types/CheckFlagsResponseData.d.ts +1 -0
  15. package/dist/api/types/DatastreamCompanyPlan.d.ts +5 -0
  16. package/dist/api/types/PlanChangeResponseData.d.ts +4 -0
  17. package/dist/api/types/PlanVersionSnapshotView.d.ts +5 -0
  18. package/dist/api/types/WhoAmIResponseData.d.ts +1 -1
  19. package/dist/api/types/index.d.ts +4 -0
  20. package/dist/index.js +3 -3
  21. package/dist/serialization/resources/billing/client/requests/CreateBillingProductRequestBody.d.ts +1 -1
  22. package/dist/serialization/resources/plangroups/types/GetPlanGroupParams.d.ts +9 -0
  23. package/dist/serialization/resources/plangroups/types/GetPlanGroupResponse.d.ts +2 -1
  24. package/dist/serialization/resources/plangroups/types/index.d.ts +1 -0
  25. package/dist/serialization/types/BillingCreditBundleResponseData.d.ts +0 -1
  26. package/dist/serialization/types/BillingCreditBundleView.d.ts +0 -1
  27. package/dist/serialization/types/CaptureRawEvent.d.ts +13 -0
  28. package/dist/serialization/types/CaptureRawEventBatch.d.ts +10 -0
  29. package/dist/serialization/types/CheckFlagsResponseData.d.ts +2 -0
  30. package/dist/serialization/types/DatastreamCompanyPlan.d.ts +11 -0
  31. package/dist/serialization/types/PlanChangeResponseData.d.ts +3 -0
  32. package/dist/serialization/types/PlanVersionSnapshotView.d.ts +11 -0
  33. package/dist/serialization/types/WhoAmIResponseData.d.ts +2 -1
  34. package/dist/serialization/types/index.d.ts +4 -0
  35. package/package.json +6 -4
package/README.md CHANGED
@@ -601,6 +601,97 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
601
601
  }
602
602
  ```
603
603
 
604
+ ## DataStream
605
+
606
+ DataStream enables local flag evaluation by maintaining a WebSocket connection to Schematic and caching flag rules, company, and user data locally.
607
+
608
+ > **Runtime compatibility:** DataStream requires Node.js APIs (`WebSocket`, `EventEmitter`) and is not supported in edge runtimes such as Cloudflare Workers, Vercel Edge Functions, or Deno Deploy. For these runtimes, use [Replicator Mode](#replicator-mode) instead.
609
+
610
+ ### Setup
611
+
612
+ ```ts
613
+ import { SchematicClient } from "@schematichq/schematic-typescript-node";
614
+
615
+ const client = new SchematicClient({
616
+ apiKey: process.env.SCHEMATIC_API_KEY,
617
+ useDataStream: true,
618
+ });
619
+
620
+ // Flag checks are now evaluated locally
621
+ const flagValue = await client.checkFlag(
622
+ { company: { id: "your-company-id" } },
623
+ "some-flag-key",
624
+ );
625
+
626
+ client.close();
627
+ ```
628
+
629
+ ### Configuration options
630
+
631
+ | Option | Type | Default | Description |
632
+ |---|---|---|---|
633
+ | `cacheTTL` | `number` | 24 hours | Cache TTL in milliseconds |
634
+ | `redisClient` | `RedisClient` | — | Redis client for shared caching (uses in-memory cache if not provided) |
635
+ | `redisKeyPrefix` | `string` | `schematic:` | Key prefix for Redis cache entries |
636
+
637
+ ```ts
638
+ import { createClient } from "redis";
639
+ import { SchematicClient } from "@schematichq/schematic-typescript-node";
640
+
641
+ const redisClient = createClient({ url: "redis://localhost:6379" });
642
+ await redisClient.connect();
643
+
644
+ const client = new SchematicClient({
645
+ apiKey: process.env.SCHEMATIC_API_KEY,
646
+ useDataStream: true,
647
+ dataStream: {
648
+ redisClient,
649
+ redisKeyPrefix: "schematic:",
650
+ cacheTTL: 60 * 60 * 1000, // 1 hour
651
+ },
652
+ });
653
+ ```
654
+
655
+ ## Replicator Mode
656
+
657
+ Replicator mode is designed for environments where a separate process (the replicator) manages the WebSocket connection and populates a shared cache. The SDK reads from that cache and evaluates flags locally without establishing its own WebSocket connection.
658
+
659
+ ### Requirements
660
+
661
+ Replicator mode requires a shared cache (Redis or custom cache providers) so the SDK can read data written by the external replicator process.
662
+
663
+ ### Setup
664
+
665
+ ```ts
666
+ import { createClient } from "redis";
667
+ import { SchematicClient } from "@schematichq/schematic-typescript-node";
668
+
669
+ const redisClient = createClient({ url: "redis://localhost:6379" });
670
+ await redisClient.connect();
671
+
672
+ const client = new SchematicClient({
673
+ apiKey: process.env.SCHEMATIC_API_KEY,
674
+ useDataStream: true,
675
+ dataStream: {
676
+ replicatorMode: true,
677
+ redisClient,
678
+ replicatorHealthURL: "http://localhost:8080/health",
679
+ replicatorHealthCheck: 30000, // 30 seconds
680
+ },
681
+ });
682
+ ```
683
+
684
+ ### Configuration options
685
+
686
+ | Option | Type | Default | Description |
687
+ |---|---|---|---|
688
+ | `replicatorMode` | `boolean` | `false` | Enable replicator mode |
689
+ | `redisClient` | `RedisClient` | — | **Required.** Redis client for reading from the shared cache |
690
+ | `redisKeyPrefix` | `string` | `schematic:` | Key prefix for Redis cache entries |
691
+ | `replicatorHealthURL` | `string` | — | URL to poll for replicator health status |
692
+ | `replicatorHealthCheck` | `number` | 30000 | Health check polling interval in milliseconds |
693
+ | `cacheTTL` | `number` | 24 hours | Cache TTL in milliseconds |
694
+
604
695
  ## Testing
605
696
 
606
697
  ### Offline mode
@@ -369,7 +369,6 @@ export declare class BillingClient {
369
369
  * @example
370
370
  * await client.billing.upsertBillingProduct({
371
371
  * externalId: "external_id",
372
- * name: "name",
373
372
  * price: 1.1
374
373
  * })
375
374
  */
@@ -3,14 +3,13 @@ import type * as Schematic from "../../../../index";
3
3
  * @example
4
4
  * {
5
5
  * externalId: "external_id",
6
- * name: "name",
7
6
  * price: 1.1
8
7
  * }
9
8
  */
10
9
  export interface CreateBillingProductRequestBody {
11
10
  externalId: string;
12
11
  isActive?: boolean;
13
- name: string;
12
+ name?: string;
14
13
  price: number;
15
14
  providerType?: Schematic.BillingProviderType;
16
15
  }
@@ -11,6 +11,7 @@ export declare class PlangroupsClient {
11
11
  protected readonly _options: NormalizedClientOptionsWithAuth<PlangroupsClient.Options>;
12
12
  constructor(options: PlangroupsClient.Options);
13
13
  /**
14
+ * @param {Schematic.GetPlanGroupRequest} request
14
15
  * @param {PlangroupsClient.RequestOptions} requestOptions - Request-specific configuration.
15
16
  *
16
17
  * @throws {@link Schematic.UnauthorizedError}
@@ -19,9 +20,11 @@ export declare class PlangroupsClient {
19
20
  * @throws {@link Schematic.InternalServerError}
20
21
  *
21
22
  * @example
22
- * await client.plangroups.getPlanGroup()
23
+ * await client.plangroups.getPlanGroup({
24
+ * includeCompanyCounts: true
25
+ * })
23
26
  */
24
- getPlanGroup(requestOptions?: PlangroupsClient.RequestOptions): core.HttpResponsePromise<Schematic.GetPlanGroupResponse>;
27
+ getPlanGroup(request?: Schematic.GetPlanGroupRequest, requestOptions?: PlangroupsClient.RequestOptions): core.HttpResponsePromise<Schematic.GetPlanGroupResponse>;
25
28
  private __getPlanGroup;
26
29
  /**
27
30
  * @param {Schematic.CreatePlanGroupRequestBody} request
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @example
3
+ * {
4
+ * includeCompanyCounts: true
5
+ * }
6
+ */
7
+ export interface GetPlanGroupRequest {
8
+ includeCompanyCounts?: boolean;
9
+ }
@@ -1,2 +1,3 @@
1
1
  export type { CreatePlanGroupRequestBody } from "./CreatePlanGroupRequestBody";
2
+ export type { GetPlanGroupRequest } from "./GetPlanGroupRequest";
2
3
  export type { UpdatePlanGroupRequestBody } from "./UpdatePlanGroupRequestBody";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Input parameters
3
+ */
4
+ export interface GetPlanGroupParams {
5
+ includeCompanyCounts?: boolean;
6
+ }
@@ -2,5 +2,5 @@ import type * as Schematic from "../../../index";
2
2
  export interface GetPlanGroupResponse {
3
3
  data: Schematic.PlanGroupDetailResponseData;
4
4
  /** Input parameters */
5
- params: Record<string, unknown>;
5
+ params: Schematic.GetPlanGroupParams;
6
6
  }
@@ -1,3 +1,4 @@
1
1
  export * from "./CreatePlanGroupResponse";
2
+ export * from "./GetPlanGroupParams";
2
3
  export * from "./GetPlanGroupResponse";
3
4
  export * from "./UpdatePlanGroupResponse";
@@ -1,6 +1,5 @@
1
1
  import type * as Schematic from "../index";
2
2
  export interface BillingCreditBundleResponseData {
3
- billingInvoiceId?: string;
4
3
  bundleType: Schematic.BillingCreditBundleType;
5
4
  createdAt: Date;
6
5
  creditDescription?: string;
@@ -1,6 +1,5 @@
1
1
  import type * as Schematic from "../index";
2
2
  export interface BillingCreditBundleView {
3
- billingInvoiceId?: string;
4
3
  bundleType: Schematic.BillingCreditBundleType;
5
4
  createdAt: Date;
6
5
  creditDescription?: string;
@@ -0,0 +1,7 @@
1
+ export interface CaptureRawEvent {
2
+ capturedAt: Date;
3
+ eventId?: string;
4
+ rawBytes: number[];
5
+ remoteIp: string;
6
+ userAgent: string;
7
+ }
@@ -0,0 +1,4 @@
1
+ import type * as Schematic from "../index";
2
+ export interface CaptureRawEventBatch {
3
+ events: Schematic.CaptureRawEvent[];
4
+ }
@@ -1,4 +1,5 @@
1
1
  import type * as Schematic from "../index";
2
2
  export interface CheckFlagsResponseData {
3
3
  flags: Schematic.CheckFlagResponseData[];
4
+ plan?: Schematic.DatastreamCompanyPlan;
4
5
  }
@@ -0,0 +1,5 @@
1
+ export interface DatastreamCompanyPlan {
2
+ id: string;
3
+ name: string;
4
+ trialEndDate?: Date;
5
+ }
@@ -9,12 +9,16 @@ export interface PlanChangeResponseData {
9
9
  basePlan?: Schematic.PlanSnapshotView;
10
10
  /** Any special behavior that affected the assignment of the base plan during this change. */
11
11
  basePlanAction?: Schematic.PlanChangeBasePlanAction;
12
+ /** The plan version that was assigned during this change. */
13
+ basePlanVersion?: Schematic.PlanVersionSnapshotView;
12
14
  company?: Schematic.CompanyResponseData;
13
15
  companyId: string;
14
16
  createdAt: Date;
15
17
  environmentId: string;
16
18
  id: string;
17
19
  previousBasePlan?: Schematic.PlanSnapshotView;
20
+ /** The plan version of the previous base plan before this change. */
21
+ previousBasePlanVersion?: Schematic.PlanVersionSnapshotView;
18
22
  requestId?: string;
19
23
  /** If a subscription was changed as a part of this plan change, indicates the type of change that was made. */
20
24
  subscriptionChangeAction?: Schematic.PlanChangeSubscriptionAction;
@@ -0,0 +1,5 @@
1
+ export interface PlanVersionSnapshotView {
2
+ id: string;
3
+ name: string;
4
+ version: number;
5
+ }
@@ -2,7 +2,7 @@ import type * as Schematic from "../index";
2
2
  export interface WhoAmIResponseData {
3
3
  accountId: string;
4
4
  accountName: string;
5
- actorType: string;
5
+ actorType: Schematic.ActorType;
6
6
  apiKeyId?: string;
7
7
  environmentId?: string;
8
8
  environments: Schematic.EnvironmentResponseData[];
@@ -47,6 +47,8 @@ export * from "./BillingSubscriptionResponseData";
47
47
  export * from "./BillingSubscriptionTrialEndSetting";
48
48
  export * from "./BillingSubscriptionView";
49
49
  export * from "./BillingTiersMode";
50
+ export * from "./CaptureRawEvent";
51
+ export * from "./CaptureRawEventBatch";
50
52
  export * from "./ChangeSubscriptionInternalRequestBody";
51
53
  export * from "./ChangeSubscriptionRequestBody";
52
54
  export * from "./ChargeType";
@@ -138,6 +140,7 @@ export * from "./DataExportOutputFileType";
138
140
  export * from "./DataExportResponseData";
139
141
  export * from "./DataExportStatus";
140
142
  export * from "./DataExportType";
143
+ export * from "./DatastreamCompanyPlan";
141
144
  export * from "./DeleteBillingPlanCreditGrantRequestBody";
142
145
  export * from "./DeleteResponse";
143
146
  export * from "./DuplicatePlanEntitlementsResponseResponseData";
@@ -230,6 +233,7 @@ export * from "./PlanVersionMigrationResponseData";
230
233
  export * from "./PlanVersionMigrationStatus";
231
234
  export * from "./PlanVersionMigrationStrategy";
232
235
  export * from "./PlanVersionResponseData";
236
+ export * from "./PlanVersionSnapshotView";
233
237
  export * from "./PlanVersionStatus";
234
238
  export * from "./PlanViewPublicResponseData";
235
239
  export * from "./PreviewObject";