@wordrhyme/plugin 0.1.0-alpha.10

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 (57) hide show
  1. package/dist/admin/index.d.ts +19 -0
  2. package/dist/admin/index.js +42 -0
  3. package/dist/admin/index.js.map +1 -0
  4. package/dist/artifact.d.ts +17 -0
  5. package/dist/artifact.js +97 -0
  6. package/dist/artifact.js.map +1 -0
  7. package/dist/chunk-3IM3FPTJ.js +1470 -0
  8. package/dist/chunk-3IM3FPTJ.js.map +1 -0
  9. package/dist/chunk-6GDCFR67.js +218 -0
  10. package/dist/chunk-6GDCFR67.js.map +1 -0
  11. package/dist/chunk-7EM22QYB.js +333 -0
  12. package/dist/chunk-7EM22QYB.js.map +1 -0
  13. package/dist/chunk-BI7E5CVM.js +26 -0
  14. package/dist/chunk-BI7E5CVM.js.map +1 -0
  15. package/dist/chunk-BVOTSKM2.js +254 -0
  16. package/dist/chunk-BVOTSKM2.js.map +1 -0
  17. package/dist/chunk-DY44Q4CK.js +188 -0
  18. package/dist/chunk-DY44Q4CK.js.map +1 -0
  19. package/dist/chunk-MZOLSLJ7.js +65 -0
  20. package/dist/chunk-MZOLSLJ7.js.map +1 -0
  21. package/dist/chunk-O4AYK3YP.js +156 -0
  22. package/dist/chunk-O4AYK3YP.js.map +1 -0
  23. package/dist/chunk-UGMYO6AU.js +37 -0
  24. package/dist/chunk-UGMYO6AU.js.map +1 -0
  25. package/dist/client-poND5ovI.d.ts +679 -0
  26. package/dist/client.d.ts +9 -0
  27. package/dist/client.js +68 -0
  28. package/dist/client.js.map +1 -0
  29. package/dist/dev-utils.d.ts +105 -0
  30. package/dist/dev-utils.js +35 -0
  31. package/dist/dev-utils.js.map +1 -0
  32. package/dist/entity-extensions-CnhKoT4k.d.ts +56 -0
  33. package/dist/globalization.d.ts +85 -0
  34. package/dist/globalization.js +53 -0
  35. package/dist/globalization.js.map +1 -0
  36. package/dist/index.d.ts +724 -0
  37. package/dist/index.js +931 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/locale.d.ts +15 -0
  40. package/dist/locale.js +13 -0
  41. package/dist/locale.js.map +1 -0
  42. package/dist/manifest-CTFX-h0w.d.ts +2053 -0
  43. package/dist/react.d.ts +227 -0
  44. package/dist/react.js +226 -0
  45. package/dist/react.js.map +1 -0
  46. package/dist/release-BDJeO54k.d.ts +230 -0
  47. package/dist/server.d.ts +115 -0
  48. package/dist/server.js +194 -0
  49. package/dist/server.js.map +1 -0
  50. package/dist/time.d.ts +34 -0
  51. package/dist/time.js +31 -0
  52. package/dist/time.js.map +1 -0
  53. package/dist/trpc.d.ts +44 -0
  54. package/dist/trpc.js +11 -0
  55. package/dist/trpc.js.map +1 -0
  56. package/dist/types-BJo3_91V.d.ts +1997 -0
  57. package/package.json +92 -0
