@rork-ai/toolkit-sdk 0.2.25 → 0.2.26

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,138 @@
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
+ // Will be set after we dynamically require the upstream transformer
9
+ let upstreamTransformer = null;
10
+
11
+ /**
12
+ * Detects the Expo SDK version from package.json content
13
+ */
14
+ function detectExpoVersion(src) {
15
+ try {
16
+ const packageJsonMatch = src.match(/"expo":\s*"~?([\d.]+)"/);
17
+ if (packageJsonMatch && packageJsonMatch[1]) {
18
+ const version = packageJsonMatch[1];
19
+ if (version.startsWith('54.')) return '54';
20
+ if (version.startsWith('53.')) return '53';
21
+ }
22
+ } catch {
23
+ // Ignore parsing errors
24
+ }
25
+ return null;
26
+ }
27
+
28
+ /**
29
+ * Checks if the file is the root _layout.tsx
30
+ */
31
+ function isRootLayout(filename) {
32
+ return (filename.includes('app/_layout.tsx') || filename.includes('app/_layout.js')) && !filename.includes('app/(') // Exclude grouped layouts
33
+ ;
34
+ }
35
+
36
+ /**
37
+ * Wraps the layout component with Rork providers
38
+ */
39
+ function wrapLayoutWithProviders(src, environment) {
40
+ // Find the default export function
41
+ const defaultExportPattern = /export\s+default\s+function\s+(\w+)/;
42
+ const match = src.match(defaultExportPattern);
43
+ if (!match) {
44
+ return src; // Can't transform, return as-is
45
+ }
46
+ const originalFunctionName = match[1];
47
+
48
+ // Remove the default keyword from the original function
49
+ let transformed = src.replace(defaultExportPattern, `function ${originalFunctionName}`);
50
+ const wrappers = [];
51
+
52
+ // Add RorkDevWrapper for development environment
53
+ if (environment === 'development') {
54
+ // Detect Expo SDK version - default to v53 if not detected
55
+ const version = detectExpoVersion(src) || '53';
56
+ const devImport = version === '54' ? "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v54';" : "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v53';";
57
+ wrappers.push({
58
+ import: devImport,
59
+ name: 'RorkDevWrapper'
60
+ });
61
+ }
62
+
63
+ // Always add AnalyticsProvider
64
+ wrappers.push({
65
+ import: "import { AnalyticsProvider } from '@rork-ai/toolkit-sdk';",
66
+ name: 'AnalyticsProvider'
67
+ });
68
+
69
+ // Add wrapper imports at the top
70
+ for (const wrapper of wrappers) {
71
+ transformed = `${wrapper.import}\n${transformed}`;
72
+ }
73
+
74
+ // Create the wrapped component JSX
75
+ let wrappedComponent = `<${originalFunctionName} />`;
76
+ for (const wrapper of wrappers) {
77
+ wrappedComponent = `<${wrapper.name}>${wrappedComponent}</${wrapper.name}>`;
78
+ }
79
+
80
+ // Add new default export that wraps the original function
81
+ const newDefaultExport = `
82
+ export default function RorkRootLayoutWrapper() {
83
+ return (
84
+ ${wrappedComponent}
85
+ );
86
+ }
87
+ `;
88
+ transformed = transformed + '\n' + newDefaultExport;
89
+ return transformed;
90
+ }
91
+
92
+ /**
93
+ * Main transform function called by Metro
94
+ */
95
+ async function transform({
96
+ src,
97
+ filename,
98
+ options
99
+ }) {
100
+ // Lazy load upstream transformer
101
+ if (!upstreamTransformer) {
102
+ try {
103
+ upstreamTransformer = require('@expo/metro-config/babel-transformer');
104
+ } catch {
105
+ // Fallback to metro-react-native-babel-transformer
106
+ upstreamTransformer = require('metro-react-native-babel-transformer');
107
+ }
108
+ }
109
+
110
+ // Check if this is a root _layout file
111
+ if (isRootLayout(filename)) {
112
+ // Determine environment from options or default to production
113
+ const environment = options?.dev || process.env.NODE_ENV === 'development' ? 'development' : 'production';
114
+
115
+ // Transform the source code
116
+ const transformedSrc = wrapLayoutWithProviders(src, environment);
117
+
118
+ // Pass the transformed source to the upstream transformer
119
+ return upstreamTransformer.transform({
120
+ src: transformedSrc,
121
+ filename,
122
+ options
123
+ });
124
+ }
125
+
126
+ // For other files, use default transformer
127
+ return upstreamTransformer.transform({
128
+ src,
129
+ filename,
130
+ options
131
+ });
132
+ }
133
+
134
+ // Export the transform function
135
+ module.exports = {
136
+ transform
137
+ };
138
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["upstreamTransformer","detectExpoVersion","src","packageJsonMatch","match","version","startsWith","isRootLayout","filename","includes","wrapLayoutWithProviders","environment","defaultExportPattern","originalFunctionName","transformed","replace","wrappers","devImport","push","import","name","wrapper","wrappedComponent","newDefaultExport","transform","options","require","dev","process","env","NODE_ENV","transformedSrc","module","exports"],"sourceRoot":"../../../src","sources":["metro/transformer.js"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA;AACA,IAAIA,mBAAmB,GAAG,IAAI;;AAE9B;AACA;AACA;AACA,SAASC,iBAAiBA,CAACC,GAAG,EAAE;E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,CAAC;;IAEhE;IACA,OAAOX,mBAAmB,CAACwB,SAAS,CAAC;MACnCtB,GAAG,EAAE6B,cAAc;MACnBvB,QAAQ;MACRiB;IACF,CAAC,CAAC;EACJ;;EAEA;EACA,OAAOzB,mBAAmB,CAACwB,SAAS,CAAC;IAAEtB,GAAG;IAAEM,QAAQ;IAAEiB;EAAQ,CAAC,CAAC;AAClE;;AAEA;AACAO,MAAM,CAACC,OAAO,GAAG;EAAET;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.26",
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",
@@ -62,6 +68,7 @@
62
68
  "access": "public"
63
69
  },
