@rork-ai/toolkit-sdk 0.2.25 → 0.2.27

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.
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Metro configuration helper for Rork
5
+ * Automatically wraps _layout.tsx with Rork providers
6
+ */
7
+ function withRorkMetro(config) {
8
+ return {
9
+ ...config,
10
+ transformer: {
11
+ ...config.transformer,
12
+ // Resolve the transformer path at runtime
13
+ // This will point to the transformer.js in the published package
14
+ babelTransformerPath: require.resolve('@rork-ai/toolkit-sdk/metro-transformer')
15
+ }
16
+ };
17
+ }
18
+ module.exports = {
19
+ withRorkMetro
20
+ };
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["withRorkMetro","config","transformer","babelTransformerPath","require","resolve","module","exports"],"sourceRoot":"../../../src","sources":["metro/index.js"],"mappings":";;AAAA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAACC,MAAM,EAAE;EAC7B,OAAO;IACL,GAAGA,MAAM;IACTC,WAAW,EAAE;MACX,GAAGD,MAAM,CAACC,WAAW;MACrB;MACA;MACAC,oBAAoB,EAAEC,OAAO,CAACC,OAAO,CAAC,wCAAwC;IAChF;EACF,CAAC;AACH;AAEAC,MAAM,CAACC,OAAO,GAAG;EAAEP;AAAc,CAAC","ignoreList":[]}
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Metro transformer that automatically wraps _layout.tsx with Rork providers
5
+ * Uses simple string transformations to inject wrappers
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ // Will be set after we dynamically require the upstream transformer
12
+ let upstreamTransformer = null;
13
+
14
+ /**
15
+ * Detects the Expo SDK version from package.json content
16
+ */
17
+ function detectExpoVersion() {
18
+ try {
19
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
20
+ if (fs.existsSync(packageJsonPath)) {
21
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
22
+ const dependencies = packageJson.dependencies || {};
23
+ const version = dependencies.expo;
24
+ if (version) {
25
+ // Remove ^ or ~ prefix
26
+ const cleanVersion = version.replace(/^[\^~]/, '');
27
+ if (cleanVersion.startsWith('54.')) return '54';
28
+ if (cleanVersion.startsWith('53.')) return '53';
29
+ }
30
+ }
31
+ } catch {
32
+ // Ignore parsing errors
33
+ }
34
+ return null;
35
+ }
36
+
37
+ /**
38
+ * Checks if the file is the root _layout.tsx
39
+ */
40
+ function isRootLayout(filename) {
41
+ return (filename.includes('app/_layout.tsx') || filename.includes('app/_layout.js')) && !filename.includes('app/(') // Exclude grouped layouts
42
+ ;
43
+ }
44
+
45
+ /**
46
+ * Wraps the layout component with Rork providers
47
+ */
48
+ function wrapLayoutWithProviders(src, environment) {
49
+ // Find the default export function
50
+ const defaultExportPattern = /export\s+default\s+function\s+(\w+)/;
51
+ const match = src.match(defaultExportPattern);
52
+ if (!match) {
53
+ return src; // Can't transform, return as-is
54
+ }
55
+ const originalFunctionName = match[1];
56
+
57
+ // Remove the default keyword from the original function
58
+ let transformed = src.replace(defaultExportPattern, `function ${originalFunctionName}`);
59
+ const wrappers = [];
60
+
61
+ // Add RorkDevWrapper for development environment
62
+ if (environment === 'development') {
63
+ // Detect Expo SDK version - default to v53 if not detected
64
+ const version = detectExpoVersion() || '53';
65
+ const devImport = version === '54' ? "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v54';" : "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v53';";
66
+ wrappers.push({
67
+ import: devImport,
68
+ name: 'RorkDevWrapper'
69
+ });
70
+ }
71
+
72
+ // Always add AnalyticsProvider
73
+ wrappers.push({
74
+ import: "import { AnalyticsProvider } from '@rork-ai/toolkit-sdk';",
75
+ name: 'AnalyticsProvider'
76
+ });
77
+
78
+ // Add wrapper imports at the top
79
+ for (const wrapper of wrappers) {
80
+ transformed = `${wrapper.import}\n${transformed}`;
81
+ }
82
+
83
+ // Create the wrapped component JSX
84
+ let wrappedComponent = `<${originalFunctionName} />`;
85
+ for (const wrapper of wrappers) {
86
+ wrappedComponent = `<${wrapper.name}>${wrappedComponent}</${wrapper.name}>`;
87
+ }
88
+
89
+ // Add new default export that wraps the original function
90
+ const newDefaultExport = `
91
+ export default function RorkRootLayoutWrapper() {
92
+ return (
93
+ ${wrappedComponent}
94
+ );
95
+ }
96
+ `;
97
+ transformed = transformed + '\n' + newDefaultExport;
98
+ return transformed;
99
+ }
100
+
101
+ /**
102
+ * Main transform function called by Metro
103
+ */
104
+ async function transform({
105
+ src,
106
+ filename,
107
+ options
108
+ }) {
109
+ // Lazy load upstream transformer
110
+ if (!upstreamTransformer) {
111
+ upstreamTransformer = require('@expo/metro-config/babel-transformer');
112
+ }
113
+
114
+ // Check if this is a root _layout file
115
+ if (isRootLayout(filename)) {
116
+ // Determine environment from options or default to production
117
+ const environment = options?.dev || process.env.NODE_ENV === 'development' ? 'development' : 'production';
118
+
119
+ // Transform the source code
120
+ const transformedSrc = wrapLayoutWithProviders(src, environment);
121
+
122
+ // Pass the transformed source to the upstream transformer
123
+ return upstreamTransformer.transform({
124
+ src: transformedSrc,
125
+ filename,
126
+ options
127
+ });
128
+ }
129
+
130
+ // For other files, use default transformer
131
+ return upstreamTransformer.transform({
132
+ src,
133
+ filename,
134
+ options
135
+ });
136
+ }
137
+
138
+ // Export the transform function
139
+ module.exports = {
140
+ transform
141
+ };
142
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["fs","require","path","upstreamTransformer","detectExpoVersion","packageJsonPath","join","process","cwd","existsSync","packageJson","JSON","parse","readFileSync","dependencies","version","expo","cleanVersion","replace","startsWith","isRootLayout","filename","includes","wrapLayoutWithProviders","src","environment","defaultExportPattern","match","originalFunctionName","transformed","wrappers","devImport","push","import","name","wrapper","wrappedComponent","newDefaultExport","transform","options","dev","env","NODE_ENV","transformedSrc","module","exports"],"sourceRoot":"../../../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pB;;AAEA;AACA;AACA;AACA,eAAeS,SAASA,CAAC;EAAEd,GAAG;EAAEH,QAAQ;EAAEkB;AAAQ,CAAC,EAAE;EACnD;EACA,IAAI,CAACpC,mBAAmB,EAAE;IACxBA,mBAAmB,GAAGF,OAAO,CAAC,sCAAsC,CAAC;EACvE;;EAEA;EACA,IAAImB,YAAY,CAACC,QAAQ,CAAC,EAAE;IAC1B;IACA,MAAMI,WAAW,GACfc,OAAO,EAAEC,GAAG,IAAIjC,OAAO,CAACkC,GAAG,CAACC,QAAQ,KAAK,aAAa,GAClD,aAAa,GACb,YAAY;;IAElB;IACA,MAAMC,cAAc,GAAGpB,uBAAuB,CAACC,GAAG,EAAEC,WAAW,CAAC;;IAEhE;IACA,OAAOtB,mBAAmB,CAACmC,SAAS,CAAC;MACnCd,GAAG,EAAEmB,cAAc;MACnBtB,QAAQ;MACRkB;IACF,CAAC,CAAC;EACJ;;EAEA;EACA,OAAOpC,mBAAmB,CAACmC,SAAS,CAAC;IAAEd,GAAG;IAAEH,QAAQ;IAAEkB;EAAQ,CAAC,CAAC;AAClE;;AAEA;AACAK,MAAM,CAACC,OAAO,GAAG;EAAEP;AAAU,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rork-ai/toolkit-sdk",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "description": "toolkit-sdk",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -11,6 +11,12 @@
11
11
  "default": "./lib/module/index.js"
