@inlang/sdk 2.7.0 → 2.9.0

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 (44) hide show
  1. package/dist/json-schema/settings.d.ts +0 -1
  2. package/dist/json-schema/settings.d.ts.map +1 -1
  3. package/dist/json-schema/settings.js +0 -5
  4. package/dist/json-schema/settings.js.map +1 -1
  5. package/dist/project/loadProject.d.ts +0 -9
  6. package/dist/project/loadProject.d.ts.map +1 -1
  7. package/dist/project/loadProject.js +0 -16
  8. package/dist/project/loadProject.js.map +1 -1
  9. package/dist/project/newProject.d.ts.map +1 -1
  10. package/dist/project/newProject.js +1 -6
  11. package/dist/project/newProject.js.map +1 -1
  12. package/dist/project/newProject.test.js +12 -0
  13. package/dist/project/newProject.test.js.map +1 -1
  14. package/dist/services/env-variables/index.d.ts +0 -1
  15. package/dist/services/env-variables/index.d.ts.map +1 -1
  16. package/dist/services/env-variables/index.js +1 -2
  17. package/dist/services/env-variables/index.js.map +1 -1
  18. package/package.json +4 -4
  19. package/src/json-schema/settings.ts +0 -10
  20. package/src/project/loadProject.ts +0 -28
  21. package/src/project/newProject.test.ts +16 -0
  22. package/src/project/newProject.ts +1 -6
  23. package/src/services/env-variables/createIndexFile.js +0 -1
  24. package/src/services/env-variables/index.d.ts +0 -1
  25. package/dist/project/maybeCaptureTelemetry.d.ts +0 -16
  26. package/dist/project/maybeCaptureTelemetry.d.ts.map +0 -1
  27. package/dist/project/maybeCaptureTelemetry.js +0 -61
  28. package/dist/project/maybeCaptureTelemetry.js.map +0 -1
  29. package/dist/project/maybeCaptureTelemetry.test.d.ts +0 -2
  30. package/dist/project/maybeCaptureTelemetry.test.d.ts.map +0 -1
  31. package/dist/project/maybeCaptureTelemetry.test.js +0 -69
  32. package/dist/project/maybeCaptureTelemetry.test.js.map +0 -1
  33. package/dist/services/telemetry/capture.d.ts +0 -24
  34. package/dist/services/telemetry/capture.d.ts.map +0 -1
  35. package/dist/services/telemetry/capture.js +0 -72
  36. package/dist/services/telemetry/capture.js.map +0 -1
  37. package/dist/services/telemetry/capture.test.d.ts +0 -2
  38. package/dist/services/telemetry/capture.test.d.ts.map +0 -1
  39. package/dist/services/telemetry/capture.test.js +0 -43
  40. package/dist/services/telemetry/capture.test.js.map +0 -1
  41. package/src/project/maybeCaptureTelemetry.test.ts +0 -80
  42. package/src/project/maybeCaptureTelemetry.ts +0 -77
  43. package/src/services/telemetry/capture.test.ts +0 -50
  44. package/src/services/telemetry/capture.ts +0 -98
@@ -23,7 +23,6 @@ export declare const ProjectSettings: import("@sinclair/typebox").TObject<{
23
23
  * ]
24
24
  */
25
25
  modules: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TString]>>>;
26
- telemetry: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TLiteral<"off">>;
27
26
  experimental: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TLiteral<true>>>;
28
27
  }>;
29
28
  //# sourceMappingURL=settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AA+FtD,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,MAAM,CAAC,OAAO,eAAe,CAAC,EAC9B,cAAc,GAAG,mBAAmB,CACpC,GAAG;IACH,mCAAmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACxB,eAAO,MAAM,eAAe;;;;;;IArE3B;;;;;;;;OAQG;;;;EA6DsC,CAAC"}
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAqFtD,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,MAAM,CAAC,OAAO,eAAe,CAAC,EAC9B,cAAc,GAAG,mBAAmB,CACpC,GAAG;IACH,mCAAmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;CAC5D,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACxB,eAAO,MAAM,eAAe;;;;;;IA3D3B;;;;;;;;OAQG;;;EAmDsC,CAAC"}
@@ -51,11 +51,6 @@ const SDKSettings = Type.Object({
51
51
  "./local-testing-plugin.js",
52
52
  ],
53
53
  })),