64
70
  "devDependencies": {
71
+ "@babel/types": "^7.28.5",
65
72
  "@eslint/compat": "^1.3.2",
66
73
  "@eslint/eslintrc": "^3.3.1",
67
74
  "@eslint/js": "^9.35.0",
@@ -75,30 +82,30 @@
75
82
  "eslint-config-prettier": "^10.1.8",
76
83
  "eslint-plugin-prettier": "^5.5.4",
77
84
  "expo": "54.0.8",
85
+ "expo-blur": "15.0.7",
86
+ "expo-modules-core": "3.0.18",
78
87
  "expo-router": "6.0.14",
79
88
  "expo-web-browser": "15.0.9",
80
- "expo-modules-core": "3.0.18",
81
89
  "jest": "^29.7.0",
90
+ "lucide-react-native": "0.544.0",
82
91
  "prettier": "3.6.2",
83
92
  "react": "19.1.0",
84
93
  "react-native": "0.81.4",
85
94
  "react-native-builder-bob": "^0.40.13",
95
+ "react-native-safe-area-context": "~5.6.1",
86
96
  "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"
97
+ "zod": "4.1.12"
91
98
  },
92
99
  "peerDependencies": {
93
- "expo-blur": "*",
94
- "lucide-react-native": "*",
95
- "react-native-safe-area-context": "*",
96
100
  "@tanstack/react-query": "*",
97
101
  "expo": "*",
102
+ "expo-blur": "*",
98
103
  "expo-modules-core": "*",
99
104
  "expo-router": "*",
100
105
  "expo-web-browser": "*",
106
+ "lucide-react-native": "*",
101
107
  "react-native": "*",
108
+ "react-native-safe-area-context": "*",
102
109
  "zod": "^4"
103
110
  },
104
111
  "workspaces": [
@@ -143,11 +150,11 @@
143
150
  },
144
151
  "dependencies": {
145
152
  "@ai-sdk/react": "^2.0.89",
153
+ "@blazejkustra/react-native-alert": "^1.0.0",
146
154
  "@stardazed/streams-text-encoding": "^1.0.2",
147
155
  "@ungap/structured-clone": "^1.3.0",
148
156
  "ai": "5.0.93",
149
- "posthog-react-native": "^4.10.8",
150
- "@blazejkustra/react-native-alert": "^1.0.0"
157
+ "posthog-react-native": "^4.10.8"
151
158
  },
