@wickermoney/plugin-sdk 0.0.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 (122) hide show
  1. package/LICENSE +202 -0
  2. package/dist/index.d.ts +16 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +13 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/manifest/CORE_TABLES.d.ts +8 -0
  7. package/dist/manifest/CORE_TABLES.d.ts.map +1 -0
  8. package/dist/manifest/CORE_TABLES.js +16 -0
  9. package/dist/manifest/CORE_TABLES.js.map +1 -0
  10. package/dist/manifest/CoreTableName.d.ts +4 -0
  11. package/dist/manifest/CoreTableName.d.ts.map +1 -0
  12. package/dist/manifest/CoreTableName.js +2 -0
  13. package/dist/manifest/CoreTableName.js.map +1 -0
  14. package/dist/manifest/ManifestParseResult.d.ts +13 -0
  15. package/dist/manifest/ManifestParseResult.d.ts.map +1 -0
  16. package/dist/manifest/ManifestParseResult.js +2 -0
  17. package/dist/manifest/ManifestParseResult.js.map +1 -0
  18. package/dist/manifest/PERMISSIONS.d.ts +9 -0
  19. package/dist/manifest/PERMISSIONS.d.ts.map +1 -0
  20. package/dist/manifest/PERMISSIONS.js +9 -0
  21. package/dist/manifest/PERMISSIONS.js.map +1 -0
  22. package/dist/manifest/PageContribution.d.ts +5 -0
  23. package/dist/manifest/PageContribution.d.ts.map +1 -0
  24. package/dist/manifest/PageContribution.js +2 -0
  25. package/dist/manifest/PageContribution.js.map +1 -0
  26. package/dist/manifest/Permission.d.ts +4 -0
  27. package/dist/manifest/Permission.d.ts.map +1 -0
  28. package/dist/manifest/Permission.js +2 -0
  29. package/dist/manifest/Permission.js.map +1 -0
  30. package/dist/manifest/PluginManifest.d.ts +5 -0
  31. package/dist/manifest/PluginManifest.d.ts.map +1 -0
  32. package/dist/manifest/PluginManifest.js +2 -0
  33. package/dist/manifest/PluginManifest.js.map +1 -0
  34. package/dist/manifest/REMOTE_ENTRY_TYPE.d.ts +15 -0
  35. package/dist/manifest/REMOTE_ENTRY_TYPE.d.ts.map +1 -0
  36. package/dist/manifest/REMOTE_ENTRY_TYPE.js +15 -0
  37. package/dist/manifest/REMOTE_ENTRY_TYPE.js.map +1 -0
  38. package/dist/manifest/SDK_MAJOR_VERSION.d.ts +8 -0
  39. package/dist/manifest/SDK_MAJOR_VERSION.d.ts.map +1 -0
  40. package/dist/manifest/SDK_MAJOR_VERSION.js +8 -0
  41. package/dist/manifest/SDK_MAJOR_VERSION.js.map +1 -0
  42. package/dist/manifest/TableGrant.d.ts +5 -0
  43. package/dist/manifest/TableGrant.d.ts.map +1 -0
  44. package/dist/manifest/TableGrant.js +2 -0
  45. package/dist/manifest/TableGrant.js.map +1 -0
  46. package/dist/manifest/WIDGET_SIZES.d.ts +6 -0
  47. package/dist/manifest/WIDGET_SIZES.d.ts.map +1 -0
  48. package/dist/manifest/WIDGET_SIZES.js +6 -0
  49. package/dist/manifest/WIDGET_SIZES.js.map +1 -0
  50. package/dist/manifest/WIDGET_SLOTS.d.ts +9 -0
  51. package/dist/manifest/WIDGET_SLOTS.d.ts.map +1 -0
  52. package/dist/manifest/WIDGET_SLOTS.js +13 -0
  53. package/dist/manifest/WIDGET_SLOTS.js.map +1 -0
  54. package/dist/manifest/WidgetContribution.d.ts +5 -0
  55. package/dist/manifest/WidgetContribution.d.ts.map +1 -0
  56. package/dist/manifest/WidgetContribution.js +2 -0
  57. package/dist/manifest/WidgetContribution.js.map +1 -0
  58. package/dist/manifest/WidgetSize.d.ts +4 -0
  59. package/dist/manifest/WidgetSize.d.ts.map +1 -0
  60. package/dist/manifest/WidgetSize.js +2 -0
  61. package/dist/manifest/WidgetSize.js.map +1 -0
  62. package/dist/manifest/WidgetSlot.d.ts +4 -0
  63. package/dist/manifest/WidgetSlot.d.ts.map +1 -0
  64. package/dist/manifest/WidgetSlot.js +2 -0
  65. package/dist/manifest/WidgetSlot.js.map +1 -0
  66. package/dist/manifest/checkRemoteEntry.d.ts +16 -0
  67. package/dist/manifest/checkRemoteEntry.d.ts.map +1 -0
  68. package/dist/manifest/checkRemoteEntry.js +29 -0
  69. package/dist/manifest/checkRemoteEntry.js.map +1 -0
  70. package/dist/manifest/federationName.d.ts +13 -0
  71. package/dist/manifest/federationName.d.ts.map +1 -0
  72. package/dist/manifest/federationName.js +15 -0
  73. package/dist/manifest/federationName.js.map +1 -0
  74. package/dist/manifest/index.d.ts +26 -0
  75. package/dist/manifest/index.d.ts.map +1 -0
  76. package/dist/manifest/index.js +17 -0
  77. package/dist/manifest/index.js.map +1 -0
  78. package/dist/manifest/isCompatible.d.ts +11 -0
  79. package/dist/manifest/isCompatible.d.ts.map +1 -0
  80. package/dist/manifest/isCompatible.js +14 -0
  81. package/dist/manifest/isCompatible.js.map +1 -0
  82. package/dist/manifest/pageContributionSchema.d.ts +18 -0
  83. package/dist/manifest/pageContributionSchema.d.ts.map +1 -0
  84. package/dist/manifest/pageContributionSchema.js +24 -0
  85. package/dist/manifest/pageContributionSchema.js.map +1 -0
  86. package/dist/manifest/pagePath.d.ts +11 -0
  87. package/dist/manifest/pagePath.d.ts.map +1 -0
  88. package/dist/manifest/pagePath.js +13 -0
  89. package/dist/manifest/pagePath.js.map +1 -0
  90. package/dist/manifest/parseManifest.d.ts +15 -0
  91. package/dist/manifest/parseManifest.d.ts.map +1 -0
  92. package/dist/manifest/parseManifest.js +31 -0
  93. package/dist/manifest/parseManifest.js.map +1 -0
  94. package/dist/manifest/pluginManifestSchema.d.ts +73 -0
  95. package/dist/manifest/pluginManifestSchema.d.ts.map +1 -0
  96. package/dist/manifest/pluginManifestSchema.js +66 -0
  97. package/dist/manifest/pluginManifestSchema.js.map +1 -0
  98. package/dist/manifest/remoteEntrySchema.d.ts +17 -0
  99. package/dist/manifest/remoteEntrySchema.d.ts.map +1 -0
  100. package/dist/manifest/remoteEntrySchema.js +47 -0
  101. package/dist/manifest/remoteEntrySchema.js.map +1 -0
  102. package/dist/manifest/tableGrantSchema.d.ts +18 -0
  103. package/dist/manifest/tableGrantSchema.d.ts.map +1 -0
  104. package/dist/manifest/tableGrantSchema.js +10 -0
  105. package/dist/manifest/tableGrantSchema.js.map +1 -0
  106. package/dist/manifest/widgetContributionSchema.d.ts +20 -0
  107. package/dist/manifest/widgetContributionSchema.d.ts.map +1 -0
  108. package/dist/manifest/widgetContributionSchema.js +19 -0
  109. package/dist/manifest/widgetContributionSchema.js.map +1 -0
  110. package/dist/manifest.d.ts +175 -0
  111. package/dist/manifest.d.ts.map +1 -0
  112. package/dist/manifest.js +148 -0
  113. package/dist/manifest.js.map +1 -0
  114. package/dist/range.d.ts +75 -0
  115. package/dist/range.d.ts.map +1 -0
  116. package/dist/range.js +86 -0
  117. package/dist/range.js.map +1 -0
  118. package/dist/runtime.d.ts +142 -0
  119. package/dist/runtime.d.ts.map +1 -0
  120. package/dist/runtime.js +36 -0
  121. package/dist/runtime.js.map +1 -0
  122. package/package.json +47 -0