12
12
  },
13
13
  "./package.json": "./package.json",
14
+ "./metro": {
15
+ "default": "./src/metro/index.js"
16
+ },
17
+ "./metro-transformer": {
18
+ "default": "./src/metro/transformer.js"
19
+ },
14
20
  "./v53": {
15
21
  "source": "./src/dev/sdk53/index.tsx",
16
22
  "types": "./lib/typescript/src/dev/sdk53/index.d.ts",
@@ -75,30 +81,30 @@
75
81
  "eslint-config-prettier": "^10.1.8",
76
82
  "eslint-plugin-prettier": "^5.5.4",
77
83
  "expo": "54.0.8",
84
+ "expo-blur": "15.0.7",
85
+ "expo-modules-core": "3.0.18",
78
86
  "expo-router": "6.0.14",
79
87
  "expo-web-browser": "15.0.9",
80
- "expo-modules-core": "3.0.18",
81
88
  "jest": "^29.7.0",
89
+ "lucide-react-native": "0.544.0",
82
90
  "prettier": "3.6.2",
83
91
  "react": "19.1.0",
84
92
  "react-native": "0.81.4",
85
93
  "react-native-builder-bob": "^0.40.13",
94
+ "react-native-safe-area-context": "~5.6.1",
86
95
  "typescript": "5.9.3",
87
- "zod": "4.1.12",
88
- "expo-blur": "15.0.7",
89
- "lucide-react-native": "0.544.0",
90
- "react-native-safe-area-context": "~5.6.1"
96
+ "zod": "4.1.12"
91
97
  },