152
159
  "scripts": {
153
160
  "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,144 @@
1
+ /**
2
+ * Metro transformer that automatically wraps _layout.tsx with Rork providers
3
+ * Uses simple string transformations to inject wrappers
4
+ */
5
+
6
+ // Will be set after we dynamically require the upstream transformer
7
+ let upstreamTransformer = null;
8
+
9
+ /**
10
+ * Detects the Expo SDK version from package.json content
11
+ */
12
+ function detectExpoVersion(src) {
13
+ try {
14
+ const packageJsonMatch = src.match(/"expo":\s*"~?([\d.]+)"/);
15
+ if (packageJsonMatch && packageJsonMatch[1]) {
16
+ const version = packageJsonMatch[1];
17
+ if (version.startsWith('54.')) return '54';
18
+ if (version.startsWith('53.')) return '53';
19
+ }
20
+ } catch {
21
+ // Ignore parsing errors
22
+ }
23
+ return null;
24
+ }
25
+
26
+ /**
27
+ * Checks if the file is the root _layout.tsx
28
+ */
29
+ function isRootLayout(filename) {
30
+ return (
31
+ (filename.includes('app/_layout.tsx') ||
32
+ filename.includes('app/_layout.js')) &&
33
+ !filename.includes('app/(') // Exclude grouped layouts
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Wraps the layout component with Rork providers
39
+ */
40
+ function wrapLayoutWithProviders(src, environment) {
41
+ // Find the default export function
42
+ const defaultExportPattern = /export\s+default\s+function\s+(\w+)/;
43
+ const match = src.match(defaultExportPattern);
44
+
45
+ if (!match) {
46
+ return src; // Can't transform, return as-is
47
+ }
48
+
49
+ const originalFunctionName = match[1];
50
+
51
+ // Remove the default keyword from the original function
52
+ let transformed = src.replace(
53
+ defaultExportPattern,
54
+ `function ${originalFunctionName}`
55
+ );
56
+
57
+ const wrappers = [];
58
+
59
+ // Add RorkDevWrapper for development environment
60
+ if (environment === 'development') {
61
+ // Detect Expo SDK version - default to v53 if not detected
62
+ const version = detectExpoVersion(src) || '53';
63
+ const devImport =
64
+ version === '54'
65
+ ? "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v54';"
66
+ : "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v53';";
67
+
68
+ wrappers.push({
69
+ import: devImport,
70
+ name: 'RorkDevWrapper',
71
+ });
72
+ }
73
+
74
+ // Always add AnalyticsProvider
75
+ wrappers.push({
76
+ import: "import { AnalyticsProvider } from '@rork-ai/toolkit-sdk';",
77
+ name: 'AnalyticsProvider',
78
+ });
79
+
80
+ // Add wrapper imports at the top
81
+ for (const wrapper of wrappers) {
82
+ transformed = `${wrapper.import}\n${transformed}`;
83
+ }
84
+
85
+ // Create the wrapped component JSX
86
+ let wrappedComponent = `<${originalFunctionName} />`;
87
+ for (const wrapper of wrappers) {
88
+ wrappedComponent = `<${wrapper.name}>${wrappedComponent}</${wrapper.name}>`;
89
+ }
90
+
91
+ // Add new default export that wraps the original function
92
+ const newDefaultExport = `
93
+ export default function RorkRootLayoutWrapper() {
94
+ return (
95
+ ${wrappedComponent}
96
+ );
97
+ }
98
+ `;
99
+
100
+ transformed = transformed + '\n' + newDefaultExport;
101
+
102
+ return transformed;
103
+ }
104
+
105
+ /**
106
+ * Main transform function called by Metro
107
+ */
108
+ async function transform({ src, filename, options }) {
109
+ // Lazy load upstream transformer
110
+ if (!upstreamTransformer) {
111
+ try {
112
+ upstreamTransformer = require('@expo/metro-config/babel-transformer');
113
+ } catch {
114
+ // Fallback to metro-react-native-babel-transformer
115
+ upstreamTransformer = require('metro-react-native-babel-transformer');
116
+ }
117
+ }
118
+
119
+ // Check if this is a root _layout file
120
+ if (isRootLayout(filename)) {
121
+ // Determine environment from options or default to production
122
+ const environment =
123
+ options?.dev || process.env.NODE_ENV === 'development'
124
+ ? 'development'
125
+ : 'production';
126
+
127
+ // Transform the source code
128
+ const transformedSrc = wrapLayoutWithProviders(src, environment);
129
+
130
+ // Pass the transformed source to the upstream transformer
131
+ return upstreamTransformer.transform({
132
+ src: transformedSrc,
133
+ filename,
134
+ options,
135
+ });
136
+ }
137
+
138
+ // For other files, use default transformer
139
+ return upstreamTransformer.transform({ src, filename, options });
140
+ }
141
+
142
+ // Export the transform function
143
+ module.exports = { transform };
144
+