@@ -0,0 +1,142 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { WidgetSize } from './manifest/index.js';
3
+ import type { DashboardRange } from './range.js';
4
+ /** The authenticated user, as the host knows them. */
5
+ export interface PluginSession {
6
+ /** The user's unique id. */
7
+ readonly userId: string;
8
+ /** The email address the user signed in with. */
9
+ readonly email: string;
10
+ /** The user's IANA time zone name, e.g. `Europe/London`. */
11
+ readonly timezone: string;
12
+ }
13
+ /**
14
+ * Scoped HTTP client handed to a plugin.
15
+ *
16
+ * Requests are relative to the plugin's own namespace (`/api/v1/p/<id>/`) for
17
+ * plugin endpoints, or to core read endpoints the manifest's `requiredTables`
18
+ * permits. The host attaches credentials — a plugin never sees the access
19
+ * token, so it cannot exfiltrate one or call the API as the user elsewhere.
20
+ */
21
+ export interface PluginApi {
22
+ /**
23
+ * Sends a `GET` request.
24
+ *
25
+ * @param path - Path relative to the plugin's namespace or a permitted core endpoint.
26
+ * @param init - Extra `fetch` options for this request.
27
+ * @returns The parsed JSON response body.
28
+ */
29
+ get<T>(path: string, init?: RequestInit): Promise<T>;
30
+ /**
31
+ * Sends a `POST` request with a JSON body.
32
+ *
33
+ * @param path - Path relative to the plugin's namespace or a permitted core endpoint.
34
+ * @param body - Value serialised as the JSON request body.
35
+ * @param init - Extra `fetch` options for this request.
36
+ * @returns The parsed JSON response body.
37
+ */
38
+ post<T>(path: string, body: unknown, init?: RequestInit): Promise<T>;
39
+ /**
40
+ * Upserts: creates the resource or replaces it if it exists.
41
+ *
42
+ * Present because a plugin editing one row of its own data should be able to
43
+ * say so. A plugin saving a line into a month that may or may not exist yet
44
+ * would otherwise have to invent its own convention for "create or replace"
45
+ * on top of `POST`.
46
+ *
47
+ * @param path - Path relative to the plugin's namespace or a permitted core endpoint.
48
+ * @param body - Value serialised as the JSON request body.
49
+ * @param init - Extra `fetch` options for this request.
50
+ * @returns The parsed JSON response body.
51
+ */
52
+ put<T>(path: string, body: unknown, init?: RequestInit): Promise<T>;
53
+ /**
54
+ * Sends a `DELETE` request. Named `del` because `delete` is a reserved word.
55
+ *
56
+ * @param path - Path relative to the plugin's namespace or a permitted core endpoint.
57
+ * @param init - Extra `fetch` options for this request.
58
+ * @returns The parsed JSON response body.
59
+ */
60
+ del<T>(path: string, init?: RequestInit): Promise<T>;
61
+ }
62
+ /**
63
+ * Everything a plugin is given. Injected as a prop — never a global, never a
64
+ * module-scoped singleton, so two plugins cannot observe or corrupt each
65
+ * other's context, and a test can construct one directly.
66
+ */
67
+ export interface PluginContext {
68
+ /** The signed-in user. */
69
+ readonly session: PluginSession;
70
+ /** Scoped HTTP client for the plugin's own endpoints and the core endpoints its manifest permits. */
71
+ readonly api: PluginApi;
72
+ /** Navigates the shell to an in-app path. */
73
+ readonly navigate: (path: string) => void;
74
+ /** Formats a numeric-string money value in the user's locale. */
75
+ readonly formatMoney: (value: string, currency?: string) => string;
76
+ /** Formats a date string in the user's locale. */
77
+ readonly formatDate: (value: string) => string;
78
+ }
79
+ /** Props the host passes to a plugin page component. */
80
+ export interface PluginPageProps {
81
+ /** Everything the plugin is given by the host. */
82
+ readonly ctx: PluginContext;
83
+ }
84
+ /** A React component that renders a full plugin page. */
85
+ export type PluginPage = ComponentType<PluginPageProps>;
86
+ /** Props the host passes to a plugin widget component. */
87
+ export interface PluginWidgetProps {
88
+ /** Everything the plugin is given by the host. */
89
+ readonly ctx: PluginContext;
90
+ /** The size the widget is being rendered at. */
91
+ readonly size: WidgetSize;
92
+ /**
93
+ * The dashboard's current time range.
94
+ *
95
+ * Every widget on the dashboard receives the same one, so two charts side by
96
+ * side cannot be showing different periods while looking comparable — which
97
+ * is the specific way a dashboard misleads. A widget with nothing to scope
98
+ * ignores it.
99
+ *
100
+ * Optional so a widget rendered outside the dashboard (an account detail
101
+ * slot, a test) still typechecks without inventing a range that means
102
+ * nothing there.
103
+ */
104
+ readonly range?: DashboardRange;
105
+ }
106
+ /** A React component that renders a plugin widget. */
107
+ export type PluginWidget = ComponentType<PluginWidgetProps>;
108
+ /**
109
+ * Shape a plugin's federated module must export.
110
+ *
111
+ * `default` keeps the contract obvious at the call site: whatever the module
112
+ * default-exports is the component the host renders.
113
+ */
114
+ export interface PluginModule {
115
+ readonly default: PluginPage | PluginWidget;
116
+ }
117
+ /**
118
+ * Adds a plugin's stylesheet to the document.
119
+ *
120
+ * A federated remote has no HTML document of its own, so a side-effect
121
+ * `import './x.css'` goes nowhere: the host loads the remote's JS by dynamic
122
+ * import and nothing ever requests the emitted stylesheet. The result is a
123
+ * widget that mounts, fetches, renders — and looks broken, with every custom
124
+ * property falling back to a default. Nothing errors, which is why it is worth
125
+ * a named helper rather than a comment.
126
+ *
127
+ * Plugins therefore import their CSS as text (`import css from './x.css?inline'`)
128
+ * and call this at module scope. The `<style>` element is keyed by plugin id, so
129
+ * two widgets from the same plugin inject once and a second copy of the SDK
130
+ * inside another remote cannot duplicate it.
131
+ *
132
+ * Scoping is still the plugin's job: keep declarations under a class the plugin
133
+ * owns. This injects into the host document; it is not a style sandbox.
134
+ *
135
+ * Does nothing when there is no `document`, so importing and calling it in a
136
+ * Node process is safe.
137
+ *
138
+ * @param pluginId - The plugin's manifest id, used to key the `<style>` element.
139
+ * @param css - The stylesheet text to inject.
140
+ */
141
+ export declare function adoptPluginStyles(pluginId: string, css: string): void;
142
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IACpD;;;;;;;OAOG;IACH,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IACpE;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;IACnE;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE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E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Adds a plugin's stylesheet to the document.
3
+ *
4
+ * A federated remote has no HTML document of its own, so a side-effect
5
+ * `import './x.css'` goes nowhere: the host loads the remote's JS by dynamic
6
+ * import and nothing ever requests the emitted stylesheet. The result is a
7
+ * widget that mounts, fetches, renders — and looks broken, with every custom
8
+ * property falling back to a default. Nothing errors, which is why it is worth
9
+ * a named helper rather than a comment.
10
+ *
11
+ * Plugins therefore import their CSS as text (`import css from './x.css?inline'`)
12
+ * and call this at module scope. The `<style>` element is keyed by plugin id, so
13
+ * two widgets from the same plugin inject once and a second copy of the SDK
14
+ * inside another remote cannot duplicate it.
15
+ *
16
+ * Scoping is still the plugin's job: keep declarations under a class the plugin
17
+ * owns. This injects into the host document; it is not a style sandbox.
18
+ *
19
+ * Does nothing when there is no `document`, so importing and calling it in a
20
+ * Node process is safe.
21
+ *
22
+ * @param pluginId - The plugin's manifest id, used to key the `<style>` element.
23
+ * @param css - The stylesheet text to inject.
24
+ */
25
+ export function adoptPluginStyles(pluginId, css) {
26
+ if (typeof document === 'undefined')
27
+ return;
28
+ const id = `wickermoney-plugin-styles:${pluginId}`;
29
+ if (document.getElementById(id) !== null)
30
+ return;
31
+ const style = document.createElement('style');
32
+ style.id = id;
33
+ style.textContent = css;
34
+ document.head.append(style);
35
+ }
36
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AA6HA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,GAAW;IAC7D,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAM;IAC3C,MAAM,EAAE,GAAG,6BAA6B,QAAQ,EAAE,CAAA;IAClD,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,IAAI;QAAE,OAAM;IAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC7C,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;IACb,KAAK,CAAC,WAAW,GAAG,GAAG,CAAA;IACvB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@wickermoney/plugin-sdk",
3
+ "version": "0.0.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/wickermoney/wicker-money.git",
8
+ "directory": "packages/plugin-sdk"
9
+ },
10
+ "homepage": "https://github.com/wickermoney/wicker-money#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/wickermoney/wicker-money/issues"
13
+ },
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./runtime": {
23
+ "types": "./dist/runtime.d.ts",
24
+ "default": "./dist/runtime.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.json",
32
+ "typecheck": "tsc -p tsconfig.json --noEmit",
33
+ "test": "vitest run"
34
+ },
35
+ "devDependencies": {
36
+ "@types/react": "^19.3.0",
37
+ "react": "^19.3.0",
38
+ "typescript": "^6.0.3",
39
+ "vitest": "^5.0.0"
40
+ },
41
+ "dependencies": {
42
+ "zod": "^4.6.5"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ }
47
+ }