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.mjs CHANGED
@@ -2887,7 +2887,7 @@ var require_providers = __commonJS({
2887
2887
  }, get developerProviders() {
2888
2888
  return _developer.developerProviders;
2889
2889
  }, get getProvider() {
2890
- return getProvider;
2890
+ return getProvider2;
2891
2891
  }, get getProviderCategory() {
2892
2892
  return getProviderCategory2;
2893
2893
  }, get getProvidersByCategory() {
@@ -2940,7 +2940,7 @@ var require_providers = __commonJS({
2940
2940
  return {};
2941
2941
  }
2942
2942
  };
2943
- var getProvider = (provider) => {
2943
+ var getProvider2 = (provider) => {
2944
2944
  if (provider === "none") {
2945
2945
  return null;
2946
2946
  }
@@ -3267,7 +3267,7 @@ var require_components = __commonJS({
3267
3267
  }, get discordLoginButton() {
3268
3268
  return _discordLogin.default;
3269
3269
  }, get getButton() {
3270
- return getButton;
3270
+ return getButton2;
3271
3271
  }, get githubLoginButton() {
3272
3272
  return _githubLogin.default;
3273
3273
  }, get googleLoginButton() {
@@ -3316,7 +3316,7 @@ var require_components = __commonJS({
3316
3316
  return obj && obj.__esModule ? obj : { default: obj };
3317
3317
  }
3318
3318
  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 };
3319
- var getButton = (provider) => {
3319
+ var getButton2 = (provider) => {
3320
3320
  if (provider === "none") {
3321
3321
  return null;
3322
3322
  }
@@ -3389,12 +3389,12 @@ var require_mappings = __commonJS({
3389
3389
  for (var name in all) Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get });
3390
3390
  }
3391
3391
  _export(exports, { get providerToButtonMap() {
3392
- return providerToButtonMap;
3392
+ return providerToButtonMap2;
3393
3393
  }, get providerToServiceMap() {
3394
3394
  return providerToServiceMap;
3395
3395
  } });
3396
3396
  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" };
3397
- 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" };
3397
+ 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" };
3398
3398
  }
3399
3399
  });
3400
3400
 
@@ -4057,110 +4057,147 @@ function registerWebComponent() {
4057
4057
  var IsaAuth = class {
4058
4058
  constructor(config = {}) {
4059
4059
  this.providerInstance = null;
4060
+ this.providerInstances = /* @__PURE__ */ new Map();
4061
+ this.authProviders = /* @__PURE__ */ new Map();
4062
+ this.config = config;
4060
4063
  const {
4061
- provider = "base",
4064
+ provider,
4062
4065
  secret = "isa-auth-secret",
4063
4066
  clientId = "",
4064
4067
  callbackUrl = "",
4065
4068
  scope,
4066
4069
  storage = "memory",
4067
4070
  storagePrefix = "",
4068
- extraOptions = {}
4071
+ extraOptions = {},
4072
+ providers: multiProviders
4069
4073
  } = config;
4070
- this.providerType = provider;
4074
+ const firstMultiKey = multiProviders ? Object.keys(multiProviders)[0] : void 0;
4075
+ const primaryProvider = provider || firstMultiKey || "base";
4076
+ this.providerType = primaryProvider;
4071
4077
  this.core = new import_isa_auth_core.default({
4072
- providerType: provider,
4078
+ providerType: primaryProvider,
4073
4079
  secret,
4074
4080
  storage,
4075
4081
  storagePrefix
4076
4082
  });
4077
- const ProviderClass = this.core.getProvider();
4078
- if (ProviderClass) {
4079
- if (provider === "google") {
4080
- this.providerInstance = new ProviderClass({
4081
- clientId,
4082
- callback: (token) => {
4083
- this.setAccessToken(token);
4084
- return token;
4085
- },
4086
- ...extraOptions
4087
- });
4088
- } else if (provider === "kakao") {
4089
- this.providerInstance = new ProviderClass({
4090
- javascriptKey: clientId,
4091
- redirectUri: callbackUrl,
4092
- scope,
4093
- ...extraOptions
4094
- });
4095
- } else if (provider === "naver") {
4096
- this.providerInstance = new ProviderClass({
4097
- clientId,
4098
- callbackUrl,
4099
- ...extraOptions
4100
- });
4101
- } else if (provider === "web3") {
4102
- this.providerInstance = new ProviderClass({
4103
- domain: typeof window !== "undefined" ? window.location.host : "localhost",
4104
- ...extraOptions
4105
- });
4106
- } else if (provider === "github") {
4107
- this.providerInstance = new ProviderClass({
4108
- clientId,
4109
- redirectUri: callbackUrl,
4110
- scope,
4111
- ...extraOptions
4112
- });
4113
- } else if (provider === "apple") {
4114
- this.providerInstance = new ProviderClass({
4115
- clientId,
4116
- redirectURI: callbackUrl,
4117
- scope,
4118
- ...extraOptions
4119
- });
4120
- } else if (provider === "discord") {
4121
- this.providerInstance = new ProviderClass({
4122
- clientId,
4123
- redirectUri: callbackUrl,
4124
- scope,
4125
- ...extraOptions
4126
- });
4127
- } else if (provider === "line") {
4128
- this.providerInstance = new ProviderClass({
4129
- clientId,
4130
- callbackUrl,
4131
- scope,
4132
- ...extraOptions
4133
- });
4134
- } else if (provider === "meta" || provider === "facebook") {
4135
- this.providerInstance = new ProviderClass({
4136
- appId: clientId,
4137
- redirectUri: callbackUrl,
4138
- scope,
4139
- ...extraOptions
4140
- });
4141
- } else if (provider === "world") {
4142
- this.providerInstance = new ProviderClass({
4143
- appId: clientId,
4144
- action: extraOptions.action || "login",
4145
- verificationLevel: extraOptions.verificationLevel || "orb",
4146
- ...extraOptions
4147
- });
4148
- } else if (provider === "passkey") {
4149
- this.providerInstance = new ProviderClass({
4150
- rpName: extraOptions.rpName || "ISA-AUTH Application",
4151
- rpId: extraOptions.rpId,
4152
- ...extraOptions
4153
- });
4154
- } else {
4155
- this.providerInstance = new ProviderClass({
4156
- clientId,
4157
- ...extraOptions
4158
- });
4083
+ const service = this.core.getService();
4084
+ if (multiProviders) {
4085
+ for (const [key, opts] of Object.entries(multiProviders)) {
4086
+ const pType = key;
4087
+ const instance = this.instantiateProvider(pType, opts || {});
4088
+ if (instance) {
4089
+ this.providerInstances.set(pType, instance);
4090
+ const btn = (0, import_isa_auth_core.getButton)(import_isa_auth_core.providerToButtonMap[pType] || "none");
4091
+ this.authProviders.set(pType, new AuthProvider_default(service, instance, btn));
4092
+ }
4159
4093
  }
4160
4094
  }
4161
- const button = this.core.getButton();
4162
- const service = this.core.getService();
4163
- this.authProvider = new AuthProvider_default(service, this.providerInstance, button);
4095
+ if (provider && !this.providerInstances.has(provider)) {
4096
+ const singleOpts = {
4097
+ clientId,
4098
+ callbackUrl,
4099
+ scope,
4100
+ extraOptions
4101
+ };
4102
+ const instance = this.instantiateProvider(provider, singleOpts);
4103
+ if (instance) {
4104
+ this.providerInstances.set(provider, instance);
4105
+ const btn = this.core.getButton();
4106
+ this.authProviders.set(provider, new AuthProvider_default(service, instance, btn));
4107
+ }
4108
+ }
4109
+ this.providerInstance = this.providerInstances.get(primaryProvider) || null;
4110
+ this.authProvider = this.authProviders.get(primaryProvider) || new AuthProvider_default(service, this.providerInstance, this.core.getButton());
4111
+ }
4112
+ instantiateProvider(type, opts) {
4113
+ if (type === "base" || type === "jwt") {
4114
+ return null;
4115
+ }
4116
+ const ProviderClass = (0, import_isa_auth_core.getProvider)(type);
4117
+ if (!ProviderClass) return null;
4118
+ const { clientId = "", callbackUrl = "", scope, extraOptions = {}, ...rest } = opts;
4119
+ const merged = { ...rest, ...extraOptions };
4120
+ if (type === "google") {
4121
+ return new ProviderClass({
4122
+ clientId,
4123
+ callback: (token) => {
4124
+ this.setAccessToken(token);
4125
+ return token;
4126
+ },
4127
+ ...merged
4128
+ });
4129
+ } else if (type === "kakao") {
4130
+ return new ProviderClass({
4131
+ javascriptKey: clientId,
4132
+ redirectUri: callbackUrl,
4133
+ scope,
4134
+ ...merged
4135
+ });
4136
+ } else if (type === "naver") {
4137
+ return new ProviderClass({
4138
+ clientId,
4139
+ callbackUrl,
4140
+ ...merged
4141
+ });
4142
+ } else if (type === "web3") {
4143
+ return new ProviderClass({
4144
+ domain: typeof window !== "undefined" ? window.location.host : "localhost",
4145
+ ...merged
4146
+ });
4147
+ } else if (type === "github") {
4148
+ return new ProviderClass({
4149
+ clientId,
4150
+ redirectUri: callbackUrl,
4151
+ scope,
4152
+ ...merged
4153
+ });
4154
+ } else if (type === "apple") {
4155
+ return new ProviderClass({
4156
+ clientId,
4157
+ redirectURI: callbackUrl,
4158
+ scope,
4159
+ ...merged
4160
+ });
4161
+ } else if (type === "discord") {
4162
+ return new ProviderClass({
4163
+ clientId,
4164
+ redirectUri: callbackUrl,
4165
+ scope,
4166
+ ...merged
4167
+ });
4168
+ } else if (type === "line") {
4169
+ return new ProviderClass({
4170
+ clientId,
4171
+ callbackUrl,
4172
+ scope,
4173
+ ...merged
4174
+ });
4175
+ } else if (type === "meta" || type === "facebook") {
4176
+ return new ProviderClass({
4177
+ appId: clientId,
4178
+ redirectUri: callbackUrl,
4179
+ scope,
4180
+ ...merged
4181
+ });
4182
+ } else if (type === "world") {
4183
+ return new ProviderClass({
4184
+ appId: clientId,
4185
+ action: merged.action || "login",
4186
+ verificationLevel: merged.verificationLevel || "orb",
4187
+ ...merged
4188
+ });
4189
+ } else if (type === "passkey") {
4190
+ return new ProviderClass({
4191
+ rpName: merged.rpName || "ISA-AUTH Application",
4192
+ rpId: merged.rpId,
4193
+ ...merged
4194
+ });
4195
+ } else {
4196
+ return new ProviderClass({
4197
+ clientId,
4198
+ ...merged
4199
+ });
4200
+ }
4164
4201
  }
4165
4202
  // 1. Core State Methods
4166
4203
  isAuthenticated() {
@@ -4176,10 +4213,11 @@ var IsaAuth = class {
4176
4213
  return this.core.getContext();
4177
4214
  }
4178
4215
  /**
4179
- * Returns current provider category ('social' | 'developer' | 'web3' | 'identity' | null)
4216
+ * Returns category of the specified or primary provider
4180
4217
  */
4181
- getCategory() {
4182
- return (0, import_isa_auth_core.getProviderCategory)(this.providerType);
4218
+ getCategory(provider) {
4219
+ const target = provider || this.providerType;
4220
+ return (0, import_isa_auth_core.getProviderCategory)(target);
4183
4221
  }
4184
4222
  setAccessToken(token) {
4185
4223
  const service = this.core.getService();
@@ -4201,8 +4239,19 @@ var IsaAuth = class {
4201
4239
  updateAuthInfo(partial) {
4202
4240
  return this.core.updateAuthInfo(partial);
4203
4241
  }
4204
- // 2. Authentication Actions
4205
- async signIn() {
4242
+ // 2. Authentication Actions (Multi-Provider Support)
4243
+ async signIn(provider) {
4244
+ if (provider) {
4245
+ const targetAuthProvider = this.authProviders.get(provider);
4246
+ if (targetAuthProvider) {
4247
+ return await targetAuthProvider.signIn();
4248
+ }
4249
+ const targetInstance = this.providerInstances.get(provider);
4250
+ if (targetInstance && typeof targetInstance.signIn === "function") {
4251
+ return await targetInstance.signIn();
4252
+ }
4253
+ throw new Error(`[ISA-AUTH] Provider "${provider}" is not registered in this IsaAuth instance.`);
4254
+ }
4206
4255
  return await this.authProvider.signIn();
4207
4256
  }
4208
4257
  signOut() {
@@ -4224,25 +4273,86 @@ var IsaAuth = class {
4224
4273
  stopAutoRefresh() {
4225
4274
  this.core.stopAutoRefresh();
4226
4275
  }
4227
- // 3. UI and Renderers
4228
- getButton() {
4276
+ // 3. UI and Renderers (Multi-Provider Support)
4277
+ getButton(provider) {
4278
+ if (provider) {
4279
+ const target = this.authProviders.get(provider);
4280
+ return target ? target.getButton() : (0, import_isa_auth_core.getButton)(import_isa_auth_core.providerToButtonMap[provider] || "none");
4281
+ }
4229
4282
  return this.authProvider.getButton();
4230
4283
  }
4231
- renderButton(container) {
4232
- const buttonData = this.getButton();
4284
+ /**
4285
+ * Renders button for specified provider (or primary provider if omitted)
4286
+ * Usage:
4287
+ * auth.renderButton(container); // primary provider
4288
+ * auth.renderButton('google', container); // specific provider
4289
+ */
4290
+ renderButton(providerOrContainer, container) {
4291
+ let targetProvider = this.providerType;
4292
+ let targetContainer = null;
4293
+ if (typeof providerOrContainer === "string") {
4294
+ targetProvider = providerOrContainer;
4295
+ targetContainer = container || null;
4296
+ } else {
4297
+ targetContainer = providerOrContainer || null;
4298
+ }
4299
+ const buttonData = this.getButton(targetProvider);
4233
4300
  if (!buttonData) return null;
4301
+ const data = typeof buttonData.toJSON === "function" ? buttonData.toJSON() : buttonData;
4234
4302
  const btn = renderByJs({
4235
- onClick: () => this.signIn(),
4236
- label: buttonData.text,
4237
- className: buttonData.className,
4238
- style: buttonData.style
4303
+ onClick: () => this.signIn(targetProvider),
4304
+ label: data.text,
4305
+ className: data.className,
4306
+ style: data.style
4239
4307
  });
4240
- if (container) {
4241
- container.innerHTML = "";
4242
- container.appendChild(btn);
4308
+ if (btn) {
4309
+ if (!btn.dataset) btn.dataset = {};
4310
+ btn.dataset.provider = targetProvider;
4311
+ }
4312
+ if (targetContainer) {
4313
+ targetContainer.innerHTML = "";
4314
+ targetContainer.appendChild(btn);
4243
4315
  }
4244
4316
  return btn;
4245
4317
  }
4318
+ /**
4319
+ * Renders all registered provider buttons inside a container element.
4320
+ */
4321
+ renderAllButtons(container, options = {}) {
4322
+ if (!container) return [];
4323
+ const { direction = "column", gap = "8px" } = options;
4324
+ const providerList = options.providers || Array.from(this.providerInstances.keys());
4325
+ const wrapper = document.createElement("div");
4326
+ wrapper.className = "isa-auth-button-group";
4327
+ wrapper.style.display = direction === "grid" ? "grid" : "flex";
4328
+ wrapper.style.flexDirection = direction === "row" ? "row" : "column";
4329
+ if (direction === "grid") {
4330
+ wrapper.style.gridTemplateColumns = "repeat(auto-fill, minmax(180px, 1fr))";
4331
+ }
4332
+ wrapper.style.gap = gap;
4333
+ const buttons = [];
4334
+ for (const p of providerList) {
4335
+ const slot = document.createElement("div");
4336
+ slot.className = `isa-auth-slot-${p}`;
4337
+ const btn = this.renderButton(p, slot);
4338
+ if (btn) {
4339
+ buttons.push(btn);
4340
+ wrapper.appendChild(slot);
4341
+ }
4342
+ }
4343
+ container.innerHTML = "";
4344
+ container.appendChild(wrapper);
4345
+ return buttons;
4346
+ }
4347
+ getProviderInstance(provider) {
4348
+ if (provider) {
4349
+ return this.providerInstances.get(provider) || null;
4350
+ }
4351
+ return this.providerInstance;
4352
+ }
4353
+ getRegisteredProviders() {
4354
+ return Array.from(this.providerInstances.keys());
4355
+ }
4246
4356
  // 4. RBAC, ABAC & Enhanced Guards
4247
4357
  hasRole(role) {
4248
4358
  return this.authProvider.hasRole(role);
@@ -4250,34 +4360,18 @@ var IsaAuth = class {
4250
4360
  hasPermission(permission) {
4251
4361
  return this.authProvider.hasPermission(permission);
4252
4362
  }
4253
- /**
4254
- * Check permission with wildcard matching support
4255
- * E.g. isaAuth.can('users:read') or isaAuth.can(['users:read', 'users:write'])
4256
- */
4257
4363
  can(permission, matchAll = true) {
4258
4364
  return this.core.hasPermission(permission, matchAll);
4259
4365
  }
4260
- /**
4261
- * Check role with optional matchAll option
4262
- */
4263
4366
  is(role, matchAll = false) {
4264
4367
  return this.core.hasRole(role, matchAll);
4265
4368
  }
4266
- /**
4267
- * Evaluates guard and returns detailed GuardResult
4268
- */
4269
4369
  async evaluateGuard(options, customContext) {
4270
4370
  return this.core.evaluateGuard(options, customContext);
4271
4371
  }
4272
- /**
4273
- * Instant boolean guard check (backwards compatible)
4274
- */
4275
4372
  createGuard(options) {
4276
4373
  return this.core.createGuard(options);
4277
4374
  }
4278
- /**
4279
- * Creates a reusable router navigation guard
4280
- */
4281
4375
  createNavigationGuard(options) {
4282
4376
  return (0, import_isa_auth_core.createNavigationGuard)({
4283
4377
  ...options,