@schematichq/schematic-typescript-node 1.2.0 → 1.2.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.
- package/README.md +114 -0
- package/dist/index.js +3 -3
- package/dist/wrapper.d.ts +8 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -83,6 +83,78 @@ const client = new SchematicClient({
|
|
|
83
83
|
client.close();
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
+
### Custom Logging
|
|
87
|
+
|
|
88
|
+
You can provide your own logger implementation to control how the Schematic client logs messages. The logger must implement the `Logger` interface with `error`, `warn`, `info`, and `debug` methods:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { SchematicClient, Logger } from "@schematichq/schematic-typescript-node";
|
|
92
|
+
|
|
93
|
+
// Example using a custom logger (could be Winston, Pino, etc.)
|
|
94
|
+
class CustomLogger implements Logger {
|
|
95
|
+
error(message: string, ...args: any[]): void {
|
|
96
|
+
// Your custom error logging logic
|
|
97
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
warn(message: string, ...args: any[]): void {
|
|
101
|
+
// Your custom warning logging logic
|
|
102
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
info(message: string, ...args: any[]): void {
|
|
106
|
+
// Your custom info logging logic
|
|
107
|
+
console.info(`[INFO] ${message}`, ...args);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
debug(message: string, ...args: any[]): void {
|
|
111
|
+
// Your custom debug logging logic
|
|
112
|
+
console.debug(`[DEBUG] ${message}`, ...args);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const apiKey = process.env.SCHEMATIC_API_KEY;
|
|
117
|
+
const client = new SchematicClient({
|
|
118
|
+
apiKey,
|
|
119
|
+
logger: new CustomLogger(),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// interactions with the client
|
|
123
|
+
|
|
124
|
+
client.close();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Example using a popular logging library like Winston:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import winston from 'winston';
|
|
131
|
+
import { SchematicClient } from "@schematichq/schematic-typescript-node";
|
|
132
|
+
|
|
133
|
+
// Create a Winston logger instance
|
|
134
|
+
const winstonLogger = winston.createLogger({
|
|
135
|
+
level: 'debug',
|
|
136
|
+
format: winston.format.combine(
|
|
137
|
+
winston.format.timestamp(),
|
|
138
|
+
winston.format.json()
|
|
139
|
+
),
|
|
140
|
+
transports: [
|
|
141
|
+
new winston.transports.Console(),
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const apiKey = process.env.SCHEMATIC_API_KEY;
|
|
146
|
+
const client = new SchematicClient({
|
|
147
|
+
apiKey,
|
|
148
|
+
logger: winstonLogger, // Winston logger directly implements the Logger interface
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// interactions with the client
|
|
152
|
+
|
|
153
|
+
client.close();
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
If no logger is provided, the client will use a default console logger that outputs to the standard console methods.
|
|
157
|
+
|
|
86
158
|
## Usage examples
|
|
87
159
|
|
|
88
160
|
A number of these examples use `keys` to identify companies and users. Learn more about keys [here](https://docs.schematichq.com/developer_resources/key_management).
|
|
@@ -268,6 +340,48 @@ client
|
|
|
268
340
|
client.close();
|
|
269
341
|
```
|
|
270
342
|
|
|
343
|
+
### Checking multiple flags
|
|
344
|
+
|
|
345
|
+
The `checkFlags` method allows you to efficiently check multiple feature flags in a single operation. When you provide specific flag keys, it will only return the flag values for those flags, leveraging intelligent caching to minimize API calls.
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
import { SchematicClient } from "@schematichq/schematic-typescript-node";
|
|
349
|
+
|
|
350
|
+
const apiKey = process.env.SCHEMATIC_API_KEY;
|
|
351
|
+
const client = new SchematicClient({ apiKey });
|
|
352
|
+
|
|
353
|
+
const evaluationCtx = {
|
|
354
|
+
company: { id: "your-company-id" },
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Check specific flags by providing an array of flag keys
|
|
358
|
+
client
|
|
359
|
+
.checkFlags(evaluationCtx, ["feature-flag-1", "feature-flag-2", "feature-flag-3"])
|
|
360
|
+
.then((flagResults) => {
|
|
361
|
+
flagResults.forEach((result) => {
|
|
362
|
+
console.log(`Flag ${result.flag}: ${result.value} (${result.reason})`);
|
|
363
|
+
if (result.value) {
|
|
364
|
+
// This flag is enabled
|
|
365
|
+
} else {
|
|
366
|
+
// This flag is disabled
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
})
|
|
370
|
+
.catch(console.error);
|
|
371
|
+
|
|
372
|
+
// Or check all available flags by omitting the keys parameter
|
|
373
|
+
client
|
|
374
|
+
.checkFlags(evaluationCtx)
|
|
375
|
+
.then((flagResults) => {
|
|
376
|
+
flagResults.forEach((result) => {
|
|
377
|
+
console.log(`Flag ${result.flag}: ${result.value}`);
|
|
378
|
+
});
|
|
379
|
+
})
|
|
380
|
+
.catch(console.error);
|
|
381
|
+
|
|
382
|
+
client.close();
|
|
383
|
+
```
|
|
384
|
+
|
|
271
385
|
### Other API operations
|
|
272
386
|
|
|
273
387
|
The Schematic API supports many operations beyond these, accessible via the API modules on the client, `Accounts`, `Billing`, `Companies`, `Entitlements`, `Events`, `Features`, and `Plans`.
|