@useairfoil/producer-polar 0.3.0 → 0.3.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 (48) hide show
  1. package/LICENSE.txt +201 -0
  2. package/README.md +43 -199
  3. package/dist/index.d.mts +4449 -0
  4. package/dist/index.mjs +3 -0
  5. package/dist/main.d.mts +1 -0
  6. package/dist/main.mjs +618 -0
  7. package/dist/main.mjs.map +1 -0
  8. package/dist/manifest.d.mts +38 -0
  9. package/dist/{manifest-B9GtCBa3.js → manifest.mjs} +15 -31
  10. package/dist/manifest.mjs.map +1 -0
  11. package/dist/{chunk-Bp6m_JJh.js → rolldown-runtime-D7D4PA-g.mjs} +4 -4
  12. package/dist/src-BWTLl2kr.mjs +802 -0
  13. package/dist/src-BWTLl2kr.mjs.map +1 -0
  14. package/package.json +28 -28
  15. package/src/api.ts +83 -136
  16. package/src/connector.ts +143 -86
  17. package/src/create-table.ts +10 -0
  18. package/src/demo/customers.ts +385 -0
  19. package/src/demo/index.ts +37 -0
  20. package/src/demo/setup.ts +79 -0
  21. package/src/demo/shared.ts +70 -0
  22. package/src/index.ts +18 -21
  23. package/src/main.ts +14 -8
  24. package/src/manifest.ts +3 -29
  25. package/src/resources/checkouts.ts +154 -0
  26. package/src/resources/customers.ts +69 -0
  27. package/src/resources/discounts.ts +84 -0
  28. package/src/resources/orders.ts +131 -0
  29. package/src/resources/products.ts +163 -0
  30. package/src/resources/refunds.ts +62 -0
  31. package/src/resources/shared.ts +88 -0
  32. package/src/resources/subscriptions.ts +109 -0
  33. package/src/sandbox.ts +3 -3
  34. package/src/start.ts +4 -6
  35. package/src/tables.ts +19 -0
  36. package/src/webhooks.ts +121 -0
  37. package/dist/index.d.ts +0 -1821
  38. package/dist/index.js +0 -4
  39. package/dist/main.d.ts +0 -1
  40. package/dist/main.js +0 -54
  41. package/dist/main.js.map +0 -1
  42. package/dist/manifest-B9GtCBa3.js.map +0 -1
  43. package/dist/manifest-CcMsQBSa.d.ts +0 -37
  44. package/dist/manifest.d.ts +0 -2
  45. package/dist/manifest.js +0 -3
  46. package/dist/src-CmGCpsxx.js +0 -634
  47. package/dist/src-CmGCpsxx.js.map +0 -1
  48. package/src/schemas.ts +0 -338
package/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 GNC Labs Limited
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
193
+ this file except in compliance with the License. You may obtain a copy of the
194
+ License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software distributed
199
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
200
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
201
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,221 +1,65 @@
1
- # @useairfoil/producer-polar
1
+ # Polar producer
2
2
 
3
- Polar producer connector for Airfoil Connector Kit.
3
+ This connector backfills Polar customers, checkouts, orders, subscriptions,
4
+ refunds, products, and discounts.
5
+ It gets live events at `POST /webhooks/polar`.
4
6
 
5
- Current scope:
7
+ ## Config
6
8
 
7
- - entities: `customers`, `checkouts`, `orders`, `subscriptions`
8
- - backfill source: Polar REST API
9
- - live source: Polar webhooks on `/webhooks/polar`
9
+ | Variable | Required | Default |
10
+ | ----------------------- | ----------- | ------- |
11
+ | `POLAR_ACCESS_TOKEN` | yes | none |
12
+ | `POLAR_WEBHOOK_SECRET` | yes | none |
13
+ | `POLAR_API_BASE_URL` | hosted only | none |
14
+ | `POLAR_ORGANIZATION_ID` | no | none |
10
15
 
11
- ## Public Exports
16
+ ## Setup
12
17
 
