isa-auth 0.2.0 → 0.2.1

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.
package/dist/index.js CHANGED
@@ -2882,7 +2882,7 @@ var require_providers = __commonJS({
2882
2882
  }, get developerProviders() {
2883
2883
  return _developer.developerProviders;
2884
2884
  }, get getProvider() {
2885
- return getProvider;
2885
+ return getProvider2;
2886
2886
  }, get getProviderCategory() {
2887
2887
  return getProviderCategory2;
2888
2888
  }, get getProvidersByCategory() {
@@ -2935,7 +2935,7 @@ var require_providers = __commonJS({
2935
2935
  return {};
2936
2936
  }
2937
2937
  };
2938
- var getProvider = (provider) => {
2938
+ var getProvider2 = (provider) => {
2939
2939
  if (provider === "none") {
2940
2940
  return null;
2941
2941
  }
@@ -3262,7 +3262,7 @@ var require_components = __commonJS({
3262
3262
  }, get discordLoginButton() {
3263
3263
  return _discordLogin.default;
3264
3264
  }, get getButton() {
3265
- return getButton;
3265
+ return getButton2;
3266
3266
  }, get githubLoginButton() {
3267
3267
  return _githubLogin.default;
3268
3268
  }, get googleLoginButton() {
@@ -3311,7 +3311,7 @@ var require_components = __commonJS({
3311
3311
  return obj && obj.__esModule ? obj : { default: obj };
3312
3312
  }
3313
3313
  var buttons = { google: _googleLogin.default, kakao: _kakaoLogin.default, naver: _naverLogin.default, apple: _appleLogin.default, line: _lineLogin.default, wechat: _wechatLogin.default, meta: _metaLogin.default, facebook: _metaLogin.default, web3: _web3Login.default, github: _githubLogin.default, discord: _discordLogin.default, world: _worldLogin.default, passkey: _passkeyLogin.default, none: null };
3314
- var getButton = (provider) => {
3314
+ var getButton2 = (provider) => {
3315
3315
  if (provider === "none") {
3316
3316
  return null;
3317
3317
  }
@@ -3384,12 +3384,12 @@ var require_mappings = __commonJS({
3384
3384
  for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get });
3385
3385
  }
3386
3386
  _export(exports2, { get providerToButtonMap() {
3387
- return providerToButtonMap;
3387
+ return providerToButtonMap2;
3388
3388
  }, get providerToServiceMap() {
3389
3389
  return providerToServiceMap;
3390
3390
  } });
3391
3391
  var providerToServiceMap = { base: "base", jwt: "jwt", google: "jwt", kakao: "jwt", naver: "jwt", web3: "base", github: "jwt", apple: "jwt", discord: "jwt", line: "jwt", meta: "jwt", facebook: "jwt", world: "base", passkey: "base" };
3392
- var providerToButtonMap = { base: "none", jwt: "none", google: "google", kakao: "kakao", naver: "naver", web3: "web3", github: "github", apple: "apple", discord: "discord", line: "line", meta: "meta", facebook: "facebook", world: "world", passkey: "passkey" };
3392
+ var providerToButtonMap2 = { base: "none", jwt: "none", google: "google", kakao: "kakao", naver: "naver", web3: "web3", github: "github", apple: "apple", discord: "discord", line: "line", meta: "meta", facebook: "facebook", world: "world", passkey: "passkey" };
3393
3393
  }
3394
3394
  });
3395
3395
 
@@ -4116,110 +4116,147 @@ function registerWebComponent() {
4116
4116
  var IsaAuth = class {
4117
4117
  constructor(config = {}) {
4118
4118
  this.providerInstance = null;
4119
+ this.providerInstances = /* @__PURE__ */ new Map();
4120
+ this.authProviders = /* @__PURE__ */ new Map();
4121
+ this.config = config;
4119
4122
  const {
4120
- provider = "base",
4123
+ provider,
4121
4124
  secret = "isa-auth-secret",
4122
4125
  clientId = "",
4123
4126
  callbackUrl = "",
4124
4127
  scope,
4125
4128
  storage = "memory",
4126
4129
  storagePrefix = "",
4127
- extraOptions = {}
4130
+ extraOptions = {},
4131
+ providers: multiProviders
4128
4132
  } = config;
4129
- this.providerType = provider;
4133
+ const firstMultiKey = multiProviders ? Object.keys(multiProviders)[0] : void 0;
4134
+ const primaryProvider = provider || firstMultiKey || "base";
4135
+ this.providerType = primaryProvider;
4130
4136
  this.core = new import_isa_auth_core.default({
4131
- providerType: provider,
4137
+ providerType: primaryProvider,
4132
4138
  secret,
4133
4139
  storage,
4134
4140
  storagePrefix
4135
4141
  });
4136
- const ProviderClass = this.core.getProvider();
4137
- if (ProviderClass) {
4138
- if (provider === "google") {
4139
- this.providerInstance = new ProviderClass({
4140
- clientId,
4141
- callback: (token) => {
4142
- this.setAccessToken(token);
4143
- return token;
4144
- },
4145
- ...extraOptions
4146
- });
4147
- } else if (provider === "kakao") {
4148
- this.providerInstance = new ProviderClass({
4149
- javascriptKey: clientId,
4150
- redirectUri: callbackUrl,
4151
- scope,
4152
- ...extraOptions
4153
- });
4154
- } else if (provider === "naver") {
4155
- this.providerInstance = new ProviderClass({
4156
- clientId,
4157
- callbackUrl,
4158
- ...extraOptions
4159
- });
4160
- } else if (provider === "web3") {
4161
- this.providerInstance = new ProviderClass({
4162
- domain: typeof window !== "undefined" ? window.location.host : "localhost",
4163
- ...extraOptions
4164
- });
4165
- } else if (provider === "github") {
4166
- this.providerInstance = new ProviderClass({
4167
- clientId,
4168
- redirectUri: callbackUrl,
4169
- scope,
4170
- ...extraOptions
4171
- });
4172
- } else if (provider === "apple") {
4173
- this.providerInstance = new ProviderClass({
4174
- clientId,
4175
- redirectURI: callbackUrl,
4176
- scope,
4177
- ...extraOptions
4178
- });
4179
- } else if (provider === "discord") {
4180
- this.providerInstance = new ProviderClass({
4181
- clientId,
4182
- redirectUri: callbackUrl,
4183
- scope,
4184
- ...extraOptions
4185
- });
4186
- } else if (provider === "line") {
4187
- this.providerInstance = new ProviderClass({
4188
- clientId,
4189
- callbackUrl,
4190
- scope,
4191
- ...extraOptions
4192
- });
4193
- } else if (provider === "meta" || provider === "facebook") {
4194
- this.providerInstance = new ProviderClass({
4195
- appId: clientId,
4196
- redirectUri: callbackUrl,
4197
- scope,
4198
- ...extraOptions
4199
- });
4200
- } else if (provider === "world") {
4201
- this.providerInstance = new ProviderClass({
4202
- appId: clientId,
4203
- action: extraOptions.action || "login",
4204
- verificationLevel: extraOptions.verificationLevel || "orb",
4205
- ...extraOptions
4206
- });
4207
- } else if (provider === "passkey") {
4208
- this.providerInstance = new ProviderClass({
4209
- rpName: extraOptions.rpName || "ISA-AUTH Application",
4210
- rpId: extraOptions.rpId,
4211
- ...extraOptions
4212
- });
4213
- } else {
4214
- this.providerInstance = new ProviderClass({
4215
- clientId,
4216
- ...extraOptions
4217
- });
4142
+ const service = this.core.getService();
4143
+ if (multiProviders) {
4144
+ for (const [key, opts] of Object.entries(multiProviders)) {
4145
+ const pType = key;
4146
+ const instance = this.instantiateProvider(pType, opts || {});
4147
+ if (instance) {
4148
+ this.providerInstances.set(pType, instance);
4149
+ const btn = (0, import_isa_auth_core.getButton)(import_isa_auth_core.providerToButtonMap[pType] || "none");
4150
+ this.authProviders.set(pType, new AuthProvider_default(service, instance, btn));
4151
+ }
4218
4152
  }
4219
4153
  }
4220
- const button = this.core.getButton();
4221
- const service = this.core.getService();
4222
- this.authProvider = new AuthProvider_default(service, this.providerInstance, button);
4154
+ if (provider && !this.providerInstances.has(provider)) {
4155
+ const singleOpts = {
4156
+ clientId,
4157
+ callbackUrl,
4158
+ scope,
4159
+ extraOptions
4160
+ };
4161
+ const instance = this.instantiateProvider(provider, singleOpts);
4162
+ if (instance) {
4163
+ this.providerInstances.set(provider, instance);
4164
+ const btn = this.core.getButton();
4165
+ this.authProviders.set(provider, new AuthProvider_default(service, instance, btn));
4166
+ }
4167
+ }
4168
+ this.providerInstance = this.providerInstances.get(primaryProvider) || null;
4169
+ this.authProvider = this.authProviders.get(primaryProvider) || new AuthProvider_default(service, this.providerInstance, this.core.getButton());
4170
+ }
4171
+ instantiateProvider(type, opts) {
4172
+ if (type === "base" || type === "jwt") {
4173
+ return null;
4174
+ }
4175
+ const ProviderClass = (0, import_isa_auth_core.getProvider)(type);
4176
+ if (!ProviderClass) return null;
4177
+ const { clientId = "", callbackUrl = "", scope, extraOptions = {}, ...rest } = opts;
4178
+ const merged = { ...rest, ...extraOptions };
4179
+ if (type === "google") {
4180
+ return new ProviderClass({
4181
+ clientId,
4182
+ callback: (token) => {
4183
+ this.setAccessToken(token);
4184
+ return token;
4185
+ },
4186
+ ...merged
4187
+ });
4188
+ } else if (type === "kakao") {
4189
+ return new ProviderClass({
4190
+ javascriptKey: clientId,
4191
+ redirectUri: callbackUrl,
4192
+ scope,
4193
+ ...merged
4194
+ });
4195
+ } else if (type === "naver") {
4196
+ return new ProviderClass({
4197
+ clientId,
4198
+ callbackUrl,
4199
+ ...merged
4200
+ });
4201
+ } else if (type === "web3") {
4202
+ return new ProviderClass({
4203
+ domain: typeof window !== "undefined" ? window.location.host : "localhost",
4204
+ ...merged
4205
+ });
4206
+ } else if (type === "github") {
4207
+ return new ProviderClass({
4208
+ clientId,
4209
+ redirectUri: callbackUrl,
4210
+ scope,
4211
+ ...merged
4212
+ });
4213
+ } else if (type === "apple") {
4214
+ return new ProviderClass({
4215
+ clientId,
4216
+ redirectURI: callbackUrl,
4217
+ scope,
4218
+ ...merged
4219
+ });
4220
+ } else if (type === "discord") {
4221
+ return new ProviderClass({
4222
+ clientId,
4223
+ redirectUri: callbackUrl,
4224
+ scope,
4225
+ ...merged
4226
+ });
4227
+ } else if (type === "line") {
4228
+ return new ProviderClass({
4229
+ clientId,
4230
+ callbackUrl,
4231
+ scope,
4232
+ ...merged
4233
+ });
4234
+ } else if (type === "meta" || type === "facebook") {
4235
+ return new ProviderClass({
4236
+ appId: clientId,
4237
+ redirectUri: callbackUrl,
4238
+ scope,
4239
+ ...merged
4240
+ });
4241
+ } else if (type === "world") {
4242
+ return new ProviderClass({
4243
+ appId: clientId,
4244
+ action: merged.action || "login",
4245
+ verificationLevel: merged.verificationLevel || "orb",
4246
+ ...merged
4247
+ });
4248
+ } else if (type === "passkey") {
4249
+ return new ProviderClass({
4250
+ rpName: merged.rpName || "ISA-AUTH Application",
4251
+ rpId: merged.rpId,
4252
+ ...merged
4253
+ });
4254
+ } else {
4255
+ return new ProviderClass({
4256
+ clientId,
4257
+ ...merged
4258
+ });
4259
+ }
4223
4260
  }
4224
4261
  // 1. Core State Methods
4225
4262
  isAuthenticated() {
@@ -4235,10 +4272,11 @@ var IsaAuth = class {
4235
4272
  return this.core.getContext();
4236
4273
  }
4237
4274
  /**
4238
- * Returns current provider category ('social' | 'developer' | 'web3' | 'identity' | null)
4275
+ * Returns category of the specified or primary provider
4239
4276
  */
4240
- getCategory() {
4241
- return (0, import_isa_auth_core.getProviderCategory)(this.providerType);
4277
+ getCategory(provider) {
4278
+ const target = provider || this.providerType;
4279
+ return (0, import_isa_auth_core.getProviderCategory)(target);
4242
4280
  }
4243
4281
  setAccessToken(token) {
4244
4282
  const service = this.core.getService();
@@ -4260,8 +4298,19 @@ var IsaAuth = class {
4260
4298
  updateAuthInfo(partial) {
4261
4299
  return this.core.updateAuthInfo(partial);
4262
4300
  }
4263
- // 2. Authentication Actions
4264
- async signIn() {
4301
+ // 2. Authentication Actions (Multi-Provider Support)
4302
+ async signIn(provider) {
4303
+ if (provider) {
4304
+ const targetAuthProvider = this.authProviders.get(provider);
4305
+ if (targetAuthProvider) {
4306
+ return await targetAuthProvider.signIn();
4307
+ }
4308
+ const targetInstance = this.providerInstances.get(provider);
4309
+ if (targetInstance && typeof targetInstance.signIn === "function") {
4310
+ return await targetInstance.signIn();
4311
+ }
4312
+ throw new Error(`[ISA-AUTH] Provider "${provider}" is not registered in this IsaAuth instance.`);
4313
+ }
4265
4314
  return await this.authProvider.signIn();
4266
4315
  }
4267
4316
  signOut() {
@@ -4283,25 +4332,86 @@ var IsaAuth = class {
4283
4332
  stopAutoRefresh() {
4284
4333
  this.core.stopAutoRefresh();
4285
4334
  }
4286
- // 3. UI and Renderers
4287
- getButton() {
4335
+ // 3. UI and Renderers (Multi-Provider Support)
4336
+ getButton(provider) {
4337
+ if (provider) {
4338
+ const target = this.authProviders.get(provider);
4339
+ return target ? target.getButton() : (0, import_isa_auth_core.getButton)(import_isa_auth_core.providerToButtonMap[provider] || "none");
4340
+ }
4288
4341
  return this.authProvider.getButton();
4289
4342
  }
4290
- renderButton(container) {
4291
- const buttonData = this.getButton();
4343
+ /**
4344
+ * Renders button for specified provider (or primary provider if omitted)
4345
+ * Usage:
4346
+ * auth.renderButton(container); // primary provider
4347
+ * auth.renderButton('google', container); // specific provider
4348
+ */
4349
+ renderButton(providerOrContainer, container) {
4350
+ let targetProvider = this.providerType;
4351
+ let targetContainer = null;
4352
+ if (typeof providerOrContainer === "string") {
4353
+ targetProvider = providerOrContainer;
4354
+ targetContainer = container || null;
4355
+ } else {
4356
+ targetContainer = providerOrContainer || null;
4357
+ }
4358
+ const buttonData = this.getButton(targetProvider);
4292
4359
  if (!buttonData) return null;
4360
+ const data = typeof buttonData.toJSON === "function" ? buttonData.toJSON() : buttonData;
4293
4361
  const btn = renderByJs({
4294
- onClick: () => this.signIn(),
4295
- label: buttonData.text,
4296
- className: buttonData.className,
4297
- style: buttonData.style
4362
+ onClick: () => this.signIn(targetProvider),
4363
+ label: data.text,
4364
+ className: data.className,
4365
+ style: data.style
4298
4366
  });
4299
- if (container) {
4300
- container.innerHTML = "";
4301
- container.appendChild(btn);
4367
+ if (btn) {
4368
+ if (!btn.dataset) btn.dataset = {};
4369
+ btn.dataset.provider = targetProvider;
4370
+ }
4371
+ if (targetContainer) {
4372
+ targetContainer.innerHTML = "";
4373
+ targetContainer.appendChild(btn);
4302
4374
  }
4303
4375
  return btn;
4304
4376
  }
4377
+ /**
4378
+ * Renders all registered provider buttons inside a container element.
4379
+ */
4380
+ renderAllButtons(container, options = {}) {
4381
+ if (!container) return [];
4382
+ const { direction = "column", gap = "8px" } = options;
4383
+ const providerList = options.providers || Array.from(this.providerInstances.keys());
4384
+ const wrapper = document.createElement("div");
4385
+ wrapper.className = "isa-auth-button-group";
4386
+ wrapper.style.display = direction === "grid" ? "grid" : "flex";
4387
+ wrapper.style.flexDirection = direction === "row" ? "row" : "column";
4388
+ if (direction === "grid") {
4389
+ wrapper.style.gridTemplateColumns = "repeat(auto-fill, minmax(180px, 1fr))";
4390
+ }
4391
+ wrapper.style.gap = gap;
4392
+ const buttons = [];
4393
+ for (const p of providerList) {
4394
+ const slot = document.createElement("div");
4395
+ slot.className = `isa-auth-slot-${p}`;
4396
+ const btn = this.renderButton(p, slot);
4397
+ if (btn) {
4398
+ buttons.push(btn);
4399
+ wrapper.appendChild(slot);
4400
+ }
4401
+ }
4402
+ container.innerHTML = "";
4403
+ container.appendChild(wrapper);
4404
+ return buttons;
4405
+ }
4406
+ getProviderInstance(provider) {
4407
+ if (provider) {
4408
+ return this.providerInstances.get(provider) || null;
4409
+ }
4410
+ return this.providerInstance;
4411
+ }
4412
+ getRegisteredProviders() {
4413
+ return Array.from(this.providerInstances.keys());
4414
+ }
4305
4415
  // 4. RBAC, ABAC & Enhanced Guards
4306
4416
  hasRole(role) {
4307
4417
  return this.authProvider.hasRole(role);
@@ -4309,34 +4419,18 @@ var IsaAuth = class {
4309
4419
  hasPermission(permission) {
4310
4420
  return this.authProvider.hasPermission(permission);
4311
4421
  }
4312
- /**
4313
- * Check permission with wildcard matching support
4314
- * E.g. isaAuth.can('users:read') or isaAuth.can(['users:read', 'users:write'])
4315
- */
4316
4422
  can(permission, matchAll = true) {
4317
4423
  return this.core.hasPermission(permission, matchAll);
4318
4424
  }
4319
- /**
4320
- * Check role with optional matchAll option
4321
- */
4322
4425
  is(role, matchAll = false) {
4323
4426
  return this.core.hasRole(role, matchAll);
4324
4427
  }
4325
- /**
4326
- * Evaluates guard and returns detailed GuardResult
4327
- */
4328
4428
  async evaluateGuard(options, customContext) {
4329
4429
  return this.core.evaluateGuard(options, customContext);
4330
4430
  }
4331
- /**
4332
- * Instant boolean guard check (backwards compatible)
4333
- */
4334
4431
  createGuard(options) {
4335
4432
  return this.core.createGuard(options);
4336
4433
  }
4337
- /**
4338
- * Creates a reusable router navigation guard
4339
- */
4340
4434
  createNavigationGuard(options) {
4341
4435
  return (0, import_isa_auth_core.createNavigationGuard)({
4342
4436
  ...options,