@@ -0,0 +1,230 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const PLUGIN_ARCHIVE_MEDIA_TYPE = "application/vnd.wordrhyme.plugin+zip";
4
+ declare const PLUGIN_RELEASE_SCHEMA_VERSION: 1;
5
+ declare const REGISTRY_CATALOG_SIGNATURE_DOMAIN = "wordrhyme.registry-catalog-page.v1\0";
6
+ declare const pluginArchivePathSchema: z.ZodString;
7
+ declare const pluginReleaseFileSchema: z.ZodObject<{
8
+ path: z.ZodString;
9
+ size: z.ZodNumber;
10
+ sha256: z.ZodString;
11
+ }, z.core.$strip>;
12
+ declare const pluginReleaseSchema: z.ZodObject<{
13
+ schemaVersion: z.ZodLiteral<1>;
14
+ pluginId: z.ZodString;
15
+ version: z.ZodString;
16
+ createdAt: z.ZodISODateTime;
17
+ mediaType: z.ZodLiteral<"application/vnd.wordrhyme.plugin+zip">;
18
+ files: z.ZodArray<z.ZodObject<{
19
+ path: z.ZodString;
20
+ size: z.ZodNumber;
21
+ sha256: z.ZodString;
22
+ }, z.core.$strip>>;
23
+ sbom: z.ZodObject<{
24
+ path: z.ZodString;
25
+ format: z.ZodLiteral<"spdx-json">;
26
+ }, z.core.$strip>;
27
+ }, z.core.$strip>;
28
+ declare const pluginSignatureSchema: z.ZodObject<{
29
+ schemaVersion: z.ZodLiteral<1>;
30
+ pluginId: z.ZodString;
31
+ version: z.ZodString;
32
+ algorithm: z.ZodLiteral<"ed25519">;
33
+ keyId: z.ZodString;
34
+ signedAt: z.ZodISODateTime;
35
+ releaseSha256: z.ZodString;
36
+ signature: z.ZodString;
37
+ }, z.core.$strip>;
38
+ declare const registryReleaseEnvelopeSchema: z.ZodObject<{
39
+ schemaVersion: z.ZodLiteral<1>;
40
+ pluginId: z.ZodString;
41
+ version: z.ZodString;
42
+ publisherId: z.ZodString;
43
+ state: z.ZodLiteral<"published">;
44
+ trustLevel: z.ZodEnum<{
45
+ first_party: "first_party";
46
+ third_party: "third_party";
47
+ }>;
48
+ artifactUrl: z.ZodURL;
49
+ artifactSha256: z.ZodString;
50
+ releaseSha256: z.ZodString;
51
+ publishedAt: z.ZodISODateTime;
52
+ }, z.core.$strip>;
53
+ declare const registrySignatureSchema: z.ZodObject<{
54
+ schemaVersion: z.ZodLiteral<1>;
55
+ algorithm: z.ZodLiteral<"ed25519">;
56
+ keyId: z.ZodString;
57
+ signedAt: z.ZodISODateTime;
58
+ envelopeSha256: z.ZodString;
59
+ signature: z.ZodString;
60
+ }, z.core.$strip>;
61
+ declare const registryCatalogPageEnvelopeSchema: z.ZodObject<{
62
+ schemaVersion: z.ZodLiteral<1>;
63
+ snapshotId: z.ZodString;
64
+ generatedAt: z.ZodISODateTime;
65
+ cursor: z.ZodNullable<z.ZodString>;
66
+ nextCursor: z.ZodNullable<z.ZodString>;
67
+ releasesSha256: z.ZodString;
68
+ }, z.core.$strip>;
69
+ /**
70
+ * The Registry signature contract intentionally uses an explicit field order.
71
+ * Do not replace this with JSON.stringify(input): callers may construct the
72
+ * same envelope with a different property insertion order.
73
+ */
74
+ declare function canonicalRegistryReleaseEnvelope(input: RegistryReleaseEnvelope): string;
75
+ declare function registryReleaseSignaturePayload(input: RegistryReleaseEnvelope): Uint8Array;
76
+ declare function canonicalRegistryCatalogPageEnvelope(input: RegistryCatalogPageEnvelope): string;
77
+ declare function registryCatalogPageSignaturePayload(input: RegistryCatalogPageEnvelope): Uint8Array;
78
+ declare const pluginRegistryReleaseSchema: z.ZodObject<{
79
+ pluginId: z.ZodString;
80
+ version: z.ZodString;
81
+ publisherId: z.ZodString;
82
+ state: z.ZodEnum<{
83
+ published: "published";
84
+ archived: "archived";
85
+ suspended: "suspended";
86
+ removed: "removed";
87
+ }>;
88
+ trustLevel: z.ZodEnum<{
89
+ first_party: "first_party";
90
+ third_party: "third_party";
91
+ }>;
92
+ manifest: z.ZodRecord<z.ZodString, z.ZodUnknown>;
93
+ release: z.ZodObject<{
94
+ schemaVersion: z.ZodLiteral<1>;
95
+ pluginId: z.ZodString;
96
+ version: z.ZodString;
97
+ createdAt: z.ZodISODateTime;
98
+ mediaType: z.ZodLiteral<"application/vnd.wordrhyme.plugin+zip">;
99
+ files: z.ZodArray<z.ZodObject<{
100
+ path: z.ZodString;
101
+ size: z.ZodNumber;
102
+ sha256: z.ZodString;
103
+ }, z.core.$strip>>;
104
+ sbom: z.ZodObject<{
105
+ path: z.ZodString;
106
+ format: z.ZodLiteral<"spdx-json">;
107
+ }, z.core.$strip>;
108
+ }, z.core.$strip>;
109
+ artifactUrl: z.ZodURL;
110
+ artifactSha256: z.ZodString;
111
+ releaseSha256: z.ZodString;
112
+ publisherSignature: z.ZodNullable<z.ZodObject<{
113
+ schemaVersion: z.ZodLiteral<1>;
114
+ pluginId: z.ZodString;
115
+ version: z.ZodString;
116
+ algorithm: z.ZodLiteral<"ed25519">;
117
+ keyId: z.ZodString;
118
+ signedAt: z.ZodISODateTime;
119
+ releaseSha256: z.ZodString;
120
+ signature: z.ZodString;
121
+ }, z.core.$strip>>;
122
+ signature: z.ZodOptional<z.ZodNullable<z.ZodObject<{
123
+ schemaVersion: z.ZodLiteral<1>;
124
+ pluginId: z.ZodString;
125
+ version: z.ZodString;
126
+ algorithm: z.ZodLiteral<"ed25519">;
127
+ keyId: z.ZodString;
128
+ signedAt: z.ZodISODateTime;
129
+ releaseSha256: z.ZodString;
130
+ signature: z.ZodString;
131
+ }, z.core.$strip>>>;
132
+ registrySignature: z.ZodObject<{
133
+ schemaVersion: z.ZodLiteral<1>;
134
+ algorithm: z.ZodLiteral<"ed25519">;
135
+ keyId: z.ZodString;
136
+ signedAt: z.ZodISODateTime;
137
+ envelopeSha256: z.ZodString;
138
+ signature: z.ZodString;
139
+ }, z.core.$strip>;
140
+ publishedAt: z.ZodISODateTime;
141
+ }, z.core.$strip>;
142
+ declare const pluginRegistryCatalogSchema: z.ZodObject<{
143
+ schemaVersion: z.ZodLiteral<1>;
144
+ snapshotId: z.ZodString;
145
+ generatedAt: z.ZodISODateTime;
146
+ releases: z.ZodArray<z.ZodObject<{
147
+ pluginId: z.ZodString;
148
+ version: z.ZodString;
149
+ publisherId: z.ZodString;
150
+ state: z.ZodEnum<{
151
+ published: "published";
152
+ archived: "archived";
153
+ suspended: "suspended";
154
+ removed: "removed";
155
+ }>;
156
+ trustLevel: z.ZodEnum<{
157
+ first_party: "first_party";
158
+ third_party: "third_party";
159
+ }>;
160
+ manifest: z.ZodRecord<z.ZodString, z.ZodUnknown>;
161
+ release: z.ZodObject<{
162
+ schemaVersion: z.ZodLiteral<1>;
163
+ pluginId: z.ZodString;
164
+ version: z.ZodString;
165
+ createdAt: z.ZodISODateTime;
166
+ mediaType: z.ZodLiteral<"application/vnd.wordrhyme.plugin+zip">;
167
+ files: z.ZodArray<z.ZodObject<{
168
+ path: z.ZodString;
169
+ size: z.ZodNumber;
170
+ sha256: z.ZodString;
171
+ }, z.core.$strip>>;
172
+ sbom: z.ZodObject<{
173
+ path: z.ZodString;
174
+ format: z.ZodLiteral<"spdx-json">;
175
+ }, z.core.$strip>;
176
+ }, z.core.$strip>;
177
+ artifactUrl: z.ZodURL;
178
+ artifactSha256: z.ZodString;
179
+ releaseSha256: z.ZodString;
180
+ publisherSignature: z.ZodNullable<z.ZodObject<{
181
+ schemaVersion: z.ZodLiteral<1>;
182
+ pluginId: z.ZodString;
183
+ version: z.ZodString;
184
+ algorithm: z.ZodLiteral<"ed25519">;
185
+ keyId: z.ZodString;
186
+ signedAt: z.ZodISODateTime;
187
+ releaseSha256: z.ZodString;
188
+ signature: z.ZodString;
189
+ }, z.core.$strip>>;
190
+ signature: z.ZodOptional<z.ZodNullable<z.ZodObject<{
191
+ schemaVersion: z.ZodLiteral<1>;
192
+ pluginId: z.ZodString;
193
+ version: z.ZodString;
194
+ algorithm: z.ZodLiteral<"ed25519">;
195
+ keyId: z.ZodString;
196
+ signedAt: z.ZodISODateTime;
197
+ releaseSha256: z.ZodString;
198
+ signature: z.ZodString;
199
+ }, z.core.$strip>>>;
200
+ registrySignature: z.ZodObject<{
201
+ schemaVersion: z.ZodLiteral<1>;
202
+ algorithm: z.ZodLiteral<"ed25519">;
203
+ keyId: z.ZodString;
204
+ signedAt: z.ZodISODateTime;
205
+ envelopeSha256: z.ZodString;
206
+ signature: z.ZodString;
207
+ }, z.core.$strip>;
208
+ publishedAt: z.ZodISODateTime;
209
+ }, z.core.$strip>>;
210
+ nextCursor: z.ZodNullable<z.ZodString>;
211
+ catalogSignature: z.ZodObject<{
212
+ schemaVersion: z.ZodLiteral<1>;
213
+ algorithm: z.ZodLiteral<"ed25519">;
214
+ keyId: z.ZodString;
215
+ signedAt: z.ZodISODateTime;
216
+ envelopeSha256: z.ZodString;
217
+ signature: z.ZodString;
218
+ }, z.core.$strip>;
219
+ }, z.core.$strip>;
220
+ declare function registryCatalogReleasesPayload(input: PluginRegistryRelease[]): Uint8Array;
221
+ type PluginReleaseFile = z.infer<typeof pluginReleaseFileSchema>;
222
+ type PluginRelease = z.infer<typeof pluginReleaseSchema>;
223
+ type PluginSignature = z.infer<typeof pluginSignatureSchema>;
224
+ type RegistryReleaseEnvelope = z.infer<typeof registryReleaseEnvelopeSchema>;
225
+ type RegistrySignature = z.infer<typeof registrySignatureSchema>;
226
+ type RegistryCatalogPageEnvelope = z.infer<typeof registryCatalogPageEnvelopeSchema>;
227
+ type PluginRegistryRelease = z.infer<typeof pluginRegistryReleaseSchema>;
228
+ type PluginRegistryCatalog = z.infer<typeof pluginRegistryCatalogSchema>;
229
+
230
+ export { type PluginRelease as P, type RegistryReleaseEnvelope as R, type RegistrySignature as a, type RegistryCatalogPageEnvelope as b, PLUGIN_ARCHIVE_MEDIA_TYPE as c, PLUGIN_RELEASE_SCHEMA_VERSION as d, type PluginRegistryCatalog as e, type PluginRegistryRelease as f, type PluginReleaseFile as g, type PluginSignature as h, REGISTRY_CATALOG_SIGNATURE_DOMAIN as i, canonicalRegistryCatalogPageEnvelope as j, canonicalRegistryReleaseEnvelope as k, pluginRegistryCatalogSchema as l, pluginRegistryReleaseSchema as m, pluginReleaseFileSchema as n, pluginReleaseSchema as o, pluginArchivePathSchema as p, pluginSignatureSchema as q, registryCatalogPageEnvelopeSchema as r, registryCatalogPageSignaturePayload as s, registryCatalogReleasesPayload as t, registryReleaseEnvelopeSchema as u, registryReleaseSignaturePayload as v, registrySignatureSchema as w };
@@ -0,0 +1,115 @@
1
+ export { createPluginContext, pluginProcedure, pluginRouter } from './trpc.js';
2
+ import { a as PluginContext } from './types-BJo3_91V.js';
3
+ export { H as HookContext, c as HookTransaction } from './types-BJo3_91V.js';
4
+ import { DateRangeResolver } from './time.js';
5
+ export { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
6
+ export { E as ENTITY_EXTENSION_VALUES_SAVE_HOOK_ID, a as EXTENSION_PROJECT_SAVE_HOOK_ID, b as EntityExtensionProjectionValue, c as EntityExtensionValueSaveHandler, d as EntityExtensionValueSavePayload, e as EntityExtensionValueSaveResult, f as entityExtensions, r as registerEntityExtensionValueSaver } from './entity-extensions-CnhKoT4k.js';
7
+ import './globalization.js';
8
+ import 'decimal.js';
9
+ import './locale.js';
10
+ import './release-BDJeO54k.js';
11
+ import 'zod';
12
+ import './manifest-CTFX-h0w.js';
13
+
14
+ interface PluginRuntimeRequestContext {
15
+ requestId?: string | undefined;
16
+ organizationId?: string | undefined;
17
+ originalOrganizationId?: string | undefined;
18
+ userId?: string | undefined;
19
+ user?: PluginContext['user'];
20
+ userRole?: string | undefined;
21
+ userRoles?: string[] | undefined;
22
+ currentTeamId?: string | undefined;
23
+ locale?: string | undefined;
24
+ currency?: string | undefined;
25
+ timezone?: string | undefined;
26
+ clientTimeZone?: string | undefined;
27
+ resolveDateRange?: DateRangeResolver | undefined;
28
+ actorType?: PluginContext['actorType'] | 'api-token';
29
+ isSystemContext?: boolean | undefined;
30
+ principal?: PluginContext['principal'];
31
+ invoker?: string | undefined;
32
+ apiTokenId?: string | undefined;
33
+ apiTokenScopes?: string[] | undefined;
34
+ }
35
+ interface CreatePluginRuntimeContextInput {
36
+ pluginId: string;
37
+ request?: unknown;
38
+ response?: unknown;
39
+ requestContext?: PluginRuntimeRequestContext | undefined;
40
+ }
41
+ interface PluginRuntimeBridge {
42
+ createRequestContext(input: PluginRuntimeRequestContext): PluginRuntimeRequestContext;
43
+ createContext(input: CreatePluginRuntimeContextInput): Promise<PluginContext>;
44
+ runWithContext<T>(requestContext: PluginRuntimeRequestContext, callback: () => Promise<T> | T): Promise<T>;
45
+ }
46
+ declare function setPluginRuntimeBridge(bridge: PluginRuntimeBridge): void;
47
+ declare function createPluginRuntimeRequestContext(input: PluginRuntimeRequestContext): PluginRuntimeRequestContext;
48
+ declare function createPluginRuntimeContext(input: CreatePluginRuntimeContextInput): Promise<PluginContext>;
49
+ declare function runWithPluginRuntimeContext<T>(requestContext: PluginRuntimeRequestContext, callback: () => Promise<T> | T): Promise<T>;
50
+
51
+ type OAuthSettingScope = {
52
+ global?: boolean;
53
+ };
54
+ type OAuthSettings = Pick<PluginContext, 'settings' | 'organizationId' | 'userId'>;
55
+ type OAuthQueryValue = string | number | boolean | null | undefined | readonly (string | number | boolean | null | undefined)[];
56
+ type OAuthQueryParams = Record<string, OAuthQueryValue>;
57
+ type OAuthStateRecord<TPayload extends Record<string, unknown> = Record<string, unknown>> = TPayload & {
58
+ createdAt: string;
59
+ expiresAt?: string;
60
+ userId?: string;
61
+ organizationId?: string;
62
+ };
63
+ interface CreateOAuthStateOptions<TPayload extends Record<string, unknown>> extends OAuthSettingScope {
64
+ keyPrefix: string;
65
+ payload: TPayload;
66
+ bytes?: number;
67
+ ttlSeconds?: number;
68
+ encrypted?: boolean;
69
+ includeContext?: boolean;
70
+ now?: Date;
71
+ }
72
+ interface ConsumeOAuthStateOptions extends OAuthSettingScope {
73
+ keyPrefix: string;
74
+ state: string;
75
+ deleteOnConsume?: boolean;
76
+ now?: Date;
77
+ }
78
+ interface VerifyQueryHmacSha256Options {
79
+ signatureKey?: string;
80
+ excludeKeys?: string[];
81
+ digest?: 'hex' | 'base64';
82
+ }
83
+ declare function buildOAuthCallbackPath(providerId: string): string;
84
+ declare function buildOAuthCallbackUrl(providerId: string, baseUrl: string): string;
85
+ declare function buildOAuthResultRedirect(path: string, params: Record<string, string | number | boolean | null | undefined>): string;
86
+ declare function buildOAuthStateKey(keyPrefix: string, state: string): string;
87
+ declare function maskOAuthSecret(value: string): string;
88
+ declare function createOAuthState<TPayload extends Record<string, unknown>>(ctx: OAuthSettings, options: CreateOAuthStateOptions<TPayload>): Promise<{
89
+ state: string;
90
+ key: string;
91
+ payload: OAuthStateRecord<TPayload>;
92
+ }>;
93
+ declare function consumeOAuthState<TPayload extends Record<string, unknown> = Record<string, unknown>>(ctx: OAuthSettings, options: ConsumeOAuthStateOptions): Promise<OAuthStateRecord<TPayload>>;
94
+ declare function verifyQueryHmacSha256(params: OAuthQueryParams, secret: string, options?: VerifyQueryHmacSha256Options): boolean;
95
+
96
+ interface PluginPublicServiceRequest {
97
+ method: string;
98
+ path: string;
99
+ query: Record<string, string | string[]>;
100
+ headers: Record<string, string | undefined>;
101
+ body: unknown;
102
+ requestId: string;
103
+ }
104
+ interface PluginPublicServiceResponse {
105
+ status?: number;
106
+ headers?: Record<string, string>;
107
+ body?: unknown;
108
+ }
109
+ interface PluginPublicService {
110
+ name: string;
111
+ handle(request: PluginPublicServiceRequest, context: PluginContext): Promise<PluginPublicServiceResponse>;
112
+ }
113
+ declare function definePublicService(service: PluginPublicService): PluginPublicService;
114
+
115
+ export { type CreatePluginRuntimeContextInput, type OAuthStateRecord, type PluginPublicService, type PluginPublicServiceRequest, type PluginPublicServiceResponse, type PluginRuntimeBridge, type PluginRuntimeRequestContext, buildOAuthCallbackPath, buildOAuthCallbackUrl, buildOAuthResultRedirect, buildOAuthStateKey, consumeOAuthState, createOAuthState, createPluginRuntimeContext, createPluginRuntimeRequestContext, definePublicService, maskOAuthSecret, runWithPluginRuntimeContext, setPluginRuntimeBridge, verifyQueryHmacSha256 };
package/dist/server.js ADDED
@@ -0,0 +1,194 @@
1
+ import {
2
+ createPluginContext,
3
+ pluginProcedure,
4
+ pluginRouter
5
+ } from "./chunk-O4AYK3YP.js";
6
+ import {
7
+ ENTITY_EXTENSION_VALUES_SAVE_HOOK_ID,
8
+ EXTENSION_PROJECT_SAVE_HOOK_ID,
9
+ entityExtensions,
10
+ registerEntityExtensionValueSaver
11
+ } from "./chunk-UGMYO6AU.js";
12
+
13
+ // src/runtime.ts
14
+ var runtimeBridge;
15
+ function setPluginRuntimeBridge(bridge) {
16
+ runtimeBridge = bridge;
17
+ }
18
+ function getPluginRuntimeBridge() {
19
+ if (!runtimeBridge) {
20
+ throw new Error("Plugin runtime bridge is not available");
21
+ }
22
+ return runtimeBridge;
23
+ }
24
+ function createPluginRuntimeRequestContext(input) {
25
+ return getPluginRuntimeBridge().createRequestContext(input);
26
+ }
27
+ function createPluginRuntimeContext(input) {
28
+ return getPluginRuntimeBridge().createContext(input);
29
+ }
30
+ function runWithPluginRuntimeContext(requestContext, callback) {
31
+ return getPluginRuntimeBridge().runWithContext(requestContext, callback);
32
+ }
33
+
34
+ // src/oauth.ts
35
+ import crypto from "crypto";
36
+ function buildOAuthCallbackPath(providerId) {
37
+ const normalized = providerId.trim();
38
+ if (!/^[a-z0-9-]+$/i.test(normalized)) {
39
+ throw new Error(`Invalid OAuth provider id: ${providerId}`);
40
+ }
41
+ return `/api/oauth/${normalized}/callback`;
42
+ }
43
+ function buildOAuthCallbackUrl(providerId, baseUrl) {
44
+ return new URL(buildOAuthCallbackPath(providerId), baseUrl).toString();
45
+ }
46
+ function buildOAuthResultRedirect(path, params) {
47
+ const url = new URL(path, "https://wordrhyme.local");
48
+ for (const [key, value] of Object.entries(params)) {
49
+ if (value !== null && value !== void 0) {
50
+ url.searchParams.set(key, String(value));
51
+ }
52
+ }
53
+ if (/^https?:\/\//i.test(path)) {
54
+ return url.toString();
55
+ }
56
+ return `${url.pathname}${url.search}${url.hash}`;
57
+ }
58
+ function buildOAuthStateKey(keyPrefix, state) {
59
+ const prefix = keyPrefix.trim().replace(/\.+$/, "");
60
+ if (!prefix) throw new Error("OAuth state keyPrefix is required");
61
+ if (!state) throw new Error("OAuth state is required");
62
+ return `${prefix}.${state}`;
63
+ }
64
+ function maskOAuthSecret(value) {
65
+ if (value.length <= 8) return "********";
66
+ return `${value.slice(0, 4)}****${value.slice(-4)}`;
67
+ }
68
+ async function createOAuthState(ctx, options) {
69
+ if (!ctx.settings) throw new Error("Settings not available");
70
+ const state = crypto.randomBytes(options.bytes ?? 24).toString("hex");
71
+ const key = buildOAuthStateKey(options.keyPrefix, state);
72
+ const now = options.now ?? /* @__PURE__ */ new Date();
73
+ const payload = {
74
+ ...options.payload,
75
+ createdAt: now.toISOString()
76
+ };
77
+ if (options.ttlSeconds && options.ttlSeconds > 0) {
78
+ payload.expiresAt = new Date(now.getTime() + options.ttlSeconds * 1e3).toISOString();
79
+ }
80
+ if (options.includeContext !== false) {
81
+ if (ctx.userId) payload.userId = ctx.userId;
82
+ if (ctx.organizationId) payload.organizationId = ctx.organizationId;
83
+ }
84
+ await ctx.settings.set(key, payload, {
85
+ encrypted: options.encrypted ?? true,
86
+ ...options.global !== void 0 ? { global: options.global } : {}
87
+ });
88
+ return { state, key, payload };
89
+ }
90
+ async function consumeOAuthState(ctx, options) {
91
+ if (!ctx.settings) throw new Error("Settings not available");
92
+ const key = buildOAuthStateKey(options.keyPrefix, options.state);
93
+ const raw = await ctx.settings.get(key);
94
+ const record = parseStateRecord(raw);
95
+ if (!record) {
96
+ throw new Error("Invalid or expired OAuth state");
97
+ }
98
+ const now = options.now ?? /* @__PURE__ */ new Date();
99
+ if (record.expiresAt && Date.parse(record.expiresAt) <= now.getTime()) {
100
+ await ctx.settings.delete(key, scopeOptions(options)).catch(() => false);
101
+ throw new Error("Invalid or expired OAuth state");
102
+ }
103
+ if (options.deleteOnConsume !== false) {
104
+ await ctx.settings.delete(key, scopeOptions(options)).catch(() => false);
105
+ }
106
+ return record;
107
+ }
108
+ function buildCanonicalQueryString(params, excludeKeys = []) {
109
+ const exclude = new Set(excludeKeys);
110
+ const entries = [];
111
+ for (const [key, value] of Object.entries(params)) {
112
+ if (exclude.has(key)) continue;
113
+ const values = Array.isArray(value) ? value : [value];
114
+ for (const item of values) {
115
+ if (item !== null && item !== void 0) {
116
+ entries.push([key, String(item)]);
117
+ }
118
+ }
119
+ }
120
+ return entries.sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => `${key}=${value}`).join("&");
121
+ }
122
+ function verifyQueryHmacSha256(params, secret, options = {}) {
123
+ if (!secret) return false;
124
+ const signatureKey = options.signatureKey ?? "hmac";
125
+ const signature = firstQueryValue(params[signatureKey]);
126
+ if (!signature) return false;
127
+ const excludeKeys = options.excludeKeys ?? [signatureKey];
128
+ const digest = options.digest ?? "hex";
129
+ const message = buildCanonicalQueryString(params, excludeKeys);
130
+ const computed = crypto.createHmac("sha256", secret).update(message).digest(digest);
131
+ return timingSafeEqualString(computed, signature);
132
+ }
133
+ function timingSafeEqualString(a, b) {
134
+ const left = Buffer.from(a, "utf8");
135
+ const right = Buffer.from(b, "utf8");
136
+ if (left.length !== right.length) return false;
137
+ return crypto.timingSafeEqual(left, right);
138
+ }
139
+ function parseStateRecord(value) {
140
+ let parsed = value;
141
+ if (typeof value === "string") {
142
+ try {
143
+ parsed = JSON.parse(value);
144
+ } catch {
145
+ return null;
146
+ }
147
+ }
148
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
149
+ return null;
150
+ }
151
+ const record = parsed;
152
+ if (typeof record["createdAt"] !== "string") {
153
+ return null;
154
+ }
155
+ if ("expiresAt" in record && typeof record["expiresAt"] !== "string") {
156
+ return null;
157
+ }
158
+ return record;
159
+ }
160
+ function firstQueryValue(value) {
161
+ const candidate = Array.isArray(value) ? value.find((item) => item !== null && item !== void 0) : value;
162
+ return candidate === null || candidate === void 0 ? null : String(candidate);
163
+ }
164
+ function scopeOptions(options) {
165
+ return options.global !== void 0 ? { global: options.global } : void 0;
166
+ }
167
+
168
+ // src/public-service.ts
169
+ function definePublicService(service) {
170
+ return service;
171
+ }
172
+ export {
173
+ ENTITY_EXTENSION_VALUES_SAVE_HOOK_ID,
174
+ EXTENSION_PROJECT_SAVE_HOOK_ID,
175
+ buildOAuthCallbackPath,
176
+ buildOAuthCallbackUrl,
177
+ buildOAuthResultRedirect,
178
+ buildOAuthStateKey,
179
+ consumeOAuthState,
180
+ createOAuthState,
181
+ createPluginContext,
182
+ createPluginRuntimeContext,
183
+ createPluginRuntimeRequestContext,
184
+ definePublicService,
185
+ entityExtensions,
186
+ maskOAuthSecret,
187
+ pluginProcedure,
188
+ pluginRouter,
189
+ registerEntityExtensionValueSaver,
190
+ runWithPluginRuntimeContext,
191
+ setPluginRuntimeBridge,
192
+ verifyQueryHmacSha256
193
+ };
194
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime.ts","../src/oauth.ts","../src/public-service.ts"],"sourcesContent":["import type { PluginContext } from './types';\nimport type { DateRangeResolver } from './time';\n\nexport interface PluginRuntimeRequestContext {\n requestId?: string | undefined;\n organizationId?: string | undefined;\n originalOrganizationId?: string | undefined;\n userId?: string | undefined;\n user?: PluginContext['user'];\n userRole?: string | undefined;\n userRoles?: string[] | undefined;\n currentTeamId?: string | undefined;\n locale?: string | undefined;\n currency?: string | undefined;\n timezone?: string | undefined;\n clientTimeZone?: string | undefined;\n resolveDateRange?: DateRangeResolver | undefined;\n actorType?: PluginContext['actorType'] | 'api-token';\n isSystemContext?: boolean | undefined;\n principal?: PluginContext['principal'];\n invoker?: string | undefined;\n apiTokenId?: string | undefined;\n apiTokenScopes?: string[] | undefined;\n}\n\nexport interface CreatePluginRuntimeContextInput {\n pluginId: string;\n request?: unknown;\n response?: unknown;\n requestContext?: PluginRuntimeRequestContext | undefined;\n}\n\nexport interface PluginRuntimeBridge {\n createRequestContext(input: PluginRuntimeRequestContext): PluginRuntimeRequestContext;\n createContext(input: CreatePluginRuntimeContextInput): Promise<PluginContext>;\n runWithContext<T>(requestContext: PluginRuntimeRequestContext, callback: () => Promise<T> | T): Promise<T>;\n}\n\nlet runtimeBridge: PluginRuntimeBridge | undefined;\n\nexport function setPluginRuntimeBridge(bridge: PluginRuntimeBridge): void {\n runtimeBridge = bridge;\n}\n\nfunction getPluginRuntimeBridge(): PluginRuntimeBridge {\n if (!runtimeBridge) {\n throw new Error('Plugin runtime bridge is not available');\n }\n return runtimeBridge;\n}\n\nexport function createPluginRuntimeRequestContext(\n input: PluginRuntimeRequestContext,\n): PluginRuntimeRequestContext {\n return getPluginRuntimeBridge().createRequestContext(input);\n}\n\nexport function createPluginRuntimeContext(\n input: CreatePluginRuntimeContextInput,\n): Promise<PluginContext> {\n return getPluginRuntimeBridge().createContext(input);\n}\n\nexport function runWithPluginRuntimeContext<T>(\n requestContext: PluginRuntimeRequestContext,\n callback: () => Promise<T> | T,\n): Promise<T> {\n return getPluginRuntimeBridge().runWithContext(requestContext, callback);\n}\n","import crypto from 'node:crypto';\nimport type { PluginContext } from './types';\n\ntype OAuthSettingScope = {\n global?: boolean;\n};\n\ntype OAuthSettings = Pick<PluginContext, 'settings' | 'organizationId' | 'userId'>;\n\nexport type OAuthQueryValue =\n | string\n | number\n | boolean\n | null\n | undefined\n | readonly (string | number | boolean | null | undefined)[];\n\nexport type OAuthQueryParams = Record<string, OAuthQueryValue>;\n\nexport type OAuthStateRecord<TPayload extends Record<string, unknown> = Record<string, unknown>> =\n TPayload & {\n createdAt: string;\n expiresAt?: string;\n userId?: string;\n organizationId?: string;\n };\n\nexport interface CreateOAuthStateOptions<TPayload extends Record<string, unknown>> extends OAuthSettingScope {\n keyPrefix: string;\n payload: TPayload;\n bytes?: number;\n ttlSeconds?: number;\n encrypted?: boolean;\n includeContext?: boolean;\n now?: Date;\n}\n\nexport interface ConsumeOAuthStateOptions extends OAuthSettingScope {\n keyPrefix: string;\n state: string;\n deleteOnConsume?: boolean;\n now?: Date;\n}\n\nexport interface VerifyQueryHmacSha256Options {\n signatureKey?: string;\n excludeKeys?: string[];\n digest?: 'hex' | 'base64';\n}\n\nexport function buildOAuthCallbackPath(providerId: string): string {\n const normalized = providerId.trim();\n if (!/^[a-z0-9-]+$/i.test(normalized)) {\n throw new Error(`Invalid OAuth provider id: ${providerId}`);\n }\n return `/api/oauth/${normalized}/callback`;\n}\n\nexport function buildOAuthCallbackUrl(providerId: string, baseUrl: string): string {\n return new URL(buildOAuthCallbackPath(providerId), baseUrl).toString();\n}\n\nexport function buildOAuthResultRedirect(\n path: string,\n params: Record<string, string | number | boolean | null | undefined>,\n): string {\n const url = new URL(path, 'https://wordrhyme.local');\n for (const [key, value] of Object.entries(params)) {\n if (value !== null && value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n\n if (/^https?:\\/\\//i.test(path)) {\n return url.toString();\n }\n return `${url.pathname}${url.search}${url.hash}`;\n}\n\nexport function buildOAuthStateKey(keyPrefix: string, state: string): string {\n const prefix = keyPrefix.trim().replace(/\\.+$/, '');\n if (!prefix) throw new Error('OAuth state keyPrefix is required');\n if (!state) throw new Error('OAuth state is required');\n return `${prefix}.${state}`;\n}\n\nexport function maskOAuthSecret(value: string): string {\n if (value.length <= 8) return '********';\n return `${value.slice(0, 4)}****${value.slice(-4)}`;\n}\n\nexport async function createOAuthState<TPayload extends Record<string, unknown>>(\n ctx: OAuthSettings,\n options: CreateOAuthStateOptions<TPayload>,\n): Promise<{ state: string; key: string; payload: OAuthStateRecord<TPayload> }> {\n if (!ctx.settings) throw new Error('Settings not available');\n\n const state = crypto.randomBytes(options.bytes ?? 24).toString('hex');\n const key = buildOAuthStateKey(options.keyPrefix, state);\n const now = options.now ?? new Date();\n const payload = {\n ...options.payload,\n createdAt: now.toISOString(),\n } as OAuthStateRecord<TPayload>;\n\n if (options.ttlSeconds && options.ttlSeconds > 0) {\n payload.expiresAt = new Date(now.getTime() + options.ttlSeconds * 1000).toISOString();\n }\n\n if (options.includeContext !== false) {\n if (ctx.userId) payload.userId = ctx.userId;\n if (ctx.organizationId) payload.organizationId = ctx.organizationId;\n }\n\n await ctx.settings.set(key, payload, {\n encrypted: options.encrypted ?? true,\n ...(options.global !== undefined ? { global: options.global } : {}),\n });\n\n return { state, key, payload };\n}\n\nexport async function consumeOAuthState<TPayload extends Record<string, unknown> = Record<string, unknown>>(\n ctx: OAuthSettings,\n options: ConsumeOAuthStateOptions,\n): Promise<OAuthStateRecord<TPayload>> {\n if (!ctx.settings) throw new Error('Settings not available');\n\n const key = buildOAuthStateKey(options.keyPrefix, options.state);\n const raw = await ctx.settings.get<unknown>(key);\n const record = parseStateRecord<TPayload>(raw);\n if (!record) {\n throw new Error('Invalid or expired OAuth state');\n }\n\n const now = options.now ?? new Date();\n if (record.expiresAt && Date.parse(record.expiresAt) <= now.getTime()) {\n await ctx.settings.delete(key, scopeOptions(options)).catch(() => false);\n throw new Error('Invalid or expired OAuth state');\n }\n\n if (options.deleteOnConsume !== false) {\n await ctx.settings.delete(key, scopeOptions(options)).catch(() => false);\n }\n\n return record;\n}\n\nexport function createPkcePair(): {\n codeVerifier: string;\n codeChallenge: string;\n method: 'S256';\n} {\n const codeVerifier = base64Url(crypto.randomBytes(32));\n const codeChallenge = base64Url(crypto.createHash('sha256').update(codeVerifier).digest());\n return { codeVerifier, codeChallenge, method: 'S256' };\n}\n\nexport function buildCanonicalQueryString(\n params: OAuthQueryParams,\n excludeKeys: string[] = [],\n): string {\n const exclude = new Set(excludeKeys);\n const entries: Array<[string, string]> = [];\n\n for (const [key, value] of Object.entries(params)) {\n if (exclude.has(key)) continue;\n const values = Array.isArray(value) ? value : [value];\n for (const item of values) {\n if (item !== null && item !== undefined) {\n entries.push([key, String(item)]);\n }\n }\n }\n\n return entries\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => `${key}=${value}`)\n .join('&');\n}\n\nexport function verifyQueryHmacSha256(\n params: OAuthQueryParams,\n secret: string,\n options: VerifyQueryHmacSha256Options = {},\n): boolean {\n if (!secret) return false;\n\n const signatureKey = options.signatureKey ?? 'hmac';\n const signature = firstQueryValue(params[signatureKey]);\n if (!signature) return false;\n\n const excludeKeys = options.excludeKeys ?? [signatureKey];\n const digest = options.digest ?? 'hex';\n const message = buildCanonicalQueryString(params, excludeKeys);\n const computed = crypto.createHmac('sha256', secret).update(message).digest(digest);\n\n return timingSafeEqualString(computed, signature);\n}\n\nexport function timingSafeEqualString(a: string, b: string): boolean {\n const left = Buffer.from(a, 'utf8');\n const right = Buffer.from(b, 'utf8');\n if (left.length !== right.length) return false;\n return crypto.timingSafeEqual(left, right);\n}\n\nfunction parseStateRecord<TPayload extends Record<string, unknown>>(\n value: unknown,\n): OAuthStateRecord<TPayload> | null {\n let parsed = value;\n if (typeof value === 'string') {\n try {\n parsed = JSON.parse(value) as unknown;\n } catch {\n return null;\n }\n }\n\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n return null;\n }\n\n const record = parsed as Record<string, unknown>;\n if (typeof record['createdAt'] !== 'string') {\n return null;\n }\n if ('expiresAt' in record && typeof record['expiresAt'] !== 'string') {\n return null;\n }\n\n return record as OAuthStateRecord<TPayload>;\n}\n\nfunction firstQueryValue(value: OAuthQueryValue): string | null {\n const candidate = Array.isArray(value) ? value.find((item) => item !== null && item !== undefined) : value;\n return candidate === null || candidate === undefined ? null : String(candidate);\n}\n\nfunction base64Url(input: Buffer): string {\n return input\n .toString('base64')\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/g, '');\n}\n\nfunction scopeOptions(options: OAuthSettingScope): OAuthSettingScope | undefined {\n return options.global !== undefined ? { global: options.global } : undefined;\n}\n","import type { PluginContext } from \"./types\";\n\nexport interface PluginPublicServiceRequest {\n method: string;\n path: string;\n query: Record<string, string | string[]>;\n headers: Record<string, string | undefined>;\n body: unknown;\n requestId: string;\n}\n\nexport interface PluginPublicServiceResponse {\n status?: number;\n headers?: Record<string, string>;\n body?: unknown;\n}\n\nexport interface PluginPublicService {\n name: string;\n handle(request: PluginPublicServiceRequest, context: PluginContext): Promise<PluginPublicServiceResponse>;\n}\n\nexport function definePublicService(service: PluginPublicService): PluginPublicService {\n return service;\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,IAAI;AAEG,SAAS,uBAAuB,QAAmC;AACtE,kBAAgB;AACpB;AAEA,SAAS,yBAA8C;AACnD,MAAI,CAAC,eAAe;AAChB,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC5D;AACA,SAAO;AACX;AAEO,SAAS,kCACZ,OAC2B;AAC3B,SAAO,uBAAuB,EAAE,qBAAqB,KAAK;AAC9D;AAEO,SAAS,2BACZ,OACsB;AACtB,SAAO,uBAAuB,EAAE,cAAc,KAAK;AACvD;AAEO,SAAS,4BACZ,gBACA,UACU;AACV,SAAO,uBAAuB,EAAE,eAAe,gBAAgB,QAAQ;AAC3E;;;ACpEA,OAAO,YAAY;AAkDZ,SAAS,uBAAuB,YAA4B;AAC/D,QAAM,aAAa,WAAW,KAAK;AACnC,MAAI,CAAC,gBAAgB,KAAK,UAAU,GAAG;AACnC,UAAM,IAAI,MAAM,8BAA8B,UAAU,EAAE;AAAA,EAC9D;AACA,SAAO,cAAc,UAAU;AACnC;AAEO,SAAS,sBAAsB,YAAoB,SAAy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,KAAK;AAAA,IAC7B,QAAQ;AACJ,aAAO;AAAA,IACX;AAAA,EACJ;AAEA,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAAG;AAChE,WAAO;AAAA,EACX;AAEA,QAAM,SAAS;AACf,MAAI,OAAO,OAAO,WAAW,MAAM,UAAU;AACzC,WAAO;AAAA,EACX;AACA,MAAI,eAAe,UAAU,OAAO,OAAO,WAAW,MAAM,UAAU;AAClE,WAAO;AAAA,EACX;AAEA,SAAO;AACX;AAEA,SAAS,gBAAgB,OAAuC;AAC5D,QAAM,YAAY,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,CAAC,SAAS,SAAS,QAAQ,SAAS,MAAS,IAAI;AACrG,SAAO,cAAc,QAAQ,cAAc,SAAY,OAAO,OAAO,SAAS;AAClF;AAUA,SAAS,aAAa,SAA2D;AAC7E,SAAO,QAAQ,WAAW,SAAY,EAAE,QAAQ,QAAQ,OAAO,IAAI;AACvE;;;ACnOO,SAAS,oBAAoB,SAAmD;AACnF,SAAO;AACX;","names":[]}
package/dist/time.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ declare const DEFAULT_TIME_ZONE = "UTC";
2
+ declare const CLIENT_TIME_ZONE_HEADER = "x-time-zone";
3
+ declare const CLIENT_TIME_ZONE_COOKIE = "wr_time_zone";
4
+ interface DateFilterInput {
5
+ value: unknown;
6
+ variant: string;
7
+ operator: string;
8
+ }
9
+ interface DateFilterRange {
10
+ start?: Date;
11
+ endExclusive?: Date;
12
+ }
13
+ type DateRangeResolver = (filter: DateFilterInput) => DateFilterRange | undefined;
14
+ interface FormatDateTimeOptions extends Intl.DateTimeFormatOptions {
15
+ locale?: string;
16
+ timeZone?: string;
17
+ }
18
+ declare function canonicalizeTimeZone(value: unknown): string | undefined;
19
+ declare function isValidTimeZone(value: unknown): value is string;
20
+ declare function normalizeTimeZone(value: unknown, fallback?: string): string;
21
+ declare function getClientTimeZone(): string | undefined;
22
+ declare function getSupportedTimeZones(): string[];
23
+ declare function toUtcDayRange(dateOnly: string, timeZone: string): DateFilterRange | undefined;
24
+ declare function resolveDateFilterRange(filter: DateFilterInput, options: {
25
+ timeZone: string;
26
+ clientTimeZone?: string;
27
+ legacyClientTimeZone?: string;
28
+ now?: Date;
29
+ }): DateFilterRange | undefined;
30
+ declare function toUtcDateTime(localValue: string, timeZone: string): Date | undefined;
31
+ declare function toDateTimeLocal(value: Date | string | number, timeZone: string): string;
32
+ declare function formatDateTime(value: Date | string | number, options?: FormatDateTimeOptions): string;
33
+
34
+ export { CLIENT_TIME_ZONE_COOKIE, CLIENT_TIME_ZONE_HEADER, DEFAULT_TIME_ZONE, type DateFilterInput, type DateFilterRange, type DateRangeResolver, type FormatDateTimeOptions, canonicalizeTimeZone, formatDateTime, getClientTimeZone, getSupportedTimeZones, isValidTimeZone, normalizeTimeZone, resolveDateFilterRange, toDateTimeLocal, toUtcDateTime, toUtcDayRange };
package/dist/time.js ADDED
@@ -0,0 +1,31 @@
1
+ import {
2
+ CLIENT_TIME_ZONE_COOKIE,
3
+ CLIENT_TIME_ZONE_HEADER,
4
+ DEFAULT_TIME_ZONE,
5
+ canonicalizeTimeZone,
6
+ formatDateTime,
7
+ getClientTimeZone,
8
+ getSupportedTimeZones,
9
+ isValidTimeZone,
10
+ normalizeTimeZone,
11
+ resolveDateFilterRange,
12
+ toDateTimeLocal,
13
+ toUtcDateTime,
14
+ toUtcDayRange
15
+ } from "./chunk-6GDCFR67.js";
16
+ export {
17
+ CLIENT_TIME_ZONE_COOKIE,
18
+ CLIENT_TIME_ZONE_HEADER,
19
+ DEFAULT_TIME_ZONE,
20
+ canonicalizeTimeZone,
21
+ formatDateTime,
22
+ getClientTimeZone,
23
+ getSupportedTimeZones,
24
+ isValidTimeZone,
25
+ normalizeTimeZone,
26
+ resolveDateFilterRange,
27
+ toDateTimeLocal,
28
+ toUtcDateTime,
29
+ toUtcDayRange
30
+ };
31
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}