13
- - root: `PolarApiClient`, `PolarConnector`, entity schemas, webhook schema, and schema-derived types
14
- - manifest subpath: `@useairfoil/producer-polar/manifest` exports browser-safe connector metadata
18
+ Create a [Polar organization access token](https://docs.polar.sh/integrate/oat)
19
+ with `customers:read`, `checkouts:read`, `orders:read`, `subscriptions:read`,
20
+ `refunds:read`, `products:read`, and `discounts:read`. Use it as
21
+ `POLAR_ACCESS_TOKEN`.
15
22
 
16
- Typical imports:
23
+ Create a webhook endpoint for `/webhooks/polar` and use its signing secret as
24
+ `POLAR_WEBHOOK_SECRET`. Sandbox tokens and webhooks must come from the Polar
25
+ sandbox. Subscribe it to the `customer.*`, `checkout.*`, `order.*`,
26
+ `subscription.*`, `refund.*`, `product.*`, and `discount.*` events. The
27
+ connector acknowledges other events without storing them.
17
28
 
18
- ```ts
19
- import { CustomerSchema, PolarConnector, type Customer } from "@useairfoil/producer-polar";
20
- import { PolarApiClient, WebhookPayloadSchema } from "@useairfoil/producer-polar";
21
- ```
22
-
23
- Connector config and runtime types are exported from the `PolarConnector` namespace.
24
-
25
- ## ConnectorApp Shape
26
-
27
- `PolarConnector` is a typed Effect service with `layer(config)` and `layerConfig(config)`. Runtime and dashboard validation both use `layerConfig(PolarConfigDef.config)`. Local sandbox runs use `layerConfig(...)` with a `Config.succeed("https://sandbox-api.polar.sh/v1/")` override for `apiBaseUrl`.
29
+ ## API version
28
30
 
29
- ## Configuration
31
+ The connector pins Polar API version `2026-10` with the `Polar-Version` header.
32
+ Set the webhook endpoint API version to `2026-10`.
30
33
 
31
- The sandbox reads connector values from the environment:
34
+ ## Limits
32
35
 
33
- ```env
34
- POLAR_ACCESS_TOKEN=polar_oat_xxx
35
- POLAR_WEBHOOK_SECRET=polar_whs_xxx
36
- ```
36
+ Deleted products stay in the `products` table because Polar has no
37
+ `product.deleted` webhook. Subscriptions without `started_at` can be missed
38
+ during a backfill because Polar has no stable sort for them. After backfill,
39
+ updates depend on webhooks. Missed webhook deliveries are not recovered yet.
37
40
 
38
- The sandbox injects the Polar sandbox API URL. Hosted `start` instead requires a read-only connector JSON file selected by `AIRFOIL_CONFIG_PATH`; matching environment values override file values per key. The file includes manifest runtime keys such as `POLAR_ACCESS_TOKEN` and `POLAR_API_BASE_URL`.
41
+ ## Demo data
39
42
 
40
- ```env
41
- POLAR_API_BASE_URL=https://api.polar.sh/v1/
42
- ```
43
+ `pnpm demo --size 128MiB` writes made-up Polar data without a Polar token. See
44
+ the Connector Kit README for the flags and the variables it needs.
43
45
 
44
- Optional:
45
-
46
- ```env
47
- POLAR_ORGANIZATION_ID=org_xxx
48
- # Defaults to 100 for sandbox and 500 for production.
49
- # POLAR_RATE_LIMIT_PER_MINUTE=500
50
- # POLAR_TRANSIENT_MAX_RETRIES=5
51
- # POLAR_RETRY_BASE_DELAY_MS=200
52
- # POLAR_REQUEST_TIMEOUT_SECONDS=120
53
- AIRFOIL_HTTP_PORT=8080
54
- OTEL_ENABLED=false
55
- OTEL_SERVICE_NAME=producer-polar
56
- # OTEL_SERVICE_VERSION=0.1.0
57
- # OTEL_RESOURCE_ATTRIBUTES=service.instance.id=team-acme-polar-primary,airfoil.connector.revision=1,airfoil.team.id=team-acme
58
- OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
59
- OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer token,X-Axiom-Dataset=airfoil-traces
60
- ```
46
+ Each customer has checkouts, subscriptions, orders, and refunds that point to
47
+ each other and to a fixed catalog of 6 products and 3 discounts. `products` and
48
+ `discounts` don't grow with the size.
61
49
 
62
- The API policy is loaded with the rest of the connector config. It is applied per connector process, so separate instances using the same Polar token do not share one request budget.
50
+ ## Local development
63
51
 
64
- Production `start` also requires platform-owned Wings, table, and PostgreSQL state config:
65
-
66
- ```env
67
- WINGS_HOST=localhost:7777
68
- WINGS_NAMESPACE=namespaces/default
69
- AIRFOIL_TABLE_BINDINGS={"customers":"namespaces/default/tables/polar-customers","checkouts":"namespaces/default/tables/polar-checkouts","orders":"namespaces/default/tables/polar-orders","subscriptions":"namespaces/default/tables/polar-subscriptions"}
70
- AIRFOIL_CONFIG_PATH=/var/run/airfoil/config/config.json
71
- AIRFOIL_CONNECTOR_INSTANCE_ID=team-acme-polar-primary
72
- # AIRFOIL_STATE_TABLE=_airfoil_connectors_state
73
- POSTGRES_CONNECTION_STRING=postgresql://...
74
- ```
75
-
76
- The sandbox uses `Telemetry.layerOtlp()` and `Telemetry.layerMetricsConsoleDump()` from Connector Kit. Connector Kit reads `OTEL_ENABLED`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and `OTEL_EXPORTER_OTLP_HEADERS` for OTLP trace/metric export. Effect reads `OTEL_SERVICE_NAME`, `OTEL_SERVICE_VERSION`, and `OTEL_RESOURCE_ATTRIBUTES` for resource metadata. HTTP runtimes expose shallow process health at `GET /health`, metrics at `GET /metrics`, and durable progress or source errors at `GET /status`.
77
-
78
- ## ConnectorApp Entrypoint
79
-
80
- The package scripts run the connector CLI from source:
52
+ The sandbox uses the Polar sandbox API.
81
53
 
82
54
  ```bash
83
- pnpm --filter @useairfoil/producer-polar run sandbox
84
- pnpm --filter @useairfoil/producer-polar run start
55
+ cd connectors/producer-polar
56
+ pnpm sandbox
85
57
  ```
86
58
 
87
- `sandbox` runs the real connector against Polar sandbox with `Publisher.layerConsole`. `start` runs against the configured `POLAR_API_BASE_URL` and loads the complete platform-owned Wings map through `Publisher.layerWingsConfig`.
88
-
89
- The CLI assembly lives in `src/main.ts`; production runtime wiring lives in `src/start.ts`; sandbox runtime wiring lives in `src/sandbox.ts`. Port and table bindings use Connector Kit's shared platform keys.
90
-
91
- Before provisioning, the dashboard backend passes `PolarConnector.PolarConnector` and `PolarConnector.layerConfig(PolarConnector.PolarConfigDef.config)` to `ConnectorApp.check(...)`. Each selected entity performs a read-only one-item request against its corresponding Polar list endpoint; unselected entities are not contacted.
92
-
93
- ## Production Image
94
-
95
- The build emits a separate `dist/main.js` CLI while keeping it outside the package exports. Build and smoke-test the non-root Node 24 image through Nx:
59
+ A hosted run loads connector config from `AIRFOIL_CONFIG_PATH`. It also needs
60
+ the Wings and PostgreSQL variables from the Connector Kit README.
96
61
 
97
62
  ```bash
98
- pnpm nx run @useairfoil/producer-polar:docker:build
99
- docker run --rm airfoil/producer-polar:local --help
63
+ cd connectors/producer-polar
64
+ pnpm start
100
65
  ```
101
-
102
- The image runs `node dist/main.js start`, exposes port `8080`, and contains only the pruned production package. Mount the complete connector JSON file read-only at the path supplied by `AIRFOIL_CONFIG_PATH`; inject the platform-owned values listed above separately. Never bake `.env`, access tokens, webhook secrets, or database credentials into the image. The operator owns Kubernetes readiness and liveness probes against `/health`.
103
-
104
- ## Minimal ConnectorApp Wiring
105
-
106
- The following is local/example wiring. Hosted production uses `RuntimeConfig.layerHosted()`, `StateStore.layerSql()` over `PgClient`, and the Wings publisher as shown by `src/start.ts`; it must not fall back to memory state.
107
-
108
- ```ts
109
- import { Publisher, ConnectorApp, StateStore, Telemetry } from "@useairfoil/connector-kit";
110
- import { Effect, Layer } from "effect";
111
- import { FetchHttpClient } from "effect/unstable/http";
112
-
113
- import { PolarConnector } from "@useairfoil/producer-polar";
114
-
115
- const BootstrapLayer = FetchHttpClient.layer;
116
-
117
- const ConnectorLayer = PolarConnector.layerConfig(PolarConnector.PolarConfigDef.config).pipe(
118
- Layer.provide(BootstrapLayer),
119
- );
120
- const TelemetryLayer = Telemetry.layerOtlp().pipe(Layer.provide(BootstrapLayer));
121
-
122
- const program = Effect.gen(function* () {
123
- const connector = yield* PolarConnector.PolarConnector;
124
- return yield* ConnectorApp.start(connector, { port: 8080 });
125
- });
126
-
127
- const RuntimeLayer = Layer.mergeAll(
128
- StateStore.layerMemory,
129
- Publisher.layerConsole,
130
- ConnectorLayer,
131
- TelemetryLayer,
132
- );
133
-
134
- const runnable = Effect.scoped(program).pipe(Effect.provide(RuntimeLayer));
135
-
136
- Effect.runPromise(runnable);
137
- ```
138
-
139
- ## Webhook Behavior
140
-
141
- - webhook path: `POST /webhooks/polar`
142
- - route payloads are schema-validated through `Webhook.route(...)`
143
- - `POLAR_WEBHOOK_SECRET` is required and every signature is verified against the raw request body
144
- - webhook upserts use the event timestamp as their Wings version
145
- - `customer.deleted` emits a delete mutation
146
- - subscription pause and resume events are supported
147
-
148
- ## API Client Layer
149
-
150
- `PolarApiClient.layer(config)` builds `PolarApiClient.PolarApiClient` from a raw `PolarConfig` value.
151
-
152
- This is useful for focused API tests or custom runtimes that do not need the full connector service.
153
-
154
- ```ts
155
- import { Effect, Layer, Option, Redacted, Schema } from "effect";
156
- import { FetchHttpClient } from "effect/unstable/http";
157
-
158
- import { PolarApiClient } from "@useairfoil/producer-polar";
159
-
160
- const apiLayer = PolarApiClient.layer({
161
- accessToken: Redacted.make("test"),
162
- apiBaseUrl: "https://sandbox-api.polar.sh/v1/",
163
- organizationId: Option.none(),
164
- rateLimitPerMinute: Option.none(),
165
- transientMaxRetries: 5,
166
- retryBaseDelayMs: 200,
167
- requestTimeoutSeconds: 120,
168
- webhookSecret: Redacted.make("test-webhook-secret"),
169
- }).pipe(Layer.provide(FetchHttpClient.layer));
170
-
171
- const program = PolarApiClient.PolarApiClient.use((api) =>
172
- api.fetchList(Schema.Any, "customers/", {
173
- page: 1,
174
- limit: 100,
175
- sorting: "-created_at",
176
- }),
177
- ).pipe(Effect.provide(apiLayer));
178
-
179
- Effect.runPromise(program);
180
- ```
181
-
182
- ## Development Notes
183
-
184
- - Polar entity streams combine live webhook events with paginated backfill
185
- - backfill is bounded by the cutoff established from live webhooks or the initial runtime cutoff
186
- - backfill pagination stays on `created_at`; decoded rows use `modified_at ?? created_at` as their version
187
- - incoming events outside the current connector scope are ignored
188
-
189
- ## Testing
190
-
191
- - `test/api.vcr.test.ts`: VCR-backed API replay against a recorded cassette
192
- - `test/check.test.ts`, `test/schemas.test.ts`, and `test/rate-limit.test.ts`: config checks, provider schemas, and request policy
193
- - `test/webhook.test.ts`: in-memory webhook round-trip using `NodeHttpServer.layerTest`
194
-
195
- Run:
196
-
197
- ```bash
198
- pnpm --filter @useairfoil/producer-polar run test:ci
199
- ```
200
-
201
- ## Sandbox Tracing
202
-
203
- Set `OTEL_ENABLED=true` to export traces and metrics from the sandbox. Metrics are also logged locally by `Telemetry.layerMetricsConsoleDump()`.
204
-
205
- The sandbox uses `Telemetry.layerOtlp()` with the default Connector Kit sensitive-header redaction. See `@useairfoil/connector-kit` for the full telemetry env var list, metric names, and redaction defaults.
206
-
207
- For local Jaeger with persistent storage, start it from the traceview package:
208
-
209
- ```bash
210
- pnpm --filter @useairfoil/traceview run jaeger:up
211
- ```
212
-
213
- Then set `OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318` and run the sandbox. After triggering a webhook or backfill, render the trace:
214
-
215
- ```bash
216
- traceview <trace-id> --source jaeger
217
- # or for Axiom:
218
- traceview <trace-id> --source axiom
219
- ```
220
-
221
- Webhook traces may include an external parent span from Polar's `traceparent` header — that parent is expected to be missing from your dataset unless Polar also exports there.