Skip to content

Commit 594ef58

Browse files
committed
style: [sdk-1556] convert example to ts
1 parent 9df4b3a commit 594ef58

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import {createMiniOxygen} from '@shopify/mini-oxygen';
1+
import { createMiniOxygen } from '@shopify/mini-oxygen';
2+
3+
/* eslint-disable no-console */
24

35
/**
46
* This is script is a simple runner for our example app. This script will run
57
* the compiled example on a local worker implementation to emulate a Oxygen worker runtime.
6-
*
8+
*
79
* For the actual example implementation, see the src/index.ts file.
810
*/
911

10-
const printValueAndBanner = (flagKey, flagValue) => {
12+
const printValueAndBanner = (flagKey: string, flagValue: string) => {
1113
console.log(`*** The '${flagKey}' feature flag evaluates to ${flagValue}.`);
1214

1315
if (flagValue) {
@@ -24,7 +26,7 @@ const printValueAndBanner = (flagKey, flagValue) => {
2426
`,
2527
);
2628
}
27-
}
29+
};
2830

2931
const main = async () => {
3032
// NOTE: you will see logging coming from mini-oxygen's default request hook.
@@ -35,44 +37,46 @@ const main = async () => {
3537
{
3638
name: 'main',
3739
modules: true,
38-
scriptPath: 'dist/index.js'
40+
scriptPath: 'dist/index.js',
3941
},
4042
],
4143
});
4244

4345
miniOxygen.ready.then(() => {
4446
console.log('Oxygen worker is started...');
4547
console.log('Press "q" or Ctrl+C to quit...');
46-
48+
4749
// Dispatch fetch every 5 seconds
4850
const interval = setInterval(() => {
4951
// NOTE: This is a bogus URL and will not be used in the actual fetch handler.
5052
// please see the src/index.ts file for the actual fetch handler.
51-
miniOxygen.dispatchFetch('https://localhost:8000')
52-
.then(d => d.json())
53-
.then(({flagValue, flagKey}) => {
53+
miniOxygen
54+
.dispatchFetch('https://localhost:8000' as any)
55+
.then((d) => d.json() as Promise<any>)
56+
.then(({ flagValue, flagKey }) => {
5457
console.clear();
5558
printValueAndBanner(flagKey, flagValue);
56-
console.log('Press "q" or Ctrl+C to quit...')
57-
}).catch((err) => {
59+
console.log('Press "q" or Ctrl+C to quit...');
60+
})
61+
.catch((err) => {
5862
console.log('Error dispatching fetch:', err.message);
59-
console.log('Press "q" or Ctrl+C to quit...')
63+
console.log('Press "q" or Ctrl+C to quit...');
6064
});
6165
}, 1000);
62-
66+
6367
// Handle keypresses for cleanup
6468
process.stdin.setRawMode(true);
6569
process.stdin.resume();
6670
process.stdin.setEncoding('utf8');
67-
68-
process.stdin.on('data', async (key) => {
71+
72+
process.stdin.on('data', async (key: string) => {
6973
// Handle Ctrl+C
7074
if (key === '\u0003') {
7175
clearInterval(interval);
7276
await miniOxygen.dispose();
7377
process.exit();
7478
}
75-
79+
7680
// Handle 'q' key
7781
if (key === 'q' || key === 'Q') {
7882
clearInterval(interval);
@@ -81,6 +85,6 @@ const main = async () => {
8185
}
8286
});
8387
});
84-
}
88+
};
8589

8690
main().catch(console.error);

packages/sdk/shopify-oxygen/example/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"scripts": {
55
"build": "tsup",
66
"clean": "rm -rf dist",
7-
"start": "yarn clean && yarn build && yarn node app.js"
7+
"start": "yarn clean && yarn build && ts-node app.ts"
88
},
99
"type": "module",
1010
"dependencies": {
1111
"@launchdarkly/shopify-oxygen-sdk": "latest",
12-
"@shopify/mini-oxygen": "^4.0.0"
12+
"@shopify/mini-oxygen": "^4.0.0",
13+
"ts-node": "^10.9.2",
14+
"typescript": "^5.9.3"
1315
},
1416
"devDependencies": {
1517
"tsup": "^8.5.1"

0 commit comments

Comments
 (0)