54
- telemetry: Type.Optional(Type.Union([
55
- Type.Literal("off", {
56
- description: "No telemetry events ",
57
- }),
58
- ], { description: "If not set, defaults to all" })),
59
54
  experimental: Type.Optional(Type.Record(Type.String(), Type.Literal(true), {
60
55
  title: "Experimental settings",
61
56
  description: "Experimental settings that are used for product development.",
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAC1D;IACD,UAAU,EAAE,IAAI,CAAC,MAAM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EAAE,CAC9C,CACD;IACD,YAAY,EAAE,IAAI,CAAC,QAAQ,CAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9C,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EACV,8DAA8D;KAC/D,CAAC,CACF;IACD;;;;OAIG;CACH,CAAC,CAAC;AAaH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC","sourcesContent":["import { type Static, Type } from \"@sinclair/typebox\";\n\nconst SDKSettings = Type.Object({\n\t// TODO SDK-v2 SETTINGS do we need to generate a settings v2 schema?\n\t$schema: Type.Optional(\n\t\tType.Literal(\"https://inlang.com/schema/project-settings\")\n\t),\n\tbaseLocale: Type.String({\n\t\ttitle: \"Base locale\",\n\t\tdescription:\n\t\t\t\"The base locale of the project. We recommend BCP-47 language tags.\",\n\t}),\n\tlocales: Type.Array(Type.String(), {\n\t\tuniqueItems: true,\n\t\ttitle: \"Project Locales\",\n\t\tdescription:\n\t\t\t\"Set the locales that are available in your project. All locales needs to be a valid BCP-47 language tag. Needs to include the base locale tag.\",\n\t}),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tsourceLanguageTag: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\n\t\t\tdeprecated: true,\n\t\t})\n\t),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tlanguageTags: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tuniqueItems: true,\n\t\t\tdeprecated: true,\n\t\t\tdescription:\n\t\t\t\t\"Use locales instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\n\t\t})\n\t),\n\t/**\n\t * The modules to load.\n\t *\n\t * @example\n\t * modules: [\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t * ]\n\t */\n\tmodules: Type.Optional(\n\t\tType.Array(\n\t\t\tType.Intersect([\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must be a valid URI according to RFC 3986.\",\n\t\t\t\t\tpattern:\n\t\t\t\t\t\t\"(?:[A-Za-z][A-Za-z0-9+.-]*:/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::([A-Za-z0-9-._~]?|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\\\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\\\\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:&|;[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?\",\n\t\t\t\t}),\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must end with `.js`.\",\n\t\t\t\t\tpattern: \".*\\\\.js$\",\n\t\t\t\t}),\n\t\t\t]),\n\t\t\t{\n\t\t\t\tuniqueItems: true,\n\t\t\t\tdescription:\n\t\t\t\t\t\"The modules to load. Must be a valid URI but can be relative.\",\n\t\t\t\texamples: [\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t\t\t\t\t\"./local-testing-plugin.js\",\n\t\t\t\t],\n\t\t\t}\n\t\t)\n\t),\n\ttelemetry: Type.Optional(\n\t\tType.Union(\n\t\t\t[\n\t\t\t\tType.Literal(\"off\", {\n\t\t\t\t\tdescription: \"No telemetry events \",\n\t\t\t\t}),\n\t\t\t],\n\t\t\t{ description: \"If not set, defaults to all\" }\n\t\t)\n\t),\n\texperimental: Type.Optional(\n\t\tType.Record(Type.String(), Type.Literal(true), {\n\t\t\ttitle: \"Experimental settings\",\n\t\t\tdescription:\n\t\t\t\t\"Experimental settings that are used for product development.\",\n\t\t})\n\t),\n\t/**\n\t * plugin.*: JSONObject\n\t *\n\t * The plugin settings are validated when importing plugins\n\t */\n});\n\nexport type ProjectSettings = Omit<\n\tStatic<typeof ProjectSettings>,\n\t\"languageTags\" | \"sourceLanguageTag\"\n> & {\n\t/** @deprecated Use `baseLocale` */\n\tsourceLanguageTag?: string;\n\t/** @deprecated Use `locales` */\n\tlanguageTags?: string[];\n\t/** @deprecated This will soon be replaced by `Lix Validation Rules` */\n\tmessageLintRuleLevels?: Record<string, \"error\" | \"warning\">;\n} & Record<string, any>;\nexport const ProjectSettings = SDKSettings;\n"]}
1
+ {"version":3,"file":"settings.js","sourceRoot":"/","sources":["json-schema/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,oEAAoE;IACpE,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAC1D;IACD,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACvB,KAAK,EAAE,aAAa;QACpB,WAAW,EACV,oEAAoE;KACrE,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QAClC,WAAW,EAAE,IAAI;QACjB,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACV,gJAAgJ;KACjJ,CAAC;IACF,oCAAoC;IACpC,mBAAmB;IACnB,iBAAiB,EAAE,IAAI,CAAC,QAAQ,CAC/B,IAAI,CAAC,MAAM,CAAC;QACX,WAAW,EACV,gIAAgI;QACjI,UAAU,EAAE,IAAI;KAChB,CAAC,CACF;IACD,oCAAoC;IACpC,mBAAmB;IACnB,YAAY,EAAE,IAAI,CAAC,QAAQ,CAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACzB,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,IAAI;QAChB,WAAW,EACV,6HAA6H;KAC9H,CAAC,CACF;IACD;;;;;;;;OAQG;IACH,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,KAAK,CACT,IAAI,CAAC,SAAS,CAAC;QACd,IAAI,CAAC,MAAM,CAAC;YACX,WAAW,EAAE,uDAAuD;YACpE,OAAO,EACN,sZAAsZ;SACvZ,CAAC;QACF,IAAI,CAAC,MAAM,CAAC;YACX,WAAW,EAAE,iCAAiC;YAC9C,OAAO,EAAE,UAAU;SACnB,CAAC;KACF,CAAC,EACF;QACC,WAAW,EAAE,IAAI;QACjB,WAAW,EACV,+DAA+D;QAChE,QAAQ,EAAE;YACT,qEAAqE;YACrE,iEAAiE;YACjE,2BAA2B;SAC3B;KACD,CACD,CACD;IACD,YAAY,EAAE,IAAI,CAAC,QAAQ,CAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9C,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EACV,8DAA8D;KAC/D,CAAC,CACF;IACD;;;;OAIG;CACH,CAAC,CAAC;AAaH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC","sourcesContent":["import { type Static, Type } from \"@sinclair/typebox\";\n\nconst SDKSettings = Type.Object({\n\t// TODO SDK-v2 SETTINGS do we need to generate a settings v2 schema?\n\t$schema: Type.Optional(\n\t\tType.Literal(\"https://inlang.com/schema/project-settings\")\n\t),\n\tbaseLocale: Type.String({\n\t\ttitle: \"Base locale\",\n\t\tdescription:\n\t\t\t\"The base locale of the project. We recommend BCP-47 language tags.\",\n\t}),\n\tlocales: Type.Array(Type.String(), {\n\t\tuniqueItems: true,\n\t\ttitle: \"Project Locales\",\n\t\tdescription:\n\t\t\t\"Set the locales that are available in your project. All locales needs to be a valid BCP-47 language tag. Needs to include the base locale tag.\",\n\t}),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tsourceLanguageTag: Type.Optional(\n\t\tType.String({\n\t\t\tdescription:\n\t\t\t\t\"Use baseLocale instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\n\t\t\tdeprecated: true,\n\t\t})\n\t),\n\t// exits for backwards compatibility\n\t// remove in SDK-v3\n\tlanguageTags: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tuniqueItems: true,\n\t\t\tdeprecated: true,\n\t\t\tdescription:\n\t\t\t\t\"Use locales instead if all your inlang apps that you are using are on the inlang SDK V2. Otherwise, leave this property in.\",\n\t\t})\n\t),\n\t/**\n\t * The modules to load.\n\t *\n\t * @example\n\t * modules: [\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t * \t \"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t * ]\n\t */\n\tmodules: Type.Optional(\n\t\tType.Array(\n\t\t\tType.Intersect([\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must be a valid URI according to RFC 3986.\",\n\t\t\t\t\tpattern:\n\t\t\t\t\t\t\"(?:[A-Za-z][A-Za-z0-9+.-]*:/{2})?(?:(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})+(?::([A-Za-z0-9-._~]?|[%][A-Fa-f0-9]{2})+)?@)?(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\\\.){1,126}[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?::[0-9]+)?(?:/(?:[A-Za-z0-9-._~]|%[A-Fa-f0-9]{2})*)*(?:\\\\?(?:[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)(?:&|;[A-Za-z0-9-._~]+(?:=(?:[A-Za-z0-9-._~+]|%[A-Fa-f0-9]{2})+)?)*)?\",\n\t\t\t\t}),\n\t\t\t\tType.String({\n\t\t\t\t\tdescription: \"The module must end with `.js`.\",\n\t\t\t\t\tpattern: \".*\\\\.js$\",\n\t\t\t\t}),\n\t\t\t]),\n\t\t\t{\n\t\t\t\tuniqueItems: true,\n\t\t\t\tdescription:\n\t\t\t\t\t\"The modules to load. Must be a valid URI but can be relative.\",\n\t\t\t\texamples: [\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-i18next@3/dist/index.js\",\n\t\t\t\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-csv@1/dist/index.js\",\n\t\t\t\t\t\"./local-testing-plugin.js\",\n\t\t\t\t],\n\t\t\t}\n\t\t)\n\t),\n\texperimental: Type.Optional(\n\t\tType.Record(Type.String(), Type.Literal(true), {\n\t\t\ttitle: \"Experimental settings\",\n\t\t\tdescription:\n\t\t\t\t\"Experimental settings that are used for product development.\",\n\t\t})\n\t),\n\t/**\n\t * plugin.*: JSONObject\n\t *\n\t * The plugin settings are validated when importing plugins\n\t */\n});\n\nexport type ProjectSettings = Omit<\n\tStatic<typeof ProjectSettings>,\n\t\"languageTags\" | \"sourceLanguageTag\"\n> & {\n\t/** @deprecated Use `baseLocale` */\n\tsourceLanguageTag?: string;\n\t/** @deprecated Use `locales` */\n\tlanguageTags?: string[];\n\t/** @deprecated This will soon be replaced by `Lix Validation Rules` */\n\tmessageLintRuleLevels?: Record<string, \"error\" | \"warning\">;\n} & Record<string, any>;\nexport const ProjectSettings = SDKSettings;\n"]}
@@ -40,14 +40,5 @@ export declare function loadProject(args: {
40
40
  *
41
41
  */
42
42
  preprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;
43
- /**
44
- * The id of the app that is using the SDK.
45
- *
46
- * The is used for telemetry purposes. To derive insights like
47
- * which app is using the SDK, how many projects are loaded, etc.
48
- *
49
- * The app id can be removed at any time in the future
50
- */
51
- appId?: string;
52
43
  }): Promise<InlangProject>;
53
44
  //# sourceMappingURL=loadProject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadProject.d.ts","sourceRoot":"/","sources":["project/loadProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAEN,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEN,KAAK,oCAAoC,EACzC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAO9C;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC;;;;;;;;;;;OAWG;IACH,4BAA4B,CAAC,EAAE,oCAAoC,CAAC;IACpE;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,aAAa,CAAC,CAiJzB"}
1
+ {"version":3,"file":"loadProject.d.ts","sourceRoot":"/","sources":["project/loadProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAEN,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEN,KAAK,oCAAoC,EACzC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAM9C;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACvC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC;;;;;;;;;;;OAWG;IACH,4BAA4B,CAAC,EAAE,oCAAoC,CAAC;CACpE,GAAG,OAAO,CAAC,aAAa,CAAC,CA+HzB"}
@@ -4,7 +4,6 @@ import { initDb } from "../database/initDb.js";
4
4
  import { importPlugins, } from "../plugin/importPlugins.js";
5
5
  import { withLanguageTagToLocaleMigration } from "../migrations/v2/withLanguageTagToLocaleMigration.js";
6
6
  import { v4 } from "uuid";
7
- import { maybeCaptureLoadedProject } from "./maybeCaptureTelemetry.js";
8
7
  import { importFiles } from "../import-export/importFiles.js";
9
8
  import { exportFiles } from "../import-export/exportFiles.js";
10
9
  /**
@@ -25,25 +24,10 @@ export async function loadProject(args) {
25
24
  preprocessPluginBeforeImport: args.preprocessPluginBeforeImport,
26
25
  });
27
26
  const plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];
28
- const idFile = await args.lix.db
29
- .selectFrom("file")
30
- .where("path", "=", "/project_id")
31
- .select("data")
32
- .executeTakeFirstOrThrow();
33
- const id = new TextDecoder().decode(idFile.data);
34
27
  // const state = createProjectState({
35
28
  // ...args,
36
29
  // settings,
37
30
  // });
38
- // not awaiting to not block the load time of a project
39
- maybeCaptureLoadedProject({
40
- db,
41
- id,
42
- settings,
43
- plugins,
44
- lix: args.lix,
45
- appId: args.appId,
46
- });
47
31
  return {
48
32
  db,
49
33
  id: {
@@ -1 +1 @@
1
- {"version":3,"file":"loadProject.js","sourceRoot":"/","sources":["project/loadProject.ts"],"names":[],"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AAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1D,OAAO,MAAM,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACxC,CAAC;QACD,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,IAG1B;IACA,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;SACf,WAAW,CAAC,MAAM,CAAC;SACnB,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;SACjB,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC;SAChC,OAAO,EAAE,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAkB;IAC3D,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;SAC1C,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC;SACd,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC;SACjC,gBAAgB,EAAE,CAAC;IAErB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACzB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;aACf,UAAU,CAAC,MAAM,CAAC;aAClB,MAAM,CAAC;YACP,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;SACpC,CAAC;aACD,OAAO,EAAE,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["import { toBlob, type Account, type Lix } from \"@lix-js/sdk\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport {\n\tcontentFromDatabase,\n\ttype SqliteWasmDatabase,\n} from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport {\n\timportPlugins,\n\ttype PreprocessPluginBeforeImportFunction,\n} from \"../plugin/importPlugins.js\";\nimport type { InlangProject } from \"./api.js\";\nimport { withLanguageTagToLocaleMigration } from \"../migrations/v2/withLanguageTagToLocaleMigration.js\";\nimport { v4 } from \"uuid\";\nimport { maybeCaptureLoadedProject } from \"./maybeCaptureTelemetry.js\";\nimport { importFiles } from \"../import-export/importFiles.js\";\nimport { exportFiles } from \"../import-export/exportFiles.js\";\n\n/**\n * Common load project logic.\n */\nexport async function loadProject(args: {\n\tsqlite: SqliteWasmDatabase;\n\tlix: Lix;\n\t/**\n\t * The account that loaded the project.\n\t *\n\t * Defaults to an anonymous/new account if undefined.\n\t *\n\t * @example\n\t * const account = localStorage.getItem(\"account\")\n\t * const project = await loadProject({ account })\n\t */\n\taccount?: Account;\n\t/**\n\t * Provide plugins to the project.\n\t *\n\t * This is useful for testing or providing plugins that are\n\t * app specific. Keep in mind that provided plugins\n\t * are not shared with other instances.\n\t */\n\tprovidePlugins?: InlangPlugin[];\n\t/**\n\t * Function that preprocesses the plugin before importing it.\n\t *\n\t * The callback can be used to process plugins as needed in the\n\t * environment of the app. For example, Sherlock uses this to convert\n\t * ESM, which all inlang plugins are written in, to CJS which Sherlock\n\t * runs in.\n\t *\n\t * @example\n\t * const project = await loadProject({ preprocessPluginBeforeImport: (moduleText) => convertEsmToCjs(moduleText) })\n\t *\n\t */\n\tpreprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;\n\t/**\n\t * The id of the app that is using the SDK.\n\t *\n\t * The is used for telemetry purposes. To derive insights like\n\t * which app is using the SDK, how many projects are loaded, etc.\n\t *\n\t * The app id can be removed at any time in the future\n\t */\n\tappId?: string;\n}): Promise<InlangProject> {\n\tconst db = initDb({ sqlite: args.sqlite });\n\n\tawait maybeMigrateFirstProjectId({ lix: args.lix });\n\n\tconst settingsFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst settings = withLanguageTagToLocaleMigration(\n\t\tJSON.parse(new TextDecoder().decode(settingsFile.data)) as ProjectSettings\n\t);\n\n\tconst importedPlugins = await importPlugins({\n\t\tsettings,\n\t\tlix: args.lix,\n\t\tpreprocessPluginBeforeImport: args.preprocessPluginBeforeImport,\n\t});\n\n\tconst plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];\n\n\tconst idFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.select(\"data\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst id = new TextDecoder().decode(idFile.data);\n\n\t// const state = createProjectState({\n\t// \t...args,\n\t// \tsettings,\n\t// });\n\n\t// not awaiting to not block the load time of a project\n\tmaybeCaptureLoadedProject({\n\t\tdb,\n\t\tid,\n\t\tsettings,\n\t\tplugins,\n\t\tlix: args.lix,\n\t\tappId: args.appId,\n\t});\n\n\treturn {\n\t\tdb,\n\t\tid: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn new TextDecoder().decode(file.data);\n\t\t\t},\n\t\t},\n\t\tsettings: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn withLanguageTagToLocaleMigration(\n\t\t\t\t\tJSON.parse(new TextDecoder().decode(file.data))\n\t\t\t\t);\n\t\t\t},\n\t\t\tset: async (newSettings) => {\n\t\t\t\tconst cloned = JSON.parse(JSON.stringify(newSettings));\n\t\t\t\tcloned.languageTags = cloned.locales;\n\t\t\t\tcloned.sourceLanguageTag = cloned.baseLocale;\n\n\t\t\t\tawait args.lix.db\n\t\t\t\t\t.updateTable(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.set({\n\t\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\t\tJSON.stringify(cloned, undefined, 2)\n\t\t\t\t\t\t),\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t},\n\t\t},\n\t\tplugins: {\n\t\t\tget: async () => plugins,\n\t\t},\n\t\terrors: {\n\t\t\tget: async () => [...importedPlugins.errors],\n\t\t},\n\t\t// errors: state.errors,\n\t\timportFiles: async ({ files, pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn await importFiles({\n\t\t\t\tfiles,\n\t\t\t\tpluginKey,\n\t\t\t\tsettings,\n\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\tplugins,\n\t\t\t\tdb,\n\t\t\t});\n\t\t},\n\t\texportFiles: async ({ pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn (\n\t\t\t\tawait exportFiles({\n\t\t\t\t\tpluginKey,\n\t\t\t\t\tdb,\n\t\t\t\t\tsettings,\n\t\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\t\tplugins,\n\t\t\t\t})\n\t\t\t).map((output) => ({ ...output, pluginKey }));\n\t\t},\n\t\tclose: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\tawait db.destroy();\n\t\t\tawait args.lix.db.destroy();\n\t\t},\n\t\t_sqlite: args.sqlite,\n\t\ttoBlob: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\treturn await toBlob({ lix: args.lix });\n\t\t},\n\t\tlix: args.lix,\n\t};\n}\n\nasync function saveDbToLix(args: {\n\tsqlite: SqliteWasmDatabase;\n\tlix: Lix;\n}): Promise<void> {\n\tconst data = contentFromDatabase(args.sqlite);\n\tawait args.lix.db\n\t\t.updateTable(\"file\")\n\t\t.set(\"data\", data)\n\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t.execute();\n}\n\n/**\n * Old leftover migration from v1. Probably not needed anymore.\n *\n * Kept it in just in case.\n */\nasync function maybeMigrateFirstProjectId(args: { lix: Lix }): Promise<void> {\n\tconst firstProjectIdFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.executeTakeFirst();\n\n\tif (!firstProjectIdFile) {\n\t\tawait args.lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values({\n\t\t\t\tpath: \"/project_id\",\n\t\t\t\tdata: new TextEncoder().encode(v4()),\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"]}
1
+ {"version":3,"file":"loadProject.js","sourceRoot":"/","sources":["project/loadProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA0B,MAAM,aAAa,CAAC;AAG7D,OAAO,EACN,mBAAmB,GAEnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB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AE;SAC1C,UAAU,CAAC,MAAM,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC;SACd,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC;SACjC,gBAAgB,EAAE,CAAC;IAErB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACzB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE;aACf,UAAU,CAAC,MAAM,CAAC;aAClB,MAAM,CAAC;YACP,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;SACpC,CAAC;aACD,OAAO,EAAE,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["import { toBlob, type Account, type Lix } from \"@lix-js/sdk\";\nimport type { InlangPlugin } from \"../plugin/schema.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport {\n\tcontentFromDatabase,\n\ttype SqliteWasmDatabase,\n} from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\nimport {\n\timportPlugins,\n\ttype PreprocessPluginBeforeImportFunction,\n} from \"../plugin/importPlugins.js\";\nimport type { InlangProject } from \"./api.js\";\nimport { withLanguageTagToLocaleMigration } from \"../migrations/v2/withLanguageTagToLocaleMigration.js\";\nimport { v4 } from \"uuid\";\nimport { importFiles } from \"../import-export/importFiles.js\";\nimport { exportFiles } from \"../import-export/exportFiles.js\";\n\n/**\n * Common load project logic.\n */\nexport async function loadProject(args: {\n\tsqlite: SqliteWasmDatabase;\n\tlix: Lix;\n\t/**\n\t * The account that loaded the project.\n\t *\n\t * Defaults to an anonymous/new account if undefined.\n\t *\n\t * @example\n\t * const account = localStorage.getItem(\"account\")\n\t * const project = await loadProject({ account })\n\t */\n\taccount?: Account;\n\t/**\n\t * Provide plugins to the project.\n\t *\n\t * This is useful for testing or providing plugins that are\n\t * app specific. Keep in mind that provided plugins\n\t * are not shared with other instances.\n\t */\n\tprovidePlugins?: InlangPlugin[];\n\t/**\n\t * Function that preprocesses the plugin before importing it.\n\t *\n\t * The callback can be used to process plugins as needed in the\n\t * environment of the app. For example, Sherlock uses this to convert\n\t * ESM, which all inlang plugins are written in, to CJS which Sherlock\n\t * runs in.\n\t *\n\t * @example\n\t * const project = await loadProject({ preprocessPluginBeforeImport: (moduleText) => convertEsmToCjs(moduleText) })\n\t *\n\t */\n\tpreprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;\n}): Promise<InlangProject> {\n\tconst db = initDb({ sqlite: args.sqlite });\n\n\tawait maybeMigrateFirstProjectId({ lix: args.lix });\n\n\tconst settingsFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst settings = withLanguageTagToLocaleMigration(\n\t\tJSON.parse(new TextDecoder().decode(settingsFile.data)) as ProjectSettings\n\t);\n\n\tconst importedPlugins = await importPlugins({\n\t\tsettings,\n\t\tlix: args.lix,\n\t\tpreprocessPluginBeforeImport: args.preprocessPluginBeforeImport,\n\t});\n\n\tconst plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];\n\n\t// const state = createProjectState({\n\t// \t...args,\n\t// \tsettings,\n\t// });\n\n\treturn {\n\t\tdb,\n\t\tid: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn new TextDecoder().decode(file.data);\n\t\t\t},\n\t\t},\n\t\tsettings: {\n\t\t\tget: async () => {\n\t\t\t\tconst file = await args.lix.db\n\t\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.select(\"file.data\")\n\t\t\t\t\t.executeTakeFirstOrThrow();\n\t\t\t\treturn withLanguageTagToLocaleMigration(\n\t\t\t\t\tJSON.parse(new TextDecoder().decode(file.data))\n\t\t\t\t);\n\t\t\t},\n\t\t\tset: async (newSettings) => {\n\t\t\t\tconst cloned = JSON.parse(JSON.stringify(newSettings));\n\t\t\t\tcloned.languageTags = cloned.locales;\n\t\t\t\tcloned.sourceLanguageTag = cloned.baseLocale;\n\n\t\t\t\tawait args.lix.db\n\t\t\t\t\t.updateTable(\"file\")\n\t\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t\t.set({\n\t\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\t\tJSON.stringify(cloned, undefined, 2)\n\t\t\t\t\t\t),\n\t\t\t\t\t})\n\t\t\t\t\t.execute();\n\t\t\t},\n\t\t},\n\t\tplugins: {\n\t\t\tget: async () => plugins,\n\t\t},\n\t\terrors: {\n\t\t\tget: async () => [...importedPlugins.errors],\n\t\t},\n\t\t// errors: state.errors,\n\t\timportFiles: async ({ files, pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn await importFiles({\n\t\t\t\tfiles,\n\t\t\t\tpluginKey,\n\t\t\t\tsettings,\n\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\tplugins,\n\t\t\t\tdb,\n\t\t\t});\n\t\t},\n\t\texportFiles: async ({ pluginKey }) => {\n\t\t\tconst settingsFile = await args.lix.db\n\t\t\t\t.selectFrom(\"file\")\n\t\t\t\t.where(\"path\", \"=\", \"/settings.json\")\n\t\t\t\t.select(\"file.data\")\n\t\t\t\t.executeTakeFirstOrThrow();\n\n\t\t\tconst settings = JSON.parse(\n\t\t\t\tnew TextDecoder().decode(settingsFile.data)\n\t\t\t) as ProjectSettings;\n\n\t\t\treturn (\n\t\t\t\tawait exportFiles({\n\t\t\t\t\tpluginKey,\n\t\t\t\t\tdb,\n\t\t\t\t\tsettings,\n\t\t\t\t\t// TODO don't use global state, might be stale\n\t\t\t\t\tplugins,\n\t\t\t\t})\n\t\t\t).map((output) => ({ ...output, pluginKey }));\n\t\t},\n\t\tclose: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\tawait db.destroy();\n\t\t\tawait args.lix.db.destroy();\n\t\t},\n\t\t_sqlite: args.sqlite,\n\t\ttoBlob: async () => {\n\t\t\tawait saveDbToLix({ sqlite: args.sqlite, lix: args.lix });\n\t\t\treturn await toBlob({ lix: args.lix });\n\t\t},\n\t\tlix: args.lix,\n\t};\n}\n\nasync function saveDbToLix(args: {\n\tsqlite: SqliteWasmDatabase;\n\tlix: Lix;\n}): Promise<void> {\n\tconst data = contentFromDatabase(args.sqlite);\n\tawait args.lix.db\n\t\t.updateTable(\"file\")\n\t\t.set(\"data\", data)\n\t\t.where(\"path\", \"=\", \"/db.sqlite\")\n\t\t.execute();\n}\n\n/**\n * Old leftover migration from v1. Probably not needed anymore.\n *\n * Kept it in just in case.\n */\nasync function maybeMigrateFirstProjectId(args: { lix: Lix }): Promise<void> {\n\tconst firstProjectIdFile = await args.lix.db\n\t\t.selectFrom(\"file\")\n\t\t.select(\"data\")\n\t\t.where(\"path\", \"=\", \"/project_id\")\n\t\t.executeTakeFirst();\n\n\tif (!firstProjectIdFile) {\n\t\tawait args.lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values({\n\t\t\t\tpath: \"/project_id\",\n\t\t\t\tdata: new TextEncoder().encode(v4()),\n\t\t\t})\n\t\t\t.execute();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"newProject.d.ts","sourceRoot":"/","sources":["project/newProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAOlE;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE;IACvC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAyDhB;AAED,eAAO,MAAM,sBAAsB;;;;;CAcR,CAAC"}
1
+ {"version":3,"file":"newProject.d.ts","sourceRoot":"/","sources":["project/newProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAOlE;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,CAAC,EAAE;IACvC,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC3B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoDhB;AAED,eAAO,MAAM,sBAAsB;;;;;CAcR,CAAC"}
@@ -14,12 +14,7 @@ export async function newProject(args) {
14
14
  initDb({ sqlite });
15
15
  try {
16
16
  const inlangDbContent = contentFromDatabase(sqlite);
17
- const lix = await openLixInMemory({
18
- blob: await newLixFile(),
19
- keyValues: [
20
- { key: "lix_telemetry", value: args?.settings?.telemetry ?? "on" },
21
- ],
22
- });
17
+ const lix = await openLixInMemory({ blob: await newLixFile() });
23
18
  const { value: lixId } = await lix.db
24
19
  .selectFrom("key_value")
25
20
  .select("value")
@@ -1 +1 @@
1
- {"version":3,"file":"newProject.js","sourceRoot":"/","sources":["project/newProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EACN,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAEhC;IACA,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC;QAC3C,QAAQ,EAAE,KAAK;KACf,CAAC,C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G,IAAI,KAAK,CAAC,wCAAwC,CAAC,EAAE,EAAE;YACpE,KAAK,EAAE,CAAC;SACR,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACb,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,OAAO,EAAE,4CAA4C;IACrD,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,OAAO,EAAE;IACR,uDAAuD;IACvD,+FAA+F;IAC/F,qGAAqG;IACrG,gGAAgG;IAChG,wEAAwE;IACxE,qFAAqF;IACrF,wGAAwG;IACxG,yFAAyF;KACzF;CACyB,CAAC","sourcesContent":["import { newLixFile, openLixInMemory, toBlob } from \"@lix-js/sdk\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport {\n\tcontentFromDatabase,\n\tcreateInMemoryDatabase,\n} from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\n\n/**\n * Creates a new inlang project.\n *\n * The app is responsible for saving the project \"whereever\"\n * e.g. the user's computer, cloud storage, or OPFS in the browser.\n */\nexport async function newProject(args?: {\n\tsettings?: ProjectSettings;\n}): Promise<Blob> {\n\tconst sqlite = await createInMemoryDatabase({\n\t\treadOnly: false,\n\t});\n\tinitDb({ sqlite });\n\n\ttry {\n\t\tconst inlangDbContent = contentFromDatabase(sqlite);\n\n\t\tconst lix = await openLixInMemory({\n\t\t\tblob: await newLixFile(),\n\t\t\tkeyValues: [\n\t\t\t\t{ key: \"lix_telemetry\", value: args?.settings?.telemetry ?? \"on\" },\n\t\t\t],\n\t\t});\n\n\t\tconst { value: lixId } = await lix.db\n\t\t\t.selectFrom(\"key_value\")\n\t\t\t.select(\"value\")\n\t\t\t.where(\"key\", \"=\", \"lix_id\")\n\t\t\t.executeTakeFirstOrThrow();\n\n\t\t// write files to lix\n\t\tawait lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values([\n\t\t\t\t{\n\t\t\t\t\tpath: \"/db.sqlite\",\n\t\t\t\t\tdata: inlangDbContent,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tpath: \"/settings.json\",\n\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\targs?.settings ?? defaultProjectSettings,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t2\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tpath: \"/project_id\",\n\t\t\t\t\tdata: new TextEncoder().encode(lixId),\n\t\t\t\t},\n\t\t\t])\n\t\t\t.execute();\n\t\tconst blob = toBlob({ lix });\n\t\tlix.sqlite.close();\n\t\treturn blob;\n\t} catch (e) {\n\t\tconst error = new Error(`Failed to create new inlang project: ${e}`, {\n\t\t\tcause: e,\n\t\t});\n\t\tthrow error;\n\t} finally {\n\t\tsqlite.close();\n\t}\n}\n\nexport const defaultProjectSettings = {\n\t$schema: \"https://inlang.com/schema/project-settings\",\n\tbaseLocale: \"en\",\n\tlocales: [\"en\"],\n\tmodules: [\n\t\t// for instant gratification, we're adding common rules\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-empty-pattern@latest/dist/index.js\",\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-missing-translation@latest/dist/index.js\",\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-without-source@latest/dist/index.js\",\n\t\t// default to the message format plugin because it supports all features\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js\",\n\t\t// the m function matcher should be installed by default in case Sherlock (VS Code extension) is adopted\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@latest/dist/index.js\",\n\t],\n} satisfies ProjectSettings;\n"]}
1
+ {"version":3,"file":"newProject.js","sourceRoot":"/","s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CAAC;aACrC;SACD,CAAC;aACD,OAAO,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7B,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,wCAAwC,CAAC,EAAE,EAAE;YACpE,KAAK,EAAE,CAAC;SACR,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACb,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,OAAO,EAAE,4CAA4C;IACrD,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,OAAO,EAAE;IACR,uDAAuD;IACvD,+FAA+F;IAC/F,qGAAqG;IACrG,gGAAgG;IAChG,wEAAwE;IACxE,qFAAqF;IACrF,wGAAwG;IACxG,yFAAyF;KACzF;CACyB,CAAC","sourcesContent":["import { newLixFile, openLixInMemory, toBlob } from \"@lix-js/sdk\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport {\n\tcontentFromDatabase,\n\tcreateInMemoryDatabase,\n} from \"sqlite-wasm-kysely\";\nimport { initDb } from \"../database/initDb.js\";\n\n/**\n * Creates a new inlang project.\n *\n * The app is responsible for saving the project \"whereever\"\n * e.g. the user's computer, cloud storage, or OPFS in the browser.\n */\nexport async function newProject(args?: {\n\tsettings?: ProjectSettings;\n}): Promise<Blob> {\n\tconst sqlite = await createInMemoryDatabase({\n\t\treadOnly: false,\n\t});\n\tinitDb({ sqlite });\n\n\ttry {\n\t\tconst inlangDbContent = contentFromDatabase(sqlite);\n\n\t\tconst lix = await openLixInMemory({ blob: await newLixFile() });\n\n\t\tconst { value: lixId } = await lix.db\n\t\t\t.selectFrom(\"key_value\")\n\t\t\t.select(\"value\")\n\t\t\t.where(\"key\", \"=\", \"lix_id\")\n\t\t\t.executeTakeFirstOrThrow();\n\n\t\t// write files to lix\n\t\tawait lix.db\n\t\t\t.insertInto(\"file\")\n\t\t\t.values([\n\t\t\t\t{\n\t\t\t\t\tpath: \"/db.sqlite\",\n\t\t\t\t\tdata: inlangDbContent,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tpath: \"/settings.json\",\n\t\t\t\t\tdata: new TextEncoder().encode(\n\t\t\t\t\t\tJSON.stringify(\n\t\t\t\t\t\t\targs?.settings ?? defaultProjectSettings,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t2\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tpath: \"/project_id\",\n\t\t\t\t\tdata: new TextEncoder().encode(lixId),\n\t\t\t\t},\n\t\t\t])\n\t\t\t.execute();\n\t\tconst blob = toBlob({ lix });\n\t\tlix.sqlite.close();\n\t\treturn blob;\n\t} catch (e) {\n\t\tconst error = new Error(`Failed to create new inlang project: ${e}`, {\n\t\t\tcause: e,\n\t\t});\n\t\tthrow error;\n\t} finally {\n\t\tsqlite.close();\n\t}\n}\n\nexport const defaultProjectSettings = {\n\t$schema: \"https://inlang.com/schema/project-settings\",\n\tbaseLocale: \"en\",\n\tlocales: [\"en\"],\n\tmodules: [\n\t\t// for instant gratification, we're adding common rules\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-empty-pattern@latest/dist/index.js\",\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-missing-translation@latest/dist/index.js\",\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/message-lint-rule-without-source@latest/dist/index.js\",\n\t\t// default to the message format plugin because it supports all features\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js\",\n\t\t// the m function matcher should be installed by default in case Sherlock (VS Code extension) is adopted\n\t\t// \"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@latest/dist/index.js\",\n\t],\n} satisfies ProjectSettings;\n"]}
@@ -38,4 +38,16 @@ test("it should have the lix id as project id", async () => {
38
38
  expect(projectId).toBeDefined();
39
39
  expect(projectId).toBe(lixId);
40
40
  });
41
+ test("it should not persist the removed SDK metadata key during project creation", async () => {
42
+ const project = await loadProjectInMemory({
43
+ blob: await newProject(),
44
+ });
45
+ const removedSdkKey = ["lix", "tele" + "metry"].join("_");
46
+ const removedKey = await project.lix.db
47
+ .selectFrom("key_value")
48
+ .select("value")
49
+ .where("key", "=", removedSdkKey)
50
+ .executeTakeFirst();
51
+ expect(removedKey).toBeUndefined();
52
+ });
41
53
  //# sourceMappingURL=newProject.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"newProject.test.js","sourceRoot":"/","sources":["project/newProject.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,IAAI,CAAC,yEAAyE,EAAE,KAAK,IAAI,EAAE;IAC1F,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC;QACzC,IAAI,EAAE,MAAM,UAAU,CAAC;YACtB,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;SAC5D,CAAC;KACF,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAC9C,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,O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defaultProjectSettings, newProject } from \"./newProject.js\";\nimport { loadProjectInMemory } from \"./loadProjectInMemory.js\";\n\ntest(\"it should be possible to provide settings for testing or other purposes\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"fr\", locales: [\"fr\"], modules: [] },\n\t\t}),\n\t});\n\tconst settings = await project.settings.get();\n\texpect(settings.baseLocale).toBe(\"fr\");\n\texpect(settings.locales).toEqual([\"fr\"]);\n\texpect(settings.modules).toEqual([]);\n});\n\ntest(\"it should be possible to create a project with default settings\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\tconst settings = await project.settings.get();\n\t// pruning old settings that might exist for legacy reasons\n\tdelete settings.languageTags;\n\tdelete settings.sourceLanguageTag;\n\texpect(settings).toStrictEqual(defaultProjectSettings);\n});\n\n// for historical reasons, inlang files introduced a project id\n// before lix'es got their own id. having two ids for the same\n// file is not needed anymore.\ntest(\"it should have the lix id as project id\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\tconst { value: lixId } = await project.lix.db\n\t\t.selectFrom(\"key_value\")\n\t\t.select(\"value\")\n\t\t.where(\"key\", \"=\", \"lix_id\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst projectId = await project.id.get();\n\texpect(projectId).toBeDefined();\n\texpect(projectId).toBe(lixId);\n});\n"]}
1
+ {"version":3,"file":"newProject.test.js","sourceRoot":"/","sources":["project/newProject.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,IAAI,CAAC,yEAAyE,EAAE,KAAK,IAAI,EAAE;IAC1F,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC;QACzC,IAAI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AAC;SACvB,MAAM,CAAC,OAAO,CAAC;SACf,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC;SAC3B,uBAAuB,EAAE,CAAC;IAE5B,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;IAC7F,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC;QACzC,IAAI,EAAE,MAAM,UAAU,EAAE;KACxB,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAE1D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE;SACrC,UAAU,CAAC,WAAW,CAAC;SACvB,MAAM,CAAC,OAAO,CAAC;SACf,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,CAAC;SAChC,gBAAgB,EAAE,CAAC;IAErB,MAAM,CAAC,UAAU,CAAC,CAAC,aAAa,EAAE,CAAC;AACpC,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"vitest\";\nimport { defaultProjectSettings, newProject } from \"./newProject.js\";\nimport { loadProjectInMemory } from \"./loadProjectInMemory.js\";\n\ntest(\"it should be possible to provide settings for testing or other purposes\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"fr\", locales: [\"fr\"], modules: [] },\n\t\t}),\n\t});\n\tconst settings = await project.settings.get();\n\texpect(settings.baseLocale).toBe(\"fr\");\n\texpect(settings.locales).toEqual([\"fr\"]);\n\texpect(settings.modules).toEqual([]);\n});\n\ntest(\"it should be possible to create a project with default settings\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\tconst settings = await project.settings.get();\n\t// pruning old settings that might exist for legacy reasons\n\tdelete settings.languageTags;\n\tdelete settings.sourceLanguageTag;\n\texpect(settings).toStrictEqual(defaultProjectSettings);\n});\n\n// for historical reasons, inlang files introduced a project id\n// before lix'es got their own id. having two ids for the same\n// file is not needed anymore.\ntest(\"it should have the lix id as project id\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\tconst { value: lixId } = await project.lix.db\n\t\t.selectFrom(\"key_value\")\n\t\t.select(\"value\")\n\t\t.where(\"key\", \"=\", \"lix_id\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst projectId = await project.id.get();\n\texpect(projectId).toBeDefined();\n\texpect(projectId).toBe(lixId);\n});\n\ntest(\"it should not persist the removed SDK metadata key during project creation\", async () => {\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\n\tconst removedSdkKey = [\"lix\", \"tele\" + \"metry\"].join(\"_\");\n\n\tconst removedKey = await project.lix.db\n\t\t.selectFrom(\"key_value\")\n\t\t.select(\"value\")\n\t\t.where(\"key\", \"=\", removedSdkKey)\n\t\t.executeTakeFirst();\n\n\texpect(removedKey).toBeUndefined();\n});\n"]}
@@ -1,5 +1,4 @@
1
1
  export declare const ENV_VARIABLES: {
2
- PUBLIC_POSTHOG_TOKEN: undefined;
3
2
  PUBLIC_INLANG_SDK_SENTRY_DSN: undefined;
4
3
  SDK_VERSION: string;
5
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/env-variables/index.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;CAIzB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/env-variables/index.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;CAGzB,CAAA"}
@@ -1,6 +1,5 @@
1
1
  export const ENV_VARIABLES = {
2
- PUBLIC_POSTHOG_TOKEN: undefined,
3
2
  PUBLIC_INLANG_SDK_SENTRY_DSN: undefined,
4
- SDK_VERSION: "2.7.0",
3
+ SDK_VERSION: "2.9.0",
5
4
  };
6
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,oBAAoB,EAAE,SAAS;IAChC,4BAA4B,EAAE,SAAS;IACvC,WAAW,EAAE,OAAO;CACpB,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n PUBLIC_POSTHOG_TOKEN: undefined,\n\tPUBLIC_INLANG_SDK_SENTRY_DSN: undefined,\n\tSDK_VERSION: \"2.7.0\",\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["services/env-variables/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,4BAA4B,EAAE,SAAS;IACvC,WAAW,EAAE,OAAO;CACpB,CAAA","sourcesContent":["\nexport const ENV_VARIABLES = {\n\tPUBLIC_INLANG_SDK_SENTRY_DSN: undefined,\n\tSDK_VERSION: \"2.9.0\",\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inlang/sdk",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -24,12 +24,12 @@
24
24
  "_comment": "Required for tree-shaking https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free",
25
25
  "sideEffects": false,
26
26
  "engines": {
27
- "node": ">=18.0.0"
27
+ "node": ">=20.0.0"
28
28
  },
29
29
  "dependencies": {
30
- "@lix-js/sdk": "0.4.7",
30
+ "@lix-js/sdk": "0.4.8",
31
31
  "@sinclair/typebox": "^0.31.17",
32
- "kysely": "^0.27.4",
32
+ "kysely": "^0.28.12",
33
33
  "sqlite-wasm-kysely": "0.3.0",
34
34
  "uuid": "^13.0.0"
35
35
  },
@@ -69,16 +69,6 @@ const SDKSettings = Type.Object({
69
69
  }
70
70
  )
71
71
  ),
72
- telemetry: Type.Optional(
73
- Type.Union(
74
- [
75
- Type.Literal("off", {
76
- description: "No telemetry events ",
77
- }),
78
- ],
79
- { description: "If not set, defaults to all" }
80
- )
81
- ),
82
72
  experimental: Type.Optional(
83
73
  Type.Record(Type.String(), Type.Literal(true), {
84
74
  title: "Experimental settings",
@@ -13,7 +13,6 @@ import {
13
13
  import type { InlangProject } from "./api.js";
14
14
  import { withLanguageTagToLocaleMigration } from "../migrations/v2/withLanguageTagToLocaleMigration.js";
15
15
  import { v4 } from "uuid";
16
- import { maybeCaptureLoadedProject } from "./maybeCaptureTelemetry.js";
17
16
  import { importFiles } from "../import-export/importFiles.js";
18
17
  import { exportFiles } from "../import-export/exportFiles.js";
19
18
 
@@ -54,15 +53,6 @@ export async function loadProject(args: {
54
53
  *
55
54
  */
56
55
  preprocessPluginBeforeImport?: PreprocessPluginBeforeImportFunction;
57
- /**
58
- * The id of the app that is using the SDK.
59
- *
60
- * The is used for telemetry purposes. To derive insights like
61
- * which app is using the SDK, how many projects are loaded, etc.
62
- *
63
- * The app id can be removed at any time in the future
64
- */
65
- appId?: string;
66
56
  }): Promise<InlangProject> {
67
57
  const db = initDb({ sqlite: args.sqlite });
68
58
 
@@ -86,29 +76,11 @@ export async function loadProject(args: {
86
76
 
87
77
  const plugins = [...(args.providePlugins ?? []), ...importedPlugins.plugins];
88
78
 
89
- const idFile = await args.lix.db
90
- .selectFrom("file")
91
- .where("path", "=", "/project_id")
92
- .select("data")
93
- .executeTakeFirstOrThrow();
94
-
95
- const id = new TextDecoder().decode(idFile.data);
96
-
97
79
  // const state = createProjectState({
98
80
  // ...args,
99
81
  // settings,
100
82
  // });
101
83
 
102
- // not awaiting to not block the load time of a project
103
- maybeCaptureLoadedProject({
104
- db,
105
- id,
106
- settings,
107
- plugins,
108
- lix: args.lix,
109
- appId: args.appId,
110
- });
111
-
112
84
  return {
113
85
  db,
114
86
  id: {
@@ -42,3 +42,19 @@ test("it should have the lix id as project id", async () => {
42
42
  expect(projectId).toBeDefined();
43
43
  expect(projectId).toBe(lixId);
44
44
  });
45
+
46
+ test("it should not persist the removed SDK metadata key during project creation", async () => {
47
+ const project = await loadProjectInMemory({
48
+ blob: await newProject(),
49
+ });
50
+
51
+ const removedSdkKey = ["lix", "tele" + "metry"].join("_");
52
+
53
+ const removedKey = await project.lix.db
54
+ .selectFrom("key_value")
55
+ .select("value")
56
+ .where("key", "=", removedSdkKey)
57
+ .executeTakeFirst();
58
+
59
+ expect(removedKey).toBeUndefined();
60
+ });
@@ -23,12 +23,7 @@ export async function newProject(args?: {
23
23
  try {
24
24
  const inlangDbContent = contentFromDatabase(sqlite);
25
25
 
26
- const lix = await openLixInMemory({
27
- blob: await newLixFile(),
28
- keyValues: [
29
- { key: "lix_telemetry", value: args?.settings?.telemetry ?? "on" },
30
- ],
31
- });
26
+ const lix = await openLixInMemory({ blob: await newLixFile() });
32
27
 
33
28
  const { value: lixId } = await lix.db
34
29
  .selectFrom("key_value")
@@ -22,7 +22,6 @@ await fs.writeFile(
22
22
  dirname + "/index.ts",
23
23
  `
24
24
  export const ENV_VARIABLES = {
25
- PUBLIC_POSTHOG_TOKEN: ${ifDefined(process.env.PUBLIC_POSTHOG_TOKEN)},
26
25
  PUBLIC_INLANG_SDK_SENTRY_DSN: ${ifDefined(
27
26
  process.env.PUBLIC_INLANG_SDK_SENTRY_DSN
28
27
  )},
@@ -7,7 +7,6 @@
7
7
  * Env variables that are available at runtime.
8
8
  */
9
9
  export declare const ENV_VARIABLES: {
10
- PUBLIC_POSTHOG_TOKEN?: string;
11
10
  PUBLIC_INLANG_SDK_SENTRY_DSN?: string;
12
11
  /**
13
12
  * As defined in the package.json
@@ -1,16 +0,0 @@
1
- import { Kysely } from "kysely";
2
- import type { InlangDatabaseSchema } from "../database/schema.js";
3
- import type { ProjectSettings } from "../json-schema/settings.js";
4
- import type { Lix } from "@lix-js/sdk";
5
- export declare function maybeCaptureLoadedProject(args: {
6
- id: string;
7
- lix: Lix;
8
- settings: ProjectSettings;
9
- plugins: Readonly<Array<{
10
- key: string;
11
- }>>;
12
- appId?: string;
13
- db: Kysely<InlangDatabaseSchema>;
14
- forceCapture?: boolean;
15
- }): Promise<void>;
16
- //# sourceMappingURL=maybeCaptureTelemetry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeCaptureTelemetry.d.ts","sourceRoot":"/","sources":["project/maybeCaptureTelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEvC,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACrD,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,iBA6DA"}
@@ -1,61 +0,0 @@
1
- import { Kysely } from "kysely";
2
- import { capture } from "../services/telemetry/capture.js";
3
- import { ENV_VARIABLES } from "../services/env-variables/index.js";
4
- export async function maybeCaptureLoadedProject(args) {
5
- if (args.settings.telemetry === "off") {
6
- return;
7
- }
8
- // --- SAMPLING ---
9
- // randomly sample 10% of projects
10
- // to reduce the number of telemetry events.
11
- //
12
- // 10% is chosen out of a gut feeling
13
- if (args.forceCapture !== true && Math.random() > 0.1) {
14
- return;
15
- }
16
- try {
17
- const activeAccount = await args.lix.db
18
- .selectFrom("active_account")
19
- .select("id")
20
- .executeTakeFirstOrThrow();
21
- const bundles = await args.db
22
- .selectFrom("bundle")
23
- .select((s) => s.fn.count("id").as("count"))
24
- .executeTakeFirst();
25
- const messages = await args.db
26
- .selectFrom("message")
27
- .select((s) => s.fn.count("id").as("count"))
28
- .executeTakeFirst();
29
- const variants = await args.db
30
- .selectFrom("variant")
31
- .select((s) => s.fn.count("id").as("count"))
32
- .executeTakeFirst();
33
- await capture("SDK loaded project", {
34
- projectId: args.id,
35
- settings: args.settings,
36
- accountId: activeAccount.id,
37
- properties: {
38
- // Insight: Which app is used by the SDK
39
- appId: args.appId,
40
- // Insight: How many languages are used, etc.
41
- settings: args.settings,
42
- // Insight on the used plugins (which one's to prioritize)
43
- pluginKeys: args.plugins.map((plugin) => plugin.key),
44
- // Insight: Which version of the SDK is used (can be used to deprecate old versions)
45
- sdkVersion: ENV_VARIABLES.SDK_VERSION,
46
- // Insight: Scale of projects (what project size to optimize for)
47
- numBundles: bundles?.count,
48
- numMessages: messages?.count,
49
- numVariants: variants?.count,
50
- },
51
- });
52
- }
53
- catch (e) {
54
- if (e instanceof Error &&
55
- e.message.includes("driver has already been destroyed")) {
56
- // The project has been closed, nothing to capture
57
- return;
58
- }
59
- }
60
- }
61
- //# sourceMappingURL=maybeCaptureTelemetry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeCaptureTelemetry.js","sourceRoot":"/","sources":["project/maybeCaptureTelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAInE,MAAM,CAAC,KAAK,U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;YACnC,SAAS,EAAE,IAAI,CAAC,EAAE;YAClB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAAE,aAAa,CAAC,EAAE;YAC3B,UAAU,EAAE;gBACX,wCAAwC;gBACxC,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,6CAA6C;gBAC7C,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,0DAA0D;gBAC1D,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;gBACpD,oFAAoF;gBACpF,UAAU,EAAE,aAAa,CAAC,WAAW;gBACrC,iEAAiE;gBACjE,UAAU,EAAE,OAAO,EAAE,KAAK;gBAC1B,WAAW,EAAE,QAAQ,EAAE,KAAK;gBAC5B,WAAW,EAAE,QAAQ,EAAE,KAAK;aAC5B;SACD,CAAC,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,IACC,CAAC,YAAY,KAAK;YAClB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,mCAAmC,CAAC,EACtD,CAAC;YACF,kDAAkD;YAClD,OAAO;QACR,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["import { Kysely } from \"kysely\";\nimport { capture } from \"../services/telemetry/capture.js\";\nimport type { InlangDatabaseSchema } from \"../database/schema.js\";\nimport { ENV_VARIABLES } from \"../services/env-variables/index.js\";\nimport type { ProjectSettings } from \"../json-schema/settings.js\";\nimport type { Lix } from \"@lix-js/sdk\";\n\nexport async function maybeCaptureLoadedProject(args: {\n\tid: string;\n\tlix: Lix;\n\tsettings: ProjectSettings;\n\tplugins: Readonly<Array<{ key: string }>>;\n\tappId?: string;\n\tdb: Kysely<InlangDatabaseSchema>;\n\tforceCapture?: boolean;\n}) {\n\tif (args.settings.telemetry === \"off\") {\n\t\treturn;\n\t}\n\n\t// --- SAMPLING ---\n\t// randomly sample 10% of projects\n\t// to reduce the number of telemetry events.\n\t//\n\t// 10% is chosen out of a gut feeling\n\tif (args.forceCapture !== true && Math.random() > 0.1) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst activeAccount = await args.lix.db\n\t\t\t.selectFrom(\"active_account\")\n\t\t\t.select(\"id\")\n\t\t\t.executeTakeFirstOrThrow();\n\n\t\tconst bundles = await args.db\n\t\t\t.selectFrom(\"bundle\")\n\t\t\t.select((s) => s.fn.count(\"id\").as(\"count\"))\n\t\t\t.executeTakeFirst();\n\t\tconst messages = await args.db\n\t\t\t.selectFrom(\"message\")\n\t\t\t.select((s) => s.fn.count(\"id\").as(\"count\"))\n\t\t\t.executeTakeFirst();\n\t\tconst variants = await args.db\n\t\t\t.selectFrom(\"variant\")\n\t\t\t.select((s) => s.fn.count(\"id\").as(\"count\"))\n\t\t\t.executeTakeFirst();\n\n\t\tawait capture(\"SDK loaded project\", {\n\t\t\tprojectId: args.id,\n\t\t\tsettings: args.settings,\n\t\t\taccountId: activeAccount.id,\n\t\t\tproperties: {\n\t\t\t\t// Insight: Which app is used by the SDK\n\t\t\t\tappId: args.appId,\n\t\t\t\t// Insight: How many languages are used, etc.\n\t\t\t\tsettings: args.settings,\n\t\t\t\t// Insight on the used plugins (which one's to prioritize)\n\t\t\t\tpluginKeys: args.plugins.map((plugin) => plugin.key),\n\t\t\t\t// Insight: Which version of the SDK is used (can be used to deprecate old versions)\n\t\t\t\tsdkVersion: ENV_VARIABLES.SDK_VERSION,\n\t\t\t\t// Insight: Scale of projects (what project size to optimize for)\n\t\t\t\tnumBundles: bundles?.count,\n\t\t\t\tnumMessages: messages?.count,\n\t\t\t\tnumVariants: variants?.count,\n\t\t\t},\n\t\t});\n\t} catch (e) {\n\t\tif (\n\t\t\te instanceof Error &&\n\t\t\te.message.includes(\"driver has already been destroyed\")\n\t\t) {\n\t\t\t// The project has been closed, nothing to capture\n\t\t\treturn;\n\t\t}\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=maybeCaptureTelemetry.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeCaptureTelemetry.test.d.ts","sourceRoot":"/","sources":["project/maybeCaptureTelemetry.test.ts"],"names":[],"mappings":""}
@@ -1,69 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
- import { loadProjectInMemory } from "./loadProjectInMemory.js";
3
- import { newProject } from "./newProject.js";
4
- import { maybeCaptureLoadedProject } from "./maybeCaptureTelemetry.js";
5
- import { capture } from "../services/telemetry/capture.js";
6
- test("it should capture as expected", async () => {
7
- vi.mock("../services/telemetry/capture.js", async () => {
8
- return {
9
- capture: vi.fn(() => Promise.resolve()),
10
- };
11
- });
12
- vi.mock("../services/env-variables/index", async () => {
13
- return {
14
- ENV_VARIABLES: {
15
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
16
- SDK_VERSION: "1.0.0-mock",
17
- },
18
- };
19
- });
20
- const project = await loadProjectInMemory({
21
- blob: await newProject(),
22
- });
23
- const account = await project.lix.db
24
- .selectFrom("active_account")
25
- .select("id")
26
- .executeTakeFirstOrThrow();
27
- const bundle = await project.db
28
- .insertInto("bundle")
29
- .defaultValues()
30
- .returningAll()
31
- .executeTakeFirstOrThrow();
32
- const message = await project.db
33
- .insertInto("message")
34
- .values({ bundleId: bundle.id, locale: "en" })
35
- .returningAll()
36
- .executeTakeFirstOrThrow();
37
- await project.db
38
- .insertInto("variant")
39
- .values({ messageId: message.id })
40
- .returningAll()
41
- .executeTakeFirst();
42
- const settings = await project.settings.get();
43
- const id = await project.id.get();
44
- const plugins = await project.plugins.get();
45
- await maybeCaptureLoadedProject({
46
- id,
47
- settings,
48
- forceCapture: true,
49
- plugins,
50
- lix: project.lix,
51
- appId: "test",
52
- db: project.db,
53
- });
54
- expect(capture).toHaveBeenCalledWith("SDK loaded project", {
55
- projectId: await project.id.get(),
56
- settings: await project.settings.get(),
57
- accountId: account.id,
58
- properties: {
59
- appId: "test",
60
- settings: await project.settings.get(),
61
- pluginKeys: [],
62
- sdkVersion: "1.0.0-mock",
63
- numBundles: 1,
64
- numMessages: 1,
65
- numVariants: 1,
66
- },
67
- });
68
- });
69
- //# sourceMappingURL=maybeCaptureTelemetry.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maybeCaptureTelemetry.test.js","sourceRoot":"/","sources":["project/maybeCaptureTelemetry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;IAChD,EAAE,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QACtD,OAAO;YACN,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;SACvC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QACrD,OAAO;YACN,aAAa,EAAE;gBACd,oBAAoB,EAAE,cAAc;gBACpC,WAAW,EAAE,YAAY;aACzB;SACD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,mBAAmB,CAAC;QACzC,IAAI,EAAE,MAAM,UAAU,EAAE;KACxB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,EAAE;SAClC,UAAU,CAAC,gBAAgB,CAAC;SAC5B,MAAM,CAAC,IAAI,CAAC;SACZ,uBAAuB,EAAE,CAAC;IAE5B,MAAM,MAAM,GAAG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CAAC,GAAG,EAAE;YACtC,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,YAAY;YACxB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,CAAC;SACd;KACD,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test, vi } from \"vitest\";\nimport { loadProjectInMemory } from \"./loadProjectInMemory.js\";\nimport { newProject } from \"./newProject.js\";\nimport { maybeCaptureLoadedProject } from \"./maybeCaptureTelemetry.js\";\nimport { capture } from \"../services/telemetry/capture.js\";\n\ntest(\"it should capture as expected\", async () => {\n\tvi.mock(\"../services/telemetry/capture.js\", async () => {\n\t\treturn {\n\t\t\tcapture: vi.fn(() => Promise.resolve()),\n\t\t};\n\t});\n\n\tvi.mock(\"../services/env-variables/index\", async () => {\n\t\treturn {\n\t\t\tENV_VARIABLES: {\n\t\t\t\tPUBLIC_POSTHOG_TOKEN: \"mock-defined\",\n\t\t\t\tSDK_VERSION: \"1.0.0-mock\",\n\t\t\t},\n\t\t};\n\t});\n\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject(),\n\t});\n\n\tconst account = await project.lix.db\n\t\t.selectFrom(\"active_account\")\n\t\t.select(\"id\")\n\t\t.executeTakeFirstOrThrow();\n\n\tconst bundle = await project.db\n\t\t.insertInto(\"bundle\")\n\t\t.defaultValues()\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n\n\tconst message = await project.db\n\t\t.insertInto(\"message\")\n\t\t.values({ bundleId: bundle.id, locale: \"en\" })\n\t\t.returningAll()\n\t\t.executeTakeFirstOrThrow();\n\n\tawait project.db\n\t\t.insertInto(\"variant\")\n\t\t.values({ messageId: message.id })\n\t\t.returningAll()\n\t\t.executeTakeFirst();\n\n\tconst settings = await project.settings.get();\n\n\tconst id = await project.id.get();\n\n\tconst plugins = await project.plugins.get();\n\n\tawait maybeCaptureLoadedProject({\n\t\tid,\n\t\tsettings,\n\t\tforceCapture: true,\n\t\tplugins,\n\t\tlix: project.lix,\n\t\tappId: \"test\",\n\t\tdb: project.db,\n\t});\n\n\texpect(capture).toHaveBeenCalledWith(\"SDK loaded project\", {\n\t\tprojectId: await project.id.get(),\n\t\tsettings: await project.settings.get(),\n\t\taccountId: account.id,\n\t\tproperties: {\n\t\t\tappId: \"test\",\n\t\t\tsettings: await project.settings.get(),\n\t\t\tpluginKeys: [],\n\t\t\tsdkVersion: \"1.0.0-mock\",\n\t\t\tnumBundles: 1,\n\t\t\tnumMessages: 1,\n\t\t\tnumVariants: 1,\n\t\t},\n\t});\n});\n"]}
@@ -1,24 +0,0 @@
1
- import type { ProjectSettings } from "../../json-schema/settings.js";
2
- /**
3
- * List of telemetry events for typesafety.
4
- *
5
- * - prefix with `SDK` to avoid collisions with other apps
6
- * - use past tense to indicate that the event is completed
7
- */
8
- type TelemetryEvent = "SDK loaded project";
9
- /**
10
- * Capture an event.
11
- *
12
- * - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
13
- */
14
- export declare const capture: (event: TelemetryEvent, args: {
15
- projectId: string;
16
- accountId: string;
17
- /**
18
- * Please use snake_case for property names.
19
- */
20
- properties: Record<string, any>;
21
- settings: Pick<ProjectSettings, "telemetry">;
22
- }) => Promise<void>;
23
- export {};
24
- //# sourceMappingURL=capture.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capture.d.ts","sourceRoot":"/","sources":["services/telemetry/capture.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE;;;;;GAKG;AACH,KAAK,cAAc,GAAG,oBAAoB,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,OAAO,UACZ,cAAc,QACf;IACL,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;CAC7C,kBA8BD,CAAC"}
@@ -1,72 +0,0 @@
1
- // import { ENV_VARIABLES } from "../env-variables/index.js";
2
- import { ENV_VARIABLES } from "../env-variables/index.js";
3
- /**
4
- * Capture an event.
5
- *
6
- * - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
7
- */
8
- export const capture = async (event, args) => {
9
- if (args.settings.telemetry === "off") {
10
- return;
11
- }
12
- else if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {
13
- return;
14
- }
15
- try {
16
- await fetch("https://eu.posthog.com/capture/", {
17
- method: "POST",
18
- body: JSON.stringify({
19
- api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
20
- event,
21
- distinct_id: args.accountId,
22
- properties: {
23
- $groups: { project: args.projectId },
24
- ...args.properties,
25
- },
26
- }),
27
- });
28
- await identifyProject({
29
- projectId: args.projectId,
30
- accountId: args.accountId,
31
- // using the id for now as a name but can be changed in the future
32
- // we need at least one property to make a project visible in the dashboar
33
- properties: { name: args.projectId },
34
- });
35
- }
36
- catch {
37
- // do nothing
38
- }
39
- };
40
- /**
41
- * Identifying a project is needed.
42
- *
43
- * Otherwise, the project will not be visible in the PostHog dashboard.
44
- */
45
- const identifyProject = async (args) => {
46
- // do not send events if the token is not set
47
- // (assuming this eases testing)
48
- if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {
49
- return;
50
- }
51
- try {
52
- await fetch("https://eu.posthog.com/capture/", {
53
- method: "POST",
54
- body: JSON.stringify({
55
- api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
56
- event: "$groupidentify",
57
- distinct_id: args.accountId,
58
- properties: {
59
- $group_type: "project",
60
- $group_key: args.projectId,
61
- $group_set: {
62
- ...args.properties,
63
- },
64
- },
65
- }),
66
- });
67
- }
68
- catch {
69
- // do nothing
70
- }
71
- };
72
- //# sourceMappingURL=capture.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file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AAC,iCAAiC,EAAE;YAC9C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACpB,OAAO,EAAE,aAAa,CAAC,oBAAoB;gBAC3C,KAAK,EAAE,gBAAgB;gBACvB,WAAW,EAAE,IAAI,CAAC,SAAS;gBAC3B,UAAU,EAAE;oBACX,WAAW,EAAE,SAAS;oBACtB,UAAU,EAAE,IAAI,CAAC,SAAS;oBAC1B,UAAU,EAAE;wBACX,GAAG,IAAI,CAAC,UAAU;qBAClB;iBACD;aACD,CAAC;SACF,CAAC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACR,aAAa;IACd,CAAC;AACF,CAAC,CAAC","sourcesContent":["// import { ENV_VARIABLES } from \"../env-variables/index.js\";\n\nimport type { ProjectSettings } from \"../../json-schema/settings.js\";\nimport { ENV_VARIABLES } from \"../env-variables/index.js\";\n\n/**\n * List of telemetry events for typesafety.\n *\n * - prefix with `SDK` to avoid collisions with other apps\n * - use past tense to indicate that the event is completed\n */\ntype TelemetryEvent = \"SDK loaded project\";\n\n/**\n * Capture an event.\n *\n * - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)\n */\nexport const capture = async (\n\tevent: TelemetryEvent,\n\targs: {\n\t\tprojectId: string;\n\t\taccountId: string;\n\t\t/**\n\t\t * Please use snake_case for property names.\n\t\t */\n\t\tproperties: Record<string, any>;\n\t\tsettings: Pick<ProjectSettings, \"telemetry\">;\n\t}\n) => {\n\tif (args.settings.telemetry === \"off\") {\n\t\treturn;\n\t} else if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait fetch(\"https://eu.posthog.com/capture/\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tapi_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,\n\t\t\t\tevent,\n\t\t\t\tdistinct_id: args.accountId,\n\t\t\t\tproperties: {\n\t\t\t\t\t$groups: { project: args.projectId },\n\t\t\t\t\t...args.properties,\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\t\tawait identifyProject({\n\t\t\tprojectId: args.projectId,\n\t\t\taccountId: args.accountId,\n\t\t\t// using the id for now as a name but can be changed in the future\n\t\t\t// we need at least one property to make a project visible in the dashboar\n\t\t\tproperties: { name: args.projectId },\n\t\t});\n\t} catch {\n\t\t// do nothing\n\t}\n};\n\n/**\n * Identifying a project is needed.\n *\n * Otherwise, the project will not be visible in the PostHog dashboard.\n */\nconst identifyProject = async (args: {\n\tprojectId: string;\n\taccountId: string;\n\t/**\n\t * Please use snake_case for property names.\n\t */\n\tproperties: Record<string, any>;\n}) => {\n\t// do not send events if the token is not set\n\t// (assuming this eases testing)\n\tif (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {\n\t\treturn;\n\t}\n\ttry {\n\t\tawait fetch(\"https://eu.posthog.com/capture/\", {\n\t\t\tmethod: \"POST\",\n\t\t\tbody: JSON.stringify({\n\t\t\t\tapi_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,\n\t\t\t\tevent: \"$groupidentify\",\n\t\t\t\tdistinct_id: args.accountId,\n\t\t\t\tproperties: {\n\t\t\t\t\t$group_type: \"project\",\n\t\t\t\t\t$group_key: args.projectId,\n\t\t\t\t\t$group_set: {\n\t\t\t\t\t\t...args.properties,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t});\n\t} catch {\n\t\t// do nothing\n\t}\n};\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=capture.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capture.test.d.ts","sourceRoot":"/","sources":["services/telemetry/capture.test.ts"],"names":[],"mappings":""}
@@ -1,43 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
- import { capture } from "./capture.js";
3
- test("it should not capture if telemetry is off", async () => {
4
- // @ts-expect-error - global.fetch is not defined
5
- global.fetch = vi.fn(() => Promise.resolve());
6
- vi.mock("../env-variables/index.js", async () => {
7
- return {
8
- ENV_VARIABLES: {
9
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
10
- },
11
- };
12
- });
13
- await capture("SDK loaded project", {
14
- projectId: "test",
15
- accountId: "test",
16
- settings: {
17
- telemetry: "off",
18
- },
19
- properties: {},
20
- });
21
- expect(global.fetch).not.toHaveBeenCalled();
22
- });
23
- test("it should not capture if telemetry is NOT off", async () => {
24
- // @ts-expect-error - global.fetch is not defined
25
- global.fetch = vi.fn(() => Promise.resolve());
26
- vi.mock("../env-variables/index.js", async () => {
27
- return {
28
- ENV_VARIABLES: {
29
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
30
- },
31
- };
32
- });
33
- await capture("SDK loaded project", {
34
- projectId: "test",
35
- accountId: "test",
36
- settings: {
37
- telemetry: undefined,
38
- },
39
- properties: {},
40
- });
41
- expect(global.fetch).toHaveBeenCalled();
42
- });
43
- //# sourceMappingURL=capture.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capture.test.js","sourceRoot":"/","sources":["services/telemetry/capture.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,IAAI,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;IAC5D,iDAAiD;IACjD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE9C,EAAE,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QAC/C,OAAO;YACN,aAAa,EAAE;gBACd,oBAAoB,EAAE,cAAc;aACpC;SACD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,oBAAoB,EAAE;QACnC,SAAS,EAAE,MAAM;QACjB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE;YACT,SAAS,EAAE,KAAK;SAChB;QACD,UAAU,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;AAC7C,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;IAChE,iDAAiD;IACjD,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE9C,EAAE,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QAC/C,OAAO;YACN,aAAa,EAAE;gBACd,oBAAoB,EAAE,cAAc;aACpC;SACD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC,oBAAoB,EAAE;QACnC,SAAS,EAAE,MAAM;QACjB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE;YACT,SAAS,EAAE,SAAS;SACpB;QACD,UAAU,EAAE,EAAE;KACd,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACzC,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test, vi } from \"vitest\";\nimport { capture } from \"./capture.js\";\n\ntest(\"it should not capture if telemetry is off\", async () => {\n\t// @ts-expect-error - global.fetch is not defined\n\tglobal.fetch = vi.fn(() => Promise.resolve());\n\n\tvi.mock(\"../env-variables/index.js\", async () => {\n\t\treturn {\n\t\t\tENV_VARIABLES: {\n\t\t\t\tPUBLIC_POSTHOG_TOKEN: \"mock-defined\",\n\t\t\t},\n\t\t};\n\t});\n\n\tawait capture(\"SDK loaded project\", {\n\t\tprojectId: \"test\",\n\t\taccountId: \"test\",\n\t\tsettings: {\n\t\t\ttelemetry: \"off\",\n\t\t},\n\t\tproperties: {},\n\t});\n\n\texpect(global.fetch).not.toHaveBeenCalled();\n});\n\ntest(\"it should not capture if telemetry is NOT off\", async () => {\n\t// @ts-expect-error - global.fetch is not defined\n\tglobal.fetch = vi.fn(() => Promise.resolve());\n\n\tvi.mock(\"../env-variables/index.js\", async () => {\n\t\treturn {\n\t\t\tENV_VARIABLES: {\n\t\t\t\tPUBLIC_POSTHOG_TOKEN: \"mock-defined\",\n\t\t\t},\n\t\t};\n\t});\n\n\tawait capture(\"SDK loaded project\", {\n\t\tprojectId: \"test\",\n\t\taccountId: \"test\",\n\t\tsettings: {\n\t\t\ttelemetry: undefined,\n\t\t},\n\t\tproperties: {},\n\t});\n\n\texpect(global.fetch).toHaveBeenCalled();\n});\n"]}
@@ -1,80 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
- import { loadProjectInMemory } from "./loadProjectInMemory.js";
3
- import { newProject } from "./newProject.js";
4
- import { maybeCaptureLoadedProject } from "./maybeCaptureTelemetry.js";
5
- import { capture } from "../services/telemetry/capture.js";
6
-
7
- test("it should capture as expected", async () => {
8
- vi.mock("../services/telemetry/capture.js", async () => {
9
- return {
10
- capture: vi.fn(() => Promise.resolve()),
11
- };
12
- });
13
-
14
- vi.mock("../services/env-variables/index", async () => {
15
- return {
16
- ENV_VARIABLES: {
17
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
18
- SDK_VERSION: "1.0.0-mock",
19
- },
20
- };
21
- });
22
-
23
- const project = await loadProjectInMemory({
24
- blob: await newProject(),
25
- });
26
-
27
- const account = await project.lix.db
28
- .selectFrom("active_account")
29
- .select("id")
30
- .executeTakeFirstOrThrow();
31
-
32
- const bundle = await project.db
33
- .insertInto("bundle")
34
- .defaultValues()
35
- .returningAll()
36
- .executeTakeFirstOrThrow();
37
-
38
- const message = await project.db
39
- .insertInto("message")
40
- .values({ bundleId: bundle.id, locale: "en" })
41
- .returningAll()
42
- .executeTakeFirstOrThrow();
43
-
44
- await project.db
45
- .insertInto("variant")
46
- .values({ messageId: message.id })
47
- .returningAll()
48
- .executeTakeFirst();
49
-
50
- const settings = await project.settings.get();
51
-
52
- const id = await project.id.get();
53
-
54
- const plugins = await project.plugins.get();
55
-
56
- await maybeCaptureLoadedProject({
57
- id,
58
- settings,
59
- forceCapture: true,
60
- plugins,
61
- lix: project.lix,
62
- appId: "test",
63
- db: project.db,
64
- });
65
-
66
- expect(capture).toHaveBeenCalledWith("SDK loaded project", {
67
- projectId: await project.id.get(),
68
- settings: await project.settings.get(),
69
- accountId: account.id,
70
- properties: {
71
- appId: "test",
72
- settings: await project.settings.get(),
73
- pluginKeys: [],
74
- sdkVersion: "1.0.0-mock",
75
- numBundles: 1,
76
- numMessages: 1,
77
- numVariants: 1,
78
- },
79
- });
80
- });
@@ -1,77 +0,0 @@
1
- import { Kysely } from "kysely";
2
- import { capture } from "../services/telemetry/capture.js";
3
- import type { InlangDatabaseSchema } from "../database/schema.js";
4
- import { ENV_VARIABLES } from "../services/env-variables/index.js";
5
- import type { ProjectSettings } from "../json-schema/settings.js";
6
- import type { Lix } from "@lix-js/sdk";
7
-
8
- export async function maybeCaptureLoadedProject(args: {
9
- id: string;
10
- lix: Lix;
11
- settings: ProjectSettings;
12
- plugins: Readonly<Array<{ key: string }>>;
13
- appId?: string;
14
- db: Kysely<InlangDatabaseSchema>;
15
- forceCapture?: boolean;
16
- }) {
17
- if (args.settings.telemetry === "off") {
18
- return;
19
- }
20
-
21
- // --- SAMPLING ---
22
- // randomly sample 10% of projects
23
- // to reduce the number of telemetry events.
24
- //
25
- // 10% is chosen out of a gut feeling
26
- if (args.forceCapture !== true && Math.random() > 0.1) {
27
- return;
28
- }
29
-
30
- try {
31
- const activeAccount = await args.lix.db
32
- .selectFrom("active_account")
33
- .select("id")
34
- .executeTakeFirstOrThrow();
35
-
36
- const bundles = await args.db
37
- .selectFrom("bundle")
38
- .select((s) => s.fn.count("id").as("count"))
39
- .executeTakeFirst();
40
- const messages = await args.db
41
- .selectFrom("message")
42
- .select((s) => s.fn.count("id").as("count"))
43
- .executeTakeFirst();
44
- const variants = await args.db
45
- .selectFrom("variant")
46
- .select((s) => s.fn.count("id").as("count"))
47
- .executeTakeFirst();
48
-
49
- await capture("SDK loaded project", {
50
- projectId: args.id,
51
- settings: args.settings,
52
- accountId: activeAccount.id,
53
- properties: {
54
- // Insight: Which app is used by the SDK
55
- appId: args.appId,
56
- // Insight: How many languages are used, etc.
57
- settings: args.settings,
58
- // Insight on the used plugins (which one's to prioritize)
59
- pluginKeys: args.plugins.map((plugin) => plugin.key),
60
- // Insight: Which version of the SDK is used (can be used to deprecate old versions)
61
- sdkVersion: ENV_VARIABLES.SDK_VERSION,
62
- // Insight: Scale of projects (what project size to optimize for)
63
- numBundles: bundles?.count,
64
- numMessages: messages?.count,
65
- numVariants: variants?.count,
66
- },
67
- });
68
- } catch (e) {
69
- if (
70
- e instanceof Error &&
71
- e.message.includes("driver has already been destroyed")
72
- ) {
73
- // The project has been closed, nothing to capture
74
- return;
75
- }
76
- }
77
- }
@@ -1,50 +0,0 @@
1
- import { expect, test, vi } from "vitest";
2
- import { capture } from "./capture.js";
3
-
4
- test("it should not capture if telemetry is off", async () => {
5
- // @ts-expect-error - global.fetch is not defined
6
- global.fetch = vi.fn(() => Promise.resolve());
7
-
8
- vi.mock("../env-variables/index.js", async () => {
9
- return {
10
- ENV_VARIABLES: {
11
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
12
- },
13
- };
14
- });
15
-
16
- await capture("SDK loaded project", {
17
- projectId: "test",
18
- accountId: "test",
19
- settings: {
20
- telemetry: "off",
21
- },
22
- properties: {},
23
- });
24
-
25
- expect(global.fetch).not.toHaveBeenCalled();
26
- });
27
-
28
- test("it should not capture if telemetry is NOT off", async () => {
29
- // @ts-expect-error - global.fetch is not defined
30
- global.fetch = vi.fn(() => Promise.resolve());
31
-
32
- vi.mock("../env-variables/index.js", async () => {
33
- return {
34
- ENV_VARIABLES: {
35
- PUBLIC_POSTHOG_TOKEN: "mock-defined",
36
- },
37
- };
38
- });
39
-
40
- await capture("SDK loaded project", {
41
- projectId: "test",
42
- accountId: "test",
43
- settings: {
44
- telemetry: undefined,
45
- },
46
- properties: {},
47
- });
48
-
49
- expect(global.fetch).toHaveBeenCalled();
50
- });
@@ -1,98 +0,0 @@
1
- // import { ENV_VARIABLES } from "../env-variables/index.js";
2
-
3
- import type { ProjectSettings } from "../../json-schema/settings.js";
4
- import { ENV_VARIABLES } from "../env-variables/index.js";
5
-
6
- /**
7
- * List of telemetry events for typesafety.
8
- *
9
- * - prefix with `SDK` to avoid collisions with other apps
10
- * - use past tense to indicate that the event is completed
11
- */
12
- type TelemetryEvent = "SDK loaded project";
13
-
14
- /**
15
- * Capture an event.
16
- *
17
- * - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
18
- */
19
- export const capture = async (
20
- event: TelemetryEvent,
21
- args: {
22
- projectId: string;
23
- accountId: string;
24
- /**
25
- * Please use snake_case for property names.
26
- */
27
- properties: Record<string, any>;
28
- settings: Pick<ProjectSettings, "telemetry">;
29
- }
30
- ) => {
31
- if (args.settings.telemetry === "off") {
32
- return;
33
- } else if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {
34
- return;
35
- }
36
- try {
37
- await fetch("https://eu.posthog.com/capture/", {
38
- method: "POST",
39
- body: JSON.stringify({
40
- api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
41
- event,
42
- distinct_id: args.accountId,
43
- properties: {
44
- $groups: { project: args.projectId },
45
- ...args.properties,
46
- },
47
- }),
48
- });
49
- await identifyProject({
50
- projectId: args.projectId,
51
- accountId: args.accountId,
52
- // using the id for now as a name but can be changed in the future
53
- // we need at least one property to make a project visible in the dashboar
54
- properties: { name: args.projectId },
55
- });
56
- } catch {
57
- // do nothing
58
- }
59
- };
60
-
61
- /**
62
- * Identifying a project is needed.
63
- *
64
- * Otherwise, the project will not be visible in the PostHog dashboard.
65
- */
66
- const identifyProject = async (args: {
67
- projectId: string;
68
- accountId: string;
69
- /**
70
- * Please use snake_case for property names.
71
- */
72
- properties: Record<string, any>;
73
- }) => {
74
- // do not send events if the token is not set
75
- // (assuming this eases testing)
76
- if (ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN === undefined) {
77
- return;
78
- }
79
- try {
80
- await fetch("https://eu.posthog.com/capture/", {
81
- method: "POST",
82
- body: JSON.stringify({
83
- api_key: ENV_VARIABLES.PUBLIC_POSTHOG_TOKEN,
84
- event: "$groupidentify",
85
- distinct_id: args.accountId,
86
- properties: {
87
- $group_type: "project",
88
- $group_key: args.projectId,
89
- $group_set: {
90
- ...args.properties,
91
- },
92
- },
93
- }),
94
- });
95
- } catch {
96
- // do nothing
97
- }
98
- };