92
98
  "peerDependencies": {
93
- "expo-blur": "*",
94
- "lucide-react-native": "*",
95
- "react-native-safe-area-context": "*",
96
99
  "@tanstack/react-query": "*",
97
100
  "expo": "*",
101
+ "expo-blur": "*",
98
102
  "expo-modules-core": "*",
99
103
  "expo-router": "*",
100
104
  "expo-web-browser": "*",
105
+ "lucide-react-native": "*",
101
106
  "react-native": "*",
107
+ "react-native-safe-area-context": "*",
102
108
  "zod": "^4"
103
109
  },
104
110
  "workspaces": [
@@ -143,11 +149,11 @@
143
149
  },
144
150
  "dependencies": {
145
151
  "@ai-sdk/react": "^2.0.89",
152
+ "@blazejkustra/react-native-alert": "^1.0.0",
146
153
  "@stardazed/streams-text-encoding": "^1.0.2",
147
154
  "@ungap/structured-clone": "^1.3.0",
148
155
  "ai": "5.0.93",
149
- "posthog-react-native": "^4.10.8",
150
- "@blazejkustra/react-native-alert": "^1.0.0"
156
+ "posthog-react-native": "^4.10.8"
151
157
  },
152
158
  "scripts": {
153
159
  "typecheck": "tsc",
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Metro configuration helper for Rork
3
+ * Automatically wraps _layout.tsx with Rork providers
4
+ */
5
+ function withRorkMetro(config) {
6
+ return {
7
+ ...config,
8
+ transformer: {
9
+ ...config.transformer,
10
+ // Resolve the transformer path at runtime
11
+ // This will point to the transformer.js in the published package
12
+ babelTransformerPath: require.resolve('@rork-ai/toolkit-sdk/metro-transformer'),
13
+ },
14
+ };
15
+ }
16
+
17
+ module.exports = { withRorkMetro };
18
+
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Metro transformer that automatically wraps _layout.tsx with Rork providers
3
+ * Uses simple string transformations to inject wrappers
4
+ */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+
9
+ // Will be set after we dynamically require the upstream transformer
10
+ let upstreamTransformer = null;
11
+
12
+ /**
13
+ * Detects the Expo SDK version from package.json content
14
+ */
15
+ function detectExpoVersion() {
16
+ try {
17
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
18
+ if (fs.existsSync(packageJsonPath)) {
19
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
20
+ const dependencies = packageJson.dependencies || {};
21
+ const version = dependencies.expo;
22
+
23
+ if (version) {
24
+ // Remove ^ or ~ prefix
25
+ const cleanVersion = version.replace(/^[\^~]/, '');
26
+ if (cleanVersion.startsWith('54.')) return '54';
27
+ if (cleanVersion.startsWith('53.')) return '53';
28
+ }
29
+ }
30
+ } catch {
31
+ // Ignore parsing errors
32
+ }
33
+ return null;
34
+ }
35
+
36
+ /**
37
+ * Checks if the file is the root _layout.tsx
38
+ */
39
+ function isRootLayout(filename) {
40
+ return (
41
+ (filename.includes('app/_layout.tsx') ||
42
+ filename.includes('app/_layout.js')) &&
43
+ !filename.includes('app/(') // Exclude grouped layouts
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Wraps the layout component with Rork providers
49
+ */
50
+ function wrapLayoutWithProviders(src, environment) {
51
+ // Find the default export function
52
+ const defaultExportPattern = /export\s+default\s+function\s+(\w+)/;
53
+ const match = src.match(defaultExportPattern);
54
+
55
+ if (!match) {
56
+ return src; // Can't transform, return as-is
57
+ }
58
+
59
+ const originalFunctionName = match[1];
60
+
61
+ // Remove the default keyword from the original function
62
+ let transformed = src.replace(
63
+ defaultExportPattern,
64
+ `function ${originalFunctionName}`
65
+ );
66
+
67
+ const wrappers = [];
68
+
69
+ // Add RorkDevWrapper for development environment
70
+ if (environment === 'development') {
71
+ // Detect Expo SDK version - default to v53 if not detected
72
+ const version = detectExpoVersion() || '53';
73
+ const devImport =
74
+ version === '54'
75
+ ? "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v54';"
76
+ : "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v53';";
77
+
78
+ wrappers.push({
79
+ import: devImport,
80
+ name: 'RorkDevWrapper',
81
+ });
82
+ }
83
+
84
+ // Always add AnalyticsProvider
85
+ wrappers.push({
86
+ import: "import { AnalyticsProvider } from '@rork-ai/toolkit-sdk';",
87
+ name: 'AnalyticsProvider',
88
+ });
89
+
90
+ // Add wrapper imports at the top
91
+ for (const wrapper of wrappers) {
92
+ transformed = `${wrapper.import}\n${transformed}`;
93
+ }
94
+
95
+ // Create the wrapped component JSX
96
+ let wrappedComponent = `<${originalFunctionName} />`;
97
+ for (const wrapper of wrappers) {
98
+ wrappedComponent = `<${wrapper.name}>${wrappedComponent}</${wrapper.name}>`;
99
+ }
100
+
101
+ // Add new default export that wraps the original function
102
+ const newDefaultExport = `
103
+ export default function RorkRootLayoutWrapper() {
104
+ return (
105
+ ${wrappedComponent}
106
+ );
107
+ }
108
+ `;
109
+
110
+ transformed = transformed + '\n' + newDefaultExport;
111
+
112
+ return transformed;
113
+ }
114
+
115
+ /**
116
+ * Main transform function called by Metro
117
+ */
118
+ async function transform({ src, filename, options }) {
119
+ // Lazy load upstream transformer
120
+ if (!upstreamTransformer) {
121
+ upstreamTransformer = require('@expo/metro-config/babel-transformer');
122
+ }
123
+
124
+ // Check if this is a root _layout file
125
+ if (isRootLayout(filename)) {
126
+ // Determine environment from options or default to production
127
+ const environment =
128
+ options?.dev || process.env.NODE_ENV === 'development'
129
+ ? 'development'
130
+ : 'production';
131
+
132
+ // Transform the source code
133
+ const transformedSrc = wrapLayoutWithProviders(src, environment);
134
+
135
+ // Pass the transformed source to the upstream transformer
136
+ return upstreamTransformer.transform({
137
+ src: transformedSrc,
138
+ filename,
139
+ options,
140
+ });
141
+ }
142
+
143
+ // For other files, use default transformer
144
+ return upstreamTransformer.transform({ src, filename, options });
145
+ }
146
+
147
+ // Export the transform function
148
+ module.exports = { transform };
149
+