@worldcoin/idkit 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/internal.ts
31
+ var internal_exports = {};
32
+ __export(internal_exports, {
33
+ ConfigSource: () => ConfigSource,
34
+ QRCode: () => QRCode_default,
35
+ __: () => __,
36
+ useIDKitStore: () => idkit_default
37
+ });
38
+ module.exports = __toCommonJS(internal_exports);
39
+
40
+ // src/lang/index.ts
41
+ var translations = {};
42
+ var getLang = () => {
43
+ if (!navigator?.languages) return;
44
+ const supportedLang = navigator.languages.find((l) => translations[l] != void 0) ?? "";
45
+ return translations[supportedLang];
46
+ };
47
+ var replaceParams = (str, params) => {
48
+ let replaced = str;
49
+ for (const [key, value] of Object.entries(params ?? {})) replaced = str.replace(`:${key}`, value);
50
+ return replaced;
51
+ };
52
+ function __(str, params) {
53
+ if (typeof navigator === "undefined") return str;
54
+ return replaceParams(getLang()?.[str] ?? str, params);
55
+ }
56
+
57
+ // src/components/QRCode.tsx
58
+ var import_react = require("react");
59
+ var import_qrcode = __toESM(require("qrcode/lib/core/qrcode.js"), 1);
60
+ var import_jsx_runtime = require("react/jsx-runtime");
61
+ var generateMatrix = (data) => {
62
+ const arr = import_qrcode.default.create(data, { errorCorrectionLevel: "M" }).modules.data;
63
+ const sqrt = Math.sqrt(arr.length);
64
+ return arr.reduce(
65
+ (rows, key, index) => {
66
+ if (index % sqrt === 0) rows.push([key]);
67
+ else rows[rows.length - 1].push(key);
68
+ return rows;
69
+ },
70
+ []
71
+ );
72
+ };
73
+ var Qrcode = ({ data, size = 300 }) => {
74
+ const dots = (0, import_react.useMemo)(() => {
75
+ const dots2 = [];
76
+ const matrix = generateMatrix(data);
77
+ const cellSize = size / matrix.length;
78
+ const qrList = [
79
+ { x: 0, y: 0 },
80
+ { x: 1, y: 0 },
81
+ { x: 0, y: 1 }
82
+ ];
83
+ qrList.forEach(({ x, y }) => {
84
+ const x1 = (matrix.length - 7) * cellSize * x;
85
+ const y1 = (matrix.length - 7) * cellSize * y;
86
+ for (let i = 0; i < 3; i++) {
87
+ dots2.push(
88
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
+ "rect",
90
+ {
91
+ fill: "currentColor",
92
+ x: x1 + cellSize * i,
93
+ y: y1 + cellSize * i,
94
+ width: cellSize * (7 - i * 2),
95
+ height: cellSize * (7 - i * 2),
96
+ rx: (i - 2) * -5,
97
+ ry: (i - 2) * -5,
98
+ className: i % 3 === 0 ? "text-black" : i % 3 === 1 ? "text-white" : "text-black"
99
+ },
100
+ `${i}-${x}-${y}`
101
+ )
102
+ );
103
+ }
104
+ });
105
+ matrix.forEach((row, i) => {
106
+ row.forEach((_, j) => {
107
+ if (!matrix[i][j]) return;
108
+ if (i < 7 && j < 7 || i > matrix.length - 8 && j < 7 || i < 7 && j > matrix.length - 8) return;
109
+ dots2.push(
110
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
111
+ "circle",
112
+ {
113
+ fill: "currentColor",
114
+ r: cellSize / 3,
115
+ cx: i * cellSize + cellSize / 2,
116
+ cy: j * cellSize + cellSize / 2,
117
+ className: "text-black dark:text-white"
118
+ },
119
+ `circle-${i}-${j}`
120
+ )
121
+ );
122
+ });
123
+ });
124
+ return dots2;
125
+ }, [size, data]);
126
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { height: size, width: size, "data-test-id": "qr-code", children: dots });
127
+ };
128
+ var QRCode_default = (0, import_react.memo)(Qrcode);
129
+
130
+ // src/store/idkit.ts
131
+ var import_shallow = require("zustand/shallow");
132
+ var import_traditional = require("zustand/traditional");
133
+ var import_idkit_core = require("@worldcoin/idkit-core");
134
+ var SELF_HOSTED_APP_ID = "self_hosted";
135
+ var useIDKitStore = (0, import_traditional.createWithEqualityFn)()(
136
+ (set, get) => ({
137
+ app_id: "",
138
+ signal: "",
139
+ action: "",
140
+ action_description: "",
141
+ bridge_url: "",
142
+ verification_level: import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
143
+ partner: false,
144
+ open: false,
145
+ result: null,
146
+ errorTitle: "",
147
+ errorDetail: "",
148
+ autoClose: true,
149
+ errorState: null,
150
+ processing: false,
151
+ errorCallbacks: {},
152
+ verifyCallbacks: {},
153
+ successCallbacks: {},
154
+ stage: "WORLD_ID" /* WORLD_ID */,
155
+ setStage: (stage) => set({ stage }),
156
+ setErrorState: (errorState) => set({ errorState }),
157
+ setProcessing: (processing) => set({ processing }),
158
+ retryFlow: () => {
159
+ set({ stage: "WORLD_ID" /* WORLD_ID */, errorState: null });
160
+ },
161
+ addErrorCallback: (cb, source) => {
162
+ set((state) => {
163
+ state.errorCallbacks[source] = cb;
164
+ return state;
165
+ });
166
+ },
167
+ addSuccessCallback: (cb, source) => {
168
+ set((state) => {
169
+ state.successCallbacks[source] = cb;
170
+ return state;
171
+ });
172
+ },
173
+ addVerificationCallback: (cb, source) => {
174
+ set((state) => {
175
+ state.verifyCallbacks[source] = cb;
176
+ return state;
177
+ });
178
+ },
179
+ setOptions: ({
180
+ handleVerify,
181
+ onSuccess,
182
+ signal,
183
+ action,
184
+ app_id,
185
+ partner,
186
+ onError,
187
+ verification_level,
188
+ action_description,
189
+ bridge_url,
190
+ autoClose,
191
+ advanced
192
+ }, source) => {
193
+ set({
194
+ signal,
195
+ action,
196
+ bridge_url,
197
+ action_description,
198
+ autoClose: autoClose ?? true,
199
+ app_id: advanced?.self_hosted ? SELF_HOSTED_APP_ID : app_id,
200
+ verification_level: verification_level ?? import_idkit_core.DEFAULT_VERIFICATION_LEVEL,
201
+ partner
202
+ });
203
+ get().addSuccessCallback(onSuccess, source);
204
+ if (onError) get().addErrorCallback(onError, source);
205
+ if (handleVerify) get().addVerificationCallback(handleVerify, source);
206
+ },
207
+ handleVerify: (result) => {
208
+ set({ stage: "HOST_APP_VERIFICATION" /* HOST_APP_VERIFICATION */, processing: false });
209
+ Promise.all(Object.values(get().verifyCallbacks).map(async (cb) => cb?.(result))).then(
210
+ () => {
211
+ set({ stage: "SUCCESS" /* SUCCESS */, result });
212
+ if (get().autoClose) setTimeout(() => get().onOpenChange(false), 2500);
213
+ },
214
+ (response) => {
215
+ let errorMessage = void 0;
216
+ if (response && typeof response === "object" && response.message) {
217
+ errorMessage = response.message;
218
+ }
219
+ set({
220
+ stage: "ERROR" /* ERROR */,
221
+ errorState: {
222
+ code: import_idkit_core.AppErrorCodes.FailedByHostApp,
223
+ message: errorMessage ? __(errorMessage) : void 0
224
+ }
225
+ });
226
+ }
227
+ );
228
+ },
229
+ onOpenChange: (open) => {
230
+ if (open) {
231
+ return set({ open });
232
+ }
233
+ const errorState = get().errorState;
234
+ if (get().stage === "ERROR" /* ERROR */ && errorState) {
235
+ const callbacks = get().errorCallbacks;
236
+ requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(errorState)));
237
+ }
238
+ const result = get().result;
239
+ if (get().stage == "SUCCESS" /* SUCCESS */ && result) {
240
+ const callbacks = get().successCallbacks;
241
+ requestAnimationFrame(() => Object.values(callbacks).forEach((cb) => void cb?.(result)));
242
+ }
243
+ set({
244
+ open,
245
+ result: null,
246
+ errorState: null,
247
+ processing: false,
248
+ stage: "WORLD_ID" /* WORLD_ID */
249
+ });
250
+ }
251
+ }),
252
+ import_shallow.shallow
253
+ );
254
+ var idkit_default = useIDKitStore;
255
+
256
+ // src/types/config.ts
257
+ var ConfigSource = /* @__PURE__ */ ((ConfigSource2) => {
258
+ ConfigSource2["HOOK"] = "hook";
259
+ ConfigSource2["PROPS"] = "props";
260
+ ConfigSource2["MANUAL"] = "manual";
261
+ return ConfigSource2;
262
+ })(ConfigSource || {});
263
+ // Annotate the CommonJS export names for ESM import in node:
264
+ 0 && (module.exports = {
265
+ ConfigSource,
266
+ QRCode,
267
+ __,
268
+ useIDKitStore
269
+ });
@@ -0,0 +1,53 @@
1
+ import * as react from 'react';
2
+ import * as zustand_traditional from 'zustand/traditional';
3
+ import * as zustand_vanilla from 'zustand/vanilla';
4
+ import { I as IDKITStage, a as ConfigSource, b as CallbackFn, C as Config } from './config-BRFx4nLT.cjs';
5
+ import { IDKitConfig, ISuccessResult, IErrorState } from '@worldcoin/idkit-core';
6
+
7
+ type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}` ? never : T extends '' ? never : T;
8
+ type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}` ? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}` ? CleanWord<Word> | ExtractPlaceholders<Rest> : never : never;
9
+ type NoPlaceholder<S extends string> = S extends `${string}:${string}` ? never : S;
10
+ type PlaceholderValues<S extends string> = {
11
+ [K in ExtractPlaceholders<S>]: string;
12
+ };
13
+ declare function __<S extends `${string}:${string}`>(str: S, params: PlaceholderValues<S>): string;
14
+ declare function __<S extends string>(str: NoPlaceholder<S>): string;
15
+
16
+ type Props = {
17
+ data: string;
18
+ size?: number;
19
+ };
20
+ declare const _default: react.MemoExoticComponent<({ data, size }: Props) => JSX.Element>;
21
+
22
+ declare const SELF_HOSTED_APP_ID = "self_hosted";
23
+ type IDKitStore = {
24
+ app_id: IDKitConfig['app_id'] | typeof SELF_HOSTED_APP_ID | '';
25
+ action: IDKitConfig['action'];
26
+ signal: IDKitConfig['signal'];
27
+ bridge_url?: IDKitConfig['bridge_url'];
28
+ action_description?: IDKitConfig['action_description'];
29
+ verification_level: NonNullable<IDKitConfig['verification_level']>;
30
+ partner?: IDKitConfig['partner'];
31
+ open: boolean;
32
+ stage: IDKITStage;
33
+ autoClose: boolean;
34
+ processing: boolean;
35
+ result: ISuccessResult | null;
36
+ errorState: IErrorState | null;
37
+ errorCallbacks: Record<ConfigSource, CallbackFn<IErrorState> | undefined> | Record<string, never>;
38
+ verifyCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
39
+ successCallbacks: Record<ConfigSource, CallbackFn<ISuccessResult> | undefined> | Record<string, never>;
40
+ retryFlow: () => void;
41
+ setStage: (stage: IDKITStage) => void;
42
+ onOpenChange: (open: boolean) => void;
43
+ setProcessing: (processing: boolean) => void;
44
+ handleVerify: (result: ISuccessResult) => void;
45
+ setErrorState: (state: IErrorState | null) => void;
46
+ setOptions: (options: Config, source: ConfigSource) => void;
47
+ addErrorCallback: (cb: CallbackFn<IErrorState>, source: ConfigSource) => void;
48
+ addSuccessCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
49
+ addVerificationCallback: (cb: CallbackFn<ISuccessResult>, source: ConfigSource) => void;
50
+ };
51
+ declare const useIDKitStore: zustand_traditional.UseBoundStoreWithEqualityFn<zustand_vanilla.StoreApi<IDKitStore>>;
52
+
53
+ export { ConfigSource, _default as QRCode, __, useIDKitStore };
package/package.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "copy-to-clipboard": "^3.3.3",
7
7
  "framer-motion": "^11.2.14",
8
8
  "qrcode": "^1.5.3",
9
- "react-shadow": "^19.1.0",
10
9
  "zustand": "^4.5.4",
11
10
  "@worldcoin/idkit-core": "2.1.0"
12
11
  },
@@ -43,12 +42,24 @@
43
42
  },
44
43
  "exports": {
45
44
  ".": {
46
- "import": "./build/index.js",
47
- "types": "./build/index.d.ts"
45
+ "import": {
46
+ "types": "./build/index.d.ts",
47
+ "default": "./build/index.js"
48
+ },
49
+ "require": {
50
+ "types": "./build/index.d.cts",
51
+ "default": "./build/index.cjs"
52
+ }
48
53
  },
49
54
  "./internal": {
50
- "import": "./build/internal.js",
51
- "types": "./build/internal.d.ts"
55
+ "import": {
56
+ "types": "./build/internal.d.ts",
57
+ "default": "./build/internal.js"
58
+ },
59
+ "require": {
60
+ "types": "./build/internal.d.cts",
61
+ "default": "./build/internal.cjs"
62
+ }
52
63
  }
53
64
  },
54
65
  "files": [
@@ -92,7 +103,7 @@
92
103
  ]
93
104
  }
94
105
  },
95
- "version": "2.2.0",
106
+ "version": "2.2.2",
96
107
  "scripts": {
97
108
  "build": "npm run build:css && tsup",
98
109
  "build:css": "npx tailwindcss -i ./src/styles/styles.css -o ./build/index.css --minify",